repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c_messages/bearer_resource_cmd.c
<reponame>nikhilc149/e-utran-features-bug-fixes<filename>cp/gtpv2c_messages/bearer_resource_cmd.c /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <rte_errno.h> #include "gtpv2c_set_ie.h" #include "gw_adapter.h" #include "sm_struct.h" #include "gtpc_session.h" #include "teid.h" #include "cp.h" #define DEFAULT_BEARER_QOS_PRIORITY (15) extern pfcp_config_t config; extern int clSystemLog; /** * @brief : The structure to contain required information from a parsed Bearer Resource * Command message * Contains UE context, bearer, and PDN connection, as well as information * elements required to process message. */ struct parse_bearer_resource_command_t { ue_context *context; pdn_connection *pdn; eps_bearer *bearer; gtpv2c_ie *linked_eps_bearer_id; gtpv2c_ie *procedure_transaction_id; traffic_aggregation_description *tad; gtpv2c_ie *flow_quality_of_service; }; /** * @brief : Parse bearer resource commnad * @param : gtpv2c_rx , gtpv2c header * @param : brc, command * @return : Returns 0 in case of success , -1 otherwise */ static int parse_bearer_resource_cmd(gtpv2c_header_t *gtpv2c_rx, struct parse_bearer_resource_command_t *brc) { gtpv2c_ie *current_ie; gtpv2c_ie *limit_ie; int ret = rte_hash_lookup_data(ue_context_by_fteid_hash, (const void *) &gtpv2c_rx->teid.has_teid.teid, (void **) &brc->context); if (ret < 0 || !brc->context) return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; /** @todo: fully verify mandatory fields within received message */ FOR_EACH_GTPV2C_IE(gtpv2c_rx, current_ie, limit_ie) { if (current_ie->type == GTP_IE_EPS_BEARER_ID && current_ie->instance == IE_INSTANCE_ZERO) { brc->linked_eps_bearer_id = current_ie; } else if (current_ie->type == GTP_IE_PROC_TRANS_ID && current_ie->instance == IE_INSTANCE_ZERO) { brc->procedure_transaction_id = current_ie; } else if (current_ie->type == GTP_IE_FLOW_QLTY_OF_SVC && current_ie->instance == IE_INSTANCE_ZERO) { brc->flow_quality_of_service = current_ie; } else if (current_ie->type == GTP_IE_TRAFFIC_AGG_DESC && current_ie->instance == IE_INSTANCE_ZERO) { brc->tad = IE_TYPE_PTR_FROM_GTPV2C_IE( traffic_aggregation_description, current_ie); } } if (!brc->linked_eps_bearer_id || !brc->procedure_transaction_id || !brc->tad) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Improper Bearer Resource Command - " "Dropping packet\n", LOG_VALUE); return -EPERM; } int ebi = *IE_TYPE_PTR_FROM_GTPV2C_IE(uint8_t, brc->linked_eps_bearer_id); int ebi_index = GET_EBI_INDEX(ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } if (!(brc->context->bearer_bitmap & (1 << ebi_index))) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Received Bearer Resource Command for non-existent LBI - " "Dropping packet\n", LOG_VALUE); return -EPERM; } brc->bearer = brc->context->eps_bearers[ebi_index]; if (!brc->bearer) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Received Bearer Resource Command on non-existent LBI - " "Bitmap Inconsistency - Dropping packet\n", LOG_VALUE); return -EPERM; } brc->pdn = brc->bearer->pdn; return 0; } /** * @brief : parse packet filter * @param : cpf * packet filter corresponding to table 10.5.144b in 3gpp 2.008 contained * within gtpv2c message * @param : pf * packet filter structure for internal use to CP * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ static int parse_packet_filter(create_pkt_filter *cpf, pkt_fltr *pf) { reset_packet_filter(pf); /*TODO: Precedence is removed from SDF. * Check impact in this case*/ pf->direction = cpf->direction; packet_filter_component *filter_component = (packet_filter_component *) &cpf[1]; uint8_t length = cpf->pkt_filter_length; while (length) { if (length < PACKET_FILTER_COMPONENT_SIZE[filter_component->type]) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Insufficient space in packet filter for" " component type %u\n", LOG_VALUE, filter_component->type); return GTPV2C_CAUSE_INVALID_LENGTH; } length -= PACKET_FILTER_COMPONENT_SIZE[filter_component->type]; switch (filter_component->type) { case IPV4_REMOTE_ADDRESS: pf->remote_ip_addr = filter_component->type_union.ipv4.ipv4; if (filter_component->type_union.ipv4.mask.s_addr && filter_component->type_union.ipv4.mask.s_addr != UINT32_MAX && __builtin_clzl(~filter_component->type_union. ipv4.mask.s_addr) + __builtin_ctzl( filter_component->type_union.ipv4.mask. s_addr) != 32) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in ipmask:\n",LOG_VALUE); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPV4_REMOTE_ADDRESS: %s\n",LOG_VALUE, inet_ntoa(pf->remote_ip_addr)); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Filter component: %s\n",LOG_VALUE, inet_ntoa(filter_component->type_union. ipv4.mask)); } pf->remote_ip_mask = __builtin_popcountl( filter_component->type_union.ipv4.mask.s_addr); filter_component = (packet_filter_component *) &filter_component->type_union.ipv4.next_component; break; case IPV4_LOCAL_ADDRESS: pf->local_ip_addr = filter_component->type_union.ipv4.ipv4; if (filter_component->type_union.ipv4.mask.s_addr && filter_component->type_union.ipv4.mask.s_addr != UINT32_MAX && __builtin_clzl(~filter_component->type_union. ipv4.mask.s_addr) + __builtin_ctzl( filter_component->type_union.ipv4.mask. s_addr) != 32) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in ipmask: \n", LOG_VALUE); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPV4_REMOTE_ADDRESS: %s\n", LOG_VALUE, inet_ntoa(pf->local_ip_addr)); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Filter Component: %s\n", LOG_VALUE, inet_ntoa( filter_component->type_union.ipv4. mask)); } pf->local_ip_mask = __builtin_popcountl( filter_component->type_union.ipv4.mask.s_addr); filter_component = (packet_filter_component *) &filter_component->type_union.ipv4.next_component; break; case PROTOCOL_ID_NEXT_HEADER: pf->proto = filter_component->type_union.proto.proto; /* 3gpp specifies no mask so we use exact match */ pf->proto_mask = UINT8_MAX; filter_component = (packet_filter_component *) &filter_component->type_union.proto.next_component; break; case SINGLE_LOCAL_PORT: pf->local_port_low = filter_component->type_union.port.port; pf->local_port_high = pf->local_port_low; filter_component = (packet_filter_component *) &filter_component->type_union.port.next_component; break; case LOCAL_PORT_RANGE: pf->local_port_low = filter_component->type_union.port_range.port_low; pf->local_port_high = filter_component->type_union.port_range.port_high; filter_component = (packet_filter_component *) &filter_component->type_union.port_range. next_component; break; case SINGLE_REMOTE_PORT: pf->remote_port_low = filter_component->type_union.port.port; pf->remote_port_high = pf->remote_port_low; filter_component = (packet_filter_component *) &filter_component->type_union.port.next_component; break; case REMOTE_PORT_RANGE: pf->remote_port_low = filter_component->type_union.port_range.port_low; pf->remote_port_high = filter_component->type_union.port_range.port_high; filter_component = (packet_filter_component *) &filter_component->type_union.port_range. next_component; break; default: clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid/Unsupported TFT Filter" " Component\n", LOG_VALUE); return GTPV2C_CAUSE_SERVICE_NOT_SUPPORTED; } } return 0; } /** * @brief : install packet filter * @param : ded_bearer * @param : tad * Traffic Aggregation Description information element as described by * clause 10.5.6.12 3gpp 24.008, as referenced by clause 8.20 3gpp 29.274 * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ static int install_packet_filters(eps_bearer *ded_bearer, traffic_aggregation_description *tad) { uint8_t tad_filter_index = 0; uint8_t bearer_filter_id = 0; int ret; uint64_t mbr; create_pkt_filter *cpf = (create_pkt_filter *) &tad[1]; for (tad_filter_index = 0; tad_filter_index < MAX_FILTERS_PER_UE; ++tad_filter_index) { ded_bearer->packet_filter_map[tad_filter_index] = -ENOENT; } /* for each filter in tad */ for (tad_filter_index = 0; tad_filter_index < tad->num_pkt_filters; ++tad_filter_index) { /* look for a free filter id in the bearer */ for (; bearer_filter_id < MAX_FILTERS_PER_UE; ++bearer_filter_id) { if (ded_bearer->packet_filter_map[bearer_filter_id] == -ENOENT) break; } if (bearer_filter_id == MAX_FILTERS_PER_UE) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Not enough packet filter " "identifiers available", LOG_VALUE); return -EPERM; } packet_filter pf; ret = parse_packet_filter(cpf, &pf.pkt_fltr); if (ret) return -ret; int dp_packet_filter_id = get_packet_filter_id(&pf.pkt_fltr); /*TODO : rating group is moved to PCC. * Handle appropriately here. */ /*pf.pkt_fltr.rating_group = ded_bearer->qos.qos.qci;*/ if (dp_packet_filter_id == -ENOENT) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Packet filters must be pre-defined by static " "file prior to reference by s11 Message\n", LOG_VALUE); /* TODO: Implement dynamic installation of packet * filters on DP - remove continue*/ continue; mbr = ded_bearer->qos.ul_mbr; /* Convert bit rate into Bytes as CIR stored in bytes */ pf.ul_mtr_idx = meter_profile_index_get(mbr); mbr = ded_bearer->qos.dl_mbr; /* Convert bit rate into Bytes as CIR stored in bytes */ pf.dl_mtr_idx = meter_profile_index_get(mbr); dp_packet_filter_id = install_packet_filter(&pf); if (dp_packet_filter_id < 0) return GTPV2C_CAUSE_SYSTEM_FAILURE; } ded_bearer->num_packet_filters++; ded_bearer->packet_filter_map[bearer_filter_id] = dp_packet_filter_id; ded_bearer->pdn->packet_filter_map[bearer_filter_id] = ded_bearer; } return 0; } /** * @brief : from parameters, populates gtpv2c message 'create bearer request' and * populates required information elements as defined by * clause 7.2.3 3gpp 29.274 * @param : gtpv2c_tx * transmission buffer to contain 'create bearer request' message * @param : sequence * sequence number as described by clause 7.6 3gpp 29.274 * @param : context * UE Context data structure pertaining to the bearer to be created * @param : bearer * EPS Bearer data structure to be created * @param : lbi * 'Linked Bearer Identifier': indicates the default bearer identifier * associated to the PDN connection to which the dedicated bearer is to be * created * @param : pti * 'Procedure Transaction Identifier' according to clause 8.35 3gpp 29.274, * as specified by table 7.2.3-1 3gpp 29.274, 'shall be the same as the one * used in the corresponding bearer resource command' * @param : eps_bearer_lvl_tft * @param : tft_len * @return : Returns nothing */ int set_create_bearer_request(gtpv2c_header_t *gtpv2c_tx, uint32_t sequence, pdn_connection *pdn, uint8_t lbi, uint8_t pti, struct resp_info *resp, uint8_t is_piggybacked, bool req_for_mme) { uint8_t len = 0; uint8_t idx = 0; ue_context *context = NULL; create_bearer_req_t cb_req = {0}; eps_bearer *bearer = NULL; context = pdn->context; if(req_for_mme == TRUE){ sequence = generate_seq_number(); } if (context->cp_mode != PGWC) { set_gtpv2c_teid_header((gtpv2c_header_t *) &cb_req, GTP_CREATE_BEARER_REQ, context->s11_mme_gtpc_teid, sequence, 0); } else { set_gtpv2c_teid_header((gtpv2c_header_t *) &cb_req, GTP_CREATE_BEARER_REQ, pdn->s5s8_sgw_gtpc_teid, sequence, 0); } if (pti) { set_pti(&cb_req.pti, IE_INSTANCE_ZERO, pti); } set_ebi(&cb_req.lbi, IE_INSTANCE_ZERO, lbi); for(idx = 0; idx < resp->bearer_count; idx++) { int8_t ebi_index = GET_EBI_INDEX(resp->eps_bearer_ids[idx]); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); } bearer = context->eps_bearers[ebi_index]; if (bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Retrive modify bearer " "context but EBI is non-existent- " "Bitmap Inconsistency - Dropping packet\n",LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } else { set_ie_header(&cb_req.bearer_contexts[idx].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_ebi(&cb_req.bearer_contexts[idx].eps_bearer_id, IE_INSTANCE_ZERO, 0); cb_req.bearer_contexts[idx].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; set_bearer_qos(&cb_req.bearer_contexts[idx].bearer_lvl_qos, IE_INSTANCE_ZERO, bearer); cb_req.bearer_contexts[idx].header.len += sizeof(gtp_bearer_qlty_of_svc_ie_t); if(SGWC != context->cp_mode) { len = set_bearer_tft(&cb_req.bearer_contexts[idx].tft, IE_INSTANCE_ZERO, TFT_CREATE_NEW, bearer, NULL); cb_req.bearer_contexts[idx].header.len += len; }else { memset(cb_req.bearer_contexts[idx].tft.eps_bearer_lvl_tft, 0, MAX_TFT_LEN); memcpy(cb_req.bearer_contexts[idx].tft.eps_bearer_lvl_tft, resp->eps_bearer_lvl_tft[idx], MAX_TFT_LEN); if (resp->eps_bearer_lvl_tft[idx] != NULL) { rte_free(resp->eps_bearer_lvl_tft[idx]); resp->eps_bearer_lvl_tft[idx] = NULL; } set_ie_header(&cb_req.bearer_contexts[idx].tft.header, GTP_IE_EPS_BEARER_LVL_TRAFFIC_FLOW_TMPL, IE_INSTANCE_ZERO, resp->tft_header_len[idx]); len = resp->tft_header_len[idx] + IE_HEADER_SIZE; cb_req.bearer_contexts[idx].header.len += len; } set_charging_id(&cb_req.bearer_contexts[idx].charging_id, IE_INSTANCE_ZERO, 1); cb_req.bearer_contexts[idx].header.len += sizeof(gtp_charging_id_ie_t); } if (PGWC == context->cp_mode) { cb_req.bearer_contexts[idx].header.len += set_gtpc_fteid(&cb_req.bearer_contexts[idx].s58_u_pgw_fteid, GTPV2C_IFTYPE_S5S8_PGW_GTPU, IE_INSTANCE_ONE, bearer->s5s8_pgw_gtpu_ip, bearer->s5s8_pgw_gtpu_teid); } else if(SGWC == context->cp_mode){ cb_req.bearer_contexts[idx].header.len += set_gtpc_fteid(&cb_req.bearer_contexts[idx].s58_u_pgw_fteid, GTPV2C_IFTYPE_S5S8_PGW_GTPU, IE_INSTANCE_ONE, bearer->s5s8_pgw_gtpu_ip, bearer->s5s8_pgw_gtpu_teid); cb_req.bearer_contexts[idx].header.len += set_gtpc_fteid(&cb_req.bearer_contexts[idx].s1u_sgw_fteid, GTPV2C_IFTYPE_S1U_SGW_GTPU, IE_INSTANCE_ZERO, bearer->s1u_sgw_gtpu_ip, bearer->s1u_sgw_gtpu_teid); } else { cb_req.bearer_contexts[idx].header.len += set_gtpc_fteid(&cb_req.bearer_contexts[idx].s1u_sgw_fteid, GTPV2C_IFTYPE_S1U_SGW_GTPU, IE_INSTANCE_ZERO, bearer->s1u_sgw_gtpu_ip, bearer->s1u_sgw_gtpu_teid); /* Add the PGW F-TEID in the CBReq to support promotion and demotion */ if ((bearer->s5s8_pgw_gtpu_teid != 0) && (bearer->s5s8_pgw_gtpu_ip.ipv4_addr != 0 || *bearer->s5s8_pgw_gtpu_ip.ipv6_addr)) { cb_req.bearer_contexts[idx].header.len += set_gtpc_fteid(&cb_req.bearer_contexts[idx].s58_u_pgw_fteid, GTPV2C_IFTYPE_S5S8_PGW_GTPU, IE_INSTANCE_ONE, bearer->s5s8_pgw_gtpu_ip, bearer->s5s8_pgw_gtpu_teid); } } cb_req.bearer_cnt++; } if(context->pra_flag){ set_presence_reporting_area_action_ie(&cb_req.pres_rptng_area_act, context); context->pra_flag = 0; } encode_create_bearer_req(&cb_req, (uint8_t *)gtpv2c_tx); RTE_SET_USED(is_piggybacked); return 0; } int set_create_bearer_response(gtpv2c_header_t *gtpv2c_tx, uint32_t sequence, pdn_connection *pdn, uint8_t lbi, uint8_t pti, struct resp_info *resp) { int ebi_index = 0, len = 0; uint8_t idx = 0; eps_bearer *bearer = NULL; ue_context *context = NULL; create_bearer_rsp_t cb_resp = {0}; context = pdn->context; set_gtpv2c_teid_header((gtpv2c_header_t *) &cb_resp, GTP_CREATE_BEARER_RSP, pdn->s5s8_pgw_gtpc_teid , sequence, 0); set_cause_accepted(&cb_resp.cause, IE_INSTANCE_ZERO); if (TRUE == context->piggyback) { cb_resp.cause.cause_value = resp->cb_rsp_attach.cause_value; } else { cb_resp.cause.cause_value = resp->gtpc_msg.cb_rsp.cause.cause_value; } if (pti) {} if (lbi) {} for(idx = 0; idx < resp->bearer_count; idx++) { ebi_index = GET_EBI_INDEX(resp->eps_bearer_ids[idx]); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } if(cb_resp.cause.cause_value != GTPV2C_CAUSE_REQUEST_ACCEPTED ) { bearer = context->eps_bearers[(idx + MAX_BEARERS)]; } else { bearer = context->eps_bearers[ebi_index]; } if (bearer == NULL) { fprintf(stderr, LOG_FORMAT" Retrive modify bearer context but EBI is non-existent- " "Bitmap Inconsistency - Dropping packet\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } else { set_ie_header(&cb_resp.bearer_contexts[idx].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_ebi(&cb_resp.bearer_contexts[idx].eps_bearer_id, IE_INSTANCE_ZERO, (resp->eps_bearer_ids[idx])); cb_resp.bearer_contexts[idx].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; set_cause_accepted(&cb_resp.bearer_contexts[idx].cause, IE_INSTANCE_ZERO); cb_resp.bearer_contexts[idx].header.len += sizeof(uint16_t) + IE_HEADER_SIZE; if (TRUE == context->piggyback) { cb_resp.bearer_contexts[idx].cause.cause_value = resp->cb_rsp_attach.bearer_cause_value[idx]; } else { cb_resp.bearer_contexts[idx].cause.cause_value = resp->gtpc_msg.cb_rsp.bearer_contexts[idx].cause.cause_value; } len = set_gtpc_fteid(&cb_resp.bearer_contexts[idx].s58_u_pgw_fteid, GTPV2C_IFTYPE_S5S8_PGW_GTPU, IE_INSTANCE_THREE, bearer->s5s8_pgw_gtpu_ip, bearer->s5s8_pgw_gtpu_teid); cb_resp.bearer_contexts[idx].header.len += len; len = set_gtpc_fteid(&cb_resp.bearer_contexts[idx].s58_u_sgw_fteid, GTPV2C_IFTYPE_S5S8_SGW_GTPU, IE_INSTANCE_TWO, bearer->s5s8_sgw_gtpu_ip, bearer->s5s8_sgw_gtpu_teid); cb_resp.bearer_contexts[idx].header.len += len; if (TRUE == context->piggyback) { if((resp->cb_rsp_attach.bearer_cause_value[idx] != GTPV2C_CAUSE_REQUEST_ACCEPTED)) { rte_free(bearer); } } else { if((resp->gtpc_msg.cb_rsp.bearer_contexts[idx].cause.cause_value != GTPV2C_CAUSE_REQUEST_ACCEPTED)) { rte_free(bearer); } } } } /*for Loop*/ if((pdn->flag_fqcsid_modified == TRUE) && (context->piggyback == TRUE)) { #ifdef USE_CSID /* Set the SGW FQ-CSID */ if (pdn->sgw_csid.num_csid) { set_gtpc_fqcsid_t(&cb_resp.sgw_fqcsid, IE_INSTANCE_ONE, &pdn->sgw_csid); } /* Set the MME FQ-CSID */ if (pdn->mme_csid.num_csid) { set_gtpc_fqcsid_t(&cb_resp.mme_fqcsid, IE_INSTANCE_ZERO, &pdn->mme_csid); } #endif /* USE_CSID */ } len = 0; if(context->uli_flag != FALSE) { if (context->uli.lai) { cb_resp.uli.lai = context->uli.lai; cb_resp.uli.lai2.lai_mcc_digit_2 = context->uli.lai2.lai_mcc_digit_2; cb_resp.uli.lai2.lai_mcc_digit_1 = context->uli.lai2.lai_mcc_digit_1; cb_resp.uli.lai2.lai_mnc_digit_3 = context->uli.lai2.lai_mnc_digit_3; cb_resp.uli.lai2.lai_mcc_digit_3 = context->uli.lai2.lai_mcc_digit_3; cb_resp.uli.lai2.lai_mnc_digit_2 = context->uli.lai2.lai_mnc_digit_2; cb_resp.uli.lai2.lai_mnc_digit_1 = context->uli.lai2.lai_mnc_digit_1; cb_resp.uli.lai2.lai_lac = context->uli.lai2.lai_lac; len += sizeof(cb_resp.uli.lai2); } if (context->uli.tai) { cb_resp.uli.tai = context->uli.tai; cb_resp.uli.tai2.tai_mcc_digit_2 = context->uli.tai2.tai_mcc_digit_2; cb_resp.uli.tai2.tai_mcc_digit_1 = context->uli.tai2.tai_mcc_digit_1; cb_resp.uli.tai2.tai_mnc_digit_3 = context->uli.tai2.tai_mnc_digit_3; cb_resp.uli.tai2.tai_mcc_digit_3 = context->uli.tai2.tai_mcc_digit_3; cb_resp.uli.tai2.tai_mnc_digit_2 = context->uli.tai2.tai_mnc_digit_2; cb_resp.uli.tai2.tai_mnc_digit_1 = context->uli.tai2.tai_mnc_digit_1; cb_resp.uli.tai2.tai_tac = context->uli.tai2.tai_tac; len += sizeof(cb_resp.uli.tai2); } if (context->uli.rai) { cb_resp.uli.rai = context->uli.rai; cb_resp.uli.rai2.ria_mcc_digit_2 = context->uli.rai2.ria_mcc_digit_2; cb_resp.uli.rai2.ria_mcc_digit_1 = context->uli.rai2.ria_mcc_digit_1; cb_resp.uli.rai2.ria_mnc_digit_3 = context->uli.rai2.ria_mnc_digit_3; cb_resp.uli.rai2.ria_mcc_digit_3 = context->uli.rai2.ria_mcc_digit_3; cb_resp.uli.rai2.ria_mnc_digit_2 = context->uli.rai2.ria_mnc_digit_2; cb_resp.uli.rai2.ria_mnc_digit_1 = context->uli.rai2.ria_mnc_digit_1; cb_resp.uli.rai2.ria_lac = context->uli.rai2.ria_lac; cb_resp.uli.rai2.ria_rac = context->uli.rai2.ria_rac; len += sizeof(cb_resp.uli.rai2); } if (context->uli.sai) { cb_resp.uli.sai = context->uli.sai; cb_resp.uli.sai2.sai_mcc_digit_2 = context->uli.sai2.sai_mcc_digit_2; cb_resp.uli.sai2.sai_mcc_digit_1 = context->uli.sai2.sai_mcc_digit_1; cb_resp.uli.sai2.sai_mnc_digit_3 = context->uli.sai2.sai_mnc_digit_3; cb_resp.uli.sai2.sai_mcc_digit_3 = context->uli.sai2.sai_mcc_digit_3; cb_resp.uli.sai2.sai_mnc_digit_2 = context->uli.sai2.sai_mnc_digit_2; cb_resp.uli.sai2.sai_mnc_digit_1 = context->uli.sai2.sai_mnc_digit_1; cb_resp.uli.sai2.sai_lac = context->uli.sai2.sai_lac; cb_resp.uli.sai2.sai_sac = context->uli.sai2.sai_sac; len += sizeof(cb_resp.uli.sai2); } if (context->uli.cgi) { cb_resp.uli.cgi = context->uli.cgi; cb_resp.uli.cgi2.cgi_mcc_digit_2 = context->uli.cgi2.cgi_mcc_digit_2; cb_resp.uli.cgi2.cgi_mcc_digit_1 = context->uli.cgi2.cgi_mcc_digit_1; cb_resp.uli.cgi2.cgi_mnc_digit_3 = context->uli.cgi2.cgi_mnc_digit_3; cb_resp.uli.cgi2.cgi_mcc_digit_3 = context->uli.cgi2.cgi_mcc_digit_3; cb_resp.uli.cgi2.cgi_mnc_digit_2 = context->uli.cgi2.cgi_mnc_digit_2; cb_resp.uli.cgi2.cgi_mnc_digit_1 = context->uli.cgi2.cgi_mnc_digit_1; cb_resp.uli.cgi2.cgi_lac = context->uli.cgi2.cgi_lac; cb_resp.uli.cgi2.cgi_ci = context->uli.cgi2.cgi_ci; len += sizeof(cb_resp.uli.cgi2); } if (context->uli.ecgi) { cb_resp.uli.ecgi = context->uli.ecgi; cb_resp.uli.ecgi2.ecgi_mcc_digit_2 = context->uli.ecgi2.ecgi_mcc_digit_2; cb_resp.uli.ecgi2.ecgi_mcc_digit_1 = context->uli.ecgi2.ecgi_mcc_digit_1; cb_resp.uli.ecgi2.ecgi_mnc_digit_3 = context->uli.ecgi2.ecgi_mnc_digit_3; cb_resp.uli.ecgi2.ecgi_mcc_digit_3 = context->uli.ecgi2.ecgi_mcc_digit_3; cb_resp.uli.ecgi2.ecgi_mnc_digit_2 = context->uli.ecgi2.ecgi_mnc_digit_2; cb_resp.uli.ecgi2.ecgi_mnc_digit_1 = context->uli.ecgi2.ecgi_mnc_digit_1; cb_resp.uli.ecgi2.ecgi_spare = context->uli.ecgi2.ecgi_spare; cb_resp.uli.ecgi2.eci = context->uli.ecgi2.eci; len += sizeof(cb_resp.uli.ecgi2); } if (context->uli.macro_enodeb_id) { cb_resp.uli.macro_enodeb_id = context->uli.macro_enodeb_id; cb_resp.uli.macro_enodeb_id2.menbid_mcc_digit_2 = context->uli.macro_enodeb_id2.menbid_mcc_digit_2; cb_resp.uli.macro_enodeb_id2.menbid_mcc_digit_1 = context->uli.macro_enodeb_id2.menbid_mcc_digit_1; cb_resp.uli.macro_enodeb_id2.menbid_mnc_digit_3 = context->uli.macro_enodeb_id2.menbid_mnc_digit_3; cb_resp.uli.macro_enodeb_id2.menbid_mcc_digit_3 = context->uli.macro_enodeb_id2.menbid_mcc_digit_3; cb_resp.uli.macro_enodeb_id2.menbid_mnc_digit_2 = context->uli.macro_enodeb_id2.menbid_mnc_digit_2; cb_resp.uli.macro_enodeb_id2.menbid_mnc_digit_1 = context->uli.macro_enodeb_id2.menbid_mnc_digit_1; cb_resp.uli.macro_enodeb_id2.menbid_spare = context->uli.macro_enodeb_id2.menbid_spare; cb_resp.uli.macro_enodeb_id2.menbid_macro_enodeb_id = context->uli.macro_enodeb_id2.menbid_macro_enodeb_id; cb_resp.uli.macro_enodeb_id2.menbid_macro_enb_id2 = context->uli.macro_enodeb_id2.menbid_macro_enb_id2; len += sizeof(cb_resp.uli.macro_enodeb_id2); } if (context->uli.extnded_macro_enb_id) { cb_resp.uli.extnded_macro_enb_id = context->uli.extnded_macro_enb_id; cb_resp.uli.extended_macro_enodeb_id2.emenbid_mcc_digit_1 = context->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_1; cb_resp.uli.extended_macro_enodeb_id2.emenbid_mnc_digit_3 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_3; cb_resp.uli.extended_macro_enodeb_id2.emenbid_mcc_digit_3 = context->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_3; cb_resp.uli.extended_macro_enodeb_id2.emenbid_mnc_digit_2 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_2; cb_resp.uli.extended_macro_enodeb_id2.emenbid_mnc_digit_1 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_1; cb_resp.uli.extended_macro_enodeb_id2.emenbid_smenb = context->uli.extended_macro_enodeb_id2.emenbid_smenb; cb_resp.uli.extended_macro_enodeb_id2.emenbid_spare = context->uli.extended_macro_enodeb_id2.emenbid_spare; cb_resp.uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id = context->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id; cb_resp.uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2 = context->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2; len += sizeof(cb_resp.uli.extended_macro_enodeb_id2); } len += 1; set_ie_header(&cb_resp.uli.header, GTP_IE_USER_LOC_INFO, IE_INSTANCE_ZERO, len); } if(context->pra_flag){ set_presence_reporting_area_info_ie(&cb_resp.pres_rptng_area_info, context); context->pra_flag = 0; } cb_resp.bearer_cnt = resp->bearer_count; encode_create_bearer_rsp(&cb_resp, (uint8_t *)gtpv2c_tx); return 0; } /** * @brief : When a bearer resource command is received for some UE Context/PDN connection * with a traffic aggregation description requesting the installation of some * packet filters, we create a dedicated bearer using those filters. Here, we * are bypassing any PCRF interaction and relying on static rules * @param : gtpv2c_rx * gtpv2c message buffer containing bearer resource command message * @param : gtpv2c_tx * gtpv2c message transmission buffer to contain transmit 'create bearer * request' message * @param : brc * bearer resource command parsed data * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ static int create_dedicated_bearer(gtpv2c_header_t *gtpv2c_rx, gtpv2c_header_t *gtpv2c_tx, struct parse_bearer_resource_command_t *brc) { flow_qos_ie *fqos; eps_bearer *ded_bearer; if (brc->context->ded_bearer != NULL) return -EPERM; if (brc->flow_quality_of_service == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Received Bearer Resource Command without Flow " "QoS IE\n", LOG_VALUE); return -EPERM; } fqos = IE_TYPE_PTR_FROM_GTPV2C_IE(flow_qos_ie, brc->flow_quality_of_service); ded_bearer = brc->context->ded_bearer = rte_zmalloc_socket(NULL, sizeof(eps_bearer), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (ded_bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "Memory for Bearer, Error: %s \n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ded_bearer->pdn = brc->pdn; if (install_packet_filters(ded_bearer, brc->tad)) return -EPERM; ded_bearer->s1u_sgw_gtpu_teid = get_s1u_sgw_gtpu_teid(ded_bearer->pdn->upf_ip, ded_bearer->pdn->context->cp_mode, &upf_teid_info_head); /* TODO: Need to handle when providing dedicate beare feature */ /* ded_bearer->s1u_sgw_gtpu_ipv4 = s1u_sgw_ip; */ ded_bearer->pdn = brc->pdn; /* VS: Remove memcpy */ //memcpy(&ded_bearer->qos.qos, &fqos->qos, sizeof(qos_segment)); /** * IE specific data segment for Quality of Service (QoS). * * Definition used by bearer_qos_ie and flow_qos_ie. */ ded_bearer->qos.qci = fqos->qos.qci; ded_bearer->qos.ul_mbr = fqos->qos.ul_mbr; ded_bearer->qos.dl_mbr = fqos->qos.dl_mbr; ded_bearer->qos.ul_gbr = fqos->qos.ul_gbr; ded_bearer->qos.dl_gbr = fqos->qos.dl_gbr; /* default values - to be considered later */ ded_bearer->qos.arp.preemption_capability = BEARER_QOS_IE_PREMPTION_DISABLED; ded_bearer->qos.arp.preemption_vulnerability = BEARER_QOS_IE_PREMPTION_ENABLED; ded_bearer->qos.arp.priority_level = DEFAULT_BEARER_QOS_PRIORITY; set_create_bearer_request(gtpv2c_tx, gtpv2c_rx->teid.has_teid.seq, brc->pdn, IE_TYPE_PTR_FROM_GTPV2C_IE(eps_bearer_id_ie, brc->linked_eps_bearer_id)->ebi, *IE_TYPE_PTR_FROM_GTPV2C_IE(uint8_t, brc->procedure_transaction_id), NULL, 0, FALSE); return 0; } /** * @brief : When a bearer resource command is received for some UE Context/PDN connection * with a traffic aggregation description requesting the removal of some * packet filters, we check if all filters are removed from the dedicated bearer * and if so, request the deletion of that bearer * @param : gtpv2c_rx * gtpv2c message buffer containing bearer resource command message * @param : gtpv2c_tx * gtpv2c message transmission buffer to contain transmit 'delete bearer * request' message * @param : brc * bearer resource command parsed data * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ static int delete_packet_filter(gtpv2c_header_t *gtpv2c_rx, gtpv2c_header_t *gtpv2c_tx, struct parse_bearer_resource_command_t *brc) { uint8_t filter_index; delete_pkt_filter *dpf = (delete_pkt_filter *) &brc->tad[1]; eps_bearer *b = brc->pdn->packet_filter_map[dpf->pkt_filter_id]; if (b == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Requesting the deletion of non-existent " "packet filter\n", LOG_VALUE); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"\t" "%"PRIx32"\t" "%"PRIx32"\n", LOG_VALUE, brc->context->s11_mme_gtpc_teid, brc->context->s11_sgw_gtpc_teid); return -ENOENT; } for (filter_index = 0; filter_index < brc->tad->num_pkt_filters; ++filter_index) { b->packet_filter_map[dpf->pkt_filter_id] = -ENOENT; brc->pdn->packet_filter_map[dpf->pkt_filter_id] = NULL; b->num_packet_filters--; } if (b->num_packet_filters == 0) { /* we delete this bearer */ set_gtpv2c_teid_header(gtpv2c_tx, GTP_DELETE_BEARER_REQ, brc->context->s11_mme_gtpc_teid, gtpv2c_rx->teid.has_teid.seq, 0); set_ebi_ie(gtpv2c_tx, IE_INSTANCE_ONE, b->eps_bearer_id); set_pti_ie(gtpv2c_tx, IE_INSTANCE_ZERO, *IE_TYPE_PTR_FROM_GTPV2C_IE(uint8_t, brc->procedure_transaction_id)); } else { /* TODO: update DP with modified packet filters */ } return 0; } int process_bearer_resource_command(gtpv2c_header_t *gtpv2c_rx, gtpv2c_header_t *gtpv2c_tx) { int ret; struct parse_bearer_resource_command_t bearer_resource_command = {0}; ret = parse_bearer_resource_cmd(gtpv2c_rx, &bearer_resource_command); if (ret) return ret; /* Bearer Resource Commands are supported to allow for UE requested * bearer resource modification procedure as defined by 3gpp 23.401 * cause 5.4.5. * Currently this command initiates either Dedicated Bearer Activation * or De-activation procedures according to the Traffic Aggregation * Description operation code */ if (bearer_resource_command.tad->tft_op_code == TFT_OP_CREATE_NEW) { return create_dedicated_bearer(gtpv2c_rx, gtpv2c_tx, &bearer_resource_command); } else if (bearer_resource_command.tad->tft_op_code == TFT_OP_DELETE_FILTER_EXISTING) { return delete_packet_filter(gtpv2c_rx, gtpv2c_tx, &bearer_resource_command); } else { return -EPERM; } }
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/csid_struct.h
<gh_stars>0 /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _CSID_STRUCT_H #define _CSID_STRUCT_H #include "pfcp_messages.h" #include "interface.h" #include "pfcp_struct.h" #ifdef CP_BUILD #include "gtp_ies.h" #endif /*CP_BUILD*/ #define ADD_NODE 0 #define UPDATE_NODE 1 #define REMOVE_NODE 2 /* Maximum possibility of the CSID per PDN connection */ #define MAX_CSID 15 /* Temp using this static value, later on need to implement linked list */ #define MAX_SESS_IDS 500 /** * @brief : * rte hash for local csid by peer node information data. * hash key: peer_node_info, data: CSID * Usage: * 1) SGW-C/U : Retrieve the local csids based on the peer nodes * 2) PGW-C/U : Retrieve the local csids based on the peer nodes */ struct rte_hash *csid_by_peer_node_hash; /** * @brief : * rte hash for collection of peer node CSIDs by local CSID. * hash key: Local CSID, data: Peer node CSIDs */ struct rte_hash *peer_csids_by_csid_hash; /** * @brief : * rte hash for session ids of CP/DP by local CSID. * hash key: csid, data: Session ids */ struct rte_hash *seids_by_csid_hash; /** * @brief : Interface mapping tables * rte hash for collection of local csids by peer mme node address. * hash key: Node IP, data: Local CSIDs */ struct rte_hash *local_csids_by_node_addr_hash; /** * @brief : * rte hash for collection of local csids by mme CSID. * hash key: MME CSID, data: Local CSIDs */ struct rte_hash *local_csids_by_mmecsid_hash; /** * @brief : * rte hash for collection of local csids by pgw CSID. * hash key: PGW CSID, data: Local CSIDs */ struct rte_hash *local_csids_by_pgwcsid_hash; /** * @brief : * rte hash for collection of local csids by sgw CSID * hash key: SGW CSID, data: Local CSIDs */ struct rte_hash *local_csids_by_sgwcsid_hash; /** * @brief : * rte hash for collection of session CP DP seid. * hash key: PEER CSID, PEER NODE IP, IFACE ID, * data: Session seid */ struct rte_hash *seid_by_peer_csid_hash; /** * @brief : * rte hash for collection of fqcsid ie Node address. * hash key: PEER NODE IP, IFACE ID, * data: Node address */ struct rte_hash *peer_node_addr_by_peer_fqcsid_node_addr_hash; /** * @brief : check ip address is present. * @param : node, * @return : Returns nothing */ int8_t is_present(node_address_t *node); /** * @brief : fill peer node address is. * @param : dst_info, * @param : src_info, * @return : Returns nothing */ void fill_peer_info(node_address_t *dst_info, node_address_t *src_info); #ifdef CP_BUILD #define COMPARE_IP_ADDRESS(src, dst) \ (((dst.ip_type == IPV4_GLOBAL_UNICAST) || (dst.ip_type == PDN_TYPE_IPV4)) ? \ (memcmp(&(dst.ipv4_addr), &(src.ipv4_addr), IPV4_SIZE)) : \ (memcmp(&(dst.ipv6_addr), &(src.ipv6_addr), IPV6_SIZE))) \ /** * @brief : Collection of the associated peer node informations */ struct peer_node_info_t { /* MME IP Address */ node_address_t mme_ip; /* S11 || Sx || S5/S8 IP Address */ node_address_t sgwc_ip; /* eNB || Sx || S5/S8 IP Address */ node_address_t sgwu_ip; /* Sx || S5/S8 IP Address */ node_address_t pgwc_ip; /* Sx || S5/S8 IP Address */ node_address_t pgwu_ip; /* eNB Address */ node_address_t enodeb_ip; /* Optional for CP */ }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); typedef struct peer_node_info_t csid_key; #else /** * @brief : Collection of the associated peer node informations */ struct peer_node_info_t { /* S11 || Sx || S5/S8 IP Address */ node_address_t cp_ip; /* eNB || Sx || S5/S8 IP Address */ node_address_t up_ip; /* eNB/SGWU Address*/ node_address_t wb_peer_ip; /* PGWU Address*/ node_address_t eb_peer_ip; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); typedef struct peer_node_info_t csid_key; #endif /* CP_BUILD */ /** * @brief : Collection of the associated peer node CSIDs */ typedef struct fq_csid_info { /* MME PDN connection set identifer */ uint16_t mme_csid[MAX_CSID]; /* SGWC/SAEGWC PDN connection set identifer */ uint16_t sgwc_csid[MAX_CSID]; /* SGWU/SAEGWU PDN connection set identifer */ uint16_t sgwu_csid[MAX_CSID]; /* PGWC PDN connection set identifer */ uint16_t pgwc_csid[MAX_CSID]; /* PGWU PDN connection set identifer */ uint16_t pgwu_csid[MAX_CSID]; }fq_csids; /** * @brief : Collection of the associated session ids informations with csid */ typedef struct sess_csid_info { /* Control-Plane session identifiers */ uint64_t cp_seid; /* User-Plane session identifiers */ uint64_t up_seid; /* Pointing to next seid linked list node */ struct sess_csid_info *next; }sess_csid; /** * @brief : Assigned the local csid */ struct csid_info { uint8_t num_csid; /* SGWC, SAEGWC, SGWU, SAEGWU, PGWC, and PGWU local csid */ uint16_t local_csid[MAX_CSID]; /* SGWC, PGWC and MME IP Address */ node_address_t node_addr; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); typedef struct csid_info csid_t; /** * @brief : Key the local csid */ struct csid_info_t { /* SGWC, PGWC and MME IP Address */ node_address_t node_addr; /* SGWC, SAEGWC, SGWU, SAEGWU, PGWC, and PGWU local csid */ uint16_t local_csid; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); typedef struct csid_info_t csid_key_t; /** * @brief : Key the peer CSID */ struct peer_csid_info { /* Local node interface */ uint8_t iface; /* SGWC, SAEGWC, SGWU, SAEGWU, PGWC, and PGWU local csid */ uint16_t peer_local_csid; /* SGWC, PGWC and MME, UP IP Address */ node_address_t peer_node_addr; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); typedef struct peer_csid_info peer_csid_key_t; /** * @brief : Key for the peer Node address */ struct peer_node_addr_info { /* Local node Interface */ uint8_t iface; /* SGWC, PGWC and MME, UP IP Address */ node_address_t peer_node_addr; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); typedef struct peer_node_addr_info peer_node_addr_key_t; /** * @brief : Structure for node address. */ struct fqcsid_ie_node_addr_info { node_address_t fqcsid_node_addr; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); typedef struct fqcsid_ie_node_addr_info fqcsid_ie_node_addr_t; /** * @brief : FQ-CSID structure */ typedef struct fqcsid_info_t { uint8_t instance; uint8_t num_csid; /* SGWC and MME csid */ uint16_t local_csid[MAX_CSID]; /* SGWC and MME IP Address */ node_address_t node_addr; }fqcsid_t; /** * @brief : FQ-CSID structure */ typedef struct sess_fqcsid_info_t { uint8_t instance; uint8_t num_csid; /* SGWC and MME csid */ uint16_t local_csid[MAX_CSID]; /* SGWC and MME IP Address */ node_address_t node_addr[MAX_CSID]; }sess_fqcsid_t; typedef struct node_addr_info { uint8_t num_addr; node_address_t node_addr[MAX_CSID]; } node_addr_t; /** * @brief : Init the hash tables for FQ-CSIDs \ */ int8_t init_fqcsid_hash_tables(void); /********[ Hash table API's ]**********/ /********[ csid_by_peer_node_hash ]*********/ /** * @brief : Add csid entry in csid hash table. * @param : struct peer_node_info csid_key. * @param : csid * @return : Returns 0 on success , 1 otherwise. */ int8_t add_csid_entry(csid_key *key, uint16_t csid); /** * @brief : Get csid entry from csid hash table. * @param : struct peer_node_info csid_key * @return : Returns csid on success , -1 otherwise. */ int16_t get_csid_entry(csid_key *key); /** * @brief : Update csid key associated peer node with csid in csid hash table. * @param : struct peer_node_info csid_key * @param : struct peer_node_info csid_key * @return : Returns 0 on success , 1 otherwise. */ int16_t update_csid_entry(csid_key *old_key, csid_key *new_key); #ifdef CP_BUILD /* Linked the Peer CSID with local CSID */ int8_t link_gtpc_peer_csids(fqcsid_t *peer_fqcsid, fqcsid_t *local_fqcsid, uint8_t iface); /** * @brief : Fills pfcp sess set delete request for cp * @param : pfcp_sess_set_del_req , structure to be filled * @param : local_csids * @return : Returns nothing */ void cp_fill_pfcp_sess_set_del_req_t(pfcp_sess_set_del_req_t *pfcp_sess_set_del_req, fqcsid_t *local_csids); /** * @brief : Process session establishment respone * @param : fqcsid, fqcsid to be filled in context * @param : context_fqcsid, fqcsid pointer of context structure * @return : Returns 0 on success, -1 otherwise */ int add_fqcsid_entry(gtp_fqcsid_ie_t *fqcsid, sess_fqcsid_t *context_fqcsid); /** * @brief : Compare the peer node information with exsting peer node entry. * @param : struct peer_node_info peer1 * @param : struct peer_node_info peer * @return : Returns 0 on success , -1 otherwise. */ int8_t compare_peer_info(csid_key *peer1, csid_key *peer2); #else /** * @brief : Linked Peer Csid With Local Csid * @param : Peer CSID * @param : Local CSID * @param : iface * @return : Returns 0 on success, -1 otherwise */ int8_t link_peer_csid_with_local_csid(fqcsid_t *peer_fqcsid, fqcsid_t *local_fqcsid, uint8_t iface); /** * @brief : Linked Peer Csid With Local Csid * @param : Peer CSID * @param : Local Memory location to stored CSID * @return : Returns 0 on success, -1 otherwise */ int8_t stored_recvd_peer_fqcsid(pfcp_fqcsid_ie_t *peer_fqcsid, fqcsid_t *local_fqcsid); #endif /* CP_BUILD */ /** * @brief : Delete csid entry from csid hash table. * @param : struct peer_node_info csid_key * @return : Returns 0 on success , 1 otherwise. */ int8_t del_csid_entry(csid_key *key); /********[ peer_csids_by_csid_hash ]*********/ /** * @brief : Add peer node csids entry in peer node csids hash table. * @param : local_csid * @param : struct fq_csid_info fq_csids * @return : Returns 0 on success , 1 otherwise. */ int8_t add_peer_csids_entry(uint16_t csid, fq_csids *csids); /** * @brief : Get peer node csids entry from peer node csids hash table. * @param : local_csid * @return : Returns fq_csids on success , NULL otherwise. */ fq_csids* get_peer_csids_entry(uint16_t csid); /** * @brief : Delete peer node csid entry from peer node csid hash table. * @param : struct peer_node_info csid_key * @return : Returns 0 on success , 1 otherwise. */ int8_t del_peer_csids_entry(uint16_t csid); /********[ seids_by_csid_hash ]*********/ /** * @brief : Add session ids entry in sess csid hash table. * @param : csid * @param : struct sess_csid_info sess_csid * @return : Returns 0 on success , 1 otherwise. */ int8_t add_sess_csid_entry(uint16_t csid, sess_csid *seids); /** * @brief : Get session ids entry from sess csid hash table. * @param : local_csid * @param : mode [add , update , remove ] * @return : Returns sess_csid on success , NULL otherwise. */ sess_csid* get_sess_csid_entry(uint16_t csid, uint8_t is_mod); /** * @brief : Delete session ids entry from sess csid hash table. * @param : local_csid * @return : Returns 0 on success , 1 otherwise. */ int8_t del_sess_csid_entry(uint16_t csid); /** * @brief : Add local csid entry by peer csid in peer csid hash table. * @param : csid_t peer_csid_key * @param : csid_t local_csid * @param : ifce S11/Sx/S5S8 * @return : Returns 0 on success , 1 otherwise. */ int8_t add_peer_csid_entry(csid_key_t *key, csid_t *csid, uint8_t iface); /** * @brief : Get local csid entry by peer csid from csid hash table. * @param : csid_t csid_key * @param : iface * @return : Returns 0 on success , -1 otherwise. */ csid_t* get_peer_csid_entry(csid_key_t *key, uint8_t iface, uint8_t is_mode); /** * @brief : Delete local csid entry by peer csid from csid hash table. * @param : csid_t csid_key * @param : iface * @return : Returns 0 on success , 1 otherwise. */ int8_t del_peer_csid_entry(csid_key_t *key, uint8_t iface); /** * @brief : Add peer node csids entry by peer node address in peer node csids hash table. * @param : node address * @param : fqcsid_t csids * @param : iface * @return : Returns 0 on success , 1 otherwise. */ int8_t add_peer_addr_csids_entry(uint32_t node_addr, fqcsid_t *csids); /** * @brief : Get peer node csids entry by peer node addr from peer node csids hash table. * @param : node address * @return : Returns fqcsid_t on success , NULL otherwise. */ fqcsid_t* get_peer_addr_csids_entry(node_address_t *node_addr, uint8_t is_mod); /** * @brief : Delete peer node csid entry by peer node addr from peer node csid hash table. * @param : node_address * @return : Returns 0 on success , 1 otherwise. */ int8_t del_peer_addr_csids_entry(node_address_t *node_addr); /** * @brief : In partial failure support initiate the Request to cleanup peer node sessions based on FQ-CSID * @param : No param * @return : Returns 0 on success , -1 otherwise. */ int8_t gen_gtpc_sess_deletion_req(void); /** * @brief : In partial failure support initiate the Request to cleanup peer node sessions based on FQ-CSID * @param : No param * @return : Returns 0 on success , -1 otherwise. */ int8_t gen_pfcp_sess_deletion_req(void); /** * @brief : Fills pfcp sess set delete request * @param : pfcp_sess_set_del_req , structure to be filled * @param : local_csids * @param : iface * @return : Returns nothing */ void fill_pfcp_sess_set_del_req_t(pfcp_sess_set_del_req_t *pfcp_sess_set_del_req, fqcsid_t *local_csids, uint8_t iface); /** * @brief : Create and Fill the FQ-CSIDs * @param : fq_csid, structure to be filled * @param : csids * @return : Returns nothing */ void set_fq_csid_t(pfcp_fqcsid_ie_t *fq_csid, fqcsid_t *csids); /** * @brief : Fill pfcp set deletion response * @param : pfcp_del_resp, structure to be filled * @param : Cause value * @param : offending_id * @return : Returns nothing */ void fill_pfcp_sess_set_del_resp(pfcp_sess_set_del_rsp_t *pfcp_del_resp, uint8_t cause_val, int offending_id); /** * @brief : Delete entry for csid * @param : peer_csids * @param : local_csids * @param : iface * @return : Returns 0 on success, -1 otherwise */ int8_t del_csid_entry_hash(fqcsid_t *peer_csids, fqcsid_t *local_csids, uint8_t iface); /* recovery function */ /** * @brief : Function to re-create affected session with peer node * @param : node_addr , node address * @param : iface * @return : Returns 0 on success, -1 otherwise */ int create_peer_node_sess(node_address_t *node_addr, uint8_t iface); /** * @brief : Process association setup request * @param : node_addr, node address * @return : Returns 0 on success, -1 otherwise */ int process_aasociation_setup_req(peer_addr_t *peer_addr); /** * @brief : Process association setup response * @param : msg * @param : peer_addr * @return : Returns 0 on success, -1 otherwise */ int process_asso_resp(void *msg, peer_addr_t *peer_addr); /** * @brief : Process session establishment respone * @param : pfcp_sess_est_rsp * @return : Returns 0 on success, -1 otherwise */ int process_sess_est_resp(pfcp_sess_estab_rsp_t *pfcp_sess_est_rsp); /** * @brief : Get session ids entry from sess csid hash table. * @param : key, hash key * @param : mode [add , update , remove ] * @return : Returns sess_csid on success , NULL otherwise. */ sess_csid* get_sess_peer_csid_entry(peer_csid_key_t *key, uint8_t is_mod); /** * @brief : Delete session ids entry from sess csid hash table. * @param : key , hash key * @return : Returns 0 on success , 1 otherwise. */ int8_t del_sess_peer_csid_entry(peer_csid_key_t *key); /** * @brief : Get Peer node address entry from peer node addr hash table. * @param : key, hash key * @param : mode [add , update , remove ] * @return : Returns sess_csid on success , NULL otherwise. */ fqcsid_ie_node_addr_t* get_peer_node_addr_entry(peer_node_addr_key_t *key, uint8_t is_mod); /** * @brief : Delete peer node addr entry from peer node addr hash table. * @param : key. hash key * @return : Returns 0 on success , 1 otherwise. */ int8_t del_peer_node_addr_entry(peer_node_addr_key_t *key); #if CP_BUILD /** * @brief : Add FQCSID IE node address into peer node address hash * @param : peer node addr, Source Node of peer node destination address. * @param : fqcsid_t, * @param : iface, * @return : Returns 0 in case of success, cause value otherwise. */ int8_t add_peer_addr_entry_for_fqcsid_ie_node_addr(node_address_t *peer_node_addr, gtp_fqcsid_ie_t *fqcsid, uint8_t iface); #else /** * @brief : Add FQCSID IE node address into peer node address hash * @param : peer node addr, Source Node of peer node destination address. * @param : fqcsid_t, * @param : iface, * @return : Returns 0 in case of success, cause value otherwise. */ int8_t add_peer_addr_entry_for_fqcsid_ie_node_addr(node_address_t *peer_node_addr, pfcp_fqcsid_ie_t *fqcsid, uint8_t iface); #endif /** * @brief : fill node address info * @param : dst_info, Source Node of peer node destination address. * @param : src_info, * @return : Returns void. */ void fill_node_addr_info(node_address_t *dst_info, node_address_t *src_info); #endif /* _CSID_STRUCT_H */
nikhilc149/e-utran-features-bug-fixes
dp/util.c
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <arpa/inet.h> #include <rte_ip.h> #include "util.h" #include "ipv4.h" #include "ipv6.h" void construct_udp_hdr(struct rte_mbuf *m, uint16_t len, uint16_t sport, uint16_t dport, uint8_t ip_type) { struct udp_hdr *udp_hdr; /* IF IP_TYPE = 1 i.e IPv6 , 0: IPv4*/ if (ip_type) { udp_hdr = get_mtoudp_v6(m); } else { udp_hdr = get_mtoudp(m); } udp_hdr->src_port = htons(sport); udp_hdr->dst_port = htons(dport); udp_hdr->dgram_len = htons(len); /* update Udp checksum */ udp_hdr->dgram_cksum = 0; if (ip_type) { struct ipv6_hdr *ipv6_hdr; ipv6_hdr = get_mtoip_v6(m); udp_hdr->dgram_cksum = rte_ipv6_udptcp_cksum(ipv6_hdr, udp_hdr); } else { struct ipv4_hdr *ipv4_hdr; ipv4_hdr = get_mtoip(m); udp_hdr->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr); } }
nikhilc149/e-utran-features-bug-fixes
cp_dp_api/ngic_timer.h
<gh_stars>0 /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __GSTIMER_H #define __GSTIMER_H #include <stdint.h> #include <stdbool.h> #include <pthread.h> #ifdef DP_BUILD #include <rte_ethdev.h> #endif #include "interface.h" #include "pfcp_struct.h" #define S11_SGW_PORT_ID 0 #define S5S8_SGWC_PORT_ID 1 #define SX_PORT_ID 2 #define S5S8_PGWC_PORT_ID 3 #define OFFSET 2208988800ULL #define PFCP_MSG_LEN 4096 /** * @brief : Numeric value for true and false */ typedef enum { False = 0, True } boolean; /** * @brief : Maintains timer related information */ typedef struct _gstimerinfo_t gstimerinfo_t; /** * @brief : function pointer to timer callback */ typedef void (*gstimercallback)(gstimerinfo_t *ti, const void *data); /** * @brief : Maintains timer type */ typedef enum { ttSingleShot, ttInterval } gstimertype_t; /** * @brief : Maintains timer related information */ struct _gstimerinfo_t { timer_t ti_id; gstimertype_t ti_type; gstimercallback ti_cb; int ti_ms; const void *ti_data; }; #ifdef CP_BUILD /** * @brief : Maintains peer node related information for control plane */ typedef struct { uint8_t cp_mode; /** S11 || S5/S8 || Sx port id */ uint8_t portId; /** In-activity Flag */ uint8_t activityFlag; /** Number of Iteration */ uint8_t itr; /** Iteration Counter */ uint8_t itr_cnt; /** Dst Addr */ node_address_t dstIP; /* Dst port */ uint16_t dstPort; /** Recovery Time */ uint32_t rcv_time; /** Periodic Timer */ gstimerinfo_t pt; /** Transmit Timer */ gstimerinfo_t tt; const char *name; /* Teid */ uint32_t teid; /*ebi ID */ int ebi_index; uint16_t buf_len; uint8_t buf[PFCP_MSG_LEN]; uint64_t imsi; } peerData; #else /** * @brief : Maintains peer node related information for data plane */ typedef struct { /** UL || DL || Sx port id */ uint8_t portId; /** In-activity Flag */ uint8_t activityFlag; /** Number of Iteration */ uint8_t itr; /** Iteration Counter */ uint8_t itr_cnt; /** GTP-U response Counter */ uint32_t rstCnt; /** src ipv4 address */ node_address_t srcIP; /** dst ipv4 address */ node_address_t dstIP; /** Recovery Time */ uint32_t rcv_time; /** src ether address */ struct ether_addr src_eth_addr; /** dst ether address */ struct ether_addr dst_eth_addr; /** Periodic Timer */ gstimerinfo_t pt; /** Transmit Timer */ gstimerinfo_t tt; /** Name String */ const char *name; //struct rte_mbuf *buf; /*urr_info */ struct urr_info_t *urr; uint64_t cp_seid; } peerData; #endif /* Configured start/up time of component */ /* extern uint32_t up_time; uint32_t current_ntp_timestamp(void); */ #ifdef DP_BUILD /** * @brief : Maintains data for peer node */ typedef struct { /** src ipv4 address */ uint32_t srcIP; /** dst ipv4 address */ uint32_t dstIP; /** Recovery Time */ uint32_t rcv_time; /** src ether address */ struct ether_addr src_eth_addr; /** dst ether address */ struct ether_addr dst_eth_addr; /** Periodic Timer */ gstimerinfo_t pt; /** Transmit Timer */ gstimerinfo_t tt; /** Name String */ const char *name; //struct rte_mbuf *buf; /*urr_info */ struct urr_info_t *urr; uint64_t cp_seid; uint64_t up_seid; } peerEntry; #endif /** * @brief : start the timer thread and wait for _timer_tid to be populated * @param : No param * @return : Returns true in case of success , false otherwise */ bool gst_init(void); /** * @brief : Stop the timer handler thread * @param : No param * @return : Returns nothing */ void gst_deinit(void); /** * @brief : Initialize timer with provided information * @param : ti, timer structure to be initialized * @param : cb, timer callback function * @param : milliseconds, timeout in milliseconds * @param : data, timer data * @return : Returns true in case of success , false otherwise */ bool gst_timer_init( gstimerinfo_t *ti, gstimertype_t tt, gstimercallback cb, int milliseconds, const void *data ); /** * @brief : Delete timer * @param : ti, holds information about timer to be deleted * @return : Returns nothing */ void gst_timer_deinit( gstimerinfo_t *ti ); /** * @brief : Set timeout in timer * @param : ti, holds information about timer * @param : milliseconds, timeout in milliseconds * @return : Returns true in case of success , false otherwise */ bool gst_timer_setduration( gstimerinfo_t *ti, int milliseconds ); /** * @brief : Start timer * @param : ti, holds information about timer * @return : Returns true in case of success , false otherwise */ bool gst_timer_start( gstimerinfo_t *ti ); /** * @brief : Stop timer * @param : ti, holds information about timer * @return : Returns nothing */ void gst_timer_stop( gstimerinfo_t *ti ); /** * @brief : Intialize peer node information * @param : md, Peer node information * @param : name, Peer node name * @param : t1ms, periodic timer interval * @param : t2ms, transmit timer interval * @return : Returns true in case of success , false otherwise */ bool initpeerData( peerData *md, const char *name, int t1ms, int t2ms ); /** * @brief : Start timer * @param : ti, holds information about timer * @return : Returns true in case of success , false otherwise */ bool startTimer( gstimerinfo_t *ti ); /** * @brief : Stop timer * @param : ti, holds information about timer * @return : Returns nothing */ void stopTimer( gstimerinfo_t *ti ); /** * @brief : Delete timer * @param : ti, holds information about timer * @return : Returns nothing */ void deinitTimer( gstimerinfo_t *ti ); /** * @brief : Delay calling process for a given amount of time * @param : seconds, timer interval * @return : Returns nothing */ void _sleep( int seconds ); /** * @brief : Timer callback * @param : ti, holds information about timer * @param : data_t, Peer node related information * @return : Returns nothing */ void timerCallback( gstimerinfo_t *ti, const void *data_t ); /** * @brief : Delete entry from connection table * @param : ipAddr, key to search entry to be deleted * @return : Returns nothing */ void del_entry_from_hash(node_address_t *ipAddr); /** * @brief : Convert time into printable format * @param : No param * @return : Returns nothing */ const char *getPrintableTime(void); /** * @brief : Reset the periodic timers * @param : dstIp, Peer node ip address * @return : Returns nothing */ uint8_t process_response(node_address_t *dstIp); /** * @brief : Add entry for recovery time into heartbeat recovery file * @param : recov_time, recovery time * @return : Returns nothing */ void recovery_time_into_file(uint32_t recov_time); /** * @brief : Initialize timer * @param : md, Peer node information * @param : t1ms, periodic timer interval * @param : cb, timer callback function * @return : Returns true in case of success , false otherwise */ bool init_timer(peerData *md, int ptms, gstimercallback cb); /** * @brief : Start timer * @param : ti, holds information about timer * @return : Returns true in case of success , false otherwise */ bool starttimer( gstimerinfo_t *ti ); /** * @brief : Stop timer * @param : tid, timer id * @return : Returns nothing */ void stoptimer(timer_t *tid); /** * @brief : Delete timer * @param : tid, timer id * @return : Returns nothing */ void deinittimer(timer_t *tid); #endif
nikhilc149/e-utran-features-bug-fixes
cp/cp.c
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <getopt.h> #include <rte_ip.h> #include <rte_udp.h> #include <rte_cfgfile.h> #include "cp.h" #include "cp_stats.h" #include "cp_config.h" #include "debug_str.h" #include "dp_ipc_api.h" #include "pfcp_util.h" #include "pfcp_set_ie.h" #include "pfcp_session.h" #include "pfcp_association.h" #include "pfcp_messages_decoder.h" #include "pfcp_messages_encoder.h" #include "sm_arr.h" #include "sm_pcnd.h" #include "sm_struct.h" #ifdef USE_REST #include "ngic_timer.h" #endif /* USE_REST */ #include "cdnshelper.h" extern int s11_fd; extern int s11_fd_v6; extern socklen_t s11_mme_sockaddr_len; extern socklen_t s11_mme_sockaddr_ipv6_len; extern pfcp_config_t config; extern peer_addr_t s11_mme_sockaddr; extern int clSystemLog; uint32_t start_time; extern struct rte_hash *conn_hash_handle; /* S5S8 */ extern int s5s8_fd; extern int s5s8_fd_v6; struct peer_addr_t s5s8_recv_sockaddr; extern socklen_t s5s8_sockaddr_len; extern socklen_t s5s8_sockaddr_ipv6_len; struct cp_params cp_params; extern struct cp_stats_t cp_stats; uint16_t payload_length; /*teid_info list pointer for upf*/ teid_info *upf_teid_info_head = NULL; /** * @brief : Process echo request * @param : gtpv2c_rx, holds data from incoming request * @param : gtpv2c_tx, structure to be filled with response * @param : iface, interfcae from which request is received * @return : Returns 0 in case of success , -1 otherwise */ static uint8_t process_echo_req(gtpv2c_header_t *gtpv2c_rx, gtpv2c_header_t *gtpv2c_tx, int iface) { int ret = 0; uint16_t payload_length = 0; echo_request_t *echo_rx = (echo_request_t *) gtpv2c_rx; echo_request_t *echo_tx = (echo_request_t *) gtpv2c_tx; if((iface != S11_IFACE) && (iface != S5S8_IFACE)){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid interface %d \n", LOG_VALUE, iface); return -1; } ret = process_echo_request(gtpv2c_rx, gtpv2c_tx); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"main.c::control_plane()::Error" "\n\tprocess_echo_req " "%s: %s\n", LOG_VALUE, gtp_type_str(gtpv2c_rx->gtpc.message_type), (ret < 0 ? strerror(-ret) : cause_str(ret))); } if ((iface == S11_IFACE) && ((echo_rx)->sending_node_feat).header.len) { if (((echo_rx)->sending_node_feat).sup_feat == PRN) { set_node_feature_ie((gtp_node_features_ie_t *) echo_tx, GTP_IE_NODE_FEATURES, sizeof(uint8_t), IE_INSTANCE_ZERO, PRN); } } #ifdef USE_REST node_address_t node_addr = {0}; /* Reset ECHO Timers */ if(iface == S11_IFACE){ get_peer_node_addr(&s11_mme_sockaddr, &node_addr); ret = process_response(&node_addr); if (ret) { /* TODO: Error handling not implemented */ } }else { get_peer_node_addr(&s5s8_recv_sockaddr, &node_addr); ret = process_response(&node_addr); if (ret) { /*TODO: Error handling not implemented */ } } #endif /* USE_REST */ payload_length = ntohs(gtpv2c_tx->gtpc.message_len) + sizeof(gtpv2c_tx->gtpc); if(iface == S11_IFACE){ gtpv2c_send(s11_fd, s11_fd_v6, s11_tx_buf, payload_length, s11_mme_sockaddr, SENT); cp_stats.echo++; } else{ gtpv2c_send(s5s8_fd, s5s8_fd_v6, s5s8_tx_buf, payload_length, s5s8_recv_sockaddr, SENT); cp_stats.echo++; } return 0; } #ifdef USE_REST /** * @brief : Process echo response * @param : gtpv2c_rx, holds data from incoming message * @param : iface, interfcae from which response is received * @return : Returns 0 in case of success , -1 otherwise */ static uint8_t process_echo_resp(gtpv2c_header_t *gtpv2c_rx, int iface) { int ret = 0; node_address_t node_addr = {0}; if((iface != S11_IFACE) && (iface != S5S8_IFACE)){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid interface %d \n", LOG_VALUE, iface); return -1; } if(iface == S11_IFACE){ get_peer_node_addr(&s11_mme_sockaddr, &node_addr); ret = process_response(&node_addr); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"main.c::control_plane()::Error" "\n\tprocess_echo_resp " "%s: %s\n", LOG_VALUE, gtp_type_str(gtpv2c_rx->gtpc.message_type), (ret < 0 ? strerror(-ret) : cause_str(ret))); /* Error handling not implemented */ return -1; } }else{ get_peer_node_addr(&s5s8_recv_sockaddr, &node_addr); ret = process_response(&node_addr); if (ret) { clLog(clSystemLog, eCLSeverityCritical, "main.c::control_plane()::Error" "\n\tprocess_echo_resp " "%s: (%d) %s\n", gtp_type_str(gtpv2c_rx->gtpc.message_type), ret, (ret < 0 ? strerror(-ret) : cause_str(ret))); /* Error handling not implemented */ return -1; } } return 0; } #endif /* USE_REST */ void msg_handler_s11(bool is_ipv6) { int ret = 0, bytes_s11_rx = 0; msg_info msg = {0}; bzero(&s11_rx_buf, sizeof(s11_rx_buf)); bzero(&s11_tx_buf, sizeof(s11_tx_buf)); gtpv2c_header_t *gtpv2c_s11_rx = (gtpv2c_header_t *) s11_rx_buf; gtpv2c_header_t *gtpv2c_s11_tx = (gtpv2c_header_t *) s11_tx_buf; gtpv2c_header_t *piggy_backed; memset(&s11_mme_sockaddr, 0, sizeof(s11_mme_sockaddr)); if (!is_ipv6) { bytes_s11_rx = recvfrom(s11_fd, s11_rx_buf, MAX_GTPV2C_UDP_LEN, MSG_DONTWAIT, (struct sockaddr *) &s11_mme_sockaddr.ipv4, &s11_mme_sockaddr_len); s11_mme_sockaddr.type |= PDN_TYPE_IPV4; clLog(clSystemLog, eCLSeverityDebug, "SGWC|SAEGWC_s11 received %d bytes " "with IPv4 Address for message %d", bytes_s11_rx, gtpv2c_s11_rx->gtpc.message_type); } else { bytes_s11_rx = recvfrom(s11_fd_v6, s11_rx_buf, MAX_GTPV2C_UDP_LEN, MSG_DONTWAIT, (struct sockaddr *) &s11_mme_sockaddr.ipv6, &s11_mme_sockaddr_ipv6_len); s11_mme_sockaddr.type |= PDN_TYPE_IPV6; clLog(clSystemLog, eCLSeverityDebug, "SGWC|SAEGWC_s11 received %d bytes " "with IPv6 Address for message %d", bytes_s11_rx, gtpv2c_s11_rx->gtpc.message_type); } if (bytes_s11_rx == 0) { clLog(clSystemLog, eCLSeverityCritical, "SGWC|SAEGWC_s11 recvfrom error:" "\n\t on %s "IPv6_FMT" :%u - %s\n", inet_ntoa(s11_mme_sockaddr.ipv4.sin_addr), IPv6_PRINT(s11_mme_sockaddr.ipv6.sin6_addr), s11_mme_sockaddr.ipv4.sin_port, strerror(errno)); return; } if ((bytes_s11_rx < 0) && (errno == EAGAIN || errno == EWOULDBLOCK)) return; if (!gtpv2c_s11_rx->gtpc.message_type) { return; } if (bytes_s11_rx > 0) ++cp_stats.rx; #ifdef USE_REST /* Reset periodic timers */ node_address_t node_addr = {0}; get_peer_node_addr(&s11_mme_sockaddr, &node_addr); process_response(&node_addr); #endif /* USE_REST */ /*CLI: update counter for any req rcvd on s11 interface */ if(gtpv2c_s11_rx->gtpc.message_type != GTP_DOWNLINK_DATA_NOTIFICATION_ACK && gtpv2c_s11_rx->gtpc.message_type != GTP_CREATE_BEARER_RSP && gtpv2c_s11_rx->gtpc.message_type != GTP_UPDATE_BEARER_RSP && gtpv2c_s11_rx->gtpc.message_type != GTP_DELETE_BEARER_RSP && gtpv2c_s11_rx->gtpc.message_type != GTP_PGW_RESTART_NOTIFICATION_ACK) { update_cli_stats((peer_address_t *)&s11_mme_sockaddr, gtpv2c_s11_rx->gtpc.message_type,RCVD,S11); } if(gtpv2c_s11_rx->gtpc.piggyback) { piggy_backed = (gtpv2c_header_t*) ((uint8_t *)gtpv2c_s11_rx + sizeof(gtpv2c_s11_rx->gtpc) + ntohs(gtpv2c_s11_rx->gtpc.message_len)); update_cli_stats((peer_address_t *)&s11_mme_sockaddr, piggy_backed->gtpc.message_type, RCVD, S11); } if (gtpv2c_s11_rx->gtpc.message_type == GTP_ECHO_REQ){ if (bytes_s11_rx > 0) { /* this call will handle echo request for boh PGWC and SGWC */ ret = process_echo_req(gtpv2c_s11_rx, gtpv2c_s11_tx, S11_IFACE); if(ret != 0){ return; } ++cp_stats.tx; } return; }else if(gtpv2c_s11_rx->gtpc.message_type == GTP_ECHO_RSP){ if (bytes_s11_rx > 0) { #ifdef USE_REST /* this call will handle echo responce for boh PGWC and SGWC */ ret = process_echo_resp(gtpv2c_s11_rx, S11_IFACE); if(ret != 0){ return; } #endif /* USE_REST */ ++cp_stats.tx; } return; }else { if ((ret = gtpc_pcnd_check(gtpv2c_s11_rx, &msg, bytes_s11_rx, &s11_mme_sockaddr, S11_IFACE)) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Failure in gtpc_pcnd_check for s11 interface messages", LOG_VALUE); return; } if(gtpv2c_s11_rx->gtpc.message_type == GTP_DOWNLINK_DATA_NOTIFICATION_ACK || gtpv2c_s11_rx->gtpc.message_type == GTP_CREATE_BEARER_RSP || gtpv2c_s11_rx->gtpc.message_type == GTP_UPDATE_BEARER_RSP || gtpv2c_s11_rx->gtpc.message_type == GTP_DELETE_BEARER_RSP || gtpv2c_s11_rx->gtpc.message_type == GTP_PGW_RESTART_NOTIFICATION_ACK ) { update_cli_stats((peer_address_t *)&s11_mme_sockaddr, gtpv2c_s11_rx->gtpc.message_type,ACC,S11); } /* State Machine execute on session level, but following messages are NODE level */ if (msg.msg_type == GTP_DELETE_PDN_CONNECTION_SET_REQ) { /* Process RCVD Delete PDN Connection Set request */ ret = process_del_pdn_conn_set_req(&msg, &s11_mme_sockaddr); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "process_del_pdn_conn_set_req() failed with Error: %d \n", LOG_VALUE, ret); } return; } else if (msg.msg_type == GTP_DELETE_PDN_CONNECTION_SET_RSP) { /* Process RCVD Delete PDN Connection Set response */ ret = process_del_pdn_conn_set_rsp(&msg, &s11_mme_sockaddr); if (ret) { /* DsTool sending Mandetory IE Missing */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "process_del_pdn_conn_set_rsp() failed with Error: %d \n", LOG_VALUE, ret); } return; } else if (msg.msg_type == GTP_PGW_RESTART_NOTIFICATION_ACK) { /* Process RCVD PGW Restart Notification Ack */ ret = process_pgw_rstrt_notif_ack(&msg, NULL); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "process_pgw_rstrt_notif_ack() failed with Error: %d \n", LOG_VALUE, ret); } return; } else { if ((msg.proc < END_PROC) && (msg.state < END_STATE) && (msg.event < END_EVNT)) { if (SGWC == msg.cp_mode) { ret = (*state_machine_sgwc[msg.proc][msg.state][msg.event])(&msg, NULL); } else if (PGWC == msg.cp_mode) { ret = (*state_machine_pgwc[msg.proc][msg.state][msg.event])(&msg, NULL); } else if (SAEGWC == msg.cp_mode) { ret = (*state_machine_saegwc[msg.proc][msg.state][msg.event])(&msg, NULL); } else { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Invalid Control Plane Type: %d \n", LOG_VALUE, msg.cp_mode); return; } if(ret == GTPC_RE_TRANSMITTED_REQ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Discarding re-transmitted %s Error: %d \n", LOG_VALUE, gtp_type_str(gtpv2c_s11_rx->gtpc.message_type), ret); return; } if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "State_Machine Callback failed with Error: %d \n", LOG_VALUE, ret); return; } } else { if ((msg.proc == END_PROC) && (msg.state == END_STATE) && (msg.event == END_EVNT)) { return; } clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Invalid Procedure or State or Event \n", LOG_VALUE); return; } } } switch (msg.cp_mode) { case SGWC: case PGWC: case SAEGWC: if (bytes_s11_rx > 0) { ++cp_stats.tx; switch (gtpv2c_s11_rx->gtpc.message_type) { case GTP_CREATE_SESSION_REQ: cp_stats.create_session++; break; case GTP_DELETE_SESSION_REQ: cp_stats.delete_session++; break; case GTP_MODIFY_BEARER_REQ: cp_stats.modify_bearer++; break; case GTP_RELEASE_ACCESS_BEARERS_REQ: cp_stats.rel_access_bearer++; break; case GTP_BEARER_RESOURCE_CMD: cp_stats.bearer_resource++; break; case GTP_CREATE_BEARER_RSP: cp_stats.create_bearer++; return; case GTP_DELETE_BEARER_RSP: cp_stats.delete_bearer++; return; case GTP_DOWNLINK_DATA_NOTIFICATION_ACK: cp_stats.ddn_ack++; } } break; default: clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "cp_stats: Unknown msg.cp_mode= %u\n", LOG_VALUE, msg.cp_mode); break; } } void msg_handler_s5s8(bool is_ipv6) { int ret = 0; int bytes_s5s8_rx = 0; msg_info msg = {0}; node_address_t s5s8_cli_addr = {0}; bzero(&s5s8_rx_buf, sizeof(s5s8_rx_buf)); gtpv2c_header_t *gtpv2c_s5s8_rx = (gtpv2c_header_t *) s5s8_rx_buf; gtpv2c_header_t *piggy_backed; #ifdef USE_REST bzero(&s5s8_tx_buf, sizeof(s5s8_tx_buf)); gtpv2c_header_t *gtpv2c_s5s8_tx = (gtpv2c_header_t *) s5s8_tx_buf; #endif /* USE_REST */ s5s8_recv_sockaddr.type = 0; if (!is_ipv6){ bytes_s5s8_rx = recvfrom(s5s8_fd, s5s8_rx_buf, MAX_GTPV2C_UDP_LEN, MSG_DONTWAIT, (struct sockaddr *) &s5s8_recv_sockaddr.ipv4, &s5s8_sockaddr_len); s5s8_recv_sockaddr.type |= PDN_TYPE_IPV4; clLog(clSystemLog, eCLSeverityDebug, "s5s8 received %d bytes " "with IPv4 Address for message %d", bytes_s5s8_rx, gtpv2c_s5s8_rx->gtpc.message_type); } else { bytes_s5s8_rx = recvfrom(s5s8_fd_v6, s5s8_rx_buf, MAX_GTPV2C_UDP_LEN, MSG_DONTWAIT, (struct sockaddr *) &s5s8_recv_sockaddr.ipv6, &s5s8_sockaddr_ipv6_len); s5s8_recv_sockaddr.type |= PDN_TYPE_IPV6; clLog(clSystemLog, eCLSeverityDebug, "s5s8 received %d bytes " "with IPv6 Address for message %d", bytes_s5s8_rx, gtpv2c_s5s8_rx->gtpc.message_type); } if (bytes_s5s8_rx == 0) { clLog(clSystemLog, eCLSeverityCritical, "s5s8 recvfrom error:" "\n\ton %s "IPv6_FMT" :%u - %s\n", inet_ntoa(s5s8_recv_sockaddr.ipv4.sin_addr), IPv6_PRINT(s5s8_recv_sockaddr.ipv6.sin6_addr), s5s8_recv_sockaddr.ipv4.sin_port, strerror(errno)); return; } ret = fill_ip_addr(s5s8_recv_sockaddr.ipv4.sin_addr.s_addr, s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr, &s5s8_cli_addr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "S5S8 IP", LOG_VALUE); } add_cli_peer((peer_address_t *) &s5s8_recv_sockaddr, S5S8); if(cli_node.s5s8_selection == NOT_PRESENT) { cli_node.s5s8_selection = OSS_S5S8_RECEIVER; } if (bytes_s5s8_rx == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"s5s8 recvfrom error:" "\n\ton %s:%u - %s\n", LOG_VALUE, inet_ntoa(s5s8_recv_sockaddr.ipv4.sin_addr), s5s8_recv_sockaddr.ipv4.sin_port, strerror(errno)); } if ( (bytes_s5s8_rx < 0) && (errno == EAGAIN || errno == EWOULDBLOCK) ) return; if (!gtpv2c_s5s8_rx->gtpc.message_type) { return; } if (bytes_s5s8_rx > 0) ++cp_stats.rx; /* Reset periodic timers */ node_address_t node_addr = {0}; get_peer_node_addr(&s5s8_recv_sockaddr, &node_addr); process_response(&node_addr); if(gtpv2c_s5s8_rx->gtpc.message_type == GTP_ECHO_REQ) { if (bytes_s5s8_rx > 0) { #ifdef USE_REST ret = process_echo_req(gtpv2c_s5s8_rx, gtpv2c_s5s8_tx, S5S8_IFACE); if(ret != 0){ return; } update_cli_stats((peer_address_t *) &s5s8_recv_sockaddr, gtpv2c_s5s8_rx->gtpc.message_type, RCVD, S5S8); #endif /* USE_REST */ ++cp_stats.tx; } return; }else if(gtpv2c_s5s8_rx->gtpc.message_type == GTP_ECHO_RSP){ if (bytes_s5s8_rx > 0) { #ifdef USE_REST ret = process_echo_resp(gtpv2c_s5s8_rx, S5S8_IFACE); if(ret != 0){ return; } update_cli_stats((peer_address_t *) &s5s8_recv_sockaddr, gtpv2c_s5s8_rx->gtpc.message_type, RCVD, S5S8); #endif /* USE_REST */ ++cp_stats.tx; } return; }else { if ((ret = gtpc_pcnd_check(gtpv2c_s5s8_rx, &msg, bytes_s5s8_rx, &s5s8_recv_sockaddr, S5S8_IFACE)) != 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Failure in gtpc_pcnd_check for s5s8 interface messages\n", LOG_VALUE); /*CLI: update csr, dsr, mbr rej response*/ update_cli_stats((peer_address_t *) &s5s8_recv_sockaddr, gtpv2c_s5s8_rx->gtpc.message_type, REJ, S5S8); return; } if ((msg.cp_mode == SGWC) && (dRespRcvd == ossS5s8MessageDefs[s5s8MessageTypes[gtpv2c_s5s8_rx->gtpc.message_type]].dir)) { update_cli_stats((peer_address_t *) &s5s8_recv_sockaddr, gtpv2c_s5s8_rx->gtpc.message_type, ACC, S5S8); } else if(msg.cp_mode == SGWC) { update_cli_stats((peer_address_t *) &s5s8_recv_sockaddr, gtpv2c_s5s8_rx->gtpc.message_type, RCVD, S5S8); } else if((msg.cp_mode == PGWC) && (dRespRcvd == ossS5s8MessageDefs[s5s8MessageTypes[gtpv2c_s5s8_rx->gtpc.message_type]].pgwc_dir)) update_cli_stats((peer_address_t *) &s5s8_recv_sockaddr, gtpv2c_s5s8_rx->gtpc.message_type, ACC, S5S8); else { update_cli_stats((peer_address_t *) &s5s8_recv_sockaddr, gtpv2c_s5s8_rx->gtpc.message_type, RCVD, S5S8); } if(gtpv2c_s5s8_rx->gtpc.piggyback) { piggy_backed = (gtpv2c_header_t*) ((uint8_t *)gtpv2c_s5s8_rx + sizeof(gtpv2c_s5s8_rx->gtpc) + ntohs(gtpv2c_s5s8_rx->gtpc.message_len)); update_cli_stats((peer_address_t *) &s5s8_recv_sockaddr, piggy_backed->gtpc.message_type, RCVD, S5S8); } if (msg.cp_mode == SGWC) { if (gtpv2c_s5s8_rx->gtpc.message_type == GTP_CREATE_SESSION_RSP ) { if ((s5s8_recv_sockaddr.ipv4.sin_addr.s_addr != 0) || (s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr)) { node_address_t node_addr = {0}; get_peer_node_addr(&s5s8_recv_sockaddr, &node_addr); add_node_conn_entry(&node_addr, S5S8_SGWC_PORT_ID, msg.cp_mode); } } if (gtpv2c_s5s8_rx->gtpc.message_type == GTP_MODIFY_BEARER_RSP) { if ((s5s8_recv_sockaddr.ipv4.sin_addr.s_addr != 0) || (s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr)) { node_address_t node_addr = {0}; get_peer_node_addr(&s5s8_recv_sockaddr, &node_addr); add_node_conn_entry(&node_addr, S5S8_SGWC_PORT_ID, msg.cp_mode); } } } /* State Machine execute on session level, but following messages are NODE level */ if (msg.msg_type == GTP_DELETE_PDN_CONNECTION_SET_REQ) { /* Process RCVD Delete PDN Connection Set request */ ret = process_del_pdn_conn_set_req(&msg, &s5s8_recv_sockaddr); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "process_del_pdn_conn_set_req() failed with Error: %d \n", LOG_VALUE, ret); } return; } else if (msg.msg_type == GTP_DELETE_PDN_CONNECTION_SET_RSP) { /* Process RCVD Delete PDN Connection Set response */ ret = process_del_pdn_conn_set_rsp(&msg, &s5s8_recv_sockaddr); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "process_del_pdn_conn_set_rsp() failed with Error: %d \n", LOG_VALUE, ret); } return; } else { if ((msg.proc < END_PROC) && (msg.state < END_STATE) && (msg.event < END_EVNT)) { if (SGWC == msg.cp_mode) { ret = (*state_machine_sgwc[msg.proc][msg.state][msg.event])(&msg, NULL); } else if (PGWC == msg.cp_mode) { ret = (*state_machine_pgwc[msg.proc][msg.state][msg.event])(&msg, NULL); } else if (SAEGWC == msg.cp_mode) { ret = (*state_machine_saegwc[msg.proc][msg.state][msg.event])(&msg, NULL); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Invalid Control Plane Type: %d \n", LOG_VALUE, msg.cp_mode); return; } if(ret == GTPC_RE_TRANSMITTED_REQ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Discarding re-transmitted %s Error: %d \n", LOG_VALUE, gtp_type_str(gtpv2c_s5s8_rx->gtpc.message_type), ret); return; } if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "State_Machine Callback failed with Error: %d \n", LOG_VALUE, ret); return; } } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Invalid Procedure or State or Event \n", LOG_VALUE); return; } } } if (bytes_s5s8_rx > 0) ++cp_stats.tx; switch (msg.cp_mode) { case SGWC: break; case PGWC: if (bytes_s5s8_rx > 0) { switch (gtpv2c_s5s8_rx->gtpc.message_type) { case GTP_CREATE_SESSION_REQ: cp_stats.create_session++; break; case GTP_MODIFY_BEARER_REQ: cp_stats.modify_bearer++; break; case GTP_DELETE_SESSION_REQ: cp_stats.delete_session++; break; case GTP_BEARER_RESOURCE_CMD: cp_stats.bearer_resource++; break; case GTP_CREATE_BEARER_RSP: cp_stats.create_bearer++; break; } } break; default: clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "cp_stats: Unknown msg.cp_mode= %u\n", LOG_VALUE, msg.cp_mode); break; } } const char * get_cc_string(uint16_t cc_value){ switch(cc_value){ case HOME: return "HOME"; case VISITING: return "VISITING"; case ROAMING: return "ROAMING"; default: return "Unknown"; } return ""; } static int update_periodic_timer_value(const int periodic_timer_value) { peerData *conn_data = NULL; const void *key; uint32_t iter = 0; config.periodic_timer = periodic_timer_value; if(conn_hash_handle != NULL) { while (rte_hash_iterate(conn_hash_handle, &key, (void **)&conn_data, &iter) >= 0) { /* If Initial timer value was set to 0, then start the timer */ if (!conn_data->pt.ti_ms) { conn_data->pt.ti_ms = (periodic_timer_value * 1000); if (startTimer( &conn_data->pt ) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Periodic Timer failed to start...\n", LOG_VALUE); } } else { conn_data->pt.ti_ms = (periodic_timer_value * 1000); } } } return 0; } static int update_transmit_timer_value(const int transmit_timer_value) { peerData *conn_data = NULL; const void *key; uint32_t iter = 0; config.transmit_timer = transmit_timer_value; if(conn_hash_handle != NULL) { while (rte_hash_iterate(conn_hash_handle, &key, (void **)&conn_data, &iter) >= 0) { /* If Initial timer value was set to 0, then start the timer */ if (!conn_data->tt.ti_ms) { conn_data->tt.ti_ms = (transmit_timer_value * 1000); if (startTimer( &conn_data->tt ) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Transmit Timer failed to start...\n", LOG_VALUE); } } else { conn_data->tt.ti_ms = (transmit_timer_value * 1000); } } } return 0; } int8_t fill_cp_configuration(cp_configuration_t *cp_configuration) { cp_configuration->cp_type = OSS_CONTROL_PLANE; cp_configuration->s11_port = config.s11_port; cp_configuration->s5s8_port = config.s5s8_port; cp_configuration->pfcp_port = config.pfcp_port; cp_configuration->dadmf_port = config.dadmf_port; strncpy(cp_configuration->dadmf_ip, config.dadmf_ip, IPV6_STR_LEN); cp_configuration->upf_pfcp_port = config.upf_pfcp_port; cp_configuration->upf_pfcp_ip.s_addr = config.upf_pfcp_ip.s_addr; cp_configuration->redis_port = config.redis_port; strncpy(cp_configuration->redis_ip_buff, config.redis_ip_buff, IPV6_STR_LEN); cp_configuration->request_tries = config.request_tries; cp_configuration->request_timeout = config.request_timeout; cp_configuration->use_dns = config.use_dns; cp_configuration->trigger_type = config.trigger_type; cp_configuration->uplink_volume_th = config.uplink_volume_th; cp_configuration->downlink_volume_th = config.downlink_volume_th; cp_configuration->time_th = config.time_th; cp_configuration->ip_pool_ip.s_addr = config.ip_pool_ip.s_addr; cp_configuration->generate_cdr = config.generate_cdr; cp_configuration->generate_sgw_cdr = config.generate_sgw_cdr; cp_configuration->sgw_cc = config.sgw_cc; cp_configuration->ip_pool_mask.s_addr = config.ip_pool_mask.s_addr; cp_configuration->num_apn = config.num_apn; cp_configuration->restoration_params.transmit_cnt = config.transmit_cnt; cp_configuration->restoration_params.transmit_timer = config.transmit_timer; cp_configuration->restoration_params.periodic_timer = config.periodic_timer; strncpy(cp_configuration->cp_redis_ip_buff, config.cp_redis_ip_buff, IPV6_STR_LEN); strncpy(cp_configuration->ddf2_ip, config.ddf2_ip, IPV6_STR_LEN); cp_configuration->add_default_rule = config.add_default_rule; cp_configuration->ddf2_port = config.ddf2_port; strncpy(cp_configuration->redis_cert_path, config.redis_cert_path, REDIS_CERT_PATH_LEN); strncpy(cp_configuration->ddf2_local_ip, config.ddf2_local_ip, IPV6_STR_LEN); strncpy(cp_configuration->dadmf_local_addr, config.dadmf_local_addr, IPV6_STR_LEN); cp_configuration->use_gx = config.use_gx; cp_configuration->perf_flag = config.perf_flag; cp_configuration->generate_sgw_cdr = config.generate_sgw_cdr; cp_configuration->sgw_cc = config.sgw_cc; if(config.cp_type != SGWC) { cp_configuration->is_gx_interface = PRESENT; } cp_configuration->s11_ip.s_addr = config.s11_ip.s_addr; cp_configuration->s5s8_ip.s_addr = config.s5s8_ip.s_addr; cp_configuration->pfcp_ip.s_addr = config.pfcp_ip.s_addr; for(uint8_t itr_apn = 0; itr_apn < cp_configuration->num_apn; itr_apn++) { cp_configuration->apn_list[itr_apn].apn_usage_type = apn_list[itr_apn].apn_usage_type; cp_configuration->apn_list[itr_apn].trigger_type = apn_list[itr_apn].trigger_type; cp_configuration->apn_list[itr_apn].uplink_volume_th = apn_list[itr_apn].uplink_volume_th; cp_configuration->apn_list[itr_apn].downlink_volume_th = apn_list[itr_apn].downlink_volume_th; cp_configuration->apn_list[itr_apn].time_th = apn_list[itr_apn].time_th; strncpy(cp_configuration->apn_list[itr_apn].apn_name_label, apn_list[itr_apn].apn_name_label+1, APN_NAME_LEN); strncpy(cp_configuration->apn_list[itr_apn].apn_net_cap, apn_list[itr_apn].apn_net_cap, MAX_NETCAP_LEN); cp_configuration->apn_list[itr_apn].ip_pool_ip.s_addr = apn_list[itr_apn].ip_pool_ip.s_addr; cp_configuration->apn_list[itr_apn].ip_pool_mask.s_addr = apn_list[itr_apn].ip_pool_mask.s_addr; cp_configuration->apn_list[itr_apn].ipv6_prefix_len = apn_list[itr_apn].ipv6_prefix_len; cp_configuration->apn_list[itr_apn].ipv6_network_id = apn_list[itr_apn].ipv6_network_id; } cp_configuration->dns_cache.concurrent = config.dns_cache.concurrent; cp_configuration->dns_cache.sec = (config.dns_cache.sec / 1000); cp_configuration->dns_cache.percent = config.dns_cache.percent; cp_configuration->dns_cache.timeoutms = config.dns_cache.timeoutms; cp_configuration->dns_cache.tries = config.dns_cache.tries; cp_configuration->app_dns.freq_sec = config.app_dns.freq_sec; cp_configuration->app_dns.nameserver_cnt = config.app_dns.nameserver_cnt; strncpy(cp_configuration->app_dns.filename, config.app_dns.filename, PATH_LEN); strncpy(cp_configuration->app_dns.nameserver_ip[config.app_dns.nameserver_cnt-DNS_IP_INDEX], config.app_dns.nameserver_ip[config.app_dns.nameserver_cnt-DNS_IP_INDEX], IPV6_STR_LEN); cp_configuration->ops_dns.freq_sec = config.ops_dns.freq_sec; cp_configuration->ops_dns.nameserver_cnt = config.ops_dns.nameserver_cnt; strncpy(cp_configuration->ops_dns.filename, config.ops_dns.filename, PATH_LEN); strncpy(cp_configuration->ops_dns.nameserver_ip[config.ops_dns.nameserver_cnt-DNS_IP_INDEX], config.ops_dns.nameserver_ip[config.ops_dns.nameserver_cnt-DNS_IP_INDEX], IPV6_STR_LEN); cp_configuration->dl_buf_suggested_pkt_cnt = config.dl_buf_suggested_pkt_cnt; cp_configuration->low_lvl_arp_priority = config.low_lvl_arp_priority; cp_configuration->ipv6_network_id = config.ipv6_network_id; cp_configuration->ipv6_prefix_len = config.ipv6_prefix_len; cp_configuration->ip_allocation_mode = config.ip_allocation_mode; cp_configuration->ip_type_supported = config.ip_type_supported; cp_configuration->ip_type_priority = config.ip_type_priority; strncpy(cp_configuration->cp_dns_ip_buff, config.cp_dns_ip_buff, IPV6_STR_LEN); cp_configuration->s5s8_ip_v6 = config.s5s8_ip_v6; cp_configuration->pfcp_ip_v6 = config.pfcp_ip_v6; cp_configuration->upf_pfcp_ip_v6 = config.upf_pfcp_ip_v6; cp_configuration->s11_ip_v6 = config.s11_ip_v6; strncpy(cp_configuration->cli_rest_ip_buff, config.cli_rest_ip_buff, IPV6_STR_LEN); cp_configuration->cli_rest_port = config.cli_rest_port; return 0; } int8_t post_request_timeout(const int request_timeout_value) { config.request_timeout = request_timeout_value; return 0; } int8_t post_request_tries(const int number_of_request_tries) { config.request_tries = number_of_request_tries; return 0; } int8_t post_periodic_timer(const int periodic_timer_value) { update_periodic_timer_value(periodic_timer_value); return 0; } int8_t post_transmit_timer(const int transmit_timer_value) { update_transmit_timer_value(transmit_timer_value); return 0; } int8_t post_transmit_count(const int transmit_count) { config.transmit_cnt = transmit_count; return 0; } int8_t update_perf_flag(const int perf_flag) { config.perf_flag = perf_flag; return 0; } int get_request_timeout(void) { return config.request_timeout; } int get_request_tries(void) { return config.request_tries; } int get_periodic_timer(void) { return config.periodic_timer; } int get_transmit_timer(void) { return config.transmit_timer; } int get_transmit_count(void) { return config.transmit_cnt; } uint8_t get_perf_flag(void) { return config.perf_flag; }
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/seid_llist.h
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SEID_LLIST_H #define SEID_LLIST_H #if CP_BUILD #include "csid_struct.h" #include "cp.h" #else #include "up_main.h" #endif #include "gw_adapter.h" /** * @brief : Function to add a node in sess_csid Linked List. * @param : head, linked list head pointer * @retrun : Returns * head in case of success * NULL otherwise */ sess_csid * add_sess_csid_data_node(sess_csid *head, uint16_t local_csid); /** * @brief : Function to add a node in sess_csid Linked List. * @param : head, linked list head pointer * @retrun : Returns * head in case of success * NULL otherwise */ sess_csid * add_peer_csid_sess_data_node(sess_csid *head, peer_csid_key_t *key); /** * @brief : Function to add a node in sess_csid Linked List. * @param : head, linked list head pointer * @param : new_node, node to be added * @retrun : Returns * 0 in case of success * -1 otherwise */ int8_t insert_sess_csid_data_node(sess_csid *head, sess_csid *new_node); /** * @brief : Function to get a node in sess_csid Linked List. * @param : head, linked list head pointer * @param : seid, seid to find node * @retrun : Returns * head in case of success * NULL otherwise */ sess_csid * get_sess_csid_data_node(sess_csid *head, uint64_t seid); /** * @brief : Function to remove a node in sess_csid Linked List. * @param : head, linked list head pointer * @param : seid, side to find node and remove * @retrun : Returns * head case of success * NULL otherwise */ sess_csid * remove_sess_csid_data_node(sess_csid *head, uint64_t seid); /** * @brief : Function to flush sess_csid Linked List. * @param : head, linked list head pointer * @retrun : Returns * 0 in case of success * -1 otherwise */ int8_t flush_sess_csid_data_list(sess_csid *head); #endif /* SEID_LLIST_H */
nikhilc149/e-utran-features-bug-fixes
dp/up_ether.c
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <arpa/inet.h> #include <rte_ip.h> #include "gtpu.h" #include "util.h" #include "ipv4.h" #include "ipv6.h" #include "pfcp_util.h" #include "up_ether.h" #include "pipeline/epc_arp.h" #include "gw_adapter.h" #define IP_HDR_IPv4_VERSION 0x45 extern int fd_array_v4[2]; extern int fd_array_v6[2]; extern int clSystemLog; #ifndef STATIC_ARP static struct sockaddr_in dest_addr[2]; static struct sockaddr_in6 ipv6_addr[2]; #endif /* STATIC_ARP */ /** * @brief : Function to set ethertype. * @param : m, mbuf pointer * @param : type, type * @return : Returns nothing */ static inline void set_ether_type(struct rte_mbuf *m, uint16_t type) { struct ether_hdr *eth_hdr = get_mtoeth(m); /* src/dst mac will be updated by send_to() */ eth_hdr->ether_type = htons(type); } int construct_ether_hdr(struct rte_mbuf *m, uint8_t portid, pdr_info_t **pdr, uint8_t flag) { /* Construct the ether header */ struct ether_hdr *eth_hdr = rte_pktmbuf_mtod(m, void *); uint8_t *ptr = (uint8_t *)(rte_pktmbuf_mtod(m, unsigned char *) + ETH_HDR_SIZE); struct arp_ip_key tmp_arp_key = {0}; /* Check L3 IP packet type its IPv4 or IPv6 */ if (*ptr == IP_HDR_IPv4_VERSION) { /* Fill the ether header for IPv4 packet */ struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)&eth_hdr[1]; tmp_arp_key.ip_type.ipv4 = PRESENT; tmp_arp_key.ip_addr.ipv4 = ipv4_hdr->dst_addr; /* Retrieve Gateway Routing IP Address of the next hop */ if (portid == app.wb_port) { if (app.wb_gw_ip != 0 && (tmp_arp_key.ip_addr.ipv4 & app.wb_mask) != app.wb_net) { /* UPLINK */ tmp_arp_key.ip_addr.ipv4 = app.wb_gw_ip; } } else if (portid == app.eb_port) { if (app.eb_gw_ip != 0 && (tmp_arp_key.ip_addr.ipv4 & app.eb_mask) != app.eb_net) { /* DOWNLINK */ tmp_arp_key.ip_addr.ipv4 = app.eb_gw_ip; } } /* IPv4 L2 hdr */ eth_hdr->ether_type = htons(ETH_TYPE_IPv4); } else if (*ptr == IPv6_VERSION) { /* Fill the ether header for IPv6 packet */ struct ipv6_hdr *ipv6_hdr = (struct ipv6_hdr *)&eth_hdr[1]; tmp_arp_key.ip_type.ipv6 = PRESENT; /* Fill the IPv6 destination Address*/ memcpy(&tmp_arp_key.ip_addr.ipv6.s6_addr, &ipv6_hdr->dst_addr, IPV6_ADDRESS_LEN); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"DST IPv6: "IPv6_FMT", ARP Key:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)ipv6_hdr->dst_addr), IPv6_PRINT(tmp_arp_key.ip_addr.ipv6)); /* TODO: Add the support if remote proxy IP configure in the config file, GW STATIC Entry */ /* IPv6 L2 hdr */ eth_hdr->ether_type = htons(ETH_TYPE_IPv6); } else { if (*pdr) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IP type in header is not set appropriate," "IP Type:%x, Outer HDR Desc:%u\n", LOG_VALUE, *ptr, ((*pdr)->far)->frwdng_parms.outer_hdr_creation.outer_hdr_creation_desc); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IP type in header is not set appropriate," "IP type:%x\n", LOG_VALUE, *ptr); } return -1; } /* Get the entry for IP address, if not present than create it */ struct arp_entry_data *ret_arp_data = NULL; ret_arp_data = retrieve_arp_entry(tmp_arp_key, portid); if (ret_arp_data == NULL) { if (tmp_arp_key.ip_type.ipv4) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Retrieve arp entry failed for ipv4: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(tmp_arp_key.ip_addr.ipv4))); } else if (tmp_arp_key.ip_type.ipv6) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Retrieve arp entry failed for ipv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(tmp_arp_key.ip_addr.ipv6)); } return -1; } if (ret_arp_data->status == INCOMPLETE) { #ifndef STATIC_ARP if (tmp_arp_key.ip_type.ipv4) { clLog(clSystemLog, eCLSeverityInfo, LOG_FORMAT"Sendto ret arp data IPv4: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(ret_arp_data->ipv4))); if (fd_array_v4[portid] > 0) { /* setting sendto destination addr */ dest_addr[portid].sin_family = AF_INET; dest_addr[portid].sin_addr.s_addr = ret_arp_data->ipv4; dest_addr[portid].sin_port = htons(SOCKET_PORT); char *data = (char *)((char *)(m)->buf_addr + (m)->data_off); if ((sendto(fd_array_v4[portid], data, m->data_len, 0, (struct sockaddr *) &dest_addr[portid], sizeof(struct sockaddr_in))) < 0) { clLog(clSystemLog, eCLSeverityCritical, "IPv4:"LOG_FORMAT"port:%u ERROR: Failed to send packet on KNI TAB.\n", LOG_VALUE, portid); perror("Socket Error:"); return -1; } } else { clLog(clSystemLog, eCLSeverityCritical, "IPv4:"LOG_FORMAT"port:%u ERROR: FD for ipv4 intf not created, Failed to send packet on KNI TAB.\n", LOG_VALUE, portid); return -1; } } else if (tmp_arp_key.ip_type.ipv6) { clLog(clSystemLog, eCLSeverityInfo, LOG_FORMAT"Sendto ret arp data IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(tmp_arp_key.ip_addr.ipv6)); if (fd_array_v6[portid] > 0) { /* setting sendto destination addr */ ipv6_addr[portid].sin6_family = AF_INET6; memcpy(&ipv6_addr[portid].sin6_addr, &ret_arp_data->ipv6, IPV6_ADDRESS_LEN); ipv6_addr[portid].sin6_port = htons(SOCKET_PORT); char *data = (char *)((char *)(m)->buf_addr + (m)->data_off); if ((sendto(fd_array_v6[portid], data, m->data_len, 0, (struct sockaddr *) &ipv6_addr[portid], sizeof(struct sockaddr_in6))) < 0) { clLog(clSystemLog, eCLSeverityCritical, "IPv6:"LOG_FORMAT"port:%u ERROR: Failed to send packet on KNI TAB.\n", LOG_VALUE, portid); perror("Socket Error:"); return -1; } } else { clLog(clSystemLog, eCLSeverityCritical, "IPv6:"LOG_FORMAT"port:%u ERROR: FD for v6 intf not created yet, Failed to send packet on KNI TAB.\n", LOG_VALUE, portid); return -1; } } #endif /* STATIC_ARP */ if (portid == app.eb_port) { if (arp_qunresolved_ulpkt(ret_arp_data, m, portid) == 0) { if (tmp_arp_key.ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"EB:Arp queue unresolved packet arp key IPv4: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(tmp_arp_key.ip_addr.ipv4))); } else if (tmp_arp_key.ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"EB:Arp queue unresolved packet arp key IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(tmp_arp_key.ip_addr.ipv6)); } return -1; } } if (portid == app.wb_port) { if (arp_qunresolved_dlpkt(ret_arp_data, m, portid) == 0) { if (tmp_arp_key.ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"WB:Arp queue unresolved packet arp key IPv4: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(tmp_arp_key.ip_addr.ipv4))); } else if (tmp_arp_key.ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"WB:Arp queue unresolved packet arp key IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(tmp_arp_key.ip_addr.ipv6)); } return -1; } } return -1; } if (tmp_arp_key.ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, "MAC found for IPv4 "IPV4_ADDR"" ", port %d - %02x:%02x:%02x:%02x:%02x:%02x\n", IPV4_ADDR_HOST_FORMAT(ntohl(tmp_arp_key.ip_addr.ipv4)), portid, ret_arp_data->eth_addr.addr_bytes[0], ret_arp_data->eth_addr.addr_bytes[1], ret_arp_data->eth_addr.addr_bytes[2], ret_arp_data->eth_addr.addr_bytes[3], ret_arp_data->eth_addr.addr_bytes[4], ret_arp_data->eth_addr.addr_bytes[5]); } else if (tmp_arp_key.ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, "MAC found for IPv6 "IPv6_FMT"" ", port %d - %02x:%02x:%02x:%02x:%02x:%02x\n", IPv6_PRINT(tmp_arp_key.ip_addr.ipv6), portid, ret_arp_data->eth_addr.addr_bytes[0], ret_arp_data->eth_addr.addr_bytes[1], ret_arp_data->eth_addr.addr_bytes[2], ret_arp_data->eth_addr.addr_bytes[3], ret_arp_data->eth_addr.addr_bytes[4], ret_arp_data->eth_addr.addr_bytes[5]); } ether_addr_copy(&ret_arp_data->eth_addr, &eth_hdr->d_addr); ether_addr_copy(&ports_eth_addr[portid], &eth_hdr->s_addr); #ifdef NGCORE_SHRINK #ifdef STATS struct gtpu_hdr *gtpu_hdr = NULL; gtpu_hdr = get_mtogtpu(m); if ((gtpu_hdr != NULL) && (gtpu_hdr->msgtype == GTP_GEMR)) { if(portid == SGI_PORT_ID) { --epc_app.ul_params[S1U_PORT_ID].pkts_in; } else if(portid == S1U_PORT_ID) { --epc_app.dl_params[SGI_PORT_ID].pkts_in; } return 0; } if (flag) { if(portid == SGI_PORT_ID) { ++epc_app.dl_params[SGI_PORT_ID].pkts_out; } else if(portid == S1U_PORT_ID) { ++epc_app.ul_params[S1U_PORT_ID].pkts_out; } } else { if(portid == SGI_PORT_ID) { ++epc_app.ul_params[S1U_PORT_ID].pkts_out; } else if(portid == S1U_PORT_ID) { ++epc_app.dl_params[SGI_PORT_ID].pkts_out; } } #endif /* STATS */ #endif /* NGCORE_SHRINK */ return 0; }
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c_messages/change_notification.c
<filename>cp/gtpv2c_messages/change_notification.c /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ue.h" #include "pfcp.h" #include "cp_stats.h" #include "sm_struct.h" #include "pfcp_util.h" #include "debug_str.h" #include "dp_ipc_api.h" #include "gtpv2c_set_ie.h" #include "pfcp_association.h" #include "pfcp_messages_encoder.h" #include "../cp_dp_api/vepc_cp_dp_api.h" #include "cp_config.h" #include "cdr.h" #include "cp_timer.h" extern int s5s8_fd; extern int s5s8_fd_v6; extern socklen_t s5s8_sockaddr_len; extern socklen_t s5s8_sockaddr_ipv6_len; extern socklen_t s11_mme_sockaddr_len; extern socklen_t s11_mme_sockaddr_ipv6_len; extern struct peer_addr_t s5s8_recv_sockaddr; extern int clSystemLog; /** * @brief : Set the Change Notification Request gtpv2c message * @param : gtpv2c_tx * transmission buffer to contain 'modify bearer request' message * @param : change notification request structure pointer This is the message which is received on the Gateway. * @return : Returns 0 for success, -1 for error */ int set_change_notification_request(gtpv2c_header_t *gtpv2c_tx, change_noti_req_t *change_not_req, pdn_connection **_pdn) { change_noti_req_t chn_not_req = {0}; pdn_connection *pdn = NULL; eps_bearer *bearer = NULL; ue_context *context = NULL; int ret = 0; int ebi_index = 0; int len = 0; uint8_t instance = 0; uint16_t payload_length = 0; uint8_t cp_mode = 0; struct teid_value_t *teid_value = NULL; teid_key_t teid_key = {0}; bzero(&tx_buf, sizeof(tx_buf)); gtpv2c_tx = (gtpv2c_header_t *)tx_buf; ebi_index = GET_EBI_INDEX(change_not_req->lbi.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ret = rte_hash_lookup_data(ue_context_by_fteid_hash, (const void *) &change_not_req->header.teid.has_teid.teid, (void **) &context); if (ret < 0 || !context) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Failed to get UE context \n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } bearer = context->eps_bearers[ebi_index]; if (!bearer) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Received modify bearer on non-existent EBI - " "Bitmap Inconsistency - Dropping packet\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } context->sequence = change_not_req->header.teid.has_teid.seq; pdn = bearer->pdn; teid_value = rte_zmalloc_socket(NULL, sizeof(teid_value_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (teid_value == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for teid value, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } teid_value->teid = pdn->s5s8_sgw_gtpc_teid; teid_value->msg_type = change_not_req->header.gtpc.message_type; snprintf(teid_key.teid_key, PROC_LEN, "%s%d", get_proc_string(pdn->proc), change_not_req->header.teid.has_teid.seq); /* Add the entry for sequence and teid value for error handling */ if (context->cp_mode != SAEGWC) { ret = add_seq_number_for_teid(teid_key, teid_value); if(ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "Sequence number for TEID: %u\n", LOG_VALUE, teid_value->teid); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } if(change_not_req->rat_type.header.len == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" RAT TYPE missing in change notification request\n", LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } if(change_not_req->imsi.header.len == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" IMSI missing in change notification request\n", LOG_VALUE); return GTPV2C_CAUSE_IMSI_NOT_KNOWN; } set_gtpv2c_teid_header((gtpv2c_header_t *) &chn_not_req, GTP_CHANGE_NOTIFICATION_REQ, pdn->s5s8_pgw_gtpc_teid, change_not_req->header.teid.has_teid.seq, 0); memcpy(&chn_not_req.imsi.imsi_number_digits, &change_not_req->imsi.imsi_number_digits, change_not_req->imsi.header.len); set_ie_header(&chn_not_req.imsi.header, GTP_IE_IMSI, IE_INSTANCE_ZERO, sizeof(chn_not_req.imsi.imsi_number_digits)); set_ebi(&chn_not_req.lbi, IE_INSTANCE_ZERO, change_not_req->lbi.ebi_ebi); if(change_not_req->uli.header.len !=0) { if (change_not_req->uli.lai) { chn_not_req.uli.lai = context->uli.lai; chn_not_req.uli.lai2.lai_mcc_digit_2 = change_not_req->uli.lai2.lai_mcc_digit_2; chn_not_req.uli.lai2.lai_mcc_digit_1 = change_not_req->uli.lai2.lai_mcc_digit_1; chn_not_req.uli.lai2.lai_mnc_digit_3 = change_not_req->uli.lai2.lai_mnc_digit_3; chn_not_req.uli.lai2.lai_mcc_digit_3 = change_not_req->uli.lai2.lai_mcc_digit_3; chn_not_req.uli.lai2.lai_mnc_digit_2 = change_not_req->uli.lai2.lai_mnc_digit_2; chn_not_req.uli.lai2.lai_mnc_digit_1 = change_not_req->uli.lai2.lai_mnc_digit_1; chn_not_req.uli.lai2.lai_lac = change_not_req->uli.lai2.lai_lac; len += sizeof(chn_not_req.uli.lai2); } if (change_not_req->uli.tai) { chn_not_req.uli.tai = context->uli.tai; chn_not_req.uli.tai2.tai_mcc_digit_2 = change_not_req->uli.tai2.tai_mcc_digit_2; chn_not_req.uli.tai2.tai_mcc_digit_1 = change_not_req->uli.tai2.tai_mcc_digit_1; chn_not_req.uli.tai2.tai_mnc_digit_3 = change_not_req->uli.tai2.tai_mnc_digit_3; chn_not_req.uli.tai2.tai_mcc_digit_3 = change_not_req->uli.tai2.tai_mcc_digit_3; chn_not_req.uli.tai2.tai_mnc_digit_2 = change_not_req->uli.tai2.tai_mnc_digit_2; chn_not_req.uli.tai2.tai_mnc_digit_1 = change_not_req->uli.tai2.tai_mnc_digit_1; chn_not_req.uli.tai2.tai_tac = change_not_req->uli.tai2.tai_tac; len += sizeof(chn_not_req.uli.tai2); } if (change_not_req->uli.rai) { chn_not_req.uli.rai = change_not_req->uli.rai; chn_not_req.uli.rai2.ria_mcc_digit_2 = change_not_req->uli.rai2.ria_mcc_digit_2; chn_not_req.uli.rai2.ria_mcc_digit_1 = change_not_req->uli.rai2.ria_mcc_digit_1; chn_not_req.uli.rai2.ria_mnc_digit_3 = change_not_req->uli.rai2.ria_mnc_digit_3; chn_not_req.uli.rai2.ria_mcc_digit_3 = change_not_req->uli.rai2.ria_mcc_digit_3; chn_not_req.uli.rai2.ria_mnc_digit_2 = change_not_req->uli.rai2.ria_mnc_digit_2; chn_not_req.uli.rai2.ria_mnc_digit_1 = change_not_req->uli.rai2.ria_mnc_digit_1; chn_not_req.uli.rai2.ria_lac = change_not_req->uli.rai2.ria_lac; chn_not_req.uli.rai2.ria_rac = change_not_req->uli.rai2.ria_rac; len += sizeof(chn_not_req.uli.rai2); } if (change_not_req->uli.sai) { chn_not_req.uli.sai = context->uli.sai; chn_not_req.uli.sai2.sai_mcc_digit_2 = change_not_req->uli.sai2.sai_mcc_digit_2; chn_not_req.uli.sai2.sai_mcc_digit_1 = change_not_req->uli.sai2.sai_mcc_digit_1; chn_not_req.uli.sai2.sai_mnc_digit_3 = change_not_req->uli.sai2.sai_mnc_digit_3; chn_not_req.uli.sai2.sai_mcc_digit_3 = change_not_req->uli.sai2.sai_mcc_digit_3; chn_not_req.uli.sai2.sai_mnc_digit_2 = change_not_req->uli.sai2.sai_mnc_digit_2; chn_not_req.uli.sai2.sai_mnc_digit_1 = change_not_req->uli.sai2.sai_mnc_digit_1; chn_not_req.uli.sai2.sai_lac = change_not_req->uli.sai2.sai_lac; chn_not_req.uli.sai2.sai_sac = change_not_req->uli.sai2.sai_sac; len += sizeof(chn_not_req.uli.sai2); } if (change_not_req->uli.cgi) { chn_not_req.uli.cgi = change_not_req->uli.cgi; chn_not_req.uli.cgi2.cgi_mcc_digit_2 = change_not_req->uli.cgi2.cgi_mcc_digit_2; chn_not_req.uli.cgi2.cgi_mcc_digit_1 = change_not_req->uli.cgi2.cgi_mcc_digit_1; chn_not_req.uli.cgi2.cgi_mnc_digit_3 = change_not_req->uli.cgi2.cgi_mnc_digit_3; chn_not_req.uli.cgi2.cgi_mcc_digit_3 = change_not_req->uli.cgi2.cgi_mcc_digit_3; chn_not_req.uli.cgi2.cgi_mnc_digit_2 = change_not_req->uli.cgi2.cgi_mnc_digit_2; chn_not_req.uli.cgi2.cgi_mnc_digit_1 = change_not_req->uli.cgi2.cgi_mnc_digit_1; chn_not_req.uli.cgi2.cgi_lac = change_not_req->uli.cgi2.cgi_lac; chn_not_req.uli.cgi2.cgi_ci = context->uli.cgi2.cgi_ci; len += sizeof(chn_not_req.uli.cgi2); } if (change_not_req->uli.ecgi) { chn_not_req.uli.ecgi = change_not_req->uli.ecgi; chn_not_req.uli.ecgi2.ecgi_mcc_digit_2 = change_not_req->uli.ecgi2.ecgi_mcc_digit_2; chn_not_req.uli.ecgi2.ecgi_mcc_digit_1 = change_not_req->uli.ecgi2.ecgi_mcc_digit_1; chn_not_req.uli.ecgi2.ecgi_mnc_digit_3 = change_not_req->uli.ecgi2.ecgi_mnc_digit_3; chn_not_req.uli.ecgi2.ecgi_mcc_digit_3 = change_not_req->uli.ecgi2.ecgi_mcc_digit_3; chn_not_req.uli.ecgi2.ecgi_mnc_digit_2 = change_not_req->uli.ecgi2.ecgi_mnc_digit_2; chn_not_req.uli.ecgi2.ecgi_mnc_digit_1 = change_not_req->uli.ecgi2.ecgi_mnc_digit_1; chn_not_req.uli.ecgi2.ecgi_spare = change_not_req->uli.ecgi2.ecgi_spare; chn_not_req.uli.ecgi2.eci = change_not_req->uli.ecgi2.eci; len += sizeof(chn_not_req.uli.ecgi2); } if (change_not_req->uli.macro_enodeb_id) { chn_not_req.uli.macro_enodeb_id = change_not_req->uli.macro_enodeb_id; chn_not_req.uli.macro_enodeb_id2.menbid_mcc_digit_2 = change_not_req->uli.macro_enodeb_id2.menbid_mcc_digit_2; chn_not_req.uli.macro_enodeb_id2.menbid_mcc_digit_1 = change_not_req->uli.macro_enodeb_id2.menbid_mcc_digit_1; chn_not_req.uli.macro_enodeb_id2.menbid_mnc_digit_3 = change_not_req->uli.macro_enodeb_id2.menbid_mnc_digit_3; chn_not_req.uli.macro_enodeb_id2.menbid_mcc_digit_3 = change_not_req->uli.macro_enodeb_id2.menbid_mcc_digit_3; chn_not_req.uli.macro_enodeb_id2.menbid_mnc_digit_2 = change_not_req->uli.macro_enodeb_id2.menbid_mnc_digit_2; chn_not_req.uli.macro_enodeb_id2.menbid_mnc_digit_1 = change_not_req->uli.macro_enodeb_id2.menbid_mnc_digit_1; chn_not_req.uli.macro_enodeb_id2.menbid_spare = change_not_req->uli.macro_enodeb_id2.menbid_spare; chn_not_req.uli.macro_enodeb_id2.menbid_macro_enodeb_id = change_not_req->uli.macro_enodeb_id2.menbid_macro_enodeb_id; chn_not_req.uli.macro_enodeb_id2.menbid_macro_enb_id2 = change_not_req->uli.macro_enodeb_id2.menbid_macro_enb_id2; len += sizeof(chn_not_req.uli.macro_enodeb_id2); } if (change_not_req->uli.extnded_macro_enb_id) { chn_not_req.uli.extnded_macro_enb_id = change_not_req->uli.extnded_macro_enb_id; chn_not_req.uli.extended_macro_enodeb_id2.emenbid_mcc_digit_1 = change_not_req->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_1; chn_not_req.uli.extended_macro_enodeb_id2.emenbid_mnc_digit_3 = change_not_req->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_3; chn_not_req.uli.extended_macro_enodeb_id2.emenbid_mcc_digit_3 = change_not_req->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_3; chn_not_req.uli.extended_macro_enodeb_id2.emenbid_mnc_digit_2 = change_not_req->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_2; chn_not_req.uli.extended_macro_enodeb_id2.emenbid_mnc_digit_1 = change_not_req->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_1; chn_not_req.uli.extended_macro_enodeb_id2.emenbid_smenb = change_not_req->uli.extended_macro_enodeb_id2.emenbid_smenb; chn_not_req.uli.extended_macro_enodeb_id2.emenbid_spare = change_not_req->uli.extended_macro_enodeb_id2.emenbid_spare; chn_not_req.uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id = change_not_req->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id; chn_not_req.uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2 = change_not_req->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2; len += sizeof(chn_not_req.uli.extended_macro_enodeb_id2); } len += 1; set_ie_header(&chn_not_req.uli.header, GTP_IE_USER_LOC_INFO, IE_INSTANCE_ZERO, len); } if(context->pra_flag){ set_presence_reporting_area_info_ie(&chn_not_req.pres_rptng_area_info, context); context->pra_flag = 0; } if(change_not_req->rat_type.header.len !=0 ) { set_ie_header(&chn_not_req.rat_type.header, GTP_IE_RAT_TYPE, IE_INSTANCE_ZERO, sizeof(gtp_rat_type_ie_t) - sizeof(ie_header_t)); chn_not_req.rat_type.rat_type = change_not_req->rat_type.rat_type; } if(change_not_req->uci.header.len !=0 ) { set_ie_header(&chn_not_req.rat_type.header,GTP_IE_USER_LOC_INFO, IE_INSTANCE_ZERO, sizeof(gtp_rat_type_ie_t) - sizeof(ie_header_t)); } chn_not_req.second_rat_count = change_not_req->second_rat_count; uint8_t flag_pgwc_second_rat = 0; if(chn_not_req.second_rat_count != 0) { for(uint8_t i =0; i< change_not_req->second_rat_count; i++) { uint8_t trigg_buff[] = "Secondary_rat_usage"; if(change_not_req->secdry_rat_usage_data_rpt[i].irsgw == 1) { cdr second_rat_data ; struct timeval unix_start_time; struct timeval unix_end_time; if(change_not_req->secdry_rat_usage_data_rpt[i].irsgw == 1) { flag_pgwc_second_rat++; } second_rat_data.cdr_type = CDR_BY_SEC_RAT; second_rat_data.change_rat_type_flag = 1; /*rat type in sec_rat_usage_rpt is NR=0 i.e RAT is 10 as per spec 29.274*/ second_rat_data.rat_type = (change_not_req->secdry_rat_usage_data_rpt[i].secdry_rat_type == 0) ? 10 : 0; second_rat_data.bearer_id = change_not_req->lbi.ebi_ebi; second_rat_data.seid = pdn->seid; second_rat_data.imsi = pdn->context->imsi; second_rat_data.start_time = change_not_req->secdry_rat_usage_data_rpt[i].start_timestamp; second_rat_data.end_time = change_not_req->secdry_rat_usage_data_rpt[i].end_timestamp; second_rat_data.data_volume_uplink = change_not_req->secdry_rat_usage_data_rpt[i].usage_data_ul; second_rat_data.data_volume_downlink = change_not_req->secdry_rat_usage_data_rpt[i].usage_data_dl; ntp_to_unix_time(&change_not_req->secdry_rat_usage_data_rpt[i].start_timestamp,&unix_start_time); ntp_to_unix_time(&change_not_req->secdry_rat_usage_data_rpt[i].end_timestamp,&unix_end_time); second_rat_data.duration_meas = unix_end_time.tv_sec - unix_start_time.tv_sec; second_rat_data.data_start_time = 0; second_rat_data.data_end_time = 0; second_rat_data.total_data_volume = change_not_req->secdry_rat_usage_data_rpt[i].usage_data_ul + change_not_req->secdry_rat_usage_data_rpt[i].usage_data_dl; memcpy(&second_rat_data.trigg_buff, &trigg_buff, sizeof(trigg_buff)); if(generate_cdr_info(&second_rat_data) == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"failed to generate CDR\n", LOG_VALUE); return -1; } } else if(change_not_req->secdry_rat_usage_data_rpt[i].irpgw == 1) { flag_pgwc_second_rat++; } else{ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IRPGW and IRSGW not set " "not expected from MME\n", LOG_VALUE); } } } if((flag_pgwc_second_rat == 0) && (change_not_req->uli.header.len == 0)) { bzero(&tx_buf, sizeof(tx_buf)); gtpv2c_header_t *gtpv2c_tx = (gtpv2c_header_t *)tx_buf; set_change_notification_response(gtpv2c_tx, pdn); payload_length = ntohs(gtpv2c_tx->gtpc.message_len) + sizeof(gtpv2c_tx->gtpc); ret = set_dest_address(pdn->context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } gtpv2c_send(s11_fd, s11_fd_v6, tx_buf, payload_length, s11_mme_sockaddr, SENT); /* copy packet for user level packet copying or li */ if (context->dupl) { process_pkt_for_li( context, S11_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s11_mme_sockaddr.type, config.s11_ip.s_addr, config.s11_ip_v6.s6_addr), fill_ip_info(s11_mme_sockaddr.type, s11_mme_sockaddr.ipv4.sin_addr.s_addr, s11_mme_sockaddr.ipv6.sin6_addr.s6_addr), config.s11_port, ((s11_mme_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s11_mme_sockaddr.ipv4.sin_port) : ntohs(s11_mme_sockaddr.ipv6.sin6_port))); } pdn->state = CONNECTED_STATE; return 0; } if(chn_not_req.second_rat_count != 0) { for(uint8_t i =0; i< change_not_req->second_rat_count; i++) { if((change_not_req->secdry_rat_usage_data_rpt[i].irpgw == 1)) { set_ie_header(&chn_not_req.secdry_rat_usage_data_rpt[i].header, GTP_IE_SECDRY_RAT_USAGE_DATA_RPT, instance, sizeof(gtp_secdry_rat_usage_data_rpt_ie_t) - sizeof(ie_header_t)); chn_not_req.secdry_rat_usage_data_rpt[i].spare2 = 0; chn_not_req.secdry_rat_usage_data_rpt[i].irsgw = change_not_req->secdry_rat_usage_data_rpt[i].irsgw; chn_not_req.secdry_rat_usage_data_rpt[i].irpgw = change_not_req->secdry_rat_usage_data_rpt[i].irpgw; chn_not_req.secdry_rat_usage_data_rpt[i].secdry_rat_type = change_not_req->secdry_rat_usage_data_rpt[i].secdry_rat_type; chn_not_req.secdry_rat_usage_data_rpt[i].ebi = change_not_req->secdry_rat_usage_data_rpt[i].ebi; chn_not_req.secdry_rat_usage_data_rpt[i].spare3 = change_not_req->secdry_rat_usage_data_rpt[i].spare3; chn_not_req.secdry_rat_usage_data_rpt[i].start_timestamp = change_not_req->secdry_rat_usage_data_rpt[i].start_timestamp; chn_not_req.secdry_rat_usage_data_rpt[i].end_timestamp = change_not_req->secdry_rat_usage_data_rpt[i].end_timestamp; chn_not_req.secdry_rat_usage_data_rpt[i].usage_data_dl = change_not_req->secdry_rat_usage_data_rpt[i].usage_data_dl; chn_not_req.secdry_rat_usage_data_rpt[i].usage_data_ul = change_not_req->secdry_rat_usage_data_rpt[i].usage_data_ul; instance++; } } } struct resp_info *resp= NULL; ret = get_sess_entry(pdn->seid , &resp); if(ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session entry found " "for seid: %lu", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } reset_resp_info_structure(resp); *_pdn = pdn; resp->state = CONNECTED_STATE; resp->proc = CHANGE_NOTIFICATION_PROC; payload_length = encode_change_noti_req(&chn_not_req, (uint8_t *)gtpv2c_tx); ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } gtpv2c_send(s5s8_fd, s5s8_fd_v6, tx_buf, payload_length, s5s8_recv_sockaddr, SENT); cp_mode = pdn->context->cp_mode; add_gtpv2c_if_timer_entry( change_not_req->header.teid.has_teid.teid, &s5s8_recv_sockaddr, tx_buf, payload_length, ebi_index, S5S8_IFACE, cp_mode); /* copy packet for user level packet copying or li */ if (context->dupl) { process_pkt_for_li( context, S5S8_C_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s5s8_recv_sockaddr.type, config.s5s8_ip.s_addr, config.s5s8_ip_v6.s6_addr), fill_ip_info(s5s8_recv_sockaddr.type, s5s8_recv_sockaddr.ipv4.sin_addr.s_addr, s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr), config.s5s8_port, ((s5s8_recv_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s5s8_recv_sockaddr.ipv4.sin_port) : ntohs(s5s8_recv_sockaddr.ipv6.sin6_port))); } return 0; } /** * @brief : Set the Change Notification Response gtpv2c message * @param : gtpv2c_tx * transmission buffer to contain 'modify bearer request' message * @param : pdn_connection structre pointer * @return : Returns nothing */ void set_change_notification_response(gtpv2c_header_t *gtpv2c_tx, pdn_connection *pdn) { change_noti_rsp_t chn_not_rsp = {0}; if (pdn->context->cp_mode == PGWC) { set_gtpv2c_teid_header((gtpv2c_header_t *) &chn_not_rsp, GTP_CHANGE_NOTIFICATION_RSP, pdn->s5s8_sgw_gtpc_teid, pdn->context->sequence, 0); } else { set_gtpv2c_teid_header((gtpv2c_header_t *) &chn_not_rsp, GTP_CHANGE_NOTIFICATION_RSP, pdn->context->s11_mme_gtpc_teid, pdn->context->sequence, 0); } chn_not_rsp.imsi.imsi_number_digits = pdn->context->imsi; set_ie_header(&chn_not_rsp.imsi.header, GTP_IE_IMSI, IE_INSTANCE_ZERO, pdn->context->imsi_len); set_cause_accepted(&chn_not_rsp.cause, IE_INSTANCE_ZERO); if(pdn->context->pra_flag){ set_presence_reporting_area_action_ie(&chn_not_rsp.pres_rptng_area_act, pdn->context); pdn->context->pra_flag = 0; } encode_change_noti_rsp(&chn_not_rsp, (uint8_t *)gtpv2c_tx); }
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/pfcp_util.c
<gh_stars>0 /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <sys/time.h> #include <rte_hash.h> #include <rte_errno.h> #include <rte_debug.h> #include <rte_jhash.h> #include <rte_lcore.h> #include <rte_hash_crc.h> #include "li_interface.h" #include "gw_adapter.h" #include "pfcp_enum.h" #include "pfcp_util.h" #include "pfcp_set_ie.h" #include "pfcp_messages.h" #include "../cp_dp_api/tcp_client.h" #include "pfcp_messages_decoder.h" #ifdef CP_BUILD #include "cp_config.h" #include "sm_pcnd.h" #include "cp_timer.h" #include "cp_stats.h" #include "li_config.h" #include "pfcp_session.h" #include "gtpv2c_error_rsp.h" #include "cdnshelper.h" #endif /* CP_BUILD */ extern int pfcp_fd; extern int pfcp_fd_v6; extern void *ddf2_fd; struct rte_hash *heartbeat_recovery_hash; struct rte_hash *associated_upf_hash; extern int clSystemLog; #ifdef CP_BUILD extern pfcp_config_t config; /** * @brief : free canonical result list * @param : result , result list * @param : res_count , total entries in result * @return : Returns nothing */ static void free_canonical_result_list(canonical_result_t *result, uint8_t res_count) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Free DNS canonical result list :: SART \n", LOG_VALUE); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"DNS result count: %d \n", LOG_VALUE, res_count); for (uint8_t itr = 0; itr < res_count; itr++) { if (result[itr].host1_info.ipv4_hosts != NULL) { for (uint8_t itr1 = 0; itr1 < result[itr].host1_info.ipv4host_count; itr1++) { if (result[itr].host1_info.ipv4_hosts[itr1] != NULL) { free(result[itr].host1_info.ipv4_hosts[itr1]); result[itr].host1_info.ipv4_hosts[itr1] = NULL; } } free(result[itr].host1_info.ipv4_hosts); result[itr].host1_info.ipv4_hosts = NULL; } if (result[itr].host1_info.ipv6_hosts != NULL) { for (uint8_t itr2 = 0; itr2 < result[itr].host1_info.ipv6host_count; itr2++) { if (result[itr].host1_info.ipv6_hosts[itr2] != NULL) { free(result[itr].host1_info.ipv6_hosts[itr2]); result[itr].host1_info.ipv6_hosts[itr2] = NULL; } } free(result[itr].host1_info.ipv6_hosts); result[itr].host1_info.ipv6_hosts = NULL; } if (result[itr].host2_info.ipv4_hosts != NULL) { for (uint8_t itr3 = 0; itr3 < result[itr].host2_info.ipv4host_count; itr3++) { if (result[itr].host2_info.ipv4_hosts[itr3] != NULL) { free(result[itr].host2_info.ipv4_hosts[itr3]); result[itr].host2_info.ipv4_hosts[itr3] = NULL; } } free(result[itr].host2_info.ipv4_hosts); result[itr].host2_info.ipv4_hosts = NULL; } if (result[itr].host2_info.ipv6_hosts != NULL) { for (uint8_t itr4 = 0; itr4 < result[itr].host2_info.ipv6host_count; itr4++) { if (result[itr].host2_info.ipv6_hosts[itr4] != NULL) { free(result[itr].host2_info.ipv6_hosts[itr4]); result[itr].host2_info.ipv6_hosts[itr4] = NULL; } } free(result[itr].host2_info.ipv6_hosts); result[itr].host2_info.ipv6_hosts = NULL; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Free DNS canonical result list :: END \n", LOG_VALUE); } /** * @brief : free DNS result list * @param : result , result list * @param : res_count , total entries in result * @return : Returns nothing */ static void free_dns_result_list(dns_query_result_t *res, uint8_t res_count) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Free DNS result list :: SART \n", LOG_VALUE); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"DNS result count: %d \n", LOG_VALUE, res_count); for (uint8_t itr = 0; itr < res_count; itr++) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPV4 DNS result count: %d \n", LOG_VALUE, res[itr].ipv4host_count); if (res[itr].ipv4_hosts != NULL) { for (uint8_t itr1 = 0; itr1 < res[itr].ipv4host_count; itr1++) { if (res[itr].ipv4_hosts[itr1] != NULL) { free(res[itr].ipv4_hosts[itr1]); res[itr].ipv4_hosts[itr1] = NULL; } } free(res[itr].ipv4_hosts); res[itr].ipv4_hosts = NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPV6 DNS result count: %d \n", LOG_VALUE, res[itr].ipv6host_count); if (res[itr].ipv6_hosts != NULL) { for (uint8_t itr2 = 0; itr2 < res[itr].ipv6host_count; itr2++) { if (res[itr].ipv6_hosts[itr2] != NULL) { free(res[itr].ipv6_hosts[itr2]); res[itr].ipv6_hosts[itr2] = NULL; } } free(res[itr].ipv6_hosts); res[itr].ipv6_hosts = NULL; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Free DNS result list :: END \n", LOG_VALUE); } static void add_dns_result_v6(dns_query_result_t *res, upfs_dnsres_t *upf_list, uint8_t i, uint8_t *upf_v6_cnt) { for (int j = 0; j < res[i].ipv6host_count; j++) { int flag_added = false; /* TODO:: duplicate entries should not be present in result itself */ if(upf_list->upf_count == 0){ inet_pton(AF_INET6, res[i].ipv6_hosts[j], &(upf_list->upf_ip[upf_list->upf_count].ipv6)); memcpy(upf_list->upf_fqdn[upf_list->upf_count], res[i].hostname, strnlen((char *)res[i].hostname,MAX_HOSTNAME_LENGTH)); flag_added = TRUE; }else{ int match_found = false; for (int k = 0; k < upf_list->upf_count ; k++) { struct in6_addr temp_ip6; inet_pton(AF_INET6, res[i].ipv6_hosts[j], temp_ip6.s6_addr); uint8_t ret = memcmp(temp_ip6.s6_addr, upf_list->upf_ip[k].ipv6.s6_addr, IPV6_ADDRESS_LEN); if (!ret) { break; } } if(match_found == false){ inet_pton(AF_INET6, res[i].ipv6_hosts[j], &upf_list->upf_ip[upf_list->upf_count].ipv6); memcpy(upf_list->upf_fqdn[upf_list->upf_count], res[i].hostname, strnlen((char *)res[i].hostname,MAX_HOSTNAME_LENGTH)); flag_added = TRUE; } } if(flag_added == TRUE){ *upf_v6_cnt += 1; } } upf_list->upf_ip_type = PDN_TYPE_IPV6; } static void add_dns_result_v4(dns_query_result_t *res, upfs_dnsres_t *upf_list, uint8_t i, uint8_t *upf_v4_cnt) { for (int j = 0; j < res[i].ipv4host_count; j++) { int flag_added = false; /* TODO:: duplicate entries should not be present in result itself */ if(upf_list->upf_count == 0) { inet_aton(res[i].ipv4_hosts[j], &upf_list->upf_ip[upf_list->upf_count].ipv4); memcpy(upf_list->upf_fqdn[upf_list->upf_count], res[i].hostname, strnlen((char *)res[i].hostname,MAX_HOSTNAME_LENGTH)); flag_added = TRUE; } else { int match_found = false; for (int k = 0; k < upf_list->upf_count ; k++) { struct in_addr temp_ip; inet_aton(res[i].ipv4_hosts[j], &temp_ip); if( temp_ip.s_addr == upf_list->upf_ip[k].ipv4.s_addr){ break; } } if(match_found == false){ inet_aton(res[i].ipv4_hosts[j], &upf_list->upf_ip[upf_list->upf_count].ipv4); memcpy(upf_list->upf_fqdn[upf_list->upf_count], res[i].hostname, strnlen((char *)res[i].hostname,MAX_HOSTNAME_LENGTH)); flag_added = TRUE; } } if(flag_added == TRUE){ *upf_v4_cnt += 1; } } upf_list->upf_ip_type = PDN_TYPE_IPV4; } static void add_canonical_result_v4(canonical_result_t *res, upfs_dnsres_t *upf_list, uint8_t i, uint8_t *upf_v4_cnt) { for (int j = 0; j < res[i].host2_info.ipv4host_count; j++) { int flag_added = false; /* TODO:: duplicate entries should not be present in result itself */ if(upf_list->upf_count == 0){ inet_aton(res[i].host2_info.ipv4_hosts[j], &upf_list->upf_ip[upf_list->upf_count].ipv4); memcpy(upf_list->upf_fqdn[upf_list->upf_count], res[i].cano_name2, strnlen((char *)res[i].cano_name2,MAX_HOSTNAME_LENGTH)); flag_added = TRUE; } else { int match_found = false; for (int k = 0; k < upf_list->upf_count ; k++) { struct in_addr temp_ip; inet_aton(res[i].host2_info.ipv4_hosts[j], &temp_ip); if( temp_ip.s_addr == upf_list->upf_ip[k].ipv4.s_addr){ match_found = true; break; } } if(match_found == false){ inet_aton(res[i].host2_info.ipv4_hosts[j], &upf_list->upf_ip[upf_list->upf_count].ipv4); memcpy(upf_list->upf_fqdn[upf_list->upf_count], res[i].cano_name2, strnlen((char *)res[i].cano_name2,MAX_HOSTNAME_LENGTH)); flag_added = TRUE; } } if(flag_added == TRUE){ *upf_v4_cnt += 1; } } upf_list->upf_ip_type = PDN_TYPE_IPV4; } static void add_canonical_result_v6(canonical_result_t *res, upfs_dnsres_t *upf_list, uint8_t i, uint8_t *upf_v6_cnt) { for (int j = 0; j < res[i].host2_info.ipv6host_count; j++) { int flag_added = false; /* TODO:: duplicate entries should not be present in result itself */ if(upf_list->upf_count == 0){ inet_pton(AF_INET6, res[i].host2_info.ipv6_hosts[j], &(upf_list->upf_ip[upf_list->upf_count].ipv6)); memcpy(upf_list->upf_fqdn[upf_list->upf_count], res[i].cano_name2, strnlen((char *)res[i].cano_name2,MAX_HOSTNAME_LENGTH)); flag_added = TRUE; }else{ int match_found = false; for (int k = 0; k < upf_list->upf_count; k++) { char ipv6[IPV6_STR_LEN]; inet_ntop(AF_INET6, upf_list->upf_ip[k].ipv6.s6_addr, ipv6, IPV6_ADDRESS_LEN); uint8_t ret = strncmp(res[i].host2_info.ipv6_hosts[j], ipv6 , IPV6_ADDRESS_LEN); if (!ret) { match_found = true; break; } } if(match_found == false){ inet_pton(AF_INET6, res[i].host2_info.ipv6_hosts[j], &upf_list->upf_ip[upf_list->upf_count].ipv6); memcpy(upf_list->upf_fqdn[upf_list->upf_count], res[i].cano_name2, strnlen((char *)res[i].cano_name2,MAX_HOSTNAME_LENGTH)); flag_added = TRUE; } } if(flag_added == TRUE){ *upf_v6_cnt += 1; } } upf_list->upf_ip_type = PDN_TYPE_IPV6; } /** * @brief : Add canonical result entry in upflist hash * @param : res , result * @param : res_count , total entries in result * @param : imsi_val , imsi value * @param : imsi_len , imsi length * @return : Returns upf count in case of success , 0 if could not get list , -1 otherwise */ static int add_canonical_result_upflist_entry(canonical_result_t *res, uint8_t res_count, uint64_t *imsi_val, uint16_t imsi_len) { uint8_t count = 0;; upfs_dnsres_t *upf_list = rte_zmalloc_socket(NULL, sizeof(upfs_dnsres_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (NULL == upf_list) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for UPF list, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); free_canonical_result_list(res, res_count); return -1; } for (int i = 0; (upf_list->upf_count < res_count) && (i < QUERY_RESULT_COUNT); i++) { uint8_t upf_v4_cnt = 0, upf_v6_cnt = 0; if (res[i].host2_info.ipv6host_count == 0 && res[i].host2_info.ipv4host_count == 0) { count += 1; continue; } if (res[i].host2_info.ipv6host_count) { add_canonical_result_v6(res, upf_list, count, &upf_v6_cnt); } if (res[i].host2_info.ipv4host_count) { add_canonical_result_v4(res, upf_list, count, &upf_v4_cnt); } count += 1; if (upf_v4_cnt != 0 || upf_v6_cnt != 0) upf_list->upf_count += 1; } if (upf_list->upf_count == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Could not get collocated " "candidate list.\n", LOG_VALUE); return 0; } upflist_by_ue_hash_entry_add(imsi_val, imsi_len, upf_list); free_canonical_result_list(res, res_count); return upf_list->upf_count; } /** * @brief : Add dns result in upflist hash * @param : res , dns result * @param : res_count , total entries in result * @param : imsi_val , imsi value * @param : imsi_len , imsi length * @return : Returns upf count in case of success , 0 if could not get list , -1 otherwise */ static int add_dns_result_upflist_entry(dns_query_result_t *res, uint8_t res_count, uint64_t *imsi_val, uint16_t imsi_len) { uint8_t count = 0; upfs_dnsres_t *upf_list = NULL; int ret = rte_hash_lookup_data(upflist_by_ue_hash, &imsi_val, (void**)&upf_list); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Failed to search entry in upflist_by_ue_hash" "hash table", LOG_VALUE); upf_list = rte_zmalloc_socket(NULL, sizeof(upfs_dnsres_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (NULL == upf_list) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for UPF list, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); free_dns_result_list(res, res_count); return -1; } } for (int i = 0; (upf_list->upf_count < res_count) && (i < QUERY_RESULT_COUNT); i++) { uint8_t upf_v4_cnt = 0, upf_v6_cnt = 0; if (res[i].ipv6host_count == 0 && res[i].ipv4host_count == 0) { count += 1; continue; } if (res[i].ipv6host_count) { add_dns_result_v6(res, upf_list, count, &upf_v6_cnt); } if (res[i].ipv4host_count) { add_dns_result_v4(res, upf_list, count, &upf_v4_cnt); } count += 1; if (upf_v4_cnt != 0 || upf_v6_cnt != 0) upf_list->upf_count += 1; } if (upf_list->upf_count == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Could not get SGW-U " "list using DNS query \n", LOG_VALUE); return 0; } upflist_by_ue_hash_entry_add(imsi_val, imsi_len, upf_list); return upf_list->upf_count; } /** * @brief : Record entries for failed enodeb * @param : endid , enodeb id * @return : Returns 0 in case of success , -1 otherwise */ static int record_failed_enbid(char *enbid) { FILE *fp = fopen(FAILED_ENB_FILE, "a"); if (fp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Could not open %s for writing failed " "eNodeB query entry.\n", LOG_VALUE, FAILED_ENB_FILE); return 1; } fwrite(enbid, sizeof(char), strnlen(enbid,MAX_ENODEB_LEN), fp); fwrite("\n", sizeof(char), 1, fp); fclose(fp); return 0; } /** * @brief : get mnc mcc into string. * @param : pdn, structure to store retrived pdn. * @param : mnc, pointer var. to store mnc string. * @param : mcc, pointer var. to store mcc string. * @return : Returns 0 in case of success , -1 otherwise */ static void get_mnc_mcc(pdn_connection *pdn, char *mnc, char *mcc) { ue_context *ctxt = NULL; ctxt = pdn->context; if (ctxt->uli.ecgi2.ecgi_mnc_digit_3 == 15) snprintf(mnc, MCC_MNC_LEN, "%u%u", ctxt->uli.ecgi2.ecgi_mnc_digit_1, ctxt->uli.ecgi2.ecgi_mnc_digit_2); else snprintf(mnc, MCC_MNC_LEN, "%u%u%u", ctxt->uli.ecgi2.ecgi_mnc_digit_1, ctxt->uli.ecgi2.ecgi_mnc_digit_2, ctxt->uli.ecgi2.ecgi_mnc_digit_3); snprintf(mcc, MCC_MNC_LEN,"%u%u%u", ctxt->uli.ecgi2.ecgi_mcc_digit_1, ctxt->uli.ecgi2.ecgi_mcc_digit_2, ctxt->uli.ecgi2.ecgi_mcc_digit_3); } /** * @brief : set ue cap. and uses type. * @param : node_sel, node selector. * @param : pdn, structure to store retrived pdn. * @return : Returns 0 in case of success , -1 otherwise */ static void set_ue_cap_ue_uses(void *node_sel, pdn_connection *pdn) { if(strnlen(pdn->apn_in_use->apn_net_cap,MAX_NETCAP_LEN) > 0) { set_nwcapability(node_sel, pdn->apn_in_use->apn_net_cap); } if (pdn->apn_in_use->apn_usage_type != -1) { set_ueusage_type(node_sel, pdn->apn_in_use->apn_usage_type); } } /** * @brief : get mnc mcc into string * @param : pdn, structure to store retrived pdn. * @return : Returns 0 in case of success , -1 otherwise */ static int send_tac_dns_query(pdn_connection *pdn) { /* Query DNS based on lb and hb of tac */ char lb[LB_HB_LEN] = {0}; char hb[LB_HB_LEN] = {0}; char mnc[MCC_MNC_LEN] = {0}; char mcc[MCC_MNC_LEN] = {0}; char enodeb[MAX_ENODEB_LEN] = {0}; uint32_t enbid = 0; dns_cb_userdata_t *cb_user_data = NULL; ue_context *ctxt = NULL; ctxt = pdn->context; enbid = ctxt->uli.ecgi2.eci >> 8; snprintf(enodeb, ENODE_LEN,"%u", enbid); record_failed_enbid(enodeb); if (ctxt->uli.tai != 1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT " Could not get SGW-U list using DNS " "query. TAC missing in CSR.\n", LOG_VALUE); return -1; } get_mnc_mcc(pdn, mnc, mcc); snprintf(lb, LB_HB_LEN, "%u", ctxt->uli.tai2.tai_tac & 0xFF); snprintf(hb, LB_HB_LEN, "%u", (ctxt->uli.tai2.tai_tac >> 8) & 0xFF); cb_user_data = rte_zmalloc_socket(NULL, sizeof(dns_cb_userdata_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (cb_user_data == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for DNS user data, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } void *sgwupf_node_sel = init_sgwupf_node_selector(lb, hb, mnc, mcc); set_desired_proto(sgwupf_node_sel, UPF_X_SXA); set_ue_cap_ue_uses(sgwupf_node_sel, pdn); cb_user_data->cb = dns_callback; cb_user_data->data = pdn; cb_user_data->obj_type = SGWUPFNODESELECTOR; process_dnsreq_async(sgwupf_node_sel, cb_user_data); return 0; } /** * @brief : get UPF address list. * @param : node_sel, node selector info. * @param : pdn, structure to store retrived pdn. * @return : Returns 0 in case of success , -1 otherwise */ static int get_upf_list(void *node_sel, pdn_connection *pdn) { int upf_count = 0; int res_count = 0; ue_context *ctxt = NULL; canonical_result_t result[QUERY_RESULT_COUNT] = {0}; ctxt = pdn->context; /* Get collocated candidate list */ if (!strnlen((char *)pdn->fqdn,MAX_HOSTNAME_LENGTH)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "SGW-U node name missing in Create Session Request. \n", LOG_VALUE); deinit_node_selector(node_sel); return 0; } res_count = get_colocated_candlist_fqdn( (char *)pdn->fqdn, node_sel, result); if (res_count == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Could not get collocated candidate list. \n", LOG_VALUE); deinit_node_selector(node_sel); return 0; } upf_count = add_canonical_result_upflist_entry(result, res_count, &ctxt->imsi, sizeof(ctxt->imsi)); return upf_count; } static void set_dns_resp_status(pdn_connection *pdn, void *node_sel) { uint8_t node_sel_type = 0; node_sel_type = get_node_selector_type(node_sel); switch(node_sel_type) { case PGWUPFNODESELECTOR: { /*apn base query response received */ pdn->dns_query_domain |= APN_BASE_QUERY; break; } case ENBUPFNODESELECTOR: { /* enB base query response received */ pdn->dns_query_domain |= ENODEB_BASE_QUERY; pdn->enb_query_flag = ENODEB_BASE_QUERY; break; } case SGWUPFNODESELECTOR: { /* Tac base query response received */ pdn->dns_query_domain |= TAC_BASE_QUERY; break; } } } int dns_callback(void *node_sel, void *data, void *user_data) { uint16_t res_count = 0,canonical_res_count = 0; int ret = 0; pdn_connection *pdn = NULL; ue_context *ctxt = NULL; if (user_data != NULL) { rte_free(user_data); user_data = NULL; } pdn = (pdn_connection *) data; if (pdn == NULL) return 0; ctxt = pdn->context; dns_query_result_t res_list[QUERY_RESULT_COUNT] = {0}; set_dns_resp_status(pdn, node_sel); get_dns_query_res(node_sel, res_list, &res_count); if ((res_count == 0) && ((pdn->enb_query_flag & ENODEB_BASE_QUERY) == ENODEB_BASE_QUERY)) { /* * If in Enode base DNS query response doesn't find any UPF address * then we sent tac base DNS query */ /* reseting enB base query bit */ pdn->dns_query_domain &= (1 << ENODEB_BASE_QUERY); pdn->enb_query_flag &= (1 << ENODEB_BASE_QUERY); deinit_node_selector(node_sel); if (send_tac_dns_query(pdn) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "ERROR : while sending TAC base DNS query \n", LOG_VALUE); if (ctxt->s11_sgw_gtpc_teid != 0) { send_error_resp(pdn, GTPV2C_CAUSE_REQUEST_REJECTED); } return 0; } return 0; } if (res_count == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Could not get UPF list using DNS query \n", LOG_VALUE); deinit_node_selector(node_sel); if (pdn != NULL && pdn->node_sel != NULL ) deinit_node_selector(pdn->node_sel); if (ctxt->s11_sgw_gtpc_teid != 0) send_error_resp(pdn, GTPV2C_CAUSE_REQUEST_REJECTED); return 0; } if (ctxt->cp_mode == PGWC) { if (get_upf_list(node_sel, pdn) <= 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Could not get UPF list using DNS query \n", LOG_VALUE); send_error_resp(pdn, GTPV2C_CAUSE_REQUEST_REJECTED); return 0; } } else if (ctxt->cp_mode == SAEGWC) { if ((pdn->node_sel != NULL) && (((pdn->dns_query_domain & TAC_BASE_QUERY) == TAC_BASE_QUERY) || ((pdn->dns_query_domain & ENODEB_BASE_QUERY) == ENODEB_BASE_QUERY)) && ((pdn->dns_query_domain & APN_BASE_QUERY) == APN_BASE_QUERY)) { canonical_result_t result[QUERY_RESULT_COUNT] = {0}; canonical_res_count = get_colocated_candlist(pdn->node_sel, node_sel, result); if (canonical_res_count == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Could not get collocated candidate list. \n", LOG_VALUE); deinit_node_selector(node_sel); deinit_node_selector(pdn->node_sel); send_error_resp(pdn, GTPV2C_CAUSE_REQUEST_REJECTED); return 0; } ret = add_canonical_result_upflist_entry(result, canonical_res_count, &ctxt->imsi, sizeof(ctxt->imsi)); if (ret <= 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to add collocated candidate list. \n", LOG_VALUE); deinit_node_selector(node_sel); deinit_node_selector(pdn->node_sel); send_error_resp(pdn, GTPV2C_CAUSE_REQUEST_REJECTED); return 0; } deinit_node_selector(pdn->node_sel); pdn->node_sel = NULL; } else if (pdn != NULL && pdn->node_sel == NULL) { pdn->node_sel = node_sel; /* Reset eNB query flag, if eNB query resp received */ if(pdn->enb_query_flag == ENODEB_BASE_QUERY) { pdn->enb_query_flag &= (1 << ENODEB_BASE_QUERY); } if (res_count != 0) { free_dns_result_list(res_list, res_count); } return 0; } } else { ret = add_dns_result_upflist_entry(res_list, res_count, &ctxt->imsi, sizeof(ctxt->imsi)); if (ret <= 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to add UFP list entry. \n", LOG_VALUE); deinit_node_selector(node_sel); send_error_resp(pdn, GTPV2C_CAUSE_REQUEST_REJECTED); return 0; } } /*Check If UPF IP is already set or not*/ if (pdn->upf_ip.ip_type == 0) { uint8_t ret = get_upf_ip(pdn->context, pdn); if (!ret) process_pfcp_sess_setup(pdn); else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to extract UPF IP\n", LOG_VALUE); send_error_resp(pdn, ret); } } if (res_count != 0) { free_dns_result_list(res_list, res_count); } pdn->dns_query_domain = NO_DNS_QUERY; deinit_node_selector(node_sel); return 0; } int push_dns_query(pdn_connection *pdn) { char apn_name[MAX_APN_LEN] = {0}; char enodeb[MAX_ENODEB_LEN] = {0}; char mnc[MCC_MNC_LEN] = {0}; char mcc[MCC_MNC_LEN] = {0}; uint32_t enbid = 0; ue_context *ctxt = NULL; if(config.use_dns) { dns_cb_userdata_t *cb_user_data = NULL; /* Retrive the UE context */ ctxt = pdn->context; /* Get enodeb id, mnc, mcc from Create Session Request */ enbid = ctxt->uli.ecgi2.eci >> 8; snprintf(enodeb, ENODE_LEN,"%u", enbid); get_mnc_mcc(pdn, mnc, mcc); /* reseting dns query domain */ pdn->dns_query_domain = NO_DNS_QUERY; if (pdn->context->cp_mode == SGWC || pdn->context->cp_mode == SAEGWC) { cb_user_data = rte_zmalloc_socket(NULL, sizeof(dns_cb_userdata_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (cb_user_data == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to " "allocate ue context structure: %s \n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } void *sgwupf_node_sel = init_enbupf_node_selector(enodeb, mnc, mcc); set_desired_proto(sgwupf_node_sel, UPF_X_SXA); set_ue_cap_ue_uses(sgwupf_node_sel, pdn); cb_user_data->cb = dns_callback; cb_user_data->data = pdn; cb_user_data->obj_type = ENBUPFNODESELECTOR; process_dnsreq_async(sgwupf_node_sel, cb_user_data); } if ((pdn->context->cp_mode == PGWC) || (pdn->context->cp_mode == SAEGWC)) { if (!pdn->apn_in_use) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" APN context not found \n", LOG_VALUE); return 0; } cb_user_data = rte_zmalloc_socket(NULL, sizeof(dns_cb_userdata_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (cb_user_data == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to " "allocate ue context structure: %s \n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } memcpy(apn_name, (pdn->apn_in_use)->apn_name_label + 1, (pdn->apn_in_use)->apn_name_length -1); void *pgwupf_node_sel = init_pgwupf_node_selector(apn_name, mnc, mcc); set_desired_proto(pgwupf_node_sel, UPF_X_SXB); set_ue_cap_ue_uses(pgwupf_node_sel, pdn); cb_user_data->cb = dns_callback; cb_user_data->data = pdn; cb_user_data->obj_type = PGWUPFNODESELECTOR; process_dnsreq_async(pgwupf_node_sel, cb_user_data); } } return 0; } int pfcp_recv(void *msg_payload, uint32_t size, peer_addr_t *peer_addr, bool is_ipv6) { socklen_t v4_addr_len = sizeof(peer_addr->ipv4); socklen_t v6_addr_len = sizeof(peer_addr->ipv6); int bytes = 0; if (!is_ipv6 ) { bytes = recvfrom(pfcp_fd, msg_payload, size, MSG_DONTWAIT, (struct sockaddr *) &peer_addr->ipv4, &v4_addr_len); peer_addr->type |= PDN_TYPE_IPV4; clLog(clSystemLog, eCLSeverityDebug, "pfcp received %d bytes " "with IPv4 Address", bytes); } else { bytes = recvfrom(pfcp_fd_v6, msg_payload, size, MSG_DONTWAIT, (struct sockaddr *) &peer_addr->ipv6, &v6_addr_len); peer_addr->type |= PDN_TYPE_IPV6; clLog(clSystemLog, eCLSeverityDebug, "pfcp received %d bytes " "with IPv6 Address", bytes); } if(bytes == 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error Receving on PFCP Sock ",LOG_VALUE); } return bytes; } #endif /* CP_BUILD */ /** * @brief : Retrive SEID from encoded message * @param : msg_payload, encoded message * @return : Returns seid for PFCP */ static uint64_t get_seid(void *msg_payload){ pfcp_header_t header = {0}; decode_pfcp_header_t((uint8_t *)msg_payload, &header); /*To get CP fseid as in Case of PFCP_SESS_ESTAB_REQ * We send 0 to establish connection with new DP in pfcp header seid*/ if(header.s && !header.seid_seqno.has_seid.seid && header.message_type == PFCP_SESS_ESTAB_REQ){ pfcp_sess_estab_req_t pfcp_session_request = {0}; decode_pfcp_sess_estab_req_t(msg_payload, &pfcp_session_request); return pfcp_session_request.cp_fseid.seid; } if(header.s) return header.seid_seqno.has_seid.seid; else return 0; } int pfcp_send(int fd_v4, int fd_v6, void *msg_payload, uint32_t size, peer_addr_t peer_addr, Dir dir) { pfcp_header_t *head = (pfcp_header_t *)msg_payload; int bytes = 0; if (peer_addr.type == PDN_TYPE_IPV4) { if(fd_v4 <= 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"PFCP send is " "not possible due to incompatiable IP Type at " "Source and Destination\n", LOG_VALUE); return 0; } bytes = sendto(fd_v4, (uint8_t *) msg_payload, size, MSG_DONTWAIT, (struct sockaddr *) &peer_addr.ipv4, sizeof(peer_addr.ipv4)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"NGIC- main.c::pfcp_send()" "\n\tpfcp_fd_v4= %d, payload_length= %d ,Direction= %d, tx bytes= %d\n", LOG_VALUE, fd_v4, size, dir, bytes); } else if (peer_addr.type == PDN_TYPE_IPV6) { if(fd_v6 <= 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"PFCP send is " "not possible due to incompatiable IP Type at " "Source and Destination\n", LOG_VALUE); return 0; } bytes = sendto(fd_v6, (uint8_t *) msg_payload, size, MSG_DONTWAIT, (struct sockaddr *) &peer_addr.ipv6, sizeof(peer_addr.ipv6)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"NGIC- main.c::pfcp_send()" "\n\tpfcp_fd_v6= %d, payload_length= %d ,Direction= %d, tx bytes= %d\n", LOG_VALUE, fd_v6, size, dir, bytes); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Socket Type " "is not set for sending message over PFCP interface ", LOG_VALUE); } update_cli_stats((peer_address_t *) &peer_addr, head->message_type, dir, SX); #ifdef CP_BUILD uint64_t sess_id = get_seid(msg_payload); process_cp_li_msg(sess_id, SX_INTFC_OUT, msg_payload, size, fill_ip_info(peer_addr.type, config.pfcp_ip.s_addr, config.pfcp_ip_v6.s6_addr), fill_ip_info(peer_addr.type, peer_addr.ipv4.sin_addr.s_addr, peer_addr.ipv6.sin6_addr.s6_addr), config.pfcp_port, ntohs(peer_addr.ipv4.sin_port)); #endif return bytes; } long uptime(void) { struct sysinfo s_info; int error = sysinfo(&s_info); if(error != 0) { #ifdef CP_BUILD clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Error in uptime\n", LOG_VALUE); #endif /* CP_BUILD */ } return s_info.uptime; } void create_heartbeat_hash_table(void) { struct rte_hash_parameters rte_hash_params = { .name = "RECOVERY_TIME_HASH", .entries = HEARTBEAT_ASSOCIATION_ENTRIES_DEFAULT, .key_len = sizeof(node_address_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }; heartbeat_recovery_hash = rte_hash_create(&rte_hash_params); if (!heartbeat_recovery_hash) { rte_panic("%s hash create failed: %s (%u)\n.", rte_hash_params.name, rte_strerror(rte_errno), rte_errno); } } void create_associated_upf_hash(void) { struct rte_hash_parameters rte_hash_params = { .name = "associated_upf_hash", .entries = 50, .key_len = UINT32_SIZE, .hash_func = rte_jhash, .hash_func_init_val = 0, .socket_id = rte_socket_id(), }; associated_upf_hash = rte_hash_create(&rte_hash_params); if (!associated_upf_hash) { rte_panic("%s Associated UPF hash create failed: %s (%u)\n.", rte_hash_params.name, rte_strerror(rte_errno), rte_errno); } } uint32_t current_ntp_timestamp(void) { struct timeval tim; uint8_t ntp_time[8] = {0}; uint32_t timestamp = 0; gettimeofday(&tim, NULL); time_to_ntp(&tim, ntp_time); timestamp |= ntp_time[0] << 24 | ntp_time[1] << 16 | ntp_time[2] << 8 | ntp_time[3]; return timestamp; } void time_to_ntp(struct timeval *tv, uint8_t *ntp) { uint64_t ntp_tim = 0; uint8_t len = (uint8_t)sizeof(ntp)/sizeof(ntp[0]); uint8_t *p = ntp + len; int i = 0; ntp_tim = tv->tv_usec; ntp_tim <<= 32; ntp_tim /= 1000000; /* Setting the ntp in network byte order */ for (i = 0; i < len/2; i++) { *--p = ntp_tim & 0xff; ntp_tim >>= 8; } ntp_tim = tv->tv_sec; ntp_tim += OFFSET; /* Settting the fraction of second */ for (; i < len; i++) { *--p = ntp_tim & 0xff; ntp_tim >>= 8; } } void ntp_to_unix_time(uint32_t *ntp, struct timeval *unix_tm) { if (*ntp == 0) { unix_tm->tv_sec = 0; } else { /* the seconds from Jan 1, 1900 to Jan 1, 1970*/ if(unix_tm != NULL) unix_tm->tv_sec = (*ntp) - 0x83AA7E80; } } /* TODO: Convert this func into inline func */ /* VS: Validate the IP Address is in the subnet or not */ int validate_Subnet(uint32_t addr, uint32_t net_init, uint32_t net_end) { if ((addr >= net_init) && (addr <= net_end)) { /* IP Address is in the subnet range */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4 Addr "IPV4_ADDR" is in the subnet\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(addr)); return 1; } /* IP Address is not in the subnet range */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4 Addr "IPV4_ADDR" is NOT in the subnet\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(addr)); return 0; } /* TODO: Convert this func into inline func */ /* VS: Validate the IPv6 Address is in the subnet or not */ int validate_ipv6_network(struct in6_addr addr, struct in6_addr local_addr, uint8_t local_prefix) { uint8_t match = 0; for (uint8_t inx = 0; inx < local_prefix/8; inx++) { /* Compare IPv6 Address Hexstat by Hexstat */ if (!memcmp(&addr.s6_addr[inx], &local_addr.s6_addr[inx], sizeof(addr.s6_addr[inx]))) { /* If Hexstat match */ match = 1; } else { /* If Hexstat is NOT match */ match = 0; break; } } if (match) { /* IPv6 Address is in the same network range */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6 Addr "IPv6_FMT" is in the network\n", LOG_VALUE, IPv6_PRINT(addr)); return 1; } /* IPv6 Address is not in the network range */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6 Addr "IPv6_FMT" is NOT in the network\n", LOG_VALUE, IPv6_PRINT(addr)); return 0; } /** * @brief : Retrieve the IPv6 Network Prefix Address * @param : local_addr, Compare Network ID * @param : local_prefix, Network bits * @return : Returns Prefix * */ struct in6_addr retrieve_ipv6_prefix(struct in6_addr addr, uint8_t local_prefix) { struct in6_addr tmp = {0}; for (uint8_t inx = 0; inx < local_prefix/8; inx++) { tmp.s6_addr[inx] = addr.s6_addr[inx]; } /* IPv6 Address is not in the network range */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6 Network Prefix "IPv6_FMT" and Prefix len:%u\n", LOG_VALUE, IPv6_PRINT(tmp), local_prefix); return tmp; } #ifdef CP_BUILD uint8_t is_li_enabled(li_data_t *li_data, uint8_t intfc_name, uint8_t cp_type) { uint8_t doCopy = NOT_PRESENT; switch (intfc_name) { case S11_INTFC_IN: case S11_INTFC_OUT: if (PRESENT == li_data->s11) { doCopy = PRESENT; } break; case S5S8_C_INTFC_IN: case S5S8_C_INTFC_OUT: if (((SGWC == cp_type) && (PRESENT == li_data->sgw_s5s8c)) || ((PGWC == cp_type) && (PRESENT == li_data->pgw_s5s8c))) { doCopy = PRESENT; } break; case SX_INTFC_IN: case SX_INTFC_OUT: if (((SGWC == cp_type) && (PRESENT == li_data->sxa)) || ((PGWC == cp_type) && (PRESENT == li_data->sxb)) || ((SAEGWC == cp_type) && (PRESENT == li_data->sxa_sxb))) { doCopy = PRESENT; } break; default: /* Do nothing. Default value is already set 0 */ break; } return doCopy; } uint8_t is_li_enabled_using_imsi(uint64_t uiImsi, uint8_t intfc_name, uint8_t cp_type) { int ret = 0; uint8_t doCopy = NOT_PRESENT; struct li_df_config_t *li_config = NULL; ret = get_li_config(uiImsi, &li_config); if (!ret) { switch (intfc_name) { case S11_INTFC_IN: case S11_INTFC_OUT: if (COPY_SIG_MSG_ON == li_config->uiS11) { doCopy = PRESENT; } break; case S5S8_C_INTFC_IN: case S5S8_C_INTFC_OUT: if ( ((SGWC == cp_type) && (COPY_SIG_MSG_ON == li_config->uiSgwS5s8C)) || ((PGWC == cp_type) && (COPY_SIG_MSG_ON == li_config->uiPgwS5s8C))) { doCopy = PRESENT; } break; case SX_INTFC_IN: case SX_INTFC_OUT: if ( ((SGWC == cp_type) && ((SX_COPY_CP_MSG == li_config->uiSxa) || (SX_COPY_CP_DP_MSG == li_config->uiSxa))) || ((PGWC == cp_type) && ((SX_COPY_CP_MSG == li_config->uiSxb) || (SX_COPY_CP_DP_MSG == li_config->uiSxb))) || ((SAEGWC == cp_type) && ((SX_COPY_CP_MSG == li_config->uiSxaSxb) || (SX_COPY_CP_DP_MSG == li_config->uiSxaSxb)))) { doCopy = PRESENT; } break; default: /* Do nothing. Default value is already set 0 */ break; } } return doCopy; } int process_pkt_for_li(ue_context *context, uint8_t intfc_name, uint8_t *buf_tx, int buf_tx_size, struct ip_addr srcIp, struct ip_addr dstIp, uint16_t uiSrcPort, uint16_t uiDstPort) { int8_t ret = 0; int retval = 0; uint8_t *pkt = NULL; int pkt_length = 0; uint8_t doCopy = NOT_PRESENT; for (uint8_t cnt = 0; cnt < context->li_data_cntr; cnt++) { doCopy = is_li_enabled(&(context->li_data[cnt]), intfc_name, context->cp_mode); if (PRESENT == doCopy) { pkt_length = buf_tx_size; pkt = (uint8_t *)malloc(pkt_length + sizeof(li_header_t)); if (NULL == pkt) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to allocate memory for" " li packet\n", LOG_VALUE); return -1; } memcpy(pkt, buf_tx, pkt_length); ret = create_li_header(pkt, &pkt_length, EVENT_BASED, context->li_data[cnt].id, context->imsi, srcIp, dstIp, uiSrcPort, uiDstPort, context->li_data[cnt].forward); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to create li header\n", LOG_VALUE); return -1; } retval = send_li_data_pkt(ddf2_fd, pkt, pkt_length); if (retval < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to send CP message on TCP" " sock with error %d\n", LOG_VALUE, retval); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT": Send to LI success.\n", LOG_VALUE); free(pkt); pkt = NULL; } } return 0; } int process_cp_li_msg(uint64_t sess_id, uint8_t intfc_name, uint8_t *buf_tx, int buf_tx_size, struct ip_addr srcIp, struct ip_addr dstIp, uint16_t uiSrcPort, uint16_t uiDstPort) { int8_t ret = 0; uint32_t teid = 0; ue_context *context = NULL; if (!sess_id) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT " Seid Recived is: %u\n", LOG_VALUE, sess_id); return -1; } teid = UE_SESS_ID(sess_id); ret = get_ue_context(teid, &context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE " "Context for teid: %u\n", LOG_VALUE, teid); return -1; } if (NULL == context) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"UE context is NULL.\n" , LOG_VALUE); return -1; } if (PRESENT == context->dupl) { process_pkt_for_li(context, intfc_name, buf_tx, buf_tx_size, srcIp, dstIp, uiSrcPort, uiDstPort); } return 0; } int process_msg_for_li(ue_context *context, uint8_t intfc_name, msg_info *msg, struct ip_addr srcIp, struct ip_addr dstIp, uint16_t uiSrcPort, uint16_t uiDstPort) { int buf_tx_size = 0; gtpv2c_header_t *header; uint8_t buf_tx[MAX_GTPV2C_UDP_LEN] = {0}; if (NULL == context) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "UE context is NULL or LI" "for this UE is not enabled \n", LOG_VALUE); return -1; } /* Handling for CSR. If want to handle other msgs then add if condition * on msg_type basis */ buf_tx_size = encode_create_sess_req(&msg->gtpc_msg.csr,(uint8_t*)buf_tx); header = (gtpv2c_header_t*) buf_tx; header->gtpc.message_len = htons(buf_tx_size); if (PRESENT == context->dupl) { process_pkt_for_li(context, intfc_name, buf_tx, buf_tx_size, srcIp, dstIp, uiSrcPort, uiDstPort); } return 0; } int process_cp_li_msg_for_cleanup(li_data_t *li_data, uint8_t uiLiDataCntr, uint8_t intfc_name, uint8_t *buf_tx, int buf_tx_size, struct ip_addr srcIp, struct ip_addr dstIp, uint16_t uiSrcPort, uint16_t uiDstPort, uint8_t uiCpMode, uint64_t uiImsi) { int8_t ret = 0; int retval = 0; uint8_t *pkt = NULL; int pkt_length = 0; uint8_t doCopy = NOT_PRESENT; if (0 == uiLiDataCntr) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"No li entry found.\n", LOG_VALUE); return -1; } for (uint8_t cnt = 0; cnt < uiLiDataCntr; cnt++) { doCopy = is_li_enabled(&li_data[cnt], intfc_name, uiCpMode); if (PRESENT == doCopy) { pkt_length = buf_tx_size; pkt = (uint8_t *)malloc(pkt_length + sizeof(li_header_t)); if (NULL == pkt) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to allocate memory for" " li packet\n", LOG_VALUE); return -1; } memcpy(pkt, buf_tx, pkt_length); ret = create_li_header(pkt, &pkt_length, EVENT_BASED, li_data[cnt].id, uiImsi, srcIp, dstIp, uiSrcPort, uiDstPort, li_data[cnt].forward); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to create li header\n", LOG_VALUE); return -1; } retval = send_li_data_pkt(ddf2_fd, pkt, pkt_length); if (retval < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to send CP message on TCP" " sock with error %d\n", LOG_VALUE, retval); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT": Send to LI success.\n", LOG_VALUE); free(pkt); pkt = NULL; } } return 0; } #endif /* CP_BUILD */
nikhilc149/e-utran-features-bug-fixes
cp/gtpc_session.c
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "gtpc_session.h" #include "gtpv2c_error_rsp.h" #include "cp_timer.h" #include "gw_adapter.h" #include "gtp_messages.h" extern int pfcp_fd; extern int pfcp_fd_v6; extern int s5s8_fd; extern int s5s8_fd_v6; extern socklen_t s5s8_sockaddr_len; extern socklen_t s5s8_sockaddr_ipv6_len; extern socklen_t s11_mme_sockaddr_len; extern socklen_t s11_mme_sockaddr_ipv6_len; extern peer_addr_t s5s8_recv_sockaddr; extern struct rte_hash *bearer_by_fteid_hash; extern int gx_app_sock; extern int clSystemLog; int fill_cs_request(create_sess_req_t *cs_req, struct ue_context_t *context, int ebi_index, uint8_t requested_pdn_type) { int len = 0 ; set_gtpv2c_header(&cs_req->header, 1, GTP_CREATE_SESSION_REQ, 0, context->sequence, 0); cs_req->imsi.imsi_number_digits = context->imsi; set_ie_header(&cs_req->imsi.header, GTP_IE_IMSI, IE_INSTANCE_ZERO, sizeof(cs_req->imsi.imsi_number_digits)); set_ie_header(&cs_req->msisdn.header, GTP_IE_MSISDN, IE_INSTANCE_ZERO, BINARY_MSISDN_LEN); cs_req->msisdn.msisdn_number_digits = context->msisdn; if (context->uli.lai) { cs_req->uli.lai = context->uli.lai; cs_req->uli.lai2.lai_mcc_digit_2 = context->uli.lai2.lai_mcc_digit_2; cs_req->uli.lai2.lai_mcc_digit_1 = context->uli.lai2.lai_mcc_digit_1; cs_req->uli.lai2.lai_mnc_digit_3 = context->uli.lai2.lai_mnc_digit_3; cs_req->uli.lai2.lai_mcc_digit_3 = context->uli.lai2.lai_mcc_digit_3; cs_req->uli.lai2.lai_mnc_digit_2 = context->uli.lai2.lai_mnc_digit_2; cs_req->uli.lai2.lai_mnc_digit_1 = context->uli.lai2.lai_mnc_digit_1; cs_req->uli.lai2.lai_lac = context->uli.lai2.lai_lac; len += sizeof(cs_req->uli.lai2); } if (context->uli.tai) { cs_req->uli.tai = context->uli.tai; cs_req->uli.tai2.tai_mcc_digit_2 = context->uli.tai2.tai_mcc_digit_2; cs_req->uli.tai2.tai_mcc_digit_1 = context->uli.tai2.tai_mcc_digit_1; cs_req->uli.tai2.tai_mnc_digit_3 = context->uli.tai2.tai_mnc_digit_3; cs_req->uli.tai2.tai_mcc_digit_3 = context->uli.tai2.tai_mcc_digit_3; cs_req->uli.tai2.tai_mnc_digit_2 = context->uli.tai2.tai_mnc_digit_2; cs_req->uli.tai2.tai_mnc_digit_1 = context->uli.tai2.tai_mnc_digit_1; cs_req->uli.tai2.tai_tac = context->uli.tai2.tai_tac; len += sizeof(cs_req->uli.tai2); } if (context->uli.rai) { cs_req->uli.rai = context->uli.rai; cs_req->uli.rai2.ria_mcc_digit_2 = context->uli.rai2.ria_mcc_digit_2; cs_req->uli.rai2.ria_mcc_digit_1 = context->uli.rai2.ria_mcc_digit_1; cs_req->uli.rai2.ria_mnc_digit_3 = context->uli.rai2.ria_mnc_digit_3; cs_req->uli.rai2.ria_mcc_digit_3 = context->uli.rai2.ria_mcc_digit_3; cs_req->uli.rai2.ria_mnc_digit_2 = context->uli.rai2.ria_mnc_digit_2; cs_req->uli.rai2.ria_mnc_digit_1 = context->uli.rai2.ria_mnc_digit_1; cs_req->uli.rai2.ria_lac = context->uli.rai2.ria_lac; cs_req->uli.rai2.ria_rac = context->uli.rai2.ria_rac; len += sizeof(cs_req->uli.rai2); } if (context->uli.sai) { cs_req->uli.sai = context->uli.sai; cs_req->uli.sai2.sai_mcc_digit_2 = context->uli.sai2.sai_mcc_digit_2; cs_req->uli.sai2.sai_mcc_digit_1 = context->uli.sai2.sai_mcc_digit_1; cs_req->uli.sai2.sai_mnc_digit_3 = context->uli.sai2.sai_mnc_digit_3; cs_req->uli.sai2.sai_mcc_digit_3 = context->uli.sai2.sai_mcc_digit_3; cs_req->uli.sai2.sai_mnc_digit_2 = context->uli.sai2.sai_mnc_digit_2; cs_req->uli.sai2.sai_mnc_digit_1 = context->uli.sai2.sai_mnc_digit_1; cs_req->uli.sai2.sai_lac = context->uli.sai2.sai_lac; cs_req->uli.sai2.sai_sac = context->uli.sai2.sai_sac; len += sizeof(cs_req->uli.sai2); } if (context->uli.cgi) { cs_req->uli.cgi = context->uli.cgi; cs_req->uli.cgi2.cgi_mcc_digit_2 = context->uli.cgi2.cgi_mcc_digit_2; cs_req->uli.cgi2.cgi_mcc_digit_1 = context->uli.cgi2.cgi_mcc_digit_1; cs_req->uli.cgi2.cgi_mnc_digit_3 = context->uli.cgi2.cgi_mnc_digit_3; cs_req->uli.cgi2.cgi_mcc_digit_3 = context->uli.cgi2.cgi_mcc_digit_3; cs_req->uli.cgi2.cgi_mnc_digit_2 = context->uli.cgi2.cgi_mnc_digit_2; cs_req->uli.cgi2.cgi_mnc_digit_1 = context->uli.cgi2.cgi_mnc_digit_1; cs_req->uli.cgi2.cgi_lac = context->uli.cgi2.cgi_lac; cs_req->uli.cgi2.cgi_ci = context->uli.cgi2.cgi_ci; len += sizeof(cs_req->uli.cgi2); } if (context->uli.ecgi) { cs_req->uli.ecgi = context->uli.ecgi; cs_req->uli.ecgi2.ecgi_mcc_digit_2 = context->uli.ecgi2.ecgi_mcc_digit_2; cs_req->uli.ecgi2.ecgi_mcc_digit_1 = context->uli.ecgi2.ecgi_mcc_digit_1; cs_req->uli.ecgi2.ecgi_mnc_digit_3 = context->uli.ecgi2.ecgi_mnc_digit_3; cs_req->uli.ecgi2.ecgi_mcc_digit_3 = context->uli.ecgi2.ecgi_mcc_digit_3; cs_req->uli.ecgi2.ecgi_mnc_digit_2 = context->uli.ecgi2.ecgi_mnc_digit_2; cs_req->uli.ecgi2.ecgi_mnc_digit_1 = context->uli.ecgi2.ecgi_mnc_digit_1; cs_req->uli.ecgi2.ecgi_spare = context->uli.ecgi2.ecgi_spare; cs_req->uli.ecgi2.eci = context->uli.ecgi2.eci; len += sizeof(cs_req->uli.ecgi2); } if (context->uli.macro_enodeb_id) { cs_req->uli.macro_enodeb_id = context->uli.macro_enodeb_id; cs_req->uli.macro_enodeb_id2.menbid_mcc_digit_2 = context->uli.macro_enodeb_id2.menbid_mcc_digit_2; cs_req->uli.macro_enodeb_id2.menbid_mcc_digit_1 = context->uli.macro_enodeb_id2.menbid_mcc_digit_1; cs_req->uli.macro_enodeb_id2.menbid_mnc_digit_3 = context->uli.macro_enodeb_id2.menbid_mnc_digit_3; cs_req->uli.macro_enodeb_id2.menbid_mcc_digit_3 = context->uli.macro_enodeb_id2.menbid_mcc_digit_3; cs_req->uli.macro_enodeb_id2.menbid_mnc_digit_2 = context->uli.macro_enodeb_id2.menbid_mnc_digit_2; cs_req->uli.macro_enodeb_id2.menbid_mnc_digit_1 = context->uli.macro_enodeb_id2.menbid_mnc_digit_1; cs_req->uli.macro_enodeb_id2.menbid_spare = context->uli.macro_enodeb_id2.menbid_spare; cs_req->uli.macro_enodeb_id2.menbid_macro_enodeb_id = context->uli.macro_enodeb_id2.menbid_macro_enodeb_id; cs_req->uli.macro_enodeb_id2.menbid_macro_enb_id2 = context->uli.macro_enodeb_id2.menbid_macro_enb_id2; len += sizeof(cs_req->uli.macro_enodeb_id2); } if (context->uli.extnded_macro_enb_id) { cs_req->uli.extnded_macro_enb_id = context->uli.extnded_macro_enb_id; cs_req->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_1 = context->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_1; cs_req->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_3 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_3; cs_req->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_3 = context->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_3; cs_req->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_2 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_2; cs_req->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_1 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_1; cs_req->uli.extended_macro_enodeb_id2.emenbid_smenb = context->uli.extended_macro_enodeb_id2.emenbid_smenb; cs_req->uli.extended_macro_enodeb_id2.emenbid_spare = context->uli.extended_macro_enodeb_id2.emenbid_spare; cs_req->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id = context->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id; cs_req->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2 = context->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2; len += sizeof(cs_req->uli.extended_macro_enodeb_id2); } len += 1; set_ie_header(&cs_req->uli.header, GTP_IE_USER_LOC_INFO, IE_INSTANCE_ZERO, len); set_ie_header(&cs_req->serving_network.header, GTP_IE_SERVING_NETWORK, IE_INSTANCE_ZERO, sizeof(gtp_serving_network_ie_t) - sizeof(ie_header_t)); cs_req->serving_network.mnc_digit_1 = context->serving_nw.mnc_digit_1; cs_req->serving_network.mnc_digit_2 = context->serving_nw.mnc_digit_2; cs_req->serving_network.mnc_digit_3 = context->serving_nw.mnc_digit_3; cs_req->serving_network.mcc_digit_1 = context->serving_nw.mcc_digit_1; cs_req->serving_network.mcc_digit_2 = context->serving_nw.mcc_digit_2; cs_req->serving_network.mcc_digit_3 = context->serving_nw.mcc_digit_3; set_ie_header(&cs_req->rat_type.header, GTP_IE_RAT_TYPE, IE_INSTANCE_ZERO, sizeof(gtp_rat_type_ie_t) - sizeof(ie_header_t)); cs_req->rat_type.rat_type = context->rat_type.rat_type; set_gtpc_fteid(&cs_req->sender_fteid_ctl_plane, GTPV2C_IFTYPE_S5S8_SGW_GTPC, IE_INSTANCE_ZERO, context->pdns[ebi_index]->s5s8_sgw_gtpc_ip, context->pdns[ebi_index]->s5s8_sgw_gtpc_teid); set_ie_header(&cs_req->apn.header, GTP_IE_ACC_PT_NAME, IE_INSTANCE_ZERO, context->pdns[ebi_index]->apn_in_use->apn_name_length); memcpy(cs_req->apn.apn, &(context->pdns[ebi_index]->apn_in_use->apn_name_label[0]), context->pdns[ebi_index]->apn_in_use->apn_name_length); if (context->selection_flag) { cs_req->selection_mode.spare2 = context->select_mode.spare2; cs_req->selection_mode.selec_mode = context->select_mode.selec_mode; } if(context->pra_flag){ set_presence_reporting_area_info_ie(&cs_req->pres_rptng_area_info, context); context->pra_flag = FALSE; } set_ie_header(&cs_req->selection_mode.header, GTP_IE_SELECTION_MODE, IE_INSTANCE_ZERO, sizeof(uint8_t)); if( context->ue_time_zone_flag == TRUE) { cs_req->ue_time_zone.time_zone = context->tz.tz; cs_req->ue_time_zone.daylt_svng_time = context->tz.dst; cs_req->ue_time_zone.spare2 = 0; set_ie_header(&cs_req->ue_time_zone.header, GTP_IE_UE_TIME_ZONE, IE_INSTANCE_ZERO, sizeof(gtp_ue_time_zone_ie_t) - sizeof(ie_header_t)); cs_req->header.gtpc.message_len = cs_req->ue_time_zone.header.len + sizeof(ie_header_t); } if(context->indication_flag.crsi == 1) { set_ie_header(&cs_req->indctn_flgs.header, GTP_IE_INDICATION, IE_INSTANCE_ZERO, sizeof(gtp_indication_ie_t) - sizeof(ie_header_t)); cs_req->indctn_flgs.indication_crsi = 1; cs_req->header.gtpc.message_len += cs_req->indctn_flgs.header.len + sizeof(ie_header_t); } if(context->indication_flag.daf == 1) { set_ie_header(&cs_req->indctn_flgs.header, GTP_IE_INDICATION, IE_INSTANCE_ZERO, sizeof(gtp_indication_ie_t) - sizeof(ie_header_t)); cs_req->indctn_flgs.indication_daf = 1; cs_req->header.gtpc.message_len += cs_req->indctn_flgs.header.len + sizeof(ie_header_t); } if(context->up_selection_flag == 1){ set_ie_header(&cs_req->up_func_sel_indctn_flgs.header, GTP_IE_UP_FUNC_SEL_INDCTN_FLGS, IE_INSTANCE_ZERO, sizeof(gtp_up_func_sel_indctn_flgs_ie_t) - sizeof(ie_header_t)); cs_req->up_func_sel_indctn_flgs.dcnr = context->dcnr_flag; cs_req->header.gtpc.message_len += cs_req->up_func_sel_indctn_flgs.header.len + sizeof(ie_header_t); cs_req->header.gtpc.message_len += cs_req->ue_time_zone.header.len + sizeof(ie_header_t); } cs_req->pdn_type.pdn_type_pdn_type = requested_pdn_type; cs_req->pdn_type.pdn_type_spare2 = context->pdns[ebi_index]->pdn_type.spare; set_ie_header(&cs_req->pdn_type.header, GTP_IE_PDN_TYPE, IE_INSTANCE_ZERO, sizeof(uint8_t)); set_paa(&cs_req->paa, IE_INSTANCE_ZERO, context->pdns[ebi_index]); cs_req->max_apn_rstrct.rstrct_type_val = context->pdns[ebi_index]->apn_restriction; set_ie_header(&cs_req->max_apn_rstrct.header, GTP_IE_APN_RESTRICTION, IE_INSTANCE_ZERO, sizeof(uint8_t)); cs_req->apn_ambr.apn_ambr_uplnk = context->pdns[ebi_index]->apn_ambr.ambr_uplink; cs_req->apn_ambr.apn_ambr_dnlnk = context->pdns[ebi_index]->apn_ambr.ambr_downlink; set_ie_header(&cs_req->apn_ambr.header, GTP_IE_AGG_MAX_BIT_RATE, IE_INSTANCE_ZERO, sizeof(uint64_t)); cs_req->bearer_count = context->bearer_count; for (uint8_t uiCnt = 0; uiCnt < context->bearer_count; ++uiCnt) { set_ebi(&cs_req->bearer_contexts_to_be_created[uiCnt].eps_bearer_id, IE_INSTANCE_ZERO, context->eps_bearers[ebi_index]->eps_bearer_id); set_ie_header(&cs_req->bearer_contexts_to_be_created[uiCnt].eps_bearer_id.header, GTP_IE_EPS_BEARER_ID, IE_INSTANCE_ZERO, sizeof(uint8_t)); set_ie_header(&cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.header, GTP_IE_BEARER_QLTY_OF_SVC, IE_INSTANCE_ZERO, sizeof(gtp_bearer_qlty_of_svc_ie_t) - sizeof(ie_header_t)); cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.pvi = context->eps_bearers[ebi_index]->qos.arp.preemption_vulnerability; cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.spare2 = 0; cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.pl = context->eps_bearers[ebi_index]->qos.arp.priority_level; cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.pci = context->eps_bearers[ebi_index]->qos.arp.preemption_capability; cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.spare3 = 0; cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.qci = context->eps_bearers[ebi_index]->qos.qci; cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.max_bit_rate_uplnk = context->eps_bearers[ebi_index]->qos.ul_mbr; cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.max_bit_rate_dnlnk = context->eps_bearers[ebi_index]->qos.dl_mbr; cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.guarntd_bit_rate_uplnk = context->eps_bearers[ebi_index]->qos.ul_gbr; cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.guarntd_bit_rate_dnlnk = context->eps_bearers[ebi_index]->qos.dl_gbr; set_gtpc_fteid(&cs_req->bearer_contexts_to_be_created[uiCnt].s5s8_u_sgw_fteid, GTPV2C_IFTYPE_S5S8_SGW_GTPU, IE_INSTANCE_TWO, context->eps_bearers[ebi_index]->s5s8_sgw_gtpu_ip, context->eps_bearers[ebi_index]->s5s8_sgw_gtpu_teid); cs_req->bearer_contexts_to_be_created[uiCnt].s5s8_u_sgw_fteid.ipv4_address = cs_req->bearer_contexts_to_be_created[uiCnt].s5s8_u_sgw_fteid.ipv4_address; set_ie_header(&cs_req->bearer_contexts_to_be_created[uiCnt].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, cs_req->bearer_contexts_to_be_created[uiCnt].eps_bearer_id.header.len + sizeof(ie_header_t) + cs_req->bearer_contexts_to_be_created[uiCnt].bearer_lvl_qos.header.len + sizeof(ie_header_t) + cs_req->bearer_contexts_to_be_created[uiCnt].s5s8_u_sgw_fteid.header.len + sizeof(ie_header_t)); } /*fill fqdn string */ set_ie_header(&cs_req->sgw_u_node_name.header, GTP_IE_FULLY_QUAL_DOMAIN_NAME, IE_INSTANCE_ZERO, strnlen((char *)context->pdns[ebi_index]->fqdn,FQDN_LEN)); strncpy((char *)&cs_req->sgw_u_node_name.fqdn, (char *)context->pdns[ebi_index]->fqdn, strnlen((char *)context->pdns[ebi_index]->fqdn,FQDN_LEN)); if (context->pdns[ebi_index]->mapped_ue_usage_type >= 0) set_mapped_ue_usage_type(&cs_req->mapped_ue_usage_type, context->pdns[ebi_index]->mapped_ue_usage_type); cs_req->header.gtpc.message_len += cs_req->imsi.header.len + cs_req->msisdn.header.len + sizeof(ie_header_t) + sizeof(ie_header_t) + cs_req->uli.header.len + cs_req->rat_type.header.len + sizeof(ie_header_t) + sizeof(ie_header_t) + cs_req->serving_network.header.len + sizeof(ie_header_t) + cs_req->sender_fteid_ctl_plane.header.len + sizeof(ie_header_t) + cs_req->apn.header.len + sizeof(ie_header_t) + cs_req->selection_mode.header.len + sizeof(ie_header_t) + cs_req->pdn_type.header.len + sizeof(ie_header_t) + cs_req->paa.header.len + sizeof(ie_header_t) + cs_req->max_apn_rstrct.header.len + sizeof(ie_header_t) + cs_req->apn_ambr.header.len + sizeof(ie_header_t) + sizeof(gtpv2c_header_t); if (context->pdns[ebi_index]->mapped_ue_usage_type >= 0) cs_req->header.gtpc.message_len += cs_req->mapped_ue_usage_type.header.len + sizeof(ie_header_t); return 0; } void fill_ds_request(del_sess_req_t *ds_req, struct ue_context_t *context, int ebi_index , uint32_t teid) { int len = 0; set_gtpv2c_header(&ds_req->header, 1, GTP_DELETE_SESSION_REQ, teid, context->sequence , 0); set_ie_header(&ds_req->lbi.header, GTP_IE_EPS_BEARER_ID, IE_INSTANCE_ZERO, sizeof(uint8_t)); set_ebi(&ds_req->lbi, IE_INSTANCE_ZERO, context->eps_bearers[ebi_index]->eps_bearer_id); if (context->uli.lai) { ds_req->uli.lai = context->uli.lai; ds_req->uli.lai2.lai_mcc_digit_2 = context->uli.lai2.lai_mcc_digit_2; ds_req->uli.lai2.lai_mcc_digit_1 = context->uli.lai2.lai_mcc_digit_1; ds_req->uli.lai2.lai_mnc_digit_3 = context->uli.lai2.lai_mnc_digit_3; ds_req->uli.lai2.lai_mcc_digit_3 = context->uli.lai2.lai_mcc_digit_3; ds_req->uli.lai2.lai_mnc_digit_2 = context->uli.lai2.lai_mnc_digit_2; ds_req->uli.lai2.lai_mnc_digit_1 = context->uli.lai2.lai_mnc_digit_1; ds_req->uli.lai2.lai_lac = context->uli.lai2.lai_lac; len += sizeof(ds_req->uli.lai2); } if (context->uli.tai) { ds_req->uli.tai = context->uli.tai; ds_req->uli.tai2.tai_mcc_digit_2 = context->uli.tai2.tai_mcc_digit_2; ds_req->uli.tai2.tai_mcc_digit_1 = context->uli.tai2.tai_mcc_digit_1; ds_req->uli.tai2.tai_mnc_digit_3 = context->uli.tai2.tai_mnc_digit_3; ds_req->uli.tai2.tai_mcc_digit_3 = context->uli.tai2.tai_mcc_digit_3; ds_req->uli.tai2.tai_mnc_digit_2 = context->uli.tai2.tai_mnc_digit_2; ds_req->uli.tai2.tai_mnc_digit_1 = context->uli.tai2.tai_mnc_digit_1; ds_req->uli.tai2.tai_tac = context->uli.tai2.tai_tac; len += sizeof(ds_req->uli.tai2); } if (context->uli.rai) { ds_req->uli.rai = context->uli.rai; ds_req->uli.rai2.ria_mcc_digit_2 = context->uli.rai2.ria_mcc_digit_2; ds_req->uli.rai2.ria_mcc_digit_1 = context->uli.rai2.ria_mcc_digit_1; ds_req->uli.rai2.ria_mnc_digit_3 = context->uli.rai2.ria_mnc_digit_3; ds_req->uli.rai2.ria_mcc_digit_3 = context->uli.rai2.ria_mcc_digit_3; ds_req->uli.rai2.ria_mnc_digit_2 = context->uli.rai2.ria_mnc_digit_2; ds_req->uli.rai2.ria_mnc_digit_1 = context->uli.rai2.ria_mnc_digit_1; ds_req->uli.rai2.ria_lac = context->uli.rai2.ria_lac; ds_req->uli.rai2.ria_rac = context->uli.rai2.ria_rac; len += sizeof(ds_req->uli.rai2); } if (context->uli.sai) { ds_req->uli.sai = context->uli.sai; ds_req->uli.sai2.sai_mcc_digit_2 = context->uli.sai2.sai_mcc_digit_2; ds_req->uli.sai2.sai_mcc_digit_1 = context->uli.sai2.sai_mcc_digit_1; ds_req->uli.sai2.sai_mnc_digit_3 = context->uli.sai2.sai_mnc_digit_3; ds_req->uli.sai2.sai_mcc_digit_3 = context->uli.sai2.sai_mcc_digit_3; ds_req->uli.sai2.sai_mnc_digit_2 = context->uli.sai2.sai_mnc_digit_2; ds_req->uli.sai2.sai_mnc_digit_1 = context->uli.sai2.sai_mnc_digit_1; ds_req->uli.sai2.sai_lac = context->uli.sai2.sai_lac; ds_req->uli.sai2.sai_sac = context->uli.sai2.sai_sac; len += sizeof(ds_req->uli.sai2); } if (context->uli.cgi) { ds_req->uli.cgi = context->uli.cgi; ds_req->uli.cgi2.cgi_mcc_digit_2 = context->uli.cgi2.cgi_mcc_digit_2; ds_req->uli.cgi2.cgi_mcc_digit_1 = context->uli.cgi2.cgi_mcc_digit_1; ds_req->uli.cgi2.cgi_mnc_digit_3 = context->uli.cgi2.cgi_mnc_digit_3; ds_req->uli.cgi2.cgi_mcc_digit_3 = context->uli.cgi2.cgi_mcc_digit_3; ds_req->uli.cgi2.cgi_mnc_digit_2 = context->uli.cgi2.cgi_mnc_digit_2; ds_req->uli.cgi2.cgi_mnc_digit_1 = context->uli.cgi2.cgi_mnc_digit_1; ds_req->uli.cgi2.cgi_lac = context->uli.cgi2.cgi_lac; ds_req->uli.cgi2.cgi_ci = context->uli.cgi2.cgi_ci; len += sizeof(ds_req->uli.cgi2); } if (context->uli.ecgi) { ds_req->uli.ecgi = context->uli.ecgi; ds_req->uli.ecgi2.ecgi_mcc_digit_2 = context->uli.ecgi2.ecgi_mcc_digit_2; ds_req->uli.ecgi2.ecgi_mcc_digit_1 = context->uli.ecgi2.ecgi_mcc_digit_1; ds_req->uli.ecgi2.ecgi_mnc_digit_3 = context->uli.ecgi2.ecgi_mnc_digit_3; ds_req->uli.ecgi2.ecgi_mcc_digit_3 = context->uli.ecgi2.ecgi_mcc_digit_3; ds_req->uli.ecgi2.ecgi_mnc_digit_2 = context->uli.ecgi2.ecgi_mnc_digit_2; ds_req->uli.ecgi2.ecgi_mnc_digit_1 = context->uli.ecgi2.ecgi_mnc_digit_1; ds_req->uli.ecgi2.ecgi_spare = context->uli.ecgi2.ecgi_spare; ds_req->uli.ecgi2.eci = context->uli.ecgi2.eci; len += sizeof(ds_req->uli.ecgi2); } if (context->uli.macro_enodeb_id) { ds_req->uli.macro_enodeb_id = context->uli.macro_enodeb_id; ds_req->uli.macro_enodeb_id2.menbid_mcc_digit_2 = context->uli.macro_enodeb_id2.menbid_mcc_digit_2; ds_req->uli.macro_enodeb_id2.menbid_mcc_digit_1 = context->uli.macro_enodeb_id2.menbid_mcc_digit_1; ds_req->uli.macro_enodeb_id2.menbid_mnc_digit_3 = context->uli.macro_enodeb_id2.menbid_mnc_digit_3; ds_req->uli.macro_enodeb_id2.menbid_mcc_digit_3 = context->uli.macro_enodeb_id2.menbid_mcc_digit_3; ds_req->uli.macro_enodeb_id2.menbid_mnc_digit_2 = context->uli.macro_enodeb_id2.menbid_mnc_digit_2; ds_req->uli.macro_enodeb_id2.menbid_mnc_digit_1 = context->uli.macro_enodeb_id2.menbid_mnc_digit_1; ds_req->uli.macro_enodeb_id2.menbid_spare = context->uli.macro_enodeb_id2.menbid_spare; ds_req->uli.macro_enodeb_id2.menbid_macro_enodeb_id = context->uli.macro_enodeb_id2.menbid_macro_enodeb_id; ds_req->uli.macro_enodeb_id2.menbid_macro_enb_id2 = context->uli.macro_enodeb_id2.menbid_macro_enb_id2; len += sizeof(ds_req->uli.macro_enodeb_id2); } if (context->uli.extnded_macro_enb_id) { ds_req->uli.extnded_macro_enb_id = context->uli.extnded_macro_enb_id; ds_req->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_1 = context->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_1; ds_req->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_3 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_3; ds_req->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_3 = context->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_3; ds_req->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_2 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_2; ds_req->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_1 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_1; ds_req->uli.extended_macro_enodeb_id2.emenbid_smenb = context->uli.extended_macro_enodeb_id2.emenbid_smenb; ds_req->uli.extended_macro_enodeb_id2.emenbid_spare = context->uli.extended_macro_enodeb_id2.emenbid_spare; ds_req->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id = context->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id; ds_req->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2 = context->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2; len += sizeof(ds_req->uli.extended_macro_enodeb_id2); } len += 1; set_ie_header(&ds_req->uli.header, GTP_IE_USER_LOC_INFO, IE_INSTANCE_ZERO, len); } int process_sgwc_s5s8_create_sess_rsp(create_sess_rsp_t *cs_rsp) { int ret = 0; ue_context *context = NULL; pdn_connection *pdn = NULL; eps_bearer *bearers[MAX_BEARERS],*bearer = NULL; struct resp_info *resp = NULL; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; pfcp_update_far_ie_t update_far[MAX_LIST_SIZE] = {0}; uint8_t index = 0; int ebi_index = 0; /*extract ebi_id from array as all the ebi's will be of same pdn. */ ebi_index = GET_EBI_INDEX(cs_rsp->bearer_contexts_created[0].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ret = get_ue_context_by_sgw_s5s8_teid(cs_rsp->header.teid.has_teid.teid, &context); if (ret < 0 || !context) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to UE context for teid: %d\n", LOG_VALUE, cs_rsp->header.teid.has_teid.teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if(cs_rsp->pres_rptng_area_act.header.len){ store_presc_reporting_area_act_to_ue_context(&cs_rsp->pres_rptng_area_act, context); } pdn = GET_PDN(context, ebi_index); if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Failed to get pdn" " for ebi_index: %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } else { /*Reseting PDN type to Update as per the type sent in CSResp from PGW-C*/ pdn->pdn_type.ipv4 = 0; pdn->pdn_type.ipv6 = 0; if (cs_rsp->paa.pdn_type == PDN_IP_TYPE_IPV6 || cs_rsp->paa.pdn_type == PDN_IP_TYPE_IPV4V6) { pdn->pdn_type.ipv6 = PRESENT; memcpy(pdn->uipaddr.ipv6.s6_addr, cs_rsp->paa.paa_ipv6, IPV6_ADDRESS_LEN); pdn->prefix_len = cs_rsp->paa.ipv6_prefix_len; } if (cs_rsp->paa.pdn_type == PDN_IP_TYPE_IPV4 || cs_rsp->paa.pdn_type == PDN_IP_TYPE_IPV4V6) { pdn->pdn_type.ipv4 = PRESENT; pdn->uipaddr.ipv4.s_addr = cs_rsp->paa.pdn_addr_and_pfx; } pdn->apn_restriction = cs_rsp->apn_restriction.rstrct_type_val; ret = fill_ip_addr(cs_rsp->pgw_s5s8_s2as2b_fteid_pmip_based_intfc_or_gtp_based_ctl_plane_intfc.ipv4_address, cs_rsp->pgw_s5s8_s2as2b_fteid_pmip_based_intfc_or_gtp_based_ctl_plane_intfc.ipv6_address, &pdn->s5s8_pgw_gtpc_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } pdn->s5s8_pgw_gtpc_teid = cs_rsp->pgw_s5s8_s2as2b_fteid_pmip_based_intfc_or_gtp_based_ctl_plane_intfc.teid_gre_key; } #ifdef USE_REST /*CLI logic : add PGWC entry when CSResponse received*/ if ((pdn->s5s8_pgw_gtpc_ip.ipv4_addr != 0) || (pdn->s5s8_pgw_gtpc_ip.ipv6_addr)) { node_address_t peer_addr = {0}; if (pdn->s5s8_pgw_gtpc_ip.ip_type == PDN_TYPE_IPV4) { peer_addr.ip_type = PDN_TYPE_IPV4; peer_addr.ipv4_addr = pdn->s5s8_pgw_gtpc_ip.ipv4_addr; } if ((pdn->s5s8_pgw_gtpc_ip.ip_type == PDN_TYPE_IPV6) || (pdn->s5s8_pgw_gtpc_ip.ip_type == PDN_TYPE_IPV4_IPV6)) { peer_addr.ip_type = PDN_IP_TYPE_IPV6; memcpy(peer_addr.ipv6_addr, pdn->s5s8_pgw_gtpc_ip.ipv6_addr, IPV6_ADDRESS_LEN); } if ((add_node_conn_entry(&peer_addr, S5S8_SGWC_PORT_ID, context->cp_mode)) != 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Fail to add " "connection entry for PGWC\n", LOG_VALUE); } } #endif pfcp_sess_mod_req.update_far_count = 0; for(uint8_t i= 0; i< MAX_BEARERS; i++) { bearer = pdn->eps_bearers[i]; if(bearer == NULL) continue; /* TODO: Implement TFTs on default bearers * if (create_s5s8_session_response.bearer_tft_ie) { * } * */ /* TODO: Implement PGWC S5S8 bearer QoS */ if (cs_rsp->bearer_contexts_created[index].bearer_lvl_qos.header.len) { bearer->qos.qci = cs_rsp->bearer_contexts_created[index].bearer_lvl_qos.qci; bearer->qos.ul_mbr = cs_rsp->bearer_contexts_created[index].bearer_lvl_qos.max_bit_rate_uplnk; bearer->qos.dl_mbr = cs_rsp->bearer_contexts_created[index].bearer_lvl_qos.max_bit_rate_dnlnk; bearer->qos.ul_gbr = cs_rsp->bearer_contexts_created[index].bearer_lvl_qos.guarntd_bit_rate_uplnk; bearer->qos.dl_gbr = cs_rsp->bearer_contexts_created[index].bearer_lvl_qos.guarntd_bit_rate_dnlnk; bearer->qos.arp.preemption_vulnerability = cs_rsp->bearer_contexts_created[index].bearer_lvl_qos.pvi; bearer->qos.arp.spare1 = cs_rsp->bearer_contexts_created[index].bearer_lvl_qos.spare2; bearer->qos.arp.priority_level = cs_rsp->bearer_contexts_created[index].bearer_lvl_qos.pl; bearer->qos.arp.preemption_capability = cs_rsp->bearer_contexts_created[index].bearer_lvl_qos.pci; bearer->qos.arp.spare2 = cs_rsp->bearer_contexts_created[index].bearer_lvl_qos.spare3; } ret = fill_ip_addr(cs_rsp->bearer_contexts_created[index].s5s8_u_pgw_fteid.ipv4_address, cs_rsp->bearer_contexts_created[index].s5s8_u_pgw_fteid.ipv6_address, &bearer->s5s8_pgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s5s8_pgw_gtpu_teid = cs_rsp->bearer_contexts_created[index].s5s8_u_pgw_fteid.teid_gre_key; bearer->pdn = pdn; update_far[index].upd_frwdng_parms.outer_hdr_creation.teid = bearer->s5s8_pgw_gtpu_teid; ret = set_node_address(&update_far[index].upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[index].upd_frwdng_parms.outer_hdr_creation.ipv6_address, bearer->s5s8_pgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } update_far[index].upd_frwdng_parms.dst_intfc.interface_value = check_interface_type(cs_rsp->bearer_contexts_created[index].s5s8_u_pgw_fteid.interface_type, context->cp_mode); update_far[index].far_id.far_id_value = get_far_id(bearer, update_far[index].upd_frwdng_parms.dst_intfc.interface_value); pfcp_sess_mod_req.update_far_count++; bearers[index] = bearer; index++; } context->change_report = FALSE; if(cs_rsp->chg_rptng_act.header.len != 0) { context->change_report = TRUE; context->change_report_action = cs_rsp->chg_rptng_act.action; } fill_pfcp_sess_mod_req(&pfcp_sess_mod_req, NULL, bearers, pdn, update_far, 0, index, context); #ifdef USE_CSID fqcsid_t *tmp = NULL; /* PGW FQ-CSID */ if (cs_rsp->pgw_fqcsid.header.len) { ret = add_peer_addr_entry_for_fqcsid_ie_node_addr( &pdn->s5s8_pgw_gtpc_ip, &cs_rsp->pgw_fqcsid, S5S8_SGWC_PORT_ID); if (ret) return ret; /* Stored the PGW CSID by PGW Node address */ ret = add_fqcsid_entry(&cs_rsp->pgw_fqcsid, context->pgw_fqcsid); if(ret) return ret; } else { tmp = get_peer_addr_csids_entry(&(pdn->s5s8_pgw_gtpc_ip), ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to " "add PGW CSID by PGW Node addres %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } memcpy(&(tmp->node_addr), &(pdn->s5s8_pgw_gtpc_ip), sizeof(node_address_t)); memcpy(&((context->pgw_fqcsid)->node_addr[(context->pgw_fqcsid)->num_csid]), &(pdn->s5s8_pgw_gtpc_ip), sizeof(node_address_t)); } fill_pdn_fqcsid_info(&pdn->pgw_csid, context->pgw_fqcsid); /* Link local CSID with PGW CSID */ if (pdn->pgw_csid.num_csid) { if (link_gtpc_peer_csids(&pdn->pgw_csid, &pdn->sgw_csid, S5S8_SGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Link " "Local CSID entry to link with PGW FQCSID, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } if (link_sess_with_peer_csid(&pdn->pgw_csid, pdn, S5S8_SGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Failed to Link " "Session with Peer CSID\n", LOG_VALUE); return -1; } /* Set PGW FQ-CSID */ set_fq_csid_t(&pfcp_sess_mod_req.pgw_c_fqcsid, &pdn->pgw_csid); } #endif /* USE_CSID */ if(pfcp_sess_mod_req.create_pdr_count){ for(int itr = 0; itr < pfcp_sess_mod_req.create_pdr_count; itr++) { pfcp_sess_mod_req.create_pdr[itr].pdi.ue_ip_address.ipv4_address = (pdn->uipaddr.ipv4.s_addr); pfcp_sess_mod_req.create_pdr[itr].pdi.src_intfc.interface_value = SOURCE_INTERFACE_VALUE_ACCESS; } } uint8_t pfcp_msg[PFCP_MSG_LEN] = {0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); if (pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr, SENT) < 0) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Send " "PFCP Session Modification to SGW-U",LOG_VALUE); else { #ifdef CP_BUILD add_pfcp_if_timer_entry(context->s11_sgw_gtpc_teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ } /* Update UE State */ pdn->state = PFCP_SESS_MOD_REQ_SNT_STATE; /* Lookup Stored the session information. */ if (get_sess_entry(pdn->seid, &resp) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No session entry " "found for session id %lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Set create session response */ /*extract ebi_id from array as all the ebi's will be of same pdn.*/ resp->linked_eps_bearer_id = cs_rsp->bearer_contexts_created[0].eps_bearer_id.ebi_ebi; resp->msg_type = GTP_CREATE_SESSION_RSP; resp->gtpc_msg.cs_rsp = *cs_rsp; resp->state = PFCP_SESS_MOD_REQ_SNT_STATE; return 0; } int process_create_bearer_response(create_bearer_rsp_t *cb_rsp) { int ret = 0; int ebi_index = 0; uint8_t idx = 0; uint32_t seq_no = 0; eps_bearer *bearers[MAX_BEARERS] = {0},*bearer = NULL; ue_context *context = NULL; pdn_connection *pdn = NULL; struct resp_info *resp = NULL; pfcp_update_far_ie_t update_far[MAX_LIST_SIZE] = {0}; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; eps_bearer *remove_bearers[MAX_BEARERS] = {0}; uint8_t remove_cnt = 0; ret = get_ue_context(cb_rsp->header.teid.has_teid.teid, &context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE" " context for teid: %d\n", LOG_VALUE, cb_rsp->header.teid.has_teid.teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } context->req_status.seq = 0; context->req_status.status = REQ_PROCESS_DONE; if (!cb_rsp->cause.header.len) { clLog(clSystemLog,eCLSeverityCritical,LOG_FORMAT"Mandatory IE not found " "in Create Bearer Response message\n", LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } if(!cb_rsp->bearer_cnt) { clLog(clSystemLog,eCLSeverityCritical,LOG_FORMAT"No bearer context found " " for Create Bearer Response message \n", LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } if(cb_rsp->pres_rptng_area_info.header.len){ store_presc_reporting_area_info_to_ue_context(&cb_rsp->pres_rptng_area_info, context); } pfcp_sess_mod_req.create_pdr_count = 0; pfcp_sess_mod_req.update_far_count = 0; if(cb_rsp->cause.cause_value != GTPV2C_CAUSE_REQUEST_ACCEPTED) { remove_cnt = cb_rsp->bearer_cnt; } for (idx = 0; idx < cb_rsp->bearer_cnt; idx++) { if(!cb_rsp->bearer_contexts[idx].eps_bearer_id.ebi_ebi){ clLog(clSystemLog,eCLSeverityCritical,LOG_FORMAT"No EPS Bearer ID " " found in bearer context in Create Bearer Response \n", LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } if(!cb_rsp->bearer_contexts[idx].cause.header.len){ clLog(clSystemLog,eCLSeverityCritical,LOG_FORMAT"No Cause found in " "bearer context in Create Bearer Response\n", LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } ebi_index = GET_EBI_INDEX(cb_rsp->bearer_contexts[idx].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[(idx + MAX_BEARERS)]; pdn = bearer->pdn; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"for BRC: proc set is : %s\n", LOG_VALUE, get_proc_string(pdn->proc)); if(get_sess_entry(pdn->seid, &resp)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No session entry " "found for session id %lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (resp == NULL) return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; if(((ebi_index + NUM_EBI_RESERVED) == pdn->default_bearer_id) || (((*context).bearer_bitmap & (1 << ebi_index)) == 1) || (cb_rsp->bearer_contexts[idx].cause.cause_value != GTPV2C_CAUSE_REQUEST_ACCEPTED)) { if((cb_rsp->bearer_contexts[idx].cause.cause_value != GTPV2C_CAUSE_REQUEST_ACCEPTED)) { bearer = context->eps_bearers[(idx + MAX_BEARERS)]; context->eps_bearers[ebi_index] = bearer; pdn->eps_bearers[ebi_index] = bearer; } remove_bearers[remove_cnt] = context->eps_bearers[(idx + MAX_BEARERS)]; resp->eps_bearer_ids[idx] = resp->gtpc_msg.cb_rsp.bearer_contexts[idx].eps_bearer_id.ebi_ebi; resp->eps_bearer_ids[idx] = resp->gtpc_msg.cb_rsp.bearer_contexts[idx].cause.cause_value; remove_cnt++; continue; } bearer = context->eps_bearers[(idx + MAX_BEARERS)]; context->eps_bearers[ebi_index] = bearer; bearer->eps_bearer_id = cb_rsp->bearer_contexts[idx].eps_bearer_id.ebi_ebi; (*context).bearer_bitmap |= (1 << ebi_index); context->eps_bearers[(idx + MAX_BEARERS )] = NULL; resp->eps_bearer_ids[idx] = cb_rsp->bearer_contexts[idx].eps_bearer_id.ebi_ebi; pdn->eps_bearers[ebi_index] = bearer; pdn->eps_bearers[(idx + MAX_BEARERS )] = NULL; if (bearer == NULL) { /* TODO: * This mean ebi we allocated and received doesnt match * In correct design match the bearer in transtient struct from sgw-u teid * */ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Context not found " "Create Bearer Response with cause %d \n", LOG_VALUE, ret); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if( PGWC == context->cp_mode || SAEGWC == context->cp_mode) { if(bearer->num_prdef_filters){ for(int dyn_rule = 0; dyn_rule < bearer->num_prdef_filters; dyn_rule++){ /* Adding rule and bearer id to a hash */ bearer_id_t *id = NULL; id = malloc(sizeof(bearer_id_t)); memset(id, 0 , sizeof(bearer_id_t)); id->bearer_id = ebi_index; rule_name_key_t key = {0}; snprintf(key.rule_name, RULE_NAME_LEN , "%s", bearer->prdef_rules[dyn_rule]->rule_name); if (add_rule_name_entry(key, id) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add_rule_name_entry with rule_name\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } } }else{ for(int dyn_rule = 0; dyn_rule < bearer->num_dynamic_filters; dyn_rule++){ /* Adding rule and bearer id to a hash */ bearer_id_t *id = NULL; id = malloc(sizeof(bearer_id_t)); memset(id, 0 , sizeof(bearer_id_t)); id->bearer_id = ebi_index; rule_name_key_t key = {0}; snprintf(key.rule_name, RULE_NAME_LEN , "%s%d", bearer->dynamic_rules[dyn_rule]->rule_name, pdn->call_id); if (add_rule_name_entry(key, id) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add_rule_name_entry with rule_name\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } } } } if ( PGWC == context->cp_mode ) { ret = fill_ip_addr(cb_rsp->bearer_contexts[idx].s58_u_sgw_fteid.ipv4_address, cb_rsp->bearer_contexts[idx].s58_u_sgw_fteid.ipv6_address, &bearer->s5s8_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s5s8_sgw_gtpu_teid = cb_rsp->bearer_contexts[idx].s58_u_sgw_fteid.teid_gre_key; ret = fill_ip_addr(cb_rsp->bearer_contexts[idx].s58_u_pgw_fteid.ipv4_address, cb_rsp->bearer_contexts[idx].s58_u_pgw_fteid.ipv6_address, &bearer->s5s8_pgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s5s8_pgw_gtpu_teid = cb_rsp->bearer_contexts[idx].s58_u_pgw_fteid.teid_gre_key; if (cb_rsp->bearer_contexts[idx].s58_u_sgw_fteid.header.len != 0) { update_far[pfcp_sess_mod_req.update_far_count]. upd_frwdng_parms.outer_hdr_creation.teid = bearer->s5s8_sgw_gtpu_teid; ret = set_node_address(&update_far[pfcp_sess_mod_req.update_far_count]. upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[pfcp_sess_mod_req.update_far_count]. upd_frwdng_parms.outer_hdr_creation.ipv6_address, bearer->s5s8_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value = check_interface_type(cb_rsp->bearer_contexts[idx].s58_u_sgw_fteid.interface_type, context->cp_mode); update_far[pfcp_sess_mod_req.update_far_count].far_id.far_id_value = get_far_id(bearer, update_far[pfcp_sess_mod_req. update_far_count].upd_frwdng_parms.dst_intfc.interface_value); update_far[pfcp_sess_mod_req.update_far_count]. apply_action.forw = PRESENT; update_far[pfcp_sess_mod_req.update_far_count]. apply_action.dupl = GET_DUP_STATUS(context); pfcp_sess_mod_req.update_far_count++; } } else { ret = fill_ip_addr(cb_rsp->bearer_contexts[idx].s1u_enb_fteid.ipv4_address, cb_rsp->bearer_contexts[idx].s1u_enb_fteid.ipv6_address, &bearer->s1u_enb_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s1u_enb_gtpu_teid = cb_rsp->bearer_contexts[idx].s1u_enb_fteid.teid_gre_key; ret = fill_ip_addr(cb_rsp->bearer_contexts[idx].s1u_sgw_fteid.ipv4_address, cb_rsp->bearer_contexts[idx].s1u_sgw_fteid.ipv6_address, &bearer->s1u_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s1u_sgw_gtpu_teid = cb_rsp->bearer_contexts[idx].s1u_sgw_fteid.teid_gre_key; if (cb_rsp->bearer_contexts[idx].s1u_enb_fteid.header.len != 0) { update_far[pfcp_sess_mod_req.update_far_count]. upd_frwdng_parms.outer_hdr_creation.teid = bearer->s1u_enb_gtpu_teid; ret = set_node_address(&update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv6_address, bearer->s1u_enb_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value = check_interface_type(cb_rsp->bearer_contexts[idx].s1u_enb_fteid.interface_type, context->cp_mode); update_far[pfcp_sess_mod_req.update_far_count].far_id.far_id_value = get_far_id(bearer, update_far[pfcp_sess_mod_req. update_far_count].upd_frwdng_parms.dst_intfc.interface_value); update_far[pfcp_sess_mod_req.update_far_count]. apply_action.forw = PRESENT; update_far[pfcp_sess_mod_req.update_far_count]. apply_action.dupl = GET_DUP_STATUS(context); pfcp_sess_mod_req.update_far_count++; } } bearers[idx] = bearer; } if(remove_cnt != 0 ) { fill_pfcp_sess_mod_req_with_remove_pdr(&pfcp_sess_mod_req, pdn, remove_bearers, remove_cnt); } fill_pfcp_sess_mod_req(&pfcp_sess_mod_req, &cb_rsp->header, bearers, bearer->pdn, update_far, 0, cb_rsp->bearer_cnt, context); if ( PGWC != context->cp_mode ) { /* Update the next hop IP address */ ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } //seq_no = cb_rsp->header.teid.has_teid.seq; seq_no = bswap_32(cb_rsp->header.teid.has_teid.seq); seq_no = seq_no >> 8; #ifdef USE_CSID if(context->cp_mode == PGWC) { /* SGW FQ-CSID */ if (cb_rsp->sgw_fqcsid.header.len) { if (cb_rsp->sgw_fqcsid.number_of_csids) { uint8_t num_csid = 0; pdn->flag_fqcsid_modified = FALSE; int ret_t = 0; /* Get the copy of existing SGW CSID */ fqcsid_t sgw_tmp_csid_t = {0}; /* Parse and stored MME and SGW FQ-CSID in the context */ ret_t = gtpc_recvd_sgw_fqcsid(&cb_rsp->sgw_fqcsid, pdn, bearer, context); if ((ret_t != 0) && (ret_t != PRESENT)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed Link peer CSID\n", LOG_VALUE); return ret_t; } /* Fill the Updated CSID in the Modification Request */ /* Set SGW FQ-CSID */ if (ret_t != PRESENT && context->sgw_fqcsid != NULL) { if (pdn->sgw_csid.num_csid) { memcpy(&sgw_tmp_csid_t, &pdn->sgw_csid, sizeof(fqcsid_t)); } pdn->sgw_csid.local_csid[num_csid] = (context->sgw_fqcsid)->local_csid[(context->sgw_fqcsid)->num_csid - 1]; pdn->sgw_csid.node_addr = (context->sgw_fqcsid)->node_addr[(context->sgw_fqcsid)->num_csid - 1]; pdn->sgw_csid.num_csid = 1; if ((pdn->sgw_csid.num_csid) && (pdn->flag_fqcsid_modified != TRUE)) { if (link_gtpc_peer_csids(&pdn->sgw_csid, &pdn->pgw_csid, S5S8_PGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Link " "Local CSID entry to link with SGW FQCSID, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } } if (link_sess_with_peer_csid(&pdn->sgw_csid, pdn, S5S8_PGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Failed to Link " "Session with MME CSID \n", LOG_VALUE); return -1; } /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; peer_csid_key_t key = {0}; key.iface = S5S8_PGWC_PORT_ID; key.peer_local_csid = sgw_tmp_csid_t.local_csid[num_csid]; key.peer_node_addr = sgw_tmp_csid_t.node_addr; tmp1 = get_sess_peer_csid_entry(&key, REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seid_by_peer_csid_hash, &key, tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry" " for CSID = %u \n", LOG_VALUE, sgw_tmp_csid_t.local_csid[num_csid]); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Delete Local CSID entry */ del_sess_peer_csid_entry(&key); } } if (pdn->sgw_csid.num_csid) { set_fq_csid_t(&pfcp_sess_mod_req.sgw_c_fqcsid, &pdn->sgw_csid); /* set PGWC FQ-CSID */ set_fq_csid_t(&pfcp_sess_mod_req.pgw_c_fqcsid, &pdn->pgw_csid); if ((cb_rsp->mme_fqcsid).number_of_csids) set_fq_csid_t(&pfcp_sess_mod_req.mme_fqcsid, &pdn->mme_csid); } } if (ret_t == PRESENT) { /* set PGWC FQ-CSID */ set_fq_csid_t(&pfcp_sess_mod_req.pgw_c_fqcsid, &pdn->pgw_csid); } } } } #endif /* USE_CSID */ uint8_t pfcp_msg[PFCP_MSG_LEN] = {0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); if (pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr, SENT) < 0) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Send " "PFCP Session Modification to SGW-U",LOG_VALUE); else { #ifdef CP_BUILD add_pfcp_if_timer_entry(cb_rsp->header.teid.has_teid.teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ } context->sequence = seq_no; bearer->pdn->state = PFCP_SESS_MOD_REQ_SNT_STATE; resp->bearer_count = cb_rsp->bearer_cnt; resp->msg_type = GTP_CREATE_BEARER_RSP; resp->gtpc_msg.cb_rsp = *cb_rsp; resp->state = PFCP_SESS_MOD_REQ_SNT_STATE; return 0; } int process_delete_session_response(del_sess_rsp_t *ds_resp) { int ret = 0; ue_context *context = NULL; struct eps_bearer_t *bearer = NULL; struct resp_info *resp = NULL; int ebi_index = 0; pfcp_sess_del_req_t pfcp_sess_del_req = {0}; /* Retrieve the UE context */ ret = get_ue_context_by_sgw_s5s8_teid(ds_resp->header.teid.has_teid.teid, &context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE " "context for teid: %u\n", LOG_VALUE, ds_resp->header.teid.has_teid.teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } fill_pfcp_sess_del_req(&pfcp_sess_del_req, context->cp_mode); ret = get_bearer_by_teid(ds_resp->header.teid.has_teid.teid, &bearer); if(ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Bearer found for " "teid : %x...\n", LOG_VALUE, ds_resp->header.teid.has_teid.teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } int ebi = UE_BEAR_ID(bearer->pdn->seid); ebi_index = GET_EBI_INDEX(ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; pfcp_sess_del_req.header.seid_seqno.has_seid.seid = bearer->pdn->dp_seid; int encoded = encode_pfcp_sess_del_req_t(&pfcp_sess_del_req, pfcp_msg); if (pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr, SENT) < 0) clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error sending while " "session delete request at sgwc %i\n", LOG_VALUE, errno); else { #ifdef CP_BUILD add_pfcp_if_timer_entry(context->s11_sgw_gtpc_teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ } /* Update UE State */ bearer->pdn->state = PFCP_SESS_DEL_REQ_SNT_STATE; /* Stored/Update the session information. */ if (get_sess_entry(bearer->pdn->seid, &resp) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No session entry " "found for session id: %lu\n", LOG_VALUE, bearer->pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } resp->msg_type = GTP_DELETE_SESSION_REQ; resp->state = PFCP_SESS_DEL_REQ_SNT_STATE; return 0; } void fill_del_sess_rsp(del_sess_rsp_t *ds_resp, uint32_t sequence, uint32_t has_teid) { set_gtpv2c_header(&ds_resp->header, 1, GTP_DELETE_SESSION_RSP, has_teid, sequence, 0); set_cause_accepted(&ds_resp->cause, IE_INSTANCE_ZERO); } int process_update_bearer_request(upd_bearer_req_t *ubr) { int ret = 0; upd_bearer_req_t ubr_req = {0}; uint8_t bearer_id = 0; int ebi_index = 0; struct resp_info *resp = NULL; pdn_connection *pdn_cntxt = NULL; uint16_t payload_length = 0; uint8_t cp_mode = 0; ue_context *context = NULL; bzero(&tx_buf, sizeof(tx_buf)); gtpv2c_header_t *gtpv2c_tx = (gtpv2c_header_t *)tx_buf; /* for now taking 0th element bearer id bcz * a request will come from commom PGW for which PDN is same */ ebi_index = GET_EBI_INDEX(ubr->bearer_contexts[0].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ret = get_ue_context_by_sgw_s5s8_teid(ubr->header.teid.has_teid.teid, &context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get" " UE context for teid %d\n", LOG_VALUE, ubr->header.teid.has_teid.teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if(ubr->pres_rptng_area_act.header.len){ store_presc_reporting_area_act_to_ue_context(&ubr->pres_rptng_area_act, context); } pdn_cntxt = GET_PDN(context, ebi_index); if (pdn_cntxt == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No PDN found " "found for ebi_index : %lu\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (get_sess_entry(pdn_cntxt->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No session entry " "found for session id: %lu\n", LOG_VALUE, pdn_cntxt->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } reset_resp_info_structure(resp); context->eps_bearers[ebi_index]->sequence = ubr->header.teid.has_teid.seq; uint32_t seq_no = 0; if(pdn_cntxt->proc == UE_REQ_BER_RSRC_MOD_PROC || resp->msg_type == GTP_MODIFY_BEARER_CMD) { seq_no = ubr->header.teid.has_teid.seq; } else { seq_no = generate_seq_no(); } set_gtpv2c_teid_header((gtpv2c_header_t *) &ubr_req, GTP_UPDATE_BEARER_REQ, context->s11_mme_gtpc_teid, seq_no, 0); if(ubr->apn_ambr.header.len){ ubr_req.apn_ambr.apn_ambr_uplnk = ubr->apn_ambr.apn_ambr_uplnk; ubr_req.apn_ambr.apn_ambr_dnlnk = ubr->apn_ambr.apn_ambr_dnlnk; set_ie_header(&ubr_req.apn_ambr.header, GTP_IE_AGG_MAX_BIT_RATE, IE_INSTANCE_ZERO, sizeof(uint64_t)); }else{ return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } /*Fill pti in ubr sent to MME*/ if (ubr->pti.header.len) memcpy(&ubr_req.pti, &ubr->pti, sizeof(ubr->pti)); /*Reset pti as transaction is completed for BRC flow*/ if (context->proc_trans_id) context->proc_trans_id = 0; if(!ubr->bearer_context_count) return GTPV2C_CAUSE_MANDATORY_IE_MISSING; if(ubr->indctn_flgs.header.len){ set_ie_header(&ubr_req.indctn_flgs.header, GTP_IE_INDICATION, IE_INSTANCE_ZERO, sizeof(gtp_indication_ie_t)- sizeof(ie_header_t)); ubr_req.indctn_flgs.indication_retloc = 1; } ubr_req.bearer_context_count = ubr->bearer_context_count; for(uint32_t i = 0; i < ubr->bearer_context_count; i++){ bearer_id = GET_EBI_INDEX(ubr->bearer_contexts[i].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } resp->eps_bearer_ids[resp->bearer_count++] = ubr->bearer_contexts[i].eps_bearer_id.ebi_ebi; int len = 0; set_ie_header(&ubr_req.bearer_contexts[i].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); if(ubr->bearer_contexts[i].tft.header.len != 0) { memset(ubr_req.bearer_contexts[i].tft.eps_bearer_lvl_tft, 0, MAX_TFT_LEN); memcpy(ubr_req.bearer_contexts[i].tft.eps_bearer_lvl_tft, ubr->bearer_contexts[i].tft.eps_bearer_lvl_tft, MAX_TFT_LEN); uint8_t tft_len = ubr->bearer_contexts[i].tft.header.len; set_ie_header(&ubr_req.bearer_contexts[i].tft.header, GTP_IE_EPS_BEARER_LVL_TRAFFIC_FLOW_TMPL, IE_INSTANCE_ZERO, tft_len); len = tft_len + IE_HEADER_SIZE; ubr_req.bearer_contexts[i].header.len += len; } if(ubr->bearer_contexts[i].bearer_lvl_qos.header.len != 0) { ubr_req.bearer_contexts[i].bearer_lvl_qos = ubr->bearer_contexts[i].bearer_lvl_qos; uint8_t qos_len = ubr->bearer_contexts[i].bearer_lvl_qos.header.len; set_ie_header(&ubr_req.bearer_contexts[i].bearer_lvl_qos.header, GTP_IE_BEARER_QLTY_OF_SVC, IE_INSTANCE_ZERO, qos_len); len = qos_len + IE_HEADER_SIZE; ubr_req.bearer_contexts[i].header.len += len; } set_ebi(&ubr_req.bearer_contexts[i].eps_bearer_id, IE_INSTANCE_ZERO, context->eps_bearers[bearer_id]->eps_bearer_id); ubr_req.bearer_contexts[i].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; } if(context->pra_flag){ set_presence_reporting_area_action_ie(&ubr_req.pres_rptng_area_act, context); context->pra_flag = 0; } if (pdn_cntxt->proc == UE_REQ_BER_RSRC_MOD_PROC) { resp->proc = UE_REQ_BER_RSRC_MOD_PROC; } else { pdn_cntxt->proc = UPDATE_BEARER_PROC; resp->proc = UPDATE_BEARER_PROC; } pdn_cntxt->state = UPDATE_BEARER_REQ_SNT_STATE; resp->gtpc_msg.ub_req = *ubr; resp->msg_type = GTP_UPDATE_BEARER_REQ; resp->state = UPDATE_BEARER_REQ_SNT_STATE; resp->cp_mode = context->cp_mode; cp_mode = context->cp_mode; /* Send update bearer request to MME*/ payload_length = encode_upd_bearer_req(&ubr_req, (uint8_t *)gtpv2c_tx); ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } gtpv2c_send(s11_fd, s11_fd_v6, tx_buf, payload_length, s11_mme_sockaddr, SENT); add_gtpv2c_if_timer_entry( context->s11_sgw_gtpc_teid, &s11_mme_sockaddr, tx_buf, payload_length, ebi_index, S11_IFACE, cp_mode); /* copy packet for user level packet copying or li */ if (context->dupl) { process_pkt_for_li( pdn_cntxt->context, S11_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s11_mme_sockaddr.type, config.s11_ip.s_addr, config.s11_ip_v6.s6_addr), fill_ip_info(s11_mme_sockaddr.type, s11_mme_sockaddr.ipv4.sin_addr.s_addr, s11_mme_sockaddr.ipv6.sin6_addr.s6_addr), config.s11_port, ((s11_mme_sockaddr.type == IPTYPE_IPV4_LI) ? s11_mme_sockaddr.ipv4.sin_port : s11_mme_sockaddr.ipv6.sin6_port)); } return 0; } int process_s5s8_upd_bearer_response(upd_bearer_rsp_t *ub_rsp, ue_context *context ) { int ebi_index = 0, ret = 0; pdn_connection *pdn_cntxt = NULL; uint32_t seq = 0; struct resp_info *resp = NULL; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; node_address_t node_value = {0}; ebi_index = GET_EBI_INDEX(ub_rsp->bearer_contexts[0].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } pdn_cntxt = GET_PDN(context, ebi_index); if(pdn_cntxt == NULL){ clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Failed to get pdn" " for ebi_index: %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (get_sess_entry(pdn_cntxt->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No session entry " "found for session id: %lu\n", LOG_VALUE, pdn_cntxt->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /*Start filling sess_mod_req*/ seq = get_pfcp_sequence_number(PFCP_SESSION_MODIFICATION_REQUEST, seq); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_mod_req.header), PFCP_SESSION_MODIFICATION_REQUEST, HAS_SEID, seq, context->cp_mode); pfcp_sess_mod_req.header.seid_seqno.has_seid.seid = pdn_cntxt->dp_seid; /*Filling Node ID for F-SEID*/ if (pdn_cntxt->upf_ip.ip_type == PDN_IP_TYPE_IPV4) { uint8_t temp[IPV6_ADDRESS_LEN] = {0}; ret = fill_ip_addr(config.pfcp_ip.s_addr, temp, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else if (pdn_cntxt->upf_ip.ip_type == PDN_IP_TYPE_IPV6) { ret = fill_ip_addr(0, config.pfcp_ip_v6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } set_fseid(&(pfcp_sess_mod_req.cp_fseid), pdn_cntxt->seid, node_value); for(uint8_t i = 0; i < ub_rsp->bearer_context_count; i++){ ebi_index = GET_EBI_INDEX(ub_rsp->bearer_contexts[i].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } fill_update_bearer_sess_mod(&pfcp_sess_mod_req, context->eps_bearers[ebi_index]); } uint8_t pfcp_msg[PFCP_MSG_LEN] = {0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); if (pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr, SENT) < 0) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in sending " "PFCP Session Modification Request to SGW-U, Error : %i\n", LOG_VALUE, errno); else { #ifdef CP_BUILD add_pfcp_if_timer_entry(ub_rsp->header.teid.has_teid.teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ } /* Update UE State */ pdn_cntxt->state = PFCP_SESS_MOD_REQ_SNT_STATE; /* Update UE Proc */ if(pdn_cntxt->proc != UE_REQ_BER_RSRC_MOD_PROC && pdn_cntxt->proc != HSS_INITIATED_SUB_QOS_MOD) { pdn_cntxt->proc = UPDATE_BEARER_PROC; resp->proc = UPDATE_BEARER_PROC; } /* Set GX rar message */ resp->msg_type = GTP_UPDATE_BEARER_RSP; resp->state = PFCP_SESS_MOD_REQ_SNT_STATE; resp->gtpc_msg.ub_rsp = *ub_rsp; resp->teid = ub_rsp->header.teid.has_teid.teid; return 0; } int process_s11_upd_bearer_response(upd_bearer_rsp_t *ub_rsp, ue_context *context) { int ebi_index = 0, ret = 0; upd_bearer_rsp_t ubr_rsp = {0}; struct resp_info *resp = NULL; pdn_connection *pdn_cntxt = NULL; uint16_t payload_length = 0; uint32_t sequence = 0; bzero(&tx_buf, sizeof(tx_buf)); gtpv2c_header_t *gtpv2c_tx = (gtpv2c_header_t *)tx_buf; ebi_index = GET_EBI_INDEX(ub_rsp->bearer_contexts[0].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } pdn_cntxt = GET_PDN(context, ebi_index); if(pdn_cntxt == NULL){ clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Failed to get pdn" " for ebi_index: %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (get_sess_entry(pdn_cntxt->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No session entry " "found for session id: %lu\n", LOG_VALUE, pdn_cntxt->seid); return -1; } if(ub_rsp->uli.header.len){ memcpy(&ubr_rsp.uli, &ub_rsp->uli, sizeof(gtp_user_loc_info_ie_t)); } /* Get seuence number from first valid bearer from list */ ebi_index = -1; for(uint32_t itr = 0; itr < ub_rsp->bearer_context_count ; itr++){ ebi_index = GET_EBI_INDEX(ub_rsp->bearer_contexts[itr].eps_bearer_id.ebi_ebi); if (ebi_index != -1) { break; } } if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; }else{ sequence = context->eps_bearers[ebi_index]->sequence; } set_gtpv2c_teid_header((gtpv2c_header_t *) &ubr_rsp, GTP_UPDATE_BEARER_RSP, pdn_cntxt->s5s8_pgw_gtpc_teid, sequence, 0); set_cause_accepted(&ubr_rsp.cause, IE_INSTANCE_ZERO); ubr_rsp.bearer_context_count = ub_rsp->bearer_context_count; for(uint8_t i = 0; i < ub_rsp->bearer_context_count; i++){ resp->eps_bearer_ids[resp->bearer_count++] = ub_rsp->bearer_contexts[i].eps_bearer_id.ebi_ebi; set_ie_header(&ubr_rsp.bearer_contexts[i].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); /* TODO Remove hardcoded ebi */ set_ebi(&ubr_rsp.bearer_contexts[i].eps_bearer_id, IE_INSTANCE_ZERO, ub_rsp->bearer_contexts[i].eps_bearer_id.ebi_ebi); ubr_rsp.bearer_contexts[i].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; set_cause_accepted(&ubr_rsp.bearer_contexts[i].cause, IE_INSTANCE_ZERO); ubr_rsp.bearer_contexts[i].header.len += sizeof(uint16_t) + IE_HEADER_SIZE; } if(context->pra_flag){ set_presence_reporting_area_info_ie(&ubr_rsp.pres_rptng_area_info, context); context->pra_flag = FALSE; } payload_length = encode_upd_bearer_rsp(&ubr_rsp, (uint8_t *)gtpv2c_tx); /* send S5S8 interface update bearer response. */ ret = set_dest_address(pdn_cntxt->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } gtpv2c_send(s5s8_fd, s5s8_fd_v6, tx_buf, payload_length, s5s8_recv_sockaddr, SENT); /* copy packet for user level packet copying or li */ if (context->dupl) { process_pkt_for_li( context, S5S8_C_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s5s8_recv_sockaddr.type, config.s5s8_ip.s_addr, config.s5s8_ip_v6.s6_addr), fill_ip_info(s5s8_recv_sockaddr.type, s5s8_recv_sockaddr.ipv4.sin_addr.s_addr, s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr), config.s5s8_port, ((s5s8_recv_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s5s8_recv_sockaddr.ipv4.sin_port) : ntohs(s5s8_recv_sockaddr.ipv6.sin6_port))); } /* Update UE Proc */ if (pdn_cntxt->proc == UE_REQ_BER_RSRC_MOD_PROC) { resp->proc = UE_REQ_BER_RSRC_MOD_PROC; } else { pdn_cntxt->proc = UPDATE_BEARER_PROC; resp->proc = UPDATE_BEARER_PROC; } /* Update UE State */ pdn_cntxt->state = CONNECTED_STATE; /* Set GX rar message */ resp->msg_type = GTP_UPDATE_BEARER_RSP; resp->state = CONNECTED_STATE; return 0; } void set_delete_bearer_command(del_bearer_cmd_t *del_bearer_cmd, pdn_connection *pdn, gtpv2c_header_t *gtpv2c_tx) { del_bearer_cmd_t del_cmd = {0}; del_cmd.header.gtpc.message_len = 0; pdn->context->sequence = del_bearer_cmd->header.teid.has_teid.seq; set_gtpv2c_teid_header((gtpv2c_header_t *) &del_cmd, GTP_DELETE_BEARER_CMD, pdn->s5s8_pgw_gtpc_teid, del_bearer_cmd->header.teid.has_teid.seq, 0); /*Below IE are Condition IE's*/ set_gtpc_fteid(&del_cmd.sender_fteid_ctl_plane, GTPV2C_IFTYPE_S5S8_SGW_GTPC, IE_INSTANCE_ZERO, pdn->s5s8_sgw_gtpc_ip, pdn->s5s8_sgw_gtpc_teid); del_cmd.header.gtpc.message_len += del_bearer_cmd->sender_fteid_ctl_plane.header.len + sizeof(ie_header_t); if(del_bearer_cmd->uli.header.len != 0) { /*set uli*/ memcpy(&del_cmd.uli, &(del_bearer_cmd->uli), sizeof(gtp_user_loc_info_ie_t)); set_ie_header(&del_cmd.uli.header, GTP_IE_USER_LOC_INFO, IE_INSTANCE_ZERO, del_bearer_cmd->uli.header.len); del_cmd.header.gtpc.message_len += del_bearer_cmd->uli.header.len + sizeof(ie_header_t); } if(del_bearer_cmd->uli_timestamp.header.len != 0) { /*set uli timestamp*/ memcpy(&del_cmd.uli_timestamp, &(del_bearer_cmd->uli_timestamp), sizeof(gtp_uli_timestamp_ie_t)); set_ie_header(&del_cmd.uli_timestamp.header, GTP_IE_ULI_TIMESTAMP, IE_INSTANCE_ZERO, del_bearer_cmd->uli_timestamp.header.len); del_cmd.header.gtpc.message_len += del_bearer_cmd->uli_timestamp.header.len + sizeof(ie_header_t); } if(del_bearer_cmd->ue_time_zone.header.len != 0) { memcpy(&del_cmd.ue_time_zone, &(del_bearer_cmd->ue_time_zone), sizeof(gtp_ue_time_zone_ie_t)); set_ie_header(&del_cmd.ue_time_zone.header, GTP_IE_UE_TIME_ZONE, IE_INSTANCE_ZERO, del_bearer_cmd->ue_time_zone.header.len); del_cmd.header.gtpc.message_len += del_bearer_cmd->ue_time_zone.header.len + sizeof(ie_header_t); } if(del_bearer_cmd->mmes4_sgsns_ovrld_ctl_info.header.len != 0) { memcpy(&del_cmd.mmes4_sgsns_ovrld_ctl_info, &(del_bearer_cmd->mmes4_sgsns_ovrld_ctl_info), sizeof(gtp_ovrld_ctl_info_ie_t)); set_ie_header(&del_cmd.mmes4_sgsns_ovrld_ctl_info.header, GTP_IE_OVRLD_CTL_INFO, IE_INSTANCE_ZERO, del_bearer_cmd->mmes4_sgsns_ovrld_ctl_info.header.len); del_cmd.header.gtpc.message_len += del_bearer_cmd->mmes4_sgsns_ovrld_ctl_info.header.len + sizeof(ie_header_t); } if(del_bearer_cmd->sgws_ovrld_ctl_info.header.len != 0) { memcpy(&del_cmd.sgws_ovrld_ctl_info, &(del_bearer_cmd->sgws_ovrld_ctl_info), sizeof(gtp_ovrld_ctl_info_ie_t)); set_ie_header(&del_cmd.sgws_ovrld_ctl_info.header, GTP_IE_OVRLD_CTL_INFO, IE_INSTANCE_ZERO, del_bearer_cmd->sgws_ovrld_ctl_info.header.len); del_cmd.header.gtpc.message_len += del_bearer_cmd->sgws_ovrld_ctl_info.header.len + sizeof(ie_header_t); } if(del_bearer_cmd->secdry_rat_usage_data_rpt.header.len != 0) { memcpy(&del_cmd.secdry_rat_usage_data_rpt, &(del_bearer_cmd->secdry_rat_usage_data_rpt), sizeof(gtp_secdry_rat_usage_data_rpt_ie_t)); set_ie_header(&del_cmd.secdry_rat_usage_data_rpt.header, GTP_IE_SECDRY_RAT_USAGE_DATA_RPT, IE_INSTANCE_ZERO, del_bearer_cmd->secdry_rat_usage_data_rpt.header.len); del_cmd.header.gtpc.message_len += del_bearer_cmd->secdry_rat_usage_data_rpt.header.len + sizeof(ie_header_t); } del_cmd.bearer_count = del_bearer_cmd->bearer_count; for(uint8_t i= 0; i< del_bearer_cmd->bearer_count; i++) { set_ie_header(&del_cmd.bearer_contexts[i].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_ebi(&del_cmd.bearer_contexts[i].eps_bearer_id, IE_INSTANCE_ZERO,del_bearer_cmd->bearer_contexts[i].eps_bearer_id.ebi_ebi); del_cmd.bearer_contexts[i].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; del_cmd.header.gtpc.message_len += del_bearer_cmd->bearer_contexts[i].header.len + sizeof(ie_header_t); } encode_del_bearer_cmd(&del_cmd, (uint8_t *)gtpv2c_tx); } int delete_rule_in_bearer(eps_bearer *bearer) { /* Deleting rules those are associated with Bearer */ for (uint8_t itr = 0; itr < RULE_CNT; ++itr) { if (NULL != bearer->dynamic_rules[itr]) { rule_name_key_t key = {0}; snprintf(key.rule_name, RULE_NAME_LEN, "%s%d", bearer->dynamic_rules[itr]->rule_name, (bearer->pdn)->call_id); if (del_rule_name_entry(key) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Error on delete rule name entries\n", LOG_VALUE); return -1; } rte_free(bearer->dynamic_rules[itr]); bearer->dynamic_rules[itr] = NULL; } if(NULL != bearer->prdef_rules[itr]){ rule_name_key_t key = {0}; snprintf(key.rule_name, RULE_NAME_LEN, "%s", bearer->prdef_rules[itr]->rule_name); if (del_rule_name_entry(key) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Error on delete rule name entries\n", LOG_VALUE); return -1; } rte_free(bearer->prdef_rules[itr]); bearer->prdef_rules[itr] = NULL; } } return 0; } /** * @brief : Delete Bearer Context associate with EBI. * @param : pdn, pdn information. * @param : ebi_index, Bearer index. * @return : Returns 0 on success, -1 otherwise */ int delete_bearer_context(pdn_connection *pdn, int ebi_index ) { if (pdn->eps_bearers[ebi_index]) { if(delete_rule_in_bearer(pdn->eps_bearers[ebi_index])){ return -1; } rte_free(pdn->eps_bearers[ebi_index]); pdn->eps_bearers[ebi_index] = NULL; pdn->context->eps_bearers[ebi_index] = NULL; pdn->context->bearer_bitmap &= ~(1 << ebi_index); } return 0; } void delete_sess_context(ue_context **_context, pdn_connection *pdn) { int ret = 0; ue_context *context = *_context; /* Deleting session entry */ del_sess_entry(pdn->seid); /* Delete pdn policy allocations*/ for(uint8_t itr = 0; itr < MAX_RULES; itr++){ if(pdn->policy.pcc_rule[itr] != NULL){ rte_free( pdn->policy.pcc_rule[itr]); pdn->policy.pcc_rule[itr] = NULL; } } /* If EBI is Default EBI then delete all bearer and rule associate with PDN */ for (uint8_t itr1 = 0; itr1 < MAX_BEARERS; ++itr1) { if (pdn->eps_bearers[itr1] == NULL) continue; del_rule_entries(pdn, itr1); delete_bearer_context(pdn, itr1); } if (context->cp_mode == SGWC) { /* Deleting Bearer hash */ rte_hash_del_key(bearer_by_fteid_hash, (const void *) &(pdn)->s5s8_sgw_gtpc_teid); } /* free apn name label */ if (pdn->apn_in_use->apn_idx < 0) { if (pdn->apn_in_use != NULL) { if (pdn->apn_in_use->apn_name_label != NULL) { rte_free(pdn->apn_in_use->apn_name_label); pdn->apn_in_use->apn_name_label = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "apn name label memory free successfully\n", LOG_VALUE); } rte_free(pdn->apn_in_use); pdn->apn_in_use = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "apn in use memory free successfully\n", LOG_VALUE); } } #ifdef USE_CSID /* * De-link entry of the session from the CSID list * for only default bearer id * */ if ((context->cp_mode == SGWC) || (context->cp_mode == SAEGWC)) { /* Remove session entry from the SGWC or SAEGWC CSID */ cleanup_csid_entry(pdn->seid, &pdn->sgw_csid, pdn); } else if (context->cp_mode == PGWC) { /* Remove session entry from the PGWC CSID */ cleanup_csid_entry(pdn->seid, &pdn->pgw_csid, pdn); } #endif /* USE_CSID */ if (pdn != NULL) { rte_free(pdn); pdn = NULL; } --context->num_pdns; if (context->num_pdns == 0) { /*Remove all hash and timer's for ddn*/ delete_ddn_timer_entry(timer_by_teid_hash, context->s11_sgw_gtpc_teid, ddn_by_seid_hash); delete_ddn_timer_entry(dl_timer_by_teid_hash, context->s11_sgw_gtpc_teid, pfcp_rep_by_seid_hash); /* Deleting UE context hash */ rte_hash_del_key(ue_context_by_fteid_hash, (const void *) &(context)->s11_sgw_gtpc_teid); /* Delete UE context entry from UE Hash */ if ((ret = rte_hash_del_key(ue_context_by_imsi_hash, &context->imsi)) < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"%s - Error on ue_context_by_fteid_hash" " deletion\n", LOG_VALUE, strerror(ret)); } if(config.use_dns) { /* Delete UPFList entry from UPF Hash */ if ((upflist_by_ue_hash_entry_delete(&context->imsi, sizeof(context->imsi))) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error on upflist_by_ue_hash deletion of IMSI \n", LOG_VALUE); } } if (context != NULL) { if(context->pre_rptng_area_act != NULL){ rte_free(context->pre_rptng_area_act); context->pre_rptng_area_act = NULL; } rte_free(*_context); *_context = NULL; } } return; } int gtpc_context_replace_check(create_sess_req_t *csr, uint8_t cp_type, apn *apn_requested) { int ret = 0; msg_info msg; uint8_t ebi = 0; int msg_len = 0; int encoded = 0; uint32_t teid = 0; uint8_t send_dsr = 0; uint32_t sequence = 0; int payload_length = 0; eps_bearer *bearer = NULL; ue_context *context = NULL; pdn_connection *pdn = NULL; uint64_t imsi = UINT64_MAX; del_sess_req_t ds_req = {0}; struct resp_info *resp = NULL; uint8_t pfcp_msg[PFCP_MSG_LEN] = {0}; uint8_t encoded_msg[GTP_MSG_LEN] = {0}; eps_bearer *bearers[MAX_BEARERS] = {NULL}; pfcp_sess_del_req_t pfcp_sess_del_req = {0}; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; uint8_t send_ccr_t = 0; uint8_t buffer[1024] = {0} ; uint16_t gx_msglen = 0; gx_msg ccr_request = {0}; imsi = csr->imsi.imsi_number_digits; ret = rte_hash_lookup_data(ue_context_by_imsi_hash, &imsi, (void **) &(context)); if (ret == -ENOENT) { /* Context not found for IMSI */ return 0; } /* Validate the GateWay Mode in case of promotion/handover */ if (csr->indctn_flgs.indication_oi) { if (context->cp_mode != cp_type) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"GateWay Mode Changed for exsiting Session, Gateway: %s --> %s\n", LOG_VALUE, context->cp_mode == SGWC ? "SGW-C" : context->cp_mode == PGWC ? "PGW-C" : context->cp_mode == SAEGWC? "SAEGW-C" : "UNKNOWN", cp_type == SGWC ? "SGW-C" : cp_type == PGWC ? "PGW-C" : cp_type == SAEGWC ? "SAEGW-C" : "UNKNOWN"); /* Continue, remove existing session info */ return 0; } } /* copy csr for li */ msg.gtpc_msg.csr = *csr; if (PGWC == context->cp_mode) { /*extract ebi_id from array as all the ebi's will be of same pdn.*/ int ebi_index = GET_EBI_INDEX(msg.gtpc_msg.csr.bearer_contexts_to_be_created[0].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); cs_error_response(&msg, GTPV2C_CAUSE_SYSTEM_FAILURE, CAUSE_SOURCE_SET_TO_0, context->cp_mode != PGWC ? S11_IFACE : S5S8_IFACE); return -1; } pdn = GET_PDN(context, ebi_index); if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get " "pdn for ebi_index %d\n", LOG_VALUE, ebi_index); return -1; } process_msg_for_li(context, S5S8_C_INTFC_IN, &msg, fill_ip_info(s5s8_recv_sockaddr.type, pdn->s5s8_sgw_gtpc_ip.ipv4_addr, pdn->s5s8_sgw_gtpc_ip.ipv6_addr), fill_ip_info(s5s8_recv_sockaddr.type, config.s5s8_ip.s_addr, config.s5s8_ip_v6.s6_addr), pdn->s5s8_sgw_gtpc_teid, config.s5s8_port); } else { process_msg_for_li(context, S11_INTFC_IN, &msg, fill_ip_info(s11_mme_sockaddr.type, context->s11_mme_gtpc_ip.ipv4_addr, context->s11_mme_gtpc_ip.ipv6_addr), fill_ip_info(s11_mme_sockaddr.type, config.s11_ip.s_addr, config.s11_ip_v6.s6_addr), ((s11_mme_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s11_mme_sockaddr.ipv4.sin_port) : ntohs(s11_mme_sockaddr.ipv6.sin6_port)), config.s11_port); } for (uint8_t itr = 0; itr < csr->bearer_count; itr++) { ebi = csr->bearer_contexts_to_be_created[itr].eps_bearer_id.ebi_ebi; ret = get_pdn(&(context), apn_requested, &pdn); if (!ret && pdn != NULL && pdn->default_bearer_id != ebi) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Requested APN" " has default bearer with different EBI \n", LOG_VALUE); return GTPV2C_CAUSE_MULTIPLE_PDN_CONNECTIONS_FOR_APN_NOT_ALLOWED; } int ebi_index = GET_EBI_INDEX(ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } sequence = CSR_SEQUENCE(csr); bearer = (context)->eps_bearers[ebi_index]; /* Checking Received CSR is re-transmitted CSR ot not */ if (bearer != NULL ) { pdn = bearer->pdn; if (pdn != NULL ) { if (pdn->csr_sequence == sequence) { /* Discarding re-transmitted csr */ return GTPC_RE_TRANSMITTED_REQ; } } } else { /* Bearer context not found for received EPS bearer ID */ return 0; } /* looking for TEID */ if (csr->header.gtpc.teid_flag == 1) { teid = csr->header.teid.has_teid.teid; } /* checking received EPS Bearer ID is default bearer id or not */ if (pdn->default_bearer_id == ebi) { if ((context->eps_bearers[ebi_index] != NULL) && (context->eps_bearers[ebi_index]->pdn != NULL)) { /* Fill PFCP deletion req with crosponding SEID and send it to SGWU */ fill_pfcp_sess_del_req(&pfcp_sess_del_req, context->cp_mode); pfcp_sess_del_req.header.seid_seqno.has_seid.seid = pdn->dp_seid; encoded = encode_pfcp_sess_del_req_t(&pfcp_sess_del_req, pfcp_msg); pdn->state = PFCP_SESS_DEL_REQ_SNT_STATE; } } else { /* * If Received EPS Bearer ID is not match with existing PDN connection * context Default EPS Bearer ID , i.e Received EBI is dedicate bearer id */ if (((teid != 0) && (context->eps_bearers[ebi_index] != NULL)) && (context->eps_bearers[ebi_index]->pdn != NULL)) { /* Fill PFCP MOD req with SEID, FAR and send it to DP */ /* Need hardcoded index for pass single bearer info. to funtion */ bearers[0] = context->eps_bearers[ebi_index]; fill_pfcp_sess_mod_req_delete(&pfcp_sess_mod_req, pdn, bearers, 1); encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); /* UPF ip address */ ret = set_dest_address(pdn->upf_ip, &upf_pfcp_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } if (pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr, SENT) < 0) clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error in sending MSG to DP err_no: %i\n", LOG_VALUE, errno); } pdn->state = PFCP_SESS_MOD_REQ_SNT_STATE; } pdn->proc = INITIAL_PDN_ATTACH_PROC; /* Retrive the session information based on session id. */ if (get_sess_entry(pdn->seid, &resp) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session Entry Found " "while sending PFCP Session Deletion / Modification Request for " "session ID:%lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } resp->state = pdn->state; resp->proc = pdn->proc; /* store csr in resp structure */ resp->gtpc_msg.csr = *csr; /* Checking PGW change or not */ if ((context->cp_mode == SGWC) && (pdn->s5s8_pgw_gtpc_ip.ipv4_addr != csr->pgw_s5s8_addr_ctl_plane_or_pmip.ipv4_address)) { /* Set flag send dsr to PGWC */ send_dsr = 1; /* * Fill Delete Session request with crosponding TEID and * EPS Bearer ID and send it to PGW */ /* Set DSR header */ /* need to think about which sequence number we can set in DSR header */ set_gtpv2c_teid_header(&ds_req.header, GTP_DELETE_SESSION_REQ, pdn->s5s8_pgw_gtpc_teid, 1/*Sequence*/, 0); /* Set EBI */ set_ebi(&ds_req.lbi, IE_INSTANCE_ZERO , pdn->default_bearer_id); msg_len = encode_del_sess_req(&ds_req, encoded_msg); } /* Sending CCR-T to PCRF if PGWC/SAEGWC and Received EBI is default */ if ((config.use_gx) && (context->cp_mode != SGWC) && (pdn->default_bearer_id == ebi)) { send_ccr_t = 1; gx_context_t *gx_context = NULL; /* Retrive Gx_context based on Sess ID. */ ret = rte_hash_lookup_data(gx_context_by_sess_id_hash, (const void*)(pdn->gx_sess_id), (void **)&gx_context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO ENTRY FOUND" " IN Gx HASH [%s]\n", LOG_VALUE, pdn->gx_sess_id); } /* Set the Msg header type for CCR-T */ ccr_request.msg_type = GX_CCR_MSG ; /* Set Credit Control Request type */ ccr_request.data.ccr.presence.cc_request_type = PRESENT; ccr_request.data.ccr.cc_request_type = TERMINATION_REQUEST ; /* Set Credit Control Bearer opertaion type */ ccr_request.data.ccr.presence.bearer_operation = PRESENT; ccr_request.data.ccr.bearer_operation = TERMINATION ; /* Fill the Credit Crontrol Request to send PCRF */ if(fill_ccr_request(&ccr_request.data.ccr, context, ebi_index, pdn->gx_sess_id, 0) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Failed CCR request filling process\n", LOG_VALUE); } /* Calculate the max size of CCR msg to allocate the buffer */ gx_msglen = gx_ccr_calc_length(&ccr_request.data.ccr); ccr_request.msg_len = gx_msglen + GX_HEADER_LEN; memcpy(&buffer, &ccr_request.msg_type, sizeof(ccr_request.msg_type)); memcpy(buffer + sizeof(ccr_request.msg_type), &ccr_request.msg_len, sizeof(ccr_request.msg_len)); if (gx_ccr_pack(&(ccr_request.data.ccr), (unsigned char *)(buffer + GX_HEADER_LEN), gx_msglen) == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR:Packing CCR Buffer... \n", LOG_VALUE); } /* Deleting PDN hash map with GX call id */ rte_hash_del_key(pdn_conn_hash, (const void *) &pdn->call_id); /* Deleting GX hash */ rte_hash_del_key(gx_context_by_sess_id_hash, (const void *) &pdn->gx_sess_id); if (gx_context != NULL) { rte_free(gx_context); gx_context = NULL; } } } /* for loop */ if ((context->cp_mode == SGWC) && (send_dsr)) { ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } gtpv2c_header_t *header = NULL; header = (gtpv2c_header_t*) encoded_msg; header->gtpc.message_len = htons(msg_len - IE_HEADER_SIZE); payload_length = (ntohs(header->gtpc.message_len) + sizeof(header->gtpc)); gtpv2c_send(s5s8_fd, s5s8_fd_v6, encoded_msg, payload_length, s5s8_recv_sockaddr, SENT); } pfcp_header_t *header = (pfcp_header_t *) pfcp_msg; header->message_len = htons(encoded - PFCP_IE_HDR_SIZE); ret = set_dest_address(pdn->upf_ip, &upf_pfcp_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } if (pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr, SENT) < 0) clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error in sending MSG to DP err_no: %i\n", LOG_VALUE, errno); if (config.use_gx) { /* Write or Send CCR -T msg to Gx_App */ if ((context->cp_mode != SGWC) && (send_ccr_t)) { send_to_ipc_channel(gx_app_sock, buffer, gx_msglen + GX_HEADER_LEN); } free_dynamically_alloc_memory(&ccr_request); } return GTPC_CONTEXT_REPLACEMENT; } uint8_t check_mbr_procedure(pdn_connection *pdn) { ue_context *context = NULL; context = pdn->context; if((context->cp_mode == SGWC )) { if((context->ue_time_zone_flag == FALSE) && (context->rat_type_flag == FALSE) && (context->uli_flag == FALSE) && (context->rat_type_flag == FALSE) && (context->uci_flag == FALSE) && (context->serving_nw_flag == FALSE) && (context->ltem_rat_type_flag == FALSE) && (context->second_rat_flag == FALSE) && (pdn->flag_fqcsid_modified == TRUE) && (context->update_sgw_fteid != TRUE)) { if(context->indication_flag.cfsi != TRUE) return UPDATE_PDN_CONNECTION; else return NO_UPDATE_MBR; } else if((context->ue_time_zone_flag == FALSE) && (context->rat_type_flag == FALSE) && (context->uli_flag == FALSE) && (context->rat_type_flag == FALSE) && (context->uci_flag == FALSE) && (context->serving_nw_flag == FALSE) && (context->ltem_rat_type_flag == FALSE) && (pdn->flag_fqcsid_modified == FALSE) && (context->second_rat_flag == FALSE)) { return NO_UPDATE_MBR; } else if((context->ue_time_zone_flag != FALSE) || (context->rat_type_flag != FALSE) || (context->uli_flag != FALSE) || (context->rat_type_flag != FALSE) || (context->uci_flag != FALSE) || (context->serving_nw_flag != FALSE) || (context->ltem_rat_type_flag != FALSE) || (pdn->flag_fqcsid_modified != FALSE) || (context->second_rat_flag != FALSE) || (context->update_sgw_fteid != FALSE)) { return FORWARD_MBR_REQUEST; } } else if(context->cp_mode == PGWC) { return NO_UPDATE_MBR; } else if(context->cp_mode == SAEGWC){ return NO_UPDATE_MBR; } return 0; } void set_bearer_resource_command(bearer_rsrc_cmd_t *bearer_rsrc_cmd, pdn_connection *pdn, gtpv2c_header_t *gtpv2c_tx) { bearer_rsrc_cmd_t brc_cmd = {0}; brc_cmd.header.gtpc.message_len = 0; pdn->context->sequence = bearer_rsrc_cmd->header.teid.has_teid.seq; set_gtpv2c_teid_header((gtpv2c_header_t *) &brc_cmd, GTP_BEARER_RESOURCE_CMD, pdn->s5s8_pgw_gtpc_teid, bearer_rsrc_cmd->header.teid.has_teid.seq, 0); set_gtpc_fteid(&brc_cmd.sender_fteid_ctl_plane, GTPV2C_IFTYPE_S5S8_SGW_GTPC, IE_INSTANCE_ZERO, pdn->s5s8_sgw_gtpc_ip, pdn->s5s8_sgw_gtpc_teid); brc_cmd.header.gtpc.message_len += bearer_rsrc_cmd->sender_fteid_ctl_plane.header.len + sizeof(ie_header_t); /*Below IE are Condition IE's*/ if (bearer_rsrc_cmd->lbi.header.len != 0) { memcpy(&brc_cmd.lbi, &(bearer_rsrc_cmd->lbi), sizeof(gtp_eps_bearer_id_ie_t)); set_ie_header(&brc_cmd.lbi.header, GTP_IE_EPS_BEARER_ID, IE_INSTANCE_ZERO, bearer_rsrc_cmd->lbi.header.len); } if (bearer_rsrc_cmd->pti.header.len != 0) { memcpy(&brc_cmd.pti, &(bearer_rsrc_cmd->pti), sizeof(gtp_proc_trans_id_ie_t)); set_ie_header(&brc_cmd.pti.header, GTP_IE_PROC_TRANS_ID, IE_INSTANCE_ZERO, bearer_rsrc_cmd->pti.header.len); } if (bearer_rsrc_cmd->tad.header.len != 0) { memcpy(&brc_cmd.tad, &(bearer_rsrc_cmd->tad), sizeof(gtp_traffic_agg_desc_ie_t)); set_ie_header(&brc_cmd.tad.header, GTP_IE_TRAFFIC_AGG_DESC, IE_INSTANCE_ZERO, bearer_rsrc_cmd->tad.header.len); } if (bearer_rsrc_cmd->flow_qos.header.len != 0) { memcpy(&brc_cmd.flow_qos, &(bearer_rsrc_cmd->flow_qos), sizeof(gtp_flow_qlty_of_svc_ie_t)); set_ie_header(&brc_cmd.flow_qos.header, GTP_IE_FLOW_QLTY_OF_SVC, IE_INSTANCE_ZERO, bearer_rsrc_cmd->flow_qos.header.len); } if (bearer_rsrc_cmd->eps_bearer_id.header.len != 0) { memcpy(&brc_cmd.eps_bearer_id, &(bearer_rsrc_cmd->eps_bearer_id), sizeof(gtp_eps_bearer_id_ie_t)); set_ie_header(&brc_cmd.eps_bearer_id.header, GTP_IE_EPS_BEARER_ID, IE_INSTANCE_ONE, bearer_rsrc_cmd->eps_bearer_id.header.len); } if (bearer_rsrc_cmd->rat_type.header.len != 0) { memcpy(&brc_cmd.rat_type, &(bearer_rsrc_cmd->rat_type), sizeof(gtp_rat_type_ie_t)); set_ie_header(&brc_cmd.rat_type.header, GTP_IE_RAT_TYPE, IE_INSTANCE_ZERO, bearer_rsrc_cmd->rat_type.header.len); } encode_bearer_rsrc_cmd(&brc_cmd, (uint8_t *)gtpv2c_tx); } void set_modify_bearer_command(mod_bearer_cmd_t *mod_bearer_cmd, pdn_connection *pdn, gtpv2c_header_t *gtpv2c_tx) { mod_bearer_cmd_t mod_cmd = {0}; mod_cmd.header.gtpc.message_len = 0; pdn->context->sequence = mod_bearer_cmd->header.teid.has_teid.seq; set_gtpv2c_teid_header((gtpv2c_header_t *) &mod_cmd, GTP_MODIFY_BEARER_CMD, pdn->s5s8_pgw_gtpc_teid, mod_bearer_cmd->header.teid.has_teid.seq, 0); set_gtpc_fteid(&mod_cmd.sender_fteid_ctl_plane, GTPV2C_IFTYPE_S5S8_SGW_GTPC, IE_INSTANCE_ZERO, pdn->s5s8_sgw_gtpc_ip, pdn->s5s8_sgw_gtpc_teid); mod_cmd.header.gtpc.message_len += mod_bearer_cmd->sender_fteid_ctl_plane.header.len + sizeof(ie_header_t); set_ie_header(&mod_cmd.bearer_context.header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_ebi(&mod_cmd.bearer_context.eps_bearer_id, IE_INSTANCE_ZERO,mod_bearer_cmd->bearer_context.eps_bearer_id.ebi_ebi); mod_cmd.bearer_context.header.len += sizeof(uint8_t) + IE_HEADER_SIZE; mod_cmd.header.gtpc.message_len += mod_bearer_cmd->bearer_context.header.len + sizeof(ie_header_t); if(mod_bearer_cmd->bearer_context.bearer_lvl_qos.header.len != 0) { mod_cmd.bearer_context.bearer_lvl_qos = mod_bearer_cmd->bearer_context.bearer_lvl_qos; uint8_t qos_len = mod_bearer_cmd->bearer_context.bearer_lvl_qos.header.len; set_ie_header(&mod_cmd.bearer_context.bearer_lvl_qos.header, GTP_IE_BEARER_QLTY_OF_SVC, IE_INSTANCE_ZERO, qos_len); mod_cmd.bearer_context.header.len += qos_len + IE_HEADER_SIZE; } memcpy(&mod_cmd.apn_ambr, &(mod_bearer_cmd->apn_ambr), sizeof(gtp_agg_max_bit_rate_ie_t)); set_ie_header(&mod_cmd.apn_ambr.header, GTP_IE_AGG_MAX_BIT_RATE, IE_INSTANCE_ZERO, mod_bearer_cmd->apn_ambr.header.len); mod_cmd.header.gtpc.message_len += mod_bearer_cmd->apn_ambr.header.len + sizeof(ie_header_t); /*Below IE are Condition IE's*/ if(mod_bearer_cmd->sgws_ovrld_ctl_info.header.len !=0) { memcpy(&mod_cmd.sgws_ovrld_ctl_info, &(mod_bearer_cmd->sgws_ovrld_ctl_info), sizeof(gtp_ovrld_ctl_info_ie_t)); set_ie_header(&mod_cmd.sgws_ovrld_ctl_info.header, GTP_IE_OVRLD_CTL_INFO, IE_INSTANCE_ZERO, mod_bearer_cmd->sgws_ovrld_ctl_info.header.len); mod_cmd.header.gtpc.message_len += mod_bearer_cmd->sgws_ovrld_ctl_info.header.len + sizeof(ie_header_t); } if(mod_bearer_cmd->mmes4_sgsns_ovrld_ctl_info.header.len != 0) { memcpy(&mod_cmd.mmes4_sgsns_ovrld_ctl_info, &(mod_bearer_cmd->mmes4_sgsns_ovrld_ctl_info), sizeof(gtp_ovrld_ctl_info_ie_t)); set_ie_header(&mod_cmd.mmes4_sgsns_ovrld_ctl_info.header, GTP_IE_OVRLD_CTL_INFO, IE_INSTANCE_ZERO, mod_bearer_cmd->mmes4_sgsns_ovrld_ctl_info.header.len); mod_cmd.header.gtpc.message_len += mod_bearer_cmd->mmes4_sgsns_ovrld_ctl_info.header.len + sizeof(ie_header_t); } uint16_t msg_len = 0; msg_len = encode_mod_bearer_cmd(&mod_cmd, (uint8_t *)gtpv2c_tx); gtpv2c_tx->gtpc.message_len = htons(msg_len - IE_HEADER_SIZE); } void store_presc_reporting_area_act_to_ue_context(gtp_pres_rptng_area_act_ie_t *ie, ue_context *context){ context->pra_flag = TRUE; if(context->pre_rptng_area_act == NULL) { context->pre_rptng_area_act = rte_zmalloc_socket(NULL, sizeof(presence_reproting_area_action_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(context->pre_rptng_area_act == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "Memory for presence repoting area action\n", LOG_VALUE); return; } } context->pre_rptng_area_act->pres_rptng_area_idnt = ie->pres_rptng_area_idnt; context->pre_rptng_area_act->action = ie->action; context->pre_rptng_area_act->number_of_tai = ie->number_of_tai; context->pre_rptng_area_act->number_of_rai = ie->number_of_rai; context->pre_rptng_area_act->nbr_of_macro_enb = ie->nbr_of_macro_enb; context->pre_rptng_area_act->nbr_of_home_enb = ie->nbr_of_home_enb; context->pre_rptng_area_act->number_of_ecgi = ie->number_of_ecgi; context->pre_rptng_area_act->number_of_sai = ie->number_of_sai; context->pre_rptng_area_act->number_of_cgi = ie->number_of_cgi; uint32_t size = 0; if(ie->number_of_tai){ size = ie->number_of_tai * sizeof(tai_field_t); memcpy(&context->pre_rptng_area_act->tais, &ie->tais, size); } if(ie->number_of_rai){ size = ie->number_of_rai * sizeof(rai_field_t); memcpy(&context->pre_rptng_area_act->rais, &ie->rais, size); } if(ie->nbr_of_macro_enb){ size = ie->nbr_of_macro_enb * sizeof(macro_enb_id_fld_t); memcpy(&context->pre_rptng_area_act->macro_enodeb_ids, &ie->macro_enb_ids, size); } if(ie->nbr_of_home_enb){ size = ie->nbr_of_home_enb * sizeof(home_enb_id_fld_t); memcpy(&context->pre_rptng_area_act->home_enb_ids, &ie->home_enb_ids, size); } if(ie->number_of_ecgi){ size = ie->number_of_ecgi * sizeof(ecgi_field_t); memcpy(&context->pre_rptng_area_act->ecgis, &ie->ecgis, size); } if(ie->number_of_cgi){ size = ie->number_of_cgi * sizeof(cgi_field_t); memcpy(&context->pre_rptng_area_act->cgis, &ie->cgis, size); } if(ie->number_of_sai){ size = ie->number_of_sai * sizeof(sai_field_t); memcpy(&context->pre_rptng_area_act->sais, &ie->sais, size); } context->pre_rptng_area_act->nbr_of_extnded_macro_enb = ie->nbr_of_extnded_macro_enb; if(ie->nbr_of_extnded_macro_enb){ size = ie->nbr_of_extnded_macro_enb * sizeof(extnded_macro_enb_id_fld_t); memcpy(&context->pre_rptng_area_act->extended_macro_enodeb_ids, &ie->extnded_macro_enb_ids, size); } return; } void store_presc_reporting_area_info_to_ue_context(gtp_pres_rptng_area_info_ie_t *ie, ue_context *context){ context->pre_rptng_area_info.pra_identifier = ie->pra_identifier; context->pre_rptng_area_info.inapra = ie->inapra; context->pre_rptng_area_info.opra = ie->opra; context->pre_rptng_area_info.ipra = ie->ipra; context->pra_flag = TRUE; return; }
nikhilc149/e-utran-features-bug-fixes
dp/ipv6.h
/* * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _IPV6_H_ #define _IPV6_H_ #include <stdint.h> #include <rte_ip.h> #include "util.h" #include "gtpu.h" /* ICMPv6 Messages define */ #define ICMPv6_ROUTER_SOLICITATION (0x85) #define ICMPv6_ROUTER_ADVERTISEMENT (0x86) #define ICMPv6_NEIGHBOR_SOLICITATION (0x87) #define ICMPv6_NEIGHBOR_ADVERTISEMENT (0x88) /* ICMPv6 Options */ /* Source Link Layer Address */ #define SRC_LINK_LAYER_ADDR (0x01) /* Target Link Layer Address */ #define TRT_LINK_LAYER_ADDR (0x02) /* Prefix information */ #define PREFIX_INFORMATION (0x03) struct icmpv6_header { uint8_t icmp6_type; /* ICMP6 packet type. */ uint8_t icmp6_code; /* ICMP6 packet code. */ uint16_t icmp6_cksum; /* ICMP6 packet checksum. */ union { uint32_t icmp6_data32[1]; /* type-specific field */ uint16_t icmp6_data16[2]; /* type-specific field: Router lifetime */ uint8_t icmp6_data8[4]; /* type-specific field: Cur Hop limit, flags */ }icmp6_data; }__attribute__((__packed__)); struct icmp6_prefix_options { uint8_t type; /* Prefix Information */ uint8_t length; /* Length */ uint8_t prefix_length; /* Prefix Length */ uint8_t flags; /* Flags */ uint32_t valid_lifetime; /* Valid Lifetime */ uint32_t preferred_lifetime; /* Preferred Lifetime */ uint32_t reserved; /* Reserved */ uint8_t prefix_addr[IPV6_ADDR_LEN]; /* Prefix */ }__attribute__((__packed__)); struct icmp6_options { uint8_t type; /* Source link-layer address */ uint8_t length; /* Length */ uint8_t link_layer_addr[ETHER_ADDR_LEN]; /* Source/Target Link Layer Address */ }__attribute__((__packed__)); /* ICMPv6 Router Solicitation Struct */ struct icmp6_hdr_rs { uint8_t icmp6_type; /* ICMP6 packet type. */ uint8_t icmp6_code; /* ICMP6 packet code. */ uint16_t icmp6_cksum; /* ICMP6 packet checksum. */ uint32_t icmp6_reserved; /* ICMP6 packet Reserved. */ struct icmp6_options opt; /* ICMP6 Possible options */ }__attribute__((__packed__)); /* ICMPv6 Router Advertisement Struct */ struct icmp6_hdr_ra { struct icmpv6_header icmp; /* ICMPv6 header */ uint32_t icmp6_reachable_time; /* ICMP6 packet Reachable time */ uint32_t icmp6_retrans_time; /* ICMP6 packet Retrans time */ struct icmp6_prefix_options opt; /* ICMP6 Possible options */ }__attribute__((__packed__)); /* ICMPv6 Neighbor Solicitation Struct */ struct icmp6_hdr_ns { uint8_t icmp6_type; /* ICMP6 packet type. */ uint8_t icmp6_code; /* ICMP6 packet code. */ uint16_t icmp6_cksum; /* ICMP6 packet checksum. */ uint32_t icmp6_reserved; /* ICMP6 packet Reserved. */ struct in6_addr icmp6_target_addr; /* ICMP6 Target address. */ struct icmp6_options opt; /* ICMP6 Possible options */ }__attribute__((__packed__)); /* ICMPv6 Neighbor Advertisement Struct */ struct icmp6_hdr_na { uint8_t icmp6_type; /* ICMP6 packet type. */ uint8_t icmp6_code; /* ICMP6 packet code. */ uint16_t icmp6_cksum; /* ICMP6 packet checksum. */ uint32_t icmp6_flags; /* ICMP6 packet flags, R:Router flag, S:Solicited flag, O:Override flag */ struct in6_addr icmp6_target_addr; /* ICMP6 Target address. */ struct icmp6_options opt; /* ICMP6 Possible options */ }__attribute__((__packed__)); /** * @file * This file contains macros, data structure definitions and function * prototypes of dataplane IPv6 header constructor. */ /** * @brief : Function to return pointer to ip headers, assuming ether header is untagged. * @param : m, mbuf pointer * @return : pointer to ipv6 headers */ static inline struct ipv6_hdr *get_mtoip_v6(struct rte_mbuf *m) { #ifdef DPDK_2_1 return (struct ipv6_hdr *)(rte_pktmbuf_mtod(m, unsigned char *) + ETH_HDR_SIZE); #else return rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *, sizeof(struct ether_hdr)); #endif } /** * @brief : Function to return pointer to encapsulated ipv6 headers, assuming ether header is untagged. * @param : m, mbuf pointer * @return : pointer to ipv6 headers */ static inline struct ipv6_hdr *get_inner_mtoipv6(struct rte_mbuf *m) { uint8_t *ptr; ptr = (uint8_t *)(rte_pktmbuf_mtod(m, unsigned char *) + ETH_HDR_SIZE + IPv6_HDR_SIZE + UDP_HDR_SIZE); ptr += GPDU_HDR_SIZE_DYNAMIC(*ptr); return (struct ipv6_hdr *)ptr; } /** * @brief : Function to return pointer to inner icmpv6 ICMP headers. * @param : m, mbuf pointer * @return : Returns pointer to udp headers */ static inline struct icmp_hdr *get_inner_mtoicmpv6(struct rte_mbuf *m) { uint8_t *ptr; ptr = (uint8_t *)(rte_pktmbuf_mtod(m, unsigned char *) + ETH_HDR_SIZE + IPv6_HDR_SIZE + UDP_HDR_SIZE); ptr += GPDU_HDR_SIZE_DYNAMIC(*ptr) + IPv6_HDR_SIZE; return (struct icmp_hdr *)ptr; } /** * @brief : Function to return pointer to icmpv6 ICMP headers. * @param : m, mbuf pointer * @return : Returns pointer to udp headers */ static inline struct icmp_hdr *get_mtoicmpv6(struct rte_mbuf *m) { return (struct icmp_hdr *)(rte_pktmbuf_mtod(m, unsigned char *) + ETH_HDR_SIZE + IPv6_HDR_SIZE); } /** * @brief : Function to return pointer to icmpv6 Router Solicitation headers. * @param : m, mbuf pointer * @return : Returns pointer to udp headers */ static inline struct icmp6_hdr_rs *get_mtoicmpv6_rs(struct rte_mbuf *m) { uint8_t *ptr; ptr = (uint8_t *)(rte_pktmbuf_mtod(m, unsigned char *) + ETH_HDR_SIZE + IPv6_HDR_SIZE + UDP_HDR_SIZE); ptr += GPDU_HDR_SIZE_DYNAMIC(*ptr) + IPv6_HDR_SIZE; return (struct icmp6_hdr_rs *)ptr; } /** * @brief : Function to return pointer to icmpv6 Router Advertisement headers. * @param : m, mbuf pointer * @return : Returns pointer to udp headers */ static inline struct icmp6_hdr_ra *get_mtoicmpv6_ra(struct rte_mbuf *m) { uint8_t *ptr; ptr = (uint8_t *)(rte_pktmbuf_mtod(m, unsigned char *) + ETH_HDR_SIZE + IPv6_HDR_SIZE + UDP_HDR_SIZE); ptr += GPDU_HDR_SIZE_DYNAMIC(*ptr) + IPv6_HDR_SIZE; return (struct icmp6_hdr_ra *)ptr; } /** * @brief : Function to return pointer to icmpv6 Neighbor Solicitation headers. * @param : m, mbuf pointer * @return : Returns pointer to udp headers */ static inline struct icmp6_hdr_ns *get_mtoicmpv6_ns(struct rte_mbuf *m) { return (struct icmp6_hdr_ns *)(rte_pktmbuf_mtod(m, unsigned char *) + ETH_HDR_SIZE + IPv6_HDR_SIZE); } /** * @brief : Function to return pointer to icmpv6 Neighbor Advertisement headers. * @param : m, mbuf pointer * @return : Returns pointer to udp headers */ static inline struct icmp6_hdr_na *get_mtoicmpv6_na(struct rte_mbuf *m) { return (struct icmp6_hdr_na *)(rte_pktmbuf_mtod(m, unsigned char *) + ETH_HDR_SIZE + IPv6_HDR_SIZE); } /** * @brief : Function to construct IPv6 header with default values. * @param : m, mbuf pointer * @return : Returns nothing */ static inline void build_ipv6_default_hdr(struct rte_mbuf *m) { struct ipv6_hdr *ipv6_hdr; ipv6_hdr = get_mtoip_v6(m); /* construct IPv6 header with hardcode values */ ipv6_hdr->vtc_flow = IPv6_VERSION; ipv6_hdr->payload_len = 0; ipv6_hdr->proto = 0; ipv6_hdr->hop_limits = 0; memset(&ipv6_hdr->src_addr, 0, IPV6_ADDR_LEN); memset(&ipv6_hdr->dst_addr, 0, IPV6_ADDR_LEN); } /** * @brief : Function to construct IPv6 header with default values. * @param : m, mbuf pointer * @param : len, len of header * @param : protocol, next protocol id * @param : src_ip, Source ip address * @param : dst_ip, destination ip address * @return : Returns nothing */ static inline void set_ipv6_hdr(struct rte_mbuf *m, uint16_t len, uint8_t protocol, struct in6_addr *src_ip, struct in6_addr *dst_ip) { struct ipv6_hdr *ipv6_hdr; ipv6_hdr = get_mtoip_v6(m); /* Set IPv6 header values */ ipv6_hdr->payload_len = htons(len); /* Fill the protocol identifier */ ipv6_hdr->proto = protocol; /* Fill the SRC IPv6 Addr */ memcpy(&ipv6_hdr->src_addr, &src_ip->s6_addr, IPV6_ADDR_LEN); /* Fill the DST IPv6 Addr */ memcpy(&ipv6_hdr->dst_addr, &dst_ip->s6_addr, IPV6_ADDR_LEN); } /** * @brief : Function to construct ipv6 header. * @param : m, mbuf pointer * @param : len, len of header * @param : protocol, next protocol id * @param : src_ip, Source ip address * @param : dst_ip, destination ip address * @return : Returns nothing */ void construct_ipv6_hdr(struct rte_mbuf *m, uint16_t len, uint8_t protocol, struct in6_addr *src_ip, struct in6_addr *dst_ip); /** * Process the IPv6 ICMPv6 checksum. * * @param ipv6_hdr * The pointer to the contiguous IPv6 header. * @param icmp_hdr * The pointer to the beginning of the L4 header. * @return * The complemented checksum to set in the IP packet. */ static inline uint16_t ipv6_icmp_cksum(const struct ipv6_hdr *ipv6_hdr, const void *icmp_hdr) { uint32_t cksum; uint32_t icmp_len; icmp_len = rte_be_to_cpu_16(ipv6_hdr->payload_len); cksum = rte_raw_cksum(icmp_hdr, icmp_len); cksum += rte_ipv6_phdr_cksum(ipv6_hdr, 0); cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff); cksum = (~cksum) & 0xffff; if (cksum == 0) cksum = 0xffff; return cksum; } /** * @brief : Function to set checksum of IPv4 and UDP header * @param : pkt rte_mbuf pointer * @return : Returns nothing */ void ra_set_checksum(struct rte_mbuf *pkt); #endif /* _IPV6_H_ */
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c_messages/delete_bearer.c
<reponame>nikhilc149/e-utran-features-bug-fixes<filename>cp/gtpv2c_messages/delete_bearer.c<gh_stars>0 /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <rte_debug.h> #include "gtpv2c.h" #include "gtpv2c_set_ie.h" #include "ue.h" #include "../cp_dp_api/vepc_cp_dp_api.h" #include "gw_adapter.h" #include "cp.h" extern int clSystemLog; /** * @brief : Maintatins data from parsed delete bearer response */ struct parse_delete_bearer_rsp_t { ue_context *context; pdn_connection *pdn; eps_bearer *ded_bearer; gtpv2c_ie *cause_ie; gtpv2c_ie *bearer_context_ebi_ie; gtpv2c_ie *bearer_context_cause_ie; }; /** * @brief : parses gtpv2c message and populates parse_delete_bearer_rsp_t structure * @param : gtpv2c_rx * buffer containing delete bearer response message * @param : dbr * data structure to contain required information elements from parsed * delete bearer response * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ static int parse_delete_bearer_response(gtpv2c_header_t *gtpv2c_rx, struct parse_delete_bearer_rsp_t *dbr) { gtpv2c_ie *current_ie; gtpv2c_ie *current_group_ie; gtpv2c_ie *limit_ie; gtpv2c_ie *limit_group_ie; int ret = rte_hash_lookup_data(ue_context_by_fteid_hash, (const void *) &gtpv2c_rx->teid.has_teid.teid, (void **) &dbr->context); if (ret < 0 || !dbr->context) return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; /** TODO: we should fully verify mandatory fields within received * message */ FOR_EACH_GTPV2C_IE(gtpv2c_rx, current_ie, limit_ie) { if (current_ie->type == GTP_IE_CAUSE && current_ie->instance == IE_INSTANCE_ZERO) { dbr->cause_ie = current_ie; } else if (current_ie->type == GTP_IE_BEARER_CONTEXT && current_ie->instance == IE_INSTANCE_ZERO) { FOR_EACH_GROUPED_IE(current_ie, current_group_ie, limit_group_ie) { if (current_group_ie->type == GTP_IE_EPS_BEARER_ID && current_group_ie->instance == IE_INSTANCE_ZERO) { dbr->bearer_context_ebi_ie = current_group_ie; } else if (current_group_ie->type == GTP_IE_CAUSE && current_group_ie->instance == IE_INSTANCE_ZERO) { dbr->bearer_context_cause_ie = current_group_ie; } } } } if (!dbr->cause_ie || !dbr->bearer_context_ebi_ie || !dbr->bearer_context_cause_ie) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Received Delete Bearer Response without " "mandatory IEs\n", LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } if (IE_TYPE_PTR_FROM_GTPV2C_IE(cause_ie, dbr->cause_ie)->cause_ie_hdr.cause_value != GTPV2C_CAUSE_REQUEST_ACCEPTED) return IE_TYPE_PTR_FROM_GTPV2C_IE(cause_ie, dbr->cause_ie)->cause_ie_hdr.cause_value; return 0; } int process_delete_bearer_response(gtpv2c_header_t *gtpv2c_rx) { struct parse_delete_bearer_rsp_t delete_bearer_rsp = { 0 }; int ret = parse_delete_bearer_response(gtpv2c_rx, &delete_bearer_rsp); if (ret && ret!=-1) return ret; uint8_t ebi = IE_TYPE_PTR_FROM_GTPV2C_IE(eps_bearer_id_ie, delete_bearer_rsp.bearer_context_ebi_ie)->ebi; int ebi_index = ebi; delete_bearer_rsp.ded_bearer = delete_bearer_rsp.context->eps_bearers[ebi_index]; if (delete_bearer_rsp.ded_bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Received Delete Bearer Response for" " non-existant EBI: %"PRIu8"\n",LOG_VALUE, ebi); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } delete_bearer_rsp.pdn = delete_bearer_rsp.ded_bearer->pdn; if (delete_bearer_rsp.context->eps_bearers[ebi_index] != delete_bearer_rsp.pdn->eps_bearers[ebi_index]) rte_panic("Incorrect provisioning of bearers\n"); if (delete_bearer_rsp.ded_bearer->eps_bearer_id == IE_TYPE_PTR_FROM_GTPV2C_IE(eps_bearer_id_ie, delete_bearer_rsp.bearer_context_ebi_ie)->ebi) { int ebi_index = GET_EBI_INDEX(delete_bearer_rsp.ded_bearer->eps_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } delete_bearer_rsp.context->bearer_bitmap &= ~(1 << ebi_index); delete_bearer_rsp.context->eps_bearers[ebi_index] = NULL; delete_bearer_rsp.pdn->eps_bearers[ebi_index] = NULL; uint8_t index = ((0x0f000000 & delete_bearer_rsp.ded_bearer->s1u_sgw_gtpu_teid) >> 24); delete_bearer_rsp.context->teid_bitmap &= ~(0x01 << index); struct dp_id dp_id = { .id = DPN_ID }; struct session_info si; memset(&si, 0, sizeof(si)); si.ue_addr.u.ipv4_addr = delete_bearer_rsp.pdn->uipaddr.ipv4.s_addr; si.sess_id = SESS_ID(delete_bearer_rsp.context->s11_sgw_gtpc_teid, delete_bearer_rsp.ded_bearer->eps_bearer_id); session_delete(dp_id, si); rte_free(delete_bearer_rsp.ded_bearer); } return 0; } void set_delete_bearer_request(gtpv2c_header_t *gtpv2c_tx, uint32_t sequence, pdn_connection *pdn, uint8_t linked_eps_bearer_id, uint8_t pti, uint8_t ded_eps_bearer_ids[], uint8_t ded_bearer_counter) { del_bearer_req_t db_req = {0}; if ((pdn->context)->cp_mode != PGWC) { set_gtpv2c_teid_header((gtpv2c_header_t *) &db_req, GTP_DELETE_BEARER_REQ, (pdn->context)->s11_mme_gtpc_teid, sequence, 0); } else { set_gtpv2c_teid_header((gtpv2c_header_t *) &db_req, GTP_DELETE_BEARER_REQ, pdn->s5s8_sgw_gtpc_teid, sequence, 0); } if(pti) set_pti(&db_req.pti, IE_INSTANCE_ZERO, pti); if (linked_eps_bearer_id > 0) { set_ebi(&db_req.lbi, IE_INSTANCE_ZERO, linked_eps_bearer_id); } else { for (uint8_t iCnt = 0; iCnt < ded_bearer_counter; ++iCnt) { set_ebi(&db_req.eps_bearer_ids[iCnt], IE_INSTANCE_ONE, ded_eps_bearer_ids[iCnt]); } db_req.bearer_count = ded_bearer_counter; } encode_del_bearer_req(&db_req, (uint8_t *)gtpv2c_tx); } void set_delete_bearer_response(gtpv2c_header_t *gtpv2c_tx, uint32_t sequence, uint8_t linked_eps_bearer_id, uint8_t ded_eps_bearer_ids[], uint8_t ded_bearer_counter, uint32_t s5s8_pgw_gtpc_teid) { del_bearer_rsp_t db_resp = {0}; set_gtpv2c_teid_header((gtpv2c_header_t *) &db_resp, GTP_DELETE_BEARER_RSP, s5s8_pgw_gtpc_teid , sequence, 0); set_cause_accepted(&db_resp.cause, IE_INSTANCE_ZERO); if (linked_eps_bearer_id > 0) { set_ebi(&db_resp.lbi, IE_INSTANCE_ZERO, linked_eps_bearer_id); } else { for (uint8_t iCnt = 0; iCnt < ded_bearer_counter; ++iCnt) { set_ie_header(&db_resp.bearer_contexts[iCnt].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_ebi(&db_resp.bearer_contexts[iCnt].eps_bearer_id, IE_INSTANCE_ZERO, ded_eps_bearer_ids[iCnt]); db_resp.bearer_contexts[iCnt].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; set_cause_accepted(&db_resp.bearer_contexts[iCnt].cause, IE_INSTANCE_ZERO); db_resp.bearer_contexts[iCnt].header.len += sizeof(uint16_t) + IE_HEADER_SIZE; } db_resp.bearer_count = ded_bearer_counter; } encode_del_bearer_rsp(&db_resp, (uint8_t *)gtpv2c_tx); }
nikhilc149/e-utran-features-bug-fixes
ulpc/d_admf/include/AckTimerThrd.h
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __ACKTIMERTHRD_H_ #define __ACKTIMERTHRD_H_ #include "emgmt.h" #include "etevent.h" #include "elogger.h" #include "Common.h" class EThreadAckTimer : public EThreadPrivate { public: EThreadAckTimer(); /** * @brief : EpcTools callback function on timer object initialization * @param : No param * @return : Returns nothing */ Void onInit(void); /** * @brief : EpcTools callback function on timer elapsed * @param : *pTimer, reference to timer object * @return : Returns nothing */ Void onTimer(EThreadEventTimer *pTimer); /** * @brief : EpcTools callback function when timer quits * @param : No param * @return : Returns nothing */ Void onQuit(void); void setTimeToElapse(const uint64_t time) { timeToElapse = time; } private: uint64_t timeToElapse; EThreadEventTimer timer; }; #endif /* __ACKTIMERTHRD_H_ */
nikhilc149/e-utran-features-bug-fixes
ulpc/admf/include/AdmfInterface.h
/* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __ADMF_INTERFACE_H_ #define __ADMF_INTERFACE_H_ #include <iostream> #include "AddUeEntry.h" #include "ModifyUeEntry.h" #include "DeleteUeEntry.h" #include "AcknowledgementPost.h" #include "UeNotification.h" #define IPV6_MAX_LEN 16 #define SEQ_ID_KEY "sequenceId" #define IMSI_KEY "imsi" #define SIGNALLING_CONFIG_KEY "signallingconfig" #define S11_KEY "s11" #define SGW_S5S8_C_KEY "sgw-s5s8c" #define PGW_S5S8_C_KEY "<KEY>" #define GX_KEY "gx" #define SX_KEY "sx" #define SX_INTFC_KEY "sxintfc" #define CP_DP_TYPE_KEY "type" #define DATA_CONFIG_KEY "dataconfig" #define S1U_CONTENT_KEY "s1u_content" #define SGW_S5S8U_CONTENT_KEY "sgw_s5s8u_content" #define PGW_S5S8U_CONTENT_KEY "pgw_s5s8u_content" #define SGI_CONTENT_KEY "sgi_content" #define DATA_INTFC_CONFIG_KEY "intfcconfig" #define DATA_INTFC_NAME_KEY "intfc" #define DATA_DIRECTION_KEY "direction" #define FORWARD_KEY "forward" #define TIMER_KEY "timer" #define START_TIME_KEY "starttime" #define STOP_TIME_KEY "stoptime" #define REQUEST_SOURCE "request_source" #define UE_DB_KEY "uedatabase" #define ACK_KEY "ack" #define REQUEST_TYPE_KEY "requestType" #define NOTIFY_TYPE_KEY "notifyType" class AdmfApplication; class AdmfInterface { private: static int iRefCnt; static AdmfInterface *mpInstance; AdmfApplication &mApp; EGetOpt &mOpt; EManagementEndpoint *mpLadmfEp; AddUeEntryPost *mpAddUeEntry; ModifyUeEntryPost *mpModUeEntry; DeleteUeEntryPost *mpDelUeEntry; AcknowledgementPost *mpAck; UeNotificationPost *mpNotify; AdmfInterface(AdmfApplication &app, EGetOpt &opt); public: /** * @brief : Initializes all references for Add, Update, Delete rest requests * @param : No param * @return : Returns nothing */ void admfInit(); /** * @brief : Creates singleton object of AdmfInterface * @param : app, reference to AdmfApplication object * @param : opt, reference to command-line parameter */ static AdmfInterface* getInstance(AdmfApplication &app, EGetOpt &opt); /** * @brief : Decreases reference count. Deletes the object if reference count becomes zero. * @param : No param * @return : Returns nothing */ void ReleaseInstance(void); ~AdmfInterface(); }; #endif /* __ADMF_INTERFACE_H_ */
nikhilc149/e-utran-features-bug-fixes
cp/cp_timer.c
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2017 Intel Corporation * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "gtpv2c.h" #include "pfcp_util.h" #include "sm_struct.h" #include "rte_common.h" #include "cp_timer.h" #include "gtpv2c_error_rsp.h" #include "gw_adapter.h" #include "debug_str.h" #include "teid.h" #include "cp.h" #include "pfcp_session.h" #include "pfcp_messages_decoder.h" #include "pfcp_messages_encoder.h" #define DIAMETER_PCC_RULE_EVENT (5142) extern int s11_fd; extern int s11_fd_v6; extern int s5s8_fd; extern int s5s8_fd_v6; extern int pfcp_fd; extern int pfcp_fd_v6; extern peer_addr_t upf_pfcp_sockaddr; extern int clSystemLog; extern pfcp_config_t config; void start_throttle_timer(node_address_t *node_ip, int thrtlng_delay_val, uint8_t thrtl_fact) { int ret = 0; throttle_timer *timer_data = NULL; /* Fill timer entry */ timer_data = rte_zmalloc_socket(NULL, sizeof(throttle_timer), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(timer_data == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "Memory for throttling timer, Error: %s \n", LOG_VALUE, rte_strerror(rte_errno)); return; } timer_data->node_ip = node_ip; timer_data->throttle_factor = thrtl_fact; TIMER_GET_CURRENT_TP(timer_data->start_time); /* Add entry into a hash */ ret = rte_hash_add_key_data(thrtl_timer_by_nodeip_hash, (const void *)node_ip, timer_data); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry into throttling timer hash for MME node " " of IP Type : %s\n with IP IPv4 : "IPV4_ADDR"\t and IPv6 : "IPv6_FMT"" "\n\tError= %d\n", LOG_VALUE, ip_type_str(node_ip->ip_type), IPV4_ADDR_HOST_FORMAT(node_ip->ipv4_addr), PRINT_IPV6_ADDR(node_ip->ipv6_addr),ret); rte_free(timer_data); timer_data = NULL; return; } /*Register timer callback*/ if(!(gst_timer_init(&timer_data->pt, ttInterval, thrtle_timer_callback, thrtlng_delay_val, timer_data))){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Faild to initialize timer entry for throttling timer\n", LOG_VALUE); ret = rte_hash_del_key(thrtl_timer_by_nodeip_hash, (const void *)node_ip); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Timer Entry not found for node " " of IP Type : %s\n with IP IPv4 : "IPV4_ADDR"\t and IPv6 : "IPv6_FMT"" "\n\tError= %d\n", LOG_VALUE, ip_type_str(node_ip->ip_type), IPV4_ADDR_HOST_FORMAT(node_ip->ipv4_addr), PRINT_IPV6_ADDR(node_ip->ipv6_addr),ret); } rte_free(timer_data); timer_data = NULL; return; } if (starttimer(&timer_data->pt) != true) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Periodic Timer " "failed to start timer for throttling \n", LOG_VALUE); ret = rte_hash_del_key(thrtl_timer_by_nodeip_hash, (const void *)node_ip); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Timer Entry not found for node " " of IP Type : %s\n with IP IPv4 : "IPV4_ADDR"\t and IPv6 : "IPv6_FMT"" "\n\tError= %d\n", LOG_VALUE, ip_type_str(node_ip->ip_type), IPV4_ADDR_HOST_FORMAT(node_ip->ipv4_addr), PRINT_IPV6_ADDR(node_ip->ipv6_addr),ret); } rte_free(timer_data); timer_data = NULL; return; }else{ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Throttling Timer Entry Started Successfully" " of IP Type : %s\n with IP IPv4 : "IPV4_ADDR"\t and IPv6 : "IPv6_FMT "\n", LOG_VALUE, ip_type_str(node_ip->ip_type), IPV4_ADDR_HOST_FORMAT(node_ip->ipv4_addr), PRINT_IPV6_ADDR(node_ip->ipv6_addr)); } } uint8_t delete_thrtle_timer(node_address_t *node_ip) { int ret = 0; uint8_t extend_timer_value = 0; thrtle_count *thrtl_cnt = NULL; throttle_timer *timer_data = NULL; ret = rte_hash_lookup_data(thrtl_timer_by_nodeip_hash, (const void *)node_ip, (void **)&timer_data); if(ret >= 0){ if(timer_data->pt.ti_id != 0) { extend_timer_value = TIMER_GET_ELAPSED_NS(timer_data->start_time) / 1000000000; stoptimer(&timer_data->pt.ti_id); deinittimer(&timer_data->pt.ti_id); ret = rte_hash_lookup_data(thrtl_ddn_count_hash, (const void *)timer_data->node_ip, (void **)&thrtl_cnt); if(ret >= 0){ delete_from_sess_info_list(thrtl_cnt->sess_ptr); } ret = rte_hash_del_key(thrtl_ddn_count_hash, (const void *)node_ip); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Throttling Count Entry not found for" " of IP Type : %s\n with IP IPv4 : "IPV4_ADDR"\t and IPv6 : "IPv6_FMT "\n", LOG_VALUE, ip_type_str(node_ip->ip_type), IPV4_ADDR_HOST_FORMAT(node_ip->ipv4_addr), PRINT_IPV6_ADDR(node_ip->ipv6_addr)); } ret = rte_hash_del_key(thrtl_timer_by_nodeip_hash, (const void *)node_ip); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Timer Entry not found for node " " of IP Type : %s\n with IP IPv4 : "IPV4_ADDR"\t and IPv6 : "IPv6_FMT"" "\n\tError= %d\n", LOG_VALUE, ip_type_str(node_ip->ip_type), IPV4_ADDR_HOST_FORMAT(node_ip->ipv4_addr), PRINT_IPV6_ADDR(node_ip->ipv6_addr),ret); } if (timer_data != NULL) { rte_free(timer_data); timer_data = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Throttling Timer Entry Deleted Successfully" " of IP Type : %s\n with IP IPv4 : "IPV4_ADDR"\t and IPv6 : "IPv6_FMT "\n", LOG_VALUE, ip_type_str(node_ip->ip_type), IPV4_ADDR_HOST_FORMAT(node_ip->ipv4_addr), PRINT_IPV6_ADDR(node_ip->ipv6_addr)); } } } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Timer Entry not found for node" "of IP Type : %s\n with IP IPv4 : "IPV4_ADDR "\t and IPv6 : "IPv6_FMT"" "\n", LOG_VALUE, ip_type_str(node_ip->ip_type), IPV4_ADDR_HOST_FORMAT(node_ip->ipv4_addr), PRINT_IPV6_ADDR(node_ip->ipv6_addr)); } return extend_timer_value; } void delete_sess_in_thrtl_timer(ue_context *context, uint64_t sess_id) { throttle_timer *thrtle_timer_data = NULL; thrtle_count *thrtl_cnt = NULL; sess_info *traverse = NULL; sess_info *prev = NULL; sess_info *head = NULL; int ret = 0; if((rte_hash_lookup_data(thrtl_timer_by_nodeip_hash, (const void *)&context->s11_mme_gtpc_ip, (void **)&thrtle_timer_data)) >= 0 ){ ret = rte_hash_lookup_data(thrtl_ddn_count_hash, (const void*)thrtle_timer_data->node_ip, (void **)&thrtl_cnt); if (ret >= 0){ if (thrtl_cnt->sess_ptr != NULL){ head = thrtl_cnt->sess_ptr; for(traverse = head; traverse != NULL; traverse = traverse->next){ if(traverse->sess_id == sess_id){ if(traverse == head){ head = head->next; }else{ for(prev = head; prev->next != traverse; prev= prev->next); prev->next = traverse->next; } rte_free(traverse); traverse = NULL; } } } } } } void start_ddn_timer_entry(struct rte_hash *hash, uint64_t seid, int delay_value, gstimercallback cb) { int ret = 0; uint32_t teid = 0; ue_level_timer *timer_data = NULL; /* Fill timer entry */ timer_data = fill_timer_entry(seid); if(timer_data != NULL){ /* Add timer entry into hash */ teid = UE_SESS_ID(seid); ret = rte_hash_add_key_data(hash, &teid, timer_data); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add into ddn timer entry hash for teid = %u" "\n\tError= %d\n", LOG_VALUE, teid, ret); rte_free(timer_data); timer_data = NULL; return; } /*Register timer callback*/ if(!gst_timer_init(&timer_data->pt, ttInterval, cb, delay_value, timer_data)){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Faild to initialize timer entry for downlink data notification\n", LOG_VALUE); ret = rte_hash_del_key(hash, &teid); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Timer Entry not " "found for teid:%u\n", LOG_VALUE, teid); } rte_free(timer_data); timer_data = NULL; return; } TIMER_GET_CURRENT_TP(timer_data->start_time); if(delay_value != 0){ if (starttimer(&timer_data->pt) != true) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Periodic Timer " "failed to start timer for downlink data notification \n", LOG_VALUE); ret = rte_hash_del_key(hash, &teid); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Timer Entry not " "found for teid:%u\n", LOG_VALUE, teid); } rte_free(timer_data); timer_data = NULL; return; } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"DDN Timer Entry Started Successfully" "for teid:%u\n", LOG_VALUE, teid); } } } } void delete_entry_from_sess_hash(uint64_t seid, struct rte_hash *sess_hash) { int ret = 0; pdr_ids *pfcp_pdr_id = NULL; ret = rte_hash_lookup_data(sess_hash, &seid, (void **)&pfcp_pdr_id); if(ret >= 0){ ret = rte_hash_del_key(sess_hash, &seid); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No session " "found for session id:%u\n", LOG_VALUE, seid); } if(pfcp_pdr_id != NULL){ rte_free(pfcp_pdr_id); pfcp_pdr_id = NULL; } } } uint8_t delete_ddn_timer_entry(struct rte_hash *hash, uint32_t teid, struct rte_hash *sess_hash) { int ret = 0; ue_context *context = NULL; uint8_t extend_timer_value = 0; ue_level_timer *timer_data = NULL; ret = rte_hash_lookup_data(hash, &teid, (void **)&timer_data); if(ret >= 0){ if(timer_data->pt.ti_id != 0) { /*lookup and delete the entry if present*/ ret = get_ue_context(teid, &context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE " "context for teid: %u\n", LOG_VALUE, teid); if(timer_data != NULL){ stoptimer(&timer_data->pt.ti_id); deinittimer(&timer_data->pt.ti_id); rte_free(timer_data); timer_data = NULL; } return 0; } /* Cleanup the maintain PDR IDs to Seids */ for(uint8_t itr = 0; itr < MAX_BEARERS; itr++){ if(context->pdns[itr] != NULL){ delete_entry_from_sess_hash(context->pdns[itr]->seid, sess_hash); } } /* Delete the timer entry from hash with key teid */ ret = rte_hash_del_key(hash, &teid); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Timer Entry not " "found for teid:%u\n", LOG_VALUE, teid); } if (timer_data != NULL) { extend_timer_value = TIMER_GET_ELAPSED_NS(timer_data->start_time) / 1000000000; /* Stop Running timer and delete the timer obj */ stoptimer(&timer_data->pt.ti_id); deinittimer(&timer_data->pt.ti_id); rte_free(timer_data); timer_data = NULL; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"DDN Timer Entry successfully" " Deleted for teid:%u\n", LOG_VALUE, teid); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Timer Entry not " "found for teid:%u\n", LOG_VALUE, teid); } return extend_timer_value; } /* Callback called after throttled timer get expired */ void thrtle_timer_callback(gstimerinfo_t *ti, const void *data_t ) { #pragma GCC diagnostic push /* require GCC 4.6 */ #pragma GCC diagnostic ignored "-Wcast-qual" throttle_timer *timer_entry = (throttle_timer*)data_t; #pragma GCC diagnostic pop int ret = 0; pdr_ids pfcp_pdr_id = {0}; ue_context *context = NULL; thrtle_count *thrtl_cnt = NULL; sess_info *traverse = NULL; thrtl_cnt = get_throtle_count(timer_entry->node_ip, DELETE_ENTRY); if (thrtl_cnt == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"FAILED: To get throtlling count" "of IP Type : %s\n with IP IPv4 : "IPV4_ADDR "\t and IPv6 : "IPv6_FMT"" "\n", LOG_VALUE, ip_type_str(timer_entry->node_ip->ip_type), IPV4_ADDR_HOST_FORMAT(timer_entry->node_ip->ipv4_addr), PRINT_IPV6_ADDR(timer_entry->node_ip->ipv6_addr)); delete_thrtle_timer(timer_entry->node_ip); return; } if (thrtl_cnt->sess_ptr == NULL){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "FAILED: To get buffered session entry" " for throttling \n\n", LOG_VALUE); delete_thrtle_timer(timer_entry->node_ip); return; } for(traverse = thrtl_cnt->sess_ptr; traverse != NULL; traverse = traverse->next){ uint32_t teid = UE_SESS_ID(traverse->sess_id); ret = get_ue_context(teid, &context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE " "context for teid: %u\n", LOG_VALUE, teid); } for(uint8_t itr = 0; itr < MAX_BEARERS; itr++){ if(context->pdns[itr] != NULL){ if(context->pdns[itr]->seid == traverse->sess_id){ memcpy(pfcp_pdr_id.pdr_id, traverse->pdr_id, sizeof(uint16_t)); pfcp_pdr_id.pdr_count = traverse->pdr_count; pfcp_pdr_id.ddn_buffered_count = 0; ret = ddn_by_session_id(traverse->sess_id, &pfcp_pdr_id); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to process DDN request \n", LOG_VALUE); } context->pfcp_rept_resp_sent_flag = 0; } } } } delete_thrtle_timer(timer_entry->node_ip); RTE_SET_USED(ti); } void send_pfcp_sess_mod_req_for_ddn(pdn_connection *pdn) { uint32_t seq = 0; int ret = 0; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; node_address_t node_value = {0}; set_pfcpsmreqflags(&(pfcp_sess_mod_req.pfcpsmreq_flags)); pfcp_sess_mod_req.pfcpsmreq_flags.drobu = 1; /*Filling Node ID for F-SEID*/ if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV4) { uint8_t temp[IPV6_ADDRESS_LEN] = {0}; ret = fill_ip_addr(config.pfcp_ip.s_addr, temp, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV6) { ret = fill_ip_addr(0, config.pfcp_ip_v6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } set_fseid(&(pfcp_sess_mod_req.cp_fseid), pdn->seid, node_value); seq = get_pfcp_sequence_number(PFCP_SESSION_MODIFICATION_REQUEST, seq); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_mod_req.header), PFCP_SESSION_MODIFICATION_REQUEST, HAS_SEID, seq, pdn->context->cp_mode); pfcp_sess_mod_req.header.seid_seqno.has_seid.seid = pdn->dp_seid; uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); pfcp_header_t *header = (pfcp_header_t *) pfcp_msg; header->message_len = htons(encoded - PFCP_IE_HDR_SIZE); if(pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr, SENT) < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Failed to send" "PFCP Session Modification Request %i\n", LOG_VALUE, errno); } } /* PFCP: Callback calls while expired UE Level timer for buffering rpt req msg*/ void dl_buffer_timer_callback(gstimerinfo_t *ti, const void *data_t ) { #pragma GCC diagnostic push /* require GCC 4.6 */ #pragma GCC diagnostic ignored "-Wcast-qual" ue_level_timer *timer_entry = (ue_level_timer *)data_t; #pragma GCC diagnostic pop int ret = 0; bool match_found = FALSE; pdr_ids *pfcp_pdr_id = NULL; ue_context *context = NULL; pdn_connection *pdn = NULL; uint32_t teid = UE_SESS_ID(timer_entry->sess_id); /* Send Pfcp Session Modification Request with apply action DROP */ ret = get_ue_context(teid, &context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE " "context for teid: %u\n", LOG_VALUE, teid); delete_ddn_timer_entry(dl_timer_by_teid_hash, teid, pfcp_rep_by_seid_hash); return; } for(uint8_t itr_pdn = 0; itr_pdn < MAX_BEARERS; itr_pdn++){ if(context->pdns[itr_pdn]!=NULL){ pdn = context->pdns[itr_pdn]; ret = rte_hash_lookup_data(pfcp_rep_by_seid_hash, &pdn->seid, (void **)&pfcp_pdr_id); if(ret >= 0 && pfcp_pdr_id != NULL){ match_found = TRUE; } } } if(match_found == TRUE){ send_pfcp_sess_mod_req_for_ddn(pdn); } delete_ddn_timer_entry(dl_timer_by_teid_hash, teid, pfcp_rep_by_seid_hash); RTE_SET_USED(ti); } /* GTPv2C: UE Level timer */ void ddn_timer_callback(gstimerinfo_t *ti, const void *data_t ) { #pragma GCC diagnostic push /* require GCC 4.6 */ #pragma GCC diagnostic ignored "-Wcast-qual" ue_level_timer *timer_entry = (ue_level_timer *)data_t; #pragma GCC diagnostic pop int ret = 0; uint8_t cp_thrtl_fact = 0; pfcp_pdr_id_ie_t pdr[MAX_LIST_SIZE] = {0}; pdr_ids *pfcp_pdr_id = NULL; ue_context *context = NULL; throttle_timer *thrtle_timer_data = NULL; uint32_t teid = UE_SESS_ID(timer_entry->sess_id); ret = get_ue_context(teid, &context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE " "context for teid: %u\n", LOG_VALUE, teid); delete_ddn_timer_entry(timer_by_teid_hash, teid, ddn_by_seid_hash); return; } for(uint8_t i = 0; i < MAX_BEARERS; i++){ if(context->pdns[i] != NULL){ ret = rte_hash_lookup_data(ddn_by_seid_hash, &context->pdns[i]->seid, (void **)&pfcp_pdr_id); if(ret >= 0){ if((rte_hash_lookup_data(thrtl_timer_by_nodeip_hash, (const void *)&context->s11_mme_gtpc_ip, (void **)&thrtle_timer_data)) >= 0){ thrtle_count *thrtl_cnt = NULL; thrtl_cnt = get_throtle_count(&context->s11_mme_gtpc_ip, ADD_ENTRY); if(thrtl_cnt != NULL){ if(thrtl_cnt->prev_ddn_eval != 0){ cp_thrtl_fact = (thrtl_cnt->prev_ddn_discard/thrtl_cnt->prev_ddn_eval) * 100; if(cp_thrtl_fact > thrtle_timer_data->throttle_factor){ pfcp_pdr_id->ddn_buffered_count = 0; ret = ddn_by_session_id(context->pdns[i]->seid, pfcp_pdr_id); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to process DDN request \n", LOG_VALUE); } thrtl_cnt->prev_ddn_eval = thrtl_cnt->prev_ddn_eval + 1; context->pfcp_rept_resp_sent_flag = 1; }else{ for(uint8_t i = 0; i < MAX_LIST_SIZE; i++){ pdr[i].rule_id = pfcp_pdr_id->pdr_id[i]; } thrtl_cnt->prev_ddn_eval = thrtl_cnt->prev_ddn_eval + 1; thrtl_cnt->prev_ddn_discard = thrtl_cnt->prev_ddn_discard + 1; fill_sess_info_id(thrtl_cnt, context->pdns[i]->seid, pfcp_pdr_id->pdr_count, pdr); context->pfcp_rept_resp_sent_flag = 1; } } else { pfcp_pdr_id->ddn_buffered_count = 0; ret = ddn_by_session_id(context->pdns[i]->seid, pfcp_pdr_id); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to process DDN request \n", LOG_VALUE); } thrtl_cnt->prev_ddn_eval = thrtl_cnt->prev_ddn_eval + 1; context->pfcp_rept_resp_sent_flag = 1; } delete_ddn_timer_entry(timer_by_teid_hash, teid, ddn_by_seid_hash); return; } } else { pfcp_pdr_id->ddn_buffered_count = 0; ret = ddn_by_session_id(context->pdns[i]->seid, pfcp_pdr_id); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to process DDN request \n", LOG_VALUE); } context->pfcp_rept_resp_sent_flag = 1; } } } } delete_ddn_timer_entry(timer_by_teid_hash, teid, ddn_by_seid_hash); RTE_SET_USED(ti); } ue_level_timer * fill_timer_entry(uint64_t seid) { ue_level_timer *timer_entry = NULL; timer_entry = rte_zmalloc_socket(NULL, sizeof(ue_level_timer), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(timer_entry == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "Memory for ue_level_timer, Error: %s \n", LOG_VALUE, rte_strerror(rte_errno)); return NULL; } timer_entry->sess_id = seid; return(timer_entry); } bool add_timer_entry(peerData *conn_data, uint32_t timeout_ms, gstimercallback cb) { if (!init_timer(conn_data, timeout_ms, cb)) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT" =>%s - initialization of %s failed erro no %d\n", LOG_VALUE, getPrintableTime(), conn_data->name, errno); return false; } return true; } void timer_callback(gstimerinfo_t *ti, const void *data_t ) { int ret = 0; msg_info msg = {0}; ue_context *context = NULL; pdn_connection *pdn = NULL; struct resp_info *resp = NULL; RTE_SET_USED(ti); #pragma GCC diagnostic push /* require GCC 4.6 */ #pragma GCC diagnostic ignored "-Wcast-qual" peerData *data = (peerData *) data_t; #pragma GCC diagnostic pop /* require GCC 4.6 */ data->itr = config.request_tries; if (data->itr_cnt >= data->itr - 1) { ret = get_ue_context(data->teid, &context); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get Ue context for teid: %d\n", LOG_VALUE, data->teid); stoptimer(&data->pt.ti_id); deinittimer(&data->pt.ti_id); if(data != NULL){ rte_free(data); data = NULL; } return; } if(context != NULL && context->eps_bearers[data->ebi_index] != NULL && context->eps_bearers[data->ebi_index]->pdn != NULL ) { pdn = context->eps_bearers[data->ebi_index]->pdn; if(get_sess_entry(pdn->seid, &resp) == 0){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Session entry " "found for session id: %s",LOG_VALUE, gtp_type_str(resp->msg_type)); if(resp->state == ERROR_OCCURED_STATE){ reset_resp_info_structure(resp); cleanup_ue_and_bearer(data->teid, data->ebi_index); } else if (GTP_MODIFY_BEARER_REQ == resp->msg_type) { msg.gtpc_msg.mbr = resp->gtpc_msg.mbr; msg.msg_type = resp->msg_type; msg.cp_mode = context->cp_mode; mbr_error_response(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, context->cp_mode != PGWC ? S11_IFACE : S5S8_IFACE); if(context->piggyback == TRUE) { msg.msg_type = GTP_CREATE_BEARER_RSP; msg.gtpc_msg.cb_rsp.header.teid.has_teid.seq = resp->cb_rsp_attach.seq; msg.gtpc_msg.cb_rsp.cause.cause_value = resp->cb_rsp_attach.cause_value; msg.gtpc_msg.cb_rsp.cause.header.len = PRESENT; resp->bearer_count = resp->cb_rsp_attach.bearer_cnt; for(int idx =0 ; idx < resp->bearer_count ; idx ++) { msg.gtpc_msg.cb_rsp.bearer_contexts[idx].eps_bearer_id.header.len = PRESENT; msg.gtpc_msg.cb_rsp.bearer_contexts[idx].cause.header.len = PRESENT; msg.gtpc_msg.cb_rsp.bearer_contexts[idx].cause.cause_value = resp->cb_rsp_attach.bearer_cause_value[idx]; msg.gtpc_msg.cb_rsp.bearer_contexts[idx].eps_bearer_id.ebi_ebi = resp->cb_rsp_attach.ebi_ebi[idx]; resp->eps_bearer_ids[idx] = resp->cb_rsp_attach.ebi_ebi[idx]; } cbr_error_response(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, S5S8_IFACE); context->piggyback = FALSE; } } else if (GTP_BEARER_RESOURCE_CMD == resp->msg_type) { msg.gtpc_msg.bearer_rsrc_cmd = resp->gtpc_msg.bearer_rsrc_cmd; msg.msg_type = resp->msg_type; msg.cp_mode = context->cp_mode; send_bearer_resource_failure_indication(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, S11_IFACE); } else if (GTP_MODIFY_BEARER_CMD == resp->msg_type) { msg.gtpc_msg.mod_bearer_cmd = resp->gtpc_msg.mod_bearer_cmd; msg.msg_type = resp->msg_type; msg.cp_mode = context->cp_mode; modify_bearer_failure_indication(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, S11_IFACE); } else if ((GTP_CREATE_SESSION_REQ == resp->msg_type) || (GTP_CREATE_SESSION_RSP == resp->msg_type)) { msg.gtpc_msg.csr = resp->gtpc_msg.csr; msg.msg_type = resp->msg_type; msg.cp_mode = context->cp_mode; msg.teid = data->teid; msg.state = resp->state; if (!context->piggyback || context->cp_mode != SGWC) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Peer not responding, hence sending an error response\n", LOG_VALUE); cs_error_response(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, context->cp_mode != PGWC ? S11_IFACE : S5S8_IFACE); } else { clean_up_while_error(context->pdns[data->ebi_index]->default_bearer_id, context, data->teid, &context->imsi, 0, &msg); } } else if (GTP_DELETE_SESSION_REQ == resp->msg_type) { if(resp->state == PFCP_SESS_MOD_REQ_SNT_STATE) { /* when timer retry end on sxa interface in case of sgwc * then send delete session requent on s5s8 interface * after recieving DSR response scenerio will execute * similar to initial attach dettach */ send_delete_session_request_after_timer_retry(context, data->ebi_index); return; } msg.gtpc_msg.dsr = resp->gtpc_msg.dsr; msg.msg_type = resp->msg_type; msg.teid = resp->teid; ds_error_response(&msg, GTPV2C_CAUSE_REQUEST_ACCEPTED, CAUSE_SOURCE_SET_TO_0, context->cp_mode != PGWC ? S11_IFACE :S5S8_IFACE); } else if ((context->cp_mode == PGWC || context->cp_mode == SAEGWC ) && ((resp->msg_type == GX_RAR_MSG) || (resp->state == CREATE_BER_REQ_SNT_STATE))) { if (resp->msg_type == GX_RAR_MSG){ msg.gx_msg.rar.session_id.len = strnlen(resp->gx_sess_id, GX_SESS_ID_LEN); memcpy(msg.gx_msg.rar.session_id.val, resp->gx_sess_id, msg.gx_msg.rar.session_id.len); } if (pdn->policy.num_charg_rule_install) { cbr_error_response(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, GX_IFACE); } else if (pdn->policy.num_charg_rule_delete) { delete_bearer_error_response(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, S5S8_IFACE); } pdn->state = CONNECTED_STATE; } else if (((resp->msg_type == GTP_CREATE_BEARER_REQ) || (resp->msg_type == GTP_CREATE_BEARER_RSP)) && (context->cp_mode == SGWC)) { msg.msg_type = resp->msg_type; msg.gtpc_msg.cb_req = resp->gtpc_msg.cb_req; if(pdn->proc == UE_REQ_BER_RSRC_MOD_PROC) { send_bearer_resource_failure_indication(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, context->cp_mode != PGWC ? S11_IFACE : S5S8_IFACE); provision_ack_ccr(pdn, pdn->eps_bearers[data->ebi_index], RULE_ACTION_ADD, RESOURCE_ALLOCATION_FAILURE); } else { cbr_error_response(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, S5S8_IFACE); } } else if (((resp->msg_type == GTP_DELETE_BEARER_REQ) || (resp->msg_type == GTP_DELETE_BEARER_RSP))) { msg.gtpc_msg.db_req = resp->gtpc_msg.db_req; msg.msg_type = resp->msg_type; if(pdn->proc == UE_REQ_BER_RSRC_MOD_PROC) { send_bearer_resource_failure_indication(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, context->cp_mode != PGWC ? S11_IFACE : S5S8_IFACE); provision_ack_ccr(pdn, pdn->eps_bearers[data->ebi_index], RULE_ACTION_DELETE, RESOURCE_ALLOCATION_FAILURE); } else { delete_bearer_error_response(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, S5S8_IFACE); } } else if ((context->cp_mode == PGWC || context->cp_mode == SAEGWC ) && ((resp->state == DELETE_BER_REQ_SNT_STATE) || (resp->state == UPDATE_BEARER_REQ_SNT_STATE) || (resp->msg_type == GTP_UPDATE_BEARER_RSP))) { if (pdn->proc == UE_REQ_BER_RSRC_MOD_PROC) { /* TODO: Timer Flow not handled properly, added temp solution */ if (resp->state == UPDATE_BEARER_REQ_SNT_STATE) { resp->msg_type = GTP_UPDATE_BEARER_REQ; msg.gtpc_msg.ub_req = resp->gtpc_msg.ub_req; } /* TODO: Timer Flow not handled properly, added temp solution */ if (resp->msg_type == GTP_UPDATE_BEARER_RSP) { msg.gtpc_msg.ub_rsp = resp->gtpc_msg.ub_rsp; } /* TODO: Timer Flow not handled properly, added temp solution */ if (resp->state == DELETE_BER_REQ_SNT_STATE) { resp->msg_type = GTP_DELETE_BEARER_REQ; msg.gtpc_msg.db_req = resp->gtpc_msg.db_req; } msg.msg_type = resp->msg_type; msg.teid = resp->teid; send_bearer_resource_failure_indication(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, context->cp_mode != PGWC ? S11_IFACE : S5S8_IFACE); provision_ack_ccr(pdn, pdn->eps_bearers[data->ebi_index], RULE_ACTION_MODIFY, RESOURCE_ALLOCATION_FAILURE); } else { gen_reauth_error_response(pdn, DIAMETER_UNABLE_TO_COMPLY); } } else if (resp->msg_type == GTP_UPDATE_BEARER_REQ) { msg.gtpc_msg.ub_req = resp->gtpc_msg.ub_req; msg.msg_type = resp->msg_type; ubr_error_response(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, context->cp_mode == SGWC ? S5S8_IFACE : GX_IFACE); } else if (resp->msg_type == GTP_RELEASE_ACCESS_BEARERS_REQ) { msg.gtpc_msg.rel_acc_ber_req = resp->gtpc_msg.rel_acc_ber_req; msg.msg_type = resp->msg_type; release_access_bearer_error_response(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, context->cp_mode != PGWC ? S11_IFACE : S5S8_IFACE); } else if(resp->state == DDN_REQ_SNT_STATE){ send_pfcp_sess_mod_req_for_ddn(pdn); /* Remove session Entry from buffered ddn request hash */ pdr_ids *pfcp_pdr_id = delete_buff_ddn_req(pdn->seid); if(pfcp_pdr_id != NULL) { rte_free(pfcp_pdr_id); pfcp_pdr_id = NULL; } } else{ /* Need to handle for other request */ } } } if(data->pt.ti_id != 0) { stoptimer(&data->pt.ti_id); deinittimer(&data->pt.ti_id); /* free peer data when timer is de int */ if(data != NULL){ rte_free(data); data = NULL; } /*if this line is uncommented timer is not getting deleted*/ //pdn->timer_entry = NULL; } return; } /* timer retry handler */ switch(data->portId) { case GX_IFACE: break; case S11_IFACE: timer_retry_send(s11_fd, s11_fd_v6, data, context); break; case S5S8_IFACE: timer_retry_send(s5s8_fd, s5s8_fd_v6, data, context); break; case PFCP_IFACE: timer_retry_send(pfcp_fd, pfcp_fd_v6, data, context); break; default: break; } data->itr_cnt++; return; } void delete_association_timer(peerData *data) { stoptimer(&data->pt.ti_id); deinittimer(&data->pt.ti_id); /* free peer data when timer is de int */ if(data != NULL){ rte_free(data); data = NULL; } } void association_fill_error_response(peerData *data) { int ret = 0; msg_info msg = {0}; ue_context *context = NULL; upf_context_t *upf_context = NULL; context_key *key = NULL; uint8_t index = 0; ret = get_ue_context(data->teid, &context); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get Ue context for teid: %d\n", LOG_VALUE, data->teid); delete_association_timer(data); return; } ret = rte_hash_lookup_data(upf_context_by_ip_hash, (const void*) &(context->eps_bearers[data->ebi_index]->pdn->upf_ip), (void **) &(upf_context)); if (upf_context != NULL && ret >= 0) { for(uint8_t idx = 0; idx < upf_context->csr_cnt; idx++) { msg.msg_type = GTP_CREATE_SESSION_REQ; key = (context_key *) upf_context->pending_csr_teid[idx]; msg.gtpc_msg.csr.sender_fteid_ctl_plane.teid_gre_key = key->sender_teid; msg.gtpc_msg.csr.header.teid.has_teid.seq = key->sequence; for (uint8_t itr = 0; itr < MAX_BEARERS; ++itr) { if(key->bearer_ids[itr] != 0){ msg.gtpc_msg.csr.bearer_contexts_to_be_created[index].header.len = sizeof(uint8_t) + IE_HEADER_SIZE; msg.gtpc_msg.csr.bearer_contexts_to_be_created[index].eps_bearer_id.ebi_ebi = key->bearer_ids[itr]; index++; } } msg.gtpc_msg.csr.bearer_count = index; msg.gtpc_msg.csr.header.teid.has_teid.teid = key->teid; msg.cp_mode = context->cp_mode; cs_error_response(&msg, GTPV2C_CAUSE_REMOTE_PEER_NOT_RESPONDING, CAUSE_SOURCE_SET_TO_0, context->cp_mode != PGWC ? S11_IFACE : S5S8_IFACE); } } if(data->pt.ti_id != 0) { delete_association_timer(data); } return; } void association_timer_callback(gstimerinfo_t *ti, const void *data_t ) { ue_context *context = NULL; upf_context_t *upf_context = NULL; int ret = 0; upfs_dnsres_t *entry = NULL; RTE_SET_USED(ti); pdn_connection *pdn = NULL; pfcp_assn_setup_req_t pfcp_ass_setup_req = {0}; int decoded = 0; node_address_t cp_node_value = {0}; #pragma GCC diagnostic push /* require GCC 4.6 */ #pragma GCC diagnostic ignored "-Wcast-qual" peerData *data = (peerData *) data_t; #pragma GCC diagnostic pop /* require GCC 4.6 */ if(config.use_dns){ ret = get_ue_context(data->teid, &context); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" " get Ue context for teid: %d\n", LOG_VALUE, data->teid); delete_association_timer(data); return; } if(rte_hash_lookup_data(upf_context_by_ip_hash, (const void*) &(context->eps_bearers[data->ebi_index]->pdn->upf_ip), (void **) &(upf_context)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Upf Context " "not found of IP Type : %s\n with IP IPv4 : "IPV4_ADDR"\t" " and IPv6 : "IPv6_FMT"", LOG_VALUE, ip_type_str(context->eps_bearers[data->ebi_index]->pdn->upf_ip.ip_type), IPV4_ADDR_HOST_FORMAT(context->eps_bearers[data->ebi_index]->pdn->upf_ip.ipv4_addr), PRINT_IPV6_ADDR(context->eps_bearers[data->ebi_index]->pdn->upf_ip.ipv6_addr)); delete_association_timer(data); return; } if (upflist_by_ue_hash_entry_lookup(&data->imsi, sizeof(data->imsi), &entry) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Failure in upflist_by_ue_hash_entry_lookup\n",LOG_VALUE); delete_association_timer(data); return; } } if(config.use_dns){ if ((entry->current_upf) == (entry->upf_count - 1)){ association_fill_error_response(data); return; } }else{ association_fill_error_response(data); return; } if (entry->current_upf < (entry->upf_count - 1)) { upf_context_t *tmp_upf_context = upf_context; /* Delete entry from teid info list for given upf*/ delete_entry_from_teid_list(context->eps_bearers[data->ebi_index]->pdn->upf_ip, &upf_teid_info_head); /* Delete old upf_ip entry from hash */ rte_hash_del_key(upf_context_by_ip_hash, (const void *) &context->eps_bearers[data->ebi_index]->pdn->upf_ip); if (entry->upf_ip_type == PDN_TYPE_IPV4 && *entry->upf_ip[entry->current_upf].ipv6.s6_addr && (config.pfcp_ip_type == PDN_TYPE_IPV4_IPV6 || config.pfcp_ip_type == PDN_TYPE_IPV6)) { ret = fill_ip_addr(0, entry->upf_ip[entry->current_upf].ipv6.s6_addr, &data->dstIP); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } ret = fill_ip_addr(0, entry->upf_ip[entry->current_upf].ipv6.s6_addr, &context->eps_bearers[data->ebi_index]->pdn->upf_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } entry->upf_ip_type |= PDN_TYPE_IPV6; } else if (entry->upf_ip_type == PDN_TYPE_IPV6 && entry->upf_ip[entry->current_upf].ipv4.s_addr != 0 && (config.pfcp_ip_type == PDN_TYPE_IPV4_IPV6 || config.pfcp_ip_type == PDN_TYPE_IPV4)) { uint8_t temp[IPV6_ADDRESS_LEN] = {0}; ret = fill_ip_addr(entry->upf_ip[entry->current_upf].ipv4.s_addr, temp, &data->dstIP); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } ret = fill_ip_addr(entry->upf_ip[entry->current_upf].ipv4.s_addr, temp, &context->eps_bearers[data->ebi_index]->pdn->upf_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } entry->upf_ip_type |= PDN_TYPE_IPV4; } else { entry->current_upf++; /*store new upf_ip entry */ memcpy(context->eps_bearers[data->ebi_index]->pdn->fqdn, entry->upf_fqdn[entry->current_upf], strnlen(entry->upf_fqdn[entry->current_upf], MAX_HOSTNAME_LENGTH)); if ((config.pfcp_ip_type == PDN_TYPE_IPV4_IPV6 || config.pfcp_ip_type == PDN_TYPE_IPV6) && (*entry->upf_ip[entry->current_upf].ipv6.s6_addr)) { ret = fill_ip_addr(0, entry->upf_ip[entry->current_upf].ipv6.s6_addr, &data->dstIP); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } ret = fill_ip_addr(0, entry->upf_ip[entry->current_upf].ipv6.s6_addr, &context->eps_bearers[data->ebi_index]->pdn->upf_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } entry->upf_ip_type = PDN_TYPE_IPV6; } else if ((config.pfcp_ip_type == PDN_TYPE_IPV4_IPV6 || config.pfcp_ip_type == PDN_TYPE_IPV4) && (entry->upf_ip[entry->current_upf].ipv4.s_addr != 0)) { uint8_t temp[IPV6_ADDRESS_LEN] = {0}; ret = fill_ip_addr(entry->upf_ip[entry->current_upf].ipv4.s_addr, temp, &data->dstIP); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } ret = fill_ip_addr(entry->upf_ip[entry->current_upf].ipv4.s_addr, temp, &context->eps_bearers[data->ebi_index]->pdn->upf_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } entry->upf_ip_type = PDN_TYPE_IPV4; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Requested type and DNS supported type are not same\n", LOG_VALUE); } } decoded = decode_pfcp_assn_setup_req_t(data->buf, &pfcp_ass_setup_req); clLog(clSystemLog, eCLSeverityDebug,LOG_FORMAT "decoded Association " "Request while retrying with %d ", LOG_VALUE, decoded); /*Filling CP Node ID*/ if (context->eps_bearers[data->ebi_index]->pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV4) { uint8_t temp[IPV6_ADDRESS_LEN] = {0}; ret = fill_ip_addr(config.pfcp_ip.s_addr, temp, &cp_node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else if (context->eps_bearers[data->ebi_index]->pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV6) { ret = fill_ip_addr(0, config.pfcp_ip_v6.s6_addr, &cp_node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } set_node_id(&pfcp_ass_setup_req.node_id, cp_node_value); int encoded = encode_pfcp_assn_setup_req_t(&pfcp_ass_setup_req, data->buf); data->buf_len = encoded; clLog(clSystemLog, eCLSeverityDebug,LOG_FORMAT "encoded Association " "Request while retrying with %d ", LOG_VALUE, encoded); /* Assign new upf_ip entry to global variable holding upf_ip */ ret = set_dest_address(context->eps_bearers[data->ebi_index]->pdn->upf_ip, &upf_pfcp_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } /*Searching UPF Context for New DNS IP*/ ret = 0; ret = rte_hash_lookup_data(upf_context_by_ip_hash, (const void*) &(context->eps_bearers[data->ebi_index]->pdn->upf_ip), (void **) &(upf_context)); if (ret == -ENOENT) { /* Add entry of new upf_ip in hash */ ret = upf_context_entry_add(&(context->eps_bearers[data->ebi_index]->pdn->upf_ip), upf_context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"failed to add entry %d \n", LOG_VALUE, ret); return ; } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Added entry " "UPF Context for IP Type : %s " "with IPv4 : "IPV4_ADDR"\t and IPv6 : "IPv6_FMT"", LOG_VALUE, ip_type_str(context->eps_bearers[data->ebi_index]->pdn->upf_ip.ip_type), IPV4_ADDR_HOST_FORMAT(context->eps_bearers[data->ebi_index]->pdn->upf_ip.ipv4_addr), PRINT_IPV6_ADDR(context->eps_bearers[data->ebi_index]->pdn->upf_ip.ipv6_addr)); } /* Send the Association Request to next UPF */ if (data->portId == PFCP_IFACE) { timer_retry_send(pfcp_fd, pfcp_fd_v6, data, context); } } else if (ret == -EINVAL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid key In RTE HASH Look UP DATA: %d \n", LOG_VALUE, ret); delete_association_timer(data); return ; } else { if(upf_context->state == PFCP_ASSOC_RESP_RCVD_STATE || upf_context->assoc_status == ASSOC_ESTABLISHED) { ret = get_ue_context(data->teid, &context); if(ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"UE context not found ", LOG_VALUE); } pdn = GET_PDN(context, data->ebi_index); if(pdn == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get " "pdn for ebi_index %d\n", LOG_VALUE, data->ebi_index); } pdn->upf_ip.ipv4_addr = upf_pfcp_sockaddr.ipv4.sin_addr.s_addr; memcpy(pdn->upf_ip.ipv6_addr, upf_pfcp_sockaddr.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); pdn->upf_ip.ip_type = upf_pfcp_sockaddr.type; int count = 0; upf_context->csr_cnt = tmp_upf_context->csr_cnt; for (uint8_t i = 0; i < tmp_upf_context->csr_cnt; i++) { context_key *key = (context_key *)tmp_upf_context->pending_csr_teid[i]; if (get_ue_context(key->teid, &context) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"UE context not found " "for teid: %d\n", LOG_VALUE, key->teid); continue; } pdn = GET_PDN(context, key->ebi_index); if(pdn == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get " "pdn for ebi_index %d\n", LOG_VALUE, key->ebi_index); continue; } // pdn->upf_ipv4.s_addr = upf_pfcp_sockaddr.ipv4.sin_addr.s_addr; ret = process_pfcp_sess_est_request(key->teid, pdn, upf_context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to process PFCP " "session eshtablishment request %d \n", LOG_VALUE, ret); fill_response(pdn->seid, key); } fill_response(pdn->seid, key); rte_free(tmp_upf_context->pending_csr_teid[i]); count++; } /*for*/ upf_context->csr_cnt = upf_context->csr_cnt - count; tmp_upf_context->csr_cnt = tmp_upf_context->csr_cnt - count; delete_association_timer(data); } } } return; } peerData * fill_timer_entry_data(enum source_interface iface, peer_addr_t *peer_addr, uint8_t *buf, uint16_t buf_len, uint8_t itr, uint32_t teid, int ebi_index ) { peerData *timer_entry = NULL; timer_entry = rte_zmalloc_socket(NULL, sizeof(peerData), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(timer_entry == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "Memory for timer entry, Error: %s \n", LOG_VALUE, rte_strerror(rte_errno)); return NULL; } timer_entry->dstIP.ip_type = peer_addr->type; if (peer_addr->type == PDN_TYPE_IPV4) { timer_entry->dstPort = peer_addr->ipv4.sin_port; timer_entry->dstIP.ipv4_addr = peer_addr->ipv4.sin_addr.s_addr; } else { timer_entry->dstPort = peer_addr->ipv6.sin6_port; memcpy(&timer_entry->dstIP.ipv6_addr, peer_addr->ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } timer_entry->portId = (uint8_t)iface; timer_entry->itr = itr; timer_entry->teid = teid; timer_entry->ebi_index = ebi_index; timer_entry->buf_len = buf_len; memcpy(&timer_entry->buf,(uint8_t *)buf, buf_len); return(timer_entry); } void delete_pfcp_if_timer_entry(uint32_t teid, int ebi_index ) { int ret = 0; peerData *data = NULL; ue_context *context = NULL; ret = get_ue_context(teid, &context); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get Ue context for teid: %d\n", LOG_VALUE, teid); return; } if(context != NULL && context->eps_bearers[ebi_index] != NULL && context->eps_bearers[ebi_index]->pdn != NULL && context->eps_bearers[ebi_index]->pdn->timer_entry != NULL) { data = context->eps_bearers[ebi_index]->pdn->timer_entry; if(data->pt.ti_id != 0) { stoptimer(&data->pt.ti_id); deinittimer(&data->pt.ti_id); /* free peer data when timer is de int */ if(data != NULL){ rte_free(data); data = NULL; } context->eps_bearers[ebi_index]->pdn->timer_entry = NULL; } } return; } void delete_gtpv2c_if_timer_entry(uint32_t teid, int ebi_index) { int ret = 0; peerData *data = NULL; ue_context *context = NULL; ret = get_ue_context(teid, &context); if(ret < 0 || context == NULL ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Context found " "for teid: %x\n", LOG_VALUE, teid); return; } if(context != NULL && context->eps_bearers[ebi_index] != NULL && context->eps_bearers[ebi_index]->pdn != NULL && context->eps_bearers[ebi_index]->pdn->timer_entry != NULL){ data = context->eps_bearers[ebi_index]->pdn->timer_entry; if(data->pt.ti_id != 0) { stoptimer(&data->pt.ti_id); deinittimer(&data->pt.ti_id); /* free peer data when timer is de int */ if(data != NULL){ rte_free(data); data = NULL; } } } return; } void delete_timer_entry(uint32_t teid) { int ret = 0; peerData *data = NULL; eps_bearer *bearer = NULL; ret = get_bearer_by_teid(teid, &bearer); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Bearer found " "for teid: %x\n", LOG_VALUE, teid); return; } if(bearer != NULL && bearer->pdn != NULL && bearer->pdn->timer_entry != NULL ) { data = bearer->pdn->timer_entry; if(data->pt.ti_id != 0) { stoptimer(&data->pt.ti_id); deinittimer(&data->pt.ti_id); /* free peer data when timer is de int */ if(data != NULL){ rte_free(data); data = NULL; } bearer->pdn->timer_entry = NULL; } } return; } void add_pfcp_if_timer_entry(uint32_t teid, peer_addr_t *peer_addr, uint8_t *buf, uint16_t buf_len, int ebi_index ) { int ret = 0; peerData *timer_entry = NULL; ue_context *context = NULL; ret = get_ue_context(teid, &context); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to get Ue context for teid: %x \n", LOG_VALUE, teid); return; } /* fill and add timer entry */ timer_entry = fill_timer_entry_data(PFCP_IFACE, peer_addr, buf, buf_len, config.request_tries, teid, ebi_index); if (timer_entry == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to Add timer entry for teid: %x\n", LOG_VALUE, teid); return; } if(!(add_timer_entry(timer_entry, config.request_timeout, timer_callback))) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add timer entry...\n", LOG_VALUE); } if(context != NULL && context->eps_bearers[ebi_index] != NULL && context->eps_bearers[ebi_index]->pdn != NULL ) { context->eps_bearers[ebi_index]->pdn->timer_entry = timer_entry; if (starttimer(&timer_entry->pt) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Periodic Timer failed to start...\n", LOG_VALUE); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Periodic Timer is started for TEID:%u\n", LOG_VALUE, teid); } } } void add_gtpv2c_if_timer_entry(uint32_t teid, peer_addr_t *peer_addr, uint8_t *buf, uint16_t buf_len, int ebi_index , enum source_interface iface, uint8_t cp_mode) { int ret = 0; peerData *timer_entry = NULL; eps_bearer *bearer = NULL; ue_context *context = NULL; /* fill and add timer entry */ timer_entry = fill_timer_entry_data(iface, peer_addr, buf, buf_len, config.request_tries, teid, ebi_index); if (timer_entry == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to Add timer entry for teid: %x\n", LOG_VALUE, teid); return; } if(!(add_timer_entry(timer_entry, config.request_timeout, timer_callback))) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Faild to add timer entry...\n", LOG_VALUE); } if(SGWC == cp_mode) { /* if we get s5s8 fteid we will retrive bearer , if we get sgw s11 fteid we will retrive ue contex */ ret = get_bearer_by_teid(teid, &bearer); if ( ret < 0) { /*The teid might be of S11*/ ret = get_ue_context(teid, &context); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get Ue context for teid: %d\n", LOG_VALUE, teid); return; } if(context != NULL && context->eps_bearers[ebi_index] != NULL && context->eps_bearers[ebi_index]->pdn != NULL ) { context->eps_bearers[ebi_index]->pdn->timer_entry = timer_entry; } else { return; } }else { bearer->pdn->timer_entry = timer_entry; } } else { ret = get_ue_context(teid, &context); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get Ue context for teid: %d\n", LOG_VALUE, teid); return; } if(context != NULL && context->eps_bearers[ebi_index] != NULL && context->eps_bearers[ebi_index]->pdn != NULL ) { context->eps_bearers[ebi_index]->pdn->timer_entry = timer_entry; } else { return; } } if (starttimer(&timer_entry->pt) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Periodic Timer failed to start...\n", LOG_VALUE); } } sess_info * insert_into_sess_info_list(sess_info *head, sess_info *new_node) { sess_info *traverse = NULL; if(new_node == NULL) return head; if(head == NULL){ head = new_node; } else{ for(traverse = head; traverse->next != NULL; traverse = traverse->next); traverse->next = new_node; } return head; } void delete_from_sess_info_list(sess_info *head) { sess_info *traverse = NULL; if(head == NULL) return; for(traverse = head; traverse != NULL;){ head = head->next; rte_free(traverse); traverse = NULL; traverse = head; } } sess_info * search_into_sess_info_list(sess_info * head, uint64_t sess_id) { sess_info *traverse = NULL; if(head == NULL) return NULL; for(traverse = head; traverse != NULL; traverse = traverse->next){ if(traverse->sess_id == sess_id){ return traverse; } } return NULL; }
nikhilc149/e-utran-features-bug-fixes
cp/gx_app/src/gx_pack.c
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdint.h> #include <stdlib.h> #include "gx.h" #define MIN(a,b) (((a) < (b)) ? (a) : (b)) /*******************************************************************************/ #define CALCLEN_PRESENCE(__length__,__data__,__member__) { \ __length__ += sizeof(__data__->__member__); \ } #define CALCLEN_BASIC(__length__,__data__,__member__) { \ if (__data__->presence.__member__) \ __length__ += sizeof(__data__->__member__); \ } #define CALCLEN_OCTETSTRING(__length__,__data__,__member__) { \ if (__data__->presence.__member__) \ __length__ += sizeof(uint32_t) + __data__->__member__.len; \ } #define CALCLEN_STRUCT(__length__,__data__,__member__,__calcfunc__) { \ if (__data__->presence.__member__) \ __length__ += __calcfunc__( &__data__->__member__ ); \ } #define CALCLEN_LIST_BASIC(__length__,__data__,__member__) { \ if (__data__->presence.__member__) { \ __length__ += sizeof(int32_t) + sizeof(*__data__->__member__.list) * __data__->__member__.count; \ } \ } #define CALCLEN_LIST_OCTETSTRING(__length__,__data__,__member__) { \ if (__data__->presence.__member__) { \ __length__ += sizeof(int32_t); \ for (int32_t idx=0; idx<__data__->__member__.count; idx++) { \ __length__ += sizeof(uint32_t) + __data__->__member__.list[idx].len; \ } \ } \ } #define CALCLEN_LIST_STRUCT(__length__,__data__,__member__,__calcfunc__) { \ if (__data__->presence.__member__) { \ __length__ += sizeof(int32_t); \ for (int32_t idx=0; idx<__data__->__member__.count; idx++) \ __length__ += __calcfunc__( &__data__->__member__.list[idx] ); \ } \ } /*******************************************************************************/ #define PACK_PRESENCE(__data__,__member__,__buffer__,__buflen__,__offset__) { \ if (*__offset__ + sizeof(__data__->__member__) > __buflen__) \ return 0; \ memcpy( &__buffer__[*__offset__], (unsigned char *)&(__data__->__member__), sizeof(__data__->__member__)); \ *__offset__ += sizeof(__data__->__member__); \ } #define PACK_BASIC(__data__,__member__,__buffer__,__buflen__,__offset__) { \ if (__data__->presence.__member__) { \ if (*__offset__ + sizeof(__data__->__member__) > __buflen__) \ return 0; \ memcpy( &__buffer__[*__offset__], (unsigned char *)&(__data__->__member__), sizeof(__data__->__member__)); \ *__offset__ += sizeof(__data__->__member__); \ } \ } #define PACK_OCTETSTRING(__data__,__member__,__buffer__,__buflen__,__offset__) { \ if (__data__->presence.__member__) { \ if (*__offset__ + sizeof(uint32_t) + __data__->__member__.len > __buflen__) \ return 0; \ *((uint32_t*)&__buffer__[*__offset__]) = __data__->__member__.len; \ *__offset__ += sizeof(uint32_t); \ memcpy( &__buffer__[*__offset__], (unsigned char *)__data__->__member__.val, __data__->__member__.len ); \ *__offset__ += __data__->__member__.len; \ } \ } #define PACK_STRUCT(__data__,__member__,__buffer__,__buflen__,__offset__,__packfunc__) { \ if (__data__->presence.__member__) { \ if (!__packfunc__(&__data__->__member__,__buffer__,__buflen__,__offset__)) \ return 0; \ } \ } #define PACK_LIST_BASIC(__data__,__member__,__buffer__,__buflen__,__offset__) { \ if (__data__->presence.__member__) { \ if (*__offset__ + sizeof(int32_t) > __buflen__) \ return 0; \ *(int32_t*)&__buffer__[*__offset__] = __data__->__member__.count; \ *__offset__ += sizeof(int32_t); \ for (int32_t idx=0; idx<__data__->__member__.count; idx++) { \ if ((*__offset__ + sizeof(*__data__->__member__.list)) > __buflen__) \ return 0; \ memcpy( &__buffer__[*__offset__], (unsigned char *)&__data__->__member__.list[idx], sizeof(*__data__->__member__.list) ); \ *__offset__ += sizeof(*__data__->__member__.list); \ } \ } \ } #define PACK_LIST_OCTETSTRING(__data__,__member__,__buffer__,__buflen__,__offset__) { \ if (__data__->presence.__member__) { \ if ((*__offset__ + sizeof(int32_t)) > __buflen__) \ return 0; \ *(int32_t*)(&__buffer__[*__offset__]) = __data__->__member__.count; \ *__offset__ += sizeof(int32_t); \ for (int32_t idx=0; idx<__data__->__member__.count; idx++) { \ if ((*__offset__ + sizeof(uint32_t) + __data__->__member__.list[idx].len) > __buflen__) \ return 0; \ *(uint32_t*)&__buffer__[*__offset__] += __data__->__member__.list[idx].len; \ *__offset__ += sizeof(uint32_t); \ memcpy( &__buffer__[*__offset__], (unsigned char *)&__data__->__member__.list[idx].val, __data__->__member__.list[idx].len); \ *__offset__ += __data__->__member__.list[idx].len; \ } \ } \ } #define PACK_LIST_STRUCT(__data__,__member__,__buffer__,__buflen__,__offset__,__packfunc__) { \ if (__data__->presence.__member__) { \ if ((*__offset__ + sizeof(int32_t)) > __buflen__) \ return 0; \ *(int32_t*)(&__buffer__[*__offset__]) = __data__->__member__.count; \ *__offset__ += sizeof(int32_t); \ for (int32_t idx=0; idx<__data__->__member__.count; idx++) { \ if (!__packfunc__(&__data__->__member__.list[idx],__buffer__,__buflen__,__offset__)) \ return 0; \ } \ } \ } /*******************************************************************************/ #define UNPACK_PRESENCE(__data__,__member__,__buffer__,__buflen__,__offset__) { \ if (*__offset__ + sizeof(__data__->__member__) > __buflen__) \ return 0; \ memcpy((unsigned char *)&__data__->__member__, &__buffer__[*__offset__], sizeof(__data__->__member__)); \ *__offset__ += sizeof(__data__->__member__); \ } #define UNPACK_BASIC(__data__,__member__,__buffer__,__buflen__,__offset__) { \ if (__data__->presence.__member__) { \ if (*__offset__ + sizeof(__data__->__member__) > __buflen__) \ return 0; \ memcpy((unsigned char *)&__data__->__member__, &__buffer__[*__offset__], sizeof(__data__->__member__)); \ *__offset__ += sizeof(__data__->__member__); \ } \ } #define UNPACK_OCTETSTRING(__data__,__member__,__buffer__,__buflen__,__offset__) { \ if (__data__->presence.__member__) { \ if (*__offset__ + sizeof(uint32_t) > __buflen__) \ return 0; \ uint32_t __len__ = *((uint32_t*)&__buffer__[*__offset__]); \ __data__->__member__.len = MIN(__len__, sizeof(__data__->__member__.val) - 1); \ *__offset__ += sizeof(uint32_t); \ if (*__offset__ + __len__ > __buflen__) \ return 0; \ memcpy(__data__->__member__.val, &__buffer__[*__offset__], __data__->__member__.len); \ __data__->__member__.val[__data__->__member__.len] = '\0'; \ *__offset__ += __len__; \ } \ } #define UNPACK_STRUCT(__data__,__member__,__buffer__,__buflen__,__offset__,__unpackfunc__) { \ if (__data__->presence.__member__) { \ if (!__unpackfunc__(__buffer__,__buflen__,&__data__->__member__,__offset__)) \ return 0; \ } \ } #define UNPACK_LIST_BASIC(__data__,__member__,__listtype__,__buffer__,__buflen__,__offset__) { \ if (__data__->presence.__member__) { \ if (*__offset__ + sizeof(int32_t) > __buflen__) \ return 0; \ __data__->__member__.count = *(int32_t*)&__buffer__[*__offset__]; \ *__offset__ += sizeof(int32_t); \ __data__->__member__.list = (__listtype__*)malloc(sizeof(__listtype__) * __data__->__member__.count); \ if (!__data__->__member__.list) \ return 0; \ for (int32_t idx=0; idx<__data__->__member__.count; idx++) { \ if (*__offset__ + sizeof(__data__->__member__.list[idx]) > __buflen__) \ return 0; \ memcpy((unsigned char *)&__data__->__member__.list[idx], &__buffer__[*__offset__], sizeof(__data__->__member__.list[idx])); \ *__offset__ += sizeof(__data__->__member__.list[idx]); \ } \ } \ } #define UNPACK_LIST_OCTETSTRING(__data__,__member__,__listtype__,__buffer__,__buflen__,__offset__) { \ if (__data__->presence.__member__) { \ if ((*__offset__ + sizeof(int32_t)) >=__buflen__) \ return 0; \ __data__->__member__.count = *(int32_t*)&__buffer__[*__offset__]; \ *__offset__ += sizeof(int32_t); \ __data__->__member__.list = (__listtype__*)malloc(sizeof(__listtype__) * __data__->__member__.count); \ if (!__data__->__member__.list) \ return 0; \ memset(__data__->__member__.list, 0, sizeof(__listtype__)* __data__->__member__.count); \ for (int32_t idx=0; idx <__data__->__member__.count; idx++) { \ if (*__offset__ + sizeof(uint32_t) > __buflen__) \ return 0; \ uint32_t __len__ = *(uint32_t*)&__buffer__[*__offset__]; \ *__offset__ += sizeof(uint32_t); \ __data__->__member__.list[idx].len = MIN(__len__, sizeof(__data__->__member__.list[idx].val) - 1); \ memcpy(__data__->__member__.list[idx].val, &__buffer__[*__offset__], __data__->__member__.list[idx].len); \ *__offset__ += __len__; \ } \ } \ } #define UNPACK_LIST_STRUCT(__data__,__member__,__listtype__,__buffer__,__buflen__,__offset__,__unpackfunc__) { \ if (__data__->presence.__member__) { \ if (*__offset__ + sizeof(int32_t) > __buflen__) \ return 0; \ __data__->__member__.count = *(int32_t*)&__buffer__[*__offset__]; \ *__offset__ += sizeof(int32_t); \ __data__->__member__.list = (__listtype__*)malloc(sizeof(__listtype__) * __data__->__member__.count); \ if (!__data__->__member__.list) \ return 0; \ for (int32_t idx=0; idx<__data__->__member__.count; idx++) { \ if (!__unpackfunc__(__buffer__,__buflen__,&__data__->__member__.list[idx],__offset__)) \ return 0; \ } \ } \ } /*******************************************************************************/ /* private structure calc_length, pack and unpack function declarations */ /*******************************************************************************/ static uint32_t calcLengthGxExperimentalResult(GxExperimentalResult *data); static uint32_t calcLengthGxPraRemove(GxPraRemove *data); static uint32_t calcLengthGxQosInformation(GxQosInformation *data); static uint32_t calcLengthGxConditionalPolicyInformation(GxConditionalPolicyInformation *data); static uint32_t calcLengthGxPraInstall(GxPraInstall *data); static uint32_t calcLengthGxAreaScope(GxAreaScope *data); static uint32_t calcLengthGxFlowInformation(GxFlowInformation *data); static uint32_t calcLengthGxTunnelInformation(GxTunnelInformation *data); static uint32_t calcLengthGxTftPacketFilterInformation(GxTftPacketFilterInformation *data); static uint32_t calcLengthGxMbsfnArea(GxMbsfnArea *data); static uint32_t calcLengthGxEventReportIndication(GxEventReportIndication *data); static uint32_t calcLengthGxTdfInformation(GxTdfInformation *data); static uint32_t calcLengthGxProxyInfo(GxProxyInfo *data); static uint32_t calcLengthGxUsedServiceUnit(GxUsedServiceUnit *data); static uint32_t calcLengthGxChargingRuleInstall(GxChargingRuleInstall *data); static uint32_t calcLengthGxChargingRuleDefinition(GxChargingRuleDefinition *data); static uint32_t calcLengthGxFinalUnitIndication(GxFinalUnitIndication *data); static uint32_t calcLengthGxUnitValue(GxUnitValue *data); static uint32_t calcLengthGxPresenceReportingAreaInformation(GxPresenceReportingAreaInformation *data); static uint32_t calcLengthGxConditionalApnAggregateMaxBitrate(GxConditionalApnAggregateMaxBitrate *data); static uint32_t calcLengthGxAccessNetworkChargingIdentifierGx(GxAccessNetworkChargingIdentifierGx *data); static uint32_t calcLengthGxOcOlr(GxOcOlr *data); static uint32_t calcLengthGxRoutingRuleInstall(GxRoutingRuleInstall *data); static uint32_t calcLengthGxTraceData(GxTraceData *data); static uint32_t calcLengthGxRoutingRuleDefinition(GxRoutingRuleDefinition *data); static uint32_t calcLengthGxMdtConfiguration(GxMdtConfiguration *data); static uint32_t calcLengthGxChargingRuleRemove(GxChargingRuleRemove *data); static uint32_t calcLengthGxAllocationRetentionPriority(GxAllocationRetentionPriority *data); static uint32_t calcLengthGxDefaultEpsBearerQos(GxDefaultEpsBearerQos *data); static uint32_t calcLengthGxRoutingRuleReport(GxRoutingRuleReport *data); static uint32_t calcLengthGxUserEquipmentInfo(GxUserEquipmentInfo *data); static uint32_t calcLengthGxSupportedFeatures(GxSupportedFeatures *data); static uint32_t calcLengthGxFixedUserLocationInfo(GxFixedUserLocationInfo *data); static uint32_t calcLengthGxDefaultQosInformation(GxDefaultQosInformation *data); static uint32_t calcLengthGxLoad(GxLoad *data); static uint32_t calcLengthGxRedirectServer(GxRedirectServer *data); static uint32_t calcLengthGxOcSupportedFeatures(GxOcSupportedFeatures *data); static uint32_t calcLengthGxPacketFilterInformation(GxPacketFilterInformation *data); static uint32_t calcLengthGxSubscriptionId(GxSubscriptionId *data); static uint32_t calcLengthGxChargingInformation(GxChargingInformation *data); static uint32_t calcLengthGxUsageMonitoringInformation(GxUsageMonitoringInformation *data); static uint32_t calcLengthGxChargingRuleReport(GxChargingRuleReport *data); static uint32_t calcLengthGxRedirectInformation(GxRedirectInformation *data); static uint32_t calcLengthGxFailedAvp(GxFailedAvp *data); static uint32_t calcLengthGxRoutingRuleRemove(GxRoutingRuleRemove *data); static uint32_t calcLengthGxRoutingFilter(GxRoutingFilter *data); static uint32_t calcLengthGxCoaInformation(GxCoaInformation *data); static uint32_t calcLengthGxGrantedServiceUnit(GxGrantedServiceUnit *data); static uint32_t calcLengthGxCcMoney(GxCcMoney *data); static uint32_t calcLengthGxApplicationDetectionInformation(GxApplicationDetectionInformation *data); static uint32_t calcLengthGxFlows(GxFlows *data); static uint32_t calcLengthGxUserCsgInformation(GxUserCsgInformation *data); static int packGxExperimentalResult(GxExperimentalResult *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxPraRemove(GxPraRemove *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxQosInformation(GxQosInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxConditionalPolicyInformation(GxConditionalPolicyInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxPraInstall(GxPraInstall *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxAreaScope(GxAreaScope *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxFlowInformation(GxFlowInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxTunnelInformation(GxTunnelInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxTftPacketFilterInformation(GxTftPacketFilterInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxMbsfnArea(GxMbsfnArea *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxEventReportIndication(GxEventReportIndication *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxTdfInformation(GxTdfInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxProxyInfo(GxProxyInfo *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxUsedServiceUnit(GxUsedServiceUnit *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxChargingRuleInstall(GxChargingRuleInstall *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxChargingRuleDefinition(GxChargingRuleDefinition *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxFinalUnitIndication(GxFinalUnitIndication *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxUnitValue(GxUnitValue *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxPresenceReportingAreaInformation(GxPresenceReportingAreaInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxConditionalApnAggregateMaxBitrate(GxConditionalApnAggregateMaxBitrate *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxAccessNetworkChargingIdentifierGx(GxAccessNetworkChargingIdentifierGx *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxOcOlr(GxOcOlr *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxRoutingRuleInstall(GxRoutingRuleInstall *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxTraceData(GxTraceData *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxRoutingRuleDefinition(GxRoutingRuleDefinition *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxMdtConfiguration(GxMdtConfiguration *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxChargingRuleRemove(GxChargingRuleRemove *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxAllocationRetentionPriority(GxAllocationRetentionPriority *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxDefaultEpsBearerQos(GxDefaultEpsBearerQos *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxRoutingRuleReport(GxRoutingRuleReport *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxUserEquipmentInfo(GxUserEquipmentInfo *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxSupportedFeatures(GxSupportedFeatures *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxFixedUserLocationInfo(GxFixedUserLocationInfo *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxDefaultQosInformation(GxDefaultQosInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxLoad(GxLoad *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxRedirectServer(GxRedirectServer *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxOcSupportedFeatures(GxOcSupportedFeatures *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxPacketFilterInformation(GxPacketFilterInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxSubscriptionId(GxSubscriptionId *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxChargingInformation(GxChargingInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxUsageMonitoringInformation(GxUsageMonitoringInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxChargingRuleReport(GxChargingRuleReport *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxRedirectInformation(GxRedirectInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxFailedAvp(GxFailedAvp *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxRoutingRuleRemove(GxRoutingRuleRemove *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxRoutingFilter(GxRoutingFilter *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxCoaInformation(GxCoaInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxGrantedServiceUnit(GxGrantedServiceUnit *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxCcMoney(GxCcMoney *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxApplicationDetectionInformation(GxApplicationDetectionInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxFlows(GxFlows *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int packGxUserCsgInformation(GxUserCsgInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset); static int unpackGxExperimentalResult(unsigned char *buf, uint32_t buflen, GxExperimentalResult *data, uint32_t *offset); static int unpackGxPraRemove(unsigned char *buf, uint32_t buflen, GxPraRemove *data, uint32_t *offset); static int unpackGxQosInformation(unsigned char *buf, uint32_t buflen, GxQosInformation *data, uint32_t *offset); static int unpackGxConditionalPolicyInformation(unsigned char *buf, uint32_t buflen, GxConditionalPolicyInformation *data, uint32_t *offset); static int unpackGxPraInstall(unsigned char *buf, uint32_t buflen, GxPraInstall *data, uint32_t *offset); static int unpackGxAreaScope(unsigned char *buf, uint32_t buflen, GxAreaScope *data, uint32_t *offset); static int unpackGxFlowInformation(unsigned char *buf, uint32_t buflen, GxFlowInformation *data, uint32_t *offset); static int unpackGxTunnelInformation(unsigned char *buf, uint32_t buflen, GxTunnelInformation *data, uint32_t *offset); static int unpackGxTftPacketFilterInformation(unsigned char *buf, uint32_t buflen, GxTftPacketFilterInformation *data, uint32_t *offset); static int unpackGxMbsfnArea(unsigned char *buf, uint32_t buflen, GxMbsfnArea *data, uint32_t *offset); static int unpackGxEventReportIndication(unsigned char *buf, uint32_t buflen, GxEventReportIndication *data, uint32_t *offset); static int unpackGxTdfInformation(unsigned char *buf, uint32_t buflen, GxTdfInformation *data, uint32_t *offset); static int unpackGxProxyInfo(unsigned char *buf, uint32_t buflen, GxProxyInfo *data, uint32_t *offset); static int unpackGxUsedServiceUnit(unsigned char *buf, uint32_t buflen, GxUsedServiceUnit *data, uint32_t *offset); static int unpackGxChargingRuleInstall(unsigned char *buf, uint32_t buflen, GxChargingRuleInstall *data, uint32_t *offset); static int unpackGxChargingRuleDefinition(unsigned char *buf, uint32_t buflen, GxChargingRuleDefinition *data, uint32_t *offset); static int unpackGxFinalUnitIndication(unsigned char *buf, uint32_t buflen, GxFinalUnitIndication *data, uint32_t *offset); static int unpackGxUnitValue(unsigned char *buf, uint32_t buflen, GxUnitValue *data, uint32_t *offset); static int unpackGxPresenceReportingAreaInformation(unsigned char *buf, uint32_t buflen, GxPresenceReportingAreaInformation *data, uint32_t *offset); static int unpackGxConditionalApnAggregateMaxBitrate(unsigned char *buf, uint32_t buflen, GxConditionalApnAggregateMaxBitrate *data, uint32_t *offset); static int unpackGxAccessNetworkChargingIdentifierGx(unsigned char *buf, uint32_t buflen, GxAccessNetworkChargingIdentifierGx *data, uint32_t *offset); static int unpackGxOcOlr(unsigned char *buf, uint32_t buflen, GxOcOlr *data, uint32_t *offset); static int unpackGxRoutingRuleInstall(unsigned char *buf, uint32_t buflen, GxRoutingRuleInstall *data, uint32_t *offset); static int unpackGxTraceData(unsigned char *buf, uint32_t buflen, GxTraceData *data, uint32_t *offset); static int unpackGxRoutingRuleDefinition(unsigned char *buf, uint32_t buflen, GxRoutingRuleDefinition *data, uint32_t *offset); static int unpackGxMdtConfiguration(unsigned char *buf, uint32_t buflen, GxMdtConfiguration *data, uint32_t *offset); static int unpackGxChargingRuleRemove(unsigned char *buf, uint32_t buflen, GxChargingRuleRemove *data, uint32_t *offset); static int unpackGxAllocationRetentionPriority(unsigned char *buf, uint32_t buflen, GxAllocationRetentionPriority *data, uint32_t *offset); static int unpackGxDefaultEpsBearerQos(unsigned char *buf, uint32_t buflen, GxDefaultEpsBearerQos *data, uint32_t *offset); static int unpackGxRoutingRuleReport(unsigned char *buf, uint32_t buflen, GxRoutingRuleReport *data, uint32_t *offset); static int unpackGxUserEquipmentInfo(unsigned char *buf, uint32_t buflen, GxUserEquipmentInfo *data, uint32_t *offset); static int unpackGxSupportedFeatures(unsigned char *buf, uint32_t buflen, GxSupportedFeatures *data, uint32_t *offset); static int unpackGxFixedUserLocationInfo(unsigned char *buf, uint32_t buflen, GxFixedUserLocationInfo *data, uint32_t *offset); static int unpackGxDefaultQosInformation(unsigned char *buf, uint32_t buflen, GxDefaultQosInformation *data, uint32_t *offset); static int unpackGxLoad(unsigned char *buf, uint32_t buflen, GxLoad *data, uint32_t *offset); static int unpackGxRedirectServer(unsigned char *buf, uint32_t buflen, GxRedirectServer *data, uint32_t *offset); static int unpackGxOcSupportedFeatures(unsigned char *buf, uint32_t buflen, GxOcSupportedFeatures *data, uint32_t *offset); static int unpackGxPacketFilterInformation(unsigned char *buf, uint32_t buflen, GxPacketFilterInformation *data, uint32_t *offset); static int unpackGxSubscriptionId(unsigned char *buf, uint32_t buflen, GxSubscriptionId *data, uint32_t *offset); static int unpackGxChargingInformation(unsigned char *buf, uint32_t buflen, GxChargingInformation *data, uint32_t *offset); static int unpackGxUsageMonitoringInformation(unsigned char *buf, uint32_t buflen, GxUsageMonitoringInformation *data, uint32_t *offset); static int unpackGxChargingRuleReport(unsigned char *buf, uint32_t buflen, GxChargingRuleReport *data, uint32_t *offset); static int unpackGxRedirectInformation(unsigned char *buf, uint32_t buflen, GxRedirectInformation *data, uint32_t *offset); static int unpackGxFailedAvp(unsigned char *buf, uint32_t buflen, GxFailedAvp *data, uint32_t *offset); static int unpackGxRoutingRuleRemove(unsigned char *buf, uint32_t buflen, GxRoutingRuleRemove *data, uint32_t *offset); static int unpackGxRoutingFilter(unsigned char *buf, uint32_t buflen, GxRoutingFilter *data, uint32_t *offset); static int unpackGxCoaInformation(unsigned char *buf, uint32_t buflen, GxCoaInformation *data, uint32_t *offset); static int unpackGxGrantedServiceUnit(unsigned char *buf, uint32_t buflen, GxGrantedServiceUnit *data, uint32_t *offset); static int unpackGxCcMoney(unsigned char *buf, uint32_t buflen, GxCcMoney *data, uint32_t *offset); static int unpackGxApplicationDetectionInformation(unsigned char *buf, uint32_t buflen, GxApplicationDetectionInformation *data, uint32_t *offset); static int unpackGxFlows(unsigned char *buf, uint32_t buflen, GxFlows *data, uint32_t *offset); static int unpackGxUserCsgInformation(unsigned char *buf, uint32_t buflen, GxUserCsgInformation *data, uint32_t *offset); /*******************************************************************************/ /* message length calculation functions */ /*******************************************************************************/ /* * * Fun: gx_rar_calc_length * * Desc: Calculate the length for the Re-Auth-Request Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Re-Auth-Request ::= <Diameter Header: 258, REQ, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * { Destination-Realm } * { Destination-Host } * { Re-Auth-Request-Type } * [ Session-Release-Cause ] * [ Origin-State-Id ] * [ OC-Supported-Features ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * * [ Charging-Rule-Remove ] * * [ Charging-Rule-Install ] * [ Default-EPS-Bearer-QoS ] * * [ QoS-Information ] * [ Default-QoS-Information ] * [ Revalidation-Time ] * * [ Usage-Monitoring-Information ] * [ PCSCF-Restoration-Indication ] * * 4 [ Conditional-Policy-Information ] * [ Removal-Of-Access ] * [ IP-CAN-Type ] * [ PRA-Install ] * [ PRA-Remove ] * * [ CSG-Information-Reporting ] * * [ Proxy-Info ] * * [ Route-Record ] * * [ AVP ] */ uint32_t gx_rar_calc_length ( GxRAR *data ) { uint32_t length = sizeof(uint32_t); CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, session_id ); CALCLEN_BASIC( length, data, drmp ); CALCLEN_BASIC( length, data, auth_application_id ); CALCLEN_OCTETSTRING( length, data, origin_host ); CALCLEN_OCTETSTRING( length, data, origin_realm ); CALCLEN_OCTETSTRING( length, data, destination_realm ); CALCLEN_OCTETSTRING( length, data, destination_host ); CALCLEN_BASIC( length, data, re_auth_request_type ); CALCLEN_BASIC( length, data, session_release_cause ); CALCLEN_BASIC( length, data, origin_state_id ); CALCLEN_STRUCT( length, data, oc_supported_features, calcLengthGxOcSupportedFeatures ); CALCLEN_LIST_BASIC( length, data, event_trigger ); CALCLEN_STRUCT( length, data, event_report_indication, calcLengthGxEventReportIndication ); CALCLEN_LIST_STRUCT( length, data, charging_rule_remove, calcLengthGxChargingRuleRemove ); CALCLEN_LIST_STRUCT( length, data, charging_rule_install, calcLengthGxChargingRuleInstall ); CALCLEN_STRUCT( length, data, default_eps_bearer_qos, calcLengthGxDefaultEpsBearerQos ); CALCLEN_LIST_STRUCT( length, data, qos_information, calcLengthGxQosInformation ); CALCLEN_STRUCT( length, data, default_qos_information, calcLengthGxDefaultQosInformation ); CALCLEN_BASIC( length, data, revalidation_time ); CALCLEN_LIST_STRUCT( length, data, usage_monitoring_information, calcLengthGxUsageMonitoringInformation ); CALCLEN_BASIC( length, data, pcscf_restoration_indication ); CALCLEN_LIST_STRUCT( length, data, conditional_policy_information, calcLengthGxConditionalPolicyInformation ); CALCLEN_BASIC( length, data, removal_of_access ); CALCLEN_BASIC( length, data, ip_can_type ); CALCLEN_STRUCT( length, data, pra_install, calcLengthGxPraInstall ); CALCLEN_STRUCT( length, data, pra_remove, calcLengthGxPraRemove ); CALCLEN_LIST_BASIC( length, data, csg_information_reporting ); CALCLEN_LIST_STRUCT( length, data, proxy_info, calcLengthGxProxyInfo ); CALCLEN_LIST_OCTETSTRING( length, data, route_record ); return length; } /* * * Fun: gx_raa_calc_length * * Desc: Calculate the length for the Re-Auth-Answer Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Re-Auth-Answer ::= <Diameter Header: 258, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Origin-Host } * { Origin-Realm } * [ Result-Code ] * [ Experimental-Result ] * [ Origin-State-Id ] * [ OC-Supported-Features ] * [ OC-OLR ] * [ IP-CAN-Type ] * [ RAT-Type ] * [ AN-Trusted ] * * 2 [ AN-GW-Address ] * [ 3GPP-SGSN-MCC-MNC ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ User-Location-Info-Time ] * [ NetLoc-Access-Support ] * [ User-CSG-Information ] * [ 3GPP-MS-TimeZone ] * [ Default-QoS-Information ] * * [ Charging-Rule-Report ] * [ Error-Message ] * [ Error-Reporting-Host ] * [ Failed-AVP ] * * [ Proxy-Info ] * * [ AVP ] */ uint32_t gx_raa_calc_length ( GxRAA *data ) { uint32_t length = sizeof(uint32_t); CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, session_id ); CALCLEN_BASIC( length, data, drmp ); CALCLEN_OCTETSTRING( length, data, origin_host ); CALCLEN_OCTETSTRING( length, data, origin_realm ); CALCLEN_BASIC( length, data, result_code ); CALCLEN_STRUCT( length, data, experimental_result, calcLengthGxExperimentalResult ); CALCLEN_BASIC( length, data, origin_state_id ); CALCLEN_STRUCT( length, data, oc_supported_features, calcLengthGxOcSupportedFeatures ); CALCLEN_STRUCT( length, data, oc_olr, calcLengthGxOcOlr ); CALCLEN_BASIC( length, data, ip_can_type ); CALCLEN_BASIC( length, data, rat_type ); CALCLEN_BASIC( length, data, an_trusted ); CALCLEN_LIST_BASIC( length, data, an_gw_address ); CALCLEN_OCTETSTRING( length, data, tgpp_sgsn_mcc_mnc ); CALCLEN_OCTETSTRING( length, data, tgpp_sgsn_address ); CALCLEN_OCTETSTRING( length, data, tgpp_sgsn_ipv6_address ); CALCLEN_OCTETSTRING( length, data, rai ); CALCLEN_OCTETSTRING( length, data, tgpp_user_location_info ); CALCLEN_BASIC( length, data, user_location_info_time ); CALCLEN_BASIC( length, data, netloc_access_support ); CALCLEN_STRUCT( length, data, user_csg_information, calcLengthGxUserCsgInformation ); CALCLEN_OCTETSTRING( length, data, tgpp_ms_timezone ); CALCLEN_STRUCT( length, data, default_qos_information, calcLengthGxDefaultQosInformation ); CALCLEN_LIST_STRUCT( length, data, charging_rule_report, calcLengthGxChargingRuleReport ); CALCLEN_OCTETSTRING( length, data, error_message ); CALCLEN_OCTETSTRING( length, data, error_reporting_host ); CALCLEN_STRUCT( length, data, failed_avp, calcLengthGxFailedAvp ); CALCLEN_LIST_STRUCT( length, data, proxy_info, calcLengthGxProxyInfo ); return length; } /* * * Fun: gx_cca_calc_length * * Desc: Calculate the length for the Credit-Control-Answer Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Credit-Control-Answer ::= <Diameter Header: 272, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * [ Result-Code ] * [ Experimental-Result ] * { CC-Request-Type } * { CC-Request-Number } * [ OC-Supported-Features ] * [ OC-OLR ] * * [ Supported-Features ] * [ Bearer-Control-Mode ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * [ Origin-State-Id ] * * [ Redirect-Host ] * [ Redirect-Host-Usage ] * [ Redirect-Max-Cache-Time ] * * [ Charging-Rule-Remove ] * * [ Charging-Rule-Install ] * [ Charging-Information ] * [ Online ] * [ Offline ] * * [ QoS-Information ] * [ Revalidation-Time ] * [ Default-EPS-Bearer-QoS ] * [ Default-QoS-Information ] * [ Bearer-Usage ] * * [ Usage-Monitoring-Information ] * * [ CSG-Information-Reporting ] * [ User-CSG-Information ] * [ PRA-Install ] * [ PRA-Remove ] * [ Presence-Reporting-Area-Information ] * [ Session-Release-Cause ] * [ NBIFOM-Support ] * [ NBIFOM-Mode ] * [ Default-Access ] * [ RAN-Rule-Support ] * * [ Routing-Rule-Report ] * * 4 [ Conditional-Policy-Information ] * [ Removal-Of-Access ] * [ IP-CAN-Type ] * [ Error-Message ] * [ Error-Reporting-Host ] * [ Failed-AVP ] * * [ Proxy-Info ] * * [ Route-Record ] * * [ Load ] * * [ AVP ] */ uint32_t gx_cca_calc_length ( GxCCA *data ) { uint32_t length = sizeof(uint32_t); CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, session_id ); CALCLEN_BASIC( length, data, drmp ); CALCLEN_BASIC( length, data, auth_application_id ); CALCLEN_OCTETSTRING( length, data, origin_host ); CALCLEN_OCTETSTRING( length, data, origin_realm ); CALCLEN_BASIC( length, data, result_code ); CALCLEN_STRUCT( length, data, experimental_result, calcLengthGxExperimentalResult ); CALCLEN_BASIC( length, data, cc_request_type ); CALCLEN_BASIC( length, data, cc_request_number ); CALCLEN_STRUCT( length, data, oc_supported_features, calcLengthGxOcSupportedFeatures ); CALCLEN_STRUCT( length, data, oc_olr, calcLengthGxOcOlr ); CALCLEN_LIST_STRUCT( length, data, supported_features, calcLengthGxSupportedFeatures ); CALCLEN_BASIC( length, data, bearer_control_mode ); CALCLEN_LIST_BASIC( length, data, event_trigger ); CALCLEN_STRUCT( length, data, event_report_indication, calcLengthGxEventReportIndication ); CALCLEN_BASIC( length, data, origin_state_id ); CALCLEN_LIST_OCTETSTRING( length, data, redirect_host ); CALCLEN_BASIC( length, data, redirect_host_usage ); CALCLEN_BASIC( length, data, redirect_max_cache_time ); CALCLEN_LIST_STRUCT( length, data, charging_rule_remove, calcLengthGxChargingRuleRemove ); CALCLEN_LIST_STRUCT( length, data, charging_rule_install, calcLengthGxChargingRuleInstall ); CALCLEN_STRUCT( length, data, charging_information, calcLengthGxChargingInformation ); CALCLEN_BASIC( length, data, online ); CALCLEN_BASIC( length, data, offline ); CALCLEN_LIST_STRUCT( length, data, qos_information, calcLengthGxQosInformation ); CALCLEN_BASIC( length, data, revalidation_time ); CALCLEN_STRUCT( length, data, default_eps_bearer_qos, calcLengthGxDefaultEpsBearerQos ); CALCLEN_STRUCT( length, data, default_qos_information, calcLengthGxDefaultQosInformation ); CALCLEN_BASIC( length, data, bearer_usage ); CALCLEN_LIST_STRUCT( length, data, usage_monitoring_information, calcLengthGxUsageMonitoringInformation ); CALCLEN_LIST_BASIC( length, data, csg_information_reporting ); CALCLEN_STRUCT( length, data, user_csg_information, calcLengthGxUserCsgInformation ); CALCLEN_STRUCT( length, data, pra_install, calcLengthGxPraInstall ); CALCLEN_STRUCT( length, data, pra_remove, calcLengthGxPraRemove ); CALCLEN_STRUCT( length, data, presence_reporting_area_information, calcLengthGxPresenceReportingAreaInformation ); CALCLEN_BASIC( length, data, session_release_cause ); CALCLEN_BASIC( length, data, nbifom_support ); CALCLEN_BASIC( length, data, nbifom_mode ); CALCLEN_BASIC( length, data, default_access ); CALCLEN_BASIC( length, data, ran_rule_support ); CALCLEN_LIST_STRUCT( length, data, routing_rule_report, calcLengthGxRoutingRuleReport ); CALCLEN_LIST_STRUCT( length, data, conditional_policy_information, calcLengthGxConditionalPolicyInformation ); CALCLEN_BASIC( length, data, removal_of_access ); CALCLEN_BASIC( length, data, ip_can_type ); CALCLEN_OCTETSTRING( length, data, error_message ); CALCLEN_OCTETSTRING( length, data, error_reporting_host ); CALCLEN_STRUCT( length, data, failed_avp, calcLengthGxFailedAvp ); CALCLEN_LIST_STRUCT( length, data, proxy_info, calcLengthGxProxyInfo ); CALCLEN_LIST_OCTETSTRING( length, data, route_record ); CALCLEN_LIST_STRUCT( length, data, load, calcLengthGxLoad ); return length; } /* * * Fun: gx_ccr_calc_length * * Desc: Calculate the length for the Credit-Control-Request Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Credit-Control-Request ::= <Diameter Header: 272, REQ, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * { Destination-Realm } * { CC-Request-Type } * { CC-Request-Number } * [ Credit-Management-Status ] * [ Destination-Host ] * [ Origin-State-Id ] * * [ Subscription-Id ] * [ OC-Supported-Features ] * * [ Supported-Features ] * [ TDF-Information ] * [ Network-Request-Support ] * * [ Packet-Filter-Information ] * [ Packet-Filter-Operation ] * [ Bearer-Identifier ] * [ Bearer-Operation ] * [ Dynamic-Address-Flag ] * [ Dynamic-Address-Flag-Extension ] * [ PDN-Connection-Charging-ID ] * [ Framed-IP-Address ] * [ Framed-IPv6-Prefix ] * [ IP-CAN-Type ] * [ 3GPP-RAT-Type ] * [ AN-Trusted ] * [ RAT-Type ] * [ Termination-Cause ] * [ User-Equipment-Info ] * [ QoS-Information ] * [ QoS-Negotiation ] * [ QoS-Upgrade ] * [ Default-EPS-Bearer-QoS ] * [ Default-QoS-Information ] * * 2 [ AN-GW-Address ] * [ AN-GW-Status ] * [ 3GPP-SGSN-MCC-MNC ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ 3GPP-GGSN-Address ] * [ 3GPP-GGSN-Ipv6-Address ] * [ 3GPP-Selection-Mode ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ Fixed-User-Location-Info ] * [ User-Location-Info-Time ] * [ User-CSG-Information ] * [ TWAN-Identifier ] * [ 3GPP-MS-TimeZone ] * * [ RAN-NAS-Release-Cause ] * [ 3GPP-Charging-Characteristics ] * [ Called-Station-Id ] * [ PDN-Connection-ID ] * [ Bearer-Usage ] * [ Online ] * [ Offline ] * * [ TFT-Packet-Filter-Information ] * * [ Charging-Rule-Report ] * * [ Application-Detection-Information ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * [ Access-Network-Charging-Address ] * * [ Access-Network-Charging-Identifier-Gx ] * * [ CoA-Information ] * * [ Usage-Monitoring-Information ] * [ NBIFOM-Support ] * [ NBIFOM-Mode ] * [ Default-Access ] * [ Origination-Time-Stamp ] * [ Maximum-Wait-Time ] * [ Access-Availability-Change-Reason ] * [ Routing-Rule-Install ] * [ Routing-Rule-Remove ] * [ HeNB-Local-IP-Address ] * [ UE-Local-IP-Address ] * [ UDP-Source-Port ] * [ TCP-Source-Port ] * * [ Presence-Reporting-Area-Information ] * [ Logical-Access-Id ] * [ Physical-Access-Id ] * * [ Proxy-Info ] * * [ Route-Record ] * [ 3GPP-PS-Data-Off-Status ] * * [ AVP ] */ uint32_t gx_ccr_calc_length ( GxCCR *data ) { uint32_t length = sizeof(uint32_t); CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, session_id ); CALCLEN_BASIC( length, data, drmp ); CALCLEN_BASIC( length, data, auth_application_id ); CALCLEN_OCTETSTRING( length, data, origin_host ); CALCLEN_OCTETSTRING( length, data, origin_realm ); CALCLEN_OCTETSTRING( length, data, destination_realm ); CALCLEN_OCTETSTRING( length, data, service_context_id ); CALCLEN_BASIC( length, data, cc_request_type ); CALCLEN_BASIC( length, data, cc_request_number ); CALCLEN_BASIC( length, data, credit_management_status ); CALCLEN_OCTETSTRING( length, data, destination_host ); CALCLEN_BASIC( length, data, origin_state_id ); CALCLEN_LIST_STRUCT( length, data, subscription_id, calcLengthGxSubscriptionId ); CALCLEN_STRUCT( length, data, oc_supported_features, calcLengthGxOcSupportedFeatures ); CALCLEN_LIST_STRUCT( length, data, supported_features, calcLengthGxSupportedFeatures ); CALCLEN_STRUCT( length, data, tdf_information, calcLengthGxTdfInformation ); CALCLEN_BASIC( length, data, network_request_support ); CALCLEN_LIST_STRUCT( length, data, packet_filter_information, calcLengthGxPacketFilterInformation ); CALCLEN_BASIC( length, data, packet_filter_operation ); CALCLEN_OCTETSTRING( length, data, bearer_identifier ); CALCLEN_BASIC( length, data, bearer_operation ); CALCLEN_BASIC( length, data, dynamic_address_flag ); CALCLEN_BASIC( length, data, dynamic_address_flag_extension ); CALCLEN_BASIC( length, data, pdn_connection_charging_id ); CALCLEN_OCTETSTRING( length, data, framed_ip_address ); CALCLEN_OCTETSTRING( length, data, framed_ipv6_prefix ); CALCLEN_BASIC( length, data, ip_can_type ); CALCLEN_OCTETSTRING( length, data, tgpp_rat_type ); CALCLEN_BASIC( length, data, an_trusted ); CALCLEN_BASIC( length, data, rat_type ); CALCLEN_BASIC( length, data, termination_cause ); CALCLEN_STRUCT( length, data, user_equipment_info, calcLengthGxUserEquipmentInfo ); CALCLEN_STRUCT( length, data, qos_information, calcLengthGxQosInformation ); CALCLEN_BASIC( length, data, qos_negotiation ); CALCLEN_BASIC( length, data, qos_upgrade ); CALCLEN_STRUCT( length, data, default_eps_bearer_qos, calcLengthGxDefaultEpsBearerQos ); CALCLEN_STRUCT( length, data, default_qos_information, calcLengthGxDefaultQosInformation ); CALCLEN_LIST_BASIC( length, data, an_gw_address ); CALCLEN_BASIC( length, data, an_gw_status ); CALCLEN_OCTETSTRING( length, data, tgpp_sgsn_mcc_mnc ); CALCLEN_OCTETSTRING( length, data, tgpp_sgsn_address ); CALCLEN_OCTETSTRING( length, data, tgpp_sgsn_ipv6_address ); CALCLEN_OCTETSTRING( length, data, tgpp_ggsn_address ); CALCLEN_OCTETSTRING( length, data, tgpp_ggsn_ipv6_address ); CALCLEN_OCTETSTRING( length, data, tgpp_selection_mode ); CALCLEN_OCTETSTRING( length, data, rai ); CALCLEN_OCTETSTRING( length, data, tgpp_user_location_info ); CALCLEN_STRUCT( length, data, fixed_user_location_info, calcLengthGxFixedUserLocationInfo ); CALCLEN_BASIC( length, data, user_location_info_time ); CALCLEN_STRUCT( length, data, user_csg_information, calcLengthGxUserCsgInformation ); CALCLEN_OCTETSTRING( length, data, twan_identifier ); CALCLEN_OCTETSTRING( length, data, tgpp_ms_timezone ); CALCLEN_LIST_OCTETSTRING( length, data, ran_nas_release_cause ); CALCLEN_OCTETSTRING( length, data, tgpp_charging_characteristics ); CALCLEN_OCTETSTRING( length, data, called_station_id ); CALCLEN_OCTETSTRING( length, data, pdn_connection_id ); CALCLEN_BASIC( length, data, bearer_usage ); CALCLEN_BASIC( length, data, online ); CALCLEN_BASIC( length, data, offline ); CALCLEN_LIST_STRUCT( length, data, tft_packet_filter_information, calcLengthGxTftPacketFilterInformation ); CALCLEN_LIST_STRUCT( length, data, charging_rule_report, calcLengthGxChargingRuleReport ); CALCLEN_LIST_STRUCT( length, data, application_detection_information, calcLengthGxApplicationDetectionInformation ); CALCLEN_LIST_BASIC( length, data, event_trigger ); CALCLEN_STRUCT( length, data, event_report_indication, calcLengthGxEventReportIndication ); CALCLEN_BASIC( length, data, access_network_charging_address ); CALCLEN_LIST_STRUCT( length, data, access_network_charging_identifier_gx, calcLengthGxAccessNetworkChargingIdentifierGx ); CALCLEN_LIST_STRUCT( length, data, coa_information, calcLengthGxCoaInformation ); CALCLEN_LIST_STRUCT( length, data, usage_monitoring_information, calcLengthGxUsageMonitoringInformation ); CALCLEN_BASIC( length, data, nbifom_support ); CALCLEN_BASIC( length, data, nbifom_mode ); CALCLEN_BASIC( length, data, default_access ); CALCLEN_BASIC( length, data, origination_time_stamp ); CALCLEN_BASIC( length, data, maximum_wait_time ); CALCLEN_BASIC( length, data, access_availability_change_reason ); CALCLEN_STRUCT( length, data, routing_rule_install, calcLengthGxRoutingRuleInstall ); CALCLEN_STRUCT( length, data, routing_rule_remove, calcLengthGxRoutingRuleRemove ); CALCLEN_BASIC( length, data, henb_local_ip_address ); CALCLEN_BASIC( length, data, ue_local_ip_address ); CALCLEN_BASIC( length, data, udp_source_port ); CALCLEN_BASIC( length, data, tcp_source_port ); CALCLEN_LIST_STRUCT( length, data, presence_reporting_area_information, calcLengthGxPresenceReportingAreaInformation ); CALCLEN_OCTETSTRING( length, data, logical_access_id ); CALCLEN_OCTETSTRING( length, data, physical_access_id ); CALCLEN_LIST_STRUCT( length, data, proxy_info, calcLengthGxProxyInfo ); CALCLEN_LIST_OCTETSTRING( length, data, route_record ); CALCLEN_BASIC( length, data, tgpp_ps_data_off_status ); return length; } /*******************************************************************************/ /* message pack functions */ /*******************************************************************************/ /* * * Fun: gx_rar_pack * * Desc: Pack the contents of the Re-Auth-Request Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Re-Auth-Request ::= <Diameter Header: 258, REQ, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * { Destination-Realm } * { Destination-Host } * { Re-Auth-Request-Type } * [ Session-Release-Cause ] * [ Origin-State-Id ] * [ OC-Supported-Features ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * * [ Charging-Rule-Remove ] * * [ Charging-Rule-Install ] * [ Default-EPS-Bearer-QoS ] * * [ QoS-Information ] * [ Default-QoS-Information ] * [ Revalidation-Time ] * * [ Usage-Monitoring-Information ] * [ PCSCF-Restoration-Indication ] * * 4 [ Conditional-Policy-Information ] * [ Removal-Of-Access ] * [ IP-CAN-Type ] * [ PRA-Install ] * [ PRA-Remove ] * * [ CSG-Information-Reporting ] * * [ Proxy-Info ] * * [ Route-Record ] * * [ AVP ] */ int gx_rar_pack ( GxRAR *data, unsigned char *buf, uint32_t buflen ) { uint32_t _offset = sizeof(uint32_t); uint32_t *offset = &_offset; PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, session_id, buf, buflen, offset ); PACK_BASIC( data, drmp, buf, buflen, offset ); PACK_BASIC( data, auth_application_id, buf, buflen, offset ); PACK_OCTETSTRING( data, origin_host, buf, buflen, offset ); PACK_OCTETSTRING( data, origin_realm, buf, buflen, offset ); PACK_OCTETSTRING( data, destination_realm, buf, buflen, offset ); PACK_OCTETSTRING( data, destination_host, buf, buflen, offset ); PACK_BASIC( data, re_auth_request_type, buf, buflen, offset ); PACK_BASIC( data, session_release_cause, buf, buflen, offset ); PACK_BASIC( data, origin_state_id, buf, buflen, offset ); PACK_STRUCT( data, oc_supported_features, buf, buflen, offset, packGxOcSupportedFeatures ); PACK_LIST_BASIC( data, event_trigger, buf, buflen, offset ); PACK_STRUCT( data, event_report_indication, buf, buflen, offset, packGxEventReportIndication ); PACK_LIST_STRUCT( data, charging_rule_remove, buf, buflen, offset, packGxChargingRuleRemove ); PACK_LIST_STRUCT( data, charging_rule_install, buf, buflen, offset, packGxChargingRuleInstall ); PACK_STRUCT( data, default_eps_bearer_qos, buf, buflen, offset, packGxDefaultEpsBearerQos ); PACK_LIST_STRUCT( data, qos_information, buf, buflen, offset, packGxQosInformation ); PACK_STRUCT( data, default_qos_information, buf, buflen, offset, packGxDefaultQosInformation ); PACK_BASIC( data, revalidation_time, buf, buflen, offset ); PACK_LIST_STRUCT( data, usage_monitoring_information, buf, buflen, offset, packGxUsageMonitoringInformation ); PACK_BASIC( data, pcscf_restoration_indication, buf, buflen, offset ); PACK_LIST_STRUCT( data, conditional_policy_information, buf, buflen, offset, packGxConditionalPolicyInformation ); PACK_BASIC( data, removal_of_access, buf, buflen, offset ); PACK_BASIC( data, ip_can_type, buf, buflen, offset ); PACK_STRUCT( data, pra_install, buf, buflen, offset, packGxPraInstall ); PACK_STRUCT( data, pra_remove, buf, buflen, offset, packGxPraRemove ); PACK_LIST_BASIC( data, csg_information_reporting, buf, buflen, offset ); PACK_LIST_STRUCT( data, proxy_info, buf, buflen, offset, packGxProxyInfo ); PACK_LIST_OCTETSTRING( data, route_record, buf, buflen, offset ); *((uint32_t*)buf) = _offset; return _offset == buflen; } /* * * Fun: gx_raa_pack * * Desc: Pack the contents of the Re-Auth-Answer Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Re-Auth-Answer ::= <Diameter Header: 258, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Origin-Host } * { Origin-Realm } * [ Result-Code ] * [ Experimental-Result ] * [ Origin-State-Id ] * [ OC-Supported-Features ] * [ OC-OLR ] * [ IP-CAN-Type ] * [ RAT-Type ] * [ AN-Trusted ] * * 2 [ AN-GW-Address ] * [ 3GPP-SGSN-MCC-MNC ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ User-Location-Info-Time ] * [ NetLoc-Access-Support ] * [ User-CSG-Information ] * [ 3GPP-MS-TimeZone ] * [ Default-QoS-Information ] * * [ Charging-Rule-Report ] * [ Error-Message ] * [ Error-Reporting-Host ] * [ Failed-AVP ] * * [ Proxy-Info ] * * [ AVP ] */ int gx_raa_pack ( GxRAA *data, unsigned char *buf, uint32_t buflen ) { uint32_t _offset = sizeof(uint32_t); uint32_t *offset = &_offset; PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, session_id, buf, buflen, offset ); PACK_BASIC( data, drmp, buf, buflen, offset ); PACK_OCTETSTRING( data, origin_host, buf, buflen, offset ); PACK_OCTETSTRING( data, origin_realm, buf, buflen, offset ); PACK_BASIC( data, result_code, buf, buflen, offset ); PACK_STRUCT( data, experimental_result, buf, buflen, offset, packGxExperimentalResult ); PACK_BASIC( data, origin_state_id, buf, buflen, offset ); PACK_STRUCT( data, oc_supported_features, buf, buflen, offset, packGxOcSupportedFeatures ); PACK_STRUCT( data, oc_olr, buf, buflen, offset, packGxOcOlr ); PACK_BASIC( data, ip_can_type, buf, buflen, offset ); PACK_BASIC( data, rat_type, buf, buflen, offset ); PACK_BASIC( data, an_trusted, buf, buflen, offset ); PACK_LIST_BASIC( data, an_gw_address, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_sgsn_mcc_mnc, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_sgsn_address, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_sgsn_ipv6_address, buf, buflen, offset ); PACK_OCTETSTRING( data, rai, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_user_location_info, buf, buflen, offset ); PACK_BASIC( data, user_location_info_time, buf, buflen, offset ); PACK_BASIC( data, netloc_access_support, buf, buflen, offset ); PACK_STRUCT( data, user_csg_information, buf, buflen, offset, packGxUserCsgInformation ); PACK_OCTETSTRING( data, tgpp_ms_timezone, buf, buflen, offset ); PACK_STRUCT( data, default_qos_information, buf, buflen, offset, packGxDefaultQosInformation ); PACK_LIST_STRUCT( data, charging_rule_report, buf, buflen, offset, packGxChargingRuleReport ); PACK_OCTETSTRING( data, error_message, buf, buflen, offset ); PACK_OCTETSTRING( data, error_reporting_host, buf, buflen, offset ); PACK_STRUCT( data, failed_avp, buf, buflen, offset, packGxFailedAvp ); PACK_LIST_STRUCT( data, proxy_info, buf, buflen, offset, packGxProxyInfo ); *((uint32_t*)buf) = _offset; return _offset == buflen; } /* * * Fun: gx_cca_pack * * Desc: Pack the contents of the Credit-Control-Answer Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Credit-Control-Answer ::= <Diameter Header: 272, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * [ Result-Code ] * [ Experimental-Result ] * { CC-Request-Type } * { CC-Request-Number } * [ OC-Supported-Features ] * [ OC-OLR ] * * [ Supported-Features ] * [ Bearer-Control-Mode ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * [ Origin-State-Id ] * * [ Redirect-Host ] * [ Redirect-Host-Usage ] * [ Redirect-Max-Cache-Time ] * * [ Charging-Rule-Remove ] * * [ Charging-Rule-Install ] * [ Charging-Information ] * [ Online ] * [ Offline ] * * [ QoS-Information ] * [ Revalidation-Time ] * [ Default-EPS-Bearer-QoS ] * [ Default-QoS-Information ] * [ Bearer-Usage ] * * [ Usage-Monitoring-Information ] * * [ CSG-Information-Reporting ] * [ User-CSG-Information ] * [ PRA-Install ] * [ PRA-Remove ] * [ Presence-Reporting-Area-Information ] * [ Session-Release-Cause ] * [ NBIFOM-Support ] * [ NBIFOM-Mode ] * [ Default-Access ] * [ RAN-Rule-Support ] * * [ Routing-Rule-Report ] * * 4 [ Conditional-Policy-Information ] * [ Removal-Of-Access ] * [ IP-CAN-Type ] * [ Error-Message ] * [ Error-Reporting-Host ] * [ Failed-AVP ] * * [ Proxy-Info ] * * [ Route-Record ] * * [ Load ] * * [ AVP ] */ int gx_cca_pack ( GxCCA *data, unsigned char *buf, uint32_t buflen ) { uint32_t _offset = sizeof(uint32_t); uint32_t *offset = &_offset; PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, session_id, buf, buflen, offset ); PACK_BASIC( data, drmp, buf, buflen, offset ); PACK_BASIC( data, auth_application_id, buf, buflen, offset ); PACK_OCTETSTRING( data, origin_host, buf, buflen, offset ); PACK_OCTETSTRING( data, origin_realm, buf, buflen, offset ); PACK_BASIC( data, result_code, buf, buflen, offset ); PACK_STRUCT( data, experimental_result, buf, buflen, offset, packGxExperimentalResult ); PACK_BASIC( data, cc_request_type, buf, buflen, offset ); PACK_BASIC( data, cc_request_number, buf, buflen, offset ); PACK_STRUCT( data, oc_supported_features, buf, buflen, offset, packGxOcSupportedFeatures ); PACK_STRUCT( data, oc_olr, buf, buflen, offset, packGxOcOlr ); PACK_LIST_STRUCT( data, supported_features, buf, buflen, offset, packGxSupportedFeatures ); PACK_BASIC( data, bearer_control_mode, buf, buflen, offset ); PACK_LIST_BASIC( data, event_trigger, buf, buflen, offset ); PACK_STRUCT( data, event_report_indication, buf, buflen, offset, packGxEventReportIndication ); PACK_BASIC( data, origin_state_id, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, redirect_host, buf, buflen, offset ); PACK_BASIC( data, redirect_host_usage, buf, buflen, offset ); PACK_BASIC( data, redirect_max_cache_time, buf, buflen, offset ); PACK_LIST_STRUCT( data, charging_rule_remove, buf, buflen, offset, packGxChargingRuleRemove ); PACK_LIST_STRUCT( data, charging_rule_install, buf, buflen, offset, packGxChargingRuleInstall ); PACK_STRUCT( data, charging_information, buf, buflen, offset, packGxChargingInformation ); PACK_BASIC( data, online, buf, buflen, offset ); PACK_BASIC( data, offline, buf, buflen, offset ); PACK_LIST_STRUCT( data, qos_information, buf, buflen, offset, packGxQosInformation ); PACK_BASIC( data, revalidation_time, buf, buflen, offset ); PACK_STRUCT( data, default_eps_bearer_qos, buf, buflen, offset, packGxDefaultEpsBearerQos ); PACK_STRUCT( data, default_qos_information, buf, buflen, offset, packGxDefaultQosInformation ); PACK_BASIC( data, bearer_usage, buf, buflen, offset ); PACK_LIST_STRUCT( data, usage_monitoring_information, buf, buflen, offset, packGxUsageMonitoringInformation ); PACK_LIST_BASIC( data, csg_information_reporting, buf, buflen, offset ); PACK_STRUCT( data, user_csg_information, buf, buflen, offset, packGxUserCsgInformation ); PACK_STRUCT( data, pra_install, buf, buflen, offset, packGxPraInstall ); PACK_STRUCT( data, pra_remove, buf, buflen, offset, packGxPraRemove ); PACK_STRUCT( data, presence_reporting_area_information, buf, buflen, offset, packGxPresenceReportingAreaInformation ); PACK_BASIC( data, session_release_cause, buf, buflen, offset ); PACK_BASIC( data, nbifom_support, buf, buflen, offset ); PACK_BASIC( data, nbifom_mode, buf, buflen, offset ); PACK_BASIC( data, default_access, buf, buflen, offset ); PACK_BASIC( data, ran_rule_support, buf, buflen, offset ); PACK_LIST_STRUCT( data, routing_rule_report, buf, buflen, offset, packGxRoutingRuleReport ); PACK_LIST_STRUCT( data, conditional_policy_information, buf, buflen, offset, packGxConditionalPolicyInformation ); PACK_BASIC( data, removal_of_access, buf, buflen, offset ); PACK_BASIC( data, ip_can_type, buf, buflen, offset ); PACK_OCTETSTRING( data, error_message, buf, buflen, offset ); PACK_OCTETSTRING( data, error_reporting_host, buf, buflen, offset ); PACK_STRUCT( data, failed_avp, buf, buflen, offset, packGxFailedAvp ); PACK_LIST_STRUCT( data, proxy_info, buf, buflen, offset, packGxProxyInfo ); PACK_LIST_OCTETSTRING( data, route_record, buf, buflen, offset ); PACK_LIST_STRUCT( data, load, buf, buflen, offset, packGxLoad ); *((uint32_t*)buf) = _offset; return _offset == buflen; } /* * * Fun: gx_ccr_pack * * Desc: Pack the contents of the Credit-Control-Request Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Credit-Control-Request ::= <Diameter Header: 272, REQ, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * { Destination-Realm } * { CC-Request-Type } * { CC-Request-Number } * [ Credit-Management-Status ] * [ Destination-Host ] * [ Origin-State-Id ] * * [ Subscription-Id ] * [ OC-Supported-Features ] * * [ Supported-Features ] * [ TDF-Information ] * [ Network-Request-Support ] * * [ Packet-Filter-Information ] * [ Packet-Filter-Operation ] * [ Bearer-Identifier ] * [ Bearer-Operation ] * [ Dynamic-Address-Flag ] * [ Dynamic-Address-Flag-Extension ] * [ PDN-Connection-Charging-ID ] * [ Framed-IP-Address ] * [ Framed-IPv6-Prefix ] * [ IP-CAN-Type ] * [ 3GPP-RAT-Type ] * [ AN-Trusted ] * [ RAT-Type ] * [ Termination-Cause ] * [ User-Equipment-Info ] * [ QoS-Information ] * [ QoS-Negotiation ] * [ QoS-Upgrade ] * [ Default-EPS-Bearer-QoS ] * [ Default-QoS-Information ] * * 2 [ AN-GW-Address ] * [ AN-GW-Status ] * [ 3GPP-SGSN-MCC-MNC ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ 3GPP-GGSN-Address ] * [ 3GPP-GGSN-Ipv6-Address ] * [ 3GPP-Selection-Mode ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ Fixed-User-Location-Info ] * [ User-Location-Info-Time ] * [ User-CSG-Information ] * [ TWAN-Identifier ] * [ 3GPP-MS-TimeZone ] * * [ RAN-NAS-Release-Cause ] * [ 3GPP-Charging-Characteristics ] * [ Called-Station-Id ] * [ PDN-Connection-ID ] * [ Bearer-Usage ] * [ Online ] * [ Offline ] * * [ TFT-Packet-Filter-Information ] * * [ Charging-Rule-Report ] * * [ Application-Detection-Information ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * [ Access-Network-Charging-Address ] * * [ Access-Network-Charging-Identifier-Gx ] * * [ CoA-Information ] * * [ Usage-Monitoring-Information ] * [ NBIFOM-Support ] * [ NBIFOM-Mode ] * [ Default-Access ] * [ Origination-Time-Stamp ] * [ Maximum-Wait-Time ] * [ Access-Availability-Change-Reason ] * [ Routing-Rule-Install ] * [ Routing-Rule-Remove ] * [ HeNB-Local-IP-Address ] * [ UE-Local-IP-Address ] * [ UDP-Source-Port ] * [ TCP-Source-Port ] * * [ Presence-Reporting-Area-Information ] * [ Logical-Access-Id ] * [ Physical-Access-Id ] * * [ Proxy-Info ] * * [ Route-Record ] * [ 3GPP-PS-Data-Off-Status ] * * [ AVP ] */ int gx_ccr_pack ( GxCCR *data, unsigned char *buf, uint32_t buflen ) { uint32_t _offset = sizeof(uint32_t); uint32_t *offset = &_offset; PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, session_id, buf, buflen, offset ); PACK_BASIC( data, drmp, buf, buflen, offset ); PACK_BASIC( data, auth_application_id, buf, buflen, offset ); PACK_OCTETSTRING( data, origin_host, buf, buflen, offset ); PACK_OCTETSTRING( data, origin_realm, buf, buflen, offset ); PACK_OCTETSTRING( data, destination_realm, buf, buflen, offset ); PACK_OCTETSTRING( data, service_context_id, buf, buflen, offset ); PACK_BASIC( data, cc_request_type, buf, buflen, offset ); PACK_BASIC( data, cc_request_number, buf, buflen, offset ); PACK_BASIC( data, credit_management_status, buf, buflen, offset ); PACK_OCTETSTRING( data, destination_host, buf, buflen, offset ); PACK_BASIC( data, origin_state_id, buf, buflen, offset ); PACK_LIST_STRUCT( data, subscription_id, buf, buflen, offset, packGxSubscriptionId ); PACK_STRUCT( data, oc_supported_features, buf, buflen, offset, packGxOcSupportedFeatures ); PACK_LIST_STRUCT( data, supported_features, buf, buflen, offset, packGxSupportedFeatures ); PACK_STRUCT( data, tdf_information, buf, buflen, offset, packGxTdfInformation ); PACK_BASIC( data, network_request_support, buf, buflen, offset ); PACK_LIST_STRUCT( data, packet_filter_information, buf, buflen, offset, packGxPacketFilterInformation ); PACK_BASIC( data, packet_filter_operation, buf, buflen, offset ); PACK_OCTETSTRING( data, bearer_identifier, buf, buflen, offset ); PACK_BASIC( data, bearer_operation, buf, buflen, offset ); PACK_BASIC( data, dynamic_address_flag, buf, buflen, offset ); PACK_BASIC( data, dynamic_address_flag_extension, buf, buflen, offset ); PACK_BASIC( data, pdn_connection_charging_id, buf, buflen, offset ); PACK_OCTETSTRING( data, framed_ip_address, buf, buflen, offset ); PACK_OCTETSTRING( data, framed_ipv6_prefix, buf, buflen, offset ); PACK_BASIC( data, ip_can_type, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_rat_type, buf, buflen, offset ); PACK_BASIC( data, an_trusted, buf, buflen, offset ); PACK_BASIC( data, rat_type, buf, buflen, offset ); PACK_BASIC( data, termination_cause, buf, buflen, offset ); PACK_STRUCT( data, user_equipment_info, buf, buflen, offset, packGxUserEquipmentInfo ); PACK_STRUCT( data, qos_information, buf, buflen, offset, packGxQosInformation ); PACK_BASIC( data, qos_negotiation, buf, buflen, offset ); PACK_BASIC( data, qos_upgrade, buf, buflen, offset ); PACK_STRUCT( data, default_eps_bearer_qos, buf, buflen, offset, packGxDefaultEpsBearerQos ); PACK_STRUCT( data, default_qos_information, buf, buflen, offset, packGxDefaultQosInformation ); PACK_LIST_BASIC( data, an_gw_address, buf, buflen, offset ); PACK_BASIC( data, an_gw_status, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_sgsn_mcc_mnc, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_sgsn_address, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_sgsn_ipv6_address, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_ggsn_address, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_ggsn_ipv6_address, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_selection_mode, buf, buflen, offset ); PACK_OCTETSTRING( data, rai, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_user_location_info, buf, buflen, offset ); PACK_STRUCT( data, fixed_user_location_info, buf, buflen, offset, packGxFixedUserLocationInfo ); PACK_BASIC( data, user_location_info_time, buf, buflen, offset ); PACK_STRUCT( data, user_csg_information, buf, buflen, offset, packGxUserCsgInformation ); PACK_OCTETSTRING( data, twan_identifier, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_ms_timezone, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, ran_nas_release_cause, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_charging_characteristics, buf, buflen, offset ); PACK_OCTETSTRING( data, called_station_id, buf, buflen, offset ); PACK_OCTETSTRING( data, pdn_connection_id, buf, buflen, offset ); PACK_BASIC( data, bearer_usage, buf, buflen, offset ); PACK_BASIC( data, online, buf, buflen, offset ); PACK_BASIC( data, offline, buf, buflen, offset ); PACK_LIST_STRUCT( data, tft_packet_filter_information, buf, buflen, offset, packGxTftPacketFilterInformation ); PACK_LIST_STRUCT( data, charging_rule_report, buf, buflen, offset, packGxChargingRuleReport ); PACK_LIST_STRUCT( data, application_detection_information, buf, buflen, offset, packGxApplicationDetectionInformation ); PACK_LIST_BASIC( data, event_trigger, buf, buflen, offset ); PACK_STRUCT( data, event_report_indication, buf, buflen, offset, packGxEventReportIndication ); PACK_BASIC( data, access_network_charging_address, buf, buflen, offset ); PACK_LIST_STRUCT( data, access_network_charging_identifier_gx, buf, buflen, offset, packGxAccessNetworkChargingIdentifierGx ); PACK_LIST_STRUCT( data, coa_information, buf, buflen, offset, packGxCoaInformation ); PACK_LIST_STRUCT( data, usage_monitoring_information, buf, buflen, offset, packGxUsageMonitoringInformation ); PACK_BASIC( data, nbifom_support, buf, buflen, offset ); PACK_BASIC( data, nbifom_mode, buf, buflen, offset ); PACK_BASIC( data, default_access, buf, buflen, offset ); PACK_BASIC( data, origination_time_stamp, buf, buflen, offset ); PACK_BASIC( data, maximum_wait_time, buf, buflen, offset ); PACK_BASIC( data, access_availability_change_reason, buf, buflen, offset ); PACK_STRUCT( data, routing_rule_install, buf, buflen, offset, packGxRoutingRuleInstall ); PACK_STRUCT( data, routing_rule_remove, buf, buflen, offset, packGxRoutingRuleRemove ); PACK_BASIC( data, henb_local_ip_address, buf, buflen, offset ); PACK_BASIC( data, ue_local_ip_address, buf, buflen, offset ); PACK_BASIC( data, udp_source_port, buf, buflen, offset ); PACK_BASIC( data, tcp_source_port, buf, buflen, offset ); PACK_LIST_STRUCT( data, presence_reporting_area_information, buf, buflen, offset, packGxPresenceReportingAreaInformation ); PACK_OCTETSTRING( data, logical_access_id, buf, buflen, offset ); PACK_OCTETSTRING( data, physical_access_id, buf, buflen, offset ); PACK_LIST_STRUCT( data, proxy_info, buf, buflen, offset, packGxProxyInfo ); PACK_LIST_OCTETSTRING( data, route_record, buf, buflen, offset ); PACK_BASIC( data, tgpp_ps_data_off_status, buf, buflen, offset ); *((uint32_t*)buf) = _offset; return _offset == buflen; } /*******************************************************************************/ /* message unpack functions */ /*******************************************************************************/ /* * * Fun: gx_rar_unpack * * Desc: Unpack the specified buffer into the Re-Auth-Request Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Re-Auth-Request ::= <Diameter Header: 258, REQ, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * { Destination-Realm } * { Destination-Host } * { Re-Auth-Request-Type } * [ Session-Release-Cause ] * [ Origin-State-Id ] * [ OC-Supported-Features ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * * [ Charging-Rule-Remove ] * * [ Charging-Rule-Install ] * [ Default-EPS-Bearer-QoS ] * * [ QoS-Information ] * [ Default-QoS-Information ] * [ Revalidation-Time ] * * [ Usage-Monitoring-Information ] * [ PCSCF-Restoration-Indication ] * * 4 [ Conditional-Policy-Information ] * [ Removal-Of-Access ] * [ IP-CAN-Type ] * [ PRA-Install ] * [ PRA-Remove ] * * [ CSG-Information-Reporting ] * * [ Proxy-Info ] * * [ Route-Record ] * * [ AVP ] */ int gx_rar_unpack ( unsigned char *buf, GxRAR *data ) { uint32_t length = *((uint32_t*)buf); uint32_t _offset = sizeof(uint32_t); uint32_t *offset = &_offset; UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, session_id, buf, length, offset ); UNPACK_BASIC( data, drmp, buf, length, offset ); UNPACK_BASIC( data, auth_application_id, buf, length, offset ); UNPACK_OCTETSTRING( data, origin_host, buf, length, offset ); UNPACK_OCTETSTRING( data, origin_realm, buf, length, offset ); UNPACK_OCTETSTRING( data, destination_realm, buf, length, offset ); UNPACK_OCTETSTRING( data, destination_host, buf, length, offset ); UNPACK_BASIC( data, re_auth_request_type, buf, length, offset ); UNPACK_BASIC( data, session_release_cause, buf, length, offset ); UNPACK_BASIC( data, origin_state_id, buf, length, offset ); UNPACK_STRUCT( data, oc_supported_features, buf, length, offset, unpackGxOcSupportedFeatures ); UNPACK_LIST_BASIC( data, event_trigger, int32_t, buf, length, offset ); UNPACK_STRUCT( data, event_report_indication, buf, length, offset, unpackGxEventReportIndication ); UNPACK_LIST_STRUCT( data, charging_rule_remove, GxChargingRuleRemove, buf, length, offset, unpackGxChargingRuleRemove ); UNPACK_LIST_STRUCT( data, charging_rule_install, GxChargingRuleInstall, buf, length, offset, unpackGxChargingRuleInstall ); UNPACK_STRUCT( data, default_eps_bearer_qos, buf, length, offset, unpackGxDefaultEpsBearerQos ); UNPACK_LIST_STRUCT( data, qos_information, GxQosInformation, buf, length, offset, unpackGxQosInformation ); UNPACK_STRUCT( data, default_qos_information, buf, length, offset, unpackGxDefaultQosInformation ); UNPACK_BASIC( data, revalidation_time, buf, length, offset ); UNPACK_LIST_STRUCT( data, usage_monitoring_information, GxUsageMonitoringInformation, buf, length, offset, unpackGxUsageMonitoringInformation ); UNPACK_BASIC( data, pcscf_restoration_indication, buf, length, offset ); UNPACK_LIST_STRUCT( data, conditional_policy_information, GxConditionalPolicyInformation, buf, length, offset, unpackGxConditionalPolicyInformation ); UNPACK_BASIC( data, removal_of_access, buf, length, offset ); UNPACK_BASIC( data, ip_can_type, buf, length, offset ); UNPACK_STRUCT( data, pra_install, buf, length, offset, unpackGxPraInstall ); UNPACK_STRUCT( data, pra_remove, buf, length, offset, unpackGxPraRemove ); UNPACK_LIST_BASIC( data, csg_information_reporting, int32_t, buf, length, offset ); UNPACK_LIST_STRUCT( data, proxy_info, GxProxyInfo, buf, length, offset, unpackGxProxyInfo ); UNPACK_LIST_OCTETSTRING( data, route_record, GxRouteRecordOctetString, buf, length, offset ); return length == _offset; } /* * * Fun: gx_raa_unpack * * Desc: Unpack the specified buffer into the Re-Auth-Answer Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Re-Auth-Answer ::= <Diameter Header: 258, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Origin-Host } * { Origin-Realm } * [ Result-Code ] * [ Experimental-Result ] * [ Origin-State-Id ] * [ OC-Supported-Features ] * [ OC-OLR ] * [ IP-CAN-Type ] * [ RAT-Type ] * [ AN-Trusted ] * * 2 [ AN-GW-Address ] * [ 3GPP-SGSN-MCC-MNC ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ User-Location-Info-Time ] * [ NetLoc-Access-Support ] * [ User-CSG-Information ] * [ 3GPP-MS-TimeZone ] * [ Default-QoS-Information ] * * [ Charging-Rule-Report ] * [ Error-Message ] * [ Error-Reporting-Host ] * [ Failed-AVP ] * * [ Proxy-Info ] * * [ AVP ] */ int gx_raa_unpack ( unsigned char *buf, GxRAA *data ) { uint32_t length = *((uint32_t*)buf); uint32_t _offset = sizeof(uint32_t); uint32_t *offset = &_offset; UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, session_id, buf, length, offset ); UNPACK_BASIC( data, drmp, buf, length, offset ); UNPACK_OCTETSTRING( data, origin_host, buf, length, offset ); UNPACK_OCTETSTRING( data, origin_realm, buf, length, offset ); UNPACK_BASIC( data, result_code, buf, length, offset ); UNPACK_STRUCT( data, experimental_result, buf, length, offset, unpackGxExperimentalResult ); UNPACK_BASIC( data, origin_state_id, buf, length, offset ); UNPACK_STRUCT( data, oc_supported_features, buf, length, offset, unpackGxOcSupportedFeatures ); UNPACK_STRUCT( data, oc_olr, buf, length, offset, unpackGxOcOlr ); UNPACK_BASIC( data, ip_can_type, buf, length, offset ); UNPACK_BASIC( data, rat_type, buf, length, offset ); UNPACK_BASIC( data, an_trusted, buf, length, offset ); UNPACK_LIST_BASIC( data, an_gw_address, FdAddress, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_sgsn_mcc_mnc, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_sgsn_address, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_sgsn_ipv6_address, buf, length, offset ); UNPACK_OCTETSTRING( data, rai, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_user_location_info, buf, length, offset ); UNPACK_BASIC( data, user_location_info_time, buf, length, offset ); UNPACK_BASIC( data, netloc_access_support, buf, length, offset ); UNPACK_STRUCT( data, user_csg_information, buf, length, offset, unpackGxUserCsgInformation ); UNPACK_OCTETSTRING( data, tgpp_ms_timezone, buf, length, offset ); UNPACK_STRUCT( data, default_qos_information, buf, length, offset, unpackGxDefaultQosInformation ); UNPACK_LIST_STRUCT( data, charging_rule_report, GxChargingRuleReport, buf, length, offset, unpackGxChargingRuleReport ); UNPACK_OCTETSTRING( data, error_message, buf, length, offset ); UNPACK_OCTETSTRING( data, error_reporting_host, buf, length, offset ); UNPACK_STRUCT( data, failed_avp, buf, length, offset, unpackGxFailedAvp ); UNPACK_LIST_STRUCT( data, proxy_info, GxProxyInfo, buf, length, offset, unpackGxProxyInfo ); return length == _offset; } /* * * Fun: gx_cca_unpack * * Desc: Unpack the specified buffer into the Credit-Control-Answer Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Credit-Control-Answer ::= <Diameter Header: 272, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * [ Result-Code ] * [ Experimental-Result ] * { CC-Request-Type } * { CC-Request-Number } * [ OC-Supported-Features ] * [ OC-OLR ] * * [ Supported-Features ] * [ Bearer-Control-Mode ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * [ Origin-State-Id ] * * [ Redirect-Host ] * [ Redirect-Host-Usage ] * [ Redirect-Max-Cache-Time ] * * [ Charging-Rule-Remove ] * * [ Charging-Rule-Install ] * [ Charging-Information ] * [ Online ] * [ Offline ] * * [ QoS-Information ] * [ Revalidation-Time ] * [ Default-EPS-Bearer-QoS ] * [ Default-QoS-Information ] * [ Bearer-Usage ] * * [ Usage-Monitoring-Information ] * * [ CSG-Information-Reporting ] * [ User-CSG-Information ] * [ PRA-Install ] * [ PRA-Remove ] * [ Presence-Reporting-Area-Information ] * [ Session-Release-Cause ] * [ NBIFOM-Support ] * [ NBIFOM-Mode ] * [ Default-Access ] * [ RAN-Rule-Support ] * * [ Routing-Rule-Report ] * * 4 [ Conditional-Policy-Information ] * [ Removal-Of-Access ] * [ IP-CAN-Type ] * [ Error-Message ] * [ Error-Reporting-Host ] * [ Failed-AVP ] * * [ Proxy-Info ] * * [ Route-Record ] * * [ Load ] * * [ AVP ] */ int gx_cca_unpack ( unsigned char *buf, GxCCA *data ) { uint32_t length = *((uint32_t*)buf); uint32_t _offset = sizeof(uint32_t); uint32_t *offset = &_offset; UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, session_id, buf, length, offset ); UNPACK_BASIC( data, drmp, buf, length, offset ); UNPACK_BASIC( data, auth_application_id, buf, length, offset ); UNPACK_OCTETSTRING( data, origin_host, buf, length, offset ); UNPACK_OCTETSTRING( data, origin_realm, buf, length, offset ); UNPACK_BASIC( data, result_code, buf, length, offset ); UNPACK_STRUCT( data, experimental_result, buf, length, offset, unpackGxExperimentalResult ); UNPACK_BASIC( data, cc_request_type, buf, length, offset ); UNPACK_BASIC( data, cc_request_number, buf, length, offset ); UNPACK_STRUCT( data, oc_supported_features, buf, length, offset, unpackGxOcSupportedFeatures ); UNPACK_STRUCT( data, oc_olr, buf, length, offset, unpackGxOcOlr ); UNPACK_LIST_STRUCT( data, supported_features, GxSupportedFeatures, buf, length, offset, unpackGxSupportedFeatures ); UNPACK_BASIC( data, bearer_control_mode, buf, length, offset ); UNPACK_LIST_BASIC( data, event_trigger, int32_t, buf, length, offset ); UNPACK_STRUCT( data, event_report_indication, buf, length, offset, unpackGxEventReportIndication ); UNPACK_BASIC( data, origin_state_id, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, redirect_host, GxRedirectHostOctetString, buf, length, offset ); UNPACK_BASIC( data, redirect_host_usage, buf, length, offset ); UNPACK_BASIC( data, redirect_max_cache_time, buf, length, offset ); UNPACK_LIST_STRUCT( data, charging_rule_remove, GxChargingRuleRemove, buf, length, offset, unpackGxChargingRuleRemove ); UNPACK_LIST_STRUCT( data, charging_rule_install, GxChargingRuleInstall, buf, length, offset, unpackGxChargingRuleInstall ); UNPACK_STRUCT( data, charging_information, buf, length, offset, unpackGxChargingInformation ); UNPACK_BASIC( data, online, buf, length, offset ); UNPACK_BASIC( data, offline, buf, length, offset ); UNPACK_LIST_STRUCT( data, qos_information, GxQosInformation, buf, length, offset, unpackGxQosInformation ); UNPACK_BASIC( data, revalidation_time, buf, length, offset ); UNPACK_STRUCT( data, default_eps_bearer_qos, buf, length, offset, unpackGxDefaultEpsBearerQos ); UNPACK_STRUCT( data, default_qos_information, buf, length, offset, unpackGxDefaultQosInformation ); UNPACK_BASIC( data, bearer_usage, buf, length, offset ); UNPACK_LIST_STRUCT( data, usage_monitoring_information, GxUsageMonitoringInformation, buf, length, offset, unpackGxUsageMonitoringInformation ); UNPACK_LIST_BASIC( data, csg_information_reporting, int32_t, buf, length, offset ); UNPACK_STRUCT( data, user_csg_information, buf, length, offset, unpackGxUserCsgInformation ); UNPACK_STRUCT( data, pra_install, buf, length, offset, unpackGxPraInstall ); UNPACK_STRUCT( data, pra_remove, buf, length, offset, unpackGxPraRemove ); UNPACK_STRUCT( data, presence_reporting_area_information, buf, length, offset, unpackGxPresenceReportingAreaInformation ); UNPACK_BASIC( data, session_release_cause, buf, length, offset ); UNPACK_BASIC( data, nbifom_support, buf, length, offset ); UNPACK_BASIC( data, nbifom_mode, buf, length, offset ); UNPACK_BASIC( data, default_access, buf, length, offset ); UNPACK_BASIC( data, ran_rule_support, buf, length, offset ); UNPACK_LIST_STRUCT( data, routing_rule_report, GxRoutingRuleReport, buf, length, offset, unpackGxRoutingRuleReport ); UNPACK_LIST_STRUCT( data, conditional_policy_information, GxConditionalPolicyInformation, buf, length, offset, unpackGxConditionalPolicyInformation ); UNPACK_BASIC( data, removal_of_access, buf, length, offset ); UNPACK_BASIC( data, ip_can_type, buf, length, offset ); UNPACK_OCTETSTRING( data, error_message, buf, length, offset ); UNPACK_OCTETSTRING( data, error_reporting_host, buf, length, offset ); UNPACK_STRUCT( data, failed_avp, buf, length, offset, unpackGxFailedAvp ); UNPACK_LIST_STRUCT( data, proxy_info, GxProxyInfo, buf, length, offset, unpackGxProxyInfo ); UNPACK_LIST_OCTETSTRING( data, route_record, GxRouteRecordOctetString, buf, length, offset ); UNPACK_LIST_STRUCT( data, load, GxLoad, buf, length, offset, unpackGxLoad ); return length == _offset; } /* * * Fun: gx_ccr_unpack * * Desc: Unpack the specified buffer into the Credit-Control-Request Message * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Credit-Control-Request ::= <Diameter Header: 272, REQ, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * { Destination-Realm } * { CC-Request-Type } * { CC-Request-Number } * [ Credit-Management-Status ] * [ Destination-Host ] * [ Origin-State-Id ] * * [ Subscription-Id ] * [ OC-Supported-Features ] * * [ Supported-Features ] * [ TDF-Information ] * [ Network-Request-Support ] * * [ Packet-Filter-Information ] * [ Packet-Filter-Operation ] * [ Bearer-Identifier ] * [ Bearer-Operation ] * [ Dynamic-Address-Flag ] * [ Dynamic-Address-Flag-Extension ] * [ PDN-Connection-Charging-ID ] * [ Framed-IP-Address ] * [ Framed-IPv6-Prefix ] * [ IP-CAN-Type ] * [ 3GPP-RAT-Type ] * [ AN-Trusted ] * [ RAT-Type ] * [ Termination-Cause ] * [ User-Equipment-Info ] * [ QoS-Information ] * [ QoS-Negotiation ] * [ QoS-Upgrade ] * [ Default-EPS-Bearer-QoS ] * [ Default-QoS-Information ] * * 2 [ AN-GW-Address ] * [ AN-GW-Status ] * [ 3GPP-SGSN-MCC-MNC ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ 3GPP-GGSN-Address ] * [ 3GPP-GGSN-Ipv6-Address ] * [ 3GPP-Selection-Mode ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ Fixed-User-Location-Info ] * [ User-Location-Info-Time ] * [ User-CSG-Information ] * [ TWAN-Identifier ] * [ 3GPP-MS-TimeZone ] * * [ RAN-NAS-Release-Cause ] * [ 3GPP-Charging-Characteristics ] * [ Called-Station-Id ] * [ PDN-Connection-ID ] * [ Bearer-Usage ] * [ Online ] * [ Offline ] * * [ TFT-Packet-Filter-Information ] * * [ Charging-Rule-Report ] * * [ Application-Detection-Information ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * [ Access-Network-Charging-Address ] * * [ Access-Network-Charging-Identifier-Gx ] * * [ CoA-Information ] * * [ Usage-Monitoring-Information ] * [ NBIFOM-Support ] * [ NBIFOM-Mode ] * [ Default-Access ] * [ Origination-Time-Stamp ] * [ Maximum-Wait-Time ] * [ Access-Availability-Change-Reason ] * [ Routing-Rule-Install ] * [ Routing-Rule-Remove ] * [ HeNB-Local-IP-Address ] * [ UE-Local-IP-Address ] * [ UDP-Source-Port ] * [ TCP-Source-Port ] * * [ Presence-Reporting-Area-Information ] * [ Logical-Access-Id ] * [ Physical-Access-Id ] * * [ Proxy-Info ] * * [ Route-Record ] * [ 3GPP-PS-Data-Off-Status ] * * [ AVP ] */ int gx_ccr_unpack ( unsigned char *buf, GxCCR *data ) { uint32_t length = *((uint32_t*)buf); uint32_t _offset = sizeof(uint32_t); uint32_t *offset = &_offset; UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, session_id, buf, length, offset ); UNPACK_BASIC( data, drmp, buf, length, offset ); UNPACK_BASIC( data, auth_application_id, buf, length, offset ); UNPACK_OCTETSTRING( data, origin_host, buf, length, offset ); UNPACK_OCTETSTRING( data, origin_realm, buf, length, offset ); UNPACK_OCTETSTRING( data, destination_realm, buf, length, offset ); UNPACK_OCTETSTRING( data, service_context_id, buf, length, offset ); UNPACK_BASIC( data, cc_request_type, buf, length, offset ); UNPACK_BASIC( data, cc_request_number, buf, length, offset ); UNPACK_BASIC( data, credit_management_status, buf, length, offset ); UNPACK_OCTETSTRING( data, destination_host, buf, length, offset ); UNPACK_BASIC( data, origin_state_id, buf, length, offset ); UNPACK_LIST_STRUCT( data, subscription_id, GxSubscriptionId, buf, length, offset, unpackGxSubscriptionId ); UNPACK_STRUCT( data, oc_supported_features, buf, length, offset, unpackGxOcSupportedFeatures ); UNPACK_LIST_STRUCT( data, supported_features, GxSupportedFeatures, buf, length, offset, unpackGxSupportedFeatures ); UNPACK_STRUCT( data, tdf_information, buf, length, offset, unpackGxTdfInformation ); UNPACK_BASIC( data, network_request_support, buf, length, offset ); UNPACK_LIST_STRUCT( data, packet_filter_information, GxPacketFilterInformation, buf, length, offset, unpackGxPacketFilterInformation ); UNPACK_BASIC( data, packet_filter_operation, buf, length, offset ); UNPACK_OCTETSTRING( data, bearer_identifier, buf, length, offset ); UNPACK_BASIC( data, bearer_operation, buf, length, offset ); UNPACK_BASIC( data, dynamic_address_flag, buf, length, offset ); UNPACK_BASIC( data, dynamic_address_flag_extension, buf, length, offset ); UNPACK_BASIC( data, pdn_connection_charging_id, buf, length, offset ); UNPACK_OCTETSTRING( data, framed_ip_address, buf, length, offset ); UNPACK_OCTETSTRING( data, framed_ipv6_prefix, buf, length, offset ); UNPACK_BASIC( data, ip_can_type, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_rat_type, buf, length, offset ); UNPACK_BASIC( data, an_trusted, buf, length, offset ); UNPACK_BASIC( data, rat_type, buf, length, offset ); UNPACK_BASIC( data, termination_cause, buf, length, offset ); UNPACK_STRUCT( data, user_equipment_info, buf, length, offset, unpackGxUserEquipmentInfo ); UNPACK_STRUCT( data, qos_information, buf, length, offset, unpackGxQosInformation ); UNPACK_BASIC( data, qos_negotiation, buf, length, offset ); UNPACK_BASIC( data, qos_upgrade, buf, length, offset ); UNPACK_STRUCT( data, default_eps_bearer_qos, buf, length, offset, unpackGxDefaultEpsBearerQos ); UNPACK_STRUCT( data, default_qos_information, buf, length, offset, unpackGxDefaultQosInformation ); UNPACK_LIST_BASIC( data, an_gw_address, FdAddress, buf, length, offset ); UNPACK_BASIC( data, an_gw_status, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_sgsn_mcc_mnc, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_sgsn_address, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_sgsn_ipv6_address, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_ggsn_address, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_ggsn_ipv6_address, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_selection_mode, buf, length, offset ); UNPACK_OCTETSTRING( data, rai, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_user_location_info, buf, length, offset ); UNPACK_STRUCT( data, fixed_user_location_info, buf, length, offset, unpackGxFixedUserLocationInfo ); UNPACK_BASIC( data, user_location_info_time, buf, length, offset ); UNPACK_STRUCT( data, user_csg_information, buf, length, offset, unpackGxUserCsgInformation ); UNPACK_OCTETSTRING( data, twan_identifier, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_ms_timezone, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, ran_nas_release_cause, GxRanNasReleaseCauseOctetString, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_charging_characteristics, buf, length, offset ); UNPACK_OCTETSTRING( data, called_station_id, buf, length, offset ); UNPACK_OCTETSTRING( data, pdn_connection_id, buf, length, offset ); UNPACK_BASIC( data, bearer_usage, buf, length, offset ); UNPACK_BASIC( data, online, buf, length, offset ); UNPACK_BASIC( data, offline, buf, length, offset ); UNPACK_LIST_STRUCT( data, tft_packet_filter_information, GxTftPacketFilterInformation, buf, length, offset, unpackGxTftPacketFilterInformation ); UNPACK_LIST_STRUCT( data, charging_rule_report, GxChargingRuleReport, buf, length, offset, unpackGxChargingRuleReport ); UNPACK_LIST_STRUCT( data, application_detection_information, GxApplicationDetectionInformation, buf, length, offset, unpackGxApplicationDetectionInformation ); UNPACK_LIST_BASIC( data, event_trigger, int32_t, buf, length, offset ); UNPACK_STRUCT( data, event_report_indication, buf, length, offset, unpackGxEventReportIndication ); UNPACK_BASIC( data, access_network_charging_address, buf, length, offset ); UNPACK_LIST_STRUCT( data, access_network_charging_identifier_gx, GxAccessNetworkChargingIdentifierGx, buf, length, offset, unpackGxAccessNetworkChargingIdentifierGx ); UNPACK_LIST_STRUCT( data, coa_information, GxCoaInformation, buf, length, offset, unpackGxCoaInformation ); UNPACK_LIST_STRUCT( data, usage_monitoring_information, GxUsageMonitoringInformation, buf, length, offset, unpackGxUsageMonitoringInformation ); UNPACK_BASIC( data, nbifom_support, buf, length, offset ); UNPACK_BASIC( data, nbifom_mode, buf, length, offset ); UNPACK_BASIC( data, default_access, buf, length, offset ); UNPACK_BASIC( data, origination_time_stamp, buf, length, offset ); UNPACK_BASIC( data, maximum_wait_time, buf, length, offset ); UNPACK_BASIC( data, access_availability_change_reason, buf, length, offset ); UNPACK_STRUCT( data, routing_rule_install, buf, length, offset, unpackGxRoutingRuleInstall ); UNPACK_STRUCT( data, routing_rule_remove, buf, length, offset, unpackGxRoutingRuleRemove ); UNPACK_BASIC( data, henb_local_ip_address, buf, length, offset ); UNPACK_BASIC( data, ue_local_ip_address, buf, length, offset ); UNPACK_BASIC( data, udp_source_port, buf, length, offset ); UNPACK_BASIC( data, tcp_source_port, buf, length, offset ); UNPACK_LIST_STRUCT( data, presence_reporting_area_information, GxPresenceReportingAreaInformation, buf, length, offset, unpackGxPresenceReportingAreaInformation ); UNPACK_OCTETSTRING( data, logical_access_id, buf, length, offset ); UNPACK_OCTETSTRING( data, physical_access_id, buf, length, offset ); UNPACK_LIST_STRUCT( data, proxy_info, GxProxyInfo, buf, length, offset, unpackGxProxyInfo ); UNPACK_LIST_OCTETSTRING( data, route_record, GxRouteRecordOctetString, buf, length, offset ); UNPACK_BASIC( data, tgpp_ps_data_off_status, buf, length, offset ); return length == _offset; } /*******************************************************************************/ /* message length calculation functions */ /*******************************************************************************/ /* * * Fun: calcLengthGxExperimentalResult * * Desc: Calculate the length for GxExperimentalResult * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Experimental-Result ::= <AVP Header: 297> * { Vendor-Id } * { Experimental-Result-Code } */ static uint32_t calcLengthGxExperimentalResult ( GxExperimentalResult *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, vendor_id ); CALCLEN_BASIC( length, data, experimental_result_code ); return length; } /* * * Fun: calcLengthGxPraRemove * * Desc: Calculate the length for GxPraRemove * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * PRA-Remove ::= <AVP Header: 2846> * * [ Presence-Reporting-Area-Identifier ] * * [ AVP ] */ static uint32_t calcLengthGxPraRemove ( GxPraRemove *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_LIST_OCTETSTRING( length, data, presence_reporting_area_identifier ); return length; } /* * * Fun: calcLengthGxQosInformation * * Desc: Calculate the length for GxQosInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * QoS-Information ::= <AVP Header: 1016> * [ QoS-Class-Identifier ] * [ Max-Requested-Bandwidth-UL ] * [ Max-Requested-Bandwidth-DL ] * [ Extended-Max-Requested-BW-UL ] * [ Extended-Max-Requested-BW-DL ] * [ Guaranteed-Bitrate-UL ] * [ Guaranteed-Bitrate-DL ] * [ Extended-GBR-UL ] * [ Extended-GBR-DL ] * [ Bearer-Identifier ] * [ Allocation-Retention-Priority ] * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ Conditional-APN-Aggregate-Max-Bitrate ] * * [ AVP ] */ static uint32_t calcLengthGxQosInformation ( GxQosInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, qos_class_identifier ); CALCLEN_BASIC( length, data, max_requested_bandwidth_ul ); CALCLEN_BASIC( length, data, max_requested_bandwidth_dl ); CALCLEN_BASIC( length, data, extended_max_requested_bw_ul ); CALCLEN_BASIC( length, data, extended_max_requested_bw_dl ); CALCLEN_BASIC( length, data, guaranteed_bitrate_ul ); CALCLEN_BASIC( length, data, guaranteed_bitrate_dl ); CALCLEN_BASIC( length, data, extended_gbr_ul ); CALCLEN_BASIC( length, data, extended_gbr_dl ); CALCLEN_OCTETSTRING( length, data, bearer_identifier ); CALCLEN_STRUCT( length, data, allocation_retention_priority, calcLengthGxAllocationRetentionPriority ); CALCLEN_BASIC( length, data, apn_aggregate_max_bitrate_ul ); CALCLEN_BASIC( length, data, apn_aggregate_max_bitrate_dl ); CALCLEN_BASIC( length, data, extended_apn_ambr_ul ); CALCLEN_BASIC( length, data, extended_apn_ambr_dl ); CALCLEN_LIST_STRUCT( length, data, conditional_apn_aggregate_max_bitrate, calcLengthGxConditionalApnAggregateMaxBitrate ); return length; } /* * * Fun: calcLengthGxConditionalPolicyInformation * * Desc: Calculate the length for GxConditionalPolicyInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Conditional-Policy-Information ::= <AVP Header: 2840> * [ Execution-Time ] * [ Default-EPS-Bearer-QoS ] * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ Conditional-APN-Aggregate-Max-Bitrate ] * * [ AVP ] */ static uint32_t calcLengthGxConditionalPolicyInformation ( GxConditionalPolicyInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, execution_time ); CALCLEN_STRUCT( length, data, default_eps_bearer_qos, calcLengthGxDefaultEpsBearerQos ); CALCLEN_BASIC( length, data, apn_aggregate_max_bitrate_ul ); CALCLEN_BASIC( length, data, apn_aggregate_max_bitrate_dl ); CALCLEN_BASIC( length, data, extended_apn_ambr_ul ); CALCLEN_BASIC( length, data, extended_apn_ambr_dl ); CALCLEN_LIST_STRUCT( length, data, conditional_apn_aggregate_max_bitrate, calcLengthGxConditionalApnAggregateMaxBitrate ); return length; } /* * * Fun: calcLengthGxPraInstall * * Desc: Calculate the length for GxPraInstall * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * PRA-Install ::= <AVP Header: 2845> * * [ Presence-Reporting-Area-Information ] * * [ AVP ] */ static uint32_t calcLengthGxPraInstall ( GxPraInstall *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_LIST_STRUCT( length, data, presence_reporting_area_information, calcLengthGxPresenceReportingAreaInformation ); return length; } /* * * Fun: calcLengthGxAreaScope * * Desc: Calculate the length for GxAreaScope * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Area-Scope ::= <AVP Header: 1624> * * [ Cell-Global-Identity ] * * [ E-UTRAN-Cell-Global-Identity ] * * [ Routing-Area-Identity ] * * [ Location-Area-Identity ] * * [ Tracking-Area-Identity ] * * [ AVP ] */ static uint32_t calcLengthGxAreaScope ( GxAreaScope *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_LIST_OCTETSTRING( length, data, cell_global_identity ); CALCLEN_LIST_OCTETSTRING( length, data, e_utran_cell_global_identity ); CALCLEN_LIST_OCTETSTRING( length, data, routing_area_identity ); CALCLEN_LIST_OCTETSTRING( length, data, location_area_identity ); CALCLEN_LIST_OCTETSTRING( length, data, tracking_area_identity ); return length; } /* * * Fun: calcLengthGxFlowInformation * * Desc: Calculate the length for GxFlowInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Flow-Information ::= <AVP Header: 1058> * [ Flow-Description ] * [ Packet-Filter-Identifier ] * [ Packet-Filter-Usage ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * [ Routing-Rule-Identifier ] * * [ AVP ] */ static uint32_t calcLengthGxFlowInformation ( GxFlowInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, flow_description ); CALCLEN_OCTETSTRING( length, data, packet_filter_identifier ); CALCLEN_BASIC( length, data, packet_filter_usage ); CALCLEN_OCTETSTRING( length, data, tos_traffic_class ); CALCLEN_OCTETSTRING( length, data, security_parameter_index ); CALCLEN_OCTETSTRING( length, data, flow_label ); CALCLEN_BASIC( length, data, flow_direction ); CALCLEN_OCTETSTRING( length, data, routing_rule_identifier ); return length; } /* * * Fun: calcLengthGxTunnelInformation * * Desc: Calculate the length for GxTunnelInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Tunnel-Information ::= <AVP Header: 1038> * [ Tunnel-Header-Length ] * [ Tunnel-Header-Filter ] */ static uint32_t calcLengthGxTunnelInformation ( GxTunnelInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, tunnel_header_length ); CALCLEN_LIST_OCTETSTRING( length, data, tunnel_header_filter ); return length; } /* * * Fun: calcLengthGxTftPacketFilterInformation * * Desc: Calculate the length for GxTftPacketFilterInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * TFT-Packet-Filter-Information ::= <AVP Header: 1013> * [ Precedence ] * [ TFT-Filter ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * * [ AVP ] */ static uint32_t calcLengthGxTftPacketFilterInformation ( GxTftPacketFilterInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, precedence ); CALCLEN_OCTETSTRING( length, data, tft_filter ); CALCLEN_OCTETSTRING( length, data, tos_traffic_class ); CALCLEN_OCTETSTRING( length, data, security_parameter_index ); CALCLEN_OCTETSTRING( length, data, flow_label ); CALCLEN_BASIC( length, data, flow_direction ); return length; } /* * * Fun: calcLengthGxMbsfnArea * * Desc: Calculate the length for GxMbsfnArea * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * MBSFN-Area ::= <AVP Header: 1694> * { MBSFN-Area-ID } * { Carrier-Frequency } * * [ AVP ] */ static uint32_t calcLengthGxMbsfnArea ( GxMbsfnArea *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, mbsfn_area_id ); CALCLEN_BASIC( length, data, carrier_frequency ); return length; } /* * * Fun: calcLengthGxEventReportIndication * * Desc: Calculate the length for GxEventReportIndication * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Event-Report-Indication ::= <AVP Header: 1033> * [ AN-Trusted ] * * [ Event-Trigger ] * [ User-CSG-Information ] * [ IP-CAN-Type ] * * 2 [ AN-GW-Address ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ 3GPP-SGSN-MCC-MNC ] * [ Framed-IP-Address ] * [ RAT-Type ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ Trace-Data ] * [ Trace-Reference ] * [ 3GPP2-BSID ] * [ 3GPP-MS-TimeZone ] * [ Routing-IP-Address ] * [ UE-Local-IP-Address ] * [ HeNB-Local-IP-Address ] * [ UDP-Source-Port ] * [ Presence-Reporting-Area-Information ] * * [ AVP ] */ static uint32_t calcLengthGxEventReportIndication ( GxEventReportIndication *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, an_trusted ); CALCLEN_LIST_BASIC( length, data, event_trigger ); CALCLEN_STRUCT( length, data, user_csg_information, calcLengthGxUserCsgInformation ); CALCLEN_BASIC( length, data, ip_can_type ); CALCLEN_LIST_BASIC( length, data, an_gw_address ); CALCLEN_OCTETSTRING( length, data, tgpp_sgsn_address ); CALCLEN_OCTETSTRING( length, data, tgpp_sgsn_ipv6_address ); CALCLEN_OCTETSTRING( length, data, tgpp_sgsn_mcc_mnc ); CALCLEN_OCTETSTRING( length, data, framed_ip_address ); CALCLEN_BASIC( length, data, rat_type ); CALCLEN_OCTETSTRING( length, data, rai ); CALCLEN_OCTETSTRING( length, data, tgpp_user_location_info ); CALCLEN_STRUCT( length, data, trace_data, calcLengthGxTraceData ); CALCLEN_OCTETSTRING( length, data, trace_reference ); CALCLEN_OCTETSTRING( length, data, tgpp2_bsid ); CALCLEN_OCTETSTRING( length, data, tgpp_ms_timezone ); CALCLEN_BASIC( length, data, routing_ip_address ); CALCLEN_BASIC( length, data, ue_local_ip_address ); CALCLEN_BASIC( length, data, henb_local_ip_address ); CALCLEN_BASIC( length, data, udp_source_port ); CALCLEN_STRUCT( length, data, presence_reporting_area_information, calcLengthGxPresenceReportingAreaInformation ); return length; } /* * * Fun: calcLengthGxTdfInformation * * Desc: Calculate the length for GxTdfInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * TDF-Information ::= <AVP Header: 1087> * [ TDF-Destination-Realm ] * [ TDF-Destination-Host ] * [ TDF-IP-Address ] */ static uint32_t calcLengthGxTdfInformation ( GxTdfInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, tdf_destination_realm ); CALCLEN_OCTETSTRING( length, data, tdf_destination_host ); CALCLEN_BASIC( length, data, tdf_ip_address ); return length; } /* * * Fun: calcLengthGxProxyInfo * * Desc: Calculate the length for GxProxyInfo * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Proxy-Info ::= <AVP Header: 284> * { Proxy-Host } * { Proxy-State } * * [ AVP ] */ static uint32_t calcLengthGxProxyInfo ( GxProxyInfo *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, proxy_host ); CALCLEN_OCTETSTRING( length, data, proxy_state ); return length; } /* * * Fun: calcLengthGxUsedServiceUnit * * Desc: Calculate the length for GxUsedServiceUnit * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Used-Service-Unit ::= <AVP Header: 446> * [ Reporting-Reason ] * [ Tariff-Change-Usage ] * [ CC-Time ] * [ CC-Money ] * [ CC-Total-Octets ] * [ CC-Input-Octets ] * [ CC-Output-Octets ] * [ CC-Service-Specific-Units ] * * [ Event-Charging-TimeStamp ] * * [ AVP ] */ static uint32_t calcLengthGxUsedServiceUnit ( GxUsedServiceUnit *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, reporting_reason ); CALCLEN_BASIC( length, data, tariff_change_usage ); CALCLEN_BASIC( length, data, cc_time ); CALCLEN_STRUCT( length, data, cc_money, calcLengthGxCcMoney ); CALCLEN_BASIC( length, data, cc_total_octets ); CALCLEN_BASIC( length, data, cc_input_octets ); CALCLEN_BASIC( length, data, cc_output_octets ); CALCLEN_BASIC( length, data, cc_service_specific_units ); CALCLEN_LIST_BASIC( length, data, event_charging_timestamp ); return length; } /* * * Fun: calcLengthGxChargingRuleInstall * * Desc: Calculate the length for GxChargingRuleInstall * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Install ::= <AVP Header: 1001> * * [ Charging-Rule-Definition ] * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * [ Bearer-Identifier ] * [ Monitoring-Flags ] * [ Rule-Activation-Time ] * [ Rule-Deactivation-Time ] * [ Resource-Allocation-Notification ] * [ Charging-Correlation-Indicator ] * [ IP-CAN-Type ] * * [ AVP ] */ static uint32_t calcLengthGxChargingRuleInstall ( GxChargingRuleInstall *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_LIST_STRUCT( length, data, charging_rule_definition, calcLengthGxChargingRuleDefinition ); CALCLEN_LIST_OCTETSTRING( length, data, charging_rule_name ); CALCLEN_LIST_OCTETSTRING( length, data, charging_rule_base_name ); CALCLEN_OCTETSTRING( length, data, bearer_identifier ); CALCLEN_BASIC( length, data, monitoring_flags ); CALCLEN_BASIC( length, data, rule_activation_time ); CALCLEN_BASIC( length, data, rule_deactivation_time ); CALCLEN_BASIC( length, data, resource_allocation_notification ); CALCLEN_BASIC( length, data, charging_correlation_indicator ); CALCLEN_BASIC( length, data, ip_can_type ); return length; } /* * * Fun: calcLengthGxChargingRuleDefinition * * Desc: Calculate the length for GxChargingRuleDefinition * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Definition ::= <AVP Header: 1003> * { Charging-Rule-Name } * [ Service-Identifier ] * [ Rating-Group ] * * [ Flow-Information ] * [ Default-Bearer-Indication ] * [ TDF-Application-Identifier ] * [ Flow-Status ] * [ QoS-Information ] * [ PS-to-CS-Session-Continuity ] * [ Reporting-Level ] * [ Online ] * [ Offline ] * [ Max-PLR-DL ] * [ Max-PLR-UL ] * [ Metering-Method ] * [ Precedence ] * [ AF-Charging-Identifier ] * * [ Flows ] * [ Monitoring-Key ] * [ Redirect-Information ] * [ Mute-Notification ] * [ AF-Signalling-Protocol ] * [ Sponsor-Identity ] * [ Application-Service-Provider-Identity ] * * [ Required-Access-Info ] * [ Sharing-Key-DL ] * [ Sharing-Key-UL ] * [ Traffic-Steering-Policy-Identifier-DL ] * [ Traffic-Steering-Policy-Identifier-UL ] * [ Content-Version ] * * [ AVP ] */ static uint32_t calcLengthGxChargingRuleDefinition ( GxChargingRuleDefinition *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, charging_rule_name ); CALCLEN_BASIC( length, data, service_identifier ); CALCLEN_BASIC( length, data, rating_group ); CALCLEN_LIST_STRUCT( length, data, flow_information, calcLengthGxFlowInformation ); CALCLEN_BASIC( length, data, default_bearer_indication ); CALCLEN_OCTETSTRING( length, data, tdf_application_identifier ); CALCLEN_BASIC( length, data, flow_status ); CALCLEN_STRUCT( length, data, qos_information, calcLengthGxQosInformation ); CALCLEN_BASIC( length, data, ps_to_cs_session_continuity ); CALCLEN_BASIC( length, data, reporting_level ); CALCLEN_BASIC( length, data, online ); CALCLEN_BASIC( length, data, offline ); CALCLEN_BASIC( length, data, max_plr_dl ); CALCLEN_BASIC( length, data, max_plr_ul ); CALCLEN_BASIC( length, data, metering_method ); CALCLEN_BASIC( length, data, precedence ); CALCLEN_OCTETSTRING( length, data, af_charging_identifier ); CALCLEN_LIST_STRUCT( length, data, flows, calcLengthGxFlows ); CALCLEN_OCTETSTRING( length, data, monitoring_key ); CALCLEN_STRUCT( length, data, redirect_information, calcLengthGxRedirectInformation ); CALCLEN_BASIC( length, data, mute_notification ); CALCLEN_BASIC( length, data, af_signalling_protocol ); CALCLEN_OCTETSTRING( length, data, sponsor_identity ); CALCLEN_OCTETSTRING( length, data, application_service_provider_identity ); CALCLEN_LIST_BASIC( length, data, required_access_info ); CALCLEN_BASIC( length, data, sharing_key_dl ); CALCLEN_BASIC( length, data, sharing_key_ul ); CALCLEN_OCTETSTRING( length, data, traffic_steering_policy_identifier_dl ); CALCLEN_OCTETSTRING( length, data, traffic_steering_policy_identifier_ul ); CALCLEN_BASIC( length, data, content_version ); return length; } /* * * Fun: calcLengthGxFinalUnitIndication * * Desc: Calculate the length for GxFinalUnitIndication * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Final-Unit-Indication ::= <AVP Header: 430> * { Final-Unit-Action } * * [ Restriction-Filter-Rule ] * * [ Filter-Id ] * [ Redirect-Server ] */ static uint32_t calcLengthGxFinalUnitIndication ( GxFinalUnitIndication *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, final_unit_action ); CALCLEN_LIST_OCTETSTRING( length, data, restriction_filter_rule ); CALCLEN_LIST_OCTETSTRING( length, data, filter_id ); CALCLEN_STRUCT( length, data, redirect_server, calcLengthGxRedirectServer ); return length; } /* * * Fun: calcLengthGxUnitValue * * Desc: Calculate the length for GxUnitValue * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Unit-Value ::= <AVP Header: 445> * { Value-Digits } * [ Exponent ] */ static uint32_t calcLengthGxUnitValue ( GxUnitValue *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, value_digits ); CALCLEN_BASIC( length, data, exponent ); return length; } /* * * Fun: calcLengthGxPresenceReportingAreaInformation * * Desc: Calculate the length for GxPresenceReportingAreaInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Presence-Reporting-Area-Information ::= <AVP Header: 2822> * [ Presence-Reporting-Area-Identifier ] * [ Presence-Reporting-Area-Status ] * [ Presence-Reporting-Area-Elements-List ] * [ Presence-Reporting-Area-Node ] * * [ AVP ] */ static uint32_t calcLengthGxPresenceReportingAreaInformation ( GxPresenceReportingAreaInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, presence_reporting_area_identifier ); CALCLEN_BASIC( length, data, presence_reporting_area_status ); CALCLEN_OCTETSTRING( length, data, presence_reporting_area_elements_list ); CALCLEN_BASIC( length, data, presence_reporting_area_node ); return length; } /* * * Fun: calcLengthGxConditionalApnAggregateMaxBitrate * * Desc: Calculate the length for GxConditionalApnAggregateMaxBitrate * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Conditional-APN-Aggregate-Max-Bitrate ::= <AVP Header: 2818> * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ IP-CAN-Type ] * * [ RAT-Type ] * * [ AVP ] */ static uint32_t calcLengthGxConditionalApnAggregateMaxBitrate ( GxConditionalApnAggregateMaxBitrate *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, apn_aggregate_max_bitrate_ul ); CALCLEN_BASIC( length, data, apn_aggregate_max_bitrate_dl ); CALCLEN_BASIC( length, data, extended_apn_ambr_ul ); CALCLEN_BASIC( length, data, extended_apn_ambr_dl ); CALCLEN_LIST_BASIC( length, data, ip_can_type ); CALCLEN_LIST_BASIC( length, data, rat_type ); return length; } /* * * Fun: calcLengthGxAccessNetworkChargingIdentifierGx * * Desc: Calculate the length for GxAccessNetworkChargingIdentifierGx * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Access-Network-Charging-Identifier-Gx ::= <AVP Header: 1022> * { Access-Network-Charging-Identifier-Value } * * [ Charging-Rule-Base-Name ] * * [ Charging-Rule-Name ] * [ IP-CAN-Session-Charging-Scope ] * * [ AVP ] */ static uint32_t calcLengthGxAccessNetworkChargingIdentifierGx ( GxAccessNetworkChargingIdentifierGx *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, access_network_charging_identifier_value ); CALCLEN_LIST_OCTETSTRING( length, data, charging_rule_base_name ); CALCLEN_LIST_OCTETSTRING( length, data, charging_rule_name ); CALCLEN_BASIC( length, data, ip_can_session_charging_scope ); return length; } /* * * Fun: calcLengthGxOcOlr * * Desc: Calculate the length for GxOcOlr * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * OC-OLR ::= <AVP Header: 623> * < OC-Sequence-Number > * < OC-Report-Type > * [ OC-Reduction-Percentage ] * [ OC-Validity-Duration ] * * [ AVP ] */ static uint32_t calcLengthGxOcOlr ( GxOcOlr *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, oc_sequence_number ); CALCLEN_BASIC( length, data, oc_report_type ); CALCLEN_BASIC( length, data, oc_reduction_percentage ); CALCLEN_BASIC( length, data, oc_validity_duration ); return length; } /* * * Fun: calcLengthGxRoutingRuleInstall * * Desc: Calculate the length for GxRoutingRuleInstall * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Install ::= <AVP Header: 1081> * * [ Routing-Rule-Definition ] * * [ AVP ] */ static uint32_t calcLengthGxRoutingRuleInstall ( GxRoutingRuleInstall *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_LIST_STRUCT( length, data, routing_rule_definition, calcLengthGxRoutingRuleDefinition ); return length; } /* * * Fun: calcLengthGxTraceData * * Desc: Calculate the length for GxTraceData * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Trace-Data ::= <AVP Header: 1458> * { Trace-Reference } * { Trace-Depth } * { Trace-NE-Type-List } * [ Trace-Interface-List ] * { Trace-Event-List } * [ OMC-Id ] * { Trace-Collection-Entity } * [ MDT-Configuration ] * * [ AVP ] */ static uint32_t calcLengthGxTraceData ( GxTraceData *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, trace_reference ); CALCLEN_BASIC( length, data, trace_depth ); CALCLEN_OCTETSTRING( length, data, trace_ne_type_list ); CALCLEN_OCTETSTRING( length, data, trace_interface_list ); CALCLEN_OCTETSTRING( length, data, trace_event_list ); CALCLEN_OCTETSTRING( length, data, omc_id ); CALCLEN_BASIC( length, data, trace_collection_entity ); CALCLEN_STRUCT( length, data, mdt_configuration, calcLengthGxMdtConfiguration ); return length; } /* * * Fun: calcLengthGxRoutingRuleDefinition * * Desc: Calculate the length for GxRoutingRuleDefinition * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Definition ::= <AVP Header: 1076> * { Routing-Rule-Identifier } * * [ Routing-Filter ] * [ Precedence ] * [ Routing-IP-Address ] * [ IP-CAN-Type ] * * [ AVP ] */ static uint32_t calcLengthGxRoutingRuleDefinition ( GxRoutingRuleDefinition *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, routing_rule_identifier ); CALCLEN_LIST_STRUCT( length, data, routing_filter, calcLengthGxRoutingFilter ); CALCLEN_BASIC( length, data, precedence ); CALCLEN_BASIC( length, data, routing_ip_address ); CALCLEN_BASIC( length, data, ip_can_type ); return length; } /* * * Fun: calcLengthGxMdtConfiguration * * Desc: Calculate the length for GxMdtConfiguration * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * MDT-Configuration ::= <AVP Header: 1622> * { Job-Type } * [ Area-Scope ] * [ List-Of-Measurements ] * [ Reporting-Trigger ] * [ Report-Interval ] * [ Report-Amount ] * [ Event-Threshold-RSRP ] * [ Event-Threshold-RSRQ ] * [ Logging-Interval ] * [ Logging-Duration ] * [ Measurement-Period-LTE ] * [ Measurement-Period-UMTS ] * [ Collection-Period-RRM-LTE ] * [ Collection-Period-RRM-UMTS ] * [ Positioning-Method ] * [ Measurement-Quantity ] * [ Event-Threshold-Event-1F ] * [ Event-Threshold-Event-1I ] * * [ MDT-Allowed-PLMN-Id ] * * [ MBSFN-Area ] * * [ AVP ] */ static uint32_t calcLengthGxMdtConfiguration ( GxMdtConfiguration *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, job_type ); CALCLEN_STRUCT( length, data, area_scope, calcLengthGxAreaScope ); CALCLEN_BASIC( length, data, list_of_measurements ); CALCLEN_BASIC( length, data, reporting_trigger ); CALCLEN_BASIC( length, data, report_interval ); CALCLEN_BASIC( length, data, report_amount ); CALCLEN_BASIC( length, data, event_threshold_rsrp ); CALCLEN_BASIC( length, data, event_threshold_rsrq ); CALCLEN_BASIC( length, data, logging_interval ); CALCLEN_BASIC( length, data, logging_duration ); CALCLEN_BASIC( length, data, measurement_period_lte ); CALCLEN_BASIC( length, data, measurement_period_umts ); CALCLEN_BASIC( length, data, collection_period_rrm_lte ); CALCLEN_BASIC( length, data, collection_period_rrm_umts ); CALCLEN_OCTETSTRING( length, data, positioning_method ); CALCLEN_OCTETSTRING( length, data, measurement_quantity ); CALCLEN_BASIC( length, data, event_threshold_event_1f ); CALCLEN_BASIC( length, data, event_threshold_event_1i ); CALCLEN_LIST_OCTETSTRING( length, data, mdt_allowed_plmn_id ); CALCLEN_LIST_STRUCT( length, data, mbsfn_area, calcLengthGxMbsfnArea ); return length; } /* * * Fun: calcLengthGxChargingRuleRemove * * Desc: Calculate the length for GxChargingRuleRemove * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Remove ::= <AVP Header: 1002> * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * * [ Required-Access-Info ] * [ Resource-Release-Notification ] * * [ AVP ] */ static uint32_t calcLengthGxChargingRuleRemove ( GxChargingRuleRemove *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_LIST_OCTETSTRING( length, data, charging_rule_name ); CALCLEN_LIST_OCTETSTRING( length, data, charging_rule_base_name ); CALCLEN_LIST_BASIC( length, data, required_access_info ); CALCLEN_BASIC( length, data, resource_release_notification ); return length; } /* * * Fun: calcLengthGxAllocationRetentionPriority * * Desc: Calculate the length for GxAllocationRetentionPriority * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Allocation-Retention-Priority ::= <AVP Header: 1034> * { Priority-Level } * [ Pre-emption-Capability ] * [ Pre-emption-Vulnerability ] */ static uint32_t calcLengthGxAllocationRetentionPriority ( GxAllocationRetentionPriority *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, priority_level ); CALCLEN_BASIC( length, data, pre_emption_capability ); CALCLEN_BASIC( length, data, pre_emption_vulnerability ); return length; } /* * * Fun: calcLengthGxDefaultEpsBearerQos * * Desc: Calculate the length for GxDefaultEpsBearerQos * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Default-EPS-Bearer-QoS ::= <AVP Header: 1049> * [ QoS-Class-Identifier ] * [ Allocation-Retention-Priority ] * * [ AVP ] */ static uint32_t calcLengthGxDefaultEpsBearerQos ( GxDefaultEpsBearerQos *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, qos_class_identifier ); CALCLEN_STRUCT( length, data, allocation_retention_priority, calcLengthGxAllocationRetentionPriority ); return length; } /* * * Fun: calcLengthGxRoutingRuleReport * * Desc: Calculate the length for GxRoutingRuleReport * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Report ::= <AVP Header: 2835> * * [ Routing-Rule-Identifier ] * [ PCC-Rule-Status ] * [ Routing-Rule-Failure-Code ] * * [ AVP ] */ static uint32_t calcLengthGxRoutingRuleReport ( GxRoutingRuleReport *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_LIST_OCTETSTRING( length, data, routing_rule_identifier ); CALCLEN_BASIC( length, data, pcc_rule_status ); CALCLEN_BASIC( length, data, routing_rule_failure_code ); return length; } /* * * Fun: calcLengthGxUserEquipmentInfo * * Desc: Calculate the length for GxUserEquipmentInfo * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * User-Equipment-Info ::= <AVP Header: 458> * { User-Equipment-Info-Type } * { User-Equipment-Info-Value } */ static uint32_t calcLengthGxUserEquipmentInfo ( GxUserEquipmentInfo *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, user_equipment_info_type ); CALCLEN_OCTETSTRING( length, data, user_equipment_info_value ); return length; } /* * * Fun: calcLengthGxSupportedFeatures * * Desc: Calculate the length for GxSupportedFeatures * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Supported-Features ::= <AVP Header: 628> * { Vendor-Id } * { Feature-List-ID } * { Feature-List } * * [ AVP ] */ static uint32_t calcLengthGxSupportedFeatures ( GxSupportedFeatures *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, vendor_id ); CALCLEN_BASIC( length, data, feature_list_id ); CALCLEN_BASIC( length, data, feature_list ); return length; } /* * * Fun: calcLengthGxFixedUserLocationInfo * * Desc: Calculate the length for GxFixedUserLocationInfo * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Fixed-User-Location-Info ::= <AVP Header: 2825> * [ SSID ] * [ BSSID ] * [ Logical-Access-Id ] * [ Physical-Access-Id ] * * [ AVP ] */ static uint32_t calcLengthGxFixedUserLocationInfo ( GxFixedUserLocationInfo *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, ssid ); CALCLEN_OCTETSTRING( length, data, bssid ); CALCLEN_OCTETSTRING( length, data, logical_access_id ); CALCLEN_OCTETSTRING( length, data, physical_access_id ); return length; } /* * * Fun: calcLengthGxDefaultQosInformation * * Desc: Calculate the length for GxDefaultQosInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Default-QoS-Information ::= <AVP Header: 2816> * [ QoS-Class-Identifier ] * [ Max-Requested-Bandwidth-UL ] * [ Max-Requested-Bandwidth-DL ] * [ Default-QoS-Name ] * * [ AVP ] */ static uint32_t calcLengthGxDefaultQosInformation ( GxDefaultQosInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, qos_class_identifier ); CALCLEN_BASIC( length, data, max_requested_bandwidth_ul ); CALCLEN_BASIC( length, data, max_requested_bandwidth_dl ); CALCLEN_OCTETSTRING( length, data, default_qos_name ); return length; } /* * * Fun: calcLengthGxLoad * * Desc: Calculate the length for GxLoad * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Load ::= <AVP Header: 650> * [ Load-Type ] * [ Load-Value ] * [ SourceID ] * * [ AVP ] */ static uint32_t calcLengthGxLoad ( GxLoad *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, load_type ); CALCLEN_BASIC( length, data, load_value ); CALCLEN_OCTETSTRING( length, data, sourceid ); return length; } /* * * Fun: calcLengthGxRedirectServer * * Desc: Calculate the length for GxRedirectServer * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Redirect-Server ::= <AVP Header: 434> * { Redirect-Address-Type } * { Redirect-Server-Address } */ static uint32_t calcLengthGxRedirectServer ( GxRedirectServer *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, redirect_address_type ); CALCLEN_OCTETSTRING( length, data, redirect_server_address ); return length; } /* * * Fun: calcLengthGxOcSupportedFeatures * * Desc: Calculate the length for GxOcSupportedFeatures * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * OC-Supported-Features ::= <AVP Header: 621> * [ OC-Feature-Vector ] * * [ AVP ] */ static uint32_t calcLengthGxOcSupportedFeatures ( GxOcSupportedFeatures *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, oc_feature_vector ); return length; } /* * * Fun: calcLengthGxPacketFilterInformation * * Desc: Calculate the length for GxPacketFilterInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Packet-Filter-Information ::= <AVP Header: 1061> * [ Packet-Filter-Identifier ] * [ Precedence ] * [ Packet-Filter-Content ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * * [ AVP ] */ static uint32_t calcLengthGxPacketFilterInformation ( GxPacketFilterInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, packet_filter_identifier ); CALCLEN_BASIC( length, data, precedence ); CALCLEN_OCTETSTRING( length, data, packet_filter_content ); CALCLEN_OCTETSTRING( length, data, tos_traffic_class ); CALCLEN_OCTETSTRING( length, data, security_parameter_index ); CALCLEN_OCTETSTRING( length, data, flow_label ); CALCLEN_BASIC( length, data, flow_direction ); return length; } /* * * Fun: calcLengthGxSubscriptionId * * Desc: Calculate the length for GxSubscriptionId * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Subscription-Id ::= <AVP Header: 443> * [ Subscription-Id-Type ] * [ Subscription-Id-Data ] */ static uint32_t calcLengthGxSubscriptionId ( GxSubscriptionId *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, subscription_id_type ); CALCLEN_OCTETSTRING( length, data, subscription_id_data ); return length; } /* * * Fun: calcLengthGxChargingInformation * * Desc: Calculate the length for GxChargingInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Information ::= <AVP Header: 618> * [ Primary-Event-Charging-Function-Name ] * [ Secondary-Event-Charging-Function-Name ] * [ Primary-Charging-Collection-Function-Name ] * [ Secondary-Charging-Collection-Function-Name ] * * [ AVP ] */ static uint32_t calcLengthGxChargingInformation ( GxChargingInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, primary_event_charging_function_name ); CALCLEN_OCTETSTRING( length, data, secondary_event_charging_function_name ); CALCLEN_OCTETSTRING( length, data, primary_charging_collection_function_name ); CALCLEN_OCTETSTRING( length, data, secondary_charging_collection_function_name ); return length; } /* * * Fun: calcLengthGxUsageMonitoringInformation * * Desc: Calculate the length for GxUsageMonitoringInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Usage-Monitoring-Information ::= <AVP Header: 1067> * [ Monitoring-Key ] * * 2 [ Granted-Service-Unit ] * * 2 [ Used-Service-Unit ] * [ Quota-Consumption-Time ] * [ Usage-Monitoring-Level ] * [ Usage-Monitoring-Report ] * [ Usage-Monitoring-Support ] * * [ AVP ] */ static uint32_t calcLengthGxUsageMonitoringInformation ( GxUsageMonitoringInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, monitoring_key ); CALCLEN_LIST_STRUCT( length, data, granted_service_unit, calcLengthGxGrantedServiceUnit ); CALCLEN_LIST_STRUCT( length, data, used_service_unit, calcLengthGxUsedServiceUnit ); CALCLEN_BASIC( length, data, quota_consumption_time ); CALCLEN_BASIC( length, data, usage_monitoring_level ); CALCLEN_BASIC( length, data, usage_monitoring_report ); CALCLEN_BASIC( length, data, usage_monitoring_support ); return length; } /* * * Fun: calcLengthGxChargingRuleReport * * Desc: Calculate the length for GxChargingRuleReport * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Report ::= <AVP Header: 1018> * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * [ Bearer-Identifier ] * [ PCC-Rule-Status ] * [ Rule-Failure-Code ] * [ Final-Unit-Indication ] * * [ RAN-NAS-Release-Cause ] * * [ Content-Version ] * * [ AVP ] */ static uint32_t calcLengthGxChargingRuleReport ( GxChargingRuleReport *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_LIST_OCTETSTRING( length, data, charging_rule_name ); CALCLEN_LIST_OCTETSTRING( length, data, charging_rule_base_name ); CALCLEN_OCTETSTRING( length, data, bearer_identifier ); CALCLEN_BASIC( length, data, pcc_rule_status ); CALCLEN_BASIC( length, data, rule_failure_code ); CALCLEN_STRUCT( length, data, final_unit_indication, calcLengthGxFinalUnitIndication ); CALCLEN_LIST_OCTETSTRING( length, data, ran_nas_release_cause ); CALCLEN_LIST_BASIC( length, data, content_version ); return length; } /* * * Fun: calcLengthGxRedirectInformation * * Desc: Calculate the length for GxRedirectInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Redirect-Information ::= <AVP Header: 1085> * [ Redirect-Support ] * [ Redirect-Address-Type ] * [ Redirect-Server-Address ] * * [ AVP ] */ static uint32_t calcLengthGxRedirectInformation ( GxRedirectInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, redirect_support ); CALCLEN_BASIC( length, data, redirect_address_type ); CALCLEN_OCTETSTRING( length, data, redirect_server_address ); return length; } /* * * Fun: calcLengthGxFailedAvp * * Desc: Calculate the length for GxFailedAvp * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Failed-AVP ::= <AVP Header: 279> * 1* { AVP } */ static uint32_t calcLengthGxFailedAvp ( GxFailedAvp *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); return length; } /* * * Fun: calcLengthGxRoutingRuleRemove * * Desc: Calculate the length for GxRoutingRuleRemove * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Remove ::= <AVP Header: 1075> * * [ Routing-Rule-Identifier ] * * [ AVP ] */ static uint32_t calcLengthGxRoutingRuleRemove ( GxRoutingRuleRemove *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_LIST_OCTETSTRING( length, data, routing_rule_identifier ); return length; } /* * * Fun: calcLengthGxRoutingFilter * * Desc: Calculate the length for GxRoutingFilter * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Filter ::= <AVP Header: 1078> * { Flow-Description } * { Flow-Direction } * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * * [ AVP ] */ static uint32_t calcLengthGxRoutingFilter ( GxRoutingFilter *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, flow_description ); CALCLEN_BASIC( length, data, flow_direction ); CALCLEN_OCTETSTRING( length, data, tos_traffic_class ); CALCLEN_OCTETSTRING( length, data, security_parameter_index ); CALCLEN_OCTETSTRING( length, data, flow_label ); return length; } /* * * Fun: calcLengthGxCoaInformation * * Desc: Calculate the length for GxCoaInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * CoA-Information ::= <AVP Header: 1039> * { Tunnel-Information } * { CoA-IP-Address } * * [ AVP ] */ static uint32_t calcLengthGxCoaInformation ( GxCoaInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_STRUCT( length, data, tunnel_information, calcLengthGxTunnelInformation ); CALCLEN_BASIC( length, data, coa_ip_address ); return length; } /* * * Fun: calcLengthGxGrantedServiceUnit * * Desc: Calculate the length for GxGrantedServiceUnit * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Granted-Service-Unit ::= <AVP Header: 431> * [ Tariff-Time-Change ] * [ CC-Time ] * [ CC-Money ] * [ CC-Total-Octets ] * [ CC-Input-Octets ] * [ CC-Output-Octets ] * [ CC-Service-Specific-Units ] * * [ AVP ] */ static uint32_t calcLengthGxGrantedServiceUnit ( GxGrantedServiceUnit *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, tariff_time_change ); CALCLEN_BASIC( length, data, cc_time ); CALCLEN_STRUCT( length, data, cc_money, calcLengthGxCcMoney ); CALCLEN_BASIC( length, data, cc_total_octets ); CALCLEN_BASIC( length, data, cc_input_octets ); CALCLEN_BASIC( length, data, cc_output_octets ); CALCLEN_BASIC( length, data, cc_service_specific_units ); return length; } /* * * Fun: calcLengthGxCcMoney * * Desc: Calculate the length for GxCcMoney * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * CC-Money ::= <AVP Header: 413> * { Unit-Value } * [ Currency-Code ] */ static uint32_t calcLengthGxCcMoney ( GxCcMoney *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_STRUCT( length, data, unit_value, calcLengthGxUnitValue ); CALCLEN_BASIC( length, data, currency_code ); return length; } /* * * Fun: calcLengthGxApplicationDetectionInformation * * Desc: Calculate the length for GxApplicationDetectionInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Application-Detection-Information ::= <AVP Header: 1098> * { TDF-Application-Identifier } * [ TDF-Application-Instance-Identifier ] * * [ Flow-Information ] * * [ AVP ] */ static uint32_t calcLengthGxApplicationDetectionInformation ( GxApplicationDetectionInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_OCTETSTRING( length, data, tdf_application_identifier ); CALCLEN_OCTETSTRING( length, data, tdf_application_instance_identifier ); CALCLEN_LIST_STRUCT( length, data, flow_information, calcLengthGxFlowInformation ); return length; } /* * * Fun: calcLengthGxFlows * * Desc: Calculate the length for GxFlows * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Flows ::= <AVP Header: 510> * { Media-Component-Number } * * [ Flow-Number ] * * [ Content-Version ] * [ Final-Unit-Action ] * [ Media-Component-Status ] * * [ AVP ] */ static uint32_t calcLengthGxFlows ( GxFlows *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, media_component_number ); CALCLEN_LIST_BASIC( length, data, flow_number ); CALCLEN_LIST_BASIC( length, data, content_version ); CALCLEN_BASIC( length, data, final_unit_action ); CALCLEN_BASIC( length, data, media_component_status ); return length; } /* * * Fun: calcLengthGxUserCsgInformation * * Desc: Calculate the length for GxUserCsgInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * User-CSG-Information ::= <AVP Header: 2319> * { CSG-Id } * { CSG-Access-Mode } * [ CSG-Membership-Indication ] */ static uint32_t calcLengthGxUserCsgInformation ( GxUserCsgInformation *data ) { uint32_t length = 0; CALCLEN_PRESENCE( length, data, presence ); CALCLEN_BASIC( length, data, csg_id ); CALCLEN_BASIC( length, data, csg_access_mode ); CALCLEN_BASIC( length, data, csg_membership_indication ); return length; } /*******************************************************************************/ /* structure pack functions */ /*******************************************************************************/ /* * * Fun: packGxExperimentalResult * * Desc: Pack the contents of the GxExperimentalResult structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Experimental-Result ::= <AVP Header: 297> * { Vendor-Id } * { Experimental-Result-Code } */ static int packGxExperimentalResult ( GxExperimentalResult *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, vendor_id, buf, buflen, offset ); PACK_BASIC( data, experimental_result_code, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxPraRemove * * Desc: Pack the contents of the GxPraRemove structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * PRA-Remove ::= <AVP Header: 2846> * * [ Presence-Reporting-Area-Identifier ] * * [ AVP ] */ static int packGxPraRemove ( GxPraRemove *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, presence_reporting_area_identifier, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxQosInformation * * Desc: Pack the contents of the GxQosInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * QoS-Information ::= <AVP Header: 1016> * [ QoS-Class-Identifier ] * [ Max-Requested-Bandwidth-UL ] * [ Max-Requested-Bandwidth-DL ] * [ Extended-Max-Requested-BW-UL ] * [ Extended-Max-Requested-BW-DL ] * [ Guaranteed-Bitrate-UL ] * [ Guaranteed-Bitrate-DL ] * [ Extended-GBR-UL ] * [ Extended-GBR-DL ] * [ Bearer-Identifier ] * [ Allocation-Retention-Priority ] * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ Conditional-APN-Aggregate-Max-Bitrate ] * * [ AVP ] */ static int packGxQosInformation ( GxQosInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, qos_class_identifier, buf, buflen, offset ); PACK_BASIC( data, max_requested_bandwidth_ul, buf, buflen, offset ); PACK_BASIC( data, max_requested_bandwidth_dl, buf, buflen, offset ); PACK_BASIC( data, extended_max_requested_bw_ul, buf, buflen, offset ); PACK_BASIC( data, extended_max_requested_bw_dl, buf, buflen, offset ); PACK_BASIC( data, guaranteed_bitrate_ul, buf, buflen, offset ); PACK_BASIC( data, guaranteed_bitrate_dl, buf, buflen, offset ); PACK_BASIC( data, extended_gbr_ul, buf, buflen, offset ); PACK_BASIC( data, extended_gbr_dl, buf, buflen, offset ); PACK_OCTETSTRING( data, bearer_identifier, buf, buflen, offset ); PACK_STRUCT( data, allocation_retention_priority, buf, buflen, offset, packGxAllocationRetentionPriority ); PACK_BASIC( data, apn_aggregate_max_bitrate_ul, buf, buflen, offset ); PACK_BASIC( data, apn_aggregate_max_bitrate_dl, buf, buflen, offset ); PACK_BASIC( data, extended_apn_ambr_ul, buf, buflen, offset ); PACK_BASIC( data, extended_apn_ambr_dl, buf, buflen, offset ); PACK_LIST_STRUCT( data, conditional_apn_aggregate_max_bitrate, buf, buflen, offset, packGxConditionalApnAggregateMaxBitrate ); return *offset <= buflen; } /* * * Fun: packGxConditionalPolicyInformation * * Desc: Pack the contents of the GxConditionalPolicyInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Conditional-Policy-Information ::= <AVP Header: 2840> * [ Execution-Time ] * [ Default-EPS-Bearer-QoS ] * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ Conditional-APN-Aggregate-Max-Bitrate ] * * [ AVP ] */ static int packGxConditionalPolicyInformation ( GxConditionalPolicyInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, execution_time, buf, buflen, offset ); PACK_STRUCT( data, default_eps_bearer_qos, buf, buflen, offset, packGxDefaultEpsBearerQos ); PACK_BASIC( data, apn_aggregate_max_bitrate_ul, buf, buflen, offset ); PACK_BASIC( data, apn_aggregate_max_bitrate_dl, buf, buflen, offset ); PACK_BASIC( data, extended_apn_ambr_ul, buf, buflen, offset ); PACK_BASIC( data, extended_apn_ambr_dl, buf, buflen, offset ); PACK_LIST_STRUCT( data, conditional_apn_aggregate_max_bitrate, buf, buflen, offset, packGxConditionalApnAggregateMaxBitrate ); return *offset <= buflen; } /* * * Fun: packGxPraInstall * * Desc: Pack the contents of the GxPraInstall structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * PRA-Install ::= <AVP Header: 2845> * * [ Presence-Reporting-Area-Information ] * * [ AVP ] */ static int packGxPraInstall ( GxPraInstall *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_LIST_STRUCT( data, presence_reporting_area_information, buf, buflen, offset, packGxPresenceReportingAreaInformation ); return *offset <= buflen; } /* * * Fun: packGxAreaScope * * Desc: Pack the contents of the GxAreaScope structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Area-Scope ::= <AVP Header: 1624> * * [ Cell-Global-Identity ] * * [ E-UTRAN-Cell-Global-Identity ] * * [ Routing-Area-Identity ] * * [ Location-Area-Identity ] * * [ Tracking-Area-Identity ] * * [ AVP ] */ static int packGxAreaScope ( GxAreaScope *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, cell_global_identity, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, e_utran_cell_global_identity, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, routing_area_identity, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, location_area_identity, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, tracking_area_identity, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxFlowInformation * * Desc: Pack the contents of the GxFlowInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Flow-Information ::= <AVP Header: 1058> * [ Flow-Description ] * [ Packet-Filter-Identifier ] * [ Packet-Filter-Usage ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * [ Routing-Rule-Identifier ] * * [ AVP ] */ static int packGxFlowInformation ( GxFlowInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, flow_description, buf, buflen, offset ); PACK_OCTETSTRING( data, packet_filter_identifier, buf, buflen, offset ); PACK_BASIC( data, packet_filter_usage, buf, buflen, offset ); PACK_OCTETSTRING( data, tos_traffic_class, buf, buflen, offset ); PACK_OCTETSTRING( data, security_parameter_index, buf, buflen, offset ); PACK_OCTETSTRING( data, flow_label, buf, buflen, offset ); PACK_BASIC( data, flow_direction, buf, buflen, offset ); PACK_OCTETSTRING( data, routing_rule_identifier, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxTunnelInformation * * Desc: Pack the contents of the GxTunnelInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Tunnel-Information ::= <AVP Header: 1038> * [ Tunnel-Header-Length ] * [ Tunnel-Header-Filter ] */ static int packGxTunnelInformation ( GxTunnelInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, tunnel_header_length, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, tunnel_header_filter, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxTftPacketFilterInformation * * Desc: Pack the contents of the GxTftPacketFilterInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * TFT-Packet-Filter-Information ::= <AVP Header: 1013> * [ Precedence ] * [ TFT-Filter ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * * [ AVP ] */ static int packGxTftPacketFilterInformation ( GxTftPacketFilterInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, precedence, buf, buflen, offset ); PACK_OCTETSTRING( data, tft_filter, buf, buflen, offset ); PACK_OCTETSTRING( data, tos_traffic_class, buf, buflen, offset ); PACK_OCTETSTRING( data, security_parameter_index, buf, buflen, offset ); PACK_OCTETSTRING( data, flow_label, buf, buflen, offset ); PACK_BASIC( data, flow_direction, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxMbsfnArea * * Desc: Pack the contents of the GxMbsfnArea structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * MBSFN-Area ::= <AVP Header: 1694> * { MBSFN-Area-ID } * { Carrier-Frequency } * * [ AVP ] */ static int packGxMbsfnArea ( GxMbsfnArea *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, mbsfn_area_id, buf, buflen, offset ); PACK_BASIC( data, carrier_frequency, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxEventReportIndication * * Desc: Pack the contents of the GxEventReportIndication structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Event-Report-Indication ::= <AVP Header: 1033> * [ AN-Trusted ] * * [ Event-Trigger ] * [ User-CSG-Information ] * [ IP-CAN-Type ] * * 2 [ AN-GW-Address ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ 3GPP-SGSN-MCC-MNC ] * [ Framed-IP-Address ] * [ RAT-Type ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ Trace-Data ] * [ Trace-Reference ] * [ 3GPP2-BSID ] * [ 3GPP-MS-TimeZone ] * [ Routing-IP-Address ] * [ UE-Local-IP-Address ] * [ HeNB-Local-IP-Address ] * [ UDP-Source-Port ] * [ Presence-Reporting-Area-Information ] * * [ AVP ] */ static int packGxEventReportIndication ( GxEventReportIndication *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, an_trusted, buf, buflen, offset ); PACK_LIST_BASIC( data, event_trigger, buf, buflen, offset ); PACK_STRUCT( data, user_csg_information, buf, buflen, offset, packGxUserCsgInformation ); PACK_BASIC( data, ip_can_type, buf, buflen, offset ); PACK_LIST_BASIC( data, an_gw_address, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_sgsn_address, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_sgsn_ipv6_address, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_sgsn_mcc_mnc, buf, buflen, offset ); PACK_OCTETSTRING( data, framed_ip_address, buf, buflen, offset ); PACK_BASIC( data, rat_type, buf, buflen, offset ); PACK_OCTETSTRING( data, rai, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_user_location_info, buf, buflen, offset ); PACK_STRUCT( data, trace_data, buf, buflen, offset, packGxTraceData ); PACK_OCTETSTRING( data, trace_reference, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp2_bsid, buf, buflen, offset ); PACK_OCTETSTRING( data, tgpp_ms_timezone, buf, buflen, offset ); PACK_BASIC( data, routing_ip_address, buf, buflen, offset ); PACK_BASIC( data, ue_local_ip_address, buf, buflen, offset ); PACK_BASIC( data, henb_local_ip_address, buf, buflen, offset ); PACK_BASIC( data, udp_source_port, buf, buflen, offset ); PACK_STRUCT( data, presence_reporting_area_information, buf, buflen, offset, packGxPresenceReportingAreaInformation ); return *offset <= buflen; } /* * * Fun: packGxTdfInformation * * Desc: Pack the contents of the GxTdfInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * TDF-Information ::= <AVP Header: 1087> * [ TDF-Destination-Realm ] * [ TDF-Destination-Host ] * [ TDF-IP-Address ] */ static int packGxTdfInformation ( GxTdfInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, tdf_destination_realm, buf, buflen, offset ); PACK_OCTETSTRING( data, tdf_destination_host, buf, buflen, offset ); PACK_BASIC( data, tdf_ip_address, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxProxyInfo * * Desc: Pack the contents of the GxProxyInfo structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Proxy-Info ::= <AVP Header: 284> * { Proxy-Host } * { Proxy-State } * * [ AVP ] */ static int packGxProxyInfo ( GxProxyInfo *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, proxy_host, buf, buflen, offset ); PACK_OCTETSTRING( data, proxy_state, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxUsedServiceUnit * * Desc: Pack the contents of the GxUsedServiceUnit structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Used-Service-Unit ::= <AVP Header: 446> * [ Reporting-Reason ] * [ Tariff-Change-Usage ] * [ CC-Time ] * [ CC-Money ] * [ CC-Total-Octets ] * [ CC-Input-Octets ] * [ CC-Output-Octets ] * [ CC-Service-Specific-Units ] * * [ Event-Charging-TimeStamp ] * * [ AVP ] */ static int packGxUsedServiceUnit ( GxUsedServiceUnit *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, reporting_reason, buf, buflen, offset ); PACK_BASIC( data, tariff_change_usage, buf, buflen, offset ); PACK_BASIC( data, cc_time, buf, buflen, offset ); PACK_STRUCT( data, cc_money, buf, buflen, offset, packGxCcMoney ); PACK_BASIC( data, cc_total_octets, buf, buflen, offset ); PACK_BASIC( data, cc_input_octets, buf, buflen, offset ); PACK_BASIC( data, cc_output_octets, buf, buflen, offset ); PACK_BASIC( data, cc_service_specific_units, buf, buflen, offset ); PACK_LIST_BASIC( data, event_charging_timestamp, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxChargingRuleInstall * * Desc: Pack the contents of the GxChargingRuleInstall structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Install ::= <AVP Header: 1001> * * [ Charging-Rule-Definition ] * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * [ Bearer-Identifier ] * [ Monitoring-Flags ] * [ Rule-Activation-Time ] * [ Rule-Deactivation-Time ] * [ Resource-Allocation-Notification ] * [ Charging-Correlation-Indicator ] * [ IP-CAN-Type ] * * [ AVP ] */ static int packGxChargingRuleInstall ( GxChargingRuleInstall *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_LIST_STRUCT( data, charging_rule_definition, buf, buflen, offset, packGxChargingRuleDefinition ); PACK_LIST_OCTETSTRING( data, charging_rule_name, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, charging_rule_base_name, buf, buflen, offset ); PACK_OCTETSTRING( data, bearer_identifier, buf, buflen, offset ); PACK_BASIC( data, monitoring_flags, buf, buflen, offset ); PACK_BASIC( data, rule_activation_time, buf, buflen, offset ); PACK_BASIC( data, rule_deactivation_time, buf, buflen, offset ); PACK_BASIC( data, resource_allocation_notification, buf, buflen, offset ); PACK_BASIC( data, charging_correlation_indicator, buf, buflen, offset ); PACK_BASIC( data, ip_can_type, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxChargingRuleDefinition * * Desc: Pack the contents of the GxChargingRuleDefinition structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Definition ::= <AVP Header: 1003> * { Charging-Rule-Name } * [ Service-Identifier ] * [ Rating-Group ] * * [ Flow-Information ] * [ Default-Bearer-Indication ] * [ TDF-Application-Identifier ] * [ Flow-Status ] * [ QoS-Information ] * [ PS-to-CS-Session-Continuity ] * [ Reporting-Level ] * [ Online ] * [ Offline ] * [ Max-PLR-DL ] * [ Max-PLR-UL ] * [ Metering-Method ] * [ Precedence ] * [ AF-Charging-Identifier ] * * [ Flows ] * [ Monitoring-Key ] * [ Redirect-Information ] * [ Mute-Notification ] * [ AF-Signalling-Protocol ] * [ Sponsor-Identity ] * [ Application-Service-Provider-Identity ] * * [ Required-Access-Info ] * [ Sharing-Key-DL ] * [ Sharing-Key-UL ] * [ Traffic-Steering-Policy-Identifier-DL ] * [ Traffic-Steering-Policy-Identifier-UL ] * [ Content-Version ] * * [ AVP ] */ static int packGxChargingRuleDefinition ( GxChargingRuleDefinition *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, charging_rule_name, buf, buflen, offset ); PACK_BASIC( data, service_identifier, buf, buflen, offset ); PACK_BASIC( data, rating_group, buf, buflen, offset ); PACK_LIST_STRUCT( data, flow_information, buf, buflen, offset, packGxFlowInformation ); PACK_BASIC( data, default_bearer_indication, buf, buflen, offset ); PACK_OCTETSTRING( data, tdf_application_identifier, buf, buflen, offset ); PACK_BASIC( data, flow_status, buf, buflen, offset ); PACK_STRUCT( data, qos_information, buf, buflen, offset, packGxQosInformation ); PACK_BASIC( data, ps_to_cs_session_continuity, buf, buflen, offset ); PACK_BASIC( data, reporting_level, buf, buflen, offset ); PACK_BASIC( data, online, buf, buflen, offset ); PACK_BASIC( data, offline, buf, buflen, offset ); PACK_BASIC( data, max_plr_dl, buf, buflen, offset ); PACK_BASIC( data, max_plr_ul, buf, buflen, offset ); PACK_BASIC( data, metering_method, buf, buflen, offset ); PACK_BASIC( data, precedence, buf, buflen, offset ); PACK_OCTETSTRING( data, af_charging_identifier, buf, buflen, offset ); PACK_LIST_STRUCT( data, flows, buf, buflen, offset, packGxFlows ); PACK_OCTETSTRING( data, monitoring_key, buf, buflen, offset ); PACK_STRUCT( data, redirect_information, buf, buflen, offset, packGxRedirectInformation ); PACK_BASIC( data, mute_notification, buf, buflen, offset ); PACK_BASIC( data, af_signalling_protocol, buf, buflen, offset ); PACK_OCTETSTRING( data, sponsor_identity, buf, buflen, offset ); PACK_OCTETSTRING( data, application_service_provider_identity, buf, buflen, offset ); PACK_LIST_BASIC( data, required_access_info, buf, buflen, offset ); PACK_BASIC( data, sharing_key_dl, buf, buflen, offset ); PACK_BASIC( data, sharing_key_ul, buf, buflen, offset ); PACK_OCTETSTRING( data, traffic_steering_policy_identifier_dl, buf, buflen, offset ); PACK_OCTETSTRING( data, traffic_steering_policy_identifier_ul, buf, buflen, offset ); PACK_BASIC( data, content_version, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxFinalUnitIndication * * Desc: Pack the contents of the GxFinalUnitIndication structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Final-Unit-Indication ::= <AVP Header: 430> * { Final-Unit-Action } * * [ Restriction-Filter-Rule ] * * [ Filter-Id ] * [ Redirect-Server ] */ static int packGxFinalUnitIndication ( GxFinalUnitIndication *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, final_unit_action, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, restriction_filter_rule, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, filter_id, buf, buflen, offset ); PACK_STRUCT( data, redirect_server, buf, buflen, offset, packGxRedirectServer ); return *offset <= buflen; } /* * * Fun: packGxUnitValue * * Desc: Pack the contents of the GxUnitValue structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Unit-Value ::= <AVP Header: 445> * { Value-Digits } * [ Exponent ] */ static int packGxUnitValue ( GxUnitValue *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, value_digits, buf, buflen, offset ); PACK_BASIC( data, exponent, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxPresenceReportingAreaInformation * * Desc: Pack the contents of the GxPresenceReportingAreaInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Presence-Reporting-Area-Information ::= <AVP Header: 2822> * [ Presence-Reporting-Area-Identifier ] * [ Presence-Reporting-Area-Status ] * [ Presence-Reporting-Area-Elements-List ] * [ Presence-Reporting-Area-Node ] * * [ AVP ] */ static int packGxPresenceReportingAreaInformation ( GxPresenceReportingAreaInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, presence_reporting_area_identifier, buf, buflen, offset ); PACK_BASIC( data, presence_reporting_area_status, buf, buflen, offset ); PACK_OCTETSTRING( data, presence_reporting_area_elements_list, buf, buflen, offset ); PACK_BASIC( data, presence_reporting_area_node, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxConditionalApnAggregateMaxBitrate * * Desc: Pack the contents of the GxConditionalApnAggregateMaxBitrate structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Conditional-APN-Aggregate-Max-Bitrate ::= <AVP Header: 2818> * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ IP-CAN-Type ] * * [ RAT-Type ] * * [ AVP ] */ static int packGxConditionalApnAggregateMaxBitrate ( GxConditionalApnAggregateMaxBitrate *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, apn_aggregate_max_bitrate_ul, buf, buflen, offset ); PACK_BASIC( data, apn_aggregate_max_bitrate_dl, buf, buflen, offset ); PACK_BASIC( data, extended_apn_ambr_ul, buf, buflen, offset ); PACK_BASIC( data, extended_apn_ambr_dl, buf, buflen, offset ); PACK_LIST_BASIC( data, ip_can_type, buf, buflen, offset ); PACK_LIST_BASIC( data, rat_type, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxAccessNetworkChargingIdentifierGx * * Desc: Pack the contents of the GxAccessNetworkChargingIdentifierGx structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Access-Network-Charging-Identifier-Gx ::= <AVP Header: 1022> * { Access-Network-Charging-Identifier-Value } * * [ Charging-Rule-Base-Name ] * * [ Charging-Rule-Name ] * [ IP-CAN-Session-Charging-Scope ] * * [ AVP ] */ static int packGxAccessNetworkChargingIdentifierGx ( GxAccessNetworkChargingIdentifierGx *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, access_network_charging_identifier_value, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, charging_rule_base_name, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, charging_rule_name, buf, buflen, offset ); PACK_BASIC( data, ip_can_session_charging_scope, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxOcOlr * * Desc: Pack the contents of the GxOcOlr structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * OC-OLR ::= <AVP Header: 623> * < OC-Sequence-Number > * < OC-Report-Type > * [ OC-Reduction-Percentage ] * [ OC-Validity-Duration ] * * [ AVP ] */ static int packGxOcOlr ( GxOcOlr *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, oc_sequence_number, buf, buflen, offset ); PACK_BASIC( data, oc_report_type, buf, buflen, offset ); PACK_BASIC( data, oc_reduction_percentage, buf, buflen, offset ); PACK_BASIC( data, oc_validity_duration, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxRoutingRuleInstall * * Desc: Pack the contents of the GxRoutingRuleInstall structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Install ::= <AVP Header: 1081> * * [ Routing-Rule-Definition ] * * [ AVP ] */ static int packGxRoutingRuleInstall ( GxRoutingRuleInstall *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_LIST_STRUCT( data, routing_rule_definition, buf, buflen, offset, packGxRoutingRuleDefinition ); return *offset <= buflen; } /* * * Fun: packGxTraceData * * Desc: Pack the contents of the GxTraceData structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Trace-Data ::= <AVP Header: 1458> * { Trace-Reference } * { Trace-Depth } * { Trace-NE-Type-List } * [ Trace-Interface-List ] * { Trace-Event-List } * [ OMC-Id ] * { Trace-Collection-Entity } * [ MDT-Configuration ] * * [ AVP ] */ static int packGxTraceData ( GxTraceData *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, trace_reference, buf, buflen, offset ); PACK_BASIC( data, trace_depth, buf, buflen, offset ); PACK_OCTETSTRING( data, trace_ne_type_list, buf, buflen, offset ); PACK_OCTETSTRING( data, trace_interface_list, buf, buflen, offset ); PACK_OCTETSTRING( data, trace_event_list, buf, buflen, offset ); PACK_OCTETSTRING( data, omc_id, buf, buflen, offset ); PACK_BASIC( data, trace_collection_entity, buf, buflen, offset ); PACK_STRUCT( data, mdt_configuration, buf, buflen, offset, packGxMdtConfiguration ); return *offset <= buflen; } /* * * Fun: packGxRoutingRuleDefinition * * Desc: Pack the contents of the GxRoutingRuleDefinition structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Definition ::= <AVP Header: 1076> * { Routing-Rule-Identifier } * * [ Routing-Filter ] * [ Precedence ] * [ Routing-IP-Address ] * [ IP-CAN-Type ] * * [ AVP ] */ static int packGxRoutingRuleDefinition ( GxRoutingRuleDefinition *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, routing_rule_identifier, buf, buflen, offset ); PACK_LIST_STRUCT( data, routing_filter, buf, buflen, offset, packGxRoutingFilter ); PACK_BASIC( data, precedence, buf, buflen, offset ); PACK_BASIC( data, routing_ip_address, buf, buflen, offset ); PACK_BASIC( data, ip_can_type, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxMdtConfiguration * * Desc: Pack the contents of the GxMdtConfiguration structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * MDT-Configuration ::= <AVP Header: 1622> * { Job-Type } * [ Area-Scope ] * [ List-Of-Measurements ] * [ Reporting-Trigger ] * [ Report-Interval ] * [ Report-Amount ] * [ Event-Threshold-RSRP ] * [ Event-Threshold-RSRQ ] * [ Logging-Interval ] * [ Logging-Duration ] * [ Measurement-Period-LTE ] * [ Measurement-Period-UMTS ] * [ Collection-Period-RRM-LTE ] * [ Collection-Period-RRM-UMTS ] * [ Positioning-Method ] * [ Measurement-Quantity ] * [ Event-Threshold-Event-1F ] * [ Event-Threshold-Event-1I ] * * [ MDT-Allowed-PLMN-Id ] * * [ MBSFN-Area ] * * [ AVP ] */ static int packGxMdtConfiguration ( GxMdtConfiguration *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, job_type, buf, buflen, offset ); PACK_STRUCT( data, area_scope, buf, buflen, offset, packGxAreaScope ); PACK_BASIC( data, list_of_measurements, buf, buflen, offset ); PACK_BASIC( data, reporting_trigger, buf, buflen, offset ); PACK_BASIC( data, report_interval, buf, buflen, offset ); PACK_BASIC( data, report_amount, buf, buflen, offset ); PACK_BASIC( data, event_threshold_rsrp, buf, buflen, offset ); PACK_BASIC( data, event_threshold_rsrq, buf, buflen, offset ); PACK_BASIC( data, logging_interval, buf, buflen, offset ); PACK_BASIC( data, logging_duration, buf, buflen, offset ); PACK_BASIC( data, measurement_period_lte, buf, buflen, offset ); PACK_BASIC( data, measurement_period_umts, buf, buflen, offset ); PACK_BASIC( data, collection_period_rrm_lte, buf, buflen, offset ); PACK_BASIC( data, collection_period_rrm_umts, buf, buflen, offset ); PACK_OCTETSTRING( data, positioning_method, buf, buflen, offset ); PACK_OCTETSTRING( data, measurement_quantity, buf, buflen, offset ); PACK_BASIC( data, event_threshold_event_1f, buf, buflen, offset ); PACK_BASIC( data, event_threshold_event_1i, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, mdt_allowed_plmn_id, buf, buflen, offset ); PACK_LIST_STRUCT( data, mbsfn_area, buf, buflen, offset, packGxMbsfnArea ); return *offset <= buflen; } /* * * Fun: packGxChargingRuleRemove * * Desc: Pack the contents of the GxChargingRuleRemove structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Remove ::= <AVP Header: 1002> * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * * [ Required-Access-Info ] * [ Resource-Release-Notification ] * * [ AVP ] */ static int packGxChargingRuleRemove ( GxChargingRuleRemove *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, charging_rule_name, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, charging_rule_base_name, buf, buflen, offset ); PACK_LIST_BASIC( data, required_access_info, buf, buflen, offset ); PACK_BASIC( data, resource_release_notification, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxAllocationRetentionPriority * * Desc: Pack the contents of the GxAllocationRetentionPriority structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Allocation-Retention-Priority ::= <AVP Header: 1034> * { Priority-Level } * [ Pre-emption-Capability ] * [ Pre-emption-Vulnerability ] */ static int packGxAllocationRetentionPriority ( GxAllocationRetentionPriority *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, priority_level, buf, buflen, offset ); PACK_BASIC( data, pre_emption_capability, buf, buflen, offset ); PACK_BASIC( data, pre_emption_vulnerability, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxDefaultEpsBearerQos * * Desc: Pack the contents of the GxDefaultEpsBearerQos structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Default-EPS-Bearer-QoS ::= <AVP Header: 1049> * [ QoS-Class-Identifier ] * [ Allocation-Retention-Priority ] * * [ AVP ] */ static int packGxDefaultEpsBearerQos ( GxDefaultEpsBearerQos *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, qos_class_identifier, buf, buflen, offset ); PACK_STRUCT( data, allocation_retention_priority, buf, buflen, offset, packGxAllocationRetentionPriority ); return *offset <= buflen; } /* * * Fun: packGxRoutingRuleReport * * Desc: Pack the contents of the GxRoutingRuleReport structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Report ::= <AVP Header: 2835> * * [ Routing-Rule-Identifier ] * [ PCC-Rule-Status ] * [ Routing-Rule-Failure-Code ] * * [ AVP ] */ static int packGxRoutingRuleReport ( GxRoutingRuleReport *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, routing_rule_identifier, buf, buflen, offset ); PACK_BASIC( data, pcc_rule_status, buf, buflen, offset ); PACK_BASIC( data, routing_rule_failure_code, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxUserEquipmentInfo * * Desc: Pack the contents of the GxUserEquipmentInfo structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * User-Equipment-Info ::= <AVP Header: 458> * { User-Equipment-Info-Type } * { User-Equipment-Info-Value } */ static int packGxUserEquipmentInfo ( GxUserEquipmentInfo *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, user_equipment_info_type, buf, buflen, offset ); PACK_OCTETSTRING( data, user_equipment_info_value, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxSupportedFeatures * * Desc: Pack the contents of the GxSupportedFeatures structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Supported-Features ::= <AVP Header: 628> * { Vendor-Id } * { Feature-List-ID } * { Feature-List } * * [ AVP ] */ static int packGxSupportedFeatures ( GxSupportedFeatures *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, vendor_id, buf, buflen, offset ); PACK_BASIC( data, feature_list_id, buf, buflen, offset ); PACK_BASIC( data, feature_list, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxFixedUserLocationInfo * * Desc: Pack the contents of the GxFixedUserLocationInfo structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Fixed-User-Location-Info ::= <AVP Header: 2825> * [ SSID ] * [ BSSID ] * [ Logical-Access-Id ] * [ Physical-Access-Id ] * * [ AVP ] */ static int packGxFixedUserLocationInfo ( GxFixedUserLocationInfo *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, ssid, buf, buflen, offset ); PACK_OCTETSTRING( data, bssid, buf, buflen, offset ); PACK_OCTETSTRING( data, logical_access_id, buf, buflen, offset ); PACK_OCTETSTRING( data, physical_access_id, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxDefaultQosInformation * * Desc: Pack the contents of the GxDefaultQosInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Default-QoS-Information ::= <AVP Header: 2816> * [ QoS-Class-Identifier ] * [ Max-Requested-Bandwidth-UL ] * [ Max-Requested-Bandwidth-DL ] * [ Default-QoS-Name ] * * [ AVP ] */ static int packGxDefaultQosInformation ( GxDefaultQosInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, qos_class_identifier, buf, buflen, offset ); PACK_BASIC( data, max_requested_bandwidth_ul, buf, buflen, offset ); PACK_BASIC( data, max_requested_bandwidth_dl, buf, buflen, offset ); PACK_OCTETSTRING( data, default_qos_name, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxLoad * * Desc: Pack the contents of the GxLoad structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Load ::= <AVP Header: 650> * [ Load-Type ] * [ Load-Value ] * [ SourceID ] * * [ AVP ] */ static int packGxLoad ( GxLoad *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, load_type, buf, buflen, offset ); PACK_BASIC( data, load_value, buf, buflen, offset ); PACK_OCTETSTRING( data, sourceid, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxRedirectServer * * Desc: Pack the contents of the GxRedirectServer structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Redirect-Server ::= <AVP Header: 434> * { Redirect-Address-Type } * { Redirect-Server-Address } */ static int packGxRedirectServer ( GxRedirectServer *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, redirect_address_type, buf, buflen, offset ); PACK_OCTETSTRING( data, redirect_server_address, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxOcSupportedFeatures * * Desc: Pack the contents of the GxOcSupportedFeatures structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * OC-Supported-Features ::= <AVP Header: 621> * [ OC-Feature-Vector ] * * [ AVP ] */ static int packGxOcSupportedFeatures ( GxOcSupportedFeatures *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, oc_feature_vector, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxPacketFilterInformation * * Desc: Pack the contents of the GxPacketFilterInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Packet-Filter-Information ::= <AVP Header: 1061> * [ Packet-Filter-Identifier ] * [ Precedence ] * [ Packet-Filter-Content ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * * [ AVP ] */ static int packGxPacketFilterInformation ( GxPacketFilterInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, packet_filter_identifier, buf, buflen, offset ); PACK_BASIC( data, precedence, buf, buflen, offset ); PACK_OCTETSTRING( data, packet_filter_content, buf, buflen, offset ); PACK_OCTETSTRING( data, tos_traffic_class, buf, buflen, offset ); PACK_OCTETSTRING( data, security_parameter_index, buf, buflen, offset ); PACK_OCTETSTRING( data, flow_label, buf, buflen, offset ); PACK_BASIC( data, flow_direction, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxSubscriptionId * * Desc: Pack the contents of the GxSubscriptionId structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Subscription-Id ::= <AVP Header: 443> * [ Subscription-Id-Type ] * [ Subscription-Id-Data ] */ static int packGxSubscriptionId ( GxSubscriptionId *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, subscription_id_type, buf, buflen, offset ); PACK_OCTETSTRING( data, subscription_id_data, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxChargingInformation * * Desc: Pack the contents of the GxChargingInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Information ::= <AVP Header: 618> * [ Primary-Event-Charging-Function-Name ] * [ Secondary-Event-Charging-Function-Name ] * [ Primary-Charging-Collection-Function-Name ] * [ Secondary-Charging-Collection-Function-Name ] * * [ AVP ] */ static int packGxChargingInformation ( GxChargingInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, primary_event_charging_function_name, buf, buflen, offset ); PACK_OCTETSTRING( data, secondary_event_charging_function_name, buf, buflen, offset ); PACK_OCTETSTRING( data, primary_charging_collection_function_name, buf, buflen, offset ); PACK_OCTETSTRING( data, secondary_charging_collection_function_name, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxUsageMonitoringInformation * * Desc: Pack the contents of the GxUsageMonitoringInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Usage-Monitoring-Information ::= <AVP Header: 1067> * [ Monitoring-Key ] * * 2 [ Granted-Service-Unit ] * * 2 [ Used-Service-Unit ] * [ Quota-Consumption-Time ] * [ Usage-Monitoring-Level ] * [ Usage-Monitoring-Report ] * [ Usage-Monitoring-Support ] * * [ AVP ] */ static int packGxUsageMonitoringInformation ( GxUsageMonitoringInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, monitoring_key, buf, buflen, offset ); PACK_LIST_STRUCT( data, granted_service_unit, buf, buflen, offset, packGxGrantedServiceUnit ); PACK_LIST_STRUCT( data, used_service_unit, buf, buflen, offset, packGxUsedServiceUnit ); PACK_BASIC( data, quota_consumption_time, buf, buflen, offset ); PACK_BASIC( data, usage_monitoring_level, buf, buflen, offset ); PACK_BASIC( data, usage_monitoring_report, buf, buflen, offset ); PACK_BASIC( data, usage_monitoring_support, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxChargingRuleReport * * Desc: Pack the contents of the GxChargingRuleReport structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Report ::= <AVP Header: 1018> * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * [ Bearer-Identifier ] * [ PCC-Rule-Status ] * [ Rule-Failure-Code ] * [ Final-Unit-Indication ] * * [ RAN-NAS-Release-Cause ] * * [ Content-Version ] * * [ AVP ] */ static int packGxChargingRuleReport ( GxChargingRuleReport *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, charging_rule_name, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, charging_rule_base_name, buf, buflen, offset ); PACK_OCTETSTRING( data, bearer_identifier, buf, buflen, offset ); PACK_BASIC( data, pcc_rule_status, buf, buflen, offset ); PACK_BASIC( data, rule_failure_code, buf, buflen, offset ); PACK_STRUCT( data, final_unit_indication, buf, buflen, offset, packGxFinalUnitIndication ); PACK_LIST_OCTETSTRING( data, ran_nas_release_cause, buf, buflen, offset ); PACK_LIST_BASIC( data, content_version, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxRedirectInformation * * Desc: Pack the contents of the GxRedirectInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Redirect-Information ::= <AVP Header: 1085> * [ Redirect-Support ] * [ Redirect-Address-Type ] * [ Redirect-Server-Address ] * * [ AVP ] */ static int packGxRedirectInformation ( GxRedirectInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, redirect_support, buf, buflen, offset ); PACK_BASIC( data, redirect_address_type, buf, buflen, offset ); PACK_OCTETSTRING( data, redirect_server_address, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxFailedAvp * * Desc: Pack the contents of the GxFailedAvp structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Failed-AVP ::= <AVP Header: 279> * 1* { AVP } */ static int packGxFailedAvp ( GxFailedAvp *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxRoutingRuleRemove * * Desc: Pack the contents of the GxRoutingRuleRemove structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Remove ::= <AVP Header: 1075> * * [ Routing-Rule-Identifier ] * * [ AVP ] */ static int packGxRoutingRuleRemove ( GxRoutingRuleRemove *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_LIST_OCTETSTRING( data, routing_rule_identifier, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxRoutingFilter * * Desc: Pack the contents of the GxRoutingFilter structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Filter ::= <AVP Header: 1078> * { Flow-Description } * { Flow-Direction } * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * * [ AVP ] */ static int packGxRoutingFilter ( GxRoutingFilter *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, flow_description, buf, buflen, offset ); PACK_BASIC( data, flow_direction, buf, buflen, offset ); PACK_OCTETSTRING( data, tos_traffic_class, buf, buflen, offset ); PACK_OCTETSTRING( data, security_parameter_index, buf, buflen, offset ); PACK_OCTETSTRING( data, flow_label, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxCoaInformation * * Desc: Pack the contents of the GxCoaInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * CoA-Information ::= <AVP Header: 1039> * { Tunnel-Information } * { CoA-IP-Address } * * [ AVP ] */ static int packGxCoaInformation ( GxCoaInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_STRUCT( data, tunnel_information, buf, buflen, offset, packGxTunnelInformation ); PACK_BASIC( data, coa_ip_address, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxGrantedServiceUnit * * Desc: Pack the contents of the GxGrantedServiceUnit structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Granted-Service-Unit ::= <AVP Header: 431> * [ Tariff-Time-Change ] * [ CC-Time ] * [ CC-Money ] * [ CC-Total-Octets ] * [ CC-Input-Octets ] * [ CC-Output-Octets ] * [ CC-Service-Specific-Units ] * * [ AVP ] */ static int packGxGrantedServiceUnit ( GxGrantedServiceUnit *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, tariff_time_change, buf, buflen, offset ); PACK_BASIC( data, cc_time, buf, buflen, offset ); PACK_STRUCT( data, cc_money, buf, buflen, offset, packGxCcMoney ); PACK_BASIC( data, cc_total_octets, buf, buflen, offset ); PACK_BASIC( data, cc_input_octets, buf, buflen, offset ); PACK_BASIC( data, cc_output_octets, buf, buflen, offset ); PACK_BASIC( data, cc_service_specific_units, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxCcMoney * * Desc: Pack the contents of the GxCcMoney structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * CC-Money ::= <AVP Header: 413> * { Unit-Value } * [ Currency-Code ] */ static int packGxCcMoney ( GxCcMoney *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_STRUCT( data, unit_value, buf, buflen, offset, packGxUnitValue ); PACK_BASIC( data, currency_code, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxApplicationDetectionInformation * * Desc: Pack the contents of the GxApplicationDetectionInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Application-Detection-Information ::= <AVP Header: 1098> * { TDF-Application-Identifier } * [ TDF-Application-Instance-Identifier ] * * [ Flow-Information ] * * [ AVP ] */ static int packGxApplicationDetectionInformation ( GxApplicationDetectionInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_OCTETSTRING( data, tdf_application_identifier, buf, buflen, offset ); PACK_OCTETSTRING( data, tdf_application_instance_identifier, buf, buflen, offset ); PACK_LIST_STRUCT( data, flow_information, buf, buflen, offset, packGxFlowInformation ); return *offset <= buflen; } /* * * Fun: packGxFlows * * Desc: Pack the contents of the GxFlows structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Flows ::= <AVP Header: 510> * { Media-Component-Number } * * [ Flow-Number ] * * [ Content-Version ] * [ Final-Unit-Action ] * [ Media-Component-Status ] * * [ AVP ] */ static int packGxFlows ( GxFlows *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, media_component_number, buf, buflen, offset ); PACK_LIST_BASIC( data, flow_number, buf, buflen, offset ); PACK_LIST_BASIC( data, content_version, buf, buflen, offset ); PACK_BASIC( data, final_unit_action, buf, buflen, offset ); PACK_BASIC( data, media_component_status, buf, buflen, offset ); return *offset <= buflen; } /* * * Fun: packGxUserCsgInformation * * Desc: Pack the contents of the GxUserCsgInformation structure * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * User-CSG-Information ::= <AVP Header: 2319> * { CSG-Id } * { CSG-Access-Mode } * [ CSG-Membership-Indication ] */ static int packGxUserCsgInformation ( GxUserCsgInformation *data, unsigned char *buf, uint32_t buflen, uint32_t *offset ) { PACK_PRESENCE( data, presence, buf, buflen, offset ); PACK_BASIC( data, csg_id, buf, buflen, offset ); PACK_BASIC( data, csg_access_mode, buf, buflen, offset ); PACK_BASIC( data, csg_membership_indication, buf, buflen, offset ); return *offset <= buflen; } /*******************************************************************************/ /* structure unpack functions */ /*******************************************************************************/ /* * * Fun: unpackGxExperimentalResult * * Desc: Unpack the specified buffer into GxExperimentalResult * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Experimental-Result ::= <AVP Header: 297> * { Vendor-Id } * { Experimental-Result-Code } */ static int unpackGxExperimentalResult ( unsigned char *buf, uint32_t length, GxExperimentalResult *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, vendor_id, buf, length, offset ); UNPACK_BASIC( data, experimental_result_code, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxPraRemove * * Desc: Unpack the specified buffer into GxPraRemove * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * PRA-Remove ::= <AVP Header: 2846> * * [ Presence-Reporting-Area-Identifier ] * * [ AVP ] */ static int unpackGxPraRemove ( unsigned char *buf, uint32_t length, GxPraRemove *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, presence_reporting_area_identifier, GxPresenceReportingAreaIdentifierOctetString, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxQosInformation * * Desc: Unpack the specified buffer into GxQosInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * QoS-Information ::= <AVP Header: 1016> * [ QoS-Class-Identifier ] * [ Max-Requested-Bandwidth-UL ] * [ Max-Requested-Bandwidth-DL ] * [ Extended-Max-Requested-BW-UL ] * [ Extended-Max-Requested-BW-DL ] * [ Guaranteed-Bitrate-UL ] * [ Guaranteed-Bitrate-DL ] * [ Extended-GBR-UL ] * [ Extended-GBR-DL ] * [ Bearer-Identifier ] * [ Allocation-Retention-Priority ] * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ Conditional-APN-Aggregate-Max-Bitrate ] * * [ AVP ] */ static int unpackGxQosInformation ( unsigned char *buf, uint32_t length, GxQosInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, qos_class_identifier, buf, length, offset ); UNPACK_BASIC( data, max_requested_bandwidth_ul, buf, length, offset ); UNPACK_BASIC( data, max_requested_bandwidth_dl, buf, length, offset ); UNPACK_BASIC( data, extended_max_requested_bw_ul, buf, length, offset ); UNPACK_BASIC( data, extended_max_requested_bw_dl, buf, length, offset ); UNPACK_BASIC( data, guaranteed_bitrate_ul, buf, length, offset ); UNPACK_BASIC( data, guaranteed_bitrate_dl, buf, length, offset ); UNPACK_BASIC( data, extended_gbr_ul, buf, length, offset ); UNPACK_BASIC( data, extended_gbr_dl, buf, length, offset ); UNPACK_OCTETSTRING( data, bearer_identifier, buf, length, offset ); UNPACK_STRUCT( data, allocation_retention_priority, buf, length, offset, unpackGxAllocationRetentionPriority ); UNPACK_BASIC( data, apn_aggregate_max_bitrate_ul, buf, length, offset ); UNPACK_BASIC( data, apn_aggregate_max_bitrate_dl, buf, length, offset ); UNPACK_BASIC( data, extended_apn_ambr_ul, buf, length, offset ); UNPACK_BASIC( data, extended_apn_ambr_dl, buf, length, offset ); UNPACK_LIST_STRUCT( data, conditional_apn_aggregate_max_bitrate, GxConditionalApnAggregateMaxBitrate, buf, length, offset, unpackGxConditionalApnAggregateMaxBitrate ); return *offset <= length; } /* * * Fun: unpackGxConditionalPolicyInformation * * Desc: Unpack the specified buffer into GxConditionalPolicyInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Conditional-Policy-Information ::= <AVP Header: 2840> * [ Execution-Time ] * [ Default-EPS-Bearer-QoS ] * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ Conditional-APN-Aggregate-Max-Bitrate ] * * [ AVP ] */ static int unpackGxConditionalPolicyInformation ( unsigned char *buf, uint32_t length, GxConditionalPolicyInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, execution_time, buf, length, offset ); UNPACK_STRUCT( data, default_eps_bearer_qos, buf, length, offset, unpackGxDefaultEpsBearerQos ); UNPACK_BASIC( data, apn_aggregate_max_bitrate_ul, buf, length, offset ); UNPACK_BASIC( data, apn_aggregate_max_bitrate_dl, buf, length, offset ); UNPACK_BASIC( data, extended_apn_ambr_ul, buf, length, offset ); UNPACK_BASIC( data, extended_apn_ambr_dl, buf, length, offset ); UNPACK_LIST_STRUCT( data, conditional_apn_aggregate_max_bitrate, GxConditionalApnAggregateMaxBitrate, buf, length, offset, unpackGxConditionalApnAggregateMaxBitrate ); return *offset <= length; } /* * * Fun: unpackGxPraInstall * * Desc: Unpack the specified buffer into GxPraInstall * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * PRA-Install ::= <AVP Header: 2845> * * [ Presence-Reporting-Area-Information ] * * [ AVP ] */ static int unpackGxPraInstall ( unsigned char *buf, uint32_t length, GxPraInstall *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_LIST_STRUCT( data, presence_reporting_area_information, GxPresenceReportingAreaInformation, buf, length, offset, unpackGxPresenceReportingAreaInformation ); return *offset <= length; } /* * * Fun: unpackGxAreaScope * * Desc: Unpack the specified buffer into GxAreaScope * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Area-Scope ::= <AVP Header: 1624> * * [ Cell-Global-Identity ] * * [ E-UTRAN-Cell-Global-Identity ] * * [ Routing-Area-Identity ] * * [ Location-Area-Identity ] * * [ Tracking-Area-Identity ] * * [ AVP ] */ static int unpackGxAreaScope ( unsigned char *buf, uint32_t length, GxAreaScope *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, cell_global_identity, GxCellGlobalIdentityOctetString, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, e_utran_cell_global_identity, GxEUtranCellGlobalIdentityOctetString, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, routing_area_identity, GxRoutingAreaIdentityOctetString, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, location_area_identity, GxLocationAreaIdentityOctetString, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, tracking_area_identity, GxTrackingAreaIdentityOctetString, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxFlowInformation * * Desc: Unpack the specified buffer into GxFlowInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Flow-Information ::= <AVP Header: 1058> * [ Flow-Description ] * [ Packet-Filter-Identifier ] * [ Packet-Filter-Usage ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * [ Routing-Rule-Identifier ] * * [ AVP ] */ static int unpackGxFlowInformation ( unsigned char *buf, uint32_t length, GxFlowInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, flow_description, buf, length, offset ); UNPACK_OCTETSTRING( data, packet_filter_identifier, buf, length, offset ); UNPACK_BASIC( data, packet_filter_usage, buf, length, offset ); UNPACK_OCTETSTRING( data, tos_traffic_class, buf, length, offset ); UNPACK_OCTETSTRING( data, security_parameter_index, buf, length, offset ); UNPACK_OCTETSTRING( data, flow_label, buf, length, offset ); UNPACK_BASIC( data, flow_direction, buf, length, offset ); UNPACK_OCTETSTRING( data, routing_rule_identifier, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxTunnelInformation * * Desc: Unpack the specified buffer into GxTunnelInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Tunnel-Information ::= <AVP Header: 1038> * [ Tunnel-Header-Length ] * [ Tunnel-Header-Filter ] */ static int unpackGxTunnelInformation ( unsigned char *buf, uint32_t length, GxTunnelInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, tunnel_header_length, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, tunnel_header_filter, GxTunnelHeaderFilterOctetString, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxTftPacketFilterInformation * * Desc: Unpack the specified buffer into GxTftPacketFilterInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * TFT-Packet-Filter-Information ::= <AVP Header: 1013> * [ Precedence ] * [ TFT-Filter ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * * [ AVP ] */ static int unpackGxTftPacketFilterInformation ( unsigned char *buf, uint32_t length, GxTftPacketFilterInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, precedence, buf, length, offset ); UNPACK_OCTETSTRING( data, tft_filter, buf, length, offset ); UNPACK_OCTETSTRING( data, tos_traffic_class, buf, length, offset ); UNPACK_OCTETSTRING( data, security_parameter_index, buf, length, offset ); UNPACK_OCTETSTRING( data, flow_label, buf, length, offset ); UNPACK_BASIC( data, flow_direction, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxMbsfnArea * * Desc: Unpack the specified buffer into GxMbsfnArea * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * MBSFN-Area ::= <AVP Header: 1694> * { MBSFN-Area-ID } * { Carrier-Frequency } * * [ AVP ] */ static int unpackGxMbsfnArea ( unsigned char *buf, uint32_t length, GxMbsfnArea *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, mbsfn_area_id, buf, length, offset ); UNPACK_BASIC( data, carrier_frequency, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxEventReportIndication * * Desc: Unpack the specified buffer into GxEventReportIndication * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Event-Report-Indication ::= <AVP Header: 1033> * [ AN-Trusted ] * * [ Event-Trigger ] * [ User-CSG-Information ] * [ IP-CAN-Type ] * * 2 [ AN-GW-Address ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ 3GPP-SGSN-MCC-MNC ] * [ Framed-IP-Address ] * [ RAT-Type ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ Trace-Data ] * [ Trace-Reference ] * [ 3GPP2-BSID ] * [ 3GPP-MS-TimeZone ] * [ Routing-IP-Address ] * [ UE-Local-IP-Address ] * [ HeNB-Local-IP-Address ] * [ UDP-Source-Port ] * [ Presence-Reporting-Area-Information ] * * [ AVP ] */ static int unpackGxEventReportIndication ( unsigned char *buf, uint32_t length, GxEventReportIndication *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, an_trusted, buf, length, offset ); UNPACK_LIST_BASIC( data, event_trigger, int32_t, buf, length, offset ); UNPACK_STRUCT( data, user_csg_information, buf, length, offset, unpackGxUserCsgInformation ); UNPACK_BASIC( data, ip_can_type, buf, length, offset ); UNPACK_LIST_BASIC( data, an_gw_address, FdAddress, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_sgsn_address, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_sgsn_ipv6_address, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_sgsn_mcc_mnc, buf, length, offset ); UNPACK_OCTETSTRING( data, framed_ip_address, buf, length, offset ); UNPACK_BASIC( data, rat_type, buf, length, offset ); UNPACK_OCTETSTRING( data, rai, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_user_location_info, buf, length, offset ); UNPACK_STRUCT( data, trace_data, buf, length, offset, unpackGxTraceData ); UNPACK_OCTETSTRING( data, trace_reference, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp2_bsid, buf, length, offset ); UNPACK_OCTETSTRING( data, tgpp_ms_timezone, buf, length, offset ); UNPACK_BASIC( data, routing_ip_address, buf, length, offset ); UNPACK_BASIC( data, ue_local_ip_address, buf, length, offset ); UNPACK_BASIC( data, henb_local_ip_address, buf, length, offset ); UNPACK_BASIC( data, udp_source_port, buf, length, offset ); UNPACK_STRUCT( data, presence_reporting_area_information, buf, length, offset, unpackGxPresenceReportingAreaInformation ); return *offset <= length; } /* * * Fun: unpackGxTdfInformation * * Desc: Unpack the specified buffer into GxTdfInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * TDF-Information ::= <AVP Header: 1087> * [ TDF-Destination-Realm ] * [ TDF-Destination-Host ] * [ TDF-IP-Address ] */ static int unpackGxTdfInformation ( unsigned char *buf, uint32_t length, GxTdfInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, tdf_destination_realm, buf, length, offset ); UNPACK_OCTETSTRING( data, tdf_destination_host, buf, length, offset ); UNPACK_BASIC( data, tdf_ip_address, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxProxyInfo * * Desc: Unpack the specified buffer into GxProxyInfo * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Proxy-Info ::= <AVP Header: 284> * { Proxy-Host } * { Proxy-State } * * [ AVP ] */ static int unpackGxProxyInfo ( unsigned char *buf, uint32_t length, GxProxyInfo *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, proxy_host, buf, length, offset ); UNPACK_OCTETSTRING( data, proxy_state, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxUsedServiceUnit * * Desc: Unpack the specified buffer into GxUsedServiceUnit * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Used-Service-Unit ::= <AVP Header: 446> * [ Reporting-Reason ] * [ Tariff-Change-Usage ] * [ CC-Time ] * [ CC-Money ] * [ CC-Total-Octets ] * [ CC-Input-Octets ] * [ CC-Output-Octets ] * [ CC-Service-Specific-Units ] * * [ Event-Charging-TimeStamp ] * * [ AVP ] */ static int unpackGxUsedServiceUnit ( unsigned char *buf, uint32_t length, GxUsedServiceUnit *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, reporting_reason, buf, length, offset ); UNPACK_BASIC( data, tariff_change_usage, buf, length, offset ); UNPACK_BASIC( data, cc_time, buf, length, offset ); UNPACK_STRUCT( data, cc_money, buf, length, offset, unpackGxCcMoney ); UNPACK_BASIC( data, cc_total_octets, buf, length, offset ); UNPACK_BASIC( data, cc_input_octets, buf, length, offset ); UNPACK_BASIC( data, cc_output_octets, buf, length, offset ); UNPACK_BASIC( data, cc_service_specific_units, buf, length, offset ); UNPACK_LIST_BASIC( data, event_charging_timestamp, FdTime, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxChargingRuleInstall * * Desc: Unpack the specified buffer into GxChargingRuleInstall * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Install ::= <AVP Header: 1001> * * [ Charging-Rule-Definition ] * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * [ Bearer-Identifier ] * [ Monitoring-Flags ] * [ Rule-Activation-Time ] * [ Rule-Deactivation-Time ] * [ Resource-Allocation-Notification ] * [ Charging-Correlation-Indicator ] * [ IP-CAN-Type ] * * [ AVP ] */ static int unpackGxChargingRuleInstall ( unsigned char *buf, uint32_t length, GxChargingRuleInstall *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_LIST_STRUCT( data, charging_rule_definition, GxChargingRuleDefinition, buf, length, offset, unpackGxChargingRuleDefinition ); UNPACK_LIST_OCTETSTRING( data, charging_rule_name, GxChargingRuleNameOctetString, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, charging_rule_base_name, GxChargingRuleBaseNameOctetString, buf, length, offset ); UNPACK_OCTETSTRING( data, bearer_identifier, buf, length, offset ); UNPACK_BASIC( data, monitoring_flags, buf, length, offset ); UNPACK_BASIC( data, rule_activation_time, buf, length, offset ); UNPACK_BASIC( data, rule_deactivation_time, buf, length, offset ); UNPACK_BASIC( data, resource_allocation_notification, buf, length, offset ); UNPACK_BASIC( data, charging_correlation_indicator, buf, length, offset ); UNPACK_BASIC( data, ip_can_type, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxChargingRuleDefinition * * Desc: Unpack the specified buffer into GxChargingRuleDefinition * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Definition ::= <AVP Header: 1003> * { Charging-Rule-Name } * [ Service-Identifier ] * [ Rating-Group ] * * [ Flow-Information ] * [ Default-Bearer-Indication ] * [ TDF-Application-Identifier ] * [ Flow-Status ] * [ QoS-Information ] * [ PS-to-CS-Session-Continuity ] * [ Reporting-Level ] * [ Online ] * [ Offline ] * [ Max-PLR-DL ] * [ Max-PLR-UL ] * [ Metering-Method ] * [ Precedence ] * [ AF-Charging-Identifier ] * * [ Flows ] * [ Monitoring-Key ] * [ Redirect-Information ] * [ Mute-Notification ] * [ AF-Signalling-Protocol ] * [ Sponsor-Identity ] * [ Application-Service-Provider-Identity ] * * [ Required-Access-Info ] * [ Sharing-Key-DL ] * [ Sharing-Key-UL ] * [ Traffic-Steering-Policy-Identifier-DL ] * [ Traffic-Steering-Policy-Identifier-UL ] * [ Content-Version ] * * [ AVP ] */ static int unpackGxChargingRuleDefinition ( unsigned char *buf, uint32_t length, GxChargingRuleDefinition *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, charging_rule_name, buf, length, offset ); UNPACK_BASIC( data, service_identifier, buf, length, offset ); UNPACK_BASIC( data, rating_group, buf, length, offset ); UNPACK_LIST_STRUCT( data, flow_information, GxFlowInformation, buf, length, offset, unpackGxFlowInformation ); UNPACK_BASIC( data, default_bearer_indication, buf, length, offset ); UNPACK_OCTETSTRING( data, tdf_application_identifier, buf, length, offset ); UNPACK_BASIC( data, flow_status, buf, length, offset ); UNPACK_STRUCT( data, qos_information, buf, length, offset, unpackGxQosInformation ); UNPACK_BASIC( data, ps_to_cs_session_continuity, buf, length, offset ); UNPACK_BASIC( data, reporting_level, buf, length, offset ); UNPACK_BASIC( data, online, buf, length, offset ); UNPACK_BASIC( data, offline, buf, length, offset ); UNPACK_BASIC( data, max_plr_dl, buf, length, offset ); UNPACK_BASIC( data, max_plr_ul, buf, length, offset ); UNPACK_BASIC( data, metering_method, buf, length, offset ); UNPACK_BASIC( data, precedence, buf, length, offset ); UNPACK_OCTETSTRING( data, af_charging_identifier, buf, length, offset ); UNPACK_LIST_STRUCT( data, flows, GxFlows, buf, length, offset, unpackGxFlows ); UNPACK_OCTETSTRING( data, monitoring_key, buf, length, offset ); UNPACK_STRUCT( data, redirect_information, buf, length, offset, unpackGxRedirectInformation ); UNPACK_BASIC( data, mute_notification, buf, length, offset ); UNPACK_BASIC( data, af_signalling_protocol, buf, length, offset ); UNPACK_OCTETSTRING( data, sponsor_identity, buf, length, offset ); UNPACK_OCTETSTRING( data, application_service_provider_identity, buf, length, offset ); UNPACK_LIST_BASIC( data, required_access_info, int32_t, buf, length, offset ); UNPACK_BASIC( data, sharing_key_dl, buf, length, offset ); UNPACK_BASIC( data, sharing_key_ul, buf, length, offset ); UNPACK_OCTETSTRING( data, traffic_steering_policy_identifier_dl, buf, length, offset ); UNPACK_OCTETSTRING( data, traffic_steering_policy_identifier_ul, buf, length, offset ); UNPACK_BASIC( data, content_version, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxFinalUnitIndication * * Desc: Unpack the specified buffer into GxFinalUnitIndication * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Final-Unit-Indication ::= <AVP Header: 430> * { Final-Unit-Action } * * [ Restriction-Filter-Rule ] * * [ Filter-Id ] * [ Redirect-Server ] */ static int unpackGxFinalUnitIndication ( unsigned char *buf, uint32_t length, GxFinalUnitIndication *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, final_unit_action, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, restriction_filter_rule, GxRestrictionFilterRuleOctetString, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, filter_id, GxFilterIdOctetString, buf, length, offset ); UNPACK_STRUCT( data, redirect_server, buf, length, offset, unpackGxRedirectServer ); return *offset <= length; } /* * * Fun: unpackGxUnitValue * * Desc: Unpack the specified buffer into GxUnitValue * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Unit-Value ::= <AVP Header: 445> * { Value-Digits } * [ Exponent ] */ static int unpackGxUnitValue ( unsigned char *buf, uint32_t length, GxUnitValue *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, value_digits, buf, length, offset ); UNPACK_BASIC( data, exponent, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxPresenceReportingAreaInformation * * Desc: Unpack the specified buffer into GxPresenceReportingAreaInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Presence-Reporting-Area-Information ::= <AVP Header: 2822> * [ Presence-Reporting-Area-Identifier ] * [ Presence-Reporting-Area-Status ] * [ Presence-Reporting-Area-Elements-List ] * [ Presence-Reporting-Area-Node ] * * [ AVP ] */ static int unpackGxPresenceReportingAreaInformation ( unsigned char *buf, uint32_t length, GxPresenceReportingAreaInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, presence_reporting_area_identifier, buf, length, offset ); UNPACK_BASIC( data, presence_reporting_area_status, buf, length, offset ); UNPACK_OCTETSTRING( data, presence_reporting_area_elements_list, buf, length, offset ); UNPACK_BASIC( data, presence_reporting_area_node, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxConditionalApnAggregateMaxBitrate * * Desc: Unpack the specified buffer into GxConditionalApnAggregateMaxBitrate * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Conditional-APN-Aggregate-Max-Bitrate ::= <AVP Header: 2818> * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ IP-CAN-Type ] * * [ RAT-Type ] * * [ AVP ] */ static int unpackGxConditionalApnAggregateMaxBitrate ( unsigned char *buf, uint32_t length, GxConditionalApnAggregateMaxBitrate *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, apn_aggregate_max_bitrate_ul, buf, length, offset ); UNPACK_BASIC( data, apn_aggregate_max_bitrate_dl, buf, length, offset ); UNPACK_BASIC( data, extended_apn_ambr_ul, buf, length, offset ); UNPACK_BASIC( data, extended_apn_ambr_dl, buf, length, offset ); UNPACK_LIST_BASIC( data, ip_can_type, int32_t, buf, length, offset ); UNPACK_LIST_BASIC( data, rat_type, int32_t, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxAccessNetworkChargingIdentifierGx * * Desc: Unpack the specified buffer into GxAccessNetworkChargingIdentifierGx * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Access-Network-Charging-Identifier-Gx ::= <AVP Header: 1022> * { Access-Network-Charging-Identifier-Value } * * [ Charging-Rule-Base-Name ] * * [ Charging-Rule-Name ] * [ IP-CAN-Session-Charging-Scope ] * * [ AVP ] */ static int unpackGxAccessNetworkChargingIdentifierGx ( unsigned char *buf, uint32_t length, GxAccessNetworkChargingIdentifierGx *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, access_network_charging_identifier_value, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, charging_rule_base_name, GxChargingRuleBaseNameOctetString, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, charging_rule_name, GxChargingRuleNameOctetString, buf, length, offset ); UNPACK_BASIC( data, ip_can_session_charging_scope, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxOcOlr * * Desc: Unpack the specified buffer into GxOcOlr * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * OC-OLR ::= <AVP Header: 623> * < OC-Sequence-Number > * < OC-Report-Type > * [ OC-Reduction-Percentage ] * [ OC-Validity-Duration ] * * [ AVP ] */ static int unpackGxOcOlr ( unsigned char *buf, uint32_t length, GxOcOlr *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, oc_sequence_number, buf, length, offset ); UNPACK_BASIC( data, oc_report_type, buf, length, offset ); UNPACK_BASIC( data, oc_reduction_percentage, buf, length, offset ); UNPACK_BASIC( data, oc_validity_duration, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxRoutingRuleInstall * * Desc: Unpack the specified buffer into GxRoutingRuleInstall * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Install ::= <AVP Header: 1081> * * [ Routing-Rule-Definition ] * * [ AVP ] */ static int unpackGxRoutingRuleInstall ( unsigned char *buf, uint32_t length, GxRoutingRuleInstall *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_LIST_STRUCT( data, routing_rule_definition, GxRoutingRuleDefinition, buf, length, offset, unpackGxRoutingRuleDefinition ); return *offset <= length; } /* * * Fun: unpackGxTraceData * * Desc: Unpack the specified buffer into GxTraceData * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Trace-Data ::= <AVP Header: 1458> * { Trace-Reference } * { Trace-Depth } * { Trace-NE-Type-List } * [ Trace-Interface-List ] * { Trace-Event-List } * [ OMC-Id ] * { Trace-Collection-Entity } * [ MDT-Configuration ] * * [ AVP ] */ static int unpackGxTraceData ( unsigned char *buf, uint32_t length, GxTraceData *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, trace_reference, buf, length, offset ); UNPACK_BASIC( data, trace_depth, buf, length, offset ); UNPACK_OCTETSTRING( data, trace_ne_type_list, buf, length, offset ); UNPACK_OCTETSTRING( data, trace_interface_list, buf, length, offset ); UNPACK_OCTETSTRING( data, trace_event_list, buf, length, offset ); UNPACK_OCTETSTRING( data, omc_id, buf, length, offset ); UNPACK_BASIC( data, trace_collection_entity, buf, length, offset ); UNPACK_STRUCT( data, mdt_configuration, buf, length, offset, unpackGxMdtConfiguration ); return *offset <= length; } /* * * Fun: unpackGxRoutingRuleDefinition * * Desc: Unpack the specified buffer into GxRoutingRuleDefinition * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Definition ::= <AVP Header: 1076> * { Routing-Rule-Identifier } * * [ Routing-Filter ] * [ Precedence ] * [ Routing-IP-Address ] * [ IP-CAN-Type ] * * [ AVP ] */ static int unpackGxRoutingRuleDefinition ( unsigned char *buf, uint32_t length, GxRoutingRuleDefinition *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, routing_rule_identifier, buf, length, offset ); UNPACK_LIST_STRUCT( data, routing_filter, GxRoutingFilter, buf, length, offset, unpackGxRoutingFilter ); UNPACK_BASIC( data, precedence, buf, length, offset ); UNPACK_BASIC( data, routing_ip_address, buf, length, offset ); UNPACK_BASIC( data, ip_can_type, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxMdtConfiguration * * Desc: Unpack the specified buffer into GxMdtConfiguration * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * MDT-Configuration ::= <AVP Header: 1622> * { Job-Type } * [ Area-Scope ] * [ List-Of-Measurements ] * [ Reporting-Trigger ] * [ Report-Interval ] * [ Report-Amount ] * [ Event-Threshold-RSRP ] * [ Event-Threshold-RSRQ ] * [ Logging-Interval ] * [ Logging-Duration ] * [ Measurement-Period-LTE ] * [ Measurement-Period-UMTS ] * [ Collection-Period-RRM-LTE ] * [ Collection-Period-RRM-UMTS ] * [ Positioning-Method ] * [ Measurement-Quantity ] * [ Event-Threshold-Event-1F ] * [ Event-Threshold-Event-1I ] * * [ MDT-Allowed-PLMN-Id ] * * [ MBSFN-Area ] * * [ AVP ] */ static int unpackGxMdtConfiguration ( unsigned char *buf, uint32_t length, GxMdtConfiguration *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, job_type, buf, length, offset ); UNPACK_STRUCT( data, area_scope, buf, length, offset, unpackGxAreaScope ); UNPACK_BASIC( data, list_of_measurements, buf, length, offset ); UNPACK_BASIC( data, reporting_trigger, buf, length, offset ); UNPACK_BASIC( data, report_interval, buf, length, offset ); UNPACK_BASIC( data, report_amount, buf, length, offset ); UNPACK_BASIC( data, event_threshold_rsrp, buf, length, offset ); UNPACK_BASIC( data, event_threshold_rsrq, buf, length, offset ); UNPACK_BASIC( data, logging_interval, buf, length, offset ); UNPACK_BASIC( data, logging_duration, buf, length, offset ); UNPACK_BASIC( data, measurement_period_lte, buf, length, offset ); UNPACK_BASIC( data, measurement_period_umts, buf, length, offset ); UNPACK_BASIC( data, collection_period_rrm_lte, buf, length, offset ); UNPACK_BASIC( data, collection_period_rrm_umts, buf, length, offset ); UNPACK_OCTETSTRING( data, positioning_method, buf, length, offset ); UNPACK_OCTETSTRING( data, measurement_quantity, buf, length, offset ); UNPACK_BASIC( data, event_threshold_event_1f, buf, length, offset ); UNPACK_BASIC( data, event_threshold_event_1i, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, mdt_allowed_plmn_id, GxMdtAllowedPlmnIdOctetString, buf, length, offset ); UNPACK_LIST_STRUCT( data, mbsfn_area, GxMbsfnArea, buf, length, offset, unpackGxMbsfnArea ); return *offset <= length; } /* * * Fun: unpackGxChargingRuleRemove * * Desc: Unpack the specified buffer into GxChargingRuleRemove * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Remove ::= <AVP Header: 1002> * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * * [ Required-Access-Info ] * [ Resource-Release-Notification ] * * [ AVP ] */ static int unpackGxChargingRuleRemove ( unsigned char *buf, uint32_t length, GxChargingRuleRemove *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, charging_rule_name, GxChargingRuleNameOctetString, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, charging_rule_base_name, GxChargingRuleBaseNameOctetString, buf, length, offset ); UNPACK_LIST_BASIC( data, required_access_info, int32_t, buf, length, offset ); UNPACK_BASIC( data, resource_release_notification, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxAllocationRetentionPriority * * Desc: Unpack the specified buffer into GxAllocationRetentionPriority * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Allocation-Retention-Priority ::= <AVP Header: 1034> * { Priority-Level } * [ Pre-emption-Capability ] * [ Pre-emption-Vulnerability ] */ static int unpackGxAllocationRetentionPriority ( unsigned char *buf, uint32_t length, GxAllocationRetentionPriority *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, priority_level, buf, length, offset ); UNPACK_BASIC( data, pre_emption_capability, buf, length, offset ); UNPACK_BASIC( data, pre_emption_vulnerability, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxDefaultEpsBearerQos * * Desc: Unpack the specified buffer into GxDefaultEpsBearerQos * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Default-EPS-Bearer-QoS ::= <AVP Header: 1049> * [ QoS-Class-Identifier ] * [ Allocation-Retention-Priority ] * * [ AVP ] */ static int unpackGxDefaultEpsBearerQos ( unsigned char *buf, uint32_t length, GxDefaultEpsBearerQos *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, qos_class_identifier, buf, length, offset ); UNPACK_STRUCT( data, allocation_retention_priority, buf, length, offset, unpackGxAllocationRetentionPriority ); return *offset <= length; } /* * * Fun: unpackGxRoutingRuleReport * * Desc: Unpack the specified buffer into GxRoutingRuleReport * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Report ::= <AVP Header: 2835> * * [ Routing-Rule-Identifier ] * [ PCC-Rule-Status ] * [ Routing-Rule-Failure-Code ] * * [ AVP ] */ static int unpackGxRoutingRuleReport ( unsigned char *buf, uint32_t length, GxRoutingRuleReport *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, routing_rule_identifier, GxRoutingRuleIdentifierOctetString, buf, length, offset ); UNPACK_BASIC( data, pcc_rule_status, buf, length, offset ); UNPACK_BASIC( data, routing_rule_failure_code, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxUserEquipmentInfo * * Desc: Unpack the specified buffer into GxUserEquipmentInfo * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * User-Equipment-Info ::= <AVP Header: 458> * { User-Equipment-Info-Type } * { User-Equipment-Info-Value } */ static int unpackGxUserEquipmentInfo ( unsigned char *buf, uint32_t length, GxUserEquipmentInfo *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, user_equipment_info_type, buf, length, offset ); UNPACK_OCTETSTRING( data, user_equipment_info_value, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxSupportedFeatures * * Desc: Unpack the specified buffer into GxSupportedFeatures * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Supported-Features ::= <AVP Header: 628> * { Vendor-Id } * { Feature-List-ID } * { Feature-List } * * [ AVP ] */ static int unpackGxSupportedFeatures ( unsigned char *buf, uint32_t length, GxSupportedFeatures *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, vendor_id, buf, length, offset ); UNPACK_BASIC( data, feature_list_id, buf, length, offset ); UNPACK_BASIC( data, feature_list, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxFixedUserLocationInfo * * Desc: Unpack the specified buffer into GxFixedUserLocationInfo * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Fixed-User-Location-Info ::= <AVP Header: 2825> * [ SSID ] * [ BSSID ] * [ Logical-Access-Id ] * [ Physical-Access-Id ] * * [ AVP ] */ static int unpackGxFixedUserLocationInfo ( unsigned char *buf, uint32_t length, GxFixedUserLocationInfo *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, ssid, buf, length, offset ); UNPACK_OCTETSTRING( data, bssid, buf, length, offset ); UNPACK_OCTETSTRING( data, logical_access_id, buf, length, offset ); UNPACK_OCTETSTRING( data, physical_access_id, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxDefaultQosInformation * * Desc: Unpack the specified buffer into GxDefaultQosInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Default-QoS-Information ::= <AVP Header: 2816> * [ QoS-Class-Identifier ] * [ Max-Requested-Bandwidth-UL ] * [ Max-Requested-Bandwidth-DL ] * [ Default-QoS-Name ] * * [ AVP ] */ static int unpackGxDefaultQosInformation ( unsigned char *buf, uint32_t length, GxDefaultQosInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, qos_class_identifier, buf, length, offset ); UNPACK_BASIC( data, max_requested_bandwidth_ul, buf, length, offset ); UNPACK_BASIC( data, max_requested_bandwidth_dl, buf, length, offset ); UNPACK_OCTETSTRING( data, default_qos_name, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxLoad * * Desc: Unpack the specified buffer into GxLoad * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Load ::= <AVP Header: 650> * [ Load-Type ] * [ Load-Value ] * [ SourceID ] * * [ AVP ] */ static int unpackGxLoad ( unsigned char *buf, uint32_t length, GxLoad *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, load_type, buf, length, offset ); UNPACK_BASIC( data, load_value, buf, length, offset ); UNPACK_OCTETSTRING( data, sourceid, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxRedirectServer * * Desc: Unpack the specified buffer into GxRedirectServer * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Redirect-Server ::= <AVP Header: 434> * { Redirect-Address-Type } * { Redirect-Server-Address } */ static int unpackGxRedirectServer ( unsigned char *buf, uint32_t length, GxRedirectServer *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, redirect_address_type, buf, length, offset ); UNPACK_OCTETSTRING( data, redirect_server_address, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxOcSupportedFeatures * * Desc: Unpack the specified buffer into GxOcSupportedFeatures * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * OC-Supported-Features ::= <AVP Header: 621> * [ OC-Feature-Vector ] * * [ AVP ] */ static int unpackGxOcSupportedFeatures ( unsigned char *buf, uint32_t length, GxOcSupportedFeatures *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, oc_feature_vector, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxPacketFilterInformation * * Desc: Unpack the specified buffer into GxPacketFilterInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Packet-Filter-Information ::= <AVP Header: 1061> * [ Packet-Filter-Identifier ] * [ Precedence ] * [ Packet-Filter-Content ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * * [ AVP ] */ static int unpackGxPacketFilterInformation ( unsigned char *buf, uint32_t length, GxPacketFilterInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, packet_filter_identifier, buf, length, offset ); UNPACK_BASIC( data, precedence, buf, length, offset ); UNPACK_OCTETSTRING( data, packet_filter_content, buf, length, offset ); UNPACK_OCTETSTRING( data, tos_traffic_class, buf, length, offset ); UNPACK_OCTETSTRING( data, security_parameter_index, buf, length, offset ); UNPACK_OCTETSTRING( data, flow_label, buf, length, offset ); UNPACK_BASIC( data, flow_direction, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxSubscriptionId * * Desc: Unpack the specified buffer into GxSubscriptionId * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Subscription-Id ::= <AVP Header: 443> * [ Subscription-Id-Type ] * [ Subscription-Id-Data ] */ static int unpackGxSubscriptionId ( unsigned char *buf, uint32_t length, GxSubscriptionId *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, subscription_id_type, buf, length, offset ); UNPACK_OCTETSTRING( data, subscription_id_data, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxChargingInformation * * Desc: Unpack the specified buffer into GxChargingInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Information ::= <AVP Header: 618> * [ Primary-Event-Charging-Function-Name ] * [ Secondary-Event-Charging-Function-Name ] * [ Primary-Charging-Collection-Function-Name ] * [ Secondary-Charging-Collection-Function-Name ] * * [ AVP ] */ static int unpackGxChargingInformation ( unsigned char *buf, uint32_t length, GxChargingInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, primary_event_charging_function_name, buf, length, offset ); UNPACK_OCTETSTRING( data, secondary_event_charging_function_name, buf, length, offset ); UNPACK_OCTETSTRING( data, primary_charging_collection_function_name, buf, length, offset ); UNPACK_OCTETSTRING( data, secondary_charging_collection_function_name, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxUsageMonitoringInformation * * Desc: Unpack the specified buffer into GxUsageMonitoringInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Usage-Monitoring-Information ::= <AVP Header: 1067> * [ Monitoring-Key ] * * 2 [ Granted-Service-Unit ] * * 2 [ Used-Service-Unit ] * [ Quota-Consumption-Time ] * [ Usage-Monitoring-Level ] * [ Usage-Monitoring-Report ] * [ Usage-Monitoring-Support ] * * [ AVP ] */ static int unpackGxUsageMonitoringInformation ( unsigned char *buf, uint32_t length, GxUsageMonitoringInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, monitoring_key, buf, length, offset ); UNPACK_LIST_STRUCT( data, granted_service_unit, GxGrantedServiceUnit, buf, length, offset, unpackGxGrantedServiceUnit ); UNPACK_LIST_STRUCT( data, used_service_unit, GxUsedServiceUnit, buf, length, offset, unpackGxUsedServiceUnit ); UNPACK_BASIC( data, quota_consumption_time, buf, length, offset ); UNPACK_BASIC( data, usage_monitoring_level, buf, length, offset ); UNPACK_BASIC( data, usage_monitoring_report, buf, length, offset ); UNPACK_BASIC( data, usage_monitoring_support, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxChargingRuleReport * * Desc: Unpack the specified buffer into GxChargingRuleReport * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Charging-Rule-Report ::= <AVP Header: 1018> * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * [ Bearer-Identifier ] * [ PCC-Rule-Status ] * [ Rule-Failure-Code ] * [ Final-Unit-Indication ] * * [ RAN-NAS-Release-Cause ] * * [ Content-Version ] * * [ AVP ] */ static int unpackGxChargingRuleReport ( unsigned char *buf, uint32_t length, GxChargingRuleReport *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, charging_rule_name, GxChargingRuleNameOctetString, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, charging_rule_base_name, GxChargingRuleBaseNameOctetString, buf, length, offset ); UNPACK_OCTETSTRING( data, bearer_identifier, buf, length, offset ); UNPACK_BASIC( data, pcc_rule_status, buf, length, offset ); UNPACK_BASIC( data, rule_failure_code, buf, length, offset ); UNPACK_STRUCT( data, final_unit_indication, buf, length, offset, unpackGxFinalUnitIndication ); UNPACK_LIST_OCTETSTRING( data, ran_nas_release_cause, GxRanNasReleaseCauseOctetString, buf, length, offset ); UNPACK_LIST_BASIC( data, content_version, uint64_t, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxRedirectInformation * * Desc: Unpack the specified buffer into GxRedirectInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Redirect-Information ::= <AVP Header: 1085> * [ Redirect-Support ] * [ Redirect-Address-Type ] * [ Redirect-Server-Address ] * * [ AVP ] */ static int unpackGxRedirectInformation ( unsigned char *buf, uint32_t length, GxRedirectInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, redirect_support, buf, length, offset ); UNPACK_BASIC( data, redirect_address_type, buf, length, offset ); UNPACK_OCTETSTRING( data, redirect_server_address, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxFailedAvp * * Desc: Unpack the specified buffer into GxFailedAvp * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Failed-AVP ::= <AVP Header: 279> * 1* { AVP } */ static int unpackGxFailedAvp ( unsigned char *buf, uint32_t length, GxFailedAvp *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxRoutingRuleRemove * * Desc: Unpack the specified buffer into GxRoutingRuleRemove * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Rule-Remove ::= <AVP Header: 1075> * * [ Routing-Rule-Identifier ] * * [ AVP ] */ static int unpackGxRoutingRuleRemove ( unsigned char *buf, uint32_t length, GxRoutingRuleRemove *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_LIST_OCTETSTRING( data, routing_rule_identifier, GxRoutingRuleIdentifierOctetString, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxRoutingFilter * * Desc: Unpack the specified buffer into GxRoutingFilter * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Routing-Filter ::= <AVP Header: 1078> * { Flow-Description } * { Flow-Direction } * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * * [ AVP ] */ static int unpackGxRoutingFilter ( unsigned char *buf, uint32_t length, GxRoutingFilter *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, flow_description, buf, length, offset ); UNPACK_BASIC( data, flow_direction, buf, length, offset ); UNPACK_OCTETSTRING( data, tos_traffic_class, buf, length, offset ); UNPACK_OCTETSTRING( data, security_parameter_index, buf, length, offset ); UNPACK_OCTETSTRING( data, flow_label, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxCoaInformation * * Desc: Unpack the specified buffer into GxCoaInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * CoA-Information ::= <AVP Header: 1039> * { Tunnel-Information } * { CoA-IP-Address } * * [ AVP ] */ static int unpackGxCoaInformation ( unsigned char *buf, uint32_t length, GxCoaInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_STRUCT( data, tunnel_information, buf, length, offset, unpackGxTunnelInformation ); UNPACK_BASIC( data, coa_ip_address, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxGrantedServiceUnit * * Desc: Unpack the specified buffer into GxGrantedServiceUnit * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Granted-Service-Unit ::= <AVP Header: 431> * [ Tariff-Time-Change ] * [ CC-Time ] * [ CC-Money ] * [ CC-Total-Octets ] * [ CC-Input-Octets ] * [ CC-Output-Octets ] * [ CC-Service-Specific-Units ] * * [ AVP ] */ static int unpackGxGrantedServiceUnit ( unsigned char *buf, uint32_t length, GxGrantedServiceUnit *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, tariff_time_change, buf, length, offset ); UNPACK_BASIC( data, cc_time, buf, length, offset ); UNPACK_STRUCT( data, cc_money, buf, length, offset, unpackGxCcMoney ); UNPACK_BASIC( data, cc_total_octets, buf, length, offset ); UNPACK_BASIC( data, cc_input_octets, buf, length, offset ); UNPACK_BASIC( data, cc_output_octets, buf, length, offset ); UNPACK_BASIC( data, cc_service_specific_units, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxCcMoney * * Desc: Unpack the specified buffer into GxCcMoney * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * CC-Money ::= <AVP Header: 413> * { Unit-Value } * [ Currency-Code ] */ static int unpackGxCcMoney ( unsigned char *buf, uint32_t length, GxCcMoney *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_STRUCT( data, unit_value, buf, length, offset, unpackGxUnitValue ); UNPACK_BASIC( data, currency_code, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxApplicationDetectionInformation * * Desc: Unpack the specified buffer into GxApplicationDetectionInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Application-Detection-Information ::= <AVP Header: 1098> * { TDF-Application-Identifier } * [ TDF-Application-Instance-Identifier ] * * [ Flow-Information ] * * [ AVP ] */ static int unpackGxApplicationDetectionInformation ( unsigned char *buf, uint32_t length, GxApplicationDetectionInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_OCTETSTRING( data, tdf_application_identifier, buf, length, offset ); UNPACK_OCTETSTRING( data, tdf_application_instance_identifier, buf, length, offset ); UNPACK_LIST_STRUCT( data, flow_information, GxFlowInformation, buf, length, offset, unpackGxFlowInformation ); return *offset <= length; } /* * * Fun: unpackGxFlows * * Desc: Unpack the specified buffer into GxFlows * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * Flows ::= <AVP Header: 510> * { Media-Component-Number } * * [ Flow-Number ] * * [ Content-Version ] * [ Final-Unit-Action ] * [ Media-Component-Status ] * * [ AVP ] */ static int unpackGxFlows ( unsigned char *buf, uint32_t length, GxFlows *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, media_component_number, buf, length, offset ); UNPACK_LIST_BASIC( data, flow_number, uint32_t, buf, length, offset ); UNPACK_LIST_BASIC( data, content_version, uint64_t, buf, length, offset ); UNPACK_BASIC( data, final_unit_action, buf, length, offset ); UNPACK_BASIC( data, media_component_status, buf, length, offset ); return *offset <= length; } /* * * Fun: unpackGxUserCsgInformation * * Desc: Unpack the specified buffer into GxUserCsgInformation * * Ret: 0 * * Notes: None * * File: gx_pack.c * * * * User-CSG-Information ::= <AVP Header: 2319> * { CSG-Id } * { CSG-Access-Mode } * [ CSG-Membership-Indication ] */ static int unpackGxUserCsgInformation ( unsigned char *buf, uint32_t length, GxUserCsgInformation *data, uint32_t *offset ) { UNPACK_PRESENCE( data, presence, buf, length, offset ); UNPACK_BASIC( data, csg_id, buf, length, offset ); UNPACK_BASIC( data, csg_access_mode, buf, length, offset ); UNPACK_BASIC( data, csg_membership_indication, buf, length, offset ); return *offset <= length; }
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/pfcp_gx.c
<filename>pfcp_messages/pfcp_gx.c /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <rte_ip.h> #include <rte_udp.h> #include <rte_cfgfile.h> #include <rte_string_fns.h> //REVIEW: Need to check this: No need to add this header files #include "pfcp.h" #include "pfcp_enum.h" #include "cp_config.h" #include "cp_stats.h" #include "gx.h" #include "sm_enum.h" #include "sm_struct.h" #include "pfcp_util.h" #include "pfcp_session.h" #include "pfcp_messages.h" #include "pfcp_messages_encoder.h" #include "cp_timer.h" #include "gw_adapter.h" #include "predef_rule_init.h" #include "gtp_ies_decoder.h" #include "enc_dec_bits.h" #define PRESENT 1 #define NUM_VALS 16 /* Default Bearer Indication Values */ #define BIND_TO_DEFAULT_BEARER 0 #define BIND_TO_APPLICABLE_BEARER 1 /* Default Bearer Indication Values */ #define SET_EVENT(val,event) (val |= (1UL<<event)) extern int pfcp_fd; extern int pfcp_fd_v6; extern int s5s8_fd; extern int s5s8_fd_v6; extern socklen_t s5s8_sockaddr_len; extern socklen_t s5s8_sockaddr_ipv6_len; extern socklen_t s11_mme_sockaddr_len; extern socklen_t s11_mme_sockaddr_ipv6_len; extern int clSystemLog; /* Assign the UE requested qos to default bearer*/ static int check_ue_requested_qos(pdn_connection *pdn) { if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"pdn_connection node is NULL\n", LOG_VALUE); return -1; } eps_bearer *bearer = NULL; int ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } bearer = pdn->eps_bearers[ebi_index]; if (bearer->qos.qci != 0) { pdn->policy.default_bearer_qos_valid = TRUE; memcpy(&pdn->policy.default_bearer_qos, &bearer->qos, sizeof(bearer_qos_ie)); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"UE requested bearer qos is NULL\n", LOG_VALUE); return -1; } return 0; } /** * @brief : Fill UE context default bearer information of default_eps_bearer_qos from CCA * @param : context , eps bearer context * @param : cca * @return : Returns 0 in case of success , -1 otherwise * */ static int store_default_bearer_qos_in_policy(pdn_connection *pdn, GxDefaultEpsBearerQos qos) { int ebi_index = 0; eps_bearer *bearer = NULL; if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "PDN Connection Node is NULL\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = pdn->eps_bearers[ebi_index]; if(bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Bearer not found for ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn->policy.default_bearer_qos_valid = TRUE; bearer_qos_ie *def_qos = &pdn->policy.default_bearer_qos; if (qos.presence.qos_class_identifier == PRESENT) { def_qos->qci = qos.qos_class_identifier; bearer->qos.qci = qos.qos_class_identifier; } if(qos.presence.allocation_retention_priority == PRESENT) { if(qos.allocation_retention_priority.presence.priority_level == PRESENT){ def_qos->arp.priority_level = qos.allocation_retention_priority.priority_level; bearer->qos.arp.priority_level = qos.allocation_retention_priority.priority_level; } if(qos.allocation_retention_priority.presence.pre_emption_capability == PRESENT){ def_qos->arp.preemption_capability = qos.allocation_retention_priority.pre_emption_capability; bearer->qos.arp.preemption_capability = qos.allocation_retention_priority.pre_emption_capability; } if(qos.allocation_retention_priority.presence.pre_emption_vulnerability == PRESENT){ def_qos->arp.preemption_vulnerability = qos.allocation_retention_priority.pre_emption_vulnerability; bearer->qos.arp.preemption_vulnerability = qos.allocation_retention_priority.pre_emption_vulnerability; } } return 0; } void update_bearer_qos(eps_bearer *bearer) { /* Firest reset to 0*/ memset(&bearer->qos, 0, sizeof(bearer_qos_ie)); for(int itr = 0; itr < bearer->num_dynamic_filters; itr++){ /* QCI and ARP value same for all rule in single bearer*/ dynamic_rule_t *dynamic_rule = bearer->dynamic_rules[itr]; bearer->qos.qci = dynamic_rule->qos.qci; bearer->qos.arp.priority_level = dynamic_rule->qos.arp.priority_level; bearer->qos.arp.preemption_capability = dynamic_rule->qos.arp.preemption_capability; bearer->qos.arp.preemption_vulnerability = dynamic_rule->qos.arp.preemption_vulnerability; /* Bearer GBR will be SUM of all GBR*/ bearer->qos.ul_gbr += dynamic_rule->qos.ul_gbr; bearer->qos.dl_gbr += dynamic_rule->qos.dl_gbr; /* Bearer MBR will be max of MBRs of all the rules*/ if(bearer->qos.ul_mbr < dynamic_rule->qos.ul_mbr){ bearer->qos.ul_mbr = dynamic_rule->qos.ul_mbr; } if(bearer->qos.dl_mbr < dynamic_rule->qos.dl_mbr){ bearer->qos.dl_mbr = dynamic_rule->qos.dl_mbr; } } return; } /** * @brief : Extracts data form sdf string str and fills into packet filter * @param : str * @param : pkt_filter * @return : Returns 0 in case of success , -1 otherwise */ static int fill_sdf_strctr(char *str, sdf_pkt_fltr *pkt_filter) { int nb_token = 0; char *str_fld[NUM_VALS]; int offset = 0; /* VG: format of sdf string is */ /* action dir fom src_ip src_port to dst_ip dst_port" */ nb_token = rte_strsplit(str, strnlen(str,MAX_SDF_DESC_LEN), str_fld, NUM_VALS, ' '); if (nb_token > NUM_VALS) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:Reach Max limit for sdf string \n", LOG_VALUE); return -1; } for(int indx=0; indx < nb_token; indx++){ if( indx == 0 ){ if(strncmp(str_fld[indx], "permit", NUM_VALS) != 0 ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:Skip sdf filling for IP filter rule action : %s \n", LOG_VALUE, str_fld[indx]); return -1; } } else if(indx == 2) { pkt_filter->proto_id = atoi(str_fld[indx]); } else if (indx == 4){ if(strncmp(str_fld[indx], "any", NUM_VALS) != 0 ){ if( strstr(str_fld[indx], "/") != NULL) { int ip_token = 0; char *ip_fld[2]; ip_token = rte_strsplit(str_fld[indx], strnlen(str_fld[indx],MAX_SDF_DESC_LEN), ip_fld, 2, '/'); if (ip_token > 2) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:Reach Max limit for sdf src ip \n", LOG_VALUE); return -1; } if(strstr(ip_fld[0], ":") != NULL){ if(inet_pton(AF_INET6, (const char *) ip_fld[0], (void *)(&pkt_filter->ulocalip.local_ip6_addr)) < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:conv of src ip fails \n", LOG_VALUE); return -1; } pkt_filter->local_ip_mask = atoi(ip_fld[1]); pkt_filter->v6 = PRESENT; }else if(strstr(ip_fld[0], ".") != NULL){ if(inet_pton(AF_INET, (const char *) ip_fld[0], (void *)(&pkt_filter->ulocalip.local_ip_addr)) < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:conv of src ip fails \n", LOG_VALUE); return -1; } pkt_filter->local_ip_mask = atoi(ip_fld[1]); pkt_filter->v4 = PRESENT; } } else { if(strstr(str_fld[indx], ":") != NULL){ if(inet_pton(AF_INET6, (const char *) str_fld[indx], (void *)(&pkt_filter->ulocalip.local_ip6_addr)) < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "AVP:conv of src ip fails \n", LOG_VALUE); return -1; } pkt_filter->v6 = PRESENT; }else if(strstr(str_fld[indx], ".") != NULL){ if(inet_pton(AF_INET, (const char *) str_fld[indx], (void *)(&pkt_filter->ulocalip.local_ip_addr)) < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "AVP:conv of src ip fails \n", LOG_VALUE); return -1; } pkt_filter->v4 = PRESENT; } } } } else if(indx == 5){ /*TODO VG : handling of multiple ports p1,p2,p3 etc*/ if(strncmp(str_fld[indx], "to", NUM_VALS) != 0 ){ if( strstr(str_fld[indx], "-") != NULL) { int port_token = 0; char *port_fld[2]; port_token = rte_strsplit(str_fld[indx], strnlen(str_fld[indx],MAX_SDF_DESC_LEN), port_fld, 2, '-'); if (port_token > 2) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "AVP:Reach Max limit for sdf src port \n", LOG_VALUE); return -1; } pkt_filter->local_port_low = atoi(port_fld[0]); pkt_filter->local_port_high = atoi(port_fld[1]); } else { pkt_filter->local_port_low = atoi(str_fld[indx]); pkt_filter->local_port_high = atoi(str_fld[indx]); } }else { offset++; } } else if (indx + offset == 7){ if(strncmp(str_fld[indx], "any", NUM_VALS) != 0 ){ if( strstr(str_fld[indx], "/") != NULL) { int ip_token = 0; char *ip_fld[2]; ip_token = rte_strsplit(str_fld[indx], strnlen(str_fld[indx],MAX_SDF_DESC_LEN), ip_fld, 2, '/'); if (ip_token > 2) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:Reach Max limit for sdf dst ip \n", LOG_VALUE); return -1; } if(strstr(ip_fld[0], ":") != NULL){ if(inet_pton(AF_INET6, (const char *) ip_fld[0], (void *)(&pkt_filter->uremoteip.remote_ip6_addr)) < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:conv of dst ip fails \n", LOG_VALUE); return -1; } pkt_filter->remote_ip_mask = atoi(ip_fld[1]); pkt_filter->v6 = PRESENT; }else if(strstr(ip_fld[0], ".") != NULL){ if(inet_pton(AF_INET, (const char *) ip_fld[0], (void *)(&pkt_filter->uremoteip.remote_ip_addr)) < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:conv of dst ip fails \n", LOG_VALUE); return -1; } pkt_filter->v4 = PRESENT; pkt_filter->remote_ip_mask = atoi(ip_fld[1]); } } else{ if(strstr(str_fld[indx], ":") != NULL){ if(inet_pton(AF_INET6, (const char *) str_fld[indx], (void *)(&pkt_filter->uremoteip.remote_ip6_addr)) < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:conv of dst ip \n", LOG_VALUE); return -1; } pkt_filter->v6 = PRESENT; }else if(strstr(str_fld[indx], ".") != NULL) { if(inet_pton(AF_INET, (const char *) str_fld[indx], (void *)(&pkt_filter->uremoteip.remote_ip_addr)) < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:conv of dst ip \n", LOG_VALUE); return -1; } pkt_filter->v4 = PRESENT; } } } } else if(indx + offset == 8){ /*TODO VG : handling of multiple ports p1,p2,p3 etc*/ if( strstr(str_fld[indx], "-") != NULL) { int port_token = 0; char *port_fld[2]; port_token = rte_strsplit(str_fld[indx], strnlen(str_fld[indx],MAX_SDF_DESC_LEN), port_fld, 2, '-'); if (port_token > 2) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:Reach Max limit for sdf dst port\n", LOG_VALUE); return -1; } pkt_filter->remote_port_low = atoi(port_fld[0]); pkt_filter->remote_port_high = atoi(port_fld[1]); } else { pkt_filter->remote_port_low = atoi(str_fld[indx]); pkt_filter->remote_port_high = atoi(str_fld[indx]); } } } return 0; } static struct mtr_entry * get_mtr_entry(uint16_t idx) { void *mtr_rule = NULL; struct mtr_entry *mtr = NULL; int ret = get_predef_rule_entry(idx, MTR_HASH, GET_RULE, (void **)&mtr_rule); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to Get MTR Rule from the internal table" "for Mtr_Indx: %u\n", LOG_VALUE, idx); return NULL; } mtr = (struct mtr_entry *)mtr_rule; return mtr; } /** * @brief : Fills dynamic rule from given charging rule definition , and adds mapping of rule and bearer id * @param : predefined_rule * @param : rule_name * @return : Returns 0 in case of success , -1 otherwise */ static int fill_predefined_rule_in_bearer(pdn_connection *pdn, dynamic_rule_t *pdef_rule, rule_name_key_t *rule_name) { uint32_t idx = 0; /* Retrive the PCC rule based on the rule name */ pcc_rule_name rule = {0}; memset(rule.rname, '\0', sizeof(rule.rname)); strncpy(rule.rname, rule_name->rule_name, sizeof(rule.rname)); struct pcc_rules *pcc = NULL; pcc = get_predef_pcc_rule_entry(&rule, GET_RULE); if (pcc == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to get PCC Rule by PCC rule name receivd in" "AVP charging rule name for Rule_Name: %s\n", LOG_VALUE, rule_name->rule_name); return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } pdef_rule->predefined_rule = TRUE; pdef_rule->online = pcc->online; pdef_rule->offline = pcc->offline; pdef_rule->flow_status = pcc->flow_status; pdef_rule->rating_group = pcc->rating_group; pdef_rule->reporting_level = pcc->report_level; pdef_rule->precedence = pcc->precedence; pdef_rule->service_id = pcc->service_id; if (pcc->sdf_idx_cnt) { pdef_rule->num_flw_desc = pcc->sdf_idx_cnt; /* Retrive the SDF rule based on the SDF Index */ for (idx = 0; idx < pcc->sdf_idx_cnt; idx++) { void *sdf_rule_t = NULL; pkt_fltr *tmp_sdf = NULL; int ret = get_predef_rule_entry(pcc->sdf_idx[idx], SDF_HASH, GET_RULE, (void **)&sdf_rule_t); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to Get SDF Rule from the internal table" "for SDF_Indx: %u\n", LOG_VALUE, pcc->sdf_idx[idx]); continue; } /* Typecast sdf rule */ tmp_sdf = (pkt_fltr *)sdf_rule_t; if (tmp_sdf == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed not found the sdf rule" "for SDF_Indx: %u\n", LOG_VALUE, pcc->sdf_idx[idx]); continue; } pdef_rule->flow_desc[idx].flow_direction = tmp_sdf->direction; pdef_rule->flow_desc[idx].sdf_flw_desc.proto_id = tmp_sdf->proto; pdef_rule->flow_desc[idx].sdf_flw_desc.proto_mask = tmp_sdf->proto_mask; pdef_rule->flow_desc[idx].sdf_flw_desc.direction = tmp_sdf->direction; pdef_rule->flow_desc[idx].sdf_flw_desc.local_ip_mask = tmp_sdf->local_ip_mask; pdef_rule->flow_desc[idx].sdf_flw_desc.remote_ip_mask = tmp_sdf->remote_ip_mask; pdef_rule->flow_desc[idx].sdf_flw_desc.local_port_low = ntohs(tmp_sdf->local_port_low); pdef_rule->flow_desc[idx].sdf_flw_desc.local_port_high = ntohs(tmp_sdf->local_port_high); pdef_rule->flow_desc[idx].sdf_flw_desc.remote_port_low = ntohs(tmp_sdf->remote_port_low); pdef_rule->flow_desc[idx].sdf_flw_desc.remote_port_high = ntohs(tmp_sdf->remote_port_high); if(tmp_sdf->v4){ pdef_rule->flow_desc[idx].sdf_flw_desc.v4 = PRESENT; pdef_rule->flow_desc[idx].sdf_flw_desc.ulocalip.local_ip_addr = tmp_sdf->local_ip_addr; pdef_rule->flow_desc[idx].sdf_flw_desc.uremoteip.remote_ip_addr = tmp_sdf->remote_ip_addr; } else { pdef_rule->flow_desc[idx].sdf_flw_desc.v6 = PRESENT; pdef_rule->flow_desc[idx].sdf_flw_desc.ulocalip.local_ip6_addr = tmp_sdf->local_ip6_addr; pdef_rule->flow_desc[idx].sdf_flw_desc.uremoteip.remote_ip6_addr = tmp_sdf->remote_ip6_addr; } pdef_rule->flow_desc[idx].sdf_flw_desc.action = pcc->rule_status; } }else{ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: NO SDF Rule present for Rule name%s\n", LOG_VALUE,rule_name->rule_name); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* Fill the MBR and GBR values */ if (pcc->qos.mtr_profile_index) { struct mtr_entry *mtr = NULL; mtr = get_mtr_entry(pcc->qos.mtr_profile_index); if (mtr != NULL) { pdef_rule->qos.ul_mbr = mtr->ul_mbr; pdef_rule->qos.dl_mbr = mtr->dl_mbr; pdef_rule->qos.ul_gbr = mtr->ul_gbr; pdef_rule->qos.dl_gbr = mtr->dl_gbr; }else{ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: NO MTR Rule present for Rule name%s\n", LOG_VALUE,rule_name->rule_name); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } /* Fill the UE requested qos in the bearer */ int ebi_index = 0; ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* TODO: Need to re-vist this code */ eps_bearer *bearer = NULL; bearer = pdn->eps_bearers[ebi_index]; if (bearer->qos.qci != 0) { pdn->policy.default_bearer_qos_valid = TRUE; memcpy(&pdn->policy.default_bearer_qos, &bearer->qos, sizeof(bearer_qos_ie)); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"UE requested bearer qos is NULL\n", LOG_VALUE); return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } /* QoS and ARP not there then use UE request qos */ if(pcc->qos.qci == 0){ memcpy(&pdef_rule->qos, &bearer->qos, sizeof(bearer_qos_ie)); }else { pdef_rule->qos.qci = pcc->qos.qci; pdef_rule->qos.arp.priority_level = pcc->qos.arp.priority_level; pdef_rule->qos.arp.preemption_capability = pcc->qos.arp.pre_emption_capability; pdef_rule->qos.arp.preemption_vulnerability = pcc->qos.arp.pre_emption_vulnerability; } /* Fill the rule name in bearer */ rule_name_key_t key = {0}; strncpy(key.rule_name, (char *)(pcc->rule_name), sizeof(pcc->rule_name)); memset(pdef_rule->rule_name, '\0', sizeof(pdef_rule->rule_name)); strncpy(pdef_rule->rule_name, (char *)pcc->rule_name, sizeof(pcc->rule_name)); return 0; } /** * @brief : Fills dynamic rule from given charging rule definition , and adds mapping of rule and bearer id * @param : dynamic_rule * @param : rule_definition * @return : Returns 0 in case of success , -1 otherwise */ static int fill_charging_rule_definition(dynamic_rule_t *dynamic_rule, GxChargingRuleDefinition *rule_definition) { int32_t idx = 0; if (rule_definition->presence.online == PRESENT) dynamic_rule->online = rule_definition->online; if (rule_definition->presence.offline == PRESENT) dynamic_rule->offline = rule_definition->offline; if (rule_definition->presence.flow_status == PRESENT) dynamic_rule->flow_status = rule_definition->flow_status; if (rule_definition->presence.reporting_level == PRESENT) dynamic_rule->reporting_level = rule_definition->reporting_level; if (rule_definition->presence.precedence == PRESENT) dynamic_rule->precedence = rule_definition->precedence; if (rule_definition->presence.service_identifier == PRESENT) dynamic_rule->service_id = rule_definition->service_identifier; if (rule_definition->presence.rating_group == PRESENT) dynamic_rule->rating_group = rule_definition->rating_group; if (rule_definition->presence.default_bearer_indication == PRESENT) dynamic_rule->def_bearer_indication = rule_definition->default_bearer_indication; else dynamic_rule->def_bearer_indication = BIND_TO_APPLICABLE_BEARER; if (rule_definition->presence.af_charging_identifier == PRESENT) { /* CHAR*/ memcpy(dynamic_rule->af_charging_id_string, rule_definition->af_charging_identifier.val, rule_definition->af_charging_identifier.len); } if (rule_definition->presence.flow_information == PRESENT) { dynamic_rule->num_flw_desc = rule_definition->flow_information.count; for(idx = 0; idx < rule_definition->flow_information.count; idx++) { if ((rule_definition->flow_information).list[idx].presence.flow_direction == PRESENT) { dynamic_rule->flow_desc[idx].flow_direction = (rule_definition->flow_information).list[idx].flow_direction; } /* CHAR*/ if ((rule_definition->flow_information).list[idx].presence.flow_description == PRESENT) { memcpy(dynamic_rule->flow_desc[idx].sdf_flow_description, (rule_definition->flow_information).list[idx].flow_description.val, (rule_definition->flow_information).list[idx].flow_description.len); dynamic_rule->flow_desc[idx].flow_desc_len = (rule_definition->flow_information).list[idx].flow_description.len; fill_sdf_strctr(dynamic_rule->flow_desc[idx].sdf_flow_description, &(dynamic_rule->flow_desc[idx].sdf_flw_desc)); /*VG assign direction in flow desc */ dynamic_rule->flow_desc[idx].sdf_flw_desc.direction =(uint8_t) (rule_definition->flow_information).list[idx].flow_direction; } } } if(rule_definition->presence.qos_information == PRESENT) { GxQosInformation *qos = &(rule_definition->qos_information); dynamic_rule->qos.qci = qos->qos_class_identifier; if(qos->allocation_retention_priority.presence.priority_level) dynamic_rule->qos.arp.priority_level = qos->allocation_retention_priority.priority_level; if(qos->allocation_retention_priority.presence.pre_emption_capability) dynamic_rule->qos.arp.preemption_capability = qos->allocation_retention_priority.pre_emption_capability; if(qos->allocation_retention_priority.presence.pre_emption_vulnerability) dynamic_rule->qos.arp.preemption_vulnerability = qos->allocation_retention_priority.pre_emption_vulnerability; dynamic_rule->qos.ul_mbr = qos->max_requested_bandwidth_ul; dynamic_rule->qos.dl_mbr = qos->max_requested_bandwidth_dl; dynamic_rule->qos.ul_gbr = qos->guaranteed_bitrate_ul; dynamic_rule->qos.dl_gbr = qos->guaranteed_bitrate_dl; } if (rule_definition->presence.charging_rule_name == PRESENT) { rule_name_key_t key = {0}; /* Commenting for compliation error Need to check id.bearer_id = bearer_id; */ strncpy(key.rule_name, (char *)(rule_definition->charging_rule_name.val), rule_definition->charging_rule_name.len); memset(dynamic_rule->rule_name, '\0', sizeof(dynamic_rule->rule_name)); strncpy(dynamic_rule->rule_name, (char *)rule_definition->charging_rule_name.val, rule_definition->charging_rule_name.len); } return 0; } /** * @brief : store the event tigger value received in CCA * @param : pdn * @param : GxEventTriggerList * @return : Returns 0 in case of success */ static int store_event_trigger(pdn_connection *pdn, GxEventTriggerList *event_trigger) { if(event_trigger != NULL) { for(uint8_t i = 0; i < event_trigger->count; i++) { int32_t val = event_trigger->list[i]; //pdn->context->event_trigger = val; //set_event_trigger_bit(pdn->context) SET_EVENT(pdn->context->event_trigger, val); } } return 0; } /** * @brief : Delete the dynamic rule entry from the bearer * @param : bearer, bearer from which rule should be remove * @param : rule_name, rule name that should be remove * @return : Returns Nothing */ static void delete_bearer_rule(eps_bearer *bearer, char *rule_name){ uint8_t flag = 0; for(uint8_t itr = 0; itr < bearer->num_dynamic_filters; itr++){ if(strncmp(rule_name, bearer->dynamic_rules[itr]->rule_name, sizeof(bearer->dynamic_rules[itr]->rule_name)) == 0){ flag = 1; rte_free(bearer->dynamic_rules[itr]); bearer->dynamic_rules[itr] = NULL; } if(flag == 1 && itr != bearer->num_dynamic_filters - 1){ bearer->dynamic_rules[itr] = bearer->dynamic_rules[itr + 1]; } } if(flag){ bearer->num_dynamic_filters--; bearer->dynamic_rules[bearer->num_dynamic_filters] = NULL; }else{ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Given rule name %s not " "Found in bearer to remove\n", LOG_VALUE, rule_name); } if(bearer->qos_bearer_check == PRESENT) { update_bearer_qos(bearer); } return; } /** * @brief : Update or Add new predefined rule into the bearer * @param : bearer, bearer for which rule need to update * @param : prdef_rule, The rule that need to update or add * @param : rule_action, Action that need to perform on bearer either update a rule or add a new rule * @return : Returns 0 on success */ static int update_prdef_bearer_rule(eps_bearer *bearer, dynamic_rule_t *pdef_rule, enum rule_action_t rule_action) { if(rule_action == RULE_ACTION_ADD) { bearer->prdef_rules[bearer->num_prdef_filters] = rte_zmalloc_socket(NULL, sizeof(dynamic_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (bearer->prdef_rules[bearer->num_prdef_filters] == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to allocate predefined rule memory " "structure: %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_NO_MEMORY_AVAILABLE; } memcpy((bearer->prdef_rules[bearer->num_prdef_filters]), pdef_rule, sizeof(dynamic_rule_t)); bearer->num_prdef_filters++; } else { for(uint8_t itr = 0; itr < bearer->num_prdef_filters; itr++){ if(strncmp(pdef_rule->rule_name, bearer->prdef_rules[itr]->rule_name, sizeof(pdef_rule->rule_name)) == 0) { memset(bearer->prdef_rules[itr], 0, sizeof(dynamic_rule_t)); memcpy((bearer->prdef_rules[itr]), pdef_rule, sizeof(dynamic_rule_t)); break; } } } return 0; } /** * @brief : Update or Add new dynamic rule into the bearer * @param : bearer, bearer for which rule need to update * @param : dyn_rule, The rule that need to update or add * @param : rule_action, Action that need to perform on bearer either update a rule or add a new rule * @return : Returns 0 on success */ static int update_bearer_rule(eps_bearer *bearer, dynamic_rule_t *dyn_rule, enum rule_action_t rule_action) { if(rule_action == RULE_ACTION_ADD) { /* As adding new rule so both TFT and QoS should modify*/ bearer->flow_desc_check = PRESENT; bearer->qos_bearer_check = PRESENT; add_pdr_qer_for_rule(bearer, FALSE); bearer->dynamic_rules[bearer->num_dynamic_filters] = rte_zmalloc_socket(NULL, sizeof(dynamic_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (bearer->dynamic_rules[bearer->num_dynamic_filters] == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to allocate dynamic rule memory " "structure: %s \n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_NO_MEMORY_AVAILABLE; } fill_pfcp_entry(bearer, dyn_rule); memcpy((bearer->dynamic_rules[bearer->num_dynamic_filters]), dyn_rule, sizeof(dynamic_rule_t)); bearer->num_dynamic_filters++; if(bearer->qos_bearer_check == PRESENT) { update_bearer_qos(bearer); } }else { for(uint8_t itr = 0; itr < bearer->num_dynamic_filters; itr++){ if(strncmp(dyn_rule->rule_name, bearer->dynamic_rules[itr]->rule_name, sizeof(dyn_rule->rule_name)) == 0){ /* Reset pckt_fltr_identifier reassign at time of Update bearer Request*/ for(uint8_t i = 0; i < bearer->dynamic_rules[itr]->num_flw_desc; i++){ uint8_t pkt_filter_id = bearer->dynamic_rules[itr]->flow_desc[i].pckt_fltr_identifier; bearer->packet_filter_map[pkt_filter_id] = NOT_PRESENT; } bearer->flow_desc_check = compare_flow_description(bearer->dynamic_rules[itr],dyn_rule); bearer->qos_bearer_check = compare_bearer_qos(bearer->dynamic_rules[itr],dyn_rule); bearer->arp_bearer_check = compare_bearer_arp(bearer->dynamic_rules[itr],dyn_rule); if(bearer->flow_desc_check == PRESENT || bearer->qos_bearer_check == PRESENT) { memset(bearer->dynamic_rules[itr], 0, sizeof(dynamic_rule_t)); memcpy((bearer->dynamic_rules[itr]), dyn_rule, sizeof(dynamic_rule_t)); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"flow_description and QoS not " "change & Not expected\n", LOG_VALUE); return -1; } int pdr_count = 0; for(uint8_t itr2 = 0; itr2 < bearer->pdr_count; itr2++){ if(pdr_count == 2) break; if(strncmp(dyn_rule->rule_name, bearer->pdrs[itr2]->rule_name, sizeof(dyn_rule->rule_name)) == 0) { if(pdr_count < 2){ bearer->dynamic_rules[itr]->pdr[pdr_count++] = bearer->pdrs[itr2]; }else{ break; } fill_pdr_sdf_qer(bearer->pdrs[itr2], dyn_rule); } } if(bearer->qos_bearer_check == PRESENT) { update_bearer_qos(bearer); } break; } } } return 0; } /** * @brief : Creates and fills dynamic/predefined rules for given bearer from received cca * @param : context , eps bearer context * @param : cca * @param : bearer_id * @return : Returns 0 in case of success , -1 otherwise */ static int store_dynamic_rules_in_policy(pdn_connection *pdn, GxChargingRuleInstallList * charging_rule_install, GxChargingRuleRemoveList * charging_rule_remove) { rule_name_key_t rule_name = {0}; GxChargingRuleDefinition *rule_definition = NULL; eps_bearer *bearer = NULL; int8_t bearer_index = -1; /* Clear Policy in PDN */ pdn->policy.count = 0; pdn->policy.num_charg_rule_install = 0; pdn->policy.num_charg_rule_modify = 0; pdn->policy.num_charg_rule_delete = 0; dynamic_rule_t *rule = NULL; uint8_t num_rule_filters = 0; int ret = 0; if(charging_rule_install != NULL) { for (int32_t idx1 = 0; idx1 < charging_rule_install->count; idx1++) { if (charging_rule_install->list[idx1].presence.charging_rule_definition == PRESENT) { for(int32_t idx2 = 0; idx2 < charging_rule_install->list[idx1].charging_rule_definition.count; idx2++) { rule_definition = &(charging_rule_install->list[idx1].charging_rule_definition.list[idx2]); if (rule_definition->presence.charging_rule_name == PRESENT) { memset(rule_name.rule_name, '\0', sizeof(rule_name.rule_name)); snprintf(rule_name.rule_name, RULE_NAME_LEN,"%s%d", rule_definition->charging_rule_name.val, pdn->call_id); if(pdn->policy.pcc_rule[pdn->policy.count] == NULL) { pdn->policy.pcc_rule[pdn->policy.count] = rte_zmalloc_socket(NULL, sizeof(pcc_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); } if(pdn->policy.pcc_rule[pdn->policy.count] == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate" "memory to pcc rule structure\n", LOG_VALUE); return GTPV2C_CAUSE_NO_MEMORY_AVAILABLE; } fill_charging_rule_definition(&(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule), rule_definition); pdn->policy.pcc_rule[pdn->policy.count]->predefined_rule = FALSE; /* Extract Bearer on basis of QCI and ARP value */ bearer = get_bearer(pdn, &pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule.qos); bearer_index = get_rule_name_entry(rule_name); if(bearer == NULL || bearer->num_dynamic_filters == 0) { if((bearer_index == -1) || (bearer != NULL && bearer->num_dynamic_filters == 0) || (pdn->eps_bearers[bearer_index] == NULL)){ pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_ADD; pdn->policy.count++; pdn->policy.num_charg_rule_install++; }else{ bearer = pdn->eps_bearers[bearer_index]; if(bearer->num_dynamic_filters > 1){ /* Remove the rule from older bearer and create new bearer */ /* Create a new bearer */ pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_ADD; pdn->policy.count++; pdn->policy.num_charg_rule_install++; if(pdn->policy.pcc_rule[pdn->policy.count] == NULL){ pdn->policy.pcc_rule[pdn->policy.count] = rte_zmalloc_socket(NULL, sizeof(pcc_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); } if(pdn->policy.pcc_rule[pdn->policy.count] == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate" "memory to pcc rule structure\n", LOG_VALUE); return GTPV2C_CAUSE_NO_MEMORY_AVAILABLE; } /* Remove rule from older bearer */ fill_charging_rule_definition( &(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule), rule_definition); pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_MODIFY_REMOVE_RULE; bearer->action = RULE_ACTION_MODIFY_REMOVE_RULE; /* As Removing rule so both TFT and QoS should modify*/ bearer->flow_desc_check = PRESENT; bearer->qos_bearer_check = PRESENT; pdn->policy.num_charg_rule_modify++; pdn->policy.count++; }else{ update_bearer_rule(bearer, &(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule), RULE_ACTION_MODIFY); if(pdn->proc == HSS_INITIATED_SUB_QOS_MOD && bearer->arp_bearer_check == PRESENT) { /*Change arp values for all bearers*/ change_arp_for_ded_bearer(pdn, &(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule.qos)); } pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_MODIFY; bearer->action = RULE_ACTION_MODIFY; pdn->policy.count++; pdn->policy.num_charg_rule_modify++; } } } else { /* IF condition check is true this means * Rule is already installed in that bearer * the rule is updated that's why we recived the same * same rule for Update * Else recevied one new rule to add into the bearer * */ if(bearer->eps_bearer_id == (bearer_index + NUM_EBI_RESERVED)){ ret = update_bearer_rule(bearer, &(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule), RULE_ACTION_MODIFY); if(ret) return ret; pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_MODIFY; bearer->action = RULE_ACTION_MODIFY; pdn->policy.count++; pdn->policy.num_charg_rule_modify++; }else{ if(bearer_index == -1) { /* The rule is not with us*/ ret = update_bearer_rule(bearer, &(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule), RULE_ACTION_ADD); if(ret) return ret; pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_MODIFY_ADD_RULE; bearer->action = RULE_ACTION_MODIFY_ADD_RULE; pdn->policy.count++; pdn->policy.num_charg_rule_modify++; }else { /* The rule was previously installed on some other bearer*/ /* Removing that rule from the older bearer*/ if(pdn->eps_bearers[bearer_index]->num_dynamic_filters > 1){ pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_MODIFY_REMOVE_RULE; pdn->eps_bearers[bearer_index]->action = RULE_ACTION_MODIFY_REMOVE_RULE; /* As Removing rule so both TFT and QoS should modify*/ pdn->eps_bearers[bearer_index]->flow_desc_check = PRESENT; pdn->eps_bearers[bearer_index]->qos_bearer_check = PRESENT; pdn->policy.count++; pdn->policy.num_charg_rule_modify++; }else { pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_DELETE; pdn->eps_bearers[bearer_index]->action = RULE_ACTION_DELETE; pdn->policy.count++; pdn->policy.num_charg_rule_delete++; } /* Adding that rule to new bearer */ fill_charging_rule_definition( &(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule), rule_definition); update_bearer_rule(bearer, &(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule), RULE_ACTION_ADD); pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_MODIFY_ADD_RULE; bearer->action = RULE_ACTION_MODIFY_ADD_RULE; pdn->policy.count++; pdn->policy.num_charg_rule_modify++; } } } } else{ //TODO: Rule without name not possible; Log IT ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Charging rule name is not present\n",LOG_VALUE); return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } } } if (charging_rule_install->list[idx1].presence.charging_rule_name == PRESENT) { GxChargingRuleNameOctetString *rule_string = NULL; /* Predefined Rule: Received only rule name from pcrf */ for(int32_t idx2 = 0; idx2 < charging_rule_install->list[idx1].charging_rule_name.count; idx2++) { rule_string = &(charging_rule_install->list[idx1].charging_rule_name.list[idx2]); memset(rule_name.rule_name, '\0', sizeof(rule_name.rule_name)); snprintf(rule_name.rule_name, RULE_NAME_LEN, "%s", rule_string->val); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"PCRF Send Predefined Charging rule name: %s\n", LOG_VALUE, rule_name.rule_name); if(pdn->policy.pcc_rule[pdn->policy.count] == NULL){ pdn->policy.pcc_rule[pdn->policy.count] = rte_zmalloc_socket(NULL, sizeof(pcc_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); } if(pdn->policy.pcc_rule[pdn->policy.count] == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate" "memory to pcc rule structure\n", LOG_VALUE); return GTPV2C_CAUSE_NO_MEMORY_AVAILABLE; } pdn->policy.pcc_rule[pdn->policy.count]->predefined_rule = TRUE; ret = fill_predefined_rule_in_bearer(pdn, &(pdn->policy.pcc_rule[pdn->policy.count]->urule.pdef_rule), &rule_name); if(ret){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to fill_predefined_rule_in_bearer for rule name: %s\n", LOG_VALUE, rule_name.rule_name); return ret; } /* Extract Bearer on basis of QCI and ARP value */ bearer = get_bearer(pdn, &pdn->policy.pcc_rule[pdn->policy.count]->urule.pdef_rule.qos); if(bearer == NULL || bearer->num_prdef_filters == 0) { pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_ADD; pdn->policy.count++; pdn->policy.num_charg_rule_install++; } else { /* IF condition check is true this means * Rule is already installed in that bearer * the rule is updated that's why we recived the same * same rule for Update * Else recevied one new rule to add into the bearer */ if(bearer->eps_bearer_id == (get_rule_name_entry(rule_name) + NUM_EBI_RESERVED)){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"In Predefine Rule currently does not support RULE_ACTION_MODIFY\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; }else{ ret = update_prdef_bearer_rule(bearer, &(pdn->policy.pcc_rule[pdn->policy.count]->urule.pdef_rule), RULE_ACTION_ADD); if(ret) return ret; /* Adding rule to Hash as Rule End in Update bearer */ bearer_id_t *id = NULL; id = malloc(sizeof(bearer_id_t)); memset(id, 0 , sizeof(bearer_id_t)); int ebi_index = GET_EBI_INDEX(bearer->eps_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } id->bearer_id = ebi_index; if (add_rule_name_entry(rule_name, id) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add_rule_name_entry with rule_name\n", LOG_VALUE, rule_name.rule_name); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_MODIFY; bearer->action = RULE_ACTION_MODIFY; pdn->policy.count++; pdn->policy.num_charg_rule_modify++; } } }else{ if (charging_rule_install->list[idx1].presence.charging_rule_definition != PRESENT){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Charging rule name is not present\n",LOG_VALUE); return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } } } } if(charging_rule_remove != NULL) { for(int32_t idx1 = 0; idx1 < charging_rule_remove->count; idx1++) { if (charging_rule_remove->list[idx1].presence.charging_rule_name == PRESENT) { char rule_temp[RULE_NAME_LEN]; /* Get the rule name and only store the name in dynamic rule_t */ memset(rule_name.rule_name, '\0', RULE_NAME_LEN); memset(rule_temp, '\0', RULE_NAME_LEN); strncpy(rule_temp, (char *)charging_rule_remove->list[idx1].charging_rule_name.list[0].val, charging_rule_remove->list[idx1].charging_rule_name.list[0].len); if(pdn->policy.pcc_rule[pdn->policy.count] == NULL){ pdn->policy.pcc_rule[pdn->policy.count] = rte_zmalloc_socket(NULL, sizeof(pcc_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(pdn->policy.pcc_rule[pdn->policy.count] == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate" "memory to pcc rule structure\n", LOG_VALUE); return GTPV2C_CAUSE_NO_MEMORY_AVAILABLE; } } if(pdn->policy.pcc_rule[pdn->policy.count]->predefined_rule){ rule = &pdn->policy.pcc_rule[pdn->policy.count]->urule.pdef_rule; snprintf(rule_name.rule_name, RULE_NAME_LEN,"%s", rule_temp); }else{ rule = &pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule; snprintf(rule_name.rule_name, RULE_NAME_LEN,"%s%d",rule_temp, pdn->call_id); } memset(rule->rule_name, '\0', RULE_NAME_LEN); strncpy(rule->rule_name, (char *)(charging_rule_remove->list[idx1].charging_rule_name.list[0].val), (charging_rule_remove->list[idx1].charging_rule_name.list[0].len > RULE_NAME_LEN ? RULE_NAME_LEN : charging_rule_remove->list[idx1].charging_rule_name.list[0].len)); /* TODO: Need to remove comment */ int8_t bearer_identifer = get_rule_name_entry(rule_name); if (bearer_identifer >= 0) { bearer = pdn->eps_bearers[bearer_identifer]; if(pdn->policy.pcc_rule[pdn->policy.count]->predefined_rule) num_rule_filters = bearer->num_prdef_filters; else num_rule_filters = bearer->num_dynamic_filters; if(num_rule_filters > 1){ pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_MODIFY_REMOVE_RULE; bearer->action = RULE_ACTION_MODIFY_REMOVE_RULE; /* As Removing rule so both TFT and QoS should modify*/ bearer->flow_desc_check = PRESENT; bearer->qos_bearer_check = PRESENT; pdn->policy.num_charg_rule_modify++; } else { pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_DELETE; bearer->action = RULE_ACTION_DELETE; pdn->policy.num_charg_rule_delete++; } pdn->policy.count++; } } } } return 0; } /** * @brief : Set UE requested Bearer QoS. * @param : pdn, pdn connection details * @param : dynamic_rule, structure for store dynami rule. * @return : Returns 0 on success, -1 otherwise */ static int set_ue_requested_bearer_qos(pdn_connection *pdn, dynamic_rule_t *dynamic_rule) { int ebi_index = 0; eps_bearer *bearer = NULL; if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"pdn_connection node is NULL\n", LOG_VALUE); return -1; } ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } bearer = pdn->eps_bearers[ebi_index]; if (bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Bearer not found for ebi_index %d\n", LOG_VALUE, ebi_index); return -1; } dynamic_rule->qos.qci = bearer->qos.qci; dynamic_rule->qos.arp.priority_level = bearer->qos.arp.priority_level; dynamic_rule->qos.arp.preemption_capability = bearer->qos.arp.preemption_capability; dynamic_rule->qos.arp.preemption_vulnerability = bearer->qos.arp.preemption_vulnerability; dynamic_rule->qos.ul_mbr = bearer->qos.ul_mbr; dynamic_rule->qos.dl_mbr = bearer->qos.dl_mbr; dynamic_rule->qos.ul_gbr = bearer->qos.ul_gbr; dynamic_rule->qos.dl_gbr = bearer->qos.dl_gbr; return 0; } /** * @brief : Add EBI in rule name hash. * @param : rule_name, rule name * @param : call_id, call id * @param : ebi, EPS Bearer ID * @param : pdef_rule, specifies whether its a predefined rule or not * @return : Returns 0 on success, -1 otherwise */ static int add_ebi_rule_name_entry(char *rule_name, uint32_t call_id, uint8_t ebi, bool pdef_rule) { /* Adding rule and bearer id to a hash */ rule_name_key_t key = {0}; bearer_id_t *id; id = malloc(sizeof(bearer_id_t)); memset(id, 0 , sizeof(bearer_id_t)); int ebi_index = GET_EBI_INDEX(ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } id->bearer_id = ebi_index; if(pdef_rule){ snprintf(key.rule_name, RULE_NAME_LEN, "%s", rule_name); }else{ snprintf(key.rule_name, RULE_NAME_LEN, "%s%d", rule_name, call_id); } if (add_rule_name_entry(key, id) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add_rule_name_entry with rule_name\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } return 0; } /** * @brief : fill default sdf rule * @param : type, whether ipv4 or ipv6 * @param : index, array index * @param : sdf_rule_len, length of sdf rule * @param : dynamic_rule, default rule * @return : Returns nothing. */ static void fill_default_sdf_rule(uint8_t type, uint8_t index, uint8_t sdf_rule_len, dynamic_rule_t *dynamic_rule) { if(type == IPV4_ADDR_TYPE){ memcpy(dynamic_rule->flow_desc[index].sdf_flow_description, DEFAULT_SDF_RULE_IPV4, sdf_rule_len); } else { memcpy(dynamic_rule->flow_desc[index].sdf_flow_description, DEFAULT_SDF_RULE_IPV6, sdf_rule_len); } dynamic_rule->flow_desc[index].flow_desc_len = sdf_rule_len; fill_sdf_strctr(dynamic_rule->flow_desc[index].sdf_flow_description, &(dynamic_rule->flow_desc[index].sdf_flw_desc)); if ((index%2) == SOURCE_INTERFACE_VALUE_ACCESS) { dynamic_rule->flow_desc[index].sdf_flw_desc.direction = TFT_DIRECTION_UPLINK_ONLY; } else if ((index%2) == SOURCE_INTERFACE_VALUE_CORE) { dynamic_rule->flow_desc[index].sdf_flw_desc.direction = TFT_DIRECTION_DOWNLINK_ONLY; } } /** * @brief : Add default rule * @param : default_flow_status, flow status details * @param : default_precedence, Precedence details * @param : pdn, pdn connection details * @return : Returns 0 on success, -1 otherwise */ static int add_default_rule(uint8_t default_flow_status, uint8_t default_precedence, pdn_connection *pdn) { uint8_t sdf_rule_len = 0; dynamic_rule_t *dynamic_rule = NULL; dynamic_rule = &(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule); if(pdn->pdn_type.ipv4 == 1 && pdn->pdn_type.ipv6 == 1){ dynamic_rule->num_flw_desc = DEFAULT_NUM_SDF_RULE_v4_v6; } else { dynamic_rule->num_flw_desc = DEFAULT_NUM_SDF_RULE; } uint8_t count = 0; if(pdn->pdn_type.ipv4 == 1){ sdf_rule_len = strnlen(DEFAULT_SDF_RULE_IPV4, MAX_SDF_DESC_LEN); for(uint8_t itr = 0; itr < DEFAULT_NUM_SDF_RULE; ++itr){ fill_default_sdf_rule(IPV4_ADDR_TYPE, count++, sdf_rule_len, dynamic_rule); } } if ( pdn->pdn_type.ipv6 == 1){ sdf_rule_len = strnlen(DEFAULT_SDF_RULE_IPV6, MAX_SDF_DESC_LEN); for(uint8_t itr = 0; itr < DEFAULT_NUM_SDF_RULE; ++itr){ fill_default_sdf_rule(IPV6_ADDR_TYPE, count++, sdf_rule_len, dynamic_rule); } } dynamic_rule->precedence = default_precedence; dynamic_rule->flow_status = default_flow_status; return 0; } static void store_rule_qos_in_bearer(pdn_connection *pdn, bearer_qos_ie *rule_qos){ if(pdn == NULL || rule_qos == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" PDN or rule_qos is NULL" " So, Failed to update bearer QoS", LOG_VALUE); return; } int ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return; } eps_bearer *bearer = pdn->eps_bearers[ebi_index]; if(bearer == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No default bearer found for" " PDN", LOG_VALUE); return; } bearer->qos.qci = rule_qos->qci; /* bearer->qos.ul_mbr = rule_qos->ul_mbr; bearer->qos.dl_mbr = rule_qos->dl_mbr; bearer->qos.ul_gbr = rule_qos->ul_gbr; bearer->qos.dl_gbr = rule_qos->dl_gbr; */ bearer->qos.arp.preemption_vulnerability = rule_qos->arp.preemption_vulnerability; bearer->qos.arp.priority_level = rule_qos->arp.priority_level; bearer->qos.arp.preemption_capability = rule_qos->arp.preemption_capability; return; } /** * @brief : Search for rules on default bearer * @param : pdn, pdn connection details * @return : Returns 0 on success, -1 otherwise */ static int check_for_rules_on_default_bearer(pdn_connection *pdn) { uint8_t idx = 0; for (idx = 0; idx < pdn->policy.num_charg_rule_install; idx++) { if (!pdn->policy.pcc_rule[idx]->predefined_rule) { if ((BIND_TO_DEFAULT_BEARER == pdn->policy.pcc_rule[idx]->urule.dyn_rule.def_bearer_indication) || (compare_default_bearer_qos(&pdn->policy.default_bearer_qos, &pdn->policy.pcc_rule[idx]->urule.dyn_rule.qos) == 0)) { store_rule_qos_in_bearer(pdn, &pdn->policy.pcc_rule[idx]->urule.dyn_rule.qos); return (add_ebi_rule_name_entry(pdn->policy.pcc_rule[idx]->urule.dyn_rule.rule_name, pdn->call_id, pdn->default_bearer_id, FALSE)); } } else { if ((compare_default_bearer_qos(&pdn->policy.default_bearer_qos, &pdn->policy.pcc_rule[idx]->urule.pdef_rule.qos) == 0)) { return (add_ebi_rule_name_entry(pdn->policy.pcc_rule[idx]->urule.pdef_rule.rule_name, pdn->call_id, pdn->default_bearer_id, TRUE)); } } } /* set the default rule */ if (config.add_default_rule) { pdn->policy.pcc_rule[pdn->policy.count] = rte_zmalloc_socket(NULL, sizeof(pcc_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); /* set default rule name */ memset(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule.rule_name, '\0', sizeof(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule.rule_name)); strncpy(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule.rule_name, DEFAULT_RULE_NAME, RULE_NAME_LEN); set_ue_requested_bearer_qos(pdn, &(pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule)); add_ebi_rule_name_entry( pdn->policy.pcc_rule[pdn->policy.count]->urule.dyn_rule.rule_name, pdn->call_id, pdn->default_bearer_id, FALSE); switch(config.add_default_rule) { case ADD_RULE_TO_ALLOW : add_default_rule(DEFAULT_FLOW_STATUS_FL_ENABLED, DEFAULT_PRECEDENCE, pdn); break; case ADD_RULE_TO_DENY : add_default_rule(DEFAULT_FLOW_STATUS_FL_DISABLED, DEFAULT_PRECEDENCE, pdn); break; } if(pdn->policy.pcc_rule[pdn->policy.count] != NULL){ pdn->policy.pcc_rule[pdn->policy.count]->action = RULE_ACTION_ADD; pdn->policy.count++; } pdn->policy.num_charg_rule_install++; return 0; } clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Rules not found for default bearer\n", LOG_VALUE); return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } static void decode_presence_area_action_from_cca(uint8_t *buf, presence_reproting_area_action_t *value){ uint16_t decoded = 0; uint16_t total_decoded = 0; value->number_of_tai = decode_bits(buf, total_decoded, 4, &decoded); total_decoded += decoded; value->number_of_rai = decode_bits(buf, total_decoded, 4, &decoded); total_decoded += decoded; value->nbr_of_macro_enb = decode_bits(buf, total_decoded, 8, &decoded); total_decoded += decoded; value->nbr_of_home_enb = decode_bits(buf, total_decoded, 8, &decoded); total_decoded += decoded; value->number_of_ecgi = decode_bits(buf, total_decoded, 8, &decoded); total_decoded += decoded; value->number_of_sai = decode_bits(buf, total_decoded, 8, &decoded); total_decoded += decoded; value->number_of_cgi = decode_bits(buf, total_decoded, 8, &decoded); total_decoded += decoded; total_decoded = total_decoded/CHAR_SIZE; if(value->number_of_tai > 0){ for(int i = 0; i < value->number_of_tai; i++) total_decoded += decode_tai_field(buf + total_decoded, (tai_field_t *)&value->tais[i]); } if(value->nbr_of_macro_enb > 0){ for(int i = 0; i < value->nbr_of_macro_enb; i++) total_decoded += decode_macro_enb_id_fld(buf + total_decoded, (macro_enb_id_fld_t *)&value->macro_enodeb_ids[i]); } if(value->nbr_of_home_enb > 0){ for(int i = 0; i < value->nbr_of_home_enb; i++) total_decoded += decode_home_enb_id_fld(buf + total_decoded, (home_enb_id_fld_t *)&value->home_enb_ids[i]); } if(value->number_of_ecgi > 0){ for(int i = 0; i < value->number_of_ecgi; i++) total_decoded += decode_ecgi_field(buf + total_decoded, (ecgi_field_t *)&value->ecgis[i]); } if(value->number_of_rai > 0){ for(int i = 0; i < value->number_of_rai; i++) total_decoded += decode_rai_field(buf + total_decoded, (rai_field_t *)&value->rais[i]); } if(value->number_of_sai > 0){ for(int i = 0; i < value->number_of_sai; i++) total_decoded += decode_sai_field(buf + total_decoded, (sai_field_t *)&value->sais[i]); } if( value->number_of_cgi > 0){ for(int i = 0; i < value->number_of_cgi; i++) total_decoded += decode_cgi_field(buf + total_decoded, (cgi_field_t *)&value->cgis[i]); } total_decoded = total_decoded*CHAR_SIZE; value->nbr_of_extnded_macro_enb = decode_bits(buf, total_decoded, 8, &decoded); total_decoded += decoded; total_decoded = total_decoded/CHAR_SIZE; if(value->nbr_of_extnded_macro_enb > 0){ for(int i = 0; i < value->nbr_of_extnded_macro_enb; i++) total_decoded += decode_extnded_macro_enb_id_fld(buf + total_decoded, (extnded_macro_enb_id_fld_t *)&value->extended_macro_enodeb_ids[i]); } } void store_presence_reporting_area_info(pdn_connection *pdn_cntxt, GxPresenceReportingAreaInformation *pres_rprtng_area_info){ ue_context *context = NULL; int ret = 0; ret = get_ue_context(UE_SESS_ID(pdn_cntxt->seid), &context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "get UE Context for teid : %d \n", LOG_VALUE, UE_SESS_ID(pdn_cntxt->seid)); return; } context->pra_flag = TRUE; if(context->pre_rptng_area_act == NULL){ context->pre_rptng_area_act = rte_zmalloc_socket(NULL, sizeof(presence_reproting_area_action_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(context->pre_rptng_area_act == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "Memory for presence repoting area action\n", LOG_VALUE); return; } } context->pre_rptng_area_act->pres_rptng_area_idnt = *(uint32_t *)pres_rprtng_area_info->presence_reporting_area_identifier.val; context->pre_rptng_area_act->action = pres_rprtng_area_info->presence_reporting_area_status; decode_presence_area_action_from_cca(pres_rprtng_area_info->presence_reporting_area_elements_list.val, context->pre_rptng_area_act); return; } /* Parse gx CCA response and fill UE context and pfcp context */ int8_t parse_gx_cca_msg(GxCCA *cca, pdn_connection **_pdn) { int ret = 0; uint32_t call_id = 0; pdn_connection *pdn_cntxt = NULL; struct resp_info *resp = NULL; /* Extract the call id from session id */ ret = retrieve_call_id((char *)&cca->session_id.val, &call_id); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT":No Call Id found " "from session id:%s\n", LOG_VALUE, cca->session_id.val); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Retrieve PDN context based on call id */ pdn_cntxt = get_pdn_conn_entry(call_id); if (pdn_cntxt == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT":No valid pdn context " "found for CALL_ID:%u\n", LOG_VALUE, call_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } *_pdn = pdn_cntxt; if(cca->presence.presence_reporting_area_information) store_presence_reporting_area_info(pdn_cntxt, &cca->presence_reporting_area_information); /* Fill the BCM */ pdn_cntxt->bearer_control_mode = cca->bearer_control_mode; /* Overwirte the CSR qos values with CCA default eps bearer qos values */ if(cca->cc_request_type == INITIAL_REQUEST) { /* Check for implimentation wise Mandotory AVP */ if ( cca->presence.charging_rule_install != PRESENT ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Error : " "AVP: charging_rule_install is missing \n", LOG_VALUE); return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } /* Fill the BCM */ pdn_cntxt->bearer_control_mode = cca->bearer_control_mode; /* Check for Default bearer QOS recevied from PCRF */ if (cca->presence.default_eps_bearer_qos != PRESENT) { ret = check_ue_requested_qos(pdn_cntxt); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"AVP:default_eps_bearer_qos is missing \n", LOG_VALUE); return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } } else { ret = store_default_bearer_qos_in_policy(pdn_cntxt, cca->default_eps_bearer_qos); if (ret) return ret; } /* VS: Fill the dynamic rule from rule install structure of cca to policy */ ret = store_dynamic_rules_in_policy(pdn_cntxt, &(cca->charging_rule_install), &(cca->charging_rule_remove)); if (ret) return ret; /* No rule to install nor to remove */ if(pdn_cntxt->policy.count == 0){ return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } if(pdn_cntxt->policy.count > 1 || ((pdn_cntxt->policy.count == 1 ) && ((compare_default_bearer_qos(&pdn_cntxt->policy.default_bearer_qos, &pdn_cntxt->policy.pcc_rule[pdn_cntxt->policy.count - 1]->urule.pdef_rule.qos) != 0 && pdn_cntxt->policy.pcc_rule[pdn_cntxt->policy.count - 1]->urule.pdef_rule.qos.qci != 0) || (compare_default_bearer_qos(&pdn_cntxt->policy.default_bearer_qos, &pdn_cntxt->policy.pcc_rule[pdn_cntxt->policy.count - 1]->urule.dyn_rule.qos) != 0 && pdn_cntxt->policy.pcc_rule[pdn_cntxt->policy.count - 1]->urule.dyn_rule.qos.qci != 0)))) { ret = store_rule_status_for_pro_ack(&pdn_cntxt->policy, &pdn_cntxt->pro_ack_rule_array); if(ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in Provsion ACK Array\n", LOG_VALUE); return ret; } } ret = check_for_rules_on_default_bearer(pdn_cntxt); if (ret) return ret; } else if(pdn_cntxt->proc == HSS_INITIATED_SUB_QOS_MOD) { /*Retrive the session information based on session id. */ if (get_sess_entry(pdn_cntxt->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, (pdn_cntxt->seid)); return -1; } if(cca->presence.charging_rule_install != PRESENT) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid message recived from " "PCRF \n", LOG_VALUE); return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } /* Fill the dynamic rule from rule install structure of cca to policy */ ret = store_dynamic_rules_in_policy(pdn_cntxt, &(cca->charging_rule_install), &(cca->charging_rule_remove)); if (ret) return ret; if(cca->presence.qos_information == PRESENT) { int32_t qos_count = cca->qos_information.count; for(int idx=0; idx < qos_count; idx++) { pdn_cntxt->apn_ambr.ambr_uplink = cca->qos_information.list[idx].apn_aggregate_max_bitrate_ul; pdn_cntxt->apn_ambr.ambr_downlink = cca->qos_information.list[idx].apn_aggregate_max_bitrate_ul; } } /*Store rule name and their status for prov ack msg*/ store_rule_status_for_pro_ack(&pdn_cntxt->policy, &pdn_cntxt->pro_ack_rule_array); /*initiate Update Bearer Request*/ ret = gx_update_bearer_req(pdn_cntxt); if(ret) return ret; resp->msg_type = GTP_MODIFY_BEARER_CMD; resp->proc = HSS_INITIATED_SUB_QOS_MOD; pdn_cntxt->proc = HSS_INITIATED_SUB_QOS_MOD; } else if(pdn_cntxt->proc == UE_REQ_BER_RSRC_MOD_PROC) { /*Retrive the session information based on session id. */ if (get_sess_entry(pdn_cntxt->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, (pdn_cntxt->seid)); return -1; } /* Fill the dynamic rule from rule install structure of cca to policy */ ret = store_dynamic_rules_in_policy(pdn_cntxt, &(cca->charging_rule_install), &(cca->charging_rule_remove)); if (ret) return ret; /*Store rule name and their status for prov ack msg*/ store_rule_status_for_pro_ack(&pdn_cntxt->policy, &pdn_cntxt->pro_ack_rule_array); rar_funtions rar_function = NULL; rar_function = rar_process(pdn_cntxt, NONE_PROC); if(rar_function != NULL){ ret = rar_function(pdn_cntxt); } else { ret = DIAMETER_MISSING_AVP; } resp->msg_type = GTP_BEARER_RESOURCE_CMD; resp->proc = UE_REQ_BER_RSRC_MOD_PROC; pdn_cntxt->proc = UE_REQ_BER_RSRC_MOD_PROC; if(ret){ return ret; } } ret = store_event_trigger(pdn_cntxt, &(cca->event_trigger)); if (ret) return ret; return 0; } int gx_create_bearer_req(pdn_connection *pdn_cntxt){ int ret = 0; uint32_t seq_no = 0; gx_context_t *gx_context = NULL; struct resp_info *resp = NULL; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; struct teid_value_t *teid_value = NULL; teid_key_t teid_key = {0}; if ((pdn_cntxt->proc == UE_REQ_BER_RSRC_MOD_PROC) && (pdn_cntxt->context != NULL) && (pdn_cntxt->context)->ue_initiated_seq_no) { seq_no = (pdn_cntxt->context)->ue_initiated_seq_no; } else { seq_no = generate_seq_number(); } /*Retrive the session information based on session id. */ if (get_sess_entry(pdn_cntxt->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, pdn_cntxt->seid); return -1; } reset_resp_info_structure(resp); fill_pfcp_gx_sess_mod_req(&pfcp_sess_mod_req, pdn_cntxt, RULE_ACTION_ADD, resp); (pdn_cntxt->context)->sequence = seq_no; uint8_t pfcp_msg[PFCP_MSG_LEN] = {0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); ret = set_dest_address(pdn_cntxt->upf_ip, &upf_pfcp_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr,SENT) < 0 ){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error in sending PFCP Session " "Modification Request for Create Bearer Request, Error : %i\n", LOG_VALUE, errno); } else { int ebi_index = GET_EBI_INDEX(pdn_cntxt->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); } if(pdn_cntxt->context->cp_mode == PGWC){ add_pfcp_if_timer_entry(pdn_cntxt->s5s8_pgw_gtpc_teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); } if(pdn_cntxt->context->cp_mode == SAEGWC) { add_pfcp_if_timer_entry(pdn_cntxt->context->s11_sgw_gtpc_teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); } } /* Retrive Gx_context based on Sess ID. */ ret = rte_hash_lookup_data(gx_context_by_sess_id_hash, (const void*)(pdn_cntxt->gx_sess_id), (void **)&gx_context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "NO ENTRY FOUND IN " "Gx HASH [%s]\n", LOG_VALUE, pdn_cntxt->gx_sess_id); return -1; } /* Update UE State */ pdn_cntxt->state = PFCP_SESS_MOD_REQ_SNT_STATE; /* Set GX rar message */ resp->msg_type = GX_RAR_MSG; resp->state = PFCP_SESS_MOD_REQ_SNT_STATE; /* Update UE Proc */ pdn_cntxt->proc = DED_BER_ACTIVATION_PROC; resp->proc = DED_BER_ACTIVATION_PROC; pdn_cntxt->rqst_ptr = gx_context->rqst_ptr; teid_value = rte_zmalloc_socket(NULL, sizeof(teid_value_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (teid_value == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for teid value, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /*Store TEID and msg_type*/ teid_value->teid = pdn_cntxt->s5s8_pgw_gtpc_teid; teid_value->msg_type = resp->msg_type; snprintf(teid_key.teid_key, PROC_LEN, "%s%d", get_proc_string(resp->proc), seq_no); /* Add the entry for sequence and teid value for error handling */ if (pdn_cntxt->context->cp_mode != SAEGWC) { ret = add_seq_number_for_teid(teid_key, teid_value); if(ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "Sequence number for TEID: %u\n", LOG_VALUE, teid_value->teid); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } return 0; } int gx_delete_bearer_req(pdn_connection *pdn_cntxt){ int ret = 0; uint32_t seq_no = 0; gx_context_t *gx_context = NULL; struct resp_info *resp = NULL; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; struct teid_value_t *teid_value = NULL; teid_key_t teid_key = {0}; if ((pdn_cntxt->proc == UE_REQ_BER_RSRC_MOD_PROC) && (pdn_cntxt->context != NULL) && (pdn_cntxt->context)->ue_initiated_seq_no) { seq_no = (pdn_cntxt->context)->ue_initiated_seq_no; } else { seq_no = generate_seq_number(); } /*Retrive the session information based on session id. */ if (get_sess_entry(pdn_cntxt->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, pdn_cntxt->seid); return -1; } reset_resp_info_structure(resp); fill_pfcp_gx_sess_mod_req(&pfcp_sess_mod_req, pdn_cntxt, RULE_ACTION_DELETE, resp); // Maintaining seq no in ue cntxt is not good idea, move it to PDN pdn_cntxt->context->sequence = seq_no; uint8_t pfcp_msg[PFCP_MSG_LEN] = {0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); ret = set_dest_address(pdn_cntxt->upf_ip, &upf_pfcp_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr,SENT) < 0 ){ clLog(clSystemLog, eCLSeverityDebug,LOG_FORMAT"Error in sending PFCP Session " "Modification Request for Delete Bearer Request, Error : %i\n", LOG_VALUE, errno); } else { int ebi_index = GET_EBI_INDEX(pdn_cntxt->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); } if(pdn_cntxt->context->cp_mode == PGWC){ add_pfcp_if_timer_entry(pdn_cntxt->s5s8_pgw_gtpc_teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); } if(pdn_cntxt->context->cp_mode == SAEGWC) { add_pfcp_if_timer_entry(pdn_cntxt->context->s11_sgw_gtpc_teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); } } /* Retrive Gx_context based on Sess ID. */ ret = rte_hash_lookup_data(gx_context_by_sess_id_hash, (const void*)(pdn_cntxt->gx_sess_id), (void **)&gx_context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, pdn_cntxt->gx_sess_id); return -1; } /* Update UE State */ pdn_cntxt->state = PFCP_SESS_MOD_REQ_SNT_STATE; /*Retrive the session information based on session id. */ if (get_sess_entry(pdn_cntxt->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, pdn_cntxt->seid); return -1; } /* Set GX rar message */ resp->msg_type = GX_RAR_MSG; resp->state = PFCP_SESS_MOD_REQ_SNT_STATE; /* Update UE Proc */ pdn_cntxt->proc = PDN_GW_INIT_BEARER_DEACTIVATION; resp->proc = PDN_GW_INIT_BEARER_DEACTIVATION; pdn_cntxt->rqst_ptr = gx_context->rqst_ptr; teid_value = rte_zmalloc_socket(NULL, sizeof(teid_value_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (teid_value == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for teid value, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /*Store TEID and msg_type*/ teid_value->teid = pdn_cntxt->s5s8_pgw_gtpc_teid; teid_value->msg_type = resp->msg_type; snprintf(teid_key.teid_key, PROC_LEN, "%s%d", get_proc_string(resp->proc), seq_no); /* Add the entry for sequence and teid value for error handling */ if (pdn_cntxt->context->cp_mode != SAEGWC) { ret = add_seq_number_for_teid(teid_key, teid_value); if(ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "Sequence number for TEID: %u\n", LOG_VALUE, teid_value->teid); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } return 0; } int gx_update_bearer_req(pdn_connection *pdn){ int ret = 0; uint32_t seq_no = 0; eps_bearer *bearer = NULL; ue_context *context = NULL; struct resp_info *resp = NULL; upd_bearer_req_t ubr_req = {0}; int send_ubr = 0; uint8_t len = 0; uint8_t cp_mode = 0; uint16_t payload_length = 0; struct teid_value_t *teid_value = NULL; teid_key_t teid_key = {0}; bzero(&tx_buf, sizeof(tx_buf)); gtpv2c_header_t *gtpv2c_tx = (gtpv2c_header_t *)tx_buf; if ((pdn->proc == UE_REQ_BER_RSRC_MOD_PROC || pdn->proc == HSS_INITIATED_SUB_QOS_MOD) && (pdn->context != NULL) && (pdn->context)->ue_initiated_seq_no) { seq_no =(pdn->context)->ue_initiated_seq_no; } else { seq_no = generate_seq_number(); } if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, pdn->seid); return DIAMETER_ERROR_USER_UNKNOWN; } reset_resp_info_structure(resp); /* Retrive the UE Context */ ret = get_ue_context(UE_SESS_ID(pdn->seid), &context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE " "Context for teid : %u \n", LOG_VALUE, UE_SESS_ID(pdn->seid)); return DIAMETER_ERROR_USER_UNKNOWN; } /* Start Creating UBR request */ if (pdn->proc == UE_REQ_BER_RSRC_MOD_PROC) set_pti(&ubr_req.pti, IE_INSTANCE_ZERO, context->proc_trans_id); cp_mode = context->cp_mode; if (context->cp_mode != PGWC) { set_gtpv2c_teid_header((gtpv2c_header_t *) &ubr_req, GTP_UPDATE_BEARER_REQ, context->s11_mme_gtpc_teid, seq_no, 0); } else { set_gtpv2c_teid_header((gtpv2c_header_t *) &ubr_req, GTP_UPDATE_BEARER_REQ, pdn->s5s8_sgw_gtpc_teid, seq_no, 0); } ubr_req.apn_ambr.apn_ambr_uplnk = pdn->apn_ambr.ambr_uplink; ubr_req.apn_ambr.apn_ambr_dnlnk = pdn->apn_ambr.ambr_downlink; set_ie_header(&ubr_req.apn_ambr.header, GTP_IE_AGG_MAX_BIT_RATE, IE_INSTANCE_ZERO, sizeof(uint64_t)); /* For now not supporting user location retrive set_ie_header(&ubr_req.indctn_flgs.header, GTP_IE_INDICATION, IE_INSTANCE_ZERO, sizeof(gtp_indication_ie_t)- sizeof(ie_header_t)); ubr_req.indctn_flgs.indication_retloc = 1; */ for (int32_t idx = 0; idx < pdn->policy.count ; idx++) { if (pdn->policy.pcc_rule[idx]->action == RULE_ACTION_MODIFY || pdn->policy.pcc_rule[idx]->action == RULE_ACTION_MODIFY_ADD_RULE || pdn->policy.pcc_rule[idx]->action == RULE_ACTION_MODIFY_REMOVE_RULE ) { uint8_t tft_op_code = 0; if(pdn->policy.pcc_rule[idx]->action == RULE_ACTION_MODIFY){ tft_op_code = TFT_REPLACE_FILTER_EXISTING; }else if(pdn->policy.pcc_rule[idx]->action == RULE_ACTION_MODIFY_ADD_RULE){ tft_op_code = TFT_ADD_FILTER_EXISTING; }else if(pdn->policy.pcc_rule[idx]->action == RULE_ACTION_MODIFY_REMOVE_RULE){ tft_op_code = TFT_REMOVE_FILTER_EXISTING; } if(pdn->policy.pcc_rule[idx]->action != RULE_ACTION_MODIFY_REMOVE_RULE){ bearer = get_bearer(pdn, &pdn->policy.pcc_rule[idx]->urule.dyn_rule.qos); } else { rule_name_key_t rule_name = {0}; memset(rule_name.rule_name, '\0', sizeof(rule_name.rule_name)); snprintf(rule_name.rule_name, RULE_NAME_LEN, "%s%d", pdn->policy.pcc_rule[idx]->urule.dyn_rule.rule_name, pdn->call_id); int8_t bearer_id = get_rule_name_entry(rule_name); bearer = context->eps_bearers[bearer_id]; } if(bearer == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Bearer return is Null for that QoS recived in RAR: %d \n", LOG_VALUE); return DIAMETER_ERROR_USER_UNKNOWN; } if(bearer->qos_bearer_check != PRESENT && bearer->flow_desc_check !=PRESENT) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Flow description and" " Qos not Updated,Not Expected \n", LOG_VALUE); return DIAMETER_INVALID_AVP_VALUE; } if(bearer->action == pdn->policy.pcc_rule[idx]->action){ set_ie_header(&ubr_req.bearer_contexts[ubr_req.bearer_context_count].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); if(bearer->flow_desc_check == PRESENT && pdn->proc != HSS_INITIATED_SUB_QOS_MOD) { len = set_bearer_tft(&ubr_req.bearer_contexts[ubr_req.bearer_context_count].tft, IE_INSTANCE_ZERO, tft_op_code, bearer, pdn->policy.pcc_rule[idx]->urule.dyn_rule.rule_name); ubr_req.bearer_contexts[ubr_req.bearer_context_count].header.len += len; } if(pdn->policy.pcc_rule[idx]->action == RULE_ACTION_MODIFY_REMOVE_RULE) delete_bearer_rule(bearer, pdn->policy.pcc_rule[idx]->urule.dyn_rule.rule_name); if(bearer->qos_bearer_check == PRESENT) { set_bearer_qos(&ubr_req.bearer_contexts[idx].bearer_lvl_qos, IE_INSTANCE_ZERO, bearer); ubr_req.bearer_contexts[idx].header.len += sizeof(gtp_bearer_qlty_of_svc_ie_t); } resp->eps_bearer_ids[resp->bearer_count++] = bearer->eps_bearer_id; set_ebi(&ubr_req.bearer_contexts[ubr_req.bearer_context_count].eps_bearer_id, IE_INSTANCE_ZERO, bearer->eps_bearer_id); ubr_req.bearer_contexts[ubr_req.bearer_context_count].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; ubr_req.bearer_context_count++; send_ubr++; } } } if(bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Rule Name not Matching or Bearer is NULL, so can't initiate " "Update Bearer Req \n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /*need to send mutiple bearer context for hss initiated flow in case of arp change*/ if(pdn->proc == HSS_INITIATED_SUB_QOS_MOD && bearer->arp_bearer_check == PRESENT) { uint8_t bearer_counter = 0; for(uint8_t idx = 0; idx < MAX_BEARERS; idx++) { bearer = pdn->eps_bearers[idx]; if(bearer != NULL) { if(bearer->eps_bearer_id == pdn->default_bearer_id) { bearer_counter++; continue; } if(bearer->arp_bearer_check == PRESENT) { /*bearer context for dedicated bearer arp changes*/ set_ie_header(&ubr_req.bearer_contexts[ubr_req.bearer_context_count].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_bearer_qos(&ubr_req.bearer_contexts[bearer_counter].bearer_lvl_qos, IE_INSTANCE_ZERO, bearer); ubr_req.bearer_contexts[bearer_counter].header.len += sizeof(gtp_bearer_qlty_of_svc_ie_t); resp->eps_bearer_ids[resp->bearer_count++] = bearer->eps_bearer_id; set_ebi(&ubr_req.bearer_contexts[ubr_req.bearer_context_count].eps_bearer_id, IE_INSTANCE_ZERO, bearer->eps_bearer_id); ubr_req.bearer_contexts[ubr_req.bearer_context_count].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; ubr_req.bearer_context_count++; bearer_counter++; } } } } int ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI Index\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } gx_context_t *gx_context = NULL; /* Retrive Gx_context based on Sess ID. */ ret = rte_hash_lookup_data(gx_context_by_sess_id_hash, (const void*)(pdn->gx_sess_id), (void **)&gx_context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO ENTRY FOUND IN Gx " "HASH [%s]\n", LOG_VALUE, pdn->gx_sess_id); return DIAMETER_UNKNOWN_SESSION_ID; } if(context->pra_flag){ set_presence_reporting_area_action_ie(&ubr_req.pres_rptng_area_act, context); context->pra_flag = 0; } pdn->rqst_ptr = gx_context->rqst_ptr; /* Update UE State */ pdn->state = UPDATE_BEARER_REQ_SNT_STATE; /* Update UE Proc */ pdn->proc = UPDATE_BEARER_PROC; resp->proc = UPDATE_BEARER_PROC; resp->msg_type = GTP_UPDATE_BEARER_REQ; resp->teid = UE_SESS_ID(pdn->seid); resp->state = UPDATE_BEARER_REQ_SNT_STATE; if(send_ubr){ memcpy(&resp->gtpc_msg.ub_req, &ubr_req, sizeof(upd_bearer_req_t)); payload_length = encode_upd_bearer_req(&ubr_req, (uint8_t *)gtpv2c_tx); if(SAEGWC != context->cp_mode){ //send S5S8 or on S11 interface update bearer request. ret = set_dest_address(pdn->s5s8_sgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } gtpv2c_send(s5s8_fd, s5s8_fd_v6, tx_buf, payload_length, s5s8_recv_sockaddr,SENT); add_gtpv2c_if_timer_entry( context->s11_sgw_gtpc_teid, &s5s8_recv_sockaddr, tx_buf, payload_length, ebi_index, S5S8_IFACE, cp_mode); process_cp_li_msg(pdn->seid, S5S8_C_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s5s8_recv_sockaddr.type, config.s5s8_ip.s_addr, config.s5s8_ip_v6.s6_addr), fill_ip_info(s5s8_recv_sockaddr.type, s5s8_recv_sockaddr.ipv4.sin_addr.s_addr, s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr), config.s5s8_port, ((s5s8_recv_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s5s8_recv_sockaddr.ipv4.sin_port) : ntohs(s5s8_recv_sockaddr.ipv6.sin6_port))); } else { ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } gtpv2c_send(s11_fd, s11_fd_v6, tx_buf, payload_length, s11_mme_sockaddr,SENT); add_gtpv2c_if_timer_entry( context->s11_sgw_gtpc_teid, &s11_mme_sockaddr, tx_buf, payload_length, ebi_index, S11_IFACE, cp_mode); process_cp_li_msg(pdn->seid, S11_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s11_mme_sockaddr.type, config.s11_ip.s_addr, config.s11_ip_v6.s6_addr), fill_ip_info(s11_mme_sockaddr.type, s11_mme_sockaddr.ipv4.sin_addr.s_addr, s11_mme_sockaddr.ipv6.sin6_addr.s6_addr), config.s11_port, ((s11_mme_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s11_mme_sockaddr.ipv4.sin_port) : ntohs(s11_mme_sockaddr.ipv6.sin6_port))); } } teid_value = rte_zmalloc_socket(NULL, sizeof(teid_value_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (teid_value == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for teid value, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /*Store TEID and msg_type*/ teid_value->teid = pdn->s5s8_pgw_gtpc_teid; teid_value->msg_type = resp->msg_type; snprintf(teid_key.teid_key, PROC_LEN, "%s%d", get_proc_string(resp->proc), seq_no); /* Add the entry for sequence and teid value for error handling */ if (pdn->context->cp_mode != SAEGWC) { ret = add_seq_number_for_teid(teid_key, teid_value); if(ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "Sequence number for TEID: %u\n", LOG_VALUE, teid_value->teid); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } return 0; } /*Handling of RAA message*/ int16_t parse_gx_rar_msg(GxRAR *rar, pdn_connection *pdn_cntxt) { int16_t ret = 0; struct resp_info *resp = NULL; /*Retrive the session information based on session id. */ if (get_sess_entry(pdn_cntxt->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, pdn_cntxt->seid); return -1; } reset_resp_info_structure(resp); /* Copy gx session id for RAR error respose */ memcpy(resp->gx_sess_id, rar->session_id.val, rar->session_id.len); if(rar->presence.default_eps_bearer_qos) { ret = store_default_bearer_qos_in_policy(pdn_cntxt, rar->default_eps_bearer_qos); if (ret) return ret; } ret = store_dynamic_rules_in_policy(pdn_cntxt, &(rar->charging_rule_install), &(rar->charging_rule_remove)); if (ret){ return ret; } rar_funtions rar_function = NULL; rar_function = rar_process(pdn_cntxt, NONE_PROC); if(rar_function != NULL){ ret = rar_function(pdn_cntxt); } else { ret = DIAMETER_MISSING_AVP; } if(ret){ return ret; } /* Storing the Event Trigger received in RAA message*/ ret = store_event_trigger(pdn_cntxt, &(rar->event_trigger)); if (ret < 0) return ret; return 0; } void get_charging_rule_remove_bearer_info(pdn_connection *pdn, uint8_t *lbi, uint8_t *ded_ebi, uint8_t *ber_cnt) { int8_t bearer_id; for (int idx = 0; idx < pdn->policy.count; idx++) { if(RULE_ACTION_DELETE == pdn->policy.pcc_rule[idx]->action) { rule_name_key_t rule_name = {0}; if(pdn->policy.pcc_rule[idx]->predefined_rule){ snprintf(rule_name.rule_name, RULE_NAME_LEN,"%s", pdn->policy.pcc_rule[idx]->urule.pdef_rule.rule_name); }else{ snprintf(rule_name.rule_name, RULE_NAME_LEN,"%s%d", pdn->policy.pcc_rule[idx]->urule.dyn_rule.rule_name, pdn->call_id); } bearer_id = get_rule_name_entry(rule_name); if (-1 == bearer_id) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid bearer_id=%d\n", LOG_VALUE, bearer_id); return; } if (pdn->default_bearer_id == (bearer_id + NUM_EBI_RESERVED)) { *lbi = pdn->default_bearer_id; *ber_cnt = pdn->num_bearer; for (int8_t iCnt = 0; iCnt < MAX_BEARERS; ++iCnt) { if (NULL != pdn->eps_bearers[iCnt]) { *ded_ebi = pdn->eps_bearers[iCnt]->eps_bearer_id; ded_ebi++; } } return; } else { *ded_ebi = bearer_id + NUM_EBI_RESERVED; ded_ebi++; *ber_cnt = *ber_cnt + NUM_EBI_RESERVED; } } } return; } uint8_t compare_flow_description(dynamic_rule_t *old_dyn_rule, dynamic_rule_t *new_dyn_rule) { bool match_pkt_fltr = FALSE; if(old_dyn_rule->num_flw_desc != new_dyn_rule->num_flw_desc) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"old_dyn_rule->num_flw_desc : %d\n", LOG_VALUE, old_dyn_rule->num_flw_desc); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"new_dyn_rule->num_flw_desc : %d\n", LOG_VALUE, new_dyn_rule->num_flw_desc); return 1; } for( int old_pkt_cnt = 0; old_pkt_cnt < old_dyn_rule->num_flw_desc; old_pkt_cnt++) { match_pkt_fltr = FALSE; for( int new_pkt_cnt = 0; new_pkt_cnt < new_dyn_rule->num_flw_desc; new_pkt_cnt++) { if( (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.proto_id != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.proto_id) || (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.proto_mask != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.proto_mask) || (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.direction != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.direction) || (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.action != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.action) || (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.local_ip_mask != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.local_ip_mask) || (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.remote_ip_mask != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.remote_ip_mask) || (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.local_port_low != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.local_port_low) || (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.local_port_high != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.local_port_high) || (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.remote_port_low != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.remote_port_low) || (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.remote_port_high != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.remote_port_high) || (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.ulocalip.local_ip_addr.s_addr != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.ulocalip.local_ip_addr.s_addr) || (old_dyn_rule->flow_desc[old_pkt_cnt].sdf_flw_desc.uremoteip.remote_ip_addr.s_addr != new_dyn_rule->flow_desc[new_pkt_cnt].sdf_flw_desc.uremoteip.remote_ip_addr.s_addr)) { if(new_pkt_cnt == (new_dyn_rule->num_flw_desc -1) && match_pkt_fltr != TRUE ) { return 1; } } else { match_pkt_fltr = TRUE; } } } return 0; } uint8_t compare_bearer_qos(dynamic_rule_t *old_dyn_rule, dynamic_rule_t *new_dyn_rule) { if( (old_dyn_rule->qos.qci != new_dyn_rule->qos.qci) || (old_dyn_rule->qos.ul_mbr != new_dyn_rule->qos.ul_mbr) || (old_dyn_rule->qos.dl_mbr != new_dyn_rule->qos.dl_mbr) || (old_dyn_rule->qos.ul_gbr != new_dyn_rule->qos.ul_gbr) || (old_dyn_rule->qos.dl_gbr != new_dyn_rule->qos.dl_gbr) || (old_dyn_rule->qos.arp.preemption_vulnerability != new_dyn_rule->qos.arp.preemption_vulnerability) || (old_dyn_rule->qos.arp.priority_level != new_dyn_rule->qos.arp.priority_level) || (old_dyn_rule->qos.arp.preemption_capability != new_dyn_rule->qos.arp.preemption_capability)) { return 1; } return 0; } int store_rule_status_for_pro_ack(policy_t *policy, pro_ack_rule_array_t *pro_ack_rule_array) { if(policy == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Policy is empty\n", LOG_VALUE); return -1; } for (int cnt=0; cnt < policy->count; cnt++) { if(policy->pcc_rule[cnt]->predefined_rule){ strncpy(pro_ack_rule_array->rule[cnt].rule_name, policy->pcc_rule[cnt]->urule.pdef_rule.rule_name, strlen(policy->pcc_rule[cnt]->urule.pdef_rule.rule_name)); }else{ strncpy(pro_ack_rule_array->rule[cnt].rule_name, policy->pcc_rule[cnt]->urule.dyn_rule.rule_name, strlen(policy->pcc_rule[cnt]->urule.dyn_rule.rule_name)); } if(policy->pcc_rule[cnt]->action != RULE_ACTION_MODIFY_REMOVE_RULE && policy->pcc_rule[cnt]->action != RULE_ACTION_DELETE) { pro_ack_rule_array->rule[cnt].rule_status = ACTIVE; } else { pro_ack_rule_array->rule[cnt].rule_status = INACTIVE; } pro_ack_rule_array->rule_cnt++; } return 0; } uint8_t compare_bearer_arp(dynamic_rule_t *old_dyn_rule, dynamic_rule_t *new_dyn_rule) { if((old_dyn_rule->qos.arp.preemption_vulnerability != new_dyn_rule->qos.arp.preemption_vulnerability) || (old_dyn_rule->qos.arp.priority_level != new_dyn_rule->qos.arp.priority_level) || (old_dyn_rule->qos.arp.preemption_capability != new_dyn_rule->qos.arp.preemption_capability)) { return 1; } return 0; } void change_arp_for_ded_bearer(pdn_connection *pdn, bearer_qos_ie *qos) { eps_bearer *bearer = NULL; for(uint8_t idx = 0; idx < MAX_BEARERS; idx++) { bearer = pdn->eps_bearers[idx]; if(bearer != NULL) { if(bearer->eps_bearer_id == pdn->default_bearer_id) continue; if(bearer->arp_bearer_check == PRESENT) { bearer->qos.arp.preemption_vulnerability = qos->arp.preemption_vulnerability; bearer->qos.arp.priority_level = qos->arp.priority_level; bearer->qos.arp.preemption_capability = qos->arp.preemption_capability; } } } return; }
nikhilc149/e-utran-features-bug-fixes
cp/cdr.c
<filename>cp/cdr.c /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <stdlib.h> #include <inttypes.h> #include <time.h> #include "cp_config.h" #include "pfcp_session.h" #include "pfcp_util.h" #include "cdr.h" #include "redis_client.h" #include "pfcp_set_ie.h" extern pfcp_config_t config; extern int clSystemLog; const uint32_t base_urr_seq_no = 0x00000000; static uint32_t urr_seq_no_offset; int fill_cdr_info_sess_rpt_req(uint64_t seid, pfcp_usage_rpt_sess_rpt_req_ie_t *usage_report) { int ret; struct timeval unix_start_time; struct timeval unix_end_time; cdr fill_cdr; memset(&fill_cdr,0,sizeof(cdr)); if(usage_report == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Usage report is absent," "failed to generate CDR\n", LOG_VALUE); return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } if(usage_report->urseqn.header.len != 0) { fill_cdr.urseqn = usage_report->urseqn.urseqn; } fill_cdr.cdr_type = CDR_BY_URR; fill_cdr.seid = seid; fill_cdr.urr_id = usage_report->urr_id.urr_id_value; fill_cdr.start_time = usage_report->start_time.start_time; fill_cdr.end_time = usage_report->end_time.end_time; fill_cdr.data_start_time = usage_report->time_of_frst_pckt.time_of_frst_pckt; fill_cdr.data_end_time = usage_report->time_of_lst_pckt.time_of_lst_pckt; fill_cdr.data_volume_uplink = usage_report->vol_meas.uplink_volume; fill_cdr.data_volume_downlink = usage_report->vol_meas.downlink_volume; fill_cdr.total_data_volume = usage_report->vol_meas.total_volume; if(usage_report->dur_meas.header.len!= 0) { fill_cdr.duration_meas = usage_report->dur_meas.duration_value; } else { ntp_to_unix_time(&fill_cdr.start_time, &unix_start_time); ntp_to_unix_time(&fill_cdr.end_time, &unix_end_time); fill_cdr.duration_meas = unix_end_time.tv_sec - unix_start_time.tv_sec; } urr_cause_code_to_str(&usage_report->usage_rpt_trig, fill_cdr.trigg_buff); ret = generate_cdr_info(&fill_cdr); if(ret != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" failed to generate CDR\n", LOG_VALUE); return ret; } return 0; } int fill_cdr_info_sess_mod_resp(uint64_t seid, pfcp_usage_rpt_sess_mod_rsp_ie_t *usage_report) { int ret; struct timeval unix_start_time; struct timeval unix_end_time; cdr fill_cdr; memset(&fill_cdr,0,sizeof(cdr)); if(usage_report == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Usage report is absent," "failed to generate CDR\n", LOG_VALUE); return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } if(usage_report->urseqn.header.len != 0) { fill_cdr.urseqn = usage_report->urseqn.urseqn; } fill_cdr.cdr_type = CDR_BY_URR; fill_cdr.seid = seid; fill_cdr.urr_id = usage_report->urr_id.urr_id_value; fill_cdr.start_time = usage_report->start_time.start_time; fill_cdr.end_time = usage_report->end_time.end_time; fill_cdr.data_start_time = usage_report->time_of_frst_pckt.time_of_frst_pckt; fill_cdr.data_end_time = usage_report->time_of_lst_pckt.time_of_lst_pckt; fill_cdr.data_volume_uplink = usage_report->vol_meas.uplink_volume; fill_cdr.data_volume_downlink = usage_report->vol_meas.downlink_volume; fill_cdr.total_data_volume = usage_report->vol_meas.total_volume; if(usage_report->dur_meas.header.len!= 0) { fill_cdr.duration_meas = usage_report->dur_meas.duration_value; } else { ntp_to_unix_time(&fill_cdr.start_time,&unix_start_time); ntp_to_unix_time(&fill_cdr.end_time,&unix_end_time); fill_cdr.duration_meas = unix_end_time.tv_sec - unix_start_time.tv_sec; } urr_cause_code_to_str(&usage_report->usage_rpt_trig, fill_cdr.trigg_buff); ret = generate_cdr_info(&fill_cdr); if(ret != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" failed to generate CDR\n", LOG_VALUE); return ret; } return 0; } int fill_cdr_info_sess_del_resp(uint64_t seid, pfcp_usage_rpt_sess_del_rsp_ie_t *usage_report) { int ret; struct timeval unix_start_time; struct timeval unix_end_time; cdr fill_cdr; memset(&fill_cdr,0,sizeof(cdr)); if(usage_report == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Usage report is absent," "failed to generate CDR\n", LOG_VALUE); return GTPV2C_CAUSE_INVALID_REPLY_FROM_REMOTE_PEER; } if(usage_report->urseqn.header.len != 0) { fill_cdr.urseqn = usage_report->urseqn.urseqn; } fill_cdr.cdr_type = CDR_BY_URR; fill_cdr.seid = seid; fill_cdr.urr_id = usage_report->urr_id.urr_id_value; fill_cdr.start_time = usage_report->start_time.start_time; fill_cdr.end_time = usage_report->end_time.end_time; fill_cdr.data_start_time = usage_report->time_of_frst_pckt.time_of_frst_pckt; fill_cdr.data_end_time = usage_report->time_of_lst_pckt.time_of_lst_pckt; fill_cdr.data_volume_uplink = usage_report->vol_meas.uplink_volume; fill_cdr.data_volume_downlink = usage_report->vol_meas.downlink_volume; fill_cdr.total_data_volume = usage_report->vol_meas.total_volume; if(usage_report->dur_meas.header.len!= 0) { fill_cdr.duration_meas = usage_report->dur_meas.duration_value; } else { ntp_to_unix_time(&fill_cdr.start_time,&unix_start_time); ntp_to_unix_time(&fill_cdr.end_time,&unix_end_time); fill_cdr.duration_meas = unix_end_time.tv_sec - unix_start_time.tv_sec; } urr_cause_code_to_str(&usage_report->usage_rpt_trig, fill_cdr.trigg_buff); ret = generate_cdr_info(&fill_cdr); if(ret != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" failed to generate CDR\n", LOG_VALUE); return ret; } return 0; } int generate_cdr_info(cdr *fill_cdr) { char cdr_buff[CDR_BUFF_SIZE]; ue_context *context = NULL; pdn_connection *pdn = NULL; uint32_t teid; int ebi_index; int ret = 0; int bearer_index = -1; uint32_t seq_no_in_bearer = 0; char apn_name[MAX_APN_LEN] = {0}; char cp_redis_ip[CDR_BUFF_SIZE] = {0}; char cp_ip_v4[CDR_BUFF_SIZE] = "NA"; char cp_ip_v6[CDR_BUFF_SIZE] = "NA"; char upf_addr_buff_v4[CDR_BUFF_SIZE] = "NA"; char upf_addr_buff_v6[CDR_BUFF_SIZE] = "NA"; char s11_sgw_addr_buff_ipv4[CDR_BUFF_SIZE] = "NA"; char s11_sgw_addr_buff_ipv6[CDR_BUFF_SIZE] = "NA"; char s5s8c_sgw_addr_buff_ipv4[CDR_BUFF_SIZE] = "NA"; char s5s8c_sgw_addr_buff_ipv6[CDR_BUFF_SIZE] = "NA"; char s5s8c_pgw_addr_buff_ipv4[CDR_BUFF_SIZE] = "NA"; char s5s8c_pgw_addr_buff_ipv6[CDR_BUFF_SIZE] = "NA"; char s1u_addr_buff_v4[CDR_BUFF_SIZE] = "NA"; char s1u_addr_buff_v6[CDR_BUFF_SIZE] = "NA"; char s5s8u_sgw_addr_buff_v4[CDR_BUFF_SIZE] = "NA"; char s5s8u_sgw_addr_buff_v6[CDR_BUFF_SIZE] = "NA"; char s5s8u_pgw_addr_buff_v4[CDR_BUFF_SIZE] = "NA"; char s5s8u_pgw_addr_buff_v6[CDR_BUFF_SIZE] = "NA"; char s1u_enb_addr_buff_v4[CDR_BUFF_SIZE] = "NA"; char s1u_enb_addr_buff_v6[CDR_BUFF_SIZE] = "NA"; char s11_mme_addr_buff_v4[CDR_BUFF_SIZE] = "NA"; char s11_mme_addr_buff_v6[CDR_BUFF_SIZE] = "NA"; char ue_ip_addr_ipv4[CDR_BUFF_SIZE] = "NA"; char ue_ip_addr_ipv6[CDR_BUFF_SIZE] = "NA"; char mcc_buff[MCC_BUFF_SIZE] = {0}; char mnc_buff[MNC_BUFF_SIZE] = {0}; struct timeval unix_start_time = {0}; struct timeval unix_end_time = {0}; struct timeval unix_data_start_time = {0}; struct timeval unix_data_end_time = {0}; char start_time_buff[CDR_TIME_BUFF] = {0}; char end_time_buff[CDR_TIME_BUFF] = {0}; char data_start_time_buff[CDR_TIME_BUFF] = {0}; char data_end_time_buff[CDR_TIME_BUFF] = {0}; char buf_pdn[CDR_PDN_BUFF] = {0}; char rule_name[RULE_NAME_LEN] = {0}; char uli_buff[CDR_BUFF_SIZE] = {0}; uint8_t eps_bearer_id = 0; eps_bearer *bearer = NULL; char record_name[CDR_BUFF_SIZE] ={0}; memset(cdr_buff,0,CDR_BUFF_SIZE); teid = UE_SESS_ID(fill_cdr->seid); ret = get_ue_context(teid, &context); if(ret!=0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get Ue context for teid: %d\n",LOG_VALUE, teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } int ebi = UE_BEAR_ID(fill_cdr->seid); ebi_index = GET_EBI_INDEX(ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn = GET_PDN(context, ebi_index); if(pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Conext not found for ebi_index : %d", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (fill_cdr->cdr_type == CDR_BY_URR) { bearer_index = get_bearer_index_by_urr_id(fill_cdr->urr_id, pdn); } else { /*case of secondary RAT*/ bearer_index = ebi_index; } if(bearer_index == -1 && context->piggyback == TRUE) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Handling Attach with DED FAILURE Case", LOG_VALUE); return 0; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ebi_index : %d\n", LOG_VALUE, ebi_index); bearer = pdn->eps_bearers[bearer_index]; if(bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Bearer not found for URR id : %d,bearer_index : %d", LOG_VALUE, fill_cdr->urr_id, bearer_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } eps_bearer_id = bearer->eps_bearer_id; clLog(clSystemLog, eCLSeverityDebug, "Genarting CDR for bearer id : %d \n", eps_bearer_id); if (context->cp_mode != SGWC && fill_cdr->cdr_type != CDR_BY_SEC_RAT) { ret = get_rule_name_by_urr_id(fill_cdr->urr_id, bearer, rule_name); if( ret != 0) { clLog(clSystemLog, eCLSeverityCritical, "rule_name not found for urr_id : %d\n", fill_cdr->urr_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } } else { strncpy(rule_name, "NULL", strlen("NULL")); } seq_no_in_bearer = ++(bearer->cdr_seq_no); fill_cdr->ul_mbr = bearer->qos.ul_mbr; fill_cdr->dl_mbr = bearer->qos.dl_mbr; fill_cdr->ul_gbr = bearer->qos.ul_gbr; fill_cdr->dl_gbr = bearer->qos.dl_gbr; /*for record type * SGW_CDR = for sgwc * PGW_CDR = for pgwc/saegwc */ if (context->cp_mode == SGWC) { fill_cdr->record_type = SGW_CDR; strncpy(record_name, SGW_RECORD_TYPE, strlen(SGW_RECORD_TYPE)); } else { fill_cdr->record_type = PGW_CDR; strncpy(record_name, PGW_RECORD_TYPE, strlen(PGW_RECORD_TYPE)); } if ((context->cp_mode == SGWC) && ((pdn->apn_in_use->apn_name_label) == NULL)) { strncpy(record_name, FORWARD_GATEWAY_RECORD_TYPE, strlen(FORWARD_GATEWAY_RECORD_TYPE)); } /*RAT type*/ if (fill_cdr->cdr_type == CDR_BY_URR) { fill_cdr->rat_type = context->rat_type.rat_type; } else { if (fill_cdr->change_rat_type_flag == 0) fill_cdr->rat_type = context->rat_type.rat_type; } /*Selection mode*/ fill_cdr->selec_mode = context->select_mode.selec_mode; memcpy(&fill_cdr->imsi, &(context->imsi), context->imsi_len); get_apn_name((pdn->apn_in_use)->apn_name_label, apn_name); /*UE IPv4*/ if ( pdn->pdn_type.ipv4 == PRESENT) { snprintf(ue_ip_addr_ipv4, CDR_BUFF_SIZE, "%s", inet_ntoa(*((struct in_addr *)&pdn->uipaddr.ipv4.s_addr))); } /*UE IPv6*/ if (pdn->pdn_type.ipv6 == PRESENT) inet_ntop(AF_INET6, pdn->uipaddr.ipv6.s6_addr, ue_ip_addr_ipv6, CDR_BUFF_SIZE); /*Control plane Mgmnt Ip address*/ if (config.pfcp_ip_type == IP_TYPE_V4 || config.pfcp_ip_type == IP_TYPE_V4V6) { snprintf(cp_ip_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&config.pfcp_ip.s_addr))); } if (config.pfcp_ip_type == IP_TYPE_V6 || config.pfcp_ip_type == IP_TYPE_V4V6) { inet_ntop(AF_INET6, config.pfcp_ip_v6.s6_addr, cp_ip_v6, CDR_BUFF_SIZE); } snprintf(cp_redis_ip, CDR_BUFF_SIZE,"%s", config.cp_redis_ip_buff); /*Data plane IP address*/ if (pdn->upf_ip.ip_type == IP_TYPE_V4 || pdn->upf_ip.ip_type == IP_TYPE_V4V6) { snprintf(upf_addr_buff_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&pdn->upf_ip.ipv4_addr))); } if (pdn->upf_ip.ip_type == IP_TYPE_V6 || pdn->upf_ip.ip_type == IP_TYPE_V4V6) { inet_ntop(AF_INET6, pdn->upf_ip.ipv6_addr, upf_addr_buff_v6, CDR_BUFF_SIZE); } if (context->cp_mode != PGWC) { /*S11 SGW IP address*/ if (context->s11_sgw_gtpc_ip.ip_type == IP_TYPE_V4 || context->s11_sgw_gtpc_ip.ip_type == IP_TYPE_V4V6) { snprintf(s11_sgw_addr_buff_ipv4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&context->s11_sgw_gtpc_ip.ipv4_addr))); } if (context->s11_sgw_gtpc_ip.ip_type == IP_TYPE_V6 || context->s11_sgw_gtpc_ip.ip_type == IP_TYPE_V4V6) { inet_ntop(AF_INET6, context->s11_sgw_gtpc_ip.ipv6_addr, s11_sgw_addr_buff_ipv6, CDR_BUFF_SIZE); } /*S1U SGW IP address*/ if (bearer->s1u_sgw_gtpu_ip.ip_type == IP_TYPE_V4 || bearer->s1u_sgw_gtpu_ip.ip_type == IP_TYPE_V4V6) { snprintf(s1u_addr_buff_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&bearer->s1u_sgw_gtpu_ip.ipv4_addr))); } if (bearer->s1u_sgw_gtpu_ip.ip_type == IP_TYPE_V6 || bearer->s1u_sgw_gtpu_ip.ip_type == IP_TYPE_V4V6) { inet_ntop(AF_INET6, bearer->s1u_sgw_gtpu_ip.ipv6_addr, s1u_addr_buff_v6, CDR_BUFF_SIZE); } /*S11 MME IP address*/ if ( context->s11_mme_gtpc_ip.ip_type == IP_TYPE_V4 || context->s11_mme_gtpc_ip.ip_type == IP_TYPE_V4V6) { snprintf(s11_mme_addr_buff_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&context->s11_mme_gtpc_ip.ipv4_addr))); } if ( context->s11_mme_gtpc_ip.ip_type == IP_TYPE_V6 || context->s11_mme_gtpc_ip.ip_type == IP_TYPE_V4V6) { inet_ntop(AF_INET6, context->s11_mme_gtpc_ip.ipv6_addr, s11_mme_addr_buff_v6, CDR_BUFF_SIZE); } /*S1U eNb IP*/ if ( bearer->s1u_enb_gtpu_ip.ip_type == IP_TYPE_V4 || bearer->s1u_enb_gtpu_ip.ip_type == IP_TYPE_V4V6) { snprintf(s1u_enb_addr_buff_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&bearer->s1u_enb_gtpu_ip.ipv4_addr))); } if ( bearer->s1u_enb_gtpu_ip.ip_type == IP_TYPE_V6 || bearer->s1u_enb_gtpu_ip.ip_type == IP_TYPE_V4V6) { inet_ntop(AF_INET6, bearer->s1u_enb_gtpu_ip.ipv6_addr, s1u_enb_addr_buff_v6, CDR_BUFF_SIZE); } } if (context->cp_mode == SGWC) { /*S5S8C SGW IP address*/ if ( pdn->s5s8_sgw_gtpc_ip.ip_type == IP_TYPE_V4 || pdn->s5s8_sgw_gtpc_ip.ip_type == IP_TYPE_V4V6) { snprintf(s5s8c_sgw_addr_buff_ipv4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&pdn->s5s8_sgw_gtpc_ip.ipv4_addr))); } if ( pdn->s5s8_sgw_gtpc_ip.ip_type == IP_TYPE_V6 || pdn->s5s8_sgw_gtpc_ip.ip_type == IP_TYPE_V4V6) { inet_ntop(AF_INET6, pdn->s5s8_sgw_gtpc_ip.ipv6_addr, s5s8c_sgw_addr_buff_ipv6, CDR_BUFF_SIZE); } /*S5S8 SGWU IP address */ if ( bearer->s5s8_sgw_gtpu_ip.ip_type == IP_TYPE_V4 || bearer->s5s8_sgw_gtpu_ip.ip_type == IP_TYPE_V4V6) { snprintf(s5s8u_sgw_addr_buff_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&bearer->s5s8_sgw_gtpu_ip.ipv4_addr))); } if ( bearer->s5s8_sgw_gtpu_ip.ip_type == IP_TYPE_V6 || bearer->s5s8_sgw_gtpu_ip.ip_type == IP_TYPE_V4V6) { inet_ntop(AF_INET6, bearer->s5s8_sgw_gtpu_ip.ipv6_addr, s5s8u_sgw_addr_buff_v6, CDR_BUFF_SIZE); } } if (context->cp_mode == PGWC) { /*S5S8 SGWC IP address*/ if ( pdn->s5s8_sgw_gtpc_ip.ip_type == IP_TYPE_V4 || pdn->s5s8_sgw_gtpc_ip.ip_type == IP_TYPE_V4V6) { snprintf(s5s8c_sgw_addr_buff_ipv4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&pdn->s5s8_sgw_gtpc_ip.ipv4_addr))); } if ( pdn->s5s8_sgw_gtpc_ip.ip_type == IP_TYPE_V6 || pdn->s5s8_sgw_gtpc_ip.ip_type == IP_TYPE_V4V6) { inet_ntop(AF_INET6, pdn->s5s8_sgw_gtpc_ip.ipv6_addr, s5s8c_sgw_addr_buff_ipv6, CDR_BUFF_SIZE); } /*S5S8 PGWC IP address*/ if (pdn->s5s8_pgw_gtpc_ip.ip_type == IP_TYPE_V4 || pdn->s5s8_pgw_gtpc_ip.ip_type == IP_TYPE_V4V6) { snprintf(s5s8c_pgw_addr_buff_ipv4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&pdn->s5s8_pgw_gtpc_ip.ipv4_addr))); } if (pdn->s5s8_pgw_gtpc_ip.ip_type == IP_TYPE_V6 || pdn->s5s8_pgw_gtpc_ip.ip_type == IP_TYPE_V4V6) { inet_ntop(AF_INET6, pdn->s5s8_pgw_gtpc_ip.ipv6_addr, s5s8c_pgw_addr_buff_ipv6, CDR_BUFF_SIZE); } /*S5S8 PGWU IP address*/ if (bearer->s5s8_pgw_gtpu_ip.ip_type == IP_TYPE_V4 || bearer->s5s8_pgw_gtpu_ip.ip_type == IP_TYPE_V4V6) { snprintf(s5s8u_pgw_addr_buff_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&bearer->s5s8_pgw_gtpu_ip.ipv4_addr))); } if (bearer->s5s8_pgw_gtpu_ip.ip_type == IP_TYPE_V6 || bearer->s5s8_pgw_gtpu_ip.ip_type == IP_TYPE_V4V6) { inet_ntop(AF_INET6, bearer->s5s8_pgw_gtpu_ip.ipv6_addr, s5s8u_pgw_addr_buff_v6, CDR_BUFF_SIZE); } } snprintf(mcc_buff, MCC_BUFF_SIZE, "%d%d%d", context->serving_nw.mcc_digit_1, context->serving_nw.mcc_digit_2, context->serving_nw.mcc_digit_3); snprintf(mnc_buff, MNC_BUFF_SIZE, "%d%d", context->serving_nw.mnc_digit_1, context->serving_nw.mnc_digit_2); if (context->serving_nw.mnc_digit_3 != 15) snprintf(mnc_buff + strnlen(mnc_buff,MNC_BUFF_SIZE), MNC_BUFF_SIZE, "%d", context->serving_nw.mnc_digit_3); ntp_to_unix_time(&fill_cdr->start_time, &unix_start_time); snprintf(start_time_buff,CDR_TIME_BUFF, "%lu", unix_start_time.tv_sec); ntp_to_unix_time(&fill_cdr->end_time, &unix_end_time); snprintf(end_time_buff, CDR_TIME_BUFF, "%lu", unix_end_time.tv_sec); ntp_to_unix_time(&fill_cdr->data_start_time, &unix_data_start_time); snprintf(data_start_time_buff, CDR_TIME_BUFF, "%lu", unix_data_start_time.tv_sec); ntp_to_unix_time(&fill_cdr->data_end_time, &unix_data_end_time); snprintf(data_end_time_buff, CDR_TIME_BUFF, "%lu", unix_data_end_time.tv_sec); check_pdn_type(&pdn->pdn_type, buf_pdn); fill_cdr->timestamp_value = context->mo_exception_data_counter.timestamp_value; fill_cdr->counter_value = context->mo_exception_data_counter.counter_value; fill_user_loc_info(&context->uli, uli_buff); ret = snprintf(cdr_buff, CDR_BUFF_SIZE, "%u,%s,%d,%d,""""%"PRIu64",%s,%lx%d,%lx,%lx,%s,%u,%s,%s,%u,%u,%u,%u,%lu,%lu,%lu,%lu,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%lu,%lu,%lu,%u,%s,%u,%u", generate_cdr_seq_no(), record_name, fill_cdr->rat_type, fill_cdr->selec_mode, fill_cdr->imsi, uli_buff, fill_cdr->seid, eps_bearer_id, fill_cdr->seid, pdn->dp_seid, rule_name, seq_no_in_bearer, fill_cdr->trigg_buff, apn_name, bearer->qos.qci, bearer->qos.arp.preemption_vulnerability, bearer->qos.arp.priority_level, bearer->qos.arp.preemption_capability, fill_cdr->ul_mbr, fill_cdr->dl_mbr, fill_cdr->ul_gbr, fill_cdr->dl_gbr, start_time_buff, end_time_buff, data_start_time_buff, data_end_time_buff, mcc_buff, mnc_buff, ue_ip_addr_ipv4, ue_ip_addr_ipv6, cp_ip_v4, cp_ip_v6, upf_addr_buff_v4, upf_addr_buff_v6, s11_sgw_addr_buff_ipv4, s11_sgw_addr_buff_ipv6, s11_mme_addr_buff_v4, s11_mme_addr_buff_v6, s5s8c_sgw_addr_buff_ipv4, s5s8c_sgw_addr_buff_ipv6, s5s8c_pgw_addr_buff_ipv4, s5s8c_pgw_addr_buff_ipv6, s1u_addr_buff_v4, s1u_addr_buff_v6, s1u_enb_addr_buff_v4, s1u_enb_addr_buff_v6, s5s8u_sgw_addr_buff_v4, s5s8u_sgw_addr_buff_v6, s5s8u_pgw_addr_buff_v4, s5s8u_pgw_addr_buff_v6, fill_cdr->data_volume_uplink, fill_cdr->data_volume_downlink, fill_cdr->total_data_volume, fill_cdr->duration_meas, buf_pdn, fill_cdr->timestamp_value, fill_cdr->counter_value); clLog(clSystemLog, eCLSeverityDebug, "CDR : %s \n", cdr_buff); if (ret < 0 || ret >= CDR_BUFF_SIZE ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Discarding generated CDR due to" "CDR buffer overflow\n", LOG_VALUE); return GTPV2C_CAUSE_NO_MEMORY_AVAILABLE; } if (ctx!=NULL) { /*CP_REDIS_IP in cfg file parameter will be * used as a key to store CDR*/ redis_save_cdr(ctx, cp_redis_ip, cdr_buff); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to store generated CDR," "not connected to redis server\n ", LOG_VALUE); return 0; } return 0; } int fill_user_loc_info(user_loc_info_t *uli, char *uli_buff) { if(uli == NULL) return -1; char temp_buff[MAX_ULI_LENGTH]; if(uli->lai == PRESENT) { snprintf(uli_buff, MAX_ULI_LENGTH, "%u", uli->lai2.lai_lac); } else { snprintf(uli_buff, MAX_ULI_LENGTH, "%s", "NP"); } if(uli->tai == PRESENT) { memset(temp_buff, 0, sizeof(temp_buff)); snprintf(temp_buff, MAX_ULI_LENGTH, ",%u", uli->tai2.tai_tac); strncat(uli_buff, temp_buff, MAX_ULI_LENGTH) ; } else { strncat(uli_buff, ",NP", MAX_ULI_LENGTH); } if(uli->ecgi == PRESENT) { memset(temp_buff, 0, sizeof(temp_buff)); snprintf(temp_buff, MAX_ULI_LENGTH, ",%u", uli->ecgi2.eci); strncat(uli_buff, temp_buff, MAX_ULI_LENGTH) ; } else { strncat(uli_buff, ",NP", MAX_ULI_LENGTH); } if(uli->rai == PRESENT) { memset(temp_buff, 0, sizeof(temp_buff)); snprintf(temp_buff, MAX_ULI_LENGTH, ",%u,%u", uli->rai2.ria_rac, uli->rai2.ria_lac); strncat(uli_buff, temp_buff, MAX_ULI_LENGTH); } else { strncat(uli_buff, ",NP,NP", MAX_ULI_LENGTH); } if(uli->cgi == PRESENT) { memset(temp_buff, 0, sizeof(temp_buff)); snprintf(temp_buff, MAX_ULI_LENGTH, ",%u,%u", uli->cgi2.cgi_lac, uli->cgi2.cgi_ci); strncat(uli_buff, temp_buff, MAX_ULI_LENGTH) ; } else { strncat(uli_buff, ",NP,NP", MAX_ULI_LENGTH); } if(uli->sai == PRESENT) { memset(temp_buff, 0, sizeof(temp_buff)); snprintf(temp_buff, MAX_ULI_LENGTH, ",%u,%u", uli->sai2.sai_lac, uli->sai2.sai_sac); strncat(uli_buff, temp_buff, MAX_ULI_LENGTH) ; } else { strncat(uli_buff, ",NP,NP", MAX_ULI_LENGTH); } if(uli->macro_enodeb_id == PRESENT) { memset(temp_buff, 0, sizeof(temp_buff)); snprintf(temp_buff, MAX_ULI_LENGTH, ",%u,%u", uli->macro_enodeb_id2.menbid_macro_enodeb_id, uli->macro_enodeb_id2.menbid_macro_enb_id2); strncat(uli_buff, temp_buff, MAX_ULI_LENGTH) ; } else { strncat(uli_buff, ",NP,NP", MAX_ULI_LENGTH); } if(uli->extnded_macro_enb_id == PRESENT) { memset(temp_buff, 0, sizeof(temp_buff)); snprintf(temp_buff, MAX_ULI_LENGTH, ",%u,%u", uli->extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id, uli->extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2); strncat(uli_buff, temp_buff, MAX_ULI_LENGTH) ; } else { strncat(uli_buff, ",NP,NP", MAX_ULI_LENGTH); } clLog(clSystemLog, eCLSeverityDebug, "uli_buff : %s\n", uli_buff); return 0; } void urr_cause_code_to_str(pfcp_usage_rpt_trig_ie_t *usage_rpt_trig, char *buf) { if(usage_rpt_trig->volth == 1) { strncpy(buf, VOLUME_LIMIT, CDR_TRIGG_BUFF); return; } if(usage_rpt_trig->timth == 1) { strncpy(buf, TIME_LIMIT, CDR_TRIGG_BUFF); return; } if(usage_rpt_trig->termr == 1) { strncpy(buf, CDR_TERMINATION, CDR_TRIGG_BUFF); return; } } void check_pdn_type(pdn_type_ie *pdn_type, char *buf) { if(pdn_type == NULL && buf == NULL) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"PDN is not " "present\n", LOG_VALUE); return; } if ( pdn_type->ipv4 == PRESENT && pdn_type->ipv6 == PRESENT ) { strncpy(buf, IPV4V6, CDR_PDN_BUFF); } else if ( pdn_type->ipv4 == PRESENT ) { strncpy(buf, IPV4, CDR_PDN_BUFF); return; } else { strncpy(buf, IPV6, CDR_PDN_BUFF); return; } } uint32_t generate_cdr_seq_no(void) { uint32_t id = 0; id = base_urr_seq_no + (++urr_seq_no_offset); return id; } int get_bearer_index_by_urr_id(uint32_t urr_id, pdn_connection *pdn) { clLog(clSystemLog, eCLSeverityDebug, "urr_id : %d\n", urr_id); if(pdn == NULL || urr_id <= 0){ clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Wrong information provided for " "extracting bearer ID\n", LOG_VALUE); return -1; } for ( int cnt = 0; cnt < MAX_BEARERS; cnt++ ) { if (pdn->eps_bearers[cnt]!= NULL) { for (int pdr_cnt = 0 ; pdr_cnt < pdn->eps_bearers[cnt]->pdr_count; pdr_cnt++) { if (urr_id == pdn->eps_bearers[cnt]->pdrs[pdr_cnt]->urr.urr_id_value) { return cnt; } } } } return -1; } int get_rule_name_by_urr_id(uint32_t urr_id, eps_bearer *bearer, char *rule_name) { if(bearer != NULL) { for( int cnt=0; cnt < bearer->pdr_count; cnt++) { if(bearer->pdrs[cnt]->urr.urr_id_value == urr_id) { strncpy(rule_name, bearer->pdrs[cnt]->rule_name, strlen(bearer->pdrs[cnt]->rule_name)); return 0; } } } else { return -1; } return -1; }
nikhilc149/e-utran-features-bug-fixes
cp/state_machine/sm_init.c
<filename>cp/state_machine/sm_init.c /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <rte_hash_crc.h> #include "ue.h" #include "sm_struct.h" #include "cp_config.h" extern struct rte_hash *bearer_by_fteid_hash; extern int clSystemLog; #define SM_HASH_SIZE (1 << 18) char proc_name[PROC_NAME_LEN]; char state_name[STATE_NAME_LEN]; char event_name[EVNT_NAME_LEN]; /** * @brief : Add session entry in state machine hash table. * @param : sess_id, key. * @param : resp_info Resp * @return : 0 or 1. */ uint8_t add_sess_entry(uint64_t sess_id, struct resp_info *resp) { int ret; struct resp_info *tmp = NULL; /* Lookup for session entry. */ ret = rte_hash_lookup_data(sm_hash, &sess_id, (void **)&tmp); if ( ret < 0) { /* No session entry for sess_id * Add session entry for sess_id at sm_hash. */ tmp = rte_malloc_socket(NULL, sizeof(struct resp_info), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "Memory, while adding session entry for SEID : 0x%x \n", LOG_VALUE, sess_id); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* Assign the resp entry to tmp */ memcpy(tmp, resp, sizeof(struct resp_info)); /* Session Entry not present. Add session Entry */ ret = rte_hash_add_key_data(sm_hash, &sess_id, tmp); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry = %lu" "\n\tError= %s\n", LOG_VALUE, sess_id, rte_strerror(abs(ret))); return -1; } } else { memcpy(tmp, resp, sizeof(struct resp_info)); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Sess Entry add for Msg_Type:%u, Sess ID:%lu, State:%s\n", LOG_VALUE, tmp->msg_type, sess_id, get_state_string(tmp->state)); return 0; } uint8_t get_sess_entry(uint64_t sess_id, struct resp_info **resp) { int ret = 0; ret = rte_hash_lookup_data(sm_hash, &sess_id, (void **)resp); if (ret < 0 || *resp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for" " sess_id:%lu...\n", LOG_VALUE, sess_id); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Msg_type:%u, Sess ID:%lu, State:%s\n", LOG_VALUE, (*resp)->msg_type, sess_id, get_state_string((*resp)->state)); return 0; } uint8_t get_sess_state(uint64_t sess_id) { int ret = 0; struct resp_info *resp = NULL; ret = rte_hash_lookup_data(sm_hash, &sess_id, (void **)&resp); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for sess_id:%lu...\n", LOG_VALUE, sess_id); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Msg_Type:%u, Sess ID:%lu, State:%s\n", LOG_VALUE, resp->msg_type, sess_id, get_state_string(resp->state)); return resp->state; } uint8_t update_sess_state(uint64_t sess_id, uint8_t state) { int ret = 0; struct resp_info *resp = NULL; ret = rte_hash_lookup_data(sm_hash, &sess_id, (void **)&resp); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for sess_id:%lu...\n", LOG_VALUE, sess_id); return -1; } resp->state = state; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Msg_Type:%u, Sess ID:%lu, State:%s\n", LOG_VALUE, resp->msg_type, sess_id, get_state_string(resp->state)); return 0; } uint8_t del_sess_entry(uint64_t sess_id) { int ret = 0; struct resp_info *resp = NULL; /* Check Session Entry is present or Not */ ret = rte_hash_lookup_data(sm_hash, &sess_id, (void **)&resp); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for " "sess_id : %lu\n",LOG_VALUE, sess_id); return 0; } /* Session Entry is present. Delete Session Entry */ ret = rte_hash_del_key(sm_hash, &sess_id); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to delete session " "entry for sess_id : %lu\n", LOG_VALUE, sess_id); return -1; } /* Free data from hash */ if (resp != NULL) { rte_free(resp); resp = NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Session deletion for Sess ID:" "%lu Success\n", LOG_VALUE, sess_id); return 0; } uint8_t update_ue_state(ue_context *context, uint8_t state, int ebi_index) { pdn_connection *pdn = NULL; pdn = GET_PDN(context , ebi_index); if(pdn == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get " "pdn for ebi_index %d\n", LOG_VALUE, ebi_index); return -1; } pdn->state = state; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Changed UE State, State:%s\n", LOG_VALUE, get_state_string(pdn->state)); return 0; } uint8_t get_ue_state(uint32_t teid_key, int ebi_index) { int ret = 0; ue_context *context = NULL; pdn_connection *pdn = NULL; ret = rte_hash_lookup_data(ue_context_by_fteid_hash, &teid_key, (void **)&context); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for teid:%x...\n", LOG_VALUE, teid_key); return -1; } pdn = GET_PDN(context , ebi_index); if(pdn == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get " "pdn for ebi_index %d\n", LOG_VALUE, ebi_index); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Teid:%u, State:%s\n", LOG_VALUE, teid_key, get_state_string(pdn->state)); return pdn->state; } int get_pdn(ue_context **context, apn *apn_requested, pdn_connection **pdn) { for (int i = 0; i < MAX_BEARERS; i++) { (*pdn) = (*context)->pdns[i]; if (*pdn) { if (strncmp((*pdn)->apn_in_use->apn_name_label, apn_requested->apn_name_label, apn_requested->apn_name_length) == 0 ) return 0; } } (*pdn) = NULL; return -1; } int8_t get_bearer_by_teid(uint32_t teid_key, struct eps_bearer_t **bearer) { int ret = 0; ret = rte_hash_lookup_data(bearer_by_fteid_hash, &teid_key, (void **)bearer); if ( ret < 0) { return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Teid %u\n", LOG_VALUE, teid_key); return 0; } int8_t get_ue_context_by_sgw_s5s8_teid(uint32_t teid_key, ue_context **context) { int ret = 0; struct eps_bearer_t *bearer = NULL; ret = get_bearer_by_teid(teid_key, &bearer); if(ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Bearer found " "for teid: %x\n", LOG_VALUE, teid_key); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if(bearer != NULL && bearer->pdn != NULL && bearer->pdn->context != NULL ) { *context = bearer->pdn->context; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Get bearer entry by sgw_s5s8_teid:%u\n", LOG_VALUE, teid_key); return 0; } return -1; } /* This function use only in clean up while error */ int8_t get_ue_context_while_error(uint32_t teid_key, ue_context **context) { int ret = 0; struct eps_bearer_t *bearer = NULL; /* If teid key is sgwc s11 */ ret = rte_hash_lookup_data(ue_context_by_fteid_hash, &teid_key, (void **)context); if( ret < 0) { /* If teid key is sgwc s5s8 */ ret = get_bearer_by_teid(teid_key, &bearer); if(ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Bearer found " "for teid: %x\n", LOG_VALUE, teid_key); return -1; } if ((*context == NULL) && (((bearer != NULL) && (bearer->pdn != NULL)) && ((bearer->pdn)->context != NULL))) { *context = (bearer->pdn)->context; } else { return -1; } } return 0; } int8_t get_sender_teid_context(uint32_t teid_key, ue_context **context) { int ret = 0; ret = rte_hash_lookup_data(ue_context_by_sender_teid_hash, &teid_key, (void **)context); if ( ret < 0 || *context == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE" " context for teid:%x...\n", LOG_VALUE, teid_key); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Teid %u\n", LOG_VALUE, teid_key); return 0; } int8_t get_ue_context(uint32_t teid_key, ue_context **context) { int ret = 0; ret = rte_hash_lookup_data(ue_context_by_fteid_hash, &teid_key, (void **)context); if ( ret < 0 || *context == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE" " context for teid:%x...\n", LOG_VALUE, teid_key); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Teid %u\n", LOG_VALUE, teid_key); return 0; } /** * @brief : Initializes the hash table used to account for CS/MB/DS req and resp handle sync. * @param : No param * @return : Returns nothing */ void init_sm_hash(void) { struct rte_hash_parameters rte_hash_params = { .name = "state_machine_hash", .entries = SM_HASH_SIZE, .key_len = sizeof(uint64_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id(), }; sm_hash = rte_hash_create(&rte_hash_params); if (!sm_hash) { rte_panic("%s hash create failed: %s (%u)\n", rte_hash_params.name, rte_strerror(rte_errno), rte_errno); } } /** * @brief : It return procedure name from enum * @param : value, procedure * @return : Returns procedure string */ const char * get_proc_string(int value) { switch(value) { case NONE_PROC: strncpy(proc_name, "NONE_PROC", PROC_NAME_LEN); break; case INITIAL_PDN_ATTACH_PROC: strncpy(proc_name, "INITIAL_PDN_ATTACH_PROC", PROC_NAME_LEN); break; case SERVICE_REQUEST_PROC: strncpy(proc_name, "SERVICE_REQUEST_PROC", PROC_NAME_LEN); break; case SGW_RELOCATION_PROC: strncpy(proc_name, "SGW_RELOCATION_PROC", PROC_NAME_LEN); break; case S1_HANDOVER_PROC: strncpy(proc_name, "S1_HANDOVER_PROC", PROC_NAME_LEN); break; case CONN_SUSPEND_PROC: strncpy(proc_name, "CONN_SUSPEND_PROC", PROC_NAME_LEN); break; case DETACH_PROC: strncpy(proc_name, "DETACH_PROC", PROC_NAME_LEN); break; case DED_BER_ACTIVATION_PROC: strncpy(proc_name, "DED_BER_ACTIVATION_PROC", PROC_NAME_LEN); break; case PDN_GW_INIT_BEARER_DEACTIVATION: strncpy(proc_name, "PDN_GW_INIT_BEARER_DEACTIVATION", PROC_NAME_LEN); break; case MME_INI_DEDICATED_BEARER_DEACTIVATION_PROC: strncpy(proc_name, "MME_INI_DEDICATED_BEARER_DEACTIVATION_PROC", PROC_NAME_LEN); break; case UPDATE_BEARER_PROC: strncpy(proc_name, "UPDATE_BEARER_PROC", PROC_NAME_LEN); break; case RESTORATION_RECOVERY_PROC: strncpy(proc_name, "RESTORATION_RECOVERY_PROC", PROC_NAME_LEN); break; case MODIFY_BEARER_PROCEDURE: strncpy(proc_name, "MODIFY_BEARER_PROCEDURE", PROC_NAME_LEN); break; case ATTACH_DEDICATED_PROC: strncpy(proc_name, "ATTACH_DEDICATED_PROC", PROC_NAME_LEN); break; case MODIFY_ACCESS_BEARER_PROC: strncpy(proc_name, "MODIFY ACCESS Bearer Response", PROC_NAME_LEN); break; case CHANGE_NOTIFICATION_PROC: strncpy(proc_name, "CHANGE_NOTIFICATION_PROC", PROC_NAME_LEN); break; case UPDATE_PDN_CONNECTION_PROC: strncpy(proc_name, "UPDATE_PDN_CONNECTION_PROC", PROC_NAME_LEN); break; case UE_REQ_BER_RSRC_MOD_PROC: strncpy(proc_name, "UE_REQ_BEARER_MOD_PROC", PROC_NAME_LEN); break; case CREATE_INDIRECT_TUNNEL_PROC: strncpy(proc_name, "CREATE_INDIRECT_TUNNEL_PROC", PROC_NAME_LEN); break; case DELETE_INDIRECT_TUNNEL_PROC: strncpy(proc_name, "DELETE_INDIRECT_TUNNEL_PROC", PROC_NAME_LEN); break; case END_PROC: strncpy(proc_name, "END_PROC", PROC_NAME_LEN); break; default: strncpy(proc_name, "UNDEFINED PROC", PROC_NAME_LEN); break; } return proc_name; } /** * @brief : It return state name from enum * @param : value, state * @return : Returns state string */ const char * get_state_string(int value) { switch(value) { case SGWC_NONE_STATE: strncpy(state_name, "SGWC_NONE_STATE", STATE_NAME_LEN); break; case PFCP_ASSOC_REQ_SNT_STATE: strncpy(state_name, "PFCP_ASSOC_REQ_SNT_STATE", STATE_NAME_LEN); break; case PFCP_ASSOC_RESP_RCVD_STATE: strncpy(state_name, "PFCP_ASSOC_RESP_RCVD_STATE", STATE_NAME_LEN); break; case PFCP_SESS_EST_REQ_SNT_STATE: strncpy(state_name, "PFCP_SESS_EST_REQ_SNT_STATE", STATE_NAME_LEN); break; case PFCP_SESS_EST_RESP_RCVD_STATE: strncpy(state_name, "PFCP_SESS_EST_RESP_RCVD_STATE", STATE_NAME_LEN); break; case CONNECTED_STATE: strncpy(state_name, "CONNECTED_STATE", STATE_NAME_LEN); break; case IDEL_STATE: strncpy(state_name, "IDEL_STATE", STATE_NAME_LEN); break; case CS_REQ_SNT_STATE: strncpy(state_name, "CS_REQ_SNT_STATE", STATE_NAME_LEN); break; case CS_RESP_RCVD_STATE: strncpy(state_name, "CS_RESP_RCVD_STATE", STATE_NAME_LEN); break; case PFCP_SESS_MOD_REQ_SNT_STATE: strncpy(state_name, "PFCP_SESS_MOD_REQ_SNT_STATE", STATE_NAME_LEN); break; case PFCP_SESS_MOD_RESP_RCVD_STATE: strncpy(state_name, "PFCP_SESS_MOD_RESP_RCVD_STATE", STATE_NAME_LEN); break; case PFCP_SESS_DEL_REQ_SNT_STATE: strncpy(state_name, "PFCP_SESS_DEL_REQ_SNT_STATE", STATE_NAME_LEN); break; case PFCP_SESS_DEL_RESP_RCVD_STATE: strncpy(state_name, "PFCP_SESS_DEL_RESP_RCVD_STATE", STATE_NAME_LEN); break; case DS_REQ_SNT_STATE: strncpy(state_name, "DS_REQ_SNT_STATE", STATE_NAME_LEN); break; case DS_RESP_RCVD_STATE: strncpy(state_name, "DS_RESP_RCVD_STATE", STATE_NAME_LEN); break; case DDN_REQ_SNT_STATE: strncpy(state_name, "DDN_REQ_SNT_STATE", STATE_NAME_LEN); break; case DDN_ACK_RCVD_STATE: strncpy(state_name, "DDN_ACK_RCVD_STATE", STATE_NAME_LEN); break; case MBR_REQ_SNT_STATE: strncpy(state_name, "MBR_REQ_SNT_STATE", STATE_NAME_LEN); break; case MBR_RESP_RCVD_STATE: strncpy(state_name, "MBR_RESP_RCVD_STATE", STATE_NAME_LEN); break; case CREATE_BER_REQ_SNT_STATE: strncpy(state_name, "CREATE_BER_REQ_SNT_STATE", STATE_NAME_LEN); break; case RE_AUTH_ANS_SNT_STATE: strncpy(state_name, "RE_AUTH_ANS_SNT_STATE", STATE_NAME_LEN); break; case PGWC_NONE_STATE: strncpy(state_name, "PGWC_NONE_STATE", STATE_NAME_LEN); break; case CCR_SNT_STATE: strncpy(state_name, "CCR_SNT_STATE", STATE_NAME_LEN); break; case CREATE_BER_RESP_SNT_STATE: strncpy(state_name, "CREATE_BER_RESP_SNT_STATE", STATE_NAME_LEN); break; case PFCP_PFD_MGMT_RESP_RCVD_STATE: strncpy(state_name, "PFCP_PFD_MGMT_RESP_RCVD_STATE", STATE_NAME_LEN); break; case ERROR_OCCURED_STATE: strncpy(state_name, "ERROR_OCCURED_STATE", STATE_NAME_LEN); break; case UPDATE_BEARER_REQ_SNT_STATE: strncpy(state_name, "UPDATE_BEARER_REQ_SNT_STATE", STATE_NAME_LEN); break; case UPDATE_BEARER_RESP_SNT_STATE: strncpy(state_name, "UPDATE_BEARER_RESP_SNT_STATE", STATE_NAME_LEN); break; case DELETE_BER_REQ_SNT_STATE: strncpy(state_name, "DELETE_BER_REQ_SNT_STATE", STATE_NAME_LEN); break; case CCRU_SNT_STATE: strncpy(state_name, "CCRU_SNT_STATE", STATE_NAME_LEN); break; case PGW_RSTRT_NOTIF_REQ_SNT_STATE: strncpy(state_name, "PGW_RSTRT_NOTIF_REQ_SNT_STATE", STATE_NAME_LEN); break; case UPD_PDN_CONN_SET_REQ_SNT_STATE: strncpy(state_name, "UPD_PDN_CONN_SET_REQ_SNT_STATE", STATE_NAME_LEN); break; case DEL_PDN_CONN_SET_REQ_SNT_STATE: strncpy(state_name, "DEL_PDN_CONN_SET_REQ_SNT_STATE", STATE_NAME_LEN); break; case DEL_PDN_CONN_SET_REQ_RCVD_STATE: strncpy(state_name, "DEL_PDN_CONN_SET_REQ_RCVD_STATE", STATE_NAME_LEN); break; case PFCP_SESS_SET_DEL_REQ_SNT_STATE: strncpy(state_name, "PFCP_SESS_SET_DEL_REQ_SNT_STATE", STATE_NAME_LEN); break; case PFCP_SESS_SET_DEL_REQ_RCVD_STATE: strncpy(state_name, "PFCP_SESS_SET_DEL_REQ_RCVD_STATE", STATE_NAME_LEN); break; case END_STATE: strncpy(state_name, "END_STATE", STATE_NAME_LEN); break; case PROVISION_ACK_SNT_STATE: strncpy(state_name, "PROVISION_ACK_SNT_STATE", STATE_NAME_LEN); break; default: strncpy(state_name, "UNDEFINED STATE", STATE_NAME_LEN); break; } return state_name; } /** * @brief : It return event name from enum * @param : value, state * @return : Returns event string */ const char * get_event_string(int value) { switch(value) { case NONE_EVNT: strncpy(event_name, "NONE_EVNT", EVNT_NAME_LEN); break; case CS_REQ_RCVD_EVNT: strncpy(event_name, "CS_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case PFCP_ASSOC_SETUP_SNT_EVNT: strncpy(event_name, "PFCP_ASSOC_SETUP_SNT_EVNT", EVNT_NAME_LEN); break; case PFCP_ASSOC_SETUP_RESP_RCVD_EVNT: strncpy(event_name, "PFCP_ASSOC_SETUP_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case PFCP_SESS_EST_REQ_RCVD_EVNT: strncpy(event_name, "PFCP_SESS_EST_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case PFCP_SESS_EST_RESP_RCVD_EVNT: strncpy(event_name, "PFCP_SESS_EST_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case CS_RESP_RCVD_EVNT: strncpy(event_name, "CS_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case MB_REQ_RCVD_EVNT: strncpy(event_name,"MB_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case PFCP_SESS_MOD_REQ_RCVD_EVNT: strncpy(event_name, "PFCP_SESS_MOD_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case PFCP_SESS_MOD_RESP_RCVD_EVNT: strncpy(event_name, "PFCP_SESS_MOD_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case MB_RESP_RCVD_EVNT: strncpy(event_name,"MB_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case REL_ACC_BER_REQ_RCVD_EVNT: strncpy(event_name, "REL_ACC_BER_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case DS_REQ_RCVD_EVNT: strncpy(event_name, "DS_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case PFCP_SESS_DEL_REQ_RCVD_EVNT: strncpy(event_name, "PFCP_SESS_DEL_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case PFCP_SESS_DEL_RESP_RCVD_EVNT: strncpy(event_name, "PFCP_SESS_DEL_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case DS_RESP_RCVD_EVNT: strncpy(event_name, "DS_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case ECHO_REQ_RCVD_EVNT: strncpy(event_name, "DDN_ACK_RCVD_EVNT", EVNT_NAME_LEN); break; case ECHO_RESP_RCVD_EVNT: strncpy(event_name, "ECHO_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case DDN_ACK_RESP_RCVD_EVNT: strncpy(event_name, "DDN_ACK_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case PFCP_SESS_RPT_REQ_RCVD_EVNT: strncpy(event_name, "PFCP_SESS_RPT_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case RE_AUTH_REQ_RCVD_EVNT: strncpy(event_name, "RE_AUTH_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case CREATE_BER_RESP_RCVD_EVNT: strncpy(event_name, "CREATE_BER_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case CCA_RCVD_EVNT: strncpy(event_name, "CCA_RCVD_EVNT", EVNT_NAME_LEN); break; case CREATE_BER_REQ_RCVD_EVNT: strncpy(event_name, "CREATE_BER_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case PFCP_PFD_MGMT_RESP_RCVD_EVNT: strncpy(event_name, "PFCP_PFD_MGMT_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case ERROR_OCCURED_EVNT: strncpy(event_name, "ERROR_OCCURED_EVNT", EVNT_NAME_LEN); break; case UPDATE_BEARER_REQ_RCVD_EVNT: strncpy(event_name, "UPDATE_BEARER_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case UPDATE_BEARER_RSP_RCVD_EVNT: strncpy(event_name, "UPDATE_BEARER_RSP_RCVD_EVNT", EVNT_NAME_LEN); break; case DELETE_BER_REQ_RCVD_EVNT: strncpy(event_name, "DELETE_BER_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case DELETE_BER_RESP_RCVD_EVNT: strncpy(event_name, "DELETE_BER_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case DELETE_BER_CMD_RCVD_EVNT: strncpy(event_name, "DELETE_BER_CMD_RCVD_EVNT", EVNT_NAME_LEN); break; case CCAU_RCVD_EVNT: strncpy(event_name, "CCAU_RCVD_EVNT", EVNT_NAME_LEN); break; case PFCP_SESS_SET_DEL_REQ_RCVD_EVNT: strncpy(event_name, "PFCP_SESS_SET_DEL_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case PFCP_SESS_SET_DEL_RESP_RCVD_EVNT: strncpy(event_name, "PFCP_SESS_SET_DEL_RSEP_RCVD_EVNT", EVNT_NAME_LEN); break; case PGW_RSTRT_NOTIF_ACK_RCVD_EVNT: strncpy(event_name, "PGW_RSTRT_NOTIF_ACK_RCVD_EVNT", EVNT_NAME_LEN); break; case UPD_PDN_CONN_SET_REQ_RCVD_EVNT: strncpy(event_name, "UPD_PDN_CONN_SET_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case UPD_PDN_CONN_SET_RESP_RCVD_EVNT: strncpy(event_name, "UPD_PDN_CONN_SET_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case DEL_PDN_CONN_SET_REQ_RCVD_EVNT: strncpy(event_name, "DEL_PDN_CONN_SET_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case DEL_PDN_CONN_SET_RESP_RCVD_EVNT: strncpy(event_name, "DEL_PDN_CONN_SET_RESP_RCVD_EVNT", EVNT_NAME_LEN); break; case CREATE_INDIR_DATA_FRWRD_TUN_REQ_RCVD_EVNT: strncpy(event_name, "CREATE_INDIR_DATA_FRWRD_TUN_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case DELETE_INDIR_DATA_FRWD_TUN_REQ_RCVD_EVNT: strncpy(event_name, "DELETE_INDIR_DATA_FRWD_TUN_REQ_RCVD_EVNT", EVNT_NAME_LEN); break; case END_EVNT: strncpy(event_name, "END_EVNT", EVNT_NAME_LEN); break; case DDN_FAILURE_INDIC_EVNT: strncpy(event_name, "DDN_FAILURE_INDIC_EVNT", EVNT_NAME_LEN); break; default: strncpy(event_name, "UNDEFINED_EVNT", EVNT_NAME_LEN); break; } return event_name; } uint8_t get_procedure(msg_info *msg) { uint8_t proc = NONE_PROC; switch(msg->msg_type) { case GTP_CREATE_SESSION_REQ: { if ((msg->gtpc_msg.csr.indctn_flgs.header.len != 0) && (1 == msg->gtpc_msg.csr.indctn_flgs.indication_oi) && (msg->gtpc_msg.csr.pgw_s5s8_addr_ctl_plane_or_pmip.teid_gre_key != 0)) { proc = SGW_RELOCATION_PROC; } else if ((msg->gtpc_msg.csr.indctn_flgs.header.len != 0) && (0 == msg->gtpc_msg.csr.indctn_flgs.indication_oi && 0 == msg->gtpc_msg.csr.indctn_flgs.indication_daf) && (msg->gtpc_msg.csr.pgw_s5s8_addr_ctl_plane_or_pmip.teid_gre_key != 0)) { proc = S1_HANDOVER_PROC; } else { proc = INITIAL_PDN_ATTACH_PROC; } break; } case GTP_CHANGE_NOTIFICATION_REQ: { proc = CHANGE_NOTIFICATION_PROC; break; } case GTP_CHANGE_NOTIFICATION_RSP: { proc = CHANGE_NOTIFICATION_PROC; break; } case GTP_MODIFY_BEARER_REQ : { proc = MODIFY_BEARER_PROCEDURE; break; } case GTP_MODIFY_BEARER_RSP : { proc = MODIFY_BEARER_PROCEDURE; break; } case GTP_MODIFY_ACCESS_BEARER_REQ: { proc = MODIFY_ACCESS_BEARER_PROC; break; } case GTP_DELETE_SESSION_REQ: { proc = DETACH_PROC; break; } case GTP_DELETE_SESSION_RSP: { proc = DETACH_PROC; break; } case GTP_RELEASE_ACCESS_BEARERS_REQ: { proc = CONN_SUSPEND_PROC; break; } case GTP_CREATE_BEARER_REQ: { proc = DED_BER_ACTIVATION_PROC; break; } case GTP_CREATE_BEARER_RSP: { proc = DED_BER_ACTIVATION_PROC; break; } case GTP_DELETE_BEARER_REQ: { proc = PDN_GW_INIT_BEARER_DEACTIVATION; break; } case GTP_DELETE_BEARER_RSP: { proc = PDN_GW_INIT_BEARER_DEACTIVATION; break; } case GTP_UPDATE_BEARER_REQ: { proc = UPDATE_BEARER_PROC; break; } case GTP_UPDATE_BEARER_RSP: { proc = UPDATE_BEARER_PROC; break; } case GTP_DELETE_BEARER_CMD: { proc = MME_INI_DEDICATED_BEARER_DEACTIVATION_PROC; break; } case GTP_MODIFY_BEARER_CMD: { proc = HSS_INITIATED_SUB_QOS_MOD; break; } case GTP_BEARER_RESOURCE_CMD : { proc = UE_REQ_BER_RSRC_MOD_PROC; break; } case GTP_BEARER_RESOURCE_FAILURE_IND : { proc = UE_REQ_BER_RSRC_MOD_PROC; break; } case GTP_DELETE_PDN_CONNECTION_SET_REQ: { proc = RESTORATION_RECOVERY_PROC; break; } case GTP_DELETE_PDN_CONNECTION_SET_RSP: { proc = RESTORATION_RECOVERY_PROC; break; } case GTP_UPDATE_PDN_CONNECTION_SET_REQ: { proc = UPDATE_PDN_CONNECTION_PROC; break; } case GTP_UPDATE_PDN_CONNECTION_SET_RSP: { proc = MODIFY_BEARER_PROCEDURE; break; } case GTP_PGW_RESTART_NOTIFICATION_ACK: { proc = RESTORATION_RECOVERY_PROC; break; } case GTP_CREATE_INDIRECT_DATA_FORWARDING_TUNNEL_REQ: { proc = CREATE_INDIRECT_TUNNEL_PROC; break; } case GTP_DELETE_INDIRECT_DATA_FORWARDING_TUNNEL_REQ: { proc = DELETE_INDIRECT_TUNNEL_PROC; break; } case GTP_DELETE_INDIRECT_DATA_FORWARDING_TUNNEL_RSP: { proc = DELETE_INDIRECT_TUNNEL_PROC; break; } } return proc; } uint8_t get_csr_proc(create_sess_req_t *csr) { if ((csr->indctn_flgs.header.len != 0) && (1 == csr->indctn_flgs.indication_oi) && (csr->pgw_s5s8_addr_ctl_plane_or_pmip.teid_gre_key != 0)) { return SGW_RELOCATION_PROC; } else if ((csr->indctn_flgs.header.len != 0) && (0 == csr->indctn_flgs.indication_oi && 0 == csr->indctn_flgs.indication_daf) && (csr->pgw_s5s8_addr_ctl_plane_or_pmip.teid_gre_key != 0)) { return S1_HANDOVER_PROC; } else { return INITIAL_PDN_ATTACH_PROC; } } uint8_t update_ue_proc(ue_context *context, uint8_t proc, int ebi_index) { pdn_connection *pdn = NULL; pdn = GET_PDN(context, ebi_index); if(pdn == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get " "pdn for ebi_index %d\n", LOG_VALUE, ebi_index); return -1; } pdn->proc = proc; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Change UE State, Procedure:%s, State:%s\n", LOG_VALUE, get_proc_string(pdn->proc), get_state_string(pdn->state)); return 0; }
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/pfcp_association.h
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef PFCP_ASSOC_H #define PFCP_ASSOC_H #include "pfcp_messages.h" #ifdef CP_BUILD #include "sm_struct.h" #include "seid_llist.h" #endif /* CP_BUILD */ /** * @brief : This is a function to fill pfcp association update response * @param : pfcp_asso_update_resp is pointer to structure of pfcp association update response * @return : This function dose not return anything */ void fill_pfcp_association_update_resp(pfcp_assn_upd_rsp_t *pfcp_asso_update_resp); /** * @brief : This is a function to fill pfcp association setup request * @param : pfcp_asso_setup_req is pointer to structure of pfcp association setup request * @return : This function dose not return anything */ void fill_pfcp_association_setup_req(pfcp_assn_setup_req_t *pfcp_ass_setup_req); /** * @brief : This is a function to fill pfcp association setup response * @param : pfcp_asso_setup_resp is pointer to structure of pfcp association setup response * @param : caues describes the whether request is accepted or not * @return : This function dose not return anything */ void fill_pfcp_association_setup_resp(pfcp_assn_setup_rsp_t *pfcp_ass_setup_resp, uint8_t cause, node_address_t dp_node_value, node_address_t cp_node_value); /** * @brief : This is a function to fill pfcp heartbeat response * @param : pfcp_heartbeat_resp is pointer to structure of pfcp heartbeat response * @return : This function dose not return anything */ void fill_pfcp_heartbeat_resp(pfcp_hrtbeat_rsp_t *pfcp_heartbeat_resp); /** * @brief : This is a function to fill pfcp pfd management response * @param : pfd_resp is pointer to structure of pfcp pfd management response * @param : cause_id describes cause if requested or not * @param : offending_ie describes IE due which request got rejected if any * @return : This function dose not return anything */ void fill_pfcp_pfd_mgmt_resp(pfcp_pfd_mgmt_rsp_t *pfd_resp, uint8_t cause_id, int offending_ie); /** * @brief : This is a function to fill pfcp heartbeat request * @param : pfcp_heartbeat_req is pointer to structure of pfcp heartbeat request * @param : seq indicates the sequence number * @return : This function dose not return anything */ void fill_pfcp_heartbeat_req(pfcp_hrtbeat_req_t *pfcp_heartbeat_req, uint32_t seq); /** * @brief : This is a function to fill pfcp session report request * @param : pfcp_sess_req_resp is pointer to structure of pfcp session report request * @param : seq indicates the sequence number * @param : cp_type, [SGWC/SAEGWC/PGWC] * @return : This function dose not return anything */ void fill_pfcp_sess_report_resp(pfcp_sess_rpt_rsp_t *pfcp_sess_rep_resp, uint32_t seq, uint8_t cp_type); #ifdef CP_BUILD /** * @brief : This function processes pfcp associatiuon response * @param : msg hold the data from pfcp associatiuon response * @param : peer_addr denotes address of peer node * @return : Returns 0 in case of success else negative value */ uint8_t process_pfcp_ass_resp(msg_info *msg, peer_addr_t *peer_addr); /** * @brief : This function adds csr to list of buffrered csrs * @param : context hold information about ue context * @param : upf_context hold information about upf context * @param : ebi indicates eps bearer id * @return : Returns 0 in case of success else negative value */ int buffer_csr_request(ue_context *context, upf_context_t *upf_context, uint8_t ebi); /** * @brief : fills default rule and qos values * @param : pdn * @return : Returns nothing */ void fill_rule_and_qos_inform_in_pdn(pdn_connection *pdn); /** * @brief : This function processes incoming create session request * @param : teid * @param : eps_bearer_id indicates eps bearer id * @return : Returns 0 in case of success else negative value */ int process_create_sess_request(uint32_t teid, uint8_t eps_bearer_id); #endif /* CP_BUILD */ #endif /* PFCP_ASSOC_H */
nikhilc149/e-utran-features-bug-fixes
dp/pfcp_up_llist.c
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "pfcp_up_llist.h" /* Function to add a node in PDR Linked List. */ int8_t insert_sess_data_node(pfcp_session_datat_t *head, pfcp_session_datat_t *new_node) { /* Allocate memory for new node * Next pointing to NULL */ new_node->next = NULL; /* Check linked list is empty or not */ if (head == NULL) { head = new_node; } else { pfcp_session_datat_t *tmp = head; /* Traverse the linked list until tmp is the last node */ while(tmp->next != NULL) { tmp = tmp->next; } tmp->next = new_node; } return 0; } /* @brief : Function to remove the 1st node from the session data Linked List. * @param : head, linked list head pointer * @retrun : Returns linked list head pointer */ static pfcp_session_datat_t * remove_sess_data_first_node(pfcp_session_datat_t *head) { /* Check linked list head pointer is not NULL */ if(head == NULL) return NULL; /* Point to head node */ pfcp_session_datat_t *current = head; /* Access the next node */ head = head->next; /* Free next node address form current node*/ current->next = NULL; /* Check this the last node in the linked list or not */ if (current == head) head = NULL; /* Free the 1st node from linked list */ rte_free(current); current = NULL; return head; } /** * @brief : Function to remove the last node from the session data Linked List. * @param : head, linked list head pointer * @retrun : Returns linked list head pointer */ static pfcp_session_datat_t * remove_sess_data_last_node(pfcp_session_datat_t *head) { /* Check linked list head pointer is not NULL */ if(head == NULL) return NULL; pfcp_session_datat_t *current = head; pfcp_session_datat_t *last = NULL; /* Find the last node in the linked list */ while(current->next != NULL) { last = current; current = current->next; } if (last != NULL) last->next = NULL; /* Check this the last node in the linked list */ if (current == head) head = NULL; /* free the last node from linked list */ rte_free(current); current = NULL; return head; } /* Function to remove the node from the session data Linked List. */ pfcp_session_datat_t * remove_sess_data_node(pfcp_session_datat_t *head, pfcp_session_datat_t *node) { /* Check linked list and node is not NULL */ if ((node == NULL) || (head == NULL)) return NULL; /* If the first node delete */ if (node == head) return remove_sess_data_first_node(head); /* If the last node delete */ if (node->next == NULL) return remove_sess_data_last_node(head); /* Middle node */ pfcp_session_datat_t *current = head; while(current != NULL) { /* Find the node */ if (current->next == node) break; /* Pointing to next node */ current = current->next; } /* Remove the current node */ if (current != NULL) { /* Stored next to next node address */ pfcp_session_datat_t *tmp = current->next; /* point the current node next to next node */ current->next = tmp->next; tmp->next = NULL; /* Free the next node */ rte_free(tmp); tmp = NULL; } return head; } /* Function to add a node in PDR Linked List. */ int8_t insert_pdr_node(pdr_info_t *head, pdr_info_t *new_node) { /* Next pointing to NULL */ new_node->next = NULL; /* Check linked list is empty or not */ if (head == NULL) { head = new_node; } else { pdr_info_t *tmp = head; /* Traverse the linked list until tmp is the last node */ while(tmp->next != NULL) { tmp = tmp->next; } tmp->next = new_node; } return 0; } /* Function to get a node from PDR Linked List. */ pdr_info_t * get_pdr_node(pdr_info_t *head, uint32_t precedence) { /* Pointing to head node */ pdr_info_t *current = head; /* Check linked list is empty or not */ while(current != NULL) { /* Validate the expected node or not */ if (current->prcdnc_val == precedence) return current; /* Pointing to next node */ current = current->next; } /* Node is not present in linked list */ return NULL; } /** * @brief : Function to remove the 1st node from the PDR Linked List. * @param : head, linked list head pointer * @retrun : Returns linked list head pointer */ static pdr_info_t * remove_pdr_first_node(pdr_info_t *head) { /* Check linked list head pointer is not NULL */ if(head == NULL) return NULL; /* Point to head node */ pdr_info_t *current = head; /* Access the next node */ head = head->next; /* Free next node address form current node*/ current->next = NULL; /* Check this the last node in the linked list or not */ if (current == head) head = NULL; /* Free the 1st node from linked list */ rte_free(current); current = NULL; return head; } /** * @brief : Function to remove the last node from the PDR Linked List. * @param : head, linked list head pointer * @retrun : Returns linked list head pointer */ static pdr_info_t * remove_pdr_last_node(pdr_info_t *head) { /* Check linked list head pointer is not NULL */ if(head == NULL) return NULL; pdr_info_t *current = head; pdr_info_t *last = NULL; /* Find the last node in the linked list */ while(current->next != NULL) { last = current; current = current->next; } if (last != NULL) last->next = NULL; /* Check this the last node in the linked list */ if (current == head) head = NULL; /* free the last node from linked list */ rte_free(current); current = NULL; return head; } /* Function to remove the node from the PDR Linked List. */ pdr_info_t * remove_pdr_node(pdr_info_t *head, pdr_info_t *node) { /* Check linked list and node is not NULL */ if ((node == NULL) || (head == NULL)) return NULL; /* If the first node delete */ if (node == head) return remove_pdr_first_node(head); /* If the last node delete */ if (node->next == NULL) return remove_pdr_last_node(head); /* Middle node */ pdr_info_t *current = head; while(current != NULL) { /* Find the node */ if (current->next == node) break; /* Pointing to next node */ current = current->next; } /* Remove the current node */ if (current != NULL) { /* Stored next to next node address */ pdr_info_t *tmp = current->next; /* point the current node next to next node */ current->next = tmp->next; tmp->next = NULL; /* Free the next node */ rte_free(tmp); tmp = NULL; } return head; } /* Function to add a node in QER Linked List. */ int8_t insert_qer_node(qer_info_t *head, qer_info_t *new_node) { /* Allocate memory for new node */ //qer_info_t *new_node = rte_malloc_socket(NULL, sizeof(qer_info_t), // RTE_CACHE_LINE_SIZE, rte_socket_id()); /* Next pointing to NULL */ //new_node = qer; new_node->next = NULL; /* Check linked list is empty or not */ if (head == NULL) { head = new_node; } else { qer_info_t *tmp = head; /* Traverse the linked list until tmp is the last node */ while(tmp->next != NULL) { tmp = tmp->next; } tmp->next = new_node; } return 0; } /** * @brief : Function to remove the 1st node from the QER Linked List. * @param : head, linked list head pointer * @retrun : Returns linked list head pointer */ static qer_info_t * remove_qer_first_node(qer_info_t *head) { /* Check linked list head pointer is not NULL */ if(head == NULL) return NULL; /* Point to head node */ qer_info_t *current = head; /* Access the next node */ head = head->next; /* Free next node address form current node*/ current->next = NULL; /* Check this the last node in the linked list or not */ if (current == head) head = NULL; /* Free the 1st node from linked list */ rte_free(current); current = NULL; return head; } /** * @brief : Function to remove the last node from the QER Linked List. * @param : head, linked list head pointer * @retrun : Returns linked list head pointer */ static qer_info_t * remove_qer_last_node(qer_info_t *head) { /* Check linked list head pointer is not NULL */ if(head == NULL) return NULL; qer_info_t *current = head; qer_info_t *last = NULL; /* Find the last node in the linked list */ while(current->next != NULL) { last = current; current = current->next; } if (last != NULL) last->next = NULL; /* Check this the last node in the linked list */ if (current == head) head = NULL; /* free the last node from linked list */ rte_free(current); current = NULL; return head; } /* Function to remove the node from the QER Linked List. */ qer_info_t * remove_qer_node(qer_info_t *head, qer_info_t *node) { /* Check linked list and node is not NULL */ if ((node == NULL) || (head == NULL)) return NULL; /* If the first node delete */ if (node == head) return remove_qer_first_node(head); /* If the last node delete */ if (node->next == NULL) return remove_qer_last_node(head); /* Middle node */ qer_info_t *current = head; while(current != NULL) { /* Find the node */ if (current->next == node) break; /* Pointing to next node */ current = current->next; } /* Remove the current node */ if (current != NULL) { /* Stored next to next node address */ qer_info_t *tmp = current->next; /* point the current node next to next node */ current->next = tmp->next; tmp->next = NULL; /* Free the next node */ rte_free(tmp); tmp = NULL; } return head; } /* Function to add a node in URR Linked List. */ int8_t insert_urr_node(urr_info_t *head, urr_info_t *new_node) { new_node->next = NULL; /* Check linked list is empty or not */ if (head == NULL) { head = new_node; } else { urr_info_t *tmp = head; /* Traverse the linked list until tmp is the last node */ while(tmp->next != NULL) { tmp = tmp->next; } tmp->next = new_node; } return 0; } /** * @brief : Function to remove the 1st node from the URR Linked List. * @param : head, linked list head pointer * @retrun : Returns linked list head pointer */ static urr_info_t * remove_urr_first_node(urr_info_t *head) { /* Check linked list head pointer is not NULL */ if(head == NULL) return NULL; /* Point to head node */ urr_info_t *current = head; /* Check this the last node in the linked list or not */ if (current == head){ head = NULL; }else{ /* Access the next node */ head = head->next; } /* Free next node address form current node*/ current->next = NULL; /* Free the 1st node from linked list */ rte_free(current); current = NULL; return head; } /** * @brief : Function to remove the last node from the URR Linked List. * @param : head, linked list head pointer * @retrun : Returns linked list head pointer */ static urr_info_t * remove_urr_last_node(urr_info_t *head) { /* Check linked list head pointer is not NULL */ if(head == NULL) return NULL; urr_info_t *current = head; urr_info_t *last = NULL; /* Find the last node in the linked list */ while(current->next != NULL) { last = current; current = current->next; } if (last != NULL) last->next = NULL; /* Check this the last node in the linked list */ if (current == head) head = NULL; /* free the last node from linked list */ rte_free(current); current = NULL; return head; } /* Function to remove the node from the URR Linked List. */ urr_info_t * remove_urr_node(urr_info_t *head, urr_info_t *node) { /* Check linked list and node is not NULL */ if ((node == NULL) || (head == NULL)) return NULL; /* If the first node delete */ if (node == head) return remove_urr_first_node(head); /* If the last node delete */ if (node->next == NULL) return remove_urr_last_node(head); /* Middle node */ urr_info_t *current = head; while(current != NULL) { /* Find the node */ if (current->next == node) break; /* Pointing to next node */ current = current->next; } /* Remove the current node */ if (current != NULL) { /* Stored next to next node address */ urr_info_t *tmp = current->next; /* point the current node next to next node */ current->next = tmp->next; tmp->next = NULL; /* Free the next node */ rte_free(tmp); tmp = NULL; } return head; } /* Function to add a node in Predefined rules Linked List. */ int8_t insert_predef_rule_node(predef_rules_t *head, predef_rules_t *rules) { /* Allocate memory for new node */ predef_rules_t *new_node = rte_malloc_socket(NULL, sizeof(predef_rules_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); /* Next pointing to NULL */ new_node = rules; new_node->next = NULL; /* Check linked list is empty or not */ if (head == NULL) { head = new_node; } else { predef_rules_t *tmp = head; /* Traverse the linked list until tmp is the last node */ while(tmp->next != NULL) { tmp = tmp->next; } tmp->next = new_node; } return 0; }
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/csid_api.c
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "pfcp_util.h" #include "pfcp_enum.h" #include "csid_struct.h" #include "pfcp_set_ie.h" #include "pfcp_messages_encoder.h" #include "gw_adapter.h" #include "pfcp_session.h" extern int clSystemLog; #ifdef CP_BUILD #include "cp.h" #include "cp_timer.h" #include "seid_llist.h" extern pfcp_config_t config; extern int pfcp_fd; extern int pfcp_fd_v6; extern peer_addr_t upf_pfcp_sockaddr; #else #include "up_main.h" #include "seid_llist.h" extern struct in_addr dp_comm_ip; extern struct in6_addr dp_comm_ipv6; extern uint8_t dp_comm_ip_type; extern struct in_addr cp_comm_ip; extern struct app_params app; int8_t stored_recvd_peer_fqcsid(pfcp_fqcsid_ie_t *peer_fqcsid, fqcsid_t *local_fqcsid) { fqcsid_t *tmp = NULL; node_address_t node_addr = {0}; if (peer_fqcsid->fqcsid_node_id_type == IPV4_GLOBAL_UNICAST) { node_addr.ip_type = IPV4_TYPE; memcpy(&node_addr.ipv4_addr, &peer_fqcsid->node_address, IPV4_SIZE); } else if (peer_fqcsid->fqcsid_node_id_type == IPV6_GLOBAL_UNICAST) { node_addr.ip_type = IPV6_TYPE; memcpy(&node_addr.ipv6_addr, &peer_fqcsid->node_address, IPV6_SIZE); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Not supporting MCC and MNC as node address \n", LOG_VALUE); return -1; } /* Stored the Peer CSID by Peer Node address */ tmp = get_peer_addr_csids_entry(&node_addr, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: %s \n", LOG_VALUE, strerror(errno)); return -1; } memcpy(&(tmp->node_addr), &(node_addr), sizeof(node_address_t)); for(uint8_t itr = 0; itr < peer_fqcsid->number_of_csids; itr++) { uint8_t match = 0; for (uint8_t itr1 = 0; itr1 < tmp->num_csid; itr1++) { if (tmp->local_csid[itr1] == peer_fqcsid->pdn_conn_set_ident[itr]){ match = 1; break; } } if (!match) { tmp->local_csid[tmp->num_csid++] = peer_fqcsid->pdn_conn_set_ident[itr]; } } for(uint8_t itr1 = 0; itr1 < peer_fqcsid->number_of_csids; itr1++) { local_fqcsid->local_csid[local_fqcsid->num_csid++] = peer_fqcsid->pdn_conn_set_ident[itr1]; } memcpy(&(local_fqcsid->node_addr), &(node_addr), sizeof(node_address_t)); return 0; } int8_t link_peer_csid_with_local_csid(fqcsid_t *peer_fqcsid, fqcsid_t *local_fqcsid, uint8_t iface) { /* LINK Peer CSID with local CSID */ if (peer_fqcsid->num_csid) { for (uint8_t itr = 0; itr < peer_fqcsid->num_csid; itr++) { csid_t *tmp1 = NULL; csid_key_t key = {0}; key.local_csid = peer_fqcsid->local_csid[itr]; memcpy(&key.node_addr, &peer_fqcsid->node_addr, sizeof(node_address_t)); tmp1 = get_peer_csid_entry(&key, iface, ADD_NODE); if (tmp1 == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: %s \n", LOG_VALUE, strerror(errno)); return -1; } if (!tmp1->num_csid) { tmp1->local_csid[tmp1->num_csid++] = local_fqcsid->local_csid[local_fqcsid->num_csid - 1]; } else { uint8_t match = 0; for (uint8_t itr1 = 0; itr1 < tmp1->num_csid; itr1++) { if (tmp1->local_csid[itr1] == local_fqcsid->local_csid[local_fqcsid->num_csid - 1]) { match = 1; break; } } if (!match) { tmp1->local_csid[tmp1->num_csid++] = local_fqcsid->local_csid[local_fqcsid->num_csid - 1]; } } memcpy(&tmp1->node_addr, &local_fqcsid->node_addr, sizeof(node_address_t)); } } return 0; } int link_dp_sess_with_peer_csid(fqcsid_t *peer_csid, pfcp_session_t *sess, uint8_t iface) { /* Add entry for cp session id with link local csid */ sess_csid *tmp = NULL; uint8_t num_csid = 0; peer_csid_key_t key = {0}; key.iface = iface; key.peer_local_csid = peer_csid->local_csid[num_csid]; memcpy(&key.peer_node_addr, &peer_csid->node_addr, sizeof(node_address_t)); tmp = get_sess_peer_csid_entry(&key, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get peer CSID " "entry, Error: %s \n", LOG_VALUE,strerror(errno)); return -1; } /* Link local csid with session id */ /* Check head node created ot not */ if(tmp->up_seid != sess->up_seid && tmp->up_seid != 0) { sess_csid *new_node = NULL; /* Add new node into csid linked list */ new_node = add_peer_csid_sess_data_node(tmp, &key); if(new_node == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to ADD new " "node into peer CSID linked list : %s\n", LOG_VALUE); return -1; } else { new_node->cp_seid = sess->cp_seid; new_node->up_seid = sess->up_seid; } } else { tmp->cp_seid = sess->cp_seid; tmp->up_seid = sess->up_seid; tmp->next = NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Link Session " "[ CP seid : %u ] [ DP seid : %u ] with CSID : %u" " Linked List \n", LOG_VALUE, tmp->cp_seid, tmp->up_seid, peer_csid->local_csid[num_csid]); return 0; } #endif /* CP_BUILD */ /* PFCP: Create and Fill the FQ-CSIDs */ void set_fq_csid_t(pfcp_fqcsid_ie_t *fq_csid, fqcsid_t *csids) { uint16_t len = 0; fq_csid->number_of_csids = csids->num_csid; if ((csids->node_addr.ip_type == PDN_TYPE_IPV4) || (csids->node_addr.ip_type == IPV4_GLOBAL_UNICAST)) { fq_csid->fqcsid_node_id_type = IPV4_GLOBAL_UNICAST; memcpy(fq_csid->node_address, &csids->node_addr.ipv4_addr, IPV4_SIZE); len += IPV4_SIZE; } else { fq_csid->fqcsid_node_id_type = IPV6_GLOBAL_UNICAST; memcpy(fq_csid->node_address, &csids->node_addr.ipv6_addr, IPV6_SIZE); len += IPV6_SIZE; } for(uint8_t itr = 0; itr < fq_csid->number_of_csids; itr++) { fq_csid->pdn_conn_set_ident[itr] = csids->local_csid[itr]; } /* Adding 1 byte in the header for flags */ len += PRESENT; pfcp_set_ie_header(&(fq_csid->header), PFCP_IE_FQCSID, (2 * (fq_csid->number_of_csids)) + len); } #ifdef CP_BUILD void set_gtpc_fqcsid_t(gtp_fqcsid_ie_t *fqcsid, enum ie_instance instance, fqcsid_t *csids) { /* Added 1 byte for Node_ID and Number of csids*/ uint8_t len = 1; set_ie_header(&fqcsid->header, GTP_IE_FQCSID, instance, 0); fqcsid->number_of_csids = csids->num_csid; if((csids->node_addr.ip_type == IPV4_GLOBAL_UNICAST) || (csids->node_addr.ip_type == PDN_TYPE_IPV4)) { fqcsid->node_id_type = IPV4_GLOBAL_UNICAST; memcpy(&(fqcsid->node_address), &(csids->node_addr.ipv4_addr), IPV4_SIZE); len += IPV4_SIZE; } else { fqcsid->node_id_type = IPV6_GLOBAL_UNICAST; memcpy(&(fqcsid->node_address), &(csids->node_addr.ipv6_addr), IPV6_SIZE); len += IPV6_SIZE; } for (uint8_t itr = 0; itr <fqcsid->number_of_csids; itr++) { fqcsid->pdn_csid[itr] = csids->local_csid[itr]; } fqcsid->header.len = (2 * (fqcsid->number_of_csids) + len); return; } void fill_node_addr_info(node_address_t *dst_info, node_address_t *src_info) { if ((src_info->ip_type == IPV4_GLOBAL_UNICAST) || (src_info->ip_type == PDN_TYPE_IPV4)) { dst_info->ip_type = src_info->ip_type; dst_info->ipv4_addr = src_info->ipv4_addr; } else { dst_info->ip_type = src_info->ip_type; memcpy(&(dst_info->ipv6_addr), &(src_info->ipv6_addr), IPV6_ADDRESS_LEN); } } /* Linked the Peer CSID with local CSID */ int8_t link_gtpc_peer_csids(fqcsid_t *peer_fqcsid, fqcsid_t *local_fqcsid, uint8_t iface) { if (local_fqcsid == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Local CSID is NULL, ERR:\n", LOG_VALUE); return -1; } for (uint8_t itr = 0; itr < peer_fqcsid->num_csid; itr++) { csid_t *tmp = NULL; csid_key_t key = {0}; key.local_csid = peer_fqcsid->local_csid[itr]; fill_node_addr_info(&key.node_addr, &peer_fqcsid->node_addr); tmp = get_peer_csid_entry(&key, iface, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get " "CSID entry to link with PEER FQCSID, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } /* Link local csid with MME CSID */ if (tmp->num_csid == 0) { tmp->local_csid[tmp->num_csid++] = local_fqcsid->local_csid[local_fqcsid->num_csid - 1]; /* Update the Node Addr */ fill_node_addr_info(&tmp->node_addr, &local_fqcsid->node_addr); } else { for (uint8_t itr1 = 0; itr1 < tmp->num_csid; itr1++) { if (tmp->local_csid[itr1] == local_fqcsid->local_csid[local_fqcsid->num_csid - 1]) { return 0; } } /* Link with peer CSID */ tmp->local_csid[tmp->num_csid++] = local_fqcsid->local_csid[local_fqcsid->num_csid - 1]; /* Update the Node Addr */ fill_node_addr_info(&tmp->node_addr, &local_fqcsid->node_addr); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer CSID Linked with Local CSID: %u\n", LOG_VALUE, local_fqcsid->local_csid[local_fqcsid->num_csid - 1]); } } return 0; } /** * @brief : Update the local CSID in hash table. * @param : node_addr, node_addr for lookup entry in hash table * @param : fqcsid, Update local CSID * @return : Returns nothing */ static void add_local_csid(node_address_t *node_addr, sess_fqcsid_t *fqcsid){ fqcsid_t *tmp = NULL; tmp = get_peer_addr_csids_entry(node_addr, UPDATE_NODE); if (tmp != NULL) { for(uint8_t itr = 0; itr < fqcsid->num_csid; itr++) { uint8_t match = 0; for (uint8_t itr1 = 0; itr1 < tmp->num_csid; itr1++) { if (tmp->local_csid[itr1] == fqcsid->local_csid[itr]) { match = 1; break; } } if (!match) { tmp->local_csid[tmp->num_csid++] = fqcsid->local_csid[itr]; } } } } int fill_peer_node_info(pdn_connection *pdn, eps_bearer *bearer) { uint8_t num_csid = 0; int16_t local_csid = 0; csid_key peer_info = {0}; /* MME FQ-CSID */ if ((pdn->context)->cp_mode != PGWC) { if (((pdn->context)->mme_fqcsid)->num_csid) { num_csid = ((pdn->context)->mme_fqcsid)->num_csid; fill_node_addr_info(&peer_info.mme_ip, &((pdn->context)->mme_fqcsid)->node_addr[num_csid - 1]); } else { /* IF MME not support partial failure */ fill_node_addr_info(&peer_info.mme_ip, &(pdn->context)->s11_mme_gtpc_ip); } (peer_info.mme_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node MME IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.mme_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node MME IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.mme_ip.ipv4_addr)); } /* SGW FQ-CSID */ if (((pdn->context)->sgw_fqcsid)->num_csid) { num_csid = ((pdn->context)->sgw_fqcsid)->num_csid; fill_node_addr_info(&peer_info.sgwc_ip, &((pdn->context)->sgw_fqcsid)->node_addr[num_csid - 1]); } else { /* IF SGWC not support partial failure */ if (((pdn->context)->cp_mode == SGWC) || ((pdn->context)->cp_mode == SAEGWC)) { fill_node_addr_info(&peer_info.sgwc_ip, &(pdn->context)->s11_sgw_gtpc_ip); } else { fill_node_addr_info(&peer_info.sgwc_ip, &pdn->s5s8_sgw_gtpc_ip); } } (peer_info.sgwc_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWC/SAEGWC IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.sgwc_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWC/SAEGWC IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.sgwc_ip.ipv4_addr)); if ((pdn->context)->cp_mode != PGWC) { /* Fill the enodeb IP */ if(pdn->context->indication_flag.s11tf){ fill_node_addr_info(&peer_info.enodeb_ip, &bearer->s11u_mme_gtpu_ip); }else{ fill_node_addr_info(&peer_info.enodeb_ip, &bearer->s1u_enb_gtpu_ip); } (peer_info.enodeb_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node enodeb IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.enodeb_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node enodeb IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.enodeb_ip.ipv4_addr)); } /* SGW and PGW peer node info */ fill_node_addr_info(&peer_info.pgwc_ip, &pdn->s5s8_pgw_gtpc_ip); (peer_info.pgwc_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWC IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.pgwc_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWC IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.pgwc_ip.ipv4_addr)); /* SGWU and PGWU peer node info */ if (((pdn->context)->cp_mode == SAEGWC) || ((pdn->context)->cp_mode == SGWC)) { fill_node_addr_info(&peer_info.sgwu_ip, &pdn->upf_ip); (peer_info.sgwu_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWU/SAEGWU IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.sgwu_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWU/SAEGWU IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.sgwu_ip.ipv4_addr)); } else if ((pdn->context)->cp_mode == PGWC) { /*TODO: Need to think on it*/ fill_node_addr_info(&peer_info.pgwu_ip, &pdn->upf_ip); (peer_info.pgwu_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWU IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.pgwu_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWU IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.pgwu_ip.ipv4_addr)); } /* PGWU s5s8 node address */ if (((pdn->context)->cp_mode == SGWC) && (is_present(&bearer->s5s8_pgw_gtpu_ip))) { fill_node_addr_info(&peer_info.pgwu_ip, &bearer->s5s8_pgw_gtpu_ip); (peer_info.pgwu_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWU IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.pgwu_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWU IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.pgwu_ip.ipv4_addr)); } else if ((((pdn->context)->cp_mode == PGWC) && (is_present(&bearer->s5s8_sgw_gtpu_ip)))) { /* SGWU s5s8 node address */ fill_node_addr_info(&peer_info.sgwu_ip, &bearer->s5s8_sgw_gtpu_ip); (peer_info.sgwu_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWU/SAEGWU IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.sgwu_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWU/SAEGWU IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.sgwu_ip.ipv4_addr)); } /* Get local csid for set of peer node */ local_csid = get_csid_entry(&peer_info); if (local_csid < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to assinged CSID..\n", LOG_VALUE); return -1; } /* Remove the dummy local CSIDs from the context */ sess_fqcsid_t tmp_csid_t = {0}; if ((pdn->context)->cp_mode != PGWC) { memcpy(&tmp_csid_t, (pdn->context)->sgw_fqcsid, sizeof(sess_fqcsid_t)); } else { memcpy(&tmp_csid_t, (pdn->context)->pgw_fqcsid, sizeof(sess_fqcsid_t)); } /* Validate the CSID present or not in exsiting CSID List */ for (uint8_t inx = 0; inx < tmp_csid_t.num_csid; inx++) { if (tmp_csid_t.local_csid[inx] == local_csid) { return 0; } } /* Update the local csid into the UE context */ if ((pdn->context)->cp_mode != PGWC) { num_csid = ((pdn->context)->sgw_fqcsid)->num_csid; if ((pdn->context)->s11_mme_gtpc_ip.ip_type == PDN_TYPE_IPV4) { ((pdn->context)->sgw_fqcsid)->node_addr[num_csid].ip_type = PDN_TYPE_IPV4; ((pdn->context)->sgw_fqcsid)->node_addr[num_csid].ipv4_addr = config.s11_ip.s_addr; pdn->sgw_csid.node_addr.ip_type = PDN_TYPE_IPV4; pdn->sgw_csid.node_addr.ipv4_addr = config.s11_ip.s_addr; } else { ((pdn->context)->sgw_fqcsid)->node_addr[num_csid].ip_type = PDN_TYPE_IPV6; memcpy( &(((pdn->context)->sgw_fqcsid)->node_addr[num_csid].ipv6_addr), &(config.s11_ip_v6.s6_addr), IPV6_ADDRESS_LEN); pdn->sgw_csid.node_addr.ip_type = PDN_TYPE_IPV6; memcpy(&(pdn->sgw_csid.node_addr.ipv6_addr), &(config.s11_ip_v6.s6_addr), IPV6_ADDRESS_LEN); } ((pdn->context)->sgw_fqcsid)->local_csid[num_csid] = local_csid; ((pdn->context)->sgw_fqcsid)->num_csid++; pdn->flag_fqcsid_modified = TRUE; add_local_csid(&((pdn->context)->s11_sgw_gtpc_ip), ((pdn->context)->sgw_fqcsid)); num_csid = 0; pdn->sgw_csid.local_csid[num_csid] = local_csid; pdn->sgw_csid.num_csid = PRESENT; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "SGW CSID is Modified ..\n", LOG_VALUE); } else { num_csid = ((pdn->context)->pgw_fqcsid)->num_csid; if (pdn->s5s8_sgw_gtpc_ip.ip_type == PDN_TYPE_IPV4) { ((pdn->context)->pgw_fqcsid)->node_addr[num_csid].ip_type = PDN_TYPE_IPV4; pdn->pgw_csid.node_addr.ip_type = PDN_TYPE_IPV4; if ((pdn->context)->cp_mode_flag == TRUE) { ((pdn->context)->pgw_fqcsid)->node_addr[num_csid].ipv4_addr = config.s11_ip.s_addr; pdn->pgw_csid.node_addr.ipv4_addr = config.s11_ip.s_addr; } else { ((pdn->context)->pgw_fqcsid)->node_addr[num_csid].ipv4_addr = config.s5s8_ip.s_addr; pdn->pgw_csid.node_addr.ipv4_addr = config.s5s8_ip.s_addr; } } else { ((pdn->context)->pgw_fqcsid)->node_addr[num_csid].ip_type = PDN_TYPE_IPV6; pdn->pgw_csid.node_addr.ip_type = PDN_TYPE_IPV6; if ((pdn->context)->cp_mode_flag == TRUE) { memcpy( &(((pdn->context)->pgw_fqcsid)->node_addr[num_csid].ipv6_addr), &(config.s11_ip_v6.s6_addr), IPV6_ADDRESS_LEN); memcpy(&(pdn->pgw_csid.node_addr.ipv6_addr), &(config.s11_ip_v6.s6_addr), IPV6_ADDRESS_LEN); } else { memcpy( &(((pdn->context)->pgw_fqcsid)->node_addr[num_csid].ipv6_addr), &(config.s5s8_ip_v6.s6_addr), IPV6_ADDRESS_LEN); memcpy(&(pdn->pgw_csid.node_addr.ipv6_addr), &(config.s5s8_ip_v6.s6_addr), IPV6_ADDRESS_LEN); } } ((pdn->context)->pgw_fqcsid)->local_csid[num_csid] = local_csid; ((pdn->context)->pgw_fqcsid)->num_csid++; pdn->flag_fqcsid_modified = TRUE; add_local_csid(&(pdn->s5s8_pgw_gtpc_ip), ((pdn->context)->pgw_fqcsid)); num_csid = 0; pdn->pgw_csid.local_csid[num_csid] = local_csid; pdn->pgw_csid.num_csid = PRESENT; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "PGW CSID is Modified ..\n", LOG_VALUE); } /* Link local CSID with MME CSID */ if (pdn->mme_csid.num_csid) { if ((pdn->context)->cp_mode != PGWC) { if (link_gtpc_peer_csids(&pdn->mme_csid, &pdn->sgw_csid, S11_SGW_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Link " "Local CSID entry to link with MME FQCSID, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } } else { if (link_gtpc_peer_csids(&pdn->mme_csid, &pdn->pgw_csid, S5S8_PGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Link " "Local CSID entry to link with MME FQCSID, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } } } /* PGW Link local CSID with SGW CSID */ if ((pdn->context)->cp_mode == PGWC) { if (pdn->sgw_csid.num_csid) { if (link_gtpc_peer_csids(&pdn->sgw_csid, &pdn->pgw_csid, S5S8_PGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Link " "Local CSID entry to link with SGW FQCSID, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } } } /* SGW Link local CSID with PGW CSID */ if ((pdn->context)->cp_mode != PGWC) { if (pdn->pgw_csid.num_csid) { if (link_gtpc_peer_csids(&pdn->pgw_csid, &pdn->sgw_csid, S5S8_SGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Link " "Local CSID entry to link with PGW FQCSID, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } } } return 0; } int delete_peer_node_info(pdn_connection *pdn, eps_bearer *bearer) { int ret = 0; uint8_t num_csid = 0; csid_key peer_info = {0}; /* MME FQ-CSID */ if ((pdn->context)->cp_mode != PGWC) { if (((pdn->context)->mme_fqcsid)->num_csid) { num_csid = ((pdn->context)->mme_fqcsid)->num_csid; fill_node_addr_info(&peer_info.mme_ip, &((pdn->context)->mme_fqcsid)->node_addr[num_csid - 1]); } else { /* IF MME not support partial failure */ fill_node_addr_info(&peer_info.mme_ip, &(pdn->context)->s11_mme_gtpc_ip); } (peer_info.mme_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node MME IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.mme_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node MME IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.mme_ip.ipv4_addr)); } /* SGW FQ-CSID */ if (((pdn->context)->sgw_fqcsid)->num_csid) { num_csid = ((pdn->context)->sgw_fqcsid)->num_csid; fill_node_addr_info(&peer_info.sgwc_ip, &((pdn->context)->sgw_fqcsid)->node_addr[num_csid - 1]); } else { /* IF SGWC not support partial failure */ if (((pdn->context)->cp_mode == SGWC) || ((pdn->context)->cp_mode == SAEGWC)) { fill_node_addr_info(&peer_info.sgwc_ip, &(pdn->context)->s11_sgw_gtpc_ip); } else { fill_node_addr_info(&peer_info.sgwc_ip, &pdn->s5s8_sgw_gtpc_ip); } } (peer_info.sgwc_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWC/SAEGWC IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.sgwc_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWC/SAEGWC IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.sgwc_ip.ipv4_addr)); if ((pdn->context)->cp_mode != PGWC) { /* Fill the enodeb IP */ if(pdn->context->indication_flag.s11tf){ fill_node_addr_info(&peer_info.enodeb_ip, &bearer->s11u_mme_gtpu_ip); }else{ fill_node_addr_info(&peer_info.enodeb_ip, &bearer->s1u_enb_gtpu_ip); } (peer_info.enodeb_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node enodeb IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.enodeb_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node enodeb IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.enodeb_ip.ipv4_addr)); } /* SGW and PGW peer node info */ fill_node_addr_info(&peer_info.pgwc_ip, &pdn->s5s8_pgw_gtpc_ip); (peer_info.pgwc_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWC IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.pgwc_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWC IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.pgwc_ip.ipv4_addr)); /* SGWU and PGWU peer node info */ if (((pdn->context)->cp_mode == SAEGWC) || ((pdn->context)->cp_mode == SGWC)) { fill_node_addr_info(&peer_info.sgwu_ip, &pdn->upf_ip); (peer_info.sgwu_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWU/SAEGWU IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.sgwu_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWU/SAEGWU IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.sgwu_ip.ipv4_addr)); } else if ((pdn->context)->cp_mode == PGWC) { /*TODO: Need to think on it*/ fill_node_addr_info(&peer_info.pgwu_ip, &pdn->upf_ip); (peer_info.pgwu_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWU IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.pgwu_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWU IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.pgwu_ip.ipv4_addr)); } /* PGWU s5s8 node address */ if (((pdn->context)->cp_mode == SGWC) && (is_present(&bearer->s5s8_pgw_gtpu_ip))) { fill_node_addr_info(&peer_info.pgwu_ip, &bearer->s5s8_pgw_gtpu_ip); (peer_info.pgwu_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWU IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.pgwu_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node PGWU IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.pgwu_ip.ipv4_addr)); } else if ((((pdn->context)->cp_mode == PGWC) && (is_present(&bearer->s5s8_sgw_gtpu_ip)))) { /* SGWU s5s8 node address */ fill_node_addr_info(&peer_info.sgwu_ip, &bearer->s5s8_sgw_gtpu_ip); (peer_info.sgwu_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWU/SAEGWU IPv6 Address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_info.sgwu_ip.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer Node SGWU/SAEGWU IPv4 Address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(peer_info.sgwu_ip.ipv4_addr)); } /* Delete Permanent CSID of node */ ret = del_csid_entry(&peer_info); /* Delete Temporary CSID of node */ if ((pdn->context)->cp_mode != PGWC) { /*Set Enb ip to zero */ memset(&peer_info.enodeb_ip, 0, sizeof(node_address_t)); if ((pdn->context)->cp_mode == SGWC) { /*Set PGWU ip to zero */ memset(&peer_info.pgwu_ip, 0, sizeof(node_address_t)); } ret = del_csid_entry(&peer_info); } return ret; } void fill_pdn_fqcsid_info(fqcsid_t *pdn_fqcsid, sess_fqcsid_t *cntx_fqcsid) { uint8_t num_csid = 0; pdn_fqcsid->local_csid[num_csid] = cntx_fqcsid->local_csid[cntx_fqcsid->num_csid -1]; if (cntx_fqcsid->node_addr[cntx_fqcsid->num_csid -1].ip_type == PDN_TYPE_IPV4) { pdn_fqcsid->node_addr.ip_type = PDN_TYPE_IPV4; pdn_fqcsid->node_addr.ipv4_addr = cntx_fqcsid->node_addr[cntx_fqcsid->num_csid -1].ipv4_addr; } else { pdn_fqcsid->node_addr.ip_type = PDN_TYPE_IPV6; memcpy(pdn_fqcsid->node_addr.ipv6_addr, cntx_fqcsid->node_addr[cntx_fqcsid->num_csid -1].ipv6_addr, IPV6_ADDRESS_LEN); } pdn_fqcsid->num_csid = PRESENT; } int8_t update_peer_csid_link(fqcsid_t *fqcsid, fqcsid_t *fqcsid_t) { /* Link local CSID with peer node CSID */ if (fqcsid->num_csid) { for (uint8_t itr = 0; itr < fqcsid->num_csid; itr++) { csid_t *tmp = NULL; csid_key_t key = {0}; key.local_csid = fqcsid->local_csid[itr]; memcpy(&(key.node_addr), &(fqcsid->node_addr), sizeof(node_address_t)); tmp = get_peer_csid_entry(&key, SX_PORT_ID, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in " "updating peer CSID link: %s \n", LOG_VALUE, strerror(errno)); return -1; } /* Link local csid with MME CSID */ if (tmp->num_csid == 0) { tmp->local_csid[tmp->num_csid++] = fqcsid_t->local_csid[fqcsid_t->num_csid - 1]; } else { uint8_t itr1 = 0; while (itr1 < tmp->num_csid) { if (tmp->local_csid[itr1] != fqcsid_t->local_csid[fqcsid_t->num_csid - 1]){ /* Handle condition like single SGWU CSID link with multiple local CSID */ tmp->local_csid[tmp->num_csid++] = fqcsid_t->local_csid[fqcsid_t->num_csid - 1]; itr1++; } else { break; } } } /* Update the Node address */ memcpy(&(tmp->node_addr), &(fqcsid_t->node_addr), sizeof(node_address_t)); } } return 0; } int8_t fill_fqcsid_sess_mod_req(pfcp_sess_mod_req_t *pfcp_sess_mod_req, pdn_connection *pdn) { /* Set SGW FQ-CSID */ if (pdn->sgw_csid.num_csid) { set_fq_csid_t(&pfcp_sess_mod_req->sgw_c_fqcsid, &pdn->sgw_csid); /* set PGWC FQ-CSID */ /* Note: In case of S1 handover pgw fqcsid is not generated, * as new sgw doesn't know the pgw fqcsid * so we don't want zero value to be set in * fqcsid in pfcp mod request. That's why the * below condition is checked*/ if(pdn->context->update_sgw_fteid == FALSE) set_fq_csid_t(&pfcp_sess_mod_req->pgw_c_fqcsid, &pdn->pgw_csid); } return 0; } int8_t fill_fqcsid_sess_est_req(pfcp_sess_estab_req_t *pfcp_sess_est_req, pdn_connection *pdn) { fqcsid_t tmp_fqcsid = {0}; if ((pdn->context)->cp_mode != PGWC) { /* Set SGW FQ-CSID */ if (pdn->sgw_csid.num_csid) { set_fq_csid_t(&pfcp_sess_est_req->sgw_c_fqcsid, &pdn->sgw_csid); } else { set_fq_csid_t(&pfcp_sess_est_req->sgw_c_fqcsid, &tmp_fqcsid); } /* Set MME FQ-CSID */ if(pdn->mme_csid.num_csid) { set_fq_csid_t(&pfcp_sess_est_req->mme_fqcsid, &pdn->mme_csid); } } else if ((pdn->context)->cp_mode == PGWC) { /* Set PGW FQ-CSID */ if (pdn->pgw_csid.num_csid) { set_fq_csid_t(&pfcp_sess_est_req->pgw_c_fqcsid, &pdn->pgw_csid); } else { set_fq_csid_t(&pfcp_sess_est_req->pgw_c_fqcsid, &tmp_fqcsid); } /* Set SGW C FQ_CSID */ if (pdn->sgw_csid.num_csid) { set_fq_csid_t(&pfcp_sess_est_req->sgw_c_fqcsid, &pdn->sgw_csid); } else { set_fq_csid_t(&pfcp_sess_est_req->sgw_c_fqcsid, &tmp_fqcsid); } /* Set MME FQ-CSID */ if(pdn->mme_csid.num_csid) { set_fq_csid_t(&pfcp_sess_est_req->mme_fqcsid, &pdn->mme_csid); } else { set_fq_csid_t(&pfcp_sess_est_req->mme_fqcsid, &tmp_fqcsid); } } return 0; } int link_sess_with_peer_csid(fqcsid_t *peer_csid, pdn_connection *pdn, uint8_t iface) { /* Add entry for cp session id with link local csid */ sess_csid *tmp = NULL; uint8_t num_csid = 0; peer_csid_key_t key = {0}; key.iface = iface; key.peer_local_csid = peer_csid->local_csid[num_csid]; memcpy(&(key.peer_node_addr), &(peer_csid->node_addr), sizeof(node_address_t)); tmp = get_sess_peer_csid_entry(&key, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get peer CSID " "entry, Error: %s \n", LOG_VALUE,strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* OPTIMIZE THE MEMORY: No Need to fill UP_SEID */ /* Link local csid with session id */ /* Check head node created ot not */ if(tmp->cp_seid != pdn->seid && tmp->cp_seid != 0) { sess_csid *new_node = NULL; /* Add new node into csid linked list */ new_node = add_peer_csid_sess_data_node(tmp, &key); if(new_node == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to ADD new " "node into peer CSID linked list : %s\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } else { new_node->cp_seid = pdn->seid; new_node->up_seid = pdn->dp_seid; } } else { tmp->cp_seid = pdn->seid; tmp->up_seid = pdn->dp_seid; tmp->next = NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Link Session " "[ CP seid : %u ] [ DP seid : %u ] with CSID : %u" " Peer Node addr Linked List \n", LOG_VALUE, tmp->cp_seid, tmp->up_seid, peer_csid->local_csid[num_csid]); return 0; } void remove_csid_from_cntx(sess_fqcsid_t *cntx_fqcsid, fqcsid_t *csid_t) { for (uint8_t itr = 0; itr < (cntx_fqcsid)->num_csid; itr++) { if (((cntx_fqcsid)->local_csid[itr] == csid_t->local_csid[csid_t->num_csid -1]) && (COMPARE_IP_ADDRESS(cntx_fqcsid->node_addr[itr], csid_t->node_addr) == 0)) { for(uint8_t pos = itr; pos < ((cntx_fqcsid)->num_csid - 1); pos++ ) { (cntx_fqcsid)->local_csid[pos] = (cntx_fqcsid)->local_csid[pos + 1]; if ((cntx_fqcsid)->node_addr[(pos + 1)].ip_type == PDN_TYPE_IPV4) { (cntx_fqcsid)->node_addr[pos].ipv4_addr = (cntx_fqcsid)->node_addr[(pos + 1)].ipv4_addr; } else { memcpy(&((cntx_fqcsid)->node_addr[pos].ipv6_addr), &((cntx_fqcsid)->node_addr[(pos + 1)].ipv6_addr), IPV6_ADDRESS_LEN); } } (cntx_fqcsid)->num_csid--; } } } #endif /* CP_BUID */ static uint16_t seq_t = 0; #ifdef CP_BUILD void cp_fill_pfcp_sess_set_del_req_t(pfcp_sess_set_del_req_t *pfcp_sess_set_del_req, fqcsid_t *local_csids) { fqcsid_t tmp = {0}; node_address_t node_value = {0}; int ret = 0; set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_set_del_req->header), PFCP_SESSION_SET_DELETION_REQUEST, NO_SEID, ++seq_t, NO_CP_MODE_REQUIRED); /*filling of node id*/ #ifdef CP_BUILD ret = fill_ip_addr(config.pfcp_ip.s_addr, config.pfcp_ip_v6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } #else ret = fill_ip_addr(dp_comm_ip.s_addr, dp_comm_ipv6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } #endif /*CP_BUILD*/ set_node_id(&(pfcp_sess_set_del_req->node_id), node_value); if (local_csids->instance == 0) { if (local_csids->num_csid) { set_fq_csid_t(&pfcp_sess_set_del_req->sgw_c_fqcsid, &tmp); set_fq_csid_t(&pfcp_sess_set_del_req->pgw_c_fqcsid, &tmp); /* Set the UP FQ-CSID */ set_fq_csid_t(&pfcp_sess_set_del_req->up_fqcsid, &tmp); set_fq_csid_t(&pfcp_sess_set_del_req->mme_fqcsid, local_csids); } } else if (local_csids->instance == 1) { if (local_csids->num_csid) { set_fq_csid_t(&pfcp_sess_set_del_req->sgw_c_fqcsid, local_csids); } } else if (local_csids->instance == 2) { if (local_csids->num_csid) { set_fq_csid_t(&pfcp_sess_set_del_req->sgw_c_fqcsid, &tmp); set_fq_csid_t(&pfcp_sess_set_del_req->pgw_c_fqcsid, local_csids); } } } #endif /* CP_BUILD */ void fill_pfcp_sess_set_del_req_t(pfcp_sess_set_del_req_t *pfcp_sess_set_del_req, fqcsid_t *local_csids, uint8_t iface) { fqcsid_t tmp_csids = {0}; node_address_t node_value = {0}; int ret = 0; set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_set_del_req->header), PFCP_SESSION_SET_DELETION_REQUEST, NO_SEID, ++seq_t, NO_CP_MODE_REQUIRED); /*filling of node id*/ #ifdef CP_BUILD ret = fill_ip_addr(config.pfcp_ip.s_addr, config.pfcp_ip_v6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } #else ret = fill_ip_addr(dp_comm_ip.s_addr, dp_comm_ipv6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } #endif /*CP_BUILD*/ set_node_id(&(pfcp_sess_set_del_req->node_id), node_value); if (local_csids->num_csid) { /* Set the SGWC FQ-CSID */ #ifdef CP_BUILD if ((iface == S11_SGW_PORT_ID) || (iface == S5S8_SGWC_PORT_ID)) { set_fq_csid_t(&pfcp_sess_set_del_req->sgw_c_fqcsid, local_csids); } if (iface == S5S8_PGWC_PORT_ID) { set_fq_csid_t(&pfcp_sess_set_del_req->sgw_c_fqcsid, &tmp_csids); set_fq_csid_t(&pfcp_sess_set_del_req->pgw_c_fqcsid, local_csids); } #else set_fq_csid_t(&pfcp_sess_set_del_req->sgw_c_fqcsid, &tmp_csids); set_fq_csid_t(&pfcp_sess_set_del_req->pgw_c_fqcsid, &tmp_csids); set_fq_csid_t(&pfcp_sess_set_del_req->up_fqcsid, local_csids); #endif /* DP_BUILD */ } } #ifdef CP_BUILD /** * @brief : Match peer node address * @param : num_node_addr, node addr count. * @param : peer_node_addr, * @param : peer_node_addrs, * @return : Returns 0 in case of match not found, 1 otherwise */ static int match_node_addr(uint8_t num_node_addr, node_address_t *peer_node_addr, node_address_t *peer_node_addrs) { int match = 0; node_address_t ip_addr = {0}, ip_addrs = {0}; memcpy(&ip_addr, peer_node_addr, sizeof(node_address_t)); for (uint8_t itr = 0; itr < num_node_addr; itr++) { memcpy(&ip_addrs, &peer_node_addrs[itr], sizeof(node_address_t)); if ((COMPARE_IP_ADDRESS(ip_addr, ip_addrs)) == 0) { match = 1; break; } } return match; } /** * @brief : get upf node address * @param : csids, * @param : upf_node_addrs, * @param : num_node_addr, * @return : Returns 0 in case of match not found, 1 otherwise */ static int8_t get_upf_node_entry(fqcsid_t *csids, node_address_t *upf_node_addrs, uint8_t *num_node_addr) { uint8_t ip_count = 0; int8_t ebi = 0; int8_t ebi_index = 0; int ret = 0; uint32_t teid_key = 0; ue_context *context = NULL; pdn_connection *pdn = NULL; sess_csid *tmp = NULL; sess_csid *current = NULL; for (uint8_t itr = 0; itr < csids->num_csid; itr++) { tmp = get_sess_csid_entry(csids->local_csid[itr], REMOVE_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to get CSID entry, CSID: %u\n", LOG_VALUE, csids->local_csid[itr]); continue; } /* Check SEID is not ZERO */ if ((tmp->cp_seid == 0) && (tmp->next == 0)) { continue; } current = tmp; while (current != NULL ) { teid_key = UE_SESS_ID(current->cp_seid); ebi = UE_BEAR_ID(current->cp_seid); ebi_index = GET_EBI_INDEX(ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Invalid EBI ID\n", LOG_VALUE); /* Assign Next node address */ tmp = current->next; current = tmp; continue; } ret = rte_hash_lookup_data(ue_context_by_fteid_hash, (const void *) &teid_key, (void **) &context); if (ret < 0 || context == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "ERROR : Failed to get UE context for teid : %u \n", LOG_VALUE, teid_key); /* Assign Next node address */ tmp = current->next; current = tmp; continue; } pdn = context->pdns[ebi_index]; if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "ERROR : Failed to get PDN context for seid : %u \n", LOG_VALUE, current->cp_seid); /* Assign Next node address */ tmp = current->next; current = tmp; continue; } if(is_present(&pdn->up_csid.node_addr)) { if ((match_node_addr(ip_count, &pdn->up_csid.node_addr, upf_node_addrs)) == 0) { fill_peer_info(&upf_node_addrs[ip_count++], &pdn->up_csid.node_addr); } } /* Assign Next node address */ tmp = current->next; current = tmp; } } *num_node_addr = ip_count; return 0; } #endif /* CP_BUILD */ /* Cleanup Session information by local csid*/ int8_t del_pfcp_peer_node_sess(node_address_t *node_addr, uint8_t iface) { pfcp_sess_set_del_req_t del_set_req_t = {0}; fqcsid_t *local_csids = NULL; fqcsid_ie_node_addr_t *tmp = NULL; fqcsid_t csids = {0}; peer_node_addr_key_t key = {0}; #ifdef CP_BUILD delete_thrtle_timer(node_addr); #endif /* Get local CSID associated with node */ local_csids = get_peer_addr_csids_entry(node_addr, UPDATE_NODE); if (local_csids == NULL) { key.iface = iface; if (node_addr->ip_type == PDN_TYPE_IPV4) { key.peer_node_addr.ip_type = PDN_TYPE_IPV4; key.peer_node_addr.ipv4_addr = node_addr->ipv4_addr; } else { key.peer_node_addr.ip_type = PDN_TYPE_IPV6; memcpy(key.peer_node_addr.ipv6_addr, node_addr->ipv6_addr, IPV6_ADDRESS_LEN); } tmp = get_peer_node_addr_entry(&key, UPDATE_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get CSID " "entry while deleting session information: %s \n", LOG_VALUE, strerror(errno)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer CSIDs are already cleanup, Node_Addr:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(node_addr->ipv4_addr)); return 0; } /* Get local CSID associated with node */ local_csids = get_peer_addr_csids_entry(&tmp->fqcsid_node_addr, UPDATE_NODE); if (local_csids == NULL) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get CSID " "entry while deleting session information: %s \n", LOG_VALUE, strerror(errno)); } /* Get the mapped local CSID */ for (int8_t itr = 0; itr < local_csids->num_csid; itr++) { csid_t *tmp = NULL; csid_key_t key = {0}; key.local_csid = local_csids->local_csid[itr]; memcpy(&key.node_addr, &local_csids->node_addr, sizeof(node_address_t)); tmp = get_peer_csid_entry(&key, iface, REMOVE_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get CSID " "while cleanup session information, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } for (int8_t itr1 = 0; itr1 < tmp->num_csid; itr1++) { csids.local_csid[csids.num_csid++] = tmp->local_csid[itr1]; } csids.node_addr = tmp->node_addr; } if (!csids.num_csid) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"CSIDs are already cleanup \n", LOG_VALUE); return 0; } #ifdef CP_BUILD uint8_t num_upf_node_addr = 0; node_address_t upf_node_addrs[MAX_CSID] = {0}; get_upf_node_entry(&csids, upf_node_addrs, &num_upf_node_addr); #endif /* CP_BUILD */ fill_pfcp_sess_set_del_req_t(&del_set_req_t, &csids, iface); /* Send the Delete set Request to peer node */ uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_set_del_req_t(&del_set_req_t, pfcp_msg); #ifdef CP_BUILD for (uint8_t itr = 0; itr < num_upf_node_addr; itr++) { int ret = set_dest_address(upf_node_addrs[itr], &upf_pfcp_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Send Pfcp Set Deletion Request to UP, Node Addr:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(upf_pfcp_sockaddr.ipv4.sin_addr.s_addr)); if (pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr, SENT) < 0 ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in sending PFCP " "Set Session Deletion Request, Error : %i\n", LOG_VALUE, errno); return -1; } } #else pfcp_header_t *header = (pfcp_header_t *) pfcp_msg; if (sendto(my_sock.sock_fd, (char *)pfcp_msg, encoded, MSG_DONTWAIT, (struct sockaddr *)&dest_addr_t.ipv4, sizeof(struct sockaddr_in)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in sending PFCP " "Set Session Deletion Request, Error : %i\n", LOG_VALUE, errno); return -1; } else { peer_address_t address; address.ipv4.sin_addr.s_addr = dest_addr_t.ipv4.sin_addr.s_addr; address.type = IPV4_TYPE; update_cli_stats((peer_address_t *) &address, header->message_type, SENT, SX); } #endif /* CP_BUILD */ return 0; } /* Fill PFCP SESSION SET SELETION RESPONSE */ void fill_pfcp_sess_set_del_resp(pfcp_sess_set_del_rsp_t *pfcp_del_resp, uint8_t cause_val, int offending_id) { node_address_t node_value = {0}; int ret = 0; memset(pfcp_del_resp, 0, sizeof(pfcp_sess_set_del_rsp_t)); set_pfcp_header(&pfcp_del_resp->header, PFCP_SESS_SET_DEL_RSP, 0); /*filling of node id*/ #ifdef CP_BUILD ret = fill_ip_addr(config.pfcp_ip.s_addr, config.pfcp_ip_v6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } #else ret = fill_ip_addr(dp_comm_ip.s_addr, dp_comm_ipv6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } #endif /*CP_BUILD*/ set_node_id(&(pfcp_del_resp->node_id), node_value); pfcp_set_ie_header(&pfcp_del_resp->cause.header, PFCP_IE_CAUSE, sizeof(pfcp_del_resp->cause.cause_value)); pfcp_del_resp->cause.cause_value = cause_val; RTE_SET_USED(offending_id); } int8_t del_csid_entry_hash(fqcsid_t *peer_csids, fqcsid_t *local_csids, uint8_t iface) { if (peer_csids != NULL) { for (int itr = 0; itr < peer_csids->num_csid; itr++) { csid_t *csids = NULL; csid_key_t key = {0}; key.local_csid = peer_csids->local_csid[itr]; memcpy(&key.node_addr, &peer_csids->node_addr, sizeof(node_address_t)); csids = get_peer_csid_entry(&key, iface, REMOVE_NODE); if (csids == NULL) continue; for (uint8_t itr1 = 0; itr1 < local_csids->num_csid; itr1++) { for (uint8_t itr2 = 0; itr2 < csids->num_csid; itr2++) { if (csids->local_csid[itr2] == local_csids->local_csid[itr1]) { for(uint8_t pos = itr2; pos < (csids->num_csid - 1); pos++ ) { csids->local_csid[pos] = csids->local_csid[pos + 1]; } csids->num_csid--; } } } if (csids->num_csid == 0) { if (del_peer_csid_entry(&key, iface)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in deleting " "peer CSID entry, Error : %i\n", LOG_VALUE, errno); /* TODO ERROR HANDLING */ return -1; } fqcsid_t *tmp = NULL; tmp = get_peer_addr_csids_entry(&peer_csids->node_addr, UPDATE_NODE); if (tmp != NULL) { for (uint8_t itr3 = 0; itr3 < tmp->num_csid; itr3++) { if (tmp->local_csid[itr3] == peer_csids->local_csid[itr]) { for(uint8_t pos = itr3; pos < (tmp->num_csid - 1); pos++ ) { tmp->local_csid[pos] = tmp->local_csid[pos + 1]; } tmp->num_csid--; } } if (!tmp->num_csid) { if (del_peer_addr_csids_entry(&peer_csids->node_addr)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in deleting " "peer CSID entry, Error : %i\n", LOG_VALUE, errno); /* TODO ERROR HANDLING */ return -1; } } } } } } return 0; } #if defined(CP_BUILD) && defined(USE_CSID) int update_peer_node_csid(pfcp_sess_mod_rsp_t *pfcp_sess_mod_rsp, pdn_connection *pdn) { uint8_t num_csid = 0; node_address_t node_addr = {0}; fqcsid_t up_old_csid = {0}; ue_context *context = NULL; context = pdn->context; /* UP FQ-CSID */ if (pfcp_sess_mod_rsp->up_fqcsid.header.len) { if (pfcp_sess_mod_rsp->up_fqcsid.number_of_csids) { uint8_t ret = 0; uint8_t match = 0; fqcsid_t *tmp = NULL; //fqcsid_t fqcsid = {0}; uint16_t old_csid = 0; if (context->up_fqcsid != NULL) { memcpy(&up_old_csid, &pdn->up_csid, sizeof(fqcsid_t)); old_csid = context->up_fqcsid->local_csid[context->up_fqcsid->num_csid - 1]; } else { context->up_fqcsid = rte_zmalloc_socket(NULL, sizeof(sess_fqcsid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (context->up_fqcsid == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to allocate the memory for fqcsids entry\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } if (pfcp_sess_mod_rsp->up_fqcsid.fqcsid_node_id_type == IPV4_GLOBAL_UNICAST) { node_addr.ip_type = PDN_TYPE_IPV4; memcpy(&node_addr.ipv4_addr, &pfcp_sess_mod_rsp->up_fqcsid.node_address, IPV4_SIZE); } else if (pfcp_sess_mod_rsp->up_fqcsid.fqcsid_node_id_type == IPV6_GLOBAL_UNICAST) { node_addr.ip_type = PDN_TYPE_IPV6; memcpy(&node_addr.ipv6_addr, &pfcp_sess_mod_rsp->up_fqcsid.node_address, IPV6_SIZE); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "te CSID entry\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Stored the UP CSID by UP Node address */ tmp = get_peer_addr_csids_entry(&node_addr, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to get peer csid entry while update CSID entry\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* coping node address */ memcpy(&tmp->node_addr, &node_addr, sizeof(node_address_t)); /* TODO: Re-write the optimizes way */ for(uint8_t itr = 0; itr < pfcp_sess_mod_rsp->up_fqcsid.number_of_csids; itr++) { match = 0; for (uint8_t itr1 = 0; itr1 < tmp->num_csid; itr1++) { if (tmp->local_csid[itr1] == pfcp_sess_mod_rsp->up_fqcsid.pdn_conn_set_ident[itr]) { match = 1; break; } } if (!match) { tmp->local_csid[tmp->num_csid++] = pfcp_sess_mod_rsp->up_fqcsid.pdn_conn_set_ident[itr]; } } /* Update the UP CSID in the context */ if (context->up_fqcsid->num_csid) { match_and_add_pfcp_sess_fqcsid(&pfcp_sess_mod_rsp->up_fqcsid, context->up_fqcsid); } else { add_pfcp_sess_fqcsid(&pfcp_sess_mod_rsp->up_fqcsid, context->up_fqcsid); } //memcpy(&fqcsid.node_addr, &node_addr, sizeof(node_address_t)); for (uint8_t itr2 = 0; itr2 < tmp->num_csid; itr2++) { if (tmp->local_csid[itr2] == old_csid) { for(uint8_t pos = itr2; pos < (tmp->num_csid - 1); pos++ ) { tmp->local_csid[pos] = tmp->local_csid[pos + 1]; } tmp->num_csid--; } } /* Remove old up csid and node address */ remove_csid_from_cntx(context->up_fqcsid, &up_old_csid); /* Delete old up csid link with local csid entry */ if (up_old_csid.num_csid) { csid_key_t key = {0}; key.local_csid = up_old_csid.local_csid[num_csid]; memcpy(&key.node_addr, &up_old_csid.node_addr, sizeof(node_address_t)); del_peer_csid_entry(&key, SX_PORT_ID); } fill_pdn_fqcsid_info(&pdn->up_csid, context->up_fqcsid); /* TODO: Add the handling if SGW or PGW not support Partial failure */ /* Link peer node SGW or PGW csid with local csid */ if (context->cp_mode != PGWC) { ret = update_peer_csid_link(&pdn->up_csid, &pdn->sgw_csid); } else { ret = update_peer_csid_link(&pdn->up_csid, &pdn->pgw_csid); } if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error: peer csid entry not found \n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (link_sess_with_peer_csid(&pdn->up_csid, pdn, SX_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Failed to Link " "Session with MME CSID \n", LOG_VALUE); return -1; } /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; peer_csid_key_t key = {0}; key.iface = SX_PORT_ID; key.peer_local_csid = up_old_csid.local_csid[num_csid]; memcpy(&key.peer_node_addr, &up_old_csid.node_addr, sizeof(node_address_t)); tmp1 = get_sess_peer_csid_entry(&key, REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seid_by_peer_csid_hash, &key, tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry" " for CSID = %u \n", LOG_VALUE, up_old_csid.local_csid[num_csid]); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Delete Local CSID entry */ del_sess_peer_csid_entry(&key); } } } } return 0; } #endif /* CP_BUILD && USE_CSID */ int8_t is_present(node_address_t *node) { if (node->ip_type == PDN_TYPE_IPV4) { if(node->ipv4_addr) { return 1; } } else if (node->ip_type == PDN_TYPE_IPV6) { if (node->ipv6_addr) { return 1; } } return 0; } void fill_peer_info(node_address_t *dst_info, node_address_t *src_info) { if ((src_info->ip_type == IPV4_GLOBAL_UNICAST) || (src_info->ip_type == PDN_TYPE_IPV4)) { dst_info->ip_type = PDN_TYPE_IPV4; dst_info->ipv4_addr = src_info->ipv4_addr; } else { dst_info->ip_type = PDN_TYPE_IPV6; memcpy(&dst_info->ipv6_addr, &src_info->ipv6_addr, IPV6_ADDRESS_LEN); } }
nikhilc149/e-utran-features-bug-fixes
ulpc/legacy_df/include/Common.h
/* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ #ifndef __COMMON_H_ #define __COMMON_H_ #include <sys/types.h> #include <sys/time.h> #include <sys/stat.h> #include <sys/statvfs.h> #include <netinet/ip.h> #include <netinet/udp.h> #include <netinet/if_ether.h> #include <fstream> #include <vector> #include "epctools.h" #include "esocket.h" #include "elogger.h" #include "emgmt.h" #include "efd.h" #define LEGACY_DF_ACK 201 #define TRUE 1 #define RET_SUCCESS 0 #define RET_FAILURE 1 #define DFPACKET_ACK 0xff #define DF_CONNECT_TIMER_VALUE 10000 #define BACKLOG_CONNECTIION 10 #define LOG_AUDIT 3 #define LOG_SYSTEM 3 #define LOG_TEST3 3 #define LOG_TEST3_SINKSET 3 #define __file__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) /* * @brief : Maintains data related to acknowledgement packet */ #pragma pack(push, 1) typedef struct AckPacket { uint8_t packetLength; struct AckPacketHeader { uint8_t packetType; uint32_t sequenceNumber; } header; } AckPacket_t; #pragma pack(pop) /* * @brief : Maintains data to be sent to DF */ #pragma pack(push, 1) typedef struct DfPacket { uint32_t packetLength; struct PacketHeader { uint32_t sequenceNumber; uint64_t liIdentifier; uint64_t imsiNumber; uint32_t dataLength; } header; uint8_t data[0]; } DfPacket_t; #pragma pack(pop) /* * @brief : Maintains data related to configurations required in DDFx */ struct Configurations { std::string strModuleName; cpStr legacyIp; UShort legacyPort; std::string strPcapFilePath; }; #endif /* __COMMON_H_ */
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c_messages/modify_bearer.c
<reponame>nikhilc149/e-utran-features-bug-fixes<filename>cp/gtpv2c_messages/modify_bearer.c /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ue.h" #include "gtp_messages.h" #include "gtpv2c_set_ie.h" #include "../cp_dp_api/vepc_cp_dp_api.h" #include "../pfcp_messages/pfcp_set_ie.h" #include "cp/cp_app.h" #include "gw_adapter.h" #include "sm_enum.h" #include "pfcp.h" #include "gtpc_session.h" extern pfcp_config_t config; extern int clSystemLog; /** * @brief : Maintains parsed data from modify bearer request */ struct parse_modify_bearer_request_t { ue_context *context; pdn_connection *pdn; eps_bearer *bearer; gtpv2c_ie *bearer_context_to_be_created_ebi; gtpv2c_ie *s1u_enb_fteid; uint8_t *delay; uint32_t *s11_mme_gtpc_fteid; }; extern uint32_t num_adc_rules; extern uint32_t adc_rule_id[]; /** * @brief : from parameters, populates gtpv2c message 'modify bearer response' and * populates required information elements as defined by * clause 7.2.8 3gpp 29.274 * @param : gtpv2c_tx * transmission buffer to contain 'modify bearer request' message * @param : sequence * sequence number as described by clause 7.6 3gpp 29.274 * @param : context * UE Context data structure pertaining to the bearer to be modified * @param : bearer * bearer data structure to be modified * @return : Returns nothing */ int set_modify_bearer_response(gtpv2c_header_t *gtpv2c_tx, uint32_t sequence, ue_context *context, eps_bearer *bearer, mod_bearer_req_t *mbr) { int ret = 0; uint8_t _ebi = bearer->eps_bearer_id; pdn_connection *pdn = NULL; int ebi_index = GET_EBI_INDEX(_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); } upf_context_t *upf_ctx = NULL; /*Retrive bearer id from bearer --> context->pdns[]->upf_ip*/ if ((ret = upf_context_entry_lookup(context->pdns[ebi_index]->upf_ip, &upf_ctx)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR:Not found UPF context\n", LOG_VALUE); return -1; } mod_bearer_rsp_t mb_resp = {0}; if((SGWC == context->cp_mode) || (SAEGWC == context->cp_mode)) { set_gtpv2c_teid_header((gtpv2c_header_t *) &mb_resp, GTP_MODIFY_BEARER_RSP, context->s11_mme_gtpc_teid, sequence, 0); }else{ set_gtpv2c_teid_header((gtpv2c_header_t *) &mb_resp, GTP_MODIFY_BEARER_RSP, bearer->pdn->s5s8_sgw_gtpc_teid, sequence, 0); } if(context->msisdn !=0 && PGWC == context->cp_mode) { set_ie_header(&mb_resp.msisdn.header, GTP_IE_MSISDN, IE_INSTANCE_ZERO, BINARY_MSISDN_LEN); mb_resp.msisdn.msisdn_number_digits = context->msisdn; } set_cause_accepted(&mb_resp.cause, IE_INSTANCE_ZERO); mb_resp.bearer_count = mbr->bearer_count; for (uint8_t uiCnt = 0; uiCnt < mbr->bearer_count; ++uiCnt) { int ebi_index = GET_EBI_INDEX(mbr->bearer_contexts_to_be_modified[uiCnt].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); } bearer = context->eps_bearers[ebi_index]; if(bearer == NULL) continue; pdn = bearer->pdn; set_ie_header(&mb_resp.bearer_contexts_modified[uiCnt].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_cause_accepted(&mb_resp.bearer_contexts_modified[uiCnt].cause, IE_INSTANCE_ZERO); mb_resp.bearer_contexts_modified[uiCnt].header.len += sizeof(struct cause_ie_hdr_t) + IE_HEADER_SIZE; set_ebi(&mb_resp.bearer_contexts_modified[uiCnt].eps_bearer_id, IE_INSTANCE_ZERO, bearer->eps_bearer_id); mb_resp.bearer_contexts_modified[uiCnt].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; if (context->cp_mode != PGWC) { if(context->indication_flag.s11tf == 1){ bearer->s11u_sgw_gtpu_teid = bearer->s1u_sgw_gtpu_teid; memcpy(&bearer->s11u_sgw_gtpu_ip, &bearer->s1u_sgw_gtpu_ip, sizeof(node_address_t)); mb_resp.bearer_contexts_modified[uiCnt].header.len += set_gtpc_fteid(&mb_resp.bearer_contexts_modified[uiCnt].s11_u_sgw_fteid, GTPV2C_IFTYPE_S11U_SGW_GTPU, IE_INSTANCE_THREE, upf_ctx->s1u_ip, bearer->s11u_sgw_gtpu_teid); }else{ mb_resp.bearer_contexts_modified[uiCnt].header.len += set_gtpc_fteid(&mb_resp.bearer_contexts_modified[uiCnt].s1u_sgw_fteid, GTPV2C_IFTYPE_S1U_SGW_GTPU, IE_INSTANCE_ZERO, upf_ctx->s1u_ip, bearer->s1u_sgw_gtpu_teid); } } } #ifdef USE_CSID pdn = GET_PDN(context, ebi_index); if(pdn->flag_fqcsid_modified == TRUE) { /* Set the SGW FQ-CSID */ if (context->cp_mode != PGWC) { if (pdn->sgw_csid.num_csid) { set_gtpc_fqcsid_t(&mb_resp.sgw_fqcsid, IE_INSTANCE_ONE, &(pdn)->sgw_csid); } } else { if ((pdn)->pgw_csid.num_csid) { set_gtpc_fqcsid_t(&mb_resp.pgw_fqcsid, IE_INSTANCE_ZERO, &(pdn)->pgw_csid); } } } #endif /* USE_CSID */ if(context->pra_flag){ set_presence_reporting_area_action_ie(&mb_resp.pres_rptng_area_act, context); context->pra_flag = 0; } /* Update status of mbr processing for ue*/ context->req_status.seq = 0; context->req_status.status = REQ_PROCESS_DONE; return (encode_mod_bearer_rsp(&mb_resp, (uint8_t *)gtpv2c_tx)); //return ntohs(gtpv2c_tx->gtpc.message_len); } /*MODIFY RESPONSE FUNCTION WHEN PGWC returns MBR RESPONSE to SGWC * in HANDOVER SCENARIO*/ void set_modify_bearer_response_handover(gtpv2c_header_t *gtpv2c_tx, uint32_t sequence, ue_context *context, eps_bearer *bearer, mod_bearer_req_t *mbr) { int ret = 0; int _ebi = bearer->eps_bearer_id; int ebi_index = GET_EBI_INDEX(_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); } upf_context_t *upf_ctx = NULL; /*Retrive bearer id from bearer --> context->pdns[]->upf_ip*/ if ((ret = upf_context_entry_lookup(context->pdns[ebi_index]->upf_ip, &upf_ctx)) < 0) { return; } mod_bearer_rsp_t mb_resp = {0}; if((SGWC == context->cp_mode) || (SAEGWC == context->cp_mode)) { set_gtpv2c_teid_header((gtpv2c_header_t *) &mb_resp, GTP_MODIFY_BEARER_RSP, context->s11_mme_gtpc_teid, sequence, 0); }else{ set_gtpv2c_teid_header((gtpv2c_header_t *) &mb_resp, GTP_MODIFY_BEARER_RSP, bearer->pdn->s5s8_sgw_gtpc_teid, sequence, 0); } /* Add MSISDN IE in case of only handover */ if(context->msisdn !=0 && PGWC == context->cp_mode && context->sgwu_changed == TRUE) { set_ie_header(&mb_resp.msisdn.header, GTP_IE_MSISDN, IE_INSTANCE_ZERO, BINARY_MSISDN_LEN); mb_resp.msisdn.msisdn_number_digits = context->msisdn; } set_cause_accepted(&mb_resp.cause, IE_INSTANCE_ZERO); { mb_resp.bearer_count = mbr->bearer_count; for (uint8_t uiCnt = 0; uiCnt < mbr->bearer_count; uiCnt++) { set_ie_header(&mb_resp.bearer_contexts_modified[uiCnt].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_cause_accepted(&mb_resp.bearer_contexts_modified[uiCnt].cause, IE_INSTANCE_ZERO); mb_resp.bearer_contexts_modified[uiCnt].header.len += sizeof(struct cause_ie_hdr_t) + IE_HEADER_SIZE; set_ebi(&mb_resp.bearer_contexts_modified[uiCnt].eps_bearer_id, IE_INSTANCE_ZERO, mbr->bearer_contexts_to_be_modified[uiCnt].eps_bearer_id.ebi_ebi); mb_resp.bearer_contexts_modified[uiCnt].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; ebi_index = GET_EBI_INDEX(mbr->bearer_contexts_to_be_modified[uiCnt].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); } bearer = context->eps_bearers[ebi_index]; if ((SGWC == context->cp_mode) || (SAEGWC == context->cp_mode)) { mb_resp.bearer_contexts_modified[uiCnt].header.len += set_gtpc_fteid(&mb_resp.bearer_contexts_modified[uiCnt].s1u_sgw_fteid, GTPV2C_IFTYPE_S1U_SGW_GTPU, IE_INSTANCE_ZERO, bearer->s1u_sgw_gtpu_ip, bearer->s1u_sgw_gtpu_teid); } else { mb_resp.bearer_contexts_modified[uiCnt].header.len += set_gtpc_fteid(&mb_resp.bearer_contexts_modified[uiCnt].s1u_sgw_fteid, GTPV2C_IFTYPE_S5S8_PGW_GTPU, IE_INSTANCE_ZERO, bearer->s5s8_pgw_gtpu_ip, bearer->s5s8_pgw_gtpu_teid); } } } if(context->pra_flag){ set_presence_reporting_area_action_ie(&mb_resp.pres_rptng_area_act, context); context->pra_flag = 0; } /* Update status of mbr processing for ue*/ context->req_status.seq = 0; context->req_status.status = REQ_PROCESS_DONE; encode_mod_bearer_rsp(&mb_resp, (uint8_t *)gtpv2c_tx); } int8_t set_mbr_upd_sgw_csid_req(gtpv2c_header_t *gtpv2c_tx, pdn_connection *pdn, uint8_t eps_bearer_id) { mod_bearer_req_t mbr = {0}; set_gtpv2c_teid_header((gtpv2c_header_t *)&mbr.header, GTP_MODIFY_BEARER_REQ, 0, pdn->context->sequence, 0); mbr.header.teid.has_teid.teid = pdn->s5s8_pgw_gtpc_teid; #ifdef USE_CSID /* Set the SGW FQ-CSID */ if (pdn->sgw_csid.num_csid) { set_gtpc_fqcsid_t(&mbr.sgw_fqcsid, IE_INSTANCE_ONE, &pdn->sgw_csid); } #endif /* USE_CSID */ mbr.bearer_count = 1; set_ie_header(&mbr.bearer_contexts_to_be_modified[0].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_ebi(&mbr.bearer_contexts_to_be_modified[0].eps_bearer_id, IE_INSTANCE_ZERO, eps_bearer_id); mbr.bearer_contexts_to_be_modified[0].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; encode_mod_bearer_req(&mbr, (uint8_t *)gtpv2c_tx); return 0; } void set_modify_bearer_request(gtpv2c_header_t *gtpv2c_tx, pdn_connection *pdn, eps_bearer *bearer) { int len = 0 ; mod_bearer_req_t mbr = {0}; struct ue_context_t *context = NULL; eps_bearer *def_bearer = bearer; struct teid_value_t *teid_value = NULL; int ret = 0; teid_key_t teid_key = {0}; /* Check PDN and Context are not NULL */ if((pdn == NULL) && (pdn->context == NULL) ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"UE contex not found : Warnning \n", LOG_VALUE); return; } /* Get the UE Context */ context = pdn->context; set_gtpv2c_teid_header((gtpv2c_header_t *)&mbr.header, GTP_MODIFY_BEARER_REQ, 0, context->sequence, 0); mbr.header.teid.has_teid.teid = pdn->s5s8_pgw_gtpc_teid; /* TODO: Need to verify */ set_gtpc_fteid(&mbr.sender_fteid_ctl_plane, GTPV2C_IFTYPE_S5S8_SGW_GTPC, IE_INSTANCE_ZERO, pdn->s5s8_sgw_gtpc_ip, pdn->s5s8_sgw_gtpc_teid); teid_value = rte_zmalloc_socket(NULL, sizeof(teid_value_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (teid_value == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for teid value, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return; } teid_value->teid = pdn->s5s8_sgw_gtpc_teid; teid_value->msg_type = gtpv2c_tx->gtpc.message_type; snprintf(teid_key.teid_key, PROC_LEN, "%s%d", get_proc_string(pdn->proc), context->sequence); /* Add the entry for sequence and teid value for error handling */ if (context->cp_mode != SAEGWC) { ret = add_seq_number_for_teid(teid_key, teid_value); if(ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "Sequence number for TEID: %u\n", LOG_VALUE, teid_value->teid); return; } } if(context->pra_flag){ set_presence_reporting_area_info_ie(&mbr.pres_rptng_area_info, context); context->pra_flag = 0; } /* Note:Below condition is added for the flow ERAB Modification * Update. sepcs ref: 23.401 Section 5.4.7-1*/ if(context->second_rat_flag == TRUE ) { uint8_t instance = 0; mbr.second_rat_count = context->second_rat_count; for(uint8_t i = 0; i < context->second_rat_count; i++) { mbr.secdry_rat_usage_data_rpt[i].spare2 = 0; mbr.secdry_rat_usage_data_rpt[i].irsgw = context->second_rat[i].irsgw; mbr.secdry_rat_usage_data_rpt[i].irpgw = context->second_rat[i].irpgw; mbr.secdry_rat_usage_data_rpt[i].secdry_rat_type = context->second_rat[i].rat_type; mbr.secdry_rat_usage_data_rpt[i].ebi = context->second_rat[i].eps_id; mbr.secdry_rat_usage_data_rpt[i].spare3 = 0; mbr.secdry_rat_usage_data_rpt[i].start_timestamp = context->second_rat[i].start_timestamp; mbr.secdry_rat_usage_data_rpt[i].end_timestamp = context->second_rat[i].end_timestamp; mbr.secdry_rat_usage_data_rpt[i].usage_data_dl = context->second_rat[i].usage_data_dl; mbr.secdry_rat_usage_data_rpt[i].usage_data_ul = context->second_rat[i].usage_data_ul; set_ie_header(&mbr.secdry_rat_usage_data_rpt[i].header, GTP_IE_SECDRY_RAT_USAGE_DATA_RPT, instance++, sizeof(gtp_secdry_rat_usage_data_rpt_ie_t) - sizeof(ie_header_t)); } } if(context->uli_flag != FALSE) { if (context->uli.lai) { mbr.uli.lai = context->uli.lai; mbr.uli.lai2.lai_mcc_digit_2 = context->uli.lai2.lai_mcc_digit_2; mbr.uli.lai2.lai_mcc_digit_1 = context->uli.lai2.lai_mcc_digit_1; mbr.uli.lai2.lai_mnc_digit_3 = context->uli.lai2.lai_mnc_digit_3; mbr.uli.lai2.lai_mcc_digit_3 = context->uli.lai2.lai_mcc_digit_3; mbr.uli.lai2.lai_mnc_digit_2 = context->uli.lai2.lai_mnc_digit_2; mbr.uli.lai2.lai_mnc_digit_1 = context->uli.lai2.lai_mnc_digit_1; mbr.uli.lai2.lai_lac = context->uli.lai2.lai_lac; len += sizeof(mbr.uli.lai2); } if (context->uli_flag & (1 << 0)) { mbr.uli.tai = context->uli.tai; mbr.uli.tai2.tai_mcc_digit_2 = context->uli.tai2.tai_mcc_digit_2; mbr.uli.tai2.tai_mcc_digit_1 = context->uli.tai2.tai_mcc_digit_1; mbr.uli.tai2.tai_mnc_digit_3 = context->uli.tai2.tai_mnc_digit_3; mbr.uli.tai2.tai_mcc_digit_3 = context->uli.tai2.tai_mcc_digit_3; mbr.uli.tai2.tai_mnc_digit_2 = context->uli.tai2.tai_mnc_digit_2; mbr.uli.tai2.tai_mnc_digit_1 = context->uli.tai2.tai_mnc_digit_1; mbr.uli.tai2.tai_tac = context->uli.tai2.tai_tac; len += sizeof(mbr.uli.tai2); } if (context->uli_flag & (1 << 3)) { mbr.uli.rai = context->uli.rai; mbr.uli.rai2.ria_mcc_digit_2 = context->uli.rai2.ria_mcc_digit_2; mbr.uli.rai2.ria_mcc_digit_1 = context->uli.rai2.ria_mcc_digit_1; mbr.uli.rai2.ria_mnc_digit_3 = context->uli.rai2.ria_mnc_digit_3; mbr.uli.rai2.ria_mcc_digit_3 = context->uli.rai2.ria_mcc_digit_3; mbr.uli.rai2.ria_mnc_digit_2 = context->uli.rai2.ria_mnc_digit_2; mbr.uli.rai2.ria_mnc_digit_1 = context->uli.rai2.ria_mnc_digit_1; mbr.uli.rai2.ria_lac = context->uli.rai2.ria_lac; mbr.uli.rai2.ria_rac = context->uli.rai2.ria_rac; len += sizeof(mbr.uli.rai2); } if (context->uli_flag & (1 << 2)) { mbr.uli.sai = context->uli.sai; mbr.uli.sai2.sai_mcc_digit_2 = context->uli.sai2.sai_mcc_digit_2; mbr.uli.sai2.sai_mcc_digit_1 = context->uli.sai2.sai_mcc_digit_1; mbr.uli.sai2.sai_mnc_digit_3 = context->uli.sai2.sai_mnc_digit_3; mbr.uli.sai2.sai_mcc_digit_3 = context->uli.sai2.sai_mcc_digit_3; mbr.uli.sai2.sai_mnc_digit_2 = context->uli.sai2.sai_mnc_digit_2; mbr.uli.sai2.sai_mnc_digit_1 = context->uli.sai2.sai_mnc_digit_1; mbr.uli.sai2.sai_lac = context->uli.sai2.sai_lac; mbr.uli.sai2.sai_sac = context->uli.sai2.sai_sac; len += sizeof(mbr.uli.sai2); } if (context->uli_flag & (1 << 1)) { mbr.uli.cgi = context->uli.cgi; mbr.uli.cgi2.cgi_mcc_digit_2 = context->uli.cgi2.cgi_mcc_digit_2; mbr.uli.cgi2.cgi_mcc_digit_1 = context->uli.cgi2.cgi_mcc_digit_1; mbr.uli.cgi2.cgi_mnc_digit_3 = context->uli.cgi2.cgi_mnc_digit_3; mbr.uli.cgi2.cgi_mcc_digit_3 = context->uli.cgi2.cgi_mcc_digit_3; mbr.uli.cgi2.cgi_mnc_digit_2 = context->uli.cgi2.cgi_mnc_digit_2; mbr.uli.cgi2.cgi_mnc_digit_1 = context->uli.cgi2.cgi_mnc_digit_1; mbr.uli.cgi2.cgi_lac = context->uli.cgi2.cgi_lac; mbr.uli.cgi2.cgi_ci = context->uli.cgi2.cgi_ci; len += sizeof(mbr.uli.cgi2); } if (context->uli_flag & (1 << 4)) { mbr.uli.ecgi = context->uli.ecgi; mbr.uli.ecgi2.ecgi_mcc_digit_2 = context->uli.ecgi2.ecgi_mcc_digit_2; mbr.uli.ecgi2.ecgi_mcc_digit_1 = context->uli.ecgi2.ecgi_mcc_digit_1; mbr.uli.ecgi2.ecgi_mnc_digit_3 = context->uli.ecgi2.ecgi_mnc_digit_3; mbr.uli.ecgi2.ecgi_mcc_digit_3 = context->uli.ecgi2.ecgi_mcc_digit_3; mbr.uli.ecgi2.ecgi_mnc_digit_2 = context->uli.ecgi2.ecgi_mnc_digit_2; mbr.uli.ecgi2.ecgi_mnc_digit_1 = context->uli.ecgi2.ecgi_mnc_digit_1; mbr.uli.ecgi2.ecgi_spare = context->uli.ecgi2.ecgi_spare; mbr.uli.ecgi2.eci = context->uli.ecgi2.eci; len += sizeof(mbr.uli.ecgi2); } if (context->uli.macro_enodeb_id) { mbr.uli.macro_enodeb_id = context->uli.macro_enodeb_id; mbr.uli.macro_enodeb_id2.menbid_mcc_digit_2 = context->uli.macro_enodeb_id2.menbid_mcc_digit_2; mbr.uli.macro_enodeb_id2.menbid_mcc_digit_1 = context->uli.macro_enodeb_id2.menbid_mcc_digit_1; mbr.uli.macro_enodeb_id2.menbid_mnc_digit_3 = context->uli.macro_enodeb_id2.menbid_mnc_digit_3; mbr.uli.macro_enodeb_id2.menbid_mcc_digit_3 = context->uli.macro_enodeb_id2.menbid_mcc_digit_3; mbr.uli.macro_enodeb_id2.menbid_mnc_digit_2 = context->uli.macro_enodeb_id2.menbid_mnc_digit_2; mbr.uli.macro_enodeb_id2.menbid_mnc_digit_1 = context->uli.macro_enodeb_id2.menbid_mnc_digit_1; mbr.uli.macro_enodeb_id2.menbid_spare = context->uli.macro_enodeb_id2.menbid_spare; mbr.uli.macro_enodeb_id2.menbid_macro_enodeb_id = context->uli.macro_enodeb_id2.menbid_macro_enodeb_id; mbr.uli.macro_enodeb_id2.menbid_macro_enb_id2 = context->uli.macro_enodeb_id2.menbid_macro_enb_id2; len += sizeof(mbr.uli.macro_enodeb_id2); } if (context->uli.extnded_macro_enb_id) { mbr.uli.extnded_macro_enb_id = context->uli.extnded_macro_enb_id; mbr.uli.extended_macro_enodeb_id2.emenbid_mcc_digit_1 = context->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_1; mbr.uli.extended_macro_enodeb_id2.emenbid_mnc_digit_3 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_3; mbr.uli.extended_macro_enodeb_id2.emenbid_mcc_digit_3 = context->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_3; mbr.uli.extended_macro_enodeb_id2.emenbid_mnc_digit_2 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_2; mbr.uli.extended_macro_enodeb_id2.emenbid_mnc_digit_1 = context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_1; mbr.uli.extended_macro_enodeb_id2.emenbid_smenb = context->uli.extended_macro_enodeb_id2.emenbid_smenb; mbr.uli.extended_macro_enodeb_id2.emenbid_spare = context->uli.extended_macro_enodeb_id2.emenbid_spare; mbr.uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id = context->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id; mbr.uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2 = context->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2; len += sizeof(mbr.uli.extended_macro_enodeb_id2); } len += 1; set_ie_header(&mbr.uli.header, GTP_IE_USER_LOC_INFO, IE_INSTANCE_ZERO, len); } if(context->serving_nw_flag == TRUE) { set_ie_header(&mbr.serving_network.header, GTP_IE_SERVING_NETWORK, IE_INSTANCE_ZERO, sizeof(gtp_serving_network_ie_t) - sizeof(ie_header_t)); mbr.serving_network.mnc_digit_1 = context->serving_nw.mnc_digit_1; mbr.serving_network.mnc_digit_2 = context->serving_nw.mnc_digit_2; mbr.serving_network.mnc_digit_3 = context->serving_nw.mnc_digit_3; mbr.serving_network.mcc_digit_1 = context->serving_nw.mcc_digit_1; mbr.serving_network.mcc_digit_2 = context->serving_nw.mcc_digit_2; mbr.serving_network.mcc_digit_3 = context->serving_nw.mcc_digit_3; } if(context->indication_flag.oi == 1 || context->indication_flag.s11tf == 1){ if(context->mo_exception_flag == TRUE){ mbr.mo_exception_data_cntr.timestamp_value = context->mo_exception_data_counter.timestamp_value; mbr.mo_exception_data_cntr.counter_value = context->mo_exception_data_counter.counter_value; set_ie_header(&mbr.mo_exception_data_cntr.header, GTP_IE_COUNTER, IE_INSTANCE_ZERO, sizeof(gtp_counter_ie_t) - sizeof(ie_header_t)); context->mo_exception_flag = FALSE; } } if(context->uci_flag == TRUE){ mbr.uci.mnc_digit_1 = context->uci.mnc_digit_1; mbr.uci.mnc_digit_2 = context->uci.mnc_digit_2; mbr.uci.mnc_digit_3 = context->uci.mnc_digit_3; mbr.uci.mcc_digit_1 = context->uci.mcc_digit_1; mbr.uci.mcc_digit_2 = context->uci.mcc_digit_2; mbr.uci.mcc_digit_3 = context->uci.mcc_digit_3; mbr.uci.spare2 = 0; mbr.uci.csg_id = context->uci.csg_id; mbr.uci.csg_id2 = context->uci.csg_id2; mbr.uci.access_mode = context->uci.access_mode; mbr.uci.spare3 = 0; mbr.uci.lcsg = context->uci.lcsg; mbr.uci.cmi = context->uci.cmi; set_ie_header(&mbr.uci.header, GTP_IE_USER_CSG_INFO, IE_INSTANCE_ZERO, sizeof(gtp_user_csg_info_ie_t) - sizeof(ie_header_t)); } if((context->ltem_rat_type_flag == TRUE) && (context->indication_flag.oi == 1 || context->rat_type_flag == TRUE)) { /** * Need to verify this condition * if rat type is lte-m and this flag is set then send lte-m rat type * else send wb-e-utran rat type * since anyway rat_type will be stored automattically like this no need to check * if(context->indication_flag.ltempi == 1) */ set_ie_header(&mbr.rat_type.header, GTP_IE_RAT_TYPE, IE_INSTANCE_ZERO, sizeof(gtp_rat_type_ie_t) - sizeof(ie_header_t)); mbr.rat_type.rat_type = context->rat_type.rat_type; } if (context->selection_flag == TRUE) { mbr.selection_mode.spare2 = context->select_mode.spare2; mbr.selection_mode.selec_mode = context->select_mode.selec_mode; set_ie_header(&mbr.selection_mode.header, GTP_IE_SELECTION_MODE, IE_INSTANCE_ZERO, sizeof(uint8_t)); } if(context->ue_time_zone_flag == TRUE) { mbr.ue_time_zone.time_zone = context->tz.tz; mbr.ue_time_zone.daylt_svng_time = context->tz.dst; mbr.ue_time_zone.spare2 = 0; set_ie_header(&mbr.ue_time_zone.header, GTP_IE_UE_TIME_ZONE, IE_INSTANCE_ZERO, (sizeof(uint8_t) * 2)); } if(context->indication_flag.oi == 1 || context->update_sgw_fteid == TRUE) { mbr.bearer_count = 0; for (uint8_t uiCnt = 0; uiCnt < MAX_BEARERS; ++uiCnt) { bearer = pdn->eps_bearers[uiCnt]; if(bearer == NULL) { continue; } mbr.bearer_count++; set_ie_header(&mbr.bearer_contexts_to_be_modified[uiCnt].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_ebi(&mbr.bearer_contexts_to_be_modified[uiCnt].eps_bearer_id, IE_INSTANCE_ZERO, bearer->eps_bearer_id); mbr.bearer_contexts_to_be_modified[uiCnt].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; /* * TODO : Below if condition is used to handle ip issue caused by use of * htonl or ntohl, Need to resolve this issue */ if(def_bearer->pdn->default_bearer_id == mbr.bearer_contexts_to_be_modified[uiCnt].eps_bearer_id.ebi_ebi) { ret = set_address(&bearer->s5s8_sgw_gtpu_ip, &bearer->s5s8_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } }else{ ret = set_address(&bearer->s5s8_sgw_gtpu_ip, &bearer->s5s8_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } /*TODO: NEED to revist here: why below condition was there if(pdn->proc == MODIFICATION_PROC){ // Refer spec 23.274.Table 7.2.7-2 } */ } mbr.bearer_contexts_to_be_modified[uiCnt].header.len += set_gtpc_fteid(&mbr.bearer_contexts_to_be_modified[uiCnt].s58_u_sgw_fteid, GTPV2C_IFTYPE_S5S8_SGW_GTPU, IE_INSTANCE_ONE,bearer->s5s8_sgw_gtpu_ip, (bearer->s5s8_sgw_gtpu_teid)); } } if(pdn->flag_fqcsid_modified == TRUE) { #ifdef USE_CSID /* Set the SGW FQ-CSID */ if (pdn->sgw_csid.num_csid) { set_gtpc_fqcsid_t(&mbr.sgw_fqcsid, IE_INSTANCE_ONE, &pdn->sgw_csid); } if ((pdn->context)->mme_changed_flag == TRUE) { /* Set the MME FQ-CSID */ if (pdn->mme_csid.num_csid) { set_gtpc_fqcsid_t(&mbr.mme_fqcsid, IE_INSTANCE_ZERO, &pdn->mme_csid); } } #endif /* USE_CSID */ } encode_mod_bearer_req(&mbr, (uint8_t *)gtpv2c_tx); } int mbr_req_pre_check(mod_bearer_req_t *mbr) { if(mbr->bearer_count == 0) { if((mbr->uli.header.len == 0) && (mbr->serving_network.header.len == 0) && (mbr->selection_mode.header.len == 0) && (mbr->indctn_flgs.header.len == 0) && (mbr->ue_time_zone.header.len == 0) && (mbr->second_rat_count == 0)) { return GTPV2C_CAUSE_CONDITIONAL_IE_MISSING; } else { return FORWARD_MBR_REQUEST; } } return 0; } int modify_acc_bearer_req_pre_check(mod_acc_bearers_req_t *mab) { if(mab->bearer_modify_count == 0) { if((mab->indctn_flgs.header.len == 0) && (mab->second_rat_count == 0)) { return GTPV2C_CAUSE_CONDITIONAL_IE_MISSING; } } return 0; }
nikhilc149/e-utran-features-bug-fixes
ulpc/common/UeEntry.h
/* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __UE_ENTRY_H_ #define __UE_ENTRY_H_ #include <iostream> /** * @brief : Maintains data related to UE entry */ typedef struct ue_data { uint64_t uiSeqIdentifier; uint64_t uiImsi; int64_t iTimeToStart; int64_t iTimeToStop; uint16_t uiS11; uint16_t uiSgws5s8c; uint16_t uiPgws5s8c; uint16_t uiForward; uint16_t s1uContent; uint16_t sgwS5S8Content; uint16_t pgwS5S8Content; uint16_t sgiContent; uint16_t ackReceived; std::string strStartTime; std::string strStopTime; std::map<uint16_t, uint16_t> mapSxConfig; std::map<uint16_t, uint16_t> mapIntfcConfig; } ue_data_t; typedef struct delete_event { uint64_t uiSeqIdentifier; uint64_t uiImsi; } delete_event_t; typedef struct UENotification { uint64_t uiSeqIdentifier; uint64_t uiImsi; uint16_t notifyType; std::string strStartTime; std::string strStopTime; } ue_notify_t; typedef struct ack { uint64_t uiSeqIdentifier; uint64_t uiImsi; uint16_t uiRequestType; } ack_t; #endif
nikhilc149/e-utran-features-bug-fixes
cp/state_machine/sm_hand.h
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include "sm_enum.h" #include "cp_app.h" /* Function */ /** * @brief : Handles association setuo request * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int association_setup_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of pfcp association response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_assoc_resp_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of create session response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_cs_resp_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of pfcp session establishment response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_sess_est_resp_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer request * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_mb_req_handler(void *arg1, void *arg2); /** * @brief : Handles processing of modify bearer request for modification procedure * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_mb_req_for_mod_proc_handler(void *arg1, void *arg2); /** * @brief : Handles processing of pfcp session modification response for * modification sent in li scenario * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_sess_mod_resp_li_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of release access bearer request * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_rel_access_ber_req_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of pfcp session modification response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_sess_mod_resp_handler(void *arg1, void *arg2); /** * @brief : Handles processing of pfcp session modification response for modification procedure * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_mod_resp_for_mod_proc_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of delete session request * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_ds_req_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of change notification request * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_change_noti_req_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of pfcp session delete response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_sess_del_resp_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of delete session response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_ds_resp_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of ddn acknowledge response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_ddn_ack_resp_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of report request * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_rpt_req_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Default handler * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_default_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing in case of error * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_error_occured_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing in case of create bearer error * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_cbr_error_occured_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing in case of ue req resource mod flow error * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_bearer_resource_cmd_error_handler(void *t1, void *t2); /* Function */ /** * @brief : Handles processing of cca message * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_dbr_error_occured_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of cca message * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int cca_msg_handler(void *arg1 , void *arg2); /* Function */ /** * @brief : Handles create session request if gx is enabled * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int gx_setup_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of pfcp session modification response in case bearer resource command * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pfcp_sess_mod_resp_brc_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles provision ack CCA-U message * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int provision_ack_ccau_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of create bearer response for pgwc * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pfcp_sess_mod_resp_cbr_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of create bearer response for sgwc * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_create_bearer_response_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of create bearer request * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_create_bearer_request_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of rar request * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_rar_request_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of pfd management request * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int pfd_management_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modification response received in case of delete request * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_mod_resp_delete_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of session modification response received in case of sgw relocation * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_sess_mod_resp_sgw_reloc_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of session establishment response received in case of sgw relocation * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_sess_est_resp_sgw_reloc_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer request received in case of sgw relocation * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_mb_req_sgw_reloc_handler(void *arg1, void *arg2); /** * @brief : Handles processing of modify bearer response in handover scenario * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_mbr_resp_handover_handler(void *arg1, void *arg2); /** * @brief : Handles processing of modify bearer response for modification procedure * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_mbr_resp_for_mod_proc_handler(void *arg1, void *arg2); /** * @brief : Handles processing of pfcp session delete response in handover scenario * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_sess_del_resp_handover_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of cca-t message * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int cca_t_msg_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : data, data contained in message * @param : unused_param, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pfcp_sess_mod_resp_dbr_handler(void *data, void *unused_param); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : data, data contained in message * @param : unused_param, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_delete_bearer_request_handler(void *data, void *unused_param); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : data, data contained in message * @param : unused_param, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_delete_bearer_resp_handler(void *data, void *unused_param); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : data, data contained in message * @param : unused_param, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pfcp_sess_del_resp_dbr_handler(void *data, void *unused_param); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_update_bearer_response_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_update_bearer_request_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_delete_bearer_command_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of bearer resource command * @param : arg1, data contained in message (BRC) * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_bearer_resource_command_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of delete bearer cmd cca msg * @param : arg1, data contained in message (BRC) * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int del_bearer_cmd_ccau_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : data, data contained in message * @param : unused_param, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int provision_ack_ccau_handler(void *data, void *unused_param); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pfcp_sess_mod_resp_ubr_handler(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_del_pdn_conn_set_req(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_s5s8_del_pdn_conn_set_req(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_del_pdn_conn_set_rsp(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_upd_pdn_conn_set_req(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_upd_pdn_conn_set_rsp(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pgw_rstrt_notif_ack(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pfcp_sess_set_del_req(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pfcp_sess_set_del_rsp(void *arg1, void *arg2); /* Function */ /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : argu2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int cca_u_msg_handler(void *arg1, void *argu2); /** * @brief : Handles processing of modify bearer response * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_mb_resp_handler(void *arg1, void *arg2); /** * @brief : Handles processing of session establishment if there's * creation of deciated bearer with deafult scenario * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_sess_est_resp_dedicated_handler(void *arg1, void *arg2); /** * @brief : Handles processing of create session response if there's * creation of deciated bearer with deafult scenario * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_cs_resp_dedicated_handler(void *arg1, void *arg2); /** * @brief : Handles processing of session modification response while there's * creation of deciated bearer with deafult scenario * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pfcp_sess_mod_resp_cs_dedicated_handler(void *arg1, void *arg2); /** * @brief : Handles processing of mbr request and create bearer response * while there's deciated bearer with deafult scenario * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_mb_request_cb_resp_handler(void *arg1, void *arg2); /** * @brief : Handles the processing of change notification * response message received * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_change_noti_resp_handler(void *arg1, void *argu2); /** * @brief : Handles the processing of Pfcp Association setup response, * in Recovery mode. * @param : arg1, data contained in message * @param : arg2, Peer node address * @return : Returns 0 in case of success , -1 otherwise */ int process_recov_asso_resp_handler(void *data, void *addr); /** * @brief : Handles the processing of pfcp estblishment * response message received, in Recovery mode. * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_recov_est_resp_handler(void *data, void *unused_param); /** * @brief : Handles the processing of UPDATE PDN SET CONNECTION * RESPONSE Message. * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_upd_pdn_set_response_handler(void *data, void *unused_param); /** * @brief : Handles the processing of PFCP SESS MOD RESPONSE * Message, on Receiving the UPDATE PDN SET CONN REQ. * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pfcp_sess_mod_resp_upd_handler(void *data, void *unused_param); /** * @brief : Handles the processing of UPDATE PDN SET * REQUEST message received * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_update_pdn_set_req_handler(void *data, void *unused_param); /** * @brief : Handles the processing of modify bearer command * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_modify_bearer_command_handler(void *data, void *unused_param); /** * @brief : Handles the processing of pfcp session deletion response * in case of context replacement message received * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pfcp_sess_del_resp_context_replacement_handler(void *data, void *unused_param); /** * @brief : Handles the processing of pfcp session deletion response * in case of context replacement message received * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_create_indir_data_frwd_req_handler(void *data, void *unused_param); /** * @brief : Handles the processing of delete indirect tunnel request. * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_del_indirect_tunnel_req_handler(void *data, void *unused_param); /** * @brief : Handles the processing of PFCP Delete Response * for delete indirect tunnel request. * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_pfcp_del_resp_del_indirect_handler(void *data, void *unused_param); /** * @brief : Handles the processing of Modify ACCESS Bearer * REQUEST message received * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise * */ int process_modify_access_bearer_handler(void *data, void *unused_param); /* @brief : Handles the ddn failure indication * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_ddn_failure_handler(void *data, void *unused_param); /** * @brief : Handles the session modification response after dl_buffer_duration expires * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_sess_mod_resp_dl_buf_dur_handler(void *data, void *unused_param); /** * @brief : Handles the session modification response after ddn request failure * @param : arg1, data contained in message * @param : arg2, optional parameter * @return : Returns 0 in case of success , -1 otherwise */ int process_sess_mod_resp_ddn_fail_handler(void *data, void *unused_param);
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c_set_ie.h
<gh_stars>0 /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef GTPV2C_SET_IE_H #define GTPV2C_SET_IE_H /** * @file * * Helper functions to add Information Elements and their specific data to * a message buffer containing a GTP header. */ #include "ue.h" #include "gtpv2c.h" #include "gtp_ies.h" #include "gtp_messages_decoder.h" // Added new #include "gtp_messages_encoder.h" // Added new #define MAX_GTPV2C_LENGTH (MAX_GTPV2C_UDP_LEN-sizeof(struct gtpc_t)) #ifdef USE_REST uint8_t rstCnt; #endif /* USE_REST */ /** * @brief : Copies existing information element to gtp message * within transmission buffer with the GTP header '*header' * @param : header * header pre-populated that contains transmission buffer for message * @param : src_ie * Existing Information element to copy into message * @return : * size of information element copied into message */ uint16_t set_ie_copy(gtpv2c_header_t *header, gtpv2c_ie *src_ie); /** * @brief : Set values in ie header * @param : header * header pre-populated that contains transmission buffer for message * @param : type, ie type value * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : length, total ie length * @return : Returns nothing */ void set_ie_header(ie_header_t *header, uint8_t type, enum ie_instance instance, uint16_t length); /** * @brief : Populates cause information element with error cause value * @param : cause ie * cause ie * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : cause value * cause value that we want to set on cause IE * @param : cause source * @return : Returns nothing */ void set_cause_error_value(gtp_cause_ie_t *cause, enum ie_instance instance, uint8_t cause_value, uint8_t cause_source); /** * @brief : Populates cause information element with accepted value * @param : cause ie * cause ie * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @return : Returns nothing */ void set_cause_accepted(gtp_cause_ie_t *cause, enum ie_instance instance); /** * @brief : Creates and populates cause information element with accepted value * within transmission buffer with the GTP header '*header' * @param : header * header pre-populated that contains transmission buffer for message * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @return : * size of information element created in message */ void set_csresp_cause(gtp_cause_ie_t *cause, uint8_t cause_value, enum ie_instance instance); /** * @brief : Creates and populates allocation/retention priority information element * with the GTP header '*header' * @param : header * header pre-populated that contains transmission buffer for message * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : bearer * eps bearer data structure that contains priority data * @return : * size of information element created in message */ uint16_t set_ar_priority_ie(gtpv2c_header_t *header, enum ie_instance instance, eps_bearer *bearer); /** * @brief : Populates F-TEID information element with ip value * @param : fteid * fully qualified teid * @param : interface * value indicating interface as defined by 3gpp 29.274 clause 8.22 * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : node_value * ip address of interface * @param : teid * Tunnel End-point IDentifier of interface * @return : Returns IE length */ int set_gtpc_fteid(gtp_fully_qual_tunn_endpt_idnt_ie_t *fteid, enum gtpv2c_interfaces interface, enum ie_instance instance, node_address_t node_value, uint32_t teid); /** * @brief : Creates and populates F-TEID information element with ipv4 value * within transmission buffer with the GTP header '*header' * @param : header * header pre-populated that contains transmission buffer for message * @param : interface * value indicating interface as defined by 3gpp 29.274 clause 8.22 * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : ipv4 * ipv4 address of interface * @param : teid * Tunnel End-point IDentifier of interface * @return : * size of information element created in message */ uint16_t set_ipv4_fteid_ie(gtpv2c_header_t *header, enum gtpv2c_interfaces interface, enum ie_instance instance, struct in_addr ipv4, uint32_t teid); /** * @brief : Populates 'PDN Address Allocation' information element with ipv4 * address of User Equipment * @param : paa * paa ie * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : ipv4 * ipv4 address of user equipment * @return : Returns nothing */ void set_paa(gtp_pdn_addr_alloc_ie_t *paa, enum ie_instance instance, pdn_connection *pdn); /** * @brief : Creates & populates 'PDN Address Allocation' information element with ipv4 * address of User Equipment * @param : header * header pre-populated that contains transmission buffer for message * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : ipv4 * ipv4 address of user equipment * @return : * size of information element created in message */ uint16_t set_ipv4_paa_ie(gtpv2c_header_t *header, enum ie_instance instance, struct in_addr ipv4); /** * @brief : Returns ipv4 UE address from 'PDN Address Allocation' information element * address of User Equipment * @param : ie * gtpv2c_ie information element * @return : * ipv4 address of user equipment */ struct in_addr get_ipv4_paa_ipv4(gtpv2c_ie *ie); /** * @brief : Creates & populates 'Access Point Name' restriction information element * according to 3gpp 29.274 clause 8.57 * @param : header * header pre-populated that contains transmission buffer for message * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : apn_restriction * value indicating the restriction according to 3gpp 29.274 table 8.57-1 * @return : * size of information element created in message */ uint16_t set_apn_restriction_ie(gtpv2c_header_t *header, enum ie_instance instance, uint8_t apn_restriction); /** * @brief : Populates 'Access Point Name' restriction information element * according to 3gpp 29.274 clause 8.57 * @param : apn_restriction * apn restriction ie * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : apn_restriction * value indicating the restriction according to 3gpp 29.274 table 8.57-1 * @return : Returns nothing */ void set_change_reporting_action(gtp_chg_rptng_act_ie_t *chg_rptng_act, enum ie_instance instance, uint8_t action); /** * @brief : Populates 'Access Point Name' restriction information element * according to 3gpp 29.274 clause 8.57 * @param : apn_restriction * apn restriction ie * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : apn_restriction * value indicating the restriction according to 3gpp 29.274 table 8.57-1 * @return : Returns nothing */ void set_apn_restriction(gtp_apn_restriction_ie_t *apn_restriction, enum ie_instance instance, uint8_t restriction_type); /** * @brief : Populates 'Eps Bearer Identifier' information element * @param : ebi * eps bearer id ie * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : ebi * value indicating the EBI according to 3gpp 29.274 clause 8.8 * @return : Returns nothing */ void set_ebi(gtp_eps_bearer_id_ie_t *ebi, enum ie_instance instance, uint8_t eps_bearer_id); /** * @brief : Populates 'allocation/retension priority' information element * @param : arp * gtp_alloc_reten_priority_ie_t ie * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : bearer * eps_bearer structure pointer * @return : Returns nothing */ void set_ar_priority(gtp_alloc_reten_priority_ie_t *arp, enum ie_instance instance, eps_bearer *bearer); /** * @brief : Populates 'Proc Trans Identifier' information element * @param : pti * Proc Trans Identifier * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : pti * value indicating the pti according to 3gpp 29.274 clause 8.8 * @return : Returns nothing */ void set_pti(gtp_proc_trans_id_ie_t *pti, enum ie_instance instance, uint8_t proc_trans_id); /** * @brief : Creates & populates 'Eps Bearer Identifier' information element * @param : header * header pre-populated that contains transmission buffer for message * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : ebi * value indicating the EBI according to 3gpp 29.274 clause 8.8 * @return : * size of information element created in message */ uint16_t set_ebi_ie(gtpv2c_header_t *header, enum ie_instance instance, uint8_t ebi); /** * @brief : Creates & populates 'Procedure Transaction ' information element * @param : header * header pre-populated that contains transmission buffer for message * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : pti * Procedure transaction value from 3gpp 29.274 clause 8.35 * @return : * size of information element created in message */ uint16_t set_pti_ie(gtpv2c_header_t *header, enum ie_instance instance, uint8_t pti); /** * @brief : Creates & populates 'Charging ID' information element * @param : header * header pre-populated that contains transmission buffer for message * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : charging_id * general value within an information element * @return : * size of information element created in message */ uint16_t set_charging_id_ie(gtpv2c_header_t *header, enum ie_instance instance, uint32_t charging_id); /** * @brief : Set values in 'Charging ID' information element * @param : charging_id * structure to be filled * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : charging_id * Charging id value * @return : Returns nothing */ void set_charging_id(gtp_charging_id_ie_t *charging_id, enum ie_instance instance, uint32_t chrgng_id_val); /** * @brief : Creates & populates 'Bearer Quality of Service' information element * @param : header * header pre-populated that contains transmission buffer for message * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : bearer * eps bearer data structure that contains qos data * @return : * size of information element created in message */ uint16_t set_bearer_qos_ie(gtpv2c_header_t *header, enum ie_instance instance, eps_bearer *bearer); /** * @brief : Set values in 'Bearer Quality of Service' information element * @param : bqos * Structure to be filled * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : bearer * eps bearer data structure that contains qos data * @return : Returns nothing */ void set_bearer_qos(gtp_bearer_qlty_of_svc_ie_t *bqos, enum ie_instance instance, eps_bearer *bearer); /** * @brief : Creates & populates 'Traffic Flow Template' information element * @param : header * header pre-populated that contains transmission buffer for message * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : bearer * eps bearer data structure that contains tft data * @return : * size of information element created in message */ uint16_t set_bearer_tft_ie(gtpv2c_header_t *header, enum ie_instance instance, eps_bearer *bearer); /** * @brief : Set values in 'Traffic Flow Template' information element * @param : tft, * Structure to be filled * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @param : tft_op_code * tft_op_code value * @param : bearer * eps bearer data structure that contains tft data * @param : rule_name * rule name for whict TFT has to upd/add/remove * @return : * size of information element */ uint8_t set_bearer_tft(gtp_eps_bearer_lvl_traffic_flow_tmpl_ie_t *tft, enum ie_instance instance, uint8_t tft_op_code, eps_bearer *bearer, char *rule_name); /** * @brief : Creates & populates 'recovery/restart counter' information element * @param : header * header pre-populated that contains transmission buffer for message * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @return : * size of information element created in message */ uint16_t set_recovery_ie(gtpv2c_header_t *header, enum ie_instance instance); /* Group Information Element Setter & Builder Functions */ /** * @brief : Modifies group_ie information element's length field, adding the length * from grouped_ie_length * @param : group_ie * group information element (such as bearer context) * @param : grouped_ie_length * grouped information element contained within 'group_ie' information element * @return : Returns nothing */ void add_grouped_ie_length(gtpv2c_ie *group_ie, uint16_t grouped_ie_length); /** * @brief : from parameters, populates gtpv2c message 'modify bearer response' and * populates required information elements as defined by * clause 7.2.8 3gpp 29.274 * @param : gtpv2c_tx * transmission buffer to contain 'modify bearer request' message * @param : sequence * sequence number as described by clause 7.6 3gpp 29.274 * @param : context * UE Context data structure pertaining to the bearer to be modified * @param : bearer * bearer data structure to be modified * @return : Returns message length */ int set_modify_bearer_response(gtpv2c_header_t *gtpv2c_tx, uint32_t sequence, ue_context *context, eps_bearer *bearer, mod_bearer_req_t *mbr); /* @brief : Function added to return Response in case of Handover * It performs the same as the function set_modify_bearer_response * @param : gtpv2c_tx * transmission buffer to contain 'modify bearer request' message * @param : sequence * sequence number as described by clause 7.6 3gpp 29.274 * @param : context * UE Context data structure pertaining to the bearer to be modified * @param : bearer * bearer data structure to be modified * @return : Returns nothing */ void set_modify_bearer_response_handover(gtpv2c_header_t *gtpv2c_tx, uint32_t sequence, ue_context *context, eps_bearer *bearer, mod_bearer_req_t *mbr); /** * @brief : Helper function to set the gtp header for a gtpv2c message. * @param : gtpv2c_tx * buffer used to contain gtp message for transmission * @param : type * gtp type according to 2gpp 29.274 table 6.1-1 * @param : has_teid * boolean to indicate if the message requires the TEID field within the * gtp header * @param : seq * sequence number as described by clause 7.6 3gpp 29.274 * @param : is_piggybacked * piggybacked as described by clause 5.5.1 3gpp 29.274 * @return : Returns nothing */ void set_gtpv2c_header(gtpv2c_header_t *gtpv2c_tx, uint8_t teidFlg, uint8_t type, uint32_t has_teid, uint32_t seq, uint8_t is_piggybacked); /** * @brief : Helper function to set the gtp header for a gtpv2c message with the * TEID field. * @param : gtpv2c_tx * buffer used to contain gtp message for transmission * @param : type * gtp type according to 2gpp 29.274 table 6.1-1 * @param : teid * GTP teid, or TEID-C, to be populated in the GTP header * @param : seq * sequence number as described by clause 7.6 3gpp 29.274 * @param : is_piggybacked * is_piggybacked as described by clause 5.5.1 3gpp 29.274 * @return : Returns nothing */ void set_gtpv2c_teid_header(gtpv2c_header_t *gtpv2c_tx, uint8_t type, uint32_t teid, uint32_t seq, uint8_t is_piggybacked); /** * @brief : Creates & populates bearer context group information element within * transmission buffer at *header * @param : header * header pre-populated that contains transmission buffer for message * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @return : * bearer context created in 'header' */ gtpv2c_ie * create_bearer_context_ie(gtpv2c_header_t *header, enum ie_instance instance); /** * @brief : Set values in fqdn ie * @param : header * header pre-populated that contains transmission buffer for message * @param : fqdn * fqdn value * @return : Returns nothing */ void set_fqdn_ie(gtpv2c_header_t *header, char *fqdn); /** * @brief : Set values in indication ie * @param : indic * Structure to be filled * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @return : Returns nothing */ void set_indication(gtp_indication_ie_t *indic, enum ie_instance instance); /** * @brief : Set values in user location information ie * @param : uli * Structure to be filled * @param : csr * buffer which holds information from create session request * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @return : Returns nothing */ void set_uli(gtp_user_loc_info_ie_t *uli, create_sess_req_t *csr, enum ie_instance instance); /** * @brief : Set values in serving network ie * @param : serving_nw * Structure to be filled * @param : csr * buffer which holds information from create session request * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @return : Returns nothing */ void set_serving_network(gtp_serving_network_ie_t *serving_nw, create_sess_req_t *csr, enum ie_instance instance); /** * @brief : Set values in ue timezone ie * @param : ue_timezone * Structure to be filled * @param : csr * buffer which holds information from create session request * @param : instance * Information element instance as specified by 3gpp 29.274 clause 6.1.3 * @return : Returns nothing */ void set_ue_timezone(gtp_ue_time_zone_ie_t *ue_timezone, create_sess_req_t *csr, enum ie_instance instance); /** * @brief : from parameters, populates gtpv2c message 'release access bearer * response' and populates required information elements as defined by * clause 7.2.22 3gpp 29.274 * @param : gtpv2c_tx * transmission buffer to contain 'release access bearer request' message * @param : sequence * sequence number as described by clause 7.6 3gpp 29.274 * @param : context * UE Context data structure pertaining to the bearer to be modified * @return : Returns nothing */ /* TODO: Remove #if 0 before rollup */ /** * @brief : Set values in mapped ue usage type ie * @param : ie * Structure to be filled * @return : Returns nothing */ void set_mapped_ue_usage_type(gtp_mapped_ue_usage_type_ie_t *ie, uint16_t usage_type_value); #ifdef CP_BUILD /** * @brief : Decodes incoming create session request and store it in structure * @param : gtpv2c_rx * transmission buffer to contain 'create session request' message * @param : csr * buffer to store decoded information from create session request * @param : cp_type, cp config type [SGWC/PGWC/SAEGWC] * @return : Returns nothing */ int decode_check_csr(gtpv2c_header_t *gtpv2c_rx, create_sess_req_t *csr, uint8_t *cp_type); /** * @brief : Precondition check for MBR * @param : mbr: MBR req. on SGWC/SAEGWC * @return : 0 on success, else error type * */ int mbr_req_pre_check(mod_bearer_req_t *mbr); /** * @brief : from parameters, populates gtpv2c message 'modify access bearer response' and * populates required information elements as defined by * clause 7.2.8 3gpp 29.274 * @param : gtpv2c_tx * transmission buffer to contain 'modify access bearer request' message * @param : sequence * sequence number as described by clause 7.6 3gpp 29.274 * @param : context * UE Context data structure pertaining to the bearer to be modified * @param : bearer * bearer data structure to be modified * @param : mabr * modify access bearer request received. * @return : Returns nothing */ void set_modify_access_bearer_response(gtpv2c_header_t *gtpv2c_tx, uint32_t sequence, ue_context *context, eps_bearer *bearer, mod_acc_bearers_req_t *mabr); /** * @brief : Precondition check for MABR * @param : mabr: Modify access req. on SGWC/SAEGWC * @return : 0 on success, else error type * */ int modify_acc_bearer_req_pre_check(mod_acc_bearers_req_t *mabr); /** * @brief : It fills the presence reporting area action ie to GTPv2 messages from UE contest * @param : ie : presence reporting area action ie to be fill * @param : context : UE Context * @return : Returns nothing */ void set_presence_reporting_area_action_ie(gtp_pres_rptng_area_act_ie_t *ie, ue_context *context); /** * @brief : It fills the presence reporting area Info ie to GTPv2 messages from UE contest * @param : ie : presence reporting area Info ie to be fill * @param : context : UE Context * @return : Returns nothing */ void set_presence_reporting_area_info_ie(gtp_pres_rptng_area_info_ie_t *ie, ue_context *context); #endif /*CP_BUILD*/ #endif /* GTPV2C_SET_IE_H */
nikhilc149/e-utran-features-bug-fixes
cp_dp_api/teid.c
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2017 Intel Corporation * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include "teid.h" #include "gw_adapter.h" #include "gtpv2c_ie.h" #include "pfcp_util.h" #include "debug_str.h" #define DEFAULT_SGW_BASE_TEID 0xC0FFEE #define DEFAULT_SGW_S5S8_BASE_TEID 0xE0FFEE #define DEFAULT_PGW_BASE_TEID 0xD0FFEE /*Number of bits needed to be shifted in teid range so that tied range value * will be at proper place in TEID * e.g 0x00000010 ==> 0x10000000 */ #define SHIFT_BITS 24 /* number of bits in teid range */ #define MAX_RI_BITS 8 /* base value for seid generation */ const uint32_t s11_sgw_gtpc_base_teid = DEFAULT_SGW_BASE_TEID; const uint32_t s5s8_sgw_gtpc_base_teid = DEFAULT_SGW_S5S8_BASE_TEID; const uint32_t s5s8_pgw_gtpc_base_teid = DEFAULT_PGW_BASE_TEID; /* offset for seid generation */ static uint32_t s11_sgw_gtpc_teid_offset; static uint32_t s5s8_sgw_gtpc_teid_offset; static uint32_t s5s8_pgw_gtpc_teid_offset; /* constant to clear first byte of teid */ static uint32_t CLEAR_BYTE = 0xffffffff; extern int clSystemLog; teid_info * get_teid_info(teid_info **head, node_address_t upf_ip){ teid_info *temp = NULL; if(*head != NULL){ temp = *head; while(temp != NULL) { if(upf_ip.ip_type == PDN_TYPE_IPV4 && (temp->dp_ip.ipv4_addr == upf_ip.ipv4_addr)) { return temp; } else if (upf_ip.ip_type == PDN_TYPE_IPV6 && (memcmp(temp->dp_ip.ipv6_addr, upf_ip.ipv6_addr, IPV6_ADDRESS_LEN) == 0)) { return temp; } temp = temp->next; } } return NULL; } /** * @brief : Initializes teid_info structure * @param : upf_info, pointer to structure * @return : Returns nothing */ static void init_teid_info(teid_info *upf_info){ #define DEFAULT_TEID_RANGE 0x00 upf_info->teid_range = DEFAULT_TEID_RANGE; #define DEFAULT_INITIAL_TEID 0x00000001 upf_info->up_gtpu_teid = DEFAULT_INITIAL_TEID; upf_info->up_gtpu_base_teid = DEFAULT_INITIAL_TEID; upf_info->dp_ip.ipv4_addr = 0; memset(upf_info->dp_ip.ipv6_addr, 0, IPV6_ADDRESS_LEN); upf_info->up_gtpu_teid_offset = 0; #define MAX_TEID_OFFSET 0xFFFFFFFF upf_info->up_gtpu_max_teid_offset = MAX_TEID_OFFSET; upf_info->next = NULL; } int8_t add_teid_info(teid_info **head, teid_info *newNode){ if (*head == NULL) { *head = newNode; }else{ teid_info *temp = *head; while(temp->next != NULL){ temp = temp->next; } temp->next = newNode; } return 0; } void delete_entry_from_teid_list(node_address_t upf_ip, teid_info **head){ teid_info *temp = NULL; teid_info *prev = NULL; if(*head == NULL){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to remove upf information, List is empty\n, " "IP Type : %s | IPV4_ADDR : %u | IPV6_ADDR : "IPv6_FMT"", LOG_VALUE, ip_type_str(upf_ip.ip_type), upf_ip.ipv4_addr, PRINT_IPV6_ADDR(upf_ip.ipv6_addr)); return; } temp = *head; /* If node to be deleted is first node */ if(upf_ip.ip_type == PDN_TYPE_IPV4 && (temp->dp_ip.ipv4_addr == upf_ip.ipv4_addr)) { *head = temp->next; free(temp); return; } else if (upf_ip.ip_type == PDN_TYPE_IPV6 && (memcmp(temp->dp_ip.ipv6_addr, upf_ip.ipv6_addr, IPV6_ADDRESS_LEN) == 0)) { *head = temp->next; free(temp); return; } /* If node to be deleted is not first node */ prev = *head; while(temp != NULL){ if(upf_ip.ip_type == PDN_TYPE_IPV4 && (temp->dp_ip.ipv4_addr == upf_ip.ipv4_addr)) { prev->next = temp->next; free(temp); return; } else if (upf_ip.ip_type == PDN_TYPE_IPV6 && (memcmp(temp->dp_ip.ipv6_addr, upf_ip.ipv6_addr, IPV6_ADDRESS_LEN) == 0)) { prev->next = temp->next; free(temp); return; } prev = temp; temp = temp->next; } } int8_t set_base_teid(uint8_t ri_val, uint8_t val, node_address_t upf_ip, teid_info **upf_teid_info_head) { teid_info *upf_info = NULL; uint8_t ret = 0; upf_info = get_teid_info(upf_teid_info_head, upf_ip); if(upf_info == NULL) { upf_info = malloc(sizeof(teid_info)); if(upf_info == NULL){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to add node for DP\n, IP Type : %s | IPV4_ADDR : %u | IPV6_ADDR : "IPv6_FMT, LOG_VALUE, ip_type_str(upf_ip.ip_type), upf_ip.ipv4_addr, PRINT_IPV6_ADDR(upf_ip.ipv6_addr)); return -1; } init_teid_info(upf_info); if (upf_ip.ip_type == PDN_TYPE_IPV4) { upf_info->dp_ip.ipv4_addr = upf_ip.ipv4_addr; upf_info->dp_ip.ip_type = PDN_TYPE_IPV4; } else if (upf_ip.ip_type == PDN_TYPE_IPV6) { memcpy(upf_info->dp_ip.ipv6_addr, upf_ip.ipv6_addr, IPV6_ADDRESS_LEN); upf_info->dp_ip.ip_type = PDN_TYPE_IPV6; } ret = add_teid_info(upf_teid_info_head, upf_info); if(ret != 0){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to add node for DP\n, IP Type : %s | IPV4_ADDR : %u | IPV6_ADDR : "IPv6_FMT, LOG_VALUE, ip_type_str(upf_ip.ip_type), upf_ip.ipv4_addr, PRINT_IPV6_ADDR(upf_ip.ipv6_addr)); return -1; } } if (ri_val != 0) { /* set cp teid_range value */ /* teid range will be (ri_val) MSBs of teid value, so need to shift teid range received from dp to MSB * e.g: if teid_range received from DP = 0000 0001 , and teidri = 3, then teid range = 0010 0000 * if teid_range received from DP = 0000 0101 , and teidri = 3, then teid range = 1010 0000 * if teid_range received from DP = 0000 0011 , and teidri = 2, then teid range = 1100 0000 */ upf_info->teid_range = (val << (MAX_RI_BITS - ri_val)); /* e.g: if teidri = 3, then CLEAR_BYTE = 0001 1111 1111 1111 1111 1111 1111 1111 * if teidri = 8, then CLEAR_BYTE = 0000 0000 1111 1111 1111 1111 1111 1111 */ CLEAR_BYTE = (CLEAR_BYTE >> (ri_val)); /* e.g: if teidri = 3, then max teid offset = 0001 1111 1111 1111 1111 1111 1111 1111 * if teidri = 8, then max teid offset = 0000 0000 1111 1111 1111 1111 1111 1111 */ upf_info->up_gtpu_max_teid_offset = CLEAR_BYTE; /* Set the TEID Base value based on the received TEID_Range*/ upf_info->up_gtpu_base_teid = (upf_info->teid_range << SHIFT_BITS); /* teid will start from index 1 if teid range value is 0 and 0 otherwise * e.g: if teid_range received from DP = 0000 0000 , and teidri = 3, then * base teid = 0000 0000 0000 0000 0000 0000 0000 0001 * if teid_range received from DP = 0000 0101 , and teidri = 3, then * base teid = 1010 0000 0000 0000 0000 0000 0000 0000 * if teid_range received from DP = 0000 0011 , and teidri = 2, then * base teid = 1100 0000 0000 0000 0000 0000 0000 0000 */ if (upf_info->teid_range == 0) { upf_info->up_gtpu_base_teid++; } } return 0; } /* TODO: Make it generic common api across the all CP modes */ uint32_t get_s1u_sgw_gtpu_teid(node_address_t upf_ip, int cp_type, teid_info **head){ uint32_t s1u_sgw_gtpu_teid = 0; teid_info *upf_info = NULL; upf_info = get_teid_info(head, upf_ip); if(upf_info == NULL){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to find upf information\n, IP Type : %s | IPV4_ADDR : %u | IPV6_ADDR : "IPv6_FMT, LOG_VALUE, ip_type_str(upf_ip.ip_type), upf_ip.ipv4_addr, PRINT_IPV6_ADDR(upf_ip.ipv6_addr)); return 0; } if ((cp_type == CP_TYPE_SGWC) || (cp_type == CP_TYPE_SAEGWC)) { upf_info->up_gtpu_teid = upf_info->up_gtpu_base_teid + upf_info->up_gtpu_teid_offset; if (upf_info->up_gtpu_teid_offset >= upf_info->up_gtpu_max_teid_offset) { upf_info->up_gtpu_teid_offset = 0; } else { ++upf_info->up_gtpu_teid_offset; } } s1u_sgw_gtpu_teid = (upf_info->up_gtpu_teid & CLEAR_BYTE) | ((upf_info->teid_range) << SHIFT_BITS); return s1u_sgw_gtpu_teid; } uint32_t get_s5s8_sgw_gtpu_teid(node_address_t upf_ip, int cp_type, teid_info **head){ /* Note: s5s8_sgw_gtpu_teid based s11_sgw_gtpc_teid * Computation same as s1u_sgw_gtpu_teid */ uint32_t s5s8_sgw_gtpu_teid = 0; teid_info *upf_info = NULL; upf_info = get_teid_info(head, upf_ip); if(upf_info == NULL){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to find upf information\n, IP Type : %s | IPV4_ADDR : %u | IPV6_ADDR : "IPv6_FMT, LOG_VALUE, ip_type_str(upf_ip.ip_type), upf_ip.ipv4_addr, PRINT_IPV6_ADDR(upf_ip.ipv6_addr)); return 0; } if ((cp_type == CP_TYPE_SGWC) || (cp_type == CP_TYPE_SAEGWC)) { upf_info->up_gtpu_teid = upf_info->up_gtpu_base_teid + upf_info->up_gtpu_teid_offset; if (upf_info->up_gtpu_teid_offset >= upf_info->up_gtpu_max_teid_offset) { upf_info->up_gtpu_teid_offset = 0; } else { ++upf_info->up_gtpu_teid_offset; } } s5s8_sgw_gtpu_teid = (upf_info->up_gtpu_teid & CLEAR_BYTE) | ((upf_info->teid_range) << SHIFT_BITS); return s5s8_sgw_gtpu_teid; } uint32_t get_s5s8_pgw_gtpu_teid(node_address_t upf_ip, int cp_type, teid_info **head){ uint32_t s5s8_pgw_gtpu_teid = 0; teid_info *upf_info = NULL; upf_info = get_teid_info(head, upf_ip); if(upf_info == NULL){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to find upf information\n, IP Type : %s | IPV4_ADDR : %u | IPV6_ADDR : "IPv6_FMT, LOG_VALUE, ip_type_str(upf_ip.ip_type), upf_ip.ipv4_addr, PRINT_IPV6_ADDR(upf_ip.ipv6_addr)); return 0; } if (cp_type == CP_TYPE_PGWC){ upf_info->up_gtpu_teid = upf_info->up_gtpu_base_teid + upf_info->up_gtpu_teid_offset; if (upf_info->up_gtpu_teid_offset >= upf_info->up_gtpu_max_teid_offset) { upf_info->up_gtpu_teid_offset = 0; } else { ++upf_info->up_gtpu_teid_offset; } } s5s8_pgw_gtpu_teid = (upf_info->up_gtpu_teid & CLEAR_BYTE) | ((upf_info->teid_range) << SHIFT_BITS); return s5s8_pgw_gtpu_teid; } uint32_t get_s5s8_sgw_gtpc_teid(void){ uint32_t s5s8_sgw_gtpc_teid = 0; s5s8_sgw_gtpc_teid = s5s8_sgw_gtpc_base_teid + s5s8_sgw_gtpc_teid_offset; ++s5s8_sgw_gtpc_teid_offset; return s5s8_sgw_gtpc_teid; } uint32_t get_s5s8_pgw_gtpc_teid(void){ uint32_t s5s8_pgw_gtpc_teid = 0; s5s8_pgw_gtpc_teid = s5s8_pgw_gtpc_base_teid + s5s8_pgw_gtpc_teid_offset; ++s5s8_pgw_gtpc_teid_offset; return s5s8_pgw_gtpc_teid; } uint32_t get_s11_sgw_gtpc_teid(uint8_t *check_if_ue_hash_exist, int cp_type, uint32_t old_s11_sgw_gtpc_teid) { uint32_t s11_sgw_gtpc_teid = old_s11_sgw_gtpc_teid; if (*check_if_ue_hash_exist == 0){ if ((cp_type == CP_TYPE_SGWC) || (cp_type == CP_TYPE_SAEGWC)) { s11_sgw_gtpc_teid = s11_sgw_gtpc_base_teid + s11_sgw_gtpc_teid_offset; ++s11_sgw_gtpc_teid_offset; } else if (cp_type == CP_TYPE_PGWC){ s11_sgw_gtpc_teid = get_s5s8_pgw_gtpc_teid(); } } return s11_sgw_gtpc_teid; }
nikhilc149/e-utran-features-bug-fixes
dp/up_pkt_handler.c
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * pkt_handler.c: Main processing for uplink and downlink packets. * Also process any notification coming from interface core for * messages from CP for modifications to an active session. * This is done by the worker core in the pipeline. */ #include <unistd.h> #include <locale.h> #include <rte_icmp.h> #include <rte_ip.h> #include "gtpu.h" #include "util.h" #include "ipv6.h" #include "up_acl.h" #include "up_main.h" #include "up_ether.h" #include "pfcp_up_llist.h" #include "pfcp_up_struct.h" #include "pfcp_set_ie.h" #include "pfcp_up_sess.h" #include "pfcp_set_ie.h" #include "pfcp_messages_encoder.h" #include "pfcp_messages_decoder.h" #include "pfcp_util.h" #include "../cp_dp_api/tcp_client.h" #include "gw_adapter.h" #include "pfcp_struct.h" #ifdef EXTENDED_CDR uint64_t s1u_non_gtp_pkts_mask; #endif #define IPV4_PKT_VER 0x45 #define SEQ_NO_SIZE 2 #define PDU_NO_SIZE 1 #define SEQ_NO_BIT 2 #define PDU_NO_BIT 1 #define EXTENSION_HDR_BIT 4 #define NO_MORE_EXTENSION_HEADERS 0 extern pcap_dumper_t *pcap_dumper_east; extern pcap_dumper_t *pcap_dumper_west; extern udp_sock_t my_sock; extern struct rte_ring *li_dl_ring; extern struct rte_ring *li_ul_ring; extern struct rte_ring *cdr_pfcp_rpt_req; extern int clSystemLog; extern uint8_t dp_comm_ip_type; uint8_t cp_comm_ip_type; extern struct in6_addr dp_comm_ipv6; extern struct in6_addr cp_comm_ip_v6; extern struct in_addr dp_comm_ip; char CDR_FILE_PATH[CDR_BUFF_SIZE]; /* GW should allow/deny sending error indication pkts to peer node: 1:allow, 0:deny */ extern bool error_indication_snd; static void enqueue_pkts_snd_err_ind(struct rte_mbuf **pkts, uint32_t n, uint8_t port, uint64_t *snd_err_pkts_mask) { for (uint32_t inx = 0; inx < n; inx++) { if (ISSET_BIT(*snd_err_pkts_mask, inx)) { send_error_indication_pkt(pkts[inx], port); } } return; } int notification_handler(struct rte_mbuf **pkts, uint32_t n) { uint16_t tx_cnt = 0; unsigned int *ring_entry = NULL; struct rte_ring *ring = NULL; struct rte_mbuf *buf_pkt = NULL; pfcp_session_datat_t *data = NULL; uint64_t pkts_mask = 0, pkts_queue_mask = 0, fwd_pkts_mask = 0, snd_err_pkts_mask; uint32_t *key = NULL; unsigned int ret = 0, num = 32, i; pfcp_session_datat_t *sess_data[MAX_BURST_SZ] = {NULL}; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Notification handler resolving the buffer packets, dl_ring_count:%u\n", LOG_VALUE, n); for (i = 0; i < n; ++i) { buf_pkt = pkts[i]; key = rte_pktmbuf_mtod(buf_pkt, uint32_t *); /* TODO: Temp Solution */ uint8_t find_teid_key = 0; /* Check key is not NULL or Zero */ if (key == NULL) { continue; } /* Add the handling of the session */ data = get_sess_by_teid_entry(*key, NULL, SESS_MODIFY); if (data == NULL) { ue_ip_t ue_ip = {0}; ue_ip.ue_ipv4 = *key; data = get_sess_by_ueip_entry(ue_ip, NULL, SESS_MODIFY); if (data == NULL) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Session entry not found for TEID/UE_IP: %u\n", LOG_VALUE, *key); continue; } } else { /* if SGWU find the key */ find_teid_key = PRESENT; } rte_ctrlmbuf_free(buf_pkt); ring = data->dl_ring; if (data->sess_state != CONNECTED) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Update the State to CONNECTED\n", LOG_VALUE); data->sess_state = CONNECTED; } if (!ring) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"No DL Ring is found\n", LOG_VALUE); continue; /* No dl ring*/ } /* de-queue this ring and send the downlink pkts*/ uint32_t cnt_t = rte_ring_count(ring); while (cnt_t) { ret = rte_ring_sc_dequeue_burst(ring, (void **)pkts, num, ring_entry); if (!ret) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"DDN:Error not able to dequeue pts from ring, pkts_cnt:%u, cnt_t:%u\n", LOG_VALUE, ret, cnt_t); cnt_t = 0; continue; } /* Reset the Session and PDR info */ pdr_info_t *pdr[MAX_BURST_SZ] = {NULL}; pfcp_session_datat_t *sess_info[MAX_BURST_SZ] = {NULL}; pkts_mask = 0; fwd_pkts_mask = 0; pkts_queue_mask = 0; snd_err_pkts_mask = 0; /* Decrement the packet counter */ cnt_t -= ret; pkts_mask = (~0LLU) >> (64 - ret); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"DDN:Dequeue pkts from the ring, pkts_cnt:%u\n", LOG_VALUE, ret); for (i = 0; i < ret; ++i) { /* Set the packet mask */ SET_BIT(fwd_pkts_mask, i); sess_info[i] = data; } for (i = 0; i < ret; ++i) pdr[i] = sess_info[i]->pdrs; if(!find_teid_key) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"SAEGWU: Encap the GTPU Pkts...\n", LOG_VALUE); /* Encap GTPU header*/ gtpu_encap(&pdr[0], &sess_info[0], (struct rte_mbuf **)pkts, ret, &pkts_mask, &fwd_pkts_mask, &pkts_queue_mask); } else { /* Get downlink session info */ dl_sess_info_get((struct rte_mbuf **)pkts, ret, &pkts_mask, &sess_data[0], &pkts_queue_mask, &snd_err_pkts_mask, NULL, NULL); } if (pkts_queue_mask != 0) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Something is wrong, the session still doesnt hv " "enb teid\n", LOG_VALUE); if(find_teid_key) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Update the Next Hop eNB ipv4 frame info\n", LOG_VALUE); /* Update nexthop L3 header*/ update_enb_info(pkts, ret, &pkts_mask, &fwd_pkts_mask, &sess_data[0], &pdr[0]); } /* Update nexthop L2 header*/ update_nexthop_info((struct rte_mbuf **)pkts, num, &pkts_mask, app.wb_port, &pdr[0], NOT_PRESENT); uint32_t pkt_indx = 0; #ifdef STATS clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Resolved the Buffer packets Pkts:%u\n", LOG_VALUE, ret); epc_app.dl_params[SGI_PORT_ID].pkts_in += ret; epc_app.dl_params[SGI_PORT_ID].ddn_buf_pkts -= ret; #endif /* STATS */ /* Capture the GTPU packets.*/ up_core_pcap_dumper(pcap_dumper_east, pkts, ret, &pkts_mask); while (ret) { uint16_t pkt_cnt = PKT_BURST_SZ; if (ret < PKT_BURST_SZ) pkt_cnt = ret; tx_cnt = rte_eth_tx_burst(S1U_PORT_ID, 0, &pkts[pkt_indx], pkt_cnt); ret -= tx_cnt; pkt_indx += tx_cnt; } } if (rte_ring_enqueue(dl_ring_container, ring) == ENOBUFS) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Can't put ring back, so free it\n", LOG_VALUE); rte_ring_free(ring); } } return 0; } int cdr_cause_code(pfcp_usage_rpt_trig_ie_t *usage_rpt_trig, char *buf) { if(usage_rpt_trig->volth == 1) { strncpy(buf, VOLUME_LIMIT, CDR_BUFF_SIZE); return 0; } if(usage_rpt_trig->timth == 1) { strncpy(buf, TIME_LIMIT, CDR_BUFF_SIZE); return 0; } if(usage_rpt_trig->termr == 1) { strncpy(buf, CDR_TERMINATION, CDR_BUFF_SIZE); return 0; } return -1; } int get_seq_no_of_cdr(char *buffer, char *seq_no) { int cnt = 0; int i = 0; if (buffer == NULL) return -1; for(i=0; i<MAX_SEQ_NO_LEN; i++) { if (buffer[i] == ',') { seq_no[i] = buffer[i]; cnt++; } else { seq_no[i] = buffer[i]; } if(cnt == 2) break; } seq_no[i] = '\0'; clLog(clSystemLog, eCLSeverityDebug, "CDR_SEQ_NO: %s\n", seq_no); return 0; } int remove_cdr_entry(uint32_t seq_no, uint64_t up_seid) { char buffer[CDR_BUFF_SIZE] = {0}; char seq_buff[CDR_BUFF_SIZE] = {0}; char seq_no_of_cdr[CDR_BUFF_SIZE] = {0}; snprintf(seq_buff, CDR_BUFF_SIZE, "%u,%lx", seq_no, up_seid); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Recived seq buff for deletion : %s\n", LOG_VALUE, seq_buff); FILE *file = fopen(CDR_FILE_PATH, "r+"); if(file == NULL) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error while opening file:%s\n", LOG_VALUE, CDR_FILE_PATH); return -1; } FILE *file_1 = fopen(PATH_TEMP, "w"); if(file_1 == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error while opening file:%s\n", LOG_VALUE, PATH_TEMP); return -1; } while(fgets(buffer,sizeof(buffer),file)!=NULL) { memset(seq_no_of_cdr, 0, sizeof(seq_no_of_cdr)); get_seq_no_of_cdr(buffer, seq_no_of_cdr); if((strncmp(seq_no_of_cdr, seq_buff, strlen(seq_buff))) == 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Remove CDR asst with seq_no : %u\n", LOG_VALUE, seq_no); continue; } else { fputs(buffer,file_1); } } fclose(file); fclose(file_1); if((remove(CDR_FILE_PATH))!=0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error while deleting\n", LOG_VALUE); return -1; } rename(PATH_TEMP, CDR_FILE_PATH); return 0; } int generate_cdr(cdr_t *dp_cdr, uint64_t up_seid, char *trigg_buff, uint32_t seq_no, uint32_t ue_ip_addr, uint8_t ue_ipv6_addr_buff[], char *CDR_BUFF) { struct timeval epoc_start_time; struct timeval epoc_end_time; struct timeval epoc_data_start_time; struct timeval epoc_data_end_time; char ue_addr_buff_v4[CDR_BUFF_SIZE] = "NA"; char ue_addr_buff_v6[CDR_BUFF_SIZE] = "NA"; char dp_ip_addr_buff_v4[CDR_BUFF_SIZE] = "NA"; char dp_ip_addr_buff_v6[CDR_BUFF_SIZE] = "NA"; char cp_ip_addr_buff_v4[CDR_BUFF_SIZE] = "NA"; char cp_ip_addr_buff_v6[CDR_BUFF_SIZE] = "NA"; char start_time_buff[CDR_TIME_BUFF] = {0}; char end_time_buff[CDR_TIME_BUFF] = {0}; char data_start_time_buff[CDR_TIME_BUFF] = {0}; char data_end_time_buff[CDR_TIME_BUFF] = {0}; pfcp_session_t *sess = NULL; pfcp_session_datat_t *sessions = NULL; uint8_t ue_ipv6_addr[IPV6_ADDRESS_LEN] = {0}; uint32_t cp_ip; uint32_t dp_ip; if (dp_cdr == NULL) { clLog(clSystemLog, eCLSeverityCritical, "usage report is NULL\n"); return -1; } sess = get_sess_info_entry(up_seid, SESS_MODIFY); if(sess == NULL) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to Retrieve Session Info\n\n", LOG_VALUE); return -1; } if(sess->sessions == NULL) { clLog(clSystemLog, eCLSeverityCritical, "Sessions not found\n"); return -1; } sessions = sess->sessions; if ( ue_ip_addr == 0 && ue_ipv6_addr_buff == 0) { if (sessions->ipv4) { ue_ip_addr = sessions->ue_ip_addr; snprintf(ue_addr_buff_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&(ue_ip_addr)))); } if(sessions->ipv6) { memcpy(ue_ipv6_addr, sessions->ue_ipv6_addr, IPV6_ADDRESS_LEN); inet_ntop(AF_INET6, ue_ipv6_addr, ue_addr_buff_v6, CDR_BUFF_SIZE); } if (!sessions->ipv4 && !sessions->ipv6 && sessions->next != NULL) { if (sessions->next->ipv4) { ue_ip_addr = sessions->next->ue_ip_addr; snprintf(ue_addr_buff_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&(ue_ip_addr)))); } if(sessions->next->ipv6) { memcpy(ue_ipv6_addr, sessions->next->ue_ipv6_addr, IPV6_ADDRESS_LEN); inet_ntop(AF_INET6, ue_ipv6_addr, ue_addr_buff_v6, CDR_BUFF_SIZE); } } } else { /**Restoration case*/ if (ue_ip_addr) { snprintf(ue_addr_buff_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&(ue_ip_addr)))); } if (*ue_ipv6_addr_buff) { inet_ntop(AF_INET6, ue_ipv6_addr_buff, ue_addr_buff_v6, CDR_BUFF_SIZE); } } if (dp_comm_ip_type == PDN_TYPE_IPV4 || dp_comm_ip_type == PDN_TYPE_IPV4_IPV6) { dp_ip = dp_comm_ip.s_addr; snprintf(dp_ip_addr_buff_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&(dp_ip)))); } if (dp_comm_ip_type == PDN_TYPE_IPV6 || dp_comm_ip_type == PDN_TYPE_IPV4_IPV6) { inet_ntop(AF_INET6, dp_comm_ipv6.s6_addr, dp_ip_addr_buff_v6, CDR_BUFF_SIZE); } if (sess->cp_ip.type == PDN_TYPE_IPV4 || sess->cp_ip.type == PDN_TYPE_IPV4_IPV6) { cp_ip = sess->cp_ip.ipv4.sin_addr.s_addr; snprintf(cp_ip_addr_buff_v4, CDR_BUFF_SIZE,"%s", inet_ntoa(*((struct in_addr *)&(cp_ip)))); } if (sess->cp_ip.type == PDN_TYPE_IPV6 || sess->cp_ip.type == PDN_TYPE_IPV4_IPV6) { inet_ntop(AF_INET6, sess->cp_ip.ipv6.sin6_addr.s6_addr, cp_ip_addr_buff_v6, CDR_BUFF_SIZE); } ntp_to_unix_time(&dp_cdr->start_time, &epoc_start_time); snprintf(start_time_buff,CDR_TIME_BUFF, "%lu", epoc_start_time.tv_sec); ntp_to_unix_time(&dp_cdr->end_time, &epoc_end_time); snprintf(end_time_buff, CDR_TIME_BUFF, "%lu", epoc_end_time.tv_sec); ntp_to_unix_time(&dp_cdr->time_of_frst_pckt, &epoc_data_start_time); snprintf(data_start_time_buff, CDR_TIME_BUFF, "%lu", epoc_data_start_time.tv_sec); ntp_to_unix_time(&dp_cdr->time_of_lst_pckt, &epoc_data_end_time); snprintf(data_end_time_buff, CDR_TIME_BUFF, "%lu", epoc_data_end_time.tv_sec); snprintf(CDR_BUFF, CDR_BUFF_SIZE, "%u,%lx,%lx,""""%"PRIu64",%s,%s,%s,%s,%s,%s,%s,%lu,%lu,%lu,%u,%s,%s,%s,%s\n" , seq_no, sess->up_seid, sess->cp_seid, sess->imsi, dp_ip_addr_buff_v4, dp_ip_addr_buff_v6, cp_ip_addr_buff_v4, cp_ip_addr_buff_v6, ue_addr_buff_v4, ue_addr_buff_v6, trigg_buff, dp_cdr->uplink_volume, dp_cdr->downlink_volume, dp_cdr->total_volume, dp_cdr->duration_value, start_time_buff, end_time_buff, data_start_time_buff, data_end_time_buff); clLog(clSystemLog, eCLSeverityDebug, "CDR : %s\n", CDR_BUFF); return 0; } /* * @brief : enqueue pfcp-sess-rpt-req message and other info * to generate CDR file in DP * @param : usage_report, usage report in pfcp-sess-rpt-req msg * @param : up_seid, user plane session id * @param : seq_no, seq_no in msg used as a key to store CDR * @return : 0 on success,else -1 */ static void enqueue_pfcp_rpt_req(pfcp_usage_rpt_sess_rpt_req_ie_t *usage_report, uint64_t up_seid, uint32_t seq_no){ cdr_rpt_req_t *cdr_data = NULL; cdr_data = rte_malloc(NULL, sizeof(cdr_rpt_req_t), 0); cdr_data->usage_report = rte_malloc(NULL, sizeof(pfcp_usage_rpt_sess_rpt_req_ie_t), 0); memcpy(cdr_data->usage_report, usage_report, sizeof(pfcp_usage_rpt_sess_rpt_req_ie_t)); cdr_data->up_seid = up_seid; cdr_data->seq_no = seq_no; if (rte_ring_enqueue(cdr_pfcp_rpt_req, (void *)cdr_data) == -ENOBUFS) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"::Can't queue UL LI pkt- ring" " full...", LOG_VALUE); } } int store_cdr_into_file_pfcp_sess_rpt_req() { FILE *file = NULL; char CDR_BUFF[CDR_BUFF_SIZE] = {0}; char TRIGG_BUFF[CDR_BUFF_SIZE] = {0}; cdr_t dp_cdr = {0}; uint32_t cdr_cnt = 0; pfcp_usage_rpt_sess_rpt_req_ie_t *usage_report = NULL; uint64_t up_seid = 0; uint32_t seq_no = 0; file = fopen(CDR_FILE_PATH, "r"); if(file == NULL) { file = fopen(CDR_FILE_PATH, "w"); if(file == NULL) { clLog(clSystemLog, eCLSeverityCritical, "Error while creating file CDR.csv\n"); return -1; } fputs(CDR_HEADER, file); clLog(clSystemLog, eCLSeverityDebug, "Adding header in file CDR.csv\n"); } fclose(file); uint32_t cdr_data_cnt = rte_ring_count(cdr_pfcp_rpt_req); cdr_rpt_req_t *cdr_data[cdr_data_cnt]; if(cdr_data_cnt){ cdr_cnt = rte_ring_dequeue_bulk(cdr_pfcp_rpt_req, (void**)cdr_data, cdr_data_cnt, NULL); } else { return 0; } file = fopen(CDR_FILE_PATH, "a"); if(file == NULL) { clLog(clSystemLog, eCLSeverityCritical, "Failed to create/open CDR.csv file\n"); return -1; } for(uint32_t i =0; i < cdr_cnt; i++){ usage_report = cdr_data[i]->usage_report; seq_no = cdr_data[i]->seq_no; up_seid = cdr_data[i]->up_seid; if(usage_report != NULL){ dp_cdr.uplink_volume = usage_report->vol_meas.uplink_volume; dp_cdr.downlink_volume = usage_report->vol_meas.downlink_volume; dp_cdr.total_volume = usage_report->vol_meas.total_volume; dp_cdr.duration_value = usage_report->dur_meas.duration_value; dp_cdr.start_time = usage_report->start_time.start_time; dp_cdr.end_time = usage_report->end_time.end_time; dp_cdr.time_of_frst_pckt = usage_report->time_of_frst_pckt.time_of_frst_pckt; dp_cdr.time_of_lst_pckt = usage_report->time_of_lst_pckt.time_of_lst_pckt; cdr_cause_code(&usage_report->usage_rpt_trig, TRIGG_BUFF); } generate_cdr(&dp_cdr, up_seid, TRIGG_BUFF, seq_no, 0, 0, CDR_BUFF); fputs(CDR_BUFF, file); rte_free(cdr_data[i]->usage_report); rte_free(cdr_data[i]); } fclose(file); return 0; } int store_cdr_for_restoration(pfcp_usage_rpt_sess_del_rsp_ie_t *usage_report, uint64_t up_seid, uint32_t trig, uint32_t seq_no, uint32_t ue_ip_addr, uint8_t ue_ipv6_addr[]) { FILE *file = NULL; char CDR_BUFF[CDR_BUFF_SIZE] = {0}; char TRIGG_BUFF[CDR_BUFF_SIZE] = {0}; cdr_t dp_cdr = {0}; file = fopen(CDR_FILE_PATH, "r"); if(file == NULL) { file = fopen(CDR_FILE_PATH, "w"); if(file == NULL) { clLog(clSystemLog, eCLSeverityCritical, "Error while creating file CDR.csv\n"); return -1; } fputs(CDR_HEADER, file); clLog(clSystemLog, eCLSeverityDebug, "Adding header in file CDR.csv\n"); } fclose(file); file = fopen(CDR_FILE_PATH, "a"); if(file == NULL) { clLog(clSystemLog, eCLSeverityCritical, "Failed to create/open CDR.csv file\n"); return -1; } dp_cdr.uplink_volume = usage_report->vol_meas.uplink_volume; dp_cdr.downlink_volume = usage_report->vol_meas.downlink_volume; dp_cdr.total_volume = usage_report->vol_meas.total_volume; dp_cdr.duration_value = usage_report->dur_meas.duration_value; dp_cdr.start_time = usage_report->start_time.start_time; dp_cdr.end_time = usage_report->end_time.end_time; dp_cdr.time_of_frst_pckt = usage_report->time_of_frst_pckt.time_of_frst_pckt; dp_cdr.time_of_lst_pckt = usage_report->time_of_lst_pckt.time_of_lst_pckt; cdr_cause_code(&usage_report->usage_rpt_trig, TRIGG_BUFF); generate_cdr(&dp_cdr, up_seid, TRIGG_BUFF, seq_no, ue_ip_addr, ue_ipv6_addr, CDR_BUFF); fputs(CDR_BUFF, file); fclose(file); return 0; } int send_usage_report_req(urr_info_t *urr, uint64_t cp_seid, uint64_t up_seid, uint32_t trig){ int encoded = 0; static uint32_t seq = 1; uint8_t pfcp_msg[PFCP_MSG_LEN] = {0}; pfcp_sess_rpt_req_t pfcp_sess_rep_req = {0}; memset(pfcp_msg, 0, sizeof(pfcp_msg)); /* Fill the Sequence number in PFCP header */ seq = get_pfcp_sequence_number(PFCP_SESSION_REPORT_REQUEST, seq); /* Set the Sequence number flag in header */ set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_rep_req.header), PFCP_SESSION_REPORT_REQUEST, HAS_SEID, seq, NO_CP_MODE_REQUIRED); /* Fill the CP Seid into header */ pfcp_sess_rep_req.header.seid_seqno.has_seid.seid = cp_seid; /* Setting Report Types in the PKT */ set_sess_report_type(&pfcp_sess_rep_req.report_type); pfcp_sess_rep_req.report_type.dldr = 0; pfcp_sess_rep_req.report_type.usar = 1; /* Fill the Session Usage report info into Report Request message */ fill_sess_rep_req_usage_report( &pfcp_sess_rep_req.usage_report[pfcp_sess_rep_req.usage_report_count], urr, trig); enqueue_pfcp_rpt_req(&pfcp_sess_rep_req.usage_report[pfcp_sess_rep_req.usage_report_count++], up_seid, seq); /* Encode the PFCP Session Report Request */ encoded = encode_pfcp_sess_rpt_req_t(&pfcp_sess_rep_req, pfcp_msg); pfcp_header_t *pfcp_hdr = (pfcp_header_t *) pfcp_msg; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"sending PFCP_SESSION_REPORT_REQUEST [%d] from dp\n", LOG_VALUE, pfcp_hdr->message_type); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"length[%d]\n", LOG_VALUE, htons(pfcp_hdr->message_len)); /* retrive the session Info */ pfcp_session_t *sess = NULL; sess = get_sess_info_entry(up_seid, SESS_MODIFY); if(sess == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Retrieve Session Info\n\n", LOG_VALUE); return -1; } /* Send the PFCP Session Report Request to CP*/ if (encoded != 0) { if(pfcp_send(my_sock.sock_fd, my_sock.sock_fd_v6, (char *)pfcp_msg, encoded, sess->cp_ip, SENT) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error Sending in PFCP Session Report" "Request for CDR: %i\n", LOG_VALUE, errno); } } process_event_li(sess, NULL, 0, pfcp_msg, encoded, &sess->cp_ip); return 0; } static inline void adjust_ipv6_pktlen(struct rte_mbuf *m, const struct ipv6_hdr *iph, uint32_t l2_len) { uint32_t plen, trim; plen = rte_be_to_cpu_16(iph->payload_len) + sizeof(*iph) + l2_len; if (plen < m->pkt_len) { trim = m->pkt_len - plen; rte_pktmbuf_trim(m, trim); } } static inline int ipv6_get_next_ext(const uint8_t *p, int proto, size_t *ext_len) { int next_proto; switch (proto) { case IPPROTO_AH: next_proto = *p++; *ext_len = (*p + 2) * sizeof(uint32_t); break; case IPPROTO_HOPOPTS: case IPPROTO_ROUTING: case IPPROTO_DSTOPTS: next_proto = *p++; *ext_len = (*p + 1) * sizeof(uint64_t); break; case IPPROTO_FRAGMENT: next_proto = *p; *ext_len = RTE_IPV6_FRAG_HDR_SIZE; break; default: return -EINVAL; } return next_proto; } static int getIPv6_header_len(struct rte_mbuf m){ struct rte_mbuf *pkt = &m; const struct ipv6_hdr *iph6; int next_proto; size_t l3len, ext_len; uint8_t *p; /* get protocol type */ iph6 = (const struct ipv6_hdr *)rte_pktmbuf_adj(pkt, ETHER_HDR_LEN); adjust_ipv6_pktlen(pkt, iph6, 0); next_proto = iph6->proto; /* determine l3 header size up to ESP extension */ l3len = sizeof(struct ipv6_hdr); p = rte_pktmbuf_mtod(pkt, uint8_t *); while (next_proto != IPPROTO_ESP && l3len < pkt->data_len && (next_proto = ipv6_get_next_ext(p + l3len, next_proto, &ext_len)) >= 0){ l3len += ext_len; } return l3len; } /** * @brief : Returns payload length (user data len) from packet * @param : pkts, pkts recived * @return : Returns user data len on succes and -1 on failure */ static int calculate_user_data_len(struct rte_mbuf *pkts) { uint64_t len = 0; uint64_t total_len = 0; uint8_t *data = NULL; if (pkts == NULL) return -1; total_len = rte_pktmbuf_data_len(pkts); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Total packet len : %lu\n", LOG_VALUE, total_len); len = ETH_HDR_SIZE; /*Get pointer to IP frame in packet*/ data = rte_pktmbuf_mtod_offset(pkts, uint8_t *, len); if ( ( data[0] & VERSION_FLAG_CHECK ) == IPv4_VERSION) { len += IPv4_HDR_SIZE; } else { len += getIPv6_header_len(*pkts); } len += UDP_HDR_SIZE; data = rte_pktmbuf_mtod_offset(pkts, uint8_t *, len); uint8_t gtpu_flags = *data; len += GTP_HDR_SIZE; /* N-PDU number */ if (gtpu_flags & PDU_NO_BIT) { len += PDU_NO_SIZE; } /* Seq. No. */ if (gtpu_flags & SEQ_NO_BIT) { len += SEQ_NO_SIZE; } /* Next Extension header */ if (gtpu_flags & EXTENSION_HDR_BIT) { while (1) { data = rte_pktmbuf_mtod_offset(pkts, uint8_t *, len); uint8_t ext_hdr_len = *data; uint8_t *next_extension_header = NULL; next_extension_header = data + (ext_hdr_len - 1); if( NO_MORE_EXTENSION_HEADERS == (*next_extension_header) ) { len += ext_hdr_len; break; } else { len += ext_hdr_len; } } } len -= ETH_HDR_SIZE; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"user data len : %lu\n", LOG_VALUE, (total_len - len)); return (total_len - len); } /** * @brief : Update the Usage Report structre as per data recived * @param : pkts, pkts recived * @param : n, no of pkts recived * @param : pkts_mask, packet mask * @param : pdr, structure for pdr info for pkts * @return : Returns 0 for succes and -1 failure */ static int update_usage(struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, pdr_info_t **pdr, uint16_t flow) { for(int i = 0; i < n; i++){ if (ISSET_BIT(*pkts_mask, i)) { /* Get the linked URRs from the PDR */ if(pdr[i] != NULL) { if(pdr[i]->urr_count){ /* Check the Flow Direction */ if(flow == DOWNLINK){ if(!pdr[i]->urr->first_pkt_time) pdr[i]->urr->first_pkt_time = current_ntp_timestamp(); /* Get System Current TimeStamp */ pdr[i]->urr->last_pkt_time = current_ntp_timestamp(); /* Retrive the data from the packet */ pdr[i]->urr->dwnlnk_data += calculate_user_data_len(pkts[i]); if((pdr[i]->urr->rept_trigg == VOL_TIME_BASED || pdr[i]->urr->rept_trigg == VOL_BASED) && (pdr[i]->urr->dwnlnk_data >= pdr[i]->urr->vol_thes_dwnlnk)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Downlink Volume threshol reached\n", LOG_VALUE); /* Send Session Usage Report for Downlink*/ send_usage_report_req(pdr[i]->urr, pdr[i]->session->cp_seid, pdr[i]->session->up_seid,VOL_BASED); /* Reset the DL data */ pdr[i]->urr->dwnlnk_data = 0; } }else if(flow == UPLINK){ /* Retrive the data from the packet */ pdr[i]->urr->uplnk_data += calculate_user_data_len(pkts[i]); if(!pdr[i]->urr->first_pkt_time) pdr[i]->urr->first_pkt_time = current_ntp_timestamp(); /* Get System Current TimeStamp */ pdr[i]->urr->last_pkt_time = current_ntp_timestamp(); if((pdr[i]->urr->rept_trigg == VOL_TIME_BASED || pdr[i]->urr->rept_trigg == VOL_BASED) && (pdr[i]->urr->uplnk_data >= pdr[i]->urr->vol_thes_uplnk)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Ulink Volume threshol reached\n", LOG_VALUE); /* Send Session Usage Report for Uplink*/ send_usage_report_req(pdr[i]->urr, pdr[i]->session->cp_seid, pdr[i]->session->up_seid, VOL_BASED); /* Reset the UL data */ pdr[i]->urr->uplnk_data = 0; } } } } } } return 0; } /** * @Brief : Function to fill pdrs from sess data * @param : n, number of packets * @param : sess_data, session data * @param : pdr, packet detection rule * @param : pkts_mask * @return : Returns nothing */ static void get_pdr_from_sess_data(uint32_t n, pfcp_session_datat_t **sess_data, pdr_info_t **pdr, uint64_t *pkts_mask, uint64_t *pkts_queue_mask) { uint32_t i; for (i = 0; i < n; i++) { if ((ISSET_BIT(*pkts_mask, i)) || ((pkts_queue_mask != NULL) && ISSET_BIT(*pkts_queue_mask, i))) { /* Fill the PDR info form the session data */ if (sess_data[i] != NULL) { if (sess_data[i]->pdrs == NULL) { /* PDR is NULL, Reset the pkts mask */ RESET_BIT(*pkts_mask, i); continue; } pdr[i] = sess_data[i]->pdrs; } else { /* Session is NULL, Reset the pkts mask */ RESET_BIT(*pkts_mask, i); } } } } /* enqueue re-direct/loopback pkts and send to DL core */ static void enqueue_loopback_pkts(struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, uint8_t port) { for (uint32_t inx = 0; inx < n; inx++) { if (ISSET_BIT(*pkts_mask, inx)) { /* Enqeue the LoopBack pkts */ if (rte_ring_enqueue(shared_ring[port], (void *)pkts[inx]) == -ENOBUFS) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"LoopBack Shared_Ring:Can't queue pkts ring full" " So Dropping Loopback pkt\n", LOG_VALUE); continue; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"LoopBack: enqueue pkts to port:%u", LOG_VALUE, port); } } } /* enqueue router solicitation pkts and send to master core */ static void enqueue_rs_pkts(struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, uint8_t port) { for (uint32_t inx = 0; inx < n; inx++) { if (ISSET_BIT(*pkts_mask, inx)) { /* Enqeue the Router solicitation pkts */ if (rte_ring_enqueue(epc_app.epc_mct_rx[port], (void *)pkts[inx]) == -ENOBUFS) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Master_Core_Ring:Can't queue pkts ring full" " So Dropping router solicitation pkt\n", LOG_VALUE); continue; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"RS: Router solicitation enqueue pkts, port:%u", LOG_VALUE, port); #ifdef STATS --epc_app.ul_params[S1U_PORT_ID].pkts_in; ++epc_app.ul_params[S1U_PORT_ID].pkts_rs_in; #endif /* STATS */ } } } /* Filter the Router Solicitations pkts from the pipeline */ static void filter_router_solicitations_pkts(struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, uint64_t *pkts_queue_mask, uint64_t *decap_pkts_mask) { for (uint32_t inx = 0; inx < n; inx++) { struct ether_hdr *ether = NULL; struct ipv6_hdr *ipv6_hdr = NULL; struct gtpu_hdr *gtpu_hdr = NULL; struct icmp_hdr *icmp = NULL; ether = (struct ether_hdr *)rte_pktmbuf_mtod(pkts[inx], uint8_t *); if (ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) { gtpu_hdr = get_mtogtpu(pkts[inx]); ipv6_hdr = (struct ipv6_hdr*)((char*)gtpu_hdr + GTPU_HDR_SIZE); icmp = (struct icmp_hdr *)((char*)gtpu_hdr + GTPU_HDR_SIZE + IPv6_HDR_SIZE); } else if (ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6)) { ipv6_hdr = get_inner_mtoipv6(pkts[inx]); icmp = get_inner_mtoicmpv6(pkts[inx]); } /* Handle the inner IPv6 router solicitation Pkts */ if (ipv6_hdr != NULL && ipv6_hdr->proto == IPPROTO_ICMPV6) { if (icmp->icmp_type == ICMPv6_ROUTER_SOLICITATION) { RESET_BIT(*pkts_mask, inx); RESET_BIT(*decap_pkts_mask, inx); SET_BIT(*pkts_queue_mask, inx); } } } } /** * @Brief : Function to calculate gtpu header length * @param : pkts, rte_mbuf packet * @return : Returns length of gtpu header length */ static uint8_t calc_gtpu_len(struct rte_mbuf *pkts) { uint8_t gtpu_len = 0; uint8_t *pkt_ptr = NULL; if (1 == app.gtpu_seqnb_in) { gtpu_len = GPDU_HDR_SIZE_WITH_SEQNB; } else if (2 == app.gtpu_seqnb_in) { gtpu_len = GPDU_HDR_SIZE_WITHOUT_SEQNB; } else { pkt_ptr = (uint8_t *) get_mtogtpu(pkts); gtpu_len = GPDU_HDR_SIZE_DYNAMIC(*pkt_ptr); } return gtpu_len; } /** * @Brief : Function to fillup ethernet information * @param : intfc, interface name * @param : dir, packet direction * @param : *src, source * @param : *dst, destination * @return : Returns nothing */ static void fill_ether_info(uint8_t intfc, uint8_t dir, int32_t *src, int32_t *dst) { *src = -1; *dst = -1; if (WEST_INTFC == intfc) { if (UPLINK_DIRECTION == dir) { *dst = app.wb_port; } else { *src = app.wb_port; } } else if (EAST_INTFC == intfc) { if (UPLINK_DIRECTION == dir) { *src = app.eb_port; } else { *dst = app.eb_port; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"intfc(%u) dir(%u) src(%d) dst(%d)\n", LOG_VALUE, intfc, dir, *src, *dst); return; } /** * @Brief : Function to update sgi pkts for LI as per LI configuration * @param : pkts, mbuf packets * @param : li_data, li_data_t structure * @param : content, packet content * @return : Returns nothing */ static void update_li_sgi_pkts(struct rte_mbuf *pkts, li_data_t *li_data, uint8_t content) { uint8_t *ptr = NULL; uint8_t *tmp_pkt = NULL; uint8_t *tmp_buf = NULL; struct udp_hdr *udp_ptr = NULL; struct ipv4_hdr *ipv4_ptr = NULL; struct ipv6_hdr *ipv6_ptr = NULL; switch (content) { case COPY_HEADER_ONLY: ptr = (uint8_t *)(rte_pktmbuf_mtod(pkts, unsigned char *) + ETH_HDR_SIZE); tmp_pkt = rte_pktmbuf_mtod(pkts, uint8_t *); li_data->size = rte_pktmbuf_data_len(pkts); /* copy data packet in temporary buffer */ tmp_buf = rte_malloc(NULL, li_data->size, 0); if (NULL == tmp_buf) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR: Memory" " allocation for pkts failed", LOG_VALUE); return; } memcpy(tmp_buf, tmp_pkt, li_data->size); if (*ptr == IPV4_PKT_VER) { /* Update length in udp packet */ udp_ptr = (struct udp_hdr *) &tmp_buf[ETH_HDR_SIZE + IPv4_HDR_SIZE]; udp_ptr->dgram_len = htons(UDP_HDR_SIZE); /* Update length in ipv4 packet */ ipv4_ptr = (struct ipv4_hdr *) &tmp_buf[ETH_HDR_SIZE]; ipv4_ptr->total_length = htons(IPv4_HDR_SIZE + UDP_HDR_SIZE); /* set length of packet */ li_data->size = ETH_HDR_SIZE + IPv4_HDR_SIZE + UDP_HDR_SIZE; } else { /* Update length in udp packet */ udp_ptr = (struct udp_hdr *) &tmp_buf[ETH_HDR_SIZE + IPv6_HDR_SIZE]; udp_ptr->dgram_len = htons(UDP_HDR_SIZE); /* Update length in ipv4 packet */ ipv6_ptr = (struct ipv6_hdr *) &tmp_buf[ETH_HDR_SIZE]; ipv6_ptr->payload_len = htons(UDP_HDR_SIZE); /* set length of packet */ li_data->size = ETH_HDR_SIZE + IPv6_HDR_SIZE + UDP_HDR_SIZE; } /* copy only header in li packet not modify original packet */ li_data->pkts = rte_malloc(NULL, (li_data->size + sizeof(li_header_t)), 0); if (NULL == li_data->pkts) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR: Memory" " allocation for pkts failed", LOG_VALUE); rte_free(tmp_buf); tmp_buf = NULL; return; } memcpy(li_data->pkts, tmp_buf, li_data->size); /* free temporary allocated buffer */ rte_free(tmp_buf); tmp_buf = NULL; break; case COPY_HEADER_DATA_ONLY: case COPY_DATA_ONLY: /* copy entire packet and set size */ li_data->size = rte_pktmbuf_data_len(pkts); tmp_pkt = rte_pktmbuf_mtod(pkts, uint8_t *); li_data->pkts = rte_malloc(NULL, (li_data->size + sizeof(li_header_t)), 0); if (NULL == li_data->pkts) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR: Memory" " allocation for pkts failed", LOG_VALUE); return; } memcpy(li_data->pkts, tmp_pkt, li_data->size); break; } return; } /** * @Brief : Function to update pkts for LI as per LI configurations * @param : pkts, mbuf packets * @param : li_data, li_data_t structure * @param : intfc, interface name * @param : dir, packet direction * @param : content, packet content * @return : Returns nothing */ static void update_li_pkts(struct rte_mbuf *pkts, li_data_t *li_data, uint8_t intfc, uint8_t dir, uint8_t content) { uint32_t i = 0; size_t len = 0; uint32_t cntr = 0; uint8_t *ptr = NULL; uint8_t gtpu_len = 0; int32_t src_ether = -1; int32_t dst_ether = -1; uint8_t *tmp_pkt = NULL; uint8_t *tmp_buf = NULL; struct udp_hdr *udp_ptr = NULL; struct ipv4_hdr *ipv4_ptr = NULL; struct ipv6_hdr *ipv6_ptr = NULL; struct ether_hdr *eth_ptr = NULL; switch (content) { case COPY_HEADER_ONLY: ptr = (uint8_t *)(rte_pktmbuf_mtod(pkts, unsigned char *) + ETH_HDR_SIZE); tmp_pkt = rte_pktmbuf_mtod(pkts, uint8_t *); li_data->size = rte_pktmbuf_data_len(pkts); /* copy data packet in temporary buffer */ tmp_buf = rte_malloc(NULL, li_data->size, 0); if (NULL == tmp_buf) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR: Memory" " allocation for pkts failed", LOG_VALUE); return; } memcpy(tmp_buf, tmp_pkt, li_data->size); /* set gtpu length as per configuration */ gtpu_len = calc_gtpu_len(pkts); if (*ptr == IPV4_PKT_VER) { /* Update length in udp packet */ udp_ptr = (struct udp_hdr *) &tmp_buf[ETH_HDR_SIZE + IPv4_HDR_SIZE]; udp_ptr->dgram_len = htons(UDP_HDR_SIZE + gtpu_len); /* Update length in ipv4 packet */ ipv4_ptr = (struct ipv4_hdr *) &tmp_buf[ETH_HDR_SIZE]; ipv4_ptr->total_length = htons(IPv4_HDR_SIZE + UDP_HDR_SIZE + gtpu_len); /* set length of packet */ len = ETH_HDR_SIZE + IPv4_HDR_SIZE + UDP_HDR_SIZE + gtpu_len; } else { udp_ptr = (struct udp_hdr *) &tmp_buf[ETH_HDR_SIZE + IPv6_HDR_SIZE]; udp_ptr->dgram_len = htons(UDP_HDR_SIZE + gtpu_len); /* Update length in ipv6 packet */ ipv6_ptr = (struct ipv6_hdr *) &tmp_buf[ETH_HDR_SIZE]; ipv6_ptr->payload_len = htons(UDP_HDR_SIZE + gtpu_len); /* set length of packet */ len = ETH_HDR_SIZE + IPv6_HDR_SIZE + UDP_HDR_SIZE + gtpu_len; } li_data->size = len; /* copy only header in li packet not modify original packet */ li_data->pkts = rte_malloc(NULL, (len + sizeof(li_header_t)), 0); if (NULL == li_data->pkts) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR: Memory" " allocation for pkts failed", LOG_VALUE); rte_free(tmp_buf); tmp_buf = NULL; return; } memcpy(li_data->pkts, tmp_buf, len); /* free temporary allocated buffer */ rte_free(tmp_buf); tmp_buf = NULL; break; case COPY_HEADER_DATA_ONLY: /* copy entire packet and set size */ li_data->size = rte_pktmbuf_data_len(pkts); tmp_pkt = rte_pktmbuf_mtod(pkts, uint8_t *); li_data->pkts = rte_malloc(NULL, (li_data->size + sizeof(li_header_t)), 0); if (NULL == li_data->pkts) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR: Memory" " allocation for pkts failed", LOG_VALUE); return; } memcpy(li_data->pkts, tmp_pkt, li_data->size); break; case COPY_DATA_ONLY: ptr = (uint8_t *)(rte_pktmbuf_mtod(pkts, unsigned char *) + ETH_HDR_SIZE); tmp_pkt = rte_pktmbuf_mtod(pkts, uint8_t *); li_data->size = rte_pktmbuf_data_len(pkts); /* copy data packet in temporary buffer */ tmp_buf = rte_malloc(NULL, li_data->size, 0); if (NULL == tmp_buf) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR: Memory" " allocation for pkts failed", LOG_VALUE); return; } memcpy(tmp_buf, tmp_pkt, li_data->size); /* set gtpu length as per configuration */ gtpu_len = calc_gtpu_len(pkts); if (*ptr == IPV4_PKT_VER) { /* * set len parameter that much bytes we are going to remove * from start of buffer which is gtpu header */ len = gtpu_len + UDP_HDR_SIZE + IPv4_HDR_SIZE; } else { /* * set len parameter that much bytes we are going to remove * from start of buffer which is gtpu header */ len = gtpu_len + UDP_HDR_SIZE + IPv6_HDR_SIZE; } /* allocate memory for li packet */ li_data->pkts = rte_malloc(NULL, ((li_data->size - len) + sizeof(li_header_t)), 0); if (NULL == li_data->pkts) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR: Memory" " allocation for pkts failed", LOG_VALUE); rte_free(tmp_buf); tmp_buf = NULL; return; } /* copy data to li packet without gtpu header */ for (cntr = len; cntr < li_data->size; ++cntr) { li_data->pkts[i++] = tmp_buf[cntr]; } /* update li data size */ li_data->size -= len; /* Update ether header with available mac address */ eth_ptr = (struct ether_hdr *)&li_data->pkts[0]; memset(eth_ptr, 0, sizeof(struct ether_hdr)); if (*ptr == IPV4_PKT_VER) { eth_ptr->ether_type = htons(ETH_TYPE_IPv4); } else { eth_ptr->ether_type = htons(ETH_TYPE_IPv6); } fill_ether_info(intfc, dir, &src_ether, &dst_ether); if (-1 != src_ether) { ether_addr_copy(&ports_eth_addr[src_ether], &eth_ptr->s_addr); } if (-1 != dst_ether) { ether_addr_copy(&ports_eth_addr[dst_ether], &eth_ptr->d_addr); } /* free temporary allocated buffer */ rte_free(tmp_buf); tmp_buf = NULL; break; } return; } /** * @Brief : Function to enqueue pkts for LI if required * @param : n, no of packets * @param : pkts, mbuf packets * @param : PDR, pointer to pdr session info * @param : intfc, interface name * @param : pkts_mask, SGI interface pkt mask * @return : Returns nothing */ static void enqueue_li_pkts(uint32_t n, struct rte_mbuf **pkts, pdr_info_t **pdr, uint8_t intfc, uint8_t direction, uint64_t *pkts_mask, uint8_t mask_type) { uint32_t i = 0; uint8_t docopy = NOT_PRESENT; for(i = 0; i < n; i++) { if(pkts[i] != NULL && pdr[i] != NULL && pdr[i]->far && pdr[i]->far->li_config_cnt > 0) { far_info_t *far = pdr[i]->far; for (uint8_t cnt = 0; cnt < far->li_config_cnt; cnt++) { li_data_t *li_data = NULL; docopy = NOT_PRESENT; li_data = rte_malloc(NULL, sizeof(li_data_t), 0); li_data->imsi = far->session->pdrs->session->imsi; li_data->id = far->li_config[cnt].id; li_data->forward = far->li_config[cnt].forward; switch (intfc) { case WEST_INTFC: if ((COPY_UP_DOWN_PKTS == far->li_config[cnt].west_direction) || ((COPY_DOWN_PKTS == far->li_config[cnt].west_direction) && (DOWNLINK_DIRECTION == direction)) || ((COPY_UP_PKTS == far->li_config[cnt].west_direction) && (UPLINK_DIRECTION == direction))) { docopy = PRESENT; /* TODO: Filter gateway allow packets */ /* Currently no need to handle below condition for mask_type*/ if (ISSET_BIT(*pkts_mask, i)) { update_li_pkts(pkts[i], li_data, intfc, direction, far->li_config[cnt].west_content); } } break; case EAST_INTFC: if ((COPY_UP_DOWN_PKTS == far->li_config[cnt].east_direction) || ((COPY_DOWN_PKTS == far->li_config[cnt].east_direction) && (DOWNLINK_DIRECTION == direction)) || ((COPY_UP_PKTS == far->li_config[cnt].east_direction) && (UPLINK_DIRECTION == direction))) { docopy = PRESENT; if (ISSET_BIT(*pkts_mask, i) && ((ENCAP_MASK == mask_type) || (DECAP_MASK == mask_type))) { update_li_sgi_pkts(pkts[i], li_data, far->li_config[cnt].east_content); } if (ISSET_BIT(*pkts_mask, i) && (FWD_MASK == mask_type)) { update_li_pkts(pkts[i], li_data, intfc, direction, far->li_config[cnt].east_content); } } break; default: docopy = NOT_PRESENT; break; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"id(%lu)" " intfc(%u) direction(%u) copy(%u) west direction(%u)" " west content(%u) east direction(%u) east content(%u)" " forward(%u)\n", LOG_VALUE, far->li_config[cnt].id, intfc, direction, docopy, far->li_config[cnt].west_direction, far->li_config[cnt].west_content, far->li_config[cnt].east_direction, far->li_config[cnt].east_content, far->li_config[cnt].forward); if (PRESENT == docopy) { if (DOWNLINK_DIRECTION == direction) { if (rte_ring_enqueue(li_dl_ring, (void *)li_data) == -ENOBUFS) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"%::Can't queue DL LI pkt- ring" " full...", LOG_VALUE); } } else if (UPLINK_DIRECTION == direction) { if (rte_ring_enqueue(li_ul_ring, (void *)li_data) == -ENOBUFS) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"::Can't queue UL LI pkt- ring" " full...", LOG_VALUE); } } } } } } } /** * @brief : Fill pdr details * @param : n, no of pdrs * @param : sess_data, session information * @param : pdr, structure to ne filled * @param : pkts_queue_mask, packet queue mask * @return : Returns nothing */ static void fill_pdr_info(uint32_t n, pfcp_session_datat_t **sess_data, pdr_info_t **pdr, uint64_t *pkts_queue_mask) { uint32_t itr = 0; for (itr = 0; itr < n; itr++) { if (ISSET_BIT(*pkts_queue_mask, itr)) { /* Fill the PDR info form the session data */ pdr[itr] = sess_data[itr]->pdrs; } } return; } /** * @brief : Get pdr details * @param : sess_data, session information * @param : pdr, structure to ne filled * @param : precedence, variable to precedence value * @param : n, no of pdrs * @param : pkts_mask, packet mask * @param : fd_pkts_mask, packet mask * @param : pkts_queue_mask, packet queue mask * @return : Returns nothing */ static void get_pdr_info(pfcp_session_datat_t **sess_data, pdr_info_t **pdr, uint32_t **precedence, uint32_t n, uint64_t *pkts_mask, uint64_t *fd_pkts_mask, uint64_t *pkts_queue_mask) { uint32_t j = 0; for (j = 0; j < n; j++) { if (((ISSET_BIT(*pkts_mask, j) && (ISSET_BIT(*fd_pkts_mask, j))) && precedence[j] != NULL)) { pdr[j] = get_pdr_node(sess_data[j]->pdrs, *precedence[j]); /* Need to check this condition */ if (pdr[j] == NULL) { RESET_BIT(*pkts_mask, j); //RESET_BIT(*pkts_queue_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT": PDR LKUP Linked List FAIL for Precedence " ":%u\n", LOG_VALUE, *precedence[j]); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"PDR LKUP: PDR ID: %u, FAR_ID: %u\n", LOG_VALUE, pdr[j]->rule_id, (pdr[j]->far)->far_id_value); } } else if (ISSET_BIT(*fd_pkts_mask, j)) { RESET_BIT(*pkts_mask, j); } } return; } /** * @brief : Acl table lookup for sdf rule * @param : pkts, mbuf packets * @param : n, no of packets * @param : pkts_mask, packet mask * @param : fd_pkts_mask, packet mask * @param : sess_data, session information * @param : prcdnc, precedence value * @return : Returns nothing */ static void acl_sdf_lookup(struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, uint64_t *fd_pkts_mask, pfcp_session_datat_t **sess_data, uint32_t **prcdnc) { uint32_t j = 0; uint32_t tmp_prcdnc = 0; for (j = 0; j < n; j++) { if ((ISSET_BIT(*pkts_mask, j)) && (ISSET_BIT(*fd_pkts_mask, j))) { if (!sess_data[j]->acl_table_indx) { RESET_BIT(*pkts_mask, j); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Not Found any ACL_Table or SDF Rule for the UL\n", LOG_VALUE); continue; } tmp_prcdnc = 0; int index = 0; for(uint16_t itr = 0; itr < sess_data[j]->acl_table_count; itr++){ if(sess_data[j]->acl_table_indx[itr] != 0){ /* Lookup for SDF in ACL Table */ prcdnc[j] = sdf_lookup(pkts, j, sess_data[j]->acl_table_indx[itr]); } if(prcdnc[j] == NULL) continue; if(tmp_prcdnc == 0 || (*prcdnc[j] != 0 && *prcdnc[j] < tmp_prcdnc)){ tmp_prcdnc = *prcdnc[j]; index = itr; }else{ *prcdnc[j] = tmp_prcdnc; } } if(prcdnc[j] != NULL) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ACL SDF LKUP TABLE Index:%u, prcdnc:%u\n", LOG_VALUE, sess_data[j]->acl_table_indx[index], *prcdnc[j]); } } } return; } void filter_ul_traffic(struct rte_pipeline *p, struct rte_mbuf **pkts, uint32_t n, int wk_index, uint64_t *pkts_mask, uint64_t *decap_pkts_mask, pdr_info_t **pdr, pfcp_session_datat_t **sess_data) { uint64_t pkts_queue_mask = 0; uint32_t *precedence[MAX_BURST_SZ] = {NULL}; /* ACL Lookup, Filter the Uplink Traffic based on 5 tuple rule */ acl_sdf_lookup(pkts, n, pkts_mask, decap_pkts_mask, &sess_data[0], &precedence[0]); /* Selection of the PDR from Session Data object based on precedence */ get_pdr_info(&sess_data[0], &pdr[0], &precedence[0], n, pkts_mask, decap_pkts_mask, &pkts_queue_mask); /* Filter UL and DL traffic based on QER Gating */ qer_gating(&pdr[0], n, pkts_mask, decap_pkts_mask, &pkts_queue_mask, UPLINK); return; } int wb_pkt_handler(struct rte_pipeline *p, struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, int wk_index) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"In WB_Pkt_Handler\n", LOG_VALUE); uint64_t fwd_pkts_mask = 0; uint64_t snd_err_pkts_mask = 0; uint64_t pkts_queue_mask = 0; uint64_t decap_pkts_mask = 0; uint64_t loopback_pkts_mask = 0; uint64_t pkts_queue_rs_mask = 0; pdr_info_t *pdr[MAX_BURST_SZ] = {NULL}; pdr_info_t *pdr_li[MAX_BURST_SZ] = {NULL}; pfcp_session_datat_t *sess_data[MAX_BURST_SZ] = {NULL}; *pkts_mask = (~0LLU) >> (64 - n); /* Get the Session Data Information */ ul_sess_info_get(pkts, n, pkts_mask, &snd_err_pkts_mask, &fwd_pkts_mask, &decap_pkts_mask, &sess_data[0]); /* Burst pkt handling */ /* Filter the Forward pkts and decasulation pkts */ if (sess_data[0] != NULL) { if (fwd_pkts_mask) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"WB: FWD Recvd pkts\n", LOG_VALUE); /* get pdr from sess data */ get_pdr_from_sess_data(n, &sess_data[0], &pdr_li[0], &fwd_pkts_mask, &pkts_queue_mask); /* TODO: Handle CDR and LI for IPv6 */ /* Send Session Usage Report */ update_usage(pkts, n, &fwd_pkts_mask, pdr_li, UPLINK); /* enqueue west interface uplink pkts for user level packet copying */ enqueue_li_pkts(n, pkts, pdr_li, WEST_INTFC, UPLINK_DIRECTION, &fwd_pkts_mask, FWD_MASK); /* Update nexthop L3 header*/ update_nexts5s8_info(pkts, n, pkts_mask, &fwd_pkts_mask, &loopback_pkts_mask, &sess_data[0], &pdr[0]); /* Fill the L2 Frame of the loopback pkts */ if (loopback_pkts_mask) { /* Update L2 Frame */ update_nexthop_info(pkts, n, &loopback_pkts_mask, app.wb_port, &pdr[0], PRESENT); /* Enqueue loopback pkts into the shared ring, i.e handover to another core to send */ enqueue_loopback_pkts(pkts, n, &loopback_pkts_mask, app.wb_port); } } if (decap_pkts_mask) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"WB: Decap Recvd pkts\n", LOG_VALUE); /* PGWU/SAEGWU */ /* Get the PDR entry for LI pkts */ get_pdr_from_sess_data(n, &sess_data[0], &pdr_li[0], &decap_pkts_mask, NULL); /* Filter the Router Solicitations pkts from the pipeline */ filter_router_solicitations_pkts(pkts, n, pkts_mask, &pkts_queue_rs_mask, &decap_pkts_mask); /* Send Session Usage Report */ update_usage(pkts, n, &decap_pkts_mask, pdr_li, UPLINK); /* enqueue west interface uplink pkts for user level packet copying */ enqueue_li_pkts(n, pkts, pdr_li, WEST_INTFC, UPLINK_DIRECTION, &decap_pkts_mask, DECAP_MASK); /* Decap GTPU and update meta data*/ gtpu_decap(pkts, n, pkts_mask, &decap_pkts_mask); /*Apply sdf filters on uplink traffic*/ filter_ul_traffic(p, pkts, n, wk_index, pkts_mask, &decap_pkts_mask, &pdr[0], &sess_data[0]); /* Enqueue Router Solicitation packets */ if (pkts_queue_rs_mask) { rte_pipeline_ah_packet_hijack(p, pkts_queue_rs_mask); enqueue_rs_pkts(pkts, n, &pkts_queue_rs_mask, app.wb_port); } } /* If Outer Header Removal Not Set in the PDR, that means forward packets */ /* Set next hop IP to S5/S8/ DL port*/ /* Update nexthop L2 header*/ update_nexthop_info(pkts, n, pkts_mask, app.eb_port, &pdr[0], NOT_PRESENT); /* up pcap dumper */ up_core_pcap_dumper(pcap_dumper_west, pkts, n, pkts_mask); } if (decap_pkts_mask) { /* enqueue west interface uplink pkts for user level packet copying */ enqueue_li_pkts(n, pkts, pdr, EAST_INTFC, UPLINK_DIRECTION, &decap_pkts_mask, DECAP_MASK); } if (fwd_pkts_mask) { /* enqueue west interface uplink pkts for user level packet copying */ enqueue_li_pkts(n, pkts, pdr, EAST_INTFC, UPLINK_DIRECTION, &fwd_pkts_mask, FWD_MASK); } /* Send the Error indication to peer node */ if (snd_err_pkts_mask && error_indication_snd) { enqueue_pkts_snd_err_ind(pkts, n, app.wb_port, &snd_err_pkts_mask); } /* Intimate the packets to be dropped*/ rte_pipeline_ah_packet_drop(p, ~(*pkts_mask)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Out WB_Pkt_Handler\n", LOG_VALUE); return 0; } /** * @brief : Filter downlink traffic * @param : p, rte pipeline data * @param : pkts, mbuf packets * @param : n, no of packets * @param : wk_index * @param : sess_data, session information * @param : pdr, structure to store pdr info * @return : Returns packet mask value */ static void filter_dl_traffic(struct rte_pipeline *p, struct rte_mbuf **pkts, uint32_t n, int wk_index, uint64_t *pkts_mask, uint64_t *fd_pkts_mask, pfcp_session_datat_t **sess_data, pdr_info_t **pdr) { uint32_t *precedence[MAX_BURST_SZ] = {NULL}; uint64_t pkts_queue_mask = 0; /* ACL Lookup, Filter the Downlink Traffic based on 5 tuple rule */ acl_sdf_lookup(pkts, n, pkts_mask, fd_pkts_mask, &sess_data[0], &precedence[0]); /* Selection of the PDR from Session Data object based on precedence */ get_pdr_info(&sess_data[0], &pdr[0], &precedence[0], n, pkts_mask, fd_pkts_mask, &pkts_queue_mask); /* Filter DL traffic based on QER Gating */ qer_gating(&pdr[0], n, pkts_mask, fd_pkts_mask, &pkts_queue_mask, DOWNLINK); #ifdef HYPERSCAN_DPI /* Send cloned dns pkts to dns handler*/ clone_dns_pkts(pkts, n, pkts_mask); #endif /* HYPERSCAN_DPI */ return; } /** * Process Downlink traffic: sdf and adc filter, metering, charging and encap gtpu. * Update adc hash if dns reply is found with ip addresses. */ int eb_pkt_handler(struct rte_pipeline *p, struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, int wk_index) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"In EB_Pkt_Handler\n", LOG_VALUE); uint64_t pkts_queue_mask = 0; uint64_t fwd_pkts_mask = 0; uint64_t encap_pkts_mask = 0; uint64_t snd_err_pkts_mask = 0; pdr_info_t *pdr[MAX_BURST_SZ] = {NULL}; pfcp_session_datat_t *sess_data[MAX_BURST_SZ] = {NULL}; *pkts_mask = (~0LLU) >> (64 - n); /* Get the Session Data Information */ dl_sess_info_get(pkts, n, pkts_mask, &sess_data[0], &pkts_queue_mask, &snd_err_pkts_mask, &fwd_pkts_mask, &encap_pkts_mask); /* Burst pkt handling */ /* Filter the Forward pkts and decasulation pkts */ if (sess_data[0] != NULL) { if (fwd_pkts_mask) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"EB: FWD Recvd pkts\n", LOG_VALUE); /* SGWU */ /* get pdr from sess data */ get_pdr_from_sess_data(n, &sess_data[0], &pdr[0], &fwd_pkts_mask, &pkts_queue_mask); /* enqueue east interface downlink pkts for user level packet copying */ enqueue_li_pkts(n, pkts, pdr, EAST_INTFC, DOWNLINK_DIRECTION, &fwd_pkts_mask, FWD_MASK); /* Update nexthop L3 header*/ update_enb_info(pkts, n, pkts_mask, &fwd_pkts_mask, &sess_data[0], &pdr[0]); } if (encap_pkts_mask) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"EB: ENCAP Recvd pkts\n", LOG_VALUE); /* PGWU/SAEGWU: Filter Downlink traffic. Apply sdf*/ filter_dl_traffic(p, pkts, n, wk_index, pkts_mask, &encap_pkts_mask, &sess_data[0], &pdr[0]); /* enqueue east interface downlink pkts for user level packet copying */ enqueue_li_pkts(n, pkts, pdr, EAST_INTFC, DOWNLINK_DIRECTION, &encap_pkts_mask, ENCAP_MASK); /* Encap GTPU header*/ gtpu_encap(&pdr[0], &sess_data[0], pkts, n, pkts_mask, &encap_pkts_mask, &pkts_queue_mask); } /* En-queue DL pkts */ if (pkts_queue_mask) { rte_pipeline_ah_packet_hijack(p, pkts_queue_mask); /* TODO: Support for DDN in IPv6*/ enqueue_dl_pkts(&pdr[0], &sess_data[0], pkts, pkts_queue_mask); } /* Next port is UL for SPGW*/ /* Update nexthop L2 header*/ update_nexthop_info(pkts, n, pkts_mask, app.wb_port, &pdr[0], NOT_PRESENT); /* Send Session Usage Report */ update_usage(pkts, n, pkts_mask, pdr, DOWNLINK); /* up pcap dumper */ up_core_pcap_dumper(pcap_dumper_east, pkts, n, pkts_mask); } if (fwd_pkts_mask) { /* enqueue west interface downlink pkts for user level packet copying */ enqueue_li_pkts(n, pkts, pdr, WEST_INTFC, DOWNLINK_DIRECTION, &fwd_pkts_mask, FWD_MASK); } if (encap_pkts_mask) { /* enqueue west interface downlink pkts for user level packet copying */ enqueue_li_pkts(n, pkts, pdr, WEST_INTFC, DOWNLINK_DIRECTION, &encap_pkts_mask, ENCAP_MASK); } /* Send the Error indication to peer node */ if (snd_err_pkts_mask && error_indication_snd) { enqueue_pkts_snd_err_ind(pkts, n, app.eb_port, &snd_err_pkts_mask); } /* Intimate the packets to be dropped*/ rte_pipeline_ah_packet_drop(p, ~(*pkts_mask)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Out EB_Pkt_Handler\n", LOG_VALUE); return 0; }
nikhilc149/e-utran-features-bug-fixes
dp/gtpu.h
<gh_stars>0 /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _GTPU_H_ #define _GTPU_H_ /** * @file * This file contains macros, data structure definitions and function * prototypes of GTPU header parsing and constructor. */ #include "util.h" #define GTPU_VERSION 0x01 #define GTP_PROTOCOL_TYPE_GTP 0x01 #define GTP_FLAG_EXTHDR 0x04 #define GTP_FLAG_SEQNB 0x02 #define GTP_FLAG_NPDU 0x01 /* GTPU_STATIC_SEQNB 0x00001122::On Wire 22 11 00 00 * Last two SEQNB bytes should be 00 00 * */ #define GTPU_STATIC_SEQNB (uint32_t)0x00000000 #define GPDU_HDR_SIZE_WITHOUT_SEQNB 8 #define GPDU_HDR_SIZE_WITH_SEQNB 12 #define GPDU_HDR_SIZE_DYNAMIC(flags) ((uint32_t)(GPDU_HDR_SIZE_WITHOUT_SEQNB + ((flags) & GTP_FLAG_SEQNB ? sizeof(GTPU_STATIC_SEQNB) : 0))) #define GTP_GPDU 0xff #define GTP_GEMR 0xfe /* GTPU-Echo defines*/ #define GTPU_ECHO_RECOVERY (14) #define GTPU_ECHO_REQUEST (0x01) #define GTPU_ECHO_RESPONSE (0x02) #define GTPU_END_MARKER_REQUEST (254) /* GTPU- TEID DATA Identifier */ #define GTPU_TEID_DATA_TYPE (16) /* GTPU-Error Indication Defines */ #define GTPU_ERROR_INDICATION (0x1a) /* 26 */ #define GTPU_PEER_ADDRESS (133) /* VS: Defined the GTPU, UDP, ETHER, and IPv4 header size micro */ #define GTPU_HDR_SIZE (8) #define GTPU_HDR_LEN 8 #define IPV4_HDR_LEN 20 #define ETH_HDR_LEN 14 #define UDP_HDR_LEN 8 #define UDP_PORT_GTPU_NW_ORDER 26632 /* GTP UDP port(2152) in NW order */ #pragma pack(1) /** * @brief : Maintains data of Gpdu header structure . */ struct gtpu_hdr { uint8_t pdn:1; /**< n-pdn number present ? */ uint8_t seq:1; /**< sequence no. */ uint8_t ex:1; /**< next extersion hdr present? */ uint8_t spare:1; /**< reserved */ uint8_t pt:1; /**< protocol type */ uint8_t version:3; /**< version */ uint8_t msgtype; /**< message type */ uint16_t msglen; /**< message length */ uint32_t teid; /**< tunnel endpoint id */ uint16_t seqnb; /**< sequence number */ }; #pragma pack() /** * @brief : Maintains data of gtpu header */ typedef struct gtpuHdr_s { uint8_t version_flags; uint8_t msg_type; uint16_t tot_len; uint32_t teid; uint16_t seq_no; /**< Optional fields if E, S or PN flags set */ } __attribute__((__packed__)) gtpuHdr_t; struct teid_data_identifier { uint8_t type; uint32_t teid_data_identifier; }__attribute__((__packed__)); /** * @brief : Maintains GTPU-Error Indication Information Element */ typedef struct gtpu_peer_address_ie_t { uint8_t type; uint16_t length; union { uint32_t ipv4_addr; uint8_t ipv6_addr[IPV6_ADDR_LEN]; }addr; } __attribute__((__packed__)) gtpu_peer_address_ie; /** * @brief : Maintains GTPU-Recovery Information Element */ typedef struct gtpu_recovery_ie_t { uint8_t type; uint8_t restart_cntr; } gtpu_recovery_ie; /** * @brief : Function to return pointer to gtpu headers. * @param : m, mbuf pointer * @return : pointer to udp headers */ static inline struct gtpu_hdr *get_mtogtpu(struct rte_mbuf *m) { return (struct gtpu_hdr *)(rte_pktmbuf_mtod(m, unsigned char *) + ETH_HDR_SIZE + IPv4_HDR_SIZE + UDP_HDR_SIZE); } /** * @brief : Function to return pointer to gtpu headers. * @param : m, mbuf pointer * @return : pointer to udp headers */ static inline struct gtpu_hdr *get_mtogtpu_v6(struct rte_mbuf *m) { return (struct gtpu_hdr *)(rte_pktmbuf_mtod(m, unsigned char *) + ETH_HDR_SIZE + IPv6_HDR_SIZE + UDP_HDR_SIZE); } /** * @brief : Function for decapsulation of gtpu headers. * @param : m, mbuf pointer * @param : ip_type, IPv4 or IPv6 header type * @return : Returns 0 in case of success , -1 otherwise */ extern int (*fp_decap_gtpu_hdr)(struct rte_mbuf *m, uint8_t ip_type); /** * @brief : Function for decapsulation of gtpu headers with dynamic sequence number * @param : m, mbuf pointer * @param : ip_type, IPv4 or IPv6 header type * @return : Returns 0 in case of success , -1 otherwise */ int decap_gtpu_hdr_dynamic_seqnb(struct rte_mbuf *m, uint8_t ip_type); /** * @brief : Function for decapsulation of gtpu headers with sequence number * @param : m, mbuf pointer * @param : ip_type, IPv4 or IPv6 header type * @return : Returns 0 in case of success , -1 otherwise */ int decap_gtpu_hdr_with_seqnb(struct rte_mbuf *m, uint8_t ip_type); /** * @brief : Function for decapsulation of gtpu headers without sequence number * @param : m, mbuf pointer * @param : ip_type, IPv4 or IPv6 header type * @return : Returns 0 in case of success , -1 otherwise */ int decap_gtpu_hdr_without_seqnb(struct rte_mbuf *m, uint8_t ip_type); #define DECAP_GTPU_HDR(a, b) (*fp_decap_gtpu_hdr)(a, b) /** * @brief : Function for encapsulation of gtpu headers * @param : m, mbuf pointer * @param : teid, tunnel endpoint id to be set in gtpu header * @param : ip_type, IPv4 or IPv6 header type * @return : Returns 0 in case of success , -1 otherwise */ extern int (*fp_encap_gtpu_hdr)(struct rte_mbuf *m, uint32_t teid, uint8_t ip_type); /** * @brief : Function for encapsulation of gtpu headers with sequence number * @param : m, mbuf pointer * @param : teid, tunnel endpoint id to be set in gtpu header * @param : ip_type, IPv4 or IPv6 header type * @return : Returns 0 in case of success , -1 otherwise */ int encap_gtpu_hdr_with_seqnb(struct rte_mbuf *m, uint32_t teid, uint8_t ip_type); /** * @brief : Function for encapsulation of gtpu headers without sequence number * @param : m, mbuf pointer * @param : teid, tunnel endpoint id to be set in gtpu header * @param : ip_type, IPv4 or IPv6 header type * @return : Returns 0 in case of success , -1 otherwise */ int encap_gtpu_hdr_without_seqnb(struct rte_mbuf *m, uint32_t teid, uint8_t ip_type); #define ENCAP_GTPU_HDR(a,b,c) (*fp_encap_gtpu_hdr)(a,b,c) /** * @brief : Function to get inner dst ip of tunneled packet. * @param : m, mbuf of the incoming packet. * @return : Returns inner dst ip */ extern uint32_t (*fp_gtpu_inner_src_ip)(struct rte_mbuf *m); /** * @brief : Function to get inner dst ip of tunneled packet with dynamic sequence number * @param : m, mbuf of the incoming packet. * @return : Returns inner dst ip */ uint32_t gtpu_inner_src_ip_dynamic_seqnb(struct rte_mbuf *m); /** * @brief : Function to get inner dst ip of tunneled packet with sequence number * @param : m, mbuf of the incoming packet. * @return : Returns inner dst ip */ uint32_t gtpu_inner_src_ip_with_seqnb(struct rte_mbuf *m); /** * @brief : Function to get inner dst ip of tunneled packet without sequence number * @param : m, mbuf of the incoming packet. * @return : Returns inner dst ip */ uint32_t gtpu_inner_src_ip_without_seqnb(struct rte_mbuf *m); #define GTPU_INNER_SRC_IP(a) (*fp_gtpu_inner_src_ip)(a) /** * @brief : Function to get inner dst ipv6 of tunneled packet. * @param : m, mbuf of the incoming packet. * @return : Returns inner dst ipv6 */ extern struct in6_addr (*fp_gtpu_inner_src_ipv6)(struct rte_mbuf *m); /** * @brief : Function to get inner dst ipv6 of tunneled packet with dynamic sequence number * @param : m, mbuf of the incoming packet. * @return : Returns inner dst ipv6 */ struct in6_addr gtpu_inner_src_ipv6_dynamic_seqnb(struct rte_mbuf *m); /** * @brief : Function to get inner dst ipv6 of tunneled packet with sequence number * @param : m, mbuf of the incoming packet. * @return : Returns inner dst ipv6 */ struct in6_addr gtpu_inner_src_ipv6_with_seqnb(struct rte_mbuf *m); /** * @brief : Function to get inner dst ipv6 of tunneled packet without sequence number * @param : m, mbuf of the incoming packet. * @return : Returns inner dst ipv6 */ struct in6_addr gtpu_inner_src_ipv6_without_seqnb(struct rte_mbuf *m); #define GTPU_INNER_SRC_IPV6(a) (*fp_gtpu_inner_src_ipv6)(a) /** * @brief : Function to get inner src and dst ip of tunneled packet. * @param : m, mbuf of the incoming packet. * @param : src_ip, source ip. * @param : dst_ip, destination ip. * @return : Retruns inner dst ip */ extern void (*fp_gtpu_get_inner_src_dst_ip)(struct rte_mbuf *m, uint32_t *src_ip, uint32_t *dst_ip); /** * @brief : Function to get inner src and dst ip of tunneled packet with sequence number * @param : m, mbuf of the incoming packet. * @param : src_ip, source ip. * @param : dst_ip, destination ip. * @return : Retruns inner dst ip */ void gtpu_get_inner_src_dst_ip_dynamic_seqnb(struct rte_mbuf *m, uint32_t *src_ip, uint32_t *dst_ip); /** * @brief : Function to get inner src and dst ip of tunneled packet with sequence number * @param : m, mbuf of the incoming packet. * @param : src_ip, source ip. * @param : dst_ip, destination ip. * @return : Retruns inner dst ip */ void gtpu_get_inner_src_dst_ip_with_seqnb(struct rte_mbuf *m, uint32_t *src_ip, uint32_t *dst_ip); /** * @brief : Function to get inner src and dst ip of tunneled packet without sequence number * @param : m, mbuf of the incoming packet. * @param : src_ip, source ip. * @param : dst_ip, destination ip. * @return : Retruns inner dst ip */ void gtpu_get_inner_src_dst_ip_without_seqnb(struct rte_mbuf *m, uint32_t *src_ip, uint32_t *dst_ip); #define GTPU_GET_INNER_SRC_DST_IP(a,b,c) (*fp_gtpu_get_inner_src_dst)(a,b,c) /** * @brief : Function to process GTPU Echo request * @param : echo_pkt, mbuf of the incoming packet. * @param : IP TYPE * @return : Returns nothing */ void process_echo_request(struct rte_mbuf *echo_pkt, uint8_t port_id, uint8_t ip_type); /** * @brief : Function to process Router Solicitation Request * @param : pkt, mbuf of the incoming packet. * #param : teid * @return : Returns nothing */ void process_router_solicitation_request(struct rte_mbuf *pkt, uint32_t teid); #endif /* _GTPU_H_ */
nikhilc149/e-utran-features-bug-fixes
ulpc/legacy_df_interface/include/LegacyClient.h
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ #ifndef _LEGACY_CLIENT_H_ #define _LEGACY_CLIENT_H_ #include <stdint.h> #include <iostream> #define TCP_COMM_MEDIUM "TCP" class LegacyClient { public: /* * @brief : Constructor of class LegacyClient */ LegacyClient() {}; /* * @brief : Destructor of class LegacyClient */ virtual ~LegacyClient() {}; /* * @brief : Virtual function to initialise legacy interface * @param : No arguments * @return : Returns int8_t */ virtual int8_t InitializeLegacyClient() = 0; /* * @brief : Virtual function to connect with legacy DF * @param : strRemoteIp, legacy DF IP * @param : uiRemotePort, legacy DF port * @return : Returns int8_t */ virtual int8_t ConnectToLegacy(const std::string& strRemoteIp, uint16_t uiRemotePort) = 0; /* * @brief : Virtual function to send information/packet to legacy DF * @param : pkt, packet to be sent * @param : packetLen, size of packet * @return : Returns int8_t */ virtual int8_t SendMessageToLegacy(uint8_t *pkt, uint32_t packetLen) = 0; /* * @brief : Virtual function to disconnect from legacy DF * @param : No arguments * @return : Returns int8_t */ virtual int8_t DisconnectToLegacy() = 0; /* * @brief : Virtual function to de-initialise legacy DF * @param : No arguments * @return : Return int8_t */ virtual int8_t DeinitializeLegacyClient() = 0; /* * @brief : Function to create legacy client object * @param : strConfig, type of connection * @return : Returns static LegacyClient pointer */ static LegacyClient *CreateLegacyClientObj(const std::string& strConfig); }; #endif /* _LEGACY_CLIENT_H_ */
nikhilc149/e-utran-features-bug-fixes
oss_adapter/libepcadapter/include/tcp_listener.h
/* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ #ifndef __TCPLISTENER_H_ #define __TCPLISTENER_H_ #include "common.h" #include "tcp_forwardinterface.h" class DdfListener; class TCPForwardInterface; class TCPListener : public ESocket::ThreadPrivate { public: /* * @brief : Constructor of class TCPListener */ TCPListener(); /* * @brief : Constructor of class TCPListener */ ~TCPListener(); /* * @brief : Library function of EPCTool */ Void onInit(); /* * @brief : Library function of EPCTool */ Void onQuit(); /* * @brief : Library function of EPCTool */ Void onClose(); /* * @brief : Function connects to the DF * @param : No function arguments * @return : Returns void */ Void connect(); /* * @brief : Library function of EPCTool */ Void onTimer(EThreadEventTimer *ptimer); /* * @brief : Functionto indicate socket exception * @param : err, error type * @param : psocket, socket * @return : Returns void */ Void errorHandler(EError &err, ESocket::BasePrivate *psocket); Void initDir(const uint8_t *ddf_ip, uint16_t port, const uint8_t *ddf_local_ip, uint8_t *mode); /* * @brief : Function to free pcap dumper map * @param : No function arguments * @return : Returns void */ void freePcapDumper(); /* * @brief : Function sends packet to DF * @param : packet, packet/information to be sent * @return : Returns void */ Void sendPacketToDdf(DdfPacket_t *packet); /* * @brief : Function to delete instance of TCPDataProcessor * on socket close, also tries re-connect to DF * @param : psocket, socket * @return : Returns void */ Void onSocketClosed(ESocket::BasePrivate *psocket); /* * @brief : Function to delete instance of TCPDataProcessor * on socket close, also tries re-connect to DF * @param : psocket, socket * @return : Returns void */ Void onSocketError(ESocket::BasePrivate *psocket); /* * @brief : Function to start timer * @param : No function arguments * @return : Returns void */ Void startDfRetryTimer(); /* * @brief : Function to stop timer * @param : No function arguments * @return : Returns void */ Void stopDfRetryTimer(); /* * @brief : Function to indicate data is pending to send to DF * @param : No function arguments * @return : Returns void */ Void setPending(); /* * @brief : Function sends pending data to DF * @param : No function arguments * @return : Returns void */ Void sendPending(); /* * @brief : Function receives ack from DF and moves ptr to next packet, * for which ack is expected * @param : ack_number, acknowledgement number * @return : Returns void */ Void msgCounter(uint32_t ack_number); /* * @brief : Function creates folder to save database file * @param : No function arguments * @return : Returns void */ Void createFolder(); /* * @brief : Function creates file to save packet * @param : No function arguments * @return : Returns void */ bool createFile(); /* * @brief : Function to open the file and set pointer to file, * to read from it * @param : No function arguments * @return : Returns void */ Void readFile(); /* * @brief : Function to delete database file * @param : No function arguments * @return : Returns void */ Void deleteFile(); /* * @brief : Function to check space availability * @param : No function arguments * @return : Returns void */ bool checkAvailableSapce(); /* * @brief : Function to check DF socket, get called from TCPForwardInterface * @param : No function arguments * @return : Returns void */ Void checkSocket(); /* * @brief : Const function to get max number of msg used in semaphore * @param : No function arguments * @return : Returns long */ Long getMaxMsgs() const { return m_maxMsgs; } /* * @brief : Function to set max number of msg used in semaphore * @param : maxMsgs, max count of msg * @return : Returns this pointer */ TCPListener &setMaxMsgs(Long maxMsgs) { m_maxMsgs = maxMsgs; return *this; } private: Long m_maxMsgs; DdfListener *m_ptrListener = NULL; EThreadEventTimer m_dfRetryTimer; TCPForwardInterface *m_ptrForwardInterface = NULL; ESemaphorePrivate msg_cnt; #define IP_ADDR_LEN_DDF 40 uint8_t ipDdfAddr[IP_ADDR_LEN_DDF] = {'\0'}; uint8_t ipDdfLocalAddr[IP_ADDR_LEN_DDF] = {'\0'}; uint8_t *modeType = NULL; uint16_t portAddr = 0; std::ofstream fileWrite; /* file handler to write into file */ std::ifstream fileRead; /* file handler to read from file */ uint8_t writeBuf[SEND_BUF_SIZE]; /* buffer to write in file */ uint8_t readBuf[SEND_BUF_SIZE]; /* buffer to read from file */ uint8_t payloadBuf[SEND_BUF_SIZE]; /* buffer to read payload */ std::vector<std::string> fileVect; /* Vector to store file names */ std::vector<std::string>::iterator vecIter; /* Iterator for vector */ uint16_t read_count = 0; /* Numb of packets read from file */ uint16_t entry_cnt = 0; /* Numb of packets write into the file */ uint16_t pkt_cnt = 0; /* Actual number of packets sent vs written into the file */ bool timer_flag = 0; /* flag to use same timer for re-connecting as \ well as to re-sending failed packets*/ bool serveNextFile = 0; bool pending_data_flag = 0; /* Flag to indicate there is backlog to be send to DF */ uint32_t read_bytes_track = 0; /* varible to track number of bytes read from the file */ uint32_t send_bytes_track = 0; /* variable to track numb of bytes read from backlog to be sent to DF*/ std::string file_name; /* Name of the current file in which packets ar being written/read from */ }; #endif /* __TCPLISTENER_H_ */
nikhilc149/e-utran-features-bug-fixes
cp/main.h
<gh_stars>0 /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _MAIN_H_ #define _MAIN_H_ #include <rte_ether.h> #include <rte_ethdev.h> #include <rte_hash.h> #include <rte_malloc.h> #include <rte_meter.h> #include <rte_jhash.h> #include <rte_version.h> //#include "vepc_cp_dp_api.h" //#include "dp_ipc_api.h" #ifdef USE_REST #include "ngic_timer.h" #endif /* use_rest */ #include "pfcp_struct.h" /** * dataplane rte logs. */ #define RTE_LOGTYPE_DP RTE_LOGTYPE_USER1 /** * CP DP communication API rte logs. */ #define RTE_LOGTYPE_API RTE_LOGTYPE_USER2 /** * CP DP communication API rte logs. */ #define RTE_LOGTYPE_API RTE_LOGTYPE_USER2 /** * rte notification log level. */ #define NOTICE 0 /** * rte information log level. */ #define NGIC_INFO 1 /** * rte debug log level. */ #define NGIC_DEBUG 2 #define LOG_LEVEL_SET (0x0001) #define REQ_ARGS (LOG_LEVEL_SET) #ifndef PERF_TEST /** Temp. work around for support debug log level into DP, DPDK version 16.11.4 */ #if (RTE_VER_YEAR >= 16) && (RTE_VER_MONTH >= 11) #undef RTE_LOG_LEVEL #define RTE_LOG_LEVEL RTE_LOG_DEBUG #define RTE_LOG_DP RTE_LOG #elif (RTE_VER_YEAR >= 18) && (RTE_VER_MONTH >= 02) #undef RTE_LOG_DP_LEVEL #define RTE_LOG_DP_LEVEL RTE_LOG_DEBUG #endif #else /* Work around for skip LOG statements at compile time in DP, DPDK 16.11.4 and 18.02 */ #if (RTE_VER_YEAR >= 16) && (RTE_VER_MONTH >= 11) #undef RTE_LOG_LEVEL #define RTE_LOG_LEVEL RTE_LOG_WARNING #define RTE_LOG_DP_LEVEL RTE_LOG_LEVEL #define RTE_LOG_DP RTE_LOG #elif (RTE_VER_YEAR >= 18) && (RTE_VER_MONTH >= 02) #undef RTE_LOG_DP_LEVEL #define RTE_LOG_DP_LEVEL RTE_LOG_WARNING #endif #endif /* PERF_TEST */ #define SDF_FILTER_TABLE "sdf_filter_table" #define ADC_TABLE "adc_rule_table" #define PCC_TABLE "pcc_table" #define SESSION_TABLE "session_table" #define METER_PROFILE_SDF_TABLE "meter_profile_sdf_table" #define METER_PROFILE_APN_TABLE "meter_profile_apn_table" #define SDF_FILTER_TABLE_SIZE (1024) #define ADC_TABLE_SIZE (1024) #define PCC_TABLE_SIZE (1025) #define METER_PROFILE_SDF_TABLE_SIZE (2048) #define DPN_ID (12345) /** * max length of name string. */ #define MAX_LEN 128 #define GX_SESS_ID_LEN 256 #ifdef USE_REST /* VS: Number of connection can maitain in the hash */ #define NUM_CONN 500 /** * max li supported limit */ #define LI_MAX_SIZE 1024 /** * no. of mbuf. */ #define NB_ECHO_MBUF 1024 #ifdef USE_CSID /* Configure the local csid */ extern uint16_t local_csid; #endif /* USE_CSID */ struct rte_mempool *echo_mpool; extern int32_t conn_cnt; /** * @brief : Initiatizes echo table and starts the timer thread * @param : No param * @return : Returns nothing */ void rest_thread_init(void); /** * @brief : Adds node connection entry * @param : dstIp, node ip address * @param : portId, port number of node * @return : cp_mode,[SGWC/PGWC/SAEGWC] * @return : Returns nothing */ uint8_t add_node_conn_entry(node_address_t *dstIp, uint8_t portId, uint8_t cp_mode); /** * @brief : Updates restart counter Value * @param : No param * @return : Returns nothing */ uint8_t update_rstCnt(void); #endif /* USE_REST */ #ifdef USE_REST /** * @brief : Function to initialize/create shared ring, ring_container and mem_pool to * inter-communication between DL and iface core. * @param : No param * @return : Returns nothing */ void echo_table_init(void); #endif /* USE_REST */ #endif /* _MAIN_H_ */
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c_echo_req.c
<filename>cp/gtpv2c_echo_req.c /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ipv4.h" #include "gtpv2c.h" #include "util.h" #include "gtp_messages.h" #include "gtpv2c_set_ie.h" #define GTPU_HDR_LEN 8 #define IPV4_HDR_LEN 20 #define ETH_HDR_LEN 14 #define UDP_HDR_LEN 8 #define IP_PROTO_UDP 17 #define UDP_PORT_GTPU 2152 #define GTPU_OFFSET 50 #define GTPu_VERSION 0x20 #define GTPu_PT_FLAG 0x10 #define GTPu_E_FLAG 0x04 #define GTPu_S_FLAG 0x02 #define GTPu_PN_FLAG 0x01 #define PKT_SIZE 54 #define CONN_ENTRIY_FILE "../config/static_arp.cfg" /** * @brief : Maintains gtpu header info */ typedef struct gtpuHdr_s { uint8_t version_flags; uint8_t msg_type; uint16_t tot_len; uint32_t teid; uint16_t seq_no; /**< Optional fields if E, S or PN flags set */ } __attribute__((__packed__)) gtpuHdr_t; /** * @brief : Maintains GTPU-Recovery Information Element */ typedef struct gtpu_recovery_ie_t { uint8_t type; uint8_t restart_cntr; } gtpu_recovery_ie; /** * @brief : Set values in recovery ie * @param : recovery, ie structure to be filled * @param : type, ie type * @param : length, total length * @param : instance, instance value * @return : Returns nothing */ static void set_recovery_ie_t(gtp_recovery_ie_t *recovery, uint8_t type, uint16_t length, uint8_t instance) { recovery->header.type = type; recovery->header.len = length; recovery->header.instance = instance; recovery->recovery = rstCnt; } /** * @brief : Set values in node features ie * @param : node_feature, structure to be filled * @param : type, ie type * @param : length, total length * @param : instance, instance value * @return : Returns nothing */ void set_node_feature_ie(gtp_node_features_ie_t *node_feature, uint8_t type, uint16_t length, uint8_t instance, uint8_t sup_feature) { node_feature->header.type = type; node_feature->header.len = length; node_feature->header.instance = instance; node_feature->sup_feat = sup_feature; } /** * @brief : Function to build GTP-U echo request * @param : echo_pkt rte_mbuf pointer * @param : gtpu_seqnb, sequence number * @return : void */ void build_gtpv2_echo_request(gtpv2c_header_t *echo_pkt, uint16_t gtpu_seqnb, uint8_t iface) { if (echo_pkt == NULL) return; echo_request_t echo_req = {0}; set_gtpv2c_header((gtpv2c_header_t *)&echo_req.header, 0, GTP_ECHO_REQ, 0, gtpu_seqnb, 0); set_recovery_ie_t((gtp_recovery_ie_t *)&echo_req.recovery, GTP_IE_RECOVERY, sizeof(uint8_t), IE_INSTANCE_ZERO); if(iface == S11_SGW_PORT_ID) { set_node_feature_ie((gtp_node_features_ie_t *)&echo_req.sending_node_feat, GTP_IE_NODE_FEATURES, sizeof(uint8_t), IE_INSTANCE_ZERO, PRN); } encode_echo_request(&echo_req, (uint8_t *)echo_pkt); }
nikhilc149/e-utran-features-bug-fixes
cp_dp_api/vepc_cp_dp_api.c
/* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http: *www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdint.h> #include <arpa/inet.h> #include <stdio.h> #include <time.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <rte_common.h> #include <rte_eal.h> #include <rte_log.h> #include <rte_malloc.h> #include <rte_jhash.h> #include <rte_cfgfile.h> #include <rte_byteorder.h> #include "util.h" #include "pfcp_util.h" #include "interface.h" #include "pfcp_set_ie.h" #include "vepc_cp_dp_api.h" #include "pfcp_messages_encoder.h" #ifdef CP_BUILD #include "cp.h" #include "main.h" #include "cp_stats.h" #include "cp_config.h" #include "sm_struct.h" //TODO:Remove it #include "cdr.h" #endif /* CP_BUILD */ extern uint32_t li_seq_no; extern int clSystemLog; /******************** IPC msgs **********************/ #ifdef CP_BUILD extern int pfcp_fd; extern int pfcp_fd_v6; extern peer_addr_t upf_pfcp_sockaddr; /** * @brief : Pack the message which has to be sent to DataPlane. * @param : mtype * mtype - Message type. * @param : dp_id * dp_id - identifier which is unique across DataPlanes. * @param : param * param - parameter to be parsed based on msg type. * @param : msg_payload * msg_payload - message payload to be sent. * @return : Returns 0 in case of success , -1 otherwise */ static int build_dp_msg(enum dp_msg_type mtype, struct dp_id dp_id, void *param, struct msgbuf *msg_payload) { msg_payload->mtype = mtype; msg_payload->dp_id = dp_id; switch (mtype) { case MSG_SDF_CRE: case MSG_ADC_TBL_CRE: case MSG_PCC_TBL_CRE: case MSG_SESS_TBL_CRE: case MSG_MTR_CRE: msg_payload->msg_union.msg_table.max_elements = *(uint32_t *)param; break; case MSG_EXP_CDR: msg_payload->msg_union.ue_cdr = *(struct msg_ue_cdr *)param; break; case MSG_SDF_DES: case MSG_ADC_TBL_DES: case MSG_PCC_TBL_DES: case MSG_SESS_TBL_DES: case MSG_MTR_DES: break; case MSG_SDF_ADD: case MSG_SDF_DEL: msg_payload->msg_union.pkt_filter_entry = *(struct pkt_filter *)param; break; case MSG_ADC_TBL_ADD: case MSG_ADC_TBL_DEL: msg_payload->msg_union.adc_filter_entry = *(struct adc_rules *)param; break; case MSG_PCC_TBL_ADD: case MSG_PCC_TBL_DEL: msg_payload->msg_union.pcc_entry = *(struct pcc_rules *)param; break; case MSG_SESS_CRE: case MSG_SESS_MOD: case MSG_SESS_DEL: msg_payload->msg_union.sess_entry = *(struct session_info *)param; break; case MSG_MTR_ADD: case MSG_MTR_DEL: msg_payload->msg_union.mtr_entry = *(struct mtr_entry *)param; break; case MSG_DDN_ACK: msg_payload->msg_union.dl_ddn = *(struct downlink_data_notification *)param; break; default: clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"build_dp_msg: " "Invalid msg type\n", LOG_VALUE); return -1; } return 0; } /** * @brief : Send message to DP. * @param : dp_id * dp_id - identifier which is unique across DataPlanes. * @param : msg_payload * msg_payload - message payload to be sent. * @return : Returns 0 in case of success , -1 otherwise */ static int send_dp_msg(struct dp_id dp_id, struct msgbuf *msg_payload) { RTE_SET_USED(dp_id); pfcp_pfd_mgmt_req_t pfd_mgmt_req; memset(&pfd_mgmt_req, 0, sizeof(pfcp_pfd_mgmt_req_t)); /* Fill pfd contents costum ie as rule string */ set_pfd_contents(&pfd_mgmt_req.app_ids_pfds[0].pfd_context[0].pfd_contents[0], msg_payload); /*Fill pfd request */ fill_pfcp_pfd_mgmt_req(&pfd_mgmt_req, 0); uint8_t pfd_msg[PFCP_MSG_LEN]={0}; uint16_t pfd_msg_len=encode_pfcp_pfd_mgmt_req_t(&pfd_mgmt_req, pfd_msg); if (pfcp_send(pfcp_fd, pfcp_fd_v6, (char *)pfd_msg, pfd_msg_len, upf_pfcp_sockaddr,SENT) < 0 ){ clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Error sending PFCP " "PFD Management Request %i\n",errno); free(pfd_mgmt_req.app_ids_pfds[0].pfd_context[0].pfd_contents[0].cstm_pfd_cntnt); return -1; } free(pfd_mgmt_req.app_ids_pfds[0].pfd_context[0].pfd_contents[0].cstm_pfd_cntnt); return 0; } //#endif /* CP_BUILD*/ /******************** SDF Pkt filter **********************/ int sdf_filter_table_create(struct dp_id dp_id, uint32_t max_elements) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_SDF_CRE, dp_id, (void *)&max_elements, &msg_payload); return send_dp_msg(dp_id, &msg_payload); #else return dp_sdf_filter_table_create(dp_id, max_elements); #endif } int sdf_filter_entry_add(struct dp_id dp_id, struct pkt_filter pkt_filter_entry) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_SDF_ADD, dp_id, (void *)&pkt_filter_entry, &msg_payload); return send_dp_msg(dp_id, &msg_payload); #else return dp_sdf_filter_entry_add(dp_id, &pkt_filter_entry); #endif } /******************** ADC Rule Table **********************/ int adc_table_create(struct dp_id dp_id, uint32_t max_elements) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_ADC_TBL_CRE, dp_id, (void *)&max_elements, &msg_payload); return send_dp_msg(dp_id, &msg_payload); #else return dp_adc_table_create(dp_id, max_elements); #endif } int adc_table_delete(struct dp_id dp_id) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_ADC_TBL_DES, dp_id, (void *)NULL, &msg_payload); return send_dp_msg(dp_id, &msg_payload); #else return dp_adc_table_delete(dp_id); #endif } int adc_entry_add(struct dp_id dp_id, struct adc_rules entry) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_ADC_TBL_ADD, dp_id, (void *)&entry, &msg_payload); return send_dp_msg(dp_id, &msg_payload); #else return dp_adc_entry_add(dp_id, &entry); #endif } int adc_entry_delete(struct dp_id dp_id, struct adc_rules entry) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_ADC_TBL_DEL, dp_id, (void *)&entry, &msg_payload); return send_dp_msg(dp_id, &msg_payload); #else return dp_adc_entry_delete(dp_id, &entry); #endif } /******************** PCC Rule Table **********************/ int pcc_table_create(struct dp_id dp_id, uint32_t max_elements) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_PCC_TBL_CRE, dp_id, (void *)&max_elements, &msg_payload); return send_dp_msg(dp_id, &msg_payload); #else return dp_pcc_table_create(dp_id, max_elements); #endif } int pcc_entry_add(struct dp_id dp_id, struct pcc_rules entry) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_PCC_TBL_ADD, dp_id, (void *)&entry, &msg_payload); return send_dp_msg(dp_id, &msg_payload); #else return dp_pcc_entry_add(dp_id, &entry); #endif } /******************** Bearer Session Table **********************/ int session_table_create(struct dp_id dp_id, uint32_t max_elements) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_SESS_TBL_CRE, dp_id, (void *)&max_elements, &msg_payload); return send_dp_msg(dp_id, &msg_payload); #else return dp_session_table_create(dp_id, max_elements); #endif } int session_create(struct dp_id dp_id, struct session_info entry) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_SESS_CRE, dp_id, (void *)&entry, &msg_payload); #ifdef SYNC_STATS struct sync_stats info = {0}; info.op_id = (op_id-1); info.type = 1; info.session_id = entry.sess_id; add_stats_entry(&info); #endif /* SYNC_STATS */ return send_dp_msg(dp_id, &msg_payload); #else return dp_session_create(dp_id, &entry); #endif /* CP_BUILD */ } int session_modify(struct dp_id dp_id, struct session_info entry) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_SESS_MOD, dp_id, (void *)&entry, &msg_payload); #ifdef SYNC_STATS struct sync_stats info = {0}; info.op_id = (op_id-1); info.type = 2; info.session_id = entry.sess_id; add_stats_entry(&info); #endif /* SYNC_STATS */ return send_dp_msg(dp_id, &msg_payload); #else return dp_session_modify(dp_id, &entry); #endif /* CP_BUILD */ } int session_delete(struct dp_id dp_id, struct session_info entry) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_SESS_DEL, dp_id, (void *)&entry, &msg_payload); #ifdef SYNC_STATS struct sync_stats info = {0}; info.op_id = (op_id-1); info.type = 3; info.session_id = entry.sess_id; add_stats_entry(&info); #endif /* SYNC_STATS */ return send_dp_msg(dp_id, &msg_payload); #else return dp_session_delete(dp_id, &entry); #endif /* CP_BUILD */ } /******************** Meter Table **********************/ int meter_profile_table_create(struct dp_id dp_id, uint32_t max_elements) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_MTR_CRE, dp_id, (void *)&max_elements, &msg_payload); return send_dp_msg(dp_id, &msg_payload); #else return dp_meter_profile_table_create(dp_id, max_elements); #endif } int meter_profile_entry_add(struct dp_id dp_id, struct mtr_entry entry) { #ifdef CP_BUILD struct msgbuf msg_payload; build_dp_msg(MSG_MTR_ADD, dp_id, (void *)&entry, &msg_payload); return send_dp_msg(dp_id, &msg_payload); #else return dp_meter_profile_entry_add(dp_id, &entry); #endif } #endif /* CP_BUILD*/ int encode_li_header(li_header_t *header, uint8_t *buf) { int encoded = 0; uint32_t tmp = 0; uint16_t tmpport = 0; uint64_t tmpid = 0; tmp = htonl(header->packet_len); memcpy(buf + encoded, &tmp, sizeof(uint32_t)); encoded += sizeof(uint32_t); memcpy(buf + encoded, &(header->type_of_payload), 1); encoded += 1; tmpid = header->id; memcpy(buf + encoded, &tmpid, sizeof(uint64_t)); encoded += sizeof(uint64_t); tmpid = header->imsi; memcpy(buf + encoded, &tmpid, sizeof(uint64_t)); encoded += sizeof(uint64_t); memcpy(buf + encoded, &(header->src_ip_type), 1); encoded += 1; tmp = htonl(header->src_ipv4); memcpy(buf + encoded, &tmp, sizeof(uint32_t)); encoded += sizeof(uint32_t); memcpy(buf + encoded, &(header->src_ipv6), IPV6_ADDRESS_LEN); encoded += IPV6_ADDRESS_LEN; tmpport = htons(header->src_port); memcpy(buf + encoded, &tmpport, sizeof(uint16_t)); encoded += sizeof(uint16_t); memcpy(buf + encoded, &(header->dst_ip_type), 1); encoded += 1; tmp = htonl(header->dst_ipv4); memcpy(buf + encoded, &tmp, sizeof(uint32_t)); encoded += sizeof(uint32_t); memcpy(buf + encoded, &(header->dst_ipv6), IPV6_ADDRESS_LEN); encoded += IPV6_ADDRESS_LEN; tmpport = htons(header->dst_port); memcpy(buf + encoded, &tmpport, sizeof(uint16_t)); encoded += sizeof(uint16_t); memcpy(buf + encoded, &(header->operation_mode), sizeof(uint8_t)); encoded += sizeof(uint8_t); tmp = htonl(header->seq_no); memcpy(buf + encoded, &tmp, sizeof(uint32_t)); encoded += sizeof(uint32_t); tmp = htonl(header->len); memcpy(buf + encoded, &tmp, sizeof(uint32_t)); encoded += sizeof(uint32_t); return encoded; } int8_t create_li_header(uint8_t *uiPayload, int *iPayloadLen, uint8_t type, uint64_t uiId, uint64_t uiImsi, struct ip_addr srcIp, struct ip_addr dstIp, uint16_t uiSrcPort, uint16_t uiDstPort, uint8_t uiOprMode) { int iEncoded; li_header_t liHdr = {0}; uint8_t uiTmp[MAX_LI_HDR_SIZE] = {0}; for (int iCnt = 0; iCnt < *iPayloadLen; iCnt++) { uiTmp[iCnt] = uiPayload[iCnt]; } if (type != NOT_PRESENT) { liHdr.type_of_payload = PRESENT; } else { liHdr.type_of_payload = NOT_PRESENT; } liHdr.id = uiId; liHdr.imsi = uiImsi; liHdr.src_ip_type = srcIp.iptype; if (srcIp.iptype == IPTYPE_IPV4) { liHdr.src_ipv4 = srcIp.u.ipv4_addr; } else { /* IPTYPE_IPV6 */ memcpy(liHdr.src_ipv6, srcIp.u.ipv6_addr, IPV6_ADDRESS_LEN); } liHdr.packet_len += sizeof(liHdr.src_ipv4); liHdr.packet_len += IPV6_ADDRESS_LEN; liHdr.src_port = uiSrcPort; liHdr.dst_ip_type = dstIp.iptype; if (dstIp.iptype == IPTYPE_IPV4) { liHdr.dst_ipv4 = dstIp.u.ipv4_addr; } else { /* IPTYPE_IPV6 */ memcpy(liHdr.dst_ipv6, dstIp.u.ipv6_addr, IPV6_ADDRESS_LEN); } liHdr.packet_len += sizeof(liHdr.dst_ipv4); liHdr.packet_len += IPV6_ADDRESS_LEN; liHdr.dst_port = uiDstPort; liHdr.operation_mode = uiOprMode; liHdr.seq_no = li_seq_no++; liHdr.len = *iPayloadLen; liHdr.packet_len += sizeof(liHdr.packet_len) + sizeof(liHdr.type_of_payload) + sizeof(liHdr.len) + sizeof(liHdr.id) + sizeof(liHdr.imsi) + + sizeof(liHdr.src_ip_type) + sizeof(liHdr.dst_ip_type) + sizeof(liHdr.src_port) + sizeof(liHdr.dst_port) + sizeof(liHdr.operation_mode) + sizeof(liHdr.seq_no) +*iPayloadLen; iEncoded = encode_li_header(&liHdr, uiPayload); for (int iCnt = 0; iCnt < *iPayloadLen; iCnt++) { uiPayload[iEncoded++] = uiTmp[iCnt]; } *iPayloadLen = iEncoded; return 0; } inline struct ip_addr fill_ip_info(uint8_t ip_type, uint32_t ipv4, uint8_t *ipv6) { struct ip_addr node; if (ip_type == IPTYPE_IPV4_LI) { node.u.ipv4_addr = ipv4; node.iptype = IPTYPE_IPV4; } else { /* IPTYPE_IPV6 */ memcpy(node.u.ipv6_addr, ipv6, IPV6_ADDRESS_LEN); node.iptype = IPTYPE_IPV6; } return node; }
nikhilc149/e-utran-features-bug-fixes
oss_adapter/libepcadapter/include/cstats_dev.h
/* * Copyright (c) 2019 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __CSTATS_DEV_H #define __CSTATS_DEV_H using namespace std; enum cp_config { SGWC = 1, PGWC, SAEGWC }; class CStatMessages { string nodestr; bool suppress; public: CStatMessages(bool suppressed) { nodestr = "messages"; suppress = suppressed; } string getNodeName() { return nodestr; } void serialize(const SPeer* peer, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); void serializeS11(const SPeer* peer, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); void serializeS5S8(const SPeer* peer, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); void serializeSx(const SPeer* peer, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); void serializeGx(const SPeer* peer, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); void serializeSystem(const cli_node_t *cli_node, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); private: }; class CStatHealth { string nodestr; bool suppress; public: CStatHealth(bool suppressed) { nodestr = "health"; suppress = suppressed; } string getNodeName() { return nodestr; } void serialize(const SPeer* peer, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); private: }; class CStatPeers { string nodestr; bool suppress; public: CStatPeers(bool suppressed) { nodestr = "peers"; suppress = suppressed; } string getNodeName() { return nodestr; } void serialize(const SPeer* peer, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); private: }; class CStatInterfaces { string nodestr; CStatPeers peer; bool suppress; public: CStatInterfaces(bool suppressed) : peer(suppressed) { nodestr = "interfaces"; suppress = suppressed; } string getNodeName() { return nodestr; } void serialize(cli_node_t *cli_node, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); void serializeInterface(cli_node_t *cli_node, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator,EInterfaceType it); private: }; class CStatGateway { string nodestr; EString reportTimeStr; CStatInterfaces interfaces; bool suppress; public: CStatGateway(bool suppressed) : interfaces(suppressed) { nodestr = "gateway"; suppress = suppressed; } string getNodeName() { return nodestr; } void initInterfaceDirection(cp_config gatway); void serialize(cli_node_t *cli_node, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); private: }; class CStatSystem { string nodestr; bool suppress; public: CStatSystem(bool suppressed) { nodestr = "system"; suppress = suppressed; } string getNodeName() { return nodestr; } void serialize(cli_node_t *cli_node, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); private: }; class CStatSession { string nodestr; bool suppress; public: CStatSession(bool suppressed) { nodestr = "sessions"; suppress = suppressed; } string getNodeName() { return nodestr; } void serialize(cli_node_t *cli_node, statsrapidjson::Value& row, statsrapidjson::Value& arrayObjects, statsrapidjson::Document::AllocatorType& allocator); private: }; #endif /* __CSTATS_DEV_H */
nikhilc149/e-utran-features-bug-fixes
ulpc/legacy_admf_interface/include/LegacyAdmfInterface.h
/* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __LEGACY_ADMF_INTERFACE_H_ #define __LEGACY_ADMF_INTERFACE_H_ #include "BaseLegacyAdmfInterface.h" #include "LegacyAdmfInterfaceThread.h" #define IPV6_MAX_LEN 16 class LegacyAdmfInterface : public BaseLegacyAdmfInterface { private: static LegacyAdmfInterface *ladmfInstance; static int refCnt; LegacyAdmfInterfaceThread *legacyAdmfIntfcThread; static ELogger *logger; public: LegacyAdmfInterface(); ~LegacyAdmfInterface(); void ConfigureLogger(ELogger &log) { logger = &log; logger->debug("LegacyAdmfInterface ELogger has been initilized"); } void startup(void *conf); uint16_t sendMessageToLegacyAdmf(void *packet); int8_t sendAckToAdmf(admf_intfc_packet_t *packet); int8_t sendRequestToAdmf(uint16_t requestType, const char *requestBody); void shutdown(); static ELogger &log() { return *logger; } }; #endif /* __LEGACY_ADMF_INTERFACE_H_ */
nikhilc149/e-utran-features-bug-fixes
oss_adapter/libepcadapter/include/rest_apis.h
<gh_stars>0 #ifndef __NGIC_REST_APIS_H__ #define __NGIC_REST_APIS_H__ #include "emgmt.h" #define GET_STAT_URI "/statlive" #define GET_PERIODIC_TIMER_URI "/periodic_timer" #define GET_TRANSMIT_TIMER_URI "/transmit_timer" #define GET_TRANSMIT_COUNT_URI "/transmit_count" #define GET_REQUEST_TRIES_URI "/request_tries" #define GET_REQUEST_TIMEOUT_URI "/request_timeout" #define GET_STAT_LOGGING_URI "/statlogging" #define GET_PCAP_STATUS_URI "/generate_pcap" #define GET_STAT_ALL_URI "/statliveall" #define GET_PERF_FLAG_URI "/perf_flag" #define GET_RESET_STATS_URI "/reset_stats" #define GET_STAT_FREQUENCY_URI "/statfreq" #define GET_CONFIG_LIVE_URI "/configlive" #define POST_UE_DETAILS_URI "/addueentry" #define PUT_UE_DETAILS_URI "/updateueentry" #define DEL_UE_DETAILS_URI "/deleteueentry" #define RSP_LEN 4096 typedef int (*CRestCallback)(const char *requestBody, char **responseBody); class RestStateLiveGet : public EManagementHandler { private: CRestCallback m_cb; public: RestStateLiveGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestStateLiveGet() {} }; class RestPeriodicTimerGet : public EManagementHandler { private: CRestCallback m_cb; public: RestPeriodicTimerGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestPeriodicTimerGet() {} }; class RestTransmitTimerGet : public EManagementHandler { private: CRestCallback m_cb; public: RestTransmitTimerGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestTransmitTimerGet() {} }; class RestTransmitCountGet : public EManagementHandler { private: CRestCallback m_cb; public: RestTransmitCountGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestTransmitCountGet() {} }; class RestRequestTriesGet : public EManagementHandler { private: CRestCallback m_cb; public: RestRequestTriesGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestRequestTriesGet() {} }; class RestRequestTimeoutGet : public EManagementHandler { private: CRestCallback m_cb; public: RestRequestTimeoutGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestRequestTimeoutGet() {} }; class RestStatLoggingGet : public EManagementHandler { private: CRestCallback m_cb; public: RestStatLoggingGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestStatLoggingGet() {} }; class RestPcapStatusGet : public EManagementHandler { private: CRestCallback m_cb; public: RestPcapStatusGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestPcapStatusGet() {} }; class RestConfigurationGet : public EManagementHandler { private: CRestCallback m_cb; public: RestConfigurationGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestConfigurationGet() {} }; class RestStatLiveAllGet : public EManagementHandler { private: CRestCallback m_cb; public: RestStatLiveAllGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestStatLiveAllGet() {} }; class RestStatFrequencyGet : public EManagementHandler { private: CRestCallback m_cb; public: RestStatFrequencyGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestStatFrequencyGet() {} }; class RestPerfFlagGet : public EManagementHandler { private: CRestCallback m_cb; public: RestPerfFlagGet(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestPerfFlagGet() {} }; class RestPeriodicTimerPost : public EManagementHandler { private: CRestCallback m_cb; public: RestPeriodicTimerPost(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestPeriodicTimerPost() {} }; class RestTransmitTimerPost : public EManagementHandler { private: CRestCallback m_cb; public: RestTransmitTimerPost(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestTransmitTimerPost() {} }; class RestTransmitCountPost : public EManagementHandler { private: CRestCallback m_cb; public: RestTransmitCountPost(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestTransmitCountPost() {} }; class RestRequestTriesPost : public EManagementHandler { private: CRestCallback m_cb; public: RestRequestTriesPost(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestRequestTriesPost() {} }; class RestRequestTimeoutPost : public EManagementHandler { private: CRestCallback m_cb; public: RestRequestTimeoutPost(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestRequestTimeoutPost() {} }; class RestStatLoggingPost : public EManagementHandler { private: CRestCallback m_cb; public: RestStatLoggingPost(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestStatLoggingPost() {} }; class RestPcapStatusPost : public EManagementHandler { private: CRestCallback m_cb; public: RestPcapStatusPost(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestPcapStatusPost() {} }; class RestResetStatPost : public EManagementHandler { private: CRestCallback m_cb; public: RestResetStatPost(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestResetStatPost() {} }; class RestStatFrequencyPost : public EManagementHandler { private: CRestCallback m_cb; public: RestStatFrequencyPost(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestStatFrequencyPost() {} }; class RestPerfFlagPost : public EManagementHandler { private: CRestCallback m_cb; public: RestPerfFlagPost(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestPerfFlagPost() {} }; class RestUEDetailsPost : public EManagementHandler { private: CRestCallback m_cb; public: RestUEDetailsPost(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestUEDetailsPost() {} }; class RestUEDetailsPut : public EManagementHandler { private: CRestCallback m_cb; public: RestUEDetailsPut(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestUEDetailsPut() {} }; class RestUEDetailsDel : public EManagementHandler { private: CRestCallback m_cb; public: RestUEDetailsDel(ELogger &audit); void registerHandler(); virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); void registerCallback(CRestCallback cb) { m_cb = cb;}; virtual ~RestUEDetailsDel() {} }; #endif /* __NGIC_REST_APIS_H__ */
nikhilc149/e-utran-features-bug-fixes
ulpc/admf/include/DAdmfInterface.h
/* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __DADMF_INTERFACE_H_ #define __DADMF_INTERFACE_H_ #include <iostream> #include "AdmfApp.h" #define HTTPS "http://" #define COLON ":" #define ADD_UE_ENTRY "/addueentry" #define UPDATE_UE_ENTRY "/updateueentry" #define DELETE_UE_ENTRY "/deleteueentry" #define ACK_POST "/ack" #define NOTIFY_URI "/notify" class AdmfApplication; class DAdmfInterface { private: static int iRefCnt; static DAdmfInterface *mpInstance; AdmfApplication &mApp; DAdmfInterface(AdmfApplication &app); public: ~DAdmfInterface(); /** * @brief : Creates singleton object of DAdmfInterface * @param : app, reference to AdmfApplication object * @return : Returns reference to DAdmfInterface */ static DAdmfInterface* getInstance(AdmfApplication &app); /** * @brief : Sends curl request to D_ADMF url * @param : requestBody, request body to use in POST request * @return : Returns 0 on success, -1 on error */ static int8_t sendRequest(const char *requestBody, const char *url); /** * @brief : Forms a request URL and calls method to send request to D_ADMF * @param : requestUrl, url-suffix (addueentry, updateueentry, deleteueentry) * @return : Returns 0 on success, -1 on error */ int8_t sendRequestToDadmf(const std::string &requestUrl, const std::string &requestBody); /** * @brief : Forms a request URL and calls method to send ACK to D_ADMF * @param : requestUrl, url-suffix (ack) * @return : Returns 0 on Success, -1 on Error */ int8_t sendAckToDadmf(const std::string &requestUrl, const std::string &requestBody); /** * @brief : Decreases reference count. Deletes the object if reference count becomes zero. * @param : No param * @return : Returns nothing */ void ReleaseInstance(void); }; #endif /* __DADMF_INTERFACE_H_ */
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c_messages/delete_session.c
<gh_stars>0 /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <rte_debug.h> #include "gtp_messages.h" #include "../cp_dp_api/vepc_cp_dp_api.h" #include "gtpv2c_set_ie.h" #include "sm_struct.h" #include "cp_config.h" #include "cp_stats.h" #include "gtpc_session.h" extern pfcp_config_t config; extern int clSystemLog; int delete_context(gtp_eps_bearer_id_ie_t lbi, uint32_t teid, ue_context **_context, pdn_connection **_pdn) { int ret = 0; ue_context *context = NULL; ret = rte_hash_lookup_data(ue_context_by_fteid_hash, (const void *) &teid, (void **) &context); if (ret < 0 || !context) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE context for teid: %d\n", LOG_VALUE, ue_context_by_fteid_hash); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (!lbi.header.len) { /* TODO: should be responding with response indicating error * in request */ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Received Delete Session Request without ebi!\n",LOG_VALUE); return GTPV2C_CAUSE_INVALID_MESSAGE_FORMAT; } int ebi_index = GET_EBI_INDEX(lbi.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } if (!(context->bearer_bitmap & (1 << ebi_index))) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Received Delete Session Request on non-existent EBI - " "Dropping packet\n", LOG_VALUE); return GTPV2C_CAUSE_INVALID_MESSAGE_FORMAT; } pdn_connection *pdn = GET_PDN(context, ebi_index); if (!pdn) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get " "pdn for ebi_index %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (pdn->default_bearer_id != lbi.ebi_ebi) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Received Delete Session Request referencing incorrect " "default bearer ebi", LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_INCORRECT; } eps_bearer *bearer = context->eps_bearers[ebi_index]; if (!bearer) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Received Delete Session Request on non-existent default EBI\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } *_context = context; *_pdn = pdn; return 0; }
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/pfcp_set_ie.c
<gh_stars>0 /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "pfcp_ies.h" #include "pfcp_util.h" #include "pfcp_set_ie.h" #include "pfcp_enum.h" #include "gw_adapter.h" #ifdef CP_BUILD #include "cp.h" #include "main.h" #include "pfcp.h" #include "debug_str.h" #else #include "pfcp_struct.h" #include "up_main.h" #endif /* CP_BUILD */ /* size of user ip resource info ie will be 6 if teid_range is not included otherwise 7 */ #define SIZE_IF_TEIDRI_PRESENT 7 #define SIZE_IF_TEIDRI_NOT_PRESENT 6 #define USER_ID_LEN 10 /* extern */ uint32_t start_time; const uint32_t pfcp_base_seq_no = 0x00000000; const uint32_t pfcp_base_urr_seq_no = 0x00000000; static uint32_t pfcp_seq_no_offset; extern int clSystemLog; #ifdef CP_BUILD extern pfcp_config_t config; static uint32_t pfcp_sgwc_seid_offset; #endif /* CP_BUILD */ extern struct rte_hash *heartbeat_recovery_hash; const uint64_t pfcp_sgwc_base_seid = 0xC0FFEE; void set_pfcp_header(pfcp_header_t *pfcp, uint8_t type, bool flag ) { pfcp->s = flag; pfcp->mp = 0; pfcp->spare = 0; pfcp->version = PFCP_VERSION; pfcp->message_type = type; } uint32_t generate_seq_no(void){ uint32_t id = 0; id = pfcp_base_seq_no + (++pfcp_seq_no_offset); return id; } uint32_t get_pfcp_sequence_number(uint8_t type, uint32_t seq){ switch(type){ case PFCP_HEARTBEAT_REQUEST : case PFCP_PFD_MGMT_REQUEST: case PFCP_ASSOCIATION_SETUP_REQUEST: case PFCP_ASSOCIATION_UPDATE_REQUEST: case PFCP_ASSOCIATION_RELEASE_REQUEST: case PFCP_NODE_REPORT_REQUEST: case PFCP_SESSION_SET_DELETION_REQUEST: case PFCP_SESSION_ESTABLISHMENT_REQUEST: case PFCP_SESSION_MODIFICATION_REQUEST: case PFCP_SESSION_DELETION_REQUEST: case PFCP_SESSION_REPORT_REQUEST: return generate_seq_no(); case PFCP_HEARTBEAT_RESPONSE: case PFCP_ASSOCIATION_SETUP_RESPONSE: case PFCP_ASSOCIATION_UPDATE_RESPONSE: case PFCP_ASSOCIATION_RELEASE_RESPONSE: case PFCP_NODE_REPORT_RESPONSE: case PFCP_SESSION_SET_DELETION_RESPONSE: case PFCP_SESSION_ESTABLISHMENT_RESPONSE: case PFCP_SESSION_MODIFICATION_RESPONSE: case PFCP_SESSION_DELETION_RESPONSE: case PFCP_SESSION_REPORT_RESPONSE: return seq; default: clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Unknown PFCP Msg " "type. \n", LOG_VALUE); return 0; break; } return 0; } void set_pfcp_seid_header(pfcp_header_t *pfcp, uint8_t type, bool flag, uint32_t seq, uint8_t cp_type) { set_pfcp_header(pfcp, type, flag ); if(flag == HAS_SEID){ #ifdef CP_BUILD if (cp_type == SGWC){ pfcp->seid_seqno.has_seid.seid = pfcp_sgwc_base_seid + pfcp_sgwc_seid_offset; pfcp_sgwc_seid_offset++; } #endif /* CP_BUILD */ pfcp->seid_seqno.has_seid.seq_no = seq; pfcp->seid_seqno.has_seid.spare = 0; pfcp->seid_seqno.has_seid.message_prio = 0; }else if (flag == NO_SEID){ pfcp->seid_seqno.no_seid.seq_no = seq; pfcp->seid_seqno.no_seid.spare = 0; } } void pfcp_set_ie_header(pfcp_ie_header_t *header, uint8_t type, uint16_t length) { header->type = type; header->len = length; } int set_node_id(pfcp_node_id_ie_t *node_id, node_address_t node_value) { memset(node_id, 0, sizeof(pfcp_node_id_ie_t)); int ie_length = sizeof(pfcp_node_id_ie_t) - sizeof(node_id->node_id_value_ipv4_address) - sizeof(node_id->node_id_value_ipv6_address) - sizeof(node_id->node_id_value_fqdn); if(node_value.ip_type == PDN_TYPE_IPV6 || node_value.ip_type == PDN_TYPE_IPV4_IPV6) { /* IPv6 Handling */ ie_length += sizeof(struct in6_addr); node_id->node_id_type = NODE_ID_TYPE_TYPE_IPV6ADDRESS; memcpy(node_id->node_id_value_ipv6_address, node_value.ipv6_addr, IPV6_ADDRESS_LEN); } else if(node_value.ip_type == PDN_TYPE_IPV4) { /* IPv4 Handling */ node_id->node_id_type = NODE_ID_TYPE_TYPE_IPV4ADDRESS; node_id->node_id_value_ipv4_address = node_value.ipv4_addr; ie_length += sizeof(struct in_addr); } else { /* FQDN Handling */ } pfcp_set_ie_header(&(node_id->header), PFCP_IE_NODE_ID, ie_length - PFCP_IE_HDR_SIZE); ie_length += PFCP_IE_HDR_SIZE; return ie_length; } void set_recovery_time_stamp(pfcp_rcvry_time_stmp_ie_t *rec_time_stamp) { pfcp_set_ie_header(&(rec_time_stamp->header), PFCP_IE_RCVRY_TIME_STMP,UINT32_SIZE); rec_time_stamp->rcvry_time_stmp_val = start_time; } void set_upf_features(pfcp_up_func_feat_ie_t *upf_feat) { pfcp_set_ie_header(&(upf_feat->header), PFCP_IE_UP_FUNC_FEAT, UINT16_SIZE); } void set_cpf_features(pfcp_cp_func_feat_ie_t *cpf_feat) { pfcp_set_ie_header(&(cpf_feat->header), PFCP_IE_CP_FUNC_FEAT, UINT8_SIZE); } void set_sess_report_type(pfcp_report_type_ie_t *rt) { pfcp_set_ie_header(&(rt->header), PFCP_IE_REPORT_TYPE, UINT8_SIZE); rt->rpt_type_spare = 0; rt->upir = 0; rt->erir = 0; rt->usar = 0; rt->dldr = 1; } #ifdef DP_BUILD static void set_up_resource_info_addr(ip_type_t type, uint32_t ipv4_addr, uint8_t ipv6_addr[], pfcp_user_plane_ip_rsrc_info_ie_t *up_ip_resource_info, int *size) { if (type.ipv6) { up_ip_resource_info->v6 = PRESENT; memcpy(up_ip_resource_info->ipv6_address, ipv6_addr, IPV6_ADDRESS_LEN); *size += sizeof(struct in6_addr); } if (type.ipv4) { up_ip_resource_info->v4 = PRESENT; up_ip_resource_info->ipv4_address = htonl(ipv4_addr); *size += sizeof(struct in_addr); } return; } void set_up_ip_resource_info(pfcp_user_plane_ip_rsrc_info_ie_t *up_ip_resource_info, uint8_t i, int8_t teid_range, uint8_t logical_iface) { if(app.teidri_val == 0){ pfcp_set_ie_header(&(up_ip_resource_info->header), PFCP_IE_USER_PLANE_IP_RSRC_INFO, SIZE_IF_TEIDRI_NOT_PRESENT); }else{ pfcp_set_ie_header(&(up_ip_resource_info->header), PFCP_IE_USER_PLANE_IP_RSRC_INFO, SIZE_IF_TEIDRI_PRESENT); } up_ip_resource_info->user_plane_ip_rsrc_info_spare = 0; up_ip_resource_info->assosi = 1; up_ip_resource_info->assoni = 0; int size = sizeof(uint8_t); if( up_ip_resource_info->assoni == 1) { memset(up_ip_resource_info->ntwk_inst, 0, PFCP_NTWK_INST_LEN); size += sizeof(up_ip_resource_info->ntwk_inst); } if (app.teidri_val != 0) { up_ip_resource_info->teidri = app.teidri_val; up_ip_resource_info->teid_range = teid_range; size += sizeof(up_ip_resource_info->teid_range); } up_ip_resource_info->user_plane_ip_rsrc_info_spare2 = 0; size += sizeof(uint8_t); if( up_ip_resource_info->assosi ) { if (logical_iface) { /* WB/ACCESS:1 Logical Interface */ if ((logical_iface == 1) && (app.wb_li_ip || isIPv6Present(&app.wb_li_ipv6))) { up_ip_resource_info->src_intfc = SOURCE_INTERFACE_VALUE_ACCESS; /*UL*/ set_up_resource_info_addr(app.wb_li_ip_type, app.wb_li_ip, app.wb_li_ipv6.s6_addr, up_ip_resource_info, &size); } /* EB/CORE:2 Logical Interface */ if ((logical_iface == 2) && (app.eb_li_ip || isIPv6Present(&app.eb_li_ipv6))) { /* East Bound Interface */ up_ip_resource_info->src_intfc = SOURCE_INTERFACE_VALUE_CORE; /*DL*/ set_up_resource_info_addr(app.eb_li_ip_type, app.eb_li_ip, app.eb_li_ipv6.s6_addr, up_ip_resource_info, &size); } } else { if ((i == 0) && (app.wb_ip || isIPv6Present(&app.wb_ipv6))) { /* West Bound Interface */ up_ip_resource_info->src_intfc = SOURCE_INTERFACE_VALUE_ACCESS; /*UL*/ set_up_resource_info_addr(app.wb_ip_type, app.wb_ip, app.wb_ipv6.s6_addr, up_ip_resource_info, &size); } if ((i == 1) && (app.eb_ip || isIPv6Present(&app.eb_ipv6))) { /* East Bound Interface */ up_ip_resource_info->src_intfc = SOURCE_INTERFACE_VALUE_CORE; /*DL*/ set_up_resource_info_addr(app.eb_ip_type, app.eb_ip, app.eb_ipv6.s6_addr, up_ip_resource_info, &size); } } } pfcp_set_ie_header(&(up_ip_resource_info->header), PFCP_IE_USER_PLANE_IP_RSRC_INFO, size); } #endif /* DP_BUILD*/ int set_bar_id(pfcp_bar_id_ie_t *bar_id, uint8_t bar_id_value) { int size = sizeof(pfcp_bar_id_ie_t); pfcp_set_ie_header(&(bar_id->header), PFCP_IE_BAR_ID, (sizeof(pfcp_bar_id_ie_t) - sizeof(pfcp_ie_header_t))); bar_id->bar_id_value = bar_id_value; return size; } void set_dl_data_notification_delay(pfcp_dnlnk_data_notif_delay_ie_t *dl_data_notification_delay) { pfcp_set_ie_header(&(dl_data_notification_delay->header), PFCP_IE_DNLNK_DATA_NOTIF_DELAY, UINT8_SIZE); dl_data_notification_delay->delay_val_in_integer_multiples_of_50_millisecs_or_zero = 0; } int set_sgstd_buff_pkts_cnt(pfcp_suggstd_buf_pckts_cnt_ie_t *sgstd_buff_pkts_cnt, uint8_t pkt_cnt) { int size = sizeof(pfcp_suggstd_buf_pckts_cnt_ie_t); pfcp_set_ie_header(&(sgstd_buff_pkts_cnt->header), PFCP_IE_SUGGSTD_BUF_PCKT_CNT, (sizeof(pfcp_suggstd_buf_pckts_cnt_ie_t) - sizeof(pfcp_ie_header_t))); sgstd_buff_pkts_cnt->pckt_cnt_val = pkt_cnt; return size; } int set_dl_buf_sgstd_pkts_cnt(pfcp_dl_buf_suggstd_pckt_cnt_ie_t *dl_buf_sgstd_pkts_cnt, uint8_t pkt_cnt) { int size = sizeof(pfcp_dl_buf_suggstd_pckt_cnt_ie_t); pfcp_set_ie_header(&(dl_buf_sgstd_pkts_cnt->header), PFCP_IE_DL_BUF_SUGGSTD_PCKT_CNT, (sizeof(pfcp_dl_buf_suggstd_pckt_cnt_ie_t) - sizeof(pfcp_ie_header_t))); dl_buf_sgstd_pkts_cnt->pckt_cnt_val = pkt_cnt; return size; } int set_pdr_id(pfcp_pdr_id_ie_t *pdr_id, uint16_t pdr_id_value) { int size = sizeof(pfcp_pdr_id_ie_t); pfcp_set_ie_header(&(pdr_id->header), PFCP_IE_PDR_ID, (sizeof(pfcp_pdr_id_ie_t) - sizeof(pfcp_ie_header_t))); pdr_id->rule_id = pdr_id_value; return size; } int set_far_id(pfcp_far_id_ie_t *far_id, uint32_t far_id_value) { int size = sizeof(pfcp_far_id_ie_t); pfcp_set_ie_header(&(far_id->header), PFCP_IE_FAR_ID, (sizeof(pfcp_far_id_ie_t) - sizeof(pfcp_ie_header_t))); far_id->far_id_value = far_id_value; return size; } int set_urr_id(pfcp_urr_id_ie_t *urr_id, uint32_t urr_id_value) { int size = sizeof(pfcp_urr_id_ie_t); urr_id->urr_id_value = urr_id_value; pfcp_set_ie_header(&(urr_id->header), PFCP_IE_URR_ID, UINT32_SIZE); return size; } int set_precedence(pfcp_precedence_ie_t *prec, uint32_t prec_value) { int size = sizeof(pfcp_precedence_ie_t); pfcp_set_ie_header(&(prec->header), PFCP_IE_PRECEDENCE, (sizeof(pfcp_precedence_ie_t) - sizeof(pfcp_ie_header_t))); prec->prcdnc_val = prec_value; return size; } int set_outer_hdr_removal(pfcp_outer_hdr_removal_ie_t *out_hdr_rem, uint8_t outer_header_desc) { int size = sizeof(pfcp_outer_hdr_removal_ie_t) - sizeof(out_hdr_rem->gtpu_ext_hdr_del); pfcp_set_ie_header(&(out_hdr_rem->header), PFCP_IE_OUTER_HDR_REMOVAL, UINT8_SIZE); /* TODO: Revisit this for change in yang */ out_hdr_rem->outer_hdr_removal_desc = outer_header_desc; /* TODO: Revisit this for change in yang */ return size; } int set_source_intf(pfcp_src_intfc_ie_t *src_intf, uint8_t src_intf_value) { int size = sizeof(pfcp_src_intfc_ie_t); pfcp_set_ie_header(&(src_intf->header), PFCP_IE_SRC_INTFC, (sizeof(pfcp_src_intfc_ie_t) - sizeof(pfcp_ie_header_t))); src_intf->src_intfc_spare = 0; src_intf->interface_value = src_intf_value; return size; } int set_pdi(pfcp_pdi_ie_t *pdi, pdi_t *bearer_pdi, uint8_t cp_type) { int size = 0; size += set_source_intf(&(pdi->src_intfc), bearer_pdi->src_intfc.interface_value); #ifdef CP_BUILD if((cp_type != SGWC) && bearer_pdi->src_intfc.interface_value == SOURCE_INTERFACE_VALUE_CORE){ size += set_network_instance(&(pdi->ntwk_inst), &bearer_pdi->ntwk_inst); size += set_ue_ip(&(pdi->ue_ip_address), bearer_pdi->ue_addr); }else{ size += set_fteid(&(pdi->local_fteid), &bearer_pdi->local_fteid); if((cp_type != SGWC) && bearer_pdi->ue_addr.v6){ size += set_ue_ip(&(pdi->ue_ip_address), bearer_pdi->ue_addr); pdi->ue_ip_address.ipv6d = 1; pdi->ue_ip_address.ipv6_pfx_dlgtn_bits = bearer_pdi->ue_addr.ipv6_pfx_dlgtn_bits; pdi->ue_ip_address.header.len += sizeof(pdi->ue_ip_address.ipv6_pfx_dlgtn_bits); size += sizeof(pdi->ue_ip_address.ipv6_pfx_dlgtn_bits); } } #endif /* CP_BUILD */ /* TODO: Revisit this for change in yang */ pfcp_set_ie_header(&(pdi->header), IE_PDI, size); return (size + sizeof(pfcp_ie_header_t)); } int set_create_pdr(pfcp_create_pdr_ie_t *create_pdr, pdr_t *bearer_pdr, uint8_t cp_type) { int size = 0; size += set_pdr_id(&(create_pdr->pdr_id), bearer_pdr->rule_id); size += set_precedence(&(create_pdr->precedence), bearer_pdr->prcdnc_val); size += set_pdi(&(create_pdr->pdi), &bearer_pdr->pdi, cp_type); #ifdef CP_BUILD uint8_t outer_header_desc = 0; if (bearer_pdr->pdi.src_intfc.interface_value == SOURCE_INTERFACE_VALUE_ACCESS) { if(cp_type != SGWC) { if (create_pdr->pdi.local_fteid.v6) outer_header_desc = GTP_U_UDP_IPv6; else if (create_pdr->pdi.local_fteid.v4) outer_header_desc = GTP_U_UDP_IPv4; size += set_outer_hdr_removal(&(create_pdr->outer_hdr_removal), outer_header_desc); } } size += set_far_id(&(create_pdr->far_id), bearer_pdr->far.far_id_value); for(int i=0; i < create_pdr->urr_id_count; i++ ) { size += set_urr_id(&(create_pdr->urr_id[i]), bearer_pdr->urr.urr_id_value); } /* TODO: Revisit this for change in yang*/ if (cp_type != SGWC){ for(int i=0; i < create_pdr->qer_id_count; i++ ) { size += set_qer_id(&(create_pdr->qer_id[i]), bearer_pdr->qer_id[i].qer_id); } } #endif /* CP_BUILD */ pfcp_set_ie_header(&(create_pdr->header), IE_CREATE_PDR, size); return size; } void set_create_far(pfcp_create_far_ie_t *create_far, far_t *bearer_far) { uint16_t len = 0; len += set_far_id(&(create_far->far_id), bearer_far->far_id_value); len += set_apply_action(&(create_far->apply_action), &bearer_far->actions); pfcp_set_ie_header(&(create_far->header), IE_CREATE_FAR, len); } void set_create_urr(pfcp_create_urr_ie_t *create_urr, pdr_t *bearer_pdr) { uint16_t len = 0; len += set_urr_id(&(create_urr->urr_id), bearer_pdr->urr.urr_id_value); len += set_measurement_method(&(create_urr->meas_mthd), &bearer_pdr->urr); len += set_reporting_trigger(&(create_urr->rptng_triggers), &bearer_pdr->urr); if(bearer_pdr->urr.rept_trigg.volth == PRESENT) len += set_volume_threshold(&(create_urr->vol_thresh), &bearer_pdr->urr, bearer_pdr->pdi.src_intfc.interface_value); if(bearer_pdr->urr.rept_trigg.timth == PRESENT) len += set_time_threshold(&(create_urr->time_threshold), &bearer_pdr->urr); pfcp_set_ie_header(&(create_urr->header), IE_CREATE_URR, len); } void set_create_bar(pfcp_create_bar_ie_t *create_bar, bar_t *bearer_bar) { uint16_t len = 0; len += set_bar_id(&(create_bar->bar_id), bearer_bar->bar_id); /* len += set_sgstd_buff_pkts_cnt(&(create_bar->suggstd_buf_pckts_cnt), bearer_bar->suggstd_buf_pckts_cnt.pckt_cnt_val); set_dl_data_notification_delay(&(create_bar->dnlnk_data_notif_delay)); */ pfcp_set_ie_header(&(create_bar->header), IE_CREATE_BAR, len); } int set_update_pdr(pfcp_update_pdr_ie_t *update_pdr, pdr_t *bearer_pdr, uint8_t cp_type) { int size = 0; size += set_pdr_id(&(update_pdr->pdr_id), bearer_pdr->rule_id); size += set_precedence(&(update_pdr->precedence), bearer_pdr->prcdnc_val); size += set_pdi(&(update_pdr->pdi), &bearer_pdr->pdi, cp_type); #ifdef CP_BUILD uint8_t outer_header_desc = 0; if (cp_type != SGWC && bearer_pdr->pdi.src_intfc.interface_value == SOURCE_INTERFACE_VALUE_ACCESS) { if (update_pdr->pdi.local_fteid.v6) outer_header_desc = GTP_U_UDP_IPv6; else if (update_pdr->pdi.local_fteid.v4) outer_header_desc = GTP_U_UDP_IPv4; size += set_outer_hdr_removal(&(update_pdr->outer_hdr_removal), outer_header_desc); } size += set_far_id(&(update_pdr->far_id), bearer_pdr->far.far_id_value); #endif /* CP_BUILD */ pfcp_set_ie_header(&(update_pdr->header), IE_UPDATE_PDR, size); return size; } void creating_bar(pfcp_create_bar_ie_t *create_bar) { pfcp_set_ie_header(&(create_bar->header), IE_CREATE_BAR, sizeof(pfcp_create_bar_ie_t) - sizeof(pfcp_ie_header_t)); set_bar_id(&(create_bar->bar_id), 1); set_dl_data_notification_delay(&(create_bar->dnlnk_data_notif_delay)); set_sgstd_buff_pkts_cnt(&(create_bar->suggstd_buf_pckts_cnt), 11); } uint16_t set_apply_action(pfcp_apply_action_ie_t *apply_action_t, apply_action *bearer_action) { pfcp_set_ie_header(&(apply_action_t->header), IE_APPLY_ACTION_ID, UINT8_SIZE); apply_action_t->apply_act_spare = 0; apply_action_t->apply_act_spare2 = 0; apply_action_t->apply_act_spare3 = 0; apply_action_t->dupl = bearer_action->dupl; apply_action_t->nocp = bearer_action->nocp; apply_action_t->buff = bearer_action->buff; apply_action_t->forw = bearer_action->forw; apply_action_t->drop = bearer_action->drop; return sizeof(pfcp_apply_action_ie_t); } uint16_t set_measurement_method(pfcp_meas_mthd_ie_t *meas_mt, urr_t *bearer_urr) { pfcp_set_ie_header(&(meas_mt->header), PFCP_IE_MEAS_MTHD, UINT8_SIZE); meas_mt->event = 0; meas_mt->volum = bearer_urr->mea_mt.volum; meas_mt->durat = bearer_urr->mea_mt.durat; return sizeof(pfcp_meas_mthd_ie_t); } uint16_t set_reporting_trigger(pfcp_rptng_triggers_ie_t *rptng_triggers, urr_t *bearer_urr) { pfcp_set_ie_header(&(rptng_triggers->header), PFCP_IE_RPTNG_TRIGGERS, UINT16_SIZE); rptng_triggers->volth = bearer_urr->rept_trigg.volth; rptng_triggers->timth = bearer_urr->rept_trigg.timth; return sizeof(pfcp_rptng_triggers_ie_t); } int set_volume_threshold(pfcp_vol_thresh_ie_t *vol_thresh, urr_t *bearer_urr, uint8_t interface_value) { int size = sizeof(pfcp_ie_header_t) + sizeof(uint8_t); if(interface_value == SOURCE_INTERFACE_VALUE_ACCESS){ vol_thresh->ulvol = PRESENT; vol_thresh->uplink_volume = bearer_urr->vol_th.uplink_volume; size += sizeof(uint64_t); }else{ vol_thresh->dlvol = PRESENT; vol_thresh->downlink_volume = bearer_urr->vol_th.downlink_volume; size += sizeof(uint64_t); } pfcp_set_ie_header(&(vol_thresh->header), PFCP_IE_VOL_THRESH, size - sizeof(pfcp_ie_header_t)); return size; } int set_volume_measurment(pfcp_vol_meas_ie_t *vol_meas) { int size = sizeof(pfcp_vol_meas_ie_t); pfcp_set_ie_header(&(vol_meas->header), PFCP_IE_VOL_MEAS, sizeof(pfcp_vol_meas_ie_t) - sizeof(pfcp_ie_header_t)); vol_meas->tovol = 1; vol_meas->dlvol = 1; vol_meas->ulvol = 1; vol_meas->total_volume = 0; vol_meas->uplink_volume = 0; vol_meas->downlink_volume = 0; return size; } int set_start_time(pfcp_start_time_ie_t *start_time) { int size = sizeof(pfcp_start_time_ie_t); pfcp_set_ie_header(&(start_time->header), PFCP_IE_START_TIME, sizeof(uint32_t)); start_time->start_time = 0; return size; } int set_end_time(pfcp_end_time_ie_t *end_time) { int size = sizeof(pfcp_end_time_ie_t); pfcp_set_ie_header(&(end_time->header), PFCP_IE_END_TIME, sizeof(uint32_t)); end_time->end_time = 0; return size; } int set_first_pkt_time(pfcp_time_of_frst_pckt_ie_t *first_pkt_time) { int size = sizeof(pfcp_time_of_frst_pckt_ie_t); pfcp_set_ie_header(&(first_pkt_time->header), PFCP_IE_TIME_OF_FRST_PCKT, sizeof(uint32_t)); first_pkt_time->time_of_frst_pckt = 0; return size; } int set_last_pkt_time(pfcp_time_of_lst_pckt_ie_t *last_pkt_time) { int size = sizeof(pfcp_time_of_lst_pckt_ie_t); pfcp_set_ie_header(&(last_pkt_time->header), PFCP_IE_TIME_OF_LST_PCKT, sizeof(uint32_t)); last_pkt_time->time_of_lst_pckt = 0; return size; } int set_time_threshold(pfcp_time_threshold_ie_t *time_thresh, urr_t *bearer_urr) { int size = sizeof(pfcp_time_threshold_ie_t); pfcp_set_ie_header(&(time_thresh->header), PFCP_IE_TIME_THRESHOLD, sizeof(pfcp_time_threshold_ie_t) - sizeof(pfcp_ie_header_t)); time_thresh->time_threshold = bearer_urr->time_th.time_threshold; return size; } uint16_t set_forwarding_param(pfcp_frwdng_parms_ie_t *frwdng_parms, node_address_t node_value, uint32_t teid, uint8_t interface_value) { uint16_t len = 0; len += set_destination_interface(&(frwdng_parms->dst_intfc), interface_value); len += set_outer_header_creation(&(frwdng_parms->outer_hdr_creation), node_value, teid); pfcp_set_ie_header(&(frwdng_parms->header), IE_FRWDNG_PARMS, len); return len + sizeof(pfcp_ie_header_t); } uint16_t set_duplicating_param(pfcp_dupng_parms_ie_t *dupng_parms) { uint16_t len = 0; node_address_t node_value = {0}; len += set_destination_interface(&(dupng_parms->dst_intfc), 5); len += set_outer_header_creation(&(dupng_parms->outer_hdr_creation), node_value, 0); len += set_frwding_policy(&(dupng_parms->frwdng_plcy)); pfcp_set_ie_header(&(dupng_parms->header), IE_DUPNG_PARMS, len); return len; } uint16_t set_upd_duplicating_param(pfcp_upd_dupng_parms_ie_t *dupng_parms) { uint16_t len = 0; node_address_t node_value = {0}; len += set_destination_interface(&(dupng_parms->dst_intfc), 5); len += set_outer_header_creation(&(dupng_parms->outer_hdr_creation), node_value, 0); len += set_frwding_policy(&(dupng_parms->frwdng_plcy)); len += PFCP_IE_HEADER_SIZE * 3; pfcp_set_ie_header(&(dupng_parms->header), IE_DUPNG_PARMS, len); return len; } uint16_t set_upd_forwarding_param(pfcp_upd_frwdng_parms_ie_t *upd_frwdng_parms, node_address_t node_value) { uint16_t len = 0; len += set_destination_interface(&(upd_frwdng_parms->dst_intfc), 0); len += set_outer_header_creation(&(upd_frwdng_parms->outer_hdr_creation), node_value, 0); pfcp_set_ie_header(&(upd_frwdng_parms->header), IE_UPD_FRWDNG_PARMS, len); return len; } uint16_t set_frwding_policy(pfcp_frwdng_plcy_ie_t *frwdng_plcy){ uint16_t len = 0; frwdng_plcy->frwdng_plcy_ident_len = sizeof(uint8_t); len += sizeof(uint8_t); memset(frwdng_plcy->frwdng_plcy_ident, 0, sizeof(frwdng_plcy->frwdng_plcy_ident)); len += sizeof(frwdng_plcy->frwdng_plcy_ident); pfcp_set_ie_header(&(frwdng_plcy->header), PFCP_IE_FRWDNG_PLCY, len); return len; } uint16_t set_outer_header_creation(pfcp_outer_hdr_creation_ie_t *outer_hdr_creation, node_address_t node_value, uint32_t teid) { uint16_t len = 0; outer_hdr_creation->teid = teid; len += sizeof(outer_hdr_creation->teid); if (node_value.ip_type == PDN_TYPE_IPV6 || node_value.ip_type == PDN_TYPE_IPV4_IPV6) { memcpy(outer_hdr_creation->ipv6_address, node_value.ipv6_addr, IPV6_ADDRESS_LEN); len += sizeof(outer_hdr_creation->ipv6_address); outer_hdr_creation->outer_hdr_creation_desc.gtpu_udp_ipv6 = PRESENT; } else if (node_value.ip_type == PDN_TYPE_IPV4) { outer_hdr_creation->ipv4_address = node_value.ipv4_addr; len += sizeof(outer_hdr_creation->ipv4_address); outer_hdr_creation->outer_hdr_creation_desc.gtpu_udp_ipv4 = PRESENT; } len += sizeof(outer_hdr_creation->outer_hdr_creation_desc); pfcp_set_ie_header(&(outer_hdr_creation->header), PFCP_IE_OUTER_HDR_CREATION, len); return (len + sizeof(pfcp_ie_header_t)); } uint16_t set_destination_interface(pfcp_dst_intfc_ie_t *dst_intfc, uint8_t interface_value) { dst_intfc->dst_intfc_spare = 0; dst_intfc->interface_value = interface_value; pfcp_set_ie_header(&(dst_intfc->header), IE_DEST_INTRFACE_ID, UINT8_SIZE); return sizeof(pfcp_dst_intfc_ie_t); } void set_fq_csid(pfcp_fqcsid_ie_t *fq_csid,uint32_t nodeid_value) { fq_csid->fqcsid_node_id_type = IPV4_GLOBAL_UNICAST; /* TODO identify the number of CSID */ fq_csid->number_of_csids = 1; memcpy(&(fq_csid->node_address), &nodeid_value, IPV4_SIZE); for(int i = 0; i < fq_csid->number_of_csids ;i++) { /*PDN CONN value is 0 when it is not used */ fq_csid->pdn_conn_set_ident[i] = 0; /*fq_csid->pdn_conn_set_ident[i] = htons(pdn_conn_set_id++);*/ } pfcp_set_ie_header(&(fq_csid->header), PFCP_IE_FQCSID,2*(fq_csid->number_of_csids) + 5); } #ifdef CP_BUILD void set_user_id(pfcp_user_id_ie_t *user_id, uint64_t imsi) { user_id->user_id_spare = 0; user_id->naif = 0; user_id->msisdnf = 0; user_id->imeif = 0; user_id->imsif = 1; user_id->length_of_imsi = BINARY_IMSI_LEN; user_id->length_of_imei = 0; user_id->len_of_msisdn = 0; user_id->length_of_nai = 0; encode_imsi_to_bin(imsi, BINARY_IMSI_LEN , user_id->imsi); pfcp_set_ie_header(&(user_id->header), PFCP_IE_USER_ID , USER_ID_LEN); } #endif /* CP_BUILD */ void set_fseid(pfcp_fseid_ie_t *fseid,uint64_t seid, node_address_t node_value) { int size = sizeof(uint8_t); fseid->fseid_spare = 0; fseid->fseid_spare2 = 0; fseid->fseid_spare3 = 0; fseid->fseid_spare4 = 0; fseid->fseid_spare5 = 0; fseid->fseid_spare6 = 0; size += sizeof(uint64_t); fseid->seid = seid; if (node_value.ip_type == PDN_TYPE_IPV6) { /* IPv6 Handling */ size += sizeof(struct in6_addr); fseid->v6 = PRESENT; memcpy(fseid->ipv6_address, node_value.ipv6_addr, IPV6_ADDRESS_LEN); } else if (node_value.ip_type == PDN_TYPE_IPV4) { /* IPv4 Handling */ size += sizeof(struct in_addr); fseid->v4 = PRESENT; fseid->ipv4_address = node_value.ipv4_addr; } pfcp_set_ie_header(&(fseid->header), PFCP_IE_FSEID, size); } int set_cause(pfcp_cause_ie_t *cause, uint8_t cause_val) { int ie_length = sizeof(pfcp_cause_ie_t); pfcp_set_ie_header(&(cause->header), PFCP_IE_CAUSE, (sizeof(pfcp_cause_ie_t) - sizeof(pfcp_ie_header_t))); cause->cause_value = cause_val; return ie_length; } void set_remove_pdr(pfcp_remove_pdr_ie_t *remove_pdr, uint16_t pdr_id_value) { pfcp_set_ie_header(&(remove_pdr->header), IE_REMOVE_PDR, sizeof(pfcp_pdr_id_ie_t)); set_pdr_id(&(remove_pdr->pdr_id), pdr_id_value); } void set_remove_bar(pfcp_remove_bar_ie_t *remove_bar, uint8_t bar_id_value) { pfcp_set_ie_header(&(remove_bar->header), IE_REMOVE_BAR, sizeof(pfcp_bar_id_ie_t)); set_bar_id(&(remove_bar->bar_id), bar_id_value); } void set_traffic_endpoint(pfcp_traffic_endpt_id_ie_t *traffic_endpoint_id) { pfcp_set_ie_header(&(traffic_endpoint_id->header), PFCP_IE_TRAFFIC_ENDPT_ID, UINT8_SIZE); traffic_endpoint_id->traffic_endpt_id_val = 2; } int set_fteid( pfcp_fteid_ie_t *local_fteid, fteid_ie_t *local_fteid_value) { int size = sizeof(uint8_t); local_fteid->chid = 0; local_fteid->ch = 0; local_fteid->fteid_spare = 0; if(local_fteid_value == NULL) { local_fteid->teid = 0; local_fteid->ipv4_address = 0; memset(local_fteid->ipv6_address, 0, sizeof(local_fteid->ipv6_address)); size = sizeof(uint32_t) + sizeof(struct in_addr) + sizeof(struct in6_addr); } else { local_fteid->teid = local_fteid_value->teid; size += sizeof(uint32_t); if ((local_fteid_value->v4 == PRESENT) && (local_fteid_value->ch == 0)) { local_fteid->v4 = PRESENT; local_fteid->ipv4_address = local_fteid_value->ipv4_address; size += sizeof(struct in_addr); } if ((local_fteid_value->v6 == PRESENT) && (local_fteid_value->ch == 0)) { local_fteid->v6 = PRESENT; memcpy(local_fteid->ipv6_address, local_fteid_value->ipv6_address, IPV6_ADDRESS_LEN); size += sizeof(struct in6_addr); } } pfcp_set_ie_header(&(local_fteid->header), PFCP_IE_FTEID, size); return size + sizeof(pfcp_ie_header_t); } int set_network_instance(pfcp_ntwk_inst_ie_t *network_instance, ntwk_inst_t *network_instance_value) { int size = sizeof(pfcp_ntwk_inst_ie_t); pfcp_set_ie_header(&(network_instance->header), PFCP_IE_NTWK_INST, (sizeof(pfcp_ntwk_inst_ie_t) - sizeof(pfcp_ie_header_t))); strncpy((char *)network_instance->ntwk_inst, (char *)&network_instance_value->ntwk_inst, PFCP_NTWK_INST_LEN); return size; } int set_ue_ip(pfcp_ue_ip_address_ie_t *ue_ip, ue_ip_addr_t ue_addr) { int size = sizeof(pfcp_ue_ip_address_ie_t) - (sizeof(ue_ip->ipv4_address) + sizeof(ue_ip->ipv6_address) + sizeof(ue_ip->ipv6_pfx_dlgtn_bits)); /* Need to remove hard coded values */ ue_ip->ue_ip_addr_spare = 0; ue_ip->ipv6d = 0; ue_ip->sd = 0; if (ue_addr.v4 == 1) { ue_ip->v4 = 1; memcpy(&(ue_ip->ipv4_address), &ue_addr.ipv4_address, IPV4_SIZE); size += sizeof(ue_ip->ipv4_address); } /* TODO: IPv6 handling */ if (ue_addr.v6 == 1) { if (ue_ip->ipv6d == 1) { /* Use IPv6 prefix */ // size += sizeof(ue_ip->ipv6_pfx_dlgtn_bits); } else { /* Use default 64 prefix */ } /* IPv6 Handling */ ue_ip->v6 = 1; memcpy(ue_ip->ipv6_address, ue_addr.ipv6_address, IPV6_ADDRESS_LEN); size += sizeof(ue_ip->ipv6_address); } /* TODO: Need to merge below if and else in above conditions */ if (ue_addr.sd == 0) { /* Source IP Address */ } else { /* Destination IP Address */ } pfcp_set_ie_header(&(ue_ip->header), PFCP_IE_UE_IP_ADDRESS, (size - sizeof(pfcp_ie_header_t))); return size; } int set_qer_id(pfcp_qer_id_ie_t *qer_id, uint32_t qer_id_value) { int size = sizeof(pfcp_qer_id_ie_t); pfcp_set_ie_header(&(qer_id->header), PFCP_IE_QER_ID, (sizeof(pfcp_qer_id_ie_t) - sizeof(pfcp_ie_header_t))); qer_id->qer_id_value = qer_id_value; return size; } int set_gate_status( pfcp_gate_status_ie_t *gate_status, gate_status_t *qer_gate_status) { int size = sizeof(pfcp_gate_status_ie_t); pfcp_set_ie_header(&(gate_status->header), PFCP_IE_GATE_STATUS, (sizeof(pfcp_gate_status_ie_t) - sizeof(pfcp_ie_header_t))); gate_status->gate_status_spare = 0; gate_status->ul_gate = qer_gate_status->ul_gate; gate_status->dl_gate = qer_gate_status->dl_gate; return size; } int set_mbr(pfcp_mbr_ie_t *mbr, mbr_t *qer_mbr) { int size = sizeof(pfcp_mbr_ie_t); pfcp_set_ie_header(&(mbr->header), PFCP_IE_MBR, (sizeof(pfcp_mbr_ie_t) - sizeof(pfcp_ie_header_t))); mbr->ul_mbr = qer_mbr->ul_mbr; mbr->dl_mbr = qer_mbr->dl_mbr; return size; } int set_gbr(pfcp_gbr_ie_t *gbr, gbr_t *qer_gbr) { int size = sizeof(pfcp_gbr_ie_t); pfcp_set_ie_header(&(gbr->header), PFCP_IE_GBR, (sizeof(pfcp_gbr_ie_t) - sizeof(pfcp_ie_header_t))); gbr->ul_gbr = qer_gbr->ul_gbr; gbr->dl_gbr = qer_gbr->dl_gbr; return size ; } void set_create_qer(pfcp_create_qer_ie_t *qer, qer_t *bearer_qer) { int size = 0; size += set_qer_id(&(qer->qer_id), bearer_qer->qer_id); size += set_gate_status(&(qer->gate_status), &(bearer_qer->gate_status)); size += set_mbr(&(qer->maximum_bitrate), &(bearer_qer->max_bitrate)); size += set_gbr(&(qer->guaranteed_bitrate), &(bearer_qer->guaranteed_bitrate)); pfcp_set_ie_header(&(qer->header), IE_CREATE_QER, size); } void set_update_qer(pfcp_update_qer_ie_t *up_qer, qer_t *bearer_qer) { int size = 0; size += set_qer_id(&(up_qer->qer_id), bearer_qer->qer_id); size += set_mbr(&(up_qer->maximum_bitrate), &(bearer_qer->max_bitrate)); size += set_gbr(&(up_qer->guaranteed_bitrate), &(bearer_qer->guaranteed_bitrate)); pfcp_set_ie_header(&(up_qer->header), IE_UPDATE_QER, size); } void updating_bar( pfcp_upd_bar_sess_mod_req_ie_t *up_bar) { set_bar_id(&(up_bar->bar_id), 1); set_dl_data_notification_delay(&(up_bar->dnlnk_data_notif_delay)); set_sgstd_buff_pkts_cnt(&(up_bar->suggstd_buf_pckts_cnt), 111); uint8_t size = sizeof(pfcp_bar_id_ie_t) + sizeof(pfcp_dnlnk_data_notif_delay_ie_t)+ sizeof(pfcp_suggstd_buf_pckts_cnt_ie_t); pfcp_set_ie_header(&(up_bar->header), IE_UPD_BAR_SESS_MOD_REQ, size); } void set_update_bar_sess_rpt_rsp(pfcp_upd_bar_sess_rpt_rsp_ie_t *up_bar, bar_t *bearer_bar) { uint16_t len = 0; len = set_bar_id(&(up_bar->bar_id), bearer_bar->bar_id); len += set_dl_buf_sgstd_pkts_cnt(&(up_bar->dl_buf_suggstd_pckt_cnt), bearer_bar->dl_buf_suggstd_pckts_cnt.pckt_cnt_val); pfcp_set_ie_header(&(up_bar->header), IE_UPDATE_BAR_SESS_RPT_RESP, len); /* set_dl_data_notification_delay(&(up_bar->dnlnk_data_notif_delay)); set_sgstd_buff_pkts_cnt(&(up_bar->suggstd_buf_pckts_cnt), 111); uint8_t size = sizeof(pfcp_bar_id_ie_t) + sizeof(pfcp_dnlnk_data_notif_delay_ie_t)+ sizeof(pfcp_suggstd_buf_pckts_cnt_ie_t); pfcp_set_ie_header(&(up_bar->header), IE_UPD_BAR_SESS_MOD_REQ, size); */ } void set_update_far(pfcp_update_far_ie_t *up_far, far_t *bearer_far) { uint16_t len = 0; if(bearer_far != NULL){ len += set_far_id(&(up_far->far_id), bearer_far->far_id_value); len += set_apply_action(&(up_far->apply_action), &bearer_far->actions); }else{ apply_action action = {0}; len += set_far_id(&(up_far->far_id), 0); len += set_apply_action(&(up_far->apply_action), &action); } pfcp_set_ie_header(&(up_far->header), IE_UPDATE_FAR, len); } void set_pfcpsmreqflags(pfcp_pfcpsmreq_flags_ie_t *pfcp_sm_req_flags) { pfcp_set_ie_header(&(pfcp_sm_req_flags->header), PFCP_IE_PFCPSMREQ_FLAGS,UINT8_SIZE); pfcp_sm_req_flags->pfcpsmreq_flgs_spare = 0; pfcp_sm_req_flags->pfcpsmreq_flgs_spare2 = 0; pfcp_sm_req_flags->pfcpsmreq_flgs_spare3 = 0; pfcp_sm_req_flags->pfcpsmreq_flgs_spare4 = 0; pfcp_sm_req_flags->pfcpsmreq_flgs_spare5 = 0; pfcp_sm_req_flags->qaurr = 0; pfcp_sm_req_flags->sndem = 0; pfcp_sm_req_flags->drobu = 0; } void set_query_urr_refernce( pfcp_query_urr_ref_ie_t *query_urr_ref) { pfcp_set_ie_header(&(query_urr_ref->header), PFCP_IE_QUERY_URR_REF,UINT32_SIZE); query_urr_ref->query_urr_ref_val = 0; } void set_pfcp_ass_rel_req(pfcp_up_assn_rel_req_ie_t *ass_rel_req) { pfcp_set_ie_header(&(ass_rel_req->header), PFCP_IE_UP_ASSN_REL_REQ, UINT8_SIZE); ass_rel_req->up_assn_rel_req_spare = 0; ass_rel_req->sarr = 0; } void set_graceful_release_period(pfcp_graceful_rel_period_ie_t *graceful_rel_period) { pfcp_set_ie_header(&(graceful_rel_period->header), PFCP_IE_GRACEFUL_REL_PERIOD,UINT8_SIZE); graceful_rel_period->timer_unit = GRACEFUL_RELEASE_PERIOD_INFORMATIONLEMENT_VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_2_SECONDS; graceful_rel_period->timer_value = 1; } void set_sequence_num(pfcp_sequence_number_ie_t *seq) { pfcp_set_ie_header(&(seq->header), PFCP_IE_SEQUENCE_NUMBER, UINT32_SIZE); seq->sequence_number = 0; } void set_metric(pfcp_metric_ie_t *metric) { pfcp_set_ie_header(&(metric->header), PFCP_IE_METRIC, UINT8_SIZE); metric->metric = 0; } void set_period_of_validity(pfcp_timer_ie_t *pov) { pfcp_set_ie_header(&(pov->header), PFCP_IE_TIMER, UINT8_SIZE); pov->timer_unit = TIMER_INFORMATIONLEMENT_VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_2_SECONDS ; pov->timer_value = 0; } void set_oci_flag( pfcp_oci_flags_ie_t *oci) { pfcp_set_ie_header(&(oci->header), PFCP_IE_OCI_FLAGS, UINT8_SIZE); oci->oci_flags_spare = 0; oci->aoci = 1; } void set_offending_ie( pfcp_offending_ie_ie_t *offending_ie, int offend_val) { pfcp_set_ie_header(&(offending_ie->header), PFCP_IE_OFFENDING_IE, UINT16_SIZE); offending_ie->type_of_the_offending_ie = offend_val; } void set_lci(pfcp_load_ctl_info_ie_t *lci) { pfcp_set_ie_header(&(lci->header),IE_LOAD_CTL_INFO, sizeof(pfcp_sequence_number_ie_t) + sizeof(pfcp_metric_ie_t)); set_sequence_num(&(lci->load_ctl_seqn_nbr)); set_metric(&(lci->load_metric)); } void set_olci(pfcp_ovrld_ctl_info_ie_t *olci) { pfcp_set_ie_header(&(olci->header), IE_OVRLD_CTL_INFO, sizeof(pfcp_sequence_number_ie_t) + sizeof(pfcp_metric_ie_t)+sizeof(pfcp_timer_ie_t) + sizeof(pfcp_oci_flags_ie_t)); set_sequence_num(&(olci->ovrld_ctl_seqn_nbr)); set_metric(&(olci->ovrld_reduction_metric)); set_period_of_validity(&(olci->period_of_validity)); set_oci_flag(&(olci->ovrld_ctl_info_flgs)); } void set_failed_rule_id(pfcp_failed_rule_id_ie_t *rule) { pfcp_set_ie_header(&(rule->header), PFCP_IE_FAILED_RULE_ID, 3); rule->failed_rule_id_spare = 0; rule ->rule_id_type = RULE_ID_TYPE_PDR; rule->rule_id_value = 0; } void set_traffic_endpoint_id(pfcp_traffic_endpt_id_ie_t *tnp) { pfcp_set_ie_header(&(tnp->header), PFCP_IE_TRAFFIC_ENDPT_ID, UINT8_SIZE); tnp->traffic_endpt_id_val = 0; } int set_pdr_id_ie(pfcp_pdr_id_ie_t *pdr) { int ie_length = sizeof(pfcp_pdr_id_ie_t); pfcp_set_ie_header(&(pdr->header), PFCP_IE_PDR_ID, sizeof(pfcp_pdr_id_ie_t) - PFCP_IE_HDR_SIZE); pdr->rule_id = 0; return ie_length; } int set_created_pdr_ie(pfcp_created_pdr_ie_t *pdr) { int ie_length = 0; ie_length += set_pdr_id_ie(&(pdr->pdr_id)); ie_length += set_fteid(&(pdr->local_fteid), NULL); pfcp_set_ie_header(&(pdr->header), IE_CREATED_PDR, ie_length); ie_length += PFCP_IE_HDR_SIZE; return ie_length; } void set_created_traffic_endpoint(pfcp_created_traffic_endpt_ie_t *cte) { pfcp_set_ie_header(&(cte->header), IE_CREATE_TRAFFIC_ENDPT, 18); set_traffic_endpoint_id(&(cte->traffic_endpt_id)); set_fteid(&(cte->local_fteid), NULL); } void set_node_report_type( pfcp_node_rpt_type_ie_t *nrt) { pfcp_set_ie_header(&(nrt->header), PFCP_IE_NODE_RPT_TYPE, UINT8_SIZE); nrt->node_rpt_type_spare = 0; nrt->upfr = 0; } void set_user_plane_path_failure_report(pfcp_user_plane_path_fail_rpt_ie_t *uppfr) { pfcp_set_ie_header(&(uppfr->header), IE_USER_PLANE_PATH_FAIL_RPT, sizeof(pfcp_rmt_gtpu_peer_ie_t)); uppfr->rmt_gtpu_peer_count = 0; } void cause_check_association(pfcp_assn_setup_req_t *pfcp_ass_setup_req, uint8_t *cause_id, int *offend_id) { *cause_id = REQUESTACCEPTED ; *offend_id = 0; if(!(pfcp_ass_setup_req->node_id.header.len)){ *cause_id = MANDATORYIEMISSING; *offend_id = PFCP_IE_NODE_ID; } else { if (pfcp_ass_setup_req->node_id.node_id_type == IPTYPE_IPV4) { if (NODE_ID_IPV4_LEN != pfcp_ass_setup_req->node_id.header.len) { *cause_id = INVALIDLENGTH; } } if (pfcp_ass_setup_req->node_id.node_id_type == IPTYPE_IPV6) { if (NODE_ID_IPV6_LEN != pfcp_ass_setup_req->node_id.header.len) { *cause_id = INVALIDLENGTH; } } } if (!(pfcp_ass_setup_req->rcvry_time_stmp.header.len)) { *cause_id = MANDATORYIEMISSING; *offend_id =PFCP_IE_RCVRY_TIME_STMP; } else if(pfcp_ass_setup_req->rcvry_time_stmp.header.len != RECOV_TIMESTAMP_LEN){ *cause_id = INVALIDLENGTH; } } void cause_check_sess_estab(pfcp_sess_estab_req_t *pfcp_session_request, uint8_t *cause_id, int *offend_id) { *cause_id = REQUESTACCEPTED; *offend_id = 0; if(!(pfcp_session_request->node_id.header.len)) { *offend_id = PFCP_IE_NODE_ID; *cause_id = MANDATORYIEMISSING; } else { if (pfcp_session_request->node_id.node_id_type == IPTYPE_IPV4) { if (NODE_ID_IPV4_LEN != pfcp_session_request->node_id.header.len) { *cause_id = INVALIDLENGTH; } } if (pfcp_session_request->node_id.node_id_type == IPTYPE_IPV6) { if (NODE_ID_IPV6_LEN != pfcp_session_request->node_id.header.len) { *cause_id = INVALIDLENGTH; } } } if(!(pfcp_session_request->cp_fseid.header.len)){ *offend_id = PFCP_IE_FSEID; *cause_id = MANDATORYIEMISSING; } else if (pfcp_session_request->cp_fseid.v6 && pfcp_session_request->cp_fseid.v4) { if (pfcp_session_request->cp_fseid.header.len != CP_FSEID_LEN_V4V6) *cause_id = INVALIDLENGTH; } else if (pfcp_session_request->cp_fseid.v4) { if (pfcp_session_request->cp_fseid.header.len != CP_FSEID_LEN_V4) *cause_id = INVALIDLENGTH; } else if (pfcp_session_request->cp_fseid.v6) { if (pfcp_session_request->cp_fseid.header.len != CP_FSEID_LEN_V6) *cause_id = INVALIDLENGTH; } if(!pfcp_session_request->create_far_count) { *offend_id = PFCP_IE_FAR_ID; *cause_id = MANDATORYIEMISSING; } else { for(uint8_t i = 0; i < pfcp_session_request->create_far_count; i++){ if(!pfcp_session_request->create_far[i].far_id.header.len){ *offend_id = PFCP_IE_FAR_ID; *cause_id = MANDATORYIEMISSING; return; } if(!pfcp_session_request->create_far[i].apply_action.header.len){ *offend_id = PFCP_IE_APPLY_ACTION; *cause_id = MANDATORYIEMISSING; return; } } } if(!pfcp_session_request->create_pdr_count){ *offend_id = PFCP_IE_PDR_ID; *cause_id = MANDATORYIEMISSING; }else{ for(uint8_t i =0; i < pfcp_session_request->create_pdr_count; i++){ if(!pfcp_session_request->create_pdr[i].pdr_id.header.len){ *offend_id = PFCP_IE_PDR_ID; *cause_id = MANDATORYIEMISSING; return; } if(!pfcp_session_request->create_pdr[i].precedence.header.len){ *offend_id = PFCP_IE_PRECEDENCE; *cause_id = MANDATORYIEMISSING; return; } if(!pfcp_session_request->create_pdr[i].pdi.header.len){ *offend_id = IE_PDI; *cause_id = MANDATORYIEMISSING; return; }else{ if(!pfcp_session_request->create_pdr[i].pdi.src_intfc.header.len){ *offend_id = PFCP_IE_SRC_INTFC; *cause_id = MANDATORYIEMISSING; return; } } } } } #ifdef CP_BUILD int gx_context_entry_add(char *sess_id, gx_context_t *entry) { int ret = 0; ret = rte_hash_add_key_data(gx_context_by_sess_id_hash, (const void *)sess_id , (void *)entry); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Failed to add GX context entry in hash\n", LOG_VALUE, strerror(ret)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } return 0; } int gx_context_entry_lookup(char *sess_id, gx_context_t **entry) { int ret = rte_hash_lookup_data(gx_context_by_sess_id_hash, (const void*) (sess_id), (void **) entry); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"NO ENTRY FOUND IN UPF " "HASH [%s]\n", LOG_VALUE, sess_id); return -1; } return 0; } uint8_t upf_context_entry_add(node_address_t *upf_ip, upf_context_t *entry) { int ret = 0; ret = rte_hash_add_key_data(upf_context_by_ip_hash, (const void *)upf_ip , (void *)entry); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to add UPF " "context entry in hash for IP Type : %s\n" "with IP IPv4 : "IPV4_ADDR"\tIPv6 : "IPv6_FMT"", LOG_VALUE, ip_type_str(upf_ip->ip_type), IPV4_ADDR_HOST_FORMAT(upf_ip->ipv4_addr), PRINT_IPV6_ADDR(upf_ip->ipv6_addr)); return 1; } return 0; } int upf_context_entry_lookup(node_address_t upf_ip, upf_context_t **entry) { int ret = rte_hash_lookup_data(upf_context_by_ip_hash, (const void*) &(upf_ip), (void **) entry); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" NO ENTRY FOUND IN UPF " "HASH for IP Type : %s\n" "with IP IPv4 : "IPV4_ADDR"\tIPv6 : "IPv6_FMT"", LOG_VALUE, ip_type_str(upf_ip.ip_type), IPV4_ADDR_HOST_FORMAT(upf_ip.ipv4_addr), PRINT_IPV6_ADDR(upf_ip.ipv6_addr)); return -1; } return 0; } #endif /* CP_BUILD */ void cause_check_sess_modification(pfcp_sess_mod_req_t *pfcp_session_mod_req, uint8_t *cause_id, int *offend_id) { *cause_id = REQUESTACCEPTED; *offend_id = 0; if(!(pfcp_session_mod_req->cp_fseid.header.len)){ *cause_id = CONDITIONALIEMISSING; *offend_id = PFCP_IE_FSEID; } else if (pfcp_session_mod_req->cp_fseid.v6 && pfcp_session_mod_req->cp_fseid.v4) { if (pfcp_session_mod_req->cp_fseid.header.len != CP_FSEID_LEN_V4V6) *cause_id = INVALIDLENGTH; } else if (pfcp_session_mod_req->cp_fseid.v4) { if (pfcp_session_mod_req->cp_fseid.header.len != CP_FSEID_LEN_V4) *cause_id = INVALIDLENGTH; } else if (pfcp_session_mod_req->cp_fseid.v6) { if (pfcp_session_mod_req->cp_fseid.header.len != CP_FSEID_LEN_V6) *cause_id = INVALIDLENGTH; } if( pfcp_ctxt.up_supported_features & UP_PDIU ) { if(!(pfcp_session_mod_req->rmv_traffic_endpt.header.len)) { *cause_id = CONDITIONALIEMISSING; *offend_id = IE_RMV_TRAFFIC_ENDPT; } else if(pfcp_session_mod_req->rmv_traffic_endpt.header.len != REMOVE_TRAFFIC_ENDPOINT_LEN) { } if(!(pfcp_session_mod_req->create_traffic_endpt.header.len)) { *cause_id = CONDITIONALIEMISSING; *offend_id = IE_CREATE_TRAFFIC_ENDPT ; } else if (pfcp_session_mod_req->create_traffic_endpt.header.len != CREATE_TRAFFIC_ENDPOINT_LEN){ } } } void cause_check_delete_session(pfcp_sess_del_req_t *pfcp_session_delete_req, uint8_t *cause_id, int *offend_id) { *cause_id = REQUESTACCEPTED; *offend_id = 0; if(!(pfcp_session_delete_req->header.message_len)) { *cause_id = MANDATORYIEMISSING; *offend_id = PFCP_IE_FSEID; } else if(pfcp_session_delete_req->header.message_len != DELETE_SESSION_HEADER_LEN){ *cause_id = INVALIDLENGTH; } } int add_data_to_heartbeat_hash_table(node_address_t *key, uint32_t *recov_time) { int ret = 0; uint32_t *temp = NULL; temp = rte_zmalloc_socket(NULL, sizeof(uint32_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (temp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory data to add in heartbeat hash, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return 1; } *temp = *recov_time; ret = rte_hash_add_key_data(heartbeat_recovery_hash, (const void *)key, temp); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Failed to add data in " "heartbeat recovery hash\n", LOG_VALUE, strerror(ret)); rte_free(temp); return 1; } return 0; } void get_peer_node_addr(peer_addr_t *peer_addr, node_address_t *node_addr) { switch(peer_addr->type) { case PDN_TYPE_IPV4 : node_addr->ip_type = PDN_TYPE_IPV4; node_addr->ipv4_addr = peer_addr->ipv4.sin_addr.s_addr; break; case PDN_TYPE_IPV6 : node_addr->ip_type = PDN_TYPE_IPV6; memcpy(&node_addr->ipv6_addr, &peer_addr->ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); break; case PDN_TYPE_IPV4_IPV6: node_addr->ip_type = PDN_TYPE_IPV6; memcpy(&node_addr->ipv6_addr, &peer_addr->ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); break; default : clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Neither IPv4 nor " "IPv6 type is set ", LOG_VALUE); break; } } void add_ip_to_heartbeat_hash(node_address_t *peer_addr, uint32_t recovery_time) { uint32_t *default_recov_time = NULL; default_recov_time = rte_zmalloc_socket(NULL, sizeof(uint32_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(default_recov_time == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory to default recovery time, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); } else { *default_recov_time = recovery_time; int ret = add_data_to_heartbeat_hash_table(peer_addr, default_recov_time); if(ret !=0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Failed to add " "default recovery time in heartbeat recovery hash\n", LOG_VALUE, strerror(ret)); } if (default_recov_time != NULL) { rte_free(default_recov_time); default_recov_time = NULL; } } } void delete_entry_heartbeat_hash(node_address_t *node_addr) { int ret = 0; ret = rte_hash_del_key(heartbeat_recovery_hash, (const void *)(node_addr)); if (ret == -EINVAL || ret == -ENOENT) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Error on " "rte_delete_enrty_key_data add in heartbeat\n", LOG_VALUE, strerror(ret)); } } void clear_heartbeat_hash_table(void) { rte_hash_free(heartbeat_recovery_hash); } #ifdef CP_BUILD void create_gx_context_hash(void) { struct rte_hash_parameters rte_hash_params = { .name = "gx_context_by_sess_id_hash", .entries = UPF_ENTRIES_DEFAULT, .key_len = GX_SESS_ID_LEN, .hash_func = rte_jhash, .hash_func_init_val = 0, .socket_id = rte_socket_id(), }; gx_context_by_sess_id_hash = rte_hash_create(&rte_hash_params); if (!gx_context_by_sess_id_hash) { rte_panic("%s hash create failed: %s (%u)\n.", rte_hash_params.name, rte_strerror(rte_errno), rte_errno); } } void create_upf_context_hash(void) { struct rte_hash_parameters rte_hash_params = { .name = "upf_context_by_ip_hash", .entries = UPF_ENTRIES_DEFAULT, .key_len = sizeof(node_address_t), .hash_func = rte_jhash, .hash_func_init_val = 0, .socket_id = rte_socket_id(), }; upf_context_by_ip_hash = rte_hash_create(&rte_hash_params); if (!upf_context_by_ip_hash) { rte_panic("%s hash create failed: %s (%u)\n.", rte_hash_params.name, rte_strerror(rte_errno), rte_errno); } } void create_upf_by_ue_hash(void) { struct rte_hash_parameters rte_hash_params = { .name = "upflist_by_ue_hash", .entries = UPF_ENTRIES_BY_UE_DEFAULT, .key_len = sizeof(uint64_t), .hash_func = rte_jhash, .hash_func_init_val = 0, .socket_id = rte_socket_id(), }; upflist_by_ue_hash = rte_hash_create(&rte_hash_params); if (!upflist_by_ue_hash) { rte_panic("%s hash create failed: %s (%u)\n.", rte_hash_params.name, rte_strerror(rte_errno), rte_errno); } } void set_pdn_type(pfcp_pdn_type_ie_t *pdn, pdn_type_ie *pdn_mme) { pfcp_set_ie_header(&(pdn->header), PFCP_IE_PDN_TYPE, UINT8_SIZE); pdn->pdn_type_spare = 0; /* Need to check the following conditions*/ if (pdn_mme->ipv4 && pdn_mme->ipv6) { pdn->pdn_type = PDN_TYPE_IPV4_IPV6; } else if (pdn_mme->ipv4) pdn->pdn_type = PDN_TYPE_IPV4; else if (pdn_mme->ipv6) pdn->pdn_type = PDN_TYPE_IPV6; } int upflist_by_ue_hash_entry_add(uint64_t *imsi_val, uint16_t imsi_len, upfs_dnsres_t *entry) { int ret = 0; uint64_t imsi = UINT64_MAX; memcpy(&imsi, imsi_val, imsi_len); upfs_dnsres_t *temp = NULL; ret = rte_hash_lookup_data(upflist_by_ue_hash, &imsi, (void **)&temp); if(ret < 0){ /* TODO: Check before adding */ int ret = rte_hash_add_key_data(upflist_by_ue_hash, &imsi, entry); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to add entry " "in upflist by UE hash table", LOG_VALUE); return -1; } }else{ memcpy(temp, entry, sizeof(upfs_dnsres_t)); } return 0; } int upflist_by_ue_hash_entry_lookup(uint64_t *imsi_val, uint16_t imsi_len, upfs_dnsres_t **entry) { uint64_t imsi = UINT64_MAX; memcpy(&imsi, imsi_val, imsi_len); /* TODO: Check before adding */ int ret = rte_hash_lookup_data(upflist_by_ue_hash, &imsi, (void **)entry); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Failed to search entry " "in upflist by UE hash table", LOG_VALUE); return ret; } return 0; } int upflist_by_ue_hash_entry_delete(uint64_t *imsi_val, uint16_t imsi_len) { uint64_t imsi = UINT64_MAX; upfs_dnsres_t *entry = NULL; memcpy(&imsi, imsi_val, imsi_len); int ret = rte_hash_lookup_data(upflist_by_ue_hash, &imsi, (void **)&entry); if (ret >= 0) { /* PDN Conn Entry is present. Delete PDN Conn Entry */ ret = rte_hash_del_key(upflist_by_ue_hash, &imsi); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IMSI entry is not " "found:%lu\n", LOG_VALUE, imsi); return -1; } } /* Free data from hash */ if (entry != NULL) { rte_free(entry); entry = NULL; } return 0; } #endif /*CP_BUILD */ /*get msg type from cstm ie string */ uint64_t get_rule_type(pfcp_pfd_contents_ie_t *pfd_conts, uint16_t *idx) { char Temp_buf[3] = {0}; for(*idx = 0; pfd_conts->cstm_pfd_cntnt[*idx] != 32; (*idx += 1)) { Temp_buf[*idx] = pfd_conts->cstm_pfd_cntnt[*idx]; } *idx += 1; Temp_buf[*idx] = '\0'; return atoi(Temp_buf); } int set_duration_measurment(pfcp_dur_meas_ie_t *dur_meas){ int size = sizeof(pfcp_dur_meas_ie_t); pfcp_set_ie_header(&(dur_meas->header), PFCP_IE_DUR_MEAS, sizeof(uint32_t)); dur_meas->duration_value = 0; return size; } int set_node_address(uint32_t *ipv4_addr, uint8_t ipv6_addr[], node_address_t node_value) { if(node_value.ip_type == NONE_PDN_TYPE) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" None of the IPv4 " "or IPv6 IP is set", LOG_VALUE); return -1; } if (node_value.ip_type == PDN_TYPE_IPV6 || node_value.ip_type == PDN_TYPE_IPV4_IPV6) { memcpy(ipv6_addr, node_value.ipv6_addr, IPV6_ADDRESS_LEN); } if (node_value.ip_type == PDN_TYPE_IPV4 || node_value.ip_type == PDN_TYPE_IPV4_IPV6) { *ipv4_addr = node_value.ipv4_addr; } return 0; } int fill_ip_addr(uint32_t ipv4_addr, uint8_t ipv6_addr[], node_address_t *node_value) { memset(node_value, 0, sizeof(node_address_t)); if (ipv4_addr == 0 && !*ipv6_addr) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" None of the IPv4 " "or IPv6 IP is present while storing IP address", LOG_VALUE); return -1; } if (ipv4_addr != 0) { node_value->ip_type |= PDN_TYPE_IPV4; node_value->ipv4_addr = ipv4_addr; } if (*ipv6_addr) { node_value->ip_type |= PDN_TYPE_IPV6; memcpy(node_value->ipv6_addr, ipv6_addr, IPV6_ADDRESS_LEN); } return 0; } int check_ipv6_zero(uint8_t addr[], uint8_t len) { for (int i = 0; i < len; i++) { if (addr[i] != 0) return -1; } return 0; }
nikhilc149/e-utran-features-bug-fixes
dp/up.c
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <arpa/inet.h> #include <pcap.h> #include <rte_ip.h> #include <sponsdn.h> #include <stdbool.h> #include <rte_errno.h> #include <rte_cycles.h> #include <rte_ip_frag.h> #include "up_main.h" #include "gtpu.h" #include "ipv4.h" #include "ipv6.h" #include "util.h" #include "up_acl.h" #include "up_ether.h" #include "pfcp_util.h" #include "interface.h" #include "gw_adapter.h" #include "epc_packet_framework.h" pcap_dumper_t *pcap_dumper_east; pcap_dumper_t *pcap_dumper_west; extern int clSystemLog; extern struct in_addr cp_comm_ip; extern struct in_addr dp_comm_ip; extern uint16_t dp_comm_port; extern uint16_t cp_comm_port; extern struct rte_hash *conn_hash_handle; extern struct app_params app; struct in6_addr dp_comm_ipv6; static inline void reset_udp_hdr_checksum(struct rte_mbuf *m, uint8_t ip_type) { struct udp_hdr *udp_hdr; /* IF IP_TYPE = 1 i.e IPv4 , 2: IPv6*/ if (ip_type == IPV6_TYPE) { udp_hdr = get_mtoudp_v6(m); /* update Udp checksum */ udp_hdr->dgram_cksum = 0; struct ipv6_hdr *ipv6_hdr; ipv6_hdr = get_mtoip_v6(m); udp_hdr->dgram_cksum = rte_ipv6_udptcp_cksum(ipv6_hdr, udp_hdr); } else if (ip_type == IPV4_TYPE) { udp_hdr = get_mtoudp(m); /* update Udp checksum */ udp_hdr->dgram_cksum = 0; struct ipv4_hdr *ipv4_hdr; ipv4_hdr = get_mtoip(m); udp_hdr->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr); } } /* Tranlator of the IP header */ /* If ip_type = 0; Covert IP header from IPv6 to IPv4 */ /* If ip_type = 1; Covert IP header from IPv4 to IPv6 */ static int translator_ip_hdr(struct rte_mbuf *m, uint8_t ip_type) { void *ret = NULL; uint8_t *pkt_ptr = NULL; if (ip_type) { /* If ip_type = 1; Covert IP header from IPv4 to IPv6 */ /* Remove IPv4 header from the packet, IPv4 hdr= 20 Bytes */ ret = rte_pktmbuf_adj(m, IPv4_HDR_SIZE); if (ret == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to remove IPv4 header\n", LOG_VALUE); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"TRANS:Remove IPv4 header, modified mbuf offset %d, data len %d, pkt len%u\n", LOG_VALUE, m->data_off, m->data_len, m->pkt_len); /* Prepend IPv6 header from the packet, IPv6 hdr= 40 Bytes */ pkt_ptr = (uint8_t *) rte_pktmbuf_prepend(m, IPv6_HDR_SIZE); if (pkt_ptr == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to add IPv6 IP header\n", LOG_VALUE); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"TRANS:Prepend IPv6 header, modified mbuf offset %d, data len %d, pkt len%u\n", LOG_VALUE, m->data_off, m->data_len, m->pkt_len); } else { /* If ip_type = 0; Covert IP header from IPv6 to IPv4 */ /* Remove IPv6 header from the packet, IPv6 hdr= 40 Bytes */ ret = rte_pktmbuf_adj(m, IPv6_HDR_SIZE); if (ret == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to remove IPv6 header\n", LOG_VALUE); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"TRANS:Remove IPv6 header, modified mbuf offset %d, data len %d, pkt len%u\n", LOG_VALUE, m->data_off, m->data_len, m->pkt_len); /* Prepend IPv4 header from the packet, IPv4 hdr= 20 Bytes */ pkt_ptr = (uint8_t *) rte_pktmbuf_prepend(m, IPv4_HDR_SIZE); if (pkt_ptr == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to add IPv4 IP header\n", LOG_VALUE); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"TRANS:Prepend IPv4 header, modified mbuf offset %d, data len %d, pkt len%u\n", LOG_VALUE, m->data_off, m->data_len, m->pkt_len); } return 0; } void gtpu_decap(struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, uint64_t *decap_pkts_mask) { uint32_t i; int ret = 0; struct ether_hdr *ether = NULL; struct ipv4_hdr *ipv4_hdr = NULL; struct ipv6_hdr *ipv6_hdr = NULL; struct udp_hdr *udp_hdr = NULL; struct gtpu_hdr *gtpu_hdr = NULL; struct epc_meta_data *meta_data = NULL; for (i = 0; i < n; i++) { if (!ISSET_BIT(*decap_pkts_mask, i)) continue; /* Get the ether header info */ ether = (struct ether_hdr *)rte_pktmbuf_mtod(pkts[i], uint8_t *); /* Process the IPv4 data packets */ if (ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) { /* reject if not with s1u/logical intf ip */ ipv4_hdr = get_mtoip(pkts[i]); uint32_t ip = 0; //GCC_Security flag uint32_t ip_li = 0; //GCC_Security flag /* Uplink IP Address */ ip = ntohl(app.wb_ip); ip_li = ntohl(app.wb_li_ip); if ((ipv4_hdr->dst_addr != ip) && (ipv4_hdr->dst_addr != ip_li)) { RESET_BIT(*pkts_mask, i); continue; } /* reject un-tunneled packet */ udp_hdr = get_mtoudp(pkts[i]); if (ntohs(udp_hdr->dst_port) != UDP_PORT_GTPU) { RESET_BIT(*pkts_mask, i); continue; } gtpu_hdr = get_mtogtpu(pkts[i]); if (gtpu_hdr->teid == 0 || gtpu_hdr->msgtype != GTP_GPDU) { #ifdef STATS --epc_app.ul_params[S1U_PORT_ID].pkts_in; #ifdef EXSTATS ++epc_app.ul_params[S1U_PORT_ID].pkts_echo; #endif /* EXSTATS */ #endif /* STATS */ RESET_BIT(*pkts_mask, i); continue; } meta_data = (struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(pkts[i], META_DATA_OFFSET); meta_data->teid = ntohl(gtpu_hdr->teid); /* Copy eNB IPv4 Address */ meta_data->ip_type_t.enb_ipv4 = ntohl(ipv4_hdr->src_addr); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Received tunneled packet with teid 0x%X\n", LOG_VALUE, ntohl(meta_data->teid)); ret = DECAP_GTPU_HDR(pkts[i], NOT_PRESENT); if (ret < 0){ RESET_BIT(*pkts_mask, i); #ifdef STATS --epc_app.ul_params[S1U_PORT_ID].pkts_in; #endif /* STATS */ } } else if (ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6)) { /* Process the IPv6 data packets */ /* reject if not with s1u/logical intf ipv6 */ ipv6_hdr = get_mtoip_v6(pkts[i]); if (memcmp(&ipv6_hdr->dst_addr, &app.wb_ipv6, IPV6_ADDRESS_LEN) && (memcmp(&ipv6_hdr->dst_addr, &app.wb_li_ipv6, IPV6_ADDRESS_LEN))) { RESET_BIT(*pkts_mask, i); continue; } /* reject un-tunneled packet */ udp_hdr = get_mtoudp_v6(pkts[i]); if (ntohs(udp_hdr->dst_port) != UDP_PORT_GTPU) { RESET_BIT(*pkts_mask, i); continue; } /* reject teid zero or non PDU gtpu packet */ gtpu_hdr = get_mtogtpu_v6(pkts[i]); if (gtpu_hdr->teid == 0 || gtpu_hdr->msgtype != GTP_GPDU) { #ifdef STATS --epc_app.ul_params[S1U_PORT_ID].pkts_in; #ifdef EXSTATS ++epc_app.ul_params[S1U_PORT_ID].pkts_echo; #endif /* EXSTATS */ #endif /* STATS */ RESET_BIT(*pkts_mask, i); continue; } meta_data = (struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(pkts[i], META_DATA_OFFSET); /* Get the TEID */ meta_data->teid = ntohl(gtpu_hdr->teid); /* Copy eNB IPv6 Address */ memcpy(&meta_data->ip_type_t.enb_ipv6, &ipv6_hdr->src_addr, IPV6_ADDRESS_LEN); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Received tunneled packet with teid 0x%X\n", LOG_VALUE, ntohl(meta_data->teid)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"From UE IPv6 ADDR:" IPv6_FMT "\n", LOG_VALUE, IPv6_PRINT(GTPU_INNER_SRC_IPV6(pkts[i]))); ret = DECAP_GTPU_HDR(pkts[i], PRESENT); if (ret < 0){ RESET_BIT(*pkts_mask, i); #ifdef STATS --epc_app.ul_params[S1U_PORT_ID].pkts_in; #endif /* STATS */ } } } } void gtpu_encap(pdr_info_t **pdrs, pfcp_session_datat_t **sess_data, struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, uint64_t *fd_pkts_mask, uint64_t *pkts_queue_mask) { uint16_t len = 0; uint32_t i = 0; pdr_info_t *pdr = NULL; far_info_t *far = NULL; struct rte_mbuf *m = NULL; pfcp_session_datat_t *si = NULL; for (i = 0; i < n; i++) { si = sess_data[i]; pdr = pdrs[i]; m = pkts[i]; if (!ISSET_BIT(*fd_pkts_mask, i)) { continue; } if (!ISSET_BIT(*pkts_mask, i)) { #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; #endif /* STATS */ continue; } if (si == NULL) { #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; #endif /* STATS */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Session Data is NULL\n", LOG_VALUE); RESET_BIT(*pkts_mask, i); continue; } if (pdr == NULL) { #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; #endif /* STATS */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"PDR INFO IS NULL\n", LOG_VALUE); RESET_BIT(*pkts_mask, i); continue; } /* If Pdr value is not NULL */ far = pdr->far; if (far == NULL) { #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; #endif /* STATS */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"FAR INFO IS NULL\n", LOG_VALUE); RESET_BIT(*pkts_mask, i); continue; } /** Check downlink bearer is ACTIVE or IDLE */ if (si->sess_state != CONNECTED) { #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; ++epc_app.dl_params[SGI_PORT_ID].ddn_buf_pkts; #endif /* STATS */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Session State is NOT CONNECTED\n", LOG_VALUE); RESET_BIT(*pkts_mask, i); SET_BIT(*pkts_queue_mask, i); continue; } if (!far->actions.forw) { #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; ++epc_app.dl_params[SGI_PORT_ID].ddn_buf_pkts; #endif /* STATS */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Action is NOT set to FORW," " PDR_ID:%u, FAR_ID:%u\n", LOG_VALUE, pdr->rule_id, far->far_id_value); RESET_BIT(*pkts_mask, i); SET_BIT(*pkts_queue_mask, i); continue; } if (!far->frwdng_parms.outer_hdr_creation.teid) { #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; #endif /* STATS */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Next hop teid is NULL: " " PDR_ID:%u, FAR_ID:%u\n", LOG_VALUE, pdr->rule_id, far->far_id_value); RESET_BIT(*pkts_mask, i); SET_BIT(*pkts_queue_mask, i); continue; } /* Construct the IPv4/IPv6 header */ if ((pdr->far)->frwdng_parms.outer_hdr_creation.outer_hdr_creation_desc == GTPU_UDP_IPv4) { if (ENCAP_GTPU_HDR(m, (pdr->far)->frwdng_parms.outer_hdr_creation.teid, NOT_PRESENT) < 0) { #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; #endif /* STATS */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to ENCAP GTPU HEADER \n", LOG_VALUE); RESET_BIT(*pkts_mask, i); continue; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4: ENCAP Pkt with GTPU HEADER \n", LOG_VALUE); len = rte_pktmbuf_data_len(m); len = len - ETH_HDR_SIZE; /* Construct IPv4 header */ uint32_t src_addr = 0; uint32_t dst_addr = 0; /* construct iphdr with destination IP Address */ dst_addr = ntohl((pdr->far)->frwdng_parms.outer_hdr_creation.ipv4_address); /* Validate the Destination IP Address subnet */ if (validate_Subnet(dst_addr, app.wb_net, app.wb_bcast_addr)) { /* construct iphdr with local IP Address */ src_addr = app.wb_ip; } else if (validate_Subnet(dst_addr, app.wb_li_net, app.wb_li_bcast_addr)) { /* construct iphdr with local IP Address */ src_addr = app.wb_li_ip; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination IPv4 Addr "IPV4_ADDR" " "is NOT in local intf subnet\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(dst_addr)); RESET_BIT(*pkts_mask, i); continue; } /* Check SRC or DST Address are not Zero */ if ((!src_addr) || (!dst_addr)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Not Found Src or Dest IPv4 Addr, SrcAddr: "IPV4_ADDR", " "DstAddr: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(src_addr), IPV4_ADDR_HOST_FORMAT(dst_addr)); RESET_BIT(*pkts_mask, i); continue; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4 hdr: SRC ADDR:"IPV4_ADDR", DST ADDR:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(src_addr), IPV4_ADDR_HOST_FORMAT(dst_addr)); construct_ipv4_hdr(m, len, IP_PROTO_UDP, src_addr, dst_addr); len = len - IPv4_HDR_SIZE; /* construct udphdr */ construct_udp_hdr(m, len, UDP_PORT_GTPU, UDP_PORT_GTPU, NOT_PRESENT); } else if ((pdr->far)->frwdng_parms.outer_hdr_creation.outer_hdr_creation_desc == GTPU_UDP_IPv6) { /* If next hop support IPv6 */ if (ENCAP_GTPU_HDR(m, (pdr->far)->frwdng_parms.outer_hdr_creation.teid, PRESENT) < 0) { #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; #endif /* STATS */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to ENCAP GTPU HEADER \n", LOG_VALUE); RESET_BIT(*pkts_mask, i); continue; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: ENCAP Pkt with GTPU HEADER \n", LOG_VALUE); len = rte_pktmbuf_data_len(m); len = len - ETH_HDR_SIZE; /* Construct IPv6 header */ struct in6_addr src_addr = {0}; struct in6_addr dst_addr = {0}; struct in6_addr tmp_addr = {0}; /* construct iphdr with destination IPv6 Address */ memcpy(&dst_addr.s6_addr, (struct in6_addr *)(pdr->far)->frwdng_parms.outer_hdr_creation.ipv6_address, IPV6_ADDRESS_LEN); /* Validate the Destination IPv6 Address Network */ if (validate_ipv6_network(dst_addr, app.wb_ipv6, app.wb_ipv6_prefix_len)) { /* Source interface IPv6 address */ memcpy(&src_addr, &app.wb_ipv6, sizeof(struct in6_addr)); } else if (validate_ipv6_network(dst_addr, app.wb_li_ipv6, app.wb_li_ipv6_prefix_len)) { /* Source interface IPv6 address */ memcpy(&src_addr, &app.wb_li_ipv6, sizeof(struct in6_addr)); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination S5S8 intf IPv6 addr "IPv6_FMT" " "is NOT in local intf Network\n", LOG_VALUE, IPv6_PRINT(dst_addr)); RESET_BIT(*pkts_mask, i); continue; } /* Check SRC or DST IPv6 Address are not Zero */ if ((!memcmp(&src_addr, &tmp_addr, IPV6_ADDRESS_LEN)) || (!memcmp(&dst_addr, &tmp_addr, IPV6_ADDRESS_LEN))) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Not Found Src or Dest IPv6 Addr, SrcAddr: "IPv6_FMT", " "DstAddr: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(src_addr), IPv6_PRINT(dst_addr)); RESET_BIT(*pkts_mask, i); continue; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6 hdr: SRC ADDR:"IPv6_FMT", DST ADDR:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(src_addr), IPv6_PRINT(dst_addr)); /* Calculate the payload length for IPv6 header */ len = len - IPv6_HDR_SIZE; construct_ipv6_hdr(m, len, IP_PROTO_UDP, &src_addr, &dst_addr); /* construct udphdr */ construct_udp_hdr(m, len, UDP_PORT_GTPU, UDP_PORT_GTPU, PRESENT); } } } void ul_sess_info_get(struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, uint64_t *snd_err_pkts_mask, uint64_t *fwd_pkts_mask, uint64_t *decap_pkts_mask, pfcp_session_datat_t **sess_data) { uint32_t j = 0; uint64_t hit_mask = 0; void *key_ptr[MAX_BURST_SZ] = {NULL}; struct ul_bm_key key[MAX_BURST_SZ] = {0}; /* TODO: uplink hash is created based on values pushed from CP. * CP always sends rule-id = 1 while creation. * After new implementation of ADC-PCC relation lookup will fail. * Hard coding rule id to 1. (temporary fix) */ for (j = 0; j < n; j++) { key[j].teid = 0; key_ptr[j] = &key[j]; struct ether_hdr *ether = NULL; struct udp_hdr *udp_hdr = NULL; struct gtpu_hdr *gtpu_hdr = NULL; /* Reject malformed packet */ if (pkts[j]->data_len == 0) { RESET_BIT(*pkts_mask, j); #ifdef STATS --epc_app.ul_params[S1U_PORT_ID].pkts_in; #endif /* STATS */ continue; } /* Get the ether header info */ ether = (struct ether_hdr *)rte_pktmbuf_mtod(pkts[j], uint8_t *); if (ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) { struct ipv4_hdr *ipv4_hdr = NULL; /* reject if not with Wstbnd ip */ ipv4_hdr = get_mtoip(pkts[j]); if ((ntohl(ipv4_hdr->dst_addr) != app.wb_ip) && (ntohl(ipv4_hdr->dst_addr) != app.wb_li_ip)) { RESET_BIT(*pkts_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4: WB_IP or WB_LI_IP is not valid dst ip address:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ipv4_hdr->dst_addr)); #ifdef STATS --epc_app.ul_params[S1U_PORT_ID].pkts_in; #endif /* STATS */ continue; } /* reject un-tunneled packet */ udp_hdr = get_mtoudp(pkts[j]); if (ntohs(udp_hdr->dst_port) != UDP_PORT_GTPU) { RESET_BIT(*pkts_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4: GTPU UDP PORT is not valid\n", LOG_VALUE); continue; } /* reject pkt if not valid type or teid zero */ gtpu_hdr = get_mtogtpu(pkts[j]); if (gtpu_hdr->teid == 0 || ((gtpu_hdr->msgtype != GTP_GPDU) && (gtpu_hdr->msgtype != GTPU_END_MARKER_REQUEST))) { RESET_BIT(*pkts_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4: GTPU TEID and MSG TYPE is not valid\n", LOG_VALUE); continue; } key[j].teid = ntohl(gtpu_hdr->teid); } else if (ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6)) { struct ipv6_hdr *ipv6_hdr = NULL; /* reject if not with Wstbnd ip */ ipv6_hdr = get_mtoip_v6(pkts[j]); /* Destination IPv6 Address */ struct in6_addr ho_addr = {0}; memcpy(&ho_addr.s6_addr, &ipv6_hdr->dst_addr, IPV6_ADDRESS_LEN); /* Validate the destination address is S1U/WB_IPv6 or not */ if ((memcmp(&(app.wb_ipv6), &ho_addr, IPV6_ADDRESS_LEN)) && (memcmp(&(app.wb_li_ipv6), &ho_addr, IPV6_ADDRESS_LEN))) { RESET_BIT(*pkts_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: WB_IP or WB_LI_IP (Expected:"IPv6_FMT") " "is not valid dst ip address:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(app.wb_ipv6), IPv6_PRINT(ho_addr)); #ifdef STATS --epc_app.ul_params[S1U_PORT_ID].pkts_in; #endif /* STATS */ continue; } /* reject un-tunneled packet */ udp_hdr = get_mtoudp_v6(pkts[j]); if (ntohs(udp_hdr->dst_port) != UDP_PORT_GTPU) { RESET_BIT(*pkts_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: GTPU UDP PORT is not valid\n", LOG_VALUE); continue; } /* reject pkt if not valid type or teid zero */ gtpu_hdr = get_mtogtpu_v6(pkts[j]); if (gtpu_hdr->teid == 0 || ((gtpu_hdr->msgtype != GTP_GPDU) && (gtpu_hdr->msgtype != GTPU_END_MARKER_REQUEST))) { RESET_BIT(*pkts_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: GTPU TEID and MSG TYPE is not valid\n", LOG_VALUE); continue; } key[j].teid = ntohl(gtpu_hdr->teid); } } if ((iface_lookup_uplink_bulk_data((const void **)&key_ptr[0], n, &hit_mask, (void **)sess_data)) < 0) { hit_mask = 0; } for (j = 0; j < n; j++) { if (!ISSET_BIT(hit_mask, j)) { RESET_BIT(*pkts_mask, j); SET_BIT(*snd_err_pkts_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT":Session Data LKUP:FAIL!! ULKEY " "TEID: %u\n", LOG_VALUE, key[j].teid); sess_data[j] = NULL; } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"SESSION INFO:" "TEID:%u, Session State:%u\n", LOG_VALUE, key[j].teid, (sess_data[j])->sess_state); if (sess_data[j] != NULL && ISSET_BIT(*pkts_mask, j)) { /* SGWU: Outer Header Removal based on the configured in PDR */ if (sess_data[j]->hdr_rvl == NOT_SET_OUT_HDR_RVL_CRT) { /* Set the Foward Pkt Mask */ SET_BIT(*fwd_pkts_mask, j); } else if ((sess_data[j]->hdr_rvl == GTPU_UDP_IPv4) || sess_data[j]->hdr_rvl == GTPU_UDP_IPv6) { /* Set the Decasulation Pkt Mask */ SET_BIT(*decap_pkts_mask, j); } } } } } /* TODO: Optimized this function */ void dl_sess_info_get(struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, pfcp_session_datat_t **si, uint64_t *pkts_queue_mask, uint64_t *snd_err_pkts_mask, uint64_t *fwd_pkts_mask, uint64_t *encap_pkts_mask) { uint32_t j = 0, ul_count = 0, dl_count = 0; void *key_ptr[MAX_BURST_SZ] = {NULL}; void *key_ptr_t[MAX_BURST_SZ] = {NULL}; uint32_t dst_addr = 0; uint64_t hit_mask = 0; struct dl_bm_key key[MAX_BURST_SZ] = {0}; struct ul_bm_key key_t[MAX_BURST_SZ] = {0}; int ul_index[MAX_BURST_SZ] = {0}; int dl_index[MAX_BURST_SZ] = {0}; pfcp_session_datat_t *ul_sess_data[MAX_BURST_SZ] = {NULL}; pfcp_session_datat_t *dl_sess_data[MAX_BURST_SZ] = {NULL}; /* TODO: downlink hash is created based on values pushed from CP. * CP always sends rule-id = 1 while creation. * After new implementation of ADC-PCC relation lookup will fail. * Hard coding rule id to 1. (temporary fix) */ for (j = 0; j < n; j++) { struct ether_hdr *ether = NULL; struct udp_hdr *udp_hdr = NULL; struct gtpu_hdr *gtpu_hdr = NULL; /* Reject malformed packet */ if (pkts[j]->data_len == 0) { RESET_BIT(*pkts_mask, j); #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; #endif /* STATS */ continue; } /* Get the ether header info */ ether = (struct ether_hdr *)rte_pktmbuf_mtod(pkts[j], uint8_t *); /* Handle the IPv4 packets */ if (ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) { struct ipv4_hdr *ipv4_hdr = NULL; udp_hdr = get_mtoudp(pkts[j]); if ((ntohs(udp_hdr->dst_port) == UDP_PORT_GTPU) || (udp_hdr->dst_port == UDP_PORT_GTPU_NW_ORDER)) { /* tunnel packets */ /* reject if not with wb ip */ ipv4_hdr = get_mtoip(pkts[j]); if ((ntohl(ipv4_hdr->dst_addr) != app.eb_ip) && (ntohl(ipv4_hdr->dst_addr) != app.eb_li_ip)) { RESET_BIT(*pkts_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4:EB IP is not valid, Exp IP:"IPV4_ADDR" or "IPV4_ADDR"," "Rcvd_IP:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(app.eb_ip), IPV4_ADDR_HOST_FORMAT(app.eb_li_ip), IPV4_ADDR_HOST_FORMAT(ntohl(ipv4_hdr->dst_addr))); #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; #endif /* STATS */ continue; } gtpu_hdr = get_mtogtpu(pkts[j]); if (gtpu_hdr->teid == 0 || gtpu_hdr->msgtype != GTP_GPDU) { if (gtpu_hdr->teid == 0 || gtpu_hdr->msgtype != GTP_GEMR) { RESET_BIT(*pkts_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4:GTPU TEID:%u and MSG_TYPE:%x is not valid\n", LOG_VALUE, gtpu_hdr->teid, gtpu_hdr->msgtype); continue; } } ul_index[ul_count] = j; key_ptr_t[ul_count] = &key_t[ul_count]; key_t[ul_count].teid = ntohl(gtpu_hdr->teid); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4:DL_KEY: TEID:%u\n", LOG_VALUE, key_t[ul_count].teid); ul_count++; } else { key[dl_count].ue_ip.ue_ipv4 = 0; memset(&key[dl_count].ue_ip.ue_ipv6, 0, sizeof(struct in6_addr)); key_ptr[dl_count] = &key[dl_count]; dl_index[dl_count] = j; ipv4_hdr = get_mtoip(pkts[j]); dst_addr = ipv4_hdr->dst_addr; key[dl_count].ue_ip.ue_ipv4 = dst_addr; struct epc_meta_data *meta_data = (struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(pkts[j], META_DATA_OFFSET); meta_data->key.ue_ip.ue_ipv4 = key[dl_count].ue_ip.ue_ipv4; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4:BEAR SESS LKUP:DL_KEY UE IP:"IPV4_ADDR "\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(meta_data->key.ue_ip.ue_ipv4)); dl_count++; } } else if (ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6)) { /* Handle the IPv6 Pkts */ struct ipv6_hdr *ipv6_hdr = NULL; udp_hdr = get_mtoudp_v6(pkts[j]); if ((ntohs(udp_hdr->dst_port) == UDP_PORT_GTPU) || (udp_hdr->dst_port == UDP_PORT_GTPU_NW_ORDER)) { /* tunnel packets */ /* reject if not with eb ip */ ipv6_hdr = get_mtoip_v6(pkts[j]); /* Destination IPv6 Address */ struct in6_addr ho_addr = {0}; memcpy(&ho_addr.s6_addr, &ipv6_hdr->dst_addr, IPV6_ADDRESS_LEN); /* Validate the destination address is S1U/WB_IPv6 or not */ if ((memcmp(&(app.eb_ipv6), &ho_addr, IPV6_ADDRESS_LEN)) && (memcmp(&(app.eb_li_ipv6), &ho_addr, IPV6_ADDRESS_LEN))) { RESET_BIT(*pkts_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: EB_IP or EB_LI_IP (Expected:"IPv6_FMT" or "IPv6_FMT") " "is not valid dst ip address:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(app.eb_ipv6), IPv6_PRINT(app.eb_li_ipv6), IPv6_PRINT(ho_addr)); #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; #endif /* STATS */ continue; } gtpu_hdr = get_mtogtpu_v6(pkts[j]); if (gtpu_hdr->teid == 0 || gtpu_hdr->msgtype != GTP_GPDU) { if (gtpu_hdr->teid == 0 || gtpu_hdr->msgtype != GTP_GEMR) { RESET_BIT(*pkts_mask, j); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6:GTPU TEID:%u and MSG_TYPE:%x is not valid\n", LOG_VALUE, gtpu_hdr->teid, gtpu_hdr->msgtype); continue; } } ul_index[ul_count] = j; key_ptr_t[ul_count] = &key_t[ul_count]; key_t[ul_count].teid = ntohl(gtpu_hdr->teid); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6:DL_KEY: TEID:%u\n", LOG_VALUE, key_t[ul_count].teid); ul_count++; } else { key[dl_count].ue_ip.ue_ipv4 = 0; memset(&key[dl_count].ue_ip.ue_ipv6, 0, sizeof(struct in6_addr)); key_ptr[dl_count] = &key[dl_count]; dl_index[dl_count] = j; ipv6_hdr = get_mtoip_v6(pkts[j]); memcpy(&key[dl_count].ue_ip.ue_ipv6, &ipv6_hdr->dst_addr, IPV6_ADDRESS_LEN); struct epc_meta_data *meta_data = (struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(pkts[j], META_DATA_OFFSET); memcpy(&meta_data->key.ue_ip.ue_ipv6, &key[dl_count].ue_ip.ue_ipv6, IPV6_ADDRESS_LEN); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6:BEAR SESS LKUP:DL_KEY UE IP:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)meta_data->key.ue_ip.ue_ipv6)); dl_count++; } } } if (ul_count && key_ptr_t[0] != NULL) { if ((iface_lookup_uplink_bulk_data((const void **)&key_ptr_t[0], ul_count, &hit_mask, (void **)ul_sess_data)) < 0) { hit_mask = 0; clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"SDF BEAR Bulk LKUP:FAIL\n", LOG_VALUE); } for (j = 0; j < ul_count; j++) { if (!ISSET_BIT(hit_mask, j)) { RESET_BIT(*pkts_mask, ul_index[j]); SET_BIT(*snd_err_pkts_mask, ul_index[j]); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"SDF BEAR LKUP FAIL!! DL KEY " "TEID:%u\n", LOG_VALUE, key_t[j].teid); si[ul_index[j]] = NULL; } else { si[ul_index[j]] = ul_sess_data[j]; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"SESSION INFO:" "TEID:%u, Session State:%u\n", LOG_VALUE, key_t[j].teid, (ul_sess_data[j])->sess_state); /** Check downlink bearer is ACTIVE or IDLE */ if (ul_sess_data[j]->sess_state != CONNECTED) { #ifdef STATS --epc_app.dl_params[SGI_PORT_ID].pkts_in; ++epc_app.dl_params[SGI_PORT_ID].ddn_buf_pkts; #endif /* STATS */ RESET_BIT(*pkts_mask, ul_index[j]); SET_BIT(*pkts_queue_mask, ul_index[j]); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Enqueue Pkts Set the Pkt Mask:%u\n", LOG_VALUE, pkts_queue_mask); } if ((fwd_pkts_mask != NULL && encap_pkts_mask != NULL) && ((ISSET_BIT(*pkts_mask, ul_index[j])) || (ISSET_BIT(*pkts_queue_mask, ul_index[j])))) { if (ul_sess_data[j] != NULL) { /* SGWU: Outer Header Creation based on the configured in PDR */ if ((ul_sess_data[j]->hdr_rvl == NOT_SET_OUT_HDR_RVL_CRT) && (!(ul_sess_data[j]->ue_ip_addr || ul_sess_data[j]->ipv6))) { /* Set the Foward Pkt Mask */ SET_BIT(*fwd_pkts_mask, ul_index[j]); } else if (((ul_sess_data[j]->hdr_crt == GTPU_UDP_IPv4) || (ul_sess_data[j]->hdr_crt == GTPU_UDP_IPv6) || (ul_sess_data[j]->hdr_crt == NOT_SET_OUT_HDR_RVL_CRT)) && (ul_sess_data[j]->hdr_rvl == NOT_SET_OUT_HDR_RVL_CRT) && ((ul_sess_data[j]->ue_ip_addr) || ul_sess_data[j]->ipv6)) { /* Set the Decasulation Pkt Mask */ SET_BIT(*encap_pkts_mask, ul_index[j]); } } } } } } if (dl_count && key_ptr[0] != NULL) { if ((iface_lookup_downlink_bulk_data((const void **)&key_ptr[0], dl_count, &hit_mask, (void **)dl_sess_data)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"SDF BEAR Bulk LKUP:FAIL\n", LOG_VALUE); } for (j = 0; j < dl_count; j++) { if (!ISSET_BIT(hit_mask, j)) { RESET_BIT(*pkts_mask, dl_index[j]); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"SDF BEAR LKUP FAIL!! DL KEY " "UE IP:"IPV4_ADDR" or "IPv6_FMT"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT((key[j]).ue_ip.ue_ipv4), IPv6_PRINT(*(struct in6_addr *)(key[j]).ue_ip.ue_ipv6)); si[dl_index[j]] = NULL; } else { si[dl_index[j]] = dl_sess_data[j]; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"SESSION INFO:" "UE IP:"IPV4_ADDR" or "IPv6_FMT", ACL TABLE Index: %u " "Session State:%u\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT((dl_sess_data[j])->ue_ip_addr), IPv6_PRINT(IPv6_CAST((dl_sess_data[j])->ue_ipv6_addr)), (dl_sess_data[j])->acl_table_indx, (dl_sess_data[j])->sess_state); if ((fwd_pkts_mask != NULL && encap_pkts_mask != NULL) && ((ISSET_BIT(*pkts_mask, dl_index[j])) || (ISSET_BIT(*pkts_queue_mask, dl_index[j])))) { if (dl_sess_data[j] != NULL) { /* SGWU: Outer Header Creation based on the configured in PDR */ if ((dl_sess_data[j]->hdr_rvl == NOT_SET_OUT_HDR_RVL_CRT) && (!(dl_sess_data[j]->ue_ip_addr || dl_sess_data[j]->ipv6))) { /* Set the Foward Pkt Mask */ SET_BIT(*fwd_pkts_mask, dl_index[j]); } else if (((dl_sess_data[j]->hdr_crt == GTPU_UDP_IPv4) || (dl_sess_data[j]->hdr_crt == GTPU_UDP_IPv6) || (dl_sess_data[j]->hdr_crt == NOT_SET_OUT_HDR_RVL_CRT)) && (dl_sess_data[j]->hdr_rvl == NOT_SET_OUT_HDR_RVL_CRT) && ((dl_sess_data[j]->ue_ip_addr) || dl_sess_data[j]->ipv6)) { /* Set the Decasulation Pkt Mask */ SET_BIT(*encap_pkts_mask, dl_index[j]); } } } } } } } void qer_gating(pdr_info_t **pdr, uint32_t n, uint64_t *pkts_mask, uint64_t *fd_pkts_mask, uint64_t *pkts_queue_mask, uint8_t direction) { uint32_t i = 0; /* Uplink Gate Status Check */ if (direction == UPLINK) { for (i = 0; i < n; i++) { if ((ISSET_BIT(*pkts_mask, i)) && (ISSET_BIT(*fd_pkts_mask, i))) { /* Currently we apply 1st qer */ if (pdr[i]->qer_count) { if ((pdr[i]->quer[0]).gate_status.ul_gate == CLOSE) { RESET_BIT(*pkts_mask, i); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Matched PDR_ID:%u, FAR_ID:%u, QER_ID:%u\n", LOG_VALUE, pdr[i]->rule_id, (pdr[i]->far)->far_id_value, (pdr[i]->quer[0]).qer_id); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Packets DROPPED UL_GATE : CLOSED\n", LOG_VALUE); } } } } } else if (direction == DOWNLINK) { /* DownLink Gate Status Check */ for (i = 0; i < n; i++) { if ((ISSET_BIT(*pkts_mask, i)) && (ISSET_BIT(*fd_pkts_mask, i))) { /* Currently we apply 1st qer */ if (pdr[i]->qer_count) { if ((pdr[i]->quer[0]).gate_status.dl_gate == CLOSE) { RESET_BIT(*pkts_mask, i); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Matched PDR_ID:%u, FAR_ID:%u, QER_ID:%u\n", LOG_VALUE, pdr[i]->rule_id, (pdr[i]->far)->far_id_value, (pdr[i]->quer[0]).qer_id); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Packets DROPPED DL_GATE : CLOSED\n", LOG_VALUE); } } } } } } /** * @brief : Check if packet contains dns data * @param : m, buffer containing packet data * @param : rid, dns rule id * @return : Returns true for dns packet, false otherwise */ static inline bool is_dns_pkt(struct rte_mbuf *m, uint32_t rid) { struct ipv4_hdr *ip_hdr; struct ether_hdr *eth_hdr; eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *); ip_hdr = (struct ipv4_hdr *)(eth_hdr + 1); if (rte_ipv4_frag_pkt_is_fragmented(ip_hdr)) return false; if (rid != DNS_RULE_ID) return false; return true; } void update_dns_meta(struct rte_mbuf **pkts, uint32_t n, uint32_t *rid) { uint32_t i; struct epc_meta_data *meta_data; for (i = 0; i < n; i++) { meta_data = (struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR( pkts[i], META_DATA_OFFSET); if (likely(!is_dns_pkt(pkts[i], rid[i]))) { meta_data->dns = 0; continue; } meta_data->dns = 1; } } #ifdef HYPERSCAN_DPI /** * @brief : Get worker index * @param : lcore_id * @return : Returns epc app worker index */ static int get_worker_index(unsigned lcore_id) { return epc_app.worker_core_mapping[lcore_id]; } void clone_dns_pkts(struct rte_mbuf **pkts, uint32_t n, uint64_t pkts_mask) { uint32_t i; struct epc_meta_data *meta_data; unsigned lcore_id = rte_lcore_id(); int worker_index = get_worker_index(lcore_id); for (i = 0; i < n; i++) { if (ISSET_BIT(pkts_mask, i)) { meta_data = (struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR( pkts[i], META_DATA_OFFSET); if (meta_data->dns) { push_dns_ring(pkts[i]); /* NGCORE_SHRINK HYPERSCAN clone_dns_pkt to be tested */ ++(epc_app.dl_params[worker_index]. num_dns_packets); } } } } #endif /* HYPERSCAN_DPI */ void update_nexthop_info(struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, uint8_t portid, pdr_info_t **pdr, uint8_t loopback_flag) { uint32_t i; for (i = 0; i < n; i++) { if ((ISSET_BIT(*pkts_mask, i)) && (pdr[i] != NULL)) { if (construct_ether_hdr(pkts[i], portid, &pdr[i], loopback_flag) < 0) RESET_BIT(*pkts_mask, i); } else { RESET_BIT(*pkts_mask, i); } /* TODO: Set checksum offload.*/ } } void update_nexts5s8_info(struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, uint64_t *fwd_pkts_mask, uint64_t *loopback_pkts_mask, pfcp_session_datat_t **sess_data, pdr_info_t **pdr) { uint32_t i; uint16_t len; for (i = 0; i < n; i++) { if ((ISSET_BIT(*pkts_mask, i)) && (ISSET_BIT(*fwd_pkts_mask, i))) { if ((sess_data[i]->pdrs != NULL) && ((sess_data[i]->pdrs)->far != NULL)) { struct ether_hdr *ether = NULL; /* Get the ether header info */ ether = (struct ether_hdr *)rte_pktmbuf_mtod(pkts[i], uint8_t *); /* Construct the IPv4/IPv6 header */ if (((sess_data[i]->pdrs)->far)->frwdng_parms.outer_hdr_creation.outer_hdr_creation_desc == GTPU_UDP_IPv4) { /* Retrieve Next Hop Destination Address */ uint32_t next_hop_addr = ntohl(((sess_data[i]->pdrs)->far)->frwdng_parms.outer_hdr_creation.ipv4_address); uint32_t src_addr = 0; /* LoopBack: Re-direct Inputs packets to another node from same intf */ if (((sess_data[i]->pdrs)->pdi.src_intfc.interface_value == ACCESS) && (((sess_data[i]->pdrs)->far)->frwdng_parms.dst_intfc.interface_value == ACCESS)) { /* If PDR and FAR info have interface type ACCESS:0, i.e needs to loopback pkts */ /* Validate the Destination IPv4 Address subnet */ if (validate_Subnet(next_hop_addr, app.wb_net, app.wb_bcast_addr)) { /* Source interface IPv4 address */ src_addr = app.wb_ip; } else if (validate_Subnet(next_hop_addr, app.wb_li_net, app.wb_li_bcast_addr)) { /* Source interface IPv4 address */ src_addr = app.wb_li_ip; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination West Bound intf IPv4 Addr "IPV4_ADDR" " "is NOT in local intf subnet\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(next_hop_addr)); RESET_BIT(*pkts_mask, i); continue; } SET_BIT(*loopback_pkts_mask, i); RESET_BIT(*pkts_mask, i); } else { /* Validate the Destination IPv4 Address subnet */ if (validate_Subnet(next_hop_addr, app.eb_net, app.eb_bcast_addr)) { /* Source interface IPv4 address */ src_addr = app.eb_ip; } else if (validate_Subnet(next_hop_addr, app.eb_li_net, app.eb_li_bcast_addr)) { /* Source interface IPv4 address */ src_addr = app.eb_li_ip; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination East Bound intf IPv4 Addr "IPV4_ADDR" " "is NOT in local intf subnet\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(next_hop_addr)); RESET_BIT(*pkts_mask, i); continue; } } /* Translator to convert IPv6 header to IPv4 header */ if ((ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6))) { if (translator_ip_hdr(pkts[i], NOT_PRESENT)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to translate IP HDR from IPv6 to IPv4\n", LOG_VALUE); RESET_BIT(*pkts_mask, i); continue; } } len = rte_pktmbuf_data_len(pkts[i]); len = len - ETH_HDR_SIZE; /* Update the GTP-U header teid of S5S8 PGWU */ ((struct gtpu_hdr *)get_mtogtpu(pkts[i]))->teid = ntohl(sess_data[i]->pdrs->far->frwdng_parms.outer_hdr_creation.teid); /* Fill the Source and Destination IP address in the IPv4 Header */ /* RCVD: CORE --> SEND: ACCESS */ /* RCVD: ACCESS --> SEND: CORE */ construct_ipv4_hdr(pkts[i], len, IP_PROTO_UDP, src_addr, next_hop_addr); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4 hdr: SRC ADDR:"IPV4_ADDR", DST ADDR:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(src_addr), IPV4_ADDR_HOST_FORMAT(next_hop_addr)); /* Update the UDP checksum */ reset_udp_hdr_checksum(pkts[i], IPV4_TYPE); } else if (((sess_data[i]->pdrs)->far)->frwdng_parms.outer_hdr_creation.outer_hdr_creation_desc == GTPU_UDP_IPv6) { /* Retrieve Next Hop Destination Address */ struct in6_addr next_hop_addr = {0}; /* Copy destination address from FAR */ memcpy(&next_hop_addr.s6_addr, ((sess_data[i]->pdrs)->far)->frwdng_parms.outer_hdr_creation.ipv6_address, IPV6_ADDRESS_LEN); /* VS: Validate the Destination IPv6 Address Subnet */ struct in6_addr src_addr = {0}; /* LoopBack: Re-direct Inputs packets to another node from same intf */ if (((sess_data[i]->pdrs)->pdi.src_intfc.interface_value == ACCESS) && (((sess_data[i]->pdrs)->far)->frwdng_parms.dst_intfc.interface_value == ACCESS)) { /* If PDR and FAR info have interface type ACCESS:0, i.e needs to loopback pkts */ /* Validate the Destination IPv6 Address Network */ if (validate_ipv6_network(next_hop_addr, app.wb_ipv6, app.wb_ipv6_prefix_len)) { /* Source interface IPv6 address */ memcpy(&src_addr, &app.wb_ipv6, sizeof(struct in6_addr)); } else if (validate_ipv6_network(next_hop_addr, app.wb_li_ipv6, app.wb_li_ipv6_prefix_len)) { /* Source interface IPv6 address */ memcpy(&src_addr, &app.wb_li_ipv6, sizeof(struct in6_addr)); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination S5S8 intf IPv6 addr "IPv6_FMT" " "is NOT in local intf Network\n", LOG_VALUE, IPv6_PRINT(next_hop_addr)); RESET_BIT(*pkts_mask, i); continue; } SET_BIT(*loopback_pkts_mask, i); RESET_BIT(*pkts_mask, i); } else { /* Validate the Destination IPv6 Address Network */ if (validate_ipv6_network(next_hop_addr, app.eb_ipv6, app.eb_ipv6_prefix_len)) { /* Source interface IPv6 address */ memcpy(&src_addr, &app.eb_ipv6, sizeof(struct in6_addr)); } else if (validate_ipv6_network(next_hop_addr, app.eb_li_ipv6, app.eb_li_ipv6_prefix_len)) { /* Source interface IPv6 address */ memcpy(&src_addr, &app.eb_li_ipv6, sizeof(struct in6_addr)); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination S5S8 intf IPv6 addr "IPv6_FMT" " "is NOT in local intf Network\n", LOG_VALUE, IPv6_PRINT(next_hop_addr)); RESET_BIT(*pkts_mask, i); continue; } } /* Translator to convert IPv4 header to IPv6 header */ if ((ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4))) { if (translator_ip_hdr(pkts[i], PRESENT)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to translate IP HDR from IPv4 to IPv6\n", LOG_VALUE); RESET_BIT(*pkts_mask, i); continue; } } /* Calculate payload length*/ len = rte_pktmbuf_data_len(pkts[i]); len = len - (ETH_HDR_SIZE + IPv6_HDR_SIZE); /* Update the GTP-U header teid of S5S8 PGWU */ ((struct gtpu_hdr *)get_mtogtpu_v6(pkts[i]))->teid = ntohl(((sess_data[i]->pdrs)->far)->frwdng_parms.outer_hdr_creation.teid); /* Fill the Source and Destination IP address in the IPv6 Header */ /* RCVD: CORE --> SEND: ACCESS */ /* RCVD: ACCESS --> SEND: CORE */ construct_ipv6_hdr(pkts[i], len, IP_PROTO_UDP, &src_addr, &next_hop_addr); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6 hdr: SRC ADDR:"IPv6_FMT", DST ADDR:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(src_addr), IPv6_PRINT(next_hop_addr)); /* Update the UDP checksum */ reset_udp_hdr_checksum(pkts[i], IPV6_TYPE); } else { RESET_BIT(*pkts_mask, i); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ERR: Outer header Creation Not Set approprietly\n", LOG_VALUE); } } else { RESET_BIT(*pkts_mask, i); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Session Data don't have PDR info\n", LOG_VALUE); sess_data[i]->pdrs = NULL; } } /* Fill the PDR info form the session data */ if (sess_data[i] != NULL) { pdr[i] = sess_data[i]->pdrs; } } } void update_enb_info(struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask, uint64_t *fd_pkts_mask, pfcp_session_datat_t **sess_data, pdr_info_t **pdr) { uint16_t len = 0; uint32_t i = 0; for (i = 0; i < n; i++) { if ((ISSET_BIT(*pkts_mask, i)) && (ISSET_BIT(*fd_pkts_mask, i))) { if(sess_data[i] != NULL) { if ((sess_data[i]->pdrs != NULL) && ((sess_data[i]->pdrs)->far != NULL)) { struct ether_hdr *ether = NULL; /* Get the ether header info */ ether = (struct ether_hdr *)rte_pktmbuf_mtod(pkts[i], uint8_t *); /* Construct the IPv4/IPv6 header */ if ((((sess_data[i]->pdrs)->far)->frwdng_parms.outer_hdr_creation.outer_hdr_creation_desc == GTPU_UDP_IPv4) && (sess_data[i]->hdr_crt == GTPU_UDP_IPv4)) { /* Next hop or destination IPv4 Address */ uint32_t enb_addr = ntohl(sess_data[i]->pdrs->far->frwdng_parms.outer_hdr_creation.ipv4_address); uint32_t src_addr = 0; /* Validate the Destination IPv4 Address subnet */ if (validate_Subnet(enb_addr, app.wb_net, app.wb_bcast_addr)) { /* Source interface IPv4 address */ src_addr = app.wb_ip; } else if (validate_Subnet(enb_addr, app.wb_li_net, app.wb_li_bcast_addr)) { /* Source interface IPv4 address */ src_addr = app.wb_li_ip; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination eNB IPv4 Addr "IPV4_ADDR" " "is NOT in local intf subnet\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(enb_addr)); RESET_BIT(*pkts_mask, i); continue; } /* Translator to convert IPv6 header to IPv4 header */ if ((ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6))) { if (translator_ip_hdr(pkts[i], NOT_PRESENT)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to translate IP HDR from IPv6 to IPv4\n", LOG_VALUE); RESET_BIT(*pkts_mask, i); continue; } } /* Calculate the IPv4 header length */ len = rte_pktmbuf_data_len(pkts[i]); len = len - ETH_HDR_SIZE; /* Update tied in GTP U header*/ ((struct gtpu_hdr *)get_mtogtpu(pkts[i]))->teid = ntohl(sess_data[i]->pdrs->far->frwdng_parms.outer_hdr_creation.teid); /* Fill the Source and Destination IP address in the IPv4 Header */ construct_ipv4_hdr(pkts[i], len, IP_PROTO_UDP, src_addr, enb_addr); /* Update the UDP checksum */ reset_udp_hdr_checksum(pkts[i], IPV4_TYPE); /* Fill the PDR info form the session data */ pdr[i] = sess_data[i]->pdrs; } else if ((((sess_data[i]->pdrs)->far)->frwdng_parms.outer_hdr_creation.outer_hdr_creation_desc == GTPU_UDP_IPv6) && (sess_data[i]->hdr_crt == GTPU_UDP_IPv6)) { /* Retrieve Next Hop Destination Address */ struct in6_addr enb_addr = {0}; /* Copy destination address from FAR */ memcpy(&enb_addr.s6_addr, ((sess_data[i]->pdrs)->far)->frwdng_parms.outer_hdr_creation.ipv6_address, IPV6_ADDRESS_LEN); /* VS: Validate the Destination IPv6 Address Subnet */ struct in6_addr src_addr = {0}; /* Validate the Destination IPv6 Address Network */ if (validate_ipv6_network(enb_addr, app.wb_ipv6, app.wb_ipv6_prefix_len)) { /* Source interface IPv6 address */ memcpy(&src_addr, &app.wb_ipv6, sizeof(struct in6_addr)); } else if (validate_ipv6_network(enb_addr, app.wb_li_ipv6, app.wb_li_ipv6_prefix_len)) { /* Source interface IPv6 address */ memcpy(&src_addr, &app.wb_li_ipv6, sizeof(struct in6_addr)); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination S5S8 intf IPv6 addr "IPv6_FMT" " "is NOT in local intf Network\n", LOG_VALUE, IPv6_PRINT(enb_addr)); RESET_BIT(*pkts_mask, i); continue; } /* Translator to convert IPv4 header to IPv6 header */ if ((ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4))) { if (translator_ip_hdr(pkts[i], PRESENT)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to translate IP HDR from IPv4 to IPv6\n", LOG_VALUE); RESET_BIT(*pkts_mask, i); continue; } } /* Calculate the payload length */ len = rte_pktmbuf_data_len(pkts[i]); len = len - (ETH_HDR_SIZE + IPv6_HDR_SIZE); /* Update the GTP-U header teid of S5S8 PGWU */ ((struct gtpu_hdr *)get_mtogtpu_v6(pkts[i]))->teid = ntohl(((sess_data[i]->pdrs)->far)->frwdng_parms.outer_hdr_creation.teid); /* Fill the Source and Destination IP address in the IPv6 Header */ construct_ipv6_hdr(pkts[i], len, IP_PROTO_UDP, &src_addr, &enb_addr); /* Update the UDP checksum */ reset_udp_hdr_checksum(pkts[i], IPV6_TYPE); /* Fill the PDR info form the session data */ pdr[i] = sess_data[i]->pdrs; } } else { RESET_BIT(*pkts_mask, i); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Session Data don't have PDR info\n", LOG_VALUE); sess_data[i]->pdrs = NULL; pdr[i] = NULL; } } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Session Data not found\n", LOG_VALUE); } } } } void update_adc_rid_from_domain_lookup(uint32_t *rb, uint32_t *rc, uint32_t n) { uint32_t i; for (i = 0; i < n; i++) if (rc[i] != 0) rb[i] = rc[i]; } /** * @brief : create hash table. * @param : name, hash name * @param : rte_hash, pointer to store created hash * @param : entrie, entries to add in table * @param : key_len, key length * @return : Returns 0 in case of success , -1 otherwise */ int hash_create(const char *name, struct rte_hash **rte_hash, uint32_t entries, uint32_t key_len) { struct rte_hash_parameters rte_hash_params = { .name = name, .entries = entries, .key_len = key_len, .hash_func = DEFAULT_HASH_FUNC, .hash_func_init_val = 0, .socket_id = rte_socket_id(), }; *rte_hash = rte_hash_create(&rte_hash_params); if (*rte_hash == NULL) rte_exit(EXIT_FAILURE, "%s hash create failed: %s (%u)\n", rte_hash_params.name, rte_strerror(rte_errno), rte_errno); return 0; } /** * @brief : Get the system current timestamp. * @param : timestamp is used for storing system current timestamp * @return : Returns 0 in case of success */ static uint8_t get_timestamp(char *timestamp) { time_t t = time(NULL); struct tm *tmp = localtime(&t); strftime(timestamp, MAX_LEN, "%Y%m%d%H%M%S", tmp); return 0; } /** * @brief : Get pcap file name . * @param : east_file, store east interface pcap file name. * @param : west_file, store west interface pcap filw name. * @param : east_iface_name, file name. * @param : west_iface_name, file name. * @return : Returns 0 in case of success */ static void get_pcap_file_name(char *east_file, char *west_file, char *east_iface_name, char *west_iface_name) { char timestamp[MAX_LEN] = {0}; get_timestamp(timestamp); snprintf(east_file, MAX_LEN, "%s%s%s", east_iface_name, timestamp, PCAP_EXTENTION); snprintf(west_file, MAX_LEN, "%s%s%s", west_iface_name, timestamp, PCAP_EXTENTION); } void up_pcap_init(void) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Pcap files will be Created\n", LOG_VALUE); char east_file[PCAP_FILENAME_LEN] = {0}; char west_file[PCAP_FILENAME_LEN] = {0}; /* Fill the PCAP File Names */ get_pcap_file_name(east_file, west_file, DOWNLINK_PCAP_FILE, UPLINK_PCAP_FILE); pcap_dumper_east = init_pcap(east_file); pcap_dumper_west = init_pcap(west_file); } pcap_dumper_t * init_pcap(char* pcap_filename) { pcap_dumper_t *pcap_dumper = NULL; pcap_t *pcap = NULL; pcap = pcap_open_dead(DLT_EN10MB, UINT16_MAX); if ((pcap_dumper = pcap_dump_open(pcap, pcap_filename)) == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in opening Pcap file\n", LOG_VALUE); return NULL; } return pcap_dumper; } void dump_pcap(struct rte_mbuf **pkts, uint32_t n, pcap_dumper_t *pcap_dumper) { uint32_t i; for (i = 0; i < n; i++) { struct pcap_pkthdr pcap_hdr; uint8_t *pkt = rte_pktmbuf_mtod(pkts[i], uint8_t *); pcap_hdr.len = pkts[i]->pkt_len; pcap_hdr.caplen = pcap_hdr.len; gettimeofday(&(pcap_hdr.ts), NULL); pcap_dump((u_char *)pcap_dumper, &pcap_hdr, pkt); pcap_dump_flush((pcap_dumper_t *)pcap_dumper); } return; } /** * @brief : Close pcap file. * @param : void. * @return : Returns nothing */ static void close_up_pcap_dump(void) { if (pcap_dumper_west != NULL) { pcap_dump_close(pcap_dumper_west); pcap_dumper_west = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "PCAP : West Pcap Generaion Stop\n", LOG_VALUE); } if (pcap_dumper_east != NULL) { pcap_dump_close(pcap_dumper_east); pcap_dumper_east = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "PCAP : East Pcap Generaion Stop\n", LOG_VALUE); } } void up_pcap_dumper(pcap_dumper_t *pcap_dumper, struct rte_mbuf **pkts, uint32_t n) { if (app.generate_pcap == PCAP_GEN_ON && pcap_dumper != NULL) { dump_pcap(pkts, n, pcap_dumper); } } static void dump_core_pkts_in_pcap(struct rte_mbuf **pkts, uint32_t n, pcap_dumper_t *pcap_dumper, uint64_t *pkts_mask) { uint32_t i; for (i = 0; i < n; i++) { if (ISSET_BIT(*pkts_mask, i)) { struct pcap_pkthdr pcap_hdr; uint8_t *pkt = rte_pktmbuf_mtod(pkts[i], uint8_t *); pcap_hdr.len = pkts[i]->pkt_len; pcap_hdr.caplen = pcap_hdr.len; gettimeofday(&(pcap_hdr.ts), NULL); pcap_dump((u_char *)pcap_dumper, &pcap_hdr, pkt); pcap_dump_flush((pcap_dumper_t *)pcap_dumper); } } return; } void up_core_pcap_dumper(pcap_dumper_t *pcap_dumper, struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask) { if (app.generate_pcap == PCAP_GEN_ON && pcap_dumper != NULL) { dump_core_pkts_in_pcap(pkts, n, pcap_dumper, pkts_mask); } } static int update_periodic_timer_value(const int periodic_timer_value) { peerData *conn_data = NULL; const void *key; uint32_t iter = 0; app.periodic_timer = periodic_timer_value; if(conn_hash_handle != NULL) { while (rte_hash_iterate(conn_hash_handle, &key, (void **)&conn_data, &iter) >= 0) { /* If Initial timer value was set to 0, then start the timer */ if (!conn_data->pt.ti_ms) { conn_data->pt.ti_ms = (periodic_timer_value * 1000); if (startTimer( &conn_data->pt ) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Periodic Timer failed to start...\n", LOG_VALUE); } } else { conn_data->pt.ti_ms = (periodic_timer_value * 1000); } } } return 0; } static int update_transmit_timer_value(const int transmit_timer_value) { peerData *conn_data = NULL; const void *key; uint32_t iter = 0; app.transmit_timer = transmit_timer_value; if(conn_hash_handle != NULL) { while (rte_hash_iterate(conn_hash_handle, &key, (void **)&conn_data, &iter) >= 0) { /* If Initial timer value was set to 0, then start the timer */ if (!conn_data->tt.ti_ms) { conn_data->tt.ti_ms = (transmit_timer_value * 1000); if (startTimer( &conn_data->tt ) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Transmit Timer failed to start...\n", LOG_VALUE); } } else { conn_data->tt.ti_ms = (transmit_timer_value * 1000); } } } return 0; } int8_t fill_dp_configuration(dp_configuration_t *dp_configuration) { dp_configuration->dp_type = OSS_USER_PLANE; dp_configuration->restoration_params.transmit_cnt = app.transmit_cnt; dp_configuration->restoration_params.transmit_timer = app.transmit_timer; dp_configuration->restoration_params.periodic_timer = app.periodic_timer; dp_configuration->ddf2_port = app.ddf2_port; dp_configuration->ddf3_port = app.ddf3_port; strncpy(dp_configuration->ddf2_ip, app.ddf2_ip, IPV6_STR_LEN); strncpy(dp_configuration->ddf3_ip, app.ddf3_ip, IPV6_STR_LEN); strncpy(dp_configuration->ddf2_local_ip, app.ddf2_local_ip, IPV6_STR_LEN); strncpy(dp_configuration->ddf3_local_ip, app.ddf3_local_ip, IPV6_STR_LEN); strncpy(dp_configuration->wb_iface_name, app.wb_iface_name, MAX_LEN); strncpy(dp_configuration->eb_iface_name, app.eb_iface_name, MAX_LEN); dp_configuration->wb_li_mask = htonl(app.wb_li_mask); dp_configuration->wb_li_ip = htonl(app.wb_li_ip); dp_configuration->wb_li_ipv6 = app.wb_li_ipv6; dp_configuration->wb_li_ipv6_prefix_len = app.wb_li_ipv6_prefix_len; strncpy(dp_configuration->wb_li_iface_name, app.wb_li_iface_name, MAX_LEN); dp_configuration->eb_li_mask = htonl(app.eb_li_mask); dp_configuration->eb_li_ip = htonl(app.eb_li_ip); dp_configuration->eb_li_ipv6 = app.eb_li_ipv6; dp_configuration->eb_li_ipv6_prefix_len = app.eb_li_ipv6_prefix_len; strncpy(dp_configuration->eb_li_iface_name, app.eb_li_iface_name, MAX_LEN); dp_configuration->gtpu_seqnb_out = app.gtpu_seqnb_out; dp_configuration->gtpu_seqnb_in = app.gtpu_seqnb_in; dp_configuration->perf_flag = app.perf_flag; dp_configuration->numa_on = app.numa_on; dp_configuration->teidri_val = app.teidri_val; dp_configuration->teidri_timeout = app.teidri_timeout; dp_configuration->generate_pcap = app.generate_pcap; dp_configuration->dp_comm_ip.s_addr = dp_comm_ip.s_addr; dp_configuration->dp_comm_port = ntohs(dp_comm_port); dp_configuration->dp_comm_ipv6 = dp_comm_ipv6; dp_configuration->pfcp_ipv6_prefix_len = app.pfcp_ipv6_prefix_len; dp_configuration->wb_ip = htonl(app.wb_ip); dp_configuration->wb_mask = htonl(app.wb_mask); set_mac_value(dp_configuration->wb_mac, app.wb_ether_addr.addr_bytes); dp_configuration->wb_ipv6 = app.wb_ipv6; dp_configuration->wb_ipv6_prefix_len = app.wb_ipv6_prefix_len; dp_configuration->eb_ip = htonl(app.eb_ip); dp_configuration->eb_mask = htonl(app.eb_mask); set_mac_value(dp_configuration->eb_mac, app.eb_ether_addr.addr_bytes); dp_configuration->eb_ipv6 = app.eb_ipv6; dp_configuration->eb_ipv6_prefix_len = app.eb_ipv6_prefix_len; dp_configuration->wb_gw_ip = app.wb_gw_ip; dp_configuration->eb_gw_ip = app.eb_gw_ip; strncpy(dp_configuration->cli_rest_ip_buff, app.cli_rest_ip_buff, IPV6_STR_LEN); dp_configuration->cli_rest_port = app.cli_rest_port; return 0; } int8_t post_periodic_timer(const int periodic_timer_value) { update_periodic_timer_value(periodic_timer_value); return 0; } int8_t post_transmit_timer(const int transmit_timer_value) { update_transmit_timer_value(transmit_timer_value); return 0; } int8_t post_transmit_count(const int transmit_count) { app.transmit_cnt = transmit_count; return 0; } int8_t update_perf_flag(const int perf_flag) { app.perf_flag = perf_flag; return 0; } int8_t post_pcap_status(const int pcap_status) { if (app.generate_pcap == pcap_status) { return 1; } app.generate_pcap = pcap_status; switch (app.generate_pcap) { case PCAP_GEN_ON: { up_pcap_init(); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "PCAP : Open file for store Packet\n", LOG_VALUE); break; } case PCAP_GEN_OFF: { close_up_pcap_dump(); break; } case PCAP_GEN_RESTART: { close_up_pcap_dump(); up_pcap_init(); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "PCAP : Restarted Pcap generation\n", LOG_VALUE); app.generate_pcap = PCAP_GEN_ON; break; } default : app.generate_pcap = PCAP_GEN_OFF; break; } return 0; } int get_periodic_timer(void) { return app.periodic_timer; } int get_transmit_timer(void) { return app.transmit_timer; } int get_transmit_count(void) { return app.transmit_cnt; } int8_t get_pcap_status(void) { return app.generate_pcap; } uint8_t get_perf_flag(void) { return app.perf_flag; }
nikhilc149/e-utran-features-bug-fixes
dp/restoration_peer.c
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <unistd.h> #include <locale.h> #include <signal.h> #include <rte_ip.h> #include <rte_udp.h> #include <rte_mbuf.h> #include <sys/time.h> #include <rte_ether.h> #include <rte_common.h> #include <rte_branch_prediction.h> #include "up_main.h" #include "epc_arp.h" #include "teid_upf.h" #include "pfcp_util.h" #include "pfcp_set_ie.h" #include "pfcp_association.h" #include "ngic_timer.h" #include "gw_adapter.h" #include "gtpu.h" #define OFFSET 2208988800ULL /* Generate new pcap for s1u port */ extern pcap_dumper_t *pcap_dumper_west; extern pcap_dumper_t *pcap_dumper_east; extern int fd_array_v4[2]; extern int fd_array_v6[2]; static peer_addr_t dest_addr[2]; /* DP restart conuter */ extern uint8_t dp_restart_cntr; extern int clSystemLog; extern uint16_t dp_comm_port; /** * rte hash handler. */ /* 2 hash handles, one for S1U and another for SGI */ extern struct rte_hash *arp_hash_handle[NUM_SPGW_PORTS]; /* GW should allow/deny sending error indication pkts to peer node: 1:allow, 0:deny */ bool error_indication_snd; /** * @brief : memory pool for queued data pkts. */ static char *echo_mpoolname = { "echo_mpool", }; int32_t conn_cnt = 0; static uint16_t gtpu_seqnb = 0; static uint16_t gtpu_sgwu_seqnb = 0; static uint16_t gtpu_sx_seqnb = 1; /** * @brief : Connection hash params. */ static struct rte_hash_parameters conn_hash_params = { .name = "CONN_TABLE", .entries = NUM_CONN, .reserved = 0, .key_len = sizeof(node_address_t), .hash_func = rte_jhash, .hash_func_init_val = 0 }; /** * rte hash handler. * * hash handles connection for S1U, SGI and PFCP */ struct rte_hash *conn_hash_handle; const char *eth_addr(struct ether_addr *eth_h) { static char *str; snprintf(str, MAX_LEN, "%02X:%02X:%02X:%02X:%02X:%02X", eth_h->addr_bytes[0], eth_h->addr_bytes[1], eth_h->addr_bytes[2], eth_h->addr_bytes[3], eth_h->addr_bytes[4], eth_h->addr_bytes[5]); return str; } /** * @brief : Print ethernet address * @param : eth_h, ethernet address * @param : type, source or destination * @return : Returns nothing */ static void print_eth(struct ether_addr *eth_h, uint8_t type) { if (type == 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"\n ETH : src=%02X:%02X:%02X:%02X:%02X:%02X\n", LOG_VALUE, eth_h->addr_bytes[0], eth_h->addr_bytes[1], eth_h->addr_bytes[2], eth_h->addr_bytes[3], eth_h->addr_bytes[4], eth_h->addr_bytes[5]); } else if (type == 1) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"\n ETH : dst = %02X:%02X:%02X:%02X:%02X:%02X\n", LOG_VALUE, eth_h->addr_bytes[0], eth_h->addr_bytes[1], eth_h->addr_bytes[2], eth_h->addr_bytes[3], eth_h->addr_bytes[4], eth_h->addr_bytes[5]); } } /** * @brief : Send arp send * @param : conn_data, peer node connection information * @return : Returns 0 in case of success , -1 otherwise */ static uint8_t arp_req_send(peerData *conn_data) { if ((fd_array_v4[conn_data->portId] > 0) || (fd_array_v6[conn_data->portId] > 0)) { /* Buffer setting */ char tmp_buf[ARP_SEND_BUFF] = {0}; int k = 0; for(k = 0; k < ARP_SEND_BUFF; k++) { tmp_buf[k] = 'v'; } tmp_buf[ARP_SEND_BUFF] = 0; if (conn_data->dstIP.ip_type == IPV6_TYPE) { /* IPv6 */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Sendto neighbor solicitation IP: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(&conn_data->dstIP.ipv6_addr))); /* setting sendto destination addr */ dest_addr[conn_data->portId].ipv6.sin6_family = AF_INET6; memcpy(&dest_addr[conn_data->portId].ipv6.sin6_addr, &conn_data->dstIP.ipv6_addr, IPV6_ADDRESS_LEN); dest_addr[conn_data->portId].ipv6.sin6_port = htons(SOCKET_PORT); if ((sendto(fd_array_v6[conn_data->portId], tmp_buf, strlen(tmp_buf), 0, (struct sockaddr *) &dest_addr[conn_data->portId].ipv6, sizeof(struct sockaddr_in6))) < 0) { perror("IPv6:Send Failed:"); return -1; } } else { /* IPv4 */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Sendto ret arp data IP: %s\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&conn_data->dstIP.ipv4_addr)); /* setting sendto destination addr */ dest_addr[conn_data->portId].ipv4.sin_family = AF_INET; dest_addr[conn_data->portId].ipv4.sin_addr.s_addr = conn_data->dstIP.ipv4_addr; dest_addr[conn_data->portId].ipv4.sin_port = htons(SOCKET_PORT); /*TODO : change strlen with strnlen with proper size (n)*/ if ((sendto(fd_array_v4[conn_data->portId], tmp_buf, strlen(tmp_buf), 0, (struct sockaddr *)&dest_addr[conn_data->portId].ipv4, sizeof(struct sockaddr_in))) < 0) { perror("IPv4:Send Failed"); return -1; } } } return 0; } uint8_t get_dp_restart_cntr(void) { FILE *fd = NULL; int tmp_rstcnt = 0; if ((fd = fopen(FILE_NAME, "r")) == NULL ) { /* Creating new file */ if ((fd = fopen(FILE_NAME,"w")) == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error! creating dp_rstCnt.txt file\n", LOG_VALUE); } return tmp_rstcnt; } /* */ if (fscanf(fd,"%d", &tmp_rstcnt) < 0) { fclose(fd); RTE_LOG(NOTICE, DP, "DP Restart Count : %d\n", tmp_rstcnt); return tmp_rstcnt; } fclose(fd); RTE_LOG(NOTICE, DP, "DP Restart Count : %d\n", tmp_rstcnt); return tmp_rstcnt; } void update_dp_restart_cntr(void) { FILE *fd; if ((fd = fopen(FILE_NAME,"w")) == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error! creating dp_rstCnt.txt file\n", LOG_VALUE); } fseek(fd, 0L, SEEK_SET); fprintf(fd, "%d\n", ++dp_restart_cntr); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Updated restart counter Value of rstcnt: %d\n", LOG_VALUE, dp_restart_cntr); fclose(fd); } void timerCallback( gstimerinfo_t *ti, const void *data_t ) { peerData *md = (peerData*)data_t; struct rte_mbuf *pkt = rte_pktmbuf_alloc(echo_mpool); /* CLI Address buffer */ peer_address_t peer_addr; if (md->dstIP.ip_type == IPV6_TYPE) { memcpy(&peer_addr.ipv6.sin6_addr, &md->dstIP.ipv6_addr, IPV6_ADDR_LEN); peer_addr.type = IPV6_TYPE; } else { peer_addr.ipv4.sin_addr.s_addr = md->dstIP.ipv4_addr; peer_addr.type = IPV4_TYPE; } (md->dstIP.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"%s - %s: IPv6:"IPv6_FMT":%u.%s (%dms) has expired\n", LOG_VALUE, getPrintableTime(), md->name, IPv6_PRINT(IPv6_CAST(md->dstIP.ipv6_addr)), md->portId, ti == &md->pt ? "Periodic_Timer" : ti == &md->tt ? "Transmit_Timer" : "unknown", ti->ti_ms ): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"%s - %s: IPv4:%s:%u.%s (%dms) has expired\n", LOG_VALUE, getPrintableTime(), md->name, inet_ntoa(*(struct in_addr *)&md->dstIP.ipv4_addr), md->portId, ti == &md->pt ? "Periodic_Timer" : ti == &md->tt ? "Transmit_Timer" : "unknown", ti->ti_ms ); md->itr = app.transmit_cnt; if (md->itr_cnt == md->itr) { /* Stop transmit timer for specific Peer Node */ stopTimer( &md->tt ); /* Stop periodic timer for specific Peer Node */ stopTimer( &md->pt ); /* Deinit transmit timer for specific Peer Node */ deinitTimer( &md->tt ); /* Deinit transmit timer for specific Peer Node */ deinitTimer( &md->pt ); if (md->dstIP.ip_type == IPV6_TYPE) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Stopped Periodic/transmit timer, peer node IPv6 "IPv6_FMT" is not reachable\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(md->dstIP.ipv6_addr))); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Peer node IPv6 "IPv6_FMT" is not reachable\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(md->dstIP.ipv6_addr))); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Stopped Periodic/transmit timer, peer node IPv4 %s is not reachable\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&md->dstIP.ipv4_addr)); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Peer node IPv4 %s is not reachable\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&md->dstIP.ipv4_addr)); } update_peer_status(&peer_addr, FALSE); delete_cli_peer(&peer_addr); if ((md->portId == S1U_PORT_ID) || (md->portId == SGI_PORT_ID)) { del_entry_from_hash(&md->dstIP); #ifdef USE_CSID if (md->portId == S1U_PORT_ID) { up_del_pfcp_peer_node_sess(&md->dstIP, S1U_PORT_ID); } else { up_del_pfcp_peer_node_sess(&md->dstIP, SGI_PORT_ID); } #endif /* USE_CSID */ } else if (md->portId == SX_PORT_ID) { delete_entry_heartbeat_hash(&md->dstIP); #ifdef USE_CSID up_del_pfcp_peer_node_sess(&md->dstIP, SX_PORT_ID); #endif /* USE_CSID */ } return; } if (md->activityFlag == 1) { (md->dstIP.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Channel is active for NODE IPv6:"IPv6_FMT", No need to send echo to it's peer node\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(md->dstIP.ipv6_addr))) : clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Channel is active for NODE IPv4:%s, No need to send echo to it's peer node\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&md->dstIP.ipv4_addr)); /* Reset activity flag */ md->activityFlag = 0; md->itr_cnt = 0; /* Stop Timer transmit timer for specific Peer Node */ stopTimer( &md->tt ); /* Stop Timer periodic timer for specific Peer Node */ stopTimer( &md->pt ); /* VS: Restet Periodic Timer */ if ( startTimer( &md->pt ) < 0) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Periodic Timer failed to start\n", LOG_VALUE); return; } if (md->portId == SX_PORT_ID) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Send PFCP HeartBeat Request to "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(md->dstIP.ipv6_addr))); /* Socket Address buffer */ peer_addr_t dest_addr_t = {0}; if (md->dstIP.ip_type == IPV6_TYPE) { dest_addr_t.type = IPV6_TYPE; dest_addr_t.ipv6.sin6_family = AF_INET6; memcpy(&dest_addr_t.ipv6.sin6_addr.s6_addr, &md->dstIP.ipv6_addr, IPV6_ADDR_LEN); dest_addr_t.ipv6.sin6_port = dp_comm_port; } else { dest_addr_t.type = IPV4_TYPE; dest_addr_t.ipv4.sin_family = AF_INET; dest_addr_t.ipv4.sin_addr.s_addr = md->dstIP.ipv4_addr; dest_addr_t.ipv4.sin_port = dp_comm_port; } if (ti == &md->pt){ gtpu_sx_seqnb = get_pfcp_sequence_number(PFCP_HEARTBEAT_REQUEST, gtpu_sx_seqnb);; } /* Send heartbeat request to peer node */ process_pfcp_heartbeat_req(dest_addr_t, gtpu_sx_seqnb); if (ti == &md->tt) { (md->itr_cnt)++; update_peer_timeouts(&peer_addr, md->itr_cnt); } if (ti == &md->pt) { if ( startTimer( &md->tt ) < 0) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Transmit Timer failed to start\n", LOG_VALUE); /* Stop periodic timer for specific Peer Node */ stopTimer( &md->pt ); } return; } if (md->dst_eth_addr.addr_bytes[0] == 0) { int ret; struct arp_ip_key arp_key = {0}; struct arp_entry_data *ret_data = NULL; /* Fill the Arp Key */ if (md->dstIP.ip_type == IPV6_TYPE) { /* IPv6: ARP Key */ arp_key.ip_type.ipv6 = PRESENT; memcpy(&arp_key.ip_addr.ipv6.s6_addr, &md->dstIP.ipv6_addr, IPV6_ADDR_LEN); } else { /* IPv4: ARP Key */ arp_key.ip_type.ipv4 = PRESENT; arp_key.ip_addr.ipv4 = md->dstIP.ipv4_addr; } ret = rte_hash_lookup_data(arp_hash_handle[md->portId], &arp_key, (void **)&ret_data); if (ret < 0) { (md->dstIP.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP is not resolved for NODE IPv6:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(md->dstIP.ipv6_addr))) : clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP is not resolved for NODE IPv4:%s\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&md->dstIP.ipv4_addr)); /* Send Arp request to peer node through linux kernal */ if ((arp_req_send(md)) < 0) { (md->dstIP.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to send ARP request to Node IPv6:%s\n",LOG_VALUE, IPv6_PRINT(IPv6_CAST(md->dstIP.ipv6_addr))): clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to send ARP request to Node IPv4:%s\n",LOG_VALUE, inet_ntoa(*(struct in_addr *)&md->dstIP)); } return; } ether_addr_copy(&ret_data->eth_addr, &md->dst_eth_addr); if (md->portId == S1U_PORT_ID) { if (ti == &md->pt) gtpu_seqnb++; build_echo_request(pkt, md, gtpu_seqnb); } else if(md->portId == SGI_PORT_ID) { if (ti == &md->pt) gtpu_sgwu_seqnb++; build_echo_request(pkt, md, gtpu_sgwu_seqnb); } } else { if (md->portId == S1U_PORT_ID) { if (ti == &md->pt) gtpu_seqnb++; build_echo_request(pkt, md, gtpu_seqnb); } else if(md->portId == SGI_PORT_ID) { if (ti == &md->pt) gtpu_sgwu_seqnb++; build_echo_request(pkt, md, gtpu_sgwu_seqnb); } } if(pkt == NULL) { return; } if (md->portId == S1U_PORT_ID) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Pkts enqueue for S1U port\n", LOG_VALUE); if (rte_ring_enqueue(shared_ring[S1U_PORT_ID], pkt) == -ENOBUFS) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Can't queue PKT ring full" " Dropping pkt\n", LOG_VALUE); } else { update_cli_stats(&peer_addr, GTPU_ECHO_REQUEST, SENT, S1U); } if (ti == &md->tt) { (md->itr_cnt)++; update_peer_timeouts(&peer_addr, md->itr_cnt); } } else if(md->portId == SGI_PORT_ID) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"PKTS enqueue for SGI port\n", LOG_VALUE); if (rte_ring_enqueue(shared_ring[SGI_PORT_ID], pkt) == -ENOBUFS) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Can't queue PKT ring full so dropping PKT\n", LOG_VALUE); } else { update_cli_stats(&peer_addr, GTPU_ECHO_REQUEST, SENT, S5S8); } if (ti == &md->tt) { (md->itr_cnt)++; update_peer_timeouts(&peer_addr, md->itr_cnt); } } if (ti == &md->pt) { if ( startTimer( &md->tt ) < 0) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Transmit Timer failed to start\n", LOG_VALUE); /* Stop periodic timer for specific Peer Node */ stopTimer( &md->pt ); } } uint8_t add_node_conn_entry(node_address_t dstIp, uint64_t sess_id, uint8_t portId) { int ret = 0; peerData *conn_data = NULL; struct arp_entry_data *ret_conn_data = NULL; struct arp_ip_key arp_key = {0}; /* Cli Struct */ peer_address_t address; CLIinterface it; /* Validate the IP Type*/ if ((dstIp.ip_type != IPV6_TYPE) && (dstIp.ip_type != IPV4_TYPE)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERR: Not setting appropriate IP Type(IPv4:1 or IPv6:2)," "IP_TYPE:%u\n", LOG_VALUE, dstIp.ip_type); return -1; } ret = rte_hash_lookup_data(conn_hash_handle, &dstIp, (void **)&conn_data); if ( ret < 0) { (dstIp.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Add entry in conn table IPv6:"IPv6_FMT", up_seid:%lu\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(dstIp.ipv6_addr)), sess_id) : clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Add entry in conn table IPv4:"IPV4_ADDR", up_seid:%lu\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(dstIp.ipv4_addr), sess_id); /* No conn entry for dstIp * Add conn_data for dstIp at * conn_hash_handle * */ conn_data = rte_malloc_socket(NULL, sizeof(peerData), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (conn_data == NULL ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to allocate memory for connection data entry : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return -1; } if (portId == S1U_PORT_ID) { /* CLI: Setting interface details */ it = S1U; if (dstIp.ip_type == IPV6_TYPE) { /* Validate the Destination IPv6 Address Network */ if (validate_ipv6_network(IPv6_CAST(dstIp.ipv6_addr), app.wb_ipv6, app.wb_ipv6_prefix_len)) { memcpy(&(conn_data->srcIP).ipv6_addr, &app.wb_ipv6.s6_addr, IPV6_ADDR_LEN); } else if (validate_ipv6_network(IPv6_CAST(dstIp.ipv6_addr), app.wb_li_ipv6, app.wb_li_ipv6_prefix_len)) { memcpy(&(conn_data->srcIP).ipv6_addr, &app.wb_li_ipv6.s6_addr, IPV6_ADDR_LEN); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination IPv6 Addr "IPv6_FMT" is NOT in local intf subnet\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(dstIp.ipv6_addr))); return -1; } /* Set the IP Type of the Source IP */ (conn_data->srcIP).ip_type = IPV6_TYPE; } else if (dstIp.ip_type == IPV4_TYPE) { /* Validate the Destination IPv4 Address subnet */ if (validate_Subnet(ntohl(dstIp.ipv4_addr), app.wb_net, app.wb_bcast_addr)) { (conn_data->srcIP).ipv4_addr = htonl(app.wb_ip); } else if (validate_Subnet(ntohl(dstIp.ipv4_addr), app.wb_li_net, app.wb_li_bcast_addr)) { (conn_data->srcIP).ipv4_addr = htonl(app.wb_li_ip); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination IPv4 Addr "IPV4_ADDR" is NOT in local intf subnet\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(dstIp.ipv4_addr)); return -1; } /* Set the IP Type of the Source IP */ (conn_data->srcIP).ip_type = IPV4_TYPE; } /* Fill the source physical address */ conn_data->src_eth_addr = app.wb_ether_addr; } else if (portId == SGI_PORT_ID) { /* CLI: Setting interface details */ it = S5S8; if (dstIp.ip_type == IPV6_TYPE) { /* Validate the Destination IPv6 Address Network */ if (validate_ipv6_network(IPv6_CAST(dstIp.ipv6_addr), app.eb_ipv6, app.eb_ipv6_prefix_len)) { memcpy(&(conn_data->srcIP).ipv6_addr, &app.eb_ipv6.s6_addr, IPV6_ADDR_LEN); } else if (validate_ipv6_network(IPv6_CAST(dstIp.ipv6_addr), app.eb_li_ipv6, app.eb_li_ipv6_prefix_len)) { memcpy(&(conn_data->srcIP).ipv6_addr, &app.eb_li_ipv6.s6_addr, IPV6_ADDR_LEN); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination IPv6 Addr "IPv6_FMT" is NOT in local intf subnet\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(dstIp.ipv6_addr))); return -1; } /* Set the IP Type of the Source IP */ (conn_data->srcIP).ip_type = IPV6_TYPE; } else if (dstIp.ip_type == IPV4_TYPE) { /* Validate the Destination IPv4 Address subnet */ if (validate_Subnet(ntohl(dstIp.ipv4_addr), app.eb_net, app.eb_bcast_addr)) { (conn_data->srcIP).ipv4_addr = htonl(app.eb_ip); } else if (validate_Subnet(ntohl(dstIp.ipv4_addr), app.eb_li_net, app.eb_li_bcast_addr)) { (conn_data->srcIP).ipv4_addr = htonl(app.eb_li_ip); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Destination IPv4 Addr "IPV4_ADDR" is NOT in local intf subnet\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(dstIp.ipv4_addr)); return -1; } /* Set the IP Type of the Source IP */ (conn_data->srcIP).ip_type = IPV4_TYPE; } /* Fill the source physical address */ conn_data->src_eth_addr = app.eb_ether_addr; } /* CLI: Setting interface details */ if (portId == SX_PORT_ID) { it = SX; } conn_data->portId = portId; conn_data->activityFlag = 0; conn_data->dstIP = dstIp; conn_data->itr = app.transmit_cnt; conn_data->itr_cnt = 0; /* Fill the info for CLI and ARP Key */ if (dstIp.ip_type == IPV6_TYPE) { memcpy(&address.ipv6.sin6_addr, &dstIp.ipv6_addr, IPV6_ADDR_LEN); address.type = IPV6_TYPE; /* IPv6: ARP Key */ arp_key.ip_type.ipv6 = PRESENT; memcpy(&arp_key.ip_addr.ipv6.s6_addr, &dstIp.ipv6_addr, IPV6_ADDR_LEN); } else if (dstIp.ip_type == IPV4_TYPE) { address.ipv4.sin_addr.s_addr = dstIp.ipv4_addr; address.type = IPV4_TYPE; /* IPv4: ARP Key */ arp_key.ip_type.ipv4 = PRESENT; arp_key.ip_addr.ipv4 = dstIp.ipv4_addr; } /* Retrieve the destination interface MAC Address */ if ((portId == S1U_PORT_ID) || (portId == SGI_PORT_ID)) { ret = rte_hash_lookup_data(arp_hash_handle[portId], &arp_key, (void **)&ret_conn_data); if (ret < 0) { if ((arp_req_send(conn_data)) < 0) { (conn_data->dstIP.ip_type == IPV6_TYPE)? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to send neighbor solicitaion request to Node:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(conn_data->dstIP.ipv6_addr))) : clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to send ARP request to Node:%s\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&conn_data->dstIP.ipv4_addr)); } } else { (dstIp.ip_type == IPV6_TYPE)? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP Entry found for IPv6:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(conn_data->dstIP.ipv6_addr))) : clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP Entry found for IPv4:%s\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&conn_data->dstIP.ipv4_addr)); ether_addr_copy(&ret_conn_data->eth_addr, &conn_data->dst_eth_addr); } } /* VS: Add peer node entry in connection hash table */ if ((rte_hash_add_key_data(conn_hash_handle, &dstIp, conn_data)) < 0 ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry in hash table", LOG_VALUE); return -1; } /* Initialized Timer entry */ if (!initpeerData(conn_data, "PEER_NODE", (app.periodic_timer * 1000), (app.transmit_timer * 1000))) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"%s - initialization of %s failed\n", LOG_VALUE, getPrintableTime(), conn_data->name); return -1; } /* Add the entry for CLI stats */ add_cli_peer((peer_address_t *) &address, it); update_peer_status((peer_address_t *) &address, TRUE); /* Start periodic timer */ if ( startTimer( &conn_data->pt ) < 0) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Periodic Timer failed to start\n", LOG_VALUE); conn_cnt++; } else { (dstIp.ip_type == IPV6_TYPE)? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Conn entry already exit in conn table for IPv6:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*((struct in6_addr *)dstIp.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Conn entry already exit in conn table for IPv4:%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&dstIp))); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Current Active Conn Cnt:%u\n", LOG_VALUE, conn_cnt); return 0; } void echo_table_init(void) { /* Create conn_hash for maintain each port peer connection details */ /* Create arp_hash for each port */ conn_hash_params.socket_id = rte_socket_id(); conn_hash_handle = rte_hash_create(&conn_hash_params); if (!conn_hash_handle) { rte_panic("%s::" "\n\thash create failed::" "\n\trte_strerror= %s; rte_errno= %u\n", conn_hash_params.name, rte_strerror(rte_errno), rte_errno); } /* Create echo_pkt TX mmempool for each port */ echo_mpool = rte_pktmbuf_pool_create( echo_mpoolname, NB_ECHO_MBUF, 32, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); if (echo_mpool == NULL) { rte_panic("rte_pktmbuf_pool_create failed::" "\n\techo_mpoolname= %s;" "\n\trte_strerror= %s\n", echo_mpoolname, rte_strerror(abs(errno))); return; } } void rest_thread_init(void) { echo_table_init(); sigset_t sigset; /* mask SIGALRM in all threads by default */ sigemptyset(&sigset); sigaddset(&sigset, SIGRTMIN + 1); sigaddset(&sigset, SIGUSR1); sigprocmask(SIG_BLOCK, &sigset, NULL); if (!gst_init()) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"%s - gstimer_init() failed!!\n", LOG_VALUE, getPrintableTime() ); rte_panic(LOG_FORMAT"Cration of timer thread failed.\n", LOG_VALUE); } } void teidri_timer_cb(gstimerinfo_t *ti, const void *data_t ) { int ret = 0; /* send the error indication, if bearer context not found */ error_indication_snd = TRUE; #pragma GCC diagnostic push /* require GCC 4.6 */ #pragma GCC diagnostic ignored "-Wcast-qual" peerData *data = (peerData *) data_t; #pragma GCC diagnostic pop /* require GCC 4.6 */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"TEIDRI Timer Callback Start \n", LOG_VALUE); /* flush data for inactive peers and recreate file with data of active peers*/ ret = flush_inactive_teidri_data(TEIDRI_FILENAME, &upf_teidri_blocked_list, &upf_teidri_allocated_list, &upf_teidri_free_list, app.teidri_val); if(ret != 0){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error in flushing data of inactive peers\n", LOG_VALUE); } if(data->pt.ti_id != 0) { stoptimer(&data->pt.ti_id); deinittimer(&data->pt.ti_id); } if (data != NULL) { rte_free(data); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"TEIDRI Timer Stop and Deinit : successfully \n", LOG_VALUE); } /* Function to add and start timer for flush the inactive teidri and peer node address from file, * and put active teidri and peer node address into file */ bool start_dp_teidri_timer(void) { peerData *timer_entry = NULL; /* Allocate the memory. */ timer_entry = rte_zmalloc_socket(NULL, sizeof(peerData), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(timer_entry == NULL ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to allocate timer entry : %s \n", LOG_VALUE, rte_strerror(rte_errno)); return false; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Init TEIDRI Timer Start \n", LOG_VALUE); if (!init_timer(timer_entry, app.teidri_timeout, teidri_timer_cb)){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Initialization of TEIDRI Timer failed erro no %d\n", LOG_VALUE, getPrintableTime(), errno); return false; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Init TEIDRI Timer END \n", LOG_VALUE); if (starttimer(&timer_entry->pt) < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"TEIDRI Timer failed to start\n", LOG_VALUE); return false; } /* Don't send the error indication */ error_indication_snd = FALSE; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"TEIDRI Timer Started successfully \n", LOG_VALUE); return true; }
nikhilc149/e-utran-features-bug-fixes
oss_adapter/libepcadapter/include/cstats.h
/* * Copyright (c) 2019 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __CSTATS_H #define __CSTATS_H #ifdef __cplusplus extern "C" { #endif #include "gw_structs.h" /* Function */ /** * @brief: intializing statstics timer * @param: void * @return: nothing */ void statTimerInit(void); /* Function */ /** * @brief: get interval * @param: response * @return: sucess code */ int csGetInterval(char **response); /* Function */ /** * @brief: get stats logging * @param: response * @return: sucess code */ int csGetStatLogging(char **response); /* Function */ /** * @brief: update stats logging * @param: json value * @param: response * @return: on sucess return sucess code and on fail return error code */ int csUpdateStatLogging(const char *json, char **response); /* Function */ /** * @brief: update interval frequency * @param: json value * @param: response * @return: on sucess return sucess code and on fail return error code */ int csUpdateInterval(const char *json, char **response); /* Function */ /** * @brief: get stats live * @param: response * @return: sucess code */ int csGetLive(char **response); /* Function */ /** * @brief: all gateway supported stats * @param: response * @return: sucess code */ int csGetLiveAll(char **response); /* Function */ /** * @brief: reset the stats * @param: json value * @param: response * @return: on sucess return sucess code and on fail return error code */ int csResetStats(const char *json, char **response); /* Function */ /** * @brief: cli intialization * @param: command line interface node * @param: peer count * @return: nothing */ void cli_init(cli_node_t *cli_node, int *cnt_peer); /* Function */ /** * @brief: get number of request tries * @param: response * @param: request tries * @return: sucess code */ int get_number_of_request_tries(char **response, int request_tries); /* Function */ /** * @brief: get transmit count value * @param: response * @param: transmit count value * @return: sucess code */ int get_number_of_transmit_count(char **response, int transmit_count); /* Function */ /** * @brief: get transmit timer value * @param: response * @param: transmit timer value * @return: sucess code */ int get_transmit_timer_value(char **response, int transmit_timer_value); /* Function */ /** * @brief: get periodic value * @param: response * @param: periodic value * @return: sucess code */ int get_periodic_timer_value(char **response, int periodic_timer_value); /* Function */ /** * @brief: get request timeout value * @param: response * @param: request timeout value * @return: sucess code */ int get_request_timeout_value(char **response, int request_timeout); /* Function */ /** * @brief: get perf flag json resp * @param: response * @param: perf flag value * @return: sucess code */ int get_perf_flag_json_resp(char **response, int perf_flag); /* Function */ /** * @brief: get request tries value * @param: json value * @param: response * @return: request tries value */ int get_request_tries_value(const char *json, char **response); /* Function */ /** * @brief: get transmit count value * @param: json value * @param: response * @return: transmit count */ int get_transmit_count_value(const char *json, char **response); /* Function */ /** * @brief: get request timeout value * @param: json value * @param: response * @return: request timeout value */ int get_request_timeout_value_in_milliseconds(const char *json, char **response); /* Function */ /** * @brief: get transmit value * @param: json value * @param: response * @return: transmit timer value in sec */ int get_transmit_timer_value_in_seconds(const char *json, char **response); /* Function */ /** * @brief: get perf flag value * @param: json value * @param: response * @return: perf flag value in 0 or 1 */ int get_perf_flag_value_in_int(const char *json, char **response); /* Function */ /** * @brief: get periodic value * @param: json value * @param: response * @return: periodic timer value in sec */ int get_periodic_timer_value_in_seconds(const char *json, char **response); /* Function */ /** * @brief: to construct json * @param: parameter name * @param: parameter set value * @return: nothing */ void construct_json(const char *param,const char *value, char *buf); /* Function */ /** * @brief: return error response if cmd not supported * @param: gateway type * @param: response * @return: return error code */ int resp_cmd_not_supported(uint8_t gw_type, char **response); /* Function */ /** * @brief: return error response if post invalid value * @param: json * @param: response * @return: return error code */ int invalid_value_error_response(const char *json, char **response); /* Function */ /** * @brief: return error response if post invalid json string * @param: json * @param: response * @return: return rest code */ int check_valid_json(const char *json, char **response); /* Function */ /** * @brief: get pcap generation status. * @param: response * @param: pcap_gen_status, status of pcap generation. * @return: return error code */ int get_pcap_generation_status(char **response, uint8_t pcap_gen_status); /* Function */ /** * @brief: get pcap generation command value. * @param: json, json data. * @param: response, response vlue. * @return: return error code */ int get_pcap_generation_cmd_value(const char *json, char **response); /* Function */ /** * @brief: get cp configuration * @param: response * @param: cp config structure pointer * @return: return rest status */ int get_cp_configuration(char **response, cp_configuration_t *cp_config_ptr); /* Function */ /** * @brief: get dp configuration * @param: response * @param: dp config structure pointer * @return: return rest status */ int get_dp_configuration(char **response, dp_configuration_t *dp_config_ptr); #ifdef __cplusplus } #endif #endif /* __CSTATS_H */
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c_messages/create_session.c
<filename>cp/gtpv2c_messages/create_session.c /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <errno.h> #include <rte_debug.h> /* TODO: Verify */ #include "ue.h" #include "packet_filters.h" #include "gtp_messages.h" #include "gtpv2c_set_ie.h" #include "../cp_dp_api/vepc_cp_dp_api.h" #include "../pfcp_messages/pfcp_set_ie.h" #include "cp_config.h" #include "cp_stats.h" #include "sm_struct.h" #include "pfcp_set_ie.h" #include "gx.h" extern pfcp_config_t config; extern int clSystemLog; extern uint32_t num_adc_rules; extern uint32_t adc_rule_id[]; uint16_t set_create_session_response(gtpv2c_header_t *gtpv2c_tx, uint32_t sequence, ue_context *context, pdn_connection *pdn, uint8_t is_piggybacked) { int ret = 0; eps_bearer *bearer = NULL; upf_context_t *upf_ctx = NULL; create_sess_rsp_t cs_resp = {0}; struct resp_info *resp = NULL; uint8_t cause_value = 0; if ((ret = upf_context_entry_lookup(pdn->upf_ip, &upf_ctx)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: upx context not found %d\n", LOG_VALUE,ret); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Lookup Stored the session information. */ if (get_sess_entry(pdn->seid, &resp) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No session entry " "found for session id %lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } set_gtpv2c_teid_header((gtpv2c_header_t *)&cs_resp.header, GTP_CREATE_SESSION_RSP, context->s11_mme_gtpc_teid, sequence, is_piggybacked); if (context->cp_mode == SGWC) { if(context->indication_flag.oi == TRUE || pdn->proc == S1_HANDOVER_PROC) { cause_value = GTPV2C_CAUSE_REQUEST_ACCEPTED; } else { cause_value = resp->gtpc_msg.cs_rsp.cause.cause_value; } } else { if (pdn->requested_pdn_type == PDN_IP_TYPE_IPV4V6 && (config.ip_type_supported == IP_V4 || config.ip_type_supported == IP_V6)) { cause_value = GTPV2C_CAUSE_NEW_PDN_TYPE_NETWORK_PREFERENCE; } else if (pdn->requested_pdn_type == PDN_IP_TYPE_IPV4V6 && (config.ip_type_supported == IPV4V6_PRIORITY || (config.ip_type_supported == IPV4V6_DUAL && !(context->indication_flag.daf)))) { cause_value = GTPV2C_CAUSE_NEW_PDN_TYPE_SINGLE_ADDR_BEARER; } else { cause_value = GTPV2C_CAUSE_REQUEST_ACCEPTED; } } set_csresp_cause(&cs_resp.cause, cause_value, IE_INSTANCE_ZERO); if(context->change_report == TRUE && context->cp_mode == SGWC) { set_change_reporting_action(&cs_resp.chg_rptng_act, IE_INSTANCE_ZERO, context->change_report_action); }else if (context->cp_mode == SAEGWC || context->cp_mode == PGWC) { if (config.use_gx) { if(((context->event_trigger & (1 << ECGI_EVENT_TRIGGER)) != 0) || ((context->event_trigger & (1 << TAI_EVENT_TRIGGER)) != 0)) set_change_reporting_action(&cs_resp.chg_rptng_act, IE_INSTANCE_ZERO, START_REPORT_TAI_ECGI); } } if (context->cp_mode != PGWC) { if ((context->s11_sgw_gtpc_teid != 0) && (context->s11_sgw_gtpc_ip.ipv4_addr != 0 || *context->s11_sgw_gtpc_ip.ipv6_addr)) { set_gtpc_fteid(&cs_resp.sender_fteid_ctl_plane, GTPV2C_IFTYPE_S11S4_SGW_GTPC, IE_INSTANCE_ZERO, context->s11_sgw_gtpc_ip, context->s11_sgw_gtpc_teid); } } if (pdn->s5s8_pgw_gtpc_teid == 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "S5S8 PGW TEID is NULL\n", LOG_VALUE); } if(pdn->s5s8_pgw_gtpc_ip.ipv4_addr == 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "S5S8 PGW IP is NULL\n", LOG_VALUE); } set_gtpc_fteid(&cs_resp.pgw_s5s8_s2as2b_fteid_pmip_based_intfc_or_gtp_based_ctl_plane_intfc, GTPV2C_IFTYPE_S5S8_PGW_GTPC, IE_INSTANCE_ONE, pdn->s5s8_pgw_gtpc_ip, pdn->s5s8_pgw_gtpc_teid); set_paa(&cs_resp.paa, IE_INSTANCE_ZERO, pdn); set_apn_restriction(&cs_resp.apn_restriction, IE_INSTANCE_ZERO, pdn->apn_restriction); if(context->pra_flag){ set_presence_reporting_area_action_ie(&cs_resp.pres_rptng_area_act, context); context->pra_flag = 0; } cs_resp.bearer_count = 0; uint8_t index = 0; for(uint8_t i= 0; i< MAX_BEARERS; i++) { bearer = pdn->eps_bearers[i]; if(bearer == NULL) continue; cs_resp.bearer_count++; set_ie_header(&cs_resp.bearer_contexts_created[index].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_ebi(&cs_resp.bearer_contexts_created[index].eps_bearer_id, IE_INSTANCE_ZERO, bearer->eps_bearer_id); cs_resp.bearer_contexts_created[index].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; set_csresp_cause(&cs_resp.bearer_contexts_created[index].cause, cause_value, IE_INSTANCE_ZERO); cs_resp.bearer_contexts_created[index].header.len += sizeof(struct cause_ie_hdr_t) + IE_HEADER_SIZE; if (bearer->s11u_mme_gtpu_teid) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"S11U Detect- set_create_session_response-" "\n\tbearer->s11u_mme_gtpu_teid= %X;" "\n\tGTPV2C_IFTYPE_S11U_MME_GTPU= %X\n", LOG_VALUE, htonl(bearer->s11u_mme_gtpu_teid), GTPV2C_IFTYPE_S11U_SGW_GTPU); /* TODO: set fteid values to create session response member */ } else { if ((bearer->s1u_sgw_gtpu_teid != 0) && (upf_ctx->s1u_ip.ipv4_addr != 0 || *upf_ctx->s1u_ip.ipv6_addr)) { cs_resp.bearer_contexts_created[index].header.len += set_gtpc_fteid(&cs_resp.bearer_contexts_created[index].s1u_sgw_fteid, GTPV2C_IFTYPE_S1U_SGW_GTPU, IE_INSTANCE_ZERO, upf_ctx->s1u_ip, bearer->s1u_sgw_gtpu_teid); } } if ((bearer->s5s8_pgw_gtpu_teid != 0) && (bearer->s5s8_pgw_gtpu_ip.ipv4_addr != 0 || *bearer->s5s8_pgw_gtpu_ip.ipv6_addr)) { cs_resp.bearer_contexts_created[index].header.len += set_gtpc_fteid(&cs_resp.bearer_contexts_created[index].s5s8_u_pgw_fteid, GTPV2C_IFTYPE_S5S8_PGW_GTPU, IE_INSTANCE_TWO, bearer->s5s8_pgw_gtpu_ip, bearer->s5s8_pgw_gtpu_teid); } set_ie_header(&cs_resp.bearer_contexts_created[index].bearer_lvl_qos.header, GTP_IE_BEARER_QLTY_OF_SVC, IE_INSTANCE_ZERO, sizeof(gtp_bearer_qlty_of_svc_ie_t) - sizeof(ie_header_t)); cs_resp.bearer_contexts_created[index].bearer_lvl_qos.pvi = context->eps_bearers[i]->qos.arp.preemption_vulnerability; cs_resp.bearer_contexts_created[index].bearer_lvl_qos.spare2 = 0; cs_resp.bearer_contexts_created[index].bearer_lvl_qos.pl = context->eps_bearers[i]->qos.arp.priority_level; cs_resp.bearer_contexts_created[index].bearer_lvl_qos.pci = context->eps_bearers[i]->qos.arp.preemption_capability; cs_resp.bearer_contexts_created[index].bearer_lvl_qos.spare3 = 0; cs_resp.bearer_contexts_created[index].bearer_lvl_qos.qci = context->eps_bearers[i]->qos.qci; cs_resp.bearer_contexts_created[index].bearer_lvl_qos.max_bit_rate_uplnk = context->eps_bearers[i]->qos.ul_mbr; cs_resp.bearer_contexts_created[index].bearer_lvl_qos.max_bit_rate_dnlnk = context->eps_bearers[i]->qos.dl_mbr; cs_resp.bearer_contexts_created[index].bearer_lvl_qos.guarntd_bit_rate_uplnk = context->eps_bearers[i]->qos.ul_gbr; cs_resp.bearer_contexts_created[index].bearer_lvl_qos.guarntd_bit_rate_dnlnk = context->eps_bearers[i]->qos.dl_gbr; cs_resp.bearer_contexts_created[index].header.len += cs_resp.bearer_contexts_created[index].bearer_lvl_qos.header.len + sizeof(ie_header_t); index++; if(is_piggybacked){ break; } } /* End of for loop */ #ifdef USE_CSID if (context->cp_mode != PGWC) { fqcsid_t *csid = NULL; /* Get peer CSID associated with node */ csid = get_peer_addr_csids_entry(&pdn->mme_csid.node_addr, UPDATE_NODE); if ((csid != NULL) && (csid->num_csid)) { /* Set the SGW FQ-CSID */ if (pdn->sgw_csid.num_csid) { set_gtpc_fqcsid_t(&cs_resp.sgw_fqcsid, IE_INSTANCE_ONE, &pdn->sgw_csid); } /* Set the PGW FQ-CSID */ if (context->cp_mode != SAEGWC) { if (pdn->pgw_csid.num_csid) { set_gtpc_fqcsid_t(&cs_resp.pgw_fqcsid, IE_INSTANCE_ZERO, &pdn->pgw_csid); } } } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Note: Not found associated Local CSID, Peer_Addr:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(context->s11_mme_gtpc_ip.ipv4_addr)); } } else { if (pdn->pgw_csid.num_csid) { set_gtpc_fqcsid_t(&cs_resp.pgw_fqcsid, IE_INSTANCE_ZERO, &pdn->pgw_csid); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Note: Not found PGW associated CSID\n", LOG_VALUE); } } #endif /* USE_CSID */ uint16_t msg_len = 0; msg_len = encode_create_sess_rsp(&cs_resp, (uint8_t *)gtpv2c_tx); return msg_len; }
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/pfcp_session.c
<reponame>nikhilc149/e-utran-features-bug-fixes<filename>pfcp_messages/pfcp_session.c /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <math.h> #include "pfcp_util.h" #include "pfcp_enum.h" #include "pfcp_set_ie.h" #include "pfcp_session.h" #include "pfcp_messages.h" #include "pfcp_association.h" #include "pfcp_messages_encoder.h" #include "pfcp_messages_decoder.h" #include "li_config.h" #include "../cp_dp_api/tcp_client.h" #include "teid.h" #ifdef CP_BUILD #include "ue.h" #include "cp.h" #include "main.h" #include "pfcp.h" #include "ipc_api.h" #include "cp_stats.h" #include "cp_config.h" #include "gtpc_session.h" #include "gtp_messages.h" #include "gtpv2c_set_ie.h" #include "cp_timer.h" #include "cdr.h" #include "cp_app.h" #include "gtpv2c_error_rsp.h" #include "debug_str.h" extern int s5s8_fd; extern int s5s8_fd_v6; extern socklen_t s5s8_sockaddr_len; extern socklen_t s11_mme_sockaddr_ipv6_len; extern peer_addr_t s5s8_recv_sockaddr; extern socklen_t s11_mme_sockaddr_len; extern int clSystemLog; #endif /* CP_BUILD */ #ifdef DP_BUILD extern struct in_addr dp_comm_ip; #endif /* DP_BUILD */ #ifdef CP_BUILD pfcp_config_t config; #ifdef USE_CSID extern int s5s8_fd; extern int s5s8_fd_v6; extern socklen_t s5s8_sockaddr_len; extern socklen_t s5s8_sockaddr_ipv6_len; #endif /* USE_CSID */ extern int gx_app_sock; extern int gx_app_sock_v6; #define size sizeof(pfcp_sess_mod_req_t) /* Header Size of set_upd_forwarding_param ie */ extern int pfcp_fd; extern int pfcp_fd_v6; /* len of flags*/ #define FLAG_LEN 2 void fill_pfcp_sess_del_req( pfcp_sess_del_req_t *pfcp_sess_del_req, uint8_t cp_mode) { uint32_t seq = 1; memset(pfcp_sess_del_req, 0, sizeof(pfcp_sess_del_req_t)); seq = get_pfcp_sequence_number(PFCP_SESSION_DELETION_REQUEST, seq); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_del_req->header), PFCP_SESSION_DELETION_REQUEST, HAS_SEID, seq, cp_mode); } void add_pdr_qer_for_rule(eps_bearer *bearer, bool prdef_rule) { if (bearer == NULL || bearer->pdr_count == 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" No PDR found in the " "bearer, so can't increase it \n", LOG_VALUE); } for(int itr = 0; itr < NUMBER_OF_PDR_PER_RULE; itr++){ pdr_t *pdr_ctxt = NULL; pdr_ctxt = rte_zmalloc_socket(NULL, sizeof(pdr_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (pdr_ctxt == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for PDR structure, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return; } memcpy(pdr_ctxt, bearer->pdrs[itr], sizeof(pdr_t)); pdr_ctxt->urr_id_count = 1; pdr_ctxt->rule_id = generate_pdr_id(&bearer->pdn->context->pdr_rule_id_offset); pdr_ctxt->urr.urr_id_value = generate_urr_id(&bearer->pdn->context->urr_rule_id_offset); bearer->pdrs[bearer->pdr_count++] = pdr_ctxt; pdr_ctxt->create_far = NOT_PRESENT; pdr_ctxt->create_urr = PRESENT; int ret = add_pdr_entry(pdr_ctxt->rule_id, pdr_ctxt, bearer->pdn->seid); if ( ret != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error while adding " "PDR entry for Rule ID %d \n", LOG_VALUE, pdr_ctxt->rule_id); return; } } if (bearer->pdn->context->cp_mode != SGWC){ if(!prdef_rule){ for(uint8_t itr = bearer->qer_count; itr < bearer->qer_count + NUMBER_OF_QER_PER_RULE; itr++){ bearer->qer_id[itr].qer_id = generate_qer_id(&bearer->pdn->context->qer_rule_id_offset); fill_qer_entry(bearer->pdn, bearer, itr); } bearer->qer_count += NUMBER_OF_QER_PER_RULE; /* TODO: Added handling for QER Approprietly */ for(uint8_t itr1 = 0; itr1 < bearer->pdr_count; itr1++){ bearer->pdrs[itr1]->qer_id[0].qer_id = bearer->qer_id[itr1].qer_id; } } } return; } void fill_pfcp_gx_sess_mod_req( pfcp_sess_mod_req_t *pfcp_sess_mod_req, pdn_connection *pdn, uint16_t action, struct resp_info *resp) { int ret = 0; uint32_t seq = 0; eps_bearer *bearer = NULL; upf_context_t *upf_ctx = NULL; ue_context *context = NULL; int tmp_bearer_idx = 0; dynamic_rule_t rule = {0}; node_address_t node_value = {0}; if ((ret = upf_context_entry_lookup(pdn->upf_ip, &upf_ctx)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error while " "extracting upf context: %d \n", LOG_VALUE, ret); return; } memset(pfcp_sess_mod_req,0,sizeof(pfcp_sess_mod_req_t)); seq = get_pfcp_sequence_number(PFCP_SESSION_MODIFICATION_REQUEST, seq); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_mod_req->header), PFCP_SESSION_MODIFICATION_REQUEST, HAS_SEID, seq, pdn->context->cp_mode); pfcp_sess_mod_req->header.seid_seqno.has_seid.seid = pdn->dp_seid; /*Filling Node ID for F-SEID*/ if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV4) { uint8_t temp[IPV6_ADDRESS_LEN] = {0}; ret = fill_ip_addr(config.pfcp_ip.s_addr, temp, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV6) { ret = fill_ip_addr(0, config.pfcp_ip_v6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } set_fseid(&(pfcp_sess_mod_req->cp_fseid), pdn->seid, node_value); if ((pdn->context->cp_mode == PGWC) || (SAEGWC == pdn->context->cp_mode)) { for (int idx=0; idx < pdn->policy.count; idx++) { if(pdn->policy.pcc_rule[idx]->action == RULE_ACTION_ADD && action == RULE_ACTION_ADD){ if(pdn->policy.pcc_rule[idx]->predefined_rule){ bearer = get_bearer(pdn, &pdn->policy.pcc_rule[idx]->urule.pdef_rule.qos); }else{ bearer = get_bearer(pdn, &pdn->policy.pcc_rule[idx]->urule.dyn_rule.qos); } if(bearer == NULL) { /* * create dedicated bearer */ bearer = rte_zmalloc_socket(NULL, sizeof(eps_bearer), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to allocate bearer " "structure: %s (%s:%d)\n",LOG_VALUE, rte_strerror(rte_errno), __FILE__, __LINE__); return; } tmp_bearer_idx = (resp->bearer_count + MAX_BEARERS + 1); resp->eps_bearer_ids[resp->bearer_count++] = tmp_bearer_idx; int ebi_index = GET_EBI_INDEX(tmp_bearer_idx); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return; } bzero(bearer, sizeof(eps_bearer)); bearer->pdn = pdn; bearer->eps_bearer_id = tmp_bearer_idx; pdn->eps_bearers[ebi_index] = bearer; pdn->context->eps_bearers[ebi_index] = bearer; pdn->num_bearer++; fill_dedicated_bearer_info(bearer, pdn->context, pdn, pdn->policy.pcc_rule[idx]->predefined_rule); }else{ add_pdr_qer_for_rule(bearer, pdn->policy.pcc_rule[idx]->predefined_rule); } /*fill predefine rule*/ if(pdn->policy.pcc_rule[idx]->predefined_rule){ memcpy(&(bearer->qos), &(pdn->policy.pcc_rule[idx]->urule.pdef_rule.qos), sizeof(bearer_qos_ie)); memcpy(&rule, &pdn->policy.pcc_rule[idx]->urule.pdef_rule, sizeof(dynamic_rule_t)); bearer->prdef_rules[bearer->num_prdef_filters] = rte_zmalloc_socket(NULL, sizeof(dynamic_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (bearer->prdef_rules[bearer->num_prdef_filters] == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to " "allocate failure rule memory structure: %s\n",LOG_VALUE, rte_strerror(rte_errno)); return; } memcpy((bearer->prdef_rules[bearer->num_prdef_filters]), &(pdn->policy.pcc_rule[idx]->urule.pdef_rule), sizeof(dynamic_rule_t)); } else { memcpy(&(bearer->qos), &(pdn->policy.pcc_rule[idx]->urule.dyn_rule.qos), sizeof(bearer_qos_ie)); memcpy(&rule, &pdn->policy.pcc_rule[idx]->urule.dyn_rule, sizeof(dynamic_rule_t)); bearer->dynamic_rules[bearer->num_dynamic_filters] = rte_zmalloc_socket(NULL, sizeof(dynamic_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (bearer->dynamic_rules[bearer->num_dynamic_filters] == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to allocate dynamic rule memory " "structure: %s (%s:%d)\n",LOG_VALUE, rte_strerror(rte_errno), __FILE__, __LINE__); return; } memcpy( (bearer->dynamic_rules[bearer->num_dynamic_filters]), &(pdn->policy.pcc_rule[idx]->urule.dyn_rule), sizeof(dynamic_rule_t)); } fill_pfcp_entry(bearer, &rule); ret = get_ue_context(UE_SESS_ID(pdn->seid), &context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "get UE Context for teid : %d \n", LOG_VALUE, UE_SESS_ID(pdn->seid)); return; } fill_create_pfcp_info(pfcp_sess_mod_req, &rule, context, pdn->generate_cdr); if(pdn->policy.pcc_rule[idx]->predefined_rule) bearer->num_prdef_filters++; else bearer->num_dynamic_filters++; } else { if(pdn->policy.pcc_rule[idx]->action == RULE_ACTION_DELETE && action == RULE_ACTION_DELETE) { rule_name_key_t rule_name = {0}; memset(rule_name.rule_name, '\0', sizeof(rule_name.rule_name)); if(pdn->policy.pcc_rule[idx]->predefined_rule){ snprintf(rule_name.rule_name, RULE_NAME_LEN,"%s",pdn->policy.pcc_rule[idx]->urule.pdef_rule.rule_name); }else{ snprintf(rule_name.rule_name, RULE_NAME_LEN, "%s%d", pdn->policy.pcc_rule[idx]->urule.dyn_rule.rule_name, pdn->call_id); } int8_t bearer_id = get_rule_name_entry(rule_name); if (-1 == bearer_id) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "get bearer for rule_name : %s \n", LOG_VALUE, rule_name.rule_name); return; } resp->eps_bearer_ids[resp->bearer_count++] = bearer_id + NUM_EBI_RESERVED; if ((bearer_id + 1) == pdn->default_bearer_id) { for (uint8_t iCnt = 0; iCnt < MAX_BEARERS; ++iCnt) { if (NULL != pdn->eps_bearers[iCnt]) { fill_remove_pfcp_info(pfcp_sess_mod_req, pdn->eps_bearers[iCnt]); } } } else { fill_remove_pfcp_info(pfcp_sess_mod_req, pdn->eps_bearers[bearer_id]); } } } } } } static int predef_pfcp_actvt_predef_rules_ie_t(pfcp_actvt_predef_rules_ie_t *actvt_predef_rules, dynamic_rule_t *pdef_rules) { int len = 0; len = strnlen((char *)(&pdef_rules->rule_name), RULE_NAME_LEN); memcpy(&actvt_predef_rules->predef_rules_nm, &pdef_rules->rule_name, len); pfcp_set_ie_header( &(actvt_predef_rules->header), PFCP_IE_ACTVT_PREDEF_RULES, len); return (len + sizeof(pfcp_ie_header_t)); } static int fill_predef_rules_pdr(pfcp_create_pdr_ie_t *create_pdr, dynamic_rule_t *pdef_rules, int pdr_counter, uint8_t rule_indx) { if (pdef_rules == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Predefined SDF rules is NULL\n", LOG_VALUE); return -1; } /* Fill the appropriate predence value into PDR*/ create_pdr[pdr_counter].precedence.prcdnc_val = pdef_rules->precedence; if((create_pdr[pdr_counter].pdi.src_intfc.interface_value == SOURCE_INTERFACE_VALUE_ACCESS) && ((pdef_rules->flow_desc[rule_indx].flow_direction == TFT_DIRECTION_UPLINK_ONLY) || (pdef_rules->flow_desc[rule_indx].flow_direction == TFT_DIRECTION_BIDIRECTIONAL))) { /* Fill the Rule Name in the Active Predefined Rules*/ uint8_t len = predef_pfcp_actvt_predef_rules_ie_t( &create_pdr[pdr_counter].actvt_predef_rules[rule_indx], pdef_rules); create_pdr[pdr_counter].actvt_predef_rules_count++; create_pdr[pdr_counter].header.len += len; }else if((create_pdr[pdr_counter].pdi.src_intfc.interface_value == SOURCE_INTERFACE_VALUE_CORE) && ((pdef_rules->flow_desc[rule_indx].flow_direction == TFT_DIRECTION_DOWNLINK_ONLY) || (pdef_rules->flow_desc[rule_indx].flow_direction == TFT_DIRECTION_BIDIRECTIONAL))) { /* Fill the Rule Name in the Active Predefined Rules*/ uint8_t len = predef_pfcp_actvt_predef_rules_ie_t( &create_pdr[pdr_counter].actvt_predef_rules[rule_indx], pdef_rules); create_pdr[pdr_counter].actvt_predef_rules_count++; create_pdr[pdr_counter].header.len += len; } return 0; } int fill_create_pfcp_info(pfcp_sess_mod_req_t *pfcp_sess_mod_req, dynamic_rule_t *dyn_rule, ue_context *context, uint8_t gen_cdr) { int ret = 0; uint16_t len = 0; imsi_id_hash_t *imsi_id_config = NULL; pfcp_create_pdr_ie_t *pdr = NULL; pfcp_create_urr_ie_t *urr = NULL; pfcp_create_far_ie_t *far = NULL; pfcp_create_qer_ie_t *qer = NULL; /* get user level packet copying token or id using imsi */ ret = get_id_using_imsi(context->imsi, &imsi_id_config); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Not applicable for li\n", LOG_VALUE); } for(int i=0; i<NUMBER_OF_PDR_PER_RULE; i++) { int idx = pfcp_sess_mod_req->create_pdr_count; pdr = &(pfcp_sess_mod_req->create_pdr[idx]); urr = &(pfcp_sess_mod_req->create_urr[idx]); far = &(pfcp_sess_mod_req->create_far[idx]); if (gen_cdr) { pdr->urr_id_count = 1; //NK:per PDR there is one URR set_create_urr(urr, dyn_rule->pdr[i]); } if(!dyn_rule->predefined_rule){ qer = &(pfcp_sess_mod_req->create_qer[idx]); pdr->qer_id_count = 1; } set_create_pdr(pdr, dyn_rule->pdr[i], context->cp_mode); if(!dyn_rule->predefined_rule){ fill_create_pdr_sdf_rules(pfcp_sess_mod_req->create_pdr, dyn_rule, idx); } else { int itr = 0; fill_predef_rules_pdr(pdr, dyn_rule, itr, itr); } /* Condition check because for new rule * no need to create new FAR */ if(dyn_rule->pdr[i]->create_far == PRESENT) { /*Just need to forward the packets that's why disabling * all other supported action*/ dyn_rule->pdr[i]->far.actions.forw = PRESENT; dyn_rule->pdr[i]->far.actions.dupl = 0; dyn_rule->pdr[i]->far.actions.drop = 0; set_create_far(far, &dyn_rule->pdr[i]->far); len = set_destination_interface(&(far->frwdng_parms.dst_intfc), dyn_rule->pdr[i]->far.dst_intfc.interface_value); pfcp_set_ie_header(&(far->frwdng_parms.header), IE_FRWDNG_PARMS, len); far->frwdng_parms.header.len = len; len += UPD_PARAM_HEADER_SIZE; far->header.len += len; far->apply_action.forw = PRESENT; far->apply_action.dupl = GET_DUP_STATUS(context); len = 0; if ((context != NULL) && (imsi_id_config != NULL) && (imsi_id_config->cntr > 0)){ update_li_info_in_dup_params(imsi_id_config, context, far); } } if(!dyn_rule->predefined_rule){ set_create_qer(qer, &(dyn_rule->pdr[i]->qer)); qer->qer_id.qer_id_value = dyn_rule->pdr[i]->qer.qer_id; pfcp_sess_mod_req->create_qer_count++; } pfcp_sess_mod_req->create_pdr_count++; pfcp_sess_mod_req->create_urr_count++; pfcp_sess_mod_req->create_far_count++; } return 0; } int fill_remove_pfcp_info(pfcp_sess_mod_req_t *pfcp_sess_mod_req, eps_bearer *bearer) { pfcp_update_far_ie_t *far = NULL; for(int i=0; i<NUMBER_OF_PDR_PER_RULE; i++) { far = &(pfcp_sess_mod_req->update_far[pfcp_sess_mod_req->update_far_count]); /*Just need to Drop the packets that's why disabling * all other supported action*/ bearer->pdrs[i]->far.actions.forw = 0; bearer->pdrs[i]->far.actions.dupl = 0; bearer->pdrs[i]->far.actions.buff = 0; bearer->pdrs[i]->far.actions.nocp = 0; bearer->pdrs[i]->far.actions.drop = PRESENT; set_update_far(far, &bearer->pdrs[i]->far); pfcp_sess_mod_req->update_far_count++; } return 0; } int fill_update_pdr_sdf_rule(pfcp_update_pdr_ie_t* update_pdr, dynamic_rule_t *dyn_rule, int pdr_counter){ int sdf_filter_count = 0; update_pdr[pdr_counter].precedence.prcdnc_val = dyn_rule->precedence; /* itr is for flow information counter */ /* sdf_filter_count is for SDF information counter */ for(int itr = 0; itr < dyn_rule->num_flw_desc; itr++) { if(dyn_rule->flow_desc[itr].sdf_flow_description != NULL) { if((update_pdr[pdr_counter].pdi.src_intfc.interface_value == SOURCE_INTERFACE_VALUE_ACCESS) && ((dyn_rule->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_UPLINK_ONLY) || (dyn_rule->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_BIDIRECTIONAL))) { int len = sdf_pkt_filter_add(&update_pdr[pdr_counter].pdi, dyn_rule, sdf_filter_count, itr, TFT_DIRECTION_UPLINK_ONLY); update_pdr[pdr_counter].header.len += len; sdf_filter_count++; }else if((update_pdr[pdr_counter].pdi.src_intfc.interface_value == SOURCE_INTERFACE_VALUE_CORE) && ((dyn_rule->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_DOWNLINK_ONLY) || (dyn_rule->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_BIDIRECTIONAL))) { int len = sdf_pkt_filter_add(&update_pdr[pdr_counter].pdi, dyn_rule, sdf_filter_count, itr, TFT_DIRECTION_DOWNLINK_ONLY); update_pdr[pdr_counter].header.len += len; sdf_filter_count++; } } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "No SDF rules found " "while updating PDR sdf rule\n", LOG_VALUE); } } update_pdr[pdr_counter].pdi.sdf_filter_count = sdf_filter_count; return 0; } void remove_pdr_from_bearer(eps_bearer *bearer, uint16_t pdr_id_value){ int flag = 0; for(uint8_t itr = 0; itr < bearer->pdr_count ; itr++) { if(bearer->pdrs[itr]->rule_id == pdr_id_value){ flag = 1; } if(flag == 1 && itr != bearer->pdr_count - 1){ bearer->pdrs[itr] = bearer->pdrs[itr + 1]; } } if(flag == 1){ bearer->pdrs[bearer->pdr_count] = NULL; bearer->pdr_count--; } return; } void remove_qer_from_bearer(eps_bearer *bearer, uint16_t qer_id_value){ int flag = 0; for(uint8_t itr = 0; itr < bearer->qer_count ; itr++) { if(bearer->qer_id[itr].qer_id == qer_id_value){ flag = 1; } if(flag == 1 && itr != bearer->qer_count - 1){ bearer->qer_id[itr] = bearer->qer_id[itr + 1]; } } if(flag == 1){ bearer->qer_id[bearer->qer_count].qer_id = 0; bearer->qer_count--; } return; } int delete_pdr_qer_for_rule(eps_bearer *bearer, uint16_t pdr_id_value) { pdr_t *pdr_ctx = NULL; /*Delete all pdr, qer entry from table */ for(uint8_t itr = 0; itr < bearer->pdr_count ; itr++) { pdr_ctx = bearer->pdrs[itr]; if(pdr_ctx != NULL && pdr_ctx->rule_id == pdr_id_value) { rule_name_key_t key = {0}; snprintf(key.rule_name, RULE_NAME_LEN, "%s%d", pdr_ctx->rule_name, (bearer->pdn)->call_id); if(bearer->eps_bearer_id == get_rule_name_entry(key) + NUM_EBI_RESERVED){ if (del_rule_name_entry(key) != 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Error while deleting rule name entries\n", LOG_VALUE); } } remove_pdr_from_bearer(bearer, pdr_id_value); if( del_pdr_entry(pdr_ctx->rule_id, bearer->pdn->seid) != 0 ){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error while deleting PDR entry for Rule id : %d\n", LOG_VALUE, pdr_ctx->rule_id); } if (config.use_gx) { remove_qer_from_bearer(bearer, pdr_ctx->qer.qer_id); if(del_qer_entry(pdr_ctx->qer.qer_id, bearer->pdn->seid) != 0 ){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error while deleting QER entry for QER id : %d\n", LOG_VALUE, pdr_ctx->qer.qer_id); } } return 0; } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"No PDR entry found while deleting pdr\n", LOG_VALUE); } } return -1; } void fill_update_bearer_sess_mod(pfcp_sess_mod_req_t *pfcp_sess_mod_req, eps_bearer *bearer){ pdn_connection *pdn = bearer->pdn; for(int idx = 0; idx < pdn->policy.count; idx++){ for(int idx2 = 0; idx2 < bearer->pdr_count; idx2++){ if((pdn->policy.pcc_rule[idx]->action == bearer->action) && (strncmp(pdn->policy.pcc_rule[idx]->urule.dyn_rule.rule_name, bearer->pdrs[idx2]->rule_name, RULE_NAME_LEN) == 0)){ if(pdn->policy.pcc_rule[idx]->action == RULE_ACTION_MODIFY){ if(bearer->flow_desc_check == PRESENT && pdn->proc != HSS_INITIATED_SUB_QOS_MOD) { int index = pfcp_sess_mod_req->update_pdr_count; set_update_pdr(&(pfcp_sess_mod_req->update_pdr[index]), bearer->pdrs[idx2], pdn->context->cp_mode ); fill_update_pdr_sdf_rule(pfcp_sess_mod_req->update_pdr, &pdn->policy.pcc_rule[idx]->urule.dyn_rule, index); pfcp_sess_mod_req->update_pdr_count++; } if(bearer->qos_bearer_check == PRESENT) { int index2 = pfcp_sess_mod_req->update_qer_count; bearer->pdrs[idx2]->qer.qer_id = bearer->qer_id[idx2].qer_id; set_update_qer(&(pfcp_sess_mod_req->update_qer[index2]), &bearer->pdrs[idx2]->qer); pfcp_sess_mod_req->update_qer_count++; } }else if(pdn->policy.pcc_rule[idx]->action == RULE_ACTION_MODIFY_ADD_RULE){ /* A new rule to be added to Bearer already present */ int index = pfcp_sess_mod_req->create_pdr_count; int index2 = pfcp_sess_mod_req->create_qer_count; pfcp_sess_mod_req->create_pdr[index].qer_id_count = 1; if (pdn->generate_cdr) { pfcp_sess_mod_req->create_pdr[index].urr_id_count = 1; set_create_urr(&pfcp_sess_mod_req->create_urr[index], bearer->pdrs[idx2]); pfcp_sess_mod_req->create_urr_count++; } set_create_pdr(&pfcp_sess_mod_req->create_pdr[index], bearer->pdrs[idx2], pdn->context->cp_mode); fill_create_pdr_sdf_rules(pfcp_sess_mod_req->create_pdr, &pdn->policy.pcc_rule[idx]->urule.dyn_rule, index); set_create_urr(&pfcp_sess_mod_req->create_urr[index], bearer->pdrs[idx2]); set_create_qer(&pfcp_sess_mod_req->create_qer[index2], &(bearer->pdrs[idx2]->qer)); pfcp_sess_mod_req->create_pdr_count++; pfcp_sess_mod_req->create_urr_count++; pfcp_sess_mod_req->create_qer_count++; /* ADDING the rule in rule_bearer_id hash */ rule_name_key_t rule_name = {0}; memset(rule_name.rule_name, '\0', sizeof(rule_name.rule_name)); snprintf(rule_name.rule_name, RULE_NAME_LEN,"%s%d", pdn->policy.pcc_rule[idx]->urule.dyn_rule.rule_name, pdn->call_id); bearer_id_t *id; id = malloc(sizeof(bearer_id_t)); memset(id, 0 , sizeof(bearer_id_t)); int ebi_index = GET_EBI_INDEX(bearer->eps_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return; } id->bearer_id = ebi_index; /* Adding rule to Hash as Rule End in Update bearer */ if (add_rule_name_entry(rule_name, id) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error while adding rule name entry\n", LOG_VALUE); return; } }else if(pdn->policy.pcc_rule[idx]->action == RULE_ACTION_MODIFY_REMOVE_RULE){ /* A rule to be remove from Bearer already present */ int index = pfcp_sess_mod_req->remove_pdr_count; set_remove_pdr(&(pfcp_sess_mod_req->remove_pdr[index]), bearer->pdrs[idx2]->rule_id); pfcp_sess_mod_req->remove_pdr_count++; } } } } /* Reset these variable as for current rule all the action is taken*/ bearer->flow_desc_check = NOT_PRESENT; bearer->qos_bearer_check = NOT_PRESENT; bearer->arp_bearer_check = NOT_PRESENT; return; } void fill_pfcp_sess_mod_req( pfcp_sess_mod_req_t *pfcp_sess_mod_req, gtpv2c_header_t *header, eps_bearer **bearer, pdn_connection *pdn, pfcp_update_far_ie_t update_far[], uint8_t endmarker_flag, uint8_t bearer_count, ue_context *context) { uint32_t seq = 0; upf_context_t *upf_ctx = NULL; int ret = 0; node_address_t node_value = {0}; if ((ret = upf_context_entry_lookup(pdn->upf_ip, &upf_ctx)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error while extracting " "upf context: %d \n", LOG_VALUE, ret); return; } if( header != NULL) clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"header is null TEID[%d]\n", LOG_VALUE, header->teid.has_teid.teid); seq = get_pfcp_sequence_number(PFCP_SESSION_MODIFICATION_REQUEST, seq); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_mod_req->header), PFCP_SESSION_MODIFICATION_REQUEST, HAS_SEID, seq, context->cp_mode); pfcp_sess_mod_req->header.seid_seqno.has_seid.seid = pdn->dp_seid; /*Filling Node ID for F-SEID*/ if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV4) { uint8_t temp[IPV6_ADDRESS_LEN] = {0}; ret = fill_ip_addr(config.pfcp_ip.s_addr, temp, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV6) { ret = fill_ip_addr(0, config.pfcp_ip_v6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } set_fseid(&(pfcp_sess_mod_req->cp_fseid), pdn->seid, node_value); /* This depends on condition in pcrf data(pcrf will send bar_rule_id if it needs to be delated). Need to handle after pcrf integration*/ /* removing_bar(&(pfcp_sess_mod_req->remove_bar)); */ /************************************************ * cp_type count FTEID_1 FTEID_2 * ************************************************* In case MBR received from MME:- SGWC 1 enodeB - PGWC - - - SAEGWC 1 enodeB - ************************************************* In case of CSResp received from PGWC to SGWC :- SGWC <----CSResp--- PGWC | pfcp_sess_mod_req | v SGWU In above scenario: count = 1 , FTEID_1 = s5s8 PGWU ************************************************/ for (int iCnt= 0; iCnt < bearer_count; iCnt++ ) { uint8_t pdr_idx = 0; if (pfcp_sess_mod_req->create_pdr_count) { fill_pdr_far_qer_using_bearer(pfcp_sess_mod_req, bearer[iCnt], context, iCnt*NUMBER_OF_PDR_PER_RULE); /* This depends on condition if the CP function requests the UP function to create a new BAR Need to add condition to check if CP needs creation of BAR*/ for( int itr = pfcp_sess_mod_req->create_pdr_count - NUMBER_OF_PDR_PER_RULE; itr < pfcp_sess_mod_req->create_pdr_count; itr++) { if((pfcp_sess_mod_req->create_pdr[itr].header.len) && (pfcp_sess_mod_req->create_pdr[itr].far_id.header.len)) { for( int j = 0; j < pfcp_sess_mod_req->create_far_count ; j++) { if(pfcp_sess_mod_req->create_far[itr].bar_id.header.len) { /* TODO: Pass bar_id from pfcp_session_mod_req->create_far[i].bar_id.bar_id_value to set bar_id*/ //creating_bar(&(pfcp_sess_mod_req->create_bar)); } } } if (context->cp_mode == SGWC || context->cp_mode == SAEGWC) { pfcp_sess_mod_req->create_pdr[itr].pdi.local_fteid.teid = bearer[iCnt]->pdrs[pdr_idx]->pdi.local_fteid.teid ; /* TODO: Revisit this for change in yang */ if (bearer[iCnt]->pdrs[pdr_idx]->pdi.ue_addr.v4) { pfcp_sess_mod_req->create_pdr[itr].pdi.ue_ip_address.ipv4_address = bearer[iCnt]->pdrs[pdr_idx]->pdi.ue_addr.ipv4_address; } if (bearer[iCnt]->pdrs[pdr_idx]->pdi.ue_addr.v6) { memcpy(pfcp_sess_mod_req->create_pdr[itr].pdi.ue_ip_address.ipv6_address, bearer[iCnt]->pdrs[pdr_idx]->pdi.ue_addr.ipv6_address, IPV6_ADDRESS_LEN); } if (bearer[iCnt]->pdrs[pdr_idx]->pdi.local_fteid.v6) { pfcp_sess_mod_req->create_pdr[itr].pdi.local_fteid.ipv4_address = bearer[iCnt]->pdrs[pdr_idx]->pdi.local_fteid.ipv4_address; } if (bearer[iCnt]->pdrs[pdr_idx]->pdi.local_fteid.v6) { memcpy(pfcp_sess_mod_req->create_pdr[itr].pdi.local_fteid.ipv6_address, bearer[iCnt]->pdrs[pdr_idx]->pdi.local_fteid.ipv6_address, IPV6_ADDRESS_LEN); } pfcp_sess_mod_req->create_pdr[itr].pdi.src_intfc.interface_value = bearer[iCnt]->pdrs[pdr_idx]->pdi.src_intfc.interface_value; } pdr_idx++; } } /*Adding FAR IE*/ for(uint8_t itr1 = 0; itr1 < pfcp_sess_mod_req->update_far_count ; itr1++) { node_address_t update_far_node = {0}; set_update_far(&(pfcp_sess_mod_req->update_far[itr1]), NULL); ret = fill_ip_addr(update_far[itr1].upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[itr1].upd_frwdng_parms.outer_hdr_creation.ipv6_address, &update_far_node); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } pfcp_sess_mod_req->update_far[itr1].far_id.far_id_value = update_far[itr1].far_id.far_id_value; /*Reset Far action and updated accroding update far action */ for (uint8_t itr2 = 0; itr2 < bearer[itr1]->pdr_count; itr2++) { if (bearer[itr1]->pdrs[itr2]->far.dst_intfc.interface_value == update_far[itr1].upd_frwdng_parms.dst_intfc.interface_value) { memset(&bearer[itr1]->pdrs[itr2]->far.actions, 0, sizeof(apply_action)); bearer[itr1]->pdrs[itr2]->far.actions.forw = PRESENT; } } pfcp_sess_mod_req->update_far[itr1].apply_action.forw = PRESENT; pfcp_sess_mod_req->update_far[itr1].apply_action.dupl = GET_DUP_STATUS(pdn->context); if (pfcp_sess_mod_req->update_far[itr1].apply_action.forw == PRESENT) { uint16_t len = 0; len += set_upd_forwarding_param(&(pfcp_sess_mod_req->update_far[itr1].upd_frwdng_parms), update_far_node); /* Currently take as hardcoded value */ len += UPD_PARAM_HEADER_SIZE; pfcp_sess_mod_req->update_far[itr1].header.len += len; } pfcp_sess_mod_req->update_far[itr1].upd_frwdng_parms.outer_hdr_creation.teid = update_far[itr1].upd_frwdng_parms.outer_hdr_creation.teid; pfcp_sess_mod_req->update_far[itr1].upd_frwdng_parms.dst_intfc.interface_value = update_far[itr1].upd_frwdng_parms.dst_intfc.interface_value; if(endmarker_flag) { set_pfcpsmreqflags(&(pfcp_sess_mod_req->update_far[itr1].upd_frwdng_parms.pfcpsmreq_flags)); pfcp_sess_mod_req->update_far[itr1].upd_frwdng_parms.pfcpsmreq_flags.sndem = 1; pfcp_sess_mod_req->update_far[itr1].header.len += sizeof(struct pfcp_pfcpsmreq_flags_ie_t); pfcp_sess_mod_req->update_far[itr1].upd_frwdng_parms.header.len += sizeof(struct pfcp_pfcpsmreq_flags_ie_t); } #if 0 /* send remove bar if apply action is not set to buff and if barid is present in bearer */ if ((PRESENT == bearer[iCnt]->bar.bar_id) && (NOT_PRESENT == pfcp_sess_mod_req->update_far[itr1].apply_action.buff)) { bearer[iCnt]->bar.bar_id = NOT_PRESENT; bearer[iCnt]->bar.suggstd_buf_pckts_cnt.pckt_cnt_val = NOT_PRESENT; set_remove_bar(&(pfcp_sess_mod_req->remove_bar[itr1]), bearer[iCnt]->bar.bar_id); } #endif } }/*end of for loop*/ set_pfcpsmreqflags(&(pfcp_sess_mod_req->pfcpsmreq_flags)); /* This IE is included if one of DROBU and QAURR flag is set, excluding this IE since we are not setting any of this flag */ if(!pfcp_sess_mod_req->pfcpsmreq_flags.qaurr && !pfcp_sess_mod_req->pfcpsmreq_flags.drobu){ pfcp_sess_mod_req->pfcpsmreq_flags.header.len = 0; } /* This IE is included if QAURR flag is set (this flag is in PFCPSMReq-Flags IE) or Query URR IE is present, Adding check to exclud this IE if any of these condition is not satisfied*/ if(pfcp_sess_mod_req->pfcpsmreq_flags.qaurr || pfcp_sess_mod_req->query_urr_count){ set_query_urr_refernce(&(pfcp_sess_mod_req->query_urr_ref)); } } void sdf_pkt_filter_to_string(sdf_pkt_fltr *sdf_flow, char *sdf_str , uint8_t direction) { char local_ip[IPV6_STR_LEN]; char remote_ip[IPV6_STR_LEN]; if(sdf_flow->v4){ snprintf(local_ip, sizeof(local_ip), "%s", inet_ntoa(sdf_flow->ulocalip.local_ip_addr)); snprintf(remote_ip, sizeof(remote_ip), "%s", inet_ntoa(sdf_flow->uremoteip.remote_ip_addr)); }else if(sdf_flow->v6){ inet_ntop(AF_INET6, sdf_flow->ulocalip.local_ip6_addr.s6_addr, local_ip, IPV6_STR_LEN); inet_ntop(AF_INET6, sdf_flow->uremoteip.remote_ip6_addr.s6_addr, remote_ip, IPV6_STR_LEN); if(!sdf_flow->remote_ip_mask || sdf_flow->remote_ip_mask > DEFAULT_IPV6_MASK) sdf_flow->remote_ip_mask = DEFAULT_IPV6_MASK; if(!sdf_flow->local_ip_mask || sdf_flow->local_ip_mask > DEFAULT_IPV6_MASK) sdf_flow->local_ip_mask = DEFAULT_IPV6_MASK; } if(sdf_flow->v4){ if (direction == TFT_DIRECTION_DOWNLINK_ONLY) { snprintf(sdf_str, MAX_LEN, "%s/%"PRIu8" %s/%"PRIu8" %" PRIu16" : %"PRIu16" %"PRIu16" : %"PRIu16 " 0x%"PRIx8"/0x%"PRIx8"", local_ip, sdf_flow->local_ip_mask, remote_ip, sdf_flow->remote_ip_mask, (sdf_flow->local_port_low), (sdf_flow->local_port_high), (sdf_flow->remote_port_low), (sdf_flow->remote_port_high), sdf_flow->proto_id, sdf_flow->proto_mask); } else if (direction == TFT_DIRECTION_UPLINK_ONLY) { snprintf(sdf_str, MAX_LEN, "%s/%"PRIu8" %s/%"PRIu8" %" PRIu16" : %"PRIu16" %"PRIu16" : %"PRIu16 " 0x%"PRIx8"/0x%"PRIx8"", local_ip, sdf_flow->local_ip_mask, remote_ip, sdf_flow->remote_ip_mask, (sdf_flow->local_port_low), (sdf_flow->local_port_high), (sdf_flow->remote_port_low), (sdf_flow->remote_port_high), sdf_flow->proto_id, sdf_flow->proto_mask); } } else if(sdf_flow->v6){ if (direction == TFT_DIRECTION_DOWNLINK_ONLY) { snprintf(sdf_str, MAX_LEN, "%s/%"PRIu8" %s/%"PRIu8"" " 0x%"PRIx8"/0x%"PRIx8"", local_ip, sdf_flow->local_ip_mask, remote_ip, sdf_flow->remote_ip_mask, sdf_flow->proto_id, sdf_flow->proto_mask); } else if (direction == TFT_DIRECTION_UPLINK_ONLY) { snprintf(sdf_str, MAX_LEN, "%s/%"PRIu8" %s/%"PRIu8"" " 0x%"PRIx8"/0x%"PRIx8"", local_ip, sdf_flow->local_ip_mask, remote_ip, sdf_flow->remote_ip_mask, sdf_flow->proto_id, sdf_flow->proto_mask); } } } void fill_pdr_far_qer_using_bearer(pfcp_sess_mod_req_t *pfcp_sess_mod_req, eps_bearer *bearer, ue_context *context, uint8_t create_pdr_counter) { int ret = 0; int itr2 = create_pdr_counter; for(int i = 0; i < NUMBER_OF_PDR_PER_RULE; i++) { if ((config.use_gx) && (context->cp_mode == PGWC || context->cp_mode == SAEGWC)){ pfcp_sess_mod_req->create_pdr[itr2].qer_id_count = 1; } if (bearer->pdn->generate_cdr) { pfcp_sess_mod_req->create_pdr[itr2].urr_id_count = 1; pfcp_sess_mod_req->create_urr_count++; set_create_urr(&(pfcp_sess_mod_req->create_urr[itr2]), bearer->pdrs[i]); } //pfcp_sess_mod_req->create_pdr[i].qer_id_count = bearer->qer_count; set_create_pdr(&(pfcp_sess_mod_req->create_pdr[itr2]), bearer->pdrs[i], context->cp_mode); pfcp_sess_mod_req->create_far_count++; /*Just need to Forward the packets that's why disabling * all other supported action*/ bearer->pdrs[i]->far.actions.forw = PRESENT; bearer->pdrs[i]->far.actions.dupl = 0; bearer->pdrs[i]->far.actions.drop = 0; set_create_far(&(pfcp_sess_mod_req->create_far[itr2]), &bearer->pdrs[i]->far); itr2++; } /* get user level packet copying token or id using imsi */ imsi_id_hash_t *imsi_id_config = NULL; ret = get_id_using_imsi(context->imsi, &imsi_id_config); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Not applicable for li\n", LOG_VALUE); } itr2 = create_pdr_counter; for(int itr = 0; itr < NUMBER_OF_PDR_PER_RULE; itr++) { if ((context->cp_mode == PGWC) || (SAEGWC == context->cp_mode)) { if (pfcp_sess_mod_req->create_far[itr2].apply_action.forw == PRESENT) { uint16_t len = 0; if ((SAEGWC == context->cp_mode) || (SOURCE_INTERFACE_VALUE_ACCESS == bearer->pdrs[itr]->pdi.src_intfc.interface_value)) { len = set_destination_interface(&(pfcp_sess_mod_req->create_far[itr2].frwdng_parms.dst_intfc), bearer->pdrs[itr]->far.dst_intfc.interface_value); pfcp_set_ie_header(&(pfcp_sess_mod_req->create_far[itr2].frwdng_parms.header), IE_FRWDNG_PARMS, sizeof(pfcp_dst_intfc_ie_t)); pfcp_sess_mod_req->create_far[itr2].frwdng_parms.header.len = len; len += UPD_PARAM_HEADER_SIZE; pfcp_sess_mod_req->create_far[itr2].header.len += len; } } } else { if ((SGWC == context->cp_mode) && (DESTINATION_INTERFACE_VALUE_CORE == bearer->pdrs[itr]->far.dst_intfc.interface_value) && (bearer->s5s8_pgw_gtpu_teid != 0) && (bearer->s5s8_pgw_gtpu_ip.ipv4_addr != 0 || *bearer->s5s8_pgw_gtpu_ip.ipv6_addr != 0)) { node_address_t node_value = {0}; ret = fill_ip_addr(bearer->pdrs[itr]->far.outer_hdr_creation.ipv4_address, bearer->pdrs[itr]->far.outer_hdr_creation.ipv6_address, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } uint16_t len = 0; len += set_forwarding_param(&(pfcp_sess_mod_req->create_far[itr2].frwdng_parms), node_value, bearer->pdrs[itr]->far.outer_hdr_creation.teid, bearer->pdrs[itr]->far.dst_intfc.interface_value); pfcp_sess_mod_req->create_far[itr2].header.len += len; } } if ((context != NULL) && (imsi_id_config != NULL) && (imsi_id_config->cntr > 0)){ update_li_info_in_dup_params(imsi_id_config, context, &(pfcp_sess_mod_req->create_far[itr2])); } itr2++; } /*for loop*/ if ((config.use_gx) && (context->cp_mode == PGWC || context->cp_mode == SAEGWC)) { pfcp_sess_mod_req->create_qer_count = bearer->qer_count; qer_t *qer_context = NULL; for(int itr1 = 0; itr1 < pfcp_sess_mod_req->create_qer_count ; itr1++) { qer_context = get_qer_entry(bearer->qer_id[itr1].qer_id, bearer->pdn->seid); /* Assign the value from the PDR */ if(qer_context) { set_create_qer(&(pfcp_sess_mod_req->create_qer[itr1]), qer_context); } } for(int itr1 = 0; itr1 < pfcp_sess_mod_req->create_pdr_count ; itr1++) { for(int index = 0; index < bearer->num_dynamic_filters; index++) fill_create_pdr_sdf_rules(pfcp_sess_mod_req->create_pdr, bearer->dynamic_rules[index], itr1); } } } void fill_gate_status(pfcp_sess_estab_req_t *pfcp_sess_est_req, int qer_counter, enum flow_status f_status) { switch(f_status) { case FL_ENABLED_UPLINK: pfcp_sess_est_req->create_qer[qer_counter].gate_status.ul_gate = UL_GATE_OPEN; pfcp_sess_est_req->create_qer[qer_counter].gate_status.dl_gate = UL_GATE_CLOSED; break; case FL_ENABLED_DOWNLINK: pfcp_sess_est_req->create_qer[qer_counter].gate_status.ul_gate = UL_GATE_CLOSED; pfcp_sess_est_req->create_qer[qer_counter].gate_status.dl_gate = UL_GATE_OPEN; break; case FL_ENABLED: pfcp_sess_est_req->create_qer[qer_counter].gate_status.ul_gate = UL_GATE_OPEN; pfcp_sess_est_req->create_qer[qer_counter].gate_status.dl_gate = UL_GATE_OPEN; break; case FL_DISABLED: pfcp_sess_est_req->create_qer[qer_counter].gate_status.ul_gate = UL_GATE_CLOSED; pfcp_sess_est_req->create_qer[qer_counter].gate_status.dl_gate = UL_GATE_CLOSED; break; case FL_REMOVED: /*TODO*/ break; } } int sdf_pkt_filter_add(pfcp_pdi_ie_t* pdi, dynamic_rule_t *dynamic_rules, int sdf_filter_count, int flow_cnt, uint8_t direction) { int len = 0; pdi->sdf_filter[sdf_filter_count].fd = 1; sdf_pkt_filter_to_string(&(dynamic_rules->flow_desc[flow_cnt].sdf_flw_desc), (char*)(pdi->sdf_filter[sdf_filter_count].flow_desc), direction); pdi->sdf_filter[sdf_filter_count].len_of_flow_desc = strnlen((char*)(&pdi->sdf_filter[sdf_filter_count].flow_desc),MAX_FLOW_DESC_LEN); len += FLAG_LEN; len += sizeof(uint16_t); len += pdi->sdf_filter[sdf_filter_count].len_of_flow_desc; pfcp_set_ie_header( &(pdi->sdf_filter[sdf_filter_count].header), PFCP_IE_SDF_FILTER, len); /*updated the header len of pdi as sdf rules has been added*/ pdi->header.len += (len + sizeof(pfcp_ie_header_t)); return (len + sizeof(pfcp_ie_header_t)); } int fill_create_pdr_sdf_rules(pfcp_create_pdr_ie_t *create_pdr, dynamic_rule_t *dynamic_rules, int pdr_counter) { int ret = 0; int sdf_filter_count = 0; /*convert pkt_filter_strucutre to char string*/ create_pdr[pdr_counter].precedence.prcdnc_val = dynamic_rules->precedence; /*itr is for flow information counter*/ /*sdf_filter_count is for SDF information counter*/ for(int itr = 0; itr < dynamic_rules->num_flw_desc; itr++) { if(dynamic_rules->flow_desc[itr].sdf_flow_description != NULL) { if((create_pdr[pdr_counter].pdi.src_intfc.interface_value == SOURCE_INTERFACE_VALUE_ACCESS) && ((dynamic_rules->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_UPLINK_ONLY) || (dynamic_rules->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_BIDIRECTIONAL))) { int len = sdf_pkt_filter_add( &create_pdr[pdr_counter].pdi, dynamic_rules, sdf_filter_count, itr, TFT_DIRECTION_UPLINK_ONLY); create_pdr[pdr_counter].header.len += len; sdf_filter_count++; } else if((create_pdr[pdr_counter].pdi.src_intfc.interface_value == SOURCE_INTERFACE_VALUE_CORE) && ((dynamic_rules->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_DOWNLINK_ONLY) || (dynamic_rules->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_BIDIRECTIONAL))) { int len = sdf_pkt_filter_add( &create_pdr[pdr_counter].pdi, dynamic_rules, sdf_filter_count, itr, TFT_DIRECTION_DOWNLINK_ONLY); create_pdr[pdr_counter].header.len += len; sdf_filter_count++; } } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "No SDF rules found " "while creating PDR sdf rule\n", LOG_VALUE); } } create_pdr[pdr_counter].pdi.sdf_filter_count = sdf_filter_count; return ret; } int fill_qer_entry(pdn_connection *pdn, eps_bearer *bearer, uint8_t itr) { int ret = -1; qer_t *qer_ctxt = NULL; qer_ctxt = rte_zmalloc_socket(NULL, sizeof(qer_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (qer_ctxt == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for QER structure, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return ret; } qer_ctxt->qer_id = bearer->qer_id[itr].qer_id; qer_ctxt->session_id = pdn->seid; qer_ctxt->max_bitrate.ul_mbr = bearer->qos.ul_mbr; qer_ctxt->max_bitrate.dl_mbr = bearer->qos.dl_mbr; qer_ctxt->guaranteed_bitrate.ul_gbr = bearer->qos.ul_gbr; qer_ctxt->guaranteed_bitrate.dl_gbr = bearer->qos.dl_gbr; ret = add_qer_entry(qer_ctxt->qer_id,qer_ctxt, pdn->seid); if(ret != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Error while adding " "QER entry \n", LOG_VALUE); return ret; } return ret; } /** * @brief : Add qer entry into hash * @param : qer, data to be added * @param : seid, Session ID of UE * @return : Returns 0 on success, -1 otherwise */ static int add_qer_into_hash(qer_t *qer, uint64_t seid) { int ret = -1; qer_t *qer_ctxt = NULL; qer_ctxt = rte_zmalloc_socket(NULL, sizeof(qer_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (qer_ctxt == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for QER structure, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return ret; } qer_ctxt->qer_id = qer->qer_id; qer_ctxt->session_id = qer->session_id; qer_ctxt->max_bitrate.ul_mbr = qer->max_bitrate.ul_mbr; qer_ctxt->max_bitrate.dl_mbr = qer->max_bitrate.dl_mbr; qer_ctxt->guaranteed_bitrate.ul_gbr = qer->guaranteed_bitrate.ul_gbr; qer_ctxt->guaranteed_bitrate.dl_gbr = qer-> guaranteed_bitrate.dl_gbr; ret = add_qer_entry(qer_ctxt->qer_id, qer_ctxt, seid); if(ret != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Error while adding " "QER entry \n", LOG_VALUE); return ret; } return ret; } void fill_pdr_sdf_qer(pdr_t *pdr_ctxt, dynamic_rule_t *dyn_rule){ int i = pdr_ctxt->pdi.src_intfc.interface_value; uint16_t flow_len = 0; for(int itr = 0; itr < dyn_rule->num_flw_desc; itr++) { if(dyn_rule->flow_desc[itr].sdf_flow_description != NULL) { flow_len = dyn_rule->flow_desc[itr].flow_desc_len; if ((i == SOURCE_INTERFACE_VALUE_ACCESS) && ((dyn_rule->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_UPLINK_ONLY) || (dyn_rule->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_BIDIRECTIONAL))) { memcpy(&(pdr_ctxt->pdi.sdf_filter[pdr_ctxt->pdi.sdf_filter_cnt].flow_desc), &(dyn_rule->flow_desc[itr].sdf_flow_description), flow_len); pdr_ctxt->pdi.sdf_filter[pdr_ctxt->pdi.sdf_filter_cnt].len_of_flow_desc = flow_len; pdr_ctxt->pdi.sdf_filter_cnt++; } else if ((i == SOURCE_INTERFACE_VALUE_CORE) && ((dyn_rule->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_DOWNLINK_ONLY) || (dyn_rule->flow_desc[itr].sdf_flw_desc.direction == TFT_DIRECTION_BIDIRECTIONAL))) { memcpy(&(pdr_ctxt->pdi.sdf_filter[pdr_ctxt->pdi.sdf_filter_cnt].flow_desc), &(dyn_rule->flow_desc[itr].sdf_flow_description), flow_len); pdr_ctxt->pdi.sdf_filter[pdr_ctxt->pdi.sdf_filter_cnt].len_of_flow_desc = flow_len; pdr_ctxt->pdi.sdf_filter_cnt++; } } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "No SDF rules found " "while filling PDR sdf rule\n", LOG_VALUE); } } pdr_ctxt->qer.max_bitrate.ul_mbr = dyn_rule->qos.ul_mbr; pdr_ctxt->qer.max_bitrate.dl_mbr = dyn_rule->qos.dl_mbr; pdr_ctxt->qer.guaranteed_bitrate.ul_gbr = dyn_rule->qos.ul_gbr; pdr_ctxt->qer.guaranteed_bitrate.dl_gbr = dyn_rule->qos.dl_gbr; return; } int fill_pfcp_entry(eps_bearer *bearer, dynamic_rule_t *dyn_rule) { pdn_connection *pdn = bearer->pdn; int ret; int idx = bearer->pdr_count - NUMBER_OF_PDR_PER_RULE; for(int i = 0; i < NUMBER_OF_PDR_PER_RULE; i++) { pdr_t *pdr_ctxt = NULL; pdr_ctxt = bearer->pdrs[idx]; pdr_ctxt->prcdnc_val = dyn_rule->precedence; pdr_ctxt->session_id = pdn->seid; /*to be filled in fill_sdf_rule*/ pdr_ctxt->pdi.sdf_filter_cnt = 0; dyn_rule->pdr[i] = pdr_ctxt; if(!dyn_rule->predefined_rule) { strncpy(pdr_ctxt->rule_name, dyn_rule->rule_name, RULE_NAME_LEN); pdr_ctxt->pdi.src_intfc.interface_value = i; pdr_ctxt->qer.qer_id = bearer->qer_id[idx].qer_id; pdr_ctxt->qer_id[0].qer_id = pdr_ctxt->qer.qer_id; pdr_ctxt->qer.session_id = pdn->seid; fill_pdr_sdf_qer(pdr_ctxt, dyn_rule); ret = add_qer_into_hash(&pdr_ctxt->qer, pdn->seid); if(ret != 0) { clLog(clSystemLog, eCLSeverityCritical, "[%s]:[%s]:[%d] Adding qer entry Error: %d \n", __file__, __func__, __LINE__, ret); return ret; } enum flow_status f_status = dyn_rule->flow_status; switch(f_status) { case FL_ENABLED_UPLINK: pdr_ctxt->qer.gate_status.ul_gate = UL_GATE_OPEN; pdr_ctxt->qer.gate_status.dl_gate = UL_GATE_CLOSED; break; case FL_ENABLED_DOWNLINK: pdr_ctxt->qer.gate_status.ul_gate = UL_GATE_CLOSED; pdr_ctxt->qer.gate_status.dl_gate = UL_GATE_OPEN; break; case FL_ENABLED: pdr_ctxt->qer.gate_status.ul_gate = UL_GATE_OPEN; pdr_ctxt->qer.gate_status.dl_gate = UL_GATE_OPEN; break; case FL_DISABLED: pdr_ctxt->qer.gate_status.ul_gate = UL_GATE_CLOSED; pdr_ctxt->qer.gate_status.dl_gate = UL_GATE_CLOSED; break; case FL_REMOVED: /*TODO*/ break; } } idx++; } /* FOR Loop */ return 0; } pdr_t * fill_pdr_entry(ue_context *context, pdn_connection *pdn, eps_bearer *bearer, uint8_t iface, uint8_t itr) { uint8_t tmp_pdr_rule_id = 0; uint8_t tmp_far_id = 0; uint8_t tmp_urr_id = 0; char mnc[MCC_MNC_LEN] = {0}; char mcc[MCC_MNC_LEN] = {0}; char nwinst[PFCP_NTWK_INST_LEN] = {0}; pdr_t *pdr_ctxt = NULL; int ret = 0; if (context->serving_nw.mnc_digit_3 == 15) { snprintf(mnc, MCC_MNC_LEN,"0%u%u", context->serving_nw.mnc_digit_1, context->serving_nw.mnc_digit_2); } else { snprintf(mnc, MCC_MNC_LEN,"%u%u%u", context->serving_nw.mnc_digit_1, context->serving_nw.mnc_digit_2, context->serving_nw.mnc_digit_3); } snprintf(mcc, MCC_MNC_LEN,"%u%u%u", context->serving_nw.mcc_digit_1, context->serving_nw.mcc_digit_2, context->serving_nw.mcc_digit_3); snprintf(nwinst, PFCP_NTWK_INST_LEN,"mnc%s.mcc%s", mnc, mcc); if (bearer->pdr_count) { if (bearer->pdrs[itr] != NULL) { pdr_ctxt = get_pdr_entry((bearer->pdrs[itr])->rule_id, pdn->seid); } } if (pdr_ctxt == NULL) { pdr_ctxt = rte_zmalloc_socket(NULL, sizeof(pdr_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (pdr_ctxt == NULL) { clLog(clSystemLog, eCLSeverityCritical, "Failure to allocate CCR Buffer memory" "structure: %s (%s:%d)\n", rte_strerror(rte_errno), __FILE__, __LINE__); return NULL; } memset(pdr_ctxt, 0, sizeof(pdr_t)); pdr_ctxt->rule_id = generate_pdr_id(&context->pdr_rule_id_offset); pdr_ctxt->far.far_id_value = generate_far_id(&context->far_rule_id_offset); pdr_ctxt->urr.urr_id_value = generate_urr_id(&context->urr_rule_id_offset); } else { /* Handover/Promotion scenario */ /* TODO */ tmp_pdr_rule_id = pdr_ctxt->rule_id; tmp_far_id = pdr_ctxt->far.far_id_value; tmp_urr_id = pdr_ctxt->urr.urr_id_value; /* Flush exisiting PDR Info */ memset(pdr_ctxt, 0, sizeof(pdr_t)); pdr_ctxt->rule_id = tmp_pdr_rule_id; pdr_ctxt->far.far_id_value = tmp_far_id; pdr_ctxt->urr.urr_id_value = tmp_urr_id; } pdr_ctxt->prcdnc_val = 1; pdr_ctxt->create_far = PRESENT; pdr_ctxt->create_urr = PRESENT; /* * per pdr there is one URR * hence hardcoded urr count to one */ pdr_ctxt->urr_id_count = URR_PER_PDR; pdr_ctxt->session_id = pdn->seid; pdr_ctxt->pdi.src_intfc.interface_value = iface; strncpy((char * )pdr_ctxt->pdi.ntwk_inst.ntwk_inst, (char *)nwinst, PFCP_NTWK_INST_LEN); /* TODO: NS Add this changes after DP related changes of VS * if(context->cp_mode != SGWC){ * pdr_ctxt->pdi.ue_addr.ipv4_address = pdn->ipv4.s_addr; * } */ pdr_ctxt->actvt_predef_rules_count += 1; /*to be filled in fill_sdf_rule*/ pdr_ctxt->pdi.sdf_filter_cnt += 1; if (context->cp_mode == PGWC || context->cp_mode == SAEGWC){ /* TODO Hardcode 1 set because one PDR contain only 1 QER entry * Revist again in case of multiple rule support */ pdr_ctxt->qer_id_count = 1; } if (pdn->pdn_type.ipv4) { pdr_ctxt->pdi.ue_addr.v4 = 1; pdr_ctxt->pdi.ue_addr.ipv4_address = pdn->uipaddr.ipv4.s_addr; } if(pdn->pdn_type.ipv6) { pdr_ctxt->pdi.ue_addr.v6 = 1; memcpy(pdr_ctxt->pdi.ue_addr.ipv6_address, pdn->uipaddr.ipv6.s6_addr, IPV6_ADDRESS_LEN); pdr_ctxt->pdi.ue_addr.ipv6_pfx_dlgtn_bits = pdn->prefix_len; pdr_ctxt->pdi.ue_addr.ipv6d = 1; } if (iface == SOURCE_INTERFACE_VALUE_ACCESS) { pdr_ctxt->pdi.local_fteid.teid = bearer->s1u_sgw_gtpu_teid; pdr_ctxt->pdi.local_fteid.ipv4_address = 0; if ((SGWC == context->cp_mode) && (bearer->s5s8_pgw_gtpu_ip.ipv4_addr != 0 || *bearer->s5s8_pgw_gtpu_ip.ipv6_addr != 0) && (bearer->s5s8_pgw_gtpu_teid != 0)) { /*Just need to Forward the packets that's why disabling * all other supported action*/ pdr_ctxt->far.actions.forw = PRESENT; pdr_ctxt->far.actions.dupl = 0; pdr_ctxt->far.actions.drop = 0; pdr_ctxt->far.dst_intfc.interface_value = DESTINATION_INTERFACE_VALUE_CORE; ret = set_node_address(&pdr_ctxt->far.outer_hdr_creation.ipv4_address, pdr_ctxt->far.outer_hdr_creation.ipv6_address, bearer->s5s8_pgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } pdr_ctxt->far.outer_hdr_creation.teid = bearer->s5s8_pgw_gtpu_teid; } else { pdr_ctxt->far.actions.forw = 0; pdr_ctxt->far.actions.dupl = 0; pdr_ctxt->far.actions.drop = 0; } if ((context->cp_mode == PGWC) || (SAEGWC == context->cp_mode)) { pdr_ctxt->far.dst_intfc.interface_value = DESTINATION_INTERFACE_VALUE_CORE; } else if ((context->cp_mode == SGWC) && (context->indication_flag.oi != 0)){ ret = set_node_address(&pdr_ctxt->far.outer_hdr_creation.ipv4_address, pdr_ctxt->far.outer_hdr_creation.ipv6_address, bearer->s5s8_pgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } pdr_ctxt->far.outer_hdr_creation.teid = bearer->s5s8_pgw_gtpu_teid; pdr_ctxt->far.dst_intfc.interface_value = DESTINATION_INTERFACE_VALUE_CORE; } } else{ if(context->cp_mode == SGWC){ pdr_ctxt->pdi.local_fteid.teid = (bearer->s5s8_sgw_gtpu_teid); pdr_ctxt->pdi.local_fteid.ipv4_address = 0; if(context->indication_flag.oi != 0){ if(bearer->s1u_enb_gtpu_ip.ip_type != NONE_PDN_TYPE) { ret = set_node_address(&pdr_ctxt->far.outer_hdr_creation.ipv4_address, pdr_ctxt->far.outer_hdr_creation.ipv6_address, bearer->s1u_enb_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } pdr_ctxt->far.outer_hdr_creation.teid = bearer->s1u_enb_gtpu_teid; pdr_ctxt->far.dst_intfc.interface_value = DESTINATION_INTERFACE_VALUE_ACCESS; } }else{ pdr_ctxt->pdi.local_fteid.teid = 0; pdr_ctxt->pdi.local_fteid.ipv4_address = 0; pdr_ctxt->far.actions.forw = 0; pdr_ctxt->far.actions.dupl = 0; pdr_ctxt->far.actions.drop = 0; if (context->cp_mode == PGWC) { ret = set_node_address(&pdr_ctxt->far.outer_hdr_creation.ipv4_address, pdr_ctxt->far.outer_hdr_creation.ipv6_address, bearer->s5s8_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } pdr_ctxt->far.outer_hdr_creation.teid = bearer->s5s8_sgw_gtpu_teid; pdr_ctxt->far.dst_intfc.interface_value = DESTINATION_INTERFACE_VALUE_ACCESS; } } } /* Measurement method set to volume as well as time as a default*/ pdr_ctxt->urr.mea_mt.volum = PRESENT; pdr_ctxt->urr.mea_mt.durat = PRESENT; if(pdn->apn_in_use->trigger_type == VOL_BASED) { pdr_ctxt->urr.rept_trigg.volth = PRESENT; if (iface == SOURCE_INTERFACE_VALUE_ACCESS) { pdr_ctxt->urr.vol_th.uplink_volume = pdn->apn_in_use->uplink_volume_th; } else { pdr_ctxt->urr.vol_th.downlink_volume = pdn->apn_in_use->downlink_volume_th; } } else if (pdn->apn_in_use->trigger_type == TIME_BASED) { pdr_ctxt->urr.rept_trigg.timth = PRESENT; pdr_ctxt->urr.time_th.time_threshold = pdn->apn_in_use->time_th; } else { pdr_ctxt->urr.rept_trigg.volth = PRESENT; pdr_ctxt->urr.rept_trigg.timth = PRESENT; if (iface == SOURCE_INTERFACE_VALUE_ACCESS) { pdr_ctxt->urr.vol_th.uplink_volume = pdn->apn_in_use->uplink_volume_th; pdr_ctxt->urr.time_th.time_threshold = pdn->apn_in_use->time_th; } else { pdr_ctxt->urr.vol_th.downlink_volume = pdn->apn_in_use->downlink_volume_th; pdr_ctxt->urr.time_th.time_threshold = pdn->apn_in_use->time_th; } } bearer->pdrs[itr] = pdr_ctxt; ret = add_pdr_entry(bearer->pdrs[itr]->rule_id, bearer->pdrs[itr], pdn->seid); if ( ret != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error while adding " "pdr entry\n", LOG_VALUE); return NULL; } return pdr_ctxt; } eps_bearer* get_default_bearer(pdn_connection *pdn) { int ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return NULL; } return pdn->eps_bearers[ebi_index]; } eps_bearer* get_bearer(pdn_connection *pdn, bearer_qos_ie *qos) { eps_bearer *bearer = NULL; for(uint8_t idx = 0; idx < MAX_BEARERS*2; idx++) { bearer = pdn->eps_bearers[idx]; if(bearer != NULL) { /* Comparing each member in arp */ if((bearer->qos.qci == qos->qci) && (bearer->qos.arp.preemption_vulnerability == qos->arp.preemption_vulnerability) && (bearer->qos.arp.priority_level == qos->arp.priority_level) && (bearer->qos.arp.preemption_capability == qos->arp.preemption_capability)) { return bearer; } } } return NULL; } int8_t compare_default_bearer_qos(bearer_qos_ie *default_bearer_qos, bearer_qos_ie *rule_qos) { if(default_bearer_qos->qci != rule_qos->qci) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Comparing default bearer qci with the rule qci\n", LOG_VALUE); return -1; } if(default_bearer_qos->arp.preemption_vulnerability != rule_qos->arp.preemption_vulnerability) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Comparing default bearer qos arp preemption vulnerablity\n", LOG_VALUE); return -1; } if(default_bearer_qos->arp.priority_level != rule_qos->arp.priority_level) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Comparing default bearer qos arp priority level\n", LOG_VALUE); return -1; } if(default_bearer_qos->arp.preemption_capability != rule_qos->arp.preemption_capability) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Comparing default bearer qos arp preemption vulnerablity\n", LOG_VALUE); return -1; } return 0; } uint16_t fill_dup_param(pfcp_dupng_parms_ie_t *dup_params, uint8_t li_policy[], uint8_t li_policy_len) { uint16_t len = 0; set_duplicating_param(dup_params); /* Set forwarding policy IE */ memset(dup_params->frwdng_plcy.frwdng_plcy_ident, 0, MAX_LI_POLICY_LIMIT); memcpy(dup_params->frwdng_plcy.frwdng_plcy_ident, li_policy, li_policy_len); len += li_policy_len * sizeof(uint8_t); dup_params->frwdng_plcy.frwdng_plcy_ident_len = li_policy_len; len += sizeof(uint8_t); /* Forwarding policy header */ dup_params->frwdng_plcy.header.len = len; len += UPD_PARAM_HEADER_SIZE; /* Duplicating parameter header */ dup_params->header.len = len; len += UPD_PARAM_HEADER_SIZE; /* IE's which are not require. Set their header length to 0 */ dup_params->dst_intfc.header.len = 0; dup_params->outer_hdr_creation.header.len = 0; /* Return value to update create far header */ return len; /* End : Need to add condition and all stuff must be in function */ } uint16_t fill_upd_dup_param(pfcp_upd_dupng_parms_ie_t *dup_params, uint8_t li_policy[], uint8_t li_policy_len) { uint16_t len = 0; set_upd_duplicating_param(dup_params); if (0 != li_policy_len) { /* Set forwarding policy IE */ memset(dup_params->frwdng_plcy.frwdng_plcy_ident, 0, MAX_LI_POLICY_LIMIT); memcpy(dup_params->frwdng_plcy.frwdng_plcy_ident, li_policy, li_policy_len); len += li_policy_len * sizeof(uint8_t); dup_params->frwdng_plcy.frwdng_plcy_ident_len = li_policy_len; len += sizeof(uint8_t); /* Forwarding policy header */ dup_params->frwdng_plcy.header.len = len; len += UPD_PARAM_HEADER_SIZE; } /* Duplicating parameter header */ dup_params->header.len = len; len += UPD_PARAM_HEADER_SIZE; /* IE's which are not require. Set their header length to 0 */ dup_params->dst_intfc.header.len = 0; dup_params->outer_hdr_creation.header.len = 0; /* Return value to update update far header */ return len; } /** * @brief : sets the sdf filters for dynamic rule in create_pdr * @param : pfcp_sess_est_req, pointer of pfcp_sess_estab_req_t struture * @param : bearer, pointer of eps_bearer structure * @param : pdr_idx, iterator * @return : Returns nothing */ static void set_sdf_rules_create_pdr(pfcp_sess_estab_req_t *pfcp_sess_est_req, eps_bearer *bearer, uint8_t *pdr_idx) { for(uint8_t itr = 0; itr < bearer->num_dynamic_filters; itr++){ enum flow_status f_status = bearer->dynamic_rules[itr]->flow_status; fill_create_pdr_sdf_rules(pfcp_sess_est_req->create_pdr, bearer->dynamic_rules[itr], *pdr_idx); fill_gate_status(pfcp_sess_est_req, *pdr_idx, f_status); (*pdr_idx)++; fill_create_pdr_sdf_rules(pfcp_sess_est_req->create_pdr, bearer->dynamic_rules[itr], *pdr_idx); fill_gate_status(pfcp_sess_est_req, *pdr_idx, f_status); (*pdr_idx)++; } } /** * @brief : sets the active predefined rule for prdefined rule in create_pdr * @param : create_pdr, pointer of pfcp_create_pdr_ie_t struture * @param : bearer, pointer of eps_bearer structure * @param : pdr_idx, iterator * @return : Returns nothing */ static void set_pdef_rules_create_pdr(pfcp_create_pdr_ie_t *create_pdr, eps_bearer *bearer, uint8_t *pdr_idx) { for(uint8_t itr = 0; itr < bearer->num_prdef_filters; itr++){ fill_predef_rules_pdr(create_pdr, bearer->prdef_rules[itr], *pdr_idx, 0); (*pdr_idx)++; fill_predef_rules_pdr(create_pdr, bearer->prdef_rules[itr], *pdr_idx, 0); (*pdr_idx)++; } } void fill_pfcp_sess_est_req( pfcp_sess_estab_req_t *pfcp_sess_est_req, pdn_connection *pdn, uint32_t seq, struct ue_context_t *context, struct resp_info *resp) { /*TODO :generate seid value and store this in array to send response from cp/dp , first check seid is there in array or not if yes then fill that seid in response and if not then seid =0 */ int ret = 0; int tmp_bearer_idx = 0; uint8_t pdr_idx =0; uint8_t bearer_id = 0; uint8_t bar_id = PRESENT; eps_bearer *bearer = NULL; upf_context_t *upf_ctx = NULL; qer_t *qer_context = NULL; bearer_qos_ie *default_bearer_qos = NULL; node_address_t node_value = {0}; dynamic_rule_t rule = {0}; int max_bearer_count = MAX_BEARERS; RTE_SET_USED(bearer_id); if ((ret = upf_context_entry_lookup(pdn->upf_ip, &upf_ctx)) < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Error while extracting " "upf context UPF ip : %u \n", LOG_VALUE, pdn->upf_ip.ipv4_addr); return; } memset(pfcp_sess_est_req,0,sizeof(pfcp_sess_estab_req_t)); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_est_req->header), PFCP_SESSION_ESTABLISHMENT_REQUEST, HAS_SEID, seq, context->cp_mode); pfcp_sess_est_req->header.seid_seqno.has_seid.seid = pdn->dp_seid; /*Filling Node ID for F-SEID*/ if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV4) { uint8_t temp[IPV6_ADDRESS_LEN] = {0}; ret = fill_ip_addr(config.pfcp_ip.s_addr, temp, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV6) { ret = fill_ip_addr(0, config.pfcp_ip_v6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } set_node_id(&(pfcp_sess_est_req->node_id), node_value); set_user_id(&(pfcp_sess_est_req->user_id), context->imsi); set_fseid(&(pfcp_sess_est_req->cp_fseid), pdn->seid, node_value); if ((context->cp_mode == PGWC) || (SAEGWC == context->cp_mode)) { pfcp_sess_est_req->create_pdr_count = pdn->policy.num_charg_rule_install * NUMBER_OF_PDR_PER_RULE; /* * For pgw create pdf, far and qer while handling pfcp messages */ for (int idx=0; idx < pdn->policy.num_charg_rule_install; idx++) { bearer = NULL; if (pdn->policy.pcc_rule[idx]->predefined_rule) { default_bearer_qos = &pdn->policy.pcc_rule[idx]->urule.pdef_rule.qos; } else { default_bearer_qos = &pdn->policy.pcc_rule[idx]->urule.dyn_rule.qos; } if(compare_default_bearer_qos(&pdn->policy.default_bearer_qos, default_bearer_qos) == 0) { /* This means rule going to install in default bearer */ bearer = get_default_bearer(pdn); if (bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"bearer object is NULL\n", LOG_VALUE); return; }else { if(!pdn->policy.pcc_rule[idx]->predefined_rule){ for(uint8_t itr=bearer->qer_count; itr < bearer->qer_count + NUMBER_OF_QER_PER_RULE; itr++){ bearer->qer_id[itr].qer_id = generate_qer_id(&context->qer_rule_id_offset); fill_qer_entry(pdn, bearer,itr); } bearer->qer_count += NUMBER_OF_QER_PER_RULE; /* TODO: Added handling for QER Approprietly */ for(uint8_t itr1 = 0; itr1 < bearer->pdr_count; itr1++){ bearer->pdrs[itr1]->qer_id[0].qer_id = bearer->qer_id[itr1].qer_id; } } } } else { /* dedicated bearer */ bearer = get_bearer(pdn, default_bearer_qos); if(bearer == NULL) { /* create dedicated bearer */ bearer = rte_zmalloc_socket(NULL, sizeof(eps_bearer), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure " "to allocate bearer structure: %s\n", LOG_VALUE, rte_strerror(rte_errno)); return; } tmp_bearer_idx = resp->bearer_count + MAX_BEARERS + 1; max_bearer_count = tmp_bearer_idx; resp->eps_bearer_ids[resp->bearer_count++] = tmp_bearer_idx; int ebi_index = GET_EBI_INDEX(tmp_bearer_idx); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return; } bzero(bearer, sizeof(eps_bearer)); bearer->pdn = pdn; bearer->eps_bearer_id = tmp_bearer_idx; pdn->eps_bearers[ebi_index] = bearer; pdn->context->eps_bearers[ebi_index] = bearer; pdn->num_bearer++; pdn->context->piggyback = TRUE; fill_dedicated_bearer_info(bearer, pdn->context, pdn, pdn->policy.pcc_rule[idx]->predefined_rule); if(pdn->policy.pcc_rule[idx]->predefined_rule == TRUE){ memcpy(&(bearer->qos), &(pdn->policy.pcc_rule[idx]->urule.pdef_rule.qos), sizeof(bearer_qos_ie)); memcpy(&rule, &pdn->policy.pcc_rule[idx]->urule.pdef_rule, sizeof(dynamic_rule_t)); }else{ memcpy(&(bearer->qos), &(pdn->policy.pcc_rule[idx]->urule.dyn_rule.qos), sizeof(bearer_qos_ie)); memcpy(&rule, &pdn->policy.pcc_rule[idx]->urule.dyn_rule, sizeof(dynamic_rule_t)); } }else{ add_pdr_qer_for_rule(bearer, pdn->policy.pcc_rule[idx]->predefined_rule); } } if(pdn->policy.pcc_rule[idx]->predefined_rule) { bearer->prdef_rules[bearer->num_prdef_filters] = rte_zmalloc_socket(NULL, sizeof(dynamic_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (bearer->prdef_rules[bearer->num_prdef_filters] == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to " "allocate failure rule memory structure: %s\n",LOG_VALUE, rte_strerror(rte_errno)); return; } memcpy((bearer->prdef_rules[bearer->num_prdef_filters]), &(pdn->policy.pcc_rule[idx]->urule.pdef_rule), sizeof(dynamic_rule_t)); for(int itr = 0; itr < NUMBER_OF_PDR_PER_RULE; itr++){ strncpy(bearer->pdrs[itr]->rule_name, pdn->policy.pcc_rule[idx]->urule.pdef_rule.rule_name, RULE_NAME_LEN); bearer->prdef_rules[bearer->num_prdef_filters]->pdr[itr] = bearer->pdrs[itr]; /* TODO: Consider dynamic rule is 1 only */ enum flow_status f_status = bearer->prdef_rules[bearer->num_prdef_filters]->flow_status; fill_gate_status(pfcp_sess_est_req, itr + 1, f_status); } bearer->num_prdef_filters++; if(pdn->context->piggyback == TRUE ) { fill_pfcp_entry(bearer, &pdn->policy.pcc_rule[idx]->urule.pdef_rule); } } else { bearer->dynamic_rules[bearer->num_dynamic_filters] = rte_zmalloc_socket(NULL, sizeof(dynamic_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (bearer->dynamic_rules[bearer->num_dynamic_filters] == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to " "allocate dynamic rule memory structure: %s\n",LOG_VALUE, rte_strerror(rte_errno)); return; } memcpy( (bearer->dynamic_rules[bearer->num_dynamic_filters]), &(pdn->policy.pcc_rule[idx]->urule.dyn_rule), sizeof(dynamic_rule_t)); for(int itr = 0; itr < NUMBER_OF_PDR_PER_RULE; itr++) { strncpy(bearer->pdrs[itr]->rule_name, pdn->policy.pcc_rule[idx]->urule.dyn_rule.rule_name, RULE_NAME_LEN); bearer->dynamic_rules[bearer->num_dynamic_filters]->pdr[itr] = bearer->pdrs[itr]; /* TODO: Consider dynamic rule is 1 only */ enum flow_status f_status = bearer->dynamic_rules[bearer->num_dynamic_filters]->flow_status; fill_gate_status(pfcp_sess_est_req, itr + 1, f_status); } bearer->num_dynamic_filters++; if(pdn->context->piggyback == TRUE ) { fill_pfcp_entry(bearer, &pdn->policy.pcc_rule[idx]->urule.dyn_rule); } } } } else { bearer = get_default_bearer(pdn); pfcp_sess_est_req->create_pdr_count = pdn->context->bearer_count * NUMBER_OF_PDR_PER_RULE; } /* get user level packet copying token or id using imsi */ imsi_id_hash_t *imsi_id_config = NULL; ret = get_id_using_imsi(context->imsi, &imsi_id_config); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Not applicable for li\n", LOG_VALUE); } uint8_t qer_idx = 0; uint8_t pdr_itr = 0; for(uint8_t i = 0; i < max_bearer_count; i++) { bearer = pdn->eps_bearers[i]; if(bearer != NULL) { for(uint8_t idx = 0; idx < bearer->pdr_count; idx++) { for (uint8_t idx1 = 0; idx1 < bearer->num_dynamic_filters; idx1++) { if (bearer->num_prdef_filters == 0 ){ if (context->cp_mode == PGWC || context->cp_mode == SAEGWC){ pfcp_sess_est_req->create_pdr[pdr_idx].qer_id_count = 1; } } } /*Just need to Forward the packets that's why disabling * all other supported action*/ if(bearer->pdrs[idx] == NULL) continue; bearer->pdrs[idx]->far.actions.forw = PRESENT; bearer->pdrs[idx]->far.actions.dupl = 0; bearer->pdrs[idx]->far.actions.drop = 0; if (pdn->generate_cdr) { pfcp_sess_est_req->create_pdr[pdr_idx].urr_id_count = 1; pfcp_sess_est_req->create_urr_count++; set_create_urr(&(pfcp_sess_est_req->create_urr[pdr_idx]), bearer->pdrs[idx]); } set_create_pdr(&(pfcp_sess_est_req->create_pdr[pdr_idx]), bearer->pdrs[idx], context->cp_mode); pfcp_sess_est_req->create_far_count++; set_create_far(&(pfcp_sess_est_req->create_far[pdr_idx]), &bearer->pdrs[idx]->far); uint8_t len = 0; if (( SGWC == context->cp_mode ) && (context->indication_flag.oi == 0)) { if (SOURCE_INTERFACE_VALUE_ACCESS == bearer->pdrs[idx]->pdi.src_intfc.interface_value) { if((bearer->s5s8_pgw_gtpu_ip.ipv4_addr != 0 || *bearer->s5s8_pgw_gtpu_ip.ipv6_addr) && bearer->s5s8_pgw_gtpu_teid != 0) { pfcp_sess_est_req->create_far[pdr_idx].apply_action.forw = PRESENT; bearer->pdrs[idx]->far.actions.forw = PRESENT; len += set_forwarding_param(&(pfcp_sess_est_req->create_far[pdr_idx].frwdng_parms), bearer->s5s8_pgw_gtpu_ip, bearer->s5s8_pgw_gtpu_teid, DESTINATION_INTERFACE_VALUE_CORE); pfcp_sess_est_req->create_far[pdr_idx].header.len += len; } else { if(bearer->s1u_enb_gtpu_ip.ipv4_addr != 0 || *(bearer->s1u_enb_gtpu_ip.ipv6_addr)){ pfcp_sess_est_req->create_far[pdr_idx].apply_action.forw = PRESENT; bearer->pdrs[idx]->far.actions.forw = PRESENT; len += set_forwarding_param(&(pfcp_sess_est_req->create_far[pdr_idx].frwdng_parms), bearer->s1u_enb_gtpu_ip, bearer->s1u_enb_gtpu_teid, DESTINATION_INTERFACE_VALUE_ACCESS); pfcp_sess_est_req->create_far[pdr_idx].header.len += len; } else { pfcp_sess_est_req->create_far[pdr_idx].apply_action.buff = PRESENT; pfcp_sess_est_req->create_far[pdr_idx].apply_action.forw = NOT_PRESENT; bearer->pdrs[idx]->far.actions.buff = PRESENT; bearer->pdrs[idx]->far.actions.forw = NOT_PRESENT; } } } else { pfcp_sess_est_req->create_far[pdr_idx].apply_action.nocp = PRESENT; pfcp_sess_est_req->create_far[pdr_idx].apply_action.buff = PRESENT; pfcp_sess_est_req->create_far[pdr_idx].apply_action.forw = NOT_PRESENT; bearer->pdrs[idx]->far.actions.buff = PRESENT; bearer->pdrs[idx]->far.actions.nocp = PRESENT; bearer->pdrs[idx]->far.actions.forw = NOT_PRESENT; if(bearer->s1u_enb_gtpu_ip.ipv4_addr != 0 || *(bearer->s1u_enb_gtpu_ip.ipv6_addr)){ pfcp_sess_est_req->create_far[pdr_idx].apply_action.buff = NOT_PRESENT; pfcp_sess_est_req->create_far[pdr_idx].apply_action.forw = PRESENT; bearer->pdrs[idx]->far.actions.forw = PRESENT; bearer->pdrs[idx]->far.actions.buff = NOT_PRESENT; len += set_forwarding_param(&(pfcp_sess_est_req->create_far[pdr_idx].frwdng_parms), bearer->s1u_enb_gtpu_ip, bearer->s1u_enb_gtpu_teid, DESTINATION_INTERFACE_VALUE_ACCESS); pfcp_sess_est_req->create_far[pdr_idx].header.len += len; } } } /* SGW Relocation*/ if(pdn->context->indication_flag.oi != 0 ) { if(pdr_idx%2) { /*NOTE: BELOW condition is introduced as there can be a scenario where enb fteid may * not come in CSR Req for SGW Reloc. e.g TAU with SGW Reloc with Data Forwarding */ if((bearer->s1u_enb_gtpu_ip.ipv4_addr != 0) || *(bearer->s1u_enb_gtpu_ip.ipv6_addr)) { len += set_forwarding_param(&(pfcp_sess_est_req->create_far[pdr_idx].frwdng_parms), bearer->s1u_enb_gtpu_ip, bearer->s1u_enb_gtpu_teid, DESTINATION_INTERFACE_VALUE_ACCESS); pfcp_sess_est_req->create_far[pdr_idx].header.len += len; } else { pfcp_sess_est_req->create_far[pdr_idx].apply_action.nocp = PRESENT; pfcp_sess_est_req->create_far[pdr_idx].apply_action.buff = PRESENT; pfcp_sess_est_req->create_far[pdr_idx].apply_action.forw = NOT_PRESENT; bearer->pdrs[idx]->far.actions.nocp = PRESENT; bearer->pdrs[idx]->far.actions.buff = PRESENT; bearer->pdrs[idx]->far.actions.forw = NOT_PRESENT; } } else { pfcp_sess_est_req->create_far[pdr_idx].apply_action.forw = PRESENT; bearer->pdrs[idx]->far.actions.forw = PRESENT; if(context->indirect_tunnel_flag == 0 ) { len += set_forwarding_param(&(pfcp_sess_est_req->create_far[pdr_idx].frwdng_parms), bearer->s5s8_pgw_gtpu_ip, bearer->s5s8_pgw_gtpu_teid, DESTINATION_INTERFACE_VALUE_CORE); } else { len += set_forwarding_param(&(pfcp_sess_est_req->create_far[pdr_idx].frwdng_parms), bearer->s1u_enb_gtpu_ip, bearer->s1u_enb_gtpu_teid, DESTINATION_INTERFACE_VALUE_ACCESS); } pfcp_sess_est_req->create_far[pdr_idx].header.len += len; } } if ((context != NULL) && (imsi_id_config != NULL) && (imsi_id_config->cntr > 0)) { update_li_info_in_dup_params(imsi_id_config, context, &(pfcp_sess_est_req->create_far[pdr_idx])); } if ((context->cp_mode == PGWC) || (SAEGWC == context->cp_mode)) { pfcp_sess_est_req->create_far[pdr_idx].apply_action.forw = PRESENT; if (pfcp_sess_est_req->create_far[pdr_idx].apply_action.forw == PRESENT) { uint16_t len = 0; if (SOURCE_INTERFACE_VALUE_ACCESS == bearer->pdrs[idx]->pdi.src_intfc.interface_value) { len = set_destination_interface(&(pfcp_sess_est_req->create_far[pdr_idx].frwdng_parms.dst_intfc), bearer->pdrs[idx]->far.dst_intfc.interface_value); pfcp_set_ie_header(&(pfcp_sess_est_req->create_far[pdr_idx].frwdng_parms.header), IE_FRWDNG_PARMS, len); pfcp_sess_est_req->create_far[pdr_idx].frwdng_parms.header.len = len; len += UPD_PARAM_HEADER_SIZE; pfcp_sess_est_req->create_far[pdr_idx].header.len += len; } else { if (context->cp_mode == PGWC) { node_address_t node_value = {0}; if ((bearer->s5s8_pgw_gtpu_ip.ip_type == PDN_TYPE_IPV6 || bearer->s5s8_pgw_gtpu_ip.ip_type == PDN_TYPE_IPV4_IPV6) && (*bearer->pdrs[idx]->far.outer_hdr_creation.ipv6_address)) { node_value.ip_type = PDN_TYPE_IPV6; memcpy(node_value.ipv6_addr, bearer->pdrs[idx]->far.outer_hdr_creation.ipv6_address, IPV6_ADDRESS_LEN); } else if (bearer->s5s8_pgw_gtpu_ip.ip_type == PDN_TYPE_IPV4 && (bearer->pdrs[idx]->far.outer_hdr_creation.ipv4_address != 0)) { node_value.ip_type |= PDN_TYPE_IPV4; node_value.ipv4_addr = bearer->pdrs[idx]->far.outer_hdr_creation.ipv4_address; } else { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address in Create FAR", LOG_VALUE); } len += set_forwarding_param(&(pfcp_sess_est_req->create_far[pdr_idx].frwdng_parms), node_value, bearer->pdrs[idx]->far.outer_hdr_creation.teid, bearer->pdrs[idx]->far.dst_intfc.interface_value); } else { pfcp_sess_est_req->create_far[pdr_idx].apply_action.nocp = PRESENT; pfcp_sess_est_req->create_far[pdr_idx].apply_action.buff = PRESENT; pfcp_sess_est_req->create_far[pdr_idx].apply_action.forw = NOT_PRESENT; bearer->pdrs[idx]->far.actions.nocp = PRESENT; bearer->pdrs[idx]->far.actions.buff = PRESENT; bearer->pdrs[idx]->far.actions.forw = NOT_PRESENT; } pfcp_sess_est_req->create_far[pdr_idx].header.len += len; } } if (bearer->num_dynamic_filters != 0 ){ qer_context = get_qer_entry(bearer->qer_id[idx].qer_id, bearer->pdn->seid); /* Assign the value from the PDR */ if(qer_context){ set_create_qer(&(pfcp_sess_est_req->create_qer[qer_idx]), qer_context); qer_idx++; } } } if ((PRESENT == pfcp_sess_est_req->create_far[pdr_idx].apply_action.buff) && (PGWC != context->cp_mode)) { /* fillup bar information in bearer */ bearer->pdrs[idx]->far.bar_id_value = bar_id; uint16_t len = 0; len = set_bar_id(&(pfcp_sess_est_req->create_far[pdr_idx].bar_id), bar_id); pfcp_sess_est_req->create_far[pdr_idx].header.len += len; } pdr_idx++; } if (bearer->num_dynamic_filters != 0){ pfcp_sess_est_req->create_qer_count += bearer->qer_count; } if (bearer->dynamic_rules != NULL ){ set_sdf_rules_create_pdr(pfcp_sess_est_req, bearer, &pdr_itr); } if(bearer->prdef_rules != NULL ){ set_pdef_rules_create_pdr(pfcp_sess_est_req->create_pdr, bearer, &pdr_itr); } } } /* send create bar ie */ if ((PGWC != context->cp_mode) && (pdn != NULL)) { pdn->bar.bar_id = bar_id; set_create_bar(&(pfcp_sess_est_req->create_bar), &pdn->bar); bar_id++; } /* Set the pdn connection type */ set_pdn_type(&(pfcp_sess_est_req->pdn_type), &(pdn->pdn_type)); } /** * @brief : Fill ULI information into UE context from CSR * @param : uli is pointer to structure to store uli info * @param : context is a pointer to ue context structure * @return : Returns 0 in case of success , -1 otherwise */ static int fill_uli_info(gtp_user_loc_info_ie_t *uli, ue_context *context) { if (uli->lai) { context->uli_flag |= 1 << 5; context->uli.lai = uli->lai; context->uli.lai2.lai_mcc_digit_2 = uli->lai2.lai_mcc_digit_2; context->uli.lai2.lai_mcc_digit_1 = uli->lai2.lai_mcc_digit_1; context->uli.lai2.lai_mnc_digit_3 = uli->lai2.lai_mnc_digit_3; context->uli.lai2.lai_mcc_digit_3 = uli->lai2.lai_mcc_digit_3; context->uli.lai2.lai_mnc_digit_2 = uli->lai2.lai_mnc_digit_2; context->uli.lai2.lai_mnc_digit_1 = uli->lai2.lai_mnc_digit_1; context->uli.lai2.lai_lac = uli->lai2.lai_lac; } if (uli->tai) { context->uli_flag |= 1; context->uli.tai = uli->tai; context->uli.tai2.tai_mcc_digit_2 = uli->tai2.tai_mcc_digit_2; context->uli.tai2.tai_mcc_digit_1 = uli->tai2.tai_mcc_digit_1; context->uli.tai2.tai_mnc_digit_3 = uli->tai2.tai_mnc_digit_3; context->uli.tai2.tai_mcc_digit_3 = uli->tai2.tai_mcc_digit_3; context->uli.tai2.tai_mnc_digit_2 = uli->tai2.tai_mnc_digit_2; context->uli.tai2.tai_mnc_digit_1 = uli->tai2.tai_mnc_digit_1; context->uli.tai2.tai_tac = uli->tai2.tai_tac; } if (uli->rai) { context->uli_flag |= 1 << 3; context->uli.rai = uli->rai; context->uli.rai2.ria_mcc_digit_2 = uli->rai2.ria_mcc_digit_2; context->uli.rai2.ria_mcc_digit_1 = uli->rai2.ria_mcc_digit_1; context->uli.rai2.ria_mnc_digit_3 = uli->rai2.ria_mnc_digit_3; context->uli.rai2.ria_mcc_digit_3 = uli->rai2.ria_mcc_digit_3; context->uli.rai2.ria_mnc_digit_2 = uli->rai2.ria_mnc_digit_2; context->uli.rai2.ria_mnc_digit_1 = uli->rai2.ria_mnc_digit_1; context->uli.rai2.ria_lac = uli->rai2.ria_lac; context->uli.rai2.ria_rac = uli->rai2.ria_rac; } if (uli->sai) { context->uli_flag |= 1 << 2; context->uli.sai = uli->sai; context->uli.sai2.sai_mcc_digit_2 = uli->sai2.sai_mcc_digit_2; context->uli.sai2.sai_mcc_digit_1 = uli->sai2.sai_mcc_digit_1; context->uli.sai2.sai_mnc_digit_3 = uli->sai2.sai_mnc_digit_3; context->uli.sai2.sai_mcc_digit_3 = uli->sai2.sai_mcc_digit_3; context->uli.sai2.sai_mnc_digit_2 = uli->sai2.sai_mnc_digit_2; context->uli.sai2.sai_mnc_digit_1 = uli->sai2.sai_mnc_digit_1; context->uli.sai2.sai_lac = uli->sai2.sai_lac; context->uli.sai2.sai_sac = uli->sai2.sai_sac; } if (uli->cgi) { context->uli_flag |= 1 << 1; context->uli.cgi = uli->cgi; context->uli.cgi2.cgi_mcc_digit_2 = uli->cgi2.cgi_mcc_digit_2; context->uli.cgi2.cgi_mcc_digit_1 = uli->cgi2.cgi_mcc_digit_1; context->uli.cgi2.cgi_mnc_digit_3 = uli->cgi2.cgi_mnc_digit_3; context->uli.cgi2.cgi_mcc_digit_3 = uli->cgi2.cgi_mcc_digit_3; context->uli.cgi2.cgi_mnc_digit_2 = uli->cgi2.cgi_mnc_digit_2; context->uli.cgi2.cgi_mnc_digit_1 = uli->cgi2.cgi_mnc_digit_1; context->uli.cgi2.cgi_lac = uli->cgi2.cgi_lac; context->uli.cgi2.cgi_ci = uli->cgi2.cgi_ci; } if (uli->ecgi) { context->uli_flag |= 1 << 4; context->uli.ecgi = uli->ecgi; context->uli.ecgi2.ecgi_mcc_digit_2 = uli->ecgi2.ecgi_mcc_digit_2; context->uli.ecgi2.ecgi_mcc_digit_1 = uli->ecgi2.ecgi_mcc_digit_1; context->uli.ecgi2.ecgi_mnc_digit_3 = uli->ecgi2.ecgi_mnc_digit_3; context->uli.ecgi2.ecgi_mcc_digit_3 = uli->ecgi2.ecgi_mcc_digit_3; context->uli.ecgi2.ecgi_mnc_digit_2 = uli->ecgi2.ecgi_mnc_digit_2; context->uli.ecgi2.ecgi_mnc_digit_1 = uli->ecgi2.ecgi_mnc_digit_1; context->uli.ecgi2.ecgi_spare = uli->ecgi2.ecgi_spare; context->uli.ecgi2.eci = uli->ecgi2.eci; } if (uli->macro_enodeb_id) { context->uli.macro_enodeb_id = uli->macro_enodeb_id; context->uli.macro_enodeb_id2.menbid_mcc_digit_2 = uli->macro_enodeb_id2.menbid_mcc_digit_2; context->uli.macro_enodeb_id2.menbid_mcc_digit_1 = uli->macro_enodeb_id2.menbid_mcc_digit_1; context->uli.macro_enodeb_id2.menbid_mnc_digit_3 = uli->macro_enodeb_id2.menbid_mnc_digit_3; context->uli.macro_enodeb_id2.menbid_mcc_digit_3 = uli->macro_enodeb_id2.menbid_mcc_digit_3; context->uli.macro_enodeb_id2.menbid_mnc_digit_2 = uli->macro_enodeb_id2.menbid_mnc_digit_2; context->uli.macro_enodeb_id2.menbid_mnc_digit_1 = uli->macro_enodeb_id2.menbid_mnc_digit_1; context->uli.macro_enodeb_id2.menbid_spare = uli->macro_enodeb_id2.menbid_spare; context->uli.macro_enodeb_id2.menbid_macro_enodeb_id = uli->macro_enodeb_id2.menbid_macro_enodeb_id; context->uli.macro_enodeb_id2.menbid_macro_enb_id2 = uli->macro_enodeb_id2.menbid_macro_enb_id2; } if (uli->extnded_macro_enb_id) { context->uli.extnded_macro_enb_id = uli->extnded_macro_enb_id; context->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_1 = uli->extended_macro_enodeb_id2.emenbid_mcc_digit_1; context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_3 = uli->extended_macro_enodeb_id2.emenbid_mnc_digit_3; context->uli.extended_macro_enodeb_id2.emenbid_mcc_digit_3 = uli->extended_macro_enodeb_id2.emenbid_mcc_digit_3; context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_2 = uli->extended_macro_enodeb_id2.emenbid_mnc_digit_2; context->uli.extended_macro_enodeb_id2.emenbid_mnc_digit_1 = uli->extended_macro_enodeb_id2.emenbid_mnc_digit_1; context->uli.extended_macro_enodeb_id2.emenbid_smenb = uli->extended_macro_enodeb_id2.emenbid_smenb; context->uli.extended_macro_enodeb_id2.emenbid_spare = uli->extended_macro_enodeb_id2.emenbid_spare; context->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id = uli->extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id; context->uli.extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2 = uli->extended_macro_enodeb_id2.emenbid_extnded_macro_enb_id2; } return 0; } int fill_context_info(create_sess_req_t *csr, ue_context *context, pdn_connection *pdn) { int ret = 0; if (csr->mei.header.len) memcpy(&context->mei, &csr->mei.mei, csr->mei.header.len); memcpy(&context->msisdn, &csr->msisdn.msisdn_number_digits, csr->msisdn.header.len); if ((context->cp_mode == SGWC) || (context->cp_mode == SAEGWC)) { /* Storing s11_mme_gtpc_ip on the basis of IP type in CSReq * Storing s11_sgw_gtpc_ip on the basis of IP type of s11_mme_gtpc_ip in CSReq */ if (csr->sender_fteid_ctl_plane.v4) { context->s11_mme_gtpc_ip.ipv4_addr = csr->sender_fteid_ctl_plane.ipv4_address; context->s11_mme_gtpc_ip.ip_type = PDN_TYPE_IPV4; context->s11_sgw_gtpc_ip.ipv4_addr = config.s11_ip.s_addr; context->s11_sgw_gtpc_ip.ip_type = PDN_TYPE_IPV4; } else if (csr->sender_fteid_ctl_plane.v6) { memcpy(context->s11_mme_gtpc_ip.ipv6_addr, csr->sender_fteid_ctl_plane.ipv6_address, IPV6_ADDRESS_LEN); context->s11_mme_gtpc_ip.ip_type = PDN_TYPE_IPV6; memcpy(context->s11_sgw_gtpc_ip.ipv6_addr, config.s11_ip_v6.s6_addr, IPV6_ADDRESS_LEN); context->s11_sgw_gtpc_ip.ip_type = PDN_TYPE_IPV6; } ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } if(csr->indctn_flgs.header.len != 0) { context->indication_flag.oi = csr->indctn_flgs.indication_oi; context->indication_flag.crsi = csr->indctn_flgs.indication_crsi; context->indication_flag.sgwci= csr->indctn_flgs.indication_sgwci; context->indication_flag.hi = csr->indctn_flgs.indication_hi; context->indication_flag.ccrsi = csr->indctn_flgs.indication_ccrsi; context->indication_flag.cprai = csr->indctn_flgs.indication_cprai; context->indication_flag.clii = csr->indctn_flgs.indication_clii; context->indication_flag.dfi = csr->indctn_flgs.indication_dfi; context->indication_flag.ltempi = csr->indctn_flgs.indication_ltempi; context->indication_flag.pt = csr->indctn_flgs.indication_pt; if (csr->indctn_flgs.indication_ltempi != 0) context->ltem_rat_type_flag = TRUE; if (context->indication_flag.oi == 1) context->procedure = SGW_RELOCATION_PROC; } } /*Storing Dual Address Bearer Flag for IPv6 IP assignment*/ if(csr->indctn_flgs.header.len != 0) context->indication_flag.daf = csr->indctn_flgs.indication_daf; /* It's senders TEID * MME TEID for MME -> SGW * SGW TEID for SGW -> PGW */ context->s11_mme_gtpc_teid = csr->sender_fteid_ctl_plane.teid_gre_key; /* Stored the serving network information in UE context */ if(csr->serving_network.header.len != 0) { context->serving_nw_flag = TRUE; context->serving_nw.mnc_digit_1 = csr->serving_network.mnc_digit_1; context->serving_nw.mnc_digit_2 = csr->serving_network.mnc_digit_2; context->serving_nw.mnc_digit_3 = csr->serving_network.mnc_digit_3; context->serving_nw.mcc_digit_1 = csr->serving_network.mcc_digit_1; context->serving_nw.mcc_digit_2 = csr->serving_network.mcc_digit_2; context->serving_nw.mcc_digit_3 = csr->serving_network.mcc_digit_3; } if (csr->uci.header.len != 0) { context->uci_flag = TRUE; context->uci.mnc_digit_1 = csr->uci.mnc_digit_1; context->uci.mnc_digit_2 = csr->uci.mnc_digit_2; context->uci.mnc_digit_3 = csr->uci.mnc_digit_3; context->uci.mcc_digit_1 = csr->uci.mcc_digit_1; context->uci.mcc_digit_2 = csr->uci.mcc_digit_2; context->uci.mcc_digit_3 = csr->uci.mcc_digit_3; context->uci.csg_id = csr->uci.csg_id; context->uci.csg_id2 = csr->uci.csg_id2; context->uci.access_mode = csr->uci.access_mode; context->uci.lcsg = csr->uci.lcsg; context->uci.cmi = csr->uci.cmi; } if (csr->ue_time_zone.header.len != 0) { context->ue_time_zone_flag = TRUE; context->tz.tz = csr->ue_time_zone.time_zone; context->tz.dst = csr->ue_time_zone.daylt_svng_time; } if (csr->mo_exception_data_cntr.header.len != 0) { context->mo_exception_flag = TRUE; context->mo_exception_data_counter.timestamp_value = csr->mo_exception_data_cntr.timestamp_value; context->mo_exception_data_counter.counter_value = csr->mo_exception_data_cntr.counter_value; context->mo_exception_flag = true; } /* Stored the RAT TYPE information in UE context */ if (csr->rat_type.header.len != 0) { context->rat_type_flag = TRUE; context->rat_type.rat_type = csr->rat_type.rat_type; context->rat_type.len = csr->rat_type.header.len; } /* Stored the UP selection flag*/ if(csr->up_func_sel_indctn_flgs.header.len != 0) { context->up_selection_flag = TRUE; context->dcnr_flag = csr->up_func_sel_indctn_flgs.dcnr; } /* Stored the RAT TYPE information in UE context */ if (csr->uli.header.len != 0) { fill_uli_info(&csr->uli, context); } /* Maintain the sequence number of CSR */ if(csr->header.gtpc.teid_flag == 1) { context->sequence = pdn->csr_sequence = csr->header.teid.has_teid.seq; } else { context->sequence = pdn->csr_sequence = csr->header.teid.no_teid.seq; } return 0; } static int fill_pdn_type(pdn_connection *pdn, create_sess_req_t *csr, uint8_t cp_type){ if(cp_type != SGWC) { if (csr->pdn_type.pdn_type_pdn_type == PDN_TYPE_IPV4 && ((config.ip_type_supported == IP_V4) || (config.ip_type_supported == IPV4V6_DUAL) || (config.ip_type_supported == IPV4V6_PRIORITY))) { pdn->pdn_type.ipv4 = 1; } else if (csr->pdn_type.pdn_type_pdn_type == PDN_TYPE_IPV6 && ((config.ip_type_supported == IP_V6) || (config.ip_type_supported == IPV4V6_DUAL) || (config.ip_type_supported == IPV4V6_PRIORITY))) { pdn->pdn_type.ipv6 = 1; } else if (csr->pdn_type.pdn_type_pdn_type == PDN_TYPE_IPV4_IPV6) { /*Add condition for DAF == 1 flag*/ if(config.ip_type_supported == IP_V4) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPV6 " "type is not supported by Gateway so only allocating IPV4 \n", LOG_VALUE); pdn->pdn_type.ipv4 = 1; } else if(config.ip_type_supported == IP_V6) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPV4 " "type is not supported by Gateway so only allocating IPV6 \n", LOG_VALUE); pdn->pdn_type.ipv6 = 1; } else if (config.ip_type_supported == IPV4V6_PRIORITY || (config.ip_type_supported == IPV4V6_DUAL && !(csr->indctn_flgs.indication_daf)) ) { if(config.ip_type_priority == IP_V4_PRIORITY) { pdn->pdn_type.ipv4 = 1; } else if(config.ip_type_priority == IP_V6_PRIORITY) { pdn->pdn_type.ipv6 = 1; } } else if (config.ip_type_supported == IPV4V6_DUAL && csr->indctn_flgs.indication_daf) { pdn->pdn_type.ipv4 = 1; pdn->pdn_type.ipv6 = 1; } } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Requested " "PDN type is not supported by Gateway \n", LOG_VALUE); return GTPV2C_CAUSE_PREFERRED_PDN_TYPE_UNSUPPORTED; } } else { if (csr->pdn_type.pdn_type_pdn_type == PDN_TYPE_IPV4) { pdn->pdn_type.ipv4 = 1; } else if (csr->pdn_type.pdn_type_pdn_type == PDN_TYPE_IPV6) { pdn->pdn_type.ipv6 = 1; } else if (csr->pdn_type.pdn_type_pdn_type == PDN_TYPE_IPV4_IPV6) { pdn->pdn_type.ipv4 = 1; pdn->pdn_type.ipv6 = 1; } } return 0; } int fill_pdn_info(create_sess_req_t *csr, pdn_connection *pdn, ue_context *context, eps_bearer *bearer) { pdn->apn_ambr.ambr_downlink = csr->apn_ambr.apn_ambr_dnlnk; pdn->apn_ambr.ambr_uplink = csr->apn_ambr.apn_ambr_uplnk; pdn->apn_restriction = csr->max_apn_rstrct.rstrct_type_val; if (csr->chrgng_char.header.len) memcpy(&pdn->charging_characteristics, &csr->chrgng_char.chrgng_char_val, sizeof(csr->chrgng_char.chrgng_char_val)); if ((context->cp_mode == SGWC) || ( context->cp_mode == SAEGWC)) { if (!pdn->s5s8_sgw_gtpc_teid) { pdn->s5s8_sgw_gtpc_teid = get_s5s8_sgw_gtpc_teid(); } /*On the basis of requested PGW IP type storing s5s8_sgw_gtpc_ip */ if (csr->pgw_s5s8_addr_ctl_plane_or_pmip.v4) { pdn->s5s8_sgw_gtpc_ip.ipv4_addr = config.s5s8_ip.s_addr; pdn->s5s8_sgw_gtpc_ip.ip_type = PDN_TYPE_IPV4; } else if (csr->pgw_s5s8_addr_ctl_plane_or_pmip.v6) { memcpy(pdn->s5s8_sgw_gtpc_ip.ipv6_addr, config.s5s8_ip_v6.s6_addr, IPV6_ADDRESS_LEN); pdn->s5s8_sgw_gtpc_ip.ip_type = PDN_TYPE_IPV6; } if(context->cp_mode == SGWC) { if (csr->pgw_s5s8_addr_ctl_plane_or_pmip.v4) { pdn->s5s8_pgw_gtpc_ip.ipv4_addr = csr->pgw_s5s8_addr_ctl_plane_or_pmip.ipv4_address; pdn->s5s8_pgw_gtpc_ip.ip_type = PDN_TYPE_IPV4; } else if (csr->pgw_s5s8_addr_ctl_plane_or_pmip.v6) { memcpy(pdn->s5s8_pgw_gtpc_ip.ipv6_addr, csr->pgw_s5s8_addr_ctl_plane_or_pmip.ipv6_address, IPV6_ADDRESS_LEN); pdn->s5s8_pgw_gtpc_ip.ip_type = PDN_TYPE_IPV6; } } else { if (csr->pgw_s5s8_addr_ctl_plane_or_pmip.v4) { /*Set only V4 address as */ pdn->s5s8_pgw_gtpc_ip.ipv4_addr = config.s5s8_ip.s_addr; pdn->s5s8_pgw_gtpc_ip.ip_type = PDN_TYPE_IPV4; } else if (csr->pgw_s5s8_addr_ctl_plane_or_pmip.v6) { memcpy(pdn->s5s8_pgw_gtpc_ip.ipv6_addr, config.s5s8_ip_v6.s6_addr, IPV6_ADDRESS_LEN); pdn->s5s8_pgw_gtpc_ip.ip_type = PDN_TYPE_IPV6; } /* Allocate the TEID in case of promotion and demotion case */ /* s11_sgw_gtpc_teid = s5s8_pgw_gtpc_teid */ pdn->s5s8_pgw_gtpc_teid = context->s11_sgw_gtpc_teid; } } else if (context->cp_mode == PGWC) { if (csr->sender_fteid_ctl_plane.v4) { pdn->s5s8_pgw_gtpc_ip.ipv4_addr = config.s5s8_ip.s_addr; pdn->s5s8_pgw_gtpc_ip.ip_type = PDN_TYPE_IPV4; } else if (csr->sender_fteid_ctl_plane.v6) { memcpy(pdn->s5s8_pgw_gtpc_ip.ipv6_addr, config.s5s8_ip_v6.s6_addr, IPV6_ADDRESS_LEN); pdn->s5s8_pgw_gtpc_ip.ip_type = PDN_TYPE_IPV6; } if (csr->sender_fteid_ctl_plane.v4) { pdn->s5s8_sgw_gtpc_ip.ipv4_addr = csr->sender_fteid_ctl_plane.ipv4_address; pdn->s5s8_sgw_gtpc_ip.ip_type = PDN_TYPE_IPV4; } else if (csr->sender_fteid_ctl_plane.v6) { memcpy(pdn->s5s8_sgw_gtpc_ip.ipv6_addr, csr->sender_fteid_ctl_plane.ipv6_address, IPV6_ADDRESS_LEN); pdn->s5s8_sgw_gtpc_ip.ip_type = PDN_TYPE_IPV6; } /* Note: s5s8_pgw_gtpc_teid generated from * s5s8_pgw_gtpc_base_teid and incremented * for each pdn connection, similar to * s11_sgw_gtpc_teid */ pdn->s5s8_pgw_gtpc_teid = context->s11_sgw_gtpc_teid; /* Note: s5s8_sgw_gtpc_teid = * * s11_sgw_gtpc_teid * */ pdn->s5s8_sgw_gtpc_teid = csr->sender_fteid_ctl_plane.teid_gre_key; /* Maitain the fqdn into table */ memcpy(pdn->fqdn, (char *)csr->sgw_u_node_name.fqdn, csr->sgw_u_node_name.header.len); } if (csr->indctn_flgs.header.len != 0 && ((context->indication_flag.oi == 1) || ((context->indication_flag.oi == 0) && (context->indication_flag.daf == 0) && (csr->pgw_s5s8_addr_ctl_plane_or_pmip.teid_gre_key != 0)))) { if (pdn->pdn_type.ipv4) { pdn->uipaddr.ipv4.s_addr = csr->paa.pdn_addr_and_pfx; } if (pdn->pdn_type.ipv6) { memcpy(pdn->uipaddr.ipv6.s6_addr, csr->paa.paa_ipv6, IPV6_ADDRESS_LEN); } pdn->s5s8_pgw_gtpc_teid = csr->pgw_s5s8_addr_ctl_plane_or_pmip.teid_gre_key; } /* Promotion Case */ if (!pdn->dp_seid) { pdn->dp_seid = 0; pdn->seid = SESS_ID(context->s11_sgw_gtpc_teid, bearer->eps_bearer_id); } pdn->context = context; if (context->cp_mode == SGWC) { if(csr->pgw_s5s8_addr_ctl_plane_or_pmip.v6) { memcpy(s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr, csr->pgw_s5s8_addr_ctl_plane_or_pmip.ipv6_address, IPV6_ADDRESS_LEN); s5s8_recv_sockaddr.type = PDN_TYPE_IPV6; } else if(csr->pgw_s5s8_addr_ctl_plane_or_pmip.v4){ s5s8_recv_sockaddr.ipv4.sin_addr.s_addr = csr->pgw_s5s8_addr_ctl_plane_or_pmip.ipv4_address; s5s8_recv_sockaddr.type = PDN_TYPE_IPV4; } /* Check for wheather to Generate CDR or NOT */ if(config.generate_sgw_cdr == SGW_CC_CHECK){ if(config.sgw_cc == csr->chrgng_char.chrgng_char_val){ pdn->generate_cdr = PRESENT; }else{ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" %s CC value Missmatched\n", LOG_VALUE); pdn->generate_cdr = NOT_PRESENT; } }else{ pdn->generate_cdr = config.generate_sgw_cdr; } }else { /* Check for wheather to Generate CDR or NOT */ pdn->generate_cdr = config.generate_cdr; } /*Store Requested PDN type*/ pdn->requested_pdn_type = csr->pdn_type.pdn_type_pdn_type; /* Stored the mapped ue usage type information in PDN */ if (csr->mapped_ue_usage_type.header.len != 0) { pdn->mapped_ue_usage_type = csr->mapped_ue_usage_type.mapped_ue_usage_type; } else { pdn->mapped_ue_usage_type = -1; } return 0; } int check_interface_type(uint8_t iface, uint8_t cp_type){ switch(iface){ case GTPV2C_IFTYPE_S1U_ENODEB_GTPU: if ((cp_type == SGWC) || (cp_type == SAEGWC)) { return DESTINATION_INTERFACE_VALUE_ACCESS; } break; case GTPV2C_IFTYPE_S5S8_SGW_GTPU: if (cp_type == PGWC){ return DESTINATION_INTERFACE_VALUE_ACCESS; } break; case GTPV2C_IFTYPE_S5S8_PGW_GTPU: if (cp_type == SGWC){ return DESTINATION_INTERFACE_VALUE_CORE; } break; case GTPV2C_IFTYPE_S11_MME_GTPU: if (cp_type != PGWC){ return DESTINATION_INTERFACE_VALUE_ACCESS; } break; case GTPV2C_IFTYPE_S1U_SGW_GTPU: case GTPV2C_IFTYPE_S11U_SGW_GTPU: case GTPV2C_IFTYPE_S11_MME_GTPC: case GTPV2C_IFTYPE_S11S4_SGW_GTPC: case GTPV2C_IFTYPE_S5S8_SGW_GTPC: case GTPV2C_IFTYPE_S5S8_PGW_GTPC: case GTPV2C_IFTYPE_S5S8_SGW_PIMPv6: case GTPV2C_IFTYPE_S5S8_PGW_PIMPv6: default: clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid interface " "type\n", LOG_VALUE); return -1; break; } return -1; } int fill_dedicated_bearer_info(eps_bearer *bearer, ue_context *context, pdn_connection *pdn, bool prdef_rule) { int ret = 0; upf_context_t *upf_ctx = NULL; int ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } ret = set_address(&bearer->s5s8_sgw_gtpu_ip, &context->eps_bearers[ebi_index]->s5s8_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } #ifdef CP_BUILD if(!prdef_rule && (config.use_gx)){ /* TODO: Revisit this for change in yang*/ if (context->cp_mode != SGWC){ for(uint8_t itr = bearer->qer_count; itr < bearer->qer_count + NUMBER_OF_QER_PER_RULE; itr++){ bearer->qer_id[itr].qer_id = generate_qer_id(&context->qer_rule_id_offset); fill_qer_entry(pdn, bearer,itr); } bearer->qer_count += NUMBER_OF_QER_PER_RULE; } } #endif /* CP_BUILD */ /*SP: As per discussion Per bearer two pdrs and fars will be there*/ /************************************************ * cp_type count FTEID_1 FTEID_2 * ************************************************* SGWC 2 s1u SGWU s5s8 SGWU PGWC 2 s5s8 PGWU NA SAEGWC 2 s1u SAEGWU NA ************************************************/ for(uint8_t itr=bearer->pdr_count; itr < bearer->pdr_count + NUMBER_OF_PDR_PER_RULE; itr++){ switch(itr){ case SOURCE_INTERFACE_VALUE_ACCESS: fill_pdr_entry(context, pdn, bearer, SOURCE_INTERFACE_VALUE_ACCESS, itr); break; case SOURCE_INTERFACE_VALUE_CORE: fill_pdr_entry(context, pdn, bearer, SOURCE_INTERFACE_VALUE_CORE, itr); break; default: break; } } bearer->pdr_count += NUMBER_OF_PDR_PER_RULE; bearer->pdn = pdn; ret = rte_hash_lookup_data(upf_context_by_ip_hash, (const void*) &(pdn->upf_ip), (void **) &(upf_ctx)); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO ENTRY FOUND IN UPF " "HASH, IP Type : %s with IPv4 : "IPV4_ADDR"\t and IPv6 : "IPv6_FMT"", LOG_VALUE, ip_type_str(pdn->upf_ip.ip_type), IPV4_ADDR_HOST_FORMAT(pdn->upf_ip.ipv4_addr), PRINT_IPV6_ADDR(pdn->upf_ip.ipv6_addr)); return GTPV2C_CAUSE_INVALID_PEER; } if (context->cp_mode == SGWC) { ret = set_address(&bearer->s5s8_sgw_gtpu_ip, &upf_ctx->s5s8_sgwu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } ret = set_address(&bearer->s1u_sgw_gtpu_ip, &upf_ctx->s1u_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s1u_sgw_gtpu_teid = get_s1u_sgw_gtpu_teid(bearer->pdn->upf_ip, context->cp_mode, &upf_teid_info_head); update_pdr_teid(bearer, bearer->s1u_sgw_gtpu_teid, upf_ctx->s1u_ip, SOURCE_INTERFACE_VALUE_ACCESS); bearer->s5s8_sgw_gtpu_teid = get_s5s8_sgw_gtpu_teid(bearer->pdn->upf_ip, context->cp_mode, &upf_teid_info_head); update_pdr_teid(bearer, bearer->s5s8_sgw_gtpu_teid, upf_ctx->s5s8_sgwu_ip, SOURCE_INTERFACE_VALUE_CORE); }else if (context->cp_mode == SAEGWC) { ret = set_address(&bearer->s1u_sgw_gtpu_ip, &upf_ctx->s1u_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s1u_sgw_gtpu_teid = get_s1u_sgw_gtpu_teid(bearer->pdn->upf_ip, context->cp_mode, &upf_teid_info_head); update_pdr_teid(bearer, bearer->s1u_sgw_gtpu_teid, upf_ctx->s1u_ip, SOURCE_INTERFACE_VALUE_ACCESS); /* Suppport the promotion and demotion */ ret = set_address(&bearer->s5s8_pgw_gtpu_ip, &upf_ctx->s5s8_pgwu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s5s8_pgw_gtpu_teid = bearer->s1u_sgw_gtpu_teid; } else { ret = set_address(&bearer->s5s8_pgw_gtpu_ip, &upf_ctx->s5s8_pgwu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s5s8_pgw_gtpu_teid = get_s5s8_pgw_gtpu_teid(bearer->pdn->upf_ip, context->cp_mode, &upf_teid_info_head); update_pdr_teid(bearer, bearer->s5s8_pgw_gtpu_teid, upf_ctx->s5s8_pgwu_ip, SOURCE_INTERFACE_VALUE_ACCESS); } /* TODO: Added handling for QER Approprietly */ if(!prdef_rule && (config.use_gx)){ if (context->cp_mode != SGWC){ for(uint8_t itr = 0; itr < bearer->pdr_count; itr++){ bearer->pdrs[itr]->qer_id[0].qer_id = bearer->qer_id[itr].qer_id; } } } RTE_SET_USED(context); return 0; } /** * @brief : Fill bearer info from incoming data in csr * @param : csr holds data in csr * @param : bearer , pointer to eps bearer structure * @param : context , pointer to ue context structure * @param : pdn , pointer to pdn connction structure * @param : index, index of an array * @return : Returns 0 in case of success , -1 otherwise */ static int fill_bearer_info(create_sess_req_t *csr, eps_bearer *bearer, ue_context *context, pdn_connection *pdn, int index ) { int ret = 0; /* Need to re-vist this ARP[Allocation/Retention priority] handling portion */ bearer->qos.arp.priority_level = csr->bearer_contexts_to_be_created[index].bearer_lvl_qos.pl; bearer->qos.arp.preemption_capability = csr->bearer_contexts_to_be_created[index].bearer_lvl_qos.pci; bearer->qos.arp.preemption_vulnerability = csr->bearer_contexts_to_be_created[index].bearer_lvl_qos.pvi; /* TODO: Implement TFTs on default bearers * if (create_session_request.bearer_tft_ie) { * }**/ /* Fill the QCI value */ bearer->qos.qci = csr->bearer_contexts_to_be_created[index].bearer_lvl_qos.qci; bearer->qos.ul_mbr = csr->bearer_contexts_to_be_created[index].bearer_lvl_qos.max_bit_rate_uplnk; bearer->qos.dl_mbr = csr->bearer_contexts_to_be_created[index].bearer_lvl_qos.max_bit_rate_dnlnk; bearer->qos.ul_gbr = csr->bearer_contexts_to_be_created[index].bearer_lvl_qos.guarntd_bit_rate_uplnk; bearer->qos.dl_gbr = csr->bearer_contexts_to_be_created[index].bearer_lvl_qos.guarntd_bit_rate_dnlnk; bearer->s1u_sgw_gtpu_teid = 0; bearer->s5s8_sgw_gtpu_teid = 0; if (context->cp_mode == PGWC){ bearer->s5s8_sgw_gtpu_teid = csr->bearer_contexts_to_be_created[index].s5s8_u_sgw_fteid.teid_gre_key; ret = fill_ip_addr(csr->bearer_contexts_to_be_created[index].s5s8_u_sgw_fteid.ipv4_address, csr->bearer_contexts_to_be_created[index].s5s8_u_sgw_fteid.ipv6_address, &bearer->s5s8_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } if (csr->indctn_flgs.header.len != 0 && ((context->indication_flag.oi) || (context->indication_flag.oi == 0 && context->indication_flag.daf == 0 && (csr->pgw_s5s8_addr_ctl_plane_or_pmip.teid_gre_key != 0)))) { ret = fill_ip_addr(csr->bearer_contexts_to_be_created[index].s5s8_u_pgw_fteid.ipv4_address, csr->bearer_contexts_to_be_created[index].s5s8_u_pgw_fteid.ipv6_address, &bearer->s5s8_pgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s5s8_pgw_gtpu_teid = csr->bearer_contexts_to_be_created[index].s5s8_u_pgw_fteid.teid_gre_key; if((((csr->bearer_contexts_to_be_created[index].s1u_enb_fteid.ipv4_address) != 0) || (*(csr->bearer_contexts_to_be_created[index].s1u_enb_fteid.ipv6_address))) && (csr->bearer_contexts_to_be_created[index].s1u_enb_fteid.teid_gre_key != 0)) { ret = fill_ip_addr(csr->bearer_contexts_to_be_created[index].s1u_enb_fteid.ipv4_address, csr->bearer_contexts_to_be_created[index].s1u_enb_fteid.ipv6_address, &bearer->s1u_enb_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s1u_enb_gtpu_teid = csr->bearer_contexts_to_be_created[index].s1u_enb_fteid.teid_gre_key; } } /*SP: As per discussion Per bearer two pdrs and fars will be there*/ /************************************************ * cp_type count FTEID_1 FTEID_2 * ************************************************* SGWC 2 s1u SGWU s5s8 SGWU PGWC 2 s5s8 PGWU NA SAEGWC 2 s1u SAEGWU NA ************************************************/ for(uint8_t itr = bearer->pdr_count; itr < bearer->pdr_count + NUMBER_OF_PDR_PER_RULE; itr++){ switch(itr){ case SOURCE_INTERFACE_VALUE_ACCESS: fill_pdr_entry(context, pdn, bearer, SOURCE_INTERFACE_VALUE_ACCESS, itr); break; case SOURCE_INTERFACE_VALUE_CORE: fill_pdr_entry(context, pdn, bearer, SOURCE_INTERFACE_VALUE_CORE, itr); break; default: break; } } bearer->pdr_count += NUMBER_OF_PDR_PER_RULE; bearer->pdn = pdn; RTE_SET_USED(context); return 0; } /** * @brief : Generate ccr request * @param : context, ue context * @param : ebi_index * @param : csr, create session request data * @return : Returns 0 on success, -1 otherwise */ static int gen_ccr_request(ue_context *context, int ebi_index , create_sess_req_t *csr) { /* VS: Initialize the Gx Parameters */ uint8_t ret = 0; uint16_t msg_len = 0; uint8_t *buffer = NULL; gx_msg ccr_request = {0}; gx_context_t *gx_context = NULL; pdn_connection *pdn = NULL; pdn = GET_PDN(context, ebi_index); /* VS: Generate unique call id per PDN connection */ pdn->call_id = generate_call_id(); /** Allocate the memory for Gx Context */ gx_context = rte_malloc_socket(NULL, sizeof(gx_context_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (gx_context == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to allocate gx " "context structure: %s \n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* Generate unique session id for communicate over the Gx interface */ if (gen_sess_id_for_ccr(gx_context->gx_sess_id, pdn->call_id)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to " "to generate unnique session id %s \n", LOG_VALUE,strerror(errno)); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Maintain the gx session id in context */ memcpy(pdn->gx_sess_id, gx_context->gx_sess_id, sizeof(pdn->gx_sess_id)); /* Maintain the PDN mapping with call id */ if ((ret = add_pdn_conn_entry(pdn->call_id, pdn) )!= 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add pdn " "entry with call id\n", LOG_VALUE); return ret; } /* Set up the CP Mode */ gx_context->cp_mode = context->cp_mode; /* Set the Msg header type for CCR */ ccr_request.msg_type = GX_CCR_MSG ; /* Set Credit Control Request type */ ccr_request.data.ccr.presence.cc_request_type = PRESENT; ccr_request.data.ccr.cc_request_type = INITIAL_REQUEST ; /* Set Credit Control Bearer opertaion type */ ccr_request.data.ccr.presence.bearer_operation = PRESENT; ccr_request.data.ccr.bearer_operation = ESTABLISHMENT ; /* Set bearer identifier value */ ccr_request.data.ccr.presence.bearer_identifier = PRESENT ; ccr_request.data.ccr.bearer_identifier.len = (1 + (uint32_t)log10((context->eps_bearers[ebi_index])->eps_bearer_id)); if (ccr_request.data.ccr.bearer_identifier.len >= GX_BEARER_IDENTIFIER_LEN) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Insufficient memory to copy bearer identifier\n",LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } else { strncpy((char *)ccr_request.data.ccr.bearer_identifier.val, (char *)&(context->eps_bearers[ebi_index])->eps_bearer_id, ccr_request.data.ccr.bearer_identifier.len); } ccr_request.data.ccr.presence.network_request_support = PRESENT; ccr_request.data.ccr.network_request_support = NETWORK_REQUEST_SUPPORTED; /* * nEED TO ADd following to Complete CCR_I, these are all mandatory IEs * AN-GW Addr (SGW) * User Eqip info (IMEI) * 3GPP-ULI * calling station id (APN) * Access n/w charging addr (PGW addr) * Charging Id */ /* Fill the Credit Crontrol Request to send PCRF */ if(fill_ccr_request(&ccr_request.data.ccr, context, ebi_index, gx_context->gx_sess_id, 0) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to fill " "CCR request\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } update_cli_stats((peer_address_t *) &config.gx_ip, OSS_CCR_INITIAL, SENT, GX); /* Update UE State */ pdn->state = CCR_SNT_STATE; /* Set the Gx State for events */ gx_context->state = CCR_SNT_STATE; gx_context->proc = pdn->proc; /* Maintain the Gx context mapping with Gx Session id */ if ((ret = gx_context_entry_add(gx_context->gx_sess_id, gx_context)) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "gx context entry : %s \n", LOG_VALUE, strerror(errno)); return ret; } /* Calculate the max size of CCR msg to allocate the buffer */ msg_len = gx_ccr_calc_length(&ccr_request.data.ccr); ccr_request.msg_len = msg_len + GX_HEADER_LEN; buffer = rte_zmalloc_socket(NULL, msg_len + GX_HEADER_LEN, RTE_CACHE_LINE_SIZE, rte_socket_id()); if (buffer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to allocate " "CCR Buffer memory structure: %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* Fill the CCR header values */ memcpy(buffer, &ccr_request.msg_type, sizeof(ccr_request.msg_type)); memcpy(buffer + sizeof(ccr_request.msg_type), &ccr_request.msg_len, sizeof(ccr_request.msg_len)); if (gx_ccr_pack(&(ccr_request.data.ccr), (unsigned char *)(buffer + GX_HEADER_LEN), msg_len) == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR in Packing " "CCR Buffer\n", LOG_VALUE); rte_free(buffer); return GTPV2C_CAUSE_SYSTEM_FAILURE; } send_to_ipc_channel(gx_app_sock, buffer, msg_len + GX_HEADER_LEN); rte_free(buffer); free_dynamically_alloc_memory(&ccr_request); RTE_SET_USED(csr); return 0; } /** * @brief : Fill tai data * @param : buf, buffer to be filled * @param : tai, tai data * @return : Returns 0 on success, -1 otherwise */ static int fill_tai(uint8_t *buf, tai_t *tai) { int index = 0; buf[index++] = ((tai->tai_mcc_digit_2 << 4) | (tai->tai_mcc_digit_1)) & 0xff; buf[index++] = ((tai->tai_mnc_digit_3 << 4 )| (tai->tai_mcc_digit_3)) & 0xff; buf[index++] = ((tai->tai_mnc_digit_2 << 4 ) | (tai->tai_mnc_digit_1)) & 0xff; buf[index++] = ((tai->tai_tac >>8) & 0xff); buf[index++] = (tai->tai_tac) &0xff; return sizeof(tai_field_t); } /** * @brief : Fill ecgi data * @param : buf, buffer to be filled * @param : ecgi, ecgi data * @return : Returns 0 on success, -1 otherwise */ static int fill_ecgi(uint8_t *buf, ecgi_t *ecgi) { int index = 0; buf[index++] = ((ecgi->ecgi_mcc_digit_2 << 4 ) | (ecgi->ecgi_mcc_digit_1)) & 0xff; buf[index++] = ((ecgi->ecgi_mnc_digit_3 << 4 ) | (ecgi->ecgi_mcc_digit_3)) & 0xff; buf[index++] = ((ecgi->ecgi_mnc_digit_2 << 4 ) | (ecgi->ecgi_mnc_digit_1)) & 0xff; buf[index++] = (((ecgi->ecgi_spare) | (ecgi->eci >> 24 )) & 0xff); buf[index++] = (((ecgi->eci >> 16 )) & 0xff); buf[index++] = (((ecgi->eci >> 8 )) & 0xff); buf[index++] = (ecgi->eci & 0xff); return sizeof(ecgi_field_t); } /** * @brief : Fill lai data * @param : buf, buffer to be filled * @param : lai, lai data * @return : Returns 0 on success, -1 otherwise */ static int fill_lai(uint8_t *buf, lai_t *lai) { int index = 0; buf[index++] = ((lai->lai_mcc_digit_2 << 4) | (lai->lai_mcc_digit_1)) & 0xff; buf[index++] = ((lai->lai_mnc_digit_3 << 4 )| (lai->lai_mcc_digit_3)) & 0xff; buf[index++] = ((lai->lai_mnc_digit_2 << 4 ) | (lai->lai_mnc_digit_1)) & 0xff; buf[index++] = ((lai->lai_lac >>8) & 0xff); buf[index++] = (lai->lai_lac) &0xff; return sizeof(lai_field_t); } /** * @brief : Fill rai data * @param : buf, buffer to be filled * @param : sai, rai data * @return : Returns 0 on success, -1 otherwise */ static int fill_rai(uint8_t *buf, rai_t *rai) { int index = 0; buf[index++] = ((rai->ria_mcc_digit_2 << 4) | (rai->ria_mcc_digit_1)) & 0xff; buf[index++] = ((rai->ria_mnc_digit_3 << 4 )| (rai->ria_mcc_digit_3)) & 0xff; buf[index++] = ((rai->ria_mnc_digit_2 << 4 ) | (rai->ria_mnc_digit_1)) & 0xff; buf[index++] = ((rai->ria_lac >>8) & 0xff); buf[index++] = (rai->ria_lac) &0xff; buf[index++] = ((rai->ria_rac >>8) & 0xff); buf[index++] = (rai->ria_rac) &0xff; return sizeof(rai_field_t); } /** * @brief : Fill sai data * @param : buf, buffer to be filled * @param : sai, sai data * @return : Returns 0 on success, -1 otherwise */ static int fill_sai(uint8_t *buf, sai_t *sai) { int index = 0; buf[index++] = ((sai->sai_mcc_digit_2 << 4) | (sai->sai_mcc_digit_1)) & 0xff; buf[index++] = ((sai->sai_mnc_digit_3 << 4 )| (sai->sai_mcc_digit_3)) & 0xff; buf[index++] = ((sai->sai_mnc_digit_2 << 4 ) | (sai->sai_mnc_digit_1)) & 0xff; buf[index++] = ((sai->sai_lac >>8) & 0xff); buf[index++] = (sai->sai_lac) &0xff; buf[index++] = ((sai->sai_sac >>8) & 0xff); buf[index++] = (sai->sai_sac) &0xff; return sizeof(sai_field_t); } /** * @brief : Fill cgi data * @param : buf, buffer to be filled * @param : cgi, cgi data * @return : Returns 0 on success, -1 otherwise */ static int fill_cgi(uint8_t *buf, cgi_t *cgi) { int index = 0; buf[index++] = ((cgi->cgi_mcc_digit_2 << 4) | (cgi->cgi_mcc_digit_1)) & 0xff; buf[index++] = ((cgi->cgi_mnc_digit_3 << 4 )| (cgi->cgi_mcc_digit_3)) & 0xff; buf[index++] = ((cgi->cgi_mnc_digit_2 << 4 ) | (cgi->cgi_mnc_digit_1)) & 0xff; buf[index++] = ((cgi->cgi_lac >>8) & 0xff); buf[index++] = (cgi->cgi_lac) &0xff; buf[index++] = ((cgi->cgi_ci >>8) & 0xff); buf[index++] = (cgi->cgi_ci) &0xff; return sizeof(cgi_field_t); } /* @brief : Store rule index in array if it not previously * : stored.Useful to identify rule name. * @param : rule_index, index at which rule is stored in bearer * @param : rule_report_arr, sructure to store rule idex & num * : of packet filter. * @return : nothing. */ static void store_rule_report_index(uint8_t rule_index, rule_report_index_t *rule_report_arr) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Received rule_index : %d\n", LOG_VALUE, rule_index); for(int cnt = 0; cnt < rule_report_arr->rule_cnt; cnt++) { if(rule_index == rule_report_arr->rule_report[cnt]) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"rule_match\n", LOG_VALUE); rule_report_arr->num_fltr[cnt] += 1; return ; } } rule_report_arr->rule_report[(rule_report_arr->rule_cnt)] = rule_index; rule_report_arr->num_fltr[(rule_report_arr->rule_cnt)] += 1; rule_report_arr->rule_cnt++; clLog(clSystemLog, eCLSeverityDebug, "Increment rule count\n"); return ; } void free_dynamically_alloc_memory(gx_msg *ccr_request) { if(ccr_request->data.ccr.presence.subscription_id == PRESENT) { rte_free(&ccr_request->data.ccr.subscription_id.list[0]); ccr_request->data.ccr.subscription_id.list = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Subscription id cleanup succesfully\n", LOG_VALUE); } if(ccr_request->data.ccr.presence.packet_filter_information == PRESENT) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"packet_filter_information.count : %d\n", LOG_VALUE, ccr_request->data.ccr.packet_filter_information.count); rte_free(&ccr_request->data.ccr.packet_filter_information.list[0]); ccr_request->data.ccr.packet_filter_information.list = NULL; clLog(clSystemLog, eCLSeverityDebug, "Free packet filter information : \n", LOG_VALUE); } if(ccr_request->data.ccr.presence.charging_rule_report == PRESENT) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"charging rule report .count : %d\n", LOG_VALUE, ccr_request->data.ccr.charging_rule_report.count); for(int cnt = 0; cnt < ccr_request->data.ccr.charging_rule_report.count; cnt++) { if(ccr_request->data.ccr.charging_rule_report.list[cnt].presence.charging_rule_name == PRESENT) { for(int iCnt = 0; iCnt < ccr_request->data.ccr.charging_rule_report.list[cnt].charging_rule_name.count; iCnt++) { rte_free(&ccr_request->data.ccr.charging_rule_report.list[cnt].charging_rule_name.list[iCnt]); } } } rte_free(&ccr_request->data.ccr.charging_rule_report.list[0]); ccr_request->data.ccr.charging_rule_report.list = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Free Charging rule report : \n", LOG_VALUE); } if(ccr_request->data.ccr.presence.presence_reporting_area_information == PRESENT){ rte_free(&ccr_request->data.ccr.presence_reporting_area_information.list[0]); ccr_request->data.ccr.presence_reporting_area_information.list = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"PRA leanup succesfully\n", LOG_VALUE); } if(ccr_request->data.ccr.event_trigger.list != NULL){ rte_free(ccr_request->data.ccr.event_trigger.list); ccr_request->data.ccr.event_trigger.list = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Free Event trigger done : \n", LOG_VALUE); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Cleanup Succesfully\n", LOG_VALUE); } /** * @brief : Generate CCR-U request for BRC * @param : bearer_rsrc_cmd , pointer to received bearer resource cmd * @param : ccr_request , pointer to ccr_request * @return : Returns 0 in case of success , error code otherwise */ static int ccru_req_for_bearer_rsrc_mod(bearer_rsrc_cmd_t *bearer_rsrc_cmd, gx_msg *ccr_request, eps_bearer *bearer) { int ret = 0; uint8_t tft_op_code = (((bearer_rsrc_cmd->tad.traffic_agg_desc) >> TFT_OP_CODE_SHIFT ) & TFT_OP_CODE_MASK); /* Set Credit Control Bearer opertaion type */ ccr_request->data.ccr.presence.bearer_operation = PRESENT; switch(tft_op_code) { case TFT_OP_CREATE_NEW : ret = fill_create_new_tft_avp(ccr_request, bearer_rsrc_cmd); break; case TFT_OP_DELETE_EXISTING : clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR :Unsupported TFT OPCODE \n", LOG_VALUE); /*Unsupported TFT code*/ ret = GTPV2C_CAUSE_SEMANTIC_ERR_IN_TAD_OP; break; case TFT_OP_DELETE_FILTER_EXISTING : ret = fill_delete_existing_filter_tft_avp(ccr_request, bearer_rsrc_cmd, bearer); break; case TFT_OP_ADD_FILTER_EXISTING : ret = fill_add_filter_existing_tft_avp(ccr_request, bearer_rsrc_cmd, bearer); break; case TFT_OP_REPLACE_FILTER_EXISTING : ret = fill_replace_filter_existing_tft_avp(ccr_request, bearer_rsrc_cmd, bearer); break; case TFT_OP_NO_OP : ret = fill_no_tft_avp(ccr_request, bearer_rsrc_cmd, bearer); break; case TFT_OP_IGNORE : clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR :Unsupported TFT OPCODE \n", LOG_VALUE); /*Unsupported TFT code*/ ret = GTPV2C_CAUSE_SEMANTIC_ERR_IN_TAD_OP; break; default : clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR :Invalid TFT OPCODE \n", LOG_VALUE); /*Invalid TFT opcode*/ ret = GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; break; } return ret; } int fill_no_tft_avp(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd, eps_bearer *bearer) { if(bearer_rsrc_cmd->flow_qos.header.len == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Flow QoS IE is " "not present for no TFT opcode \n",LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } else { fill_qos_avp_bearer_resource_cmd(ccr_request, bearer_rsrc_cmd); } /*Check E bit is 1 or not for parameter list*/ if ((((bearer_rsrc_cmd->tad.traffic_agg_desc) >> 4) & (E_BIT_MASK)) != 1 ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Parameter list " "is not included, " "E bit is not set \n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } uint8_t pkt_flt_cnt = 0; pkt_flt_cnt = ((bearer_rsrc_cmd->tad.traffic_agg_desc) & NUM_OF_PKT_FLTR_MASK); if (pkt_flt_cnt != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Packet filter list " "should not present when TFT op code is " "no TFT\n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } uint8_t num_param_list = 0; uint8_t pkt_indx = 0; rule_report_index_t rule_report = {0}; int rule_index = -1; num_param_list = ((bearer_rsrc_cmd->tad.header.len - 1) / 3) ; if(num_param_list <= 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Parameter list " "is empty for TFT op code " "no TFT\n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } /*Check received packet filter id in BRC is exist in * bearer or not,if exist then store rule index */ for(int cnt = 0; cnt < num_param_list; cnt++) { param_list param_lst = {0}; parse_parameter_list(&bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx], &param_lst); pkt_indx += 3; rule_index = check_pckt_fltr_id_in_rule(param_lst.packet_id, bearer); if(rule_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Packet filter identifier" "is not exist in given bearer\n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } store_rule_report_index(rule_index, &rule_report); } /*Include rule name for affected rule in AVP*/ ccr_request->data.ccr.presence.charging_rule_report = PRESENT; ccr_request->data.ccr.charging_rule_report.count = rule_report.rule_cnt; ccr_request->data.ccr.charging_rule_report.list = rte_malloc_socket(NULL, (sizeof(GxChargingRuleReport)*(rule_report.rule_cnt)), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.charging_rule_report.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule report information avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } for(int id = 0; id < rule_report.rule_cnt; id++) { ccr_request->data.ccr.charging_rule_report.list[id].presence.charging_rule_name = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.count = 1; ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list = rte_malloc_socket(NULL, (sizeof(GxChargingRuleNameOctetString)*(rule_report.rule_cnt)), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule name avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].len = strnlen(bearer->dynamic_rules[rule_report.rule_report[id]]->rule_name, RULE_NAME_LEN); memcpy(ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].val, bearer->dynamic_rules[rule_report.rule_report[id]]->rule_name, strlen(bearer->dynamic_rules[0]->rule_name)); ccr_request->data.ccr.charging_rule_report.list[id].presence.pcc_rule_status = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].pcc_rule_status = ACTIVE; ccr_request->data.ccr.charging_rule_report.list[id].presence.rule_failure_code = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].rule_failure_code = NO_BEARER_BOUND; } ccr_request->data.ccr.bearer_operation = MODIFICATION; ccr_request->data.ccr.presence.packet_filter_operation = PRESENT; ccr_request->data.ccr.packet_filter_operation = MODIFICATION; ccr_request->data.ccr.presence.packet_filter_information = PRESENT; /*As per spec 29.212 only one Packet-Filter-Information AVP should present*/ ccr_request->data.ccr.packet_filter_information.count = num_param_list; ccr_request->data.ccr.packet_filter_information.list = rte_malloc_socket(NULL, (sizeof(GxPacketFilterInformation)*num_param_list),RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.packet_filter_information.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to" "allocate Packet filter Buffer : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } pkt_indx = 0; for (int idx = 0; idx < num_param_list; idx++) { /* TODO : remove hardcode value */ ccr_request->data.ccr.packet_filter_information.list[idx].presence.packet_filter_identifier = PRESENT; param_list param_lst = {0}; parse_parameter_list(&bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx], &param_lst); pkt_indx += 3; memcpy(ccr_request->data.ccr.packet_filter_information.list[idx].packet_filter_identifier.val, &param_lst.packet_id,1); ccr_request->data.ccr.packet_filter_information.list[idx].packet_filter_identifier.len = 1; } return 0; } int fill_create_new_tft_avp(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd) { ccr_request->data.ccr.bearer_operation = ESTABLISHMENT; ccr_request->data.ccr.presence.packet_filter_operation = PRESENT; ccr_request->data.ccr.packet_filter_operation = ADDITION; ccr_request->data.ccr.presence.packet_filter_information = PRESENT; if(bearer_rsrc_cmd->flow_qos.header.len != 0) fill_qos_avp_bearer_resource_cmd(ccr_request, bearer_rsrc_cmd); else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Flow QoS IE " "is Missing for create new TFT opcode\n", LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } uint8_t idx = 0; uint8_t pkt_flt_cnt = 0; pkt_flt_cnt = ((bearer_rsrc_cmd->tad.traffic_agg_desc) & NUM_OF_PKT_FLTR_MASK); if(pkt_flt_cnt == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Packet filter " "is Missing while creating new TFT AVp \n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } /*no.of packet filter present BRC inside TAD IE*/ ccr_request->data.ccr.packet_filter_information.count = pkt_flt_cnt; ccr_request->data.ccr.packet_filter_information.list = rte_malloc_socket(NULL, (sizeof(GxPacketFilterInformation)*pkt_flt_cnt),RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.packet_filter_information.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Packet filter information avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } uint8_t pkt_indx = 0; for( idx = 0; idx < pkt_flt_cnt; idx++ ) { ccr_request->data.ccr.packet_filter_information.list[idx].presence.packet_filter_content = PRESENT; ccr_request->data.ccr.packet_filter_information.list[idx].presence.packet_filter_identifier = PRESENT; ccr_request->data.ccr.packet_filter_information.list[idx].presence.flow_direction = PRESENT; ccr_request->data.ccr.packet_filter_information.list[idx].presence.precedence = PRESENT; tad_pkt_fltr_t tad_pkt_fltr = {0}; parse_tad_packet_filter(&bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx], &tad_pkt_fltr); pkt_indx = (bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx + PKT_FLTR_LEN_INDEX]) + PKT_FLTR_CONTENT_INDEX; fill_packet_fltr_info_avp(ccr_request, &tad_pkt_fltr, idx); } return 0; } int fill_replace_filter_existing_tft_avp(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd, eps_bearer *bearer) { ccr_request->data.ccr.bearer_operation = MODIFICATION; ccr_request->data.ccr.presence.packet_filter_operation = PRESENT; ccr_request->data.ccr.packet_filter_operation = MODIFICATION; ccr_request->data.ccr.presence.packet_filter_information = PRESENT; uint8_t idx = 0; uint8_t pkt_flt_cnt = 0; uint8_t pkt_indx = 0; rule_report_index_t rule_report = {0}; int rule_index = -1; pkt_flt_cnt = ((bearer_rsrc_cmd->tad.traffic_agg_desc) & NUM_OF_PKT_FLTR_MASK); if(pkt_flt_cnt == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Packet filter " "is Missing while replacing TFT AVP\n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } /*Check received packet filter id in BRC is exist in bearer or not *If exist, then include store rule index & add rule name in *Charging-Rule-Report AVP */ for (int cnt = 0; cnt < pkt_flt_cnt; cnt++) { tad_pkt_fltr_t tad_pkt_fltr = {0}; parse_tad_packet_filter(&bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx], &tad_pkt_fltr); pkt_indx = (bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx + PKT_FLTR_LEN_INDEX]) + PKT_FLTR_CONTENT_INDEX; rule_index = check_pckt_fltr_id_in_rule(tad_pkt_fltr.pckt_fltr_id, bearer); if(rule_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Packet filter identifier" "is not exist in given bearer\n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } store_rule_report_index(rule_index, &rule_report); } ccr_request->data.ccr.presence.charging_rule_report = PRESENT; ccr_request->data.ccr.charging_rule_report.count = rule_report.rule_cnt; ccr_request->data.ccr.charging_rule_report.list = rte_malloc_socket(NULL, (sizeof(GxChargingRuleReport)*(rule_report.rule_cnt)), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.charging_rule_report.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule report information avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } for(int id = 0; id < rule_report.rule_cnt; id++) { ccr_request->data.ccr.charging_rule_report.list[id].presence.charging_rule_name = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.count = 1; ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list = rte_malloc_socket(NULL, (sizeof(GxChargingRuleNameOctetString)*(rule_report.rule_cnt)), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule name avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].len = strnlen(bearer->dynamic_rules[rule_report.rule_report[id]]->rule_name, RULE_NAME_LEN); memcpy(ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].val, bearer->dynamic_rules[rule_report.rule_report[id]]->rule_name, strlen(bearer->dynamic_rules[0]->rule_name)); ccr_request->data.ccr.charging_rule_report.list[id].presence.pcc_rule_status = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].pcc_rule_status = ACTIVE; ccr_request->data.ccr.charging_rule_report.list[id].presence.rule_failure_code = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].rule_failure_code = NO_BEARER_BOUND; } /*no.of packet filter present BRC inside TAD IE*/ ccr_request->data.ccr.packet_filter_information.count = pkt_flt_cnt; ccr_request->data.ccr.packet_filter_information.list = rte_malloc_socket(NULL, (sizeof(GxPacketFilterInformation)*pkt_flt_cnt),RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.packet_filter_information.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Packet filter information avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } pkt_indx = 0; for( idx = 0; idx < pkt_flt_cnt; idx++ ) { ccr_request->data.ccr.packet_filter_information.list[idx].presence.packet_filter_content = PRESENT; ccr_request->data.ccr.packet_filter_information.list[idx].presence.packet_filter_identifier = PRESENT; ccr_request->data.ccr.packet_filter_information.list[idx].presence.flow_direction = PRESENT; ccr_request->data.ccr.packet_filter_information.list[idx].presence.precedence = PRESENT; tad_pkt_fltr_t tad_pkt_fltr = {0}; parse_tad_packet_filter(&bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx], &tad_pkt_fltr); pkt_indx = (bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx + PKT_FLTR_LEN_INDEX]) + PKT_FLTR_CONTENT_INDEX; fill_packet_fltr_info_avp(ccr_request, &tad_pkt_fltr, idx); } /*If qos is requested to modify*/ if(bearer_rsrc_cmd->flow_qos.header.len != 0) fill_qos_avp_bearer_resource_cmd(ccr_request, bearer_rsrc_cmd); return 0; } int fill_add_filter_existing_tft_avp(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd, eps_bearer *bearer) { /*Check E bit is 1 or not for parameter list*/ if ((((bearer_rsrc_cmd->tad.traffic_agg_desc) >> 4) & (E_BIT_MASK)) != 1 ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Parameter list " "is not included \n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } ccr_request->data.ccr.bearer_operation = MODIFICATION; ccr_request->data.ccr.presence.packet_filter_operation = PRESENT; ccr_request->data.ccr.packet_filter_operation = ADDITION; ccr_request->data.ccr.presence.packet_filter_information = PRESENT; int ret = 0; uint8_t idx = 0; uint8_t pkt_flt_cnt = 0; uint16_t total_len = bearer_rsrc_cmd->tad.header.len; pkt_flt_cnt = ((bearer_rsrc_cmd->tad.traffic_agg_desc) & NUM_OF_PKT_FLTR_MASK); if(pkt_flt_cnt == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Packet filter " "is Missing while adding filter to existing TFT AVP\n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } param_list param_lst = {0}; int id = 0; /*Get index of parameter list in TAD IE*/ uint8_t param_lst_index = bearer_rsrc_cmd->tad.header.len - PARAM_LIST_INDEX; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"param_lst_index : %d\n", LOG_VALUE, param_lst_index); ret = parse_parameter_list(&bearer_rsrc_cmd->tad.pkt_fltr_buf[param_lst_index], &param_lst); if(ret!=0) return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; int rule_index = -1; /*Check received packet filter id in BRC is exist or not*/ rule_index = check_pckt_fltr_id_in_rule(param_lst.packet_id, bearer); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"rule_index : %d\n\n", LOG_VALUE, rule_index); if(rule_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Packet filter id " "is not found in bearer TFT\n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } /*Include affted charging rule name in Charging-Rule-Report AVP*/ ccr_request->data.ccr.presence.charging_rule_report = PRESENT; ccr_request->data.ccr.charging_rule_report.count = 1; ccr_request->data.ccr.charging_rule_report.list = rte_malloc_socket(NULL, (sizeof(GxChargingRuleReport)), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.charging_rule_report.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule report information avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ccr_request->data.ccr.charging_rule_report.list[id].presence.charging_rule_name = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.count = 1; ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list = rte_malloc_socket(NULL, (sizeof(GxChargingRuleNameOctetString)), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule name avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].len = strnlen(bearer->dynamic_rules[rule_index]->rule_name, RULE_NAME_LEN); memcpy(ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].val, bearer->dynamic_rules[rule_index]->rule_name, strlen(bearer->dynamic_rules[rule_index]->rule_name)); ccr_request->data.ccr.charging_rule_report.list[id].presence.pcc_rule_status = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].pcc_rule_status = ACTIVE; ccr_request->data.ccr.charging_rule_report.list[id].presence.rule_failure_code = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].rule_failure_code = NO_BEARER_BOUND; /*no.of packet filter present BRC inside TAD IE*/ ccr_request->data.ccr.packet_filter_information.count = pkt_flt_cnt + 1; /*Assumption : only one parameter list will be present*/ ccr_request->data.ccr.packet_filter_information.list = rte_malloc_socket(NULL, (sizeof(GxPacketFilterInformation)*(pkt_flt_cnt + 1)),RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.packet_filter_information.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Packet filter information avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } uint8_t pkt_indx = 0; uint16_t total_decoded = 1; while (total_decoded < total_len) { for( idx = 0; idx < pkt_flt_cnt; idx++ ) { ccr_request->data.ccr.packet_filter_information.list[idx].presence.packet_filter_content = PRESENT; ccr_request->data.ccr.packet_filter_information.list[idx].presence.packet_filter_identifier = PRESENT; ccr_request->data.ccr.packet_filter_information.list[idx].presence.flow_direction = PRESENT; ccr_request->data.ccr.packet_filter_information.list[idx].presence.precedence = PRESENT; tad_pkt_fltr_t tad_pkt_fltr = {0}; parse_tad_packet_filter(&bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx], &tad_pkt_fltr); fill_packet_fltr_info_avp(ccr_request, &tad_pkt_fltr, idx); pkt_indx += (bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx + PKT_FLTR_LEN_INDEX]) + PKT_FLTR_CONTENT_INDEX; total_decoded += pkt_indx; } param_list param_lst = {0}; ret = parse_parameter_list(&bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx], &param_lst); if(ret!=0) return -1; pkt_indx += PARAMETER_LIST_LEN; total_decoded += PARAMETER_LIST_LEN; /*Fill only packet-filter-identifier in packet-filter-information AVP using param list*/ ccr_request->data.ccr.packet_filter_information.list[idx].presence.packet_filter_identifier = PRESENT; memcpy(ccr_request->data.ccr.packet_filter_information.list[idx].packet_filter_identifier.val, &param_lst.packet_id,1); ccr_request->data.ccr.packet_filter_information.list[idx].packet_filter_identifier.len = 1; idx++; } if(bearer_rsrc_cmd->flow_qos.header.len != 0) fill_qos_avp_bearer_resource_cmd(ccr_request, bearer_rsrc_cmd); return 0; } int fill_delete_existing_filter_tft_avp(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd, eps_bearer *bearer) { ccr_request->data.ccr.presence.packet_filter_operation = PRESENT; ccr_request->data.ccr.packet_filter_operation = DELETION; ccr_request->data.ccr.presence.packet_filter_information = PRESENT; uint8_t idx = 0; uint8_t pkt_indx = 0; uint8_t pkt_flt_cnt = 0; rule_report_index_t rule_report = {0}; int rule_index = -1; pkt_flt_cnt = ((bearer_rsrc_cmd->tad.traffic_agg_desc) & NUM_OF_PKT_FLTR_MASK); if(pkt_flt_cnt == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Packet filter " "is Missing while deleting existing filter TFT AVP \n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"pkt_flt_cnt rcvd in BRC: %d\n", LOG_VALUE, pkt_flt_cnt); /*Check UE sends valid packet filter count or not *if valid then store rule index in structure */ for(int cnt = 0; cnt < pkt_flt_cnt; cnt++ ) { delete_pkt_filter pkt_id = {0}; fill_gx_packet_filter_id(&bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx], &pkt_id); pkt_indx += 1; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"pkt flt id : %d\n", LOG_VALUE, pkt_id.pkt_filter_id); rule_index = check_pckt_fltr_id_in_rule(pkt_id.pkt_filter_id, bearer); if(rule_index == -1){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Packet filter " "is Missing while deleting existing filter TFT AVP \n",LOG_VALUE); return GTPV2C_CAUSE_SYNTACTIC_ERR_IN_TAD_OP; } store_rule_report_index(rule_index, &rule_report); } uint8_t total_no_of_pckt_fltr = 0; for ( int cnt=0 ; cnt < bearer->num_dynamic_filters ; cnt++ ) { total_no_of_pckt_fltr += bearer->dynamic_rules[cnt]->num_flw_desc; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"total_no_of_pckt_fltr : %d\n" "& pkt_flt_cnt in brc : %d\n", LOG_VALUE, total_no_of_pckt_fltr, pkt_flt_cnt); /* If bearer containt num of packet filter which is equal to * num of packet filter id received in BRC then delete that bearer * else update */ if(total_no_of_pckt_fltr == pkt_flt_cnt) { ccr_request->data.ccr.bearer_operation = TERMINATION; ccr_request->data.ccr.presence.charging_rule_report = PRESENT; ccr_request->data.ccr.charging_rule_report.count = rule_report.rule_cnt; ccr_request->data.ccr.charging_rule_report.list = rte_malloc_socket(NULL, (sizeof(GxChargingRuleReport)*(rule_report.rule_cnt)), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.charging_rule_report.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule report information avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } for(int id = 0; id < rule_report.rule_cnt; id++) { ccr_request->data.ccr.charging_rule_report.list[id].presence.charging_rule_name = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.count = 1; ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list = rte_malloc_socket(NULL, (sizeof(GxChargingRuleNameOctetString)), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule name avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].len = strnlen(bearer->dynamic_rules[rule_report.rule_report[id]]->rule_name, RULE_NAME_LEN); memcpy(ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].val, bearer->dynamic_rules[rule_report.rule_report[id]]->rule_name, strlen(bearer->dynamic_rules[0]->rule_name)); ccr_request->data.ccr.charging_rule_report.list[id].presence.pcc_rule_status = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].pcc_rule_status = INACTIVE; ccr_request->data.ccr.charging_rule_report.list[id].presence.rule_failure_code = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].rule_failure_code = NO_BEARER_BOUND; } } else { ccr_request->data.ccr.bearer_operation = MODIFICATION; ccr_request->data.ccr.presence.charging_rule_report = PRESENT; ccr_request->data.ccr.charging_rule_report.count = rule_report.rule_cnt; ccr_request->data.ccr.charging_rule_report.list = rte_malloc_socket(NULL, (sizeof(GxChargingRuleReport)*(rule_report.rule_cnt)), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.charging_rule_report.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule report information avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /*Include Charging-Rule-Report IE for each affected rule*/ for(int id = 0; id < rule_report.rule_cnt; id++) { ccr_request->data.ccr.charging_rule_report.list[id].presence.charging_rule_name = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.count = 1; ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list = rte_malloc_socket(NULL, (sizeof(GxChargingRuleNameOctetString)*(rule_report.rule_cnt)), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule name avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].len = strnlen(bearer->dynamic_rules[rule_report.rule_report[id]]->rule_name, RULE_NAME_LEN); memcpy(ccr_request->data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].val, bearer->dynamic_rules[rule_report.rule_report[id]]->rule_name, strlen(bearer->dynamic_rules[0]->rule_name)); ccr_request->data.ccr.charging_rule_report.list[id].presence.pcc_rule_status = PRESENT; /*If all packet filter in rule is removed then set status to INACTIVE else ACTIVE*/ if(bearer->dynamic_rules[rule_report.rule_report[id]]->num_flw_desc == rule_report.num_fltr[id]) { ccr_request->data.ccr.charging_rule_report.list[id].pcc_rule_status = INACTIVE; } else { ccr_request->data.ccr.charging_rule_report.list[id].pcc_rule_status = ACTIVE; } ccr_request->data.ccr.charging_rule_report.list[id].presence.rule_failure_code = PRESENT; ccr_request->data.ccr.charging_rule_report.list[id].rule_failure_code = NO_BEARER_BOUND; } } /*no.of packet filter identifier present BRC inside TAD IE*/ ccr_request->data.ccr.packet_filter_information.count = pkt_flt_cnt; ccr_request->data.ccr.packet_filter_information.list = rte_malloc_socket(NULL, (sizeof(GxPacketFilterInformation)*pkt_flt_cnt),RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request->data.ccr.packet_filter_information.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Packet filter information avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } pkt_indx = 0; for( idx = 0; idx < pkt_flt_cnt; idx++ ) { ccr_request->data.ccr.packet_filter_information.list[idx].presence.packet_filter_identifier = PRESENT; delete_pkt_filter pkt_id = {0}; fill_gx_packet_filter_id(&bearer_rsrc_cmd->tad.pkt_fltr_buf[pkt_indx], &pkt_id); pkt_indx += 1; ccr_request->data.ccr.packet_filter_information.list[idx].packet_filter_identifier.val[0] = pkt_id.pkt_filter_id; ccr_request->data.ccr.packet_filter_information.list[idx].packet_filter_identifier.len = 1; } if(bearer_rsrc_cmd->flow_qos.header.len != 0) fill_qos_avp_bearer_resource_cmd(ccr_request, bearer_rsrc_cmd); return 0; } int fill_delete_existing_tft_avp(gx_msg *ccr_request) { ccr_request->data.ccr.bearer_operation = TERMINATION; ccr_request->data.ccr.presence.packet_filter_operation = PRESENT; ccr_request->data.ccr.packet_filter_operation = DELETION; return 0; } int parse_parameter_list(uint8_t pkt_fltr_buf[], param_list *param_lst) { param_lst->param_id = pkt_fltr_buf[0]; param_lst->len = pkt_fltr_buf[1]; if(param_lst->param_id == 0x03) { param_lst->packet_id = pkt_fltr_buf[2]; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Parameter identifier in" "parameter list is not supported \n",LOG_VALUE); return -1; } return 0; } int fill_qos_avp_bearer_resource_cmd(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd) { ccr_request->data.ccr.presence.qos_information = PRESENT; ccr_request->data.ccr.qos_information.presence.qos_class_identifier = PRESENT; ccr_request->data.ccr.qos_information.presence.guaranteed_bitrate_ul = PRESENT; ccr_request->data.ccr.qos_information.presence.guaranteed_bitrate_dl = PRESENT; ccr_request->data.ccr.qos_information.qos_class_identifier = bearer_rsrc_cmd->flow_qos.qci; ccr_request->data.ccr.qos_information.guaranteed_bitrate_ul = bearer_rsrc_cmd->flow_qos.guarntd_bit_rate_uplnk; ccr_request->data.ccr.qos_information.guaranteed_bitrate_dl = bearer_rsrc_cmd->flow_qos.guarntd_bit_rate_dnlnk; return 0; } int fill_gx_packet_filter_id(uint8_t *pkt_fltr_buf, delete_pkt_filter *pkt_id) { pkt_id->pkt_filter_id = (*pkt_fltr_buf & 0x0f); return 0; } int parse_tad_packet_filter(uint8_t pkt_fltr_buf[], tad_pkt_fltr_t *tad_pkt_fltr) { int index = 0; int itr = 0 ; uint8_t total_pkt_fltr_len = pkt_fltr_buf[2] + 2; for(index = 0; index< total_pkt_fltr_len; index++) { if(index == 0) { tad_pkt_fltr->pckt_fltr_id = ((pkt_fltr_buf[0]) & 0x0f); tad_pkt_fltr->pckt_fltr_dir = ((pkt_fltr_buf[0] >> 4) & 0x03); continue; } if(index == 1) { tad_pkt_fltr->precedence = pkt_fltr_buf[1]; continue; } if(index == 2) { /*Packet filter length*/ continue; } if (pkt_fltr_buf[index] == TFT_IPV4_SRC_ADDR_TYPE) { memcpy(&tad_pkt_fltr->local_ip_addr,&pkt_fltr_buf[index+1],PKT_FLTR_COMP_TYPE_ID_LEN); index = index + PKT_FLTR_COMP_TYPE_ID_LEN + 1; for ( itr = index; itr < (index+PKT_FLTR_COMP_TYPE_ID_LEN); itr++) { if(pkt_fltr_buf[itr] == 0xff) tad_pkt_fltr->local_ip_mask += IP_MASK; } index = index + NEXT_PKT_FLTR_COMP_INDEX; tad_pkt_fltr->v4 = TRUE; continue; } if (pkt_fltr_buf[index] == TFT_IPV6_SRC_ADDR_PREFIX_LEN_TYPE) { memcpy(&tad_pkt_fltr->local_ip6_addr, &pkt_fltr_buf[index+1], IPV6_ADDRESS_LEN); index = index + IPV6_ADDRESS_LEN + 1; tad_pkt_fltr->local_ip_mask = pkt_fltr_buf[index]; tad_pkt_fltr->v6 = TRUE; continue; } if (pkt_fltr_buf[index] == TFT_IPV6_REMOTE_ADDR_PREFIX_LEN_TYPE) { memcpy(&tad_pkt_fltr->remote_ip6_addr,&pkt_fltr_buf[index+1],IPV6_ADDRESS_LEN); index = index + IPV6_ADDRESS_LEN + 1; tad_pkt_fltr->remote_ip_mask = pkt_fltr_buf[index]; tad_pkt_fltr->v6 = TRUE; continue; } if (pkt_fltr_buf[index] == TFT_IPV4_REMOTE_ADDR_TYPE) { memcpy(&tad_pkt_fltr->remote_ip_addr,&pkt_fltr_buf[index+1],PKT_FLTR_COMP_TYPE_ID_LEN); index = index + PKT_FLTR_COMP_TYPE_ID_LEN + 1; for ( itr = index; itr < (index+PKT_FLTR_COMP_TYPE_ID_LEN); itr++) { if(pkt_fltr_buf[itr] == 0xff) tad_pkt_fltr->remote_ip_mask += IP_MASK; } index = index + NEXT_PKT_FLTR_COMP_INDEX; tad_pkt_fltr->v4 = TRUE; continue; } if (pkt_fltr_buf[index] == TFT_PROTO_IDENTIFIER_NEXT_HEADER_TYPE) { memcpy(&tad_pkt_fltr->proto_id,&pkt_fltr_buf[index+1],1); index = index + 1; continue; } if (pkt_fltr_buf[index] == TFT_DEST_PORT_RANGE_TYPE) { memcpy(&tad_pkt_fltr->local_port_low,&pkt_fltr_buf[index+1],PORT_LEN); index = index + PORT_LEN; memcpy(&tad_pkt_fltr->local_port_high,&pkt_fltr_buf[index+1],PORT_LEN); index = index + PORT_LEN; tad_pkt_fltr->local_port_low = ntohs(tad_pkt_fltr->local_port_low); tad_pkt_fltr->local_port_high = ntohs(tad_pkt_fltr->local_port_high); continue; } if (pkt_fltr_buf[index] == TFT_SRC_PORT_RANGE_TYPE) { memcpy(&tad_pkt_fltr->remote_port_low,&pkt_fltr_buf[index+1],PORT_LEN); index = index + PORT_LEN; memcpy(&tad_pkt_fltr->remote_port_high,&pkt_fltr_buf[index+1],PORT_LEN); index = index + PORT_LEN; tad_pkt_fltr->remote_port_low = ntohs(tad_pkt_fltr->remote_port_low); tad_pkt_fltr->remote_port_high = ntohs(tad_pkt_fltr->remote_port_high); continue; } if(pkt_fltr_buf[index] == TFT_SINGLE_REMOTE_PORT_TYPE) { memcpy(&tad_pkt_fltr->remote_port_low,&pkt_fltr_buf[index+1],PORT_LEN); memcpy(&tad_pkt_fltr->remote_port_high,&pkt_fltr_buf[index+1],PORT_LEN); tad_pkt_fltr->remote_port_low = ntohs(tad_pkt_fltr->remote_port_low); tad_pkt_fltr->remote_port_high = ntohs(tad_pkt_fltr->remote_port_high); index = index + PORT_LEN; continue; } if(pkt_fltr_buf[index] == TFT_SINGLE_SRC_PORT_TYPE) { memcpy(&tad_pkt_fltr->local_port_low,&pkt_fltr_buf[index+1],PORT_LEN); memcpy(&tad_pkt_fltr->local_port_high,&pkt_fltr_buf[index+1],PORT_LEN); tad_pkt_fltr->local_port_low = ntohs(tad_pkt_fltr->local_port_low); tad_pkt_fltr->local_port_high = ntohs(tad_pkt_fltr->local_port_high); index = index + PORT_LEN; continue; } } return 0; } /** * @brief : Generate ccru request * @param : pdn, pdn connection data * @param : bearer, bearer information * @param : bearer resource command * @param : Modify Bearer command * @return : Returns 0 on success, -1 otherwise */ int gen_ccru_request(ue_context *context, eps_bearer *bearer, bearer_rsrc_cmd_t *bearer_rsrc_cmd, mod_bearer_cmd_t *mod_bearer_cmd) { /* * TODO: * Passing bearer as parameter is a BAD IDEA * because what if multiple bearer changes? * code SHOULD anchor only on pdn. */ /* Initialize the Gx Parameters */ uint16_t msg_len = 0; uint8_t bearer_resource_mod_flow_flag = 0; gx_msg ccr_request = {0}; uint8_t *buffer = NULL; gx_context_t *gx_context = NULL; pdn_connection *pdn = NULL; pdn = bearer->pdn; if( pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"PDN not found while generating CCR-UPDATE\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } int ret = rte_hash_lookup_data(gx_context_by_sess_id_hash, (const void*)(pdn->gx_sess_id), (void **)&gx_context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR :NO ENTRY FOUND IN Gx HASH [%s]\n", LOG_VALUE,pdn->gx_sess_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Set the Msg header type for CCR */ ccr_request.msg_type = GX_CCR_MSG ; /* Set Credit Control Request type */ ccr_request.data.ccr.presence.cc_request_type = PRESENT; ccr_request.data.ccr.cc_request_type = UPDATE_REQUEST ; if (bearer_rsrc_cmd == NULL) { /* Set Credit Control Bearer opertaion type */ ccr_request.data.ccr.presence.bearer_operation = PRESENT; ccr_request.data.ccr.bearer_operation = MODIFICATION; } else { bearer_resource_mod_flow_flag = 1; ret = ccru_req_for_bearer_rsrc_mod(bearer_rsrc_cmd, &ccr_request, bearer); if( ret!= 0 ) return ret; } /* Set bearer identifier value */ ccr_request.data.ccr.presence.bearer_identifier = PRESENT; if(bearer_resource_mod_flow_flag == 1) { if (bearer_rsrc_cmd->eps_bearer_id.ebi_ebi != 0) { ccr_request.data.ccr.bearer_identifier.len = (1 + (uint32_t)log10(bearer->eps_bearer_id)); } else { ccr_request.data.ccr.bearer_identifier.len = (1 + (uint32_t)log10(EBI_ABSENT)); } } else { ccr_request.data.ccr.bearer_identifier.len = (1 + (uint32_t)log10(bearer->eps_bearer_id)); } if (ccr_request.data.ccr.bearer_identifier.len >= GX_BEARER_IDENTIFIER_LEN) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Insufficient memory to copy bearer identifier\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } else { strncpy((char *)ccr_request.data.ccr.bearer_identifier.val, (char *)&bearer->eps_bearer_id, ccr_request.data.ccr.bearer_identifier.len); } /* Subscription-Id */ if(context->imsi || context->msisdn) { uint8_t idx = 0; ccr_request.data.ccr.presence.subscription_id = PRESENT; ccr_request.data.ccr.subscription_id.count = 2; // IMSI & MSISDN ccr_request.data.ccr.subscription_id.list = rte_malloc_socket(NULL, (sizeof(GxSubscriptionId)*2), RTE_CACHE_LINE_SIZE, rte_socket_id()); /* Fill IMSI */ if(context->imsi != 0) { ccr_request.data.ccr.subscription_id.list[idx]. subscription_id_type = END_USER_IMSI; ccr_request.data.ccr.subscription_id.list[idx]. subscription_id_data.len = pdn->context->imsi_len; memcpy(ccr_request.data.ccr.subscription_id.list[idx].subscription_id_data.val, &context->imsi, context->imsi_len); idx++; } /* Fill MSISDN */ if(context->msisdn !=0) { ccr_request.data.ccr.subscription_id.list[idx]. subscription_id_type = END_USER_E164; ccr_request.data.ccr.subscription_id.list[idx]. subscription_id_data.len = pdn->context->msisdn_len; memcpy(ccr_request.data.ccr.subscription_id.list[idx]. subscription_id_data.val, &context->msisdn, context->msisdn_len); } } ccr_request.data.ccr.presence.network_request_support = PRESENT; ccr_request.data.ccr.network_request_support = NETWORK_REQUEST_SUPPORTED; int index = 0; int len = 0; uint8_t evnt_tigger_list[EVENT_TRIGGER_LIST] = {0}; ccr_request.data.ccr.presence.event_trigger = PRESENT ; ccr_request.data.ccr.event_trigger.count = 0 ; if(bearer_resource_mod_flow_flag == 1 || mod_bearer_cmd != NULL ) { evnt_tigger_list[ccr_request.data.ccr.event_trigger.count++] = RESOURCE_MODIFICATION_REQUEST; } if(context->rat_type_flag != FALSE) { evnt_tigger_list[ccr_request.data.ccr.event_trigger.count++] = RAT_EVENT_TRIGGER; } if(context->uli_flag != FALSE) { if((context->event_trigger & (1 << ULI_EVENT_TRIGGER)) != 0) { evnt_tigger_list[ccr_request.data.ccr.event_trigger.count++] = ULI_EVENT_TRIGGER; } if(context->uli_flag == ECGI_AND_TAI_PRESENT) { if(((context->event_trigger & (1 << TAI_EVENT_TRIGGER)) != 0) && ((context->event_trigger & (1 << ECGI_EVENT_TRIGGER)) != 0)) { evnt_tigger_list[ccr_request.data.ccr.event_trigger.count++] = ECGI_EVENT_TRIGGER; evnt_tigger_list[ccr_request.data.ccr.event_trigger.count++] = TAI_EVENT_TRIGGER; } ccr_request.data.ccr.presence.tgpp_user_location_info = PRESENT; ccr_request.data.ccr.tgpp_user_location_info.val[index++] = GX_ECGI_AND_TAI_TYPE; ccr_request.data.ccr.tgpp_user_location_info.len =index ; len = fill_tai(&(ccr_request.data.ccr.tgpp_user_location_info.val[index]), &(context->uli.tai2)); ccr_request.data.ccr.tgpp_user_location_info.len += len; len = fill_ecgi(&(ccr_request.data.ccr.tgpp_user_location_info.val[len + 1]), &(context->uli.ecgi2)); ccr_request.data.ccr.tgpp_user_location_info.len += len; } else if (((context->uli_flag & (1<< 0)) == TAI_PRESENT) ) { if(((context->event_trigger & (1 << TAI_EVENT_TRIGGER)) != 0)) { evnt_tigger_list[ccr_request.data.ccr.event_trigger.count++] = TAI_EVENT_TRIGGER; } ccr_request.data.ccr.presence.tgpp_user_location_info = PRESENT; ccr_request.data.ccr.tgpp_user_location_info.val[index++] = GX_TAI_TYPE; ccr_request.data.ccr.tgpp_user_location_info.len = index ; len = fill_tai(&(ccr_request.data.ccr.tgpp_user_location_info.val[index]), &(context->uli.tai2)); ccr_request.data.ccr.tgpp_user_location_info.len += len; } else if (((context->uli_flag & (1 << 4)) == ECGI_PRESENT)) { if(((context->event_trigger & (1 << ECGI_EVENT_TRIGGER)) != 0)) { evnt_tigger_list[ccr_request.data.ccr.event_trigger.count++] = ECGI_EVENT_TRIGGER; } ccr_request.data.ccr.presence.tgpp_user_location_info = PRESENT; ccr_request.data.ccr.tgpp_user_location_info.val[index++] = GX_ECGI_TYPE; ccr_request.data.ccr.tgpp_user_location_info.len = index ; len = fill_ecgi(&(ccr_request.data.ccr.tgpp_user_location_info.val[index]), &(context->uli.ecgi2)); ccr_request.data.ccr.tgpp_user_location_info.len += len; } else if (((context->uli_flag & (1 << 2)) == SAI_PRESENT)) { ccr_request.data.ccr.presence.tgpp_user_location_info = PRESENT; ccr_request.data.ccr.tgpp_user_location_info.val[index++] = GX_SAI_TYPE; ccr_request.data.ccr.tgpp_user_location_info.len = index ; len = fill_sai(&(ccr_request.data.ccr.tgpp_user_location_info.val[index]), &(context->uli.sai2)); ccr_request.data.ccr.tgpp_user_location_info.len += len; } else if (((context->uli_flag & (1 << 3)) == RAI_PRESENT)) { if(((pdn->context->event_trigger & (1 << RAI_EVENT_TRIGGER)) != 0)) { evnt_tigger_list[ccr_request.data.ccr.event_trigger.count++] = RAI_EVENT_TRIGGER; } ccr_request.data.ccr.presence.tgpp_user_location_info = PRESENT; ccr_request.data.ccr.tgpp_user_location_info.val[index++] = GX_RAI_TYPE; ccr_request.data.ccr.tgpp_user_location_info.len = index ; len = fill_rai(&(ccr_request.data.ccr.tgpp_user_location_info.val[index]), &(context->uli.rai2)); ccr_request.data.ccr.tgpp_user_location_info.len += len; } else if (((context->uli_flag & (1 << 1)) == CGI_PRESENT)) { ccr_request.data.ccr.presence.tgpp_user_location_info = PRESENT; ccr_request.data.ccr.tgpp_user_location_info.val[index++] = GX_CGI_TYPE; ccr_request.data.ccr.tgpp_user_location_info.len = index ; len = fill_cgi(&(ccr_request.data.ccr.tgpp_user_location_info.val[index]), &(context->uli.cgi2)); ccr_request.data.ccr.tgpp_user_location_info.len += len; } else if (((context->uli_flag & (1 << 6)) == 1)) { len = fill_lai(&(ccr_request.data.ccr.tgpp_user_location_info.val[index]), &(context->old_uli.lai2)); } context->uli_flag = FALSE; } if( context->ue_time_zone_flag != FALSE ) { evnt_tigger_list[ccr_request.data.ccr.event_trigger.count++] = UE_TIMEZONE_EVT_TRIGGER; index = 0; ccr_request.data.ccr.presence.tgpp_ms_timezone = PRESENT; ccr_request.data.ccr.tgpp_ms_timezone.val[index++] = ((context->tz.tz) & 0xff); ccr_request.data.ccr.tgpp_ms_timezone.val[index++] = ((context->tz.dst) & 0xff); ccr_request.data.ccr.tgpp_ms_timezone.len = index; } context->ue_time_zone_flag = FALSE; ccr_request.data.ccr.event_trigger.list = (int32_t *) rte_malloc_socket(NULL, (ccr_request.data.ccr.event_trigger.count * sizeof(int32_t)), RTE_CACHE_LINE_SIZE, rte_socket_id()); for(uint8_t count = 0; count < ccr_request.data.ccr.event_trigger.count; count++ ) { *(ccr_request.data.ccr.event_trigger.list + count) = evnt_tigger_list[count]; } int ebi_index = GET_EBI_INDEX(bearer->eps_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } /* Fill the Credit Crontrol Request to send PCRF */ if(fill_ccr_request(&ccr_request.data.ccr, context, ebi_index, pdn->gx_sess_id, bearer_resource_mod_flow_flag) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed CCR request filling process\n", LOG_VALUE); return -1; } update_cli_stats((peer_address_t *) &config.gx_ip, OSS_CCR_UPDATE, SENT, GX); /* Update UE State */ pdn->state = CCRU_SNT_STATE; /* Set the Gx State for events */ gx_context->state = CCRU_SNT_STATE; gx_context->proc = pdn->proc; /* Calculate the max size of CCR msg to allocate the buffer */ msg_len = gx_ccr_calc_length(&ccr_request.data.ccr); ccr_request.msg_len = msg_len + GX_HEADER_LEN; buffer = rte_zmalloc_socket(NULL, msg_len + GX_HEADER_LEN, RTE_CACHE_LINE_SIZE, rte_socket_id()); if (buffer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to allocate CCR Buffer memory" "structure: %s \n",LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* Fill the CCR header values */ memcpy(buffer, &ccr_request.msg_type, sizeof(ccr_request.msg_type)); memcpy(buffer + sizeof(ccr_request.msg_type), &ccr_request.msg_len, sizeof(ccr_request.msg_len)); if (gx_ccr_pack(&(ccr_request.data.ccr), (unsigned char *)(buffer + GX_HEADER_LEN), msg_len) == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR in Packing CCR " "Buffer\n", LOG_VALUE); rte_free(buffer); return GTPV2C_CAUSE_SYSTEM_FAILURE; } send_to_ipc_channel(gx_app_sock, buffer, msg_len + GX_HEADER_LEN); rte_free(buffer); free_dynamically_alloc_memory(&ccr_request); return 0; } /** * @brief : Generate CCR request * @param : context , pointer to ue context structure * @param : ebi_index, index in array where eps bearer is stored * @return : Returns 0 in case of success , -1 otherwise */ static int ccru_req_for_bear_termination(pdn_connection *pdn, eps_bearer *bearer) { /* * TODO: * Passing bearer as parameter is a BAD IDEA * because what if multiple bearer changes? * code SHOULD anchor only on pdn. */ /* Initialize the Gx Parameters */ int ret = 0; uint16_t msg_len = 0; uint8_t *buffer = NULL; gx_msg ccr_request = {0}; gx_context_t *gx_context = NULL; ret = rte_hash_lookup_data(gx_context_by_sess_id_hash, (const void*)(pdn->gx_sess_id), (void **)&gx_context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO ENTRY FOUND IN Gx " "HASH [%s]\n", LOG_VALUE, pdn->gx_sess_id); return -1; } /* Set the Msg header type for CCR */ ccr_request.msg_type = GX_CCR_MSG ; /* Set Credit Control Request type */ ccr_request.data.ccr.presence.cc_request_type = PRESENT; ccr_request.data.ccr.cc_request_type = UPDATE_REQUEST ; /* Set Credit Control Bearer opertaion type */ ccr_request.data.ccr.presence.bearer_operation = PRESENT; ccr_request.data.ccr.bearer_operation = TERMINATION; uint8_t indx_bearer = bearer->eps_bearer_id; /* Set bearer identifier value */ ccr_request.data.ccr.presence.bearer_identifier = PRESENT; ccr_request.data.ccr.bearer_identifier.len = (1 + (uint32_t)log10(indx_bearer)); if (ccr_request.data.ccr.bearer_identifier.len >= GX_BEARER_IDENTIFIER_LEN) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Insufficient memory to copy bearer identifier\n", LOG_VALUE); return -1; } else { strncpy((char *)ccr_request.data.ccr.bearer_identifier.val, (char *)&indx_bearer, ccr_request.data.ccr.bearer_identifier.len); } ccr_request.data.ccr.presence.network_request_support = PRESENT; ccr_request.data.ccr.network_request_support = NETWORK_REQUEST_SUPPORTED; int idx = 0; ccr_request.data.ccr.presence.charging_rule_report = PRESENT; ccr_request.data.ccr.charging_rule_report.count = 1; ccr_request.data.ccr.charging_rule_report.list = rte_malloc_socket(NULL, ((sizeof(GxChargingRuleReport))*1), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (ccr_request.data.ccr.charging_rule_report.list == NULL) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Failure to allocate charging rule report list memory\n", LOG_VALUE); return GTPV2C_CAUSE_NO_MEMORY_AVAILABLE; } ccr_request.data.ccr.charging_rule_report.list[idx].presence.charging_rule_name = PRESENT; ccr_request.data.ccr.charging_rule_report.list[idx].charging_rule_name.list = rte_malloc_socket(NULL, ((sizeof(GxChargingRuleNameOctetString))*1), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (ccr_request.data.ccr.charging_rule_report.list[idx] .charging_rule_name.list == NULL) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Failure to allocate charging rule report" " list memory\n", LOG_VALUE); return GTPV2C_CAUSE_NO_MEMORY_AVAILABLE; } ccr_request.data.ccr.charging_rule_report.list[idx].charging_rule_name.count = 1; int8_t itr1 = 0; int8_t itr2 = 0; int8_t num_filters = bearer->num_dynamic_filters + bearer->num_prdef_filters; for(uint8_t cnt = 0; cnt < num_filters; cnt++){ if(itr1 < bearer->num_dynamic_filters){ ccr_request.data.ccr.charging_rule_report.list[idx].charging_rule_name.list[cnt].len = strnlen(bearer->dynamic_rules[itr1]->rule_name, RULE_NAME_LEN); for(uint16_t i = 0 ; i<strnlen(bearer->dynamic_rules[itr1]->rule_name, RULE_NAME_LEN); i++){ ccr_request.data.ccr.charging_rule_report.list[idx].charging_rule_name.list[cnt].val[i] = bearer->dynamic_rules[itr1]->rule_name[i]; } itr1++; } else { if(itr2 < bearer->num_prdef_filters){ ccr_request.data.ccr.charging_rule_report.list[idx].charging_rule_name.list[cnt].len = strnlen(bearer->prdef_rules[itr2]->rule_name, RULE_NAME_LEN); for(uint16_t i = 0 ; i<strnlen(bearer->prdef_rules[itr2]->rule_name, RULE_NAME_LEN); i++){ ccr_request.data.ccr.charging_rule_report.list[idx].charging_rule_name.list[cnt].val[i] = bearer->prdef_rules[itr2]->rule_name[i]; } itr2++; } } } ccr_request.data.ccr.charging_rule_report.list[idx].presence.pcc_rule_status = PRESENT; ccr_request.data.ccr.charging_rule_report.list[idx].pcc_rule_status = INACTIVE; ccr_request.data.ccr.charging_rule_report.list[idx].presence.rule_failure_code = PRESENT; ccr_request.data.ccr.charging_rule_report.list[idx].rule_failure_code = NO_BEARER_BOUND; int ebi_index = GET_EBI_INDEX(bearer->eps_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } /* Fill the Credit Crontrol Request to send PCRF */ if(fill_ccr_request(&ccr_request.data.ccr, pdn->context, ebi_index,pdn->gx_sess_id, 0) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure in CCR request " "filling process\n", LOG_VALUE); return -1; } update_cli_stats((peer_address_t *) &config.gx_ip, OSS_CCR_UPDATE, SENT, GX); /* Update UE State */ pdn->state = CCRU_SNT_STATE; /* Set the Gx State for events */ gx_context->state = CCRU_SNT_STATE; gx_context->proc = pdn->proc; /* Calculate the max size of CCR msg to allocate the buffer */ msg_len = gx_ccr_calc_length(&ccr_request.data.ccr); ccr_request.msg_len = msg_len + GX_HEADER_LEN; buffer = rte_zmalloc_socket(NULL, msg_len + GX_HEADER_LEN, RTE_CACHE_LINE_SIZE, rte_socket_id()); if (buffer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure to allocate " "CCR-TERMINATION Buffer memory structure: %s\n", LOG_VALUE, rte_strerror(rte_errno)); return -1; } /* Fill the CCR header values */ memcpy(buffer, &ccr_request.msg_type, sizeof(ccr_request.msg_type)); memcpy(buffer + sizeof(ccr_request.msg_type), &ccr_request.msg_len, sizeof(ccr_request.msg_len)); if (gx_ccr_pack(&(ccr_request.data.ccr), (unsigned char *)(buffer + GX_HEADER_LEN), msg_len) == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in Packing " "CCR-TERMINATION Buffer\n", LOG_VALUE); rte_free(buffer); return -1; } send_to_ipc_channel(gx_app_sock, buffer, msg_len + GX_HEADER_LEN); rte_free(buffer); free_dynamically_alloc_memory(&ccr_request); store_rule_status_for_del_bearer_cmd(&pdn->pro_ack_rule_array, bearer); return 0; } int store_rule_status_for_del_bearer_cmd(pro_ack_rule_array_t *pro_ack_rule_array, eps_bearer *bearer) { if(bearer == NULL) { return -1; } uint8_t num_filters = bearer->num_prdef_filters + bearer->num_dynamic_filters; uint8_t itr1 = 0; uint8_t itr2 = 0; for(int cnt = 0; cnt < num_filters; cnt++) { if(itr1 < bearer->num_dynamic_filters) { if( bearer->dynamic_rules[cnt] != NULL) { strncpy(pro_ack_rule_array->rule[cnt].rule_name, bearer->dynamic_rules[itr1]->rule_name, strnlen(bearer->dynamic_rules[itr1]->rule_name, RULE_NAME_LEN)); itr1++; } } else { if(itr2 < bearer->num_prdef_filters) { if( bearer->prdef_rules[cnt] != NULL) { strncpy(pro_ack_rule_array->rule[cnt].rule_name, bearer->prdef_rules[itr2]->rule_name, strnlen(bearer->prdef_rules[itr2]->rule_name, RULE_NAME_LEN)); itr2++; } } } pro_ack_rule_array->rule[cnt].rule_status = INACTIVE; pro_ack_rule_array->rule_cnt++; } return 0; } void fill_rule_and_qos_inform_in_pdn(pdn_connection *pdn) { uint8_t idx = 0; pcc_rule_t *prule = rte_zmalloc_socket(NULL, sizeof(pcc_rule_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(prule == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate" "memory to pcc rule structure\n", LOG_VALUE); return; } pdn->policy.pcc_rule[0] = prule; dynamic_rule_t *dynamic_rule = dynamic_rule = &pdn->policy.pcc_rule[0]->urule.dyn_rule; const char *local_ipv6_addr = "fc00:db20:35b:7399::5"; const char *remote_ipv6_addr = "fc00:db20:35b:7399::5"; int ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return; } eps_bearer *bearer = pdn->eps_bearers[ebi_index]; pdn->policy.default_bearer_qos_valid = TRUE; bearer_qos_ie *def_qos = &pdn->policy.default_bearer_qos; pdn->policy.num_charg_rule_install = DEFAULT_RULE_COUNT; def_qos->qci = QCI_VALUE; def_qos->arp.priority_level = GX_PRIORITY_LEVEL; def_qos->arp.preemption_capability = PREEMPTION_CAPABILITY_DISABLED; def_qos->arp.preemption_vulnerability = PREEMPTION_VALNERABILITY_ENABLED; bearer->qos.qci = QCI_VALUE; bearer->qos.arp.priority_level = GX_PRIORITY_LEVEL; bearer->qos.arp.preemption_capability = PREEMPTION_CAPABILITY_DISABLED; bearer->qos.arp.preemption_vulnerability = PREEMPTION_VALNERABILITY_ENABLED; memset(dynamic_rule->rule_name, '\0', sizeof(dynamic_rule->rule_name)); strncpy(dynamic_rule->rule_name, RULE_NAME, RULE_LENGTH ); dynamic_rule->online = ENABLE_ONLINE; dynamic_rule->offline = DISABLE_OFFLINE; dynamic_rule->flow_status = GX_ENABLE; dynamic_rule->precedence = PRECEDENCE; dynamic_rule->service_id = SERVICE_INDENTIFIRE; dynamic_rule->rating_group = RATING_GROUP; dynamic_rule->num_flw_desc = GX_FLOW_COUNT; for(idx = 0; idx < GX_FLOW_COUNT; idx++) { dynamic_rule->flow_desc[idx].flow_direction = BIDIRECTIONAL; dynamic_rule->flow_desc[idx].sdf_flw_desc.proto_id = PROTO_ID; dynamic_rule->flow_desc[idx].sdf_flw_desc.local_port_low = PORT_LOW; dynamic_rule->flow_desc[idx].sdf_flw_desc.local_port_high = PORT_HIGH; dynamic_rule->flow_desc[idx].sdf_flw_desc.remote_port_low = PORT_LOW; dynamic_rule->flow_desc[idx].sdf_flw_desc.remote_port_high = PORT_HIGH; dynamic_rule->flow_desc[idx].sdf_flw_desc.direction = TFT_DIRECTION_BIDIRECTIONAL; if(pdn->pdn_type.ipv4 == 1){ dynamic_rule->flow_desc[idx].sdf_flw_desc.v4 = PRESENT; dynamic_rule->flow_desc[idx].sdf_flw_desc.local_ip_mask = LOCAL_IP_MASK; dynamic_rule->flow_desc[idx].sdf_flw_desc.ulocalip.local_ip_addr.s_addr = LOCAL_IP_ADDR; dynamic_rule->flow_desc[idx].sdf_flw_desc.remote_ip_mask = REMOTE_IP_MASK; dynamic_rule->flow_desc[idx].sdf_flw_desc.uremoteip.remote_ip_addr.s_addr = REMOTE_IP_ADDR; } else{ dynamic_rule->flow_desc[idx].sdf_flw_desc.v6 = PRESENT; inet_pton(AF_INET6, local_ipv6_addr, &dynamic_rule->flow_desc[idx].sdf_flw_desc.ulocalip.local_ip6_addr); dynamic_rule->flow_desc[idx].sdf_flw_desc.local_ip_mask = LOCAL_IPV6_MASK; inet_pton(AF_INET6, remote_ipv6_addr, &dynamic_rule->flow_desc[idx].sdf_flw_desc.uremoteip.remote_ip6_addr); dynamic_rule->flow_desc[idx].sdf_flw_desc.remote_ip_mask = REMOTE_IPV6_MASK; } } /* For dual connectivity as v4 infomation * is already filled so just fill flow information of v6 * */ if(pdn->pdn_type.ipv4 == 1 && pdn->pdn_type.ipv6 == 1){ dynamic_rule->flow_desc[idx].flow_direction = BIDIRECTIONAL; dynamic_rule->flow_desc[idx].sdf_flw_desc.proto_id = PROTO_ID; dynamic_rule->flow_desc[idx].sdf_flw_desc.direction = TFT_DIRECTION_BIDIRECTIONAL; dynamic_rule->flow_desc[idx].sdf_flw_desc.v6 = PRESENT; inet_pton(AF_INET6, local_ipv6_addr, &dynamic_rule->flow_desc[idx].sdf_flw_desc.ulocalip.local_ip6_addr); dynamic_rule->flow_desc[idx].sdf_flw_desc.local_ip_mask = LOCAL_IPV6_MASK; inet_pton(AF_INET6, remote_ipv6_addr, &dynamic_rule->flow_desc[idx].sdf_flw_desc.uremoteip.remote_ip6_addr); dynamic_rule->flow_desc[idx].sdf_flw_desc.remote_ip_mask = REMOTE_IPV6_MASK; /*increment as new flow added*/ dynamic_rule->num_flw_desc ++; } dynamic_rule->qos.qci = QCI_VALUE; dynamic_rule->qos.arp.priority_level = GX_PRIORITY_LEVEL; dynamic_rule->qos.arp.preemption_capability = PREEMPTION_CAPABILITY_DISABLED; dynamic_rule->qos.arp.preemption_vulnerability = PREEMPTION_VALNERABILITY_ENABLED; dynamic_rule->qos.ul_mbr = REQUESTED_BANDWIDTH_UL; dynamic_rule->qos.dl_mbr = REQUESTED_BANDWIDTH_DL; dynamic_rule->qos.ul_gbr = GURATEED_BITRATE_UL; dynamic_rule->qos.dl_gbr = GURATEED_BITRATE_DL; } int process_create_sess_req(create_sess_req_t *csr, ue_context **_context, node_address_t upf_ip, uint8_t cp_type) { int ret = 0; struct in_addr ue_ip = {0}; struct in6_addr ue_ipv6 = {0}; ue_context *context = NULL; eps_bearer *bearer = NULL; pdn_connection *pdn = NULL; int ebi_index = 0; uint8_t check_if_ue_hash_exist = 0; uint64_t imsi = UINT64_MAX; imsi_id_hash_t *imsi_id_config = NULL; apn *apn_requested = get_apn((char *)csr->apn.apn, csr->apn.header.len); if (!apn_requested) return GTPV2C_CAUSE_MISSING_UNKNOWN_APN; /* Checking Received CSR is for context replcement or not */ ret = gtpc_context_replace_check(csr, cp_type, apn_requested); if (ret != 0) { if (ret == GTPC_CONTEXT_REPLACEMENT) { return GTPC_CONTEXT_REPLACEMENT; } if (ret != -1){ memcpy(&imsi, &csr->imsi.imsi_number_digits, csr->imsi.header.len); rte_hash_lookup_data(ue_context_by_imsi_hash, &imsi, (void **) &context); if(context != NULL ) { *_context = context; } return ret; } return ret; } if(csr->mapped_ue_usage_type.header.len > 0) { apn_requested->apn_usage_type = csr->mapped_ue_usage_type.mapped_ue_usage_type; } /* In the case of Promotion get the exsiting session info */ if ((cp_type == SAEGWC) && (csr->pgw_s5s8_addr_ctl_plane_or_pmip.teid_gre_key != 0)) { if (csr->indctn_flgs.indication_oi) { rte_hash_lookup_data(ue_context_by_fteid_hash, &csr->pgw_s5s8_addr_ctl_plane_or_pmip.teid_gre_key, (void **)&context); if (context != NULL) { /* Parse handover CSR and Fill the PFCP Session Modification Request */ if (promotion_parse_cs_req(csr, context, cp_type) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to parse CSR in promotion case\n", LOG_VALUE); return -1; } context->promotion_flag = TRUE; *_context = context; return 0; } } } for(uint8_t i = 0; i< csr->bearer_count ; i++) { if (!csr->bearer_contexts_to_be_created[i].header.len) { return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } ebi_index = GET_EBI_INDEX(csr->bearer_contexts_to_be_created[i].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* set s11_sgw_gtpc_teid= key->ue_context_by_fteid_hash */ ret = create_ue_context(&csr->imsi.imsi_number_digits, csr->imsi.header.len, csr->bearer_contexts_to_be_created[i].eps_bearer_id.ebi_ebi, &context, apn_requested, CSR_SEQUENCE(csr), &check_if_ue_hash_exist, cp_type); if (ret) return ret; *_context = context; context->indirect_tunnel_flag = 0; if(csr->pres_rptng_area_info.header.len){ store_presc_reporting_area_info_to_ue_context(&csr->pres_rptng_area_info, context); } if (cp_type != 0) { context->cp_mode = cp_type; }else { return -1; } /* Retrive procedure of CSR */ pdn = GET_PDN(context, ebi_index); if (pdn == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "get pdn for ebi_index %d \n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } ret = fill_pdn_type(pdn, csr, cp_type); if(ret){ return ret; } /* IP allocation to UE */ if (cp_type != SGWC) { if(pdn->pdn_type.ipv4 == 1){ if (!config.ip_allocation_mode) { ret = acquire_ip(apn_requested->ip_pool_ip, apn_requested->ip_pool_mask, &ue_ip); if (ret) return ret; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Dymanic IP " "allocation mode is not supported for now\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } if(pdn->pdn_type.ipv6 == 1){ if (!config.ip_allocation_mode) { ret = acquire_ipv6(apn_requested->ipv6_network_id, (apn_requested->ipv6_prefix_len/sizeof(uint64_t)), &ue_ipv6); pdn->prefix_len = apn_requested->ipv6_prefix_len; if (ret) return ret; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Dymanic IP " "allocation mode is not supported for now\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } } bearer = context->eps_bearers[ebi_index]; if (csr->linked_eps_bearer_id.ebi_ebi) { pdn->default_bearer_id = csr->linked_eps_bearer_id.ebi_ebi; } if (pdn->default_bearer_id == csr->bearer_contexts_to_be_created[i].eps_bearer_id.ebi_ebi) { if(fill_context_info(csr, context, pdn) != 0) return -1; pdn->proc = get_csr_proc(csr); context->procedure = pdn->proc; if (context->cp_mode != SGWC) { if (pdn->pdn_type.ipv4) pdn->uipaddr.ipv4.s_addr = ue_ip.s_addr; if (pdn->pdn_type.ipv6) memcpy(pdn->uipaddr.ipv6.s6_addr, ue_ipv6.s6_addr, IPV6_ADDRESS_LEN); } if (fill_pdn_info(csr, pdn, context, bearer) != 0) return -1; } /*Check UE Exist*/ /* To minimize lookup of hash for LI */ if ((NULL == imsi_id_config) && (NULL != context)) { if (NULL == imsi_id_config) { /* Get User Level Packet Copying Token or Id Using Imsi */ ret = get_id_using_imsi(context->imsi, &imsi_id_config); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, "[%s]:[%s]:[%d] Not applicable for li\n", __file__, __func__, __LINE__); } } if (NULL != imsi_id_config) { /* Fillup context from li hash */ fill_li_config_in_context(context, imsi_id_config); } } if (fill_bearer_info(csr, bearer, context, pdn, i) != 0) return -1; pdn->context = context; } /*for loop*/ /*Handling in case context is not created*/ if(context == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Context not found " "while processing Create Session Request \n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if ((context->cp_mode == PGWC) || (context->cp_mode == SAEGWC)) { if (config.use_gx) { ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if ((ret = gen_ccr_request(context, ebi_index, csr)) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "generate CCR-INITIAL requset : %s\n", LOG_VALUE, strerror(errno)); return ret; } } else { fill_rule_and_qos_inform_in_pdn(pdn); } } #ifdef USE_CSID /* Parse and stored MME and SGW FQ-CSID in the context */ fqcsid_t *tmp = NULL; /* Allocate the memory for each session */ if (context != NULL) { if (context->mme_fqcsid == NULL) context->mme_fqcsid = rte_zmalloc_socket(NULL, sizeof(sess_fqcsid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (context->sgw_fqcsid == NULL) context->sgw_fqcsid = rte_zmalloc_socket(NULL, sizeof(sess_fqcsid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (context->pgw_fqcsid == NULL) context->pgw_fqcsid = rte_zmalloc_socket(NULL, sizeof(sess_fqcsid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if ((context->mme_fqcsid == NULL) || (context->sgw_fqcsid == NULL) || (context->pgw_fqcsid == NULL)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the " "memory for fqcsids entry\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Context not found " "while processing Create Session Request \n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* MME FQ-CSID */ if (csr->mme_fqcsid.header.len) { if (context->cp_mode != PGWC) { /* need to revisite here for s11 mme addr and log */ ret = add_peer_addr_entry_for_fqcsid_ie_node_addr( &context->s11_mme_gtpc_ip, &csr->mme_fqcsid, S11_SGW_PORT_ID); if (ret) return ret; } /* Adding MME csid for the existing session */ ret = add_fqcsid_entry(&csr->mme_fqcsid, context->mme_fqcsid); if(ret) return ret; fill_pdn_fqcsid_info(&pdn->mme_csid, context->mme_fqcsid); } else { /* Stored the MME CSID by MME Node address */ tmp = get_peer_addr_csids_entry(&context->s11_mme_gtpc_ip, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "Add the MME CSID by MME Node address, Error : %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } memcpy(&(tmp->node_addr), &(context->s11_mme_gtpc_ip), sizeof(node_address_t)); memcpy(&((context->mme_fqcsid)->node_addr[(context->mme_fqcsid)->num_csid]), &(context->s11_mme_gtpc_ip), sizeof(node_address_t)); } /* SGW FQ-CSID -- PGWC */ if (csr->sgw_fqcsid.header.len) { ret = add_peer_addr_entry_for_fqcsid_ie_node_addr( &pdn->s5s8_sgw_gtpc_ip, &csr->sgw_fqcsid, S5S8_PGWC_PORT_ID); if (ret) return ret; /* Stored the SGW CSID by SGW Node address */ ret = add_fqcsid_entry(&csr->sgw_fqcsid, context->sgw_fqcsid); if(ret) return ret; fill_pdn_fqcsid_info(&pdn->sgw_csid, context->sgw_fqcsid); } else { if ((context->cp_mode == SGWC) || (context->cp_mode == SAEGWC)) { tmp = get_peer_addr_csids_entry(&context->s11_sgw_gtpc_ip, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed " "to Add the SGW CSID by SGW Node address, Error : %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } memcpy(&(tmp->node_addr), &(context->s11_sgw_gtpc_ip), sizeof(node_address_t)); memcpy(&((context->sgw_fqcsid)->node_addr[(context->sgw_fqcsid)->num_csid]), &(context->s11_sgw_gtpc_ip), sizeof(node_address_t)); } } /* PGW FQ-CSID */ if (context->cp_mode == PGWC) { tmp = get_peer_addr_csids_entry(&pdn->s5s8_pgw_gtpc_ip, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "Add the PGW CSID by PGW Node address, Error : %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } memcpy(&(tmp->node_addr), &(pdn->s5s8_pgw_gtpc_ip), sizeof(node_address_t)); memcpy(&((context->pgw_fqcsid)->node_addr[(context->pgw_fqcsid)->num_csid]), &(pdn->s5s8_pgw_gtpc_ip), sizeof(node_address_t)); } #endif /* USE_CSID */ /* Store the context of ue in pdn */ context->bearer_count = csr->bearer_count; pdn->context = context; RTE_SET_USED(upf_ip); return 0; } int process_pfcp_sess_est_request(uint32_t teid, pdn_connection *pdn, upf_context_t *upf_ctx) { uint32_t sequence = 0; eps_bearer *bearer = NULL; struct resp_info *resp = NULL; ue_context *context = pdn->context; pfcp_sess_estab_req_t pfcp_sess_est_req = {0}; int ebi_index = GET_EBI_INDEX(pdn->default_bearer_id), ret = 0; if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if(context == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Context not found " "while processing PFCP Session Establishment Request \n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } sequence = get_pfcp_sequence_number(PFCP_SESSION_ESTABLISHMENT_REQUEST, sequence); if(context->indirect_tunnel_flag != 0) { pdn = pdn->context->indirect_tunnel->pdn; pdn->proc = CREATE_INDIRECT_TUNNEL_PROC; } for(uint8_t i= 0; i< MAX_BEARERS; i++) { bearer = pdn->eps_bearers[i]; if(bearer == NULL) continue; /* Validate Bearer is linked with PDN or not */ if (bearer->pdn == NULL) bearer->pdn = pdn; /* Update upf ip if not updated in bearer */ if ((bearer->pdn)->upf_ip.ip_type == NOT_PRESENT) (bearer->pdn)->upf_ip = pdn->upf_ip; if (context->cp_mode == SGWC) { /* Generating TEID for S1U interface */ if(context->indirect_tunnel_flag != 0){ //context->indirect_tunnel->pdn->eps_bearers[i]->pdr_count = 0; for(uint8_t itr = context->indirect_tunnel->pdn->eps_bearers[i]->pdr_count; itr < (context->indirect_tunnel->pdn->eps_bearers[i]->pdr_count + NUMBER_OF_PDR_PER_RULE); itr++){ if(itr%2 == 0) { fill_pdr_entry(context, context->indirect_tunnel->pdn, context->indirect_tunnel->pdn->eps_bearers[i], SOURCE_INTERFACE_VALUE_ACCESS, itr); } else if ((itr%2 != 0) && ((upf_ctx->s5s8_li_sgwu_ip.ipv4_addr != 0) || *(upf_ctx->s5s8_li_sgwu_ip.ipv6_addr))){ fill_pdr_entry(context, context->indirect_tunnel->pdn, context->indirect_tunnel->pdn->eps_bearers[i], SOURCE_INTERFACE_VALUE_CORE, itr); } } context->indirect_tunnel->pdn->eps_bearers[i]->pdr_count += NUMBER_OF_PDR_PER_RULE; } bearer->s1u_sgw_gtpu_teid = get_s1u_sgw_gtpu_teid(bearer->pdn->upf_ip, context->cp_mode, &upf_teid_info_head); update_pdr_teid(bearer, bearer->s1u_sgw_gtpu_teid, upf_ctx->s1u_ip, SOURCE_INTERFACE_VALUE_ACCESS); /* Generating TEID for SGW S5S8 interface */ bearer->s5s8_sgw_gtpu_teid = get_s5s8_sgw_gtpu_teid(bearer->pdn->upf_ip, context->cp_mode, &upf_teid_info_head); if(context->indirect_tunnel_flag == 0){ update_pdr_teid(bearer, bearer->s5s8_sgw_gtpu_teid, upf_ctx->s5s8_sgwu_ip, SOURCE_INTERFACE_VALUE_CORE); } else { update_pdr_teid(bearer, bearer->s5s8_sgw_gtpu_teid, upf_ctx->s5s8_li_sgwu_ip, SOURCE_INTERFACE_VALUE_CORE); } ret = set_address(&bearer->s1u_sgw_gtpu_ip, &upf_ctx->s1u_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } if(context->indirect_tunnel_flag == 0){ ret = set_address(&bearer->s5s8_sgw_gtpu_ip, &upf_ctx->s5s8_sgwu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else { if((upf_ctx->s5s8_li_sgwu_ip.ipv4_addr != 0) || *(upf_ctx->s5s8_li_sgwu_ip.ipv6_addr)){ ret = set_address(&bearer->s5s8_sgw_gtpu_ip, &upf_ctx->s5s8_li_sgwu_ip); }else{ ret = set_address(&bearer->s5s8_sgw_gtpu_ip, &upf_ctx->s5s8_sgwu_ip); } if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } } else if (context->cp_mode == SAEGWC) { /*Generating TEID for S1U interface*/ bearer->s1u_sgw_gtpu_teid = get_s1u_sgw_gtpu_teid(bearer->pdn->upf_ip, context->cp_mode, &upf_teid_info_head); update_pdr_teid(bearer, bearer->s1u_sgw_gtpu_teid, upf_ctx->s1u_ip, SOURCE_INTERFACE_VALUE_ACCESS); ret = set_address(&bearer->s5s8_sgw_gtpu_ip, &upf_ctx->s5s8_sgwu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } ret = set_address(&bearer->s1u_sgw_gtpu_ip, &upf_ctx->s1u_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } ret = set_address(&bearer->s5s8_pgw_gtpu_ip, &upf_ctx->s5s8_pgwu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s5s8_pgw_gtpu_teid = bearer->s1u_sgw_gtpu_teid; if((pdn->pdn_type.ipv4 && upf_ctx->s5s8_sgwu_ip.ip_type == PDN_TYPE_IPV6) || (pdn->pdn_type.ipv6 && upf_ctx->s5s8_sgwu_ip.ip_type == PDN_TYPE_IPV4)){ clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "SGI IP is not compatible" " with UE IP", LOG_VALUE); return GTPV2C_CAUSE_REQUEST_REJECTED; } } else { /* Generating TEID for PGW S5S8 interface */ bearer->s5s8_pgw_gtpu_teid = get_s5s8_pgw_gtpu_teid(bearer->pdn->upf_ip, context->cp_mode, &upf_teid_info_head); update_pdr_teid(bearer, bearer->s5s8_pgw_gtpu_teid, upf_ctx->s5s8_pgwu_ip, SOURCE_INTERFACE_VALUE_ACCESS); /* Update the PGWU IP address */ ret = set_address(&bearer->s5s8_pgw_gtpu_ip, &upf_ctx->s5s8_pgwu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } if((pdn->pdn_type.ipv4 && upf_ctx->s5s8_sgwu_ip.ip_type == PDN_TYPE_IPV6) || (pdn->pdn_type.ipv6 && upf_ctx->s5s8_sgwu_ip.ip_type == PDN_TYPE_IPV4)){ clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "SGI IP is not compatible" " with UE IP", LOG_VALUE); return GTPV2C_CAUSE_REQUEST_REJECTED; } if((bearer->s5s8_sgw_gtpu_ip.ip_type != PDN_TYPE_IPV4_IPV6 && bearer->s5s8_pgw_gtpu_ip.ip_type != PDN_TYPE_IPV4_IPV6) && bearer->s5s8_sgw_gtpu_ip.ip_type != bearer->s5s8_pgw_gtpu_ip.ip_type){ clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "S5S8 IP is not compatible" " on SGW and PGW", LOG_VALUE); return GTPV2C_CAUSE_REQUEST_REJECTED; } /* Filling PDN structure*/ pfcp_sess_est_req.pdn_type.header.type = PFCP_IE_PDN_TYPE; pfcp_sess_est_req.pdn_type.header.len = UINT8_SIZE; pfcp_sess_est_req.pdn_type.pdn_type_spare = 0; pfcp_sess_est_req.pdn_type.pdn_type = 1; } } resp = rte_malloc_socket(NULL, sizeof(struct resp_info), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(resp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error in dynamic mem allocation through rte_malloc", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } fill_pfcp_sess_est_req(&pfcp_sess_est_req, pdn, sequence, context, resp); #ifdef USE_CSID if(context->indirect_tunnel_flag == 0) { /*Pointing bearer t the default bearer*/ bearer = pdn->eps_bearers[ebi_index]; if(bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Bearer not " "found for EBI ID : %d\n",LOG_VALUE, pdn->default_bearer_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Get the copy of existing SGW CSID */ fqcsid_t tmp_csid_t = {0}; if (pdn->sgw_csid.num_csid) { memcpy(&tmp_csid_t, &pdn->sgw_csid, sizeof(fqcsid_t)); } /* Add the entry for peer nodes */ if (fill_peer_node_info(pdn, bearer)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to fill peer node info and assignment of the " "CSID Error: %s\n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if ((context->cp_mode != PGWC) && (pdn->flag_fqcsid_modified == TRUE)) { uint8_t tmp_csid = 0; /* Validate the exsiting CSID or allocated new one */ for (uint8_t inx1 = 0; inx1 < tmp_csid_t.num_csid; inx1++) { if (pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1] == tmp_csid_t.local_csid[inx1]) { tmp_csid = tmp_csid_t.local_csid[inx1]; break; } } if (!tmp_csid) { for (uint8_t inx = 0; inx < tmp_csid_t.num_csid; inx++) { /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; tmp1 = get_sess_csid_entry(tmp_csid_t.local_csid[inx], REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seids_by_csid_hash, &tmp_csid_t.local_csid[inx], tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry for CSID = %u" "\n\tError= %s\n", LOG_VALUE, tmp_csid_t.local_csid[inx], rte_strerror(abs(ret))); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Removing temporary local CSID associated with MME */ remove_peer_temp_csid(&pdn->mme_csid, tmp_csid_t.local_csid[inx], S11_SGW_PORT_ID); /* Removing temporary local CSID assocoated with PGWC */ remove_peer_temp_csid(&pdn->pgw_csid, tmp_csid_t.local_csid[inx], S5S8_SGWC_PORT_ID); del_sess_csid_entry(tmp_csid_t.local_csid[inx]); } /* Delete CSID from the context */ remove_csid_from_cntx(context->sgw_fqcsid, &tmp_csid_t); } else { sess_csid *tmp1 = NULL; tmp1 = get_sess_csid_entry(tmp_csid_t.local_csid[inx], REMOVE_NODE); if(tmp1 == NULL) { /* Removing temporary local CSID associated with MME */ remove_peer_temp_csid(&pdn->mme_csid, tmp_csid_t.local_csid[inx], S11_SGW_PORT_ID); /* Removing temporary local CSID assocoated with PGWC */ remove_peer_temp_csid(&pdn->pgw_csid, tmp_csid_t.local_csid[inx], S5S8_SGWC_PORT_ID); del_sess_csid_entry(tmp_csid_t.local_csid[inx]); } clLog(clSystemLog, eCLSeverityDebug,LOG_FORMAT"Failed to " "get Session ID entry for CSID:%u\n", LOG_VALUE, tmp_csid_t.local_csid[inx]); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Remove session link from Old CSID:%u\n", LOG_VALUE, tmp_csid_t.local_csid[inx]); } } } /* Add entry for cp session id with link local csid */ sess_csid *tmp = NULL; uint16_t local_csid = 0; if ((context->cp_mode == SGWC) || (context->cp_mode == SAEGWC)) { tmp = get_sess_csid_entry( pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1], ADD_NODE); local_csid = pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1]; } else { /* PGWC */ tmp = get_sess_csid_entry( pdn->pgw_csid.local_csid[pdn->pgw_csid.num_csid - 1], ADD_NODE); local_csid = pdn->pgw_csid.local_csid[pdn->pgw_csid.num_csid - 1]; } if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get CSID " "entry, Error: %s \n", LOG_VALUE,strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* Link local csid with session id */ /* Check head node created ot not */ if(tmp->cp_seid != pdn->seid && tmp->cp_seid != 0) { sess_csid *new_node = NULL; /* Add new node into csid linked list */ new_node = add_sess_csid_data_node(tmp, local_csid); if(new_node == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to ADD new " "node into CSID linked list : %s\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } else { new_node->cp_seid = pdn->seid; new_node->up_seid = pdn->dp_seid; } } else { tmp->cp_seid = pdn->seid; tmp->up_seid = pdn->dp_seid; tmp->next = NULL; } if (pdn->flag_fqcsid_modified == TRUE) { /* Fill the fqcsid into the session est request */ if (fill_fqcsid_sess_est_req(&pfcp_sess_est_req, pdn)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to fill FQ-CSID " "in Session Establishment Request, Error: %s\n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } } #endif /* USE_CSID */ /* Update UE State */ bearer = pdn->eps_bearers[ebi_index]; bearer->pdn->state = PFCP_SESS_EST_REQ_SNT_STATE; /* Allocate the memory for response */ resp->linked_eps_bearer_id = pdn->default_bearer_id; if(pdn->context->indirect_tunnel_flag == 0) resp->msg_type = GTP_CREATE_SESSION_REQ; else resp->msg_type = GTP_CREATE_INDIRECT_DATA_FORWARDING_TUNNEL_REQ; resp->state = PFCP_SESS_EST_REQ_SNT_STATE; resp->proc = pdn->proc; resp->cp_mode = context->cp_mode; uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_estab_req_t(&pfcp_sess_est_req, pfcp_msg); if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr,SENT) < 0 ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure in sending " " PFCP Session Establishment Request, Error : %i\n", LOG_VALUE, errno); return -1; } else { #ifdef CP_BUILD add_pfcp_if_timer_entry(teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ } if (add_sess_entry(pdn->seid, resp) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add response " "structure entry in SM_HASH\n", LOG_VALUE); return -1; } if(resp != NULL){ rte_free(resp); resp = NULL; } return 0; } int8_t process_pfcp_sess_est_resp(pfcp_sess_estab_rsp_t *pfcp_sess_est_rsp, gtpv2c_header_t *gtpv2c_tx, uint8_t is_piggybacked) { int ret = 0, msg_len = 0; eps_bearer *bearer = NULL; ue_context *context = NULL; pdn_connection *pdn = NULL; struct resp_info *resp = NULL; uint64_t sess_id = pfcp_sess_est_rsp->header.seid_seqno.has_seid.seid; uint64_t dp_sess_id = pfcp_sess_est_rsp->up_fseid.seid; uint32_t teid = UE_SESS_ID(sess_id); gtpv2c_header_t *gtpv2c_cbr_t = NULL; /* Retrive the session information based on session id. */ if (get_sess_entry(sess_id, &resp) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session Entry Found " "while PFCP Session Establishment Response for " "session ID:%lu\n", LOG_VALUE, sess_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Update the session state */ resp->state = PFCP_SESS_EST_RESP_RCVD_STATE; /* Retrieve the UE context */ ret = get_ue_context(teid, &context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE " "Context for teid: %u\n", LOG_VALUE, teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /*TODO need to think on eps_bearer_id*/ int ebi_index = GET_EBI_INDEX(resp->linked_eps_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (context->indirect_tunnel_flag == 0){ pdn = GET_PDN(context, ebi_index); if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get pdn for " "ebi_index %d \n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[ebi_index]; } else { pdn = context->indirect_tunnel->pdn; bearer = context->indirect_tunnel->pdn->eps_bearers[ebi_index]; } #ifdef USE_CSID node_address_t node_addr = {0}; node_address_t up_node_id = {0}; fqcsid_t *tmp = NULL; sess_fqcsid_t *fqcsid = NULL; if (context->up_fqcsid == NULL ) { fqcsid = rte_zmalloc_socket(NULL, sizeof(sess_fqcsid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (fqcsid == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the " "memory for fqcsids entry\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } else { fqcsid = context->up_fqcsid; } /* Stored the UP Node address */ if (pfcp_sess_est_rsp->up_fseid.v4) { up_node_id.ip_type = PDN_TYPE_IPV4; up_node_id.ipv4_addr = pfcp_sess_est_rsp->up_fseid.ipv4_address; } else { up_node_id.ip_type = PDN_TYPE_IPV6; memcpy(&up_node_id.ipv6_addr, pfcp_sess_est_rsp->up_fseid.ipv6_address, IPV6_ADDRESS_LEN); } /* UP FQ-CSID */ if (pfcp_sess_est_rsp->up_fqcsid.header.len) { if (pfcp_sess_est_rsp->up_fqcsid.number_of_csids) { /* Stored the UP CSID by UP Node address */ if (pfcp_sess_est_rsp->up_fqcsid.fqcsid_node_id_type == IPV4_GLOBAL_UNICAST) { node_addr.ip_type = PDN_TYPE_IPV4; memcpy(&node_addr.ipv4_addr, pfcp_sess_est_rsp->up_fqcsid.node_address, IPV4_SIZE); } else if (pfcp_sess_est_rsp->up_fqcsid.fqcsid_node_id_type == IPV6_GLOBAL_UNICAST) { node_addr.ip_type = PDN_TYPE_IPV6; memcpy(&node_addr.ipv6_addr, pfcp_sess_est_rsp->up_fqcsid.node_address, IPV6_SIZE); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error : Unknown fqcsid node id type %d \n", LOG_VALUE, pfcp_sess_est_rsp->up_fqcsid.fqcsid_node_id_type); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ret = add_peer_addr_entry_for_fqcsid_ie_node_addr( &up_node_id, (gtp_fqcsid_ie_t *)(&pfcp_sess_est_rsp->up_fqcsid), SX_PORT_ID); if (ret) return ret; tmp = get_peer_addr_csids_entry(&node_addr, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Add the " "SGW-U CSID by SGW Node address, Error : %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } memcpy(&(tmp->node_addr), &node_addr, sizeof(node_address_t)); for(uint8_t itr = 0; itr < pfcp_sess_est_rsp->up_fqcsid.number_of_csids; itr++) { uint8_t match = 0; for (uint8_t itr1 = 0; itr1 < tmp->num_csid; itr1++) { if (tmp->local_csid[itr1] == pfcp_sess_est_rsp->up_fqcsid.pdn_conn_set_ident[itr]) { match = 1; break; } } if (!match) { tmp->local_csid[tmp->num_csid++] = pfcp_sess_est_rsp->up_fqcsid.pdn_conn_set_ident[itr]; } } if (fqcsid->num_csid) { match_and_add_pfcp_sess_fqcsid( &(pfcp_sess_est_rsp->up_fqcsid), fqcsid); } else { add_pfcp_sess_fqcsid( &(pfcp_sess_est_rsp->up_fqcsid), fqcsid); } /* Coping UP csid */ fill_pdn_fqcsid_info(&pdn->up_csid, fqcsid); } } else { tmp = get_peer_addr_csids_entry(&up_node_id, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "the SGW-U CSID by SGW Node address, Error : %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } memcpy(&(tmp->node_addr),&(up_node_id), sizeof(node_address_t)); memcpy(&(fqcsid->node_addr[fqcsid->num_csid]), &(up_node_id), sizeof(node_address_t)); } if ((pdn->up_csid.num_csid) && ((pdn->sgw_csid.num_csid) || (pdn->pgw_csid.num_csid))) { /* TODO: Add the handling if SGW or PGW not support Partial failure */ /* Link peer node SGW or PGW csid with local csid */ if ((context->cp_mode == SGWC) || (context->cp_mode == SAEGWC)) { ret = update_peer_csid_link(&pdn->up_csid, &pdn->sgw_csid); } else if (context->cp_mode == PGWC) { ret = update_peer_csid_link(&pdn->up_csid, &pdn->pgw_csid); } if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Update and " "Link Peer node CSID with local CSID, Error : %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* Update entry for up session id with link local csid */ sess_csid *sess_t = NULL; sess_csid *sess_tmp = NULL; if ((context->cp_mode == SGWC) || (context->cp_mode == SAEGWC)) { if (context->sgw_fqcsid) { sess_t = get_sess_csid_entry( pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1], UPDATE_NODE); } } else { /* PGWC */ if (context->pgw_fqcsid) { sess_t = get_sess_csid_entry( pdn->pgw_csid.local_csid[pdn->pgw_csid.num_csid - 1], UPDATE_NODE); } } if (sess_t == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get CSID " "entry, Error: %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* Link local csid with session id */ sess_tmp = get_sess_csid_data_node(sess_t, pdn->seid); if(sess_tmp == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get node " "data for SEID: %x\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Update up SEID in CSID linked list node */ sess_tmp->up_seid = dp_sess_id; pdn->dp_seid = dp_sess_id; /* Add entry for cp session id with link local csid */ if ((context->cp_mode != PGWC)) { if (pdn->mme_csid.num_csid) { /* Link Session with Peer CSID */ link_sess_with_peer_csid(&pdn->mme_csid, pdn, S11_SGW_PORT_ID); } } else { if (pdn->sgw_csid.num_csid) { /* Link Session with Peer CSID */ link_sess_with_peer_csid(&pdn->sgw_csid, pdn, S5S8_PGWC_PORT_ID); } if (pdn->mme_csid.num_csid) { link_sess_with_peer_csid(&pdn->mme_csid, pdn, S5S8_PGWC_PORT_ID); } } /* Link session with Peer CSID */ link_sess_with_peer_csid(&pdn->up_csid, pdn, SX_PORT_ID); } /* Update the UP CSID in the context */ if (context->up_fqcsid == NULL) context->up_fqcsid = fqcsid; #endif /* USE_CSID */ pdn->dp_seid = dp_sess_id; /* Update the UE state */ pdn->state = PFCP_SESS_EST_RESP_RCVD_STATE; if (context->cp_mode == SAEGWC || context->cp_mode == PGWC || pdn->proc == S1_HANDOVER_PROC) { msg_len = set_create_session_response(gtpv2c_tx, context->sequence, context, pdn, is_piggybacked); if(is_piggybacked) { uint8_t buf1[MAX_GTPV2C_UDP_LEN] = {0}; gtpv2c_cbr_t = (gtpv2c_header_t *)buf1; gtpv2c_cbr_t = (gtpv2c_header_t *)((uint8_t *)gtpv2c_tx + msg_len); set_create_bearer_request(gtpv2c_cbr_t, context->sequence, pdn, pdn->default_bearer_id, 0, resp, is_piggybacked, TRUE); resp->state = CREATE_BER_REQ_SNT_STATE; pdn->state = CREATE_BER_REQ_SNT_STATE; uint32_t payload =ntohs(gtpv2c_cbr_t->gtpc.message_len) + sizeof(gtpv2c_cbr_t->gtpc); if(context->cp_mode == PGWC) { add_gtpv2c_if_timer_entry( teid, &s5s8_recv_sockaddr, (uint8_t *)gtpv2c_cbr_t, payload, ebi_index, S5S8_IFACE, context->cp_mode); } else { add_gtpv2c_if_timer_entry( teid, &s11_mme_sockaddr, (uint8_t *)gtpv2c_cbr_t, payload, ebi_index, S11_IFACE, context->cp_mode); } } if (context->cp_mode == SAEGWC || context->cp_mode == SGWC) { ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } if (context->cp_mode == PGWC) { ret = set_dest_address(pdn->s5s8_sgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } pdn->csr_sequence =0; if(pdn->proc == S1_HANDOVER_PROC) { context->update_sgw_fteid = TRUE; ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } ret = add_bearer_entry_by_sgw_s5s8_tied(pdn->s5s8_sgw_gtpc_teid, &bearer); if(ret) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to add bearer entry by sgw_s5s8_teid\n", LOG_VALUE); return ret; } } } else if (context->cp_mode == SGWC) { upf_context_t *upf_context = NULL; ret = rte_hash_lookup_data(upf_context_by_ip_hash, (const void*) &((context->pdns[ebi_index])->upf_ip), (void **) &(upf_context)); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"NO ENTRY FOUND IN UPF " "HASH [%u]\n", LOG_VALUE, (context->pdns[ebi_index])->upf_ip.ipv4_addr); return GTPV2C_CAUSE_INVALID_PEER; } if (context->indirect_tunnel_flag == 1){ set_create_indir_data_frwd_tun_response(gtpv2c_tx, context->indirect_tunnel->pdn); ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } resp->state = CONNECTED_STATE; pdn->state = CONNECTED_STATE; return 0; } else { ret = add_bearer_entry_by_sgw_s5s8_tied(pdn->s5s8_sgw_gtpc_teid, &bearer); if(ret) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to add bearer entry by sgw_s5s8_teid\n", LOG_VALUE); return ret; } if(context->indication_flag.oi == 1) { (pdn->context)->mme_changed_flag = TRUE; memset(gtpv2c_tx, 0, MAX_GTPV2C_UDP_LEN); set_modify_bearer_request(gtpv2c_tx, pdn, bearer); ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } resp->state = MBR_REQ_SNT_STATE; pdn->state = resp->state; pdn->proc = SGW_RELOCATION_PROC; return 0; } /*Add procedure based call here * for pdn -> CSR * for sgw relocation -> MBR */ create_sess_req_t cs_req = {0}; ret = fill_cs_request(&cs_req, context, ebi_index, pdn->requested_pdn_type); #ifdef USE_CSID /* Set the SGW FQ-CSID */ if (context->sgw_fqcsid != NULL) { if (pdn->sgw_csid.num_csid) { set_gtpc_fqcsid_t(&cs_req.sgw_fqcsid, IE_INSTANCE_ONE, &pdn->sgw_csid); } } /* Set the MME FQ-CSID */ if (context->mme_fqcsid != NULL) { if (pdn->mme_csid.num_csid) { set_gtpc_fqcsid_t(&cs_req.mme_fqcsid, IE_INSTANCE_ZERO, &pdn->mme_csid); } } #endif /* USE_CSID */ if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Failed to fill Create " "Session Request \n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } encode_create_sess_req(&cs_req, (uint8_t*)gtpv2c_tx); if (ret < 0) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to generate " "S5S8 SGWC Create Session Request.\n", LOG_VALUE); ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } /* Update the session state */ resp->state = CS_REQ_SNT_STATE; /* stored teid in csr header for clean up */ resp->gtpc_msg.csr.header.teid.has_teid.teid = pdn->s5s8_sgw_gtpc_teid; /* Update the UE state */ pdn->state = CS_REQ_SNT_STATE; return 0; } } update_sys_stat(number_of_users,INCREMENT); update_sys_stat(number_of_active_session, INCREMENT); /* Update the session state */ resp->state = CONNECTED_STATE; /* Update the UE state */ pdn->state = CONNECTED_STATE; return 0; } int8_t gtpc_recvd_sgw_fqcsid(gtp_fqcsid_ie_t *sgw_fqcsid, pdn_connection *pdn, eps_bearer *bearer, ue_context *context) { int ret = 0; uint8_t pgw_tmp_csid = 0; /* Get the copy of existing SGW CSID */ fqcsid_t sgw_tmp_csid_t = {0}; node_address_t node_addr = {0}; if (pdn->sgw_csid.num_csid) { memcpy(&sgw_tmp_csid_t, &pdn->sgw_csid, sizeof(fqcsid_t)); } if ((sgw_fqcsid->number_of_csids) && (sgw_fqcsid->node_id_type == IPV4_GLOBAL_UNICAST)) { node_addr.ip_type = PDN_TYPE_IPV4; memcpy(&node_addr.ipv4_addr, &sgw_fqcsid->node_address, IPV4_SIZE); } else { node_addr.ip_type = PDN_TYPE_IPV6; memcpy(&node_addr.ipv6_addr, &sgw_fqcsid->node_address, IPV6_SIZE); } uint8_t tmp_csid = 0; /* Validate the exsiting CSID */ for (uint8_t inx = 0; inx < sgw_fqcsid->number_of_csids; inx++) { for (uint8_t inx1 = 0; inx1 < sgw_tmp_csid_t.num_csid; inx1++) { if ((sgw_fqcsid->pdn_csid[inx] == sgw_tmp_csid_t.local_csid[inx1]) && (COMPARE_IP_ADDRESS(node_addr, sgw_tmp_csid_t.node_addr) == 0)) { tmp_csid = sgw_tmp_csid_t.local_csid[inx1]; break; } } } /* Get the copy of existing PGW CSID */ fqcsid_t pgw_tmp_csid_t = {0}; if (pdn->pgw_csid.num_csid) { memcpy(&pgw_tmp_csid_t, &pdn->pgw_csid, sizeof(fqcsid_t)); } if (!tmp_csid) { /* SGW FQ-CSID */ ret = add_peer_addr_entry_for_fqcsid_ie_node_addr( &pdn->s5s8_sgw_gtpc_ip, sgw_fqcsid, S5S8_PGWC_PORT_ID); if (ret) return ret; /* SGW FQ-CSID */ /* Stored the SGW CSID by SGW Node address */ ret = add_fqcsid_entry(sgw_fqcsid, context->sgw_fqcsid); if(ret) return ret; /* Update the entry for peer nodes */ if (fill_peer_node_info(pdn, bearer)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to fill peer node info and assignment of the " "CSID Error: %s\n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (pdn->flag_fqcsid_modified == TRUE) { /* Validate the exsiting CSID or allocated new one */ for (uint8_t inx1 = 0; inx1 < pgw_tmp_csid_t.num_csid; inx1++) { if ((context->pgw_fqcsid)->local_csid[(context->pgw_fqcsid)->num_csid - 1] == pgw_tmp_csid_t.local_csid[inx1]) { pgw_tmp_csid = pgw_tmp_csid_t.local_csid[inx1]; break; } } if (!pgw_tmp_csid) { for (uint8_t inx = 0; inx < pgw_tmp_csid_t.num_csid; inx++) { /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; tmp1 = get_sess_csid_entry(pgw_tmp_csid_t.local_csid[inx], REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seids_by_csid_hash, &pgw_tmp_csid_t.local_csid[inx], tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry for CSID = %u" "\n\tError= %s\n", LOG_VALUE, pgw_tmp_csid_t.local_csid[inx], rte_strerror(abs(ret))); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Removing temporary local CSID associated with MME */ remove_peer_temp_csid(&pdn->mme_csid, pgw_tmp_csid_t.local_csid[inx], S5S8_PGWC_PORT_ID); /* Removing temporary local CSID assocoated with SGWC */ remove_peer_temp_csid(&pdn->sgw_csid, pgw_tmp_csid_t.local_csid[inx], S5S8_PGWC_PORT_ID); /* Deleting local CSID */ del_sess_csid_entry(pgw_tmp_csid_t.local_csid[inx]); } /* Delete CSID from the context */ remove_csid_from_cntx(context->pgw_fqcsid, &pgw_tmp_csid_t); del_local_csid(&(pdn->s5s8_pgw_gtpc_ip), &pgw_tmp_csid_t); } else { /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; tmp1 = get_sess_csid_entry(pgw_tmp_csid_t.local_csid[inx], REMOVE_NODE); if (tmp1 == NULL) { /* Removing temporary local CSID associated with MME */ remove_peer_temp_csid(&pdn->mme_csid, pgw_tmp_csid_t.local_csid[inx], S5S8_PGWC_PORT_ID); /* Removing temporary local CSID assocoated with SGWC */ remove_peer_temp_csid(&pdn->sgw_csid, pgw_tmp_csid_t.local_csid[inx], S5S8_PGWC_PORT_ID); /* Deleting local CSID */ del_sess_csid_entry(pgw_tmp_csid_t.local_csid[inx]); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to " "get Session ID entry for CSID:%u\n", LOG_VALUE, pgw_tmp_csid_t.local_csid[inx]); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Remove session link from Old CSID:%u\n", LOG_VALUE, pgw_tmp_csid_t.local_csid[inx]); } } /* update entry for cp session id with link local csid */ sess_csid *tmp = NULL; /* PGWC */ tmp = get_sess_csid_entry( pdn->pgw_csid.local_csid[pdn->pgw_csid.num_csid - 1], ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get " "session of CSID entry, Error %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Link local csid with session id */ /* Check head node created ot not */ if(tmp->cp_seid != pdn->seid && tmp->cp_seid != 0) { sess_csid *new_node = NULL; /* Add new node into csid linked list */ new_node = add_sess_csid_data_node(tmp, pdn->pgw_csid.local_csid[pdn->pgw_csid.num_csid - 1]); if(new_node == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "ADD new node into CSID linked list : %s\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } else { new_node->cp_seid = pdn->seid; new_node->up_seid = pdn->dp_seid; } } else { tmp->cp_seid = pdn->seid; tmp->up_seid = pdn->dp_seid; tmp->next = NULL; } /* Generate the New CSID */ if (!pgw_tmp_csid) return PRESENT; } /* Remove the Old CSID from the table */ fqcsid_t *tmp_t = NULL; /* Get the Peer node CSID List */ tmp_t = get_peer_addr_csids_entry(&node_addr, REMOVE_NODE); if (tmp_t != NULL) { for (uint8_t inx2 = 0; inx2 < tmp_t->num_csid; inx2++) { for (uint8_t inx3 = 0; inx3 < sgw_tmp_csid_t.num_csid; inx3++) { if (tmp_t->local_csid[inx2] == sgw_tmp_csid_t.local_csid[inx3]) { /* Removed old CSID from the list */ for(uint8_t pos = inx2; pos < (tmp_t->num_csid - 1); pos++ ) { tmp_t->local_csid[pos] = tmp_t->local_csid[pos + 1]; } /* Decrement the CSID List counter */ tmp_t->num_csid--; } } } } } /* Cleanup Internal data structures */ ret = del_csid_entry_hash(&sgw_tmp_csid_t, &pgw_tmp_csid_t, S5S8_PGWC_PORT_ID); if (ret) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to delete CSID " "Entry from hash while cleanup session \n", LOG_VALUE); } /* Delete old sgwc node entry */ if (pdn->old_sgw_addr_valid == True) { peer_node_addr_key_t key = {0}; key.iface = S5S8_PGWC_PORT_ID; memcpy(&key.peer_node_addr, &pdn->old_sgw_addr, sizeof(node_address_t)); del_peer_node_addr_entry(&key); } return 0; } int send_pfcp_sess_mod_req(pdn_connection *pdn, eps_bearer *bearer, mod_bearer_req_t *mb_req) { struct resp_info *resp = NULL; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; int ebi_index = 0, index = 0, ret = 0; eps_bearer *bearers[MAX_BEARERS] = {NULL}; uint8_t send_endmarker = 0; ue_context *context = NULL; eps_bearer *tmp_bearer = NULL; pfcp_update_far_ie_t update_far[MAX_LIST_SIZE] = {0}; pfcp_sess_mod_req.update_far_count = 0; ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } tmp_bearer = bearer; RTE_SET_USED(update_far); /* TODO: CHECK FOR BEARER MODIFCIATION */ if(((pdn->context->sgwu_changed == TRUE) && (pdn->context->cp_mode == PGWC)) || ((pdn->context)->cp_mode == SAEGWC)) { for(uint8_t j= 0; j< mb_req->bearer_count; j++) { for(uint8_t i =0 ;i< MAX_BEARERS; i++) { bearer = pdn->eps_bearers[i]; if(bearer == NULL) continue; if(bearer->eps_bearer_id != mb_req->bearer_contexts_to_be_modified[j].eps_bearer_id.ebi_ebi) { continue; } else { if ((mb_req->bearer_contexts_to_be_modified[j].s1_enodeb_fteid.header.len != 0) || (mb_req->bearer_contexts_to_be_modified[j].s58_u_sgw_fteid.header.len != 0) || (mb_req->bearer_contexts_to_be_modified[j].s11_u_mme_fteid.header.len != 0)) { if((mb_req->bearer_contexts_to_be_modified[j].s1_enodeb_fteid.v6 && bearer->s1u_sgw_gtpu_ip.ip_type == PDN_TYPE_IPV4) || (mb_req->bearer_contexts_to_be_modified[j].s1_enodeb_fteid.v4 && bearer->s1u_sgw_gtpu_ip.ip_type == PDN_TYPE_IPV6)){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"The EnodeB s1u IP not compatible" " with SGW/SAEGW s1u IP\n", LOG_VALUE); return GTPV2C_CAUSE_REQUEST_REJECTED; } if(mb_req->indctn_flgs.indication_s11tf) { /* Set the indication flag for s11-u teid */ pdn->context->indication_flag.s11tf = 1; /* Set if MME sends MO Exception Data Counter */ if(mb_req->mo_exception_data_cntr.header.len){ pdn->context->mo_exception_flag = True; if(mb_req->mo_exception_data_cntr.counter_value == 1) pdn->context->mo_exception_data_counter.timestamp_value = mb_req->mo_exception_data_cntr.timestamp_value; pdn->context->mo_exception_data_counter.counter_value = mb_req->mo_exception_data_cntr.counter_value; } ret = fill_ip_addr(mb_req->bearer_contexts_to_be_modified[j].s11_u_mme_fteid.ipv4_address, mb_req->bearer_contexts_to_be_modified[j].s11_u_mme_fteid.ipv6_address, &bearer->s11u_mme_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s11u_mme_gtpu_teid = mb_req->bearer_contexts_to_be_modified[j].s11_u_mme_fteid.teid_gre_key; update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.\ outer_hdr_creation.teid = bearer->s11u_mme_gtpu_teid; ret = set_node_address(&update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv6_address, bearer->s11u_mme_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.\ dst_intfc.interface_value = check_interface_type(mb_req->bearer_contexts_to_be_modified[j].\ s11_u_mme_fteid.interface_type, pdn->context->cp_mode); update_far[pfcp_sess_mod_req.update_far_count].far_id.far_id_value = get_far_id(bearer, update_far[pfcp_sess_mod_req.update_far_count].\ upd_frwdng_parms.dst_intfc.interface_value); if ( pdn->context->cp_mode != PGWC) { update_far[pfcp_sess_mod_req.update_far_count].apply_action.forw = PRESENT; update_far[pfcp_sess_mod_req.update_far_count].apply_action.dupl = GET_DUP_STATUS(pdn->context); } pfcp_sess_mod_req.update_far_count++; } if (mb_req->bearer_contexts_to_be_modified[j].s1_enodeb_fteid.header.len != 0){ pdn->context->indication_flag.s11tf = 0; /* TAU change */ if((bearer->s1u_enb_gtpu_ip.ipv4_addr != 0 || *bearer->s1u_enb_gtpu_ip.ipv6_addr) && (bearer->s1u_enb_gtpu_teid != 0)) { if((mb_req->bearer_contexts_to_be_modified[j].s1_enodeb_fteid.teid_gre_key) != bearer->s1u_enb_gtpu_teid || ((mb_req->bearer_contexts_to_be_modified[j].s1_enodeb_fteid.ipv4_address) !=bearer->s1u_enb_gtpu_ip.ipv4_addr) || (memcmp(mb_req->bearer_contexts_to_be_modified[j].s1_enodeb_fteid.ipv6_address, bearer->s1u_enb_gtpu_ip.ipv6_addr, IPV6_ADDRESS_LEN) !=0)) { send_endmarker = 1; } } if(pdn->state == IDEL_STATE) { update_pdr_actions_flags(bearer); } ret = fill_ip_addr(mb_req->bearer_contexts_to_be_modified[j].s1_enodeb_fteid.ipv4_address, mb_req->bearer_contexts_to_be_modified[j].s1_enodeb_fteid.ipv6_address, &bearer->s1u_enb_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s1u_enb_gtpu_teid = mb_req->bearer_contexts_to_be_modified[j].s1_enodeb_fteid.teid_gre_key; update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.teid = bearer->s1u_enb_gtpu_teid; ret = set_node_address(&update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv6_address, bearer->s1u_enb_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value = check_interface_type(mb_req->bearer_contexts_to_be_modified[j].s1_enodeb_fteid.interface_type, pdn->context->cp_mode); update_far[pfcp_sess_mod_req.update_far_count].far_id.far_id_value = get_far_id(bearer, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value); if ( pdn->context->cp_mode != PGWC) { update_far[pfcp_sess_mod_req.update_far_count].apply_action.forw = PRESENT; update_far[pfcp_sess_mod_req.update_far_count].apply_action.dupl = GET_DUP_STATUS(pdn->context); } pfcp_sess_mod_req.update_far_count++; } if (mb_req->bearer_contexts_to_be_modified[j].s58_u_sgw_fteid.header.len != 0){ if( (bearer->s5s8_sgw_gtpu_ip.ipv4_addr != mb_req->bearer_contexts_to_be_modified[j].s58_u_sgw_fteid.ipv4_address || memcmp( bearer->s5s8_sgw_gtpu_ip.ipv6_addr, mb_req->bearer_contexts_to_be_modified[j].s58_u_sgw_fteid.ipv6_address, IPV6_ADDRESS_LEN) != 0) || (bearer->s5s8_sgw_gtpu_teid != mb_req->bearer_contexts_to_be_modified[j].s58_u_sgw_fteid.teid_gre_key)){ send_endmarker = 1; } ret = fill_ip_addr(mb_req->bearer_contexts_to_be_modified[j].s58_u_sgw_fteid.ipv4_address, mb_req->bearer_contexts_to_be_modified[j].s58_u_sgw_fteid.ipv6_address, &bearer->s5s8_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s5s8_sgw_gtpu_teid = mb_req->bearer_contexts_to_be_modified[j].s58_u_sgw_fteid.teid_gre_key; update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.teid = bearer->s5s8_sgw_gtpu_teid; ret = set_node_address(&update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv6_address, bearer->s5s8_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value = check_interface_type(mb_req->bearer_contexts_to_be_modified[j].s58_u_sgw_fteid.interface_type, pdn->context->cp_mode); update_far[pfcp_sess_mod_req.update_far_count].far_id.far_id_value = get_far_id(bearer, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value); if ( pdn->context->cp_mode != PGWC) { update_far[pfcp_sess_mod_req.update_far_count].apply_action.forw = PRESENT; update_far[pfcp_sess_mod_req.update_far_count].apply_action.dupl = GET_DUP_STATUS(pdn->context); } pfcp_sess_mod_req.update_far_count++; } /* After SAEGWU --> PGWU update the PDR info */ if ((pdn->context)->cp_mode_flag) { for(uint8_t pdr = 0; pdr < bearer->pdr_count; pdr++) { if (bearer->pdrs[pdr] == NULL) { continue; } if ((bearer->pdrs[pdr])->pdi.src_intfc.interface_value == SOURCE_INTERFACE_VALUE_ACCESS) { /* Update the local source IP Address and teid */ ret = set_node_address(&(bearer->pdrs[pdr])->pdi.local_fteid.ipv4_address, (bearer->pdrs[pdr])->pdi.local_fteid.ipv6_address, bearer->s5s8_pgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } /* Update the PDR info */ set_update_pdr(&(pfcp_sess_mod_req.update_pdr[pfcp_sess_mod_req.update_pdr_count]), bearer->pdrs[pdr], (pdn->context)->cp_mode); /* Reset Precedance, No need to forward */ memset(&(pfcp_sess_mod_req.update_pdr[pfcp_sess_mod_req.update_pdr_count].precedence), 0, sizeof(pfcp_precedence_ie_t)); /* Reset FAR ID, No need to forward */ memset(&(pfcp_sess_mod_req.update_pdr[pfcp_sess_mod_req.update_pdr_count].far_id), 0, sizeof(pfcp_far_id_ie_t)); /* Update the PDR header length */ pfcp_sess_mod_req.update_pdr[pfcp_sess_mod_req.update_pdr_count].header.len -= (sizeof(pfcp_far_id_ie_t) + sizeof(pfcp_precedence_ie_t)); pfcp_sess_mod_req.update_pdr_count++; } } } /* Added 0 in the last argument below as it is not X2 handover case */ bearers[index] = bearer; index++; } j++; } } } } fill_pfcp_sess_mod_req(&pfcp_sess_mod_req, &mb_req->header, bearers, pdn, update_far, send_endmarker, index, pdn->context); context = pdn->context; #ifdef USE_CSID uint8_t num_csid = 0; fqcsid_t tmp_fqcsid = {0}; if(mb_req->mme_fqcsid.header.len != 0 ) { if ((mb_req->mme_fqcsid).number_of_csids) { if ((context != NULL) && (context->mme_fqcsid == NULL)) { context->mme_fqcsid = rte_zmalloc_socket(NULL, sizeof(sess_fqcsid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (context->mme_fqcsid == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the " "memory for fqcsids entry\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } /* Coping Exsiting MME CSID associted with Session */ memcpy(&tmp_fqcsid, &pdn->mme_csid, sizeof(fqcsid_t)); if (context->cp_mode != PGWC ) { int ret = add_peer_addr_entry_for_fqcsid_ie_node_addr( &context->s11_mme_gtpc_ip, &mb_req->mme_fqcsid, S11_SGW_PORT_ID); if (ret) return ret; } /* Parse and stored MME FQ-CSID in the context */ ret = add_fqcsid_entry(&mb_req->mme_fqcsid, context->mme_fqcsid); if(ret) return ret; fill_pdn_fqcsid_info(&pdn->mme_csid, context->mme_fqcsid); /* Remove old mme csid from UE context */ remove_csid_from_cntx(context->mme_fqcsid, &tmp_fqcsid); if (link_sess_with_peer_csid(&pdn->mme_csid, pdn, ((context->cp_mode != PGWC) ? S11_SGW_PORT_ID : S5S8_PGWC_PORT_ID))) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error : Failed to Link Session with MME CSID \n", LOG_VALUE); return -1; } /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; peer_csid_key_t key = {0}; key.iface = ((context->cp_mode != PGWC) ? S11_SGW_PORT_ID : S5S8_PGWC_PORT_ID); key.peer_local_csid = tmp_fqcsid.local_csid[num_csid]; memcpy(&key.peer_node_addr, &(tmp_fqcsid.node_addr), sizeof(node_address_t)); tmp1 = get_sess_peer_csid_entry(&key, REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seid_by_peer_csid_hash, &key, tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry" " for CSID = %u \n", LOG_VALUE, tmp_fqcsid.local_csid[num_csid]); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Delete Local CSID entry */ del_sess_peer_csid_entry(&key); } } if (context->cp_mode != PGWC) { /* Cleanup Internal data structures */ ret = del_csid_entry_hash(&tmp_fqcsid, &pdn->sgw_csid, S11_SGW_PORT_ID); if (ret) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to delete CSID " "Entry from hash while cleanup session \n", LOG_VALUE); } } else { if (link_gtpc_peer_csids(&pdn->mme_csid, &pdn->pgw_csid, S5S8_PGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Link " "Local CSID entry to link with MME FQCSID, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } /* Cleanup Internal data structures */ ret = del_csid_entry_hash(&tmp_fqcsid, &pdn->pgw_csid, S5S8_PGWC_PORT_ID); if (ret) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to delete CSID " "Entry from hash while cleanup session \n", LOG_VALUE); } } /* set MME FQ-CSID */ set_fq_csid_t(&pfcp_sess_mod_req.mme_fqcsid, &pdn->mme_csid); } } if(mb_req->sgw_fqcsid.header.len != 0 ) { /* Parse and stored SGW FQ-CSID in the context */ if (mb_req->sgw_fqcsid.number_of_csids) { int ret_t = 0; /* Get the copy of existing SGW CSID */ fqcsid_t sgw_tmp_csid_t = {0}; pdn->flag_fqcsid_modified = FALSE; ret_t = gtpc_recvd_sgw_fqcsid(&mb_req->sgw_fqcsid, pdn, tmp_bearer, context); if ((ret_t != 0) && (ret_t != PRESENT)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed Link peer CSID\n", LOG_VALUE); return ret_t; } /* Fill the Updated CSID in the Modification Request */ /* Set SGW FQ-CSID */ if (context->sgw_fqcsid != NULL) { if (pdn->sgw_csid.num_csid) { memcpy(&sgw_tmp_csid_t, &pdn->sgw_csid, sizeof(fqcsid_t)); /*Need to remove the previous CSID(in case of TAU with DF)*/ remove_csid_from_cntx(context->sgw_fqcsid, &sgw_tmp_csid_t); } fill_pdn_fqcsid_info(&pdn->sgw_csid, context->sgw_fqcsid); if (pdn->sgw_csid.num_csid) { if (link_gtpc_peer_csids(&pdn->sgw_csid, &pdn->pgw_csid, S5S8_PGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Link " "Local CSID entry to link with SGW FQCSID, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } } /* Link session with new sgwc csid */ if (link_sess_with_peer_csid(&pdn->sgw_csid, pdn, S5S8_PGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Failed to Link " "session with SGW CSID \n", LOG_VALUE); return -1; } /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; peer_csid_key_t key = {0}; key.iface = S5S8_PGWC_PORT_ID; key.peer_local_csid = sgw_tmp_csid_t.local_csid[num_csid]; memcpy(&key.peer_node_addr, &sgw_tmp_csid_t.node_addr, sizeof(node_address_t)); tmp1 = get_sess_peer_csid_entry(&key, REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seid_by_peer_csid_hash, &key, tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry" " for CSID = %u \n", LOG_VALUE, sgw_tmp_csid_t.local_csid[num_csid]); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Delete Local CSID entry */ del_sess_peer_csid_entry(&key); } } if (pdn->sgw_csid.num_csid) { set_fq_csid_t(&pfcp_sess_mod_req.sgw_c_fqcsid, &pdn->sgw_csid); /* set PGWC FQ-CSID */ set_fq_csid_t(&pfcp_sess_mod_req.pgw_c_fqcsid, &pdn->pgw_csid); } } if (ret_t == PRESENT) { /* set PGWC FQ-CSID */ set_fq_csid_t(&pfcp_sess_mod_req.pgw_c_fqcsid, &pdn->pgw_csid); } } } /*context->cp_mode == SAEGWC*/ if (context->cp_mode != PGWC) { /* Get the copy of existing SGW CSID */ fqcsid_t tmp_csid_t = {0}; pdn->flag_fqcsid_modified = FALSE; if (pdn->sgw_csid.num_csid) { memcpy(&tmp_csid_t, &pdn->sgw_csid, sizeof(fqcsid_t)); } /* Update the entry for peer nodes */ if (fill_peer_node_info(pdn, tmp_bearer)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to fill peer node info and assignment of the " "CSID Error: %s\n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (pdn->flag_fqcsid_modified == TRUE) { uint8_t tmp_csid = 0; /* Validate the exsiting CSID or allocated new one */ for (uint8_t inx1 = 0; inx1 < tmp_csid_t.num_csid; inx1++) { if ((context->sgw_fqcsid)->local_csid[(context->sgw_fqcsid)->num_csid - 1] == tmp_csid_t.local_csid[inx1]) { tmp_csid = tmp_csid_t.local_csid[inx1]; break; } } if (!tmp_csid) { for (uint8_t inx = 0; inx < tmp_csid_t.num_csid; inx++) { /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; tmp1 = get_sess_csid_entry(tmp_csid_t.local_csid[inx], REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seids_by_csid_hash, &tmp_csid_t.local_csid[inx], tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry for CSID = %u" "\n\tError= %s\n", LOG_VALUE, tmp_csid_t.local_csid[inx], rte_strerror(abs(ret))); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Removing temporary local CSID associated with MME */ remove_peer_temp_csid(&pdn->mme_csid, tmp_csid_t.local_csid[inx], S11_SGW_PORT_ID); /* Removing temporary local CSID assocoated with PGWC */ remove_peer_temp_csid(&pdn->pgw_csid, tmp_csid_t.local_csid[inx], S5S8_SGWC_PORT_ID); /* Delete Local CSID entry */ del_sess_csid_entry(tmp_csid_t.local_csid[inx]); } /* Delete CSID from the context */ remove_csid_from_cntx(context->sgw_fqcsid, &tmp_csid_t); del_local_csid(&(context->s11_sgw_gtpc_ip), &tmp_csid_t); } else { /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; tmp1 = get_sess_csid_entry(tmp_csid_t.local_csid[inx], REMOVE_NODE); if (tmp1 == NULL) { /* Removing temporary local CSID associated with MME */ remove_peer_temp_csid(&pdn->mme_csid, tmp_csid_t.local_csid[inx], S11_SGW_PORT_ID); /* Removing temporary local CSID assocoated with PGWC */ remove_peer_temp_csid(&pdn->pgw_csid, tmp_csid_t.local_csid[inx], S5S8_SGWC_PORT_ID); /* Delete Local CSID entry */ del_sess_csid_entry(tmp_csid_t.local_csid[inx]); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to " "get Session ID entry for CSID:%u\n", LOG_VALUE, tmp_csid); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Remove session link from Old CSID:%u\n", LOG_VALUE, tmp_csid); } } /* update entry for cp session id with link local csid */ sess_csid *tmp = NULL; tmp = get_sess_csid_entry( pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1], ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get " "session of CSID entry, Error %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Link local csid with session id */ /* Check head node created ot not */ if(tmp->cp_seid != pdn->seid && tmp->cp_seid != 0) { sess_csid *new_node = NULL; /* Add new node into csid linked list */ new_node = add_sess_csid_data_node(tmp, pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1]); if(new_node == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "ADD new node into CSID linked list : %s\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } else { new_node->cp_seid = pdn->seid; new_node->up_seid = pdn->dp_seid; } } else { tmp->cp_seid = pdn->seid; tmp->up_seid = pdn->dp_seid; tmp->next = NULL; } /* Fill the fqcsid into the session est request */ if (fill_fqcsid_sess_mod_req(&pfcp_sess_mod_req, pdn)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to fill " "FQ-CSID in Sess EST Req ERROR: %s\n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } } } #endif /* USE_CSID */ /* After SAEGWU --> PGWU update the PDR info */ if ((pdn->context)->cp_mode_flag) { /* Reset Flag */ (pdn->context)->cp_mode_flag = FALSE; } uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr,SENT) < 0 ) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error sending PFCP Session " "Modification Request : %i\n", LOG_VALUE, errno); } /* Update UE State */ pdn->state = PFCP_SESS_MOD_REQ_SNT_STATE; #ifdef CP_BUILD add_pfcp_if_timer_entry(mb_req->header.teid.has_teid.teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ /*Retrive the session information based on session id. */ if (get_sess_entry(pdn->seid, &resp) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session entry found for " "session ID:%lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn->context->sequence = mb_req->header.teid.has_teid.seq; for (int itr = 0 ; itr < mb_req->bearer_count ; itr++) { resp->eps_bearer_ids[itr] = mb_req->bearer_contexts_to_be_modified[ebi_index].eps_bearer_id.ebi_ebi; } resp->msg_type = GTP_MODIFY_BEARER_REQ; resp->state = PFCP_SESS_MOD_REQ_SNT_STATE; pdn->state = PFCP_SESS_MOD_REQ_SNT_STATE; pdn->proc = MODIFY_BEARER_PROCEDURE; resp->proc = pdn->proc; resp->cp_mode = pdn->context->cp_mode; resp->gtpc_msg.mbr = *mb_req; return 0; } /** * @brief : Compare ecgi data * @param : mb_ecgi, ecgi from incoming request * @param : context_ecgi, ecgi data stored in context * @return : Returns 0 on success, -1 otherwise */ static int compare_ecgi(ecgi_field_t *mb_ecgi, ecgi_t *context_ecgi) { if(mb_ecgi->ecgi_mcc_digit_1 != context_ecgi->ecgi_mcc_digit_1) return FALSE; if(mb_ecgi->ecgi_mcc_digit_2 != context_ecgi->ecgi_mcc_digit_2) return FALSE; if(mb_ecgi->ecgi_mcc_digit_3 != context_ecgi->ecgi_mcc_digit_3) return FALSE; if(mb_ecgi->ecgi_mnc_digit_1 != context_ecgi->ecgi_mnc_digit_1) return FALSE; if(mb_ecgi->ecgi_mnc_digit_2 != context_ecgi->ecgi_mnc_digit_2) return FALSE; if(mb_ecgi->ecgi_mnc_digit_3 != context_ecgi->ecgi_mnc_digit_3) return FALSE; if(mb_ecgi->ecgi_spare != context_ecgi->ecgi_spare) return FALSE; if(mb_ecgi->eci != context_ecgi->eci) return FALSE; return TRUE; } /** * @brief : Compare cgi data * @param : mb_cgi, cgi from incoming request * @param : context_cgi, cgi data stored in context * @return : Returns 0 on success, -1 otherwise */ static int compare_cgi(cgi_field_t *mb_cgi, cgi_t *context_cgi) { if(mb_cgi->cgi_mcc_digit_1 != context_cgi->cgi_mcc_digit_1) return FALSE; if(mb_cgi->cgi_mcc_digit_2 != context_cgi->cgi_mcc_digit_2) return FALSE; if(mb_cgi->cgi_mcc_digit_3 != context_cgi->cgi_mcc_digit_3) return FALSE; if(mb_cgi->cgi_mnc_digit_1 != context_cgi->cgi_mnc_digit_1) return FALSE; if(mb_cgi->cgi_mnc_digit_2 != context_cgi->cgi_mnc_digit_2) return FALSE; if(mb_cgi->cgi_mnc_digit_3 != context_cgi->cgi_mnc_digit_3) return FALSE; if(mb_cgi->cgi_lac != context_cgi->cgi_lac) return FALSE; if(mb_cgi->cgi_ci != context_cgi->cgi_ci) return FALSE; return TRUE; } /** * @brief : Compare sai data * @param : mb_sai, sai from incoming request * @param : context_sai, sai data stored in context * @return : Returns 0 on success, -1 otherwise */ static int compare_sai(sai_field_t *mb_sai, sai_t *context_sai) { if(mb_sai->sai_mcc_digit_1 != context_sai->sai_mcc_digit_1) return FALSE; if(mb_sai->sai_mcc_digit_2 != context_sai->sai_mcc_digit_2) return FALSE; if(mb_sai->sai_mcc_digit_3 != context_sai->sai_mcc_digit_3) return FALSE; if(mb_sai->sai_mnc_digit_1 != context_sai->sai_mnc_digit_1) return FALSE; if(mb_sai->sai_mnc_digit_2 != context_sai->sai_mnc_digit_2) return FALSE; if(mb_sai->sai_mnc_digit_3 != context_sai->sai_mnc_digit_3) return FALSE; if(mb_sai->sai_lac != context_sai->sai_lac) return FALSE; if(mb_sai->sai_sac != context_sai->sai_sac) return FALSE; return TRUE; } /** * @brief : Compare rai data * @param : mb_rai, rai from incoming request * @param : context_rai, rai data stored in context * @return : Returns 0 on success, -1 otherwise */ static int compare_rai(rai_field_t *mb_rai, rai_t *context_rai) { if(mb_rai->ria_mcc_digit_1 != context_rai->ria_mcc_digit_1) return FALSE; if(mb_rai->ria_mcc_digit_2 != context_rai->ria_mcc_digit_2) return FALSE; if(mb_rai->ria_mcc_digit_3 != context_rai->ria_mcc_digit_3) return FALSE; if(mb_rai->ria_mnc_digit_1 != context_rai->ria_mnc_digit_1) return FALSE; if(mb_rai->ria_mnc_digit_2 != context_rai->ria_mnc_digit_2) return FALSE; if(mb_rai->ria_mnc_digit_3 != context_rai->ria_mnc_digit_3) return FALSE; if(mb_rai->ria_lac != context_rai->ria_lac) return FALSE; if(mb_rai->ria_rac != context_rai->ria_rac) return FALSE; return TRUE; } /** * @brief : Compare tai data * @param : mb_tai, tai from incoming request * @param : context_tai, tai data stored in context * @return : Returns 0 on success, -1 otherwise */ static int compare_tai(tai_field_t *mb_tai, tai_t *context_tai) { if(mb_tai->tai_mcc_digit_1 != context_tai->tai_mcc_digit_1) return FALSE; if(mb_tai->tai_mcc_digit_2 != context_tai->tai_mcc_digit_2) return FALSE; if(mb_tai->tai_mcc_digit_3 != context_tai->tai_mcc_digit_3) return FALSE; if(mb_tai->tai_mnc_digit_1 != context_tai->tai_mnc_digit_1) return FALSE; if(mb_tai->tai_mnc_digit_2 != context_tai->tai_mnc_digit_2) return FALSE; if(mb_tai->tai_mnc_digit_3 != context_tai->tai_mnc_digit_3) return FALSE; if(mb_tai->tai_tac != context_tai->tai_tac) return FALSE; return TRUE; } /** * @brief : Compare uci information * @param : mb_req, data from incoming request * @param : context, data stored in ue context * @return : Returns 0 on success, -1 otherwise */ static int compare_uci(mod_bearer_req_t *mb_req, ue_context *context){ if(context->uci.mnc_digit_1 != mb_req->uci.mnc_digit_1) return FALSE; if(context->uci.mnc_digit_2 != mb_req->uci.mnc_digit_2) return FALSE; if(context->uci.mnc_digit_3 != mb_req->uci.mnc_digit_3) return FALSE; if(context->uci.mcc_digit_1 != mb_req->uci.mcc_digit_1) return FALSE; if(context->uci.mcc_digit_2 != mb_req->uci.mcc_digit_2) return FALSE; if(context->uci.mcc_digit_3 != mb_req->uci.mcc_digit_3) return FALSE; if(context->uci.csg_id != mb_req->uci.csg_id) return FALSE; if(context->uci.csg_id2 != mb_req->uci.csg_id2) return FALSE; if(context->uci.access_mode != mb_req->uci.access_mode) return FALSE; if(context->uci.lcsg != mb_req->uci.lcsg) return FALSE; if(context->uci.cmi != mb_req->uci.cmi) return FALSE; return TRUE; } /** * @brief : Compare serving network information * @param : mb_req, data from incoming request * @param : context, data stored in ue context * @return : Returns 0 on success, -1 otherwise */ static int compare_serving_network(mod_bearer_req_t *mb_req, ue_context *context){ if(context->serving_nw.mnc_digit_1 != mb_req->serving_network.mnc_digit_1) return FALSE; if(context->serving_nw.mnc_digit_2 != mb_req->serving_network.mnc_digit_2) return FALSE; if(context->serving_nw.mnc_digit_3 != mb_req->serving_network.mnc_digit_3) return FALSE; if(context->serving_nw.mcc_digit_1 != mb_req->serving_network.mcc_digit_1) return FALSE; if(context->serving_nw.mcc_digit_2 != mb_req->serving_network.mcc_digit_2) return FALSE; if(context->serving_nw.mcc_digit_3 != mb_req->serving_network.mcc_digit_3) return FALSE; return TRUE; } /** * @brief : Save serving network information * @param : mb_req, data from incoming request * @param : context, data stored in ue context * @return : Returns 0 on success, -1 otherwise */ static void save_serving_network(mod_bearer_req_t *mb_req, ue_context *context){ context->serving_nw.mnc_digit_1 = mb_req->serving_network.mnc_digit_1; context->serving_nw.mnc_digit_2 = mb_req->serving_network.mnc_digit_2; context->serving_nw.mnc_digit_3 = mb_req->serving_network.mnc_digit_3; context->serving_nw.mcc_digit_1 = mb_req->serving_network.mcc_digit_1; context->serving_nw.mcc_digit_2 = mb_req->serving_network.mcc_digit_2; context->serving_nw.mcc_digit_3 = mb_req->serving_network.mcc_digit_3; } /** * @brief : Save uci information * @param : recv_uci, data from incoming request * @param : context, data stored in ue context * @return : Returns 0 on success, -1 otherwise */ static void save_uci(gtp_user_csg_info_ie_t *recv_uci, ue_context *context){ context->uci.mnc_digit_1 = recv_uci->mnc_digit_1; context->uci.mnc_digit_2 = recv_uci->mnc_digit_2; context->uci.mnc_digit_3 = recv_uci->mnc_digit_3; context->uci.mcc_digit_1 = recv_uci->mcc_digit_1; context->uci.mcc_digit_2 = recv_uci->mcc_digit_2; context->uci.mcc_digit_3 = recv_uci->mcc_digit_3; context->uci.csg_id = recv_uci->csg_id; context->uci.csg_id2 = recv_uci->csg_id2; context->uci.access_mode = recv_uci->access_mode; context->uci.lcsg = recv_uci->lcsg; context->uci.cmi = recv_uci->cmi; } /** * @brief : Save tai information * @param : recv_tai, data from incoming request * @param : context_tai, data stored in ue context * @return : Returns 0 on success, -1 otherwise */ static void save_tai(tai_field_t *recv_tai, tai_t *context_tai) { //context_tai->uli_old.tai = uli->tai; context_tai->tai_mcc_digit_2 = recv_tai->tai_mcc_digit_2; context_tai->tai_mcc_digit_1 = recv_tai->tai_mcc_digit_1; context_tai->tai_mnc_digit_3 = recv_tai->tai_mnc_digit_3; context_tai->tai_mcc_digit_3 = recv_tai->tai_mcc_digit_3; context_tai->tai_mnc_digit_2 = recv_tai->tai_mnc_digit_2; context_tai->tai_mnc_digit_1 = recv_tai->tai_mnc_digit_1; context_tai->tai_tac = recv_tai->tai_tac; } /** * @brief : Save cgi information * @param : recv_cgi, data from incoming request * @param : context_cgi, data stored in ue context * @return : Returns 0 on success, -1 otherwise */ static void save_cgi(cgi_field_t *recv_cgi, cgi_t *context_cgi) { context_cgi->cgi_mcc_digit_2 = recv_cgi->cgi_mcc_digit_2; context_cgi->cgi_mcc_digit_1 = recv_cgi->cgi_mcc_digit_1; context_cgi->cgi_mnc_digit_3 = recv_cgi->cgi_mnc_digit_3; context_cgi->cgi_mcc_digit_3 = recv_cgi->cgi_mcc_digit_3; context_cgi->cgi_mnc_digit_2 = recv_cgi->cgi_mnc_digit_2; context_cgi->cgi_mnc_digit_1 = recv_cgi->cgi_mnc_digit_1; context_cgi->cgi_lac =recv_cgi->cgi_lac; context_cgi->cgi_ci = recv_cgi->cgi_ci; } /** * @brief : Save sai information * @param : recv_sai, data from incoming request * @param : context_sai, data stored in ue context * @return : Returns 0 on success, -1 otherwise */ static void save_sai(sai_field_t *recv_sai, sai_t *context_sai) { context_sai->sai_mcc_digit_2 = recv_sai->sai_mcc_digit_2; context_sai->sai_mcc_digit_1 = recv_sai->sai_mcc_digit_1; context_sai->sai_mnc_digit_3 = recv_sai->sai_mnc_digit_3; context_sai->sai_mcc_digit_3 = recv_sai->sai_mcc_digit_3; context_sai->sai_mnc_digit_2 = recv_sai->sai_mnc_digit_2; context_sai->sai_mnc_digit_1 = recv_sai->sai_mnc_digit_1; context_sai->sai_lac = recv_sai->sai_lac; context_sai->sai_sac = recv_sai->sai_sac; } /** * @brief : Save rai information * @param : recv_rai, data from incoming request * @param : context_rai, data stored in ue context * @return : Returns 0 on success, -1 otherwise */ static void save_rai(rai_field_t *recv_rai, rai_t *context_rai) { context_rai->ria_mcc_digit_2 = recv_rai->ria_mcc_digit_2; context_rai->ria_mcc_digit_1 = recv_rai->ria_mcc_digit_1; context_rai->ria_mnc_digit_3 = recv_rai->ria_mnc_digit_3; context_rai->ria_mcc_digit_3 = recv_rai->ria_mcc_digit_3; context_rai->ria_mnc_digit_2 = recv_rai->ria_mnc_digit_2; context_rai->ria_mnc_digit_1 = recv_rai->ria_mnc_digit_1; context_rai->ria_lac = recv_rai->ria_lac; context_rai->ria_rac = recv_rai->ria_rac; } /** * @brief : Save ecgi information * @param : recv_ecgi, data from incoming request * @param : context_ecgi, data stored in ue context * @return : Returns 0 on success, -1 otherwise */ static void save_ecgi(ecgi_field_t *recv_ecgi, ecgi_t *context_ecgi) { context_ecgi->ecgi_mcc_digit_2 = recv_ecgi->ecgi_mcc_digit_2; context_ecgi->ecgi_mcc_digit_1 = recv_ecgi->ecgi_mcc_digit_1; context_ecgi->ecgi_mnc_digit_3 = recv_ecgi->ecgi_mnc_digit_3; context_ecgi->ecgi_mcc_digit_3 = recv_ecgi->ecgi_mcc_digit_3; context_ecgi->ecgi_mnc_digit_2 = recv_ecgi->ecgi_mnc_digit_2; context_ecgi->ecgi_mnc_digit_1 = recv_ecgi->ecgi_mnc_digit_1; context_ecgi->ecgi_spare = recv_ecgi->ecgi_spare; context_ecgi->eci = recv_ecgi->eci; } /** * @brief : Function checks if uli information is changed * @param : uli, data from incoming request * @param : context, data stored in ue context * @param : flag_check, flag to set if uli is changed * @return : Returns 0 on success, -1 otherwise */ void check_for_uli_changes(gtp_user_loc_info_ie_t *uli, ue_context *context) { uint8_t ret = 0; if(uli->tai) { ret = compare_tai(&uli->tai2, &context->uli.tai2); if(ret == FALSE) { context->uli_flag |= (1 << 0 ); save_tai(&uli->tai2, &context->uli.tai2); } } if(uli->cgi) { ret = compare_cgi(&uli->cgi2, &context->uli.cgi2); if(ret == FALSE) { context->uli_flag |= ( 1<< 1 ); save_cgi(&uli->cgi2, &context->uli.cgi2); } } if(uli->sai) { ret = compare_sai(&uli->sai2, &context->uli.sai2); if(ret == FALSE) { context->uli_flag |= (1 << 2 ); save_sai(&uli->sai2, &context->uli.sai2); } } if(uli->rai) { ret = compare_rai(&uli->rai2, &context->uli.rai2); if(ret == FALSE) { context->uli_flag |= ( 1 << 3 ); save_rai(&uli->rai2, &context->uli.rai2); } } if(uli->ecgi) { ret = compare_ecgi(&uli->ecgi2, &context->uli.ecgi2); if(ret == FALSE) { context->uli_flag |= (1 << 4); save_ecgi(&uli->ecgi2, &context->uli.ecgi2); } } } void update_pdr_actions_flags(eps_bearer *bearer) { if (bearer != NULL) { for(uint8_t itr = 0; itr < bearer->pdr_count ; itr++) { if(bearer->pdrs[itr] != NULL) { if(bearer->pdrs[itr]->pdi.src_intfc.interface_value == SOURCE_INTERFACE_VALUE_CORE) { bearer->pdrs[itr]->far.actions.buff = FALSE; bearer->pdrs[itr]->far.actions.nocp = FALSE; } } } } } int8_t update_ue_context(mod_bearer_req_t *mb_req, ue_context *context, eps_bearer *bearer, pdn_connection *pdn) { int ret = 0; int ebi_index = 0; if(context != NULL ) { if(context->req_status.seq == mb_req->header.teid.has_teid.seq) { if(context->req_status.status == REQ_IN_PROGRESS) { /* Discarding re-transmitted mbr */ return GTPC_RE_TRANSMITTED_REQ; }else{ /* Restransmitted MBR but processing altready done for previous req */ context->req_status.status = REQ_IN_PROGRESS; } }else{ context->req_status.seq = mb_req->header.teid.has_teid.seq; context->req_status.status = REQ_IN_PROGRESS; } } /*extract ebi_id from array as all the ebi's will be of same pdn.*/ if(mb_req->bearer_count != 0 ) { ebi_index = GET_EBI_INDEX(mb_req->bearer_contexts_to_be_modified[0].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (!(context->bearer_bitmap & (1 << ebi_index))) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Received modify bearer on non-existent EBI - " "Dropping packet while Update UE context\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } bearer = context->eps_bearers[ebi_index]; if (!bearer) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Received modify bearer on non-existent EBI - " "Bitmap Inconsistency - Dropping packet while Update " "UE context\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } } else { for(uint8_t i = 0; i <MAX_BEARERS; i++) { bearer = context->eps_bearers[i]; if(bearer != NULL) break; } } pdn = bearer->pdn; if(pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get pdn while Update UE context\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /*Setting all the flags*/ context->second_rat_count = 0; context->uli_flag = 0; context->second_rat_flag = FALSE; context->ue_time_zone_flag = FALSE; context->rat_type_flag = FALSE; context->uci_flag = FALSE; context->serving_nw_flag = FALSE; context->ltem_rat_type_flag = FALSE; pdn->flag_fqcsid_modified = FALSE; context->sgwu_changed = FALSE; context->mme_changed_flag = FALSE; context->procedure = MODIFY_BEARER_PROCEDURE; /*Update Secondary Rat Data if Received on MBR*/ if(mb_req->second_rat_count != 0) { for(uint8_t i= 0; i < mb_req->second_rat_count; i++) { if (mb_req->secdry_rat_usage_data_rpt[i].irpgw == 1) { context->second_rat_count++; context->second_rat_flag = TRUE; context->second_rat[i].spare2 = mb_req->secdry_rat_usage_data_rpt[i].spare2; context->second_rat[i].irsgw = mb_req->secdry_rat_usage_data_rpt[i].irsgw; context->second_rat[i].irpgw = mb_req->secdry_rat_usage_data_rpt[i].irpgw; context->second_rat[i].rat_type = mb_req->secdry_rat_usage_data_rpt[i].secdry_rat_type; context->second_rat[i].eps_id = mb_req->secdry_rat_usage_data_rpt[i].ebi; context->second_rat[i].spare3 = mb_req->secdry_rat_usage_data_rpt[i].spare3; context->second_rat[i].start_timestamp = mb_req->secdry_rat_usage_data_rpt[i].start_timestamp; context->second_rat[i].end_timestamp = mb_req->secdry_rat_usage_data_rpt[i].end_timestamp; context->second_rat[i].usage_data_dl = mb_req->secdry_rat_usage_data_rpt[i].usage_data_dl; context->second_rat[i].usage_data_ul = mb_req->secdry_rat_usage_data_rpt[i].usage_data_ul; } } } if(mb_req->sender_fteid_ctl_plane.header.len) { /* Update new MME information */ if(mb_req->sender_fteid_ctl_plane.interface_type == S11_MME_GTP_C ) { if((context->s11_mme_gtpc_teid != mb_req->sender_fteid_ctl_plane.teid_gre_key) ||((context->s11_mme_gtpc_ip.ipv4_addr != mb_req->sender_fteid_ctl_plane.ipv4_address) ||(memcmp(context->s11_mme_gtpc_ip.ipv6_addr, mb_req->sender_fteid_ctl_plane.ipv6_address, IPV6_ADDRESS_LEN) != 0))) { /* Delete old MME node entry */ fqcsid_ie_node_addr_t *tmp = NULL; fqcsid_t *csid = NULL; peer_node_addr_key_t key = {0}; key.iface = S11_SGW_PORT_ID; memcpy(&(key.peer_node_addr), &(context->s11_mme_gtpc_ip), sizeof(node_address_t)); tmp = get_peer_node_addr_entry(&key, UPDATE_NODE); if (tmp != NULL) { csid = get_peer_addr_csids_entry(&tmp->fqcsid_node_addr, UPDATE_NODE); if ((csid != NULL) && (csid->num_csid == 0)) del_peer_node_addr_entry(&key); } context->s11_mme_gtpc_teid = mb_req->sender_fteid_ctl_plane.teid_gre_key; ret = fill_ip_addr(mb_req->sender_fteid_ctl_plane.ipv4_address, mb_req->sender_fteid_ctl_plane.ipv6_address, &context->s11_mme_gtpc_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } context->mme_changed_flag = TRUE; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "New MME INFO UPDATED SUCCESSFULLY", LOG_VALUE); } } else if ((context->cp_mode == PGWC) && (mb_req->sender_fteid_ctl_plane.interface_type == S5_S8_SGW_GTP_C)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Updating S5S8 SGWC FTEID" "AT PGWC in Case of SGWC Relocation\n", LOG_VALUE); /* Update SGWC information */ pdn->s5s8_sgw_gtpc_teid = mb_req->sender_fteid_ctl_plane.teid_gre_key; if (mb_req->sender_fteid_ctl_plane.v4) { pdn->s5s8_sgw_gtpc_ip.ipv4_addr = mb_req->sender_fteid_ctl_plane.ipv4_address; pdn->s5s8_sgw_gtpc_ip.ip_type |= PDN_TYPE_IPV4; } if (mb_req->sender_fteid_ctl_plane.v6) { memcpy(pdn->s5s8_sgw_gtpc_ip.ipv6_addr, mb_req->sender_fteid_ctl_plane.ipv6_address, IPV6_ADDRESS_LEN); pdn->s5s8_sgw_gtpc_ip.ip_type |= PDN_TYPE_IPV6; } } } /* Update time zone information*/ if(mb_req->ue_time_zone.header.len) { if((mb_req->ue_time_zone.time_zone != context->tz.tz) || (mb_req->ue_time_zone.daylt_svng_time != context->tz.dst)) { context->tz.tz = mb_req->ue_time_zone.time_zone; context->tz.dst = mb_req->ue_time_zone.daylt_svng_time; context->ue_time_zone_flag = TRUE; } } if(context->cp_mode == PGWC) { for(uint8_t i =0 ; i < MAX_BEARERS ; i++) { if (mb_req->bearer_contexts_to_be_modified[i].header.len != 0) { if (mb_req->bearer_contexts_to_be_modified[i].s58_u_sgw_fteid.header.len != 0) { eps_bearer *temp_bearer = NULL; for(uint8_t b_count =0 ; b_count < MAX_BEARERS ; b_count++) { temp_bearer = pdn->eps_bearers[b_count]; if(temp_bearer == NULL) continue; if(mb_req->bearer_contexts_to_be_modified[i].eps_bearer_id.ebi_ebi == temp_bearer->eps_bearer_id){ if((temp_bearer->s5s8_sgw_gtpu_ip.ipv4_addr != mb_req->bearer_contexts_to_be_modified[i].s58_u_sgw_fteid.ipv4_address || memcmp(temp_bearer->s5s8_sgw_gtpu_ip.ipv6_addr, mb_req->bearer_contexts_to_be_modified[i].s58_u_sgw_fteid.ipv6_address, IPV6_ADDRESS_LEN) != 0) || (temp_bearer->s5s8_sgw_gtpu_teid != mb_req->bearer_contexts_to_be_modified[i].s58_u_sgw_fteid.teid_gre_key)) { context->sgwu_changed = TRUE; break; } } } } } } } /*The above flag will be set bit wise as * Bit 7| Bit 6 | Bit 5 | Bit 4 | Bit 3| Bit 2| Bit 1| Bit 0 | *--------------------------------------------------------------- *| EMEI| MEI | LAI | ECGI | RAI | SAI | CGI | TAI | ---------------------------------------------------------------- */ if(mb_req->uli.header.len != 0) { check_for_uli_changes(&mb_req->uli, context); } /* Update RAT type information */ if (mb_req->rat_type.header.len != 0) { if( context->rat_type.rat_type != mb_req->rat_type.rat_type || context->rat_type.len != mb_req->rat_type.header.len){ context->rat_type.rat_type = mb_req->rat_type.rat_type; context->rat_type.len = mb_req->rat_type.header.len; context->rat_type_flag = TRUE; } } /* Update User CSG information */ if (mb_req->uci.header.len != 0) { ret = compare_uci(mb_req, context); if(ret == FALSE) { context->uci_flag = TRUE; save_uci(&mb_req->uci, context); } } /* Update serving network information */ if(mb_req->serving_network.header.len) { ret = compare_serving_network(mb_req, context); if(ret == FALSE) { context->serving_nw_flag = TRUE; save_serving_network(mb_req, context); } } /* LTE-M RAT type reporting to PGW flag */ if(mb_req->indctn_flgs.header.len) { /* LTE-M RAT type reporting to PGW flag */ if(mb_req->indctn_flgs.indication_ltempi) { context->ltem_rat_type_flag = TRUE; } /* TAU HO with Data Forwarding */ if(mb_req->indctn_flgs.indication_cfsi) { context->indication_flag.cfsi= TRUE; } } return 0; } int process_pfcp_sess_mod_req_for_saegwc_pgwc(mod_bearer_req_t *mb_req, ue_context *context) { int ebi_index = 0; int ret = 0; eps_bearer *bearer = NULL; pdn_connection *pdn = NULL; pdr_ids *pfcp_pdr_id = NULL; if(mb_req->bearer_count != 0 ) { ebi_index = GET_EBI_INDEX(mb_req->bearer_contexts_to_be_modified[0].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (!(context->bearer_bitmap & (1 << ebi_index))) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Received modify bearer on non-existent EBI - " "Dropping packet while Processing PFCP Session Modification " "Request \n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } bearer = context->eps_bearers[ebi_index]; if (!bearer) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Received modify bearer on non-existent EBI - " "Bitmap Inconsistency - Dropping packet while Processing PFCP " "Session Modification Request \n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } } else { for (uint8_t i = 0; i < MAX_BEARERS; i++) { bearer = context->eps_bearers[i]; if(bearer != NULL) break; } } pdn = bearer->pdn; pdn->proc = MODIFY_BEARER_PROCEDURE; if(context->cp_mode == SAEGWC){ /* Remove session Entry from buffered ddn request hash */ pfcp_pdr_id = delete_buff_ddn_req(pdn->seid); if(pfcp_pdr_id != NULL) { rte_free(pfcp_pdr_id); pfcp_pdr_id = NULL; } /* Delete the timer entry for UE LEVEL timer if already present */ delete_ddn_timer_entry(timer_by_teid_hash, mb_req->header.teid.has_teid.teid, ddn_by_seid_hash); /* Delete the timer entry for buffer report request messages based on dl buffer timer if present*/ delete_ddn_timer_entry(dl_timer_by_teid_hash, mb_req->header.teid.has_teid.teid, pfcp_rep_by_seid_hash); /* Remove the session from throttling timer session list */ delete_sess_in_thrtl_timer(context, pdn->seid); /* UE Level: Delay Downlink packet notification timer*/ if(mb_req->delay_dnlnk_pckt_notif_req.header.len){ if(mb_req->delay_dnlnk_pckt_notif_req.delay_value > 0){ /* Start ue level timer with the assgined delay */ /* As per spec. Delay Downlink packet notification * timer value range in between 1 - 255 and * value should be multiple of 50 */ start_ddn_timer_entry(timer_by_teid_hash, pdn->seid, (mb_req->delay_dnlnk_pckt_notif_req.delay_value * 50), ddn_timer_callback); } } } if(mb_req->sgw_fqcsid.header.len != 0) pdn->flag_fqcsid_modified = TRUE; if(context->second_rat_flag == TRUE) { uint8_t trigg_buff[] = "secondary_rat_usage"; for(uint8_t i = 0; i < context->second_rat_count; i++ ) { cdr second_rat_data = {0} ; struct timeval unix_start_time; struct timeval unix_end_time; second_rat_data.cdr_type = CDR_BY_SEC_RAT; second_rat_data.change_rat_type_flag = 1; /*rat type in sec_rat_usage_rpt is NR=0 i.e RAT is 10 as per spec 29.274*/ second_rat_data.rat_type = (mb_req->secdry_rat_usage_data_rpt[i].secdry_rat_type == 0) ? 10 : 0; second_rat_data.bearer_id = mb_req->secdry_rat_usage_data_rpt[i].ebi; second_rat_data.seid = pdn->seid; second_rat_data.imsi = pdn->context->imsi; second_rat_data.start_time = mb_req->secdry_rat_usage_data_rpt[i].start_timestamp; second_rat_data.end_time = mb_req->secdry_rat_usage_data_rpt[i].end_timestamp; second_rat_data.data_volume_uplink = mb_req->secdry_rat_usage_data_rpt[i].usage_data_ul; second_rat_data.data_volume_downlink = mb_req->secdry_rat_usage_data_rpt[i].usage_data_dl; ntp_to_unix_time(&second_rat_data.start_time, &unix_start_time); ntp_to_unix_time(&second_rat_data.end_time, &unix_end_time); second_rat_data.duration_meas = unix_end_time.tv_sec - unix_start_time.tv_sec; second_rat_data.data_start_time = 0; second_rat_data.data_end_time = 0; second_rat_data.total_data_volume = second_rat_data.data_volume_uplink + second_rat_data.data_volume_downlink; memcpy(&second_rat_data.trigg_buff, &trigg_buff, sizeof(trigg_buff)); if(generate_cdr_info(&second_rat_data) == -1) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Failed to generate " "CDR\n",LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"CDR For Secondary Rat " "is generated\n", LOG_VALUE); } } if (context->cp_mode == PGWC) { if(pdn->s5s8_sgw_gtpc_ip.ipv4_addr != mb_req->sender_fteid_ctl_plane.ipv4_address || memcmp(pdn->s5s8_sgw_gtpc_ip.ipv6_addr, mb_req->sender_fteid_ctl_plane.ipv6_address, IPV6_ADDRESS_LEN) != 0) { ret = fill_ip_addr(pdn->s5s8_sgw_gtpc_ip.ipv4_addr, pdn->s5s8_sgw_gtpc_ip.ipv6_addr, &pdn->old_sgw_addr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } pdn->old_sgw_addr_valid = TRUE; if (mb_req->sender_fteid_ctl_plane.v4) { pdn->s5s8_sgw_gtpc_ip.ipv4_addr = mb_req->sender_fteid_ctl_plane.ipv4_address; pdn->s5s8_sgw_gtpc_ip.ip_type |= PDN_TYPE_IPV4; } if (mb_req->sender_fteid_ctl_plane.v6) { memcpy(pdn->s5s8_sgw_gtpc_ip.ipv6_addr, mb_req->sender_fteid_ctl_plane.ipv6_address, IPV6_ADDRESS_LEN); pdn->s5s8_sgw_gtpc_ip.ip_type |= PDN_TYPE_IPV6; } } } /*The ULI flag set bit as * Bit 7| Bit 6 | Bit 5 | Bit 4 | Bit 3| Bit 2| Bit 1| Bit 0 | *--------------------------------------------------------------- *| | | | ECGI | RAI | SAI | CGI | TAI | ---------------------------------------------------------------- */ /* TODO something with modify_bearer_request.delay if set */ if (config.use_gx) { struct resp_info *resp = NULL; if(((context->uli_flag != FALSE) && (((context->event_trigger & (1 << ULI_EVENT_TRIGGER))) != 0)) || ((context->ue_time_zone_flag != FALSE) && (((context->event_trigger) & (1 << UE_TIMEZONE_EVT_TRIGGER)) != 0)) || ((context->rat_type_flag != FALSE) && ((context->event_trigger & (1 << RAT_EVENT_TRIGGER))) != 0)) { ret = gen_ccru_request(context, bearer, NULL, NULL); /*Retrive the session information based on session id. */ if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Session Entry " "Found for session ID:%lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } reset_resp_info_structure(resp); resp->msg_type = GX_CCR_MSG; resp->gtpc_msg.mbr = *mb_req; resp->cp_mode = context->cp_mode; return ret; } } ret = send_pfcp_sess_mod_req(pdn, bearer, mb_req); return ret; } int process_sess_mod_req_del_cmd(pdn_connection *pdn) { int ret = 0; ue_context *context = NULL; eps_bearer *bearers[MAX_BEARERS]; int ebi = 0; struct resp_info *resp = NULL; int teid = UE_SESS_ID(pdn->seid); pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; ret = get_ue_context(teid, &context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to update UE " "State for teid: %u\n", LOG_VALUE, teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "NO Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } for (uint8_t iCnt = 0; iCnt < resp->bearer_count; ++iCnt) { ebi = resp->eps_bearer_ids[iCnt]; int ebi_index = GET_EBI_INDEX(ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearers[iCnt] = context->eps_bearers[ebi_index]; } fill_pfcp_sess_mod_req_delete(&pfcp_sess_mod_req ,pdn, bearers, resp->bearer_count); uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr,SENT) < 0 ){ clLog(clSystemLog, eCLSeverityDebug,LOG_FORMAT"Error sending PFCP Session " "Modification Request for Delete Bearer Command : %i\n",LOG_VALUE, errno); } else { #ifdef CP_BUILD int ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } add_pfcp_if_timer_entry(context->s11_sgw_gtpc_teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ } /* Update UE State */ pdn->state = PFCP_SESS_MOD_REQ_SNT_STATE; /* Update the sequence number */ context->sequence = resp->gtpc_msg.del_bearer_cmd.header.teid.has_teid.seq; resp->msg_type = GTP_DELETE_BEARER_CMD; resp->state = PFCP_SESS_MOD_REQ_SNT_STATE; resp->proc = pdn->proc; return 0; } int process_modify_bearer_cmd(mod_bearer_cmd_t *mod_bearer_cmd, gtpv2c_header_t *gtpv2c_tx, ue_context *context) { eps_bearer *bearer = NULL; pdn_connection *pdn = NULL; int ebi_index = 0, ret = 0; struct resp_info *resp = NULL; if(mod_bearer_cmd->bearer_context.header.len == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"MANDATORY IE MISSING" " For Modify Bearer Command\n",LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } if(mod_bearer_cmd->apn_ambr.header.len == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"MANDATORY IE MISSING" " For Modify Bearer Command\n",LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } /*store ue initiated seq no in context.*/ context->ue_initiated_seq_no = mod_bearer_cmd->header.teid.has_teid.seq; ebi_index = GET_EBI_INDEX(mod_bearer_cmd->bearer_context.eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[ebi_index]; if(bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get bearer for ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn = bearer->pdn; if(pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get PDN for ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Session Entry Found for sess ID:%lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } reset_resp_info_structure(resp); if (mod_bearer_cmd->bearer_context.eps_bearer_id.ebi_ebi != pdn->default_bearer_id) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Incorrect Default Bearer ID " "received for Modification.\n", LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_INCORRECT; } resp->linked_eps_bearer_id = mod_bearer_cmd->bearer_context.eps_bearer_id.ebi_ebi; pdn->apn_ambr.ambr_uplink = mod_bearer_cmd->apn_ambr.apn_ambr_uplnk; pdn->apn_ambr.ambr_downlink = mod_bearer_cmd->apn_ambr.apn_ambr_dnlnk; if(SGWC == context->cp_mode) { /*forward MBC to PGWC*/ set_modify_bearer_command(mod_bearer_cmd, pdn, gtpv2c_tx); ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else if(SAEGWC == context->cp_mode || PGWC == context->cp_mode) { /*Need to compare the arp values with all the bearers*/ compare_arp_value(bearer, pdn); if(mod_bearer_cmd->bearer_context.bearer_lvl_qos.header.len != 0) { /* QCI_0; QCI value 0 is Reserved*/ if(mod_bearer_cmd->bearer_context.bearer_lvl_qos.qci != 0) bearer->qos.qci = mod_bearer_cmd->bearer_context.bearer_lvl_qos.qci; bearer->qos.ul_mbr = mod_bearer_cmd->bearer_context.bearer_lvl_qos.max_bit_rate_uplnk; bearer->qos.dl_mbr = mod_bearer_cmd->bearer_context.bearer_lvl_qos.max_bit_rate_dnlnk; bearer->qos.arp.preemption_capability = mod_bearer_cmd->bearer_context.bearer_lvl_qos.pci; /*arp values ranges from 1 to 15 */ if(mod_bearer_cmd->bearer_context.bearer_lvl_qos.pl != 0) bearer->qos.arp.priority_level = mod_bearer_cmd->bearer_context.bearer_lvl_qos.pl; bearer->qos.arp.preemption_vulnerability = mod_bearer_cmd->bearer_context.bearer_lvl_qos.pvi; } if (config.use_gx) { if(gen_ccru_request(context , bearer, NULL, mod_bearer_cmd) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"CCR-UPDATE " "Failed For HSS initiated Sub Qos Modification Flow %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } } context->sequence = mod_bearer_cmd->header.teid.has_teid.seq; pdn->state = CONNECTED_STATE; resp->msg_type = GTP_MODIFY_BEARER_CMD; resp->state = CONNECTED_STATE; resp->gtpc_msg.mod_bearer_cmd = *mod_bearer_cmd; resp->gtpc_msg.mod_bearer_cmd.header.teid.has_teid.seq = mod_bearer_cmd->header.teid.has_teid.seq; resp->proc = pdn->proc; return 0; } int process_delete_bearer_cmd_request(del_bearer_cmd_t *del_bearer_cmd, gtpv2c_header_t *gtpv2c_tx, ue_context *context) { eps_bearer *bearer = NULL; pdn_connection *pdn = NULL; int ebi_index = 0, ret = 0; struct resp_info *resp = NULL; for(uint8_t i=0; i<del_bearer_cmd->bearer_count; i++) { if(del_bearer_cmd->bearer_contexts[i].header.len == 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"MANDATORY IE MISSING" " For Delete Bearer Command\n",LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_MISSING; } } ebi_index = GET_EBI_INDEX(del_bearer_cmd->bearer_contexts[ebi_index].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[ebi_index]; pdn = bearer->pdn; if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "No Session Entry Found " "for session ID:%lu\n",LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } reset_resp_info_structure(resp); resp->bearer_count = del_bearer_cmd->bearer_count; for (uint8_t iCnt = 0; iCnt < del_bearer_cmd->bearer_count; ++iCnt) { if (del_bearer_cmd->bearer_contexts[iCnt].eps_bearer_id.ebi_ebi == pdn->default_bearer_id) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Default Bearer ID " "is received for deactivation.\n", LOG_VALUE); return GTPV2C_CAUSE_REQUEST_REJECTED; } resp->eps_bearer_ids[iCnt] = del_bearer_cmd->bearer_contexts[iCnt].eps_bearer_id.ebi_ebi; } if (SAEGWC == context->cp_mode || PGWC == context->cp_mode) { if (ccru_req_for_bear_termination(pdn, bearer)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"CCR-UPDATE " "Failed For Delete Bearer Command %s \n", LOG_VALUE, strerror(errno)); return -1; } } else if(SGWC == context->cp_mode) { set_delete_bearer_command(del_bearer_cmd, pdn, gtpv2c_tx); ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } pdn->state = CONNECTED_STATE; resp->msg_type = GTP_DELETE_BEARER_CMD; resp->state = CONNECTED_STATE; resp->gtpc_msg.del_bearer_cmd = *del_bearer_cmd; resp->gtpc_msg.del_bearer_cmd.header.teid.has_teid.seq = del_bearer_cmd->header.teid.has_teid.seq; resp->proc = pdn->proc; resp->cp_mode = context->cp_mode; return 0; } int process_bearer_rsrc_cmd(bearer_rsrc_cmd_t *bearer_rsrc_cmd, gtpv2c_header_t *gtpv2c_tx, ue_context *context) { int ret = 0; int ebi_index = 0; eps_bearer *bearer = NULL; pdn_connection *pdn = NULL; struct resp_info *resp = NULL; struct teid_value_t *teid_value = NULL; teid_key_t teid_key = {0}; /*store pti in context*/ if(context->proc_trans_id != bearer_rsrc_cmd->pti.proc_trans_id) { context->proc_trans_id = bearer_rsrc_cmd->pti.proc_trans_id; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"PTI already in used\n ", LOG_VALUE); return GTPV2C_CAUSE_MANDATORY_IE_INCORRECT; } /*store ue initiated seq no in context.*/ context->ue_initiated_seq_no = bearer_rsrc_cmd->header.teid.has_teid.seq; /*Get default bearer id i.e. lbi from BRC */ ebi_index = GET_EBI_INDEX(bearer_rsrc_cmd->lbi.ebi_ebi); if(ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /*bearer id for which bearer resource mod req in BRC is received*/ if(bearer_rsrc_cmd->eps_bearer_id.header.len != 0) { /*Check bearer is present or not for received ebi id*/ ret = check_ebi_presence_in_ue(bearer_rsrc_cmd->eps_bearer_id.ebi_ebi, context); if(ret != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI,eps bearer not found" "for ebi : %d\n", LOG_VALUE, bearer_rsrc_cmd->eps_bearer_id.ebi_ebi); return GTPV2C_CAUSE_MANDATORY_IE_INCORRECT; } ebi_index = GET_EBI_INDEX(bearer_rsrc_cmd->eps_bearer_id.ebi_ebi); } if(ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /*either use default bearer or dedicated*/ bearer = context->eps_bearers[ebi_index]; if (bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Bearer not found for ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND;; } pdn = GET_PDN(context, ebi_index); if(pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get PDN ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND;; } if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Session Entry Found for sess ID:%lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } reset_resp_info_structure(resp); if (SAEGWC == context->cp_mode || PGWC == context->cp_mode) { int ret = 0; if ((ret = gen_ccru_request(context , bearer, bearer_rsrc_cmd, NULL)) != 0) { if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure in CCR-UPDATE Failed For UE requested " "bearer resource modification flow, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } else { /*Error in TFT*/ if(ret != 0) return ret; } } } else { /*Forword BRC on S5S8 to PGWC*/ set_bearer_resource_command(bearer_rsrc_cmd, pdn, gtpv2c_tx); ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } pdn->state = CONNECTED_STATE; resp->msg_type = GTP_BEARER_RESOURCE_CMD; resp->state = CONNECTED_STATE; resp->gtpc_msg.bearer_rsrc_cmd = *bearer_rsrc_cmd; resp->gtpc_msg.bearer_rsrc_cmd.header.teid.has_teid.seq = bearer_rsrc_cmd->header.teid.has_teid.seq; resp->proc = pdn->proc; /* Store sgw s5s8 teid based on msg seq number for Error handling * if response receive to bearer resourse cmd contain wrong * teid or zero teid. * */ if (pdn->context->cp_mode == SGWC) { teid_value = rte_zmalloc_socket(NULL, sizeof(teid_value_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (teid_value == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for teid value, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /*Store TEID and msg_type*/ teid_value->teid = pdn->s5s8_sgw_gtpc_teid; teid_value->msg_type = resp->msg_type; snprintf(teid_key.teid_key, PROC_LEN, "%s%d", get_proc_string(resp->proc), bearer_rsrc_cmd->header.teid.has_teid.seq); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"teid_key.teid_key : %s\n", LOG_VALUE,teid_key.teid_key); /* Add the entry for sequence and teid value for error handling */ ret = add_seq_number_for_teid(teid_key, teid_value); if(ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "Sequence number for TEID: %u\n", LOG_VALUE, teid_value->teid); rte_free(teid_value); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } return 0; } uint32_t get_far_id(eps_bearer *bearer, int interface_value){ pdr_t *pdr_ctxt = NULL; for(uint8_t itr = 0; itr < bearer->pdr_count ; itr++) { if(bearer->pdrs[itr]->pdi.src_intfc.interface_value != interface_value){ pdr_ctxt = bearer->pdrs[itr]; /* Update destination interface into create far */ pdr_ctxt->far.dst_intfc.interface_value = interface_value; return pdr_ctxt->far.far_id_value; } } return 0; } int process_pfcp_sess_mod_request(mod_bearer_req_t *mb_req, ue_context *context) { int ebi_index = 0, ret = 0; uint8_t send_endmarker = 0; eps_bearer *bearer = NULL; eps_bearer *bearers[MAX_BEARERS] ={NULL}; pdn_connection *pdn = NULL; struct resp_info *resp = NULL; pdr_ids *pfcp_pdr_id = NULL; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; pfcp_update_far_ie_t update_far[MAX_LIST_SIZE] = {0}; pfcp_sess_mod_req.update_far_count = 0; for(uint8_t i = 0; i < mb_req->bearer_count; i++) { if ( (!mb_req->bearer_contexts_to_be_modified[i].eps_bearer_id.header.len) || ( !mb_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.header.len && !mb_req->bearer_contexts_to_be_modified[i].s11_u_mme_fteid.header.len)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Bearer Context not " "found for Modify Bearer Request, Dropping packet\n", LOG_VALUE); return GTPV2C_CAUSE_INVALID_LENGTH; } ebi_index = GET_EBI_INDEX(mb_req->bearer_contexts_to_be_modified[i].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (!(context->bearer_bitmap & (1 << ebi_index))) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Received modify bearer on non-existent EBI - " "for while PFCP Session Modification Request Modify Bearer " "Request, Dropping packet\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } bearer = context->eps_bearers[ebi_index]; if (!bearer) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Received modify bearer on non-existent EBI - " "for while PFCP Session Modification Request Modify Bearer " "Request, Dropping packet\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if((mb_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.v6 && bearer->s1u_sgw_gtpu_ip.ip_type == PDN_TYPE_IPV4) || (mb_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.v4 && bearer->s1u_sgw_gtpu_ip.ip_type == PDN_TYPE_IPV6)){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"The EnodeB s1u IP not compatible with SGW/SAEGW s1u IP\n", LOG_VALUE); return GTPV2C_CAUSE_REQUEST_REJECTED; } pdn = bearer->pdn; pdn->proc = MODIFY_BEARER_PROCEDURE; /* Remove session Entry from buffered ddn request hash */ pfcp_pdr_id = delete_buff_ddn_req(pdn->seid); if(pfcp_pdr_id != NULL) { rte_free(pfcp_pdr_id); pfcp_pdr_id = NULL; } /* Delete the timer entry for UE LEVEL timer if already present */ delete_ddn_timer_entry(timer_by_teid_hash, mb_req->header.teid.has_teid.teid, ddn_by_seid_hash); /* Delete the timer entry for buffer report request messages based on dl buffer timer if present*/ delete_ddn_timer_entry(dl_timer_by_teid_hash, mb_req->header.teid.has_teid.teid, pfcp_rep_by_seid_hash); /* Remove the session from throttling timer */ delete_sess_in_thrtl_timer(context, pdn->seid); /* UE Level: Delay Downlink packet notification timer */ if(mb_req->delay_dnlnk_pckt_notif_req.header.len){ if(mb_req->delay_dnlnk_pckt_notif_req.delay_value > 0){ /* Start ue level timer with the assgined delay */ /* As per spec. Delay Downlink packet notification * timer value range in between 1 - 255 and * value should be multiple of 50 */ start_ddn_timer_entry(timer_by_teid_hash, pdn->seid, (mb_req->delay_dnlnk_pckt_notif_req.delay_value * 50), ddn_timer_callback); } } if(pdn->state == IDEL_STATE) { update_pdr_actions_flags(bearer); } if(mb_req->indctn_flgs.indication_s11tf) { /* Set the indication flag for s11-u teid */ context->indication_flag.s11tf = 1; /* Set if MME sends MO Exception Data Counter */ if(mb_req->mo_exception_data_cntr.header.len){ context->mo_exception_flag = True; if(mb_req->mo_exception_data_cntr.counter_value == 1) context->mo_exception_data_counter.timestamp_value = mb_req->mo_exception_data_cntr.timestamp_value; context->mo_exception_data_counter.counter_value = mb_req->mo_exception_data_cntr.counter_value; } ret = fill_ip_addr(mb_req->bearer_contexts_to_be_modified[i].s11_u_mme_fteid.ipv4_address, mb_req->bearer_contexts_to_be_modified[i].s11_u_mme_fteid.ipv6_address, &bearer->s11u_mme_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s11u_mme_gtpu_teid = mb_req->bearer_contexts_to_be_modified[i].s11_u_mme_fteid.teid_gre_key; update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.teid = bearer->s11u_mme_gtpu_teid; ret = set_node_address(&update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv6_address, bearer->s11u_mme_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value = check_interface_type(mb_req->bearer_contexts_to_be_modified[i].s11_u_mme_fteid.interface_type, context->cp_mode); update_far[pfcp_sess_mod_req.update_far_count].far_id.far_id_value = get_far_id(bearer, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value); update_far[pfcp_sess_mod_req.update_far_count].apply_action.forw = PRESENT; update_far[pfcp_sess_mod_req.update_far_count].apply_action.dupl = GET_DUP_STATUS(pdn->context); pfcp_sess_mod_req.update_far_count++; } if (mb_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.header.len != 0) { /* In case Establishment of S1-U bearer during Data * Transport in Control Plane CIoT EPS Optimisation * handling a corner case * */ context->indication_flag.s11tf = 0; /*NOTE: IDEL STATE means bearer is in Suspend State, so no need to send Send Endmarker */ if((bearer->s1u_enb_gtpu_ip.ipv4_addr != 0 || *bearer->s1u_enb_gtpu_ip.ipv6_addr) && (bearer->s1u_enb_gtpu_teid != 0)) { if((mb_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.teid_gre_key != bearer->s1u_enb_gtpu_teid) || (mb_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.ipv4_address != bearer->s1u_enb_gtpu_ip.ipv4_addr) || (memcmp(mb_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.ipv6_address, bearer->s1u_enb_gtpu_ip.ipv6_addr, IPV6_ADDRESS_LEN) != 0)) { send_endmarker = TRUE; } } ret = fill_ip_addr(mb_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.ipv4_address, mb_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.ipv6_address, &bearer->s1u_enb_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s1u_enb_gtpu_teid = mb_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.teid_gre_key; update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.teid = bearer->s1u_enb_gtpu_teid; ret = set_node_address(&update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv6_address, bearer->s1u_enb_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value = check_interface_type(mb_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.interface_type, context->cp_mode); update_far[pfcp_sess_mod_req.update_far_count].far_id.far_id_value = get_far_id(bearer, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value); update_far[pfcp_sess_mod_req.update_far_count].apply_action.forw = PRESENT; update_far[pfcp_sess_mod_req.update_far_count].apply_action.dupl = GET_DUP_STATUS(pdn->context); pfcp_sess_mod_req.update_far_count++; } if (mb_req->bearer_contexts_to_be_modified[i].s58_u_sgw_fteid.header.len != 0){ ret = fill_ip_addr(mb_req->bearer_contexts_to_be_modified[i].s58_u_sgw_fteid.ipv4_address, mb_req->bearer_contexts_to_be_modified[i].s58_u_sgw_fteid.ipv6_address, &bearer->s5s8_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s5s8_sgw_gtpu_teid = mb_req->bearer_contexts_to_be_modified[i].s58_u_sgw_fteid.teid_gre_key; update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.teid = bearer->s5s8_sgw_gtpu_teid; ret = set_node_address(&update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv6_address, bearer->s5s8_sgw_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value = check_interface_type(mb_req->bearer_contexts_to_be_modified[i].s58_u_sgw_fteid.interface_type, context->cp_mode); update_far[pfcp_sess_mod_req.update_far_count].far_id.far_id_value = get_far_id(bearer, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value); if ( context->cp_mode != PGWC) { update_far[pfcp_sess_mod_req.update_far_count].apply_action.forw = PRESENT; update_far[pfcp_sess_mod_req.update_far_count].apply_action.dupl= GET_DUP_STATUS(pdn->context); } pfcp_sess_mod_req.update_far_count++; } bearers[i] = bearer; } /* forloop */ if(pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get PDN ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[ebi_index]; pdn = bearer->pdn; fill_pfcp_sess_mod_req(&pfcp_sess_mod_req, &mb_req->header, bearers, pdn, update_far, send_endmarker, mb_req->bearer_count, context); /* Adding the secondary rat usage report to the CDR Entry when it it a E RAB * MODIFICATION */ if(mb_req->second_rat_count != 0) { uint8_t trigg_buff[] = "secondary_rat_usage"; for(uint8_t i =0; i< mb_req->second_rat_count; i++) { if(mb_req->secdry_rat_usage_data_rpt[i].irsgw == 1) { cdr second_rat_data = {0}; struct timeval unix_start_time; struct timeval unix_end_time; second_rat_data.cdr_type = CDR_BY_SEC_RAT; second_rat_data.change_rat_type_flag = 1; /*rat type in sec_rat_usage_rpt is NR=0 i.e RAT is 10 as per spec 29.274*/ second_rat_data.rat_type = (mb_req->secdry_rat_usage_data_rpt[i].secdry_rat_type == 0) ? 10 : 0; second_rat_data.bearer_id = mb_req->secdry_rat_usage_data_rpt[i].ebi; second_rat_data.seid = pdn->seid; second_rat_data.imsi = pdn->context->imsi; second_rat_data.start_time = mb_req->secdry_rat_usage_data_rpt[i].start_timestamp; second_rat_data.end_time = mb_req->secdry_rat_usage_data_rpt[i].end_timestamp; second_rat_data.data_volume_uplink = mb_req->secdry_rat_usage_data_rpt[i].usage_data_ul; second_rat_data.data_volume_downlink = mb_req->secdry_rat_usage_data_rpt[i].usage_data_dl; ntp_to_unix_time(&second_rat_data.start_time, &unix_start_time); ntp_to_unix_time(&second_rat_data.end_time, &unix_end_time); second_rat_data.duration_meas = unix_end_time.tv_sec - unix_start_time.tv_sec; second_rat_data.data_start_time = 0; second_rat_data.data_end_time = 0; second_rat_data.total_data_volume = second_rat_data.data_volume_uplink + second_rat_data.data_volume_downlink; memcpy(&second_rat_data.trigg_buff, &trigg_buff, sizeof(trigg_buff)); if(generate_cdr_info(&second_rat_data) == -1) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Failed to generate " "CDR\n",LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } } } #ifdef USE_CSID /* Generate the permant CSID for SGW */ if (context->cp_mode != PGWC) { /* Get the copy of existing SGW CSID */ fqcsid_t tmp_csid_t = {0}; if (pdn->sgw_csid.num_csid) { memcpy(&tmp_csid_t, &pdn->sgw_csid, sizeof(fqcsid_t)); } /* Checking for mme relocation flag */ if (context->mme_changed_flag == TRUE) { if((mb_req->mme_fqcsid.header.len != 0) && ((mb_req->mme_fqcsid).number_of_csids)) { if ((context->mme_fqcsid == NULL)) { context->mme_fqcsid = rte_zmalloc_socket(NULL, sizeof(sess_fqcsid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (context->mme_fqcsid == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the " "memory for fqcsids entry\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } uint8_t num_csid = 0; fqcsid_t mme_old_fqcsid = {0}; if(pdn->mme_csid.num_csid) { /* Coping Exsiting MME CSID associted with Session */ memcpy(&mme_old_fqcsid, &pdn->mme_csid, sizeof(fqcsid_t)); } int ret = add_peer_addr_entry_for_fqcsid_ie_node_addr( &context->s11_mme_gtpc_ip, &mb_req->mme_fqcsid, S11_SGW_PORT_ID); if (ret) return ret; /* Parse and stored MME FQ-CSID in the context */ ret = add_fqcsid_entry(&mb_req->mme_fqcsid, context->mme_fqcsid); if(ret) return ret; fill_pdn_fqcsid_info(&pdn->mme_csid, context->mme_fqcsid); if (link_sess_with_peer_csid(&pdn->mme_csid, pdn, S11_SGW_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Failed to Link " "Session with MME CSID \n", LOG_VALUE); return -1; } /* Remove old mme csid */ remove_csid_from_cntx(context->mme_fqcsid, &mme_old_fqcsid); /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; peer_csid_key_t key = {0}; key.iface = S11_SGW_PORT_ID; key.peer_local_csid = mme_old_fqcsid.local_csid[num_csid]; memcpy(&(key.peer_node_addr), &(mme_old_fqcsid.node_addr), sizeof(node_address_t)); tmp1 = get_sess_peer_csid_entry(&key, REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seid_by_peer_csid_hash, &key, tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry" " for CSID = %u \n", LOG_VALUE, mme_old_fqcsid.local_csid[num_csid]); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Delete Local CSID entry */ del_sess_peer_csid_entry(&key); } } /* Cleanup Internal data structures */ ret = del_csid_entry_hash(&mme_old_fqcsid, &pdn->sgw_csid, S11_SGW_PORT_ID); if (ret) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to delete CSID " "Entry from hash while cleanup session \n", LOG_VALUE); } if (pdn->mme_csid.num_csid) set_fq_csid_t(&pfcp_sess_mod_req.mme_fqcsid, &pdn->mme_csid); } } /* Update the entry for peer nodes */ if (fill_peer_node_info(pdn, bearer)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to fill peer node info and assignment of the " "CSID Error: %s\n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (pdn->flag_fqcsid_modified == TRUE) { uint8_t tmp_csid = 0; /* Validate the exsiting CSID or allocated new one */ for (uint8_t inx1 = 0; inx1 < tmp_csid_t.num_csid; inx1++) { if ((context->sgw_fqcsid)->local_csid[(context->sgw_fqcsid)->num_csid - 1] == tmp_csid_t.local_csid[inx1]) { tmp_csid = tmp_csid_t.local_csid[inx1]; break; } } if (!tmp_csid) { for (uint8_t inx = 0; inx < tmp_csid_t.num_csid; inx++) { /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; tmp1 = get_sess_csid_entry(tmp_csid_t.local_csid[inx], REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seids_by_csid_hash, &tmp_csid_t.local_csid[inx], tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry for CSID = %u" "\n\tError= %s\n", LOG_VALUE, tmp_csid_t.local_csid[inx], rte_strerror(abs(ret))); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Removing temporary local CSID associated with MME */ remove_peer_temp_csid(&pdn->mme_csid, tmp_csid_t.local_csid[inx], S11_SGW_PORT_ID); /* Removing temporary local CSID assocoated with PGWC */ remove_peer_temp_csid(&pdn->pgw_csid, tmp_csid_t.local_csid[inx], S5S8_SGWC_PORT_ID); /* Delete Local CSID entry */ del_sess_csid_entry(tmp_csid_t.local_csid[inx]); } /* Delete CSID from the context */ remove_csid_from_cntx(context->sgw_fqcsid, &tmp_csid_t); del_local_csid(&(context->s11_sgw_gtpc_ip), &tmp_csid_t); } else { sess_csid *tmp1 = NULL; tmp1 = get_sess_csid_entry(tmp_csid_t.local_csid[inx], REMOVE_NODE); if (tmp1 == NULL) { /* Removing temporary local CSID associated with MME */ remove_peer_temp_csid(&pdn->mme_csid, tmp_csid_t.local_csid[inx], S11_SGW_PORT_ID); /* Removing temporary local CSID assocoated with PGWC */ remove_peer_temp_csid(&pdn->pgw_csid, tmp_csid_t.local_csid[inx], S5S8_SGWC_PORT_ID); /* Delete Local CSID entry */ del_sess_csid_entry(tmp_csid_t.local_csid[inx]); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to " "get Session ID entry for CSID:%u\n", LOG_VALUE, tmp_csid_t.local_csid[inx]); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Remove session link from Old CSID:%u\n", LOG_VALUE, tmp_csid_t.local_csid[inx]); } } /* update entry for cp session id with link local csid */ sess_csid *tmp = NULL; tmp = get_sess_csid_entry( pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1], ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get session of CSID entry %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Link local csid with session id */ /* Check head node created ot not */ if(tmp->cp_seid != pdn->seid && tmp->cp_seid != 0) { sess_csid *new_node = NULL; /* Add new node into csid linked list */ new_node = add_sess_csid_data_node(tmp, pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1]); if(new_node == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "ADD new node into CSID linked list : %s\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } else { new_node->cp_seid = pdn->seid; new_node->up_seid = pdn->dp_seid; } } else { tmp->cp_seid = pdn->seid; tmp->up_seid = pdn->dp_seid; tmp->next = NULL; } /* Fill the fqcsid into the session est request */ if (fill_fqcsid_sess_mod_req(&pfcp_sess_mod_req, pdn)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to fill " "FQ-CSID in Session Establishment Request, " "Error: %s\n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } } } #endif /* USE_CSID */ uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr,SENT) < 0 ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in sending PFCP " "Session Modification Request for Modify Bearer Request %i\n", LOG_VALUE, errno); } else { #ifdef CP_BUILD add_pfcp_if_timer_entry(mb_req->header.teid.has_teid.teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ } /* Update the Sequence number for the request */ context->sequence = mb_req->header.teid.has_teid.seq; /* Update UE State */ pdn->state = PFCP_SESS_MOD_REQ_SNT_STATE; /*Retrive the session information based on session id. */ if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } reset_resp_info_structure(resp); /* Set create session response */ resp->linked_eps_bearer_id = pdn->default_bearer_id; resp->msg_type = GTP_MODIFY_BEARER_REQ; resp->state = PFCP_SESS_MOD_REQ_SNT_STATE; resp->proc = pdn->proc; resp->cp_mode = context->cp_mode; memcpy(&resp->gtpc_msg.mbr, mb_req, sizeof(mod_bearer_req_t)); return 0; } int proc_pfcp_sess_mbr_udp_csid_req(upd_pdn_conn_set_req_t *upd_req) { int ret = 0; ue_context *context = NULL; eps_bearer *bearers[MAX_BEARERS], *bearer = NULL; pdn_connection *pdn = NULL; struct resp_info *resp = NULL; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; ret = rte_hash_lookup_data(ue_context_by_fteid_hash, (const void *) &upd_req->header.teid.has_teid.teid, (void **) &context); if (ret < 0 || !context) return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; if(upd_req->sgw_fqcsid.header.len == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"SGWC FQCSID IS " "MISSING\n", LOG_VALUE); return GTPV2C_CAUSE_CONDITIONAL_IE_MISSING; } for(uint8_t i = 0; i< MAX_BEARERS; i++) { bearer = context->eps_bearers[i]; if(bearer == NULL) continue; else break; } if (bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NULL Bearer found while " "Update PDN Connection Set Request\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn = bearer->pdn; if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NULL PDN found while " "Update PDN Connection Set Request\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } bearers[0] = bearer; fill_pfcp_sess_mod_req(&pfcp_sess_mod_req, &upd_req->header, bearers, pdn, NULL, 0, 1, context); #ifdef USE_CSID uint8_t num_csid = 0; if (upd_req->mme_fqcsid.header.len) { if (upd_req->mme_fqcsid.number_of_csids) { fqcsid_t tmp_fqcsid = {0}; if (pdn->mme_csid.num_csid) { /* Coping Exsiting MME CSID associted with Session */ memcpy(&tmp_fqcsid, &pdn->mme_csid, sizeof(fqcsid_t)); } /* Parse and stored MME FQ-CSID in the context */ int ret = add_fqcsid_entry(&upd_req->mme_fqcsid, context->mme_fqcsid); if(ret) return ret; fill_pdn_fqcsid_info(&pdn->mme_csid, context->mme_fqcsid); /* Remove old mme csid */ remove_csid_from_cntx(context->mme_fqcsid, &tmp_fqcsid); if (link_sess_with_peer_csid(&pdn->mme_csid, pdn, S5S8_PGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Failed to Link " "Session with MME CSID \n", LOG_VALUE); return -1; } /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; peer_csid_key_t key = {0}; key.iface = S5S8_PGWC_PORT_ID; key.peer_local_csid = tmp_fqcsid.local_csid[num_csid]; memcpy(&key.peer_node_addr, &tmp_fqcsid.node_addr, sizeof(node_address_t)); tmp1 = get_sess_peer_csid_entry(&key, REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seid_by_peer_csid_hash, &key, tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry" " for CSID = %u \n", LOG_VALUE, tmp_fqcsid.local_csid[num_csid]); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Delete Local CSID entry */ del_sess_peer_csid_entry(&key); } } /* Cleanup Internal data structures */ ret = del_csid_entry_hash(&tmp_fqcsid, &pdn->pgw_csid, S5S8_PGWC_PORT_ID); if (ret) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to delete CSID " "Entry from hash while cleanup session \n", LOG_VALUE); } } } /* SGW FQ-CSID */ if (upd_req->sgw_fqcsid.header.len) { if (upd_req->sgw_fqcsid.number_of_csids) { pdn->flag_fqcsid_modified = FALSE; int ret_t = 0; /* Get the copy of existing SGW CSID */ fqcsid_t sgw_tmp_csid_t = {0}; /* Parse and stored MME and SGW FQ-CSID in the context */ ret_t = gtpc_recvd_sgw_fqcsid(&upd_req->sgw_fqcsid, pdn, bearer, context); if ((ret_t != 0) && (ret_t != PRESENT)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed Link peer CSID\n", LOG_VALUE); return ret_t; } /* Fill the Updated CSID in the Modification Request */ /* Set SGW FQ-CSID */ if (ret_t != PRESENT && context->sgw_fqcsid != NULL) { if (pdn->sgw_csid.num_csid) { memcpy(&sgw_tmp_csid_t, &pdn->sgw_csid, sizeof(fqcsid_t)); } fill_pdn_fqcsid_info(&pdn->sgw_csid, context->sgw_fqcsid); if ((pdn->sgw_csid.num_csid) && (pdn->flag_fqcsid_modified != TRUE)) { if (link_gtpc_peer_csids(&pdn->sgw_csid, &pdn->pgw_csid, S5S8_PGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Link " "Local CSID entry to link with SGW FQCSID, Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } } if (link_sess_with_peer_csid(&pdn->sgw_csid, pdn, S5S8_PGWC_PORT_ID)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error : Failed to Link " "Session with SGWC CSID \n", LOG_VALUE); return -1; } /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; peer_csid_key_t key = {0}; key.iface = S5S8_PGWC_PORT_ID; key.peer_local_csid = sgw_tmp_csid_t.local_csid[num_csid]; memcpy(&key.peer_node_addr, &sgw_tmp_csid_t.node_addr, sizeof(node_address_t)); tmp1 = get_sess_peer_csid_entry(&key, REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seid_by_peer_csid_hash, &key, tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry" " for CSID = %u \n", LOG_VALUE, sgw_tmp_csid_t.local_csid[num_csid]); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Delete Local CSID entry */ del_sess_peer_csid_entry(&key); } } if (pdn->sgw_csid.num_csid) { set_fq_csid_t(&pfcp_sess_mod_req.sgw_c_fqcsid, &pdn->sgw_csid); /* set PGWC FQ-CSID */ set_fq_csid_t(&pfcp_sess_mod_req.pgw_c_fqcsid, &pdn->pgw_csid); if ((upd_req->mme_fqcsid).number_of_csids) set_fq_csid_t(&pfcp_sess_mod_req.mme_fqcsid, &pdn->mme_csid); } } if (ret_t == PRESENT) { /* set PGWC FQ-CSID */ set_fq_csid_t(&pfcp_sess_mod_req.pgw_c_fqcsid, &pdn->pgw_csid); } } } #endif /* USE_CSID */ uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); ret = set_dest_address(pdn->upf_ip, &upf_pfcp_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr, SENT) < 0 ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in sending " "Update PDN Connection Set Request, Error : %s\n", LOG_VALUE, strerror(errno)); } /* Update the Sequence number for the request */ context->sequence = upd_req->header.teid.has_teid.seq; /* Update UE State */ pdn->state = PFCP_SESS_MOD_REQ_SNT_STATE; pdn->proc = UPDATE_PDN_CONNECTION_PROC; /*Retrive the session information based on session id. */ if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session Entry Found " "for session ID:%lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } reset_resp_info_structure(resp); /* Set create session response */ resp->linked_eps_bearer_id = pdn->default_bearer_id; resp->msg_type = GTP_MODIFY_BEARER_REQ; resp->state = PFCP_SESS_MOD_REQ_SNT_STATE; resp->proc = pdn->proc; resp->gtpc_msg.upd_req = *upd_req; return 0; } rar_funtions rar_process(pdn_connection *pdn, uint8_t proc){ rar_funtions function = NULL; if(proc == DED_BER_ACTIVATION_PROC) { pdn->policy.num_charg_rule_install = 0; function = &gen_reauth_response; } else if(proc == PDN_GW_INIT_BEARER_DEACTIVATION) { pdn->policy.num_charg_rule_delete = 0; function = &gen_reauth_response; } else if(proc == UPDATE_BEARER_PROC){ pdn->policy.num_charg_rule_modify = 0; function = &gen_reauth_response; } /* Keep the same order for function call * else we will face problem in case of * when qci/arp of a rule get changes and we have to * delete that rule from one bearer and add the rule to * another bearer */ if(pdn->policy.num_charg_rule_delete) { function = &gx_delete_bearer_req; } else if(pdn->policy.num_charg_rule_modify) { function = &gx_update_bearer_req; } else if(pdn->policy.num_charg_rule_install){ function = &gx_create_bearer_req; } return function; } int gen_reauth_response(pdn_connection *pdn) { /* VS: Initialize the Gx Parameters */ uint16_t msg_len = 0; uint8_t *buffer = NULL; gx_msg raa = {0}; gx_context_t *gx_context = NULL; uint16_t msg_type_ofs = 0; uint16_t msg_body_ofs = 0; uint16_t rqst_ptr_ofs = 0; uint16_t msg_len_total = 0; if ((gx_context_entry_lookup(pdn->gx_sess_id, &gx_context)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "gx context not found for sess id %s\n", LOG_VALUE, pdn->gx_sess_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } raa.data.cp_raa.session_id.len = strnlen(pdn->gx_sess_id,MAX_LEN); memcpy(raa.data.cp_raa.session_id.val, pdn->gx_sess_id, raa.data.cp_raa.session_id.len); raa.data.cp_raa.presence.session_id = PRESENT; /* VS: Set the Msg header type for CCR */ raa.msg_type = GX_RAA_MSG; /* Result code */ raa.data.cp_raa.result_code = 2001; raa.data.cp_raa.presence.result_code = PRESENT; /* Update UE State */ pdn->state = RE_AUTH_ANS_SNT_STATE; /* Set the Gx State for events */ gx_context->state = RE_AUTH_ANS_SNT_STATE; /* VS: Calculate the max size of CCR msg to allocate the buffer */ msg_len = gx_raa_calc_length(&raa.data.cp_raa); msg_body_ofs = GX_HEADER_LEN; rqst_ptr_ofs = msg_len + msg_body_ofs; msg_len_total = rqst_ptr_ofs + sizeof(pdn->rqst_ptr); raa.msg_len = msg_len_total; buffer = rte_zmalloc_socket(NULL, msg_len_total, RTE_CACHE_LINE_SIZE, rte_socket_id()); if (buffer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for buffer while generating RAA, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return -1; } memcpy(buffer + msg_type_ofs, &raa.msg_type, sizeof(raa.msg_type)); memcpy(buffer + sizeof(raa.msg_type), &raa.msg_len, sizeof(raa.msg_len)); if (gx_raa_pack(&(raa.data.cp_raa), (unsigned char *)(buffer + msg_body_ofs), msg_len) == 0 ) { clLog(clSystemLog, eCLSeverityDebug,LOG_FORMAT"Error while Packing RAA\n", LOG_VALUE); rte_free(buffer); return -1; } //memcpy((unsigned char *)(buffer + sizeof(raa.msg_type) + msg_len), &(context->eps_bearers[1]->rqst_ptr), memcpy((unsigned char *)(buffer + rqst_ptr_ofs), &(pdn->rqst_ptr), sizeof(pdn->rqst_ptr)); send_to_ipc_channel(gx_app_sock, buffer, msg_len_total); //msg_len + sizeof(raa.msg_type) + sizeof(unsigned long)); update_cli_stats((peer_address_t *) &config.gx_ip, OSS_RAA, SENT, GX); rte_free(buffer); pdn->state = CONNECTED_STATE; gx_context->state = CONNECTED_STATE; pdn->policy.count = 0; return 0; } uint8_t process_delete_bearer_pfcp_sess_response(uint64_t sess_id, ue_context *context, gtpv2c_header_t *gtpv2c_tx, struct resp_info *resp) { pdn_connection *pdn = NULL; int ebi = UE_BEAR_ID(sess_id), ret = 0; int ebi_index = GET_EBI_INDEX(ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } resp->state = PFCP_SESS_MOD_RESP_RCVD_STATE; pdn = GET_PDN(context, ebi_index); if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get PDN for " "ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn->state = PFCP_SESS_MOD_RESP_RCVD_STATE; if (resp->msg_type == GX_RAR_MSG || resp->msg_type == GTP_DELETE_BEARER_CMD || resp->msg_type == GTP_DELETE_BEARER_REQ || resp->msg_type == GTP_BEARER_RESOURCE_CMD) { uint8_t lbi = 0; uint8_t bearer_count = 0; uint8_t eps_bearer_ids[MAX_BEARERS]; if(resp->msg_type == GX_RAR_MSG || resp->msg_type == GTP_BEARER_RESOURCE_CMD) { get_charging_rule_remove_bearer_info(pdn, &lbi,eps_bearer_ids, &bearer_count); } else { lbi = resp->linked_eps_bearer_id; bearer_count = resp->bearer_count; memcpy(eps_bearer_ids, resp->eps_bearer_ids, MAX_BEARERS); } uint8_t pti = 0; uint32_t seq_no = 0; /*If proc is BRC then use same seq no as received in BRC msg*/ if ((SGWC == pdn->context->cp_mode) && (pdn->proc == PDN_GW_INIT_BEARER_DEACTIVATION)) { seq_no = generate_seq_number(); } else if (pdn->proc == UE_REQ_BER_RSRC_MOD_PROC) { pti = context->proc_trans_id; seq_no = context->ue_initiated_seq_no; } else { seq_no = context->sequence; } set_delete_bearer_request(gtpv2c_tx, seq_no, pdn, lbi, pti, eps_bearer_ids, bearer_count); resp->state = DELETE_BER_REQ_SNT_STATE; pdn->state = DELETE_BER_REQ_SNT_STATE; if( PGWC == context->cp_mode ) { ret = set_dest_address(pdn->s5s8_sgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else { ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } /* Reset the PTI Value */ context->proc_trans_id = 0; } else if (resp->msg_type == GTP_DELETE_BEARER_RSP) { if ((SAEGWC == context->cp_mode) || (PGWC == context->cp_mode)) { int ret = 0; if (resp->proc == PDN_GW_INIT_BEARER_DEACTIVATION) { if (context->mbc_cleanup_status == PRESENT) { uint16_t msglen = 0; uint8_t *buffer = NULL; gx_msg ccr_request = {0}; set_ccr_t_message(pdn, context, (gx_msg *)&ccr_request, ebi_index); /* Calculate the max size of CCR msg to allocate the buffer */ msglen = gx_ccr_calc_length(&ccr_request.data.ccr); ccr_request.msg_len = msglen + GX_HEADER_LEN; if (config.use_gx) { buffer = rte_zmalloc_socket(NULL, msglen + GX_HEADER_LEN, RTE_CACHE_LINE_SIZE, rte_socket_id()); if (buffer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "Memory for Buffer, Error: %s \n", LOG_VALUE, rte_strerror(rte_errno)); return -1; } memcpy(buffer, &ccr_request.msg_type, sizeof(ccr_request.msg_type)); memcpy(buffer + sizeof(ccr_request.msg_type), &ccr_request.msg_len, sizeof(ccr_request.msg_len)); if (gx_ccr_pack(&(ccr_request.data.ccr), (unsigned char *)(buffer + GX_HEADER_LEN), msglen) == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to Packing " "CCR Buffer\n", LOG_VALUE); rte_free(buffer); return -1; } /* Write or Send CCR -T msg to Gx_App */ send_to_ipc_channel(gx_app_sock, buffer, msglen + GX_HEADER_LEN); if (buffer != NULL) { rte_free(buffer); buffer = NULL; } free_dynamically_alloc_memory(&ccr_request); update_cli_stats((peer_address_t *) &config.gx_ip, OSS_CCR_TERMINATE, SENT, GX); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"send CCR-TERMINATION for " "MBC for cleanup\n", LOG_VALUE); resp->msg_type = GX_CCR_MSG; } else { delete_dedicated_bearers(pdn, resp->eps_bearer_ids, resp->bearer_count); rar_funtions rar_function = NULL; rar_function = rar_process(pdn, pdn->proc); if(rar_function != NULL){ ret = rar_function(pdn); if(ret) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed in processing " "RAR function\n", LOG_VALUE); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"None of the RAR function " "returned\n", LOG_VALUE); } resp->msg_type = GX_RAA_MSG; resp->proc = pdn->proc; } } else if (resp->proc == MME_INI_DEDICATED_BEARER_DEACTIVATION_PROC) { /*extract ebi_id from array as all the ebi's will be of same pdn.*/ int ebi_index = GET_EBI_INDEX(resp->eps_bearer_ids[0]); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } provision_ack_ccr(pdn, (context->eps_bearers[ebi_index]), RULE_ACTION_DELETE,NO_FAIL); delete_dedicated_bearers(pdn, resp->eps_bearer_ids, resp->bearer_count); resp->msg_type = GX_CCR_MSG; } else { if( resp->proc == UE_REQ_BER_RSRC_MOD_PROC) { int ebi_index = GET_EBI_INDEX(resp->eps_bearer_ids[0]); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } pdn->proc = resp->proc; provision_ack_ccr(pdn, context->eps_bearers[ebi_index], RULE_ACTION_DELETE,NO_FAIL); } delete_dedicated_bearers(pdn, resp->eps_bearer_ids, resp->bearer_count); resp->msg_type = GX_CCR_MSG; } resp->state = pdn->state; if (context->cp_mode != PGWC) { ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } return 0; } else { int ebi_index = -1; uint32_t sequence = 0; /* Get seuence number from bearer*/ if (resp->linked_eps_bearer_id > 0) { ebi_index = GET_EBI_INDEX(resp->linked_eps_bearer_id); }else{ for(int itr = 0; itr < resp->bearer_count; itr++){ ebi_index = GET_EBI_INDEX(resp->eps_bearer_ids[itr]); if (ebi_index != -1){ break; } } } if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; }else{ sequence = context->eps_bearers[ebi_index]->sequence; } set_delete_bearer_response(gtpv2c_tx, sequence, resp->linked_eps_bearer_id, resp->eps_bearer_ids, resp->bearer_count, pdn->s5s8_pgw_gtpc_teid); delete_dedicated_bearers(pdn, resp->eps_bearer_ids, resp->bearer_count); resp->state = CONNECTED_STATE; pdn->state = CONNECTED_STATE; if (context->cp_mode == PGWC) ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } } return 0; } uint8_t process_pfcp_sess_upd_mod_resp(pfcp_sess_mod_rsp_t *pfcp_sess_mod_rsp) { int ret = 0; int ebi_index = 0; eps_bearer *bearer = NULL; ue_context *context = NULL; pdn_connection *pdn = NULL; struct resp_info *resp = NULL; uint64_t sess_id = pfcp_sess_mod_rsp->header.seid_seqno.has_seid.seid; uint32_t teid = UE_SESS_ID(sess_id); /* Retrive the session information based on session id. */ if (get_sess_entry(sess_id, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, sess_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Update the session state */ resp->state = PFCP_SESS_MOD_RESP_RCVD_STATE; /* Retrieve the UE context */ ret = get_ue_context(teid, &context); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get UE context " "for teid: %u\n", LOG_VALUE, teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } int ebi = UE_BEAR_ID(sess_id); ebi_index = GET_EBI_INDEX(ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[ebi_index]; /* Update the UE state */ pdn = GET_PDN(context, ebi_index); if(pdn == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get pdn for " "ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn->state = PFCP_SESS_MOD_RESP_RCVD_STATE; if (!bearer) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get bearer for " "ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (resp->msg_type == GTP_MODIFY_BEARER_REQ) { resp->state = CONNECTED_STATE; /* Update the UE state */ pdn->state = CONNECTED_STATE; } return 0; } int process_pfcp_sess_mod_resp_mbr_req(pfcp_sess_mod_rsp_t *pfcp_sess_mod_rsp, gtpv2c_header_t *gtpv2c_tx, pdn_connection *pdn, struct resp_info *resp, eps_bearer *bearer, uint8_t *mbr_procedure) { uint8_t cp_mode = 0; ue_context *context = NULL; uint64_t sess_id = pfcp_sess_mod_rsp->header.seid_seqno.has_seid.seid; int ebi = UE_BEAR_ID(sess_id); int ebi_index = GET_EBI_INDEX(ebi); struct teid_value_t *teid_value = NULL; int ret = 0; teid_key_t teid_key = {0}; if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } resp->state = PFCP_SESS_MOD_RESP_RCVD_STATE; pdn->state = PFCP_SESS_MOD_RESP_RCVD_STATE; context = pdn->context; /* For CIOT flow s11u fteid = s1u fteid */ if (context->indication_flag.s11tf == 1) { bearer->s11u_sgw_gtpu_teid = bearer->s1u_sgw_gtpu_teid; memcpy(&bearer->s11u_sgw_gtpu_ip, &bearer->s1u_sgw_gtpu_ip, sizeof(node_address_t)); } if (*mbr_procedure == NO_UPDATE_MBR) { set_modify_bearer_response(gtpv2c_tx, context->sequence, context, bearer, &resp->gtpc_msg.mbr); resp->state = CONNECTED_STATE; if (PGWC != context->cp_mode) { ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } uint16_t payload_length = ntohs(gtpv2c_tx->gtpc.message_len) + sizeof(gtpv2c_tx->gtpc); gtpv2c_send(s11_fd, s11_fd_v6, tx_buf, payload_length, s11_mme_sockaddr, ACC); if (PRESENT == context->dupl) { process_cp_li_msg( pdn->seid, S11_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s11_mme_sockaddr.type, config.s11_ip.s_addr, config.s11_ip_v6.s6_addr), fill_ip_info(s11_mme_sockaddr.type, s11_mme_sockaddr.ipv4.sin_addr.s_addr, s11_mme_sockaddr.ipv6.sin6_addr.s6_addr), config.s11_port, ((s11_mme_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s11_mme_sockaddr.ipv4.sin_port) : ntohs(s11_mme_sockaddr.ipv6.sin6_port))); } resp->state = CONNECTED_STATE; pdn->state = CONNECTED_STATE; return 0; } else if (*mbr_procedure == UPDATE_PDN_CONNECTION) { resp->state = UPD_PDN_CONN_SET_REQ_SNT_STATE; pdn->state = UPD_PDN_CONN_SET_REQ_SNT_STATE; #ifdef USE_CSID if ((context->cp_mode == SGWC)) { /* Update peer node csid */ update_peer_node_csid(pfcp_sess_mod_rsp, pdn); uint16_t payload_length = 0; bzero(&s5s8_tx_buf, sizeof(s5s8_tx_buf)); gtpv2c_header_t *gtpc_tx = (gtpv2c_header_t *)s5s8_tx_buf; upd_pdn_conn_set_req_t upd_pdn_set = {0}; set_gtpv2c_teid_header((gtpv2c_header_t *)&upd_pdn_set.header, GTP_UPDATE_PDN_CONNECTION_SET_REQ, 0, context->sequence, 0); /* Add the entry for sequence and teid value for error handling */ teid_value = rte_zmalloc_socket(NULL, sizeof(teid_value_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (teid_value == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for teid value, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } teid_value->teid = pdn->s5s8_sgw_gtpc_teid; teid_value->msg_type = gtpv2c_tx->gtpc.message_type; snprintf(teid_key.teid_key, PROC_LEN, "%s%d", get_proc_string(pdn->proc), context->sequence); /* Add the entry for sequence and teid value for error handling */ if (context->cp_mode != SAEGWC) { ret = add_seq_number_for_teid(teid_key, teid_value); if(ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "Sequence number for TEID: %u\n", LOG_VALUE, teid_value->teid); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } upd_pdn_set.header.teid.has_teid.teid = pdn->s5s8_pgw_gtpc_teid; set_gtpc_fqcsid_t(&upd_pdn_set.sgw_fqcsid, IE_INSTANCE_ONE, &pdn->sgw_csid); /* MME Relocation */ if (context->mme_changed_flag == TRUE) { set_gtpc_fqcsid_t(&upd_pdn_set.mme_fqcsid, IE_INSTANCE_ZERO, &pdn->mme_csid); } payload_length = encode_upd_pdn_conn_set_req(&upd_pdn_set, (uint8_t *)gtpc_tx); ret = set_dest_address(bearer->pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"s5s8_recv_sockaddr.sin_addr.s_addr :%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&s5s8_recv_sockaddr.ipv4.sin_addr.s_addr))); gtpv2c_send(s5s8_fd, s5s8_fd_v6, s5s8_tx_buf, payload_length, s5s8_recv_sockaddr, SENT); cp_mode = context->cp_mode; add_gtpv2c_if_timer_entry( pdn->context->s11_sgw_gtpc_teid, &s5s8_recv_sockaddr, s5s8_tx_buf, payload_length, ebi_index, S5S8_IFACE, cp_mode); /* copy packet for user level packet copying or li */ if (context->dupl) { process_pkt_for_li( context, S5S8_C_INTFC_OUT, s5s8_tx_buf, payload_length, fill_ip_info(s5s8_recv_sockaddr.type, config.s5s8_ip.s_addr, config.s5s8_ip_v6.s6_addr), fill_ip_info(s5s8_recv_sockaddr.type, s5s8_recv_sockaddr.ipv4.sin_addr.s_addr, s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr), config.s5s8_port, ((s5s8_recv_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s5s8_recv_sockaddr.ipv4.sin_port) : ntohs(s5s8_recv_sockaddr.ipv6.sin6_port))); } return 0; } #endif /* USE_CSID */ } else if (*mbr_procedure == FORWARD_MBR_REQUEST) { set_modify_bearer_request(gtpv2c_tx, pdn, bearer); ret = set_dest_address(bearer->pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"s5s8_recv_sockaddr.sin_addr.s_addr :%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&s5s8_recv_sockaddr.ipv4.sin_addr.s_addr))); uint16_t payload_length = ntohs(gtpv2c_tx->gtpc.message_len) + sizeof(gtpv2c_tx->gtpc); gtpv2c_send(s5s8_fd, s5s8_fd_v6, tx_buf, payload_length, s5s8_recv_sockaddr, SENT); if (context->update_sgw_fteid == TRUE) { context->uli_flag = 0; context->ue_time_zone_flag = FALSE; context->serving_nw_flag = FALSE; pdn->flag_fqcsid_modified = FALSE; } cp_mode = pdn->context->cp_mode; add_gtpv2c_if_timer_entry( pdn->context->s11_sgw_gtpc_teid, &s5s8_recv_sockaddr, tx_buf, payload_length, ebi_index, S5S8_IFACE, cp_mode); /* copy packet for user level packet copying or li */ if (context->dupl) { process_pkt_for_li( context, S5S8_C_INTFC_OUT, s5s8_tx_buf, payload_length, fill_ip_info(s5s8_recv_sockaddr.type, config.s5s8_ip.s_addr, config.s5s8_ip_v6.s6_addr), fill_ip_info(s5s8_recv_sockaddr.type, s5s8_recv_sockaddr.ipv4.sin_addr.s_addr, s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr), config.s5s8_port, ((s5s8_recv_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s5s8_recv_sockaddr.ipv4.sin_port) : ntohs(s5s8_recv_sockaddr.ipv6.sin6_port))); } resp->state = MBR_REQ_SNT_STATE; pdn->state = MBR_REQ_SNT_STATE; return 0; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO STATE SET IN MBR :%s\n", LOG_VALUE); /*No State Set*/ return -1; } return 0; } uint8_t process_pfcp_sess_mod_resp(pfcp_sess_mod_rsp_t *pfcp_sess_mod_rsp, gtpv2c_header_t *gtpv2c_tx,ue_context *context, struct resp_info *resp) { int ret = 0; uint8_t pti = 0; int ebi_index = 0; eps_bearer *bearer = NULL; pdn_connection *pdn = NULL; uint64_t sess_id = pfcp_sess_mod_rsp->header.seid_seqno.has_seid.seid; /* Update the session state */ resp->state = PFCP_SESS_MOD_RESP_RCVD_STATE; int ebi = UE_BEAR_ID(sess_id); ebi_index = GET_EBI_INDEX(ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[ebi_index]; /* Update the UE state */ pdn = GET_PDN(context, ebi_index); if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get pdn for ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if(context->piggyback == TRUE) { pdn->state = CONNECTED_STATE; pdn->proc = ATTACH_DEDICATED_PROC; resp->proc = ATTACH_DEDICATED_PROC; /*NOTE:*/ int index = GET_EBI_INDEX(resp->eps_bearer_ids[0]); if (index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } provision_ack_ccr(pdn, context->eps_bearers[index], RULE_ACTION_ADD, NO_FAIL); return 0; } pdn->state = PFCP_SESS_MOD_RESP_RCVD_STATE; if (!bearer) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get bearer for ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (resp->msg_type == GTP_CREATE_SESSION_REQ) { /* Sent the CSR Response in the promotion case */ if (context->cp_mode == SAEGWC) { /* Update UP CSID in case of promotion Demotion */ if ((pfcp_sess_mod_rsp->up_fqcsid.header.len) && (pfcp_sess_mod_rsp->up_fqcsid.number_of_csids)) { update_peer_node_csid(pfcp_sess_mod_rsp, pdn); } /* Fill the Create session response */ set_create_session_response( gtpv2c_tx, context->sequence, context, pdn, 0); pdn->csr_sequence = 0; } } else if (resp->msg_type == GTP_CREATE_SESSION_RSP) { /* Fill the Create session response */ set_create_session_response( gtpv2c_tx, context->sequence, context, pdn, 0); pdn->csr_sequence = 0; } else if (resp->msg_type == GX_RAR_MSG || resp->msg_type == GTP_BEARER_RESOURCE_CMD) { if (pdn->proc == UE_REQ_BER_RSRC_MOD_PROC) pti = context->proc_trans_id; ret = set_create_bearer_request(gtpv2c_tx, context->sequence, pdn, pdn->default_bearer_id, pti, resp, 0, FALSE); resp->state = CREATE_BER_REQ_SNT_STATE; pdn->state = CREATE_BER_REQ_SNT_STATE; //pratick: need to check for IPV6 if (SAEGWC == context->cp_mode) { ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else { ret = set_dest_address(pdn->s5s8_sgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } return ret; } else if (resp->msg_type == GTP_CREATE_BEARER_REQ) { bool flag = TRUE; if ( pdn->proc == UE_REQ_BER_RSRC_MOD_PROC ) { pti = context->proc_trans_id; flag = FALSE; } ret = set_create_bearer_request(gtpv2c_tx, context->sequence, pdn, pdn->default_bearer_id, pti, resp, 0, flag); /*Reset pti for BRC flow*/ if (pdn->proc == UE_REQ_BER_RSRC_MOD_PROC) context->proc_trans_id = 0; resp->state = CREATE_BER_REQ_SNT_STATE; pdn->state = CREATE_BER_REQ_SNT_STATE; ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } return ret; } else if (resp->msg_type == GTP_CREATE_BEARER_RSP) { if ((SAEGWC == context->cp_mode) || (PGWC == context->cp_mode)) { if(pdn->proc == UE_REQ_BER_RSRC_MOD_PROC) { int index = GET_EBI_INDEX(resp->eps_bearer_ids[0]); if (index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } provision_ack_ccr(pdn, context->eps_bearers[index], RULE_ACTION_ADD, NO_FAIL); resp->msg_type = GX_CCR_MSG; } else { rar_funtions rar_function = NULL; rar_function = rar_process(pdn, pdn->proc); if(rar_function != NULL){ ret = rar_function(pdn); if(ret) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed in processing" "RAR function\n", LOG_VALUE); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"None of the RAR function " "returned\n", LOG_VALUE); } } if (pdn->proc == UE_REQ_BER_RSRC_MOD_PROC) { resp->msg_type = GX_CCR_MSG; resp->state = CONNECTED_STATE; pdn->state = CONNECTED_STATE; } else { resp->state = pdn->state; resp->msg_type = GX_RAA_MSG; } return 0; } else { uint32_t cbr_sequence = 0; ebi_index = -1; /* Get seuence number from bearer*/ for(int itr = 0; itr < resp->bearer_count; itr++){ ebi_index = GET_EBI_INDEX(resp->eps_bearer_ids[itr]); if (ebi_index != -1){ break; } } if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[ebi_index]; cbr_sequence = bearer->sequence; set_create_bearer_response( gtpv2c_tx, cbr_sequence, pdn, resp->linked_eps_bearer_id, 0, resp); resp->state = CONNECTED_STATE; pdn->state = CONNECTED_STATE; ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } return 0; } } else if(resp->msg_type == GTP_DELETE_SESSION_REQ) { if (pdn->context->cp_mode == SGWC) { uint8_t encoded_msg[GTP_MSG_LEN] = {0}; /* Indication flags not required in DSR for PGWC */ resp->gtpc_msg.dsr.indctn_flgs.header.len = 0; encode_del_sess_req( (del_sess_req_t *)&(resp->gtpc_msg.dsr), encoded_msg); gtpv2c_header *header; header =(gtpv2c_header*) encoded_msg; ret = gen_sgwc_s5s8_delete_session_request((gtpv2c_header_t *)encoded_msg, gtpv2c_tx, htonl(bearer->pdn->s5s8_pgw_gtpc_teid), header->teid_u.has_teid.seq, resp->linked_eps_bearer_id); ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } /* Update the session state */ resp->state = DS_REQ_SNT_STATE; /* Update the UE state */ if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ret = update_ue_state(context, DS_REQ_SNT_STATE, ebi_index); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" " update UE State for ebi_index : %d.\n", LOG_VALUE, ebi_index); } return 0; } } else if(resp->msg_type == GTP_RELEASE_ACCESS_BEARERS_REQ) { /* Update the session state */ resp->state = IDEL_STATE; /* Update the UE state */ pdn->state = IDEL_STATE; /* Fill the release bearer response */ if(context->pfcp_sess_count == PRESENT) { uint16_t payload_length = 0; pfcp_sess_mod_rsp_t pfcp_sess_mod_resp ={0}; set_release_access_bearer_response(gtpv2c_tx, pdn); if (context->indication_flag.s11tf) { context->indication_flag.s11tf = 0; } ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"s11_mme_sockaddr.sin_addr.s_addr :%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&s11_mme_sockaddr.ipv4.sin_addr.s_addr))); payload_length = ntohs(gtpv2c_tx->gtpc.message_len) + sizeof(gtpv2c_tx->gtpc); gtpv2c_send(s11_fd, s11_fd_v6, tx_buf, payload_length, s11_mme_sockaddr,ACC); process_cp_li_msg( pfcp_sess_mod_resp.header.seid_seqno.has_seid.seid, S11_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s11_mme_sockaddr.type, config.s11_ip.s_addr, config.s11_ip_v6.s6_addr), fill_ip_info(s11_mme_sockaddr.type, s11_mme_sockaddr.ipv4.sin_addr.s_addr, s11_mme_sockaddr.ipv6.sin6_addr.s6_addr), config.s11_port, ((s11_mme_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s11_mme_sockaddr.ipv4.sin_port) : ntohs(s11_mme_sockaddr.ipv6.sin6_port))); } else { context->pfcp_sess_count--; } return 0; } else if(resp->msg_type == GTP_MODIFY_ACCESS_BEARER_REQ) { if(context->cp_mode == SAEGWC ) { set_modify_access_bearer_response(gtpv2c_tx, context->sequence, context, bearer, &resp->gtpc_msg.mod_acc_req); resp->state = CONNECTED_STATE; ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"s11_mme_sockaddr.sin_addr.s_addr :%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&s11_mme_sockaddr.ipv4.sin_addr.s_addr))); uint16_t payload_length = ntohs(gtpv2c_tx->gtpc.message_len) + sizeof(gtpv2c_tx->gtpc); gtpv2c_send(s11_fd, s11_fd_v6, tx_buf, payload_length, s11_mme_sockaddr,ACC); process_cp_li_msg( pdn->seid, S11_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s11_mme_sockaddr.type, config.s11_ip.s_addr, config.s11_ip_v6.s6_addr), fill_ip_info(s11_mme_sockaddr.type, s11_mme_sockaddr.ipv4.sin_addr.s_addr, s11_mme_sockaddr.ipv6.sin6_addr.s6_addr), config.s11_port, ((s11_mme_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s11_mme_sockaddr.ipv4.sin_port) : ntohs(s11_mme_sockaddr.ipv6.sin6_port))); resp->state = CONNECTED_STATE; pdn->state = CONNECTED_STATE; return 0; } else { resp->state = UPD_PDN_CONN_SET_REQ_SNT_STATE; pdn->state = UPD_PDN_CONN_SET_REQ_SNT_STATE; #ifdef USE_CSID if ((context->cp_mode == SGWC)) { /* Update peer node csid */ update_peer_node_csid(pfcp_sess_mod_rsp, pdn); uint16_t payload_length = 0; bzero(&s5s8_tx_buf, sizeof(s5s8_tx_buf)); gtpv2c_header_t *gtpc_tx = (gtpv2c_header_t *)s5s8_tx_buf; upd_pdn_conn_set_req_t upd_pdn_set = {0}; set_gtpv2c_teid_header((gtpv2c_header_t *)&upd_pdn_set.header, GTP_UPDATE_PDN_CONNECTION_SET_REQ, 0, context->sequence, 0); upd_pdn_set.header.teid.has_teid.teid = pdn->s5s8_pgw_gtpc_teid; set_gtpc_fqcsid_t(&upd_pdn_set.sgw_fqcsid, IE_INSTANCE_ONE, &pdn->sgw_csid); /* MME Relocation */ if (context->mme_changed_flag == TRUE) { set_gtpc_fqcsid_t(&upd_pdn_set.mme_fqcsid, IE_INSTANCE_ZERO, &pdn->mme_csid); } payload_length = encode_upd_pdn_conn_set_req(&upd_pdn_set, (uint8_t *)gtpc_tx); ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } gtpv2c_send(s5s8_fd, s5s8_fd_v6, s5s8_tx_buf, payload_length, s5s8_recv_sockaddr, SENT); uint8_t cp_mode = context->cp_mode; add_gtpv2c_if_timer_entry( pdn->context->s11_sgw_gtpc_teid, &s5s8_recv_sockaddr, tx_buf, payload_length, ebi_index, S5S8_IFACE, cp_mode); /* copy packet for user level packet copying or li */ if (context->dupl) { process_pkt_for_li( context, S5S8_C_INTFC_OUT, s5s8_tx_buf, payload_length, fill_ip_info(s5s8_recv_sockaddr.type, config.s5s8_ip.s_addr, config.s5s8_ip_v6.s6_addr), fill_ip_info(s5s8_recv_sockaddr.type, s5s8_recv_sockaddr.ipv4.sin_addr.s_addr, s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr), config.s5s8_port, ((s5s8_recv_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s5s8_recv_sockaddr.ipv4.sin_port) : ntohs(s5s8_recv_sockaddr.ipv6.sin6_port))); } return 0; } #endif /* USE_CSID */ } } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"INVALID MSG TYPE", LOG_VALUE); } /* Update the session state */ resp->state = CONNECTED_STATE; /* Update the UE state */ pdn->state = CONNECTED_STATE; ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"s11_mme_sockaddr.sin_addr.s_addr :%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&s11_mme_sockaddr.ipv4.sin_addr.s_addr))); return 0; } int process_change_noti_request(change_noti_req_t *change_not_req, ue_context *context) { int ebi_index = 0, ret = 0; eps_bearer *bearer = NULL; pdn_connection *pdn = NULL; ebi_index = GET_EBI_INDEX(change_not_req->lbi.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[ebi_index]; if (!bearer) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get bearer " "for ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if(change_not_req->rat_type.header.len == 0) return GTPV2C_CAUSE_MANDATORY_IE_MISSING; pdn = bearer->pdn; if(change_not_req->imsi.header.len == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IMSI NOT FOUND in Change Notification Message\n", LOG_VALUE); return GTPV2C_CAUSE_IMSI_NOT_KNOWN; } context->sequence = change_not_req->header.teid.has_teid.seq; if(change_not_req->second_rat_count != 0 ) { /*Add to the CDR */ uint8_t trigg_buff[] = "secondary_rat_usage"; for(uint8_t i = 0; i < change_not_req->second_rat_count; i++) { cdr second_rat_data = {0} ; struct timeval unix_start_time; struct timeval unix_end_time; second_rat_data.cdr_type = CDR_BY_SEC_RAT; second_rat_data.change_rat_type_flag = 1; /*rat type in sec_rat_usage_rpt is NR=0 i.e RAT is 10 as per spec 29.274*/ second_rat_data.rat_type = (change_not_req->secdry_rat_usage_data_rpt[i].secdry_rat_type == 0) ? 10 : 0; second_rat_data.bearer_id = change_not_req->lbi.ebi_ebi; second_rat_data.seid = pdn->seid; second_rat_data.imsi = pdn->context->imsi; second_rat_data.start_time = change_not_req->secdry_rat_usage_data_rpt[i].start_timestamp; second_rat_data.end_time = change_not_req->secdry_rat_usage_data_rpt[i].end_timestamp; second_rat_data.data_volume_uplink = change_not_req->secdry_rat_usage_data_rpt[i].usage_data_ul; second_rat_data.data_volume_downlink = change_not_req->secdry_rat_usage_data_rpt[i].usage_data_dl; ntp_to_unix_time(&change_not_req->secdry_rat_usage_data_rpt[i].start_timestamp,&unix_start_time); ntp_to_unix_time(&change_not_req->secdry_rat_usage_data_rpt[i].end_timestamp,&unix_end_time); second_rat_data.duration_meas = unix_end_time.tv_sec - unix_start_time.tv_sec; second_rat_data.data_start_time = 0; second_rat_data.data_end_time = 0; second_rat_data.total_data_volume = change_not_req->secdry_rat_usage_data_rpt[i].usage_data_ul + change_not_req->secdry_rat_usage_data_rpt[i].usage_data_dl; memcpy(&second_rat_data.trigg_buff, &trigg_buff, sizeof(trigg_buff)); if(generate_cdr_info(&second_rat_data) == -1) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"failed to generate " "CDR\n",LOG_VALUE); return -1; } } } context->uli_flag = FALSE; check_for_uli_changes(&change_not_req->uli, pdn->context); if((config.use_gx) && context->uli_flag != 0 ) { int ret = gen_ccru_request(pdn->context, bearer, NULL, NULL); return ret; } uint8_t payload_length = 0; bzero(&tx_buf, sizeof(tx_buf)); gtpv2c_header_t *gtpv2c_tx = (gtpv2c_header_t *)tx_buf; set_change_notification_response(gtpv2c_tx, pdn); payload_length = ntohs(gtpv2c_tx->gtpc.message_len) + sizeof(gtpv2c_tx->gtpc); if(context->cp_mode == PGWC) { ret = set_dest_address(pdn->s5s8_sgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } gtpv2c_send(s5s8_fd, s5s8_fd_v6, tx_buf, payload_length, s5s8_recv_sockaddr,SENT); /* copy packet for user level packet copying or li */ if (context->dupl) { process_pkt_for_li( context, S5S8_C_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s5s8_recv_sockaddr.type, config.s5s8_ip.s_addr, config.s5s8_ip_v6.s6_addr), fill_ip_info(s5s8_recv_sockaddr.type, s5s8_recv_sockaddr.ipv4.sin_addr.s_addr, s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr), config.s5s8_port, ((s5s8_recv_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s5s8_recv_sockaddr.ipv4.sin_port) : ntohs(s5s8_recv_sockaddr.ipv6.sin6_port))); } } else { ret = set_dest_address(pdn->context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } gtpv2c_send(s11_fd, s11_fd_v6, tx_buf, payload_length, s11_mme_sockaddr, SENT); /* copy packet for user level packet copying or li */ if (context->dupl) { process_pkt_for_li( context, S11_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s11_mme_sockaddr.type, config.s11_ip.s_addr, config.s11_ip_v6.s6_addr), fill_ip_info(s11_mme_sockaddr.type, s11_mme_sockaddr.ipv4.sin_addr.s_addr, s11_mme_sockaddr.ipv6.sin6_addr.s6_addr), config.s11_port, ((s11_mme_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s11_mme_sockaddr.ipv4.sin_port) : ntohs(s11_mme_sockaddr.ipv6.sin6_port))); } } return 0; } int process_change_noti_response(change_noti_rsp_t *change_not_rsp, gtpv2c_header_t *gtpv2c_tx) { ue_context *context = NULL; pdn_connection *pdn = NULL; eps_bearer *bearer = NULL; int ret = 0; change_noti_rsp_t change_notification_rsp = {0}; ret = get_ue_context_by_sgw_s5s8_teid(change_not_rsp->header.teid.has_teid.teid, &context); if (ret < 0 || !context) { return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } ret = get_bearer_by_teid(change_not_rsp->header.teid.has_teid.teid, &bearer); if(ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get bearer " "for teid: %u\n", LOG_VALUE, change_not_rsp->header.teid.has_teid.teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if(change_not_rsp->pres_rptng_area_act.header.len){ store_presc_reporting_area_act_to_ue_context(&change_not_rsp->pres_rptng_area_act, context); } pdn = bearer->pdn; set_gtpv2c_teid_header((gtpv2c_header_t *) &change_notification_rsp, GTP_CHANGE_NOTIFICATION_RSP, context->s11_mme_gtpc_teid, context->sequence, 0); set_cause_accepted(&change_notification_rsp.cause, IE_INSTANCE_ZERO); change_notification_rsp.cause.cause_value = change_not_rsp->cause.cause_value; memcpy(&change_notification_rsp.imsi.imsi_number_digits, &(context->imsi), context->imsi_len); set_ie_header(&change_notification_rsp.imsi.header, GTP_IE_IMSI, IE_INSTANCE_ZERO, context->imsi_len); ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } if(context->pra_flag){ set_presence_reporting_area_action_ie(&change_notification_rsp.pres_rptng_area_act, context); context->pra_flag = 0; } encode_change_noti_rsp(&change_notification_rsp, (uint8_t *)gtpv2c_tx); pdn->state = CONNECTED_STATE; pdn->proc = CHANGE_NOTIFICATION_PROC; return 0; } int process_sgwc_delete_session_request(del_sess_req_t *del_req, ue_context *context) { int ebi_index = 0; pdn_connection *pdn = NULL; struct resp_info *resp = NULL; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; struct teid_value_t *teid_value = NULL; int ret = 0; teid_key_t teid_key = {0}; ebi_index = GET_EBI_INDEX(del_req->lbi.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (!(context->bearer_bitmap & (1 << ebi_index))) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Received Delete Session " "on non-existent EBI : %d.Dropping packet\n",LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn = GET_PDN(context, ebi_index); if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Failed to get pdn " "for ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } fill_pfcp_sess_mod_req_delete(&pfcp_sess_mod_req, pdn, pdn->eps_bearers, MAX_BEARERS); uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); /* UPF ip address */ ret = set_dest_address(pdn->upf_ip, &upf_pfcp_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr, SENT) < 0 ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in sending PFCP Session " "Modification Request for Delete Session Request %i\n", LOG_VALUE, errno); } else { #ifdef CP_BUILD add_pfcp_if_timer_entry(context->s11_sgw_gtpc_teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ } /* Update UE State */ pdn->state = PFCP_SESS_MOD_REQ_SNT_STATE; /* Update the sequence number */ context->sequence = del_req->header.teid.has_teid.seq; teid_value = rte_zmalloc_socket(NULL, sizeof(teid_value_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (teid_value == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "memory for Teid Value structure, Error : %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } teid_value->teid = pdn->s5s8_sgw_gtpc_teid; teid_value->msg_type = del_req->header.gtpc.message_type; snprintf(teid_key.teid_key, PROC_LEN, "%s%d", get_proc_string(pdn->proc), del_req->header.teid.has_teid.seq); if (context->cp_mode != SAEGWC) { ret = add_seq_number_for_teid(teid_key, teid_value); if(ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "Sequence number key for TEID: %u\n", LOG_VALUE, teid_value->teid); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } /*Retrive the session information based on session id. */ if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session Entry " "Found for sess ID : %lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } reset_resp_info_structure(resp); resp->gtpc_msg.dsr = *del_req; resp->linked_eps_bearer_id = del_req->lbi.ebi_ebi; resp->msg_type = GTP_DELETE_SESSION_REQ; resp->state = PFCP_SESS_MOD_REQ_SNT_STATE; resp->proc = pdn->proc; resp->cp_mode = pdn->context->cp_mode; return 0; } int process_pfcp_sess_del_request(del_sess_req_t *ds_req, ue_context *context) { int ret = 0; pdn_connection *pdn = NULL; struct resp_info *resp = NULL; pfcp_sess_del_req_t pfcp_sess_del_req = {0}; int ebi_index = GET_EBI_INDEX(ds_req->lbi.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* Lookup and get context of delete request */ ret = delete_context(ds_req->lbi, ds_req->header.teid.has_teid.teid, &context, &pdn); if (ret) return ret; if (pdn == NULL || context == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get pdn or " "UE context for ebi_index : %d\n ", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Fill pfcp structure for pfcp delete request and send it */ fill_pfcp_sess_del_req(&pfcp_sess_del_req, context->cp_mode); pfcp_sess_del_req.header.seid_seqno.has_seid.seid = pdn->dp_seid; uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_del_req_t(&pfcp_sess_del_req, pfcp_msg); /* Fill the target UPF ip address */ ret = set_dest_address(pdn->upf_ip, &upf_pfcp_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr,SENT) < 0 ){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error sending pfcp session " "deletion request : %i\n", LOG_VALUE, errno); return -1; } else { #ifdef CP_BUILD add_pfcp_if_timer_entry(context->s11_sgw_gtpc_teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ } /* Update the sequence number */ context->sequence = ds_req->header.teid.has_teid.seq; /* Update UE State */ pdn->state = PFCP_SESS_DEL_REQ_SNT_STATE; /* Lookup entry in hash table on the basis of session id*/ if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session Entry Found " "for sess ID : %lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } reset_resp_info_structure(resp); /* Store s11 struture data into sm_hash for sending delete response back to s11 */ resp->gtpc_msg.dsr = *ds_req; resp->linked_eps_bearer_id = ds_req->lbi.ebi_ebi; resp->msg_type = GTP_DELETE_SESSION_REQ; resp->state = PFCP_SESS_DEL_REQ_SNT_STATE; resp->proc = pdn->proc; resp->cp_mode = context->cp_mode; resp->teid = context->s11_sgw_gtpc_teid; return 0; } int process_pfcp_sess_del_request_delete_bearer_rsp(del_bearer_rsp_t *db_rsp) { int ret = 0; ue_context *context = NULL; struct resp_info *resp = NULL; pdn_connection *pdn = NULL; pfcp_sess_del_req_t pfcp_sess_del_req = {0}; int ebi_index = GET_EBI_INDEX(db_rsp->lbi.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ret = delete_context(db_rsp->lbi, db_rsp->header.teid.has_teid.teid, &context, &pdn); if (ret) return ret; if (pdn == NULL || context == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get pdn or " "UE context for ebi_index : %d\n ", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (ret && ret!=-1) return ret; /* Fill pfcp structure for pfcp delete request and send it */ fill_pfcp_sess_del_req(&pfcp_sess_del_req, context->cp_mode); pfcp_sess_del_req.header.seid_seqno.has_seid.seid = pdn->dp_seid; uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_del_req_t(&pfcp_sess_del_req, pfcp_msg); if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr,SENT) < 0 ){ clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Error sending Session " "Modification Request %i\n", LOG_VALUE, errno); return -1; } else { #ifdef CP_BUILD add_pfcp_if_timer_entry(db_rsp->header.teid.has_teid.teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ } /* Update the sequence number */ context->sequence = db_rsp->header.teid.has_teid.seq; /* Update UE State */ pdn->state = PFCP_SESS_DEL_REQ_SNT_STATE; /* Lookup entry in hash table on the basis of session id*/ if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } resp->linked_eps_bearer_id = db_rsp->lbi.ebi_ebi; resp->msg_type = GTP_DELETE_BEARER_RSP; resp->state = PFCP_SESS_DEL_REQ_SNT_STATE; resp->proc = pdn->proc; resp->cp_mode = context->cp_mode; if(resp->proc == HSS_INITIATED_SUB_QOS_MOD) { pdn->proc = PDN_GW_INIT_BEARER_DEACTIVATION; resp->proc = PDN_GW_INIT_BEARER_DEACTIVATION; } return 0; } int delete_dedicated_bearers(pdn_connection *pdn, uint8_t bearer_ids[], uint8_t bearer_cntr) { /* Delete multiple dedicated bearer of pdn */ for (int iCnt = 0; iCnt < bearer_cntr; ++iCnt) { int ebi_index = GET_EBI_INDEX(bearer_ids[iCnt]); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } /* Delete PDR, QER of bearer */ if (del_rule_entries(pdn, ebi_index)) { /* TODO: Error message handling in case deletion failed */ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to delete rule entries for " "ebi_index : %d \n", LOG_VALUE, ebi_index); return -1; } delete_bearer_context(pdn, ebi_index); } return 0; } int del_rule_entries(pdn_connection *pdn, int ebi_index ) { int ret = 0; pdr_t *pdr_ctx = NULL; /*Delete all pdr, far, qer entry from table */ if (config.use_gx) { for(uint8_t itr = 0; itr < pdn->eps_bearers[ebi_index]->qer_count; itr++) { if( del_qer_entry(pdn->eps_bearers[ebi_index]->qer_id[itr].qer_id, pdn->seid) != 0 ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure in deleting QER entry for ebi_index : %d, " "Error : %s \n", LOG_VALUE, ebi_index, strerror(ret)); } } } for(uint8_t itr = 0; itr < pdn->eps_bearers[ebi_index]->pdr_count; itr++) { pdr_ctx = pdn->eps_bearers[ebi_index]->pdrs[itr]; if(pdr_ctx == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No PDR entry found for ebi_index : %d, " "Error : %s \n", LOG_VALUE, ebi_index, strerror(ret)); } else { if( del_pdr_entry(pdr_ctx->rule_id, pdn->seid) != 0 ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure in deleting PDR entry for ebi_index : %d, " "Error : %s \n", LOG_VALUE, ebi_index, strerror(ret)); } /* Reset PDR to NULL in bearer */ pdn->eps_bearers[ebi_index]->pdrs[itr] = NULL; } } return 0; } int process_pfcp_sess_del_resp_indirect_tunnel(uint64_t sess_id, gtpv2c_header_t *gtpv2c_tx, uint64_t *uiImsi, int *li_sock_fd) { int ret = 0; uint8_t ebi_index = 0; uint16_t msg_len = 0; ue_context *context = NULL; struct resp_info *resp = NULL; del_indir_data_fwdng_tunn_resp_t dlt_indr_tun_resp = {0}; uint32_t teid = UE_SESS_ID(sess_id); RTE_SET_USED(ebi_index); RTE_SET_USED(li_sock_fd); pdn_connection *pdn = NULL; if (get_sess_entry(sess_id, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "NO response Entry Found for sess ID:%lu\n", LOG_VALUE, sess_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Update the session state */ resp->state = PFCP_SESS_DEL_RESP_RCVD_STATE; /* Retrieve the UE context */ ret = get_ue_context(teid, &context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Context Not found for teid: %u\n", LOG_VALUE, teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Set IMSI for lawful interception */ *uiImsi = context->imsi; ebi_index = context->indirect_tunnel->eps_bearer_id - NUM_EBI_RESERVED; pdn = context->indirect_tunnel->pdn; /* Update the UE state */ pdn->state = PFCP_SESS_DEL_RESP_RCVD_STATE; /* Fill gtpv2c structure for sending on s11 interface */ set_gtpv2c_teid_header((gtpv2c_header_t *) &dlt_indr_tun_resp, GTP_DELETE_INDIRECT_DATA_FORWARDING_TUNNEL_RSP, context->s11_mme_gtpc_teid, context->sequence, 0); set_cause_accepted(&dlt_indr_tun_resp.cause, IE_INSTANCE_ZERO); /*Encode the S11 delete session response message. */ msg_len = encode_del_indir_data_fwdng_tunn_rsp(&dlt_indr_tun_resp, (uint8_t *)gtpv2c_tx); gtpv2c_tx->gtpc.message_len = htons(msg_len - IE_HEADER_SIZE); ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } clLog(clSystemLog, eCLSeverityDebug, "Msg Sent to "LOG_FORMAT "IP Address :%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&s11_mme_sockaddr.ipv4.sin_addr.s_addr))); /* Delete entry from session entry */ if (del_sess_entry(sess_id) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "NO Session Entry Found for Key sess ID:%lu\n", LOG_VALUE, sess_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* hash created for indirect tunnel*/ if(rte_hash_del_key(ue_context_by_sender_teid_hash, (const void *) &(context)->s11_sgw_gtpc_teid) <0 ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error on ue_context_by_fteid_hash del\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } uint8_t if_anchor_gateway = false; if_anchor_gateway = context->indirect_tunnel->anchor_gateway_flag; for(uint8_t i = 0;i <MAX_BEARERS; i++) { if((context->indirect_tunnel->pdn->eps_bearers[i]) != NULL) { rte_free(context->indirect_tunnel->pdn->eps_bearers[i]); } } if(if_anchor_gateway == false) { rte_free(context->indirect_tunnel->pdn); free(context->indirect_tunnel); context->indirect_tunnel->pdn = NULL; context->indirect_tunnel = NULL; } if(context->indirect_tunnel_flag == CANCEL_S1_HO_INDICATION) { delete_sess_context(&context, context->pdns[ebi_index]); } /*ANCHOR GAETWAY*/ if(if_anchor_gateway == true) { rte_free(context->indirect_tunnel->pdn->apn_in_use); context->indirect_tunnel->pdn->apn_in_use = NULL; if (context->indirect_tunnel->pdn != NULL) { rte_free(context->indirect_tunnel->pdn); context->indirect_tunnel->pdn = NULL; } if(context->num_pdns == 0) { /* hash created in while creating ue_context */ if(rte_hash_del_key(ue_context_by_fteid_hash, &context->s11_sgw_gtpc_teid) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error on ue_context_by_fteid_hash del\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Delete UE context entry from UE Hash */ if (rte_hash_del_key(ue_context_by_imsi_hash, &context->imsi) < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error on ue_context_by_fteid_hash del\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } free(context->indirect_tunnel); context->indirect_tunnel = NULL; if (context != NULL) { rte_free(context); context = NULL; } } } return 0; } int process_del_indirect_tunnel_request(del_indir_data_fwdng_tunn_req_t *del_indir_req) { ue_context *context = NULL; pdn_connection *pdn = NULL; struct resp_info *resp = NULL; pfcp_sess_del_req_t pfcp_sess_del_req = {0}; int ret = 0; ret = rte_hash_lookup_data(ue_context_by_sender_teid_hash, (const void *) &del_indir_req->header.teid.has_teid.teid, (void **) &context); if (ret < 0 || !context){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "UE Context Not Found\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn = context->indirect_tunnel->pdn; pdn->state = PFCP_SESS_DEL_REQ_SNT_STATE; fill_pfcp_sess_del_req(&pfcp_sess_del_req, context->cp_mode); pfcp_sess_del_req.header.seid_seqno.has_seid.seid = context->indirect_tunnel->pdn->dp_seid; context->sequence = del_indir_req->header.teid.has_teid.seq; uint8_t pfcp_msg[PFCP_MSG_LEN] = {0}; int encoded = encode_pfcp_sess_del_req_t(&pfcp_sess_del_req, pfcp_msg); pfcp_header_t *header = (pfcp_header_t *) pfcp_msg; header->message_len = htons(encoded - 4); if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr,SENT) < 0 ){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error sending: %i\n", LOG_VALUE, errno); return -1; } else { add_pfcp_if_timer_entry(context->s11_sgw_gtpc_teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, 0); } if (get_sess_entry(context->indirect_tunnel->pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO response Entry " "Found for sess ID : %lu\n", LOG_VALUE, context->indirect_tunnel->pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn->state = PFCP_SESS_DEL_REQ_SNT_STATE; resp->gtpc_msg.dlt_indr_tun_req = *del_indir_req; resp->msg_type = GTP_DELETE_INDIRECT_DATA_FORWARDING_TUNNEL_REQ; resp->state = PFCP_SESS_DEL_REQ_SNT_STATE; resp->proc = DELETE_INDIRECT_TUNNEL_PROC; resp->cp_mode = context->cp_mode; return 0; } int process_create_indir_data_frwd_tun_request(create_indir_data_fwdng_tunn_req_t *create_indir_req, ue_context **_context) { ue_context *context = NULL; eps_bearer *bearer = NULL; pdn_connection *pdn = NULL; int ebi_index = 0; uint8_t check_if_ue_hash_exist = 0; int ret = 0; uint8_t pdn_type = 0; /* CP mode will change to SGWC if it was not set to SGWC */ uint8_t cp_mode = SGWC; ret = rte_hash_lookup_data(ue_context_by_fteid_hash, &create_indir_req->header.teid.has_teid.teid, (void **) &context); if(ret < 0) { for( uint8_t i = 0; i < create_indir_req->bearer_count; i++) { ebi_index = GET_EBI_INDEX(create_indir_req->bearer_contexts[i].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if((create_indir_req->bearer_contexts[i].enb_fteid_dl_data_fwdng.v4 == 1) && (create_indir_req->bearer_contexts[i].enb_fteid_dl_data_fwdng.v6 == 1)){ pdn_type = PDN_TYPE_IPV4_IPV6; } else if(create_indir_req->bearer_contexts[i].enb_fteid_dl_data_fwdng.v4 == 1) { pdn_type = PDN_TYPE_IPV4; } else if (create_indir_req->bearer_contexts[i].enb_fteid_dl_data_fwdng.v6 == 1) { pdn_type = PDN_TYPE_IPV6; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid PDN TYPE(IPv4/IPV6) in Bearer Context" "of Create Indirect Tuneel Request\n", LOG_VALUE); } ret = create_ue_context(&create_indir_req->imsi.imsi_number_digits, create_indir_req->imsi.header.len, create_indir_req->bearer_contexts[i].eps_bearer_id.ebi_ebi, &context, NULL, create_indir_req->header.teid.has_teid.seq, &check_if_ue_hash_exist, cp_mode); } if (ret) return ret; context->cp_mode = config.cp_type; context->bearer_count = create_indir_req->bearer_count; context->indirect_tunnel = (struct indirect_tunnel_t *) malloc(sizeof(struct indirect_tunnel_t)); if(context->indirect_tunnel == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error to allocate memory for Indirect Tunnel: %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } context->indirect_tunnel->anchor_gateway_flag = true; //char str[] = "ngic_rtc_apn"; //apn *apn_requested = get_apn(str, strlen(str)); apn *apn_requested = set_default_apn(); context->indirect_tunnel->pdn = context->eps_bearers[ebi_index]->pdn; /*DNS will not be used. UP IP will be picked up set in the cp.cfg file*/ fill_ip_addr(config.upf_pfcp_ip.s_addr, config.upf_pfcp_ip_v6.s6_addr, &context->indirect_tunnel->pdn->upf_ip); context->eps_bearers[ebi_index]->pdn->apn_in_use = apn_requested; context->indirect_tunnel->pdn->context = context; context->indirect_tunnel->pdn->dp_seid = 0; context->indirect_tunnel->pdn->generate_cdr = config.generate_sgw_cdr; if(PDN_TYPE_IPV4_IPV6 == pdn_type){ context->indirect_tunnel->pdn->pdn_type.ipv4 = 1; context->indirect_tunnel->pdn->pdn_type.ipv6 = 1; }else if(PDN_TYPE_IPV4 == pdn_type){ context->indirect_tunnel->pdn->pdn_type.ipv4 = 1; }else { context->indirect_tunnel->pdn->pdn_type.ipv6 = 1; } context->sequence = create_indir_req->header.teid.has_teid.seq; context->indirect_tunnel->pdn->seid = SESS_ID(context->s11_sgw_gtpc_teid, context->eps_bearers[ebi_index]->eps_bearer_id); uint8_t tmp_bearer_count = 0; for( uint8_t i = 0; i < MAX_BEARERS; i++) { if (context->eps_bearers[i] == NULL) continue; context->indirect_tunnel->pdn->eps_bearers[i] = context->eps_bearers[i]; fill_ip_addr(create_indir_req->bearer_contexts[tmp_bearer_count].enb_fteid_dl_data_fwdng.ipv4_address, create_indir_req->bearer_contexts[tmp_bearer_count].enb_fteid_dl_data_fwdng.ipv6_address, &context->indirect_tunnel->pdn->eps_bearers[i]->s1u_enb_gtpu_ip); context->indirect_tunnel->pdn->eps_bearers[i]->s1u_enb_gtpu_teid = create_indir_req->bearer_contexts[tmp_bearer_count].enb_fteid_dl_data_fwdng.teid_gre_key; tmp_bearer_count++; } if ((context->cp_mode == SGWC) || (context->cp_mode == SAEGWC)) { fill_ip_addr(config.s11_ip.s_addr, config.s11_ip_v6.s6_addr, &context->s11_sgw_gtpc_ip); context->s11_mme_gtpc_teid = create_indir_req->sender_fteid_ctl_plane.teid_gre_key; fill_ip_addr(create_indir_req->sender_fteid_ctl_plane.ipv4_address, create_indir_req->sender_fteid_ctl_plane.ipv6_address, &context->s11_mme_gtpc_ip); } } else { pdn = rte_zmalloc_socket(NULL, sizeof(struct pdn_connection_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failure to allocate PDN structure: %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } eps_bearer *default_bearer = NULL; for(int i = 0; i <MAX_BEARERS; i++) { default_bearer = context->eps_bearers[i]; if(default_bearer == NULL) continue; else break; } pdn_connection *default_bearer_pdn = default_bearer->pdn; ret = set_address(&pdn->upf_ip, &default_bearer_pdn->upf_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } context->indirect_tunnel = (struct indirect_tunnel_t *) malloc(sizeof(struct indirect_tunnel_t)); if(context->indirect_tunnel == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Fail to allocate memory for Indirect Tunnel: %s\n", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } context->indirect_tunnel->pdn = pdn; context->sequence = create_indir_req->header.teid.has_teid.seq; for (uint8_t i = 0; i < create_indir_req->bearer_count; i++) { ebi_index = GET_EBI_INDEX(create_indir_req->bearer_contexts[i].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if((create_indir_req->bearer_contexts[i].enb_fteid_dl_data_fwdng.v4 == 1) && (create_indir_req->bearer_contexts[i].enb_fteid_dl_data_fwdng.v6 == 1)){ pdn_type = PDN_TYPE_IPV4_IPV6; } else if(create_indir_req->bearer_contexts[i].enb_fteid_dl_data_fwdng.v4 == 1) { pdn_type = PDN_TYPE_IPV4; } else if (create_indir_req->bearer_contexts[i].enb_fteid_dl_data_fwdng.v6 == 1) { pdn_type = PDN_TYPE_IPV6; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid PDN TYPE(IPv4/IPV6) in Bearer Context" "of Create Indirect Tuneel Request\n", LOG_VALUE); } bearer = rte_zmalloc_socket(NULL, sizeof(eps_bearer), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (bearer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failure to allocate Bearer structure: %s\n", LOG_VALUE, rte_strerror(rte_errno)); rte_free(pdn); pdn = NULL; return GTPV2C_CAUSE_SYSTEM_FAILURE; } pdn->context = context; bearer->pdn = pdn; bearer->eps_bearer_id = create_indir_req->bearer_contexts[i].eps_bearer_id.ebi_ebi; pdn->num_bearer++; context->indirect_tunnel->pdn->eps_bearers[ebi_index] = bearer; pdn->eps_bearers[ebi_index] = bearer; pdn->seid = SESS_ID(context->s11_sgw_gtpc_teid, bearer->eps_bearer_id); pdn->dp_seid = 0; pdn->apn_in_use = default_bearer_pdn->apn_in_use; if(PDN_TYPE_IPV4_IPV6 == pdn_type){ context->indirect_tunnel->pdn->pdn_type.ipv4 = 1; context->indirect_tunnel->pdn->pdn_type.ipv6 = 1; }else if(PDN_TYPE_IPV4 == pdn_type){ context->indirect_tunnel->pdn->pdn_type.ipv4 = 1; }else { context->indirect_tunnel->pdn->pdn_type.ipv6 = 1; } if (i == 0) pdn->default_bearer_id = create_indir_req->bearer_contexts[i].eps_bearer_id.ebi_ebi; fill_ip_addr(create_indir_req->bearer_contexts[i].enb_fteid_dl_data_fwdng.ipv4_address, create_indir_req->bearer_contexts[i].enb_fteid_dl_data_fwdng.ipv6_address, &bearer->s1u_enb_gtpu_ip); bearer->s1u_enb_gtpu_teid = create_indir_req->bearer_contexts[i].enb_fteid_dl_data_fwdng.teid_gre_key; } context->num_pdns++; } ue_context **_cntxt = &context; ret = rte_hash_add_key_data(ue_context_by_sender_teid_hash, (const void *) &(*_cntxt)->s11_sgw_gtpc_teid, (void *) (*_cntxt)); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error on ue_context_by_sender_teid_hash add:%s\n", LOG_VALUE, rte_strerror(rte_errno)); return -1; } context->eps_bearers[ebi_index]->pdn->proc = CREATE_INDIRECT_TUNNEL_PROC; context->indirect_tunnel_flag = 1; *_context = context; return 0; } #ifdef USE_CSID int8_t cleanup_session_entries(uint16_t local_csid, pdn_connection *pdn) { int ret = 0; ue_context *context = NULL; context = pdn->context; /* Clean MME FQ-CSID */ if (context->mme_fqcsid != NULL) { if ((context->mme_fqcsid)->num_csid) { csid_t *csid = NULL; csid_key_t key_t = {0}; key_t.local_csid = pdn->mme_csid.local_csid[pdn->mme_csid.num_csid - 1]; memcpy(&key_t.node_addr, &pdn->mme_csid.node_addr, sizeof(node_address_t)); if (context->cp_mode != PGWC) csid = get_peer_csid_entry(&key_t, S11_SGW_PORT_ID, REMOVE_NODE); else csid = get_peer_csid_entry(&key_t, S5S8_PGWC_PORT_ID, REMOVE_NODE); if (csid == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"MME CSID found null while clean up process " "for session entries %s \n", LOG_VALUE, strerror(errno)); return -1; } for (uint8_t itr1 = 0; itr1 < csid->num_csid; itr1++) { if (csid->local_csid[itr1] == local_csid) { for(uint8_t pos = itr1; pos < (csid->num_csid); pos++ ) { csid->local_csid[pos] = csid->local_csid[pos + 1]; } csid->num_csid--; } } if (csid->num_csid == 0) { if (context->cp_mode != PGWC) ret = del_peer_csid_entry(&key_t, S11_SGW_PORT_ID); else ret = del_peer_csid_entry(&key_t, S5S8_PGWC_PORT_ID); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to delete peer MME csid entry %s \n", LOG_VALUE, strerror(errno)); return -1; } } fqcsid_t *tmp = NULL; tmp = get_peer_addr_csids_entry(&pdn->mme_csid.node_addr, UPDATE_NODE); if (tmp != NULL) { for (uint8_t itr3 = 0; itr3 < tmp->num_csid; itr3++) { if (tmp->local_csid[itr3] == pdn->mme_csid.local_csid[(pdn->mme_csid.num_csid - 1)]) { for(uint8_t pos = itr3; pos < (tmp->num_csid - 1); pos++ ) { tmp->local_csid[pos] = tmp->local_csid[pos + 1]; } tmp->num_csid--; } } if (!tmp->num_csid) { if (del_peer_addr_csids_entry(&pdn->mme_csid.node_addr)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in deleting " "peer CSID entry, Error : %i\n", LOG_VALUE, errno); /* TODO ERROR HANDLING */ return -1; } } } remove_csid_from_cntx(context->mme_fqcsid, &pdn->mme_csid); if ((context->mme_fqcsid)->num_csid == 0) { if (context->mme_fqcsid != NULL) { rte_free(context->mme_fqcsid); context->mme_fqcsid = NULL; } } } } /* Clean SGW FQ-CSID */ if ((context->cp_mode == PGWC) && (context->sgw_fqcsid != NULL)) { if ((context->sgw_fqcsid)->num_csid) { csid_t *csid = NULL; csid_key_t key_t = {0}; key_t.local_csid = (pdn->sgw_csid).local_csid[(pdn->sgw_csid).num_csid - 1]; memcpy(&key_t.node_addr, &(pdn->sgw_csid).node_addr, sizeof(node_address_t)); if (context->cp_mode != PGWC) csid = get_peer_csid_entry(&key_t, S11_SGW_PORT_ID, REMOVE_NODE); else csid = get_peer_csid_entry(&key_t, S5S8_PGWC_PORT_ID, REMOVE_NODE); if (csid == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"SGW CSID found null while clean up process " "for session entries %s \n", LOG_VALUE, strerror(errno)); return -1; } for (uint8_t itr1 = 0; itr1 < csid->num_csid; itr1++) { if (csid->local_csid[itr1] == local_csid) { for(uint8_t pos = itr1; pos < (csid->num_csid - 1); pos++ ) { csid->local_csid[pos] = csid->local_csid[pos + 1]; } csid->num_csid--; } } if (csid->num_csid == 0) { if (context->cp_mode != PGWC) ret = del_peer_csid_entry(&key_t, S11_SGW_PORT_ID); else ret = del_peer_csid_entry(&key_t, S5S8_PGWC_PORT_ID); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to delete peer SGW CSID entry %s \n", LOG_VALUE, strerror(errno)); return -1; } } fqcsid_t *tmp = NULL; tmp = get_peer_addr_csids_entry(&pdn->sgw_csid.node_addr, UPDATE_NODE); if (tmp != NULL) { for (uint8_t itr3 = 0; itr3 < tmp->num_csid; itr3++) { if (tmp->local_csid[itr3] == pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1]) { for(uint8_t pos = itr3; pos < (tmp->num_csid - 1); pos++ ) { tmp->local_csid[pos] = tmp->local_csid[pos + 1]; } tmp->num_csid--; } } if (!tmp->num_csid) { if (del_peer_addr_csids_entry(&pdn->sgw_csid.node_addr)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in deleting " "peer CSID entry, Error : %i\n", LOG_VALUE, errno); /* TODO ERROR HANDLING */ return -1; } } } remove_csid_from_cntx(context->sgw_fqcsid, &pdn->sgw_csid); if ((context->sgw_fqcsid)->num_csid == 0) { if (context->sgw_fqcsid != NULL) { rte_free(context->sgw_fqcsid); context->sgw_fqcsid = NULL; } } } } if (context->cp_mode == SGWC) { /* Clean PGW FQ-CSID */ if (context->pgw_fqcsid != NULL) { if ((context->pgw_fqcsid)->num_csid) { csid_t *csid = NULL; csid_key_t key_t = {0}; key_t.local_csid = ( pdn->pgw_csid).local_csid[(pdn->pgw_csid).num_csid - 1]; memcpy(&key_t.node_addr, &(pdn->pgw_csid).node_addr, sizeof(node_address_t)); if (context->cp_mode != PGWC) csid = get_peer_csid_entry(&key_t, S5S8_SGWC_PORT_ID, REMOVE_NODE); else csid = get_peer_csid_entry(&key_t, S5S8_PGWC_PORT_ID, REMOVE_NODE); if (csid == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"PGW CSID found null while clean up process " "for session entries %s \n", LOG_VALUE, strerror(errno)); return -1; } for (uint8_t itr1 = 0; itr1 < csid->num_csid; itr1++) { if (csid->local_csid[itr1] == local_csid) { for(uint8_t pos = itr1; pos < (csid->num_csid - 1); pos++ ) { csid->local_csid[pos] = csid->local_csid[pos + 1]; } csid->num_csid--; } } if (csid->num_csid == 0) { if (context->cp_mode != PGWC) ret = del_peer_csid_entry(&key_t, S5S8_SGWC_PORT_ID); else ret = del_peer_csid_entry(&key_t, S5S8_PGWC_PORT_ID); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to delete peer PGW CSID entry %s \n", LOG_VALUE, strerror(errno)); return -1; } } fqcsid_t *tmp = NULL; tmp = get_peer_addr_csids_entry(&pdn->pgw_csid.node_addr, UPDATE_NODE); if (tmp != NULL) { for (uint8_t itr3 = 0; itr3 < tmp->num_csid; itr3++) { if (tmp->local_csid[itr3] == pdn->pgw_csid.local_csid[pdn->pgw_csid.num_csid - 1]) { for(uint8_t pos = itr3; pos < (tmp->num_csid - 1); pos++ ) { tmp->local_csid[pos] = tmp->local_csid[pos + 1]; } tmp->num_csid--; } } if (!tmp->num_csid) { if (del_peer_addr_csids_entry(&pdn->pgw_csid.node_addr)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in deleting " "peer CSID entry, Error : %i\n", LOG_VALUE, errno); /* TODO ERROR HANDLING */ return -1; } } } remove_csid_from_cntx(context->pgw_fqcsid, &pdn->pgw_csid); if ((context->pgw_fqcsid)->num_csid == 0) { if (context->pgw_fqcsid != NULL) { rte_free(context->pgw_fqcsid); context->pgw_fqcsid = NULL; } } } } } /* Clean UP FQ-CSID */ if (context->up_fqcsid != NULL) { if ((context->up_fqcsid)->num_csid) { csid_t *csid = NULL; csid_key_t key_t = {0}; key_t.local_csid = (pdn->up_csid).local_csid[(pdn->up_csid).num_csid - 1]; memcpy(&key_t.node_addr, &(pdn->up_csid).node_addr, sizeof(node_address_t)); csid = get_peer_csid_entry(&key_t, SX_PORT_ID, REMOVE_NODE); if (csid == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"UP CSID found null while clean up process " "for session entries %s \n", LOG_VALUE, strerror(errno)); return -1; } for (uint8_t itr1 = 0; itr1 < csid->num_csid; itr1++) { if (csid->local_csid[itr1] == local_csid) { for(uint8_t pos = itr1; pos < (csid->num_csid - 1); pos++ ) { csid->local_csid[pos] = csid->local_csid[pos + 1]; } csid->num_csid--; } } if (csid->num_csid == 0) { ret = del_peer_csid_entry(&key_t, SX_PORT_ID); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to delete peer UP CSID entry %s \n", LOG_VALUE, strerror(errno)); } } fqcsid_t *tmp = NULL; tmp = get_peer_addr_csids_entry(&pdn->up_csid.node_addr, UPDATE_NODE); if (tmp != NULL) { for (uint8_t itr3 = 0; itr3 < tmp->num_csid; itr3++) { if (tmp->local_csid[itr3] == pdn->up_csid.local_csid[pdn->up_csid.num_csid - 1]) { for(uint8_t pos = itr3; pos < (tmp->num_csid - 1); pos++ ) { tmp->local_csid[pos] = tmp->local_csid[pos + 1]; } tmp->num_csid--; } } if (!tmp->num_csid) { if (del_peer_addr_csids_entry(&pdn->up_csid.node_addr)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in deleting " "peer CSID entry, Error : %i\n", LOG_VALUE, errno); /* TODO ERROR HANDLING */ return -1; } } } remove_csid_from_cntx(context->up_fqcsid, &pdn->up_csid); if ((context->up_fqcsid)->num_csid == 0) { if (context->up_fqcsid != NULL) { rte_free(context->up_fqcsid); context->up_fqcsid = NULL; } } } } return 0; } int remove_sess_entry(sess_csid *head, uint64_t seid, peer_csid_key_t *key) { int ret = 0; if (head == NULL) { /* Delete Local CSID entry */ del_sess_peer_csid_entry(key); return -1; } /* Remove node from csid linked list */ head = remove_sess_csid_data_node(head, seid); /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seid_by_peer_csid_hash, key, head); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry" " for CSID = %u \n", LOG_VALUE, key->peer_local_csid); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (head == NULL) { /* Delete Local CSID entry */ del_sess_peer_csid_entry(key); } return 0; } int del_session_csid_entry(pdn_connection *pdn) { uint8_t num_csid = 0; sess_csid *tmp1 = NULL; peer_csid_key_t key = {0}; ue_context *context = NULL; context = pdn->context; if (pdn->mme_csid.num_csid) { /* Remove the session link from MME CSID */ key.iface = ((context->cp_mode != PGWC) ? S11_SGW_PORT_ID : S5S8_PGWC_PORT_ID); key.peer_local_csid = pdn->mme_csid.local_csid[num_csid]; memcpy(&key.peer_node_addr, &pdn->mme_csid.node_addr, sizeof(node_address_t)); tmp1 = get_sess_peer_csid_entry(&key, REMOVE_NODE); remove_sess_entry(tmp1, pdn->seid, &key); } if (pdn->up_csid.num_csid) { /* Remove the session link from UP CSID */ key.iface = SX_PORT_ID; key.peer_local_csid = pdn->up_csid.local_csid[num_csid]; memcpy(&key.peer_node_addr, &pdn->up_csid.node_addr, sizeof(node_address_t)); tmp1 = get_sess_peer_csid_entry(&key, REMOVE_NODE); remove_sess_entry(tmp1, pdn->seid, &key); } if ((pdn->pgw_csid.num_csid) && (context->cp_mode == SGWC)) { /* Remove the session link from UP CSID */ key.iface = S5S8_SGWC_PORT_ID; key.peer_local_csid = pdn->pgw_csid.local_csid[num_csid]; memcpy(&key.peer_node_addr, &pdn->pgw_csid.node_addr, sizeof(node_address_t)); tmp1 = get_sess_peer_csid_entry(&key, REMOVE_NODE); remove_sess_entry(tmp1, pdn->seid, &key); } if ((pdn->sgw_csid.num_csid) && (context->cp_mode == PGWC)) { /* Remove the session link from UP CSID */ key.iface = S5S8_PGWC_PORT_ID; key.peer_local_csid = pdn->sgw_csid.local_csid[num_csid]; memcpy(&key.peer_node_addr, &pdn->sgw_csid.node_addr, sizeof(node_address_t)); tmp1 = get_sess_peer_csid_entry(&key, REMOVE_NODE); remove_sess_entry(tmp1, pdn->seid, &key); } return 0; } #endif /* USE_CSID */ int8_t process_pfcp_sess_del_resp(uint64_t sess_id, gtpv2c_header_t *gtpv2c_tx, gx_msg *ccr_request, uint16_t *msglen, ue_context *context) { int ebi_index = 0; struct resp_info *resp = NULL; pdn_connection *pdn = NULL; del_sess_rsp_t del_resp = {0}; uint32_t sender_teid = 0; int ret = 0; pdr_ids *pfcp_pdr_id = NULL; /* Lookup entry in hash table on the basis of session id*/ if (get_sess_entry(sess_id, &resp) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO response Entry " "Found for sess ID : %lu\n", LOG_VALUE, sess_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Update the session state */ resp->state = PFCP_SESS_DEL_RESP_RCVD_STATE; resp->cp_mode = context->cp_mode; ebi_index = GET_EBI_INDEX(resp->linked_eps_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } pdn = GET_PDN(context, ebi_index); if (pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get pdn " "for ebi_index : %d ",LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Update the UE state */ pdn->state = PFCP_SESS_DEL_RESP_RCVD_STATE; if ((config.use_gx) && context->cp_mode != SGWC) { gx_context_t *gx_context = NULL; /* Retrive Gx_context based on Sess ID. */ ret = rte_hash_lookup_data(gx_context_by_sess_id_hash, (const void*)(pdn->gx_sess_id), (void **)&gx_context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO ENTRY FOUND IN " "Gx HASH [%s]\n", LOG_VALUE, pdn->gx_sess_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Set the CP Mode, to check the CP mode after session deletion */ gx_context->cp_mode = context->cp_mode; /* Set the Msg header type for CCR-T */ ccr_request->msg_type = GX_CCR_MSG ; /* Set Credit Control Request type */ ccr_request->data.ccr.presence.cc_request_type = PRESENT; ccr_request->data.ccr.cc_request_type = TERMINATION_REQUEST ; /* Set Credit Control Bearer opertaion type */ ccr_request->data.ccr.presence.bearer_operation = PRESENT; ccr_request->data.ccr.bearer_operation = TERMINATION ; /* Fill the Credit Crontrol Request to send PCRF */ if(fill_ccr_request(&ccr_request->data.ccr, context, ebi_index, pdn->gx_sess_id, 0) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed CCR request " "filling process\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Update UE State */ pdn->state = CCR_SNT_STATE; /* Set the Gx State for events */ gx_context->state = CCR_SNT_STATE; gx_context->proc = pdn->proc; /* Calculate the max size of CCR msg to allocate the buffer */ *msglen = gx_ccr_calc_length(&ccr_request->data.ccr); ccr_request->msg_len = *msglen + GX_HEADER_LEN; } if ( context->cp_mode == PGWC) { ret = set_dest_address(pdn->s5s8_sgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } sender_teid = pdn->s5s8_sgw_gtpc_teid; (pdn->s5s8_sgw_gtpc_ip.ip_type == IPV6_TYPE)? clLog(clSystemLog, eCLSeverityDebug, "Msg Sent to "LOG_FORMAT "IPv6 Address :"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(s5s8_recv_sockaddr.ipv6.sin6_addr.s6_addr))): clLog(clSystemLog, eCLSeverityDebug, "Msg Sent to "LOG_FORMAT "IPv4 Address :%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&s5s8_recv_sockaddr.ipv4.sin_addr.s_addr))); } else { ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } sender_teid = context->s11_mme_gtpc_teid; (context->s11_mme_gtpc_ip.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, "Msg Sent to "LOG_FORMAT "IPv6 Address :"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(s11_mme_sockaddr.ipv6.sin6_addr.s6_addr))): clLog(clSystemLog, eCLSeverityDebug, "Msg Sent to "LOG_FORMAT "IPv4 Address :%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&s11_mme_sockaddr.ipv4.sin_addr.s_addr))); } /* Fill gtpv2c structure for sending on s11/s5s8 interface */ fill_del_sess_rsp(&del_resp, context->sequence, sender_teid); /*Encode the S11 delete session response message. */ encode_del_sess_rsp(&del_resp, (uint8_t *)gtpv2c_tx); /* Update status of dsr processing for ue */ context->req_status.seq = 0; context->req_status.status = REQ_PROCESS_DONE; /* Remove session Entry from buffered ddn request hash */ pfcp_pdr_id = delete_buff_ddn_req(pdn->seid); if(pfcp_pdr_id != NULL) { rte_free(pfcp_pdr_id); pfcp_pdr_id = NULL; } /*delete only session entries */ delete_entry_from_sess_hash(sess_id, ddn_by_seid_hash); delete_entry_from_sess_hash(sess_id, pfcp_rep_by_seid_hash); delete_sess_in_thrtl_timer(context, sess_id); if(context->indirect_tunnel_flag == 0) { /* Update status of dsr processing for ue */ delete_sess_context(&context, pdn); } else { context->indirect_tunnel_flag = CANCEL_S1_HO_INDICATION; context->indirect_tunnel->eps_bearer_id = pdn->default_bearer_id; } return 0; } void fill_pfcp_sess_mod_req_delete(pfcp_sess_mod_req_t *pfcp_sess_mod_req, pdn_connection *pdn, eps_bearer *bearers[], uint8_t bearer_cntr) { uint32_t seq = 0; int ret = 0; upf_context_t *upf_ctx = NULL; pdr_t *pdr_ctxt = NULL; node_address_t node_value = {0}; if ((ret = upf_context_entry_lookup(pdn->upf_ip, &upf_ctx)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure in upf context " "lookup.Error:%d \n", LOG_VALUE, ret); return; } memset(pfcp_sess_mod_req, 0, sizeof(pfcp_sess_mod_req_t)); seq = get_pfcp_sequence_number(PFCP_SESSION_MODIFICATION_REQUEST, seq); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_mod_req->header), PFCP_SESSION_MODIFICATION_REQUEST, HAS_SEID, seq, pdn->context->cp_mode); pfcp_sess_mod_req->header.seid_seqno.has_seid.seid = pdn->dp_seid; /*Filling Node ID for F-SEID*/ if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV4) { uint8_t temp[IPV6_ADDRESS_LEN] = {0}; ret = fill_ip_addr(config.pfcp_ip.s_addr, temp, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV6) { ret = fill_ip_addr(0, config.pfcp_ip_v6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } set_fseid(&(pfcp_sess_mod_req->cp_fseid), pdn->seid, node_value); /* Adding FAR IE*/ pfcp_sess_mod_req->update_far_count = 0; for (int index = 0; index < bearer_cntr; index++) { if (bearers[index] != NULL) { for(uint8_t itr = 0; itr < bearers[index]->pdr_count ; itr++) { pdr_ctxt = bearers[index]->pdrs[itr]; if (pdr_ctxt) { /*Just need to Drop the packets that's why disabling * all other supported action*/ pdr_ctxt->far.actions.forw = FALSE; pdr_ctxt->far.actions.dupl = GET_DUP_STATUS(pdn->context); pdr_ctxt->far.actions.nocp = FALSE; pdr_ctxt->far.actions.buff = FALSE; pdr_ctxt->far.actions.drop = TRUE; set_update_far(&(pfcp_sess_mod_req->update_far[pfcp_sess_mod_req->update_far_count]), &pdr_ctxt->far); pfcp_sess_mod_req->update_far_count++; } } if (pdn->default_bearer_id == bearers[index]->eps_bearer_id) { set_remove_bar(&(pfcp_sess_mod_req->remove_bar), pdn->bar.bar_id); } } } } void fill_pfcp_sess_mod_req_with_remove_pdr(pfcp_sess_mod_req_t *pfcp_sess_mod_req, pdn_connection *pdn, eps_bearer *bearers[], uint8_t bearer_cntr) { int ret = 0; //uint32_t seq = 0; eps_bearer *bearer = NULL; pdr_t *pdr_ctxt = NULL; upf_context_t *upf_ctx = NULL; if ((ret = upf_context_entry_lookup(pdn->upf_ip, &upf_ctx)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error while extracting " "upf context: %d \n", LOG_VALUE, ret); return; } //memset(pfcp_sess_mod_req, 0, sizeof(pfcp_sess_mod_req_t)); pfcp_sess_mod_req->remove_pdr_count = 0; for (uint8_t index = 0; index < bearer_cntr; index++){ bearer = bearers[index]; if(bearer != NULL) { for(uint8_t itr = 0; itr < bearer->pdr_count ; itr++) { pdr_ctxt = bearer->pdrs[itr]; if(pdr_ctxt){ set_remove_pdr(&(pfcp_sess_mod_req->remove_pdr[pfcp_sess_mod_req->remove_pdr_count]), pdr_ctxt->rule_id); pfcp_sess_mod_req->remove_pdr_count++; } } } bearer = NULL; } } void fill_pfcp_sess_mod_req_pgw_init_remove_pdr(pfcp_sess_mod_req_t *pfcp_sess_mod_req, pdn_connection *pdn, eps_bearer *bearers[], uint8_t bearer_cntr) { int ret = 0; uint32_t seq = 0; eps_bearer *bearer = NULL; pdr_t *pdr_ctxt = NULL; upf_context_t *upf_ctx = NULL; node_address_t node_value = {0}; if ((ret = upf_context_entry_lookup(pdn->upf_ip, &upf_ctx)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error while extracting " "upf context: %d \n", LOG_VALUE, ret); return; } memset(pfcp_sess_mod_req, 0, sizeof(pfcp_sess_mod_req_t)); seq = get_pfcp_sequence_number(PFCP_SESSION_MODIFICATION_REQUEST, seq); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_mod_req->header), PFCP_SESSION_MODIFICATION_REQUEST, HAS_SEID, seq, pdn->context->cp_mode); pfcp_sess_mod_req->header.seid_seqno.has_seid.seid = pdn->dp_seid; /*Filling Node ID for F-SEID*/ if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV4) { uint8_t temp[IPV6_ADDRESS_LEN] = {0}; ret = fill_ip_addr(config.pfcp_ip.s_addr, temp, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV6) { ret = fill_ip_addr(0, config.pfcp_ip_v6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } set_fseid(&(pfcp_sess_mod_req->cp_fseid), pdn->seid, node_value); pfcp_sess_mod_req->remove_pdr_count = 0; for (uint8_t index = 0; index < bearer_cntr; index++){ bearer = bearers[index]; if(bearer != NULL) { for(uint8_t itr = 0; itr < bearer->pdr_count ; itr++) { pdr_ctxt = bearer->pdrs[itr]; if(pdr_ctxt){ set_remove_pdr(&(pfcp_sess_mod_req->remove_pdr[pfcp_sess_mod_req->remove_pdr_count]), pdr_ctxt->rule_id); pfcp_sess_mod_req->remove_pdr_count++; } } } bearer = NULL; } } uint8_t process_pfcp_sess_mod_resp_handover(uint64_t sess_id, gtpv2c_header_t *gtpv2c_tx, ue_context *context) { int ret = 0; int ebi_index = 0; eps_bearer *bearer = NULL; struct resp_info *resp = NULL; uint32_t teid = UE_SESS_ID(sess_id); /* Retrive the session information based on session id. */ if (get_sess_entry(sess_id, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, sess_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Update the session state */ resp->state = PFCP_SESS_MOD_RESP_RCVD_STATE; ebi_index = GET_EBI_INDEX(resp->eps_bearer_ids[0]); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } /* Update the UE state */ ret = update_ue_state(context, PFCP_SESS_MOD_RESP_RCVD_STATE ,ebi_index); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to update UE " "State\n", LOG_VALUE, context->pdns[ebi_index]->s5s8_pgw_gtpc_teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } bearer = context->eps_bearers[ebi_index]; if (!bearer) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get " "bearer for teid: %u\n", LOG_VALUE, teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Fill the modify bearer response */ set_modify_bearer_response_handover(gtpv2c_tx, context->sequence, context, bearer, &resp->gtpc_msg.mbr); /* Update the session state */ resp->state = CONNECTED_STATE; bearer->pdn->state = CONNECTED_STATE; /* Update the UE state */ ret = update_ue_state(context, CONNECTED_STATE, ebi_index); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to update UE " "State for ebi_index : %d \n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } ret = set_dest_address(bearer->pdn->s5s8_sgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"s5s8_recv_sockaddr.sin_addr.s_addr :%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&s5s8_recv_sockaddr.ipv4.sin_addr.s_addr))); return 0; } int process_pfcp_sess_mod_resp_cs_cbr_request(uint64_t sess_id, gtpv2c_header_t *gtpv2c_tx, struct resp_info *resp) { int ret = 0; int ebi_index = 0; eps_bearer *bearer = NULL; ue_context *context = NULL; pdn_connection *pdn = NULL; uint32_t teid = UE_SESS_ID(sess_id); gtpv2c_header_t *gtpv2c_cbr_t = NULL; uint16_t msg_len = 0; /* Retrive the session information based on session id. */ if (get_sess_entry(sess_id, &resp) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, sess_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Update the session state */ resp->state = PFCP_SESS_MOD_RESP_RCVD_STATE; /* Retrieve the UE context */ ret = get_ue_context(teid, &context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to update UE " "State for teid: %u\n", LOG_VALUE, teid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } int ebi = UE_BEAR_ID(sess_id); ebi_index = GET_EBI_INDEX(ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[ebi_index]; /* Update the UE state */ pdn = GET_PDN(context, ebi_index); if(pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get pdn " "for ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn->state = PFCP_SESS_MOD_RESP_RCVD_STATE; if (resp->msg_type == GTP_MODIFY_BEARER_REQ) { /*send mbr resp to mme and create brearer resp to pgw*/ if (resp->gtpc_msg.mbr.bearer_count) { msg_len = set_modify_bearer_response(gtpv2c_tx, context->sequence, context, bearer, &resp->gtpc_msg.mbr); ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } if((context->piggyback == TRUE) && (context->cp_mode == SAEGWC)) { int index = GET_EBI_INDEX(resp->eps_bearer_ids[0]); if (index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } provision_ack_ccr(pdn, context->eps_bearers[index], RULE_ACTION_ADD, NO_FAIL); return 0; } if ((SAEGWC == context->cp_mode) ) { if (config.use_gx) { rar_funtions rar_function = NULL; rar_function = rar_process(pdn, pdn->proc); if (rar_function != NULL) { ret = rar_function(pdn); if(ret) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed in processing" "RAR function\n", LOG_VALUE); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"None of the RAR function " "returned\n", LOG_VALUE); } update_cli_stats((peer_address_t *) &config.gx_ip, OSS_RAA, SENT, GX); resp->state = pdn->state; return 0; } } else { int ebi_index = GET_EBI_INDEX(resp->eps_bearer_ids[0]); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[ebi_index]; gtpv2c_cbr_t = (gtpv2c_header_t *)((uint8_t *)gtpv2c_tx + msg_len); set_create_bearer_response( gtpv2c_cbr_t, resp->cbr_seq, pdn, resp->linked_eps_bearer_id, 0, resp); resp->state = CONNECTED_STATE; pdn->state = CONNECTED_STATE; ret = set_dest_address(pdn->s5s8_pgw_gtpc_ip, &s5s8_recv_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } return 0; } } else { /* Fill the create session response */ msg_len = set_create_session_response( gtpv2c_tx, context->sequence, context, bearer->pdn, 1); gtpv2c_cbr_t = (gtpv2c_header_t *)((uint8_t *)gtpv2c_tx + msg_len); uint8_t seq_no = resp->gtpc_msg.cb_req.header.teid.has_teid.seq; /* Fill the Create bearer request*/ ret = set_create_bearer_request(gtpv2c_cbr_t, seq_no, pdn, pdn->default_bearer_id, 0, resp, 0, TRUE); ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } resp->state = CREATE_BER_REQ_SNT_STATE; pdn->state = CREATE_BER_REQ_SNT_STATE; pdn->csr_sequence = 0; if (context->piggyback && SGWC == context->cp_mode) { uint32_t payload_len = ntohs(gtpv2c_cbr_t->gtpc.message_len) + sizeof(gtpv2c_cbr_t->gtpc); /* handle piggybacked msg case */ resp->msg_type = GTP_CREATE_SESSION_REQ; add_gtpv2c_if_timer_entry( teid, &s11_mme_sockaddr, (uint8_t *)gtpv2c_cbr_t, payload_len, ebi_index, S11_IFACE, context->cp_mode); } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"s5s8_recv_sockaddr.sin_addr.s_addr :%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&s5s8_recv_sockaddr.ipv4.sin_addr.s_addr))); return 0; } int8_t check_if_bearer_index_free(ue_context *context, int ebi_index) { if (!(context->bearer_bitmap & (1 << ebi_index))) { return -1; } return 0; } int8_t get_new_bearer_id(pdn_connection *pdn_cntxt) { int ret = 0; int bearer_id = pdn_cntxt->num_bearer; for(uint8_t icnt = pdn_cntxt->num_bearer; icnt< MAX_BEARERS; icnt++){ ret = check_if_bearer_index_free(pdn_cntxt->context, bearer_id); if(ret == 0){ return bearer_id; } else { bearer_id++; continue; } } clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } void send_pfcp_sess_mod_req_for_li(uint64_t imsi) { int ret = 0; uint32_t seq = 0; uint8_t ebi_index = 0; pdr_t *pdr_ctxt = NULL; eps_bearer *bearer = NULL; ue_context *context = NULL; pdn_connection *pdn = NULL; upf_context_t *upf_ctx = NULL; pfcp_sess_mod_req_t pfcp_sess_mod_req; imsi_id_hash_t *imsi_id_config = NULL; node_address_t node_value = {0}; ret = rte_hash_lookup_data(ue_context_by_imsi_hash, &imsi, (void **) &(context)); if (ret == -ENOENT){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"No data found for %x imsi\n" , LOG_VALUE, imsi); return; } if (NULL == context) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "UE context is NULL\n", LOG_VALUE); /* Ue is not attach yet, so no need to send modification request */ return; } /* get user level packet copying token or id using imsi */ ret = get_id_using_imsi(context->imsi, &imsi_id_config); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Not applicable for li\n", LOG_VALUE); if (PRESENT == context->dupl) { context->dupl = NOT_PRESENT; context->li_data_cntr = 0; memset(context->li_data, 0, MAX_LI_ENTRIES_PER_UE * sizeof(li_data_t)); } else { return; } } if (NULL != imsi_id_config) { /* Fillup context from li hash */ fill_li_config_in_context(context, imsi_id_config); } for (uint8_t bearerCntr = 0; bearerCntr < MAX_BEARERS; bearerCntr++) { if (NULL == context->eps_bearers[bearerCntr]) { continue; } bearer = context->eps_bearers[bearerCntr]; pdn = bearer->pdn; if ((ret = upf_context_entry_lookup(pdn->upf_ip, &upf_ctx)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Lookup of upf %d \n", LOG_VALUE, ret); return; } memset(&pfcp_sess_mod_req, 0, sizeof(pfcp_sess_mod_req_t)); seq = get_pfcp_sequence_number(PFCP_SESSION_MODIFICATION_REQUEST, seq); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_mod_req.header), PFCP_SESSION_MODIFICATION_REQUEST, HAS_SEID, seq, context->cp_mode); pfcp_sess_mod_req.header.seid_seqno.has_seid.seid = pdn->dp_seid; /*Filling Node ID for F-SEID*/ if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV4) { uint8_t temp[IPV6_ADDRESS_LEN] = {0}; ret = fill_ip_addr(config.pfcp_ip.s_addr, temp, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } else if (pdn->upf_ip.ip_type == PDN_IP_TYPE_IPV6) { ret = fill_ip_addr(0, config.pfcp_ip_v6.s6_addr, &node_value); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } set_fseid(&(pfcp_sess_mod_req.cp_fseid), pdn->seid, node_value); pfcp_sess_mod_req.update_far_count = NOT_PRESENT; for(uint8_t itr = 0; itr < bearer->pdr_count ; itr++) { pdr_ctxt = bearer->pdrs[itr]; if (pdr_ctxt) { set_update_far(&(pfcp_sess_mod_req.update_far[pfcp_sess_mod_req.update_far_count]), NULL); pfcp_sess_mod_req.update_far[pfcp_sess_mod_req.update_far_count].far_id.far_id_value = pdr_ctxt->far.far_id_value; pfcp_sess_mod_req.update_far[pfcp_sess_mod_req.update_far_count].apply_action.dupl = GET_DUP_STATUS(pdn->context); pfcp_sess_mod_req.update_far[pfcp_sess_mod_req.update_far_count].apply_action.forw = PRESENT; if (PRESENT == pfcp_sess_mod_req.update_far[pfcp_sess_mod_req.update_far_count].apply_action.dupl) { update_li_info_in_upd_dup_params(imsi_id_config, context, &(pfcp_sess_mod_req.update_far[pfcp_sess_mod_req.update_far_count])); } pfcp_sess_mod_req.update_far_count++; } } } uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr, SENT) < 0 ){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error sending: %i\n", LOG_VALUE, errno); } else { add_pfcp_if_timer_entry(context->s11_sgw_gtpc_teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); } } uint8_t fill_li_policy(uint8_t *li_policy, li_df_config_t *li_config, uint8_t cp_mode) { switch(cp_mode) { case SGWC: { if ((SX_COPY_DP_MSG == li_config->uiSxa) || (SX_COPY_CP_DP_MSG == li_config->uiSxa)) { li_policy[FRWDING_PLCY_SX] = PRESENT; } else { li_policy[FRWDING_PLCY_SX] = NOT_PRESENT; } li_policy[FRWDING_PLCY_WEST_DIRECTION] = li_config->uiS1u; li_policy[FRWDING_PLCY_WEST_CONTENT] = li_config->uiS1uContent; li_policy[FRWDING_PLCY_EAST_DIRECTION] = li_config->uiSgwS5s8U; li_policy[FRWDING_PLCY_EAST_CONTENT] = li_config->uiSgwS5s8UContent; break; } case PGWC: { if ((SX_COPY_DP_MSG == li_config->uiSxb) || (SX_COPY_CP_DP_MSG == li_config->uiSxb)) { li_policy[FRWDING_PLCY_SX] = PRESENT; } else { li_policy[FRWDING_PLCY_SX] = NOT_PRESENT; } li_policy[FRWDING_PLCY_WEST_DIRECTION] = li_config->uiPgwS5s8U; li_policy[FRWDING_PLCY_WEST_CONTENT] = li_config->uiPgwS5s8UContent; li_policy[FRWDING_PLCY_EAST_DIRECTION] = li_config->uiSgi; li_policy[FRWDING_PLCY_EAST_CONTENT] = li_config->uiSgiContent; break; } case SAEGWC: { if ((SX_COPY_DP_MSG == li_config->uiSxaSxb) || (SX_COPY_CP_DP_MSG == li_config->uiSxaSxb)) { li_policy[FRWDING_PLCY_SX] = PRESENT; } else { li_policy[FRWDING_PLCY_SX] = NOT_PRESENT; } li_policy[FRWDING_PLCY_WEST_DIRECTION] = li_config->uiS1u; li_policy[FRWDING_PLCY_WEST_CONTENT] = li_config->uiS1uContent; li_policy[FRWDING_PLCY_EAST_DIRECTION] = li_config->uiSgi; li_policy[FRWDING_PLCY_EAST_CONTENT] = li_config->uiSgiContent; break; } } li_policy[FRWDING_PLCY_FORWARD] = li_config->uiForward; memcpy(&li_policy[FRWDING_PLCY_ID], &li_config->uiId, sizeof(uint64_t)); return (FRWDING_PLCY_ID + sizeof(uint64_t)); } int update_li_info_in_dup_params(imsi_id_hash_t *imsi_id_config, ue_context *context, pfcp_create_far_ie_t *far) { int ret = 0; int dup_cntr = 0; uint8_t li_policy_len = 0; li_df_config_t *li_config = NULL; uint8_t li_policy[MAX_LI_POLICY_LIMIT] = {0}; for (uint8_t cnt = 0; cnt < imsi_id_config->cntr; cnt++) { ret = get_li_config(imsi_id_config->ids[cnt], &li_config); if (!ret) { context->dupl = PRESENT; far->apply_action.dupl = GET_DUP_STATUS(context); if (far->apply_action.dupl == PRESENT) { li_policy_len = fill_li_policy(li_policy, li_config, context->cp_mode); uint16_t len = fill_dup_param(&(far->dupng_parms[dup_cntr]), li_policy, li_policy_len); far->header.len += len; dup_cntr++; } } } far->dupng_parms_count = dup_cntr; return 0; } int update_li_info_in_upd_dup_params(imsi_id_hash_t *imsi_id_config, ue_context *context, pfcp_update_far_ie_t *far) { int ret = 0; int dup_cntr = 0; uint8_t li_policy_len = 0; li_df_config_t *li_config = NULL; uint8_t li_policy[MAX_LI_POLICY_LIMIT] = {0}; for (uint8_t cnt = 0; cnt < imsi_id_config->cntr; cnt++) { ret = get_li_config(imsi_id_config->ids[cnt], &li_config); if (!ret) { context->dupl = PRESENT; far->apply_action.dupl = GET_DUP_STATUS(context); if (far->apply_action.dupl == PRESENT) { li_policy_len = fill_li_policy(li_policy, li_config, context->cp_mode); uint16_t len = fill_upd_dup_param(&(far->upd_dupng_parms[dup_cntr]), li_policy, li_policy_len); far->header.len += len; dup_cntr++; } } } far->upd_dupng_parms_count = dup_cntr; return 0; } int process_pfcp_sess_setup(pdn_connection *pdn) { int ebi_index = 0; int ret = 0; uint8_t index = 0; upf_context_t *upf_context = NULL; struct resp_info *resp = NULL; /* Retrive EBI index from Default EBI */ ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return -1; } ret = process_pfcp_assoication_request(pdn, ebi_index); if (ret) { if(ret != -1) { send_error_resp(pdn, ret); } clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure in Processing " "PFCP Association Request with cause %s \n", LOG_VALUE, cause_str(ret)); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Added UPF Entry for IP Type : %s\n" "with IP IPv4 : "IPV4_ADDR"\tIPv6 : "IPv6_FMT"", LOG_VALUE, ip_type_str(pdn->upf_ip.ip_type), IPV4_ADDR_HOST_FORMAT(pdn->upf_ip.ipv4_addr), PRINT_IPV6_ADDR(pdn->upf_ip.ipv6_addr)); /* Retrive association state based on UPF IP. */ ret = rte_hash_lookup_data(upf_context_by_ip_hash, (const void*) &(pdn->upf_ip), (void **) &(upf_context)); /* send error response in case of pfcp est. fail using this data */ if(upf_context->state == PFCP_ASSOC_RESP_RCVD_STATE) { ret = get_sess_entry(pdn->seid, &resp); if(ret != -1 && resp != NULL){ if(pdn->context->cp_mode == PGWC) { resp->gtpc_msg.csr.sender_fteid_ctl_plane.teid_gre_key = pdn->s5s8_sgw_gtpc_teid; resp->gtpc_msg.csr.header.teid.has_teid.teid = pdn->s5s8_pgw_gtpc_teid; } if(pdn->context->cp_mode == SAEGWC || pdn->context->cp_mode == SGWC) { resp->gtpc_msg.csr.sender_fteid_ctl_plane.teid_gre_key = pdn->context->s11_mme_gtpc_teid; resp->gtpc_msg.csr.header.teid.has_teid.teid = pdn->context->s11_sgw_gtpc_teid; } resp->gtpc_msg.csr.header.teid.has_teid.seq = pdn->context->sequence; for (uint8_t itr = 0; itr < MAX_BEARERS; ++itr) { if(pdn->eps_bearers[itr] != NULL){ resp->gtpc_msg.csr.bearer_contexts_to_be_created[index].header.len = sizeof(uint8_t) + IE_HEADER_SIZE; resp->gtpc_msg.csr.bearer_contexts_to_be_created[index].eps_bearer_id.ebi_ebi = pdn->context->eps_bearers[itr]->eps_bearer_id; index++; } } resp->gtpc_msg.csr.bearer_count = index; } } return 0; } int provision_ack_ccr(pdn_connection *pdn, eps_bearer *bearer, enum rule_action_t rule_action, enum rule_failure_code error_code) { /* Initialize the Gx Parameters */ int ret = 0; int ebi_index = 0; uint16_t msg_len = 0; uint8_t *buffer = NULL; gx_msg ccr_request = {0}; gx_context_t *gx_context = NULL; if (bearer == NULL) return -1; ret = rte_hash_lookup_data(gx_context_by_sess_id_hash, (const void*)(pdn->gx_sess_id), (void **)&gx_context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" NO ENTRY FOUND " "IN Gx HASH [%s]\n", LOG_VALUE,pdn->gx_sess_id); return -1; } /* Set the Msg header type for CCR */ ccr_request.msg_type = GX_CCR_MSG ; /* Set Credit Control Request type */ ccr_request.data.ccr.presence.cc_request_type = PRESENT; ccr_request.data.ccr.cc_request_type = UPDATE_REQUEST ; ccr_request.data.ccr.presence.network_request_support = PRESENT; ccr_request.data.ccr.network_request_support = NETWORK_REQUEST_SUPPORTED; ccr_request.data.ccr.presence.charging_rule_report = PRESENT; ccr_request.data.ccr.charging_rule_report.count = pdn->pro_ack_rule_array.rule_cnt; ccr_request.data.ccr.charging_rule_report.list = rte_malloc_socket(NULL, (sizeof(GxChargingRuleReport)*(pdn->pro_ack_rule_array.rule_cnt)), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request.data.ccr.charging_rule_report.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule report information avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } for(int id = 0; id < pdn->pro_ack_rule_array.rule_cnt; id++) { memset(&ccr_request.data.ccr.charging_rule_report.list[id].presence, 0 , sizeof(ccr_request.data.ccr.charging_rule_report.list[id].presence)); ccr_request.data.ccr.charging_rule_report.list[id].presence.charging_rule_name = PRESENT; ccr_request.data.ccr.charging_rule_report.list[id].charging_rule_name.count = 1; ccr_request.data.ccr.charging_rule_report.list[id].charging_rule_name.list = rte_malloc_socket(NULL,(sizeof(GxChargingRuleNameOctetString)*1), RTE_CACHE_LINE_SIZE, rte_socket_id()); if(ccr_request.data.ccr.charging_rule_report.list[id].charging_rule_name.list == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to" "allocate memory for Charging rule name avp : %s", LOG_VALUE, rte_strerror(rte_errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } ccr_request.data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].len = strlen(pdn->pro_ack_rule_array.rule[id].rule_name); memcpy(&ccr_request.data.ccr.charging_rule_report.list[id].charging_rule_name.list[0].val, pdn->pro_ack_rule_array.rule[id].rule_name, strlen(pdn->pro_ack_rule_array.rule[id].rule_name)); ccr_request.data.ccr.charging_rule_report.list[id].presence. pcc_rule_status = PRESENT; if (error_code != 0 || rule_action == RULE_ACTION_DELETE ) { ccr_request.data.ccr.charging_rule_report.list[id]. pcc_rule_status = INACTIVE; } else { ccr_request.data.ccr.charging_rule_report.list[id]. pcc_rule_status = pdn->pro_ack_rule_array.rule[id].rule_status; } if(error_code != 0) { ccr_request.data.ccr.charging_rule_report.list[id].presence.rule_failure_code = PRESENT; ccr_request.data.ccr.charging_rule_report.list[id].rule_failure_code = error_code; } } uint8_t evnt_tigger_list[EVENT_TRIGGER_LIST] = {0}; ccr_request.data.ccr.event_trigger.count = 0; /*Event-Trigger will send for succesful operation */ if (error_code == 0) { if (rule_action == RULE_ACTION_ADD || rule_action == RULE_ACTION_MODIFY) { ccr_request.data.ccr.presence.event_trigger = PRESENT; evnt_tigger_list[ccr_request.data.ccr.event_trigger.count++] = SUCCESSFUL_RESOURCE_ALLOCATION; } else { ccr_request.data.ccr.presence.event_trigger = PRESENT; evnt_tigger_list[ccr_request.data.ccr.event_trigger.count++] = RESOURCE_RELEASE; } } ccr_request.data.ccr.event_trigger.list = (int32_t *) rte_malloc_socket(NULL, (ccr_request.data.ccr.event_trigger.count * sizeof(int32_t)), RTE_CACHE_LINE_SIZE, rte_socket_id()); for(uint8_t count = 0; count < ccr_request.data.ccr.event_trigger.count; count++ ) { *(ccr_request.data.ccr.event_trigger.list + count) = evnt_tigger_list[count]; } char *temp = inet_ntoa(pdn->uipaddr.ipv4); memcpy(ccr_request.data.ccr.framed_ip_address.val, &temp, strnlen(temp,(GX_FRAMED_IP_ADDRESS_LEN + 1))); ebi_index = GET_EBI_INDEX(bearer->eps_bearer_id); if(ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid" "ebi_index ", LOG_VALUE); return -1; } /* Fill the Credit Crontrol Request to send PCRF */ if(fill_ccr_request(&ccr_request.data.ccr, pdn->context, ebi_index, pdn->gx_sess_id, 0) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed CCR request " "filling process\n", LOG_VALUE); return -1; } update_cli_stats((peer_address_t *) &config.gx_ip, OSS_CCR_UPDATE, SENT, GX); /* Update UE State */ pdn->state = PROVISION_ACK_SNT_STATE; /* Set the Gx State for events */ gx_context->state = PROVISION_ACK_SNT_STATE; /* Set the Gx State for events */ gx_context->state = PROVISION_ACK_SNT_STATE; gx_context->proc = pdn->proc; /*Clear pti and ue_initiated_seq_no*/ pdn->context->proc_trans_id = 0; pdn->context->ue_initiated_seq_no = 0; /* Calculate the max size of CCR msg to allocate the buffer */ msg_len = gx_ccr_calc_length(&ccr_request.data.ccr); ccr_request.msg_len = msg_len + GX_HEADER_LEN; buffer = rte_zmalloc_socket(NULL, msg_len + GX_HEADER_LEN, RTE_CACHE_LINE_SIZE, rte_socket_id()); if (buffer == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Failure to allocate CCR Buffer" " memory structure: %s\n", LOG_VALUE, rte_strerror(rte_errno)); return -1; } /* Fill the CCR header values */ memcpy(buffer, &ccr_request.msg_type, sizeof(ccr_request.msg_type)); memcpy(buffer + sizeof(ccr_request.msg_type), &ccr_request.msg_len, sizeof(ccr_request.msg_len)); if (gx_ccr_pack(&(ccr_request.data.ccr), (unsigned char *)(buffer + GX_HEADER_LEN), msg_len) == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERROR in Packing CCR " "Buffer\n", LOG_VALUE); rte_free(buffer); return -1; } send_to_ipc_channel(gx_app_sock, buffer, msg_len + GX_HEADER_LEN); rte_free(buffer); free_dynamically_alloc_memory(&ccr_request); memset(&pdn->pro_ack_rule_array, 0, sizeof(pro_ack_rule_array_t)); return 0; } void reset_resp_info_structure(struct resp_info *resp) { if (resp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Response received is " "NULL\n", LOG_VALUE); return; } resp->proc = NONE_PROC; resp->state = SGWC_NONE_STATE; resp->linked_eps_bearer_id = 0; for(uint8_t iterator = 0 ; iterator <resp->bearer_count; iterator++){ resp->eps_bearer_ids[iterator] = 0; } resp->bearer_count = 0; if(resp->gtpc_msg.csr.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.csr, 0, sizeof(create_sess_req_t)); } else if(resp->gtpc_msg.cs_rsp.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.cs_rsp, 0, sizeof(create_sess_rsp_t)); } else if(resp->gtpc_msg.mbr.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.mbr, 0, sizeof(mod_bearer_req_t)); } else if(resp->gtpc_msg.cb_req.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.cb_req, 0, sizeof(create_bearer_req_t)); } else if(resp->gtpc_msg.cb_rsp.header.gtpc.message_len != 0) { memset((void*)&resp->gtpc_msg.cb_rsp, 0, sizeof(create_bearer_rsp_t)); } else if(resp->gtpc_msg.dsr.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.dsr, 0, sizeof(del_sess_req_t)); } else if(resp->gtpc_msg.rel_acc_ber_req.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.rel_acc_ber_req, 0, sizeof(rel_acc_ber_req_t)); } else if(resp->gtpc_msg.del_bearer_cmd.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.del_bearer_cmd, 0, sizeof(del_bearer_cmd_t)); } else if(resp->gtpc_msg.bearer_rsrc_cmd.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.bearer_rsrc_cmd, 0, sizeof(bearer_rsrc_cmd_t)); } else if(resp->gtpc_msg.change_not_req.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.change_not_req, 0, sizeof(change_noti_req_t)); } else if(resp->gtpc_msg.db_req.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.db_req, 0, sizeof(del_bearer_req_t)); } else if(resp->gtpc_msg.ub_req.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.ub_req, 0, sizeof(upd_bearer_req_t)); } else if(resp->gtpc_msg.ub_rsp.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.ub_rsp, 0, sizeof(upd_bearer_rsp_t)); } else if(resp->gtpc_msg.upd_req.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.upd_req, 0, sizeof(upd_pdn_conn_set_req_t)); } else if(resp->gtpc_msg.upd_rsp.header.gtpc.message_len != 0) { memset((void *)&resp->gtpc_msg.upd_rsp, 0, sizeof(upd_pdn_conn_set_rsp_t)); } } #endif #ifdef DP_BUILD void fill_pfcp_sess_set_del_resp(pfcp_sess_set_del_rsp_t *pfcp_sess_set_del_resp) { /*take seq no from set del request when it is implemented*/ uint32_t seq = 1; uint32_t node_value = 0 ; memset(pfcp_sess_set_del_resp, 0, sizeof(pfcp_sess_set_del_rsp_t)); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_set_del_resp->header), PFCP_SESSION_SET_DELETION_RESPONSE, NO_SEID, seq); set_node_id(&(pfcp_sess_set_del_resp->node_id), node_value); // TODO : REmove the CAUSE_VALUES_REQUESTACCEPTEDSUCCESS in set_cause set_cause(&(pfcp_sess_set_del_resp->cause), REQUESTACCEPTED); //TODO Replace IE_NODE_ID with the real offendID set_offending_ie(&(pfcp_sess_set_del_resp->offending_ie), PFCP_IE_NODE_ID ); } void fill_pfcp_sess_del_resp(pfcp_sess_del_rsp_t * pfcp_sess_del_resp, uint8_t cause, int offend) { uint32_t seq = 1; set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_del_resp->header), PFCP_SESSION_DELETION_RESPONSE, HAS_SEID, seq); set_cause(&(pfcp_sess_del_resp->cause), cause); if(cause == CONDITIONALIEMISSING || cause == MANDATORYIEMISSING) { set_offending_ie(&(pfcp_sess_del_resp->offending_ie), offend); } if( pfcp_ctxt.cp_supported_features & CP_LOAD ) set_lci(&(pfcp_sess_del_resp->load_ctl_info)); if( pfcp_ctxt.cp_supported_features & CP_OVRL ) set_olci(&(pfcp_sess_del_resp->ovrld_ctl_info)); } void fill_pfcp_session_modify_resp(pfcp_sess_mod_rsp_t *pfcp_sess_modify_resp, pfcp_sess_mod_req_t *pfcp_session_mod_req, uint8_t cause, int offend) { uint32_t seq = 1; memset(pfcp_sess_modify_resp, 0, sizeof(pfcp_sess_mod_rsp_t)); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_modify_resp->header), PFCP_SESSION_MODIFICATION_RESPONSE, HAS_SEID, seq); set_cause(&(pfcp_sess_modify_resp->cause), cause); if(cause == CONDITIONALIEMISSING || cause == MANDATORYIEMISSING) { set_offending_ie(&(pfcp_sess_modify_resp->offending_ie), offend); } //created_bar // Need to do if(cause == REQUESTACCEPTED){ if(pfcp_session_mod_req->create_pdr_count > 0 && pfcp_session_mod_req->create_pdr[0].pdi.local_fteid.ch){ set_created_pdr_ie(&(pfcp_sess_modify_resp->created_pdr)); } } if( pfcp_ctxt.cp_supported_features & CP_LOAD ) set_lci(&(pfcp_sess_modify_resp->load_ctl_info)); if( pfcp_ctxt.cp_supported_features & CP_OVRL ) set_olci(&(pfcp_sess_modify_resp->ovrld_ctl_info)); if(cause == RULECREATION_MODIFICATIONFAILURE){ set_failed_rule_id(&(pfcp_sess_modify_resp->failed_rule_id)); } } void fill_pfcp_session_est_resp(pfcp_sess_estab_rsp_t *pfcp_sess_est_resp, uint8_t cause, int offend, struct in_addr dp_comm_ip, pfcp_sess_estab_req_t *pfcp_session_request) { uint32_t seq = 0; uint32_t node_value = 0; set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_est_resp->header), PFCP_SESSION_ESTABLISHMENT_RESPONSE, HAS_SEID, seq); set_node_id(&(pfcp_sess_est_resp->node_id), node_value); set_cause(&(pfcp_sess_est_resp->cause), cause); if(cause == CONDITIONALIEMISSING || cause == MANDATORYIEMISSING) { set_offending_ie(&(pfcp_sess_est_resp->offending_ie), offend); } if(REQUESTACCEPTED == cause) { uint64_t up_seid = pfcp_session_request->header.seid_seqno.has_seid.seid;; set_fseid(&(pfcp_sess_est_resp->up_fseid), up_seid, node_value); } if(pfcp_ctxt.cp_supported_features & CP_LOAD) { set_lci(&(pfcp_sess_est_resp->load_ctl_info)); } if(pfcp_ctxt.cp_supported_features & CP_OVRL) { set_olci(&(pfcp_sess_est_resp->ovrld_ctl_info)); } if(RULECREATION_MODIFICATIONFAILURE == cause) { set_failed_rule_id(&(pfcp_sess_est_resp->failed_rule_id)); } } #endif /* DP_BUILD */ int check_pckt_fltr_id_in_rule(uint8_t pckt_id, eps_bearer *bearer) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Received pckt_id : %d\n", LOG_VALUE, pckt_id); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"bearer->num_dynamic_filters : %d\n", LOG_VALUE, bearer->num_dynamic_filters); for( int rule_cnt = 0; rule_cnt < bearer->num_dynamic_filters; rule_cnt++) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"bearer->dynaic_rules[%d].num_flw_desc : %d\n", LOG_VALUE, rule_cnt, bearer->dynamic_rules[rule_cnt]->num_flw_desc); for( int pckt_cnt = 0; pckt_cnt < bearer->dynamic_rules[rule_cnt]->num_flw_desc; pckt_cnt++) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"bearer->dynamic_rules[%d].flow_desc[%d].pckt_fltr_identifier : %d\n", LOG_VALUE, rule_cnt, pckt_cnt, bearer->dynamic_rules[rule_cnt]->flow_desc[pckt_cnt].pckt_fltr_identifier); if(pckt_id == bearer->dynamic_rules[rule_cnt]->flow_desc[pckt_cnt].pckt_fltr_identifier) { return rule_cnt; } } } return -1; } int check_default_bearer_id_presence_in_ue(uint8_t bearer_id, ue_context *context) { if(context != NULL) { for (int pdn_cnt = 0; pdn_cnt < MAX_BEARERS; pdn_cnt++) { if(context->pdns[pdn_cnt] != NULL) { if(context->pdns[pdn_cnt]->default_bearer_id == bearer_id) return 0; } } } else { return -1; } return -1; } int check_ebi_presence_in_ue(uint8_t bearer_id, ue_context *context) { if(context != NULL) { for (int bearer_cnt = 0; bearer_cnt < MAX_BEARERS; bearer_cnt++) { if(context->eps_bearers[bearer_cnt] != NULL) { if(context->eps_bearers[bearer_cnt]->eps_bearer_id == bearer_id) return 0; } } } else { return -1; } return -1; } int process_pfcp_mod_req_modify_access_req(mod_acc_bearers_req_t *mod_acc_req) { int ret = 0; int ebi_index = 0; uint8_t send_endmarker = 0; ue_context *context = NULL; eps_bearer *bearer = NULL, *bearers[MAX_BEARERS] ={NULL}; pdn_connection *pdn = NULL; struct resp_info *resp = NULL; pfcp_sess_mod_req_t pfcp_sess_mod_req = {0}; pfcp_update_far_ie_t update_far[MAX_LIST_SIZE] = {0}; ret = rte_hash_lookup_data(ue_context_by_fteid_hash, (const void *) &mod_acc_req->header.teid.has_teid.teid, (void **) &context); if (ret < 0 || !context) return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; pfcp_sess_mod_req.update_far_count = 0; for(uint8_t i = 0; i < mod_acc_req->bearer_modify_count; i++) { if (!mod_acc_req->bearer_contexts_to_be_modified[i].eps_bearer_id.header.len ||( !mod_acc_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.header.len && !mod_acc_req->bearer_contexts_to_be_modified[i].s11_u_mme_fteid.header.len)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Bearer Context not " "found for Modify Bearer Request, Dropping packet\n", LOG_VALUE); return GTPV2C_CAUSE_INVALID_LENGTH; } ebi_index = GET_EBI_INDEX(mod_acc_req->bearer_contexts_to_be_modified[i].eps_bearer_id.ebi_ebi); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } if (!(context->bearer_bitmap & (1 << ebi_index))) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Received modify bearer on non-existent EBI - " "for while PFCP Session Modification Request Modify Bearer " "Request, Dropping packet\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } bearer = context->eps_bearers[ebi_index]; context->eps_bearers[ebi_index] = bearer; if (!bearer) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Received modify bearer on non-existent EBI - " "for while PFCP Session Modification Request Modify Bearer " "Request, Dropping packet\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } pdn = bearer->pdn; /* Delete the timer entry for UE LEVEL timer if already present */ delete_ddn_timer_entry(timer_by_teid_hash, mod_acc_req->header.teid.has_teid.teid, ddn_by_seid_hash); /* Delete the timer entry for buffer report request messages based on dl buffer timer if present*/ delete_ddn_timer_entry(dl_timer_by_teid_hash, mod_acc_req->header.teid.has_teid.teid, pfcp_rep_by_seid_hash); /* Remove the session from throttling timer */ delete_sess_in_thrtl_timer(context, pdn->seid); if(mod_acc_req->delay_dnlnk_pckt_notif_req.header.len){ if(mod_acc_req->delay_dnlnk_pckt_notif_req.delay_value > 0){ /* Start ue level timer with the assgined delay */ /* As per spec. Delay Downlink packet notification * timer value range in between 1 - 255 and * value should be multiple of 50 */ start_ddn_timer_entry(timer_by_teid_hash, pdn->seid, (mod_acc_req->delay_dnlnk_pckt_notif_req.delay_value * 50), ddn_timer_callback); } } bearer->eps_bearer_id = mod_acc_req->bearer_contexts_to_be_modified[i].eps_bearer_id.ebi_ebi; if(mod_acc_req->indctn_flgs.indication_s11tf) { /* Set the indication flag for s11-u teid */ context->indication_flag.s11tf = 1; ret = fill_ip_addr(mod_acc_req->bearer_contexts_to_be_modified[i].s11_u_mme_fteid.ipv4_address, mod_acc_req->bearer_contexts_to_be_modified[i].s11_u_mme_fteid.ipv6_address, &bearer->s11u_mme_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s11u_mme_gtpu_teid = mod_acc_req->bearer_contexts_to_be_modified[i].s11_u_mme_fteid.teid_gre_key; update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.teid = bearer->s11u_mme_gtpu_teid; ret = set_node_address(&update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv6_address, bearer->s11u_mme_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value = check_interface_type(mod_acc_req->bearer_contexts_to_be_modified[i].s11_u_mme_fteid.interface_type, context->cp_mode); update_far[pfcp_sess_mod_req.update_far_count].far_id.far_id_value = get_far_id(bearer, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value); update_far[pfcp_sess_mod_req.update_far_count].apply_action.forw = PRESENT; update_far[pfcp_sess_mod_req.update_far_count].apply_action.dupl = GET_DUP_STATUS(pdn->context); pfcp_sess_mod_req.update_far_count++; } if (mod_acc_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.header.len != 0) { /* In case Establishment of S1-U bearer during Data * Transport in Control Plane CIoT EPS Optimisation * handling a corner case * */ context->indication_flag.s11tf = 0; /*NOTE: IDEL STATE means bearer is in Suspend State, so no need to send Send Endmarker */ if((bearer->s1u_enb_gtpu_ip.ipv4_addr != 0) && (pdn->state != IDEL_STATE)) { if((mod_acc_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.teid_gre_key) != bearer->s1u_enb_gtpu_teid || ((mod_acc_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.ipv4_address) != bearer->s1u_enb_gtpu_ip.ipv4_addr) || (memcmp(mod_acc_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.ipv6_address, bearer->s1u_enb_gtpu_ip.ipv6_addr, IPV6_ADDRESS_LEN) != 0)) { send_endmarker = 1; } } ret = fill_ip_addr(mod_acc_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.ipv4_address, mod_acc_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.ipv6_address, &bearer->s1u_enb_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } bearer->s1u_enb_gtpu_teid = mod_acc_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.teid_gre_key; update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.teid = bearer->s1u_enb_gtpu_teid; ret = set_node_address(&update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv4_address, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.outer_hdr_creation.ipv6_address, bearer->s1u_enb_gtpu_ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value = check_interface_type(mod_acc_req->bearer_contexts_to_be_modified[i].s1_enodeb_fteid.interface_type, pdn->context->cp_mode); update_far[pfcp_sess_mod_req.update_far_count].far_id.far_id_value = get_far_id(bearer, update_far[pfcp_sess_mod_req.update_far_count].upd_frwdng_parms.dst_intfc.interface_value); update_far[pfcp_sess_mod_req.update_far_count].apply_action.forw = PRESENT; update_far[pfcp_sess_mod_req.update_far_count].apply_action.dupl = GET_DUP_STATUS(pdn->context); pfcp_sess_mod_req.update_far_count++; } bearers[i] = bearer; } /*forloop*/ if(pdn == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get PDN ebi_index : %d\n", LOG_VALUE, ebi_index); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } ebi_index = GET_EBI_INDEX(pdn->default_bearer_id); if (ebi_index == -1) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid EBI ID\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } bearer = context->eps_bearers[ebi_index]; pdn = bearer->pdn; if(mod_acc_req->bearer_modify_count != 0) { fill_pfcp_sess_mod_req(&pfcp_sess_mod_req, &mod_acc_req->header, bearers, pdn, update_far, send_endmarker, mod_acc_req->bearer_modify_count, context); } if(mod_acc_req->second_rat_count != 0) { uint8_t trigg_buff[] = "secondary_rat_usage"; for(uint8_t i =0; i< mod_acc_req->second_rat_count; i++) { if(mod_acc_req->secdry_rat_usage_data_rpt[i].irsgw == 1) { cdr second_rat_data = {0}; struct timeval unix_start_time; struct timeval unix_end_time; second_rat_data.cdr_type = CDR_BY_SEC_RAT; second_rat_data.change_rat_type_flag = 1; /*rat type in sec_rat_usage_rpt is NR=0 i.e RAT is 10 as per spec 29.274*/ second_rat_data.rat_type = (mod_acc_req->secdry_rat_usage_data_rpt[i].secdry_rat_type == 0) ? 10 : 0; second_rat_data.bearer_id = mod_acc_req->secdry_rat_usage_data_rpt[i].ebi; second_rat_data.seid = pdn->seid; second_rat_data.imsi = pdn->context->imsi; second_rat_data.start_time = mod_acc_req->secdry_rat_usage_data_rpt[i].start_timestamp; second_rat_data.end_time = mod_acc_req->secdry_rat_usage_data_rpt[i].end_timestamp; second_rat_data.data_volume_uplink = mod_acc_req->secdry_rat_usage_data_rpt[i].usage_data_ul; second_rat_data.data_volume_downlink = mod_acc_req->secdry_rat_usage_data_rpt[i].usage_data_dl; ntp_to_unix_time(&second_rat_data.start_time, &unix_start_time); ntp_to_unix_time(&second_rat_data.end_time, &unix_end_time); second_rat_data.duration_meas = unix_end_time.tv_sec - unix_start_time.tv_sec; second_rat_data.data_start_time = 0; second_rat_data.data_end_time = 0; second_rat_data.total_data_volume = second_rat_data.data_volume_uplink + second_rat_data.data_volume_downlink; memcpy(&second_rat_data.trigg_buff, &trigg_buff, sizeof(trigg_buff)); if(generate_cdr_info(&second_rat_data) == -1) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Failed to generate " "CDR\n",LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } } } if(mod_acc_req->bearer_modify_count != 0) { #ifdef USE_CSID /* Generate the permant CSID for SGW */ /* Get the copy of existing SGW CSID */ fqcsid_t tmp_csid_t = {0}; if (pdn->sgw_csid.num_csid) { memcpy(&tmp_csid_t, &pdn->sgw_csid, sizeof(fqcsid_t)); } /* Update the entry for peer nodes */ if (fill_peer_node_info(pdn, bearer)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to fill peer node info and assignment of the " "CSID Error: %s\n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (pdn->flag_fqcsid_modified == TRUE) { uint8_t tmp_csid = 0; /* Validate the exsiting CSID or allocated new one */ for (uint8_t inx1 = 0; inx1 < tmp_csid_t.num_csid; inx1++) { if (pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1] == tmp_csid_t.local_csid[inx1]) { tmp_csid = tmp_csid_t.local_csid[inx1]; break; } } if (!tmp_csid) { for (uint8_t inx = 0; inx < tmp_csid_t.num_csid; inx++) { /* Remove the session link from old CSID */ sess_csid *tmp1 = NULL; tmp1 = get_sess_csid_entry(tmp_csid_t.local_csid[inx], REMOVE_NODE); if (tmp1 != NULL) { /* Remove node from csid linked list */ tmp1 = remove_sess_csid_data_node(tmp1, pdn->seid); int8_t ret = 0; /* Update CSID Entry in table */ ret = rte_hash_add_key_data(seids_by_csid_hash, &tmp_csid_t.local_csid[inx], tmp1); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry for CSID = %u" "\n\tError= %s\n", LOG_VALUE, tmp_csid_t.local_csid[inx], rte_strerror(abs(ret))); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (tmp1 == NULL) { /* Removing temporary local CSID associated with MME */ remove_peer_temp_csid(&pdn->mme_csid, tmp_csid_t.local_csid[inx], S11_SGW_PORT_ID); /* Removing temporary local CSID assocoated with PGWC */ remove_peer_temp_csid(&pdn->pgw_csid, tmp_csid_t.local_csid[inx], S5S8_SGWC_PORT_ID); /* Delete Local CSID entry */ del_sess_csid_entry(tmp_csid_t.local_csid[inx]); } /* Delete CSID from the context */ for (uint8_t itr1 = 0; itr1 < (context->sgw_fqcsid)->num_csid; itr1++) { if ((context->sgw_fqcsid)->local_csid[itr1] == tmp_csid_t.local_csid[inx]) { for(uint8_t pos = itr1; pos < ((context->sgw_fqcsid)->num_csid - 1); pos++ ) { (context->sgw_fqcsid)->local_csid[pos] = (context->sgw_fqcsid)->local_csid[pos + 1]; (context->sgw_fqcsid)->node_addr[pos] = (context->sgw_fqcsid)->node_addr[(pos + 1)]; } (context->sgw_fqcsid)->num_csid--; } } } else { sess_csid *tmp1 = NULL; tmp1 = get_sess_csid_entry(tmp_csid_t.local_csid[inx], REMOVE_NODE); if (tmp1 == NULL) { /* Removing temporary local CSID associated with MME */ remove_peer_temp_csid(&pdn->mme_csid, tmp_csid_t.local_csid[inx], S11_SGW_PORT_ID); /* Removing temporary local CSID assocoated with PGWC */ remove_peer_temp_csid(&pdn->pgw_csid, tmp_csid_t.local_csid[inx], S5S8_SGWC_PORT_ID); /* Delete Local CSID entry */ del_sess_csid_entry(tmp_csid_t.local_csid[inx]); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to " "get Session ID entry for CSID:%u\n", LOG_VALUE, tmp_csid_t.local_csid[inx]); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Remove session link from Old CSID:%u\n", LOG_VALUE, tmp_csid_t.local_csid[inx]); } } /* update entry for cp session id with link local csid */ sess_csid *tmp = NULL; tmp = get_sess_csid_entry( pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1], ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get session of CSID entry %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Link local csid with session id */ /* Check head node created ot not */ if(tmp->cp_seid != pdn->seid && tmp->cp_seid != 0) { sess_csid *new_node = NULL; /* Add new node into csid linked list */ new_node = add_sess_csid_data_node(tmp, pdn->sgw_csid.local_csid[pdn->sgw_csid.num_csid - 1]); if(new_node == NULL ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "ADD new node into CSID linked list : %s\n", LOG_VALUE); return GTPV2C_CAUSE_SYSTEM_FAILURE; } else { new_node->cp_seid = pdn->seid; new_node->up_seid = pdn->dp_seid; } } else { tmp->cp_seid = pdn->seid; tmp->up_seid = pdn->dp_seid; tmp->next = NULL; } /* Fill the fqcsid into the session est request */ if (fill_fqcsid_sess_mod_req(&pfcp_sess_mod_req, pdn)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to fill " "FQ-CSID in Session Establishment Request, " "Error: %s\n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } } #endif /* USE_CSID */ uint8_t pfcp_msg[size]={0}; int encoded = encode_pfcp_sess_mod_req_t(&pfcp_sess_mod_req, pfcp_msg); pfcp_header_t *header = (pfcp_header_t *) pfcp_msg; header->message_len = htons(encoded - 4); if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr,SENT) < 0 ){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error in sending PFCP " "Session Modification Request for Modify Bearer Request %i\n", LOG_VALUE, errno); } else { #ifdef CP_BUILD add_pfcp_if_timer_entry(mod_acc_req->header.teid.has_teid.teid, &upf_pfcp_sockaddr, pfcp_msg, encoded, ebi_index); #endif /* CP_BUILD */ } /* Update the Sequence number for the request */ context->sequence = mod_acc_req->header.teid.has_teid.seq; /* Update UE State */ pdn->state = PFCP_SESS_MOD_REQ_SNT_STATE; /*Retrive the session information based on session id. */ if (get_sess_entry(pdn->seid, &resp) != 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"No Session Entry Found " "for sess ID:%lu\n", LOG_VALUE, pdn->seid); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Set create session response */ resp->eps_bearer_id = pdn->default_bearer_id; resp->msg_type = GTP_MODIFY_ACCESS_BEARER_REQ; resp->state = PFCP_SESS_MOD_REQ_SNT_STATE; resp->proc = pdn->proc; resp->cp_mode = context->cp_mode; memcpy(&resp->gtpc_msg.mod_acc_req, mod_acc_req, sizeof(mod_bearer_req_t)); } else { bzero(&tx_buf, sizeof(tx_buf)); gtpv2c_header_t *gtpv2c_tx = (gtpv2c_header_t *)tx_buf; set_modify_access_bearer_response(gtpv2c_tx, context->sequence, context, bearer, mod_acc_req); resp->state = CONNECTED_STATE; if (PGWC != context->cp_mode) { ret = set_dest_address(context->s11_mme_gtpc_ip, &s11_mme_sockaddr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } } uint16_t payload_length = ntohs(gtpv2c_tx->gtpc.message_len) + sizeof(gtpv2c_tx->gtpc); gtpv2c_send(s11_fd, s11_fd_v6, tx_buf, payload_length, s11_mme_sockaddr,ACC); process_cp_li_msg( pdn->seid, S11_INTFC_OUT, tx_buf, payload_length, fill_ip_info(s11_mme_sockaddr.type, config.s11_ip.s_addr, config.s11_ip_v6.s6_addr), fill_ip_info(s11_mme_sockaddr.type, s11_mme_sockaddr.ipv4.sin_addr.s_addr, s11_mme_sockaddr.ipv6.sin6_addr.s6_addr), config.s11_port, ((s11_mme_sockaddr.type == IPTYPE_IPV4_LI) ? ntohs(s11_mme_sockaddr.ipv4.sin_port) : ntohs(s11_mme_sockaddr.ipv6.sin6_port))); pdn->state = CONNECTED_STATE; } return 0; } int set_ccr_t_message(pdn_connection *pdn, ue_context *context, gx_msg *ccr_request, int ebi_index) { gx_context_t *gx_context = NULL; int ret = 0; /* Retrive Gx_context based on Sess ID. */ ret = rte_hash_lookup_data(gx_context_by_sess_id_hash, (const void*)(pdn->gx_sess_id), (void **)&gx_context); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"NO ENTRY FOUND IN " "Gx HASH [%s]\n", LOG_VALUE, pdn->gx_sess_id); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Set the CP Mode, to check the CP mode after session deletion */ gx_context->cp_mode = context->cp_mode; /* Set the Msg header type for CCR-T */ ccr_request->msg_type = GX_CCR_MSG ; /* Set Credit Control Request type */ ccr_request->data.ccr.presence.cc_request_type = PRESENT; ccr_request->data.ccr.cc_request_type = TERMINATION_REQUEST ; /* Set Credit Control Bearer opertaion type */ ccr_request->data.ccr.presence.bearer_operation = PRESENT; ccr_request->data.ccr.bearer_operation = TERMINATION ; /* Fill the Credit Crontrol Request to send PCRF */ if(fill_ccr_request(&ccr_request->data.ccr, context, ebi_index, pdn->gx_sess_id, 0) != 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed CCR request " "filling process\n", LOG_VALUE); return GTPV2C_CAUSE_CONTEXT_NOT_FOUND; } /* Update UE State */ pdn->state = CCR_SNT_STATE; /* Set the Gx State for events */ gx_context->state = CCR_SNT_STATE; gx_context->proc = pdn->proc; return 0; } void compare_arp_value(eps_bearer *def_bearer, pdn_connection *pdn) { eps_bearer *bearer = NULL; for(uint8_t idx = 0; idx < MAX_BEARERS; idx++) { bearer = pdn->eps_bearers[idx]; if(bearer != NULL) { if(bearer->eps_bearer_id == def_bearer->eps_bearer_id) continue; if(def_bearer->qos.arp.preemption_vulnerability == bearer->qos.arp.preemption_vulnerability && def_bearer->qos.arp.priority_level == bearer->qos.arp.priority_level && def_bearer->qos.arp.preemption_capability == bearer->qos.arp.preemption_capability) { bearer->arp_bearer_check = PRESENT; } } } return; } int set_address(node_address_t *node_value, node_address_t *node) { if(node->ip_type == NONE_TYPE) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" None of the IPv4 " "or IPv6 IP is set", LOG_VALUE); return -1; } if(node->ip_type == PDN_IP_TYPE_IPV4 || node->ip_type == PDN_IP_TYPE_IPV4V6) { node_value->ipv4_addr = node->ipv4_addr; node_value->ip_type |= PDN_IP_TYPE_IPV4; } if(node->ip_type == PDN_IP_TYPE_IPV6 || node->ip_type == PDN_IP_TYPE_IPV4V6) { memcpy(node_value->ipv6_addr, node->ipv6_addr, IPV6_ADDRESS_LEN); node_value->ip_type |= PDN_IP_TYPE_IPV6; } return 0; } int set_dest_address(node_address_t src_addr, peer_addr_t *dst_addr) { if(src_addr.ip_type == PDN_TYPE_IPV4) { dst_addr->ipv4.sin_addr.s_addr = src_addr.ipv4_addr; dst_addr->ipv4.sin_family = AF_INET; dst_addr->type = PDN_TYPE_IPV4; } else if(src_addr.ip_type == PDN_TYPE_IPV6 || src_addr.ip_type == PDN_TYPE_IPV4_IPV6) { memcpy(dst_addr->ipv6.sin6_addr.s6_addr, src_addr.ipv6_addr, IPV6_ADDRESS_LEN); dst_addr->ipv6.sin6_family = AF_INET6; dst_addr->type = PDN_TYPE_IPV6; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" None of the IPv4 " "or IPv6 IP is present while storing IP address", LOG_VALUE); return -1; } return 0; } int fill_packet_fltr_info_avp(gx_msg *ccr_request, tad_pkt_fltr_t *tad_pkt_fltr, uint8_t idx) { char dest_addr_buff[ADDR_BUF_SIZE]= {0}; char src_addr_buff[ADDR_BUF_SIZE]= {0}; char pkt_buff[PCKT_BUF_SIZE] = {0}; struct in_addr src_ip_addr; struct in_addr dst_ip_addr; memcpy(ccr_request->data.ccr.packet_filter_information.list[idx].packet_filter_identifier.val, &tad_pkt_fltr->pckt_fltr_id,1); ccr_request->data.ccr.packet_filter_information.list[idx].packet_filter_identifier.len = 1; ccr_request->data.ccr.packet_filter_information.list[idx].flow_direction = tad_pkt_fltr->pckt_fltr_dir; memcpy(&ccr_request->data.ccr.packet_filter_information.list[idx].precedence, &tad_pkt_fltr->precedence,1); if (tad_pkt_fltr->v4) { src_ip_addr.s_addr = tad_pkt_fltr->local_ip_addr; dst_ip_addr.s_addr = tad_pkt_fltr->remote_ip_addr; snprintf(src_addr_buff,ADDR_BUF_SIZE,"%s",inet_ntoa(src_ip_addr)); snprintf(dest_addr_buff,ADDR_BUF_SIZE,"%s",inet_ntoa(dst_ip_addr)); if (tad_pkt_fltr->pckt_fltr_dir == TFT_DIRECTION_DOWNLINK_ONLY || tad_pkt_fltr->pckt_fltr_dir == TFT_DIRECTION_BIDIRECTIONAL) { snprintf(pkt_buff,PCKT_BUF_SIZE,"%s %s/%d %u-%u to %s/%d %u-%u ","permit out ip from", dest_addr_buff,tad_pkt_fltr->remote_ip_mask,tad_pkt_fltr->remote_port_low, tad_pkt_fltr->remote_port_high,src_addr_buff,tad_pkt_fltr->local_ip_mask, tad_pkt_fltr->local_port_low,tad_pkt_fltr->local_port_high); } else if (tad_pkt_fltr->pckt_fltr_dir == TFT_DIRECTION_UPLINK_ONLY){ snprintf(pkt_buff,PCKT_BUF_SIZE,"%s %s/%d %u-%u to %s/%d %u-%u ","permit out ip from", src_addr_buff,tad_pkt_fltr->local_ip_mask,tad_pkt_fltr->local_port_low, tad_pkt_fltr->local_port_high,dest_addr_buff,tad_pkt_fltr->remote_ip_mask, tad_pkt_fltr->remote_port_low,tad_pkt_fltr->remote_port_high); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid packet filter direction" "received in TAD of Bearer resource command\n", LOG_VALUE); return -1; } } else if (tad_pkt_fltr->v6) { inet_ntop(AF_INET6, tad_pkt_fltr->local_ip6_addr, src_addr_buff, ADDR_BUF_SIZE); inet_ntop(AF_INET6, tad_pkt_fltr->remote_ip6_addr, dest_addr_buff, ADDR_BUF_SIZE); if (tad_pkt_fltr->pckt_fltr_dir == TFT_DIRECTION_DOWNLINK_ONLY || tad_pkt_fltr->pckt_fltr_dir == TFT_DIRECTION_BIDIRECTIONAL) { snprintf(pkt_buff,PCKT_BUF_SIZE,"%s %s/%d %u-%u to %s/%d %u-%u ","permit out ip from", dest_addr_buff,tad_pkt_fltr->remote_ip_mask,tad_pkt_fltr->remote_port_low, tad_pkt_fltr->remote_port_high,src_addr_buff,tad_pkt_fltr->local_ip_mask, tad_pkt_fltr->local_port_low,tad_pkt_fltr->local_port_high); } else if (tad_pkt_fltr->pckt_fltr_dir == TFT_DIRECTION_UPLINK_ONLY){ snprintf(pkt_buff,PCKT_BUF_SIZE,"%s %s/%d %u-%u to %s/%d %u-%u ","permit out ip from", src_addr_buff,tad_pkt_fltr->local_ip_mask,tad_pkt_fltr->local_port_low, tad_pkt_fltr->local_port_high,dest_addr_buff,tad_pkt_fltr->remote_ip_mask, tad_pkt_fltr->remote_port_low,tad_pkt_fltr->remote_port_high); } else { /**error*/ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid packet filter direction" "received in TAD of Bearer resource command\n", LOG_VALUE); return -1; } } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Neither IPv4 nor IPv6 packet filter component " "identifier received in TAD of Bearer resource command\n", LOG_VALUE); return -1; } memcpy(ccr_request->data.ccr.packet_filter_information.list[idx].packet_filter_content.val, pkt_buff,strlen(pkt_buff)); ccr_request->data.ccr.packet_filter_information.list[idx].packet_filter_content.len = strlen(pkt_buff); return 0; } #ifdef CP_BUILD int send_pfcp_del_sess_req(uint64_t sess_id, peer_addr_t *peer_addr) { uint32_t seq = 1; uint64_t up_sess_id = 0; pfcp_sess_del_req_t pfcp_sess_del_req = {0}; seq = get_pfcp_sequence_number(PFCP_SESSION_DELETION_REQUEST, seq); set_pfcp_seid_header((pfcp_header_t *) &(pfcp_sess_del_req.header), PFCP_SESSION_DELETION_REQUEST, HAS_SEID, seq, 0); /* Generate UP SEID from CP SEID */ up_sess_id = ((((sess_id >> 32) + 1) << 32) | (sess_id & 0xfffffff) ); pfcp_sess_del_req.header.seid_seqno.has_seid.seid = up_sess_id; uint8_t pfcp_msg[PFCP_MSG_LEN]={0}; int encoded = encode_pfcp_sess_del_req_t(&pfcp_sess_del_req, pfcp_msg); /* Fill the target UPF ip address */ memcpy(&upf_pfcp_sockaddr, peer_addr, sizeof(peer_addr_t)); if ( pfcp_send(pfcp_fd, pfcp_fd_v6, pfcp_msg, encoded, upf_pfcp_sockaddr,SENT) < 0 ){ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error sending pfcp session " "deletion request : %i\n", LOG_VALUE, errno); return -1; } return 0; } #endif /* CP_BUILD */
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/csid_peer_init.c
<filename>pfcp_messages/csid_peer_init.c /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <time.h> #include <rte_hash_crc.h> #include "pfcp_util.h" #include "csid_struct.h" #include "gw_adapter.h" #include "pfcp_enum.h" #include "pfcp_set_ie.h" #ifdef CP_BUILD #include "gtp_ies.h" #include "cp.h" #include "main.h" #else #include "up_main.h" #endif /* CP_BUILD */ extern int clSystemLog; /** * Add local csid entry by peer csid in peer csid hash table. * * @param csid_t peer_csid_key * key. * @param csid_t local_csid * @param ifce S11/Sx/S5S8 * return 0 or 1. * */ int8_t add_peer_csid_entry(csid_key_t *key, csid_t *csid, uint8_t iface) { int ret = 0; csid_t *tmp = NULL; struct rte_hash *hash = NULL; if (iface == S11_SGW_PORT_ID) { hash = local_csids_by_mmecsid_hash; } else if (iface == SX_PORT_ID) { hash = local_csids_by_sgwcsid_hash; } else if (iface == S5S8_SGWC_PORT_ID) { hash = local_csids_by_pgwcsid_hash; } else if (iface == S5S8_PGWC_PORT_ID) { hash = local_csids_by_pgwcsid_hash; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Selected Invalid iface " "type while adding peer CSID entry..\n", LOG_VALUE); return -1; } /* Lookup for CSID entry. */ ret = rte_hash_lookup_data(hash, key, (void **)&tmp); if ( ret < 0) { tmp = rte_zmalloc_socket(NULL, sizeof(csid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the memory for csid while adding " "peer CSID entry\n", LOG_VALUE); return -1; } tmp = csid; /* CSID Entry add if not present */ ret = rte_hash_add_key_data(hash, key, tmp); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for csid: %u" "\n\tError= %s\n", LOG_VALUE, tmp->local_csid[tmp->num_csid - 1], rte_strerror(abs(ret))); return -1; } } else { tmp = csid; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"CSID entry added for csid:%u\n", LOG_VALUE, tmp->local_csid[tmp->num_csid - 1]); return 0; } /** * Get local csid entry by peer csid from csid hash table. * * @param csid_t csid_key * key. * @param iface * return csid or -1 * */ csid_t* get_peer_csid_entry(csid_key_t *key, uint8_t iface, uint8_t is_mod) { int ret = 0; csid_t *csid = NULL; struct rte_hash *hash = NULL; if (iface == S11_SGW_PORT_ID) { hash = local_csids_by_mmecsid_hash; } else if (iface == SX_PORT_ID) { hash = local_csids_by_sgwcsid_hash; } else if (iface == S5S8_SGWC_PORT_ID) { hash = local_csids_by_pgwcsid_hash; } else if (iface == S5S8_PGWC_PORT_ID) { hash = local_csids_by_pgwcsid_hash; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Selected Invalid iface type..\n", LOG_VALUE); return NULL; } /* Check csid entry is present or Not */ ret = rte_hash_lookup_data(hash, key, (void **)&csid); if (ret < 0) { if (is_mod != ADD_NODE) { (key->node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for Node IPv6 addrees :"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(key->node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for Node IPv4 addrees :"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(key->node_addr.ipv4_addr)); return NULL; } (key->node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found in peer node hash table, CSID:%u, Node IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, key->local_csid, IPv6_PRINT(IPv6_CAST(key->node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found in peer node hash table, CSID:%u, Node IPv4 Addr:"IPV4_ADDR"\n", LOG_VALUE, key->local_csid, IPV4_ADDR_HOST_FORMAT(key->node_addr.ipv4_addr)); /* Allocate the memory for local CSID */ csid = rte_zmalloc_socket(NULL, sizeof(csid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (csid == NULL) { (key->node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the memory for CSID: %u, Node IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, key->local_csid, IPv6_PRINT(IPv6_CAST(key->node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the memory for CSID: %u, Node IPv4 Addr:"IPV4_ADDR"\n", LOG_VALUE, key->local_csid, IPV4_ADDR_HOST_FORMAT(key->node_addr.ipv4_addr)); return NULL; } /* CSID Entry add if not present */ ret = rte_hash_add_key_data(hash, key, csid); if (ret) { (key->node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for CSID: %u, Node IPv6 Addr:"IPv6_FMT"" "\n\tError= %s\n", LOG_VALUE, key->local_csid, IPv6_PRINT(IPv6_CAST(key->node_addr.ipv6_addr)), rte_strerror(abs(ret))): clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for CSID: %u, Node IPv4 Addr:"IPV4_ADDR"" "\n\tError= %s\n", LOG_VALUE, key->local_csid, IPV4_ADDR_HOST_FORMAT(key->node_addr.ipv4_addr), rte_strerror(abs(ret))); return NULL; } return csid; } (key->node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Found Entry for Key CSID: %u, Node IPv6 Addr:"IPv6_FMT", Num_Csids:%u, IFACE:%u\n", LOG_VALUE, key->local_csid, IPv6_PRINT(IPv6_CAST(key->node_addr.ipv6_addr)), csid->num_csid, iface): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Found Entry for Key CSID: %u, Node IPv4 Addr:"IPV4_ADDR", Num_Csids:%u, IFACE:%u\n", LOG_VALUE, key->local_csid, IPV4_ADDR_HOST_FORMAT(key->node_addr.ipv4_addr), csid->num_csid, iface); for (uint8_t itr = 0; itr < csid->num_csid; itr++) { (key->node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Node IPv6 Addr:"IPv6_FMT", Local CSID:%u, Counter:%u, Max_Counter:%u\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(csid->node_addr.ipv6_addr)), csid->local_csid[itr], itr, csid->num_csid): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Node IPv4 Addr:"IPV4_ADDR", Local CSID:%u, Counter:%u, Max_Counter:%u\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(csid->node_addr.ipv4_addr), csid->local_csid[itr], itr, csid->num_csid); } return csid; } /** * Delete local csid entry by peer csid from csid hash table. * * @param csid_t csid_key * key. * @param iface * return 0 or 1. * */ int8_t del_peer_csid_entry(csid_key_t *key, uint8_t iface) { int ret = 0; csid_t *csid = NULL; struct rte_hash *hash = NULL; if (iface == S11_SGW_PORT_ID) { hash = local_csids_by_mmecsid_hash; } else if (iface == SX_PORT_ID) { hash = local_csids_by_sgwcsid_hash; } else if (iface == S5S8_SGWC_PORT_ID) { hash = local_csids_by_pgwcsid_hash; } else if (iface == S5S8_PGWC_PORT_ID) { hash = local_csids_by_pgwcsid_hash; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Select Invalid iface type " "while deleting CSID entry..\n", LOG_VALUE); return -1; } /* Check peer node CSID entry is present or Not */ ret = rte_hash_lookup_data(hash, key, (void **)&csid); if ( ret < 0) { (key->node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"CSID entry not found..!!, CSID:%u, Node IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, key->local_csid, IPv6_PRINT(IPv6_CAST(key->node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"CSID entry not found..!!, CSID:%u, Node IPv4 Addr:"IPV4_ADDR"\n", LOG_VALUE, key->local_csid, IPV4_ADDR_HOST_FORMAT(key->node_addr.ipv4_addr)); return -1; } /* Peer node CSID Entry is present. Delete the CSID Entry */ ret = rte_hash_del_key(hash, key); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failure in deleting " "peer csid entry\n", LOG_VALUE); return -1; } /* Free data from hash */ if (csid != NULL){ rte_free(csid); csid = NULL; } (key->node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer node CSID entry deleted, CSID:%u, Node IPv6 Addr:"IPv6_FMT", IFACE:%u\n", LOG_VALUE, key->local_csid, IPv6_PRINT(IPv6_CAST(key->node_addr.ipv6_addr)), iface): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer node CSID entry deleted, CSID:%u, Node IPv4 Addr:"IPV4_ADDR", IFACE:%u\n", LOG_VALUE, key->local_csid, IPV4_ADDR_HOST_FORMAT(key->node_addr.ipv4_addr), iface); return 0; } /** * Add peer node csids entry by peer node address in peer node csids hash table. * * @param node address * key. * @param fqcsid_t csids * return 0 or 1. * */ int8_t add_peer_addr_csids_entry(uint32_t node_addr, fqcsid_t *csids) { int ret = 0; fqcsid_t *tmp = NULL; struct rte_hash *hash = NULL; hash = local_csids_by_node_addr_hash; /* Lookup for local CSID entry. */ ret = rte_hash_lookup_data(hash, &node_addr, (void **)&tmp); if ( ret < 0) { tmp = rte_zmalloc_socket(NULL, sizeof(fqcsid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (tmp == NULL) { /*clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the memory for node addr:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(node_addr));*/ return -1; } memcpy(tmp, csids, sizeof(fqcsid_t)); /* Local CSID Entry not present. Add CSID Entry */ ret = rte_hash_add_key_data(hash, &node_addr, csids); if (ret) { /*clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for CSIDs for Node address:"IPV4_ADDR "\n\tError= %s\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(node_addr), rte_strerror(abs(ret)));*/ return -1; } } else { memcpy(tmp, csids, sizeof(fqcsid_t)); } /*clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"CSID entry added for node address:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(node_addr));*/ return 0; } /** * Get peer node csids entry by peer node addr from peer node csids hash table. * * @param node address * key. * @param is_mod * return fqcsid_t or NULL * */ fqcsid_t* get_peer_addr_csids_entry(node_address_t *node_addr, uint8_t is_mod) { int ret = 0; fqcsid_t *tmp = NULL; struct rte_hash *hash = NULL; hash = local_csids_by_node_addr_hash; ret = rte_hash_lookup_data(hash, node_addr, (void **)&tmp); if ( ret < 0) { if (is_mod != ADD_NODE) { (node_addr->ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for IPv6 Node addrees :"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(node_addr->ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for IPv4 Node addrees :"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(node_addr->ipv4_addr)); return NULL; } tmp = rte_zmalloc_socket(NULL, sizeof(fqcsid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (tmp == NULL) { (node_addr->ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the memory for ipv6 node addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(node_addr->ipv6_addr))): clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the memory for node addr:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(node_addr->ipv4_addr)); return NULL; } /* Local CSID Entry not present. Add CSID Entry */ ret = rte_hash_add_key_data(hash, node_addr, tmp); if (ret) { (node_addr->ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for CSIDs for IPv6 Node address:"IPv6_FMT "\n\tError= %s\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(node_addr->ipv6_addr)), rte_strerror(abs(ret))): clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for CSIDs for Node address:"IPV4_ADDR "\n\tError= %s\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(node_addr->ipv4_addr), rte_strerror(abs(ret))); return NULL; } (node_addr->ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry added for IPv6 Node address: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST((node_addr->ipv6_addr)))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry added for IPv4 Node address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(node_addr->ipv4_addr)); return tmp; } (node_addr->ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry found for IPv6 Node address: "IPv6_FMT", NUM_CSIDs:%u\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST((node_addr->ipv6_addr))), tmp->num_csid): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry found for Node address: "IPV4_ADDR", NUM_CSIDs:%u\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(node_addr->ipv4_addr), tmp->num_csid); for (uint8_t itr = 0; itr < tmp->num_csid; itr++) { (node_addr->ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6 Node address: "IPv6_FMT", PEER_CSID:%u, Counter:%u, Max_Counter:%u\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(tmp->node_addr.ipv6_addr)), tmp->local_csid[itr], itr, tmp->num_csid): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4 Node address: "IPV4_ADDR", PEER_CSID:%u, Counter:%u, Max_Counter:%u\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(tmp->node_addr.ipv4_addr), tmp->local_csid[itr], itr, tmp->num_csid); } return tmp; } /** * Delete peer node csid entry by peer node addr from peer node csid hash table. * * @param node_address * key. * return 0 or 1. * */ int8_t del_peer_addr_csids_entry(node_address_t *node_addr) { int ret = 0; fqcsid_t *tmp = NULL; struct rte_hash *hash = NULL; hash = local_csids_by_node_addr_hash; /* Check local CSID entry is present or Not */ ret = rte_hash_lookup_data(hash, node_addr, (void **)&tmp); if ( ret < 0) { (node_addr->ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for Node Addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(node_addr->ipv6_addr))) : clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for Node Addr:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(node_addr->ipv4_addr)); return -1; } /* Local CSID Entry is present. Delete local csid Entry */ ret = rte_hash_del_key(hash, node_addr); /* Free data from hash */ if ((tmp != NULL)){ rte_free(tmp); tmp = NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry deleted for node addr:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(node_addr->ipv4_addr)); return 0; } #ifdef CP_BUILD int match_and_add_pfcp_sess_fqcsid(pfcp_fqcsid_ie_t *fqcsid, sess_fqcsid_t *context_fqcsid) { uint8_t cnd = 0; uint8_t ex_csid_match = 0; uint8_t ex_node_addr_match = 0; uint8_t itr = 0; uint8_t num_csid = context_fqcsid->num_csid; for (itr = 0; itr < fqcsid->number_of_csids; itr++) { /* Reset Flags */ ex_csid_match = 0; ex_node_addr_match = 0; for (uint8_t itr1 = 0; itr1 < context_fqcsid->num_csid; itr1++) { if (context_fqcsid->local_csid[itr1] == fqcsid->pdn_conn_set_ident[itr]) { ex_csid_match = 1; for (uint8_t itr2 = 0; itr2 < context_fqcsid->num_csid; itr2++) { if (fqcsid->fqcsid_node_id_type == IPV4_GLOBAL_UNICAST) { cnd = memcmp(&(context_fqcsid->node_addr[itr2].ipv4_addr), &(fqcsid->node_address), IPV4_SIZE); } else { cnd = memcmp(&(context_fqcsid->node_addr[itr2].ipv6_addr), &(fqcsid->node_address), IPV6_SIZE); } if (cnd == 0) { ex_node_addr_match = 1; break; } } break; } } if ((ex_csid_match == 0) || (ex_node_addr_match == 0) ) { context_fqcsid->local_csid[num_csid] = fqcsid->pdn_conn_set_ident[itr]; if (fqcsid->fqcsid_node_id_type == IPV4_GLOBAL_UNICAST) { context_fqcsid->node_addr[num_csid].ip_type = PDN_TYPE_IPV4; memcpy(&context_fqcsid->node_addr[num_csid].ipv4_addr, &fqcsid->node_address, IPV4_SIZE); } else { context_fqcsid->node_addr[num_csid].ip_type = PDN_TYPE_IPV6; memcpy(&(context_fqcsid->node_addr[num_csid].ipv6_addr), &(fqcsid->node_address), IPV6_SIZE); } num_csid++; } } context_fqcsid->num_csid = num_csid; return 0; } void add_pfcp_sess_fqcsid(pfcp_fqcsid_ie_t *fqcsid, sess_fqcsid_t *context_fqcsid) { uint8_t num_csid = context_fqcsid->num_csid; for (uint8_t itr = 0; itr < fqcsid->number_of_csids; itr++) { context_fqcsid->local_csid[num_csid] = fqcsid->pdn_conn_set_ident[itr]; if (fqcsid->fqcsid_node_id_type == IPV4_GLOBAL_UNICAST) { context_fqcsid->node_addr[num_csid].ip_type = PDN_TYPE_IPV4; memcpy(&context_fqcsid->node_addr[num_csid].ipv4_addr, &fqcsid->node_address, IPV4_SIZE); } else { context_fqcsid->node_addr[num_csid].ip_type = PDN_TYPE_IPV6; memcpy(&(context_fqcsid->node_addr[num_csid].ipv6_addr), &(fqcsid->node_address), IPV6_SIZE); } num_csid++; } context_fqcsid->num_csid = num_csid; } int match_and_add_sess_fqcsid(gtp_fqcsid_ie_t *fqcsid, sess_fqcsid_t *context_fqcsid) { uint8_t ex_csid_match = 0; uint8_t ex_node_addr_match = 0; uint8_t itr = 0; uint8_t num_csid = context_fqcsid->num_csid; node_address_t node_addr = {0}; for (itr = 0; itr < fqcsid->number_of_csids; itr++) { /* Reset Flags */ ex_csid_match = 0; ex_node_addr_match = 0; for (uint8_t itr1 = 0; itr1 < context_fqcsid->num_csid; itr1++) { if (context_fqcsid->local_csid[itr1] == fqcsid->pdn_csid[itr]) { ex_csid_match = 1; for (uint8_t itr2 = 0; itr2 < context_fqcsid->num_csid; itr2++) { if (fqcsid->node_id_type == IPV4_GLOBAL_UNICAST) { node_addr.ip_type = PDN_TYPE_IPV4; memcpy(&node_addr.ipv4_addr, &(fqcsid->node_address), IPV4_SIZE); } else { node_addr.ip_type = PDN_TYPE_IPV6; memcpy(&node_addr.ipv6_addr, &(fqcsid->node_address), IPV6_SIZE); } if ((COMPARE_IP_ADDRESS(context_fqcsid->node_addr[itr2], node_addr)) == 0) { ex_node_addr_match = 1; break; } } break; } } if ((ex_csid_match == 0) || (ex_node_addr_match == 0) ) { context_fqcsid->local_csid[num_csid] = fqcsid->pdn_csid[itr]; if (fqcsid->node_id_type == IPV4_GLOBAL_UNICAST) { context_fqcsid->node_addr[num_csid].ip_type = PDN_TYPE_IPV4; memcpy(&(context_fqcsid->node_addr[num_csid].ipv4_addr), &(fqcsid->node_address), IPV4_SIZE); } else { context_fqcsid->node_addr[num_csid].ip_type = PDN_TYPE_IPV6; memcpy(&(context_fqcsid->node_addr[num_csid].ipv6_addr), &(fqcsid->node_address), IPV6_SIZE); } num_csid++; } } context_fqcsid->num_csid = num_csid; return 0; } void add_sess_fqcsid(gtp_fqcsid_ie_t *fqcsid, sess_fqcsid_t *context_fqcsid) { uint8_t num_csid = context_fqcsid->num_csid; for (uint8_t itr = 0; itr < fqcsid->number_of_csids; itr++) { context_fqcsid->local_csid[num_csid] = fqcsid->pdn_csid[itr]; if (fqcsid->node_id_type == IPV4_GLOBAL_UNICAST) { context_fqcsid->node_addr[num_csid].ip_type = PDN_TYPE_IPV4; memcpy(&(context_fqcsid->node_addr[num_csid].ipv4_addr), &(fqcsid->node_address), IPV4_SIZE); } else { context_fqcsid->node_addr[num_csid].ip_type = PDN_TYPE_IPV6; memcpy(&(context_fqcsid->node_addr[num_csid].ipv6_addr), &(fqcsid->node_address), IPV6_SIZE); } num_csid++; } context_fqcsid->num_csid = num_csid; } int add_fqcsid_entry(gtp_fqcsid_ie_t *fqcsid, sess_fqcsid_t *context_fqcsid) { fqcsid_t *tmp = NULL; node_address_t node_addr = {0}; if (fqcsid->node_id_type == IPV4_GLOBAL_UNICAST) { memcpy(&(node_addr.ipv4_addr), &fqcsid->node_address, IPV4_SIZE); node_addr.ip_type = PDN_TYPE_IPV4; } else if (fqcsid->node_id_type == IPV6_GLOBAL_UNICAST) { memcpy(&(node_addr.ipv6_addr), &fqcsid->node_address, IPV6_SIZE); node_addr.ip_type = PDN_TYPE_IPV6; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Error : Unknown node id type: %d \n", LOG_VALUE, fqcsid->node_id_type); return GTPV2C_CAUSE_SYSTEM_FAILURE; } tmp = get_peer_addr_csids_entry(&node_addr, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "FQ-CSID. Error : %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } memcpy(&tmp->node_addr, &node_addr, sizeof(node_address_t)); for(uint8_t itr = 0; itr < fqcsid->number_of_csids; itr++) { uint8_t match = 0; for (uint8_t itr1 = 0; itr1 < tmp->num_csid; itr1++) { if (tmp->local_csid[itr1] == fqcsid->pdn_csid[itr]) { match = 1; (tmp->node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Found Match FQ-CSID entry, CSID:%u, Node IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, fqcsid->pdn_csid[itr], IPv6_PRINT(IPv6_CAST(tmp->node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Found Match FQ-CSID entry, CSID:%u, Node IPv4 Addr:"IPV4_ADDR"\n", LOG_VALUE, fqcsid->pdn_csid[itr], IPV4_ADDR_HOST_FORMAT(tmp->node_addr.ipv4_addr)); break; } } if (!match) { tmp->local_csid[tmp->num_csid++] = fqcsid->pdn_csid[itr]; (tmp->node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Add FQ-CSID entry, CSID:%u, Node IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, fqcsid->pdn_csid[itr], IPv6_PRINT(IPv6_CAST(tmp->node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Add FQ-CSID entry, CSID:%u, Node IPv4 Addr:"IPV4_ADDR"\n", LOG_VALUE, fqcsid->pdn_csid[itr], IPV4_ADDR_HOST_FORMAT(tmp->node_addr.ipv4_addr)); } } if (context_fqcsid->num_csid) { match_and_add_sess_fqcsid(fqcsid, context_fqcsid); } else { add_sess_fqcsid(fqcsid, context_fqcsid); } return 0; } #endif /*CP_BUILD*/ #if USE_CSID fqcsid_ie_node_addr_t* get_peer_node_addr_entry(peer_node_addr_key_t *key, uint8_t is_mod) { int ret = 0; fqcsid_ie_node_addr_t *tmp = NULL; struct rte_hash *hash = NULL; hash = peer_node_addr_by_peer_fqcsid_node_addr_hash; ret = rte_hash_lookup_data(hash, key, (void **)&tmp); if ( ret < 0) { if (is_mod != ADD_NODE) { ( (key->peer_node_addr.ip_type == PDN_TYPE_IPV4) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for Node addrees :"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)) : clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for Node addrees :"IPv6_FMT"\n", LOG_VALUE, PRINT_IPV6_ADDR(key->peer_node_addr.ipv6_addr))); return NULL; } tmp = rte_zmalloc_socket(NULL, sizeof(fqcsid_ie_node_addr_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (tmp == NULL) { ( (key->peer_node_addr.ip_type == PDN_TYPE_IPV4) ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the memory for node addr:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)) : clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate the memory for node addr:"IPv6_FMT"\n", LOG_VALUE, PRINT_IPV6_ADDR(key->peer_node_addr.ipv6_addr))); return NULL; } /* Local CSID Entry not present. Add CSID Entry */ ret = rte_hash_add_key_data(hash, key, tmp); if (ret) { ( (key->peer_node_addr.ip_type == PDN_TYPE_IPV4) ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for Node address:"IPV4_ADDR "\n\tError= %s\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr), rte_strerror(abs(ret))) : clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for Node address:"IPv6_FMT "\n\tError= %s\n", LOG_VALUE, PRINT_IPV6_ADDR(key->peer_node_addr.ipv6_addr), rte_strerror(abs(ret)))); return NULL; } ( (key->peer_node_addr.ip_type == PDN_TYPE_IPV4) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry added for Node address: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)) : clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry added for Node address: "IPv6_FMT"\n", LOG_VALUE, PRINT_IPV6_ADDR(key->peer_node_addr.ipv6_addr))); return tmp; } ( (tmp->fqcsid_node_addr.ip_type == PDN_TYPE_IPV4) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Entry found, Fqcsid IE Node address :"IPV4_ADDR" \n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(tmp->fqcsid_node_addr.ipv4_addr)) : clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Entry found, Fqcsid Node address :"IPv6_FMT",\n", LOG_VALUE, PRINT_IPV6_ADDR(tmp->fqcsid_node_addr.ipv6_addr))); return tmp; } int8_t del_peer_node_addr_entry(peer_node_addr_key_t *key) { int ret = 0; fqcsid_ie_node_addr_t *tmp = NULL; struct rte_hash *hash = NULL; hash = peer_node_addr_by_peer_fqcsid_node_addr_hash; /* Check local CSID entry is present or Not */ ret = rte_hash_lookup_data(hash, key, (void **)&tmp); if ( ret < 0) { (key->peer_node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for Peer Node IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(key->peer_node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for Peer Node IPv4 Addr:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)); return -1; } /* Local CSID Entry is present. Delete local csid Entry */ ret = rte_hash_del_key(hash, key); /* Free data from hash */ if(tmp != NULL){ rte_free(tmp); tmp = NULL; } (key->peer_node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry deleted for Peer node ipv6 addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(key->peer_node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry deleted for Peer node ipv4 addr:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)); return 0; } #if CP_BUILD int8_t add_peer_addr_entry_for_fqcsid_ie_node_addr(node_address_t *peer_node_addr, gtp_fqcsid_ie_t *fqcsid, uint8_t iface) { uint32_t ipv4_node_addr = 0; fqcsid_ie_node_addr_t *tmp = NULL; peer_node_addr_key_t key = {0}; node_address_t peer_node_fqcsid_ie_info = {0}; if (fqcsid->node_id_type == IPV4_GLOBAL_UNICAST) { memcpy(&ipv4_node_addr, &(fqcsid->node_address), IPV4_SIZE); if (ipv4_node_addr == peer_node_addr->ipv4_addr) { return 0; } /* Fill peer fq-csid node info */ peer_node_fqcsid_ie_info.ip_type = PDN_TYPE_IPV4; peer_node_fqcsid_ie_info.ipv4_addr = ipv4_node_addr; } else { if ((memcmp(&(fqcsid->node_address), &peer_node_addr->ipv6_addr, IPV6_ADDRESS_LEN)) == 0) { return 0; } /* Fill peer fq-csid node info */ peer_node_fqcsid_ie_info.ip_type = PDN_TYPE_IPV6; memcpy(&(peer_node_fqcsid_ie_info.ipv6_addr), &(fqcsid->node_address), IPV6_ADDRESS_LEN); } switch(peer_node_addr->ip_type) { case PDN_TYPE_IPV4 : { key.peer_node_addr.ip_type = PDN_TYPE_IPV4; key.iface = iface; key.peer_node_addr.ipv4_addr = peer_node_addr->ipv4_addr; break; } case PDN_TYPE_IPV6 : { key.peer_node_addr.ip_type = PDN_TYPE_IPV6; key.iface = iface; memcpy(&(key.peer_node_addr.ipv6_addr), &(peer_node_addr->ipv6_addr), IPV6_ADDRESS_LEN); break; } case PDN_TYPE_IPV4_IPV6 : { key.peer_node_addr.ip_type = PDN_TYPE_IPV6; key.iface = iface; memcpy(&(key.peer_node_addr.ipv6_addr), &(peer_node_addr->ipv6_addr), IPV6_ADDRESS_LEN); break; } default : { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Neither IPv4 nor " "IPv6 type is set ", LOG_VALUE); return PRESENT; } } tmp = get_peer_node_addr_entry(&key, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "FQ-CSID IE address. Error : %s \n", LOG_VALUE, strerror(errno)); return GTPV2C_CAUSE_SYSTEM_FAILURE; } if (fqcsid->node_id_type == IPV4_GLOBAL_UNICAST) { if ((ipv4_node_addr) && (ipv4_node_addr != tmp->fqcsid_node_addr.ipv4_addr)) { memcpy(&tmp->fqcsid_node_addr, &peer_node_fqcsid_ie_info, sizeof(node_address_t)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Mapped:Fqcsid IE node address " "added : Fqcsid node address type: %d \n", LOG_VALUE, tmp->fqcsid_node_addr.ip_type); } } else { if (memcmp(tmp->fqcsid_node_addr.ipv6_addr, fqcsid->node_address, IPV6_ADDRESS_LEN) != 0) { memcpy(&tmp->fqcsid_node_addr, &peer_node_fqcsid_ie_info, sizeof(node_address_t)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Mapped:Fqcsid IE node address " "added : Fqcsid node address type: %d \n", LOG_VALUE, tmp->fqcsid_node_addr.ip_type); } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Fqcsid IE Node address added into hash\n", LOG_VALUE); return 0; } #else int8_t add_peer_addr_entry_for_fqcsid_ie_node_addr(node_address_t *peer_node_addr, pfcp_fqcsid_ie_t *fqcsid, uint8_t iface) { uint32_t ipv4_node_addr = 0; fqcsid_ie_node_addr_t *tmp = NULL; peer_node_addr_key_t key = {0}; node_address_t peer_node_fqcsid_ie_info = {0}; if (fqcsid->fqcsid_node_id_type == IPV4_GLOBAL_UNICAST) { memcpy(&ipv4_node_addr, &(fqcsid->node_address), IPV4_SIZE); if (ipv4_node_addr == peer_node_addr->ipv4_addr) { return 0; } /* Fill peer fq-csid node info */ peer_node_fqcsid_ie_info.ip_type = IPV4_TYPE; peer_node_fqcsid_ie_info.ipv4_addr = ipv4_node_addr; } else { if ((memcmp(&(fqcsid->node_address), &peer_node_addr->ipv6_addr, IPV6_ADDRESS_LEN)) == 0) { return 0; } /* Fill peer fq-csid node info */ peer_node_fqcsid_ie_info.ip_type = IPV6_TYPE; memcpy(&(peer_node_fqcsid_ie_info.ipv6_addr), &(fqcsid->node_address), IPV6_ADDRESS_LEN); } switch(peer_node_addr->ip_type) { case PDN_TYPE_IPV4 : { key.peer_node_addr.ip_type = PDN_TYPE_IPV4; key.iface = iface; key.peer_node_addr.ipv4_addr = peer_node_addr->ipv4_addr; break; } case PDN_TYPE_IPV6 : { key.peer_node_addr.ip_type = PDN_TYPE_IPV6; key.iface = iface; memcpy(&(key.peer_node_addr.ipv6_addr), peer_node_addr->ipv6_addr, IPV6_ADDRESS_LEN); break; } case PDN_TYPE_IPV4_IPV6 : { key.peer_node_addr.ip_type = PDN_TYPE_IPV6; key.iface = iface; memcpy(&(key.peer_node_addr.ipv6_addr), &(peer_node_addr->ipv6_addr), IPV6_ADDRESS_LEN); break; } default : { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT" Neither IPv4 nor " "IPv6 type is set ", LOG_VALUE); return PRESENT; } } tmp = get_peer_node_addr_entry(&key, ADD_NODE); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add " "FQ-CSID IE address. Error : %s \n", LOG_VALUE, strerror(errno)); return -1; } if (fqcsid->fqcsid_node_id_type == IPV4_GLOBAL_UNICAST) { if (ipv4_node_addr && (ipv4_node_addr != tmp->fqcsid_node_addr.ipv4_addr)) { memcpy(&tmp->fqcsid_node_addr, &peer_node_fqcsid_ie_info, sizeof(node_address_t)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Mapped:Fqcsid IE node address IPv4" "added: "IPV4_ADDR" With CP IPv4 Addr:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(tmp->fqcsid_node_addr.ipv4_addr), IPV4_ADDR_HOST_FORMAT(key.peer_node_addr.ipv4_addr)); } } else { if (memcmp(tmp->fqcsid_node_addr.ipv6_addr, fqcsid->node_address, IPV6_ADDRESS_LEN) != 0) { memcpy(&tmp->fqcsid_node_addr, &peer_node_fqcsid_ie_info, sizeof(node_address_t)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Mapped:Fqcsid IE node address IPv6" "added : "IPv6_FMT" with CP IPv6 Addr: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(tmp->fqcsid_node_addr.ipv6_addr)), IPv6_PRINT(IPv6_CAST(key.peer_node_addr.ipv6_addr))); } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Fqcsid IE Node address added into hash\n", LOG_VALUE); return 0; } #endif /* CP_BUILD */ #endif /* USE_CSID */
nikhilc149/e-utran-features-bug-fixes
cp/main.c
/* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <getopt.h> #include <rte_ip.h> #include <rte_udp.h> #include <rte_cfgfile.h> #include "cp.h" #include "main.h" #include "cp_app.h" #include "cp_stats.h" #include "pfcp_util.h" #include "sm_struct.h" #include "cp_config.h" #include "debug_str.h" #include "dp_ipc_api.h" #include "pfcp_set_ie.h" #include "../pfcp_messages/pfcp.h" #include "li_interface.h" #include "gw_adapter.h" #include "li_config.h" #include "cdnshelper.h" #include "ipc_api.h" #include "predef_rule_init.h" #include "redis_client.h" #include "config_validater.h" #ifdef USE_REST #include "ngic_timer.h" #endif /* USE_REST */ #ifdef SDN_ODL_BUILD #include "nb.h" #endif #ifdef USE_CSID #include "csid_struct.h" #endif /* USE_CSID */ //#define RTE_LOGTYPE_CP RTE_LOGTYPE_USER4 #define CP "CONTROL PLANE" #define CP_LOG_PATH "logs/cp.log" #define LOGGER_JSON_PATH "../config/log.json" #define DDF2 "DDF2" extern void *ddf2_fd; uint32_t li_seq_no; uint32_t start_time; extern pfcp_config_t config; extern uint8_t gw_type; enum cp_config spgw_cfg; #ifdef USE_REST uint32_t up_time = 0; uint8_t rstCnt = 0; #endif /* USE_REST*/ #ifdef USE_CSID uint16_t local_csid = 0; #endif /* USE_CSID */ struct cp_params cp_params; extern struct cp_stats_t cp_stats; extern int gx_app_sock_read; extern int route_sock; int route_sock = -1; int apnidx = 0; clock_t cp_stats_execution_time; _timer_t st_time; int clSystemLog = STANDARD_LOGID; /** * @brief : Setting/enable CP RTE LOG_LEVEL. * @param : log_level, log level to be set * @return : Returns nothing */ static void set_log_level(uint8_t log_level) { /** Note :In dpdk set max log level is INFO, here override the * max value of RTE_LOG_INFO for enable DEBUG logs (dpdk-16.11.4 * and dpdk-18.02). */ if (log_level == NGIC_DEBUG) rte_log_set_level(RTE_LOGTYPE_CP, RTE_LOG_DEBUG); else if (log_level == NOTICE) rte_log_set_global_level(RTE_LOG_NOTICE); else rte_log_set_global_level(RTE_LOG_INFO); } /** * * @brief : Parses non-dpdk command line program arguments for control plane * @param : argc, number of arguments * @param : argv, array of c-string arguments * @return : Returns nothing */ static void parse_arg(int argc, char **argv) { char errbuff[PCAP_ERRBUF_SIZE]; int args_set = 0; int c = 0; pcap_t *pcap; const struct option long_options[] = { {"pcap_file_in", required_argument, NULL, 'x'}, {"pcap_file_out", required_argument, NULL, 'y'}, {"log_level", required_argument, NULL, 'z'}, {0, 0, 0, 0} }; do { int option_index = 0; c = getopt_long(argc, argv, "x:y:z:", long_options, &option_index); if (c == -1) break; switch (c) { case 'x': pcap_reader = pcap_open_offline(optarg, errbuff); break; case 'y': pcap = pcap_open_dead(DLT_EN10MB, UINT16_MAX); pcap_dumper = pcap_dump_open(pcap, optarg); s11_pcap_fd = pcap_fileno(pcap); break; case 'z': set_log_level((uint8_t)atoi(optarg)); args_set |= LOG_LEVEL_SET; break; default: rte_panic("Unknown argument - %s.", argv[optind]); break; } } while (c != -1); if ((args_set & REQ_ARGS) != REQ_ARGS) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Usage: %s\n", LOG_VALUE, argv[0]); for (c = 0; long_options[c].name; ++c) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"\t[ -%s | -%c ] %s\n", LOG_VALUE, long_options[c].name, long_options[c].val, long_options[c].name); } rte_panic("\n"); } } /** * @brief : callback initated by nb listener thread * @param : arg, unused * @return : never returns */ static int control_plane(void) { iface_init_ipc_node(); iface_ipc_register_msg_cb(MSG_DDN, cb_ddn); while (1) { process_cp_msgs(); } return 0; } /** * @brief : callback * @param : signal * @return : never returns */ static void sig_handler(int signo) { clLog(clSystemLog, eCLSeverityDebug, "signal received \n"); if ((signo == SIGINT) || (signo == SIGTERM)) { /*Close connection to redis server*/ if ( ctx != NULL) redis_disconnect(ctx); if ((config.use_gx) && gx_app_sock_read > 0) close_ipc_channel(gx_app_sock_read); deinit_ddf(); #ifdef SYNC_STATS retrive_stats_entry(); close_stats(); #endif /* SYNC_STATS */ #ifdef USE_REST gst_deinit(); #endif /* USE_REST */ close(route_sock); rte_exit(EXIT_SUCCESS, "received SIGINT\n"); } } /** * @brief : init signals * @param : void * @return : never returns */ static void init_signal_handler(void) { { sigset_t sigset; /* mask SIGALRM in all threads by default */ sigemptyset(&sigset); sigaddset(&sigset, SIGRTMIN); sigaddset(&sigset, SIGRTMIN + 2); sigaddset(&sigset, SIGRTMIN + 3); sigaddset(&sigset, SIGUSR1); sigprocmask(SIG_BLOCK, &sigset, NULL); } struct sigaction sa; /* Setup the signal handler */ sa.sa_handler = sig_handler; sa.sa_flags = SA_RESTART; sigfillset(&sa.sa_mask); if (sigaction(SIGINT, &sa, NULL) == -1) {} if (sigaction(SIGTERM, &sa, NULL) == -1) {} if (sigaction(SIGRTMIN+1, &sa, NULL) == -1) {} } /** * @brief : initializes the core assignments for various control plane threads * @param : No param * @return : Returns nothing */ static void init_cp_params(void) { unsigned last_lcore = rte_get_master_lcore(); cp_params.stats_core_id = rte_get_next_lcore(last_lcore, 1, 0); if (cp_params.stats_core_id == RTE_MAX_LCORE) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Insufficient cores in coremask to " "spawn stats thread\n", LOG_VALUE); last_lcore = cp_params.stats_core_id; #ifdef SIMU_CP cp_params.simu_core_id = rte_get_next_lcore(last_lcore, 1, 0); if (cp_params.simu_core_id == RTE_MAX_LCORE) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Insufficient cores in coremask to " "spawn stats thread\n", LOG_VALUE); last_lcore = cp_params.simu_core_id; #endif } static void init_cli_framework(void) { set_gw_type(OSS_CONTROL_PLANE); cli_node.upsecs = &cli_node.cli_config.oss_reset_time; cli_init(&cli_node, &cli_node.cli_config.cnt_peer); cli_node.cli_config.perf_flag = config.perf_flag; cli_node.cli_config.gw_adapter_callback_list.update_request_tries = &post_request_tries; cli_node.cli_config.gw_adapter_callback_list.update_request_timeout = &post_request_timeout; cli_node.cli_config.gw_adapter_callback_list.update_periodic_timer = &post_periodic_timer; cli_node.cli_config.gw_adapter_callback_list.update_transmit_timer = &post_transmit_timer; cli_node.cli_config.gw_adapter_callback_list.update_transmit_count = &post_transmit_count; cli_node.cli_config.gw_adapter_callback_list.update_perf_flag = &update_perf_flag; cli_node.cli_config.gw_adapter_callback_list.get_request_tries = &get_request_tries; cli_node.cli_config.gw_adapter_callback_list.get_request_timeout = &get_request_timeout; cli_node.cli_config.gw_adapter_callback_list.get_periodic_timer = &get_periodic_timer; cli_node.cli_config.gw_adapter_callback_list.get_transmit_timer = &get_transmit_timer; cli_node.cli_config.gw_adapter_callback_list.get_transmit_count = get_transmit_count; cli_node.cli_config.gw_adapter_callback_list.get_perf_flag = &get_perf_flag; cli_node.cli_config.gw_adapter_callback_list.get_cp_config = &fill_cp_configuration; cli_node.cli_config.gw_adapter_callback_list.add_ue_entry = &fillup_li_df_hash; cli_node.cli_config.gw_adapter_callback_list.update_ue_entry = &fillup_li_df_hash; cli_node.cli_config.gw_adapter_callback_list.delete_ue_entry = &del_li_entry; /* Init rest framework */ init_rest_framework(config.cli_rest_ip_buff, config.cli_rest_port); } /** * @brief : Main function - initializes dpdk environment, parses command line arguments, * calls initialization function, and spawns stats and control plane function * @param : argc, number of arguments * @param : argv, array of c-string arguments * @return : returns 0 */ int main(int argc, char **argv) { int ret; uint16_t uiLiCntr = 0; struct li_df_config_t li_df_config[LI_MAX_SIZE]; /* Precondition for configuration file */ read_cfg_file(CP_CFG_PATH); init_log_module(LOGGER_JSON_PATH); init_signal_handler(); start_time = current_ntp_timestamp(); #ifdef USE_REST /* Set current component start/up time */ up_time = current_ntp_timestamp(); /* Increment the restart counter value after starting control plane */ rstCnt = update_rstCnt(); TIMER_GET_CURRENT_TP(st_time); printf("CP: Control-Plane rstCnt: %u\n", rstCnt); recovery_time_into_file(start_time); #endif /* USE_REST */ ret = rte_eal_init(argc, argv); if (ret < 0) rte_panic("Cannot init EAL\n"); parse_arg(argc - ret, argv + ret); config_cp_ip_port(&config); init_cli_framework(); init_cp(); init_cp_params(); if (config.cp_type != SGWC) { /* Create and initialize the tables to maintain the predefined rules info*/ init_predef_rule_hash_tables(); /* Init rule tables of user-plane */ init_dp_rule_tables(); } if (config.cp_type == SGWC && config.generate_sgw_cdr) { init_redis(); } else if(config.cp_type != SGWC && config.generate_cdr){ init_redis(); } ret = registerCpOnDadmf(config.dadmf_ip, config.dadmf_port, config.dadmf_local_addr, li_df_config, &uiLiCntr); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, "Failed to register Control Plane on D-ADMF"); } ret = fillup_li_df_hash(li_df_config, uiLiCntr); if (ret != 0) { clLog(clSystemLog, eCLSeverityCritical, "Failed to fillup LI hash"); } /* Create TCP connection between control-plane and d-df2 */ init_ddf(); ddf2_fd = create_ddf_tunnel(config.ddf2_ip, config.ddf2_port, config.ddf2_local_ip, (const uint8_t *)DDF2); if (ddf2_fd == NULL) { clLog(clSystemLog, eCLSeverityCritical, "Failed to create tcp connection between Control Plane and D-DF2"); } /* TODO: Need to Re-arrange the hash initialize */ create_heartbeat_hash_table(); /* Make a connection between control-plane and gx_app */ if((config.use_gx) && config.cp_type != SGWC) { start_cp_app(); fill_gx_iface_ip(); } #ifdef SYNC_STATS stats_init(); init_stats_hash(); #endif /* SYNC_STATS */ init_stats_timer(); if (cp_params.stats_core_id != RTE_MAX_LCORE) rte_eal_remote_launch(do_stats, NULL, cp_params.stats_core_id); #ifdef SIMU_CP if (cp_params.simu_core_id != RTE_MAX_LCORE) rte_eal_remote_launch(simu_cp, NULL, cp_params.simu_core_id); #endif #ifdef USE_REST /* Create thread for handling for sending echo req to its peer node */ rest_thread_init(); #endif /* USE_REST */ init_pfcp_tables(); init_sm_hash(); #ifdef USE_CSID init_fqcsid_hash_tables(); #endif /* USE_CSID */ recovery_flag = 0; control_plane(); /* TODO: Move this call in appropriate place */ /* clear_heartbeat_hash_table(); */ return 0; }
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c_messages/create_indir_data_frwd_tunnel.c
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ue.h" #include "gtp_messages.h" #include "gtpv2c_set_ie.h" #include "pfcp_set_ie.h" extern int clSystemLog; extern pfcp_config_t config; void set_create_indir_data_frwd_tun_response(gtpv2c_header_t *gtpv2c_tx, pdn_connection *pdn) { eps_bearer *bearer = NULL; ue_context *context = NULL; int ret = 0; create_indir_data_fwdng_tunn_rsp_t crt_resp = {0}; node_address_t ip = {0}; context= pdn->context; ret = fill_ip_addr(config.s11_ip.s_addr, config.s11_ip_v6.s6_addr, &ip); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT "Error while assigning " "IP address", LOG_VALUE); } set_gtpv2c_teid_header((gtpv2c_header_t *) &crt_resp, GTP_CREATE_INDIRECT_DATA_FORWARDING_TUNNEL_RSP, pdn->context->s11_mme_gtpc_teid, pdn->context->sequence, 0); set_cause_accepted(&crt_resp.cause, IE_INSTANCE_ZERO); set_gtpc_fteid(&crt_resp.sender_fteid_ctl_plane, GTPV2C_IFTYPE_S11S4_SGW_GTPC, IE_INSTANCE_ZERO, ip, (pdn->context->s11_sgw_gtpc_teid)); for (uint8_t uiCnt = 0; uiCnt < MAX_BEARERS; ++uiCnt) { bearer = context->indirect_tunnel->pdn->eps_bearers[uiCnt]; if(bearer == NULL) continue; set_ie_header(&crt_resp.bearer_contexts[uiCnt].header, GTP_IE_BEARER_CONTEXT, IE_INSTANCE_ZERO, 0); set_cause_accepted(&crt_resp.bearer_contexts[uiCnt].cause, IE_INSTANCE_ZERO); crt_resp.bearer_contexts[uiCnt].header.len += sizeof(struct cause_ie_hdr_t) + IE_HEADER_SIZE; set_ebi(&crt_resp.bearer_contexts[uiCnt].eps_bearer_id, IE_INSTANCE_ZERO, bearer->eps_bearer_id); crt_resp.bearer_contexts[uiCnt].header.len += sizeof(uint8_t) + IE_HEADER_SIZE; set_gtpc_fteid(&crt_resp.bearer_contexts[uiCnt].sgw_fteid_dl_data_fwdng, GTPV2C_IFTYPE_S1U_SGW_GTPU ,IE_INSTANCE_THREE, bearer->s1u_sgw_gtpu_ip, bearer->s1u_sgw_gtpu_teid); crt_resp.bearer_contexts[uiCnt].header.len += sizeof(struct fteid_ie_hdr_t) + sizeof(struct in_addr) + IE_HEADER_SIZE; } uint16_t msg_len = 0; msg_len = encode_create_indir_data_fwdng_tunn_rsp(&crt_resp, (uint8_t *)gtpv2c_tx); gtpv2c_tx->gtpc.message_len = htons(msg_len - 4); }
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c_messages/delete_s5s8_session.c
<filename>cp/gtpv2c_messages/delete_s5s8_session.c /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <errno.h> #include <rte_debug.h> #include "packet_filters.h" #include "gtpv2c_set_ie.h" #include "../cp_dp_api/vepc_cp_dp_api.h" #include "pfcp_messages.h" #include "pfcp_set_ie.h" #include "pfcp_messages_encoder.h" #include "pfcp_util.h" #include "pfcp_session.h" #include "sm_struct.h" #include "../cp_stats.h" #include "../ue.h" #include"cp_config.h" extern int pfcp_fd; extern int pfcp_fd_v6; extern peer_addr_t upf_pfcp_sockaddr; extern int clSystemLog; int gen_sgwc_s5s8_delete_session_request(gtpv2c_header_t *gtpv2c_rx, gtpv2c_header_t *gtpv2c_tx, uint32_t pgw_gtpc_del_teid, uint32_t sequence, uint8_t del_ebi) { gtpv2c_ie *current_rx_ie; gtpv2c_ie *limit_rx_ie; set_gtpv2c_teid_header(gtpv2c_tx, GTP_DELETE_SESSION_REQ, pgw_gtpc_del_teid, sequence, 0); FOR_EACH_GTPV2C_IE(gtpv2c_rx, current_rx_ie, limit_rx_ie) { if (current_rx_ie->type == GTP_IE_EPS_BEARER_ID && current_rx_ie->instance == IE_INSTANCE_ZERO) { set_ebi_ie(gtpv2c_tx, IE_INSTANCE_ZERO, del_ebi); } else if (current_rx_ie->type == GTP_IE_USER_LOC_INFO && current_rx_ie->instance == IE_INSTANCE_ZERO) { set_ie_copy(gtpv2c_tx, current_rx_ie); } else if (current_rx_ie->type == GTP_IE_INDICATION && current_rx_ie->instance == IE_INSTANCE_ZERO) { set_ie_copy(gtpv2c_tx, current_rx_ie); } } return 0; }
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/pfcp_up_struct.h
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef PFCP_UP_STRUCT_H #define PFCP_UP_STRUCT_H #include <stdbool.h> #include "pfcp_ies.h" #include "pfcp_struct.h" #include "vepc_cp_dp_api.h" #include "../interface/interface.h" #ifdef USE_CSID #include "csid_struct.h" #endif /* USE_CSID */ /** * ipv4 address format. */ #define IPV4_ADDR "%u.%u.%u.%u" #define IPV4_ADDR_HOST_FORMAT(a) (uint8_t)(((a) & 0xff000000) >> 24), \ (uint8_t)(((a) & 0x00ff0000) >> 16), \ (uint8_t)(((a) & 0x0000ff00) >> 8), \ (uint8_t)((a) & 0x000000ff) /* Interface type define */ #define ACCESS 0 #define CORE 1 #define MAX_BEARERS 15 #define MAX_LIST_SIZE 16 #define ACL_TABLE_NAME_LEN 16 #define MAX_ACL_TABLES 1000 #define MAX_SDF_RULE_NUM 32 #define NAME_LEN 32 typedef struct pfcp_session_t pfcp_session_t; typedef struct pfcp_session_datat_t pfcp_session_datat_t; typedef struct pdr_info_t pdr_info_t; typedef struct qer_info_t qer_info_t; typedef struct urr_info_t urr_info_t; typedef struct predef_rules_t predef_rules_t; /** * @brief : rte hash for pfcp context * hash key: pfcp sess id, data: pfcp_session_t */ struct rte_hash *sess_ctx_by_sessid_hash; /** * @brief : rte hash for session data by teid. * hash key: teid, data: pfcp_session_datat_t * Usage: * 1) SGW-U : UL & DL packet detection (Check packet against sdf rules defined in acl_table_name and get matching PDR ID. * 2) PGW-U : UL packet detection (Check against UE IP address and sdf rules defined in acl_table_name and get matching PDR ID.) */ struct rte_hash *sess_by_teid_hash; /** * @brief : rte hash for session data by ue ip4 addr. * hash key: ue ip addr, data: pfcp_session_datat_t * Usage: * PGW-U : DL packet detection () */ struct rte_hash *sess_by_ueip_hash; /** * @brief : rte hash for pdr by pdr id. * hash key: pdr id, data: pdr_info_t (pointer to already allocated pfcp_session_datat_t:pdr_info_t) */ struct rte_hash *pdr_by_id_hash; /** * @brief : rte hash for far by far id. * hash key: far id, data: far_info_t (pointer to already allocated pfcp_session_datat_t:pdr_info_t:far_info_t) */ struct rte_hash *far_by_id_hash; /** * @brief : rte hash for qer by qer id. * hash key: qer id, data: qer_info_t (pointer to already allocated pfcp_session_datat_t:pdr_info_t:qer_info_t) */ struct rte_hash *qer_by_id_hash; /** * @brief : rte hash for urr data by urr id. * hash key: urr id, data: urr_info_t (pointer to already allocated pfcp_session_datat_t:pdr_info_t:urr_info_t) */ struct rte_hash *urr_by_id_hash; /** * @brief : rte hash for timer data by urr id. * hash key: urr id, data: peerData */ struct rte_hash *timer_by_id_hash; /** * @brief : rte hash for qer_id and rule name. * hash key: qer id, data: mtr_rule */ struct rte_hash *qer_rule_hash; enum up_session_state { CONNECTED, IDLE, IN_PROGRESS }; /* Outer Header Removal/Creation */ enum outer_header_rvl_crt { GTPU_UDP_IPv4, GTPU_UDP_IPv6, UP_UDP_IPv4, UP_UDP_IPv6, NOT_SET_OUT_HDR_RVL_CRT }; /* use both Ipv6 and Ipv4 IPs as key to store session data */ struct ue_ip { uint32_t ue_ipv4; uint8_t ue_ipv6[IPV6_ADDRESS_LEN]; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); typedef struct ue_ip ue_ip_t; /** * @brief : Maintains predefined rules list */ typedef struct predef_rules_t { uint8_t predef_rules_nm[RULE_NAME_LEN]; /* TODO: Need to Discuss */ predef_rules_t *next; }predef_rules_t; /** * @brief : Maintains far related forwarding parameter info */ typedef struct far_frwdng_parms_t { ntwk_inst_t ntwk_inst; /* Network Instance */ dst_intfc_t dst_intfc; /* Destination Interface */ outer_hdr_creation_t outer_hdr_creation; /* Outer Header Creation */ trnspt_lvl_marking_t trnspt_lvl_marking; /* Transport Level Marking */ frwdng_plcy_t frwdng_plcy; /* Forwarding policy */ /* pfcpsmreq_flags [sndem]*/ hdr_enrchmt_t hdr_enrchmt; /* Container for header enrichment */ } far_frwdng_parms_t; /** * @brief : Maintains duplicating parameters */ typedef struct duplicating_parms_t { dst_intfc_t dst_intfc; outer_hdr_creation_t outer_hdr_creation; }duplicating_parms_t; /** * @brief : Maintains li data */ typedef struct li_config_t { uint64_t id; uint8_t west_direction; uint8_t west_content; uint8_t east_direction; uint8_t east_content; uint8_t forward; } li_config_t; /** * @brief : Maintains far related information */ typedef struct far_info_t { uint16_t pdr_count; /*PDR using the FAR*/ uint32_t far_id_value; /* FAR ID */ apply_action actions; /* Apply Action parameters */ far_frwdng_parms_t frwdng_parms; /* Forwarding paramneters */ uint8_t li_config_cnt; li_config_t li_config[MAX_LI_ENTRIES_PER_UE]; /* User Level Packet Copying configurations */ uint32_t dup_parms_cnt; duplicating_parms_t dup_parms[MAX_LIST_SIZE]; //pfcp_session_t *session; /* Pointer to session */ pfcp_session_datat_t *session; /* Pointer to session */ /* Mapping of FAR with BAR */ uint8_t bar_id_value; }far_info_t; /** * @brief : Maintains qer related information */ typedef struct qer_info_t { uint32_t qer_id; /* FAR ID */ uint32_t qer_corr_id_val; /* QER Correlation ID */ gate_status_t gate_status; /* Gate Status UL/DL */ mbr_t max_bitrate; /* Maximum Bitrate */ gbr_t guaranteed_bitrate; /* Guaranteed Bitrate */ packet_rate_t packet_rate; /* Packet Rate */ dl_flow_lvl_marking_t dl_flow_lvl_marking; /* Downlink Flow Level Marking */ qfi_t qos_flow_ident; /* QOS Flow Ident */ rqi_t reflective_qos; /* RQI */ paging_plcy_indctr_t paging_plcy_indctr; /* Paging policy */ avgng_wnd_t avgng_wnd; /* Averaging Window */ //pfcp_session_t *session; /* Pointer to session */ pfcp_session_datat_t *session; /* Pointer to session */ qer_info_t *next; }qer_info_t; /** * @brief : Maintains bar related information */ typedef struct bar_info_t { uint8_t bar_id; /* BAR ID */ dnlnk_data_notif_delay_t ddn_delay; suggstd_buf_pckts_cnt_t suggstd_buf_pckts_cnt; dl_buffering_suggested_packets_cnt_t dl_buf_suggstd_pckts_cnt; }bar_info_t; /** * @brief : Maintains urr related information */ typedef struct urr_info_t { /* TODO: Add members */ uint16_t pdr_count; /*PDR using the URR*/ uint32_t urr_id; /* URR ID */ uint32_t urr_seq_num; /* URR seq num */ uint16_t meas_method; /* Measurment Method */ uint16_t rept_trigg; /* Reporting Trigger */ uint32_t vol_thes_uplnk; /* Vol Threshold */ uint32_t vol_thes_dwnlnk; /* Vol Threshold */ uint32_t time_thes; /* Time Threshold */ uint32_t uplnk_data; /* Uplink data usage */ uint32_t dwnlnk_data; /* Downlink Data Usage */ uint32_t start_time; /* Start Time */ uint32_t end_time; /* End Time */ uint32_t first_pkt_time; /* First Pkt Time */ uint32_t last_pkt_time; /* Last Pkt Time */ urr_info_t *next; }urr_info_t; /** * @brief : Maintains pdr related information */ typedef struct pdr_info_t { uint16_t rule_id; /* PDR ID*/ uint32_t prcdnc_val; /* Precedence Value*/ far_info_t *far; pdi_t pdi; /* Packet Detection Information */ outer_hdr_removal_t outer_hdr_removal; /* Outer Header Removal */ uint8_t qer_count; /* Number of QER */ qer_info_t *quer; /* Collection of QER IDs */ uint8_t urr_count; /* Number of URR */ urr_info_t *urr; /* Collection of URR IDs */ uint8_t predef_rules_count; /* Number of predefine rules */ predef_rules_t predef_rules[MAX_LIST_SIZE]; /* Collection of active predefined rules */ /* Need to discuss on it: DDN*/ pfcp_session_t *session; /* Pointer to session */ pdr_info_t *next; }pdr_info_t; /** * @brief : Maintains pfcp session data related information */ typedef struct pfcp_session_datat_t { uint8_t ipv4; uint8_t ipv6; /* UE Addr */ uint32_t ue_ip_addr; uint8_t ue_ipv6_addr[IPV6_ADDRESS_LEN]; /* West Bound eNB/SGWU Address*/ node_address_t wb_peer_ip_addr; /* East Bound PGWU Address */ node_address_t eb_peer_ip_addr; char acl_table_name[ACL_TABLE_NAME_LEN]; int acl_table_indx[MAX_SDF_RULE_NUM]; uint8_t acl_table_count; bool predef_rule; pdr_info_t *pdrs; /** Session state for use with downlink data processing*/ enum up_session_state sess_state; /* Header Creation */ enum outer_header_rvl_crt hdr_crt; /* Header Removal */ enum outer_header_rvl_crt hdr_rvl; /** Ring to hold the DL pkts for this session */ struct rte_ring *dl_ring; struct pfcp_session_datat_t *next; } pfcp_session_datat_t; /** * @brief : Maintains sx li config */ typedef struct li_sx_config_t { uint64_t id; uint8_t sx; uint8_t forward; } li_sx_config_t; /** * @brief : Maintains pfcp session related information */ typedef struct pfcp_session_t { uint64_t cp_seid; uint64_t up_seid; uint64_t imsi; /* TODO: Add the struct for peer_addr info*/ peer_addr_t cp_ip; node_address_t cp_node_addr; uint8_t ber_cnt; uint32_t teids[MAX_BEARERS]; #ifdef USE_CSID /* West Bound eNB/SGWU FQ-CSID */ fqcsid_t *wb_peer_fqcsid; /* East Bound PGWU FQ-CSID */ fqcsid_t *eb_peer_fqcsid; /* MME FQ-CSID*/ fqcsid_t *mme_fqcsid; /* SGW-C/SAEGW-C CSID */ fqcsid_t *sgw_fqcsid; /* PGW-C FQ-CSID */ fqcsid_t *pgw_fqcsid; /* SGW-U/PGW-U/SAEGW-U FQ-CSID */ fqcsid_t *up_fqcsid; #endif /* USE_REST */ /* User Level Packet Copying Sx Configurations */ uint8_t li_sx_config_cnt; li_sx_config_t li_sx_config[MAX_LI_ENTRIES_PER_UE]; /* BAR ID Changes */ bar_info_t bar; pfcp_session_datat_t *sessions; } pfcp_session_t; /** * @brief : Maintains peer node address and type related information */ struct peer_ip_addr{ uint8_t type; union{ uint32_t ipv4_addr; uint8_t ipv6_addr[IPV6_ADDRESS_LEN]; }ip; }__attribute__((packed)); /** * @brief : Maintains information for hash key for rule */ typedef struct { struct peer_ip_addr cp_ip_addr; uint64_t cp_seid; uint32_t id; }rule_key; /** * @brief : Add session entry in session context hash table. * @param : up_sess_id , key * @param : pfcp_session_t sess_cntxt * @return : 0 or 1. */ int8_t add_sess_info_entry(uint64_t up_sess_id, pfcp_session_t *sess_cntxt); /** * @brief : Get UP Session entry from session hash table. * @param : UP SESS ID key. * @param : is_mod * @return : pfcp_session_t sess_cntxt or NULL */ pfcp_session_t * get_sess_info_entry(uint64_t up_sess_id, uint8_t is_mod); /** * @brief : Delete Session entry from Session hash table. * @param : UP SESS ID, key. * @return : 0 or 1. */ int8_t del_sess_info_entry(uint64_t up_sess_id); /** * @brief : Get Session entry by teid from session hash table. * @param : teid, key. * @param : pfcp_session_datat_t head, head pointer * @param : is_mod * @return : pfcp_session_t sess_cntxt or NULL */ pfcp_session_datat_t * get_sess_by_teid_entry(uint32_t teid, pfcp_session_datat_t **head, uint8_t is_mod); /** * @brief : Delete Session entry by teid from Session hash table. * @param : teid, key. * @return : 0 or 1. */ int8_t del_sess_by_teid_entry(uint32_t teid); /** * @brief : Get Session entry by UE_IP type V4 from session hash table. * @param : UE_IP, key. * @param : pfcp_session_datat_t head, head pointer * @param : is_mod * @return : pfcp_session_t sess_cntxt or NULL */ pfcp_session_datat_t * get_sess_by_ueip_entry(ue_ip_t ue_ip, pfcp_session_datat_t **head, uint8_t is_mod); /** * @brief : Delete Session entry by UE_IP from Session hash table. * @param : UE_IP, key. * @return : 0 or 1. */ int8_t del_sess_by_ueip_entry(ue_ip_t ue_ip); /** * @brief : Get PDR entry from PDR hash table. * @param : PDR ID, key * @param : pdr_info_t *head, head pointer * @param : cp_ip, peer node address * @param : cp_seid, CP session ID of UE * @return : pdr_info_t pdr or NULL */ pdr_info_t * get_pdr_info_entry(uint16_t rule_id, pdr_info_t **head, uint16_t is_add, peer_addr_t cp_ip, uint64_t cp_seid); /** * @brief : Delete PDR entry from PDR hash table. * @param : PDR ID, key * @param : peer_ip, ip address and type of peer node * @param : cp_ip, peer node address * @param : cp_seid, CP session ID of UE * @return : 0 or 1. */ int8_t del_pdr_info_entry(uint16_t rule_id, peer_addr_t cp_ip, uint64_t cp_seid); /** * @brief : Add FAR entry in FAR hash table. * @param : FAR_ID, key * @param : far_info_t far * @param : cp_ip, peer node address * @param : cp_seid, CP session ID of UE * @return : 0 or 1. */ int8_t add_far_info_entry(uint16_t far_id, far_info_t **far, peer_addr_t cp_ip, uint64_t cp_seid); /** * @brief : Get FAR entry from FAR hash table. * @param : FAR ID, key * @param : cp_ip, peer node address * @param : cp_seid, CP session ID of UE * @return : far_info_t pdr or NULL */ far_info_t * get_far_info_entry(uint16_t far_id, peer_addr_t cp_ip, uint64_t cp_seid); /** * @brief : Delete FAR entry from FAR hash table. * @param : FAR ID, key. * @param : cp_ip, peer node address * @param : cp_seid, CP session ID of UE * @return : 0 or 1. */ int8_t del_far_info_entry(uint16_t far_id, peer_addr_t cp_ip, uint64_t cp_seid); /** * @brief : Add QER entry in QER hash table. * @param : qer_id, key * @param : qer_info_t context * @param : cp_ip, peer node address * @param : cp_seid, CP session ID of UE * @return : 0 or 1. */ int8_t add_qer_info_entry(uint32_t qer_id, qer_info_t **cntxt, peer_addr_t cp_ip, uint64_t cp_seid); /** * @brief : Get QER entry from QER hash table. * @param : QER ID, key. * @param : cp_ip, peer node address * @param : cp_seid, CP session ID of UE * @return : qer_info_t cntxt or NULL */ qer_info_t * get_qer_info_entry(uint32_t qer_id, qer_info_t **head, peer_addr_t cp_ip, uint64_t cp_seid); /** * @brief : Delete QER entry from QER hash table. * @param : QER ID, key * @param : cp_ip, peer node address * @param : cp_seid, CP session ID of UE * @return : 0 or 1. */ int8_t del_qer_info_entry(uint32_t qer_id, peer_addr_t cp_ip, uint64_t cp_seid); /** * @brief : Add URR entry in URR hash table. * @param : urr_id, key * @param : urr_info_t context * @param : cp_ip, peer node address * @param : cp_seid, CP session ID of UE * @return : 0 or 1. */ int8_t add_urr_info_entry(uint32_t urr_id, urr_info_t **cntxt, peer_addr_t cp_ip, uint64_t cp_seid); /** * @brief : Get URR entry from urr hash table. * @param : URR ID, key * @param : cp_ip, peer node address * @param : cp_seid, CP session ID of UE * @return : urr_info_t cntxt or NULL */ urr_info_t * get_urr_info_entry(uint32_t urr_id, peer_addr_t cp_ip, uint64_t cp_seid); /** * @brief : Delete URR entry from URR hash table. * @param : URR ID, key * @param : cp_ip, ip address and type of peer node * @param : cp_seid, CP session ID of UE * @return : 0 or 1. */ int8_t del_urr_info_entry(uint32_t urr_id, peer_addr_t cp_ip, uint64_t cp_seid); /** * @brief : Initializes the pfcp context hash table used to account for * PDR, QER, BAR and FAR rules information tables and Session tables based on sessid, teid and UE_IP. * @param : No param * @return : Returns nothing */ void init_up_hash_tables(void); /** * @brief : Generate the user plane SESSION ID * @param : cp session id * @return : up session id */ uint64_t gen_up_sess_id(uint64_t cp_sess_id); /** * @brief : Add entry for meter rule and qer_id * @param : rule_name * @param : qer_id * @return : Retuns 0 if success else -1 */ qer_info_t * add_rule_info_qer_hash(uint8_t *rule_name); /** * @brief : Allocates ring for buffering downlink packets * Allocate downlink packet buffer ring from a set of * rings from the ring container. * @param : No param * @return : Returns rte_ring Allocated ring on success, NULL on failure */ struct rte_ring *allocate_ring(unsigned int dl_ring_size); #endif /* PFCP_UP_STRUCT_H */
nikhilc149/e-utran-features-bug-fixes
cp/cp_config.c
<gh_stars>0 /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <rte_common.h> #include <rte_debug.h> #include <rte_eal.h> #include <rte_cfgfile.h> #include <netdb.h> #include "cp_config.h" #include "cp_stats.h" #include "debug_str.h" extern int clSystemLog; extern pfcp_config_t config; void config_cp_ip_port(pfcp_config_t *config) { int32_t i = 0; int32_t num_ops_entries = 0; int32_t num_app_entries = 0; int32_t num_apn_entries = 0; int32_t num_cache_entries = 0; int32_t num_ip_pool_entries = 0; int32_t num_global_entries = 0; int32_t num_urr_entries = 0; struct rte_cfgfile_entry *global_entries = NULL; struct rte_cfgfile_entry *apn_entries = NULL; struct rte_cfgfile_entry *ip_pool_entries = NULL; struct rte_cfgfile_entry *cache_entries = NULL; struct rte_cfgfile_entry *app_entries = NULL; struct rte_cfgfile_entry *ops_entries = NULL; struct rte_cfgfile_entry *urr_entries = NULL; struct rte_cfgfile *file = rte_cfgfile_load(STATIC_CP_FILE, 0); if (file == NULL) { rte_exit(EXIT_FAILURE, "Cannot load configuration file %s\n", STATIC_CP_FILE); } fprintf(stderr, "CP: PFCP Config Parsing %s\n", STATIC_CP_FILE); /* Read GLOBAL seaction values and configure respective params. */ num_global_entries = rte_cfgfile_section_num_entries(file, GLOBAL_ENTRIES); if (num_global_entries > 0) { global_entries = rte_malloc_socket(NULL, sizeof(struct rte_cfgfile_entry) * num_global_entries, RTE_CACHE_LINE_SIZE, rte_socket_id()); } if (global_entries == NULL) { rte_panic("Error configuring global entry of %s\n", STATIC_CP_FILE); } rte_cfgfile_section_entries(file, GLOBAL_ENTRIES, global_entries, num_global_entries); for (i = 0; i < num_global_entries; ++i) { /* Parse SGWC, PGWC and SAEGWC values from cp.cfg */ if(strncmp(CP_TYPE, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->cp_type = (uint8_t)atoi(global_entries[i].value); fprintf(stderr, "CP: CP_TYPE : %s\n", config->cp_type == SGWC ? "SGW-C" : config->cp_type == PGWC ? "PGW-C" : config->cp_type == SAEGWC ? "SAEGW-C" : "UNKNOWN"); }else if (strncmp(S11_IPS, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { inet_aton(global_entries[i].value, &(config->s11_ip)); config->s11_ip_type |= 1; fprintf(stderr, "CP: S11_IP : %s\n", inet_ntoa(config->s11_ip)); }else if (strncmp(S11_IPS_V6, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { inet_pton(AF_INET6, global_entries[i].value, &(config->s11_ip_v6)); config->s11_ip_type |= 2; fprintf(stderr, "CP: S11_IP_V6 : %s\n", global_entries[i].value); }else if (strncmp(S11_PORTS, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->s11_port = (uint16_t)atoi(global_entries[i].value); fprintf(stderr, "CP: S11_PORT : %d\n", config->s11_port); } else if (strncmp(S5S8_IPS, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { inet_aton(global_entries[i].value, &(config->s5s8_ip)); config->s5s8_ip_type |= 1; fprintf(stderr, "CP: S5S8_IP : %s\n", inet_ntoa(config->s5s8_ip)); } else if (strncmp(S5S8_IPS_V6, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { inet_pton(AF_INET6, global_entries[i].value, &(config->s5s8_ip_v6)); config->s5s8_ip_type |= 2; fprintf(stderr, "CP: S5S8_IP_V6 : %s\n", global_entries[i].value); } else if (strncmp(S5S8_PORTS, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->s5s8_port = (uint16_t)atoi(global_entries[i].value); fprintf(stderr, "CP: S5S8_PORT : %d\n", config->s5s8_port); } else if (strncmp(PFCP_IPS , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { inet_aton(global_entries[i].value, &(config->pfcp_ip)); config->pfcp_ip_type |= 1; fprintf(stderr, "CP: PFCP_IP : %s\n", inet_ntoa(config->pfcp_ip)); } else if (strncmp(PFCP_IPS_V6, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { inet_pton(AF_INET6, global_entries[i].value, &(config->pfcp_ip_v6)); config->pfcp_ip_type |= 2; fprintf(stderr, "CP: PFCP_IPS_V6 : %s\n", global_entries[i].value); } else if (strncmp(PFCP_PORTS, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->pfcp_port = (uint16_t)atoi(global_entries[i].value); fprintf(stderr, "CP: PFCP_PORT : %d\n", config->pfcp_port); } else if (strncmp(DDF2_IP , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { strncpy(config->ddf2_ip, global_entries[i].value, IPV6_STR_LEN); fprintf(stderr, "CP: DDF2_IP : %s\n", config->ddf2_ip); } else if (strncmp(DDF2_PORT , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->ddf2_port = (uint16_t)atoi(global_entries[i].value); fprintf(stderr, "CP: DDF2_PORT : %d\n", config->ddf2_port); } else if (strncmp(DDF2_LOCAL_IPS , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { strncpy(config->ddf2_local_ip, global_entries[i].value, IPV6_STR_LEN); fprintf(stderr, "CP: DDF2_LOCAL_IP : %s\n", config->ddf2_local_ip); } else if (strncmp(DADMF_IPS , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { strncpy(config->dadmf_ip, global_entries[i].value, IPV6_STR_LEN); fprintf(stderr, "CP: DADMF_IP : %s\n", config->dadmf_ip); } else if (strncmp(DADMF_PORTS, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->dadmf_port = (uint16_t)atoi(global_entries[i].value); fprintf(stderr, "CP: DADMF_PORT : %d\n", config->dadmf_port); } else if (strncmp(DADMF_LOCAL_IPS , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { strncpy(config->dadmf_local_addr, global_entries[i].value, IPV6_STR_LEN); fprintf(stderr, "CP: DADMF_LOCAL_IP : %s\n", (config->dadmf_local_addr)); } else if (strncmp(UPF_PFCP_IPS , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { inet_aton(global_entries[i].value, &(config->upf_pfcp_ip)); config->upf_pfcp_ip_type |= 1; fprintf(stderr, "CP: UPF_PFCP_IP : %s\n", inet_ntoa(config->upf_pfcp_ip)); } else if (strncmp(UPF_PFCP_IPS_V6, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { inet_pton(AF_INET6, global_entries[i].value, &(config->upf_pfcp_ip_v6)); config->upf_pfcp_ip_type |= 2; fprintf(stderr, "CP: UPF_PFCP_IP_V6 : %s\n", global_entries[i].value); } else if (strncmp(UPF_PFCP_PORTS, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->upf_pfcp_port = (uint16_t)atoi(global_entries[i].value); fprintf(stderr, "CP: UPF_PFCP_PORT: %d\n", config->upf_pfcp_port); } else if (strncmp(REDIS_IPS , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { /*Check for IP type (ipv4/ipv6)*/ int ret = get_ip_address_type(global_entries[i].value); if ( ret == -1) { fprintf(stderr, "CP: CP_REDIS_IP : %s is in incorrect format\n", config->cp_redis_ip_buff); return; } else { config->redis_server_ip_type = ret; } strncpy(config->redis_ip_buff, global_entries[i].value, IPV6_STR_LEN); fprintf(stderr, "CP: REDIS_IP : %s\n", config->redis_ip_buff); } else if (strncmp(CP_REDIS_IP , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { /*Check for IP type (ipv4/ipv6)*/ int ret = get_ip_address_type(global_entries[i].value); if ( ret == -1) { fprintf(stderr, "CP: CP_REDIS_IP : %s is in incorrect format\n", config->cp_redis_ip_buff); return; } else { config->cp_redis_ip_type = ret; } strncpy(config->cp_redis_ip_buff, global_entries[i].value, IPV6_STR_LEN); fprintf(stderr, "CP: CP_REDIS_IP : %s\n", config->cp_redis_ip_buff); } else if (strncmp(REDIS_CERT_PATH , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { strncpy(config->redis_cert_path, global_entries[i].value, REDIS_CERT_PATH_LEN); fprintf(stderr, "CP: REDIS_CERT_PATH : %s\n", config->redis_cert_path); } else if (strncmp(REDIS_PORTS, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->redis_port = (uint16_t)atoi(global_entries[i].value); fprintf(stderr, "CP: REDIS_PORT: %d\n", config->redis_port); } else if (strncmp(SUGGESTED_PKT_COUNT, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->dl_buf_suggested_pkt_cnt = (uint16_t)atoi(global_entries[i].value); fprintf(stderr, "CP: SUGGESTED_PKT_COUNT: %d\n", config->dl_buf_suggested_pkt_cnt); } else if (strncmp(LOW_LVL_ARP_PRIORITY, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->low_lvl_arp_priority = (uint16_t)atoi(global_entries[i].value); fprintf(stderr, "CP: LOW_LEVEL_ARP_PRIORITY: %d\n", config->low_lvl_arp_priority); } /* Parse timer and counter values from cp.cfg */ if(strncmp(TRANSMIT_TIMER, global_entries[i].name, ENTRY_NAME_SIZE) == 0) config->transmit_timer = (int)atoi(global_entries[i].value); if(strncmp(PERIODIC_TIMER, global_entries[i].name, ENTRY_NAME_SIZE) == 0) config->periodic_timer = (int)atoi(global_entries[i].value); if(strncmp(TRANSMIT_COUNT, global_entries[i].name, ENTRY_NAME_SIZE) == 0) config->transmit_cnt = (uint8_t)atoi(global_entries[i].value); /* Parse CP Timer Request Time Out and Retries Values from cp.cfg */ if(strncmp(REQUEST_TIMEOUT, global_entries[i].name, ENTRY_NAME_SIZE) == 0){ if(check_cp_req_timeout_config(global_entries[i].value) == 0) { config->request_timeout = (int)atoi(global_entries[i].value); fprintf(stderr, "CP: REQUEST_TIMEOUT: %d\n", config->request_timeout); } else { rte_panic("Error configuring " "CP TIMER "REQUEST_TIMEOUT" invalid entry of %s\n", STATIC_CP_FILE); } }else { /* if CP Request Timer Parameter is not present is cp.cfg */ /* Defualt Request Timerout value */ /* 3 seconds = 3000 milisecond */ if(config->request_timeout == 0) { config->request_timeout = REQUEST_TIMEOUT_DEFAULT_VALUE; } } if(strncmp(REQUEST_TRIES, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { if(check_cp_req_tries_config(global_entries[i].value) == 0) { config->request_tries = (uint8_t)atoi(global_entries[i].value); fprintf(stderr, "CP: REQUEST_TRIES: %d\n", config->request_tries); } else { rte_panic("Error configuring " "CP TIMER "REQUEST_TRIES" invalid entry of %s\n", STATIC_CP_FILE); } } else { /* if CP Request Timer Parameter is not present is cp.cfg */ /* Defualt Request Retries value */ if(config->request_tries == 0) { config->request_tries = REQUEST_TRIES_DEFAULT_VALUE; } } /* DNS Parameter for Config CP with or without DNSquery */ if(strncmp(USE_DNS, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->use_dns = (uint8_t)atoi(global_entries[i].value); fprintf(stderr, "CP: %s : %s \n", (config->cp_type == SGWC ? "SGW-C" : config->cp_type == PGWC ? "PGW-C" : config->cp_type == SAEGWC ? "SAEGW-C" : "UNKNOWN"), ((config->use_dns)? "WITH DNS": "WITHOUT DNS")); } if (strncmp(CP_DNS_IP , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { /* Check for IP type (ipv4/ipv6) */ int8_t ip_type = get_ip_address_type(global_entries[i].value); if (ip_type == -1) { fprintf(stderr, "CP: CP_DNS_IP : %s is in incorrect format\n", global_entries[i].value); rte_panic(); } else { config->cp_dns_ip_type = ip_type; } strncpy(config->cp_dns_ip_buff, global_entries[i].value, IPV6_STR_LEN); fprintf(stdout, "CP: CP_DNS_IP : %s\n", config->cp_dns_ip_buff); } if (strncmp(CLI_REST_IP , global_entries[i].name, ENTRY_NAME_SIZE) == 0) { /* Check for IP type (ipv4/ipv6) */ int8_t ip_type = get_ip_address_type(global_entries[i].value); if (ip_type == -1) { fprintf(stderr, "CP: CP_REST_IP : %s is in incorrect format\n", global_entries[i].value); rte_panic(); } strncpy(config->cli_rest_ip_buff, global_entries[i].value, IPV6_STR_LEN); fprintf(stdout, "CP: CP_REST_IP : %s\n", config->cli_rest_ip_buff); } if(strncmp(CLI_REST_PORT, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->cli_rest_port = (uint16_t)atoi(global_entries[i].value); fprintf(stdout, "CP: CLI_REST_PORT : %d\n", config->cli_rest_port); } /* To ON/OFF CDR on PGW/SAEGW */ if(strncmp(GENERATE_CDR, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->generate_cdr = (uint8_t)atoi(global_entries[i].value); fprintf(stderr, "CP: [PGW/SAEGW] CDR GENERATION : %s\n", (config->generate_cdr)? "ENABLED" : "DISABLED"); if(config->generate_cdr > CDR_ON){ rte_panic("Error : Invalide value aasign to paramtere GENERATE_CDR \n"); } } /* To ON/OFF/CC_CHECK for CDR generation on SGW */ if(strncmp(GENERATE_SGW_CDR, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->generate_sgw_cdr = (uint8_t)atoi(global_entries[i].value); fprintf(stderr, "CP: [SGW] CDR GENERATION : %d\n", (config->generate_sgw_cdr)); if(config->generate_sgw_cdr > SGW_CC_CHECK){ rte_panic("Error : Invalide value aasign to paramtere GENERATE_SGW_CDR \n"); } } /* Charging Characteristic for the case of SGW */ if((config->generate_sgw_cdr == SGW_CC_CHECK) && strncmp(SGW_CC, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->sgw_cc = (uint8_t)atoi(global_entries[i].value); fprintf(stderr, "CP: Charging Characteristic for SGW : %s\n", get_cc_string(config->sgw_cc)); } if(config->cp_type != SGWC) { if(strncmp(USE_GX, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->use_gx = (uint8_t)atoi(global_entries[i].value); if(config->use_gx <= 1) { fprintf(stderr, "CP: USE GX : %s\n", (config->use_gx)? "ENABLED" : "DISABLED"); } else { rte_panic("Use 0 or 1 for gx interface DISABLE/ENABLE : %s\n", STATIC_CP_FILE); } } } if (strncmp(PERF_FLAG, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->perf_flag = (uint8_t)atoi(global_entries[i].value); if (config->perf_flag == PERF_ON || config->perf_flag == PERF_OFF) { fprintf(stderr, "CP: PERF FlAG : %s\n", (config->perf_flag)? "ENABLED" : "DISABLED"); } else { rte_panic("Use 0 or 1 for perf flag DISABLE/ENABLE : %s\n", STATIC_CP_FILE); } } if(strncmp(ADD_DEFAULT_RULE, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->add_default_rule = (uint8_t)atoi(global_entries[i].value); fprintf(stderr, "CP: ADD_DEFAULT_RULE : %s\n", (config->add_default_rule)? ((config->add_default_rule == 1) ? "ALLOW ANY TO ANY" : "DENY ANY TO ANY") : "DISABLED"); } /* IP_ALLOCATION_MODE parameter for CP Config */ if(strncmp(IP_ALLOCATION_MODE, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->ip_allocation_mode = (uint8_t)atoi(global_entries[i].value); fprintf(stderr, "CP: IP_ALLOCATION_MODE : %s\n", (config->ip_allocation_mode) ? "DYNAMIC" : "STATIC"); if (config->ip_allocation_mode > IP_MODE) { rte_panic("Error : Invalid value aasigned to IP_ALLOCATION_MODE \n"); } } /* IP_TYPE_SUPPORTED parameter for CP Config */ if(strncmp(IP_TYPE_SUPPORTED, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->ip_type_supported = (uint8_t)atoi(global_entries[i].value); fprintf(stderr, "IP_TYPE_SUPPORTED : %s\n", config->ip_type_supported == IP_V4 ? "IPV4" : config->ip_type_supported == IP_V6 ? "IPV6" : config->ip_type_supported == IPV4V6_PRIORITY ? "IPV4V6_PRIORITY" : config->ip_type_supported == IPV4V6_DUAL ? "IPV4V6_DUAL" : "UNKNOWN"); if (config->ip_type_supported > IP_TYPE) { rte_panic("Error : Invalid value aasigned to IP_TYPE_SUPPORTED \n"); } } /* IP_TYPE_PRIORITY parameter for CP Config */ if(strncmp(IP_TYPE_PRIORITY, global_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->ip_type_priority = (uint8_t)atoi(global_entries[i].value); fprintf(stderr, "CP: IP_TYPE_PRIORITY : %s\n", (config->ip_type_priority) ? "IPv6 TYPE" : "IPv4 TYPE"); if (config->ip_type_priority > IP_PRIORITY) { rte_panic("Error : Invalid value aasigned to IP_TYPE_PRIORITY \n"); } } } if(!config->use_dns){ if((config->pfcp_ip_type != PDN_TYPE_IPV4_IPV6 && config->upf_pfcp_ip_type!= PDN_TYPE_IPV4_IPV6) && (config->pfcp_ip_type != config->upf_pfcp_ip_type)){ fprintf(stderr, "CP: PFCP_IP is not compatible with UPF_PFCP_IP and" " We are not using DNS\n"); rte_panic(); } } fprintf(stderr, "CP: S11_IP_TYPE : %s\n", ip_type_str(config->s11_ip_type)); fprintf(stderr, "CP: S5S8_IP_TYPE : %s\n", ip_type_str(config->s5s8_ip_type)); fprintf(stderr, "CP: PFCP_IP_TYPE : %s\n", ip_type_str(config->pfcp_ip_type)); rte_free(global_entries); /*Read Default configuration of URR*/ num_urr_entries = rte_cfgfile_section_num_entries(file, URR_DEFAULT); if (num_urr_entries > 0) { urr_entries = rte_malloc_socket(NULL, sizeof(struct rte_cfgfile_entry) *num_urr_entries, RTE_CACHE_LINE_SIZE, rte_socket_id()); } if (urr_entries != NULL){ rte_cfgfile_section_entries(file, URR_DEFAULT, urr_entries, num_urr_entries); for (i = 0; i < num_urr_entries; ++i) { fprintf(stderr, "\nCP: [%s] = %s", urr_entries[i].name, urr_entries[i].value); if (strncmp(TRIGGER_TYPE, urr_entries[i].name, ENTRY_NAME_SIZE) == 0) config->trigger_type = (int)atoi(urr_entries[i].value); if (strncmp(UPLINK_VOLTH, urr_entries[i].name, ENTRY_NAME_SIZE) == 0) config->uplink_volume_th = (int)atoi(urr_entries[i].value); if (strncmp(DOWNLINK_VOLTH, urr_entries[i].name, ENTRY_NAME_SIZE) == 0) config->downlink_volume_th = (int)atoi(urr_entries[i].value); if (strncmp(TIMETH, urr_entries[i].name, ENTRY_NAME_SIZE) == 0) config->time_th = (int)atoi(urr_entries[i].value); } } else { config->trigger_type = DEFAULT_TRIGGER_TYPE; config->uplink_volume_th = DEFAULT_VOL_THRESHOLD; config->downlink_volume_th = DEFAULT_VOL_THRESHOLD; config->time_th = DEFAULT_TIME_THRESHOLD; } /*check for valid configuration*/ if(config->trigger_type < 0 || config->trigger_type > 2) { fprintf(stderr, "\nConfigure Wrong Default trigger_type" " Using default value as: [%d]", DEFAULT_TRIGGER_TYPE); config->trigger_type = DEFAULT_TRIGGER_TYPE; } if(config->uplink_volume_th <= 0 ) { fprintf(stderr, "\nConfigure Wrong Default uplink_volume_th" " Using default value as: [%d]", DEFAULT_VOL_THRESHOLD); config->uplink_volume_th = DEFAULT_VOL_THRESHOLD; } if(config->downlink_volume_th <= 0 ) { fprintf(stderr, "\nConfigure Wrong Default downlink_volume_th" " Using default value as: [%d]", DEFAULT_VOL_THRESHOLD); config->downlink_volume_th = DEFAULT_VOL_THRESHOLD; } if(config->time_th <= 0 ) { fprintf(stderr, "\nConfigure Wrong Default time_th" " Using default value as: [%d]", DEFAULT_TIME_THRESHOLD); config->time_th = DEFAULT_TIME_THRESHOLD; } rte_free(urr_entries); /* Parse APN and nameserver values. */ uint16_t app_nameserver_ip_idx = 0; uint16_t ops_nameserver_ip_idx = 0; /* Fill the entries in APN list. */ int num_apn = 0; num_apn = rte_cfgfile_num_sections(file, APN_ENTRIES, APN_SEC_NAME_LEN); int j; int apn_num_entries = 0; int apn_idx = 0; total_apn_cnt = 0; char apn_name[APN_SEC_NAME_LEN] = {0}; strncpy(apn_name, APN_ENTRIES,APN_SEC_NAME_LEN); for(i = 1 ; i <= num_apn; i++ ) { num_apn_entries = rte_cfgfile_section_num_entries_by_index(file, apn_name, i); if (num_apn_entries > 0) { /* Allocate the memory. */ apn_entries = rte_malloc_socket(NULL, sizeof(struct rte_cfgfile_entry) * num_apn_entries, RTE_CACHE_LINE_SIZE, rte_socket_id()); if (apn_entries == NULL) rte_panic("Error configuring" "apn entry of %s\n", STATIC_CP_FILE); } apn_num_entries = rte_cfgfile_section_entries_by_index(file, i, apn_name, apn_entries, 13); if (apn_num_entries > 0 ) { for(j = 0; j < apn_num_entries; ++j ) { fprintf(stderr,"\nCP: [%s] = %s", apn_entries[j].name, apn_entries[j].value); if(strncmp(NAME, apn_entries[j].name, ENTRY_NAME_SIZE) == 0) { apn_list[apn_idx].apn_name_label = apn_entries[j].value; } else if (strncmp(USAGE_TYPE, apn_entries[j].name, ENTRY_NAME_SIZE) == 0 ) { apn_list[apn_idx].apn_usage_type = (int)atoi(apn_entries[j].value); } else if (strncmp(NETWORK_CAPABILITY, apn_entries[j].name, ENTRY_NAME_SIZE) == 0) { strncpy(apn_list[apn_idx].apn_net_cap, apn_entries[j].value, ENTRY_VALUE_SIZE); } else if (strncmp(TRIGGER_TYPE, apn_entries[j].name, ENTRY_NAME_SIZE) == 0) { apn_list[apn_idx].trigger_type = (int)atoi(apn_entries[j].value); } else if (strncmp(UPLINK_VOLTH, apn_entries[j].name, ENTRY_NAME_SIZE) == 0) { apn_list[apn_idx].uplink_volume_th = (int)atoi(apn_entries[j].value); } else if (strncmp(DOWNLINK_VOLTH, apn_entries[j].name, ENTRY_NAME_SIZE) == 0) { apn_list[apn_idx].downlink_volume_th = (int)atoi(apn_entries[j].value); } else if (strncmp(TIMETH, apn_entries[j].name, ENTRY_NAME_SIZE) == 0) { apn_list[apn_idx].time_th = (int)atoi(apn_entries[j].value); } else if (strncmp(IP_POOL_IP, apn_entries[j].name, ENTRY_NAME_SIZE) == 0) { inet_aton(apn_entries[j].value, &(apn_list[apn_idx].ip_pool_ip)); } else if (strncmp(IP_POOL_MASK, apn_entries[j].name, ENTRY_NAME_SIZE) == 0) { inet_aton(apn_entries[j].value, &(apn_list[apn_idx].ip_pool_mask)); } else if (strncmp(IPV6_NETWORK_ID, apn_entries[j].name, ENTRY_NAME_SIZE) == 0) { inet_pton(AF_INET6, apn_entries[j].value, &(apn_list[apn_idx].ipv6_network_id)); } else if(strncmp(IPV6_PREFIX_LEN, apn_entries[j].name, ENTRY_NAME_SIZE) == 0) { apn_list[apn_idx].ipv6_prefix_len = (uint8_t)atoi(apn_entries[j].value); } } config->num_apn = num_apn; apn_list[apn_idx].apn_idx = apn_idx; /*check for valid configuration*/ if(apn_list[apn_idx].trigger_type < 0 || apn_list[apn_idx].trigger_type > 2) { fprintf(stderr, "\nConfigure Wrong trigger_type for apn [%s]" " Using trigger_type: [%d] ", apn_list[apn_idx].apn_name_label, config->trigger_type); apn_list[apn_idx].trigger_type = config->trigger_type; } if(apn_list[apn_idx].uplink_volume_th <= 0 ) { fprintf(stderr, "\nConfigure Wrong uplink_volume_th for apn [%s]" " Using uplink_volume_th: [%d] ", apn_list[apn_idx].apn_name_label, config->uplink_volume_th); apn_list[apn_idx].uplink_volume_th = config->uplink_volume_th; } if(apn_list[apn_idx].downlink_volume_th <= 0 ) { fprintf(stderr, "\nConfigure Wrong downlink_volume_th for apn [%s]" " Using downlink_volume_th: [%d] ", apn_list[apn_idx].apn_name_label, config->downlink_volume_th); apn_list[apn_idx].downlink_volume_th = config->downlink_volume_th; } if(apn_list[apn_idx].time_th <= 0 ) { fprintf(stderr, "\nConfigure Wrong time_th for apn [%s]" " Using time_th: [%d] ", apn_list[apn_idx].apn_name_label, config->time_th); apn_list[apn_idx].time_th = config->time_th; } set_apn_name(&apn_list[apn_idx], apn_list[apn_idx].apn_name_label); apn_idx++; total_apn_cnt++; } rte_free(apn_entries); apn_entries = NULL; } /* Read cache values from cfg seaction. */ num_cache_entries = rte_cfgfile_section_num_entries(file, CACHE_ENTRIES); if (num_cache_entries > 0) { cache_entries = rte_malloc_socket(NULL, sizeof(struct rte_cfgfile_entry) *num_cache_entries, RTE_CACHE_LINE_SIZE, rte_socket_id()); } if (cache_entries == NULL) rte_panic("Error configuring" "CACHE entry of %s\n", STATIC_CP_FILE); rte_cfgfile_section_entries(file, CACHE_ENTRIES, cache_entries, num_cache_entries); for (i = 0; i < num_cache_entries; ++i) { fprintf(stderr, "CP: [%s] = %s\n", cache_entries[i].name, cache_entries[i].value); if (strncmp(CONCURRENT, cache_entries[i].name, ENTRY_NAME_SIZE) == 0) config->dns_cache.concurrent = (uint32_t)atoi(cache_entries[i].value); if (strncmp(PERCENTAGE, cache_entries[i].name, ENTRY_NAME_SIZE) == 0) config->dns_cache.percent = (uint32_t)atoi(cache_entries[i].value); if (strncmp(INT_SEC, cache_entries[i].name, ENTRY_NAME_SIZE) == 0) config->dns_cache.sec = (((uint32_t)atoi(cache_entries[i].value)) * 1000); if (strncmp(QUERY_TIMEOUT, cache_entries[i].name, ENTRY_NAME_SIZE) == 0) config->dns_cache.timeoutms = (long)atol(cache_entries[i].value); if (strncmp(QUERY_TRIES, cache_entries[i].name, ENTRY_NAME_SIZE) == 0) config->dns_cache.tries = (uint32_t)atoi(cache_entries[i].value); } rte_free(cache_entries); /* Read app values from cfg seaction. */ num_app_entries = rte_cfgfile_section_num_entries(file, APP_ENTRIES); if (num_app_entries > 0) { app_entries = rte_malloc_socket(NULL, sizeof(struct rte_cfgfile_entry) *num_app_entries, RTE_CACHE_LINE_SIZE, rte_socket_id()); if (app_entries == NULL) rte_panic("Error configuring" "APP entry of %s\n", STATIC_CP_FILE); } if (app_entries != NULL) { rte_cfgfile_section_entries(file, APP_ENTRIES, app_entries, num_app_entries); for (i = 0; i < num_app_entries; ++i) { fprintf(stderr, "CP: [%s] = %s\n", app_entries[i].name, app_entries[i].value); if (strncmp(FREQ_SEC, app_entries[i].name, ENTRY_NAME_SIZE) == 0) config->app_dns.freq_sec = (uint8_t)atoi(app_entries[i].value); if (strncmp(FILENAME, app_entries[i].name, ENTRY_NAME_SIZE) == 0) strncpy(config->app_dns.filename, app_entries[i].value, sizeof(config->app_dns.filename)); if (strncmp(NAMESERVER, app_entries[i].name, ENTRY_NAME_SIZE) == 0) { strncpy(config->app_dns.nameserver_ip[app_nameserver_ip_idx], app_entries[i].value, sizeof(config->app_dns.nameserver_ip[app_nameserver_ip_idx])); int8_t ip_type = get_ip_address_type(app_entries[i].value); /* comparing the ip type of nameserver with source address ip type of CP */ if (!(ip_type & config->cp_dns_ip_type)) { fprintf(stderr, "CP: CP_DNS_IP and app nameserver IP type should be equal "); rte_panic(); } app_nameserver_ip_idx++; } } config->app_dns.nameserver_cnt = app_nameserver_ip_idx; rte_free(app_entries); } /* Read ops values from cfg seaction. */ num_ops_entries = rte_cfgfile_section_num_entries(file, OPS_ENTRIES); if (num_ops_entries > 0) { ops_entries = rte_malloc_socket(NULL, sizeof(struct rte_cfgfile_entry) *num_ops_entries, RTE_CACHE_LINE_SIZE, rte_socket_id()); if (ops_entries == NULL) rte_panic("Error configuring" "OPS entry of %s\n", STATIC_CP_FILE); } if (ops_entries != NULL) { rte_cfgfile_section_entries(file, OPS_ENTRIES, ops_entries, num_ops_entries); for (i = 0; i < num_ops_entries; ++i) { fprintf(stderr, "CP: [%s] = %s\n", ops_entries[i].name, ops_entries[i].value); if (strncmp(FREQ_SEC, ops_entries[i].name, ENTRY_NAME_SIZE) == 0) config->ops_dns.freq_sec = (uint8_t)atoi(ops_entries[i].value); if (strncmp(FILENAME, ops_entries[i].name, ENTRY_NAME_SIZE) == 0) strncpy(config->ops_dns.filename, ops_entries[i].value, strnlen(ops_entries[i].value,CFG_VALUE_LEN)); if (strncmp(NAMESERVER, ops_entries[i].name, ENTRY_NAME_SIZE) == 0) { strncpy(config->ops_dns.nameserver_ip[ops_nameserver_ip_idx], ops_entries[i].value, strnlen(ops_entries[i].value,CFG_VALUE_LEN)); int8_t ip_type = get_ip_address_type(ops_entries[i].value); /* comparing the ip type of nameserver with source address ip type of CP */ if (!(ip_type & config->cp_dns_ip_type)) { fprintf(stderr, "CP: CP_DNS_IP and ops nameserver IP type should be equal "); rte_panic(); } ops_nameserver_ip_idx++; } } config->ops_dns.nameserver_cnt = ops_nameserver_ip_idx; rte_free(ops_entries); } /* Read IP_POOL_CONFIG seaction */ num_ip_pool_entries = rte_cfgfile_section_num_entries (file, IP_POOL_ENTRIES); if (num_ip_pool_entries > 0) { ip_pool_entries = rte_malloc_socket(NULL, sizeof(struct rte_cfgfile_entry) * num_ip_pool_entries, RTE_CACHE_LINE_SIZE, rte_socket_id()); if (ip_pool_entries == NULL) rte_panic("Error configuring ip" "pool entry of %s\n", STATIC_CP_FILE); } rte_cfgfile_section_entries(file, IP_POOL_ENTRIES, ip_pool_entries, num_ip_pool_entries); for (i = 0; i < num_ip_pool_entries; ++i) { fprintf(stderr, "CP: [%s] = %s\n", ip_pool_entries[i].name, ip_pool_entries[i].value); if (strncmp(IP_POOL_IP, ip_pool_entries[i].name, ENTRY_NAME_SIZE) == 0) { inet_aton(ip_pool_entries[i].value, &(config->ip_pool_ip)); } else if (strncmp (IP_POOL_MASK, ip_pool_entries[i].name, ENTRY_NAME_SIZE) == 0) { inet_aton(ip_pool_entries[i].value, &(config->ip_pool_mask)); } else if (strncmp(IPV6_NETWORK_ID, ip_pool_entries[i].name, ENTRY_NAME_SIZE) == 0) { inet_pton(AF_INET6, ip_pool_entries[i].value, &(config->ipv6_network_id)); } else if(strncmp(IPV6_PREFIX_LEN, ip_pool_entries[i].name, ENTRY_NAME_SIZE) == 0) { config->ipv6_prefix_len = (uint8_t)atoi(ip_pool_entries[i].value); } } rte_free(ip_pool_entries); if (file != NULL) { rte_cfgfile_close(file); file = NULL; } return; } int check_cp_req_timeout_config(char *value) { unsigned int idx = 0; if(value == NULL ) return -1; /* check string has all digit 0 to 9 */ for(idx = 0; idx < strnlen(value,CFG_VALUE_LEN); idx++) { if(isdigit(value[idx]) == 0) { return -1; } } /* check cp request timer timeout range */ if((int)atoi(value) >= 1 && (int)atoi(value) <= 1800000 ) { return 0; } return -1; } int check_cp_req_tries_config(char *value) { unsigned int idx = 0; if(value == NULL ) return -1; /* check string has all digit 0 to 9 */ for(idx = 0; idx < strnlen(value,CFG_VALUE_LEN); idx++) { if(isdigit(value[idx]) == 0) { return -1; } } /* check cp request timer tries range */ if((int)atoi(value) >= 1 && (int)atoi(value) <= 20) { return 0; } return -1; } int get_apn_name(char *apn_name_label, char *apn_name) { if(apn_name_label == NULL) return -1; uint8_t length = strnlen(apn_name_label, MAX_NB_DPN); for (uint8_t i=0; i<length; i++) { uint8_t len = apn_name_label[i]; if (i!=0) apn_name[i - 1] = '.'; for (uint8_t j=i; j<(i +len); j++) { apn_name[j] = apn_name_label[j+1]; } i = i + len; } return 0; } int get_ip_address_type(const char *ip_addr) { struct addrinfo *ip_type = NULL; /*Check for IP type (ipv4/ipv6)*/ if ( getaddrinfo(ip_addr, NULL, NULL, &ip_type )) { return -1; } if(ip_type->ai_family == AF_INET6) { freeaddrinfo(ip_type); return PDN_TYPE_IPV6; } else { freeaddrinfo(ip_type); return PDN_TYPE_IPV4; } } int fill_pcrf_ip(const char *filename, char *peer_addr) { FILE *gx_fd = NULL; char data[LINE_SIZE] = {0}; char *token = NULL; char *token1 = NULL; uint8_t str_len = 0; char *data_ptr = NULL; gx_fd = fopen(filename, "r"); if (NULL == gx_fd) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"unable to read [%s] file\n", LOG_VALUE, filename); return -1; } while ((fgets(data, LINE_SIZE, gx_fd)) != NULL) { if (data[0] == '#') { continue; } data_ptr = strstr(data, CONNECT_TO); if (data_ptr != NULL) { token = strchr(data_ptr, '"'); if (token != NULL) { token1 = strchr(token + 1, '"'); if (token != NULL) { str_len = token1 - token; strncpy(peer_addr, token + 1, str_len - 1); peer_addr[str_len] = '\0'; } } fclose(gx_fd); return 0; } } fclose(gx_fd); return -1; } int8_t fill_gx_iface_ip(void) { char peer_addr[IPV6_STR_LEN] = {0}; if(fill_pcrf_ip(GX_FILE_PATH, peer_addr)) { return -1; } int8_t ip_type = get_ip_address_type(peer_addr); if (PDN_TYPE_IPV4 == ip_type) { inet_pton(AF_INET, peer_addr, &config.gx_ip.ipv4.sin_addr); config.gx_ip.type = PDN_TYPE_IPV4; } else if (PDN_TYPE_IPV6 == ip_type) { inet_pton(AF_INET6, peer_addr, &config.gx_ip.ipv6.sin6_addr); config.gx_ip.type = PDN_TYPE_IPV6; } else { return -1; } return 0; }
nikhilc149/e-utran-features-bug-fixes
ulpc/admf/include/UeNotification.h
/* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __UE_NOTIFICATION_H_ #define __UE_NOTIFICATION_H_ #include "emgmt.h" class AdmfApplication; class UeNotificationPost : public EManagementHandler { public: AdmfApplication &mApp; UeNotificationPost(ELogger &audit, AdmfApplication &app); /** * @brief : Processes the notifications (start/stop) request on ADMF * @param : request, reference to request object * @param : response, reference to response object * @return : Returns nothing */ virtual Void process(const Pistache::Http::Request& request, Pistache::Http::ResponseWriter &response); virtual ~UeNotificationPost() {} private: UeNotificationPost(); }; #endif /* __UE_NOTIFICATION_H_ */
nikhilc149/e-utran-features-bug-fixes
ulpc/d_admf/include/UeConfig.h
<filename>ulpc/d_admf/include/UeConfig.h /* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __UE_CONFIG_H_ #define __UE_CONFIG_H_ #include <map> #include "Common.h" #include "UeTimer.h" #define UE_TMP_FILE "database/uedb_tmp.csv" #define SEQ_ID_ATTR 0 #define IMSI_ATTR 1 #define S11_ATTR 2 #define SGW_S5S8_C_ATTR 3 #define PGW_S5S8_C_ATTR 4 #define SX_ATTR 5 #define S1U_CONTENT_ATTR 6 #define SGW_S5S8U_CONTENT_ATTR 7 #define PGW_S5S8U_CONTENT_ATTR 8 #define SGI_CONTENT_ATTR 9 #define INTFC_CONFIG_ATTR 10 #define FORWARD_ATTR 11 #define START_TIME_ATTR 12 #define STOP_TIME_ATTR 13 #define ACK_RCVD_ATTR 14 #define SIGNALLING_CONFIG_ATTR 15 #define DATA_CONFIG_ATTR 16 #define TIMER_ATTR 17 #define KEY 0 #define VALUE 1 class UeConfig { protected: std::map<uint64_t, ue_data_t> mapUeConfig; std::map<uint64_t, EUeTimer*> mapStartUeTimers; std::map<uint64_t, EUeTimer*> mapStopUeTimers; public: UeConfig() {} virtual int8_t ReadUeConfig(void) = 0; /** * @brief : Virtual method. Extended class needs to implement this method * @param : uiAction, action can be add(1)/update(2)/delete(3) * @param : mod_ue_data, structure representing the Ue entry * @return : Returns 0 in case of Success, -1 otherwise */ virtual int8_t UpdateUeConfig(uint8_t uiAction, ue_data_t &modUeData) = 0; std::map<uint64_t, ue_data_t> &getMapUeConfig() { return mapUeConfig; } void setMapUeConfig(const std::map<uint64_t, ue_data_t> ueMap) { mapUeConfig = ueMap; } std::map<uint64_t, EUeTimer*> &getMapStartUeTimers() { return mapStartUeTimers; } void setMapStartUeTimers(const std::map<uint64_t, EUeTimer*> startTimerMap) { mapStartUeTimers = startTimerMap; } std::map<uint64_t, EUeTimer*> &getMapStopUeTimers() { return mapStopUeTimers; } void setMapStopUeTimers(const std::map<uint64_t, EUeTimer*> stopTimerMap) { mapStopUeTimers = stopTimerMap; } virtual ~UeConfig() {}; }; #endif /* __UE_CONFIG_H_ */
nikhilc149/e-utran-features-bug-fixes
cp_dp_api/tcp_client.h
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _TCP_CLIENT_H_ #define _TCP_CLIENT_H_ #define IPV4_ADDR_MAX_LEN 16 /** * @file * This file contains macros, data structure definitions and function * prototypes for TCP based connections for LI. */ #ifdef DP_BUILD #include "up_main.h" #else #include "cp.h" #endif #include <netinet/tcp.h> #include <sys/ioctl.h> #include <net/if.h> /* * Define type of Action need to take * TCP_GET, Get tcp sockfd already created * TCP_CREATE, Create a new sockfd */ enum TCP_SOCKET { TCP_GET = 0, TCP_CREATE = 1 }; /** * @brief : Add the sock fd to the sock arr which is not present in that arry * @param : sock_arr, Array sockfd on which we need to add new fd * @param : arr_size, the no of fd in sock_arr * @param : fd, new fd to be added * @return : Nothing */ void insert_fd(int *sock_arr, uint32_t *arr_size, int fd); #endif /*_TCP_CLIENT_H_*/
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c.c
<filename>cp/gtpv2c.c /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ue.h" #include "gtpv2c.h" #include "interface.h" #include "gtpv2c_ie.h" #include "gtpv2c_set_ie.h" in_port_t s11_port; in_port_t s5s8_port; struct sockaddr_in s11_sockaddr; struct sockaddr_in s5s8_sockaddr; uint8_t s11_rx_buf[MAX_GTPV2C_UDP_LEN]; uint8_t s11_tx_buf[MAX_GTPV2C_UDP_LEN]; uint8_t pfcp_tx_buf[MAX_GTPV2C_UDP_LEN]; #ifdef USE_REST /* ECHO PKTS HANDLING */ uint8_t echo_tx_buf[MAX_GTPV2C_UDP_LEN]; #endif /* USE_REST */ uint8_t s5s8_rx_buf[MAX_GTPV2C_UDP_LEN]; uint8_t s5s8_tx_buf[MAX_GTPV2C_UDP_LEN]; gtpv2c_ie * get_first_ie(gtpv2c_header_t *gtpv2c_h) { if (gtpv2c_h) { gtpv2c_ie *first_ie = IE_BEGIN(gtpv2c_h); if (NEXT_IE(first_ie) <= GTPV2C_IE_LIMIT(gtpv2c_h)) return first_ie; } return NULL; } gtpv2c_ie * get_next_ie(gtpv2c_ie *gtpv2c_ie_ptr, gtpv2c_ie *limit) { if (gtpv2c_ie_ptr) { gtpv2c_ie *first_ie = NEXT_IE(gtpv2c_ie_ptr); if (NEXT_IE(first_ie) <= limit) return first_ie; } return NULL; } void set_gtpv2c_header(gtpv2c_header_t *gtpv2c_tx, uint8_t teid_flag, uint8_t type, uint32_t has_teid, uint32_t seq, uint8_t is_piggybacked) { gtpv2c_tx->gtpc.version = GTP_VERSION_GTPV2C; gtpv2c_tx->gtpc.piggyback = is_piggybacked; gtpv2c_tx->gtpc.message_type = type; gtpv2c_tx->gtpc.spare = 0; gtpv2c_tx->gtpc.teid_flag = teid_flag; if (teid_flag) { gtpv2c_tx->teid.has_teid.teid = has_teid; gtpv2c_tx->teid.has_teid.seq = seq; } else { gtpv2c_tx->teid.no_teid.seq = seq; } gtpv2c_tx->gtpc.message_len = teid_flag ? htons(sizeof(gtpv2c_tx->teid.has_teid)) : htons(sizeof(gtpv2c_tx->teid.no_teid)); } void set_gtpv2c_teid_header(gtpv2c_header_t *gtpv2c_tx, uint8_t type, uint32_t teid, uint32_t seq, uint8_t is_piggybacked) { /* Default set teid_flag = 1 */ set_gtpv2c_header(gtpv2c_tx, 1, type, teid, seq, is_piggybacked); } void set_gtpv2c_echo(gtpv2c_header_t *gtpv2c_tx, uint8_t teid_flag, uint8_t type, uint32_t teid, uint32_t seq) { set_gtpv2c_header(gtpv2c_tx, teid_flag, type, teid, seq, 0); set_recovery_ie(gtpv2c_tx, IE_INSTANCE_ZERO); }
nikhilc149/e-utran-features-bug-fixes
cp/gtpv2c.h
<reponame>nikhilc149/e-utran-features-bug-fixes<filename>cp/gtpv2c.h /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef GTPV2C_H #define GTPV2C_H /** * @file * * GTPv2C definitions and helper macros. * * GTP Message type definition and GTP header definition according to 3GPP * TS 29.274; as well as IE parsing helper functions/macros, and message * processing function declarations. * */ #include "cp.h" #include "ue.h" #include "gtpv2c_ie.h" #include "gw_adapter.h" #include <stddef.h> #include <arpa/inet.h> #include "../libgtpv2c/include/gtp_messages.h" #define GTPC_UDP_PORT (2123) #define MAX_GTPV2C_UDP_LEN (4096) /* PGW Restart Notification */ #define PRN 1 #define GTP_VERSION_GTPV2C (2) /* GTP Message Type Values */ #define GTP_ECHO_REQ (1) #define GTP_ECHO_RSP (2) #define GTP_VERSION_NOT_SUPPORTED_IND (3) #define GTP_CREATE_SESSION_REQ (32) #define GTP_CREATE_SESSION_RSP (33) #define GTP_MODIFY_BEARER_REQ (34) #define GTP_MODIFY_BEARER_RSP (35) #define GTP_DELETE_SESSION_REQ (36) #define GTP_DELETE_SESSION_RSP (37) #define GTP_CHANGE_NOTIFICATION_REQ (38) #define GTP_CHANGE_NOTIFICATION_RSP (39) #define GTP_MODIFY_BEARER_CMD (64) #define GTP_MODIFY_BEARER_FAILURE_IND (65) #define GTP_DELETE_BEARER_CMD (66) #define GTP_DELETE_BEARER_FAILURE_IND (67) #define GTP_BEARER_RESOURCE_CMD (68) #define GTP_BEARER_RESOURCE_FAILURE_IND (69) #define GTP_DOWNLINK_DATA_NOTIFICATION_FAILURE_IND (70) #define GTP_TRACE_SESSION_ACTIVATION (71) #define GTP_TRACE_SESSION_DEACTIVATION (72) #define GTP_STOP_PAGING_IND (73) #define GTP_CREATE_BEARER_REQ (95) #define GTP_CREATE_BEARER_RSP (96) #define GTP_UPDATE_BEARER_REQ (97) #define GTP_UPDATE_BEARER_RSP (98) #define GTP_DELETE_BEARER_REQ (99) #define GTP_DELETE_BEARER_RSP (100) #define GTP_DELETE_PDN_CONNECTION_SET_REQ (101) #define GTP_DELETE_PDN_CONNECTION_SET_RSP (102) #define GTP_IDENTIFICATION_REQ (128) #define GTP_IDENTIFICATION_RSP (129) #define GTP_CONTEXT_REQ (130) #define GTP_CONTEXT_RSP (131) #define GTP_CONTEXT_ACK (132) #define GTP_FORWARD_RELOCATION_REQ (133) #define GTP_FORWARD_RELOCATION_RSP (134) #define GTP_FORWARD_RELOCATION_COMPLETE_NTF (135) #define GTP_FORWARD_RELOCATION_COMPLETE_ACK (136) #define GTP_FORWARD_ACCESS_CONTEXT_NTF (137) #define GTP_FORWARD_ACCESS_CONTEXT_ACK (138) #define GTP_RELOCATION_CANCEL_REQ (139) #define GTP_RELOCATION_CANCEL_RSP (140) #define GTP_CONFIGURE_TRANSFER_TUNNEL (141) #define GTP_DETACH_NTF (149) #define GTP_DETACH_ACK (150) #define GTP_CS_PAGING_INDICATION (151) #define GTP_RAN_INFORMATION_RELAY (152) #define GTP_ALERT_MME_NTF (153) #define GTP_ALERT_MME_ACK (154) #define GTP_UE_ACTIVITY_NTF (155) #define GTP_UE_ACTIVITY_ACK (156) #define GTP_CREATE_FORWARDING_TUNNEL_REQ (160) #define GTP_CREATE_FORWARDING_TUNNEL_RSP (161) #define GTP_SUSPEND_NTF (162) #define GTP_SUSPEND_ACK (163) #define GTP_RESUME_NTF (164) #define GTP_RESUME_ACK (165) #define GTP_CREATE_INDIRECT_DATA_FORWARDING_TUNNEL_REQ (166) #define GTP_CREATE_INDIRECT_DATA_FORWARDING_TUNNEL_RSP (167) #define GTP_DELETE_INDIRECT_DATA_FORWARDING_TUNNEL_REQ (168) #define GTP_DELETE_INDIRECT_DATA_FORWARDING_TUNNEL_RSP (169) #define GTP_RELEASE_ACCESS_BEARERS_REQ (170) #define GTP_RELEASE_ACCESS_BEARERS_RSP (171) #define GTP_DOWNLINK_DATA_NOTIFICATION (176) #define GTP_DOWNLINK_DATA_NOTIFICATION_ACK (177) #define GTP_RESERVED (178) #define GTP_PGW_RESTART_NOTIFICATION (179) #define GTP_PGW_RESTART_NOTIFICATION_ACK (180) #define GTP_UPDATE_PDN_CONNECTION_SET_REQ (200) #define GTP_UPDATE_PDN_CONNECTION_SET_RSP (201) #define GTP_MODIFY_ACCESS_BEARER_REQ (211) #define GTP_MODIFY_ACCESS_BEARER_RSP (212) #define GTP_MBMS_SESSION_START_REQ (231) #define GTP_MBMS_SESSION_START_RSP (232) #define GTP_MBMS_SESSION_UPDATE_REQ (233) #define GTP_MBMS_SESSION_UPDATE_RSP (234) #define GTP_MBMS_SESSION_STOP_REQ (235) #define GTP_MBMS_SESSION_STOP_RSP (236) #define GTP_MSG_END (255) /** * @brief : GTPv2c Interface coded values for use in F-TEID IE, as defined in 3GPP * TS 29.274, clause 8.22. These values are a subset of those defined in the TS, * and represent only those used by the Control Plane (in addition to a couple * that are not currently used). */ enum gtpv2c_interfaces { GTPV2C_IFTYPE_S1U_ENODEB_GTPU = 0, GTPV2C_IFTYPE_S1U_SGW_GTPU = 1, GTPV2C_IFTYPE_S12_RNC_GTPU = 2, GTPV2C_IFTYPE_S12_SGW_GTPU = 3, GTPV2C_IFTYPE_S5S8_SGW_GTPU = 4, GTPV2C_IFTYPE_S5S8_PGW_GTPU = 5, GTPV2C_IFTYPE_S5S8_SGW_GTPC = 6, GTPV2C_IFTYPE_S5S8_PGW_GTPC = 7, GTPV2C_IFTYPE_S5S8_SGW_PIMPv6 = 8, GTPV2C_IFTYPE_S5S8_PGW_PIMPv6 = 9, GTPV2C_IFTYPE_S11_MME_GTPC = 10, GTPV2C_IFTYPE_S11S4_SGW_GTPC = 11, GTPV2C_IFTYPE_SGW_GTPU_DL_DATA_FRWD = 23, GTPV2C_IFTYPE_SGW_GTPU_UL_DATA_FRWD = 28, GTPV2C_IFTYPE_S11_MME_GTPU = 38, GTPV2C_IFTYPE_S11U_SGW_GTPU = 39 }; #pragma pack(1) /** * TODO: REMOVE_DUPLICATE_USE_LIBGTPV2C * Remove following structure and use structure defined in * libgtpv2c header file. * Following structure has dependency on functionality * which can not to be tested now. */ /** * @brief : Maintains information related to gtpv2c header */ typedef struct gtpv2c_header { struct gtpc_t { uint8_t spare :3; uint8_t teidFlg :1; uint8_t piggyback :1; uint8_t version :3; uint8_t type; uint16_t length; } gtpc; union teid_u_t { struct has_teid { uint32_t teid; uint32_t seq :24; uint32_t spare :8; } has_teid; struct no_teid { uint32_t seq :24; uint32_t spare :8; } no_teid; } teid_u; } gtpv2c_header; #pragma pack() /* These IE functions/macros are 'safe' in that the ie's returned, if any, fall * within the memory range limit specified by either the gtpv2c header or * grouped ie length values */ /** * @brief : Macro to provide address of first Information Element within message buffer * containing GTP header. Address may be invalid and must be validated to ensure * it does not exceed message buffer. * @param : gtpv2c_h * Pointer of address of message buffer containing GTP header. * @return : Pointer of address of first Information Element. */ #define IE_BEGIN(gtpv2c_h) \ ((gtpv2c_h)->gtpc.teid_flag \ ? (gtpv2c_ie *)((&(gtpv2c_h)->teid.has_teid)+1) \ : (gtpv2c_ie *)((&(gtpv2c_h)->teid.no_teid)+1)) /** * @brief : Macro to provide address of next Information Element within message buffer * given previous information element. Address may be invalid and must be * validated to ensure it does not exceed message buffer. * @param : gtpv2c_ie_ptr * Pointer of address of information element preceding desired IE.. * @return : Pointer of address of following Information Element. */ #define NEXT_IE(gtpv2c_ie_ptr) \ (gtpv2c_ie *)((uint8_t *)(gtpv2c_ie_ptr + 1) \ + ntohs(gtpv2c_ie_ptr->length)) /** * @brief : Helper macro to calculate the address of some offset from some base address * @param : base, base or starting address * @param : offset, offset to be added to base for return value * @return : Cacluated address of Offset from some Base address */ #define IE_LIMIT(base, offset) \ (gtpv2c_ie *)((uint8_t *)(base) + offset) /** * @brief : Helper macro to calculate the limit of a Gropued Information Element * @param : gtpv2c_ie_ptr * Pointer to address of a Grouped Information Element * @return : The limit (or exclusive end) of a grouped information element by its length field */ #define GROUPED_IE_LIMIT(gtpv2c_ie_ptr)\ IE_LIMIT(gtpv2c_ie_ptr + 1, ntohs(gtpv2c_ie_ptr->length)) /** * @brief : Helper macro to calculate the limit of a GTP message buffer given the GTP * header (which contains its length) * @param : gtpv2c_h * Pointer to address message buffer containing a GTP Header * @return : The limit (or exclusive end) of a GTP message (and thus its IEs) given the * message buffer containing a GTP header and its length field. */ #define GTPV2C_IE_LIMIT(gtpv2c_h)\ IE_LIMIT(&gtpv2c_h->teid, ntohs(gtpv2c_h->gtpc.message_len)) /** * @brief : Helper function to get the location, according to the buffer and gtp header * located at '*gtpv2c_h', of the first information element according to * 3gppp 29.274 clause 5.6, & figure 5.6-1 * @param : gtpv2c_h * header and buffer containing gtpv2c message * @return : - NULL \- No such information element exists due to address exceeding limit * - pointer to address of first information element, if exists. */ gtpv2c_ie * get_first_ie(gtpv2c_header_t * gtpv2c_h); /** * @brief : Helper macro to loop through GTPv2C Information Elements (IE) * @param : gtpv2c_h * Pointer to address message buffer containing a GTP Header * @param : gtpv2c_ie_ptr * Pointer to starting IE to loop from * @param : gtpv2c_limit_ie_ptr * Pointer to ending IE of the loop * @return : nothing * */ #define FOR_EACH_GTPV2C_IE(gtpv2c_h, gtpv2c_ie_ptr, gtpv2c_limit_ie_ptr) \ for (gtpv2c_ie_ptr = get_first_ie(gtpv2c_h), \ gtpv2c_limit_ie_ptr = GTPV2C_IE_LIMIT(gtpv2c_h); \ gtpv2c_ie_ptr; \ gtpv2c_ie_ptr = get_next_ie(gtpv2c_ie_ptr, gtpv2c_limit_ie_ptr)) /** * @brief : Calculates address of Information Element which follows gtpv2c_ie_ptr * according to its length field while considering the limit, which may be * calculated according to the buffer allocated for the GTP message or length of * a Information Element Group * * @param : gtpv2c_ie_ptr * Known information element preceding desired information element. * @param : limit * Memory limit for next information element, if one exists * @return : - NULL \- No such information element exists due to address exceeding limit * - pointer to address of next available information element */ gtpv2c_ie * get_next_ie(gtpv2c_ie *gtpv2c_ie_ptr, gtpv2c_ie *limit); /** * @brief : Helper macro to loop through GTPv2C Grouped Information Elements (IE) * @param : parent_ie_ptr * Pointer to address message buffer containing a parent GTPv2C IE * @param : child_ie_ptr * Pointer to starting child IE to loop from * @param : gtpv2c_limit_ie_ptr * Pointer to ending IE of the loop * @return : Nothing * */ #define FOR_EACH_GROUPED_IE(parent_ie_ptr, child_ie_ptr, gtpv2c_limit_ie_ptr) \ for (gtpv2c_limit_ie_ptr = GROUPED_IE_LIMIT(parent_ie_ptr), \ child_ie_ptr = parent_ie_ptr + 1; \ child_ie_ptr; \ child_ie_ptr = get_next_ie(child_ie_ptr, gtpv2c_limit_ie_ptr)) extern peer_addr_t s11_mme_sockaddr; extern struct in_addr s11_sgw_ip; extern in_port_t s11_port; extern struct sockaddr_in s11_sgw_sockaddr; extern uint8_t s11_rx_buf[MAX_GTPV2C_UDP_LEN]; extern uint8_t s11_tx_buf[MAX_GTPV2C_UDP_LEN]; extern uint8_t tx_buf[MAX_GTPV2C_UDP_LEN]; #ifdef USE_REST //VS: ECHO BUFFERS extern uint8_t echo_tx_buf[MAX_GTPV2C_UDP_LEN]; #endif /* USE_REST */ extern struct in_addr s5s8_sgwc_ip; extern in_port_t s5s8_sgwc_port; extern struct sockaddr_in s5s8_sgwc_sockaddr; extern struct in_addr s5s8_pgwc_ip; extern in_port_t s5s8_pgwc_port; extern struct sockaddr_in s5s8_pgwc_sockaddr; extern uint8_t pfcp_tx_buf[MAX_GTPV2C_UDP_LEN]; extern uint8_t s5s8_rx_buf[MAX_GTPV2C_UDP_LEN]; extern uint8_t s5s8_tx_buf[MAX_GTPV2C_UDP_LEN]; extern struct in_addr s1u_sgw_ip; extern struct in_addr s5s8_sgwu_ip; extern struct in_addr s5s8_pgwu_ip; #ifdef CP_BUILD /* SGWC S5S8 handlers: * static int parse_sgwc_s5s8_create_session_response(...) * int gen_sgwc_s5s8_create_session_request(...) * int process_sgwc_s5s8_create_session_response(...) * */ /** * @brief : Handles processing of sgwc s5s8 create session response messages * @param : gtpv2c_rx * gtpc2c message reception buffer containing the response message * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_sgwc_s5s8_create_session_response(gtpv2c_header_t *gtpv2c_rx); /** * @brief : Handles processing of create bearer request messages * @param : cb_req * message reception buffer containing the request message * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_create_bearer_request(create_bearer_req_t *cb_req); /** * @brief : Handles processing of sgwc s11 create bearer response messages * @param : gtpv2c_rx * gtpc2c message reception buffer containing the response message * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_sgwc_s11_create_bearer_response(gtpv2c_header_t *gtpv2c_rx); /** * @brief : Handles processing of delete bearer request messages * @param : db_req, message reception buffer containing the request message * @param : context, structure for context information * @param : proc_type, procedure name * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_delete_bearer_request(del_bearer_req_t *db_req, ue_context *context, uint8_t proc_type); /** * @brief : Handles processing of delete bearer response messages * @param : db_rsp, message reception buffer containing the response message * @param : context, structure for context information * @param : proc_type, type of procedure * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_delete_bearer_resp(del_bearer_rsp_t *db_rsp, ue_context *context, uint8_t proc_type); /** * @brief : Writes packet at @tx_buf of length @payload_length to pcap file specified * in @pcap_dumper (global) * @param : payload_length, total length * @param : tx_buf, buffer containg packets * @return : Returns nothing */ void dump_pcap(uint16_t payload_length, uint8_t *tx_buf); #endif /* CP_BUILD */ /** * @brief : Helper function to set the gtp header for a gtp echo message. * @param : gtpv2c_tx, buffer used to contain gtp message for transmission * @param : teifFlg, Indicates if tied is available or not * @param : type, gtp type according to 2gpp 29.274 table 6.1-1 * @param : has_teid, teid information * @param : seq, sequence number as described by clause 7.6 3gpp 29.274 * @return : Returns nothing */ void set_gtpv2c_echo(gtpv2c_header_t *gtpv2c_tx, uint8_t teidFlg, uint8_t type, uint32_t has_teid, uint32_t seq); /* gtpv2c message handlers as defined in gtpv2c_messages folder */ /** * @brief : Handles the processing of bearer resource commands received by the * control plane. * @param : gtpv2c_rx * gtpv2c message buffer containing bearer resource command message * @param : gtpv2c_tx * gtpv2c message transmission buffer to contain any triggered message * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_bearer_resource_command(gtpv2c_header_t *gtpv2c_rx, gtpv2c_header_t *gtpv2c_tx); /** * @brief : Handles the processing of create session request messages received by the * control plane * @param : gtpv2c_rx * gtpv2c message buffer containing the create session request message * @param : gtpv2c_s11_tx * gtpc2c message transmission buffer to contain s11 response message * @param : gtpv2c_s5s8_tx * gtpc2c message transmission buffer to contain s5s8 response message * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_create_session_request(gtpv2c_header_t *gtpv2c_rx, gtpv2c_header_t *gtpv2c_s11_tx, gtpv2c_header_t *gtpv2c_s5s8_tx); /** * @brief : from parameters, populates gtpv2c message 'create session response' and * populates required information elements as defined by * clause 7.2.2 3gpp 29.274 * @param : gtpv2c_tx * transmission buffer to contain 'create session response' message * @param : sequence * sequence number as described by clause 7.6 3gpp 29.274 * @param : context * UE Context data structure pertaining to the session to be created * @param : pdn * PDN Connection data structure pertaining to the session to be created * @param : bearer * Default EPS Bearer corresponding to the PDN Connection to be created * @param : is_piggybacked * describes whether message is piggybacked. * @return : message length */ uint16_t set_create_session_response(gtpv2c_header_t *gtpv2c_tx, uint32_t sequence, ue_context *context, pdn_connection *pdn, uint8_t is_piggybacked); /** * @brief : Handles the processing of pgwc create session request messages * * @param : gtpv2c_rx * gtpv2c message buffer containing the create session request message * @param : upf_ipv4, upf id address * @param : proc, procedure type * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_pgwc_s5s8_create_session_request(gtpv2c_header_t *gtpv2c_rx, struct in_addr *upf_ipv4, uint8_t proc); /** * @brief : Handles the processing of delete bearer response messages received by the * control plane. * @param : gtpv2c_rx * gtpv2c message buffer containing delete bearer response * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_delete_bearer_response(gtpv2c_header_t *gtpv2c_rx); /** * @brief : Handles the generation of sgwc s5s8 delete session request messages * @param : gtpv2c_rx * gtpv2c message buffer containing delete session request message * @param : gtpv2c_tx * gtpv2c message buffer to contain delete session response message * @param : pgw_gtpc_del_teid * Default pgw_gtpc_del_teid to be deleted on PGW * @param : sequence * sequence number as described by clause 7.6 3gpp 29.274 * @param : del_ebi * Id of EPS Bearer to be deleted * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int gen_sgwc_s5s8_delete_session_request(gtpv2c_header_t *gtpv2c_rx, gtpv2c_header_t *gtpv2c_tx, uint32_t pgw_gtpc_del_teid, uint32_t sequence, uint8_t del_ebi); /** * @brief : Handles the processing and reply of gtp echo requests received by the control plane * @param : gtpv2c_rx * gtpv2c buffer received by CP containing echo request * @param : gtpv2c_tx * gtpv2c buffer to transmit from CP containing echo response * @return : will return 0 to indicate success */ int process_echo_request(gtpv2c_header_t *gtpv2c_rx, gtpv2c_header_t *gtpv2c_tx); /** * @brief : Handles the processing of modify bearer request messages received by the * control plane. * @param : gtpv2c_rx * gtpv2c message buffer containing the modify bearer request message * @param : gtpv2c_tx * gtpv2c message transmission buffer to response message * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_modify_bearer_request(gtpv2c_header_t *gtpv2c_rx, gtpv2c_header_t *gtpv2c_tx); /** * @brief : Handles the processing of release access bearer request messages received by * the control plane. * @param : rel_acc_ber_req_t * gtpv2c message buffer containing the modify bearer request message * @param : proc, procedure type * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_release_access_bearer_request(rel_acc_ber_req_t *rel_acc_ber_req, uint8_t proc); /** * @brief : Processes a Downlink Data Notification Acknowledgement message * (29.274 Section 7.2.11.2). Populates the delay value @delay * @param : decode_dnlnk_data_notif_ack * Containing the Downlink Data Notification Acknowledgement * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_ddn_ack(dnlnk_data_notif_ack_t *ddn_ack); /** * @brief : Processes a Downlink Data Notification Failure Indication message * @param : decoded dnlnk_data_notif_fail_indctn_t * @return : - 0 if successful and -1 on error */ int process_ddn_failure(dnlnk_data_notif_fail_indctn_t *ddn_fail_ind); /** * @brief : Creates a Downlink Data Notification message * @param : context * the UE context for the DDN * @param : eps_bearer_id * the eps bearer ID to be included in the DDN * @param : sequence * sequence number as described by clause 7.6 3gpp 29.274 * @param : gtpv2c_tx * gtpv2c message buffer containing the Downlink Data Notification to * transmit * @param : pfcp_pdr_id, pdr_ids pointer * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value */ int create_downlink_data_notification(ue_context *context, uint8_t eps_bearer_id, uint32_t sequence, gtpv2c_header_t *gtpv2c_tx, pdr_ids *pfcp_pdr_id); /** * @brief : parses gtpv2c message and populates parse_release_access_bearer_request_t * structure * @param : gtpv2c_rx * buffer containing received release access bearer request message * @param : release_access_bearer_request * structure to contain parsed information from message * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int parse_release_access_bearer_request(gtpv2c_header_t *gtpv2c_rx, rel_acc_ber_req_t *rel_acc_ber_req); /** * @brief : Utility to send or dump gtpv2c messages * @param : gtpv2c_if_id_v4, file discpretor for IPV4 * @param : gtpv2c_if_id_v6, file discpretor for IPV6 * @param : gtpv2c_tx_buf, gtpv2c message transmission buffer to response message * @param : gtpv2c_pyld_len, gtpv2c message length * @param : dest_addr, ip address of destination * @param : dir, message direction * @return : Returns the transmitted bytes */ int gtpv2c_send(int gtpv2c_if_id_v4, int gtpv2c_if_id_v6, uint8_t *gtpv2c_tx_buf, uint16_t gtpv2c_pyld_len, peer_addr_t dest_addr, Dir dir); /** * @brief : Util to send or dump gtpv2c messages * @param : fd_v4, IPv4 interface indentifier * @param : fd_v6, IPv6 interface indentifier * @param : t_tx, buffer to store data for peer node * @param : context, UE context for lawful interception * @return : Returns nothing */ void timer_retry_send(int fd_v4, int fd_v6, peerData *t_tx, ue_context *context); /** * @brief : Set values in node features ie * @param : node_feature, structure to be filled * @param : type, ie type * @param : length, total length * @param : instance, instance value * @return : Returns nothing */ void set_node_feature_ie(gtp_node_features_ie_t *node_feature, uint8_t type, uint16_t length, uint8_t instance, uint8_t sup_feature); /** * @brief : Function to build GTP-U echo request * @param : echo_pkt rte_mbuf pointer * @param : gtpu_seqnb, sequence number * @param : iface, interface value * @return : Returns nothing */ void build_gtpv2_echo_request(gtpv2c_header_t *echo_pkt, uint16_t gtpu_seqnb, uint8_t iface); /** * @brief : Set values in modify bearer request * @param : gtpv2c_tx, gtpv2c message transmission buffer to response message * @param : pdn, PDN Connection data structure pertaining to the session to be created * @param : bearer, Default EPS Bearer corresponding to the PDN Connection to be created * @return : Returns nothing */ void set_modify_bearer_request(gtpv2c_header_t *gtpv2c_tx, /*create_sess_req_t *csr,*/ pdn_connection *pdn, eps_bearer *bearer); /** * @brief : Set values in modify bearer request to send sgw csid * @param : gtpv2c_tx, gtpv2c message transmission buffer to response message * @param : pdn, PDN Connection data structure pertaining to the session to be created * @param : eps_bearer_id, Default EPS Bearer ID corresponding to the PDN Connection to be created * @return : Returns 0 in case of success , -1 otherwise */ int8_t set_mbr_upd_sgw_csid_req(gtpv2c_header_t *gtpv2c_tx, pdn_connection *pdn, uint8_t eps_bearer_id); /** * @brief : Process modify bearer response received on s5s8 interface at sgwc * @param : mb_rsp, buffer containing response data * @param : gtpv2c_tx, gtpv2c message transmission buffer to response message * @param : context, ue context * @return : Returns 0 in case of success , -1 otherwise */ int process_sgwc_s5s8_modify_bearer_response(mod_bearer_rsp_t *mb_rsp, gtpv2c_header_t *gtpv2c_tx, ue_context **context); /** * @brief : Process modify bearer response received on s5s8 interface at sgwc * @param : mb_rsp, buffer containing response data * @param : gtpv2c_tx, gtpv2c message transmission buffer to response messa * @return : Returns 0 in case of success , -1 otherwise */ int process_sgwc_s5s8_mbr_for_mod_proc(mod_bearer_rsp_t *mb_rsp, gtpv2c_header_t *gtpv2c_tx); /** * @brief : Handles processing of create bearer request and create session response messages * @param : cb_req * message reception buffer containing the request message * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_cs_resp_cb_request(create_bearer_req_t *cb_req); /** * @brief : Handles processing of modify bearer request and create bearer response message * @param : mbr * @param : cbr * message reception buffer containing the response message * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_mb_request_cb_response(mod_bearer_req_t *mbr, create_bearer_rsp_t *cbr); /** * @brief : Handles Change Notfication Response Mesage * @param : Change Notification Response struct pointer change_noti_rsp_t * : gtpv2c_header_t pointer * message reception buffer containing the response message * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int process_change_noti_response(change_noti_rsp_t *change_not_rsp, gtpv2c_header_t *gtpv2c_tx); /** * @brief : Set the change notification response message * @param : gtpv2c_header_t * : pdn_connection * @return : void */ void set_change_notification_response(gtpv2c_header_t *gtpv2c_tx, pdn_connection *pdn); /** * @brief : It sets the chnage notification message to be forwarded * @param : gtpv2c_header_t * : change_noti_req_t message pointer which is received at the * SGWC * @return : - 0 if successful * - > 0 if error occurs during packet filter parsing corresponds to 3gpp * specified cause error value * - < 0 for all other errors */ int set_change_notification_request(gtpv2c_header_t *gtpv2c_tx, change_noti_req_t *change_not_req, pdn_connection **pdn); /** * @brief : Set the release access bearer response message * @param : gtpv2c_header_t * : pdn_connection * @return : void */ void set_release_access_bearer_response(gtpv2c_header_t *gtpv2c_tx, pdn_connection *pdn); /* * @brief : Set the Create Indirect Data Forwarding Tunnel Response gtpv2c message * @param : gtpv2c_tx ,transmission buffer * @param : pdn_connection structre pointer * @return : Returns nothing */ void set_create_indir_data_frwd_tun_response(gtpv2c_header_t *gtpv2c_tx, pdn_connection *pdn); /* * @brief : process session modification response after mbr in s1 handover * @param : mb_rsp , modify bearer response object * @param : conetxt, ue_context * @param : pdn_connection structre pointer * @param : bearer, eps_bearer * @return : Returns zero on success. */ int process_pfcp_sess_mod_resp_s1_handover(mod_bearer_rsp_t *mb_rsp, ue_context *context, pdn_connection *pdn, eps_bearer *bearer); #endif /* GTPV2C_H */
nikhilc149/e-utran-features-bug-fixes
oss_adapter/libepcadapter/include/gw_structs.h
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2019 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdbool.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/ip.h> #ifndef GW_STRUCT_H #define GW_STRUCT_H #define IP_ADDR_V4_LEN 16 #define IPV6_STR_LEN 40 #define REST_SUCESSS 200 #define REST_FAIL 400 #define LAST_TIMER_SIZE 128 #define JSON_RESP_SIZE 512 #define SX_STATS_SIZE 23 #define S11_STATS_SIZE 51 #define S5S8_STATS_SIZE 37 #define GX_STATS_SIZE 23 #define ENTRY_VALUE_SIZE 64 #define ENTRY_NAME_SIZE 64 #define LINE_SIZE 256 #define CMD_LIST_SIZE 10 #define MAC_ADDR_LEN 64 #define MAX_LEN 128 #define ENODE_LEN 16 #define MCC_MNC_LEN 4 #define LB_HB_LEN 8 #define MAX_SYS_STATS 5 #define MAX_NUM_NAMESERVER 8 #define NETCAP_LEN 64 #define MAC_BYTES_LEN 32 #define MAX_NUM_APN 16 #define INET_ADDRSTRLEN 16 #define PATH_LEN 64 #define APN_NAME_LEN 64 #define DNS_IP_INDEX 1 #define MAC_ADDR_BYTES_IN_INT_ARRAY 6 #define FOUR_BIT_MAX_VALUE 15 #define REDIS_CERT_PATH_LEN 256 #define SGW_CHARGING_CHARACTERISTICS 2 #define CLI_GX_IP "127.0.0.1" #define MAX_PEER 10 #define S11_MSG_TYPE_LEN 49 #define S5S8_MSG_TYPE_LEN 35 #define SX_MSG_TYPE_LEN 23 #define GX_MSG_TYPE_LEN 8 #define SYSTEM_MSG_TYPE_LEN 4 #define HEALTH_STATS_SIZE 2 #define MAX_NUM_GW_MESSAGES 256 #define MAX_INTERFACE_NAME_LEN 10 #define MAX_GATEWAY_NAME_LEN 16 #define CP_PATH "../config/cp.cfg" #define DP_PATH "../config/dp.cfg" #define GTP_ECHO_REQ (1) #define GTP_ECHO_RSP (2) #define GTP_CREATE_SESSION_REQ (32) #define GTP_CREATE_SESSION_RSP (33) #define GTP_MODIFY_BEARER_REQ (34) #define GTP_MODIFY_BEARER_RSP (35) #define GTP_DELETE_SESSION_REQ (36) #define GTP_DELETE_SESSION_RSP (37) #define GTP_CREATE_BEARER_REQ (95) #define GTP_CREATE_BEARER_RSP (96) #define GTP_UPDATE_BEARER_REQ (97) #define GTP_UPDATE_BEARER_RSP (98) #define GTP_DELETE_BEARER_REQ (99) #define GTP_DELETE_BEARER_RSP (100) #define GTP_DELETE_PDN_CONNECTION_SET_REQ (101) #define GTP_DELETE_PDN_CONNECTION_SET_RSP (102) #define GTP_CHANGE_NOTIFICATION_REQ (38) #define GTP_CHANGE_NOTIFICATION_RSP (39) #define GTP_DELETE_BEARER_CMD (66) #define GTP_DELETE_BEARER_FAILURE_IND (67) #define GTP_MODIFY_BEARER_CMD (64) #define GTP_MODIFY_BEARER_FAILURE_IND (65) #define GTP_BEARER_RESOURCE_CMD (68) #define GTP_BEARER_RESOURCE_FAILURE_IND (69) #define GTP_PGW_RESTART_NOTIFICATION (179) #define GTP_PGW_RESTART_NOTIFICATION_ACK (180) #define GTP_UPDATE_PDN_CONNECTION_SET_REQ (200) #define GTP_UPDATE_PDN_CONNECTION_SET_RSP (201) #define IPV4_TYPE (1) #define IPV6_TYPE (2) #define IP_ADDR_V6_LEN (16) enum GxMessageType { OSS_CCR_INITIAL = 120, OSS_CCA_INITIAL, OSS_CCR_UPDATE, OSS_CCA_UPDATE, OSS_CCR_TERMINATE, OSS_CCA_TERMINATE, OSS_RAR, OSS_RAA }; enum oss_gw_config { OSS_CONTROL_PLANE = 01, OSS_USER_PLANE = 02 }; enum oss_s5s8_selection { OSS_S5S8_RECEIVER = 01, OSS_S5S8_SENDER = 02 }; typedef enum { PERIODIC_TIMER_INDEX, TRANSMIT_TIMER_INDEX, TRANSMIT_COUNT_INDEX, REQUEST_TIMEOUT_INDEX, REQUEST_TRIES_INDEX, PCAP_GENERATION_INDEX, } SystemCmds; /** * @brief : Maintains restoration parameters information */ typedef struct restoration_params_t { uint8_t transmit_cnt; int transmit_timer; int periodic_timer; } restoration_params_t; /** * @brief : Maintains apn related information */ typedef struct apn_info_t { char apn_name_label[APN_NAME_LEN]; int apn_usage_type; char apn_net_cap[NETCAP_LEN]; int trigger_type; int uplink_volume_th; int downlink_volume_th; int time_th; size_t apn_name_length; uint8_t apn_idx; struct in_addr ip_pool_ip; struct in_addr ip_pool_mask; struct in6_addr ipv6_network_id; uint8_t ipv6_prefix_len; } apn_info_t; /** * @brief : Maintains dns cache information */ typedef struct dns_cache_parameters_t { uint32_t concurrent; uint32_t sec; uint8_t percent; unsigned long timeoutms; uint32_t tries; } dns_cache_parameters_t; typedef enum { ACC = 0, REJ = 1, SENT = 0, RCVD = 1, BOTH = 0 } Dir; typedef enum { S11, S5S8, SX, GX, S1U, SGI }CLIinterface; typedef enum { itS11, itS5S8, itSx, itGx, itS1U, itSGI, } EInterfaceType; typedef enum { dIn, dOut, dRespSend, dRespRcvd, dBoth, dNone } EDirection; typedef enum { DECREMENT, INCREMENT, } Operation; typedef enum { number_of_active_session, number_of_users, number_of_bearers, number_of_pdn_connections, } SystemStats; typedef enum { PCAP_GEN_OFF, PCAP_GEN_ON, PCAP_GEN_RESTART, } PcapGenCmd; /** * @brief : Maintains dns configuration */ typedef struct dns_configuration_t { uint8_t freq_sec; char filename[PATH_LEN]; uint8_t nameserver_cnt; char nameserver_ip[MAX_NUM_NAMESERVER][IPV6_STR_LEN]; } dns_configuration_t; typedef struct { int msgtype; const char *msgname; EDirection dir; EDirection pgwc_dir; } MessageType; typedef struct { int cnt[2]; char ts[LAST_TIMER_SIZE]; } Statistic; /** * @brief : Maintains peer address details */ typedef struct peer_address_t { uint8_t type; struct sockaddr_in ipv4; struct sockaddr_in6 ipv6; } peer_address_t; /** * @brief : Maintains health request , response and interface stats for peers */ #pragma pack(1) typedef struct { peer_address_t cli_peer_addr; EInterfaceType intfctype; bool status; int *response_timeout; int *maxtimeout; uint8_t timeouts; char lastactivity[LAST_TIMER_SIZE]; int hcrequest[HEALTH_STATS_SIZE]; int hcresponse[HEALTH_STATS_SIZE]; union { Statistic s11[S11_STATS_SIZE]; Statistic s5s8[S5S8_STATS_SIZE]; Statistic sx[SX_STATS_SIZE]; Statistic gx[GX_STATS_SIZE]; } stats; } SPeer; /** * @brief : Maintains CP-Configuration */ typedef struct { uint8_t cp_type; uint16_t s11_port; uint16_t s5s8_port; uint16_t pfcp_port; uint16_t dadmf_port; uint16_t ddf2_port; struct in_addr s11_ip; struct in_addr s5s8_ip; struct in_addr pfcp_ip; char dadmf_ip[IPV6_STR_LEN]; char ddf2_ip[IPV6_STR_LEN]; char ddf2_local_ip[IPV6_STR_LEN]; uint16_t upf_pfcp_port; struct in_addr upf_pfcp_ip; uint16_t redis_port; char redis_ip_buff[IPV6_STR_LEN]; char cp_redis_ip_buff[IPV6_STR_LEN]; char redis_cert_path[REDIS_CERT_PATH_LEN]; uint8_t request_tries; int request_timeout; uint8_t add_default_rule; uint8_t use_dns; uint32_t num_apn; struct apn_info_t apn_list[MAX_NUM_APN]; int trigger_type; int uplink_volume_th; int downlink_volume_th; int time_th; struct dns_cache_parameters_t dns_cache; struct dns_configuration_t ops_dns; struct dns_configuration_t app_dns; struct restoration_params_t restoration_params; struct in_addr ip_pool_ip; struct in_addr ip_pool_mask; uint8_t generate_cdr; uint8_t generate_sgw_cdr; uint16_t sgw_cc; uint8_t ip_byte_order_changed; uint8_t use_gx; uint8_t perf_flag; uint8_t is_gx_interface; char dadmf_local_addr[IPV6_STR_LEN]; uint16_t dl_buf_suggested_pkt_cnt; uint16_t low_lvl_arp_priority; struct in6_addr ipv6_network_id; uint8_t ipv6_prefix_len; uint8_t ip_allocation_mode; uint8_t ip_type_supported; uint8_t ip_type_priority; char cp_dns_ip_buff[IPV6_STR_LEN]; struct in6_addr s11_ip_v6; struct in6_addr s5s8_ip_v6; struct in6_addr pfcp_ip_v6; struct in6_addr upf_pfcp_ip_v6; uint16_t cli_rest_port; char cli_rest_ip_buff[IPV6_STR_LEN]; } cp_configuration_t; /** * @brief : Maintains DP-Configuration */ typedef struct { uint8_t dp_type; uint32_t wb_ip; struct in6_addr wb_ipv6; uint8_t wb_ipv6_prefix_len; uint32_t wb_mask; uint32_t wb_port; uint32_t eb_ip; uint32_t eb_mask; uint32_t eb_port; uint8_t eb_ipv6_prefix_len; struct in6_addr eb_ipv6; uint32_t numa_on; int teidri_val; int teidri_timeout; uint8_t generate_pcap; uint8_t perf_flag; struct in_addr dp_comm_ip; struct in6_addr dp_comm_ipv6; uint8_t pfcp_ipv6_prefix_len; uint16_t dp_comm_port; struct restoration_params_t restoration_params; char ddf2_ip[IPV6_STR_LEN]; char ddf3_ip[IPV6_STR_LEN]; uint16_t ddf2_port; uint16_t ddf3_port; char ddf2_local_ip[IPV6_STR_LEN]; char ddf3_local_ip[IPV6_STR_LEN]; char wb_iface_name[MAX_LEN]; char eb_iface_name[MAX_LEN]; char wb_mac[MAC_BYTES_LEN]; char eb_mac[MAC_BYTES_LEN]; uint32_t wb_li_ip; struct in6_addr wb_li_ipv6; uint8_t wb_li_ipv6_prefix_len; char wb_li_iface_name[MAX_LEN]; uint32_t wb_li_mask; char eb_li_iface_name[MAX_LEN]; uint32_t eb_li_mask; uint32_t eb_li_ip; struct in6_addr eb_li_ipv6; uint8_t eb_li_ipv6_prefix_len; struct in6_addr eb_l3_ipv6; struct in6_addr wb_l3_ipv6; uint32_t wb_gw_ip; uint32_t eb_gw_ip; uint8_t gtpu_seqnb_out; uint8_t gtpu_seqnb_in; uint16_t cli_rest_port; char cli_rest_ip_buff[IPV6_STR_LEN]; } dp_configuration_t; typedef struct li_df_config_t { /* Identifier */ uint64_t uiId; /* Unique Ue Identity */ uint64_t uiImsi; /* Signalling Interfaces */ uint16_t uiS11; uint16_t uiSgwS5s8C; uint16_t uiPgwS5s8C; /* Sx Signalling Interfaces */ uint16_t uiSxa; uint16_t uiSxb; uint16_t uiSxaSxb; /* Header OR Header + Data OR Data*/ uint16_t uiS1uContent; uint16_t uiSgwS5s8UContent; uint16_t uiPgwS5s8UContent; uint16_t uiSgiContent; /* Data Interfaces */ uint16_t uiS1u; uint16_t uiSgwS5s8U; uint16_t uiPgwS5s8U; uint16_t uiSgi; /* Forward to DFx */ uint16_t uiForward; } li_df_config_t; /** * @brief : Maintains GW-Callbacks */ typedef struct gw_adapter_callback_register { int8_t (*update_request_tries)(const int); int8_t (*update_request_timeout)(const int); int8_t (*update_periodic_timer)(const int); int8_t (*update_transmit_timer)(const int); int8_t (*update_transmit_count)(const int); int8_t (*update_pcap_status)(const int); int8_t (*update_perf_flag)(const int); int (*get_request_tries)(void); int (*get_request_timeout)(void); int (*get_periodic_timer)(void); int (*get_transmit_timer)(void); int (*get_transmit_count)(void); uint8_t (*get_perf_flag)(void); int8_t (*get_cp_config)(cp_configuration_t*); int8_t (*get_dp_config)(dp_configuration_t*); int8_t (*get_generate_pcap)(void); int8_t (*add_ue_entry)(li_df_config_t*, uint16_t); int8_t (*update_ue_entry)(li_df_config_t*, uint16_t); uint8_t (*delete_ue_entry)(uint64_t*, uint16_t); } gw_adapter_callback_register; /** * @brief : Maintains CLI-config data */ typedef struct cli_config_t { int number_of_transmit_count; int number_of_request_tries; int transmit_timer_value; int periodic_timer_value; int request_timeout_value; uint8_t generate_pcap_status; int cnt_peer; int nbr_of_peer; uint64_t oss_reset_time; uint8_t perf_flag; cp_configuration_t cp_configuration; dp_configuration_t dp_configuration; gw_adapter_callback_register gw_adapter_callback_list; } cli_config_t; /** * @brief : Maintains CLI-node data */ typedef struct { uint8_t gw_type; uint64_t *upsecs; uint64_t *resetsecs; uint8_t s5s8_selection; uint64_t stats[MAX_SYS_STATS]; cli_config_t cli_config; SPeer *peer[MAX_PEER]; }cli_node_t; #pragma pack() /*Following variables also used in ngic-rtc*/ extern int s11MessageTypes[MAX_NUM_GW_MESSAGES]; extern int s5s8MessageTypes[MAX_NUM_GW_MESSAGES]; extern int sxMessageTypes[MAX_NUM_GW_MESSAGES]; extern int gxMessageTypes[MAX_NUM_GW_MESSAGES]; extern int supported_commands[CMD_LIST_SIZE][CMD_LIST_SIZE]; extern MessageType ossS5s8MessageDefs[]; extern MessageType ossS11MessageDefs[]; extern MessageType ossSxMessageDefs[]; extern MessageType ossGxMessageDefs[]; extern MessageType ossSystemMessageDefs[]; extern char ossInterfaceStr[][MAX_INTERFACE_NAME_LEN]; extern char ossInterfaceProtocolStr[][MAX_INTERFACE_NAME_LEN]; extern char ossGatewayStr[][MAX_GATEWAY_NAME_LEN]; extern uint64_t reset_time; #endif
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/pfcp_init.c
<reponame>nikhilc149/e-utran-features-bug-fixes<gh_stars>0 /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <time.h> #include <rte_hash_crc.h> #include "cp.h" #include "pfcp.h" #include "gw_adapter.h" /*VS:TODO: Need to revist this for hash size */ #define PFCP_CNTXT_HASH_SIZE (1 << 16) #define TIMESTAMP_LEN 14 #define NUM_OF_TABLES 4 #define NUM_INIT_TABLES 3 #define MAX_HASH_SIZE (1 << 16) #define MAX_SEQ_ENTRIES_HASH_SIZE (1 << 10) #define MAX_PDN_HASH_SIZE (1 << 12) /* Entries = (No. of UE's * 2) */ #define UN_16_BIT_HASH_SIZE (1 << 17) const uint8_t bar_base_rule_id = 0x00; const uint16_t pdr_base_rule_id = 0x0000; const uint32_t far_base_rule_id = 0x00000000; const uint32_t urr_base_rule_id = 0x00000000; const uint32_t qer_base_rule_id = 0x00000000; /* VS: Need to decide the base value of call id */ /* const uint32_t call_id_base_value = 0xFFFFFFFF; */ const uint32_t call_id_base_value = 0x00000000; static uint32_t call_id_offset; static uint64_t dp_sess_id_offset; const uint32_t rar_base_rule_id = 0x00000000; const uint32_t base_seq_number = 0x00000000; static uint32_t seq_number_offset; extern int clSystemLog; /** * Add PDN Connection entry in PDN hash table. * * @param CALL ID * key. * @param pdn_connection pdn * return 0 or 1. * */ uint8_t add_pdn_conn_entry(uint32_t call_id, pdn_connection *pdn) { int ret = 0; pdn_connection *tmp = NULL; /* Lookup for PDN Connection entry. */ ret = rte_hash_lookup_data(pdn_conn_hash, &call_id, (void **)&tmp); if ( ret < 0) { /* PDN Connection Entry if not present */ ret = rte_hash_add_key_data(pdn_conn_hash, &call_id, pdn); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add pdn " "connection for CALL_ID = %u" "\n\tError= %s\n", LOG_VALUE, call_id, rte_strerror(abs(ret))); return GTPV2C_CAUSE_SYSTEM_FAILURE; } } else { memcpy(tmp, pdn, sizeof(pdn_connection)); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" PDN Connection entry add for CALL_ID:%u", LOG_VALUE, call_id); return 0; } /** * Get PDN Connection entry from PDN hash table. * * @param CALL ID * key. * return pdn_connection pdn or NULL * */ pdn_connection *get_pdn_conn_entry(uint32_t call_id) { int ret = 0; pdn_connection *pdn = NULL; /* Check PDN Conn entry is present or Not */ ret = rte_hash_lookup_data(pdn_conn_hash, &call_id, (void **)&pdn); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for CALL_ID:%u " "while extrating PDN entry\n", LOG_VALUE, call_id); return NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"CALL_ID for PDN connection entry:%u", LOG_VALUE, call_id); return pdn; } /** * Delete PDN Connection entry from PDN hash table. * * @param CALL ID * key. * return 0 or 1. * */ uint8_t del_pdn_conn_entry(uint32_t call_id) { int ret = 0; pdn_connection *pdn = NULL; /* Check PDN Conn entry is present or Not */ ret = rte_hash_lookup_data(pdn_conn_hash, &call_id, (void **)&pdn); if (ret >= 0) { /* PDN Conn Entry is present. Delete PDN Conn Entry */ ret = rte_hash_del_key(pdn_conn_hash, &call_id); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found " "for CALL_ID :%u while deleting PDN connection entry\n", LOG_VALUE, call_id); return -1; } } /* Free data from hash */ if (pdn != NULL) { rte_free(pdn); pdn = NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"CALL_ID for PDN connection entry:%u", LOG_VALUE, call_id); return 0; } /** * Add Rule name entry with bearer identifier in Rule and bearer map hash table. * * @param Rule_Name * key. * @param uint8_t bearer id * return 0 or 1. * */ uint8_t add_rule_name_entry(const rule_name_key_t rule_key, bearer_id_t *bearer) { int ret = 0; bearer_id_t *tmp = NULL; /* Lookup for Rule entry. */ ret = rte_hash_lookup_data(rule_name_bearer_id_map_hash, &rule_key, (void **)&tmp); if ( ret < 0) { /* Rule Entry if not present */ ret = rte_hash_add_key_data(rule_name_bearer_id_map_hash, &rule_key, bearer); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add rule " "entry for Rule_Name = %s" "\n\tError= %s\n", LOG_VALUE, rule_key.rule_name, rte_strerror(abs(ret))); return -1; } } else { memcpy(tmp, bearer, sizeof(bearer_id_t)); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT":Rule Name entry add for " "Rule_Name:%s, Bearer_id:%u\n", LOG_VALUE, rule_key.rule_name, bearer->bearer_id); return 0; } /** * Get Rule Name entry from Rule and Bearer Map table. * * @param Rule_Name * key. * return Bearer ID or NULL * */ int8_t get_rule_name_entry(const rule_name_key_t rule_key) { int ret = 0; bearer_id_t *bearer = NULL; /* Check Rule Name entry is present or Not */ ret = rte_hash_lookup_data(rule_name_bearer_id_map_hash, &rule_key, (void **)&bearer); if ( ret < 0) { return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT": Rule_Name:%s, Bearer_ID:%u\n", LOG_VALUE, rule_key.rule_name, bearer->bearer_id); return bearer->bearer_id; } int8_t add_seq_number_for_teid(const teid_key_t teid_key, struct teid_value_t *teid_value) { int ret = 0; struct teid_value_t *tmp = NULL; ret = rte_hash_lookup_data(ds_seq_key_with_teid, &teid_key, (void **)&tmp); if(ret < 0) { ret = rte_hash_add_key_data(ds_seq_key_with_teid, &teid_key, teid_value); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add TEID " "entry for key = %s" "\n\tError= %s\n", LOG_VALUE, teid_key.teid_key, rte_strerror(abs(ret))); return -1; } } else { memcpy(tmp, &teid_value, sizeof(struct teid_value_t)); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT":TEID entry added for " "key :%s, TEID : %u\n", LOG_VALUE, teid_key.teid_key, teid_value->teid); return 0; } teid_value_t *get_teid_for_seq_number(const teid_key_t teid_key) { int ret = 0; teid_value_t *teid_value = NULL; /* lookup the entry based on the sequence number */ ret = rte_hash_lookup_data(ds_seq_key_with_teid, &teid_key, (void **)&teid_value); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get teid value " "for key : %s\n", LOG_VALUE, teid_key.teid_key); return NULL; } //memcpy(teid_t, teid, sizeof(uint32_t)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Found entry for Key:%s, TEID:%u\n", LOG_VALUE, teid_key.teid_key, teid_value->teid); return teid_value; } int8_t delete_teid_entry_for_seq(const teid_key_t teid_key) { int ret = 0; struct teid_value_t *teid_value = NULL; ret = rte_hash_lookup_data(ds_seq_key_with_teid, &teid_key, (void **)&teid_value); if(ret >= 0) { ret = rte_hash_del_key(ds_seq_key_with_teid, &teid_key); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to " "delete TEID entry for key = %s\n\tError= %s\n", LOG_VALUE, teid_key.teid_key, rte_strerror(abs(ret))); return -1; } } /* Free data from hash */ if (teid_value != NULL) { rte_free(teid_value); teid_value = NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"TEID entry deleted for " "teid key :%s\n", LOG_VALUE, teid_key.teid_key); return 0; } /** * Delete Rule Name entry from Rule and Bearer Map hash table. * * @param Rule_Name * key. * return 0 or 1. * */ uint8_t del_rule_name_entry(const rule_name_key_t rule_key) { int ret = 0; bearer_id_t *bearer = NULL; /* Check Rule Name entry is present or Not */ ret = rte_hash_lookup_data(rule_name_bearer_id_map_hash, &rule_key, (void **) &bearer); if (ret >= 0) { /* Rule Name Entry is present. Delete Rule Name Entry */ ret = rte_hash_del_key(rule_name_bearer_id_map_hash, &rule_key); if ( ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for Rule_Name:%s...\n", LOG_VALUE, rule_key.rule_name); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Rule_Name:%s is found \n", LOG_VALUE, rule_key.rule_name); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Rule_Name:%s is not " "found \n", LOG_VALUE, rule_key.rule_name); } /* Free data from hash */ if (bearer != NULL) { free(bearer); bearer = NULL; } return 0; } /** * Add PDR entry in PDR hash table. * * @param rule_id/PDR_ID * key. * @param pdr_t cntxt * return 0 or 1. * */ uint8_t add_pdr_entry(uint16_t rule_id, pdr_t *cntxt, uint64_t cp_seid) { int ret = 0; pdr_t *tmp = NULL; rule_key_t hash_key = {0}; hash_key.id = (uint32_t)rule_id; hash_key.cp_seid = cp_seid; /* Lookup for PDR entry. */ ret = rte_hash_lookup_data(pdr_entry_hash, &hash_key, (void **)&tmp); if ( ret < 0) { /* PDR Entry not present. Add PDR Entry */ ret = rte_hash_add_key_data(pdr_entry_hash, &hash_key, cntxt); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for PDR_ID = %u" "\n\tError= %s\n", LOG_VALUE, rule_id, rte_strerror(abs(ret))); return -1; } } else { memcpy(tmp, cntxt, sizeof(pdr_t)); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT": PDR entry added for PDR_ID:%u\n", LOG_VALUE, rule_id); return 0; } /** * Get PDR entry from PDR hash table. * * @param PDR ID * key. * return pdr_t cntxt or NULL * */ pdr_t *get_pdr_entry(uint16_t rule_id, uint64_t cp_seid) { int ret = 0; pdr_t *cntxt = NULL; rule_key_t hash_key = {0}; hash_key.id = (uint32_t)rule_id; hash_key.cp_seid = cp_seid; ret = rte_hash_lookup_data(pdr_entry_hash, &hash_key, (void **)&cntxt); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for PDR_ID:%u...\n", LOG_VALUE, rule_id); return NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT": PDR_ID:%u\n", LOG_VALUE, rule_id); return cntxt; } int update_pdr_teid(eps_bearer *bearer, uint32_t teid, node_address_t addr, uint8_t iface){ int ret = -1; for(uint8_t itr = 0; itr < bearer->pdr_count ; itr++) { if(bearer->pdrs[itr] == NULL) continue; if(bearer->pdrs[itr]->pdi.src_intfc.interface_value == iface){ bearer->pdrs[itr]->pdi.local_fteid.teid = teid; if(addr.ip_type == PDN_IP_TYPE_IPV4) { bearer->pdrs[itr]->pdi.local_fteid.ipv4_address = addr.ipv4_addr; bearer->pdrs[itr]->pdi.local_fteid.v4 = PRESENT; } if(addr.ip_type == PDN_IP_TYPE_IPV6) { memcpy(bearer->pdrs[itr]->pdi.local_fteid.ipv6_address, addr.ipv6_addr, IPV6_ADDRESS_LEN); bearer->pdrs[itr]->pdi.local_fteid.v6 = PRESENT; } if(addr.ip_type == PDN_IP_TYPE_IPV4V6) { bearer->pdrs[itr]->pdi.local_fteid.ipv4_address = addr.ipv4_addr; memcpy(bearer->pdrs[itr]->pdi.local_fteid.ipv6_address, addr.ipv6_addr, IPV6_ADDRESS_LEN); bearer->pdrs[itr]->pdi.local_fteid.v4 = PRESENT; bearer->pdrs[itr]->pdi.local_fteid.v6 = PRESENT; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Updated pdr entry Successfully for PDR_ID:%u\n", LOG_VALUE, bearer->pdrs[itr]->rule_id); ret = 0; break; } } return ret; } /** * Delete PDR entry from PDR hash table. * * @param PDR ID * key. * return 0 or 1. * */ uint8_t del_pdr_entry(uint16_t rule_id, uint64_t cp_seid) { int ret = 0; pdr_t *cntxt = NULL; rule_key_t hash_key = {0}; hash_key.id = (uint32_t)rule_id; hash_key.cp_seid = cp_seid; /* Check PDR entry is present or Not */ ret = rte_hash_lookup_data(pdr_entry_hash, &hash_key, (void **)&cntxt); if (ret >= 0) { /* PDR Entry is present. Delete PDR Entry */ ret = rte_hash_del_key(pdr_entry_hash, &hash_key); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found " "for PDR_ID:%u\n", LOG_VALUE, rule_id); return -1; } /* Free data from hash */ if (cntxt != NULL) { rte_free(cntxt); cntxt = NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"PDR_ID:%u\n",LOG_VALUE, rule_id); return 0; } /** * Add QER entry in QER hash table. * * @param qer_id * key. * @param qer_t context * return 0 or 1. * */ uint8_t add_qer_entry(uint32_t qer_id, qer_t *cntxt, uint64_t cp_seid) { int ret = 0; qer_t *tmp = NULL; rule_key_t hash_key = {0}; hash_key.id = (uint32_t)qer_id; hash_key.cp_seid = cp_seid; /* Lookup for QER entry. */ ret = rte_hash_lookup_data(qer_entry_hash, &hash_key, (void **)&tmp); if ( ret < 0) { /* QER Entry not present. Add QER Entry in table */ ret = rte_hash_add_key_data(qer_entry_hash, &hash_key, cntxt); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add QER entry for QER_ID = %u" "\n\tError= %s\n", LOG_VALUE, qer_id, rte_strerror(abs(ret))); return -1; } } else { memcpy(tmp, cntxt, sizeof(qer_t)); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" QER entry add for QER_ID:%u\n", LOG_VALUE, qer_id); return 0; } /** * Get QER entry from QER hash table. * * @param QER ID * key. * return qer_t cntxt or NULL * */ qer_t *get_qer_entry(uint32_t qer_id, uint64_t cp_seid) { int ret = 0; qer_t *cntxt = NULL; rule_key_t hash_key = {0}; hash_key.id = qer_id; hash_key.cp_seid = cp_seid; /* Retireve QER entry */ ret = rte_hash_lookup_data(qer_entry_hash, &hash_key, (void **)&cntxt); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for QER_ID:%u " "while extrating QER\n", LOG_VALUE, qer_id); return NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT": QER_ID:%u\n", LOG_VALUE, qer_id); return cntxt; } /** * Delete QER entry from QER hash table. * * @param QER ID * key. * return 0 or 1. * */ uint8_t del_qer_entry(uint32_t qer_id, uint64_t cp_seid) { int ret = 0; qer_t *cntxt = NULL; rule_key_t hash_key = {0}; hash_key.id = qer_id; hash_key.cp_seid = cp_seid; /* Check QER entry is present or Not */ ret = rte_hash_lookup_data(qer_entry_hash, &hash_key, (void **)&cntxt); if (ret >= 0) { /* QER Entry is present. Delete Session Entry */ ret = rte_hash_del_key(qer_entry_hash, &hash_key); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found " "for QER_ID:%u while deleting QER\n", LOG_VALUE, qer_id); return -1; } } /* Free data from hash */ if (cntxt != NULL) { rte_free(cntxt); cntxt = NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"QER_ID:%u\n", LOG_VALUE, qer_id); return 0; } /** * Generate the BAR ID */ uint8_t generate_bar_id(uint8_t *bar_rule_id_offset) { uint8_t id = 0; id = bar_base_rule_id + (++(*bar_rule_id_offset)); return id; } /** * Generate the PDR ID */ uint16_t generate_pdr_id(uint16_t *pdr_rule_id_offset) { uint16_t id = 0; id = pdr_base_rule_id + (++(*pdr_rule_id_offset)); return id; } /** * Generate the FAR ID */ uint32_t generate_far_id(uint32_t *far_rule_id_offset) { uint32_t id = 0; id = far_base_rule_id + (++(*far_rule_id_offset)); return id; } /** * Generate the URR ID */ uint32_t generate_urr_id(uint32_t *urr_rule_id_offset) { uint32_t id = 0; id = urr_base_rule_id + (++(*urr_rule_id_offset)); return id; } /** * Generate the QER ID */ uint32_t generate_qer_id(uint32_t *qer_rule_id_offset) { uint32_t id = 0; id = qer_base_rule_id + (++(*qer_rule_id_offset)); return id; } /** * Generates sequence numbers for sgwc generated * gtpv2c messages for mme */ uint32_t generate_seq_number(void) { uint32_t id = 0; id = base_seq_number + (++seq_number_offset); return id; } /** * Convert the decimal value into the string. */ int int_to_str(char *buf , uint32_t val) { uint8_t tmp_buf[10] = {0}; uint32_t cnt = 0, num = 0; uint8_t idx = 0; while(val) { num = val%10; tmp_buf[cnt] = (uint8_t)(num + 48); val/=10; ++cnt; } tmp_buf[cnt] = '\0'; --cnt; for(; tmp_buf[idx]; ++idx) { buf[idx] = tmp_buf[cnt]; --cnt; } buf[idx] = '\0'; return idx; } /** * @brief : Get the system current timestamp. * @param : timestamp is used for storing system current timestamp * @return : Returns 0 in case of success */ static uint8_t get_timestamp(char *timestamp) { time_t t = time(NULL); struct tm *tmp = localtime(&t); strftime(timestamp, MAX_LEN, "%Y%m%d%H%M%S", tmp); return 0; } /** * @brief : Generate CCR session id with the combination of timestamp and call id * @param : str_buf is used to store generated session id * @param : timestamp is used to pass timestamp * @param : value is used to pas call id * @return : Returns 0 in case of success , -1 otherwise */ static int gen_sess_id_string(char *str_buf, char *timestamp , uint32_t value) { char buf[MAX_LEN] = {0}; int len = 0; if (timestamp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Time stamp is NULL " "while generating session ID\n", LOG_VALUE); return -1; } /* itoa(value, buf, 10); 10 Means base value, i.e. indicate decimal value */ len = int_to_str(buf, value); if(buf[0] == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed in coversion of " "integer to string, len:%d \n", LOG_VALUE, len); return -1; } snprintf(str_buf, GX_SESS_ID_LEN,"%s%s", timestamp, buf); return 0; } /** * Generate the CALL ID */ uint32_t generate_call_id(void) { uint32_t call_id = 0; call_id = call_id_base_value + (++call_id_offset); return call_id; } /** * Retrieve the call id from the CCR session id. */ int retrieve_call_id(char *str, uint32_t *call_id) { uint8_t idx = 0, index = 0; char buf[MAX_LEN] = {0}; if(str == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"String is NULL \n", LOG_VALUE); return -1; } idx = TIMESTAMP_LEN; /* TIMESTAMP STANDARD BYTE SIZE */ for(;str[idx] != '\0'; ++idx) { buf[index] = str[idx]; ++index; } *call_id = atoi(buf); if (*call_id == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Call ID not found\n", LOG_VALUE); return -1; } return 0; } /** * Return the CCR session id. */ int8_t gen_sess_id_for_ccr(char *sess_id, uint32_t call_id) { char timestamp[GX_SESS_ID_LEN] = {0}; get_timestamp(timestamp); if((gen_sess_id_string(sess_id, timestamp, call_id)) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to generate " "session id for CCR\n", LOG_VALUE); return -1; } return 0; } /** * @brief Initializes the pfcp context hash table used to account for * PDR, QER, BAR and FAR rules information. */ void init_hash_tables(void) { struct rte_hash_parameters pfcp_hash_params[NUM_OF_TABLES] = { { .name = "PDR_ENTRY_HASH", .entries = UN_16_BIT_HASH_SIZE, .key_len = sizeof(rule_key_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "QER_ENTRY_HASH", .entries = UN_16_BIT_HASH_SIZE, .key_len = sizeof(rule_key_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "PDN_CONN_HASH", //.entries = MAX_PDN_HASH_SIZE, .entries = MAX_HASH_SIZE, .key_len = sizeof(uint32_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() } }; pdr_entry_hash = rte_hash_create(&pfcp_hash_params[0]); if (!pdr_entry_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[0].name, rte_strerror(rte_errno), rte_errno); } qer_entry_hash = rte_hash_create(&pfcp_hash_params[1]); if (!qer_entry_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[1].name, rte_strerror(rte_errno), rte_errno); } pdn_conn_hash = rte_hash_create(&pfcp_hash_params[2]); if (!pdn_conn_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[3].name, rte_strerror(rte_errno), rte_errno); } } /** * @brief Initializes the pfcp context hash table used to account for * PDR, QER, BAR and FAR rules information in control plane. */ void init_pfcp_tables(void) { struct rte_hash_parameters pfcp_hash_params[NUM_INIT_TABLES] = { { .name = "PFCP_CNTXT_HASH", .entries = PFCP_CNTXT_HASH_SIZE, .key_len = sizeof(uint64_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "RULE_NAME_BEARER_ID_HASH", .entries = UN_16_BIT_HASH_SIZE, .key_len = sizeof(rule_name_key_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "DS_SEQ_TEID_HASH", .entries = MAX_HASH_SIZE, .key_len = sizeof(uint32_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() } }; rule_name_bearer_id_map_hash = rte_hash_create(&pfcp_hash_params[1]); if (!rule_name_bearer_id_map_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[1].name, rte_strerror(rte_errno), rte_errno); } ds_seq_key_with_teid = rte_hash_create(&pfcp_hash_params[2]); if (!ds_seq_key_with_teid) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[2].name, rte_strerror(rte_errno), rte_errno); } init_hash_tables(); } /** * Generate the SESSION ID */ uint64_t generate_dp_sess_id(uint64_t cp_sess_id) { uint64_t dp_sess_id = 0; dp_sess_id = ((++dp_sess_id_offset << 32) | cp_sess_id); return dp_sess_id; }
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/pfcp_session.h
<filename>pfcp_messages/pfcp_session.h /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef PFCP_SESSION_H #define PFCP_SESSION_H #include "pfcp_messages.h" #ifdef CP_BUILD #include "gtpv2c.h" #include "sm_struct.h" #include "gtpv2c_ie.h" #include "pfcp_set_ie.h" #include "gtpv2c_set_ie.h" #include "gtp_messages.h" #endif #define NUM_UE 10000 #define NUM_DP 100 #define MAX_LI_POLICY_LIMIT 255 #define ADDR_BUF_SIZE 64 #define PCKT_BUF_SIZE 256 /** * @brief : This structure holds data related to association with dp */ typedef struct association_context{ uint8_t rx_buf[NUM_DP][NUM_UE]; char sgwu_fqdn[NUM_DP][MAX_HOSTNAME_LENGTH]; uint32_t upf_ip; uint32_t csr_cnt; }association_context_t; #ifdef CP_BUILD #define PKT_FLTR_CONTENT_INDEX 3 #define PKT_FLTR_LEN_INDEX 2 #define PKT_FLTR_COMP_TYPE_ID_LEN 4 #define IP_MASK 8 #define PORT_LEN 2 #define PARAMETER_LIST_LEN 3 #define NEXT_PKT_FLTR_COMP_INDEX 3 #define NUM_OF_PKT_FLTR_MASK 0x0f #define E_BIT_MASK 0x01 #define PKT_FLTR_ID_SIZE 8 #define EBI_ABSENT 0 #define TFT_OP_CODE_SHIFT 5 #define TFT_OP_CODE_MASK 0x0f #define PARAM_LIST_INDEX 4 /** * @brief : This structure holds rule cnt which is * : to be send in Charging-Rule-Report AVP * : in BRC flow. * : Also store rule index of pckt-filter-id * : and num of packet filter in rule */ typedef struct rule_report_index { uint8_t rule_cnt; uint8_t rule_report[MAX_RULE_PER_BEARER]; uint8_t num_fltr[MAX_FILTERS_PER_UE]; }rule_report_index_t; /** * @brief : This structure use to parse * : packet filter receive in * : TAD IE in bearer resourse command. */ typedef struct tad_pkt_fltr { uint8_t v4; uint8_t v6; uint8_t proto_id; uint8_t pckt_fltr_dir; uint32_t local_ip_addr; uint8_t local_ip6_addr[IPV6_ADDRESS_LEN]; uint8_t local_ip_mask ; uint32_t remote_ip_addr; uint8_t remote_ip6_addr[IPV6_ADDRESS_LEN]; uint8_t remote_ip_mask; uint16_t local_port_low ; uint16_t local_port_high; uint16_t remote_port_low; uint16_t remote_port_high; uint16_t single_remote_port; uint16_t single_local_port; uint8_t pckt_fltr_id ; uint8_t precedence ; }tad_pkt_fltr_t; /** * @brief : This function use to fill packet-filter-inforamation AVP * : TAD structure. * @param : ccr_request, pointer to CCR-U message * @param : tad_pkt_fltr, pointer to TAD structure. * @return : Returns 0 on success,else -1 */ int fill_packet_fltr_info_avp(gx_msg *ccr_request, tad_pkt_fltr_t *tad_pkt_fltr, uint8_t idx); /** * @brief : Check presence of packet filter id in rules * @param : pckt_id, packet filter id received in bearer resource cmd * @param : bearer, pointer to bearer in which pckt_id is to be find. * @return : Returns rule index which contain packet id on success,else -1 */ int check_pckt_fltr_id_in_rule(uint8_t pckt_id, eps_bearer *bearer); /** * @brief : Parse TAD packet filter * @param : pkt_fltr_buf,packet filter in bearer resource cmd * @param : tad_pkt_fltr,structure used to fill AVP * @return : Returns 0 on success,else 0 */ int parse_tad_packet_filter(uint8_t pkt_fltr_buf[], tad_pkt_fltr_t *tad_pkt_fltr); /** * @brief : Fill gx AVP corresponding to bearer resource cmd * @param : pkt_fltr_buf,packet filter in bearer resource cmd * @param : tad_pkt_fltr,structure used to fill AVP * @return : Returns 0 on success,else 0 */ int fill_create_new_tft_avp(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd); /** * @brief : Fill gx AVP corresponding to bearer resource cmd * @param : pkt_fltr_buf,packet filter in bearer resource cmd * @param : tad_pkt_fltr,structure used to fill AVP * @return : Returns 0 on success,else 0 */ int fill_delete_existing_tft_avp(gx_msg *ccr_request); /** * @brief : Fill gx AVP corresponding to bearer resource cmd * @param : pkt_fltr_buf,packet filter in bearer resource cmd * @param : tad_pkt_fltr,structure used to fill AVP * @return : Returns 0 on success,else 0 */ int fill_delete_existing_filter_tft_avp(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd, eps_bearer *bearer); /** * @brief : Fill gx AVP corresponding to bearer resource cmd * @param : ccr_request, ptr to ccr msg structure. * @param : bearer_rsrc_cmd, ptr to bearer rsrc cmd msg * @param : bearer, ptr to bearer for which bearer id is recv in BRC * @return : Returns 0 on success,else return error code. */ int fill_no_tft_avp(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd, eps_bearer *bearer); /** * @brief : Fill gx AVP corresponding to bearer resource cmd * @param : ccr_request, pointer to ccr msg buffer * @param : bearer_rsrc_cmd, holds bearer resource cmd msg * @return : Returns 0 on success,else return error code */ int fill_replace_filter_existing_tft_avp(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd, eps_bearer *bearer); /** * @brief : Fill gx AVP corresponding to bearer resource cmd * @param : pkt_fltr_buf,packet filter in bearer resource cmd * @param : tad_pkt_fltr,structure used to fill AVP * @return : Returns 0 on success,else 0 */ int fill_qos_avp_bearer_resource_cmd(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd); /** * @brief : Fill gx AVP corresponding to bearer resource cmd * @param : pkt_fltr_buf,packet filter in bearer resource cmd * @param : tad_pkt_fltr,structure used to fill AVP * @return : Returns 0 on success,else 0 */ int fill_gx_packet_filter_id(uint8_t *pkt_fltr_buf, delete_pkt_filter *pkt_id); /** * @brief : Fill gx AVP corresponding to bearer resource cmd * @param : ccr_request, pointer to msg which is send in ccr-u. * @param : bearer_rsrc_cmd, pointer to received bearer resource cmd * @return : Returns 0 on success,else err code. */ int fill_add_filter_existing_tft_avp(gx_msg *ccr_request, bearer_rsrc_cmd_t *bearer_rsrc_cmd, eps_bearer *bearer); /** * @brief : Fill gx AVP corresponding to bearer resource cmd * @param : pkt_fltr_buf,packet filter in bearer resource cmd * @param : tad_pkt_fltr,structure used to fill AVP * @return : Returns 0 on success,else 0 */ int parse_parameter_list(uint8_t pkt_fltr_buf[], param_list *param_lst); /** * @brief : Generate CCR request for provision ack * @param : pdn , pointer to pdn connection structure * @param : bearer, pointer to eps bearer structure * @param : rule_action, indicate bearer operartin ADD/MODIFY/DELETE * @param : code, indicate failure code * @param : rule_report, structure contain affected rules * @return : Returns 0 on success,else 0 */ int provision_ack_ccr(pdn_connection *pdn, eps_bearer *bearer, enum rule_action_t rule_action, enum rule_failure_code code); typedef int(*rar_funtions)(pdn_connection *); /** * @brief : This function fills the csr in resp structure * @param : sess_id , session id. * @param : key, pointer of context_key structure. * @return : returns 0 on success. * * */ int fill_response(uint64_t sess_id, context_key *key); #endif extern association_context_t assoc_ctxt[NUM_DP] ; /** * @brief : Update cli statistics * @param : msg_type, msg for which cli stats to be updated * @return : Returns nothing */ void stats_update(uint8_t msg_type); /** * @brief : Fill pfcp session establishment response * @param : pfcp_sess_est_resp , structure to be filled * @param : cause , cause whether request is accepted or not * @param : offend , Offending ie type * @param : dp_comm_ip , ip address of dp * @param : pfcp_session_request, pfcp session establishment request data * @return : Returns nothing */ // void // fill_pfcp_session_est_resp(pfcp_sess_estab_rsp_t // *pfcp_sess_est_resp, uint8_t cause, int offend, // struct in_addr dp_comm_ip, // struct pfcp_sess_estab_req_t *pfcp_session_request); /** * @brief : Fill pfcp session delete response * @param : pfcp_sess_del_resp , structure to be filled * @param : cause , cause whether request is accepted or not * @param : offend , Offending ie type * @return : Returns nothing */ void fill_pfcp_sess_del_resp(pfcp_sess_del_rsp_t *pfcp_sess_del_resp, uint8_t cause, int offend); /** * @brief : Fill pfcp session modify response * @param : pfcp_sess_modify_resp , structure to be filled * @param : pfcp_session_mod_req , pfcp session modify request data * @param : cause , cause whether request is accepted or not * @param : offend , Offending ie type * @return : Returns nothing */ void fill_pfcp_session_modify_resp(pfcp_sess_mod_rsp_t *pfcp_sess_modify_resp, pfcp_sess_mod_req_t *pfcp_session_mod_req, uint8_t cause, int offend); #ifdef CP_BUILD /** * @brief : Fill pfcp session establishment request * @param : pfcp_sess_est_req , structure to be filled * @param : context , pointer to ue context structure * @param : ebi_index, index of bearer in array * @param : seq, sequence number of request * @param : resp, struct resp_info * @return : Returns nothing */ void fill_pfcp_sess_est_req( pfcp_sess_estab_req_t *pfcp_sess_est_req, pdn_connection *pdn, uint32_t seq, struct ue_context_t *context, struct resp_info *resp); /** * @brief : Checks and returns interface type if it access or core * @param : iface , interface type * @param : cp_type, cp type [SGWC/PGWC/SAEGWC]. * @retrun : Returns interface type in case of success , -1 otherwise */ int check_interface_type(uint8_t iface, uint8_t cp_type); /** * @brief : Fill pfcp session modification request * @param : pfcp_sess_mod_req , structure to be filled * @param : header, holds info in gtpv2c header * @param : bearer, pointer to bearer structure * @param : pdn , pdn information * @param : update_far , array of update far rules * @param : handover_flag , flag to check if it is handover scenario or not * @param : beaer_count , number of bearer to be modified. * @return : Returns nothing */ void fill_pfcp_sess_mod_req( pfcp_sess_mod_req_t *pfcp_sess_mod_req, gtpv2c_header_t *header, eps_bearer **bearers, pdn_connection *pdn, pfcp_update_far_ie_t update_far[], uint8_t handover_flag, uint8_t bearer_count, ue_context *context); /** * @brief : Add new PDRs in bearer as we recive a new rule to be add in existing bearer * @param : bearer , bearer to be modify * @param : prdef, signifies predefine or dynamic rule * @return : Returns nothing */ void add_pdr_qer_for_rule(eps_bearer *bearer, bool prdef_rule); /** * @brief : Fill pfcp session modification request for delete session request * @param : pfcp_sess_mod_req , structure to be filled * @param : pdn , pdn information * @param : action, action we will be taking either delete or create bearer * @param : resp , resp information * @return : Returns nothing */ void fill_pfcp_gx_sess_mod_req(pfcp_sess_mod_req_t *pfcp_sess_mod_req, pdn_connection *pdn, uint16_t action, struct resp_info *resp); /** * @brief : Create and Send pfcp session modification request for LI scenario * @param : imsi, imsi of ue * @return : Returns nothing */ void send_pfcp_sess_mod_req_for_li(uint64_t imsi); /** * @brief : update far ie as per li configurations * @param : imsi_id_config, imsi_id_hash_t * @param : context, ue_context * @param : far, far ie * @return : Returns -1 in case of error */ int update_li_info_in_upd_dup_params(imsi_id_hash_t *imsi_id_config, ue_context *context, pfcp_update_far_ie_t *far); /** * @brief : create far ie as per li configurations * @param : imsi_id_config, imsi_id_hash_t * @param : context, ue_context * @param : far, far ie * @return : Returns -1 in case of error */ int update_li_info_in_dup_params(imsi_id_hash_t *imsi_id_config, ue_context *context, pfcp_create_far_ie_t *far); /** * @brief : fill li policy using li_df_config_t * @param : li_policy, user plane li policies * @param : li_config, li df config * @param : cp_mode, control plane mode * @return : Returns li policy length */ uint8_t fill_li_policy(uint8_t *li_policy, li_df_config_t *li_config, uint8_t cp_mode); /** * @brief : Fill pfcp session modification request for handover scenario * @param : pfcp_sess_mod_req , structure to be filled * @param : header, holds info in gtpv2c header * @param : pdn , pdn information * @return : Returns nothing */ void fill_pfcp_sess_mod_req_delete(pfcp_sess_mod_req_t *pfcp_sess_mod_req, pdn_connection *pdn, eps_bearer *bearers[], uint8_t bearer_cntr); /** * @brief : Fill pfcp session modification request for delete bearer scenario * to fill remove_pdr ie * @param : pfcp_sess_mod_req , structure to be filled * @param : pdn , pdn information * @param : bearers, pointer to bearer structure * @param : bearer_cntr , number of bearer to be modified. * @return : Returns nothing */ void fill_pfcp_sess_mod_req_with_remove_pdr(pfcp_sess_mod_req_t *pfcp_sess_mod_req, pdn_connection *pdn, eps_bearer *bearers[], uint8_t bearer_cntr); /** * @brief : Fill pfcp session modification request for delete bearer scenario * to fill remove_pdr ie * @param : pfcp_sess_mod_req , structure to be filled * @param : pdn , pdn information * @param : bearers, pointer to bearer structure * @param : bearer_cntr , number of bearer to be modified. * @return : Returns nothing */ void fill_pfcp_sess_mod_req_pgw_init_remove_pdr(pfcp_sess_mod_req_t *pfcp_sess_mod_req, pdn_connection *pdn, eps_bearer *bearers[], uint8_t bearer_cntr); /** * @brief : Process pfcp session establishment response * @param : pfcp_sess_est_rsp, structure to be filled * @param : gtpv2c_tx, holds info in gtpv2c header * @param : is_piggybacked flag to indicate whether message is to piggybacked. * @retrun : Returns 0 in case of success */ int8_t process_pfcp_sess_est_resp(pfcp_sess_estab_rsp_t *pfcp_sess_est_rsp, gtpv2c_header_t *gtpv2c_tx, uint8_t is_piggybacked); /** * @brief : Process pfcp session modification response for handover scenario * @param : sess_id, session id * @param : gtpv2c_tx, holds info in gtpv2c header * @param : context, ue context * @retrun : Returns 0 in case of success */ uint8_t process_pfcp_sess_mod_resp_handover(uint64_t sess_id, gtpv2c_header_t *gtpv2c_tx, ue_context *context); /** * @brief : Process pfcp session modification response * @param : sess_id, session id * @param : gtpv2c_tx, holds info in gtpv2c header * @param : resp, resp_info for that sx session * @param : context, UE context for user * @retrun : Returns 0 in case of success */ uint8_t process_pfcp_sess_mod_resp(pfcp_sess_mod_rsp_t *pfcp_sess_mod_rsp, gtpv2c_header_t *gtpv2c_tx, ue_context *context, struct resp_info *resp); /** * @brief : Process pfcp session modification response for modification procedure * @param : sess_id, session id * @param : gtpv2c_tx, holds info in gtpv2c header * @param : is_handover, indicates if it is handover scenario or not * @retrun : Returns 0 in case of success */ uint8_t process_pfcp_sess_mod_resp_for_mod_proc(uint64_t sess_id, gtpv2c_header_t *gtpv2c_tx); /** * @brief : Process pfcp session modification response * @param : sess_id, session id * @retrun : Returns 0 in case of success */ uint8_t process_pfcp_sess_upd_mod_resp(pfcp_sess_mod_rsp_t *pfcp_sess_mod_rsp); /** * @brief : Process pfcp session modification response for delete bearer scenario * @param : sess_id, session id * @param : context, structure for context information * @param : gtpv2c_tx, buffer to hold incoming data * @param : resp, structure for response information * @retrun : Returns 0 in case of success */ uint8_t process_delete_bearer_pfcp_sess_response(uint64_t sess_id, ue_context *context, gtpv2c_header_t *gtpv2c_tx, struct resp_info *resp); /** * @brief : Process pfcp session modification request for delete bearer scenario * @param : pdn, details of pdn connection * @retrun : Returns 0 in case of success, -1 otherwise */ int process_sess_mod_req_del_cmd(pdn_connection *pdn); /** * @brief : Process pfcp session modification response * in case of attach with dedicated flow * @param : sess_id, session id * @param : gtpv2c_tx, holds info in gtpv2c header * @param : resp, response structure information * @retrun : Returns 0 in case of success */ int process_pfcp_sess_mod_resp_cs_cbr_request(uint64_t sess_id, gtpv2c_header_t *gtpv2c_tx, struct resp_info *resp); /** * @brief : Fill pdr entry * @param : context , pointer to ue context structure * @param : pdn , pdn information * @param : bearer, pointer to bearer structure * @param : iface , interface type access or core * @param : itr, index in pdr array stored in bearer context * @retrun : Returns 0 in case of success , -1 otherwise */ pdr_t* fill_pdr_entry(ue_context *context, pdn_connection *pdn, eps_bearer *bearer, uint8_t iface, uint8_t itr); /** * @brief : Process Modify bearer command * @param : mod_bearer_cmd, modify bearer command structure * @param : gtpv2c_tx, holds info in gtpv2c header * @param : context, structure for context information * @return : Returns 0 in case of success , -1 otherwise */ int process_modify_bearer_cmd(mod_bearer_cmd_t *mod_bearer_cmd, gtpv2c_header_t *gtpv2c_tx, ue_context *context); /** * @brief : Process delete bearer command request * @param : del_bearer_cmd, delete bearer command structure * @param : gtpv2c_tx, holds info in gtpv2c header * @param : context, structure for context information * @return : Returns 0 in case of success , -1 otherwise */ int process_delete_bearer_cmd_request(del_bearer_cmd_t *del_bearer_cmd, gtpv2c_header_t *gtpv2c_tx, ue_context *context); /** * @brief : Process bearer bearer resource command request * @param : bearer_rsrc_cmd * @param : gtpv2c_tx * @param : context, pointer to the ue context * @return : Returns 0 in case of success , -1 otherwise */ int process_bearer_rsrc_cmd(bearer_rsrc_cmd_t *bearer_rsrc_cmd, gtpv2c_header_t *gtpv2c_tx, ue_context *context); /** * @brief : Fill pfcp entry * @param : bearer, pointer to bearer structure * @param : dyn_rule, rule information * @param : rule_action * @retrun : Returns 0 in case of success , -1 otherwise */ int fill_pfcp_entry(eps_bearer *bearer, dynamic_rule_t *dyn_rule); /** * @brief : Fill SDF and QER of PDR using dyn_rule * @param : pdr_ctxt , pdr_ctxt whose SDF and QER to be fill * @param : dyn_rule, The QER and SDF from dynamic rule should fill * @retrun : Returns 0 in case of success , -1 otherwise */ void fill_pdr_sdf_qer(pdr_t *pdr_ctxt, dynamic_rule_t *dyn_rule); /** * @brief : Fill qer entry * @param : pdn , pdn information * @param : bearer, pointer to bearer structure * @param : dyn_rule, rule information * @param : rule_action * @retrun : Returns 0 in case of success , -1 otherwise */ int fill_qer_entry(pdn_connection *pdn, eps_bearer *bearer,uint8_t itr); /** * @brief : Process pfcp delete session response * @param : sess_id, session id * @param : gtpv2c_tx, holds info in gtpv2c header * @param : ccr_request, structure to be filled for ccr request * @param : msglen, total length * @param : ue_context * @retrun : Returns 0 in case of success */ int8_t process_pfcp_sess_del_resp(uint64_t sess_id, gtpv2c_header_t *gtpv2c_tx, gx_msg *ccr_request, uint16_t *msglen, ue_context *context); /** * @brief : function to proces delete session request on SGWC * @param : ds_rsp, holds information in delete session request * @retrun : Returns 0 in case of success , -1 otherwise */ int process_sgwc_s5s8_delete_session_request(del_sess_rsp_t *ds_rsp); /** * @brief : Delete all pdr, far, qer entry from table * @param : ebi_index, index of bearer in array * @param : pdn , pointer to pdn connection structure * @retrun : Returns 0 in case of success , -1 otherwise */ int del_rule_entries(pdn_connection *pdn, int ebi_index); /** * @brief : Delete dedicated bearers entry * @param : pdn , pdn information * @param : bearer_ids, array of bearer ids * @param : bearer_cntr , number of bearer to be modified. * @retrun : Returns 0 in case of success , -1 otherwise */ int delete_dedicated_bearers(pdn_connection *pdn, uint8_t bearer_ids[], uint8_t bearer_cntr); /** * @brief : Generate string using sdf packet filters * @param : sdf_flow , sdf packect filter info * @param : sdf_str , string to store output * @param : direction, data flow direction * @return : Returns nothing */ void sdf_pkt_filter_to_string(sdf_pkt_fltr *sdf_flow, char *sdf_str,uint8_t direction); /** * @brief : Fill sdf packet filters in pfcp session establishment request * @param : pfcp_sess_est_req, structure to be filled * @param : bearer, pointer to bearer structure * @param : pdr_counter , index to pdr * @param : sdf_filter_count * @param : dynamic_filter_cnt * @param : flow_cnt * @param : direction, data flow direction * @return : Returns nothing */ int sdf_pkt_filter_add(pfcp_pdi_ie_t* pdi, dynamic_rule_t *dynamic_rules, int sdf_filter_count, int flow_cnt, uint8_t direction); /** * @brief : Fill sdf rules in pfcp session establishment request * @param : pfcp_sess_est_req, structure to be filled * @param : bearer, pointer to bearer structure * @param : pdr_counter , index to pdr * @retrun : Returns 0 in case of success , -1 otherwise */ int fill_create_pdr_sdf_rules(pfcp_create_pdr_ie_t *create_pdr, dynamic_rule_t *dynamic_rules, int pdr_counter); /** * @brief : Fill pdr , far and qer in pfcp session mod request from bearer * @param : pfcp_sess_mod_req, structure to be filled * @param : bearer, pointer to bearer structure * @return : Returns nothing */ void fill_pdr_far_qer_using_bearer(pfcp_sess_mod_req_t *pfcp_sess_mod_req, eps_bearer *bearer, ue_context *context, uint8_t create_pdr_counter); /** * @brief : Fill dedicated bearer information * @param : bearer, pointer to bearer structure * @param : context , pointer to ue context structure * @param : pdn , pointer to pdn connection structure * @param : prdef_rule, specify its a predef rule or not * @retrun : Returns 0 in case of success , -1 otherwise */ int fill_dedicated_bearer_info(eps_bearer *bearer, ue_context *context, pdn_connection *pdn, bool prdef_rule); /* @brief : Free dynamically allocated memory in ccr request * @param : ccr_request, ptr to ccr msg structure in which * : memory is allocated. * @return : nothing. */ void free_dynamically_alloc_memory(gx_msg *ccr_request); /** * @brief : Fill gate status in pfcp session establishment request * @param : pfcp_sess_est_req , structure to be filled * @param : qer_counter , qer rule index * @param : f_status , flow status * @return : Returns nothing */ void fill_gate_status(pfcp_sess_estab_req_t *pfcp_sess_est_req,int qer_counter,enum flow_status f_status); /** * @brief : Get bearer information * @param : pdn , pointer to pdn connection structure * @param : qos, qos information * @retrun : Returns bearer structure pointer in case of success , NULL otherwise */ eps_bearer * get_bearer(pdn_connection *pdn, bearer_qos_ie *qos); /** * @brief : Get dedicated bearer information * @param : pdn , pointer to pdn connection structure * @retrun : Returns bearer structure pointer in case of success , NULL otherwise */ eps_bearer * get_default_bearer(pdn_connection *pdn); /** * @brief : Fill create pfcp information * @param : pfcp_sess_mod_req, structure to be filled * @param : dyn_rule, rule information * @param : context , pointer to ue context structure * @param : gen_cdr, boolean value for generation of CDR * @retrun : Returns 0 in case of success , -1 otherwise */ int fill_create_pfcp_info(pfcp_sess_mod_req_t *pfcp_sess_mod_req, dynamic_rule_t *dyn_rule, ue_context *context, uint8_t gen_cdr); /** * @brief : Fill update pfcp information * @param : pfcp_sess_mod_req, structure to be filled * @param : dyn_rule, rule information * @retrun : Returns 0 in case of success , -1 otherwise */ int fill_update_pfcp_info(pfcp_sess_mod_req_t *pfcp_sess_mod_req, dynamic_rule_t *dyn_rule, ue_context *contex); /** * @brief : Return a Function Pointer on basis of action to be taken on * rule received in RAR request * @param : pdn, pdn structure * @param : proc, procedure from which the function being called * @retrun : Returns function pointer in success , NULL otherwise */ rar_funtions rar_process(pdn_connection *pdn, uint8_t proc); /** * @brief : Generate reauth response * @param : context , pointer to ue context structure * @param : ebi_index, index in array where eps bearer is stored * @return : Returns 0 in case of success , -1 otherwise */ int gen_reauth_response(pdn_connection *pdn); /** * @brief : Fill remove pfcp information * @param : pfcp_sess_mod_req, structure to be filled * @param : bearer, bearer information * @retrun : Returns 0 in case of success , -1 otherwise */ int fill_remove_pfcp_info(pfcp_sess_mod_req_t *pfcp_sess_mod_req, eps_bearer *bearer); /** * @brief : check if bearer index free or not * @param : context, ue context * @param : ebi_index, index which needs to be search * @retrun : Returns 0 in case of success , -1 otherwise */ int8_t check_if_bearer_index_free(ue_context *context, int ebi_index); /** * @brief : Create new bearer id * @param : pdn_cntxt, pdn connection information * @retrun : Returns bearer_id in case of success , -1 otherwise */ int8_t get_new_bearer_id(pdn_connection *pdn_cntxt); /** * @brief : Process pfcp sess setup for establish session * @param : pdn, pdn connection information * @retrun : Returns 0 in case of success , -1 otherwise */ int process_pfcp_sess_setup(pdn_connection *pdn); /** * @brief : Process the recieved FQCSID * @param : pdn, pdn connection information * @param : bearer, bearer information * @param : context, ue context * @retrun : Returns 0 in case of success , -1 otherwise */ int8_t gtpc_recvd_sgw_fqcsid(gtp_fqcsid_ie_t *sgw_fqcsid, pdn_connection *pdn, eps_bearer *bearer, ue_context *context); #else #endif /* CP_BUILD */ /** * @brief : Fill pfcp duplicating paramers IE of create FAR * @param : dup_params , structure to be filled * @param : li_policy, User Level Packet Copying Policy array * @param : li_policy_len, User Level Packet Copying Policy array length * @return : Returns 0 for success and -1 for failure */ uint16_t fill_dup_param(pfcp_dupng_parms_ie_t *dup_params, uint8_t li_policy[], uint8_t li_policy_len); /** * @brief : Fill pfcp duplicating paramers IE of update FAR * @param : dup_params , structure to be filled * @param : li_policy, User Level Packet Copying Policy array * @param : li_policy_len, User Level Packet Copying Policy array length * @return : Returns 0 for success and -1 for failure */ uint16_t fill_upd_dup_param(pfcp_upd_dupng_parms_ie_t *dup_params, uint8_t li_policy[], uint8_t li_policy_len); /** * @brief : Fill pfcp session delete request * @param : pfcp_sess_del_req , structure to be filled * @param : cp_type, [SGWC/SAEGWC/PGWC] * @return : Returns nothing */ void fill_pfcp_sess_del_req( pfcp_sess_del_req_t *pfcp_sess_del_req, uint8_t cp_type); #ifdef CP_BUILD /** * @brief : Update ue context information * @param : mb_req, buffer which contains incoming request data, ue context * @retrun : Returns 0 in case of success , -1 otherwise */ int8_t update_ue_context(mod_bearer_req_t *mb_req, ue_context *context, eps_bearer *bearer, pdn_connection *pdn); /** * @brief : Delete QER from bearer array * @param : Bearer whose QER to be deleted * @param : qer_id_value, QER id which is to be deleted * @retrun : Returns nothing */ void remove_qer_from_bearer(eps_bearer *bearer, uint16_t qer_id_value); /** * @brief : Delete PDR from bearer array * @param : bearer, Bearer whose PDR to be deleted * @param : pdr_id_value, PDR id which is to be deleted * @retrun : Returns nothing */ void remove_pdr_from_bearer(eps_bearer *bearer, uint16_t pdr_id_value); /** * @brief : Delete PDR entery and corresponding QER entery * @param : bearer, Bearer whose PDR and QER to be deleted * @param : pdr_id_value, PDR id which is to be deleted * @retrun : Returns nothing */ int delete_pdr_qer_for_rule(eps_bearer *bearer, uint16_t pdr_id_value); /** * @brief : Fill ue context info from incoming data in create sess request * @param : csr holds data in csr * @param : context , pointer to ue context structure * @return : Returns 0 in case of success , -1 otherwise */ int fill_context_info(create_sess_req_t *csr, ue_context *context, pdn_connection *pdn); /** * @brief : Fill pdn info from data in incoming csr * * @param : csr holds data in csr * @param : pdn , pointer to pdn connction structure * @return : Returns 0 in case of success , -1 otherwise */ int fill_pdn_info(create_sess_req_t *csr, pdn_connection *pdn, ue_context *context, eps_bearer *bearer); /** * @brief : Fill update pdr information * @param : pfcp_sess_mod_req, structure to be filled * @param : bearer, bearer information * @retrun : Returns nothing * */ void fill_update_bearer_sess_mod(pfcp_sess_mod_req_t *pfcp_sess_mod_req, eps_bearer *bearer); /** * @brief : Fill update pdr information * @param : pfcp_sess_mod_req, structure to be filled * @param : bearer, bearer information * @param : cp_type, [SWGC/SAEGWC/PGWC] * @retrun : Returns nothing */ void fill_update_pdr(pfcp_sess_mod_req_t *pfcp_sess_mod_req, eps_bearer *bearer, uint8_t cp_type); /** * @brief : Fill update pdr information * @param : update_pdr, structure to be filled * @param : dyn_rule, dynamic rule information * @param : pdr_counter, No of PDR * @retrun : Returns 0 in case of success , -1 otherwise */ int fill_update_pdr_sdf_rule(pfcp_update_pdr_ie_t* update_pdr, dynamic_rule_t *dyn_rule, int pdr_counter); /* @brief : clear the resp_info struct information * @param : resp, pointer to resp_info structure needs to be cleaned up * @return : Returns nothing * */ void reset_resp_info_structure(struct resp_info *resp); /** * @brief : Parse handover CSR request on Combined GW * @param : csr holds data in csr * @param : Context, pointer to UE context structure * @param : CP_TYPE: changed gateway type, promotion PGWC --> SAEGWC * @return : Returns 0 in case of success , -1 otherwise */ int8_t promotion_parse_cs_req(create_sess_req_t *csr, ue_context *context, uint8_t cp_type); /** * @brief : Send the PFCP Session Modification Request after promotion * @param : Context, pointer to UE context structure * @param : bearer, bearer to be deleted. * @param : pdn , pointer to pdn connection structure * @param : csr holds data in csr * @param : ebi_index, bearer identifier * @return : Returns 0 in case of success , -1 otherwise */ int8_t send_pfcp_modification_req(ue_context *context, pdn_connection *pdn, eps_bearer *bearer, create_sess_req_t *csr, uint8_t ebi_index); /** * @brief : processes indirect tunnel request * @param : create_indir_req, create indirect data forwarding request * @param : context, ue_context * @retrun : Returns 0 in case of success , -1 otherwise */ int process_create_indir_data_frwd_tun_request(create_indir_data_fwdng_tunn_req_t *create_indir_req, ue_context **_context); /** * @brief : processes deleete indirect tunnel request * @param : delete_indir_tunnel_req * @retrun : Returns 0 in case of success , -1 otherwise */ int process_del_indirect_tunnel_request(del_indir_data_fwdng_tunn_req_t *del_indir_req); /** * @brief : Process pfcp delete session response for delete * indirect tunnel request * @param : sess_id, session id * @param : gtpv2c_tx, holds info in gtpv2c header * @param : msglen, total length * @param : uiImsi, for lawful interception * @param : li_sock_fd for lawful interception * @retrun : Returns 0 in case of success */ int process_pfcp_sess_del_resp_indirect_tunnel(uint64_t sess_id, gtpv2c_header_t *gtpv2c_tx, uint64_t *uiImsi, int *li_sock_fd); /* @brief : Check presense of LBI in ue context * @param : bearer_id,bearer id receive in LBI of BRC * @param : context, pointer to ue_context structure * @return : Returns 0 on success, else -1 * */ int check_default_bearer_id_presence_in_ue(uint8_t bearer_id, ue_context *context); /* @brief : Check presense of LBI in ue context * @param : bearer_id,bearer id receive in LBI of BRC * @param : context, pointer to ue_context structure * @return : Returns 0 on success, else -1 * */ int check_ebi_presence_in_ue(uint8_t bearer_id, ue_context *context); /* @brief : Store rule name & status for Delete bearer cmd * @param : pro_ack_rule_array, array to store rule name & status * @param : bearer, bearer to be deleted. * @return : Returns 0 on success, else -1 * */ int store_rule_status_for_del_bearer_cmd(pro_ack_rule_array_t *pro_ack_rule_array, eps_bearer *bearer); /* @brief : update the pdr actions flags * @param : bearer, bearer for modify pdr actions flags * @return : Nothing * */ void update_pdr_actions_flags(eps_bearer *bearer); /* @brief : set CCR_t message to send to PCRF * @param : pdn; PDN * @param : Context; context * @param : ccr_request ; ccr_message structure * @param : ebi_index, where bearer is stored * @return : 0 if success otherwise error cause * */ int set_ccr_t_message(pdn_connection *pdn, ue_context *context, gx_msg *ccr_request, int ebi_index); /* @brief : compare the arp values with all the PDN bearers * @param : def_bearer; default bearer * @param : pdn; PDN * @return : nothing * */ void compare_arp_value(eps_bearer *def_bearer, pdn_connection *pdn); /* @brief : copy Ip address for IPV4 and IPV6 * @param : node_value; destination * @param : node; source * @return : returns -1 if IP is not set, otherwise 0 * */ int set_address(node_address_t *node_value, node_address_t *node); /* @brief : copy Ip address for IPV4 and IPV6 * @param : src_addr; Src address(copy from) * @param : dst_addr; destibnation addres(copy to) * @return : returns -1 if IP is not stored, otherwise 0 * */ int set_dest_address(node_address_t src_addr, peer_addr_t *dst_addr); /* @brief : Send pfcp del session req. if pfcp sess report req failed * @param : sess_id, session ID. * @param : peer_addr, destibnation addres. * @return : returns -1 if IP is not stored, otherwise 0 * */ int send_pfcp_del_sess_req(uint64_t sess_id, peer_addr_t *peer_addr); /* @brief : delete the buffered ddn request from hash * @param : sess_id, session id * @return : returns pdr_ids pointer on success, oterwise NULL * */ pdr_ids * delete_buff_ddn_req(uint64_t sess_id); #endif /* CP_BUILD */ #endif /* PFCP_SESSION_H */
nikhilc149/e-utran-features-bug-fixes
cp/restoration_peer.c
<filename>cp/restoration_peer.c /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <signal.h> #include "cp.h" #include "main.h" #include "pfcp_messages/pfcp_set_ie.h" #include "cp_stats.h" #include "cp_config.h" #include "gw_adapter.h" #include "sm_struct.h" #include "pfcp_util.h" #include "ngic_timer.h" char filename[256] = "../config/cp_rstCnt.txt"; extern socklen_t s11_mme_sockaddr_len; extern socklen_t s11_mme_sockaddr_ipv6_len; extern socklen_t s5s8_sockaddr_len; extern socklen_t s5s8_sockaddr_ipv6_len; extern int s11_fd; extern int s11_fd_v6; extern int s5s8_fd; extern int s5s8_fd_v6; extern pfcp_config_t config; extern int clSystemLog; extern uint8_t rstCnt; int32_t conn_cnt = 0; /* Sequence number allocation for echo request */ static uint16_t gtpu_mme_seqnb = 0; static uint16_t gtpu_sgwc_seqnb = 0; static uint16_t gtpu_pgwc_seqnb = 0; static uint16_t gtpu_sx_seqnb = 1; /** * @brief : Connection hash params. */ static struct rte_hash_parameters conn_hash_params = { .name = "CONN_TABLE", .entries = NUM_CONN, .reserved = 0, .key_len = sizeof(node_address_t), .hash_func = rte_jhash, .hash_func_init_val = 0 }; /** * rte hash handler. * * hash handles connection for S1U, SGI and PFCP */ struct rte_hash *conn_hash_handle; uint8_t update_rstCnt(void) { FILE *fp; int tmp; if ((fp = fopen(filename,"rw+")) == NULL){ if ((fp = fopen(filename,"w")) == NULL) clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"Error! creating cp_rstCnt.txt file", LOG_VALUE); } if (fscanf(fp,"%u", &tmp) < 0) { /* Cur pos shift to initial pos */ fseek(fp, 0, SEEK_SET); fprintf(fp, "%u\n", ++rstCnt); fclose(fp); return rstCnt; } /* Cur pos shift to initial pos */ fseek(fp, 0, SEEK_SET); rstCnt = tmp; fprintf(fp, "%d\n", ++rstCnt); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Updated restart counter Value of rstcnt=%u\n",LOG_VALUE, rstCnt); fclose(fp); return rstCnt; } void timerCallback( gstimerinfo_t *ti, const void *data_t ) { uint16_t payload_length; peer_addr_t dest_addr; peer_address_t addr; #pragma GCC diagnostic push /* require GCC 4.6 */ #pragma GCC diagnostic ignored "-Wcast-qual" peerData *md = (peerData*)data_t; #pragma GCC diagnostic pop /* require GCC 4.6 */ if (md->dstIP.ip_type == PDN_TYPE_IPV4) { /* setting sendto destination addr */ dest_addr.type = PDN_TYPE_IPV4; dest_addr.ipv4.sin_addr.s_addr = md->dstIP.ipv4_addr; dest_addr.ipv4.sin_family = AF_INET; dest_addr.ipv4.sin_port = htons(GTPC_UDP_PORT); addr.ipv4.sin_addr.s_addr = md->dstIP.ipv4_addr; addr.type = IPV4_TYPE; } else { /* setting sendto destination addr */ memcpy(&dest_addr.ipv6.sin6_addr.s6_addr, &md->dstIP.ipv6_addr, IPV6_ADDRESS_LEN); dest_addr.type = PDN_TYPE_IPV6; dest_addr.ipv6.sin6_family = AF_INET6; dest_addr.ipv6.sin6_port = htons(GTPC_UDP_PORT); memcpy(&addr.ipv6.sin6_addr.s6_addr, &md->dstIP.ipv6_addr, IPV6_ADDRESS_LEN); addr.type = IPV6_TYPE; } md->itr = config.transmit_cnt; (md->dstIP.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, "%s - %s:"IPv6_FMT":%u.%s (%dms) has expired\n", getPrintableTime(), md->name, IPv6_PRINT(IPv6_CAST(md->dstIP.ipv6_addr)), md->portId, ti == &md->pt ? "Periodic_Timer" : ti == &md->tt ? "Transmit_Timer" : "unknown", ti->ti_ms ): clLog(clSystemLog, eCLSeverityDebug, "%s - %s:%s:%u.%s (%dms) has expired\n", getPrintableTime(), md->name, inet_ntoa(*(struct in_addr *)&md->dstIP.ipv4_addr), md->portId, ti == &md->pt ? "Periodic_Timer" : ti == &md->tt ? "Transmit_Timer" : "unknown", ti->ti_ms ); if (md->itr_cnt == md->itr) { /* Stop transmit timer for specific Peer Node */ stopTimer( &md->tt ); /* Stop periodic timer for specific Peer Node */ stopTimer( &md->pt ); /* Deinit transmit timer for specific Peer Node */ deinitTimer( &md->tt ); /* Deinit transmit timer for specific Peer Node */ deinitTimer( &md->pt ); (md->dstIP.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Stopped Periodic/transmit timer, peer ipv6 node:port "IPv6_FMT":%u is not reachable\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(md->dstIP.ipv6_addr)), md->portId): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Stopped Periodic/transmit timer, peer ipv4 node:port %s:%u is not reachable\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&md->dstIP.ipv4_addr), md->portId); update_peer_status(&addr, FALSE); delete_cli_peer(&addr); if (md->portId == S11_SGW_PORT_ID) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"MME status : Inactive\n", LOG_VALUE); } if (md->portId == SX_PORT_ID) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" SGWU/SPGWU/PGWU status : Inactive\n", LOG_VALUE); } if (md->portId == S5S8_SGWC_PORT_ID) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"PGWC status : Inactive\n", LOG_VALUE); } if (md->portId == S5S8_PGWC_PORT_ID) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"SGWC status : Inactive\n", LOG_VALUE); } /* TODO: Flush sessions */ if (md->portId == SX_PORT_ID) { delete_entry_heartbeat_hash(&md->dstIP); #ifdef USE_CSID del_peer_node_sess(&md->dstIP, SX_PORT_ID); #endif /* USE_CSID */ } /* Flush sessions */ if (md->portId == S11_SGW_PORT_ID) { #ifdef USE_CSID del_pfcp_peer_node_sess(&md->dstIP, S11_SGW_PORT_ID); /* TODO: Need to Check */ del_peer_node_sess(&md->dstIP, S11_SGW_PORT_ID); #endif /* USE_CSID */ } /* Flush sessions */ if (md->portId == S5S8_SGWC_PORT_ID) { #ifdef USE_CSID del_pfcp_peer_node_sess(&md->dstIP, S5S8_SGWC_PORT_ID); del_peer_node_sess(&md->dstIP, S5S8_SGWC_PORT_ID); #endif /* USE_CSID */ } /* Flush sessions */ if (md->portId == S5S8_PGWC_PORT_ID) { #ifdef USE_CSID del_pfcp_peer_node_sess(&md->dstIP, S5S8_PGWC_PORT_ID); del_peer_node_sess(&md->dstIP, S5S8_PGWC_PORT_ID); #endif /* USE_CSID */ } del_entry_from_hash(&md->dstIP); if (md->portId == S11_SGW_PORT_ID || md->portId == S5S8_SGWC_PORT_ID) { (md->dstIP.ip_type == IPV6_TYPE) ? printf("CP: Peer node IPv6:PortId "IPv6_FMT":%u is not reachable\n", IPv6_PRINT(IPv6_CAST(md->dstIP.ipv6_addr)), md->portId): printf("CP: Peer node IPv4:PortId %s:%u is not reachable\n", inet_ntoa(*(struct in_addr *)&md->dstIP.ipv4_addr), md->portId); } else { (md->dstIP.ip_type == IPV6_TYPE) ? printf("CP: Peer node IPv6:PortId "IPv6_FMT":%u is not reachable\n", IPv6_PRINT(IPv6_CAST(md->dstIP.ipv6_addr)), md->portId): printf("CP: Peer node IPv4:PortId %s:%u is not reachable\n", inet_ntoa(*(struct in_addr *)&md->dstIP.ipv4_addr), md->portId); } return; } bzero(&echo_tx_buf, sizeof(echo_tx_buf)); gtpv2c_header_t *gtpv2c_tx = (gtpv2c_header_t *) echo_tx_buf; if (md->portId == S11_SGW_PORT_ID) { if (ti == &md->pt) gtpu_mme_seqnb++; build_gtpv2_echo_request(gtpv2c_tx, gtpu_mme_seqnb, S11_SGW_PORT_ID); } else if (md->portId == S5S8_SGWC_PORT_ID) { if (ti == &md->pt) gtpu_sgwc_seqnb++; build_gtpv2_echo_request(gtpv2c_tx, gtpu_sgwc_seqnb, S5S8_SGWC_PORT_ID); } else if (md->portId == S5S8_PGWC_PORT_ID) { if (ti == &md->pt) gtpu_pgwc_seqnb++; build_gtpv2_echo_request(gtpv2c_tx, gtpu_pgwc_seqnb, S5S8_PGWC_PORT_ID); } payload_length = ntohs(gtpv2c_tx->gtpc.message_len) + sizeof(gtpv2c_tx->gtpc); if (md->portId == S11_SGW_PORT_ID) { gtpv2c_send(s11_fd, s11_fd_v6, echo_tx_buf, payload_length, dest_addr, SENT); if (ti == &md->tt) { (md->itr_cnt)++; } } else if (md->portId == S5S8_SGWC_PORT_ID) { gtpv2c_send(s5s8_fd, s5s8_fd_v6, echo_tx_buf, payload_length, dest_addr, SENT); if (ti == &md->tt) { (md->itr_cnt)++; } } else if (md->portId == S5S8_PGWC_PORT_ID) { gtpv2c_send(s5s8_fd, s5s8_fd_v6, echo_tx_buf, payload_length, dest_addr, SENT); if (ti == &md->tt) { (md->itr_cnt)++; } } else if (md->portId == SX_PORT_ID) { /* TODO: Defined this part after merging sx heartbeat*/ /* process_pfcp_heartbeat_req(md->dst_ip, up_time); */ /* TODO: Future Enhancement */ /* Setting PFCP Port ID */ if (dest_addr.type == IPV6_TYPE) { dest_addr.ipv6.sin6_port = htons(config.pfcp_port); } else { dest_addr.ipv4.sin_port = htons(config.pfcp_port); } if (ti == &md->pt){ gtpu_sx_seqnb = get_pfcp_sequence_number(PFCP_HEARTBEAT_REQUEST, gtpu_sx_seqnb);; } process_pfcp_heartbeat_req(dest_addr, gtpu_sx_seqnb); if (ti == &md->tt) { (md->itr_cnt)++; } } if(ti == &md->tt) { update_peer_timeouts(&addr, md->itr_cnt); } if (ti == &md->pt) { if ( startTimer( &md->tt ) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Transmit Timer failed to start..\n", LOG_VALUE); } /* Stop periodic timer for specific Peer Node */ stopTimer( &md->pt ); } return; } uint8_t add_node_conn_entry(node_address_t *dstIp, uint8_t portId, uint8_t cp_mode) { int ret; peerData *conn_data = NULL; /* Validate the IP Type*/ if ((dstIp->ip_type != PDN_TYPE_IPV4) && (dstIp->ip_type != PDN_TYPE_IPV6)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ERR: Not setting appropriate IP Type(IPv4:1 or IPv6:2)," "IP_TYPE:%u\n", LOG_VALUE, dstIp->ip_type); return -1; } ret = rte_hash_lookup_data(conn_hash_handle, dstIp, (void **)&conn_data); if ( ret < 0) { (dstIp->ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Add entry in conn table for IPv6:"IPv6_FMT", portId:%u\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(dstIp->ipv6_addr)), portId): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Add entry in conn table for IPv4:%s, portId:%u\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&dstIp->ipv4_addr)), portId); /* No conn entry for dstIp * Add conn_data for dstIp at * conn_hash_handle * */ conn_data = rte_malloc_socket(NULL, sizeof(peerData), RTE_CACHE_LINE_SIZE, rte_socket_id()); conn_data->portId = portId; conn_data->activityFlag = 0; conn_data->itr = config.transmit_cnt; conn_data->itr_cnt = 0; conn_data->rcv_time = 0; conn_data->cp_mode = cp_mode; memcpy(&conn_data->dstIP, dstIp, sizeof(node_address_t)); /* Add peer node entry in connection hash table */ if ((rte_hash_add_key_data(conn_hash_handle, dstIp, conn_data)) < 0 ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry in hash table",LOG_VALUE); } if ( !initpeerData( conn_data, "PEER_NODE", (config.periodic_timer * 1000), (config.transmit_timer * 1000)) ) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"%s - initialization of %s failed\n", LOG_VALUE, getPrintableTime(), conn_data->name ); return -1; } peer_address_t addr; /*CLI: when add node conn entry called then always peer status will be true*/ if (dstIp->ip_type == IPV4_TYPE) { addr.ipv4.sin_addr.s_addr = dstIp->ipv4_addr; addr.type = IPV4_TYPE; } else { memcpy(&addr.ipv6.sin6_addr.s6_addr, dstIp->ipv6_addr, IPV6_ADDR_LEN); addr.type = IPV6_TYPE; } update_peer_status(&addr, TRUE); if ( startTimer( &conn_data->pt ) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Periodic Timer failed to start...\n", LOG_VALUE); } conn_cnt++; } else { /* TODO: peer node entry already exit in conn table */ (dstIp->ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Conn entry already exit in conn table for IPv6:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(dstIp->ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Conn entry already exit in conn table for IPv4:%s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&dstIp->ipv4_addr))); if ( startTimer( &conn_data->pt ) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Periodic Timer failed to start...\n", LOG_VALUE); } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Current Active Conn Cnt:%u\n", LOG_VALUE, conn_cnt); return 0; } void echo_table_init(void) { /* Create conn_hash for maintain each port peer connection details */ /* Create arp_hash for each port */ conn_hash_params.socket_id = rte_socket_id(); conn_hash_handle = rte_hash_create(&conn_hash_params); if (!conn_hash_handle) { rte_panic("%s::" "\n\thash create failed::" "\n\trte_strerror= %s; rte_errno= %u\n", conn_hash_params.name, rte_strerror(rte_errno), rte_errno); } return; } void rest_thread_init(void) { echo_table_init(); sigset_t sigset; /* mask SIGALRM in all threads by default */ sigemptyset(&sigset); sigaddset(&sigset, SIGRTMIN + 1); sigaddset(&sigset, SIGUSR1); sigprocmask(SIG_BLOCK, &sigset, NULL); if (!gst_init()) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"%s - gstimer_init() failed!!\n", LOG_VALUE, getPrintableTime() ); } return; }
nikhilc149/e-utran-features-bug-fixes
cp/gx_app/src/gx_app.c
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "cp_app.h" #include "ipc_api.h" #include "gx.h" extern int done ; int g_gx_client_sock = 0; int gx_sock = 0; int gx_app_sock_read = 0; void hexDump(char *desc, void *addr, int len) { int i; unsigned char buff[17]; unsigned char *pc = (unsigned char*)addr; // Output description if given. if (desc != NULL) printf ("%s:\n", desc); // Process every byte in the data. for (i = 0; i < len; i++) { // Multiple of 16 means new line (with line offset). if ((i % 16) == 0) { // Just don't print ASCII for the zeroth line. if (i != 0) printf(" %s\n", buff); // Output the offset. printf(" %04x ", i); } // Now the hex code for the specific character. printf(" %02x", pc[i]); // And store a printable ASCII character for later. if ((pc[i] < 0x20) || (pc[i] > 0x7e)) { buff[i % 16] = '.'; } else { buff[i % 16] = pc[i]; } buff[(i % 16) + 1] = '\0'; } // Pad out last line if not exactly 16 characters. while ((i % 16) != 0) { printf(" "); i++; } // And print the final ASCII bit. printf(" %s\n", buff); } int recv_msg_handler( int sock ) { int bytes_recv = 0; char buf[BUFFSIZE] = {0}; int msg_len = 0; gx_msg *req = NULL; bytes_recv = recv_from_ipc_channel(sock, buf); #ifdef GX_DEBUG hexDump(NULL, buf, bytes_recv); #endif while(bytes_recv > 0){ req = (gx_msg*)(buf + msg_len); switch (req->msg_type){ case GX_CCR_MSG: gx_send_ccr(&(req->data.ccr)); break; case GX_RAA_MSG: gx_send_raa(&(req->data.cp_raa)); break; default: printf( "Unknown message received from CP app - %d\n", req->msg_type); } msg_len += req->msg_len; bytes_recv = bytes_recv - req->msg_len; } return 0; } void start_read_channel() { struct sockaddr_un gx_app_sockaddr = {0}; struct sockaddr_un cp_app_sockaddr = {0}; /* Socket Creation */ gx_sock = create_ipc_channel(); /* Bind the socket*/ bind_ipc_channel(gx_sock, gx_app_sockaddr, CLIENT_PATH); /* Mark the socket fd for listen */ listen_ipc_channel(gx_sock); /* Accept incomming connection request receive on socket */ gx_app_sock_read = accept_from_ipc_channel( gx_sock, cp_app_sockaddr); if (gx_app_sock_read < 0) { /*Gracefully Exit*/ exit(0); } printf("Successfully connected to CP...\n"); } int unixsock() { int ret = -1; int n, rv; fd_set readfds; struct timeval tv; /* clear the set ahead of time */ FD_ZERO(&readfds); struct sockaddr_un cp_app_sockaddr = {0}; g_gx_client_sock = create_ipc_channel(); ret = connect_to_ipc_channel( g_gx_client_sock, cp_app_sockaddr, SERVER_PATH ); if (ret) { printf("Could not connect to CP. \n"); exit(0); } start_read_channel(); while(1){ /* add our descriptors to the set */ FD_SET(gx_app_sock_read, &readfds); n = gx_app_sock_read + 1; /* wait until either socket has data * ready to be recv()d (timeout 10.5 secs) */ tv.tv_sec = 10; tv.tv_usec = 500000; rv = select(n, &readfds, NULL, NULL, &tv); if (rv == -1) { if( errno == EINTR && done == 1 ) break; perror("select"); /* error occurred in select() */ } else if (rv > 0) { if (FD_ISSET(gx_app_sock_read, &readfds)){ ret = recv_msg_handler(gx_app_sock_read); } } } return 0; }
nikhilc149/e-utran-features-bug-fixes
test/simu_cp/simu_cp.c
<reponame>nikhilc149/e-utran-features-bug-fixes<gh_stars>0 /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdint.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <stdio.h> #include <time.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <rte_common.h> #include <rte_eal.h> #include <rte_log.h> #include <rte_malloc.h> #include <rte_jhash.h> #include <rte_cfgfile.h> #include <math.h> #include "interface.h" #include "main.h" #include "packet_filters.h" #include "util.h" #include "cp_stats.h" #ifdef SIMU_CP #define SIMU_CP_FILE "../config/simu_cp.cfg" #define NG4T_SIMU extern char *dpn_id; extern uint32_t num_adc_rules; extern uint32_t adc_rule_id[MAX_ADC_RULES]; uint32_t base_s1u_spgw_gtpu_teid = 0xf0000000; static uint32_t s1u_spgw_gtpu_teid_offset; /* Control-Plane Simulator configure parameters. */ struct simu_params { uint32_t enb_ip; uint32_t s1u_sgw_ip; uint32_t ue_ip_s; uint32_t ue_ip_s_range; uint32_t as_ip_s; uint32_t max_ue_sess; uint32_t default_bearer; uint32_t tps; uint32_t duration; #ifdef NG4T_SIMU uint32_t max_ue_ran; uint32_t max_enb_ran; #endif } __attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); /* Show Total statistics of Control-plane */ static void print_stats(struct simu_params *cfg) { printf("\n**************************\n"); printf("STATS :: \n"); printf("**************************\n"); printf("MAX_NUM_CS : %u\n", cfg->max_ue_sess); printf("MAX_NUM_MB : %u\n", cfg->max_ue_sess); printf("NUM_CS_SEND : %"PRIu64"\n", cp_stats.create_session); printf("NUM_MB_SEND : %"PRIu64"\n", cp_stats.modify_bearer); printf("NUM_CS_FAILED : %"PRIu64"\n", (cfg->max_ue_sess - cp_stats.create_session)); printf("NUM_MB_FAILED : %"PRIu64"\n", (cfg->max_ue_sess - cp_stats.modify_bearer)); printf("**************************\n\n"); if ((cfg->max_ue_sess != cp_stats.create_session) || (cfg->max_ue_sess != cp_stats.modify_bearer)) { printf("\n**ERROR : DP not configure properly for %u CS/MB requests.**\n", cfg->max_ue_sess); exit(1); } printf("\n************ DP Configured successfully ************\n"); } #ifdef DEL_SESS_REQ /* Show Total statistics of Control-plane */ static void print_del_stats(struct simu_params *cfg) { printf("\n**************************\n"); printf("STATS :: \n"); printf("**************************\n"); printf("MAX_NUM_DEL : %u\n", cfg->max_ue_sess); printf("NUM_DEL_SEND : %"PRIu64"\n", cp_stats.delete_session); printf("NUM_DEL_FAILED: %"PRIu64"\n", (cfg->max_ue_sess - cp_stats.delete_session)); printf("**************************\n\n"); } #endif #ifdef NG4T_SIMU /* Generate unique eNB teid. */ static uint32_t simu_cp_enbv4_teid(int ue_idx, int max_ue_ran, int max_enb_ran, uint32_t *teid, uint32_t *enb_idx) { int ran; int enb; int enb_of_ran; int ue_of_ran; uint32_t ue_teid; uint32_t session_idx = 0; if (max_ue_ran == 0 || max_enb_ran == 0) return -1; /* need to have at least one of each */ ue_of_ran = ue_idx % max_ue_ran; ran = ue_idx / max_ue_ran; enb_of_ran = ue_of_ran % max_enb_ran; enb = ran * max_enb_ran + enb_of_ran; ue_teid = ue_of_ran + max_ue_ran * session_idx + 1; //*teid = teid_swap(ue_teid); *teid = ue_teid; *enb_idx = enb; //static int found=0; //if (ran <= 1 && found<500 && !(ue_idx%1)) //{ // found += 1; // printf("ue_idx: %d; enb_idx: %d; teid: %d\n", ue_idx, *enb_idx, *teid); //} return 0; } #endif /* Generate unique teid for each create session. */ static void generate_teid(uint32_t *teid) { *teid = base_s1u_spgw_gtpu_teid + s1u_spgw_gtpu_teid_offset; ++s1u_spgw_gtpu_teid_offset; } #ifdef DEL_SESS_REQ /* Form and delete request to DP*/ static int process_delete_req(struct simu_params *param) { printf("\n\n %50s", "Start sending delete session request ....!!! \n"); /* Create Session Information*/ uint32_t s1u_teid = 0; uint32_t enb_teid = 0; uint32_t enb_ip_idx = 0; time_t tstart, tend; unsigned int count = 0; int second_expired = 1; while(1) { if(second_expired) time(&tstart); second_expired = 0; while(cp_stats.delete_session < param->max_ue_sess) { time(&tend); if(fabs(difftime(tend, tstart)) >= fabs(1.0)) { count = 0; second_expired = 1; break; } if (count < param->tps) { struct session_info sess; memset(&sess, 0, sizeof(struct session_info)); /*generate teid for each create session */ generate_teid(&s1u_teid); #ifdef NG4T_SIMU simu_cp_enbv4_teid(cp_stats.delete_session, param->max_ue_ran, param->max_enb_ran, &enb_teid, &enb_ip_idx); #endif sess.ue_addr.iptype = IPTYPE_IPV4; sess.ue_addr.u.ipv4_addr = (param->ue_ip_s) + cp_stats.delete_session; sess.sess_id = SESS_ID(sess.ue_addr.u.ipv4_addr, param->default_bearer); struct dp_id dp_id = { .id = DPN_ID }; if (session_delete(dp_id, sess) < 0) rte_exit(EXIT_FAILURE,"Bearer Session create fail !!!"); cp_stats.delete_session++; ++count; } if(second_expired) break; } if (cp_stats.delete_session >= param->max_ue_sess) break; } return 0; } #endif /* DEL_SESS_REQ */ /* Form and send CS and MB request to DP*/ static int process_cs_mb_req(struct simu_params *param) { printf("\n\n %50s", " CS and MB Requests Generator is started ....!!! \n"); printf("\n\n %50s", " Please wait for DP configured message ....!!! \n"); /* Create Session Information*/ uint32_t s1u_teid = 0; uint32_t enb_teid = 0; uint32_t enb_ip_idx = 0; time_t tstart, tend; unsigned int count = 0; int second_expired = 1; while(1) { if(second_expired) time(&tstart); second_expired = 0; while(cp_stats.create_session < param->max_ue_sess){ time(&tend); if(fabs(difftime(tend, tstart)) >= fabs(1.0)) { count = 0; second_expired = 1; break; } if (count < param->tps) { struct session_info sess; memset(&sess, 0, sizeof(struct session_info)); /*generate teid for each create session */ generate_teid(&s1u_teid); #ifdef NG4T_SIMU simu_cp_enbv4_teid(cp_stats.create_session, param->max_ue_ran, param->max_enb_ran, &enb_teid, &enb_ip_idx); #endif sess.ue_addr.iptype = IPTYPE_IPV4; sess.ue_addr.u.ipv4_addr = (param->ue_ip_s) + cp_stats.create_session; sess.ul_s1_info.sgw_teid = s1u_teid; sess.ul_s1_info.sgw_addr.iptype = IPTYPE_IPV4; sess.ul_s1_info.sgw_addr.u.ipv4_addr = param->s1u_sgw_ip; sess.dl_s1_info.sgw_addr.iptype = IPTYPE_IPV4; sess.dl_s1_info.sgw_addr.u.ipv4_addr = param->s1u_sgw_ip; sess.ul_apn_mtr_idx = ulambr_idx; sess.dl_apn_mtr_idx = dlambr_idx; sess.ipcan_dp_bearer_cdr.charging_id = 10; sess.ipcan_dp_bearer_cdr.pdn_conn_charging_id = 10; sess.ul_s1_info.enb_addr.iptype = IPTYPE_IPV4; sess.ul_s1_info.enb_addr.u.ipv4_addr = param->enb_ip + enb_ip_idx; sess.num_ul_pcc_rules = 1; sess.num_dl_pcc_rules = 1; sess.ul_pcc_rule_id[0] = FIRST_FILTER_ID; sess.dl_pcc_rule_id[0] = FIRST_FILTER_ID; sess.sess_id = SESS_ID(sess.ue_addr.u.ipv4_addr, param->default_bearer); struct dp_id dp_id = { .id = DPN_ID }; if (session_create(dp_id, sess) < 0) rte_exit(EXIT_FAILURE,"Bearer Session create fail !!!"); cp_stats.create_session++; /* Modify the session */ sess.dl_s1_info.enb_teid = ntohl(enb_teid); sess.dl_s1_info.enb_addr.iptype = IPTYPE_IPV4; sess.dl_s1_info.enb_addr.u.ipv4_addr = param->enb_ip + enb_ip_idx; sess.num_adc_rules = num_adc_rules; for (uint32_t i = 0; i < num_adc_rules; i++) sess.adc_rule_id[i] = adc_rule_id[i]; if (session_modify(dp_id, sess) < 0) rte_exit(EXIT_FAILURE,"Bearer Session modify fail !!!"); ++count; cp_stats.modify_bearer++; } if(second_expired) break; } if(cp_stats.create_session >= param->max_ue_sess) break; } return 0; } static int parse_agrs(struct simu_params *cfg) { struct in_addr addr; const char *file_entry = NULL; char *end = NULL; struct rte_cfgfile *file = rte_cfgfile_load(SIMU_CP_FILE, 0); if (file == NULL) rte_exit(EXIT_FAILURE, "Cannot load configuration profile %s\n", SIMU_CP_FILE); file_entry = rte_cfgfile_get_entry(file, "0", "S1U_SGW_IP"); if (file_entry) { if (inet_aton(file_entry, &addr) == 0) { fprintf(stderr, "Invalid address\n"); exit(EXIT_FAILURE); } cfg->s1u_sgw_ip = ntohl(addr.s_addr); } file_entry = rte_cfgfile_get_entry(file, "0", "ENODEB_IP_START"); if (file_entry) { if (inet_aton(file_entry, &addr) == 0) { fprintf(stderr, "Invalid address\n"); exit(EXIT_FAILURE); } cfg->enb_ip = ntohl(addr.s_addr); } file_entry = rte_cfgfile_get_entry(file, "0", "UE_IP_START"); if (file_entry) { if (inet_aton(file_entry, &addr) == 0) { fprintf(stderr, "Invalid address\n"); exit(EXIT_FAILURE); } cfg->ue_ip_s = ntohl(addr.s_addr); } file_entry = rte_cfgfile_get_entry(file, "0", "UE_IP_START_RANGE"); if (file_entry) { if (inet_aton(file_entry, &addr) == 0) { fprintf(stderr, "Invalid address\n"); exit(EXIT_FAILURE); } cfg->ue_ip_s_range = ntohl(addr.s_addr); } file_entry = rte_cfgfile_get_entry(file, "0", "AS_IP_START"); if (file_entry) { if (inet_aton(file_entry, &addr) == 0) { fprintf(stderr, "Invalid address\n"); exit(EXIT_FAILURE); } cfg->as_ip_s = ntohl(addr.s_addr); } file_entry = rte_cfgfile_get_entry(file, "0", "MAX_UE_SESS"); if (file_entry) cfg->max_ue_sess = (uint32_t) strtoll(file_entry, &end, 10); file_entry = rte_cfgfile_get_entry(file, "0", "DEFAULT_BEARER"); if (file_entry) cfg->default_bearer = (uint32_t) strtoll(file_entry, &end, 10); file_entry = rte_cfgfile_get_entry(file, "0", "TPS"); if (file_entry) cfg->tps = (uint32_t) strtoll(file_entry, &end, 10); file_entry = rte_cfgfile_get_entry(file, "0", "BREAK_DURATION"); if (file_entry) cfg->duration = (uint32_t) strtoll(file_entry, &end, 10); #ifdef NG4T_SIMU file_entry = rte_cfgfile_get_entry(file, "0", "ng4t_max_ue_ran"); if (file_entry) cfg->max_ue_ran = (uint32_t) strtoll(file_entry, &end, 10); file_entry = rte_cfgfile_get_entry(file, "0", "ng4t_max_enb_ran"); if (file_entry) cfg->max_enb_ran = (uint32_t) strtoll(file_entry, &end, 10); #endif return 0; } #ifdef CP_BUILD int simu_cp(__rte_unused void *ptr) #else int simu_cp(void) #endif /* CP_BUILD */ { struct simu_params cfg; /* Parsing simu config parameters. */ int ret = parse_agrs(&cfg); if (ret < 0) exit(1); #ifndef CP_BUILD /* Parse the rules into DP */ /* Configure PCC, Meter and SDF rules on DP. */ init_packet_filters(); /* Configure ADC rules on DP.*/ parse_adc_rules(); #endif /* CP_BUILD */ /* Wait to create stream channel with FPC*/ sleep(5); /* Form and send CS and MB request to DP. */ ret = process_cs_mb_req(&cfg); if (ret < 0) exit(1); /* Show CS and MB requests STATS. */ sleep(5); print_stats(&cfg); #ifdef DEL_SESS_REQ sleep(cfg.duration); /* Form and send delete request to DP. */ ret = process_delete_req(&cfg); if (ret < 0) exit(1); /* Show delete session requests STATS. */ sleep(5); print_del_stats(&cfg); #endif /* DEL_SESS_REQ */ return 0; } #endif /* SIMU_CP */
nikhilc149/e-utran-features-bug-fixes
interface/ipc/dp_ipc_api.c
<gh_stars>0 /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdint.h> #include <arpa/inet.h> #include <stdio.h> #include <time.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <rte_common.h> #include <rte_eal.h> #include <rte_log.h> #include <rte_malloc.h> #include <rte_cfgfile.h> #include <rte_errno.h> #include <errno.h> #include "interface.h" #include "dp_ipc_api.h" #include "../../pfcp_messages/pfcp_util.h" #ifdef CP_BUILD #include "../cp/cp.h" #include "../cp/cp_app.h" #include "../cp/cp_stats.h" #include "../cp/cp_config.h" #include "../cp/state_machine/sm_struct.h" extern int gx_app_sock_read; extern uint8_t recovery_flag; #endif /* CP_BUILD */ extern udp_sock_t my_sock; void iface_ipc_register_msg_cb(int msg_id, int (*msg_cb)(struct msgbuf *msg_payload)) { struct ipc_node *node; node = &basenode[msg_id]; node->msg_id = msg_id; node->msg_cb = msg_cb; } /********************************** DP API ************************************/ void iface_init_ipc_node(void) { basenode = rte_zmalloc("iface_ipc", sizeof(struct ipc_node) * MSG_END, RTE_CACHE_LINE_SIZE); if (basenode == NULL) exit(0); }
nikhilc149/e-utran-features-bug-fixes
pfcp_messages/csid_init.c
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <time.h> #include <rte_hash_crc.h> #include "pfcp_util.h" #include "csid_struct.h" #include "seid_llist.h" #include "gw_adapter.h" #ifdef CP_BUILD #include "cp.h" #include "main.h" #else #include "up_main.h" #endif /* CP_BUILD */ #define NUM_OF_TABLES 9 #define NUM_OF_NODE 15 #define MAX_HASH_SIZE (1 << 12) /* Total entry : 4095 */ #define PEER_NODE_ADDR_MAX_HASH_SIZE (64) extern uint16_t local_csid; extern int clSystemLog; /** * Add csid entry in csid hash table. * * @param struct peer_node_info csid_key * key. * @param csid * return 0 or 1. * */ int8_t add_csid_entry(csid_key *key, uint16_t csid) { int ret = 0; uint16_t *tmp = NULL; /* Lookup for CSID entry. */ ret = rte_hash_lookup_data(csid_by_peer_node_hash, key, (void **)&tmp); if ( ret < 0) { tmp = rte_zmalloc_socket(NULL, sizeof(uint16_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "the memory for csid\n", LOG_VALUE); } *tmp = csid; /* CSID Entry add if not present */ ret = rte_hash_add_key_data(csid_by_peer_node_hash, key, tmp); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for csid : %u" "\n\tError= %s\n", LOG_VALUE, *tmp, rte_strerror(abs(ret))); return -1; } } else { *tmp = csid; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" CSID entry added for csid:%u\n", LOG_VALUE, *tmp); return 0; } #ifdef CP_BUILD /** * Compare the peer node information with exsting peer node entry. * * @param struct peer_node_info peer1 * key. * @param struct peer_node_info peer * return 0 or -1. * */ //int8_t //compare_peer_info(csid_key *peer1, csid_key *peer2) //{ // if ((peer1 == NULL) || (peer2 == NULL)) { // clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"CSID key value is NULL\n", LOG_VALUE); // return -1; // } // // /* Compare peer nodes information */ // if ((peer1->mme_ip == peer2->mme_ip) && // (peer1->sgwc_ip== peer2->sgwc_ip) && // (peer1->sgwu_ip == peer2->sgwu_ip) && // (peer1->pgwc_ip == peer2->pgwc_ip) && // (peer1->pgwu_ip == peer2->pgwu_ip) // && (peer1->enodeb_ip == peer2->enodeb_ip) // ) { // clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer node exsting entry is matched\n", LOG_VALUE); // return 0; // } // clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer node exsting entry is not matched\n", LOG_VALUE); // return -1; // //} #endif /* CP_BUILD */ /** * Update csid key associated peer node with csid in csid hash table. * * @param struct peer_node_info csid_key * key. * @param struct peer_node_info csid_key * return csid or -1. * */ int16_t update_csid_entry(csid_key *old_key, csid_key *new_key) { int ret = 0; uint16_t *csid = NULL; /* Check peer node CSID entry is present or Not */ ret = rte_hash_lookup_data(csid_by_peer_node_hash, old_key, (void **)&csid); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"CSID Entry not found for peer_info \n", LOG_VALUE); return -1; } else { /* Peer node CSID Entry is present. Delete the CSID Entry */ ret = rte_hash_del_key(csid_by_peer_node_hash, old_key); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to delete csid entry\n", LOG_VALUE); return -1; } /* CSID Entry add if not present */ ret = rte_hash_add_key_data(csid_by_peer_node_hash, new_key, csid); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for csid : %u" "\n\tError= %s\n", LOG_VALUE, *csid, rte_strerror(abs(ret))); return -1; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Key updated for CSID:%u\n", LOG_VALUE, *csid); return *csid; } /** * Get csid entry from csid hash table. * * @param struct peer_node_info csid_key * key. * return csid or -1 * */ int16_t get_csid_entry(csid_key *key) { int ret = 0; csid_t *csid = NULL; /* Check csid entry is present or Not */ ret = rte_hash_lookup_data(csid_by_peer_node_hash, key, (void **)&csid); if ( ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found in peer node hash table..\n", LOG_VALUE); /* Allocate the memory for local CSID */ csid = rte_zmalloc_socket(NULL, sizeof(csid_t), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (csid == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "the memory for csid\n", LOG_VALUE); return -1; } /* Assign the local csid */ csid->local_csid[csid->num_csid++] = ++local_csid; /* CSID Entry add if not present */ ret = rte_hash_add_key_data(csid_by_peer_node_hash, key, csid); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for csid : %u" "\n\tError= %s\n", LOG_VALUE, csid->local_csid[csid->num_csid - 1], rte_strerror(abs(ret))); return -1; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"CSID : %u\n", LOG_VALUE, csid->local_csid[csid->num_csid - 1]); return csid->local_csid[csid->num_csid - 1]; } /** * Delete csid entry from csid hash table. * * @param struct peer_node_info csid_key * key. * return 0 or 1. * */ int8_t del_csid_entry(csid_key *key) { int ret = 0; uint16_t *csid = NULL; /* Check peer node CSID entry is present or Not */ ret = rte_hash_lookup_data(csid_by_peer_node_hash, key, (void **)&csid); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to delete csid entry\n", LOG_VALUE); return -1; } /* Peer node CSID Entry is present. Delete the CSID Entry */ ret = rte_hash_del_key(csid_by_peer_node_hash, key); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to delete csid entry\n", LOG_VALUE); return -1; } /* Free data from hash */ if (csid != NULL) { rte_free(csid); csid = NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Peer node CSID entry deleted\n", LOG_VALUE); return 0; } /** * Add peer node csids entry in peer node csids hash table. * * @param local_csid * key. * @param struct fq_csid_info fq_csids * return 0 or 1. * */ int8_t add_peer_csids_entry(uint16_t csid, fq_csids *csids) { int ret = 0; fq_csids *tmp = NULL; /* Lookup for local CSID entry. */ ret = rte_hash_lookup_data(peer_csids_by_csid_hash, &csid, (void **)&tmp); if ( ret < 0) { /* Local CSID Entry not present. Add CSID Entry */ ret = rte_hash_add_key_data(peer_csids_by_csid_hash, &csid, csids); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for CSID: %u" "\n\tError= %s\n", LOG_VALUE, csid, rte_strerror(abs(ret))); return -1; } } else { memcpy(tmp, csids, sizeof(fq_csids)); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"CSID entry added for CSID: %u\n", LOG_VALUE, csid); return 0; } /** * Get peer node csids entry from peer node csids hash table. * * @param local_csid * key. * return fq_csids or NULL * */ fq_csids* get_peer_csids_entry(uint16_t csid) { int ret = 0; fq_csids *tmp = NULL; ret = rte_hash_lookup_data(peer_csids_by_csid_hash, &csid, (void **)&tmp); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for CSID: %u\n", LOG_VALUE, csid); return NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry found for CSID: %u\n", LOG_VALUE, csid); return tmp; } /** * Delete peer node csid entry from peer node csid hash table. * * @param csid * key. * return 0 or 1. * */ int8_t del_peer_csids_entry(uint16_t csid) { int ret = 0; fq_csids *tmp = NULL; /* Check local CSID entry is present or Not */ ret = rte_hash_lookup_data(peer_csids_by_csid_hash, &csid, (void **)&tmp); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for CSID: %u\n", LOG_VALUE, csid); return -1; } /* Local CSID Entry is present. Delete local csid Entry */ ret = rte_hash_del_key(peer_csids_by_csid_hash, &csid); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to delete peer " "csid entry\n", LOG_VALUE); return -1; } /* Free data from hash */ if (tmp != NULL) { rte_free(tmp); tmp = NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry deleted for CSID:%u\n", LOG_VALUE, csid); return 0; } /********[ seids_by_csid_hash ]*********/ /** * Add session ids entry in sess csid hash table. * * @param csid * key. * @param struct sess_csid_info sess_csid * return 0 or 1. * */ int8_t add_sess_csid_entry(uint16_t csid, sess_csid *seids) { int ret = 0; sess_csid *tmp = NULL; /* Lookup for csid entry. */ ret = rte_hash_lookup_data(seids_by_csid_hash, &csid, (void **)&tmp); if ( ret < 0) { /* CSID Entry not present. Add CSID Entry in table */ ret = rte_hash_add_key_data(seids_by_csid_hash, &csid, seids); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry for CSID = %u" "\n\tError= %s\n", LOG_VALUE, csid, rte_strerror(abs(ret))); return -1; } } else { memcpy(tmp, seids, sizeof(sess_csid)); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Session IDs entry added for CSID:%u\n", LOG_VALUE, csid); return 0; } /** * Get session ids entry from sess csid hash table. * * @param local_csid * key. * return sess_csid or NULL * */ sess_csid* get_sess_csid_entry(uint16_t csid, uint8_t is_mod) { int ret = 0; sess_csid *tmp = NULL; sess_csid *head = NULL; /* Retireve CSID entry */ ret = rte_hash_lookup_data(seids_by_csid_hash, &csid, (void **)&tmp); if ( (ret < 0) || (tmp == NULL)) { if(is_mod != ADD_NODE) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for CSID: %u\n", LOG_VALUE, csid); return NULL; } /* Allocate the memory for session IDs */ tmp = rte_zmalloc_socket(NULL, sizeof(sess_csid), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (tmp == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate " "the memory for csid\n", LOG_VALUE); return NULL; } /* CSID Entry not present. Add CSID Entry in table */ ret = rte_hash_add_key_data(seids_by_csid_hash, &csid, tmp); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add Session IDs entry for CSID = %u" "\n\tError= %s\n", LOG_VALUE, csid, rte_strerror(abs(ret))); return NULL; } if (insert_sess_csid_data_node(head, tmp) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add node ," "Session IDs entry for CSID: %u", LOG_VALUE, csid); } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry Found for CSID:%u\n", LOG_VALUE, csid); return tmp; } /** * Delete session ids entry from sess csid hash table. * * @param local_csid * key. * return 0 or 1. * */ int8_t del_sess_csid_entry(uint16_t csid) { int ret = 0; sess_csid *tmp = NULL; /* Check CSID entry is present or Not */ ret = rte_hash_lookup_data(seids_by_csid_hash, &csid, (void **)&tmp); if ( ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for CSID:%u\n", LOG_VALUE, csid); return -1; } /* CSID Entry is present. Delete Session Entry */ ret = rte_hash_del_key(seids_by_csid_hash, &csid); /* Free data from hash */ if (tmp != NULL) { if ((tmp->up_seid != 0)) { rte_free(tmp); tmp = NULL; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Sessions IDs Entry deleted for CSID:%u\n", LOG_VALUE, csid); return 0; } sess_csid* get_sess_peer_csid_entry(peer_csid_key_t *key, uint8_t is_mod) { int ret = 0; sess_csid *tmp = NULL; sess_csid *head = NULL; /* Retireve CSID entry */ ret = rte_hash_lookup_data(seid_by_peer_csid_hash, key, (void **)&tmp); if ( (ret < 0) || (tmp == NULL)) { if(is_mod != ADD_NODE) { (key->peer_node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Entry not found for iface : %d : Peer CSID:%u :" " Peer IPv6 node addr : "IPv6_FMT"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPv6_PRINT(IPv6_CAST(key->peer_node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Entry not found for iface : %d : Peer CSID:%u :" " Peer IPv4 node addr : "IPV4_ADDR"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)); return NULL; } /* Allocate the memory for session IDs */ tmp = rte_zmalloc_socket(NULL, sizeof(sess_csid), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (tmp == NULL) { (key->peer_node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Entry not found for iface : %d : Peer CSID:%u :" " Peer IPv6 node addr : "IPv6_FMT"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPv6_PRINT(IPv6_CAST(key->peer_node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Entry not found for iface : %d : Peer CSID:%u :" " Peer IPv4 node addr : "IPV4_ADDR"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)); return NULL; } /* CSID Entry not present. Add CSID Entry in table */ ret = rte_hash_add_key_data(seid_by_peer_csid_hash, key, tmp); if (ret) { (key->peer_node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to add Session IDs entry for iface : %d : Peer CSID:%u :" " Peer IPv6 node addr : "IPv6_FMT"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPv6_PRINT(IPv6_CAST(key->peer_node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to add Session IDs entry for iface : %d : Peer CSID:%u :" " Peer IPv4 node addr : "IPV4_ADDR"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)); return NULL; } if(insert_sess_csid_data_node(head, tmp) < 0) { (key->peer_node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to add node for iface : %d : Peer CSID:%u :" " Peer IPv6 node addr : "IPv6_FMT"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPv6_PRINT(IPv6_CAST(key->peer_node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT "Failed to add node for iface : %d : Peer CSID:%u :" " Peer IPv4 node addr : "IPV4_ADDR"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)); } } (key->peer_node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Entry found for iface : %d : Peer CSID:%u :" " Peer IPv6 node addr : "IPv6_FMT"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPv6_PRINT(IPv6_CAST(key->peer_node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Entry found for iface : %d : Peer CSID:%u :" " Peer IPv4 node addr : "IPV4_ADDR"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)); return tmp; } /** * Delete session ids entry from sess csid hash table. * * @param local_csid * key. * return 0 or 1. * */ int8_t del_sess_peer_csid_entry(peer_csid_key_t *key) { int ret = 0; sess_csid *tmp = NULL; /* Check CSID entry is present or Not */ ret = rte_hash_lookup_data(seid_by_peer_csid_hash, key, (void **)&tmp); if ( ret < 0) { (key->peer_node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Entry not found for iface : %d : Peer CSID:%u :" " Peer node ipv6 addr : "IPv6_FMT"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPv6_PRINT(IPv6_CAST(key->peer_node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Entry not found for iface : %d : Peer CSID:%u :" " Peer node ipv4 addr : "IPV4_ADDR"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)); return -1; } /* CSID Entry is present. Delete Session Entry */ ret = rte_hash_del_key(seid_by_peer_csid_hash, key); /* Free data from hash */ if (tmp != NULL) { if ((tmp->up_seid != 0) && (tmp->next !=0)) { rte_free(tmp); tmp = NULL; } } (key->peer_node_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Session IDs Entry delete for iface : %d : Peer CSID:%u :" " Peer node IPv6 addr : "IPv6_FMT"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPv6_PRINT(IPv6_CAST(key->peer_node_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "Session IDs Entry delete for iface : %d : Peer CSID:%u :" " Peer node IPv4 addr : "IPV4_ADDR"\n", LOG_VALUE, key->iface, key->peer_local_csid, IPV4_ADDR_HOST_FORMAT(key->peer_node_addr.ipv4_addr)); return 0; } /** *Init the hash tables for FQ-CSIDs */ int8_t init_fqcsid_hash_tables(void) { struct rte_hash_parameters pfcp_hash_params[NUM_OF_TABLES] = { { .name = "CSID_BY_PEER_NODE_HASH", .entries = MAX_HASH_SIZE, .key_len = sizeof(csid_key), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "PEER_CSIDS_BY_CSID_HASH", .entries = MAX_HASH_SIZE, .key_len = sizeof(uint16_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "SEIDS_BY_CSID_HASH", .entries = MAX_HASH_SIZE, .key_len = sizeof(uint16_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "LOCAL_CSIDS_BY_NODE_ADDR_HASH", .entries = NUM_OF_NODE, .key_len = sizeof(node_address_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "LOCAL_CSIDS_BY_MMECSID_HASH", .entries = MAX_HASH_SIZE, .key_len = sizeof(csid_key_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "LOCAL_CSIDS_BY_PGWCSID_HASH", .entries = MAX_HASH_SIZE, .key_len = sizeof(csid_key_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "LOCAL_CSIDS_BY_SGWCSID_HASH", .entries = MAX_HASH_SIZE, .key_len = sizeof(csid_key_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "SEID_BY_PEER_CSID_HASH", .entries = MAX_HASH_SIZE, .key_len = sizeof(peer_csid_key_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "PEER_NODE_ADDR_BY_PEER_FQCSID_NODE_ADDR_HASH", .entries = PEER_NODE_ADDR_MAX_HASH_SIZE, .key_len = sizeof(peer_node_addr_key_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() } }; csid_by_peer_node_hash = rte_hash_create(&pfcp_hash_params[0]); if (!csid_by_peer_node_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[0].name, rte_strerror(rte_errno), rte_errno); } peer_csids_by_csid_hash = rte_hash_create(&pfcp_hash_params[1]); if (!peer_csids_by_csid_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[1].name, rte_strerror(rte_errno), rte_errno); } seids_by_csid_hash = rte_hash_create(&pfcp_hash_params[2]); if (!seids_by_csid_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[2].name, rte_strerror(rte_errno), rte_errno); } local_csids_by_node_addr_hash = rte_hash_create(&pfcp_hash_params[3]); if (!local_csids_by_node_addr_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[3].name, rte_strerror(rte_errno), rte_errno); } local_csids_by_mmecsid_hash = rte_hash_create(&pfcp_hash_params[4]); if (!local_csids_by_mmecsid_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[4].name, rte_strerror(rte_errno), rte_errno); } local_csids_by_pgwcsid_hash = rte_hash_create(&pfcp_hash_params[5]); if (!local_csids_by_pgwcsid_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[5].name, rte_strerror(rte_errno), rte_errno); } local_csids_by_sgwcsid_hash = rte_hash_create(&pfcp_hash_params[6]); if (!local_csids_by_sgwcsid_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[6].name, rte_strerror(rte_errno), rte_errno); } seid_by_peer_csid_hash = rte_hash_create(&pfcp_hash_params[7]); if (!seid_by_peer_csid_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[7].name, rte_strerror(rte_errno), rte_errno); } peer_node_addr_by_peer_fqcsid_node_addr_hash = rte_hash_create(&pfcp_hash_params[8]); if (peer_node_addr_by_peer_fqcsid_node_addr_hash == NULL) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[7].name, rte_strerror(rte_errno), rte_errno); } return 0; }
nikhilc149/e-utran-features-bug-fixes
dp/pfcp_up_init.c
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <time.h> #include <rte_hash.h> #include <rte_errno.h> #include <rte_debug.h> #include <rte_jhash.h> #include <rte_lcore.h> #include <rte_hash_crc.h> #include "gw_adapter.h" #include "up_main.h" #include "pfcp_up_llist.h" #include "pfcp_up_struct.h" #include "predef_rule_init.h" #define NUM_OF_TABLES 10 #define MAX_HASH_SIZE (1 << 16) #define MAX_PDN_HASH_SIZE (1 << 12) #define UN_16_BIT_HASH_SIZE (1 << 17) #define SESS_CREATE 0 #define SESS_MODIFY 1 #define SESS_DEL 2 /* User-Plane base increment offset parameter */ static uint32_t up_qer_indx_offset; extern struct rte_hash *sess_ctx_by_sessid_hash; extern struct rte_hash *sess_by_teid_hash; extern struct rte_hash *sess_by_ueip_hash; extern struct rte_hash *pdr_by_id_hash; extern struct rte_hash *far_by_id_hash; extern struct rte_hash *qer_by_id_hash; extern struct rte_hash *urr_by_id_hash; extern struct rte_hash *timer_by_id_hash; extern struct rte_hash *qer_rule_hash; extern int clSystemLog; int8_t add_sess_info_entry(uint64_t up_sess_id, pfcp_session_t *sess_cntxt) { int ret = 0; pfcp_session_t *tmp = NULL; /* Lookup for up session context entry. */ ret = rte_hash_lookup_data(sess_ctx_by_sessid_hash, &up_sess_id, (void **)&tmp); if ( ret < 0) { /* allocate memory for session info*/ tmp = rte_zmalloc("Session_Info", sizeof(pfcp_session_t), RTE_CACHE_LINE_SIZE); if (tmp == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory for session info, Error: %s\n", LOG_VALUE, rte_strerror(rte_errno)); return -1; } if (sess_cntxt != NULL) memcpy(tmp, sess_cntxt, sizeof(pfcp_session_t)); /* Session Entry not present. Add new session entry */ ret = rte_hash_add_key_data(sess_ctx_by_sessid_hash, &up_sess_id, tmp); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for UP SESSION ID: %lu" ", Error :%s\n", LOG_VALUE, up_sess_id, rte_strerror(abs(ret))); /* free allocated memory */ rte_free(tmp); tmp = NULL; return -1; } } else { memcpy(tmp, sess_cntxt, sizeof(pfcp_session_t)); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Session entry added by UP SESSION ID: %lu\n", LOG_VALUE, up_sess_id); return 0; } pfcp_session_t * get_sess_info_entry(uint64_t up_sess_id, uint8_t is_mod) { int ret = 0; pfcp_session_t *sess_cntxt = NULL; ret = rte_hash_lookup_data(sess_ctx_by_sessid_hash, &up_sess_id, (void **)&sess_cntxt); if ( ret < 0) { /* allocate memory only if request is from session establishment */ if (is_mod != SESS_CREATE) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for UP SESSION ID: %lu\n", LOG_VALUE, up_sess_id); return NULL; } /* allocate memory for session info*/ sess_cntxt = rte_zmalloc("Session_Info", sizeof(pfcp_session_t), RTE_CACHE_LINE_SIZE); if (sess_cntxt == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory for session info, Error: %s\n", LOG_VALUE, rte_strerror(rte_errno)); return NULL; } /* Session Entry not present. Add new session entry */ ret = rte_hash_add_key_data(sess_ctx_by_sessid_hash, &up_sess_id, sess_cntxt); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for UP SESSION ID: %lu" ", Error: %s\n", LOG_VALUE, up_sess_id, rte_strerror(abs(ret))); /* free allocated memory */ rte_free(sess_cntxt); sess_cntxt = NULL; return NULL; } /* Fill the UP Session ID */ sess_cntxt->up_seid = up_sess_id; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"UP SESSION ID: %lu\n", LOG_VALUE, up_sess_id); return sess_cntxt; } int8_t del_sess_info_entry(uint64_t up_sess_id) { int ret = 0; pfcp_session_t *sess_cntxt = NULL; /* Check session entry is present or Not */ ret = rte_hash_lookup_data(sess_ctx_by_sessid_hash, &up_sess_id, (void **)&sess_cntxt); if (ret >=0 ) { /* Session Entry is present. Delete Session Entry */ ret = rte_hash_del_key(sess_ctx_by_sessid_hash, &up_sess_id); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found " "for UP SESSION ID: %lu\n", LOG_VALUE, up_sess_id); return -1; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"UP SESS ID: %lu\n", LOG_VALUE, up_sess_id); return 0; } pfcp_session_datat_t * get_sess_by_teid_entry(uint32_t teid, pfcp_session_datat_t **head, uint8_t is_mod) { int ret = 0; pfcp_session_datat_t *sess_cntxt = NULL; ret = rte_hash_lookup_data(sess_by_teid_hash, &teid, (void **)&sess_cntxt); if ( ret < 0) { if (is_mod != SESS_CREATE) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for TEID: %u\n", LOG_VALUE, teid); return NULL; } /* allocate memory for session info*/ sess_cntxt = rte_zmalloc("Sess_data_Info", sizeof(pfcp_session_datat_t), RTE_CACHE_LINE_SIZE); if (sess_cntxt == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory for session data info, Error: %s\n", LOG_VALUE, rte_strerror(abs(ret))); return NULL; } /* Session Entry not present. Add new session entry */ ret = rte_hash_add_key_data(sess_by_teid_hash, &teid, sess_cntxt); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for TEID: %u" ", Error: %s\n", LOG_VALUE, ntohl(teid), rte_strerror(abs(ret))); /* free allocated memory */ rte_free(sess_cntxt); sess_cntxt = NULL; return NULL; } /* Function to add a node in Sesions Data Linked List. */ if (insert_sess_data_node(*head, sess_cntxt)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add node entry in LL for TEID : %u" "Error :%s\n", LOG_VALUE, teid, rte_strerror(abs(ret))); } if (*head == NULL) *head = sess_cntxt; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"TEID Value: %u\n", LOG_VALUE, teid); return sess_cntxt; } int8_t del_sess_by_teid_entry(uint32_t teid) { int ret = 0; pfcp_session_datat_t *sess_cntxt = NULL; /* Check session entry is present or Not */ ret = rte_hash_lookup_data(sess_by_teid_hash, &teid, (void **)&sess_cntxt); if (ret >= 0) { /* Session Entry is present. Delete Session Entry */ ret = rte_hash_del_key(sess_by_teid_hash, &teid); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found " "for TEID: %u\n", LOG_VALUE, ntohl(teid)); return -1; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"TEID Value: %u\n", LOG_VALUE, ntohl(teid)); return 0; } pfcp_session_datat_t * get_sess_by_ueip_entry(ue_ip_t ue_ip, pfcp_session_datat_t **head, uint8_t is_mod) { int ret = 0; pfcp_session_datat_t *sess_cntxt = NULL; char ipv6[IPV6_STR_LEN]; inet_ntop(AF_INET6, ue_ip.ue_ipv6, ipv6, IPV6_STR_LEN); ret = rte_hash_lookup_data(sess_by_ueip_hash, &ue_ip, (void **)&sess_cntxt); if ( ret < 0) { if (is_mod != SESS_CREATE) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Entry not found for UE IPv4: "IPV4_ADDR" or IPv6 IP %s\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ue_ip.ue_ipv4), ipv6); return NULL; } /* allocate memory for session info*/ sess_cntxt = rte_zmalloc("Sess_data_Info", sizeof(pfcp_session_datat_t), RTE_CACHE_LINE_SIZE); if (sess_cntxt == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory for session data info\n", LOG_VALUE); return NULL; } /* Session Entry not present. Add new session entry */ ret = rte_hash_add_key_data(sess_by_ueip_hash, &ue_ip, sess_cntxt); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for UE IPv4: "IPV4_ADDR" or IPv6 IP %s" ", Error: %s\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ue_ip.ue_ipv4), ipv6, rte_strerror(abs(ret))); /* free allocated memory */ rte_free(sess_cntxt); sess_cntxt = NULL; return NULL; } /* Function to add a node in Sesions Data Linked List. */ if (insert_sess_data_node(*head, sess_cntxt)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add node entry in LInked List for UE IPv4: "IPV4_ADDR" or IPv6 IP:%s" ",Error: %s\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ue_ip.ue_ipv4), ipv6, rte_strerror(abs(ret))); } if (*head == NULL) *head = sess_cntxt; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"UE IPv4: "IPV4_ADDR" or IPv6 IP %s\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ue_ip.ue_ipv4), ipv6); return sess_cntxt; } int8_t del_sess_by_ueip_entry(ue_ip_t ue_ip) { int ret = 0; pfcp_session_datat_t *sess_cntxt = NULL; char ipv6[IPV6_STR_LEN]; inet_ntop(AF_INET6, ue_ip.ue_ipv6, ipv6, IPV6_STR_LEN); /* Check session entry is present or Not */ ret = rte_hash_lookup_data(sess_by_ueip_hash, &ue_ip, (void **)&sess_cntxt); if (ret >= 0) { /* Session Entry is present. Delete Session Entry */ ret = rte_hash_del_key(sess_by_ueip_hash, &ue_ip); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found " "for UE IPv4: "IPV4_ADDR" or IPv6 %s\n", LOG_VALUE,IPV4_ADDR_HOST_FORMAT(ue_ip.ue_ipv4), ipv6); return -1; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Session context Deleted for" "UE IPv4: "IPV4_ADDR" or IPv6 %s\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ue_ip.ue_ipv4), ipv6); return 0; } pdr_info_t * get_pdr_info_entry(uint16_t rule_id, pdr_info_t **head, uint16_t is_add, peer_addr_t cp_ip, uint64_t cp_seid) { int ret = 0; pdr_info_t *pdr = NULL; rule_key hash_key = {0}; hash_key.cp_ip_addr.type = cp_ip.type; if(cp_ip.type == PDN_TYPE_IPV4){ hash_key.cp_ip_addr.ip.ipv4_addr = cp_ip.ipv4.sin_addr.s_addr; }else{ memcpy(hash_key.cp_ip_addr.ip.ipv6_addr, cp_ip.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } hash_key.id = (uint32_t)rule_id; hash_key.cp_seid = cp_seid; ret = rte_hash_lookup_data(pdr_by_id_hash, &hash_key, (void **)&pdr); if ( ret < 0) { if (is_add != SESS_CREATE) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to get PDR entry\n", LOG_VALUE); return NULL; } /* allocate memory for session info*/ pdr = rte_zmalloc("Session_Info", sizeof(pdr_info_t), RTE_CACHE_LINE_SIZE); if (pdr == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory for PDR info, Error: %s\n", LOG_VALUE, rte_strerror(abs(ret))); return NULL; } /* PDR Entry not present. Add PDR Entry */ ret = rte_hash_add_key_data(pdr_by_id_hash, &hash_key, pdr); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for PDR ID: %u , Error: %s\n", LOG_VALUE, rule_id, rte_strerror(abs(ret))); /* free allocated memory */ rte_free(pdr); pdr = NULL; return NULL; } /* Update the rule id */ pdr->rule_id = rule_id; /* Function to add a node in PDR data Linked List. */ if (insert_pdr_node(*head, pdr)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add node entry in Linked List" " for PDR ID: %u ,Error: %s\n", LOG_VALUE, rule_id, rte_strerror(abs(ret))); } if (*head == NULL) { *head = pdr; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"PDR ID: %u\n", LOG_VALUE, rule_id); return pdr; } int8_t del_pdr_info_entry(uint16_t rule_id, peer_addr_t cp_ip, uint64_t cp_seid) { int ret = 0; pdr_info_t *pdr = NULL; rule_key hash_key = {0}; hash_key.cp_ip_addr.type = cp_ip.type; if(cp_ip.type == PDN_TYPE_IPV4){ hash_key.cp_ip_addr.ip.ipv4_addr = cp_ip.ipv4.sin_addr.s_addr; }else{ memcpy(hash_key.cp_ip_addr.ip.ipv6_addr, cp_ip.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } hash_key.id = (uint32_t)rule_id; hash_key.cp_seid = cp_seid; /* Check PDR entry is present or Not */ ret = rte_hash_lookup_data(pdr_by_id_hash, &hash_key, (void **)&pdr); if (ret >= 0) { /* PDR Entry is present. Delete PDR Entry */ ret = rte_hash_del_key(pdr_by_id_hash, &hash_key); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found " "for PDR ID: %u\n", LOG_VALUE, rule_id); return -1; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"PDR ID:%u\n", LOG_VALUE, rule_id); return 0; } int8_t add_far_info_entry(uint16_t far_id, far_info_t **far, peer_addr_t cp_ip, uint64_t cp_seid) { int ret = 0; far_info_t *tmp = NULL; rule_key hash_key = {0}; hash_key.cp_ip_addr.type = cp_ip.type; if(cp_ip.type == PDN_TYPE_IPV4){ hash_key.cp_ip_addr.ip.ipv4_addr = cp_ip.ipv4.sin_addr.s_addr; }else{ memcpy(hash_key.cp_ip_addr.ip.ipv6_addr, cp_ip.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } hash_key.id = (uint32_t)far_id; hash_key.cp_seid = cp_seid; /* Lookup for FAR entry. */ ret = rte_hash_lookup_data(far_by_id_hash, &hash_key, (void **)&tmp); if ( ret < 0) { /* allocate memory for session info*/ *far = rte_zmalloc("FAR", sizeof(far_info_t), RTE_CACHE_LINE_SIZE); if (*far == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory for FAR info\n", LOG_VALUE); return -1; } /* FAR Entry not present. Add FAR Entry */ ret = rte_hash_add_key_data(far_by_id_hash, &hash_key, *far); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for FAR ID: %u" "Error :%s\n", LOG_VALUE, far_id, rte_strerror(abs(ret))); /* free allocated memory */ rte_free(*far); *far = NULL; return -1; } } else { if(*far != NULL) memcpy(tmp, *far, sizeof(far_info_t)); else *far = tmp; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"FAR entry added by FAR ID: %u\n", LOG_VALUE, far_id); return 0; } far_info_t * get_far_info_entry(uint16_t far_id, peer_addr_t cp_ip, uint64_t cp_seid) { int ret = 0; far_info_t *far = NULL; rule_key hash_key = {0}; hash_key.cp_ip_addr.type = cp_ip.type; if(cp_ip.type == PDN_TYPE_IPV4){ hash_key.cp_ip_addr.ip.ipv4_addr = cp_ip.ipv4.sin_addr.s_addr; }else{ memcpy(hash_key.cp_ip_addr.ip.ipv6_addr, cp_ip.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } hash_key.id = (uint32_t)far_id; hash_key.cp_seid = cp_seid; ret = rte_hash_lookup_data(far_by_id_hash, &hash_key, (void **)&far); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found for FAR ID: %u\n", LOG_VALUE, far_id); return NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"FAR ID:%u, TEID Value: %u, Dst Ipv4 addr: "IPV4_ADDR", Dst Itf type:%u\n", LOG_VALUE, far_id, far->frwdng_parms.outer_hdr_creation.teid, IPV4_ADDR_HOST_FORMAT(far->frwdng_parms.outer_hdr_creation.ipv4_address), far->frwdng_parms.dst_intfc.interface_value); return far; } int8_t del_far_info_entry(uint16_t far_id, peer_addr_t cp_ip, uint64_t cp_seid) { int ret = 0; far_info_t *far = NULL; rule_key hash_key = {0}; hash_key.cp_ip_addr.type = cp_ip.type; if(cp_ip.type == PDN_TYPE_IPV4){ hash_key.cp_ip_addr.ip.ipv4_addr = cp_ip.ipv4.sin_addr.s_addr; }else{ memcpy(hash_key.cp_ip_addr.ip.ipv6_addr, cp_ip.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } hash_key.id = (uint32_t)far_id; hash_key.cp_seid = cp_seid; /* Check FAR entry is present or Not */ ret = rte_hash_lookup_data(far_by_id_hash, &hash_key, (void **)&far); if (ret >= 0) { /* FAR Entry is present. Delete FAR Entry */ ret = rte_hash_del_key(far_by_id_hash, &hash_key); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not " "found for FAR ID: %u\n",LOG_VALUE, far_id); return -1; } } /* Free data from hash */ if (far != NULL) { rte_free(far); far = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "free the qer memory successfully with" " key FAR ID and PEER IP: %lu\n", LOG_VALUE, hash_key); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"FAR ID:%u\n", LOG_VALUE, far_id); return 0; } int8_t add_qer_info_entry(uint32_t qer_id, qer_info_t **head, peer_addr_t cp_ip, uint64_t cp_seid) { int ret = 0; qer_info_t *qer = NULL; rule_key hash_key = {0}; hash_key.cp_ip_addr.type = cp_ip.type; if(cp_ip.type == PDN_TYPE_IPV4){ hash_key.cp_ip_addr.ip.ipv4_addr = cp_ip.ipv4.sin_addr.s_addr; }else{ memcpy(hash_key.cp_ip_addr.ip.ipv6_addr, cp_ip.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } hash_key.id = qer_id; hash_key.cp_seid = cp_seid; /* Lookup for QER entry. */ ret = rte_hash_lookup_data(qer_by_id_hash, &hash_key, (void **)&qer); if ((ret < 0) || (qer == NULL)) { /* allocate memory for session info*/ qer = rte_zmalloc("QER", sizeof(qer_info_t), RTE_CACHE_LINE_SIZE); if (qer == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory for QER info, Error: %s\n", LOG_VALUE, rte_strerror(abs(ret))); return -1; } /* QER Entry not present. Add QER Entry in table */ ret = rte_hash_add_key_data(qer_by_id_hash, &hash_key, qer); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add QER entry for QER ID: %u" ",Error: %s\n", LOG_VALUE, qer_id, rte_strerror(abs(ret))); /* free allocated memory */ rte_free(qer); qer = NULL; return -1; } /* Update the rule id */ qer->qer_id = qer_id; /* Function to add a node in PDR data Linked List. */ if (insert_qer_node(*head, qer)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add node entry in Linked List for QER ID: %u" "Error: %s\n", LOG_VALUE, qer_id, rte_strerror(abs(ret))); } if (*head == NULL) { *head = qer; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"QER entry add for QER ID:%u\n", LOG_VALUE, qer_id); return 0; } else { if (*head == NULL) { *head = qer; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Found QER entry for QER ID:%u\n", LOG_VALUE, qer_id); return 0; } qer_info_t * get_qer_info_entry(uint32_t qer_id, qer_info_t **head, peer_addr_t cp_ip, uint64_t cp_seid) { int ret = 0; qer_info_t *qer = NULL; rule_key hash_key = {0}; hash_key.cp_ip_addr.type = cp_ip.type; if(cp_ip.type == PDN_TYPE_IPV4){ hash_key.cp_ip_addr.ip.ipv4_addr = cp_ip.ipv4.sin_addr.s_addr; }else{ memcpy(hash_key.cp_ip_addr.ip.ipv6_addr, cp_ip.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } hash_key.id = qer_id; hash_key.cp_seid = cp_seid; /* Retireve QER entry */ ret = rte_hash_lookup_data(qer_by_id_hash, &hash_key, (void **)&qer); if ( ret < 0) { /* allocate memory for session info*/ qer = rte_zmalloc("Session_Info", sizeof(qer_info_t), RTE_CACHE_LINE_SIZE); if (qer == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory for QER info, Error: %s\n", LOG_VALUE, rte_strerror(abs(ret))); return NULL; } /* QER Entry not present. Add PDR Entry */ ret = rte_hash_add_key_data(qer_by_id_hash, &hash_key, qer); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add entry for QER_ID: %u" ",Error: %s\n", LOG_VALUE, qer_id, rte_strerror(abs(ret))); /* free allocated memory */ rte_free(qer); qer = NULL; return NULL; } /* Update the rule id */ qer->qer_id = qer_id; /* Function to add a node in PDR data Linked List. */ if (insert_qer_node(*head, qer)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add node entry in Linked List for QER ID: %u" ",Error: %s\n", LOG_VALUE, qer_id, rte_strerror(abs(ret))); } if (*head == NULL) *head = qer; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Add QER Entry for QER ID: %u\n", LOG_VALUE, qer_id); return qer; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Found entry for QER ID: %u\n", LOG_VALUE, qer_id); return qer; } int8_t del_qer_info_entry(uint32_t qer_id, peer_addr_t cp_ip, uint64_t cp_seid) { int ret = 0; qer_info_t *qer = NULL; rule_key hash_key = {0}; hash_key.cp_ip_addr.type = cp_ip.type; if(cp_ip.type == PDN_TYPE_IPV4){ hash_key.cp_ip_addr.ip.ipv4_addr = cp_ip.ipv4.sin_addr.s_addr; }else{ memcpy(hash_key.cp_ip_addr.ip.ipv6_addr, cp_ip.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } hash_key.id = qer_id; hash_key.cp_seid = cp_seid; /* Check QER entry is present or Not */ ret = rte_hash_lookup_data(qer_by_id_hash, &hash_key, (void **)&qer); if (ret >= 0) { /* QER Entry is present. Delete Session Entry */ ret = rte_hash_del_key(qer_by_id_hash, &hash_key); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found " "for QER_ID: %u\n", LOG_VALUE, qer_id); return -1; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"QER ID: %u\n", LOG_VALUE, qer_id); return 0; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Not Deleted entry for QER ID: %u\n", LOG_VALUE, qer_id); return 0; } int8_t add_urr_info_entry(uint32_t urr_id, urr_info_t **head, peer_addr_t cp_ip, uint64_t cp_seid) { int ret = 0; urr_info_t *urr = NULL; rule_key hash_key = {0}; hash_key.cp_ip_addr.type = cp_ip.type; if(cp_ip.type == PDN_TYPE_IPV4){ hash_key.cp_ip_addr.ip.ipv4_addr = cp_ip.ipv4.sin_addr.s_addr; }else{ memcpy(hash_key.cp_ip_addr.ip.ipv6_addr, cp_ip.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } hash_key.id = urr_id; hash_key.cp_seid = cp_seid; /* Lookup for URR entry. */ ret = rte_hash_lookup_data(urr_by_id_hash, &hash_key, (void **)&urr); if ( ret < 0) { /* allocate memory for session info*/ urr = rte_zmalloc("URR", sizeof(urr_info_t), RTE_CACHE_LINE_SIZE); if (urr == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory for URR info, Error: %s\n", LOG_VALUE, rte_strerror(abs(ret))); return -1; } /* URR Entry not present. Add URR Entry in table */ ret = rte_hash_add_key_data(urr_by_id_hash, &hash_key, urr); if (ret) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add URR entry for URR ID: %u" ",Error: %s\n", LOG_VALUE, urr_id, rte_strerror(abs(ret))); /* free allocated memory */ rte_free(urr); urr = NULL; return -1; } if (insert_urr_node(*head, urr)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add node entry in Linked List for URR ID: %u" ",Error: %s\n", LOG_VALUE, urr_id, rte_strerror(abs(ret))); } if(*head == NULL) *head = urr; }else { if(*head == NULL) *head = urr; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"URR entry add for URR ID: %u\n", LOG_VALUE, urr_id); return 0; } urr_info_t * get_urr_info_entry(uint32_t urr_id, peer_addr_t cp_ip, uint64_t cp_seid) { int ret = 0; urr_info_t *urr = NULL; rule_key hash_key = {0}; hash_key.cp_ip_addr.type = cp_ip.type; if(cp_ip.type == PDN_TYPE_IPV4){ hash_key.cp_ip_addr.ip.ipv4_addr = cp_ip.ipv4.sin_addr.s_addr; }else{ memcpy(hash_key.cp_ip_addr.ip.ipv6_addr, cp_ip.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } hash_key.id = urr_id; hash_key.cp_seid = cp_seid; /* Retireve URR entry */ ret = rte_hash_lookup_data(urr_by_id_hash, &hash_key, (void **)&urr); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found " "for URR ID: %u\n", LOG_VALUE, urr_id); return NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"URR ID: %u\n", LOG_VALUE, urr_id); return urr; } int8_t del_urr_info_entry(uint32_t urr_id, peer_addr_t cp_ip, uint64_t cp_seid) { int ret = 0; urr_info_t *urr = NULL; rule_key hash_key = {0}; hash_key.cp_ip_addr.type = cp_ip.type; if(cp_ip.type == PDN_TYPE_IPV4){ hash_key.cp_ip_addr.ip.ipv4_addr = cp_ip.ipv4.sin_addr.s_addr; }else{ memcpy(hash_key.cp_ip_addr.ip.ipv6_addr, cp_ip.ipv6.sin6_addr.s6_addr, IPV6_ADDRESS_LEN); } hash_key.id = urr_id; hash_key.cp_seid = cp_seid; /* Check URR entry is present or Not */ ret = rte_hash_lookup_data(urr_by_id_hash, &hash_key, (void **)&urr); if (ret >= 0) { /* URR Entry is present. Delete Session Entry */ ret = rte_hash_del_key(urr_by_id_hash, &hash_key); if ( ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Entry not found " "for URR ID: %u\n", LOG_VALUE, urr_id); return -1; } } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"URR ID: %u\n", LOG_VALUE, urr_id); return 0; } qer_info_t * add_rule_info_qer_hash(uint8_t *rule_name) { int ret = 0; qer_info_t *qer = NULL; pcc_rule_name rule = {0}; struct pcc_rules *pcc = NULL; struct mtr_entry *mtr = NULL; if (rule_name == NULL) return NULL; /* Fill/Copy the Rule Name */ memcpy(&rule.rname, (void *)rule_name, strnlen(((char *)rule_name), MAX_RULE_LEN)); pcc = get_predef_pcc_rule_entry(&rule, GET_RULE); if (pcc == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to GET PCC Rule in the pcc table" " for Rule_Name: %s\n", LOG_VALUE, rule.rname); return NULL; }else { if (pcc->qos.mtr_profile_index) { void *mtr_rule = NULL; ret = get_predef_rule_entry(pcc->qos.mtr_profile_index, MTR_HASH, GET_RULE, (void **)&mtr_rule); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to GET MTR Rule from the internal table" "for Mtr_Indx: %u\n", LOG_VALUE, pcc->qos.mtr_profile_index); return NULL; } else { /* Fill the QER info */ mtr = (struct mtr_entry *)mtr_rule; if (mtr != NULL) { /* allocate memory for QER info*/ qer = rte_zmalloc("QER_prdef_Info", sizeof(qer_info_t), RTE_CACHE_LINE_SIZE); if (qer == NULL){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory for QER Prdef info\n", LOG_VALUE); return NULL; } /* TODO: Handle the separate Gate Status in predef rule */ /* Generate/Set QER ID */ qer->qer_id = ++up_qer_indx_offset; /* Linked QER ID with PCC */ pcc->qer_id = qer->qer_id; /* Set UL Gate Status */ qer->gate_status.ul_gate = pcc->ul_gate_status; /* Set DL Gate Status */ qer->gate_status.dl_gate = pcc->dl_gate_status; /* Set the Uplink Max Bitrate */ qer->max_bitrate.ul_mbr = mtr->ul_mbr; /* Set the Downlink Max Bitrate */ qer->max_bitrate.dl_mbr = mtr->dl_mbr; /* Set the Uplink Guaranteed Bitrate */ qer->guaranteed_bitrate.ul_gbr = mtr->ul_gbr; /* Set the Downlink Guaranteed Bitrate */ qer->guaranteed_bitrate.dl_gbr = mtr->dl_gbr; ret = rte_hash_add_key_data(qer_rule_hash, &qer->qer_id, qer); if(ret < 0){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to add in qer_rule_hash" "for qer_id: %u\n", LOG_VALUE, qer->qer_id); return NULL; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Successfully added qer entry in qer_rule_hash for qer_id:%u\n", LOG_VALUE, qer->qer_id); return qer; } } } clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to get mtr index" "mtr_index: %u\n", LOG_VALUE, pcc->qos.mtr_profile_index); } return NULL; } void init_up_hash_tables(void) { struct rte_hash_parameters pfcp_hash_params[NUM_OF_TABLES] = { { .name = "PDR_ENTRY_HASH", .entries = UN_16_BIT_HASH_SIZE, .key_len = sizeof(rule_key), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "FAR_ENTRY_HASH", .entries = UN_16_BIT_HASH_SIZE, .key_len = sizeof(rule_key), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "QER_ENTRY_HASH", .entries = UN_16_BIT_HASH_SIZE, .key_len = sizeof(rule_key), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "URR_ENTRY_HASH", .entries = UN_16_BIT_HASH_SIZE, .key_len = sizeof(rule_key), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "SESSION_HASH", .entries = UN_16_BIT_HASH_SIZE, .key_len = sizeof(uint64_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "SESSION_DATA_HASH", .entries = UN_16_BIT_HASH_SIZE, .key_len = sizeof(uint32_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "SESSION_UEIP_HASH", .entries = MAX_HASH_SIZE, .key_len = sizeof(struct ue_ip), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "SESSION_TIMER_HASH", .entries = UN_16_BIT_HASH_SIZE, .key_len = sizeof(rule_key), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "QER_RULE_HASH", .entries = MAX_HASH_SIZE, .key_len = sizeof(uint32_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() }, { .name = "SOCK_DDFIP_HASH", .entries = MAX_HASH_SIZE, .key_len = sizeof(uint32_t), .hash_func = rte_hash_crc, .hash_func_init_val = 0, .socket_id = rte_socket_id() } }; pdr_by_id_hash = rte_hash_create(&pfcp_hash_params[0]); if (!pdr_by_id_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[0].name, rte_strerror(rte_errno), rte_errno); } far_by_id_hash = rte_hash_create(&pfcp_hash_params[1]); if (!far_by_id_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[1].name, rte_strerror(rte_errno), rte_errno); } qer_by_id_hash = rte_hash_create(&pfcp_hash_params[2]); if (!qer_by_id_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[2].name, rte_strerror(rte_errno), rte_errno); } urr_by_id_hash = rte_hash_create(&pfcp_hash_params[3]); if (!urr_by_id_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[3].name, rte_strerror(rte_errno), rte_errno); } sess_ctx_by_sessid_hash = rte_hash_create(&pfcp_hash_params[4]); if (!sess_ctx_by_sessid_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[4].name, rte_strerror(rte_errno), rte_errno); } sess_by_teid_hash = rte_hash_create(&pfcp_hash_params[5]); if (!sess_by_teid_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[5].name, rte_strerror(rte_errno), rte_errno); } sess_by_ueip_hash = rte_hash_create(&pfcp_hash_params[6]); if (!sess_by_ueip_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[6].name, rte_strerror(rte_errno), rte_errno); } timer_by_id_hash = rte_hash_create(&pfcp_hash_params[7]); if (!timer_by_id_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[7].name, rte_strerror(rte_errno), rte_errno); } qer_rule_hash = rte_hash_create(&pfcp_hash_params[8]); if (!qer_rule_hash) { rte_panic("%s: hash create failed: %s (%u)\n", pfcp_hash_params[8].name, rte_strerror(rte_errno), rte_errno); } printf("Session, Session Data, PDR, QER, URR, BAR and FAR " "hash table created successfully \n"); } /** * Generate the User-Plane SESSION ID */ uint64_t gen_up_sess_id(uint64_t cp_sess_id) { uint64_t up_sess_id = 0; up_sess_id = ((((cp_sess_id >> 32) + 1) << 32) | (cp_sess_id & 0xfffffff) ); return up_sess_id; }
nikhilc149/e-utran-features-bug-fixes
ulpc/df/include/Controller.h
<gh_stars>0 /* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ #ifndef __DF_CONTROLLER_ #define __DF_CONTROLLER_ #include "Common.h" #include "TCPListener.h" class TCPListener; class Controller { /* * @brief : Construstor of class Controller, initialises * object for TCPListener */ Controller(); /* * @brief : Destructor of class Controller, destructs * object of TCPListener */ ~Controller(); public: /* * @brief : Function to get unique instance of class Controller * @param : No parameters * @return : Returns unique instance of class Controller */ static Controller * getInstance(); /* * @brief : Function to release instance of class Controller * @param : No parameters * @return : Returns nothing */ void releaseInstance(); /* * @brief : Function to get instance of class TCPListener * @param : No parameters * @return : Returns TCPListener * */ TCPListener *getListener() { return listenerObject; } /* * @brief : Function to delete listener object * @param : No parameters * @return : Returns nothing */ Void shutdown(); /* * @brief : Function to create listener object * @param : opt, object of EGetOpt * @param : legacyIntfc, object of BaseLegacyInterface * @return : Returns nothing */ Void startUp(EGetOpt &opt, BaseLegacyInterface *legacyIntfc); /* * @brief : Function to set shutdown event * @param : No function arguments * @return : Returns void */ Void setShutdownEvent() { m_shutdown.set(); } /* * @brief : Function waits for shutdown * @param : No function arguments * @return : Returns void */ Void waitForShutdown() { m_shutdown.wait(); } private: EEvent m_shutdown; TCPListener *listenerObject; static uint8_t iRefCntr; static Controller *controller; }; void ackFromLegacy (uint32_t ack_number); void sockColseLegacy (); void sockConnLegacy (); #endif /* __DF_CONTROLLER_ */
nikhilc149/e-utran-features-bug-fixes
cp/packet_filters.c
<filename>cp/packet_filters.c /* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <rte_acl.h> #include <rte_cfgfile.h> #include "ue.h" #include "cp.h" #include "util.h" #include "gw_adapter.h" #include "packet_filters.h" #include "vepc_cp_dp_api.h" #include "predef_rule_init.h" extern pfcp_config_t config; extern int clSystemLog; const char *direction_str[] = { [TFT_DIRECTION_DOWNLINK_ONLY] = "DOWNLINK_ONLY ", [TFT_DIRECTION_UPLINK_ONLY] = "UPLINK_ONLY ", [TFT_DIRECTION_BIDIRECTIONAL] = "BIDIRECTIONAL " }; const pkt_fltr catch_all = { .direction = TFT_DIRECTION_BIDIRECTIONAL, .remote_ip_addr.s_addr = 0, .remote_ip_mask = 0, .remote_port_low = 0, .remote_port_high = UINT16_MAX, .proto = 0, .proto_mask = 0, .local_ip_addr.s_addr = 0, .local_ip_mask = 0, .local_port_low = 0, .local_port_high = UINT16_MAX, }; struct mtr_entry *mtr_profiles[METER_PROFILE_SDF_TABLE_SIZE] = { [0] = NULL, /* index = 0 is invalid */ }; struct pcc_rules *pcc_filters[PCC_TABLE_SIZE] = { [0] = NULL, /* index = 0 is invalid */ }; pkt_fltr *sdf_filters[SDF_FILTER_TABLE_SIZE] = { [0] = NULL, /* index = 0 is invalid */ }; packet_filter *packet_filters[SDF_FILTER_TABLE_SIZE] = { [0] = NULL, /* index = 0 is invalid */ }; uint16_t num_mtr_profiles; uint16_t num_packet_filters = FIRST_FILTER_ID; uint16_t num_sdf_filters = FIRST_FILTER_ID; uint16_t num_pcc_filter = FIRST_FILTER_ID; uint32_t num_adc_rules; uint32_t adc_rule_id[MAX_ADC_RULES]; uint64_t cbs; uint64_t ebs; uint16_t ulambr_idx; uint16_t dlambr_idx; /** * @brief : Converts char string to number * @param : name , char string to be converted * @return : Returns converted number */ static uint32_t name_to_num(const char *name) { /*TODO : change strlen with strnlen with proper size (n)*/ uint32_t num = 0; int i; for (i = strlen(name) - 1; i >= 0; i--) num = (num << 4) | (name[i] - 'a'); return num; } int get_packet_filter_id(const pkt_fltr *pf) { uint16_t index; for (index = FIRST_FILTER_ID; index < num_packet_filters; ++index) { if (!memcmp(pf, &packet_filters[index]->pkt_fltr, sizeof(pkt_fltr))) return index; } return -ENOENT; } uint8_t get_packet_filter_direction(uint16_t index) { return packet_filters[index]->pkt_fltr.direction; } packet_filter * get_packet_filter(uint16_t index) { if (unlikely(index >= num_packet_filters)) return NULL; return packet_filters[index]; } void reset_packet_filter(pkt_fltr *pf) { memcpy(pf, &catch_all, sizeof(pkt_fltr)); } int meter_profile_index_get(uint64_t cir) { int index; uint64_t CIR = cir >> 3; /* Convert bit rate into bytes */ for (index = 0; index < num_mtr_profiles; index++) { if (mtr_profiles[index]->mtr_param.cir == CIR) return mtr_profiles[index]->mtr_profile_index; } return 0; } void push_sdf_rules(uint16_t index) { struct dp_id dp_id = { .id = DPN_ID }; char local_ip[INET_ADDRSTRLEN]; char remote_ip[INET_ADDRSTRLEN]; snprintf(local_ip, sizeof(local_ip), "%s", inet_ntoa(sdf_filters[index]->local_ip_addr)); snprintf(remote_ip, sizeof(remote_ip), "%s", inet_ntoa(sdf_filters[index]->remote_ip_addr)); struct pkt_filter pktf = { .rule_id = index }; if (sdf_filters[index]->direction & TFT_DIRECTION_DOWNLINK_ONLY) { snprintf(pktf.u.rule_str, MAX_LEN, "%s/%"PRIu8" %s/%"PRIu8 " %"PRIu16" : %"PRIu16" %"PRIu16" : %"PRIu16 " 0x%"PRIx8"/0x%"PRIx8"\n", remote_ip, sdf_filters[index]->remote_ip_mask, local_ip, sdf_filters[index]->local_ip_mask, ntohs(sdf_filters[index]->remote_port_low), ntohs(sdf_filters[index]->remote_port_high), ntohs(sdf_filters[index]->local_port_low), ntohs(sdf_filters[index]->local_port_high), sdf_filters[index]->proto, sdf_filters[index]->proto_mask); if (sdf_filters[index]->direction == TFT_DIRECTION_BIDIRECTIONAL) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Ignoring uplink portion of packet " "filter for now\n", LOG_VALUE); } else if (sdf_filters[index]->direction & TFT_DIRECTION_UPLINK_ONLY) { snprintf(pktf.u.rule_str, MAX_LEN, "%s/%"PRIu8" %s/%"PRIu8" %" PRIu16" : %"PRIu16" %"PRIu16" : %"PRIu16" 0x%" PRIx8"/0x%"PRIx8"\n", local_ip, sdf_filters[index]->local_ip_mask, remote_ip, sdf_filters[index]->remote_ip_mask, ntohs(sdf_filters[index]->local_port_low), ntohs(sdf_filters[index]->local_port_high), ntohs(sdf_filters[index]->remote_port_low), ntohs(sdf_filters[index]->remote_port_high), sdf_filters[index]->proto, sdf_filters[index]->proto_mask); } clLog(clSystemLog, eCLSeverityDebug,LOG_FORMAT"Installing %s pkt_filter #%"PRIu16" : %s", LOG_VALUE, direction_str[sdf_filters[index]->direction], index, pktf.u.rule_str); if (sdf_filter_entry_add(dp_id, pktf) < 0) rte_exit(EXIT_FAILURE,"SDF filter entry add fail !!!"); } /** * @brief : Initialize meter profiles * @param : No param * @return : Returns nothing */ static void init_mtr_profile(void) { unsigned no_of_idx = 0; unsigned i = 0; struct rte_cfgfile *file = rte_cfgfile_load(METER_PROFILE_FILE, 0); const char *entry; // struct dp_id dp_id = { .id = DPN_ID }; if (file == NULL) rte_panic("Cannot load configuration file %s\n", METER_PROFILE_FILE); entry = rte_cfgfile_get_entry(file, "GLOBAL", "NUM_OF_IDX"); if (!entry) rte_panic("Invalid metering index\n"); no_of_idx = atoi(entry); for (i = 1; i <= no_of_idx; ++i) { char sectionname[64]; struct mtr_entry mtr_entry = {0}; snprintf(sectionname, sizeof(sectionname), "ENTRY_%u", i); entry = rte_cfgfile_get_entry(file, sectionname, "CIR"); if (!entry) rte_panic("Invalid CIR configuration\n"); mtr_entry.mtr_param.cir = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "CBS"); if (!entry) rte_panic("Invalid CBS configuration\n"); mtr_entry.mtr_param.cbs = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "EBS"); if (!entry) rte_panic("Invalid EBS configuration\n"); mtr_entry.mtr_param.ebs = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "UL_MBR"); if (!entry) rte_panic("Invalid UL_MBR configuration\n"); mtr_entry.ul_mbr = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "DL_MBR"); if (!entry) rte_panic("Invalid DL_MBR configuration\n"); mtr_entry.dl_mbr = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "UL_GBR"); if (entry) mtr_entry.ul_gbr = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "DL_GBR"); if (entry) mtr_entry.dl_gbr = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "UL_AMBR"); if (entry) mtr_entry.ul_ambr = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "DL_AMBR"); if (entry) mtr_entry.dl_ambr = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "MTR_PROFILE_IDX"); if (!entry) rte_panic("Invalid MTR_PROFILE_IDX configuration\n"); mtr_entry.mtr_profile_index = atoi(entry); int ret = 0; ret = get_predef_rule_entry(mtr_entry.mtr_profile_index, MTR_HASH, ADD_RULE, (void **)&mtr_entry); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to add Meter Rule in the internal table, MTR_Indx:%u\n", LOG_VALUE, mtr_entry.mtr_profile_index); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"MTR Rule Added in the internal table," "Rule_Index:%u\n", LOG_VALUE, mtr_entry.mtr_profile_index); } } if (file != NULL) { rte_cfgfile_close(file); file = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "%s file operation is successfully performed\n", LOG_VALUE, METER_PROFILE_FILE); } } /** * @brief : checks for ip address validity * @param : entry , string contating the ip address * @param : type, specifies whether ipv4 or ipv6 * @return : Returns 0 on success and -1 on failure */ static int validate_ip_address(const char *entry, uint8_t type) { if(IPV4_ADDR_TYPE == type){ if(strchr(entry, ':') != NULL){ return -1; } } else { if(strchr(entry, '.') != NULL){ return -1; } } return 0; } /** * @brief : Initialize sdf rules * @param : No param * @return : Returns nothing */ static void init_sdf_rules(void) { unsigned num_sdf_rules = 0; unsigned i = 0; const char *entry = NULL; struct rte_cfgfile *file = rte_cfgfile_load(SDF_RULE_FILE, 0); if (NULL == file) rte_panic("Cannot load configuration file %s\n", SDF_RULE_FILE); entry = rte_cfgfile_get_entry(file, "GLOBAL", "NUM_SDF_FILTERS"); if (!entry) rte_panic("Invalid sdf configuration file format\n"); num_sdf_rules = atoi(entry); for (i = 1; i <= num_sdf_rules; ++i) { char sectionname[64] = {0}; int ret = 0; struct in_addr tmp_addr; pkt_fltr pf; reset_packet_filter(&pf); snprintf(sectionname, sizeof(sectionname), "SDF_FILTER_%u", i); entry = rte_cfgfile_get_entry(file, sectionname, "DIRECTION"); if (entry) { if (strcmp(entry, "bidirectional") == 0){ pf.direction = TFT_DIRECTION_BIDIRECTIONAL; } else if (strcmp(entry, "uplink_only") == 0) pf.direction = TFT_DIRECTION_UPLINK_ONLY; else if (strcmp(entry, "downlink_only") == 0) pf.direction = TFT_DIRECTION_DOWNLINK_ONLY; else rte_panic("Invalid SDF direction. Supported : uplink_only," "downlink_only\n"); } entry = rte_cfgfile_get_entry(file, sectionname, "IPV4_REMOTE"); if (entry) { if (validate_ip_address(entry, IPV4_ADDR_TYPE) == 0){ if (inet_aton(entry, &pf.remote_ip_addr) == 0) rte_panic("Invalid address %s in section %s " "sdf config file %s\n", entry, sectionname, SDF_RULE_FILE); pf.v4 = PRESENT; } else{ rte_panic("Invalid ip address given for ipv4 \n"); } } else { entry = rte_cfgfile_get_entry(file, sectionname, "IPV6_REMOTE"); if (entry) { if(validate_ip_address(entry, IPV6_ADDR_TYPE) == 0){ if (inet_pton(AF_INET6, entry, &pf.remote_ip6_addr) == 0) rte_panic("Invalid address %s in section %s " "sdf config file %s\n", entry, sectionname, SDF_RULE_FILE); pf.v6 = PRESENT; } else { rte_panic("Invalid ip address given for ipv6\n"); } } } if(pf.v4 == PRESENT){ entry = rte_cfgfile_get_entry(file, sectionname, "IPV4_REMOTE_MASK"); if (entry) { ret = inet_aton(entry, &tmp_addr); if (ret == 0 || __builtin_clzl(~tmp_addr.s_addr) + __builtin_ctzl(tmp_addr.s_addr) != 32){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid address %s in section %s " "sdf config file %s. Setting to default 32.\n", LOG_VALUE, entry, sectionname, SDF_RULE_FILE); pf.remote_ip_mask = 32; } else pf.remote_ip_mask = __builtin_popcountl(tmp_addr.s_addr); } } else { entry = rte_cfgfile_get_entry(file, sectionname, "IPV6_REMOTE_MASK"); if (entry) { pf.remote_ip_mask = (uint16_t) atoi(entry); if(pf.remote_ip_mask == 0 || pf.remote_ip_mask > DEFAULT_IPV6_MASK) pf.remote_ip_mask = DEFAULT_IPV6_MASK; } } entry = rte_cfgfile_get_entry(file, sectionname, "REMOTE_LOW_LIMIT_PORT"); if (entry) pf.remote_port_low = htons((uint16_t) atoi(entry)); entry = rte_cfgfile_get_entry(file, sectionname, "REMOTE_HIGH_LIMIT_PORT"); if (entry) pf.remote_port_high = htons((uint16_t) atoi(entry)); entry = rte_cfgfile_get_entry(file, sectionname, "PROTOCOL"); if (entry) { pf.proto = atoi(entry); pf.proto_mask = UINT8_MAX; } else { /* Validate Protocol is set or not */ rte_panic("ERROR: PROTOCOL type field is not configured in SDF Rule," " Check the configured rules in sdf_rules.cfg file..!!\n\n"); } if(pf.v4 == PRESENT){ entry = rte_cfgfile_get_entry(file, sectionname, "IPV4_LOCAL"); if (entry) { if(validate_ip_address(entry, IPV4_ADDR_TYPE) == 0){ if (inet_aton(entry, &pf.local_ip_addr) == 0) rte_panic("Invalid address %s in section %s " "sdf config file %s\n", entry, sectionname, SDF_RULE_FILE); } else{ rte_panic("Invalid ip address for IPV4 \n"); } } else { rte_panic("Invalid ip address\n"); } } else { entry = rte_cfgfile_get_entry(file, sectionname, "IPV6_LOCAL"); if (entry) { if(validate_ip_address(entry, IPV6_ADDR_TYPE) == 0){ if (inet_pton(AF_INET6, entry, &pf.local_ip6_addr) == 0) rte_panic("Invalid address %s in section %s " "sdf config file %s\n", entry, sectionname, SDF_RULE_FILE); } else { rte_panic("Invalid ip address for ipv6 \n"); } } else{ rte_panic("Invalid ip address \n"); } } if(pf.v4 == PRESENT){ entry = rte_cfgfile_get_entry(file, sectionname, "IPV4_LOCAL_MASK"); if (entry) { ret = inet_aton(entry, &tmp_addr); if (ret == 0 || __builtin_clzl(~tmp_addr.s_addr) + __builtin_ctzl(tmp_addr.s_addr) != 32){ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Invalid address %s in section %s " "sdf config file %s. Setting to default 32.\n", LOG_VALUE, entry, sectionname, SDF_RULE_FILE); pf.remote_ip_mask = 32; } else pf.local_ip_mask = __builtin_popcountl(tmp_addr.s_addr); } } else { entry = rte_cfgfile_get_entry(file, sectionname, "IPV6_LOCAL_MASK"); if (entry) { pf.local_ip_mask = (uint16_t) atoi(entry); if(pf.local_ip_mask == 0 || pf.local_ip_mask > DEFAULT_IPV6_MASK) pf.local_ip_mask = DEFAULT_IPV6_MASK; } } entry = rte_cfgfile_get_entry(file, sectionname, "LOCAL_LOW_LIMIT_PORT"); if (entry) pf.local_port_low = htons((uint16_t) atoi(entry)); entry = rte_cfgfile_get_entry(file, sectionname, "LOCAL_HIGH_LIMIT_PORT"); if (entry) pf.local_port_high = htons((uint16_t) atoi(entry)); /* Sotred the SDF rules in centralized location by sdf_index */ ret = get_predef_rule_entry(i, SDF_HASH, ADD_RULE, (void **)&pf); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to add SDF Rule in the internal table\n", LOG_VALUE); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"SDF Rule Added in the internal table," "Rule_Index: %u\n", LOG_VALUE, i); } } if (file != NULL) { rte_cfgfile_close(file); file = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "%s file operation is successfully performed\n", LOG_VALUE, SDF_RULE_FILE); } } /** * @brief : Initialize pcc rules * @param : No param * @return : Returns nothing */ static void init_pcc_rules(void) { unsigned num_pcc_rules = 0; unsigned i = 0; const char *entry = NULL; struct rte_cfgfile *file = rte_cfgfile_load(PCC_RULE_FILE, 0); if (NULL == file) rte_panic("Cannot load configuration file %s\n", PCC_RULE_FILE); entry = rte_cfgfile_get_entry(file, "GLOBAL", "NUM_PCC_FILTERS"); if (!entry) rte_panic("Invalid pcc configuration file format\n"); num_pcc_rules = atoi(entry); for (i = 1; i <= num_pcc_rules; ++i) { char sectionname[64] = {0}; struct pcc_rules tmp_pcc = {0}; pcc_rule_name key = {0}; memset(key.rname, '\0', sizeof(key.rname)); snprintf(sectionname, sizeof(sectionname), "PCC_FILTER_%u", i); entry = rte_cfgfile_get_entry(file, sectionname, "RULE_NAME"); if (entry) { strncpy(tmp_pcc.rule_name, entry, sizeof(tmp_pcc.rule_name)); strncpy(key.rname, entry, sizeof(key.rname)); } entry = rte_cfgfile_get_entry(file, sectionname, "RATING_GROUP"); if (!entry) rte_panic( "Invalid pcc configuration file format - " "each filter must contain RATING_GROUP entry\n"); tmp_pcc.rating_group = atoi(entry); if(0 == tmp_pcc.rating_group) { tmp_pcc.rating_group = name_to_num(entry); } entry = rte_cfgfile_get_entry(file, sectionname, "SERVICE_ID"); if (entry) { tmp_pcc.service_id = atoi(entry); if(0 == tmp_pcc.service_id) tmp_pcc.service_id = name_to_num(entry); } entry = rte_cfgfile_get_entry(file, sectionname, "RULE_STATUS"); if (entry) tmp_pcc.rule_status = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "UL_GATE_STATUS"); if (entry) tmp_pcc.ul_gate_status = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "DL_GATE_STATUS"); if (entry) tmp_pcc.dl_gate_status = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "SESSION_CONT"); if (entry) tmp_pcc.session_cont = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "REPORT_LEVEL"); if (entry) tmp_pcc.report_level = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "CHARGING_MODE"); if (entry) tmp_pcc.charging_mode = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "METERING_METHOD"); if (entry) tmp_pcc.metering_method = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "MUTE_NOTIFY"); if (entry) tmp_pcc.mute_notify = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "MONITORING_KEY"); if (entry) tmp_pcc.monitoring_key = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "SPONSOR_ID"); if (entry) strncpy(tmp_pcc.sponsor_id, entry, sizeof(tmp_pcc.sponsor_id)); entry = rte_cfgfile_get_entry(file, sectionname, "REDIRECT_INFO"); if (entry) tmp_pcc.redirect_info.info = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "PRECEDENCE"); if (entry) tmp_pcc.precedence = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "DROP_PKT_COUNT"); if (entry) tmp_pcc.drop_pkt_count = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "ONLINE"); if (entry) tmp_pcc.online = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "OFFLINE"); if (entry) tmp_pcc.offline = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "FLOW_STATUS"); if (entry) tmp_pcc.flow_status = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "QoS_CLASS_IDENTIFIER"); if (entry) tmp_pcc.qos.qci = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "PRIORITY_LEVEL"); if (entry) tmp_pcc.qos.arp.priority_level = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "PRE_EMPTION_CAPABILITY"); if (entry) tmp_pcc.qos.arp.pre_emption_capability = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "PRE_EMPTION_VULNERABILITY"); if (entry) tmp_pcc.qos.arp.pre_emption_vulnerability = atoi(entry); entry = rte_cfgfile_get_entry(file, sectionname, "MTR_PROFILE_IDX"); if (!entry) rte_panic("Invalid MTR_PROFILE_IDX configuration\n"); tmp_pcc.qos.mtr_profile_index = atoi(entry); /** Read mapped ADC or SDF rules. Either ADC or SDF rules will be * present, not both. SDF count will be 0 if ADC rules are present.*/ tmp_pcc.sdf_idx_cnt = 0; entry = rte_cfgfile_get_entry(file, sectionname, "ADC_FILTER_IDX"); if (!entry) { /*No ADC entry, so check for SDF entry*/ entry = rte_cfgfile_get_entry(file, sectionname, "SDF_FILTER_IDX"); if (!entry) rte_panic("Missing SDF or ADC rule for PCC rule %d\n",i); char *next = NULL; uint16_t sdf_cnt = 0; /*SDF entries format : "1, 2: 10, 30"*/ for(int x=0; x < MAX_SDF_IDX_COUNT; ++x) { errno = 0; int sdf_idx = strtol(entry, &next, 10); if (errno != 0) { perror("strtol"); rte_panic("Invalid SDF index value\n"); } if('\0' == *entry) break; /*If non number e.g.',', then ignore and continue*/ if(entry == next && (0 == sdf_idx)){ entry = ++next; continue; } entry = next; tmp_pcc.sdf_idx[sdf_cnt++] = sdf_idx; } tmp_pcc.sdf_idx_cnt = sdf_cnt; } else { char *next = NULL; uint16_t adc_cnt = 0; /* ADC entries format : "1, 2: 10, 30"*/ for(int x=0; x < MAX_ADC_IDX_COUNT; ++x) { errno = 0; int adc_idx = strtol(entry, &next, 10); if (errno != 0) { perror("strtol"); rte_panic("Invalid ADC index value\n"); } if('\0' == *entry) break; /*If non number e.g.',', then ignore and continue*/ if(entry == next && (0 == adc_idx)){ entry = ++next; continue; } entry = next; tmp_pcc.adc_idx[adc_cnt++] = adc_idx; } tmp_pcc.adc_idx_cnt = adc_cnt; } /* Stored the PCC rule in centralized location by using Rule Name*/ struct pcc_rules *pcc = NULL; pcc = get_predef_pcc_rule_entry(&key, ADD_RULE); if (pcc != NULL) { memcpy(pcc, &tmp_pcc, sizeof(struct pcc_rules)); /* Add PCC rule name in centralized location to dump rules on UP*/ rules_struct *rule = NULL; rule = get_map_rule_entry(config.pfcp_ip.s_addr, ADD_RULE); if (rule != NULL) { if (rule->rule_cnt != 0) { rules_struct *new_node = NULL; /* Calculate the memory size to allocate */ uint16_t size = sizeof(rules_struct); /* allocate memory for rule entry*/ new_node = rte_zmalloc("Rules_Infos", size, RTE_CACHE_LINE_SIZE); if (new_node == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory for rule entry.\n", LOG_VALUE); return; } /* Set/Stored the rule name in the centralized location */ memcpy(new_node->rule_name.rname, key.rname, sizeof(key.rname)); /* Insert the node into the LL */ if (insert_rule_name_node(rule, new_node) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to add node entry in LL\n", LOG_VALUE); return; } }else { /* Set/Stored the rule name in the centralized location */ memcpy(rule->rule_name.rname, key.rname, sizeof(key.rname)); rule->rule_cnt++; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"PCC Rule add/inserted in the internal table and map," "Rule_Name: %s, Node_Count:%u\n", LOG_VALUE, key.rname, rule->rule_cnt); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to add PCC Rule in the centralized map table\n", LOG_VALUE); } } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to add PCC Rule in the internal table\n", LOG_VALUE); } } if (file != NULL) { rte_cfgfile_close(file); file = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "%s file operation is successfully performed\n", LOG_VALUE, PCC_RULE_FILE); } num_pcc_filter = FIRST_FILTER_ID; /*Reset num_pcc_filter*/ } void init_packet_filters(void) { /* init pcc rule tables on dp*/ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Reading predefined PCC rules\n", LOG_VALUE); init_pcc_rules(); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Reading predefined pcc rules completed\n", LOG_VALUE); /* init dpn meter profile table before configuring pcc/adc rules*/ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Reading predefined meter rules\n", LOG_VALUE); init_mtr_profile(); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Reading predefined meter rules completed\n", LOG_VALUE); /* init dpn sdf rules table configuring on dp*/ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Reading predefined sdf rules\n", LOG_VALUE); init_sdf_rules(); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Reading predefined sdf rules completed\n", LOG_VALUE); } /** * @brief : Prints adc rule info * @param : adc_rule, rule info to be printed * @return : Returns nothing */ static void print_adc_rule(struct adc_rules adc_rule) { clLog(clSystemLog, eCLSeverityDebug,"%-8u ", adc_rule.rule_id); switch (adc_rule.sel_type) { case DOMAIN_IP_ADDR: clLog(clSystemLog, eCLSeverityDebug,"%-10s " IPV4_ADDR, "IP", IPV4_ADDR_HOST_FORMAT(adc_rule.u.domain_ip.u.ipv4_addr)); break; case DOMAIN_IP_ADDR_PREFIX: clLog(clSystemLog, eCLSeverityDebug,"%-10s " IPV4_ADDR"/%d ", "IP_PREFIX", IPV4_ADDR_HOST_FORMAT(adc_rule.u.domain_prefix.ip_addr.u.ipv4_addr), adc_rule.u.domain_prefix.prefix); break; case DOMAIN_NAME: clLog(clSystemLog, eCLSeverityDebug,"%-10s %-35s ", "DOMAIN", adc_rule.u.domain_name); break; default: clLog(clSystemLog, eCLSeverityCritical,LOG_FORMAT"ERROR IN ADC RULE", LOG_VALUE); } } void parse_adc_rules(void) { unsigned num_adc_rules = 0; unsigned i = 0; uint32_t rule_id = 1; const char *entry = NULL; //struct dp_id dp_id = { .id = DPN_ID }; struct rte_cfgfile *file = rte_cfgfile_load(ADC_RULE_FILE, 0); if (file == NULL) rte_panic("Cannot load configuration file %s\n", ADC_RULE_FILE); entry = rte_cfgfile_get_entry(file, "GLOBAL", "NUM_ADC_RULES"); if (!entry) rte_panic("Invalid adc configuration file format\n"); num_adc_rules = atoi(entry); for (i = 1; i <= num_adc_rules; ++i) { char sectionname[64] = {0}; struct adc_rules tmp_adc = { 0 }; struct in_addr addr; snprintf(sectionname, sizeof(sectionname), "ADC_RULE_%u", i); entry = rte_cfgfile_get_entry(file, sectionname, "ADC_TYPE"); if (!entry) rte_panic("Invalid ADC TYPE configuration file format\n"); tmp_adc.sel_type = atoi(entry); switch (tmp_adc.sel_type) { case DOMAIN_NAME: entry = rte_cfgfile_get_entry(file, sectionname, "DOMAIN"); if(entry) strncpy(tmp_adc.u.domain_name, entry, sizeof(tmp_adc.u.domain_name)); break; case DOMAIN_IP_ADDR: entry = rte_cfgfile_get_entry(file, sectionname, "IP"); if (entry) { inet_aton(entry, &addr); tmp_adc.u.domain_ip.u.ipv4_addr = ntohl(addr.s_addr); tmp_adc.u.domain_ip.iptype = IPTYPE_IPV4; } break; case DOMAIN_IP_ADDR_PREFIX: entry = rte_cfgfile_get_entry(file, sectionname, "IP"); if (entry) { inet_aton(entry, &addr); tmp_adc.u.domain_ip.u.ipv4_addr = ntohl(addr.s_addr); tmp_adc.u.domain_ip.iptype = IPTYPE_IPV4; } entry = rte_cfgfile_get_entry(file, sectionname, "PREFIX"); if (entry) tmp_adc.u.domain_prefix.prefix = atoi(entry); break; default: rte_exit(EXIT_FAILURE, "Unexpected ADC TYPE : %d\n", tmp_adc.sel_type); } /* Add Default rule */ adc_rule_id[rule_id - 1] = rule_id; tmp_adc.rule_id = rule_id++; int ret = 0; ret = get_predef_rule_entry(tmp_adc.rule_id, ADC_HASH, ADD_RULE, (void **)&tmp_adc); if (ret < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error: Failed to add ADC Rule in the internal table\n", LOG_VALUE); } else { print_adc_rule(tmp_adc); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ADC Rule Added in the internal table, ADC_Indx:%u\n", LOG_VALUE, tmp_adc.rule_id); } //if (adc_entry_add(dp_id, tmp_adc) < 0) // rte_exit(EXIT_FAILURE, "ADC entry add fail !!!"); //print_adc_rule(tmp_adc); } if (file != NULL) { rte_cfgfile_close(file); file = NULL; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT "%s file operation is successfully performed\n", LOG_VALUE, ADC_RULE_FILE); } num_adc_rules = rule_id - 1; }
nikhilc149/e-utran-features-bug-fixes
cp/ipc_api.c
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "cp_app.h" #include "ipc_api.h" int create_ipc_channel( void ) { /* STREAM - BiDirectional DATAGRAM - uniDirectional */ int sock ; /* Unix Socket Creation and Verification */ sock = socket( AF_UNIX, SOCK_STREAM, 0); if ( sock == -1 ){ fprintf(stderr,"%s: Unix socket creation failed. Error:%s\n", __func__, strerror(errno)); return -1; } return sock; } int connect_to_ipc_channel(int sock, struct sockaddr_un sock_addr, const char *path) { int rc = 0; socklen_t len = LENGTH; sock_addr.sun_family = AF_UNIX; chmod( path, 755 ); strncpy(sock_addr.sun_path, path, sizeof(sock_addr.sun_path)); rc = connect( sock, (struct sockaddr *) &sock_addr, len); if ( rc == -1) { fprintf(stderr, "%s: Could not connect to socket. Error: %s\n", __func__, strerror(errno)); close_ipc_channel( sock ); } return rc; } void bind_ipc_channel(int sock, struct sockaddr_un sock_addr,const char *path) { int rc = 0; /* Assign specific permission to path file read, write and executable */ chmod( path, 755 ); /* Assign Socket family and PATH */ sock_addr.sun_family = AF_UNIX; strncpy(sock_addr.sun_path, path, strnlen(path,MAX_PATH_LEN)); /* Remove the symbolic link of path names */ unlink(path); /* Bind the new created socket to given PATH and verification */ rc = bind( sock, (struct sockaddr *) &sock_addr, LENGTH); if( rc != 0 ){ close_ipc_channel(sock); printf("%s: Could not bind to socket. Error: %s\n", __func__, strerror(errno)); /*Greacefull Exit*/ exit(0); } } int accept_from_ipc_channel(int sock, struct sockaddr_un sock_addr) { int client_sock = 0; socklen_t len ; len = sizeof(sock_addr); while (1) { /* Accept incomming connection request receive on socket */ client_sock = accept( sock, (struct sockaddr *) &sock_addr, &len); if (client_sock < 0){ if (errno == EINTR) continue; close_ipc_channel(sock); printf("%s: Could not accept socket connection." "Error: %s\n", __func__,strerror(errno)); } else { break; } } return client_sock; } void listen_ipc_channel( int sock ) { /* Mark the socket as a passive socket to accept incomming connections */ if( listen(sock, BACKLOG) == -1){ close_ipc_channel(sock); printf("%s: Socket Listen failed error: %s\n", __func__, strerror(errno)); /* Greacefull Exit */ exit(0); } } void get_peer_name(int sock, struct sockaddr_un sock_addr) { socklen_t len = LENGTH; if( getpeername( sock, (struct sockaddr *) &sock_addr, &len) == -1) { if(errno != EINTR) { fprintf(stderr, "%s: Socket getpeername failed error: %s\n", __func__, strerror(errno)); close_ipc_channel(sock); /* Greacefull Exit */ exit(0); } } else { fprintf(stderr, "CP: Gx_app client socket path %s...!!!\n",sock_addr.sun_path); } } int recv_from_ipc_channel(int sock, char *buf) { int bytes_recv = 0; bytes_recv = recv(sock, buf, BUFFSIZE, 0 ) ; if ( bytes_recv <= 0 ){ if(errno != EINTR){ fprintf(stderr, "%s: Socket recv failed error: %s\n", __func__, strerror(errno)); close_ipc_channel(sock); /* Greacefull Exit */ exit(0); } } return bytes_recv; } int send_to_ipc_channel(int sock, uint8_t *buf, int len) { int rc = 0; if ((rc = send(sock, buf, len, 0)) <= 0){ if(errno != EINTR){ fprintf(stderr, "%s: Socket send failed error: %s\n", __func__, strerror(errno)); close_ipc_channel(sock); /* Greacefull Exit */ exit(0); } } return rc; } void close_ipc_channel(int sock) { /* Closed unix socket */ close(sock); }
nikhilc149/e-utran-features-bug-fixes
ulpc/d_df/include/Common.h
<filename>ulpc/d_df/include/Common.h /* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ #ifndef __COMMON_H_ #define __COMMON_H_ #include <sys/types.h> #include <sys/time.h> #include <sys/stat.h> #include <sys/statvfs.h> #include <netinet/ip.h> #include <linux/ipv6.h> #include <netinet/udp.h> #include <netinet/if_ether.h> #include <fstream> #include <vector> #include "epctools.h" #include "esocket.h" #include "elogger.h" #include "emgmt.h" #include "efd.h" #define TRUE 1 #define DDF2 "DDF2" #define DDF3 "DDF3" #define PAYLOAD_MAX_LENGTH 4098 #define RET_SUCCESS 0 #define RET_FAILURE 1 #define DATA_TYPE 0 #define EVENT_TYPE 1 #define DEBUG_DATA 1 #define FORWARD_DATA 2 #define BOTH_FW_DG 3 #define TTL 64 #define ETHER_TYPE 0x0800 #define ETHER_TYPE_V6 0x86DD #define IPV4_VERSION 4 #define IPV6_VERSION 6 #define INTERNET_HDR_LEN 5 #define UDP_CHECKSUM 0 #define UDP_CHECKSUM_IPV6 1 #define DDFPACKET_ACK 0xee #define DFPACKET_ACK 0xff #define DF_CONNECT_TIMER_VALUE 10000 #define BACKLOG_CONNECTIION 10 #define SEND_BUF_SIZE 4096 #define IPV6_ADDRESS_LEN 16 #define IPTYPE_IPV4 0 #define IPTYPE_IPV6 1 #define LOG_AUDIT 3 #define LOG_SYSTEM 3 #define LOG_TEST3 3 #define LOG_TEST3_SINKSET 3 #define __file__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) /* * @brief : Maintains data related to DDF packet received from CP/DP */ #pragma pack(push, 1) typedef struct DdfPacket { uint32_t packetLength; struct PacketHeader { uint8_t typeOfPayload; uint64_t liIdentifier; uint64_t imsiNumber; uint8_t srcIpType; uint32_t sourceIpAddress; uint8_t srcIpv6[IPV6_ADDRESS_LEN]; uint16_t sourcePort; uint8_t dstIpType; uint32_t destIpAddress; uint8_t dstIpv6[IPV6_ADDRESS_LEN]; uint16_t destPort; uint8_t operationMode; uint32_t sequenceNumber; uint32_t dataLength; } header; uint8_t data[0]; } DdfPacket_t; #pragma pack(pop) /* * @brief : Maintains data related to acknowledgement packet */ #pragma pack(push, 1) typedef struct AckPacket { uint8_t packetLength; struct AckPacketHeader { uint8_t packetType; uint32_t sequenceNumber; } header; } AckPacket_t; #pragma pack(pop) /* * @brief : Maintains data to be sent to DF */ #pragma pack(push, 1) typedef struct DfPacket { uint32_t packetLength; struct PacketHeader { uint32_t sequenceNumber; uint64_t liIdentifier; uint64_t imsiNumber; uint32_t dataLength; } header; uint8_t data[0]; } DfPacket_t; #pragma pack(pop) /* * @brief : Maintains data related to configurations required in DDFx */ struct Configurations { std::string strDModuleName; cpStr ddf_ip; UShort ddf_port; cpStr df_ip; UShort df_port; std::string strDFilePath; std::string strDirName; }; #endif /* __COMMON_H_ */
nikhilc149/e-utran-features-bug-fixes
dp/pipeline/epc_arp.c
/* * Copyright (c) 2017 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <unistd.h> #include <arpa/inet.h> #include <time.h> #include <rte_common.h> #include <rte_malloc.h> #include <rte_lcore.h> #include <rte_ip.h> #include <rte_byteorder.h> #include <rte_table_lpm.h> #include <rte_table_hash.h> #include <rte_pipeline.h> #include <rte_arp.h> #include <rte_icmp.h> #include <rte_hash.h> #include <rte_jhash.h> #include <rte_port_ring.h> #include <rte_table_stub.h> #include <rte_mbuf.h> #include <rte_ring.h> #include <rte_errno.h> #include <rte_log.h> #include <rte_ethdev.h> #include <rte_port_ethdev.h> #include <rte_kni.h> #ifdef STATIC_ARP #include <rte_cfgfile.h> #endif /* STATIC_ARP */ /* VS: Routing Discovery */ #include <fcntl.h> #include "linux/netlink.h" #include "linux/rtnetlink.h" #include "net/if.h" #include "net/if_arp.h" #include "sys/ioctl.h" #include "net/route.h" #include "util.h" #include "gtpu.h" #include "ipv4.h" #include "ipv6.h" #include "stats.h" #include "up_main.h" #include "epc_arp.h" #include "pfcp_util.h" #include "epc_packet_framework.h" #ifdef use_rest #include "../rest_timer/gstimer.h" #endif /* use_rest */ #include "li_interface.h" #ifdef DP_BUILD #include "gw_adapter.h" #endif #include "pfcp_enum.h" #ifdef STATIC_ARP #define STATIC_ARP_FILE "../config/static_arp.cfg" #endif /* STATIC_ARP */ #if (RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN) /* x86 == little endian * network == big endian */ #define CHECK_ENDIAN_16(x) rte_be_to_cpu_16(x) #define CHECK_ENDIAN_32(x) rte_be_to_cpu_32(x) #else #define CHECK_ENDIAN_16(x) (x) #define CHECK_ENDIAN_32(x) (x) #endif /** * no. of mbuf. */ #define NB_ARP_MBUF 1024 /** * ipv4 version */ #define IP_VERSION_4 0x40 /** * default IP header length == five 32-bits words. */ #define IP_HDRLEN 0x05 /** * header def. */ #define IP_VHL_DEF (IP_VERSION_4 | IP_HDRLEN) /** * check multicast ipv4 address. */ #define is_multicast_ipv4_addr(ipv4_addr) \ (((rte_be_to_cpu_32((ipv4_addr)) >> 24) & 0x000000FF) == 0xE0) /** * pipeline port out action handler */ #define PIPELINE_PORT_OUT_AH(f_ah, f_pkt_work, f_pkt4_work) \ static int \ f_ah( \ struct rte_mbuf *pkt, \ uint64_t *pkts_mask, \ void *arg) \ { \ f_pkt4_work(pkt, arg); \ f_pkt_work(pkt, arg); \ int i = *pkts_mask; i++; \ return 0; \ } /** * pipeline port out bulk action handler */ #define PIPELINE_PORT_OUT_BAH(f_ah, f_pkt_work, f_pkt4_work) \ static int \ f_ah( \ struct rte_mbuf **pkt, \ uint64_t *pkts_mask, \ void *arg) \ { \ f_pkt4_work(*pkt, arg); \ f_pkt_work(*pkt, arg); \ int i = *pkts_mask; i++; \ return 0; \ } struct kni_port_params *kni_port_params_array[RTE_MAX_ETHPORTS]; /** * VS: Routing Discovery */ #define NETMASK ntohl(4294967040) #define TABLE_SIZE (8192 * 4) #define ERR_RET(x) do { perror(x); return EXIT_FAILURE; } while (0); /** * VS: Get Local arp table entry */ #define ARP_CACHE "/proc/net/arp" #define ARP_BUFFER_LEN 1024 #define ARP_DELIM " " #define BUFFER_SIZE 4096 /* VS: buffers */ char ipAddr[128]; char gwAddr[128]; char netMask[128]; int route_sock_v4 = -1; int route_sock_v6 = -1; int gatway_flag = 0; extern int clSystemLog; extern struct rte_hash *conn_hash_handle; struct addr_info { struct sockaddr_nl addr_ipv4; struct sockaddr_nl addr_ipv6; }; /** * @brief : Structure for sending the request */ struct route_request_t { struct nlmsghdr nlMsgHdr; struct rtmsg rtMsg; char buf[4096]; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); typedef struct route_request_t route_request; /** * @brief : Structure for storing routes */ struct RouteInfo { uint32_t dstAddr; uint32_t mask; uint32_t gateWay; uint32_t flags; uint32_t srcAddr; char proto; char ifName[IF_NAMESIZE]; /** mac address */ struct ether_addr gateWay_Mac; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); struct RouteInfo_v6 { uint8_t prefix; uint32_t flags; struct in6_addr dstAddr; struct in6_addr gateWay; struct in6_addr srcAddr; char proto; char ifName[IF_NAMESIZE]; /** mac address */ struct ether_addr gateWay_Mac; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); /** * @brief : print arp table * @param : No param * @return : Returns nothing */ static void print_arp_table(void); /** * memory pool for arp pkts. */ static char *arp_xmpoolname[NUM_SPGW_PORTS] = { "arp_icmp_ULxmpool", "arp_icmp_DLxmpool" }; struct rte_mempool *arp_xmpool[NUM_SPGW_PORTS]; /** * arp pkts buffer. */ struct rte_mbuf *arp_pkt[NUM_SPGW_PORTS]; /** * memory pool for queued data pkts. */ static char *arp_quxmpoolname[NUM_SPGW_PORTS] = { "arp_ULquxmpool", "arp_DLquxmpool" }; struct rte_mempool *arp_quxmpool[NUM_SPGW_PORTS]; /** * @brief : hash params. */ static struct rte_hash_parameters arp_hash_params[NUM_SPGW_PORTS] = { { .name = "ARP_UL", .entries = 64*64, .reserved = 0, .key_len = sizeof(struct arp_ip_key), .hash_func = rte_jhash, .hash_func_init_val = 0 }, { .name = "ARP_DL", .entries = 64*64, .reserved = 0, .key_len = sizeof(struct arp_ip_key), .hash_func = rte_jhash, .hash_func_init_val = 0 } }; /** * rte hash handler. */ /* 2 hash handles, one for S1U and another for SGI */ struct rte_hash *arp_hash_handle[NUM_SPGW_PORTS]; /** * arp pipeline */ struct rte_pipeline *myP; /** * @brief : arp port address */ struct arp_port_address { /** IP type */ ip_type_t ip_type; /** ipv4 address*/ uint32_t ipv4; /** ipv6 address*/ struct in6_addr ipv6; /** mac address */ struct ether_addr *mac_addr; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); /** * ports mac address. */ extern struct ether_addr ports_eth_addr[]; /** * arp port address */ static struct arp_port_address arp_port_addresses[RTE_MAX_ETHPORTS]; /** * @brief : arp params structure. */ struct epc_arp_params { /** Count since last flush */ int flush_count; /** Number of pipeline runs between flush */ int flush_max; /** RTE pipeline params */ struct rte_pipeline_params pipeline_params; /** Input port id */ uint32_t port_in_id[NUM_SPGW_PORTS]; /** Output port IDs */ uint32_t port_out_id[NUM_SPGW_PORTS]; /** table id */ uint32_t table_id; /** RTE pipeline name*/ char name[PIPE_NAME_SIZE]; }__attribute__((packed, aligned(RTE_CACHE_LINE_SIZE))); /** * global arp param variable. */ static struct epc_arp_params arp_params; uint32_t pkt_hit_count; uint32_t pkt_miss_count; uint32_t pkt_key_count; uint32_t pkt_out_count; /** * @brief : arp icmp route table details */ struct arp_icmp_route_table_entry { uint32_t ip; uint32_t mask; uint32_t port; uint32_t nh; }; struct ether_addr broadcast_ether_addr = { .addr_bytes[0] = 0xFF, .addr_bytes[1] = 0xFF, .addr_bytes[2] = 0xFF, .addr_bytes[3] = 0xFF, .addr_bytes[4] = 0xFF, .addr_bytes[5] = 0xFF, }; static const struct ether_addr null_ether_addr = { .addr_bytes[0] = 0x00, .addr_bytes[1] = 0x00, .addr_bytes[2] = 0x00, .addr_bytes[3] = 0x00, .addr_bytes[4] = 0x00, .addr_bytes[5] = 0x00, }; /** * @brief : Print Ip address * @param : ip , ip address * @return : Returns nothing */ static void print_ip(int ip) { unsigned char bytes[4]; bytes[0] = ip & 0xFF; bytes[1] = (ip >> 8) & 0xFF; bytes[2] = (ip >> 16) & 0xFF; bytes[3] = (ip >> 24) & 0xFF; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IP Address: %d.%d.%d.%d\n", LOG_VALUE, bytes[3], bytes[2], bytes[1], bytes[0]); } /** * @brief : Function to parse ethernet address * @param : hw_addr, structure to fill ethernet address * @param : str , string to be parsed * @return : Returns number of parsed characters */ static int parse_ether_addr(struct ether_addr *hw_addr, const char *str) { int ret = sscanf(str, "%"SCNx8":" "%"SCNx8":" "%"SCNx8":" "%"SCNx8":" "%"SCNx8":" "%"SCNx8, &hw_addr->addr_bytes[0], &hw_addr->addr_bytes[1], &hw_addr->addr_bytes[2], &hw_addr->addr_bytes[3], &hw_addr->addr_bytes[4], &hw_addr->addr_bytes[5]); return ret - RTE_DIM(hw_addr->addr_bytes); } /** * @brief : Add entry in ARP table. * @param : arp_key, key. * @param : ret_arp_data, arp data * @param : portid, port * @return : Returns nothing */ static void add_arp_data( struct arp_ip_key *arp_key, struct arp_entry_data *ret_arp_data, uint8_t portid) { int ret; /* ARP Entry not present. Add ARP Entry */ ret = rte_hash_add_key_data(arp_hash_handle[portid], arp_key, ret_arp_data); if (ret) { if (arp_key->ip_type.ipv4) { /* Add arp_data failed because : * ret == -EINVAL && wrong parameter || * ret == -ENOSPC && hash table size insufficient * */ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ARP: Error at:%s::" "\n\tadd arp_data= %s" "\n\tError= %s\n", __func__, inet_ntoa(*(struct in_addr *)&arp_key->ip_addr.ipv4), rte_strerror(abs(ret))); return; } else if (arp_key->ip_type.ipv6) { /* Add arp_data failed because : * ret == -EINVAL && wrong parameter || * ret == -ENOSPC && hash table size insufficient * */ clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ARP: Error at:%s::" "\n\tadd arp_data= "IPv6_FMT"" "\n\tError= %s\n", __func__, IPv6_PRINT(arp_key->ip_addr.ipv6), rte_strerror(abs(ret))); return; } } if (arp_key->ip_type.ipv4) { clLog(clSystemLog, eCLSeverityInfo, LOG_FORMAT"ARP: Entry added for IPv4: "IPV4_ADDR", portid:%u\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_key->ip_addr.ipv4)), portid); } else if (arp_key->ip_type.ipv6) { clLog(clSystemLog, eCLSeverityInfo, LOG_FORMAT"ARP: Entry added for IPv6: "IPv6_FMT", portid:%u\n", LOG_VALUE, IPv6_PRINT(arp_key->ip_addr.ipv6), portid); } } /** * returns 0 if packet was queued * return 1 if arp was resolved prior to acquiring lock - not queued - to be forwarded * return -1 if packet could not be queued - no ring */ int arp_qunresolved_ulpkt(struct arp_entry_data *arp_data, struct rte_mbuf *m, uint8_t portid) { int ret; struct rte_mbuf *buf_pkt = rte_pktmbuf_clone(m, arp_quxmpool[portid]); struct epc_meta_data *from_meta_data; struct epc_meta_data *to_meta_data; if (buf_pkt == NULL) { if (arp_data->ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP:" " Error rte pkt memory buf clone Dropping pkt" "arp data IPv4: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_data->ipv4))); } else if (arp_data->ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP:" " Error rte pkt memory buf clone Dropping pkt" "arp data IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(arp_data->ipv6)); } clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error rte PKT memory buf clone Dropping pkt\n", LOG_VALUE); print_arp_table(); return -1; } from_meta_data = (struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(m, META_DATA_OFFSET); to_meta_data = (struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(buf_pkt, META_DATA_OFFSET); *to_meta_data = *from_meta_data; ret = rte_ring_enqueue(arp_data->queue, buf_pkt); if (ret == -ENOBUFS) { rte_pktmbuf_free(buf_pkt); if (arp_data->ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Can't queue PKT ring full, so dropping PKT" "arp data IP: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(arp_data->ipv4)); } else if (arp_data->ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Can't queue PKT ring full, so dropping PKT" "arp data IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(arp_data->ipv6)); } } else { if (ARPICMP_DEBUG) { if (arp_data->ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Queued PKT arp data IPv4: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_data->ipv4))); } else if (arp_data->ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Queued PKT arp data IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(arp_data->ipv6)); } } } return ret; } int arp_qunresolved_dlpkt(struct arp_entry_data *arp_data, struct rte_mbuf *m, uint8_t portid) { int ret; struct rte_mbuf *buf_pkt = rte_pktmbuf_clone(m, arp_quxmpool[portid]); struct epc_meta_data *from_meta_data; struct epc_meta_data *to_meta_data; if (buf_pkt == NULL) { if (arp_data->ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP" ": Error rte PKT memory buf clone so dropping PKT" "and arp data IPv4: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(arp_data->ipv4)); } else if (arp_data->ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP" ": Error rte PKT memory buf clone so dropping PKT" "and arp data IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(arp_data->ipv6)); } clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ARP :Error rte PKT memory buf clone so dropping PKT\n", LOG_VALUE); print_arp_table(); return -1; } from_meta_data = (struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(m, META_DATA_OFFSET); to_meta_data = (struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(buf_pkt, META_DATA_OFFSET); *to_meta_data = *from_meta_data; ret = rte_ring_enqueue(arp_data->queue, buf_pkt); if (ret == -ENOBUFS) { rte_pktmbuf_free(buf_pkt); if (arp_data->ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Can't queue PKT ring full so dropping PKT" " arp data IPv4: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(arp_data->ipv4)); } else if (arp_data->ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Can't queue PKT ring full so dropping PKT" " arp data IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(arp_data->ipv6)); } } else { if (ARPICMP_DEBUG) { if (arp_data->ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Queued pkt" " and arp data IPv4: "IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(arp_data->ipv4)); } else if (arp_data->ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Queued pkt" " and arp data IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(arp_data->ipv6)); } } } return ret; } /** * @brief : Get arp opration name string * @param : arp_op, opration type * @return : Returns arp opration name string */ static const char * arp_op_name(uint16_t arp_op) { switch (CHECK_ENDIAN_16(arp_op)) { case (ARP_OP_REQUEST): return "ARP Request"; case (ARP_OP_REPLY): return "ARP Reply"; case (ARP_OP_REVREQUEST): return "Reverse ARP Request"; case (ARP_OP_REVREPLY): return "Reverse ARP Reply"; case (ARP_OP_INVREQUEST): return "Peer Identify Request"; case (ARP_OP_INVREPLY): return "Peer Identify Reply"; default: break; } return "Unkwown ARP op"; } /** * @brief : Print icmp packet information * @param : icmp_h, icmp header data * @return : Returns nothing */ static void print_icmp_packet(struct icmp_hdr *icmp_h) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ICMP: type=%d (%s) code=%d id=%d seqnum=%d\n", LOG_VALUE, icmp_h->icmp_type, (icmp_h->icmp_type == IP_ICMP_ECHO_REPLY ? "Reply" : (icmp_h->icmp_type == IP_ICMP_ECHO_REQUEST ? "Reqest" : "Undef")), icmp_h->icmp_code, CHECK_ENDIAN_16(icmp_h->icmp_ident), CHECK_ENDIAN_16(icmp_h->icmp_seq_nb)); } /** * @brief : Print ipv4 packet information * @param : ip_h, ipv4 header data * @return : Returns nothing */ static void print_ipv4_h(struct ipv4_hdr *ip_h) { struct icmp_hdr *icmp_h = (struct icmp_hdr *)((char *)ip_h + sizeof(struct ipv4_hdr)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"\tIPv4: Version=%d" " Header LEN=%d Type=%d Protocol=%d Length=%d\n", LOG_VALUE, (ip_h->version_ihl & 0xf0) >> 4, (ip_h->version_ihl & 0x0f), ip_h->type_of_service, ip_h->next_proto_id, rte_cpu_to_be_16(ip_h->total_length)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Dst IP:", LOG_VALUE); print_ip(ntohl(ip_h->dst_addr)); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Src IP:", LOG_VALUE); print_ip(ntohl(ip_h->src_addr)); if (ip_h->next_proto_id == IPPROTO_ICMP) { print_icmp_packet(icmp_h); } } /** * @brief : Print arp packet information * @param : arp_h, arp header data * @return : Returns nothing */ static void print_arp_packet(struct arp_hdr *arp_h) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP: hrd=%d proto=0x%04x hln=%d " "pln=%d op=%u (%s)\n", LOG_VALUE, CHECK_ENDIAN_16(arp_h->arp_hrd), CHECK_ENDIAN_16(arp_h->arp_pro), arp_h->arp_hln, arp_h->arp_pln, CHECK_ENDIAN_16(arp_h->arp_op), arp_op_name(arp_h->arp_op)); if (CHECK_ENDIAN_16(arp_h->arp_hrd) != ARP_HRD_ETHER) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Incorrect arp header format for IPv4 ARP (%d)\n", LOG_VALUE, (arp_h->arp_hrd)); } else if (CHECK_ENDIAN_16(arp_h->arp_pro) != ETHER_TYPE_IPv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Incorrect arp protocol format for IPv4 ARP (%d)\n", LOG_VALUE, (arp_h->arp_pro)); } else if (arp_h->arp_hln != 6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Incorrect arp_hln format for IPv4 ARP (%d)\n", LOG_VALUE, arp_h->arp_hln); } else if (arp_h->arp_pln != 4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Incorrect arp_pln format for IPv4 ARP (%d)\n", LOG_VALUE, arp_h->arp_pln); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Sha: %02X:%02X:%02X:%02X:%02X:%02X", LOG_VALUE, arp_h->arp_data.arp_sha.addr_bytes[0], arp_h->arp_data.arp_sha.addr_bytes[1], arp_h->arp_data.arp_sha.addr_bytes[2], arp_h->arp_data.arp_sha.addr_bytes[3], arp_h->arp_data.arp_sha.addr_bytes[4], arp_h->arp_data.arp_sha.addr_bytes[5]); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"SIP: %d.%d.%d.%d\n", LOG_VALUE, (CHECK_ENDIAN_32(arp_h->arp_data.arp_sip) >> 24) & 0xFF, (CHECK_ENDIAN_32(arp_h->arp_data.arp_sip) >> 16) & 0xFF, (CHECK_ENDIAN_32(arp_h->arp_data.arp_sip) >> 8) & 0xFF, CHECK_ENDIAN_32(arp_h->arp_data.arp_sip) & 0xFF); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Tha: %02X:%02X:%02X:%02X:%02X:%02X", LOG_VALUE, arp_h->arp_data.arp_tha.addr_bytes[0], arp_h->arp_data.arp_tha.addr_bytes[1], arp_h->arp_data.arp_tha.addr_bytes[2], arp_h->arp_data.arp_tha.addr_bytes[3], arp_h->arp_data.arp_tha.addr_bytes[4], arp_h->arp_data.arp_tha.addr_bytes[5]); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Tip: %d.%d.%d.%d\n", LOG_VALUE, (CHECK_ENDIAN_32(arp_h->arp_data.arp_tip) >> 24) & 0xFF, (CHECK_ENDIAN_32(arp_h->arp_data.arp_tip) >> 16) & 0xFF, (CHECK_ENDIAN_32(arp_h->arp_data.arp_tip) >> 8) & 0xFF, CHECK_ENDIAN_32(arp_h->arp_data.arp_tip) & 0xFF); } } /** * @brief : Print ethernet data * @param : eth_h, ethernet header data * @return : Returns nothing */ static void print_eth(struct ether_hdr *eth_h) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" ETH: src: %02X:%02X:%02X:%02X:%02X:%02X", LOG_VALUE, eth_h->s_addr.addr_bytes[0], eth_h->s_addr.addr_bytes[1], eth_h->s_addr.addr_bytes[2], eth_h->s_addr.addr_bytes[3], eth_h->s_addr.addr_bytes[4], eth_h->s_addr.addr_bytes[5]); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" dst: %02X:%02X:%02X:%02X:%02X:%02X\n", LOG_VALUE, eth_h->d_addr.addr_bytes[0], eth_h->d_addr.addr_bytes[1], eth_h->d_addr.addr_bytes[2], eth_h->d_addr.addr_bytes[3], eth_h->d_addr.addr_bytes[4], eth_h->d_addr.addr_bytes[5]); } /** * @brief : Print ethernet data * @param : eth_h, ethernet header data * @return : Returns nothing */ static void print_ipv6_eth(struct ether_addr *eth_h) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6 Pkt: ETH: src: %02X:%02X:%02X:%02X:%02X:%02X", LOG_VALUE, eth_h->addr_bytes[0], eth_h->addr_bytes[1], eth_h->addr_bytes[2], eth_h->addr_bytes[3], eth_h->addr_bytes[4], eth_h->addr_bytes[5]); } void print_mbuf(const char *rx_tx, unsigned portid, struct rte_mbuf *mbuf, unsigned line) { struct ether_hdr *eth_h = rte_pktmbuf_mtod(mbuf, struct ether_hdr *); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"%s(%u): on port %u pkt-len=%u nb-segs=%u\n", LOG_VALUE, rx_tx, line, portid, mbuf->pkt_len, mbuf->nb_segs); /* Print the ether header information*/ print_eth(eth_h); switch (rte_cpu_to_be_16(eth_h->ether_type)) { case ETHER_TYPE_IPv4: { struct ipv4_hdr *ipv4_h = (struct ipv4_hdr *)((char *)eth_h + sizeof(struct ether_hdr)); print_ipv4_h(ipv4_h); break; } case ETHER_TYPE_IPv6: { /* TODO: print the IPv6 header */ break; } case ETHER_TYPE_ARP: { struct arp_hdr *arp_h = (struct arp_hdr *)((char *)eth_h + sizeof(struct ether_hdr)); print_arp_packet(arp_h); break; } default: clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Unknown packet type\n", LOG_VALUE); break; } fflush(stdout); } struct arp_entry_data * retrieve_arp_entry(struct arp_ip_key arp_key, uint8_t portid) { int ret; struct arp_entry_data *ret_arp_data = NULL; struct RouteInfo *route_entry = NULL; if (ARPICMP_DEBUG) { if (arp_key.ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Retrieve arp entry for ipv4: "IPV4_ADDR", portid:%u\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_key.ip_addr.ipv4)), portid); } else if (arp_key.ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Retrieve arp entry for ipv6: "IPv6_FMT", portid:%u\n", LOG_VALUE, IPv6_PRINT(arp_key.ip_addr.ipv6), portid); } } ret = rte_hash_lookup_data(arp_hash_handle[portid], (const void *)&arp_key, (void **)&ret_arp_data); if (ret < 0) { if (arp_key.ip_type.ipv4) { /* Compute the key(subnet) based on netmask is 24 */ struct RouteInfo key; key.dstAddr = (arp_key.ip_addr.ipv4 & NETMASK); ret = rte_hash_lookup_data(route_hash_handle, &key.dstAddr, (void **)&route_entry); if (ret == 0) { if ((route_entry->gateWay != 0) && (route_entry->gateWay_Mac.addr_bytes != 0)) { /* Fill the gateway entry */ ret_arp_data = rte_malloc_socket(NULL, sizeof(struct arp_entry_data), RTE_CACHE_LINE_SIZE, rte_socket_id()); ret_arp_data->last_update = time(NULL); ret_arp_data->status = COMPLETE; ret_arp_data->ip_type.ipv4 = PRESENT; ret_arp_data->ipv4 = route_entry->gateWay; ret_arp_data->eth_addr = route_entry->gateWay_Mac; return ret_arp_data; } else if ((route_entry->gateWay != 0) && (route_entry->gateWay_Mac.addr_bytes == 0)) { struct arp_ip_key gw_arp_key; gw_arp_key.ip_type.ipv4 = PRESENT; gw_arp_key.ip_addr.ipv4 = route_entry->gateWay; clLog(clSystemLog, eCLSeverityInfo, LOG_FORMAT"GateWay ARP entry not found for %s\n", LOG_VALUE, inet_ntoa(*((struct in_addr *)&gw_arp_key.ip_addr.ipv4))); /* No arp entry for arp_key.ip_addr.ipv4 * Add arp_data for arp_key.ip_addr.ipv4 at * arp_hash_handle[portid] * */ ret_arp_data = rte_malloc_socket(NULL, sizeof(struct arp_entry_data), RTE_CACHE_LINE_SIZE, rte_socket_id()); ret_arp_data->last_update = time(NULL); ret_arp_data->status = INCOMPLETE; ret_arp_data->ip_type.ipv4 = PRESENT; add_arp_data(&gw_arp_key, ret_arp_data, portid); /* Added arp_data for gw_arp_key.ip_addr.ipv4 at * arp_hash_handle[portid] * Queue arp_data in arp_pkt mbuf * send_arp_req(portid, gw_arp_key.ip_addr.ipv4) * */ ret_arp_data->ipv4 = gw_arp_key.ip_addr.ipv4; ret_arp_data->queue = rte_ring_create( inet_ntoa(*((struct in_addr *)&gw_arp_key.ip_addr.ipv4)), ARP_BUFFER_RING_SIZE, rte_socket_id(), 0); if (ret_arp_data->queue == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ARP ring create error" " arp key IPv4: %s, portid: %d" "\n\tError: %s, errno(%d)\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&gw_arp_key.ip_addr.ipv4), portid, rte_strerror(abs(rte_errno)), rte_errno); print_arp_table(); if (rte_errno == EEXIST) { rte_free(ret_arp_data); ret_arp_data = NULL; clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ARP Ring Create Failed due to a " " memzone with the same name already exists 'EEXIST'\n"); } } else { if (ARPICMP_DEBUG) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP Ring Create for key ipv4: "IPV4_ADDR", portid:%u\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_key.ip_addr.ipv4)), portid); } } return ret_arp_data; } } clLog(clSystemLog, eCLSeverityInfo, LOG_FORMAT"ARP entry not found for IPv4: "IPV4_ADDR", portid:%u\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_key.ip_addr.ipv4)), portid); /* No arp entry for arp_key.ip_addr.ip * Add arp_data for arp_key.ip_addr.ip at * arp_hash_handle[portid] * */ ret_arp_data = rte_malloc_socket(NULL, sizeof(struct arp_entry_data), RTE_CACHE_LINE_SIZE, rte_socket_id()); ret_arp_data->last_update = time(NULL); ret_arp_data->status = INCOMPLETE; ret_arp_data->ip_type.ipv4 = PRESENT; add_arp_data(&arp_key, ret_arp_data, portid); /* Added arp_data for arp_key.ip_addr.ipv4 at * arp_hash_handle[portid] * Queue arp_data in arp_pkt mbuf * send_arp_req(portid, arp_key.ip_addr.ipv4) * */ ret_arp_data->ipv4 = arp_key.ip_addr.ipv4; ret_arp_data->queue = rte_ring_create( inet_ntoa(*((struct in_addr *)&arp_key.ip_addr.ipv4)), ARP_BUFFER_RING_SIZE, rte_socket_id(), 0); if (ret_arp_data->queue == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ARP ring create error" " arp key IPv4: "IPV4_ADDR", portid: %d" ",Error: %s , errno(%d)\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_key.ip_addr.ipv4)), portid, rte_strerror(abs(rte_errno)), rte_errno); print_arp_table(); if (rte_errno == EEXIST) { rte_free(ret_arp_data); ret_arp_data = NULL; clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ARP Ring Create Failed due to a " " memzone with the same name already exists 'EEXIST'\n"); } } else { if (ARPICMP_DEBUG) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP Ring Create for key ipv4: "IPV4_ADDR", portid:%u\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_key.ip_addr.ipv4)), portid); } } } else if (arp_key.ip_type.ipv6) { clLog(clSystemLog, eCLSeverityInfo, LOG_FORMAT"ARP entry not found for IPv6: "IPv6_FMT", portid:%u\n", LOG_VALUE, IPv6_PRINT(arp_key.ip_addr.ipv6), portid); /* No arp entry for arp_key.ip_addr.ipv6 * Add arp_data for arp_key.ip_addr.ipv6 at * arp_hash_handle[portid] * */ ret_arp_data = rte_malloc_socket(NULL, sizeof(struct arp_entry_data), RTE_CACHE_LINE_SIZE, rte_socket_id()); ret_arp_data->last_update = time(NULL); ret_arp_data->status = INCOMPLETE; ret_arp_data->ip_type.ipv6 = PRESENT; add_arp_data(&arp_key, ret_arp_data, portid); /* Added arp_data for arp_key.ip_addr.ipv6 at * arp_hash_handle[portid] * Queue arp_data in arp_pkt mbuf * send_arp_req(portid, arp_key.ip_addr.ipv6) * */ ret_arp_data->ipv6 = arp_key.ip_addr.ipv6; /* If received address is multicast address */ char *all_node_addr = "fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b"; char *all_router_addr = "fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b"; struct in6_addr all_node_addr_t = {0}; struct in6_addr all_router_addr_t = {0}; /* All Node IPV6 Address */ if (!inet_pton(AF_INET6, all_node_addr, &all_node_addr_t)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Multicast:Invalid all Node IPv6 Address\n", LOG_VALUE); } /* All Router IPV6 Address */ if (!inet_pton(AF_INET6, all_router_addr, &all_router_addr_t)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Multicast:Invalid all Router IPv6 Address\n", LOG_VALUE); } if (!memcmp(&ret_arp_data->ipv6, &all_node_addr_t, IPV6_ADDR_LEN)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Multicast:all Node IPv6 Address:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(ret_arp_data->ipv6)); const char *mac_addr = "33:33:00:00:00:01"; if (parse_ether_addr(&ret_arp_data->eth_addr, mac_addr)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Muticast:Error parsing static arp entry for all node mac addr" "%s\n", LOG_VALUE, mac_addr); } ret_arp_data->status = COMPLETE; } else if (!memcmp(&ret_arp_data->ipv6, &all_router_addr_t, IPV6_ADDR_LEN)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Multicast:all Router IPv6 Address:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(ret_arp_data->ipv6)); const char *mac_addr = "33:33:00:00:00:02"; if (parse_ether_addr(&ret_arp_data->eth_addr, mac_addr)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Muticast:Error parsing static arp entry for all route mac addr" "%s\n", LOG_VALUE, mac_addr); } ret_arp_data->status = COMPLETE; } ret_arp_data->queue = rte_ring_create((char *)&arp_key.ip_addr.ipv6, ARP_BUFFER_RING_SIZE, rte_socket_id(), 0); if (ret_arp_data->queue == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ARP ring create error" " arp key IPv6: "IPv6_FMT", portid: %d" ",Error: %s , errno(%d)\n", LOG_VALUE, IPv6_PRINT(arp_key.ip_addr.ipv6), portid, rte_strerror(abs(rte_errno)), rte_errno); print_arp_table(); if (rte_errno == EEXIST) { rte_free(ret_arp_data); ret_arp_data = NULL; clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"ARP Ring Create Failed due to a " " memzone with the same name already exists 'EEXIST'\n"); } } else { if (ARPICMP_DEBUG) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP Ring Create for key ipv6: "IPv6_FMT", portid:%u\n", LOG_VALUE, IPv6_PRINT(arp_key.ip_addr.ipv6), portid); } } } return ret_arp_data; } if (ARPICMP_DEBUG) { if (arp_key.ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Found arp entry for ipv4: "IPV4_ADDR", portid:%u\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_key.ip_addr.ipv4)), portid); } else if (arp_key.ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Found arp entry for ipv6: "IPv6_FMT", portid:%u\n", LOG_VALUE, IPv6_PRINT(arp_key.ip_addr.ipv6), portid); } } return ret_arp_data; } void print_arp_table(void) { const void *next_key; void *next_data; uint32_t iter = 0; for (uint8_t port_cnt = 0; port_cnt < NUM_SPGW_PORTS; port_cnt++) { while ( rte_hash_iterate( arp_hash_handle[port_cnt], &next_key, &next_data, &iter ) >= 0) { struct arp_entry_data *tmp_arp_data = (struct arp_entry_data *)next_data; struct arp_ip_key tmp_arp_key; memcpy(&tmp_arp_key, next_key, sizeof(struct arp_ip_key)); if (tmp_arp_data->ip_type.ipv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv4:\t%02X:%02X:%02X:%02X:%02X:%02X %10s %s Portid:%u\n", LOG_VALUE, tmp_arp_data->eth_addr.addr_bytes[0], tmp_arp_data->eth_addr.addr_bytes[1], tmp_arp_data->eth_addr.addr_bytes[2], tmp_arp_data->eth_addr.addr_bytes[3], tmp_arp_data->eth_addr.addr_bytes[4], tmp_arp_data->eth_addr.addr_bytes[5], tmp_arp_data->status == COMPLETE ? "COMPLETE" : "INCOMPLETE", inet_ntoa( *((struct in_addr *)(&tmp_arp_data->ipv4))), port_cnt); } else if (tmp_arp_data->ip_type.ipv6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6:\t%02X:%02X:%02X:%02X:%02X:%02X %10s "IPv6_FMT" Portid:%u\n", LOG_VALUE, tmp_arp_data->eth_addr.addr_bytes[0], tmp_arp_data->eth_addr.addr_bytes[1], tmp_arp_data->eth_addr.addr_bytes[2], tmp_arp_data->eth_addr.addr_bytes[3], tmp_arp_data->eth_addr.addr_bytes[4], tmp_arp_data->eth_addr.addr_bytes[5], tmp_arp_data->status == COMPLETE ? "COMPLETE" : "INCOMPLETE", IPv6_PRINT(tmp_arp_data->ipv6), port_cnt); } } } } /** * @brief : Forward buffered arp packets * @param : queue, packet queue pointer * @param : hw_addr, ethernet address * @param : portid, port number * @return : Returns nothing */ static void arp_send_buffered_pkts(struct rte_ring *queue, const struct ether_addr *hw_addr, uint8_t portid) { unsigned ring_count = rte_ring_count(queue); unsigned count = 0; while (!rte_ring_empty(queue)) { struct rte_mbuf *pkt; int ret = rte_ring_dequeue(queue, (void **) &pkt); if (ret == 0) { struct ether_hdr *e_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *); ether_addr_copy(hw_addr, &e_hdr->d_addr); ether_addr_copy(&ports_eth_addr[portid], &e_hdr->s_addr); if (rte_ring_enqueue(shared_ring[portid], pkt) == -ENOBUFS) { rte_pktmbuf_free(pkt); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Can't queue PKT ring full" " so dropping PKT\n", LOG_VALUE); continue; } ++count; } } #ifdef STATS if (portid == SGI_PORT_ID) { epc_app.ul_params[S1U_PORT_ID].pkts_out += count; } else if (portid == S1U_PORT_ID) { epc_app.dl_params[SGI_PORT_ID].pkts_out += count; } #endif /* STATS */ if (ARPICMP_DEBUG) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Forwarded count PKTS: %u" " Out of PKTS in ring: %u\n", LOG_VALUE, count, ring_count); } rte_ring_free(queue); } #ifdef USE_REST /** * @brief : Function to process GTP-U echo response * @param : echo_pkt, rte_mbuf pointer * @return : Returns nothing */ static void process_echo_response(struct rte_mbuf *echo_pkt) { int ret = 0; peerData *conn_data = NULL; node_address_t peer_addr = {0}; struct ether_hdr *ether = NULL; /* Get the ether header info */ ether = (struct ether_hdr *)rte_pktmbuf_mtod(echo_pkt, uint8_t *); if (ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) { /* Retrieve src IP addresses */ struct ipv4_hdr *ipv4_hdr = get_mtoip(echo_pkt); peer_addr.ip_type = IPV4_TYPE; peer_addr.ipv4_addr = ipv4_hdr->src_addr; } else if (ether->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6)) { /* Retrieve src IP addresses */ struct ipv6_hdr *ipv6_hdr = get_mtoip_v6(echo_pkt); peer_addr.ip_type = IPV6_TYPE; memcpy(peer_addr.ipv6_addr, ipv6_hdr->src_addr, IPV6_ADDR_LEN); } /* VS: */ ret = rte_hash_lookup_data(conn_hash_handle, &peer_addr, (void **)&conn_data); if ( ret < 0) { (peer_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ECHO_RSP: Entry not found for NODE IPv6 Addr: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ECHO_RSP: Entry not found for NODE IPv4 Addr: %s\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&peer_addr.ipv4_addr)); return; } else { conn_data->itr_cnt = 0; peer_address_t addr = {0}; addr.type = peer_addr.ip_type; if (peer_addr.ip_type == IPV6_TYPE) { memcpy(addr.ipv6.sin6_addr.s6_addr, peer_addr.ipv6_addr, IPV6_ADDR_LEN); } else if (peer_addr.ip_type == IPV4_TYPE) { addr.ipv4.sin_addr.s_addr = peer_addr.ipv4_addr; } update_peer_timeouts(&addr, 0); /* Reset Activity flag */ conn_data->activityFlag = 0; /* Stop transmit timer for specific Node */ stopTimer( &conn_data->tt ); /* Stop periodic timer for specific Node */ stopTimer( &conn_data->pt ); /* Reset Periodic Timer */ if ( startTimer( &conn_data->pt ) < 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Periodic Timer failed to start\n", LOG_VALUE); return; } (peer_addr.ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ECHO_RSP: Periodic Timer restarted for NODE IPv6 Addr: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(peer_addr.ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ECHO_RSP: Periodic Timer restarted for NODE IPv4 Addr: %s\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&peer_addr.ipv4_addr)); } } #endif /* USE_REST */ /** * @brief : Function to process arp message * @param : hw_addr, ethernet address * @param : ipaddr, ip address * @param : portid, port number * @return : Returns nothing */ static void process_arp_msg(const struct ether_addr *hw_addr, uint32_t ipaddr, uint8_t portid) { struct arp_ip_key arp_key = {0}; arp_key.ip_type.ipv4 = PRESENT; arp_key.ip_addr.ipv4 = ipaddr; if (ARPICMP_DEBUG) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP_RSP: Arp key IPv4 "IPV4_ADDR", portid= %d\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_key.ip_addr.ipv4)), portid); } /* On ARP_REQ || ARP_RSP retrieve_arp_entry */ struct arp_entry_data *arp_data = NULL; arp_data = retrieve_arp_entry(arp_key, portid); if (arp_data) { arp_data->last_update = time(NULL); if (!(is_same_ether_addr(&arp_data->eth_addr, hw_addr))) { /* ARP_RSP || ARP_REQ: * Copy hw_addr -> arp_data->eth_addr * */ ether_addr_copy(hw_addr, &arp_data->eth_addr); if (arp_data->status == INCOMPLETE) { if (arp_data->queue) { arp_send_buffered_pkts( arp_data->queue, hw_addr, portid); } arp_data->status = COMPLETE; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP_RSP: Resoved the queued pkts and RING status = COMPLETE " "for IPv4:"IPV4_ADDR", portid: %d\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_key.ip_addr.ipv4)), portid); } } } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP_RSP: Arp data not found for key IPv4 "IPV4_ADDR", portid= %d\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(arp_key.ip_addr.ipv4)), portid); } } /** * @brief : Function to process neighbor advertisement message * @param : hw_addr, ethernet address * @param : ip6_addr, ip6 address * @param : portid, port number * @return : Returns nothing */ static void process_neighbor_advert_msg(const struct ether_addr *hw_addr, struct in6_addr *ip6_addr, uint8_t portid) { struct arp_ip_key arp_key = {0}; arp_key.ip_type.ipv6 = PRESENT; /* Fill the IPv6 Address and resolved buffered packets */ memcpy(&arp_key.ip_addr.ipv6, ip6_addr, IPV6_ADDRESS_LEN); if (ARPICMP_DEBUG) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"NEIGHBOR: key IPv6 "IPv6_FMT", portid= %d\n", LOG_VALUE, IPv6_PRINT(arp_key.ip_addr.ipv6), portid); } /* On NEIGHBOR_SLOLITATION_REQ || NEIGHBOR_ADVERTISEMENT_RSP retrieve_arp_entry */ struct arp_entry_data *arp_data = NULL; arp_data = retrieve_arp_entry(arp_key, portid); if (arp_data) { arp_data->last_update = time(NULL); if (!(is_same_ether_addr(&arp_data->eth_addr, hw_addr))) { /* NEIGHBOR_SLOLITATION_REQ || NEIGHBOR_ADVERTISEMENT_RSP: * Copy hw_addr -> arp_data->eth_addr * */ ether_addr_copy(hw_addr, &arp_data->eth_addr); if (ARPICMP_DEBUG) print_ipv6_eth(&arp_data->eth_addr); if (arp_data->status == INCOMPLETE) { if (arp_data->queue) { arp_send_buffered_pkts( arp_data->queue, hw_addr, portid); } arp_data->status = COMPLETE; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP_RSP: Resoved the queued pkts and RING status = COMPLETE " "for IPv6:"IPv6_FMT", portid: %d\n", LOG_VALUE, IPv6_PRINT(arp_key.ip_addr.ipv6), portid); } } } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"NEIGHBOR_ADVERT: Ether data not found for key IPv6 "IPv6_FMT", portid= %d\n", LOG_VALUE, IPv6_PRINT(arp_key.ip_addr.ipv6), portid); } } void print_pkt1(struct rte_mbuf *pkt) { if (ARPICMP_DEBUG < 2) return; uint8_t *rd = RTE_MBUF_METADATA_UINT8_PTR(pkt, 0); int i = 0, j = 0; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARPICMP Packet Stats" "- hit = %u, miss = %u, key %u, out %u\n", LOG_VALUE, pkt_hit_count, pkt_miss_count, pkt_key_count, pkt_out_count); for (i = 0; i < 20; i++) { for (j = 0; j < 20; j++) clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"%02x \n", LOG_VALUE, rd[(20*i)+j]); } } /** * @brief : Function to retrive mac address and ipv4 address * @param : addr, arp port address * @param : portid, port number * @return : Returns nothing */ static void get_mac_ip_addr(struct arp_port_address *addr, uint32_t ip_addr, uint8_t port_id) { if (app.wb_port == port_id) { /* Validate the Destination IP Address subnet */ if (validate_Subnet(ntohl(ip_addr), app.wb_net, app.wb_bcast_addr)) { addr[port_id].ipv4 = htonl(app.wb_ip); } else if (validate_Subnet(ntohl(ip_addr), app.wb_li_net, app.wb_li_bcast_addr)) { addr[port_id].ipv4 = htonl(app.wb_li_ip); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"WB:ARP Destination IPv4 Addr "IPV4_ADDR" " "is NOT in local intf subnet\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(ip_addr))); } addr[port_id].ip_type.ipv4 = PRESENT; addr[port_id].mac_addr = &app.wb_ether_addr; } else if (app.eb_port == port_id) { /* Validate the Destination IP Address subnet */ if (validate_Subnet(ntohl(ip_addr), app.eb_net, app.eb_bcast_addr)) { addr[port_id].ipv4 = htonl(app.eb_ip); } else if (validate_Subnet(ntohl(ip_addr), app.eb_li_net, app.eb_li_bcast_addr)) { addr[port_id].ipv4 = htonl(app.eb_li_ip); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"EB:ARP Destination IPv4 Addr "IPV4_ADDR" " "is NOT in local intf subnet\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ntohl(ip_addr))); } addr[port_id].ip_type.ipv4 = PRESENT; addr[port_id].mac_addr = &app.eb_ether_addr; } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Unknown input port\n", LOG_VALUE); } } /** * @brief : Function to retrive mac address and ipv6 address * @param : addr, ns port address * @param : portid, port number * @return : Returns nothing */ static void get_mac_ipv6_addr(struct arp_port_address *addr, struct in6_addr ip_addr, uint8_t port_id) { if (app.wb_port == port_id) { /* Validate the Destination IPv6 Address subnet */ if (validate_ipv6_network(ip_addr, app.wb_ipv6, app.wb_ipv6_prefix_len)) { memcpy(&addr[port_id].ipv6, &app.wb_ipv6, IPV6_ADDRESS_LEN); } else if (validate_ipv6_network(ip_addr, app.wb_li_ipv6, app.wb_li_ipv6_prefix_len)){ memcpy(&addr[port_id].ipv6, &app.wb_li_ipv6, IPV6_ADDRESS_LEN); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"WB:Neighbor Destination IPv6 Addr "IPv6_FMT" " "is NOT in local intf subnet\n", LOG_VALUE, IPv6_PRINT(ip_addr)); } addr[port_id].ip_type.ipv6 = PRESENT; addr[port_id].mac_addr = &app.eb_ether_addr; } else if (app.eb_port == port_id) { /* Validate the Destination IPv6 Address subnet */ if (validate_ipv6_network(ip_addr, app.eb_ipv6, app.eb_ipv6_prefix_len)) { memcpy(&addr[port_id].ipv6, &app.eb_ipv6, IPV6_ADDRESS_LEN); } else if (validate_ipv6_network(ip_addr, app.eb_li_ipv6, app.eb_li_ipv6_prefix_len)){ memcpy(&addr[port_id].ipv6, &app.eb_li_ipv6, IPV6_ADDRESS_LEN); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"EB:Neighbor Destination IPv6 Addr "IPv6_FMT" " "is NOT in local intf subnet\n", LOG_VALUE, IPv6_PRINT(ip_addr)); } addr[port_id].ip_type.ipv6 = PRESENT; addr[port_id].mac_addr = &app.eb_ether_addr; } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Unknown input port\n", LOG_VALUE); } } /** * @brief : Function to process arp request * @param : pkt, rte_mbuf pointer * @param : arg, port id * @return : Returns nothing */ static inline void pkt_work_arp_key( struct rte_mbuf *pkt, void *arg) { uint8_t in_port_id = (uint8_t)(uintptr_t)arg; pkt_key_count++; print_pkt1(pkt); CLIinterface it; if (in_port_id == S1U_PORT_ID) { it = S1U; } else { it = SGI; } struct ether_hdr *eth_h = rte_pktmbuf_mtod(pkt, struct ether_hdr *); if ((eth_h->d_addr.addr_bytes[0] == 0x01) && (eth_h->d_addr.addr_bytes[1] == 0x80) && (eth_h->d_addr.addr_bytes[2] == 0xc2)) return ; if ((eth_h->d_addr.addr_bytes[0] == 0x01) && (eth_h->d_addr.addr_bytes[1] == 0x00) && (eth_h->d_addr.addr_bytes[2] == 0x0c)) return ; /* Print ethernet header information */ if (ARPICMP_DEBUG) print_eth(eth_h); if (eth_h->ether_type == rte_cpu_to_be_16(ETHER_TYPE_ARP)) { struct arp_hdr *arp_h = (struct arp_hdr *)((char *)eth_h + sizeof(struct ether_hdr)); /* Print ARP header information */ if (ARPICMP_DEBUG) print_arp_packet(arp_h); if (CHECK_ENDIAN_16(arp_h->arp_hrd) != ARP_HRD_ETHER) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Invalid hardware address format-" "not processing ARP REQ\n", LOG_VALUE); } else if (CHECK_ENDIAN_16(arp_h->arp_pro) != ETHER_TYPE_IPv4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Invalid protocol format-" "not processing ARP REQ\n", LOG_VALUE); } else if (arp_h->arp_hln != 6) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Invalid hardware address length-" "not processing ARP REQ\n", LOG_VALUE); } else if (arp_h->arp_pln != 4) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Invalid protocol address length-" "not processing ARP REQ\n", LOG_VALUE); } else { get_mac_ip_addr(arp_port_addresses, arp_h->arp_data.arp_tip, in_port_id); if (arp_h->arp_data.arp_tip != arp_port_addresses[in_port_id].ipv4) { if (ARPICMP_DEBUG) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP REQ IPv4 != Port IP::discarding" "ARP REQ IP: %s;" "Port ID: %X; Interface IPv4: %s\n",LOG_VALUE, inet_ntoa(*(struct in_addr *)&arp_h->arp_data.arp_tip), in_port_id, inet_ntoa(*(struct in_addr *)&arp_port_addresses[in_port_id].ipv4)); } } else if (arp_h->arp_op == rte_cpu_to_be_16(ARP_OP_REQUEST)) { /* ARP_REQ IP matches. Process ARP_REQ */ if (ARPICMP_DEBUG) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"\nArp op: %d; ARP OP REQUEST: %d" " print memory bufffer:\n", LOG_VALUE, arp_h->arp_op, rte_cpu_to_be_16(ARP_OP_REQUEST)); print_mbuf("RX", in_port_id, pkt, __LINE__); } process_arp_msg(&arp_h->arp_data.arp_sha, arp_h->arp_data.arp_sip, in_port_id); #ifdef STATIC_ARP /* Build ARP_RSP */ uint32_t req_tip = arp_h->arp_data.arp_tip; ether_addr_copy(&eth_h->s_addr, &eth_h->d_addr); ether_addr_copy( arp_port_addresses[in_port_id].mac_addr, &eth_h->s_addr); arp_h->arp_op = rte_cpu_to_be_16(ARP_OP_REPLY); ether_addr_copy(&eth_h->s_addr, &arp_h->arp_data.arp_sha); arp_h->arp_data.arp_tip = arp_h->arp_data.arp_sip; arp_h->arp_data.arp_sip = req_tip; ether_addr_copy(&eth_h->d_addr, &arp_h->arp_data.arp_tha); if (ARPICMP_DEBUG) { print_mbuf("TX", in_port_id, pkt, __LINE__); print_pkt1(pkt); } /* Send ARP_RSP */ int pkt_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_mbuf)); /* arp_pkt @arp_xmpool[port_id] */ struct rte_mbuf *pkt1 = arp_pkt[in_port_id]; if (pkt1) { memcpy(pkt1, pkt, pkt_size); rte_pipeline_port_out_packet_insert( myP, in_port_id, pkt1); } #endif /* STATIC_ARP */ } else if (arp_h->arp_op == rte_cpu_to_be_16(ARP_OP_REPLY)) { /* Process ARP_RSP */ if (ARPICMP_DEBUG) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ARP RSP::IPv4= %s; "FORMAT_MAC"\n", LOG_VALUE, inet_ntoa( *(struct in_addr *)&arp_h-> arp_data.arp_sip), FORMAT_MAC_ARGS(arp_h->arp_data.arp_sha) ); } process_arp_msg(&arp_h->arp_data.arp_sha, arp_h->arp_data.arp_sip, in_port_id); } else { if (ARPICMP_DEBUG) clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Invalid ARP OPCODE= %X" "\nnot processing ARP REQ||ARP RSP\n", LOG_VALUE, arp_h->arp_op); } } } else if (eth_h->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) { /* If UDP dest port is 2152, then pkt is GTPU-Echo request */ struct gtpu_hdr *gtpuhdr = get_mtogtpu(pkt); if (gtpuhdr && (gtpuhdr->msgtype == GTPU_ECHO_REQUEST)) { struct ipv4_hdr *ip_hdr = get_mtoip(pkt); /* Check Request recvd form Valid IP address */ if ((app.wb_ip != ntohl(ip_hdr->dst_addr)) && (app.eb_ip != ntohl(ip_hdr->dst_addr))) { /* Check for logical interface */ if ((app.wb_li_ip != ntohl(ip_hdr->dst_addr)) && (app.eb_li_ip != ntohl(ip_hdr->dst_addr))) { return; } } peer_address_t address; address.ipv4.sin_addr.s_addr = ip_hdr->src_addr; address.type = IPV4_TYPE; update_cli_stats((peer_address_t *) &address, GTPU_ECHO_REQUEST, RCVD, it); process_echo_request(pkt, in_port_id, IPV4_TYPE); /* Send ECHO_RSP */ int pkt_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_mbuf)); /* gtpu_echo_pkt @arp_xmpool[port_id] */ struct rte_mbuf *pkt1 = arp_pkt[in_port_id]; if (pkt1) { memcpy(pkt1, pkt, pkt_size); if (rte_ring_enqueue(shared_ring[in_port_id], pkt1) == -ENOBUFS) { rte_pktmbuf_free(pkt1); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Can't queue pkt- ring full" " Dropping pkt\n", LOG_VALUE); return; } peer_address_t address; address.ipv4.sin_addr.s_addr = ip_hdr->dst_addr; address.type = IPV4_TYPE; update_cli_stats((peer_address_t *) &address, GTPU_ECHO_RESPONSE, SENT,it); } } else if (gtpuhdr && gtpuhdr->msgtype == GTPU_ECHO_RESPONSE) { #ifdef USE_REST /*VS: Add check for Restart counter */ /* If peer Restart counter value of peer node is less than privious value than start flusing session*/ struct ipv4_hdr *ip_hdr = get_mtoip(pkt); peer_address_t address; address.ipv4.sin_addr.s_addr = ip_hdr->src_addr; address.type = IPV4_TYPE; update_cli_stats((peer_address_t *) &address, GTPU_ECHO_RESPONSE, RCVD, it); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"GTPU Echo Response Received\n", LOG_VALUE); process_echo_response(pkt); #endif /* USE_REST */ } else if (gtpuhdr && gtpuhdr->msgtype == GTP_GPDU) { /* Process the Router Solicitation Message */ struct ipv6_hdr *ipv6_hdr = NULL; ipv6_hdr = (struct ipv6_hdr*)((char*)gtpuhdr + GTPU_HDR_SIZE); if (ipv6_hdr->proto == IPPROTO_ICMPV6) { /* Target IPv6 Address */ struct in6_addr target_addr = {0}; memcpy(&target_addr.s6_addr, &ipv6_hdr->src_addr, IPV6_ADDR_LEN); /* Get the ICMPv6 Header */ struct icmp_hdr *icmp = NULL; icmp = (struct icmp_hdr *)((char*)gtpuhdr + GTPU_HDR_SIZE + IPv6_HDR_SIZE); if (icmp->icmp_type == ICMPv6_ROUTER_SOLICITATION) { /* Check the TEID value */ if (!gtpuhdr->teid) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv6: Failed to Process ICMPv6_ROUTER_SOLICITATION Message," " due to teid value is not set\n", LOG_VALUE); return; } /* Retrieve Session info based on the teid */ pfcp_session_datat_t *ul_sess_data = NULL; pfcp_session_datat_t *dl_sess_data = NULL; struct ul_bm_key key = {0}; struct dl_bm_key dl_key = {0}; key.teid = ntohl(gtpuhdr->teid); /* Get the session info */ if (iface_lookup_uplink_data(&key, (void **)&ul_sess_data) < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT":RS:Session Data LKUP:FAIL!! ULKEY " "TEID: %u\n", LOG_VALUE, key.teid); return; } /* Check session data is not NULL */ if (ul_sess_data == NULL) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT":RS:Session Data LKUP:FAIL!! ULKEY " "TEID: %u\n", LOG_VALUE, key.teid); return; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"RS:SESSION INFO:" "TEID:%u, Session State:%u\n", LOG_VALUE, key.teid, ul_sess_data->sess_state); if (ul_sess_data->pdrs != NULL) { /* Get the Downlink PDR and FAR info */ memcpy(&dl_key.ue_ip.ue_ipv6, &(ul_sess_data->pdrs)->pdi.ue_addr.ipv6_address, IPV6_ADDR_LEN); /* Get the Downlink Session information */ if (iface_lookup_downlink_data(&dl_key, (void **)&dl_sess_data) < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT":RS:Session Data LKUP:FAIL!! DLKEY " "UE IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)dl_key.ue_ip.ue_ipv6)); return; } /* Check session data is not NULL */ if (dl_sess_data == NULL) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT":RS:Session Data LKUP:FAIL!! DLKEY " "UE IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)dl_key.ue_ip.ue_ipv6)); return; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"RS:SESSION INFO:" "UE IPv6:"IPv6_FMT", Session State:%u\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)dl_key.ue_ip.ue_ipv6), dl_sess_data->sess_state); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT":RS:PDR is NULL in UL session for " "TEID: %u\n", LOG_VALUE, key.teid); return; } /* Validate PDR and FAR is not NULL */ if ((dl_sess_data->pdrs != NULL) && ((dl_sess_data->pdrs)->far != NULL)) { /* Processing received Router Solicitation Request and responsed with Advertisement Resp */ uint32_t tmp_teid = ntohl((dl_sess_data->pdrs)->far->frwdng_parms.outer_hdr_creation.teid); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: Process RCVD ICMPv6_ROUTER_SOLICITATION Message..!!\n", LOG_VALUE); /* Update the GTPU TEID */ process_router_solicitation_request(pkt, tmp_teid); /* Update the Inner IPv6 HDR Src Address */ struct ipv6_hdr *ipv6_hdr = NULL; ipv6_hdr = (struct ipv6_hdr*)((char*)gtpuhdr + GTPU_HDR_SIZE); /* Update the Source Link Locak Layer Address */ memcpy(&ipv6_hdr->src_addr, &app.wb_l3_ipv6, IPV6_ADDR_LEN); /* Update the Router Advertisement pkt */ struct icmp6_hdr_ra *ra = (struct icmp6_hdr_ra *)((char*)gtpuhdr + GTPU_HDR_SIZE + IPv6_HDR_SIZE); /* Get the Network Prefix */ struct in6_addr prefix_addr_t = {0}; prefix_addr_t = retrieve_ipv6_prefix(*(struct in6_addr*)(ul_sess_data->pdrs)->pdi.ue_addr.ipv6_address, (ul_sess_data->pdrs)->pdi.ue_addr.ipv6_pfx_dlgtn_bits); /* Fill the Network Prefix and Prefix Length */ ra->icmp.icmp6_data.icmp6_data8[0] = (ul_sess_data->pdrs)->pdi.ue_addr.ipv6_pfx_dlgtn_bits; ra->opt.prefix_length = (ul_sess_data->pdrs)->pdi.ue_addr.ipv6_pfx_dlgtn_bits; memcpy(ra->opt.prefix_addr, &prefix_addr_t.s6_addr, IPV6_ADDR_LEN); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"RA: Fill the Network Prefix:"IPv6_FMT" and Prefix len:%u, TEID:%u\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr*)ra->opt.prefix_addr), ra->opt.prefix_length, tmp_teid); /* Set the ICMPv6 Header Checksum */ ra->icmp.icmp6_cksum = 0; ra->icmp.icmp6_cksum = ipv6_icmp_cksum(ipv6_hdr, &ra->icmp); /* Update the IP and UDP header checksum */ ra_set_checksum(pkt); /* Send ICMPv6 Router Advertisement resp */ int pkt_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_mbuf)); /* arp_pkt @arp_xmpool[port_id] */ struct rte_mbuf *pkt1 = arp_pkt[in_port_id]; if (pkt1) { memcpy(pkt1, pkt, pkt_size); if (rte_ring_enqueue(shared_ring[in_port_id], pkt1) == -ENOBUFS) { rte_pktmbuf_free(pkt1); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"RA:Can't queue pkt- ring full" " Dropping pkt\n", LOG_VALUE); return; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: Send ICMPv6_ROUTER_ADVERTISEMENT Message " "to IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)ipv6_hdr->dst_addr)); #ifdef STATS ++epc_app.ul_params[in_port_id].pkts_rs_out; #endif /* STATS */ } } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"RS:SESSION INFO: PDR/FAR not found(NULL) for UE IPv6:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)dl_key.ue_ip.ue_ipv6)); } } } } else if (gtpuhdr && gtpuhdr->msgtype == GTPU_ERROR_INDICATION) { struct ipv4_hdr *ip_hdr = get_mtoip(pkt); /* Handle the Error indication pkts received from the peer nodes */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ERROR_INDICATION: Received Error Indication pkts from the peer node:"IPV4_ADDR"\n", LOG_VALUE, IPV4_ADDR_HOST_FORMAT(ip_hdr->src_addr)); #ifdef STATS if(in_port_id == SGI_PORT_ID) { ++epc_app.dl_params[in_port_id].pkts_err_in; } else { ++epc_app.ul_params[in_port_id].pkts_err_in; } #endif /* STATS */ } } else if (eth_h->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6)) { /* Get the IPv6 Header from pkt */ struct ipv6_hdr *ipv6_hdr = NULL; ipv6_hdr = get_mtoip_v6(pkt); /* L4: If next header is ICMPv6 and Neighbor Solicitation/Advertisement */ if ((ipv6_hdr->proto == IPPROTO_ICMPV6) && (ipv6_hdr->proto != IPPROTO_UDP)) { /* Get the ICMP IPv6 Header from pkt */ struct icmp_hdr *icmp = NULL; icmp = get_mtoicmpv6(pkt); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: RCVD ICMPv6 Message Type:%u\n", LOG_VALUE, icmp->icmp_type); /* Process Neighbor Solicitation/Advertisement Messages */ if (icmp->icmp_type == ICMPv6_NEIGHBOR_SOLICITATION) { struct icmp6_hdr_ns *ns = get_mtoicmpv6_ns(pkt); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: Process RCVD ICMPv6_NEIGHBOR_SOLICITATION Message..!!\n", LOG_VALUE); /* Validate the Target IPv6 Address */ if (in_port_id == S1U_PORT_ID) { /* Validate the Source IPv6 address is in same network */ if (memcmp(&(app.wb_ipv6), &ns->icmp6_target_addr, IPV6_ADDRESS_LEN) && memcmp(&(app.wb_li_ipv6), &ns->icmp6_target_addr, IPV6_ADDRESS_LEN)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"NEIGHBOR_SOLICITATION: Target dest addr mismatch " "Expected:app.wb_ipv6("IPv6_FMT" or "IPv6_FMT") != RCVD:ns->icmp6_target_addr("IPv6_FMT")\n", LOG_VALUE, IPv6_PRINT(app.wb_ipv6), IPv6_PRINT(app.wb_li_ipv6), IPv6_PRINT(ns->icmp6_target_addr)); return; } } else if (in_port_id == SGI_PORT_ID) { /* Validate the Source IPv6 address is in same network */ if (memcmp(&(app.eb_ipv6), &ns->icmp6_target_addr, IPV6_ADDRESS_LEN) && memcmp(&(app.eb_li_ipv6), &ns->icmp6_target_addr, IPV6_ADDRESS_LEN)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"NEIGHBOR_SOLICITATION: Target dest addr mismatch " "Expected:app.eb_ipv6("IPv6_FMT" or "IPv6_FMT") != RCVD:ns->icmp6_target_addr("IPv6_FMT")\n", LOG_VALUE, IPv6_PRINT(app.eb_ipv6), IPv6_PRINT(app.eb_li_ipv6), IPv6_PRINT(ns->icmp6_target_addr)); return; } } /* Source hardware address */ if (ns->opt.type == SRC_LINK_LAYER_ADDR) { struct ether_addr mac_addr = {0}; /* Source IPv6 Address */ struct in6_addr src_addr = {0}; memcpy(&src_addr, (struct in6_addr *)ipv6_hdr->src_addr, IPV6_ADDRESS_LEN); /* Fill the Source Link Layer Address */ memcpy(&mac_addr, &ns->opt.link_layer_addr, ETHER_ADDR_LEN); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6_ARP_NS: Check ARP entry for IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)ipv6_hdr->src_addr)); if (ARPICMP_DEBUG) { print_ipv6_eth(&mac_addr); } /* Add the ARP entry into arp table and resolved buffer packets */ process_neighbor_advert_msg(&mac_addr, &src_addr, in_port_id); #ifdef STATIC_ARP /* Build ICMPv6_NEIGHBOR_ADVERTISEMENT Resp */ get_mac_ipv6_addr(arp_port_addresses, ns->icmp6_target_addr, in_port_id); /* Fill the ether header info */ ether_addr_copy(&eth_h->s_addr, &eth_h->d_addr); ether_addr_copy( arp_port_addresses[in_port_id].mac_addr, &eth_h->s_addr); /* Fill the IPv6 header */ memcpy(&ipv6_hdr->dst_addr, &ipv6_hdr->src_addr, IPV6_ADDRESS_LEN); memcpy(&ipv6_hdr->src_addr, &arp_port_addresses[in_port_id].ipv6.s6_addr, IPV6_ADDRESS_LEN); struct in6_addr target_addr = {0}; memcpy(&target_addr, &ns->icmp6_target_addr, IPV6_ADDRESS_LEN); /* Reset the neighbor solicitaion header */ memset(ns, 0, sizeof(struct icmp6_hdr_ns)); struct icmp6_hdr_na *na = get_mtoicmpv6_na(pkt); memset(na, 0, sizeof(struct icmp6_hdr_na)); /* Fill neighbor advertisement pkt */ na->icmp6_type = ICMPv6_NEIGHBOR_ADVERTISEMENT; na->icmp6_code = 0; /*TODO: Calculate the checksum */ //na->icmp6_cksum = 0; na->icmp6_flags = 0x60; //na->icmp6_reserved = 0; memcpy(&na->icmp6_target_addr, &arp_port_addresses[in_port_id].ipv6, IPV6_ADDRESS_LEN); na->opt.type = TRT_LINK_LAYER_ADDR; na->opt.length = (ETHER_ADDR_LEN + sizeof(na->opt.length))/8; memcpy(&na->opt.link_layer_addr, &arp_port_addresses[in_port_id].mac_addr, ETHER_ADDR_LEN); /* Send ICMPv6 Neighbor Advertisement resp */ int pkt_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_mbuf)); /* arp_pkt @arp_xmpool[port_id] */ struct rte_mbuf *pkt1 = arp_pkt[in_port_id]; if (pkt1) { memcpy(pkt1, pkt, pkt_size); rte_pipeline_port_out_packet_insert( myP, in_port_id, pkt1); } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: Send ICMPv6_NEIGHBOR_ADVERTISEMENT Message " "to IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)ipv6_hdr->dst_addr)); #endif /* STATIC_ARP */ } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: RCVD ICMPv6_NEIGHBOR_SOLICITATION Message " "not include SRC_LINK_LAYER_ADDR\n", LOG_VALUE); } } else if (icmp->icmp_type == ICMPv6_NEIGHBOR_ADVERTISEMENT) { struct icmp6_hdr_na *na = get_mtoicmpv6_na(pkt); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: Process RCVD ICMPv6_NEIGHBOR_ADVERTISEMENT Message..!!\n", LOG_VALUE); /* Validate the Target IPv6 Address */ if (in_port_id == S1U_PORT_ID) { /* Validate the Source IPv6 address is in same network */ if (memcmp(&(app.wb_ipv6), (struct in6_addr *)ipv6_hdr->dst_addr, IPV6_ADDRESS_LEN) && memcmp(&(app.wb_li_ipv6), (struct in6_addr *)ipv6_hdr->dst_addr, IPV6_ADDRESS_LEN)) { if (memcmp(&(app.wb_l3_ipv6), (struct in6_addr *)ipv6_hdr->dst_addr, IPV6_ADDRESS_LEN)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"NEIGHBOR_ADVERT: Dest Addr mismatch " "Expected:app.wb_ipv6("IPv6_FMT" or "IPv6_FMT") != RCVD:ns->ipv6_dst_addr("IPv6_FMT")\n", LOG_VALUE, IPv6_PRINT(app.wb_ipv6), IPv6_PRINT(app.wb_li_ipv6), IPv6_PRINT(*(struct in6_addr *)ipv6_hdr->dst_addr)); return; } } } else if (in_port_id == SGI_PORT_ID) { /* Validate the Source IPv6 address is in same network */ if (memcmp(&(app.eb_ipv6), (struct in6_addr *)ipv6_hdr->dst_addr, IPV6_ADDRESS_LEN) && memcmp(&(app.eb_li_ipv6), (struct in6_addr *)ipv6_hdr->dst_addr, IPV6_ADDRESS_LEN)) { if (memcmp(&(app.eb_l3_ipv6), (struct in6_addr *)ipv6_hdr->dst_addr, IPV6_ADDRESS_LEN)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"NEIGHBOR_ADVERT: Dest Addr mismatch " "Expected:app.eb_ipv6("IPv6_FMT" or "IPv6_FMT") != RCVD:ns->ipv6_dst_addr("IPv6_FMT")\n", LOG_VALUE, IPv6_PRINT(app.eb_ipv6), IPv6_PRINT(app.eb_li_ipv6), IPv6_PRINT(*(struct in6_addr *)ipv6_hdr->dst_addr)); return; } } } /* Target hardware address */ if (na->opt.type == TRT_LINK_LAYER_ADDR) { struct ether_addr mac_addr = {0}; /* Target IPv6 Address */ struct in6_addr target_addr = {0}; memcpy(&target_addr, &na->icmp6_target_addr, IPV6_ADDRESS_LEN); /* Fill the Source Link Layer Address */ memcpy(&mac_addr, &na->opt.link_layer_addr, ETHER_ADDR_LEN); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6_ARP_NA: Check ARP entry for IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(na->icmp6_target_addr)); if (ARPICMP_DEBUG) { print_ipv6_eth(&mac_addr); } /* Add the ARP entry into arp table and resolved buffer packets */ process_neighbor_advert_msg(&mac_addr, &target_addr, in_port_id); } else { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: RCVD ICMPv6_NEIGHBOR_ADVERTISEMENT Message " "not include TRT_LINK_LAYER_ADDR\n", LOG_VALUE); } } } else if ((ipv6_hdr->proto == IPPROTO_UDP) && (ipv6_hdr->proto != IPPROTO_ICMPV6)) { /* If UDP dest port is 2152, then pkt is GTPU-Echo request */ struct gtpu_hdr *gtpuhdr = get_mtogtpu_v6(pkt); if (gtpuhdr && (gtpuhdr->msgtype == GTPU_ECHO_REQUEST)) { peer_address_t addr = {0}; addr.type = IPV6_TYPE; memcpy(addr.ipv6.sin6_addr.s6_addr, ipv6_hdr->dst_addr, IPV6_ADDR_LEN); update_cli_stats(&addr, GTPU_ECHO_REQUEST, RCVD, it); /* Host IPv6 Address */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: RCVD Echo Request Received From IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(addr.ipv6.sin6_addr.s6_addr))); process_echo_request(pkt, in_port_id, IPV6_TYPE); /* Send ECHO_RSP */ int pkt_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_mbuf)); /* gtpu_echo_pkt @arp_xmpool[port_id] */ struct rte_mbuf *pkt1 = arp_pkt[in_port_id]; if (pkt1) { memcpy(pkt1, pkt, pkt_size); if (rte_ring_enqueue(shared_ring[in_port_id], pkt1) == -ENOBUFS) { rte_pktmbuf_free(pkt1); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Can't queue pkt- ring full" " Dropping pkt\n", LOG_VALUE); return; } update_cli_stats(&addr, GTPU_ECHO_RESPONSE, SENT,it); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: Send Echo Response to IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(addr.ipv6.sin6_addr.s6_addr))); } } else if (gtpuhdr && gtpuhdr->msgtype == GTPU_ECHO_RESPONSE) { /* TODO: Add the Handling for GTPU ECHO Resp Process for IPv6 */ /* Host IPv6 Address */ struct in6_addr ho_addr = {0}; memcpy(&ho_addr.s6_addr, &ipv6_hdr->dst_addr, IPV6_ADDR_LEN); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: RCVD Echo Response Received From IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(ho_addr)); #ifdef USE_REST /* If peer Restart counter value of peer node is less than privious value than start flusing session*/ peer_address_t addr = {0}; memcpy(addr.ipv6.sin6_addr.s6_addr, ipv6_hdr->dst_addr, IPV6_ADDR_LEN); addr.type = IPV6_TYPE; update_cli_stats(&addr, GTPU_ECHO_RESPONSE, RCVD, it); process_echo_response(pkt); #endif /* USE_REST */ } else if (gtpuhdr && gtpuhdr->msgtype == GTP_GPDU) { /* Process the Router Solicitation Message */ struct ipv6_hdr *ipv6_hdr = NULL; ipv6_hdr = get_inner_mtoipv6(pkt); if (ipv6_hdr->proto == IPPROTO_ICMPV6) { /* Target IPv6 Address */ struct in6_addr target_addr = {0}; memcpy(&target_addr.s6_addr, &ipv6_hdr->src_addr, IPV6_ADDR_LEN); /* Get the ICMPv6 Header */ struct icmp_hdr *icmp = NULL; icmp = get_inner_mtoicmpv6(pkt); if (icmp->icmp_type == ICMPv6_ROUTER_SOLICITATION) { /* Check the TEID value */ if (!gtpuhdr->teid) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv6: Failed to Process ICMPv6_ROUTER_SOLICITATION Message," " due to teid value is not set\n", LOG_VALUE); return; } /* Retrieve Session info based on the teid */ pfcp_session_datat_t *ul_sess_data = NULL; pfcp_session_datat_t *dl_sess_data = NULL; struct ul_bm_key key = {0}; struct dl_bm_key dl_key = {0}; key.teid = ntohl(gtpuhdr->teid); /* Get the session info */ if (iface_lookup_uplink_data(&key, (void **)&ul_sess_data) < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT":RS:Session Data LKUP:FAIL!! ULKEY " "TEID: %u\n", LOG_VALUE, key.teid); return; } /* Check session data is not NULL */ if (ul_sess_data == NULL) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT":RS:Session Data LKUP:FAIL!! ULKEY " "TEID: %u\n", LOG_VALUE, key.teid); return; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"RS:SESSION INFO:" "TEID:%u, Session State:%u\n", LOG_VALUE, key.teid, ul_sess_data->sess_state); if (ul_sess_data->pdrs != NULL) { /* Get the Downlink PDR and FAR info */ memcpy(&dl_key.ue_ip.ue_ipv6, &(ul_sess_data->pdrs)->pdi.ue_addr.ipv6_address, IPV6_ADDR_LEN); /* Get the Downlink Session information */ if (iface_lookup_downlink_data(&dl_key, (void **)&dl_sess_data) < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT":RS:Session Data LKUP:FAIL!! DLKEY " "UE IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)dl_key.ue_ip.ue_ipv6)); return; } /* Check session data is not NULL */ if (dl_sess_data == NULL) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT":RS:Session Data LKUP:FAIL!! DLKEY " "UE IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)dl_key.ue_ip.ue_ipv6)); return; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"RS:SESSION INFO:" "UE IPv6:"IPv6_FMT", Session State:%u\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)dl_key.ue_ip.ue_ipv6), dl_sess_data->sess_state); } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT":RS:PDR is NULL in UL session for " "TEID: %u\n", LOG_VALUE, key.teid); return; } /* Validate PDR and FAR is not NULL */ if ((dl_sess_data->pdrs != NULL) && ((dl_sess_data->pdrs)->far != NULL)) { /* Processing received Router Solicitation Request and responsed with Advertisement Resp */ uint32_t tmp_teid = ntohl((dl_sess_data->pdrs)->far->frwdng_parms.outer_hdr_creation.teid); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: Process RCVD ICMPv6_ROUTER_SOLICITATION Message..!!\n", LOG_VALUE); /* Update the GTPU TEID */ process_router_solicitation_request(pkt, tmp_teid); /* Update the Inner IPv6 HDR Src Address */ struct ipv6_hdr *ipv6_hdr = NULL; ipv6_hdr = (struct ipv6_hdr*)((char*)gtpuhdr + GTPU_HDR_SIZE); /* Update the Source Link Locak Layer Address */ memcpy(&ipv6_hdr->src_addr, &app.wb_l3_ipv6, IPV6_ADDR_LEN); /* Update the Router Advertisement pkt */ struct icmp6_hdr_ra *ra = get_mtoicmpv6_ra(pkt); /* Get the Network Prefix */ struct in6_addr prefix_addr_t = {0}; prefix_addr_t = retrieve_ipv6_prefix(*(struct in6_addr*)(ul_sess_data->pdrs)->pdi.ue_addr.ipv6_address, (ul_sess_data->pdrs)->pdi.ue_addr.ipv6_pfx_dlgtn_bits); /* Fill the Network Prefix and Prefix Length */ ra->icmp.icmp6_data.icmp6_data8[0] = (ul_sess_data->pdrs)->pdi.ue_addr.ipv6_pfx_dlgtn_bits; ra->opt.prefix_length = (ul_sess_data->pdrs)->pdi.ue_addr.ipv6_pfx_dlgtn_bits; memcpy(ra->opt.prefix_addr, &prefix_addr_t.s6_addr, IPV6_ADDR_LEN); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"RA: Fill the Network Prefix:"IPv6_FMT" and Prefix len:%u, TEID:%u\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr*)ra->opt.prefix_addr), ra->opt.prefix_length, tmp_teid); /* Set the ICMPv6 Header Checksum */ ra->icmp.icmp6_cksum = 0; ra->icmp.icmp6_cksum = ipv6_icmp_cksum(ipv6_hdr, &ra->icmp); /* Update the IP and UDP header checksum */ ra_set_checksum(pkt); /* Send ICMPv6 Router Advertisement resp */ int pkt_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_mbuf)); /* arp_pkt @arp_xmpool[port_id] */ struct rte_mbuf *pkt1 = arp_pkt[in_port_id]; if (pkt1) { memcpy(pkt1, pkt, pkt_size); if (rte_ring_enqueue(shared_ring[in_port_id], pkt1) == -ENOBUFS) { rte_pktmbuf_free(pkt1); clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"RA:Can't queue pkt- ring full" " Dropping pkt\n", LOG_VALUE); return; } clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: Send ICMPv6_ROUTER_ADVERTISEMENT Message " "to IPv6 Addr:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)ipv6_hdr->dst_addr)); #ifdef STATS ++epc_app.ul_params[in_port_id].pkts_rs_out; #endif /* STATS */ } } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"RS:SESSION INFO: PDR/FAR not found(NULL) for UE IPv6:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)dl_key.ue_ip.ue_ipv6)); } } } } else if (gtpuhdr && gtpuhdr->msgtype == GTPU_ERROR_INDICATION) { struct ipv6_hdr *ipv6_hdr = NULL; ipv6_hdr = get_mtoip_v6(pkt); /* Handle the Error indication pkts received from the peer nodes */ clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"ERROR_INDICATION: Received Error Indication pkts from the peer node:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(ipv6_hdr->src_addr))); #ifdef STATS if(in_port_id == SGI_PORT_ID) { ++epc_app.dl_params[in_port_id].pkts_err_in; } else { ++epc_app.ul_params[in_port_id].pkts_err_in; } #endif /* STATS */ } } } } /** * @brief : Function to be implemented * @param : pkt, unused param * @param : arg, unused param * @return : Returns nothing */ static inline void pkt4_work_arp_key( struct rte_mbuf **pkt, void *arg) { (void)pkt; (void)arg; /* TO BE IMPLEMENTED IF REQUIRED */ } /** * @brief : Function to process incoming arp packets * @param : p. rte pipeline pointer * @param : pkt, rte_mbuf pointer * @param : n, number of packets * @param : arg, port id * @return : Returns 0 in case of success */ static int port_in_ah_arp_key( struct rte_pipeline *p, struct rte_mbuf **pkts, uint32_t n, void *arg) { unsigned int i; for (i = 0; i < n; i++) { if (pkts[i]) pkt_work_arp_key(pkts[i], arg); } return 0; } #ifdef STATIC_ARP /** * @brief : Add static arp entry for IPv4 Address * @param : entry, entry to be added * @param : port_id, port number * @return : Returns nothing */ static void add_static_arp_ipv4_entry(struct rte_cfgfile_entry *entry, uint8_t port_id) { struct arp_ip_key key; struct arp_entry_data *data; char *low_ptr; char *high_ptr; char *saveptr; struct in_addr low_addr; struct in_addr high_addr; uint32_t low_ip; uint32_t high_ip; uint32_t cur_ip; struct ether_addr hw_addr; int ret; low_ptr = strtok_r(entry->name, " \t", &saveptr); high_ptr = strtok_r(NULL, " \t", &saveptr); if (low_ptr == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv4:Error parsing static arp entry: %s = %s\n", LOG_VALUE, entry->name, entry->value); return; } ret = inet_aton(low_ptr, &low_addr); if (ret == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv4:Error parsing static arp entry: %s = %s\n", LOG_VALUE, entry->name, entry->value); return; } if (high_ptr) { ret = inet_aton(high_ptr, &high_addr); if (ret == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv4:Error parsing static arp entry: %s = %s\n", LOG_VALUE, entry->name, entry->value); return; } } else { high_addr = low_addr; } low_ip = ntohl(low_addr.s_addr); high_ip = ntohl(high_addr.s_addr); if (high_ip < low_ip) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv4:Error parsing static arp entry" " - range must be low to high: %s = %s\n", LOG_VALUE, entry->name, entry->value); return; } if (parse_ether_addr(&hw_addr, entry->value)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv4:Error parsing static arp entry mac addr" "%s = %s\n", LOG_VALUE, entry->name, entry->value); return; } for (cur_ip = low_ip; cur_ip <= high_ip; ++cur_ip) { key.ip_type.ipv4 = PRESENT; key.ip_addr.ipv4 = ntohl(cur_ip); data = rte_malloc_socket(NULL, sizeof(struct arp_entry_data), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (data == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv4:Error allocating arp entry - " "%s = %s\n", LOG_VALUE, entry->name, entry->value); return; } data->eth_addr = hw_addr; data->port = port_id; data->status = COMPLETE; data->ip_type.ipv4 = PRESENT; data->ipv4 = key.ip_addr.ipv4; data->last_update = time(NULL); data->queue = NULL; add_arp_data(&key, data, port_id); } } /** * @brief : Add static arp entry for IPv6 Address * @param : entry, entry to be added * @param : port_id, port number * @return : Returns nothing */ static void add_static_arp_ipv6_entry(struct rte_cfgfile_entry *entry, uint8_t port_id) { struct arp_ip_key key; struct arp_entry_data *data; char *low_ptr; char *high_ptr; char *saveptr; struct in6_addr low_addr; struct in6_addr high_addr; struct ether_addr hw_addr; int ret; low_ptr = strtok_r(entry->name, " \t", &saveptr); high_ptr = strtok_r(NULL, " \t", &saveptr); if (low_ptr == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv6:Error parsing static arp entry: %s = %s\n", LOG_VALUE, entry->name, entry->value); return; } ret = inet_pton(AF_INET6, low_ptr, &low_addr); if (ret == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv6:Error parsing static arp entry: %s = %s\n", LOG_VALUE, entry->name, entry->value); return; } if (high_ptr) { ret = inet_pton(AF_INET6, high_ptr, &high_addr); if (ret == 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv6:Error parsing static arp entry: %s = %s\n", LOG_VALUE, entry->name, entry->value); return; } } else { high_addr = low_addr; } if (memcmp(&low_addr, &high_addr, IPV6_ADDRESS_LEN) > 0) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv6:Error parsing static arp entry" " - range must be low to high: %s = %s\n", LOG_VALUE, entry->name, entry->value); return; } if (parse_ether_addr(&hw_addr, entry->value)) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"IPv6:Error parsing static arp entry mac addr" "%s = %s\n", LOG_VALUE, entry->name, entry->value); return; } if (!memcmp(&low_addr, &high_addr, IPV6_ADDRESS_LEN)) { key.ip_type.ipv6 = PRESENT; memcpy(&key.ip_addr.ipv6, &low_addr, IPV6_ADDRESS_LEN); data = rte_malloc_socket(NULL, sizeof(struct arp_entry_data), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (data == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error allocating arp entry - " "%s = %s\n", LOG_VALUE, entry->name, entry->value); return; } data->eth_addr = hw_addr; data->port = port_id; data->status = COMPLETE; data->last_update = time(NULL); data->queue = NULL; data->ip_type.ipv6 = PRESENT; memcpy(&data->ipv6, &key.ip_addr.ipv6, IPV6_ADDRESS_LEN); add_arp_data(&key, data, port_id); } else { int bit = 0; for (;;) { /* Break the Loop if low addr reached to high range */ if (memcmp(&low_addr, &high_addr, IPV6_ADDRESS_LEN) > 0) { break; } key.ip_type.ipv6 = PRESENT; memcpy(&key.ip_addr.ipv6, &low_addr, IPV6_ADDRESS_LEN); data = rte_malloc_socket(NULL, sizeof(struct arp_entry_data), RTE_CACHE_LINE_SIZE, rte_socket_id()); if (data == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error allocating arp entry - " "%s = %s\n", LOG_VALUE, entry->name, entry->value); return; } data->eth_addr = hw_addr; data->port = port_id; data->status = COMPLETE; data->last_update = time(NULL); data->queue = NULL; data->ip_type.ipv6 = PRESENT; memcpy(&data->ipv6, &key.ip_addr.ipv6, IPV6_ADDRESS_LEN); add_arp_data(&key, data, port_id); /* Increment the Low addr pointer towards high pointer*/ for (bit = 15; bit >=0; --bit) { if (low_addr.s6_addr[bit] < 255) { low_addr.s6_addr[bit]++; break; } else { low_addr.s6_addr[bit] = 0; } } /* Break the loop if reached to last bit*/ if (bit < 0) { break; } } } } /** * @brief : Configure static arp * @param : No param * @return : Returns nothing */ static void config_static_arp(void) { int i; int num_eb_entries; int num_wb_entries; struct rte_cfgfile_entry *eb_entries = NULL; struct rte_cfgfile_entry *wb_entries = NULL; struct rte_cfgfile *file = rte_cfgfile_load(STATIC_ARP_FILE, 0); if (file == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Cannot load configuration file %s\n", LOG_VALUE, STATIC_ARP_FILE); return; } clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Parsing %s\n", LOG_VALUE, STATIC_ARP_FILE); /* VS: EB IPv4 entries */ num_eb_entries = rte_cfgfile_section_num_entries(file, "EASTBOUND_IPv4"); if (num_eb_entries > 0) { eb_entries = rte_malloc_socket(NULL, sizeof(struct rte_cfgfile_entry) * num_eb_entries, RTE_CACHE_LINE_SIZE, rte_socket_id()); } if (eb_entries == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error configuring EB IPv4 entry of %s\n", LOG_VALUE, STATIC_ARP_FILE); } else { rte_cfgfile_section_entries(file, "EASTBOUND_IPv4", eb_entries, num_eb_entries); for (i = 0; i < num_eb_entries; ++i) { clLog(clSystemLog, eCLSeverityDebug,"[EASTBOUND_IPv4]: %s = %s\n", eb_entries[i].name, eb_entries[i].value); add_static_arp_ipv4_entry(&eb_entries[i], SGI_PORT_ID); } rte_free(eb_entries); eb_entries = NULL; } /* VS: EB IPv6 entries */ num_eb_entries = rte_cfgfile_section_num_entries(file, "EASTBOUND_IPv6"); if (num_eb_entries > 0) { eb_entries = rte_malloc_socket(NULL, sizeof(struct rte_cfgfile_entry) * num_eb_entries, RTE_CACHE_LINE_SIZE, rte_socket_id()); } if (eb_entries == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error configuring EB IPv6 entry of %s\n", LOG_VALUE, STATIC_ARP_FILE); } else { rte_cfgfile_section_entries(file, "EASTBOUND_IPv6", eb_entries, num_eb_entries); for (i = 0; i < num_eb_entries; ++i) { clLog(clSystemLog, eCLSeverityDebug,"[EASTBOUND_IPv6]: %s = %s\n", eb_entries[i].name, eb_entries[i].value); add_static_arp_ipv6_entry(&eb_entries[i], SGI_PORT_ID); } rte_free(eb_entries); eb_entries = NULL; } /* VS: WB IPv4 entries */ num_wb_entries = rte_cfgfile_section_num_entries(file, "WESTBOUND_IPv4"); if (num_wb_entries > 0) { wb_entries = rte_malloc_socket(NULL, sizeof(struct rte_cfgfile_entry) * num_wb_entries, RTE_CACHE_LINE_SIZE, rte_socket_id()); } if (wb_entries == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error configuring WB IPv4 entry of %s\n", LOG_VALUE, STATIC_ARP_FILE); } else { rte_cfgfile_section_entries(file, "WESTBOUND_IPv4", wb_entries, num_wb_entries); for (i = 0; i < num_wb_entries; ++i) { clLog(clSystemLog, eCLSeverityDebug,"[WESTBOUND_IPv4]: %s = %s\n", wb_entries[i].name, wb_entries[i].value); add_static_arp_ipv4_entry(&wb_entries[i], S1U_PORT_ID); } rte_free(wb_entries); wb_entries = NULL; } /* VS: WB IPv6 entries */ num_wb_entries = rte_cfgfile_section_num_entries(file, "WESTBOUND_IPv6"); if (num_wb_entries > 0) { wb_entries = rte_malloc_socket(NULL, sizeof(struct rte_cfgfile_entry) * num_wb_entries, RTE_CACHE_LINE_SIZE, rte_socket_id()); } if (wb_entries == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Error configuring WB IPv6 entry of %s\n", LOG_VALUE, STATIC_ARP_FILE); } else { rte_cfgfile_section_entries(file, "WESTBOUND_IPv6", wb_entries, num_wb_entries); for (i = 0; i < num_wb_entries; ++i) { clLog(clSystemLog, eCLSeverityDebug,"[WESTBOUND_IPv6]: %s = %s\n", wb_entries[i].name, wb_entries[i].value); add_static_arp_ipv6_entry(&wb_entries[i], S1U_PORT_ID); } rte_free(wb_entries); wb_entries = NULL; } if (ARPICMP_DEBUG) print_arp_table(); } #endif /* STATIC_ARP */ /** * VS: Routing Discovery */ /** * @brief : Print route entry information * @param : entry, route information entry * @return : Returns 0 in case of success , -1 otherwise */ static int print_route_entry( struct RouteInfo *entry) { /* VS: Print the route records on cosole */ printf("-----------\t------- \t--------\t------\t------ \n"); printf("Destination\tGateway \tNetmask \tflags \tIfname \n"); printf("-----------\t------- \t--------\t------\t------ \n"); struct in_addr IP_Addr, GW_Addr, Net_Mask; IP_Addr.s_addr = entry->dstAddr; GW_Addr.s_addr = entry->gateWay; Net_Mask.s_addr = ntohl(entry->mask); strncpy(ipAddr, inet_ntoa(IP_Addr), sizeof(ipAddr)); strncpy(gwAddr, inet_ntoa(GW_Addr), sizeof(gwAddr)); strncpy(netMask, inet_ntoa(Net_Mask), sizeof(netMask)); printf("%s \t%8s\t%8s \t%u \t%s\n", ipAddr, gwAddr, netMask, entry->flags, entry->ifName); printf("-----------\t------- \t--------\t------\t------ \n"); return 0; } /** * @brief : Print IPv6 Link Local Layer entry information * @param : entry, route information entry * @return : Returns 0 in case of success , -1 otherwise */ static int print_ipv6_link_entry( struct RouteInfo_v6 *entry) { /* VS: Print the route records on cosole */ printf("--------------------- \t\t\t-------\n"); printf("Local Link Layer Addr \t\t\tIfname \n"); printf("--------------------- \t\t\t-------\n"); printf(""IPv6_FMT"\t%s\n", IPv6_PRINT(entry->dstAddr), entry->ifName); printf("--------------------- \t\t\t--------\n"); return 0; } /** * @brief : Print IPv6 route entry information * @param : entry, route information entry * @return : Returns 0 in case of success , -1 otherwise */ static int print_ipv6_route_entry( struct RouteInfo_v6 *entry) { /* VS: Print the route records on cosole */ printf("-----------\t------- \t------ \n"); printf("Destination\tNext Hop\tIfname \n"); printf("-----------\t------- \t------ \n"); printf(""IPv6_FMT"\t"IPv6_FMT"\t%s\n", IPv6_PRINT(entry->dstAddr), IPv6_PRINT(entry->gateWay), entry->ifName); printf("-----------\t------- \t------- \n"); return 0; } /** * @brief : Delete entry in route table. * @param : info, route information entry * @return : Returns nothing */ static int del_route_entry( struct RouteInfo *info) { int ret; struct RouteInfo *ret_route_data = NULL; /* Check Route Entry is present or Not */ ret = rte_hash_lookup_data(route_hash_handle, &info->dstAddr, (void **)&ret_route_data); if (ret) { /* Route Entry is present. Delete Route Entry */ ret = rte_hash_del_key(route_hash_handle, &info->dstAddr); if (ret < 0) { rte_panic("ROUTE: Error at:%s::" "\n\tDelete route_data= %s" "\n\tError= %s\n", __func__, inet_ntoa(*(struct in_addr *)&info->dstAddr), rte_strerror(abs(ret))); return -1; } printf("Route entry DELETED from hash table :: \n"); print_route_entry(info); } return 0; } /** * @brief : Delete entry in route table for IPv6. * @param : info, route information entry * @return : Returns nothing */ static void del_ipv6_route_entry( struct RouteInfo_v6 *info) { printf("Route entry DELETED in hash table :: \n"); print_ipv6_route_entry(info); return; } /** * @brief : Add entry in route table for IPv6. * @param : info, route information entry * @return : Returns nothing */ static void add_ipv6_route_entry( struct RouteInfo_v6 *info) { printf("Route entry ADDED in hash table :: \n"); print_ipv6_route_entry(info); return; } /** * @brief : Add entry in route table. * @param : info, route information entry * @return : Returns nothing */ static void add_route_data( struct RouteInfo *info) { int ret; struct RouteInfo *ret_route_data = NULL; /* Check Route Entry is present or Not */ ret = rte_hash_lookup_data(route_hash_handle, &info->dstAddr, (void **)&ret_route_data); if (ret < 0) { /* Route Entry not present. Add Route Entry */ if (gatway_flag != 1) { info->gateWay = 0; memset(&info->gateWay_Mac, 0, sizeof(struct ether_addr)); } ret = rte_hash_add_key_data(route_hash_handle, &info->dstAddr, info); if (ret) { /* Add route_data panic because: * ret == -EINVAL && wrong parameter || * ret == -ENOSPC && hash table size insufficient * */ rte_panic("ROUTE: Error at:%s::" "\n\tadd route_data= %s" "\n\tError= %s\n", __func__, inet_ntoa(*(struct in_addr *)&info->dstAddr), rte_strerror(abs(ret))); } gatway_flag = 0; printf("Route entry ADDED in hash table :: \n"); print_route_entry(info); return; } else if (ret == 0) { if (ret_route_data->dstAddr == info->dstAddr){ /* Route Entry not present. Add Route Entry */ if (gatway_flag != 1) { info->gateWay = 0; memset(&info->gateWay_Mac, 0, sizeof(struct ether_addr)); } ret = rte_hash_add_key_data(route_hash_handle, &info->dstAddr, info); if (ret) { /* Add route_data panic because: * ret == -EINVAL && wrong parameter || * ret == -ENOSPC && hash table size insufficient * */ rte_panic("ROUTE: Error at:%s::" "\n\tadd route_data= %s" "\n\tError= %s\n", __func__, inet_ntoa(*(struct in_addr *)&info->dstAddr), rte_strerror(abs(ret))); } gatway_flag = 0; clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Route entry ADDED in hash table\n", LOG_VALUE); print_route_entry(info); return; } } print_route_entry(ret_route_data); } /** * @brief : Get the interface name based on interface index. * @param : iface_index, interface index * @param : iface_Name, parameter to store interface name * @return : Returns 0 in case of success , -1 otherwise */ static int get_iface_name(int iface_index, char *iface_Name) { int fd; struct ifreq ifr; fd = socket(AF_INET, SOCK_DGRAM, 0); if(fd == -1) { perror("socket"); exit(1); } ifr.ifr_ifindex = iface_index; if(ioctl(fd, SIOCGIFNAME, &ifr, sizeof(ifr))) { perror("ioctl"); return -1; } strncpy(iface_Name, ifr.ifr_name, IF_NAMESIZE); return 0; } /* * @brief : Read cache data * @param : Fd, file descriptor of input data * @param : Buffer, buffer to store read result * @return : Returns 0 in case of success , -1 otherwise */ static int readCache(int Fd, char *Buffer) { if (Fd < 0) { perror("Error"); return -1; } char ch; size_t Read = 0; while (read(Fd, (Buffer + Read), 1)) { ch = Buffer[Read]; if (ch == '\n') { break; } Read++; } if (Read) { Buffer[Read] = 0; return 0; } clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to readCache\n", LOG_VALUE); return -1; } /** * @brief : Get field value * @param : Line_Arg, input data * @param : Field, param to store output * @return : Returns result string in case of success, NULL otherwise */ static char *getField(char *Line_Arg, int Field) { char *ret = NULL; char *s = NULL; char *Line = malloc(strnlen(Line_Arg, ARP_BUFFER_LEN)), *ptr; if(Line != NULL){ memcpy(Line, Line_Arg, strnlen(Line_Arg, ARP_BUFFER_LEN)); ptr = Line; } else { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Failed to allocate memory\n", LOG_VALUE); } s = strtok(Line, ARP_DELIM); while (Field && s) { s = strtok(NULL, ARP_DELIM); Field--; }; if (s) { int len = strnlen(s,ARP_BUFFER_LEN); ret = (char*)malloc(len + 1); memset(ret, 0, len + 1); memcpy(ret, s, len); } free(ptr); return s ? ret : NULL; } /** * @brief : Get the Gateway MAC Address from ARP TABLE. * @param : IP_gateWay, gateway address * @param : iface_Mac, mac address * @return : Returns 0 in case of success , 1 otherwise */ static int get_gateWay_mac(uint32_t IP_gateWay, char *iface_Mac) { int Fd = open(ARP_CACHE, O_RDONLY); if (Fd < 0) { fprintf(stdout, "Arp Cache: Failed to open file \"%s\"\n", ARP_CACHE); return 1; } char Buffer[ARP_BUFFER_LEN]; /* Ignore first line */ int Ret = readCache(Fd, &Buffer[0]); Ret = readCache(Fd, &Buffer[0]); //int count = 0; while (Ret == 0) { char *Line; Line = &Buffer[0]; /* Get Ip, Mac, Interface */ char *Ip = getField(Line, 0); char *Mac = getField(Line, 3); char *IfaceStr = getField(Line, 5); char *tmp = inet_ntoa(*(struct in_addr *)&IP_gateWay); if (strcmp(Ip, tmp) == 0) { //fprintf(stdout, "%03d: here, Mac Address of [%s] on [%s] is \"%s\"\n", // ++count, Ip, IfaceStr, Mac); strncpy(iface_Mac, Mac, MAC_ADDR_LEN); return 0; } free(Ip); free(Mac); free(IfaceStr); Ret = readCache(Fd, &Buffer[0]); } close(Fd); return 0; } /** * @brief : Create pthread to read or receive data/events from netlink socket. * @param : arg, input * @return : Returns nothing */ static void *netlink_recv_thread_ipv6(void *arg) { int i = 0; int recv_bytes = 0; struct nlmsghdr *nlp; struct rtmsg *rtp; struct RouteInfo_v6 route[24]; struct rtattr *rtap; int rtl = 0; char buffer[BUFFER_SIZE]; bzero(buffer, sizeof(buffer)); struct sockaddr_nl *addr = (struct sockaddr_nl *)arg; while(1) { /* VS: Receive data pkts from netlink socket*/ while (1) { bzero(buffer, sizeof(buffer)); recv_bytes = recv(route_sock_v6, buffer, sizeof(buffer), 0); if (recv_bytes < 0) clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"IPv6: Error in recv\n", LOG_VALUE); nlp = (struct nlmsghdr *) buffer; if ((nlp->nlmsg_type == NLMSG_DONE) || (nlp->nlmsg_type == RTM_NEWROUTE) || (nlp->nlmsg_type == RTM_DELROUTE) || (nlp->nlmsg_type == RTM_NEWADDR) || (addr->nl_groups == RTMGRP_IPV6_ROUTE)) break; } if (nlp->nlmsg_type == RTM_NEWADDR) { /* Set the Reference Link Local Layer Address*/ struct in6_addr tmp_addr = {0}; char *tmp = "fe80::"; /* All Node IPV6 Address */ if (!inet_pton(AF_INET6, tmp, &tmp_addr)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"LL2:Invalid Local Link layer IPv6 Address\n", LOG_VALUE); } for (i = -1 ; NLMSG_OK(nlp, recv_bytes); \ nlp = NLMSG_NEXT(nlp, recv_bytes)) { uint8_t ignore = 0; struct ifaddrmsg *ifa = NULL; i++; /* Get the interface details */ ifa = (struct ifaddrmsg *)NLMSG_DATA(nlp); /* Get the interface attribute info */ rtap = (struct rtattr *)IFA_RTA(ifa); /* Get the interface info and check valid interface needed */ get_iface_name(ifa->ifa_index, route[i].ifName); rtl = IFA_PAYLOAD(nlp); /* Loop through all attributes */ for( ; RTA_OK(rtap, rtl); rtap = RTA_NEXT(rtap, rtl)) { switch(rtap->rta_type) { case IFA_ADDRESS: memcpy(&route[i].dstAddr.s6_addr, RTA_DATA(rtap), IPV6_ADDR_LEN); break; default: break; } } /* Filter the WBdev and EBdev Interfaces */ if (!memcmp(&route[i].ifName, &app.wb_iface_name, MAX_LEN)) { /* Validate the Link Layer hexstat: 2 byte, 'fe80' */ for (uint8_t inx = 0; inx < 2; inx++) { if (memcmp(&route[i].dstAddr.s6_addr[inx], &tmp_addr.s6_addr[inx], sizeof(route[i].dstAddr.s6_addr[inx]))) { ignore = 1; break; } } if (!ignore) { fprintf(stderr, "IPv6: %s interface Local Link Layer Addr..\n", route[i].ifName); app.wb_l3_ipv6 = route[i].dstAddr; print_ipv6_link_entry(&route[i]); } } if (!memcmp(&route[i].ifName, &app.eb_iface_name, MAX_LEN)) { /* Validate the Link Layer hexstat: 2 byte, 'fe80' */ for (uint8_t inx = 0; inx < 2; inx++) { if (memcmp(&route[i].dstAddr.s6_addr[inx], &tmp_addr.s6_addr[inx], sizeof(route[i].dstAddr.s6_addr[inx]))) { ignore = 1; break; } } if (!ignore) { fprintf(stderr, "IPv6: %s interface Local Link Layer Addr..\n", route[i].ifName); app.eb_l3_ipv6 = route[i].dstAddr; print_ipv6_link_entry(&route[i]); } } } } else { for (i = -1 ; NLMSG_OK(nlp, recv_bytes); \ nlp = NLMSG_NEXT(nlp, recv_bytes)) { rtp = (struct rtmsg *) NLMSG_DATA(nlp); /* Get main routing table */ if ((rtp->rtm_family != AF_INET6) || (rtp->rtm_table != RT_TABLE_MAIN)) continue; i++; /* Get attributes of rtp */ rtap = (struct rtattr *) RTM_RTA(rtp); /* Get the route atttibutes len */ rtl = RTM_PAYLOAD(nlp); /* Loop through all attributes */ for( ; RTA_OK(rtap, rtl); rtap = RTA_NEXT(rtap, rtl)) { switch(rtap->rta_type) { case RTA_DST: route[i].dstAddr = *(struct in6_addr *)RTA_DATA(rtap); break; case RTA_GATEWAY: route[i].gateWay = *(struct in6_addr *)RTA_DATA(rtap); break; case RTA_SRC: route[i].srcAddr = *(struct in6_addr *)RTA_DATA(rtap); break; case RTA_PREFSRC: route[i].srcAddr = *(struct in6_addr *)RTA_DATA(rtap); break; case RTA_OIF: get_iface_name(*((int *) RTA_DATA(rtap)), route[i].ifName); break; case RTA_IIF: break; default: break; } } /* Now we can dump the routing attributes */ if (nlp->nlmsg_type == RTM_DELROUTE) { del_ipv6_route_entry(&route[i]); } if (nlp->nlmsg_type == RTM_NEWROUTE) { add_ipv6_route_entry(&route[i]); } } } } fprintf(stderr, "IPv6: Netlink Listner thread terminated.\n"); return NULL; //GCC_Security flag } /** * @brief : Create pthread to read or receive data/events from netlink socket. * @param : arg, input * @return : Returns nothing */ static void *netlink_recv_thread(void *arg) { int recv_bytes = 0; int count = 0, i; struct nlmsghdr *nlp; struct rtmsg *rtp; struct RouteInfo route[24]; struct rtattr *rtap; int rtl = 0; char buffer[BUFFER_SIZE]; bzero(buffer, sizeof(buffer)); struct sockaddr_nl *addr = (struct sockaddr_nl *)arg; while(1) { /* VS: Receive data pkts from netlink socket*/ while (1) { bzero(buffer, sizeof(buffer)); recv_bytes = recv(route_sock_v4, buffer, sizeof(buffer), 0); if (recv_bytes < 0) clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error in recv\n", LOG_VALUE); nlp = (struct nlmsghdr *) buffer; if ((nlp->nlmsg_type == NLMSG_DONE) || (nlp->nlmsg_type == RTM_NEWROUTE) || (nlp->nlmsg_type == RTM_DELROUTE) || (addr->nl_groups == RTMGRP_IPV4_ROUTE)) break; } for (i = -1 ; NLMSG_OK(nlp, recv_bytes); \ nlp = NLMSG_NEXT(nlp, recv_bytes)) { rtp = (struct rtmsg *) NLMSG_DATA(nlp); /* Get main routing table */ if ((rtp->rtm_family != AF_INET) || (rtp->rtm_table != RT_TABLE_MAIN)) continue; i++; /* Get attributes of rtp */ rtap = (struct rtattr *) RTM_RTA(rtp); /* Get the route atttibutes len */ rtl = RTM_PAYLOAD(nlp); /* Loop through all attributes */ for( ; RTA_OK(rtap, rtl); rtap = RTA_NEXT(rtap, rtl)) { switch(rtap->rta_type) { /* Get the destination IPv4 address */ case RTA_DST: count = 32 - rtp->rtm_dst_len; route[i].dstAddr = *(uint32_t *) RTA_DATA(rtap); route[i].mask = 0xffffffff; for (; count!=0 ;count--) route[i].mask = route[i].mask << 1; break; case RTA_GATEWAY: { gatway_flag = 1; char mac[MAC_ADDR_LEN]; route[i].gateWay = *(uint32_t *) RTA_DATA(rtap); get_gateWay_mac(route[i].gateWay, mac); if (parse_ether_addr(&(route[i].gateWay_Mac), mac)) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Error parsing gatway arp entry mac addr" "= %s\n", LOG_VALUE, mac); } fprintf(stdout, "Gateway, Mac Address of [%s] is \"%02X:%02X:%02X:%02X:%02X:%02X\"\n", inet_ntoa(*(struct in_addr *)&route[i].gateWay), route[i].gateWay_Mac.addr_bytes[0], route[i].gateWay_Mac.addr_bytes[1], route[i].gateWay_Mac.addr_bytes[2], route[i].gateWay_Mac.addr_bytes[3], route[i].gateWay_Mac.addr_bytes[4], route[i].gateWay_Mac.addr_bytes[5]); break; } case RTA_PREFSRC: route[i].srcAddr = *(uint32_t *) RTA_DATA(rtap); break; case RTA_OIF: get_iface_name(*((int *) RTA_DATA(rtap)), route[i].ifName); break; default: break; } route[i].flags|=RTF_UP; if (route[i].gateWay != 0) route[i].flags|=RTF_GATEWAY; if (route[i].mask == 0xFFFFFFFF) route[i].flags|=RTF_HOST; } /* Now we can dump the routing attributes */ if (nlp->nlmsg_type == RTM_DELROUTE) { del_route_entry(&route[i]); } if (nlp->nlmsg_type == RTM_NEWROUTE) { add_route_data(&route[i]); } } } fprintf(stderr, "IPv4: Netlink Listner thread terminated.\n"); return NULL; //GCC_Security flag } /** * @brief : Initialize netlink socket * @param : No param * @return : Returns 0 in case of success , -1 otherwise */ static int init_netlink_socket(void) { int retValue = -1; struct sockaddr_nl addr_t; struct sockaddr_nl addr_v6; struct addr_info addr = {0}; route_request *request = (route_request *)malloc(sizeof(route_request)); route_request *request_v6 = (route_request *)malloc(sizeof(route_request)); route_sock_v4 = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE); route_sock_v6 = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE); clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"NetLink Sockets Created, IPv4:%u, IPv6:%u\n", LOG_VALUE, route_sock_v4, route_sock_v6); bzero(request, sizeof(route_request)); bzero(request_v6, sizeof(route_request)); /* Fill the NETLINK header for IPv4 */ request->nlMsgHdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); request->nlMsgHdr.nlmsg_type = RTM_GETROUTE; //request->nlMsgHdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; request->nlMsgHdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT; /* set the routing message header IPv4*/ request->rtMsg.rtm_family = AF_INET; request->rtMsg.rtm_table = RT_TABLE_MAIN; /* Set Sockets info for IPv4 */ addr_t.nl_family = PF_NETLINK; addr_t.nl_pad = 0; addr_t.nl_pid = getpid(); addr_t.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_ROUTE; /* Fill the NETLINK header for IPv6 */ request_v6->nlMsgHdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); request_v6->nlMsgHdr.nlmsg_type = RTM_GETROUTE | RTM_GETADDR; request_v6->nlMsgHdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT; /* set the routing message header IPv6*/ request_v6->rtMsg.rtm_family = AF_INET6; request_v6->rtMsg.rtm_table = RT_TABLE_MAIN; /* Set Sockets info for IPv6 */ addr_v6.nl_family = PF_NETLINK; addr_v6.nl_pad = 0; //addr_v6.nl_pid = getpid(); addr_v6.nl_groups = RTMGRP_LINK | RTMGRP_IPV6_ROUTE | RTMGRP_IPV6_IFADDR; if (bind(route_sock_v4, (struct sockaddr *)&addr_t, sizeof(addr_t)) < 0) { fprintf(stderr, "IPv4 bind socket ID:%u\n", route_sock_v4); ERR_RET("IPv4 bind socket"); } if (bind(route_sock_v6, (struct sockaddr *)&addr_v6, sizeof(addr_v6)) < 0) { fprintf(stderr, "IPv6 bind socket ID:%u\n", route_sock_v6); ERR_RET("IPv6 bind socket"); } /* Send routing request IPv4 */ if ((retValue = send(route_sock_v4, request, sizeof(route_request), 0)) < 0) { perror("IPv4: Send"); return -1; } /* Send routing request IPv6 */ if ((retValue = send(route_sock_v6, request_v6, sizeof(route_request), 0)) < 0) { perror("IPv6: Send"); return -1; } /* Fill the IPv4 and IPv6 Addr Structure */ addr.addr_ipv4 = addr_t; addr.addr_ipv6 = addr_v6; /* * Create pthread to read or receive data/events from netlink socket. */ pthread_t net, net1; int err_val; err_val = pthread_create(&net, NULL, &netlink_recv_thread, &addr.addr_ipv4); if (err_val != 0) { printf("\nAPI_IPv4: Can't create Netlink socket event reader thread :[%s]\n", strerror(err_val)); return -1; } err_val = pthread_create(&net1, NULL, &netlink_recv_thread_ipv6, &addr.addr_ipv6); if (err_val != 0) { printf("\nAPI_IPv6: Can't create Netlink socket event reader thread :[%s]\n", strerror(err_val)); return -1; } else { printf("\nAPI: Netlink socket event reader thread " "created successfully...!!!\n"); } return 0; } void epc_arp_init(void) { struct rte_pipeline *p; uint32_t i; struct epc_arp_params *params = &arp_params; /* Pipeline */ { struct rte_pipeline_params pipeline_params = { .name = "arp icmp", .socket_id = rte_socket_id(), .offset_port_id = 0, }; p = rte_pipeline_create(&pipeline_params); if (p == NULL) { return; } myP = p; } /* Input port configuration */ for (i = 0; i < epc_app.n_ports; i++) { struct rte_port_ring_reader_params port_ring_params = { .ring = epc_app.epc_mct_rx[i] }; struct rte_pipeline_port_in_params port_params = { .ops = &rte_port_ring_reader_ops, .arg_create = &port_ring_params, .f_action = port_in_ah_arp_key, .arg_ah = (void *)(uintptr_t)i, .burst_size = epc_app.burst_size_tx_write }; int status = rte_pipeline_port_in_create(p, &port_params, &params->port_in_id[i]); if (status) { rte_pipeline_free(p); } } /* Output port configuration */ for (i = 0; i < epc_app.n_ports; i++) { struct rte_port_ethdev_writer_nodrop_params port_ethdev_params = { .port_id = epc_app.ports[i], .queue_id = 0, .tx_burst_sz = epc_app.burst_size_tx_write, .n_retries = 0, }; struct rte_pipeline_port_out_params port_params = { .ops = &rte_port_ethdev_writer_nodrop_ops, .arg_create = (void *)&port_ethdev_params, .f_action = NULL, .arg_ah = NULL, }; if ( rte_pipeline_port_out_create(p, &port_params, &params->port_out_id[i]) ) { rte_panic("%s::" "\n\tError!!! On config o/p ring RX %i\n", __func__, i); } } /* Table configuration */ struct rte_pipeline_table_params table_params = { .ops = &rte_table_stub_ops, }; int status; status = rte_pipeline_table_create(p, &table_params, &params->table_id); if (status) { rte_pipeline_free(p); return; } /* Add entries to tables */ for (i = 0; i < epc_app.n_ports; i++) { struct rte_pipeline_table_entry entry = { .action = RTE_PIPELINE_ACTION_DROP, }; struct rte_pipeline_table_entry *default_entry_ptr; if ( rte_pipeline_table_default_entry_add(p, params->table_id, &entry, &default_entry_ptr) ) rte_panic("Error!!! on default entry @table id= %u\n", params->table_id); } for (i = 0; i < epc_app.n_ports; i++) { int status = rte_pipeline_port_in_connect_to_table(p, params->port_in_id[i], params->table_id); if (status) { rte_pipeline_free(p); } } for (i = 0; i < epc_app.n_ports; i++) { int status = rte_pipeline_port_in_enable(p, params->port_in_id[i]); if (status) { rte_pipeline_free(p); } } if (rte_pipeline_check(p) < 0) { rte_pipeline_free(p); rte_panic("%s::" "\n\tPipeline consistency check failed\n", __func__); } uint8_t port_cnt; for (port_cnt = 0; port_cnt < NUM_SPGW_PORTS; ++port_cnt) { /* Create arp_pkt TX mempool for each port */ arp_xmpool[port_cnt] = rte_pktmbuf_pool_create( arp_xmpoolname[port_cnt], NB_ARP_MBUF, 32, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); if (arp_xmpool[port_cnt] == NULL) { rte_panic("rte_pktmbuf_pool_create failed::" "\n\tarp_icmp_xmpoolname[%u]= %s;" "\n\trte_strerror= %s\n", port_cnt, arp_xmpoolname[port_cnt], rte_strerror(abs(errno))); return; } /* Allocate arp_pkt mbuf at port mempool */ arp_pkt[port_cnt] = rte_pktmbuf_alloc(arp_xmpool[port_cnt]); if (arp_pkt[port_cnt] == NULL) { return; } /* Create arp_queued_pkt TX mmempool for each port */ arp_quxmpool[port_cnt] = rte_pktmbuf_pool_create( arp_quxmpoolname[port_cnt], NB_ARP_MBUF, 32, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); if (arp_quxmpool[port_cnt] == NULL) { rte_panic("rte_pktmbuf_pool_create failed::" "\n\tarp_quxmpoolname[%u]= %s;" "\n\trte_strerror= %s\n", port_cnt, arp_quxmpoolname[port_cnt], rte_strerror(abs(errno))); return; } /* Create arp_hash for each port */ arp_hash_params[port_cnt].socket_id = rte_socket_id(); arp_hash_handle[port_cnt] = rte_hash_create(&arp_hash_params[port_cnt]); if (!arp_hash_handle[port_cnt]) { rte_panic("%s::" "\n\thash create failed::" "\n\trte_strerror= %s; rte_errno= %u\n", arp_hash_params[port_cnt].name, rte_strerror(rte_errno), rte_errno); } } /** * VS: Routing Discovery */ if (init_netlink_socket() != 0) rte_exit(EXIT_FAILURE, "Cannot init netlink socket...!!!\n"); #ifdef STATIC_ARP config_static_arp(); #endif /* STATIC_ARP */ } /** * @brief : Burst rx from kni interface and enqueue rx pkts in ring * @param : No param * @return : Returns 0 in case of success , -1 otherwise */ static void *handle_kni_process(__rte_unused void *arg) { for (uint32_t port = 0; port < nb_ports; port++) { kni_egress(kni_port_params_array[port]); } return NULL; //GCC_Security flag } void process_li_data() { int ret = 0; struct ip_addr dummy = {0}; uint32_t li_ul_cnt = rte_ring_count(li_ul_ring); if(li_ul_cnt){ li_data_t *li_data[li_ul_cnt]; uint32_t ul_cnt = rte_ring_dequeue_bulk(li_ul_ring, (void**)li_data, li_ul_cnt, NULL); for(uint32_t i = 0; i < ul_cnt; i++){ if (NULL == li_data[i]) { continue; } int size = li_data[i]->size; uint64_t id = li_data[i]->id; uint64_t imsi = li_data[i]->imsi; if (NULL == li_data[i]->pkts) { continue; } create_li_header(li_data[i]->pkts, &size, CC_BASED, id, imsi, dummy, dummy, 0, 0, li_data[i]->forward); ret = send_li_data_pkt(ddf3_fd, li_data[i]->pkts, size); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to send UPLINK" " data on TCP sock with error %d\n", LOG_VALUE, ret); } rte_free(li_data[i]->pkts); rte_free(li_data[i]); } } uint32_t li_dl_cnt = rte_ring_count(li_dl_ring); if(li_dl_cnt){ li_data_t *li_data[li_dl_cnt]; uint32_t dl_cnt = rte_ring_dequeue_bulk(li_dl_ring, (void**)li_data, li_dl_cnt, NULL); for(uint32_t i = 0; i < dl_cnt; i++){ if (li_data[i] == NULL) { continue; } int size = li_data[i]->size; uint64_t id = li_data[i]->id; uint64_t imsi = li_data[i]->imsi; if (li_data[i]->pkts == NULL) { continue; } create_li_header(li_data[i]->pkts, &size, CC_BASED, id, imsi, dummy, dummy, 0, 0, li_data[i]->forward); ret = send_li_data_pkt(ddf3_fd, li_data[i]->pkts, size); if (ret < 0) { clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to send DOWNLINK" " data on TCP sock with error %d\n", LOG_VALUE, ret); } rte_free(li_data[i]->pkts); rte_free(li_data[i]); } } return; } void epc_arp(__rte_unused void *arg) { struct epc_arp_params *param = &arp_params; rte_pipeline_run(myP); if (++param->flush_count >= param->flush_max) { rte_pipeline_flush(myP); param->flush_count = 0; } handle_kni_process(NULL); #ifdef NGCORE_SHRINK #ifdef STATS epc_stats_core(); #endif #endif process_li_data(); store_cdr_into_file_pfcp_sess_rpt_req(); }
nikhilc149/e-utran-features-bug-fixes
dp/pfcp_up_llist.h
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef PFCP_UP_LLIST_H #define PFCP_UP_LLIST_H #include "up_main.h" #include "pfcp_messages.h" #include "pfcp_up_struct.h" /** * @brief : Function to add a node in PDR Linked List. * @param : head, linked list head pointer * @param : sess_data, node to be added * @retrun : Returns linked list head pointer */ int8_t insert_sess_data_node(pfcp_session_datat_t *head, pfcp_session_datat_t *sess_data); /** * @brief : Function to remove the last node from the session data Linked List. * @param : head, linked list head pointer * @param : node, node to be deleted * @retrun : Returns linked list head pointer */ pfcp_session_datat_t *remove_sess_data_node(pfcp_session_datat_t *head, pfcp_session_datat_t *node); /** * @brief : Function to add a node in PDR Linked List. * @param : head, linked list head pointer * @param : pdr, pdr information * @return : Returns 0 in case of success , -1 otherwise */ int8_t insert_pdr_node(pdr_info_t *head, pdr_info_t *pdr); /** * @brief : Function to get a node from PDR Linked List. * @param : head, linked list head pointer * @param : precedence, precedence value * @retrun : Returns linked list head pointer */ pdr_info_t *get_pdr_node(pdr_info_t *head, uint32_t precedence); /** * @brief : Function to remove the node from the PDR Linked List. * @param : head, linked list head pointer * @param : node, node to be removed * @retrun : Returns linked list head pointer */ pdr_info_t *remove_pdr_node(pdr_info_t *head, pdr_info_t *node); /** * @brief : Function to add a node in QER Linked List. * @param : head, linked list head pointer * @param : qer, qer information * @return : Returns 0 in case of success , -1 otherwise. */ int8_t insert_qer_node(qer_info_t *head, qer_info_t *qer); /** * @brief : Function to remove the node from the QER Linked List. * @param : head, linked list head pointer * @param : node, node to be removed * @retrun : Returns linked list head pointer */ qer_info_t *remove_qer_node(qer_info_t *head, qer_info_t *node); /** * @brief : Function to add a node in URR Linked List. * @param : head, linked list head pointer * @param : urr, node to be added * @retrun : Returns 0 in case of success , -1 otherwise */ int8_t insert_urr_node(urr_info_t *head, urr_info_t *urr); /** * @brief : Function to remove the node from the URR Linked List. * @param : head, linked list head pointer * @param : node, node to be removed * @retrun : Returns linked list head pointer */ urr_info_t *remove_urr_node(urr_info_t *head, urr_info_t *node); /** * @brief : Function to add a node in Predefined rules Linked List. * @param : head, linked list head pointer * @return : Returns 0 in case of success , -1 otherwise */ int8_t insert_predef_rule_node(predef_rules_t *head, predef_rules_t *rules); #endif /* PFCP_UP_LLIST_H */
nikhilc149/e-utran-features-bug-fixes
ulpc/legacy_admf_interface/include/LegacyAdmfInterfaceThread.h
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __LEGACY_ADMF_INTERFACE_THREAD_H_ #define __LEGACY_ADMF_INTERFACE_THREAD_H_ #include <iostream> #include <cstdlib> #include "epctools.h" #include "etevent.h" #include "esocket.h" #include "LegacyAdmfInterfaceListener.h" #include "LegacyAdmfInterfaceTalker.h" #include "LegacyAdmfClient.h" #include "LegacyAdmfInterface.h" #define BACKLOG_CONNECTIION 10 class LegacyAdmfInterfaceListener; class LegacyAdmfInterfaceTalker; class LegacyAdmfClient; class LegacyAdmfInterface; class LegacyAdmfInterfaceThread : public ESocket::ThreadPrivate { public: LegacyAdmfInterfaceThread(LegacyAdmfInterface *intfc); ~LegacyAdmfInterfaceThread(); Void onInit(); Void onQuit(); Void onSocketClosed(ESocket::BasePrivate *psocket); Void onClose(); Void onTimer(EThreadEventTimer *ptimer); Void errorHandler(EError &err, ESocket::BasePrivate *psocket); Void processData(void *packet); Void connect(); LegacyAdmfInterfaceTalker *createLegacyAdmfTalker(); UShort getLegacyAdmfPort() const { return legacyAdmfPort; } LegacyAdmfInterfaceThread &setLegacyAdmfPort(uint16_t port) { legacyAdmfPort = port; return *this; } std::string getLegacyAdmfIp() const { return legacyAdmfIp; } LegacyAdmfInterfaceThread &setLegacyAdmfIp(std::string ip) { legacyAdmfIp = ip; return *this; } UShort getLegacyAdmfInterfacePort() const { return legacyAdmfInterfacePort; } std::string getLegacyAdmfInterfaceIp() const { return legacyAdmfInterfaceIp; } LegacyAdmfInterfaceThread &setLegacyAdmfInterfacePort(uint16_t port) { legacyAdmfInterfacePort = port; return *this; } LegacyAdmfInterfaceThread &setLegacyAdmfInterfaceIp(std::string ip) { legacyAdmfInterfaceIp = ip; return *this; } Void startLegacyAdmfConnectTimer(Long ms = 100000); LegacyAdmfInterface &getLegacyAdmfInterface() { return *legAdmfIntfc; } Void sendPending(); DECLARE_MESSAGE_MAP() private: LegacyAdmfInterface *legAdmfIntfc; LegacyAdmfInterfaceListener *legAdmfIntfcListener; LegacyAdmfInterfaceTalker *legAdmfIntfcTalker; LegacyAdmfClient *legAdmfClient; EThreadEventTimer legAdmfConnectTimer; UShort legacyAdmfPort; std::string legacyAdmfIp; UShort legacyAdmfInterfacePort; std::string legacyAdmfInterfaceIp; Bool quitting; }; #endif /* endif __LEGACY_ADMF_INTERFACE_THREAD_H_ */
nikhilc149/e-utran-features-bug-fixes
ulpc/df/include/TCPListener.h
/* * Copyright (c) 2020 Sprint * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ #ifndef __TCPListener_H_ #define __TCPListener_H_ #include "Common.h" #include "TCPDataProcessor.h" class DfListener; class TCPDataProcessor; class TCPListener : public ESocket::ThreadPrivate { public: /* * @brief : Constructor of class TCPListener */ TCPListener(); /* * @brief : Destructor of class TCPListener */ ~TCPListener(); /* * @brief : Library function of EPCTool */ Void onInit(); /* * @brief : Library function of EPCTool */ Void onQuit(); /* * @brief : Library function of EPCTool */ Void onClose(); /* * @brief : Function connects to the Legacy DF * @param : No function arguments * @return : Returns void */ Void connect(); /* * @brief : Library function of EPCTool */ Void onTimer(EThreadEventTimer *ptimer); /* * @brief : Functionto indicate socket exception * @param : err, error type * @param : psocket, socket * @return : Returns void */ Void errorHandler(EError &err, ESocket::BasePrivate *psocket); /* * @brief : Function tries to initialise legacy interface * @param : No function arguments * @return : Returns void */ Void InitLegacyAgain(); /* * @brief : Function to start timer * @param : No function arguments * @return : Returns void */ Void startDfRetryTimer(); /* * @brief : Function to stop timer * @param : No function arguments * @return : Returns void */ Void stopDfRetryTimer(); /* * @brief : Function creates instance of TCPDataProcessor * @param : No function arguments * @return : Returns TCPDataProcessor instance */ TCPDataProcessor *createDfTalker(); /* * @brief : Function to process data received from DDF * @param : packet, object of struct DfPacket_t * @return : Returns void */ Void processData(DfPacket_t *packet); /* * @brief : Function to delete instance of TCPDataProcessor * on socket close, also tries re-connect to DF * @param : psocket, socket * @return : Returns void */ Void onSocketClosed(ESocket::BasePrivate *psocket); /* * @brief : Function to delete instance of TCPDataProcessor * on socket close, also tries re-connect to DF * @param : psocket, socket * @return : Returns void */ Void onSocketError(ESocket::BasePrivate *psocket); /* * @brief : Const function to get max number of msg used in semaphore * @param : No function arguments * @return : Returns long */ Long getMaxMsgs() const { return m_maxMsgs; } /* * @brief : Function to set max number of msg used in semaphore * @param : maxMsgs, max count of msg * @return : Returns this pointer */ TCPListener &setMaxMsgs(Long maxMsgs) { m_maxMsgs = maxMsgs; return *this; } /* * @brief : Function to indicate data is pending to send to legacy DF * @param : No function arguments * @return : Returns void */ Void setPending(); /* * @brief : Function sends pending data to legacy DF * @param : No function arguments * @return : Returns void */ Void sendPending(); /* * @brief : Function receives ack from legacy DF and moves ptr to next packet, * for which ack is expected * @param : ack_number, acknowledgement number * @return : Returns void */ Void msgCounter(uint32_t ack_number); /* * @brief : Function creates folder to save database file * @param : No function arguments * @return : Returns void */ Void createFolder(); /* * @brief : Function creates file to save packet * @param : No function arguments * @return : Returns void */ bool createFile(); /* * @brief : Function to open the file and set pointer to file, * to read from it * @param : No function arguments * @return : Returns void */ Void readFile(); /* * @brief : Function to delete database file * @param : No function arguments * @return : Returns void */ Void deleteFile(); /* * @brief : Function to check space availability * @param : No function arguments * @return : Returns void */ bool checkAvailableSapce(); /* * @brief : Function to check DF socket, get called from TCPForwardInterface * @param : No function arguments * @return : Returns void */ Void checkSocket(); /* * @brief : Function to set BaseLegacyInterface pointer value * @param : ptr, object of BaseLegacyInterface * @return : Returns void */ Void setIntfcPtr(BaseLegacyInterface *ptr); Void resetFlag(); private: Long m_maxMsgs; DfListener *m_ptrListener = NULL; EThreadEventTimer m_dfRetryTimer; std::list<TCPDataProcessor *> m_ptrDataProcessor; BaseLegacyInterface *m_legacyIntfc = NULL; ESemaphorePrivate msg_cnt; std::ofstream fileWrite; /* file handler to write into file */ std::ifstream fileRead; /* file handler to read from file */ uint8_t writeBuf[SEND_BUF_SIZE]; /* buffer to write in file */ uint8_t readBuf[SEND_BUF_SIZE]; /* buffer to read from file */ uint8_t payloadBuf[SEND_BUF_SIZE]; /* buffer to read payload */ std::vector<std::string> fileVect; /* Vector to store file names */ std::vector<std::string>::iterator vecIter; /* Iterator for vector */ int16_t read_count = 0; /* Numb of packets read from file */ int16_t entry_cnt = 0; /* Numb of packets write into the file */ int16_t pkt_cnt = 0; /* Actual number of packets sent vs written into the file */ std::atomic<bool> legacy_conn; /* flag to indicate connection status with legacy Df */ bool serveNextFile = 0; bool timer_flag = 0; /* flag to use same timer for re-connecting as \ well as to re-sending failed packets*/ bool pending_data_flag = 0; /* Flag to indicate there is backlog to be send to legacy DF */ int32_t send_bytes_track = 0; /* variable to track numb of bytes read from backlog to be sent to legacy DF*/ int32_t read_bytes_track = 0; /* varible to track number of bytes read from the file */ std::string file_name; /* Name of the current file in which packets ar being written/read from */ std::string msgCntr_file_name; /* Name of fle which msg counter is reffering */ }; #endif /* __TCPListener_H_ */
nikhilc149/e-utran-features-bug-fixes
cp_dp_api/ngic_timer.c
<reponame>nikhilc149/e-utran-features-bug-fixes /* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <memory.h> #include <semaphore.h> #include <unistd.h> #include <signal.h> #include <pthread.h> #include <sys/time.h> #include <sys/types.h> #include <sys/syscall.h> #include <arpa/inet.h> #include "pfcp_util.h" #include "ngic_timer.h" #ifdef CP_BUILD #include "main.h" #include "cp_stats.h" #else #include "up_main.h" #endif #include "gw_adapter.h" #include "pfcp_set_ie.h" char hbt_filename[256] = "../config/hrtbeat_recov_time.txt"; static pthread_t _gstimer_thread; static pid_t _gstimer_tid; extern int clSystemLog; extern struct rte_hash *conn_hash_handle; const char *getPrintableTime(void) { static char buf[128]; struct timeval tv; struct timezone tz; struct tm *ptm; gettimeofday(&tv, &tz); ptm = localtime( &tv.tv_sec ); snprintf( buf, MAX_LEN, "%04d-%02d-%02d %02d:%02d:%02d.%03ld", ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, tv.tv_usec / 1000 ); return buf; } /** * @brief : Start timer thread * @param : arg, used to control access to thread * @return : Returns nothing */ static void *_gstimer_thread_func(void *arg) { int keepgoing = 1; sem_t *psem = (sem_t*)arg; sigset_t set; siginfo_t si; _gstimer_tid = syscall(SYS_gettid); sem_post( psem ); sigemptyset( &set ); sigaddset( &set, SIGRTMIN + 1 ); sigaddset( &set, SIGUSR1 ); while (keepgoing) { int sig = sigwaitinfo( &set, &si ); if ( sig == SIGRTMIN + 1) { gstimerinfo_t *ti = (gstimerinfo_t*)si.si_value.sival_ptr; if ( ti->ti_cb ) (*ti->ti_cb)( ti, ti->ti_data ); } else if ( sig == SIGUSR1 ) { keepgoing = 0; } } return NULL; } /** * @brief : Initialize timer * @param : timer_id, timer if * @param : data, holds timer related information * @return : Returns true in case of success , false otherwise */ static bool _create_timer(timer_t *timer_id, const void *data) { int status; struct sigevent se; /* * Set the sigevent structure to cause the signal to be * delivered by creating a new thread. */ memset(&se, 0, sizeof(se)); se.sigev_notify = SIGEV_THREAD_ID; se._sigev_un._tid = _gstimer_tid; se.sigev_signo = SIGRTMIN + 1; #pragma GCC diagnostic push /* require GCC 4.6 */ #pragma GCC diagnostic ignored "-Wcast-qual" se.sigev_value.sival_ptr = (void*)data; #pragma GCC diagnostic pop /* require GCC 4.6 */ /* * create the timer */ status = timer_create(CLOCK_REALTIME, &se, timer_id); return status == 0 ? true : false; } bool gst_init(void) { int status; sem_t sem; /* * start the timer thread and wait for _timer_tid to be populated */ sem_init( &sem, 0, 0 ); status = pthread_create( &_gstimer_thread, NULL, &_gstimer_thread_func, &sem ); if (status != 0) return False; sem_wait( &sem ); sem_destroy( &sem ); return true; } void gst_deinit(void) { /* * stop the timer handler thread */ pthread_kill( _gstimer_thread, SIGUSR1 ); pthread_join( _gstimer_thread, NULL ); } bool gst_timer_init( gstimerinfo_t *ti, gstimertype_t tt, gstimercallback cb, int milliseconds, const void *data ) { ti->ti_type = tt; ti->ti_cb = cb; ti->ti_ms = milliseconds; ti->ti_data = data; return _create_timer( &ti->ti_id, ti ); } void gst_timer_deinit(gstimerinfo_t *ti) { timer_delete( ti->ti_id ); } bool gst_timer_setduration(gstimerinfo_t *ti, int milliseconds) { ti->ti_ms = milliseconds; return gst_timer_start( ti ); } bool gst_timer_start(gstimerinfo_t *ti) { int status; struct itimerspec ts; /* * set the timer expiration */ ts.it_value.tv_sec = ti->ti_ms / 1000; ts.it_value.tv_nsec = (ti->ti_ms % 1000) * 1000000; if ( ti->ti_type == ttInterval ) { ts.it_interval.tv_sec = ts.it_value.tv_sec; ts.it_interval.tv_nsec = ts.it_value.tv_nsec; } else { ts.it_interval.tv_sec = 0; ts.it_interval.tv_nsec = 0; } status = timer_settime( ti->ti_id, 0, &ts, NULL ); return status == -1 ? false : true; } void gst_timer_stop(gstimerinfo_t *ti) { struct itimerspec ts; /* * set the timer expiration, setting it_value and it_interval to 0 disables the timer */ ts.it_value.tv_sec = 0; ts.it_value.tv_nsec = 0; ts.it_interval.tv_sec = 0; ts.it_interval.tv_nsec = 0; timer_settime( ti->ti_id, 0, &ts, NULL ); } bool initpeerData( peerData *md, const char *name, int ptms, int ttms ) { md->name = name; if ( !gst_timer_init( &md->pt, ttInterval, timerCallback, ptms, md ) ) return False; return gst_timer_init( &md->tt, ttInterval, timerCallback, ttms, md ); } bool startTimer( gstimerinfo_t *ti ) { return gst_timer_start( ti ); } void stopTimer( gstimerinfo_t *ti ) { gst_timer_stop( ti ); } void deinitTimer( gstimerinfo_t *ti ) { gst_timer_deinit( ti ); } bool init_timer(peerData *md, int ptms, gstimercallback cb) { return gst_timer_init(&md->pt, ttInterval, cb, ptms, md); } bool starttimer(gstimerinfo_t *ti) { return gst_timer_start( ti ); } void stoptimer(timer_t *tid) { struct itimerspec ts; /* * set the timer expiration, setting it_value and it_interval to 0 disables the timer */ ts.it_value.tv_sec = 0; ts.it_value.tv_nsec = 0; ts.it_interval.tv_sec = 0; ts.it_interval.tv_nsec = 0; timer_settime(*tid, 0, &ts, NULL); } void deinittimer(timer_t *tid) { timer_delete(*tid); } void _sleep( int seconds ) { sleep( seconds ); } void del_entry_from_hash(node_address_t *ipAddr) { int ret = 0; (ipAddr->ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Delete entry from connection table of ipv6:"IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(*(struct in6_addr *)ipAddr->ipv6_addr)): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Delete entry from connection table of ipv4:%s\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&ipAddr->ipv4_addr)); /* Delete entry from connection hash table */ ret = rte_hash_del_key(conn_hash_handle, ipAddr); if (ret == -ENOENT) clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"key is not found\n", LOG_VALUE); if (ret == -EINVAL) clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Invalid Params: Failed to del from hash table\n", LOG_VALUE); if (ret < 0) clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT"Failed to del entry from hash table\n", LOG_VALUE); conn_cnt--; } uint8_t process_response(node_address_t *dstIp) { int ret = 0; peerData *conn_data = NULL; ret = rte_hash_lookup_data(conn_hash_handle, dstIp, (void **)&conn_data); if ( ret < 0) { (dstIp->ip_type == IPV6_TYPE) ? clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Entry not found for NODE IPv6: "IPv6_FMT"\n", LOG_VALUE, IPv6_PRINT(IPv6_CAST(dstIp->ipv6_addr))): clLog(clSystemLog, eCLSeverityDebug, LOG_FORMAT" Entry not found for NODE IPv4: %s\n", LOG_VALUE, inet_ntoa(*(struct in_addr *)&dstIp->ipv4_addr)); } else { conn_data->itr_cnt = 0; peer_address_t address; address.ipv4.sin_addr.s_addr = conn_data->dstIP.ipv4_addr; address.type = IPV4_TYPE; update_peer_timeouts((peer_address_t *) &address, 0); /* Stop transmit timer for specific peer node */ stopTimer( &conn_data->tt ); /* Stop periodic timer for specific peer node */ stopTimer( &conn_data->pt ); /* Reset Periodic Timer */ if ( startTimer( &conn_data->pt ) < 0) clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Periodic Timer failed to start...\n", LOG_VALUE); } return 0; } void recovery_time_into_file(uint32_t recov_time) { FILE *fp = NULL; if ((fp = fopen(hbt_filename, "w+")) == NULL) { clLog(clSystemLog, eCLSeverityCritical, LOG_FORMAT"Unable to open " "heartbeat recovery file..\n", LOG_VALUE); } else { fseek(fp, 0, SEEK_SET); fprintf(fp, "%u\n", recov_time); fclose(fp); } }
nikhilc149/e-utran-features-bug-fixes
cp/gx_app/src/gx_parsers.c
/* * Copyright (c) 2019 Sprint * Copyright (c) 2020 T-Mobile * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdint.h> #include <stdlib.h> #include "gx.h" #define IS_AVP(a) (gxDict.a.avp_code == hdr->avp_code) /*******************************************************************************/ /* private grouped avp parser function declarations */ /*******************************************************************************/ static int parseGxExperimentalResult(struct avp *avp, GxExperimentalResult *data); static int parseGxPraRemove(struct avp *avp, GxPraRemove *data); static int parseGxQosInformation(struct avp *avp, GxQosInformation *data); static int parseGxConditionalPolicyInformation(struct avp *avp, GxConditionalPolicyInformation *data); static int parseGxPraInstall(struct avp *avp, GxPraInstall *data); static int parseGxAreaScope(struct avp *avp, GxAreaScope *data); static int parseGxFlowInformation(struct avp *avp, GxFlowInformation *data); static int parseGxTunnelInformation(struct avp *avp, GxTunnelInformation *data); static int parseGxTftPacketFilterInformation(struct avp *avp, GxTftPacketFilterInformation *data); static int parseGxMbsfnArea(struct avp *avp, GxMbsfnArea *data); static int parseGxEventReportIndication(struct avp *avp, GxEventReportIndication *data); static int parseGxTdfInformation(struct avp *avp, GxTdfInformation *data); static int parseGxProxyInfo(struct avp *avp, GxProxyInfo *data); static int parseGxUsedServiceUnit(struct avp *avp, GxUsedServiceUnit *data); static int parseGxChargingRuleInstall(struct avp *avp, GxChargingRuleInstall *data); static int parseGxChargingRuleDefinition(struct avp *avp, GxChargingRuleDefinition *data); static int parseGxFinalUnitIndication(struct avp *avp, GxFinalUnitIndication *data); static int parseGxUnitValue(struct avp *avp, GxUnitValue *data); static int parseGxPresenceReportingAreaInformation(struct avp *avp, GxPresenceReportingAreaInformation *data); static int parseGxConditionalApnAggregateMaxBitrate(struct avp *avp, GxConditionalApnAggregateMaxBitrate *data); static int parseGxAccessNetworkChargingIdentifierGx(struct avp *avp, GxAccessNetworkChargingIdentifierGx *data); static int parseGxOcOlr(struct avp *avp, GxOcOlr *data); static int parseGxRoutingRuleInstall(struct avp *avp, GxRoutingRuleInstall *data); static int parseGxTraceData(struct avp *avp, GxTraceData *data); static int parseGxRoutingRuleDefinition(struct avp *avp, GxRoutingRuleDefinition *data); static int parseGxMdtConfiguration(struct avp *avp, GxMdtConfiguration *data); static int parseGxChargingRuleRemove(struct avp *avp, GxChargingRuleRemove *data); static int parseGxAllocationRetentionPriority(struct avp *avp, GxAllocationRetentionPriority *data); static int parseGxDefaultEpsBearerQos(struct avp *avp, GxDefaultEpsBearerQos *data); static int parseGxRoutingRuleReport(struct avp *avp, GxRoutingRuleReport *data); static int parseGxUserEquipmentInfo(struct avp *avp, GxUserEquipmentInfo *data); static int parseGxSupportedFeatures(struct avp *avp, GxSupportedFeatures *data); static int parseGxFixedUserLocationInfo(struct avp *avp, GxFixedUserLocationInfo *data); static int parseGxDefaultQosInformation(struct avp *avp, GxDefaultQosInformation *data); static int parseGxLoad(struct avp *avp, GxLoad *data); static int parseGxRedirectServer(struct avp *avp, GxRedirectServer *data); static int parseGxOcSupportedFeatures(struct avp *avp, GxOcSupportedFeatures *data); static int parseGxPacketFilterInformation(struct avp *avp, GxPacketFilterInformation *data); static int parseGxSubscriptionId(struct avp *avp, GxSubscriptionId *data); static int parseGxChargingInformation(struct avp *avp, GxChargingInformation *data); static int parseGxUsageMonitoringInformation(struct avp *avp, GxUsageMonitoringInformation *data); static int parseGxChargingRuleReport(struct avp *avp, GxChargingRuleReport *data); static int parseGxRedirectInformation(struct avp *avp, GxRedirectInformation *data); static int parseGxFailedAvp(struct avp *avp, GxFailedAvp *data); static int parseGxRoutingRuleRemove(struct avp *avp, GxRoutingRuleRemove *data); static int parseGxRoutingFilter(struct avp *avp, GxRoutingFilter *data); static int parseGxCoaInformation(struct avp *avp, GxCoaInformation *data); static int parseGxGrantedServiceUnit(struct avp *avp, GxGrantedServiceUnit *data); static int parseGxCcMoney(struct avp *avp, GxCcMoney *data); static int parseGxApplicationDetectionInformation(struct avp *avp, GxApplicationDetectionInformation *data); static int parseGxFlows(struct avp *avp, GxFlows *data); static int parseGxUserCsgInformation(struct avp *avp, GxUserCsgInformation *data); static int freeGxPraRemove(GxPraRemove *data); static int freeGxQosInformation(GxQosInformation *data); static int freeGxConditionalPolicyInformation(GxConditionalPolicyInformation *data); static int freeGxPraInstall(GxPraInstall *data); static int freeGxAreaScope(GxAreaScope *data); static int freeGxTunnelInformation(GxTunnelInformation *data); static int freeGxEventReportIndication(GxEventReportIndication *data); static int freeGxUsedServiceUnit(GxUsedServiceUnit *data); static int freeGxChargingRuleInstall(GxChargingRuleInstall *data); static int freeGxChargingRuleDefinition(GxChargingRuleDefinition *data); static int freeGxFinalUnitIndication(GxFinalUnitIndication *data); static int freeGxConditionalApnAggregateMaxBitrate(GxConditionalApnAggregateMaxBitrate *data); static int freeGxAccessNetworkChargingIdentifierGx(GxAccessNetworkChargingIdentifierGx *data); static int freeGxRoutingRuleInstall(GxRoutingRuleInstall *data); static int freeGxTraceData(GxTraceData *data); static int freeGxRoutingRuleDefinition(GxRoutingRuleDefinition *data); static int freeGxMdtConfiguration(GxMdtConfiguration *data); static int freeGxChargingRuleRemove(GxChargingRuleRemove *data); static int freeGxRoutingRuleReport(GxRoutingRuleReport *data); static int freeGxUsageMonitoringInformation(GxUsageMonitoringInformation *data); static int freeGxChargingRuleReport(GxChargingRuleReport *data); static int freeGxRoutingRuleRemove(GxRoutingRuleRemove *data); static int freeGxCoaInformation(GxCoaInformation *data); static int freeGxApplicationDetectionInformation(GxApplicationDetectionInformation *data); static int freeGxFlows(GxFlows *data); /*******************************************************************************/ /* message parsing functions */ /*******************************************************************************/ /* * * Fun: gx_rar_parse * * Desc: Parse Re-Auth-Request Message * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Re-Auth-Request ::= <Diameter Header: 258, REQ, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * { Destination-Realm } * { Destination-Host } * { Re-Auth-Request-Type } * [ Session-Release-Cause ] * [ Origin-State-Id ] * [ OC-Supported-Features ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * * [ Charging-Rule-Remove ] * * [ Charging-Rule-Install ] * [ Default-EPS-Bearer-QoS ] * * [ QoS-Information ] * [ Default-QoS-Information ] * [ Revalidation-Time ] * * [ Usage-Monitoring-Information ] * [ PCSCF-Restoration-Indication ] * * 4 [ Conditional-Policy-Information ] * [ Removal-Of-Access ] * [ IP-CAN-Type ] * [ PRA-Install ] * [ PRA-Remove ] * * [ CSG-Information-Reporting ] * * [ Proxy-Info ] * * [ Route-Record ] * * [ AVP ] */ int gx_rar_parse ( struct msg *msg, GxRAR *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* clear the data buffer */ memset((void*)data, 0, sizeof(*data)); /* iterate through the AVPNAME child AVP's */ FDCHECK_FCT(fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_session_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->session_id, GX_SESSION_ID_LEN); data->presence.session_id=1; } else if (IS_AVP(davp_drmp)) { data->drmp = hdr->avp_value->i32; data->presence.drmp=1; } else if (IS_AVP(davp_auth_application_id)) { data->auth_application_id = hdr->avp_value->u32; data->presence.auth_application_id=1; } else if (IS_AVP(davp_origin_host)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->origin_host, GX_ORIGIN_HOST_LEN); data->presence.origin_host=1; } else if (IS_AVP(davp_origin_realm)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->origin_realm, GX_ORIGIN_REALM_LEN); data->presence.origin_realm=1; } else if (IS_AVP(davp_destination_realm)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->destination_realm, GX_DESTINATION_REALM_LEN); data->presence.destination_realm=1; } else if (IS_AVP(davp_destination_host)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->destination_host, GX_DESTINATION_HOST_LEN); data->presence.destination_host=1; } else if (IS_AVP(davp_re_auth_request_type)) { data->re_auth_request_type = hdr->avp_value->i32; data->presence.re_auth_request_type=1; } else if (IS_AVP(davp_session_release_cause)) { data->session_release_cause = hdr->avp_value->i32; data->presence.session_release_cause=1; } else if (IS_AVP(davp_origin_state_id)) { data->origin_state_id = hdr->avp_value->u32; data->presence.origin_state_id=1; } else if (IS_AVP(davp_oc_supported_features)) { FDCHECK_PARSE_DIRECT(parseGxOcSupportedFeatures, child_avp, &data->oc_supported_features); data->presence.oc_supported_features=1; } else if (IS_AVP(davp_event_trigger)) { data->event_trigger.count++; cnt++; data->presence.event_trigger=1; } else if (IS_AVP(davp_event_report_indication)) { FDCHECK_PARSE_DIRECT(parseGxEventReportIndication, child_avp, &data->event_report_indication); data->presence.event_report_indication=1; } else if (IS_AVP(davp_charging_rule_remove)) { data->charging_rule_remove.count++; cnt++; data->presence.charging_rule_remove=1; } else if (IS_AVP(davp_charging_rule_install)) { data->charging_rule_install.count++; cnt++; data->presence.charging_rule_install=1; } else if (IS_AVP(davp_default_eps_bearer_qos)) { FDCHECK_PARSE_DIRECT(parseGxDefaultEpsBearerQos, child_avp, &data->default_eps_bearer_qos); data->presence.default_eps_bearer_qos=1; } else if (IS_AVP(davp_qos_information)) { data->qos_information.count++; cnt++; data->presence.qos_information=1; } else if (IS_AVP(davp_default_qos_information)) { FDCHECK_PARSE_DIRECT(parseGxDefaultQosInformation, child_avp, &data->default_qos_information); data->presence.default_qos_information=1; } else if (IS_AVP(davp_revalidation_time)) { FD_PARSE_TIME(hdr->avp_value, data->revalidation_time); data->presence.revalidation_time=1; } else if (IS_AVP(davp_usage_monitoring_information)) { data->usage_monitoring_information.count++; cnt++; data->presence.usage_monitoring_information=1; } else if (IS_AVP(davp_pcscf_restoration_indication)) { data->pcscf_restoration_indication = hdr->avp_value->u32; data->presence.pcscf_restoration_indication=1; } else if (IS_AVP(davp_conditional_policy_information)) { data->conditional_policy_information.count++; cnt++; data->presence.conditional_policy_information=1; } else if (IS_AVP(davp_removal_of_access)) { data->removal_of_access = hdr->avp_value->i32; data->presence.removal_of_access=1; } else if (IS_AVP(davp_ip_can_type)) { data->ip_can_type = hdr->avp_value->i32; data->presence.ip_can_type=1; } else if (IS_AVP(davp_pra_install)) { FDCHECK_PARSE_DIRECT(parseGxPraInstall, child_avp, &data->pra_install); data->presence.pra_install=1; } else if (IS_AVP(davp_pra_remove)) { FDCHECK_PARSE_DIRECT(parseGxPraRemove, child_avp, &data->pra_remove); data->presence.pra_remove=1; } else if (IS_AVP(davp_csg_information_reporting)) { data->csg_information_reporting.count++; cnt++; data->presence.csg_information_reporting=1; } else if (IS_AVP(davp_proxy_info)) { data->proxy_info.count++; cnt++; data->presence.proxy_info=1; } else if (IS_AVP(davp_route_record)) { data->route_record.count++; cnt++; data->presence.route_record=1; } /* get the next child AVP */ FDCHECK_FCT( fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->event_trigger, int32_t); FD_ALLOC_LIST(data->charging_rule_remove, GxChargingRuleRemove); FD_ALLOC_LIST(data->charging_rule_install, GxChargingRuleInstall); FD_ALLOC_LIST(data->qos_information, GxQosInformation); FD_ALLOC_LIST(data->usage_monitoring_information, GxUsageMonitoringInformation); FD_ALLOC_LIST(data->conditional_policy_information, GxConditionalPolicyInformation); FD_ALLOC_LIST(data->csg_information_reporting, int32_t); FD_ALLOC_LIST(data->proxy_info, GxProxyInfo); FD_ALLOC_LIST(data->route_record, GxRouteRecordOctetString); /* iterate through the AVPNAME child AVP's */ FDCHECK_FCT(fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_event_trigger)) { data->event_trigger.list[data->event_trigger.count] = hdr->avp_value->i32; data->event_trigger.count++; } else if (IS_AVP(davp_charging_rule_remove)) { FDCHECK_PARSE_DIRECT(parseGxChargingRuleRemove, child_avp, &data->charging_rule_remove.list[data->charging_rule_remove.count]); data->charging_rule_remove.count++; } else if (IS_AVP(davp_charging_rule_install)) { FDCHECK_PARSE_DIRECT(parseGxChargingRuleInstall, child_avp, &data->charging_rule_install.list[data->charging_rule_install.count]); data->charging_rule_install.count++; } else if (IS_AVP(davp_qos_information)) { FDCHECK_PARSE_DIRECT(parseGxQosInformation, child_avp, &data->qos_information.list[data->qos_information.count]); data->qos_information.count++; } else if (IS_AVP(davp_usage_monitoring_information)) { FDCHECK_PARSE_DIRECT(parseGxUsageMonitoringInformation, child_avp, &data->usage_monitoring_information.list[data->usage_monitoring_information.count]); data->usage_monitoring_information.count++; } else if (IS_AVP(davp_conditional_policy_information)) { FDCHECK_PARSE_DIRECT(parseGxConditionalPolicyInformation, child_avp, &data->conditional_policy_information.list[data->conditional_policy_information.count]); data->conditional_policy_information.count++; } else if (IS_AVP(davp_csg_information_reporting)) { data->csg_information_reporting.list[data->csg_information_reporting.count] = hdr->avp_value->i32; data->csg_information_reporting.count++; } else if (IS_AVP(davp_proxy_info)) { FDCHECK_PARSE_DIRECT(parseGxProxyInfo, child_avp, &data->proxy_info.list[data->proxy_info.count]); data->proxy_info.count++; } else if (IS_AVP(davp_route_record)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->route_record.list[data->route_record.count], GX_ROUTE_RECORD_LEN); data->route_record.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: gx_raa_parse * * Desc: Parse Re-Auth-Answer Message * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Re-Auth-Answer ::= <Diameter Header: 258, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Origin-Host } * { Origin-Realm } * [ Result-Code ] * [ Experimental-Result ] * [ Origin-State-Id ] * [ OC-Supported-Features ] * [ OC-OLR ] * [ IP-CAN-Type ] * [ RAT-Type ] * [ AN-Trusted ] * * 2 [ AN-GW-Address ] * [ 3GPP-SGSN-MCC-MNC ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ User-Location-Info-Time ] * [ NetLoc-Access-Support ] * [ User-CSG-Information ] * [ 3GPP-MS-TimeZone ] * [ Default-QoS-Information ] * * [ Charging-Rule-Report ] * [ Error-Message ] * [ Error-Reporting-Host ] * [ Failed-AVP ] * * [ Proxy-Info ] * * [ AVP ] */ int gx_raa_parse ( struct msg *msg, GxRAA *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* clear the data buffer */ memset((void*)data, 0, sizeof(*data)); /* iterate through the AVPNAME child AVP's */ FDCHECK_FCT(fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_session_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->session_id, GX_SESSION_ID_LEN); data->presence.session_id=1; } else if (IS_AVP(davp_drmp)) { data->drmp = hdr->avp_value->i32; data->presence.drmp=1; } else if (IS_AVP(davp_origin_host)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->origin_host, GX_ORIGIN_HOST_LEN); data->presence.origin_host=1; } else if (IS_AVP(davp_origin_realm)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->origin_realm, GX_ORIGIN_REALM_LEN); data->presence.origin_realm=1; } else if (IS_AVP(davp_result_code)) { data->result_code = hdr->avp_value->u32; data->presence.result_code=1; } else if (IS_AVP(davp_experimental_result)) { FDCHECK_PARSE_DIRECT(parseGxExperimentalResult, child_avp, &data->experimental_result); data->presence.experimental_result=1; } else if (IS_AVP(davp_origin_state_id)) { data->origin_state_id = hdr->avp_value->u32; data->presence.origin_state_id=1; } else if (IS_AVP(davp_oc_supported_features)) { FDCHECK_PARSE_DIRECT(parseGxOcSupportedFeatures, child_avp, &data->oc_supported_features); data->presence.oc_supported_features=1; } else if (IS_AVP(davp_oc_olr)) { FDCHECK_PARSE_DIRECT(parseGxOcOlr, child_avp, &data->oc_olr); data->presence.oc_olr=1; } else if (IS_AVP(davp_ip_can_type)) { data->ip_can_type = hdr->avp_value->i32; data->presence.ip_can_type=1; } else if (IS_AVP(davp_rat_type)) { data->rat_type = hdr->avp_value->i32; data->presence.rat_type=1; } else if (IS_AVP(davp_an_trusted)) { data->an_trusted = hdr->avp_value->i32; data->presence.an_trusted=1; } else if (IS_AVP(davp_an_gw_address)) { data->an_gw_address.count++; cnt++; data->presence.an_gw_address=1; } else if (IS_AVP(davp_3gpp_sgsn_mcc_mnc)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_sgsn_mcc_mnc, GX_3GPP_SGSN_MCC_MNC_LEN); data->presence.tgpp_sgsn_mcc_mnc=1; } else if (IS_AVP(davp_3gpp_sgsn_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_sgsn_address, GX_3GPP_SGSN_ADDRESS_LEN); data->presence.tgpp_sgsn_address=1; } else if (IS_AVP(davp_3gpp_sgsn_ipv6_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_sgsn_ipv6_address, GX_3GPP_SGSN_IPV6_ADDRESS_LEN); data->presence.tgpp_sgsn_ipv6_address=1; } else if (IS_AVP(davp_rai)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->rai, GX_RAI_LEN); data->presence.rai=1; } else if (IS_AVP(davp_3gpp_user_location_info)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_user_location_info, GX_3GPP_USER_LOCATION_INFO_LEN); data->presence.tgpp_user_location_info=1; } else if (IS_AVP(davp_user_location_info_time)) { FD_PARSE_TIME(hdr->avp_value, data->user_location_info_time); data->presence.user_location_info_time=1; } else if (IS_AVP(davp_netloc_access_support)) { data->netloc_access_support = hdr->avp_value->u32; data->presence.netloc_access_support=1; } else if (IS_AVP(davp_user_csg_information)) { FDCHECK_PARSE_DIRECT(parseGxUserCsgInformation, child_avp, &data->user_csg_information); data->presence.user_csg_information=1; } else if (IS_AVP(davp_3gpp_ms_timezone)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_ms_timezone, GX_3GPP_MS_TIMEZONE_LEN); data->presence.tgpp_ms_timezone=1; } else if (IS_AVP(davp_default_qos_information)) { FDCHECK_PARSE_DIRECT(parseGxDefaultQosInformation, child_avp, &data->default_qos_information); data->presence.default_qos_information=1; } else if (IS_AVP(davp_charging_rule_report)) { data->charging_rule_report.count++; cnt++; data->presence.charging_rule_report=1; } else if (IS_AVP(davp_error_message)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->error_message, GX_ERROR_MESSAGE_LEN); data->presence.error_message=1; } else if (IS_AVP(davp_error_reporting_host)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->error_reporting_host, GX_ERROR_REPORTING_HOST_LEN); data->presence.error_reporting_host=1; } else if (IS_AVP(davp_failed_avp)) { FDCHECK_PARSE_DIRECT(parseGxFailedAvp, child_avp, &data->failed_avp); data->presence.failed_avp=1; } else if (IS_AVP(davp_proxy_info)) { data->proxy_info.count++; cnt++; data->presence.proxy_info=1; } /* get the next child AVP */ FDCHECK_FCT( fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->an_gw_address, FdAddress); FD_ALLOC_LIST(data->charging_rule_report, GxChargingRuleReport); FD_ALLOC_LIST(data->proxy_info, GxProxyInfo); /* iterate through the AVPNAME child AVP's */ FDCHECK_FCT(fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_an_gw_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->an_gw_address.list[data->an_gw_address.count]); data->an_gw_address.count++; } else if (IS_AVP(davp_charging_rule_report)) { FDCHECK_PARSE_DIRECT(parseGxChargingRuleReport, child_avp, &data->charging_rule_report.list[data->charging_rule_report.count]); data->charging_rule_report.count++; } else if (IS_AVP(davp_proxy_info)) { FDCHECK_PARSE_DIRECT(parseGxProxyInfo, child_avp, &data->proxy_info.list[data->proxy_info.count]); data->proxy_info.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: gx_cca_parse * * Desc: Parse Credit-Control-Answer Message * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Credit-Control-Answer ::= <Diameter Header: 272, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * [ Result-Code ] * [ Experimental-Result ] * { CC-Request-Type } * { CC-Request-Number } * [ OC-Supported-Features ] * [ OC-OLR ] * * [ Supported-Features ] * [ Bearer-Control-Mode ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * [ Origin-State-Id ] * * [ Redirect-Host ] * [ Redirect-Host-Usage ] * [ Redirect-Max-Cache-Time ] * * [ Charging-Rule-Remove ] * * [ Charging-Rule-Install ] * [ Charging-Information ] * [ Online ] * [ Offline ] * * [ QoS-Information ] * [ Revalidation-Time ] * [ Default-EPS-Bearer-QoS ] * [ Default-QoS-Information ] * [ Bearer-Usage ] * * [ Usage-Monitoring-Information ] * * [ CSG-Information-Reporting ] * [ User-CSG-Information ] * [ PRA-Install ] * [ PRA-Remove ] * [ Presence-Reporting-Area-Information ] * [ Session-Release-Cause ] * [ NBIFOM-Support ] * [ NBIFOM-Mode ] * [ Default-Access ] * [ RAN-Rule-Support ] * * [ Routing-Rule-Report ] * * 4 [ Conditional-Policy-Information ] * [ Removal-Of-Access ] * [ IP-CAN-Type ] * [ Error-Message ] * [ Error-Reporting-Host ] * [ Failed-AVP ] * * [ Proxy-Info ] * * [ Route-Record ] * * [ Load ] * * [ AVP ] */ int gx_cca_parse ( struct msg *msg, GxCCA *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* clear the data buffer */ memset((void*)data, 0, sizeof(*data)); /* iterate through the AVPNAME child AVP's */ FDCHECK_FCT(fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_session_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->session_id, GX_SESSION_ID_LEN); data->presence.session_id=1; } else if (IS_AVP(davp_drmp)) { data->drmp = hdr->avp_value->i32; data->presence.drmp=1; } else if (IS_AVP(davp_auth_application_id)) { data->auth_application_id = hdr->avp_value->u32; data->presence.auth_application_id=1; } else if (IS_AVP(davp_origin_host)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->origin_host, GX_ORIGIN_HOST_LEN); data->presence.origin_host=1; } else if (IS_AVP(davp_origin_realm)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->origin_realm, GX_ORIGIN_REALM_LEN); data->presence.origin_realm=1; } else if (IS_AVP(davp_result_code)) { data->result_code = hdr->avp_value->u32; data->presence.result_code=1; } else if (IS_AVP(davp_experimental_result)) { FDCHECK_PARSE_DIRECT(parseGxExperimentalResult, child_avp, &data->experimental_result); data->presence.experimental_result=1; } else if (IS_AVP(davp_cc_request_type)) { data->cc_request_type = hdr->avp_value->i32; data->presence.cc_request_type=1; } else if (IS_AVP(davp_cc_request_number)) { data->cc_request_number = hdr->avp_value->u32; data->presence.cc_request_number=1; } else if (IS_AVP(davp_oc_supported_features)) { FDCHECK_PARSE_DIRECT(parseGxOcSupportedFeatures, child_avp, &data->oc_supported_features); data->presence.oc_supported_features=1; } else if (IS_AVP(davp_oc_olr)) { FDCHECK_PARSE_DIRECT(parseGxOcOlr, child_avp, &data->oc_olr); data->presence.oc_olr=1; } else if (IS_AVP(davp_supported_features)) { data->supported_features.count++; cnt++; data->presence.supported_features=1; } else if (IS_AVP(davp_bearer_control_mode)) { data->bearer_control_mode = hdr->avp_value->i32; data->presence.bearer_control_mode=1; } else if (IS_AVP(davp_event_trigger)) { data->event_trigger.count++; cnt++; data->presence.event_trigger=1; } else if (IS_AVP(davp_event_report_indication)) { FDCHECK_PARSE_DIRECT(parseGxEventReportIndication, child_avp, &data->event_report_indication); data->presence.event_report_indication=1; } else if (IS_AVP(davp_origin_state_id)) { data->origin_state_id = hdr->avp_value->u32; data->presence.origin_state_id=1; } else if (IS_AVP(davp_redirect_host)) { data->redirect_host.count++; cnt++; data->presence.redirect_host=1; } else if (IS_AVP(davp_redirect_host_usage)) { data->redirect_host_usage = hdr->avp_value->i32; data->presence.redirect_host_usage=1; } else if (IS_AVP(davp_redirect_max_cache_time)) { data->redirect_max_cache_time = hdr->avp_value->u32; data->presence.redirect_max_cache_time=1; } else if (IS_AVP(davp_charging_rule_remove)) { data->charging_rule_remove.count++; cnt++; data->presence.charging_rule_remove=1; } else if (IS_AVP(davp_charging_rule_install)) { data->charging_rule_install.count++; cnt++; data->presence.charging_rule_install=1; } else if (IS_AVP(davp_charging_information)) { FDCHECK_PARSE_DIRECT(parseGxChargingInformation, child_avp, &data->charging_information); data->presence.charging_information=1; } else if (IS_AVP(davp_online)) { data->online = hdr->avp_value->i32; data->presence.online=1; } else if (IS_AVP(davp_offline)) { data->offline = hdr->avp_value->i32; data->presence.offline=1; } else if (IS_AVP(davp_qos_information)) { data->qos_information.count++; cnt++; data->presence.qos_information=1; } else if (IS_AVP(davp_revalidation_time)) { FD_PARSE_TIME(hdr->avp_value, data->revalidation_time); data->presence.revalidation_time=1; } else if (IS_AVP(davp_default_eps_bearer_qos)) { FDCHECK_PARSE_DIRECT(parseGxDefaultEpsBearerQos, child_avp, &data->default_eps_bearer_qos); data->presence.default_eps_bearer_qos=1; } else if (IS_AVP(davp_default_qos_information)) { FDCHECK_PARSE_DIRECT(parseGxDefaultQosInformation, child_avp, &data->default_qos_information); data->presence.default_qos_information=1; } else if (IS_AVP(davp_bearer_usage)) { data->bearer_usage = hdr->avp_value->i32; data->presence.bearer_usage=1; } else if (IS_AVP(davp_usage_monitoring_information)) { data->usage_monitoring_information.count++; cnt++; data->presence.usage_monitoring_information=1; } else if (IS_AVP(davp_csg_information_reporting)) { data->csg_information_reporting.count++; cnt++; data->presence.csg_information_reporting=1; } else if (IS_AVP(davp_user_csg_information)) { FDCHECK_PARSE_DIRECT(parseGxUserCsgInformation, child_avp, &data->user_csg_information); data->presence.user_csg_information=1; } else if (IS_AVP(davp_pra_install)) { FDCHECK_PARSE_DIRECT(parseGxPraInstall, child_avp, &data->pra_install); data->presence.pra_install=1; } else if (IS_AVP(davp_pra_remove)) { FDCHECK_PARSE_DIRECT(parseGxPraRemove, child_avp, &data->pra_remove); data->presence.pra_remove=1; } else if (IS_AVP(davp_presence_reporting_area_information)) { FDCHECK_PARSE_DIRECT(parseGxPresenceReportingAreaInformation, child_avp, &data->presence_reporting_area_information); data->presence.presence_reporting_area_information=1; } else if (IS_AVP(davp_session_release_cause)) { data->session_release_cause = hdr->avp_value->i32; data->presence.session_release_cause=1; } else if (IS_AVP(davp_nbifom_support)) { data->nbifom_support = hdr->avp_value->i32; data->presence.nbifom_support=1; } else if (IS_AVP(davp_nbifom_mode)) { data->nbifom_mode = hdr->avp_value->i32; data->presence.nbifom_mode=1; } else if (IS_AVP(davp_default_access)) { data->default_access = hdr->avp_value->i32; data->presence.default_access=1; } else if (IS_AVP(davp_ran_rule_support)) { data->ran_rule_support = hdr->avp_value->u32; data->presence.ran_rule_support=1; } else if (IS_AVP(davp_routing_rule_report)) { data->routing_rule_report.count++; cnt++; data->presence.routing_rule_report=1; } else if (IS_AVP(davp_conditional_policy_information)) { data->conditional_policy_information.count++; cnt++; data->presence.conditional_policy_information=1; } else if (IS_AVP(davp_removal_of_access)) { data->removal_of_access = hdr->avp_value->i32; data->presence.removal_of_access=1; } else if (IS_AVP(davp_ip_can_type)) { data->ip_can_type = hdr->avp_value->i32; data->presence.ip_can_type=1; } else if (IS_AVP(davp_error_message)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->error_message, GX_ERROR_MESSAGE_LEN); data->presence.error_message=1; } else if (IS_AVP(davp_error_reporting_host)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->error_reporting_host, GX_ERROR_REPORTING_HOST_LEN); data->presence.error_reporting_host=1; } else if (IS_AVP(davp_failed_avp)) { FDCHECK_PARSE_DIRECT(parseGxFailedAvp, child_avp, &data->failed_avp); data->presence.failed_avp=1; } else if (IS_AVP(davp_proxy_info)) { data->proxy_info.count++; cnt++; data->presence.proxy_info=1; } else if (IS_AVP(davp_route_record)) { data->route_record.count++; cnt++; data->presence.route_record=1; } else if (IS_AVP(davp_load)) { data->load.count++; cnt++; data->presence.load=1; } /* get the next child AVP */ FDCHECK_FCT( fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->supported_features, GxSupportedFeatures); FD_ALLOC_LIST(data->event_trigger, int32_t); FD_ALLOC_LIST(data->redirect_host, GxRedirectHostOctetString); FD_ALLOC_LIST(data->charging_rule_remove, GxChargingRuleRemove); FD_ALLOC_LIST(data->charging_rule_install, GxChargingRuleInstall); FD_ALLOC_LIST(data->qos_information, GxQosInformation); FD_ALLOC_LIST(data->usage_monitoring_information, GxUsageMonitoringInformation); FD_ALLOC_LIST(data->csg_information_reporting, int32_t); FD_ALLOC_LIST(data->routing_rule_report, GxRoutingRuleReport); FD_ALLOC_LIST(data->conditional_policy_information, GxConditionalPolicyInformation); FD_ALLOC_LIST(data->proxy_info, GxProxyInfo); FD_ALLOC_LIST(data->route_record, GxRouteRecordOctetString); FD_ALLOC_LIST(data->load, GxLoad); /* iterate through the AVPNAME child AVP's */ FDCHECK_FCT(fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_supported_features)) { FDCHECK_PARSE_DIRECT(parseGxSupportedFeatures, child_avp, &data->supported_features.list[data->supported_features.count]); data->supported_features.count++; } else if (IS_AVP(davp_event_trigger)) { data->event_trigger.list[data->event_trigger.count] = hdr->avp_value->i32; data->event_trigger.count++; } else if (IS_AVP(davp_redirect_host)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->redirect_host.list[data->redirect_host.count], GX_REDIRECT_HOST_LEN); data->redirect_host.count++; } else if (IS_AVP(davp_charging_rule_remove)) { FDCHECK_PARSE_DIRECT(parseGxChargingRuleRemove, child_avp, &data->charging_rule_remove.list[data->charging_rule_remove.count]); data->charging_rule_remove.count++; } else if (IS_AVP(davp_charging_rule_install)) { FDCHECK_PARSE_DIRECT(parseGxChargingRuleInstall, child_avp, &data->charging_rule_install.list[data->charging_rule_install.count]); data->charging_rule_install.count++; } else if (IS_AVP(davp_qos_information)) { FDCHECK_PARSE_DIRECT(parseGxQosInformation, child_avp, &data->qos_information.list[data->qos_information.count]); data->qos_information.count++; } else if (IS_AVP(davp_usage_monitoring_information)) { FDCHECK_PARSE_DIRECT(parseGxUsageMonitoringInformation, child_avp, &data->usage_monitoring_information.list[data->usage_monitoring_information.count]); data->usage_monitoring_information.count++; } else if (IS_AVP(davp_csg_information_reporting)) { data->csg_information_reporting.list[data->csg_information_reporting.count] = hdr->avp_value->i32; data->csg_information_reporting.count++; } else if (IS_AVP(davp_routing_rule_report)) { FDCHECK_PARSE_DIRECT(parseGxRoutingRuleReport, child_avp, &data->routing_rule_report.list[data->routing_rule_report.count]); data->routing_rule_report.count++; } else if (IS_AVP(davp_conditional_policy_information)) { FDCHECK_PARSE_DIRECT(parseGxConditionalPolicyInformation, child_avp, &data->conditional_policy_information.list[data->conditional_policy_information.count]); data->conditional_policy_information.count++; } else if (IS_AVP(davp_proxy_info)) { FDCHECK_PARSE_DIRECT(parseGxProxyInfo, child_avp, &data->proxy_info.list[data->proxy_info.count]); data->proxy_info.count++; } else if (IS_AVP(davp_route_record)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->route_record.list[data->route_record.count], GX_ROUTE_RECORD_LEN); data->route_record.count++; } else if (IS_AVP(davp_load)) { FDCHECK_PARSE_DIRECT(parseGxLoad, child_avp, &data->load.list[data->load.count]); data->load.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: gx_ccr_parse * * Desc: Parse Credit-Control-Request Message * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Credit-Control-Request ::= <Diameter Header: 272, REQ, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * { Destination-Realm } * { CC-Request-Type } * { CC-Request-Number } * [ Credit-Management-Status ] * [ Destination-Host ] * [ Origin-State-Id ] * * [ Subscription-Id ] * [ OC-Supported-Features ] * * [ Supported-Features ] * [ TDF-Information ] * [ Network-Request-Support ] * * [ Packet-Filter-Information ] * [ Packet-Filter-Operation ] * [ Bearer-Identifier ] * [ Bearer-Operation ] * [ Dynamic-Address-Flag ] * [ Dynamic-Address-Flag-Extension ] * [ PDN-Connection-Charging-ID ] * [ Framed-IP-Address ] * [ Framed-IPv6-Prefix ] * [ IP-CAN-Type ] * [ 3GPP-RAT-Type ] * [ AN-Trusted ] * [ RAT-Type ] * [ Termination-Cause ] * [ User-Equipment-Info ] * [ QoS-Information ] * [ QoS-Negotiation ] * [ QoS-Upgrade ] * [ Default-EPS-Bearer-QoS ] * [ Default-QoS-Information ] * * 2 [ AN-GW-Address ] * [ AN-GW-Status ] * [ 3GPP-SGSN-MCC-MNC ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ 3GPP-GGSN-Address ] * [ 3GPP-GGSN-Ipv6-Address ] * [ 3GPP-Selection-Mode ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ Fixed-User-Location-Info ] * [ User-Location-Info-Time ] * [ User-CSG-Information ] * [ TWAN-Identifier ] * [ 3GPP-MS-TimeZone ] * * [ RAN-NAS-Release-Cause ] * [ 3GPP-Charging-Characteristics ] * [ Called-Station-Id ] * [ PDN-Connection-ID ] * [ Bearer-Usage ] * [ Online ] * [ Offline ] * * [ TFT-Packet-Filter-Information ] * * [ Charging-Rule-Report ] * * [ Application-Detection-Information ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * [ Access-Network-Charging-Address ] * * [ Access-Network-Charging-Identifier-Gx ] * * [ CoA-Information ] * * [ Usage-Monitoring-Information ] * [ NBIFOM-Support ] * [ NBIFOM-Mode ] * [ Default-Access ] * [ Origination-Time-Stamp ] * [ Maximum-Wait-Time ] * [ Access-Availability-Change-Reason ] * [ Routing-Rule-Install ] * [ Routing-Rule-Remove ] * [ HeNB-Local-IP-Address ] * [ UE-Local-IP-Address ] * [ UDP-Source-Port ] * [ TCP-Source-Port ] * * [ Presence-Reporting-Area-Information ] * [ Logical-Access-Id ] * [ Physical-Access-Id ] * * [ Proxy-Info ] * * [ Route-Record ] * [ 3GPP-PS-Data-Off-Status ] * * [ AVP ] */ int gx_ccr_parse ( struct msg *msg, GxCCR *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* clear the data buffer */ memset((void*)data, 0, sizeof(*data)); /* iterate through the AVPNAME child AVP's */ FDCHECK_FCT(fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_session_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->session_id, GX_SESSION_ID_LEN); data->presence.session_id=1; } else if (IS_AVP(davp_drmp)) { data->drmp = hdr->avp_value->i32; data->presence.drmp=1; } else if (IS_AVP(davp_auth_application_id)) { data->auth_application_id = hdr->avp_value->u32; data->presence.auth_application_id=1; } else if (IS_AVP(davp_origin_host)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->origin_host, GX_ORIGIN_HOST_LEN); data->presence.origin_host=1; } else if (IS_AVP(davp_origin_realm)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->origin_realm, GX_ORIGIN_REALM_LEN); data->presence.origin_realm=1; } else if (IS_AVP(davp_destination_realm)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->destination_realm, GX_DESTINATION_REALM_LEN); data->presence.destination_realm=1; } else if (IS_AVP(davp_service_context_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->service_context_id, GX_SERVICE_CONTEXT_ID_LEN); data->presence.service_context_id=1; } else if (IS_AVP(davp_cc_request_type)) { data->cc_request_type = hdr->avp_value->i32; data->presence.cc_request_type=1; } else if (IS_AVP(davp_cc_request_type)) { data->cc_request_type = hdr->avp_value->i32; data->presence.cc_request_type=1; } else if (IS_AVP(davp_cc_request_number)) { data->cc_request_number = hdr->avp_value->u32; data->presence.cc_request_number=1; } else if (IS_AVP(davp_credit_management_status)) { data->credit_management_status = hdr->avp_value->u32; data->presence.credit_management_status=1; } else if (IS_AVP(davp_destination_host)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->destination_host, GX_DESTINATION_HOST_LEN); data->presence.destination_host=1; } else if (IS_AVP(davp_origin_state_id)) { data->origin_state_id = hdr->avp_value->u32; data->presence.origin_state_id=1; } else if (IS_AVP(davp_subscription_id)) { data->subscription_id.count++; cnt++; data->presence.subscription_id=1; } else if (IS_AVP(davp_oc_supported_features)) { FDCHECK_PARSE_DIRECT(parseGxOcSupportedFeatures, child_avp, &data->oc_supported_features); data->presence.oc_supported_features=1; } else if (IS_AVP(davp_supported_features)) { data->supported_features.count++; cnt++; data->presence.supported_features=1; } else if (IS_AVP(davp_tdf_information)) { FDCHECK_PARSE_DIRECT(parseGxTdfInformation, child_avp, &data->tdf_information); data->presence.tdf_information=1; } else if (IS_AVP(davp_network_request_support)) { data->network_request_support = hdr->avp_value->i32; data->presence.network_request_support=1; } else if (IS_AVP(davp_packet_filter_information)) { data->packet_filter_information.count++; cnt++; data->presence.packet_filter_information=1; } else if (IS_AVP(davp_packet_filter_operation)) { data->packet_filter_operation = hdr->avp_value->i32; data->presence.packet_filter_operation=1; } else if (IS_AVP(davp_bearer_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->bearer_identifier, GX_BEARER_IDENTIFIER_LEN); data->presence.bearer_identifier=1; } else if (IS_AVP(davp_bearer_operation)) { data->bearer_operation = hdr->avp_value->i32; data->presence.bearer_operation=1; } else if (IS_AVP(davp_dynamic_address_flag)) { data->dynamic_address_flag = hdr->avp_value->i32; data->presence.dynamic_address_flag=1; } else if (IS_AVP(davp_dynamic_address_flag_extension)) { data->dynamic_address_flag_extension = hdr->avp_value->i32; data->presence.dynamic_address_flag_extension=1; } else if (IS_AVP(davp_pdn_connection_charging_id)) { data->pdn_connection_charging_id = hdr->avp_value->u32; data->presence.pdn_connection_charging_id=1; } else if (IS_AVP(davp_framed_ip_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->framed_ip_address, GX_FRAMED_IP_ADDRESS_LEN); data->presence.framed_ip_address=1; } else if (IS_AVP(davp_framed_ipv6_prefix)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->framed_ipv6_prefix, GX_FRAMED_IPV6_PREFIX_LEN); data->presence.framed_ipv6_prefix=1; } else if (IS_AVP(davp_ip_can_type)) { data->ip_can_type = hdr->avp_value->i32; data->presence.ip_can_type=1; } else if (IS_AVP(davp_3gpp_rat_type)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_rat_type, GX_3GPP_RAT_TYPE_LEN); data->presence.tgpp_rat_type=1; } else if (IS_AVP(davp_an_trusted)) { data->an_trusted = hdr->avp_value->i32; data->presence.an_trusted=1; } else if (IS_AVP(davp_rat_type)) { data->rat_type = hdr->avp_value->i32; data->presence.rat_type=1; } else if (IS_AVP(davp_termination_cause)) { data->termination_cause = hdr->avp_value->i32; data->presence.termination_cause=1; } else if (IS_AVP(davp_user_equipment_info)) { FDCHECK_PARSE_DIRECT(parseGxUserEquipmentInfo, child_avp, &data->user_equipment_info); data->presence.user_equipment_info=1; } else if (IS_AVP(davp_qos_information)) { FDCHECK_PARSE_DIRECT(parseGxQosInformation, child_avp, &data->qos_information); data->presence.qos_information=1; } else if (IS_AVP(davp_qos_negotiation)) { data->qos_negotiation = hdr->avp_value->i32; data->presence.qos_negotiation=1; } else if (IS_AVP(davp_qos_upgrade)) { data->qos_upgrade = hdr->avp_value->i32; data->presence.qos_upgrade=1; } else if (IS_AVP(davp_default_eps_bearer_qos)) { FDCHECK_PARSE_DIRECT(parseGxDefaultEpsBearerQos, child_avp, &data->default_eps_bearer_qos); data->presence.default_eps_bearer_qos=1; } else if (IS_AVP(davp_default_qos_information)) { FDCHECK_PARSE_DIRECT(parseGxDefaultQosInformation, child_avp, &data->default_qos_information); data->presence.default_qos_information=1; } else if (IS_AVP(davp_an_gw_address)) { data->an_gw_address.count++; cnt++; data->presence.an_gw_address=1; } else if (IS_AVP(davp_an_gw_status)) { data->an_gw_status = hdr->avp_value->i32; data->presence.an_gw_status=1; } else if (IS_AVP(davp_3gpp_sgsn_mcc_mnc)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_sgsn_mcc_mnc, GX_3GPP_SGSN_MCC_MNC_LEN); data->presence.tgpp_sgsn_mcc_mnc=1; } else if (IS_AVP(davp_3gpp_sgsn_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_sgsn_address, GX_3GPP_SGSN_ADDRESS_LEN); data->presence.tgpp_sgsn_address=1; } else if (IS_AVP(davp_3gpp_sgsn_ipv6_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_sgsn_ipv6_address, GX_3GPP_SGSN_IPV6_ADDRESS_LEN); data->presence.tgpp_sgsn_ipv6_address=1; } else if (IS_AVP(davp_3gpp_ggsn_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_ggsn_address, GX_3GPP_GGSN_ADDRESS_LEN); data->presence.tgpp_ggsn_address=1; } else if (IS_AVP(davp_3gpp_ggsn_ipv6_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_ggsn_ipv6_address, GX_3GPP_GGSN_IPV6_ADDRESS_LEN); data->presence.tgpp_ggsn_ipv6_address=1; } else if (IS_AVP(davp_3gpp_selection_mode)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_selection_mode, GX_3GPP_SELECTION_MODE_LEN); data->presence.tgpp_selection_mode=1; } else if (IS_AVP(davp_rai)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->rai, GX_RAI_LEN); data->presence.rai=1; } else if (IS_AVP(davp_3gpp_user_location_info)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_user_location_info, GX_3GPP_USER_LOCATION_INFO_LEN); data->presence.tgpp_user_location_info=1; } else if (IS_AVP(davp_fixed_user_location_info)) { FDCHECK_PARSE_DIRECT(parseGxFixedUserLocationInfo, child_avp, &data->fixed_user_location_info); data->presence.fixed_user_location_info=1; } else if (IS_AVP(davp_user_location_info_time)) { FD_PARSE_TIME(hdr->avp_value, data->user_location_info_time); data->presence.user_location_info_time=1; } else if (IS_AVP(davp_user_csg_information)) { FDCHECK_PARSE_DIRECT(parseGxUserCsgInformation, child_avp, &data->user_csg_information); data->presence.user_csg_information=1; } else if (IS_AVP(davp_twan_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->twan_identifier, GX_TWAN_IDENTIFIER_LEN); data->presence.twan_identifier=1; } else if (IS_AVP(davp_3gpp_ms_timezone)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_ms_timezone, GX_3GPP_MS_TIMEZONE_LEN); data->presence.tgpp_ms_timezone=1; } else if (IS_AVP(davp_ran_nas_release_cause)) { data->ran_nas_release_cause.count++; cnt++; data->presence.ran_nas_release_cause=1; } else if (IS_AVP(davp_3gpp_charging_characteristics)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_charging_characteristics, GX_3GPP_CHARGING_CHARACTERISTICS_LEN); data->presence.tgpp_charging_characteristics=1; } else if (IS_AVP(davp_called_station_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->called_station_id, GX_CALLED_STATION_ID_LEN); data->presence.called_station_id=1; } else if (IS_AVP(davp_pdn_connection_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->pdn_connection_id, GX_PDN_CONNECTION_ID_LEN); data->presence.pdn_connection_id=1; } else if (IS_AVP(davp_bearer_usage)) { data->bearer_usage = hdr->avp_value->i32; data->presence.bearer_usage=1; } else if (IS_AVP(davp_online)) { data->online = hdr->avp_value->i32; data->presence.online=1; } else if (IS_AVP(davp_offline)) { data->offline = hdr->avp_value->i32; data->presence.offline=1; } else if (IS_AVP(davp_tft_packet_filter_information)) { data->tft_packet_filter_information.count++; cnt++; data->presence.tft_packet_filter_information=1; } else if (IS_AVP(davp_charging_rule_report)) { data->charging_rule_report.count++; cnt++; data->presence.charging_rule_report=1; } else if (IS_AVP(davp_application_detection_information)) { data->application_detection_information.count++; cnt++; data->presence.application_detection_information=1; } else if (IS_AVP(davp_event_trigger)) { data->event_trigger.count++; cnt++; data->presence.event_trigger=1; } else if (IS_AVP(davp_event_report_indication)) { FDCHECK_PARSE_DIRECT(parseGxEventReportIndication, child_avp, &data->event_report_indication); data->presence.event_report_indication=1; } else if (IS_AVP(davp_access_network_charging_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->access_network_charging_address); data->presence.access_network_charging_address=1; } else if (IS_AVP(davp_access_network_charging_identifier_gx)) { data->access_network_charging_identifier_gx.count++; cnt++; data->presence.access_network_charging_identifier_gx=1; } else if (IS_AVP(davp_coa_information)) { data->coa_information.count++; cnt++; data->presence.coa_information=1; } else if (IS_AVP(davp_usage_monitoring_information)) { data->usage_monitoring_information.count++; cnt++; data->presence.usage_monitoring_information=1; } else if (IS_AVP(davp_nbifom_support)) { data->nbifom_support = hdr->avp_value->i32; data->presence.nbifom_support=1; } else if (IS_AVP(davp_nbifom_mode)) { data->nbifom_mode = hdr->avp_value->i32; data->presence.nbifom_mode=1; } else if (IS_AVP(davp_default_access)) { data->default_access = hdr->avp_value->i32; data->presence.default_access=1; } else if (IS_AVP(davp_origination_time_stamp)) { data->origination_time_stamp = hdr->avp_value->u64; data->presence.origination_time_stamp=1; } else if (IS_AVP(davp_maximum_wait_time)) { data->maximum_wait_time = hdr->avp_value->u32; data->presence.maximum_wait_time=1; } else if (IS_AVP(davp_access_availability_change_reason)) { data->access_availability_change_reason = hdr->avp_value->u32; data->presence.access_availability_change_reason=1; } else if (IS_AVP(davp_routing_rule_install)) { FDCHECK_PARSE_DIRECT(parseGxRoutingRuleInstall, child_avp, &data->routing_rule_install); data->presence.routing_rule_install=1; } else if (IS_AVP(davp_routing_rule_remove)) { FDCHECK_PARSE_DIRECT(parseGxRoutingRuleRemove, child_avp, &data->routing_rule_remove); data->presence.routing_rule_remove=1; } else if (IS_AVP(davp_henb_local_ip_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->henb_local_ip_address); data->presence.henb_local_ip_address=1; } else if (IS_AVP(davp_ue_local_ip_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->ue_local_ip_address); data->presence.ue_local_ip_address=1; } else if (IS_AVP(davp_udp_source_port)) { data->udp_source_port = hdr->avp_value->u32; data->presence.udp_source_port=1; } else if (IS_AVP(davp_tcp_source_port)) { data->tcp_source_port = hdr->avp_value->u32; data->presence.tcp_source_port=1; } else if (IS_AVP(davp_presence_reporting_area_information)) { data->presence_reporting_area_information.count++; cnt++; data->presence.presence_reporting_area_information=1; } else if (IS_AVP(davp_logical_access_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->logical_access_id, GX_LOGICAL_ACCESS_ID_LEN); data->presence.logical_access_id=1; } else if (IS_AVP(davp_physical_access_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->physical_access_id, GX_PHYSICAL_ACCESS_ID_LEN); data->presence.physical_access_id=1; } else if (IS_AVP(davp_proxy_info)) { data->proxy_info.count++; cnt++; data->presence.proxy_info=1; } else if (IS_AVP(davp_route_record)) { data->route_record.count++; cnt++; data->presence.route_record=1; } else if (IS_AVP(davp_3gpp_ps_data_off_status)) { data->tgpp_ps_data_off_status = hdr->avp_value->i32; data->presence.tgpp_ps_data_off_status=1; } /* get the next child AVP */ FDCHECK_FCT( fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->subscription_id, GxSubscriptionId); FD_ALLOC_LIST(data->supported_features, GxSupportedFeatures); FD_ALLOC_LIST(data->packet_filter_information, GxPacketFilterInformation); FD_ALLOC_LIST(data->an_gw_address, FdAddress); FD_ALLOC_LIST(data->ran_nas_release_cause, GxRanNasReleaseCauseOctetString); FD_ALLOC_LIST(data->tft_packet_filter_information, GxTftPacketFilterInformation); FD_ALLOC_LIST(data->charging_rule_report, GxChargingRuleReport); FD_ALLOC_LIST(data->application_detection_information, GxApplicationDetectionInformation); FD_ALLOC_LIST(data->event_trigger, int32_t); FD_ALLOC_LIST(data->access_network_charging_identifier_gx, GxAccessNetworkChargingIdentifierGx); FD_ALLOC_LIST(data->coa_information, GxCoaInformation); FD_ALLOC_LIST(data->usage_monitoring_information, GxUsageMonitoringInformation); FD_ALLOC_LIST(data->presence_reporting_area_information, GxPresenceReportingAreaInformation); FD_ALLOC_LIST(data->proxy_info, GxProxyInfo); FD_ALLOC_LIST(data->route_record, GxRouteRecordOctetString); /* iterate through the AVPNAME child AVP's */ FDCHECK_FCT(fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_subscription_id)) { FDCHECK_PARSE_DIRECT(parseGxSubscriptionId, child_avp, &data->subscription_id.list[data->subscription_id.count]); data->subscription_id.count++; } else if (IS_AVP(davp_supported_features)) { FDCHECK_PARSE_DIRECT(parseGxSupportedFeatures, child_avp, &data->supported_features.list[data->supported_features.count]); data->supported_features.count++; } else if (IS_AVP(davp_packet_filter_information)) { FDCHECK_PARSE_DIRECT(parseGxPacketFilterInformation, child_avp, &data->packet_filter_information.list[data->packet_filter_information.count]); data->packet_filter_information.count++; } else if (IS_AVP(davp_an_gw_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->an_gw_address.list[data->an_gw_address.count]); data->an_gw_address.count++; } else if (IS_AVP(davp_ran_nas_release_cause)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->ran_nas_release_cause.list[data->ran_nas_release_cause.count], GX_RAN_NAS_RELEASE_CAUSE_LEN); data->ran_nas_release_cause.count++; } else if (IS_AVP(davp_tft_packet_filter_information)) { FDCHECK_PARSE_DIRECT(parseGxTftPacketFilterInformation, child_avp, &data->tft_packet_filter_information.list[data->tft_packet_filter_information.count]); data->tft_packet_filter_information.count++; } else if (IS_AVP(davp_charging_rule_report)) { FDCHECK_PARSE_DIRECT(parseGxChargingRuleReport, child_avp, &data->charging_rule_report.list[data->charging_rule_report.count]); data->charging_rule_report.count++; } else if (IS_AVP(davp_application_detection_information)) { FDCHECK_PARSE_DIRECT(parseGxApplicationDetectionInformation, child_avp, &data->application_detection_information.list[data->application_detection_information.count]); data->application_detection_information.count++; } else if (IS_AVP(davp_event_trigger)) { data->event_trigger.list[data->event_trigger.count] = hdr->avp_value->i32; data->event_trigger.count++; } else if (IS_AVP(davp_access_network_charging_identifier_gx)) { FDCHECK_PARSE_DIRECT(parseGxAccessNetworkChargingIdentifierGx, child_avp, &data->access_network_charging_identifier_gx.list[data->access_network_charging_identifier_gx.count]); data->access_network_charging_identifier_gx.count++; } else if (IS_AVP(davp_coa_information)) { FDCHECK_PARSE_DIRECT(parseGxCoaInformation, child_avp, &data->coa_information.list[data->coa_information.count]); data->coa_information.count++; } else if (IS_AVP(davp_usage_monitoring_information)) { FDCHECK_PARSE_DIRECT(parseGxUsageMonitoringInformation, child_avp, &data->usage_monitoring_information.list[data->usage_monitoring_information.count]); data->usage_monitoring_information.count++; } else if (IS_AVP(davp_presence_reporting_area_information)) { FDCHECK_PARSE_DIRECT(parseGxPresenceReportingAreaInformation, child_avp, &data->presence_reporting_area_information.list[data->presence_reporting_area_information.count]); data->presence_reporting_area_information.count++; } else if (IS_AVP(davp_proxy_info)) { FDCHECK_PARSE_DIRECT(parseGxProxyInfo, child_avp, &data->proxy_info.list[data->proxy_info.count]); data->proxy_info.count++; } else if (IS_AVP(davp_route_record)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->route_record.list[data->route_record.count], GX_ROUTE_RECORD_LEN); data->route_record.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /*******************************************************************************/ /* free message data functions */ /*******************************************************************************/ /* * * Fun: gx_rar_free * * Desc: Free the multiple occurrance AVP's for Re-Auth-Request * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Re-Auth-Request ::= <Diameter Header: 258, REQ, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * { Destination-Realm } * { Destination-Host } * { Re-Auth-Request-Type } * [ Session-Release-Cause ] * [ Origin-State-Id ] * [ OC-Supported-Features ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * * [ Charging-Rule-Remove ] * * [ Charging-Rule-Install ] * [ Default-EPS-Bearer-QoS ] * * [ QoS-Information ] * [ Default-QoS-Information ] * [ Revalidation-Time ] * * [ Usage-Monitoring-Information ] * [ PCSCF-Restoration-Indication ] * * 4 [ Conditional-Policy-Information ] * [ Removal-Of-Access ] * [ IP-CAN-Type ] * [ PRA-Install ] * [ PRA-Remove ] * * [ CSG-Information-Reporting ] * * [ Proxy-Info ] * * [ Route-Record ] * * [ AVP ] */ int gx_rar_free ( GxRAR *data ) { FD_CALLFREE_STRUCT( data->event_report_indication, freeGxEventReportIndication ); FD_CALLFREE_LIST( data->charging_rule_remove, freeGxChargingRuleRemove ); FD_CALLFREE_LIST( data->charging_rule_install, freeGxChargingRuleInstall ); FD_CALLFREE_LIST( data->qos_information, freeGxQosInformation ); FD_CALLFREE_LIST( data->usage_monitoring_information, freeGxUsageMonitoringInformation ); FD_CALLFREE_LIST( data->conditional_policy_information, freeGxConditionalPolicyInformation ); FD_CALLFREE_STRUCT( data->pra_install, freeGxPraInstall ); FD_CALLFREE_STRUCT( data->pra_remove, freeGxPraRemove ); FD_FREE_LIST( data->event_trigger ); FD_FREE_LIST( data->charging_rule_remove ); FD_FREE_LIST( data->charging_rule_install ); FD_FREE_LIST( data->qos_information ); FD_FREE_LIST( data->usage_monitoring_information ); FD_FREE_LIST( data->conditional_policy_information ); FD_FREE_LIST( data->csg_information_reporting ); FD_FREE_LIST( data->proxy_info ); FD_FREE_LIST( data->route_record ); return FD_REASON_OK; } /* * * Fun: gx_raa_free * * Desc: Free the multiple occurrance AVP's for Re-Auth-Answer * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Re-Auth-Answer ::= <Diameter Header: 258, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Origin-Host } * { Origin-Realm } * [ Result-Code ] * [ Experimental-Result ] * [ Origin-State-Id ] * [ OC-Supported-Features ] * [ OC-OLR ] * [ IP-CAN-Type ] * [ RAT-Type ] * [ AN-Trusted ] * * 2 [ AN-GW-Address ] * [ 3GPP-SGSN-MCC-MNC ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ User-Location-Info-Time ] * [ NetLoc-Access-Support ] * [ User-CSG-Information ] * [ 3GPP-MS-TimeZone ] * [ Default-QoS-Information ] * * [ Charging-Rule-Report ] * [ Error-Message ] * [ Error-Reporting-Host ] * [ Failed-AVP ] * * [ Proxy-Info ] * * [ AVP ] */ int gx_raa_free ( GxRAA *data ) { FD_CALLFREE_LIST( data->charging_rule_report, freeGxChargingRuleReport ); FD_FREE_LIST( data->an_gw_address ); FD_FREE_LIST( data->charging_rule_report ); FD_FREE_LIST( data->proxy_info ); return FD_REASON_OK; } /* * * Fun: gx_cca_free * * Desc: Free the multiple occurrance AVP's for Credit-Control-Answer * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Credit-Control-Answer ::= <Diameter Header: 272, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * [ Result-Code ] * [ Experimental-Result ] * { CC-Request-Type } * { CC-Request-Number } * [ OC-Supported-Features ] * [ OC-OLR ] * * [ Supported-Features ] * [ Bearer-Control-Mode ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * [ Origin-State-Id ] * * [ Redirect-Host ] * [ Redirect-Host-Usage ] * [ Redirect-Max-Cache-Time ] * * [ Charging-Rule-Remove ] * * [ Charging-Rule-Install ] * [ Charging-Information ] * [ Online ] * [ Offline ] * * [ QoS-Information ] * [ Revalidation-Time ] * [ Default-EPS-Bearer-QoS ] * [ Default-QoS-Information ] * [ Bearer-Usage ] * * [ Usage-Monitoring-Information ] * * [ CSG-Information-Reporting ] * [ User-CSG-Information ] * [ PRA-Install ] * [ PRA-Remove ] * [ Presence-Reporting-Area-Information ] * [ Session-Release-Cause ] * [ NBIFOM-Support ] * [ NBIFOM-Mode ] * [ Default-Access ] * [ RAN-Rule-Support ] * * [ Routing-Rule-Report ] * * 4 [ Conditional-Policy-Information ] * [ Removal-Of-Access ] * [ IP-CAN-Type ] * [ Error-Message ] * [ Error-Reporting-Host ] * [ Failed-AVP ] * * [ Proxy-Info ] * * [ Route-Record ] * * [ Load ] * * [ AVP ] */ int gx_cca_free ( GxCCA *data ) { FD_CALLFREE_STRUCT( data->event_report_indication, freeGxEventReportIndication ); FD_CALLFREE_LIST( data->charging_rule_remove, freeGxChargingRuleRemove ); FD_CALLFREE_LIST( data->charging_rule_install, freeGxChargingRuleInstall ); FD_CALLFREE_LIST( data->qos_information, freeGxQosInformation ); FD_CALLFREE_LIST( data->usage_monitoring_information, freeGxUsageMonitoringInformation ); FD_CALLFREE_STRUCT( data->pra_install, freeGxPraInstall ); FD_CALLFREE_STRUCT( data->pra_remove, freeGxPraRemove ); FD_CALLFREE_LIST( data->routing_rule_report, freeGxRoutingRuleReport ); FD_CALLFREE_LIST( data->conditional_policy_information, freeGxConditionalPolicyInformation ); FD_FREE_LIST( data->supported_features ); FD_FREE_LIST( data->event_trigger ); FD_FREE_LIST( data->redirect_host ); FD_FREE_LIST( data->charging_rule_remove ); FD_FREE_LIST( data->charging_rule_install ); FD_FREE_LIST( data->qos_information ); FD_FREE_LIST( data->usage_monitoring_information ); FD_FREE_LIST( data->csg_information_reporting ); FD_FREE_LIST( data->routing_rule_report ); FD_FREE_LIST( data->conditional_policy_information ); FD_FREE_LIST( data->proxy_info ); FD_FREE_LIST( data->route_record ); FD_FREE_LIST( data->load ); return FD_REASON_OK; } /* * * Fun: gx_ccr_free * * Desc: Free the multiple occurrance AVP's for Credit-Control-Request * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Credit-Control-Request ::= <Diameter Header: 272, REQ, PXY, 16777238> * < Session-Id > * [ DRMP ] * { Auth-Application-Id } * { Origin-Host } * { Origin-Realm } * { Destination-Realm } * { CC-Request-Type } * { CC-Request-Number } * [ Credit-Management-Status ] * [ Destination-Host ] * [ Origin-State-Id ] * * [ Subscription-Id ] * [ OC-Supported-Features ] * * [ Supported-Features ] * [ TDF-Information ] * [ Network-Request-Support ] * * [ Packet-Filter-Information ] * [ Packet-Filter-Operation ] * [ Bearer-Identifier ] * [ Bearer-Operation ] * [ Dynamic-Address-Flag ] * [ Dynamic-Address-Flag-Extension ] * [ PDN-Connection-Charging-ID ] * [ Framed-IP-Address ] * [ Framed-IPv6-Prefix ] * [ IP-CAN-Type ] * [ 3GPP-RAT-Type ] * [ AN-Trusted ] * [ RAT-Type ] * [ Termination-Cause ] * [ User-Equipment-Info ] * [ QoS-Information ] * [ QoS-Negotiation ] * [ QoS-Upgrade ] * [ Default-EPS-Bearer-QoS ] * [ Default-QoS-Information ] * * 2 [ AN-GW-Address ] * [ AN-GW-Status ] * [ 3GPP-SGSN-MCC-MNC ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ 3GPP-GGSN-Address ] * [ 3GPP-GGSN-Ipv6-Address ] * [ 3GPP-Selection-Mode ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ Fixed-User-Location-Info ] * [ User-Location-Info-Time ] * [ User-CSG-Information ] * [ TWAN-Identifier ] * [ 3GPP-MS-TimeZone ] * * [ RAN-NAS-Release-Cause ] * [ 3GPP-Charging-Characteristics ] * [ Called-Station-Id ] * [ PDN-Connection-ID ] * [ Bearer-Usage ] * [ Online ] * [ Offline ] * * [ TFT-Packet-Filter-Information ] * * [ Charging-Rule-Report ] * * [ Application-Detection-Information ] * * [ Event-Trigger ] * [ Event-Report-Indication ] * [ Access-Network-Charging-Address ] * * [ Access-Network-Charging-Identifier-Gx ] * * [ CoA-Information ] * * [ Usage-Monitoring-Information ] * [ NBIFOM-Support ] * [ NBIFOM-Mode ] * [ Default-Access ] * [ Origination-Time-Stamp ] * [ Maximum-Wait-Time ] * [ Access-Availability-Change-Reason ] * [ Routing-Rule-Install ] * [ Routing-Rule-Remove ] * [ HeNB-Local-IP-Address ] * [ UE-Local-IP-Address ] * [ UDP-Source-Port ] * [ TCP-Source-Port ] * * [ Presence-Reporting-Area-Information ] * [ Logical-Access-Id ] * [ Physical-Access-Id ] * * [ Proxy-Info ] * * [ Route-Record ] * [ 3GPP-PS-Data-Off-Status ] * * [ AVP ] */ int gx_ccr_free ( GxCCR *data ) { FD_CALLFREE_STRUCT( data->qos_information, freeGxQosInformation ); FD_CALLFREE_LIST( data->charging_rule_report, freeGxChargingRuleReport ); FD_CALLFREE_LIST( data->application_detection_information, freeGxApplicationDetectionInformation ); FD_CALLFREE_STRUCT( data->event_report_indication, freeGxEventReportIndication ); FD_CALLFREE_LIST( data->access_network_charging_identifier_gx, freeGxAccessNetworkChargingIdentifierGx ); FD_CALLFREE_LIST( data->coa_information, freeGxCoaInformation ); FD_CALLFREE_LIST( data->usage_monitoring_information, freeGxUsageMonitoringInformation ); FD_CALLFREE_STRUCT( data->routing_rule_install, freeGxRoutingRuleInstall ); FD_CALLFREE_STRUCT( data->routing_rule_remove, freeGxRoutingRuleRemove ); FD_FREE_LIST( data->subscription_id ); FD_FREE_LIST( data->supported_features ); FD_FREE_LIST( data->packet_filter_information ); FD_FREE_LIST( data->an_gw_address ); FD_FREE_LIST( data->ran_nas_release_cause ); FD_FREE_LIST( data->tft_packet_filter_information ); FD_FREE_LIST( data->charging_rule_report ); FD_FREE_LIST( data->application_detection_information ); FD_FREE_LIST( data->event_trigger ); FD_FREE_LIST( data->access_network_charging_identifier_gx ); FD_FREE_LIST( data->coa_information ); FD_FREE_LIST( data->usage_monitoring_information ); FD_FREE_LIST( data->presence_reporting_area_information ); FD_FREE_LIST( data->proxy_info ); FD_FREE_LIST( data->route_record ); return FD_REASON_OK; } /*******************************************************************************/ /* grouped avp parsing functions */ /*******************************************************************************/ /* * * Fun: parseGxExperimentalResult * * Desc: Parse Experimental-Result AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Experimental-Result ::= <AVP Header: 297> * { Vendor-Id } * { Experimental-Result-Code } */ static int parseGxExperimentalResult ( struct avp *avp, GxExperimentalResult *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Experimental-Result child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_vendor_id)) { data->vendor_id = hdr->avp_value->u32; data->presence.vendor_id=1; } else if (IS_AVP(davp_experimental_result_code)) { data->experimental_result_code = hdr->avp_value->u32; data->presence.experimental_result_code=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Experimental-Result child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxPraRemove * * Desc: Parse PRA-Remove AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * PRA-Remove ::= <AVP Header: 2846> * * [ Presence-Reporting-Area-Identifier ] * * [ AVP ] */ static int parseGxPraRemove ( struct avp *avp, GxPraRemove *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the PRA-Remove child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_presence_reporting_area_identifier)) { data->presence_reporting_area_identifier.count++; cnt++; data->presence.presence_reporting_area_identifier=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->presence_reporting_area_identifier, GxPresenceReportingAreaIdentifierOctetString); /* iterate through the PRA-Remove child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_presence_reporting_area_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->presence_reporting_area_identifier.list[data->presence_reporting_area_identifier.count], GX_PRESENCE_REPORTING_AREA_IDENTIFIER_LEN); data->presence_reporting_area_identifier.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxQosInformation * * Desc: Parse QoS-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * QoS-Information ::= <AVP Header: 1016> * [ QoS-Class-Identifier ] * [ Max-Requested-Bandwidth-UL ] * [ Max-Requested-Bandwidth-DL ] * [ Extended-Max-Requested-BW-UL ] * [ Extended-Max-Requested-BW-DL ] * [ Guaranteed-Bitrate-UL ] * [ Guaranteed-Bitrate-DL ] * [ Extended-GBR-UL ] * [ Extended-GBR-DL ] * [ Bearer-Identifier ] * [ Allocation-Retention-Priority ] * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ Conditional-APN-Aggregate-Max-Bitrate ] * * [ AVP ] */ static int parseGxQosInformation ( struct avp *avp, GxQosInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the QoS-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_qos_class_identifier)) { data->qos_class_identifier = hdr->avp_value->i32; data->presence.qos_class_identifier=1; } else if (IS_AVP(davp_max_requested_bandwidth_ul)) { data->max_requested_bandwidth_ul = hdr->avp_value->u32; data->presence.max_requested_bandwidth_ul=1; } else if (IS_AVP(davp_max_requested_bandwidth_dl)) { data->max_requested_bandwidth_dl = hdr->avp_value->u32; data->presence.max_requested_bandwidth_dl=1; } else if (IS_AVP(davp_extended_max_requested_bw_ul)) { data->extended_max_requested_bw_ul = hdr->avp_value->u32; data->presence.extended_max_requested_bw_ul=1; } else if (IS_AVP(davp_extended_max_requested_bw_dl)) { data->extended_max_requested_bw_dl = hdr->avp_value->u32; data->presence.extended_max_requested_bw_dl=1; } else if (IS_AVP(davp_guaranteed_bitrate_ul)) { data->guaranteed_bitrate_ul = hdr->avp_value->u32; data->presence.guaranteed_bitrate_ul=1; } else if (IS_AVP(davp_guaranteed_bitrate_dl)) { data->guaranteed_bitrate_dl = hdr->avp_value->u32; data->presence.guaranteed_bitrate_dl=1; } else if (IS_AVP(davp_extended_gbr_ul)) { data->extended_gbr_ul = hdr->avp_value->u32; data->presence.extended_gbr_ul=1; } else if (IS_AVP(davp_extended_gbr_dl)) { data->extended_gbr_dl = hdr->avp_value->u32; data->presence.extended_gbr_dl=1; } else if (IS_AVP(davp_bearer_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->bearer_identifier, GX_BEARER_IDENTIFIER_LEN); data->presence.bearer_identifier=1; } else if (IS_AVP(davp_allocation_retention_priority)) { FDCHECK_PARSE_DIRECT(parseGxAllocationRetentionPriority, child_avp, &data->allocation_retention_priority); data->presence.allocation_retention_priority=1; } else if (IS_AVP(davp_apn_aggregate_max_bitrate_ul)) { data->apn_aggregate_max_bitrate_ul = hdr->avp_value->u32; data->presence.apn_aggregate_max_bitrate_ul=1; } else if (IS_AVP(davp_apn_aggregate_max_bitrate_dl)) { data->apn_aggregate_max_bitrate_dl = hdr->avp_value->u32; data->presence.apn_aggregate_max_bitrate_dl=1; } else if (IS_AVP(davp_extended_apn_ambr_ul)) { data->extended_apn_ambr_ul = hdr->avp_value->u32; data->presence.extended_apn_ambr_ul=1; } else if (IS_AVP(davp_extended_apn_ambr_dl)) { data->extended_apn_ambr_dl = hdr->avp_value->u32; data->presence.extended_apn_ambr_dl=1; } else if (IS_AVP(davp_conditional_apn_aggregate_max_bitrate)) { data->conditional_apn_aggregate_max_bitrate.count++; cnt++; data->presence.conditional_apn_aggregate_max_bitrate=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->conditional_apn_aggregate_max_bitrate, GxConditionalApnAggregateMaxBitrate); /* iterate through the QoS-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_conditional_apn_aggregate_max_bitrate)) { FDCHECK_PARSE_DIRECT(parseGxConditionalApnAggregateMaxBitrate, child_avp, &data->conditional_apn_aggregate_max_bitrate.list[data->conditional_apn_aggregate_max_bitrate.count]); data->conditional_apn_aggregate_max_bitrate.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxConditionalPolicyInformation * * Desc: Parse Conditional-Policy-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Conditional-Policy-Information ::= <AVP Header: 2840> * [ Execution-Time ] * [ Default-EPS-Bearer-QoS ] * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ Conditional-APN-Aggregate-Max-Bitrate ] * * [ AVP ] */ static int parseGxConditionalPolicyInformation ( struct avp *avp, GxConditionalPolicyInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Conditional-Policy-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_execution_time)) { FD_PARSE_TIME(hdr->avp_value, data->execution_time); data->presence.execution_time=1; } else if (IS_AVP(davp_default_eps_bearer_qos)) { FDCHECK_PARSE_DIRECT(parseGxDefaultEpsBearerQos, child_avp, &data->default_eps_bearer_qos); data->presence.default_eps_bearer_qos=1; } else if (IS_AVP(davp_apn_aggregate_max_bitrate_ul)) { data->apn_aggregate_max_bitrate_ul = hdr->avp_value->u32; data->presence.apn_aggregate_max_bitrate_ul=1; } else if (IS_AVP(davp_apn_aggregate_max_bitrate_dl)) { data->apn_aggregate_max_bitrate_dl = hdr->avp_value->u32; data->presence.apn_aggregate_max_bitrate_dl=1; } else if (IS_AVP(davp_extended_apn_ambr_ul)) { data->extended_apn_ambr_ul = hdr->avp_value->u32; data->presence.extended_apn_ambr_ul=1; } else if (IS_AVP(davp_extended_apn_ambr_dl)) { data->extended_apn_ambr_dl = hdr->avp_value->u32; data->presence.extended_apn_ambr_dl=1; } else if (IS_AVP(davp_conditional_apn_aggregate_max_bitrate)) { data->conditional_apn_aggregate_max_bitrate.count++; cnt++; data->presence.conditional_apn_aggregate_max_bitrate=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->conditional_apn_aggregate_max_bitrate, GxConditionalApnAggregateMaxBitrate); /* iterate through the Conditional-Policy-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_conditional_apn_aggregate_max_bitrate)) { FDCHECK_PARSE_DIRECT(parseGxConditionalApnAggregateMaxBitrate, child_avp, &data->conditional_apn_aggregate_max_bitrate.list[data->conditional_apn_aggregate_max_bitrate.count]); data->conditional_apn_aggregate_max_bitrate.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxPraInstall * * Desc: Parse PRA-Install AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * PRA-Install ::= <AVP Header: 2845> * * [ Presence-Reporting-Area-Information ] * * [ AVP ] */ static int parseGxPraInstall ( struct avp *avp, GxPraInstall *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the PRA-Install child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_presence_reporting_area_information)) { data->presence_reporting_area_information.count++; cnt++; data->presence.presence_reporting_area_information=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->presence_reporting_area_information, GxPresenceReportingAreaInformation); /* iterate through the PRA-Install child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_presence_reporting_area_information)) { FDCHECK_PARSE_DIRECT(parseGxPresenceReportingAreaInformation, child_avp, &data->presence_reporting_area_information.list[data->presence_reporting_area_information.count]); data->presence_reporting_area_information.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxAreaScope * * Desc: Parse Area-Scope AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Area-Scope ::= <AVP Header: 1624> * * [ Cell-Global-Identity ] * * [ E-UTRAN-Cell-Global-Identity ] * * [ Routing-Area-Identity ] * * [ Location-Area-Identity ] * * [ Tracking-Area-Identity ] * * [ AVP ] */ static int parseGxAreaScope ( struct avp *avp, GxAreaScope *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Area-Scope child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_cell_global_identity)) { data->cell_global_identity.count++; cnt++; data->presence.cell_global_identity=1; } else if (IS_AVP(davp_e_utran_cell_global_identity)) { data->e_utran_cell_global_identity.count++; cnt++; data->presence.e_utran_cell_global_identity=1; } else if (IS_AVP(davp_routing_area_identity)) { data->routing_area_identity.count++; cnt++; data->presence.routing_area_identity=1; } else if (IS_AVP(davp_location_area_identity)) { data->location_area_identity.count++; cnt++; data->presence.location_area_identity=1; } else if (IS_AVP(davp_tracking_area_identity)) { data->tracking_area_identity.count++; cnt++; data->presence.tracking_area_identity=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->cell_global_identity, GxCellGlobalIdentityOctetString); FD_ALLOC_LIST(data->e_utran_cell_global_identity, GxEUtranCellGlobalIdentityOctetString); FD_ALLOC_LIST(data->routing_area_identity, GxRoutingAreaIdentityOctetString); FD_ALLOC_LIST(data->location_area_identity, GxLocationAreaIdentityOctetString); FD_ALLOC_LIST(data->tracking_area_identity, GxTrackingAreaIdentityOctetString); /* iterate through the Area-Scope child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_cell_global_identity)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->cell_global_identity.list[data->cell_global_identity.count], GX_CELL_GLOBAL_IDENTITY_LEN); data->cell_global_identity.count++; } else if (IS_AVP(davp_e_utran_cell_global_identity)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->e_utran_cell_global_identity.list[data->e_utran_cell_global_identity.count], GX_E_UTRAN_CELL_GLOBAL_IDENTITY_LEN); data->e_utran_cell_global_identity.count++; } else if (IS_AVP(davp_routing_area_identity)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->routing_area_identity.list[data->routing_area_identity.count], GX_ROUTING_AREA_IDENTITY_LEN); data->routing_area_identity.count++; } else if (IS_AVP(davp_location_area_identity)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->location_area_identity.list[data->location_area_identity.count], GX_LOCATION_AREA_IDENTITY_LEN); data->location_area_identity.count++; } else if (IS_AVP(davp_tracking_area_identity)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tracking_area_identity.list[data->tracking_area_identity.count], GX_TRACKING_AREA_IDENTITY_LEN); data->tracking_area_identity.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxFlowInformation * * Desc: Parse Flow-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Flow-Information ::= <AVP Header: 1058> * [ Flow-Description ] * [ Packet-Filter-Identifier ] * [ Packet-Filter-Usage ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * [ Routing-Rule-Identifier ] * * [ AVP ] */ static int parseGxFlowInformation ( struct avp *avp, GxFlowInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Flow-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_flow_description)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->flow_description, GX_FLOW_DESCRIPTION_LEN); data->presence.flow_description=1; } else if (IS_AVP(davp_packet_filter_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->packet_filter_identifier, GX_PACKET_FILTER_IDENTIFIER_LEN); data->presence.packet_filter_identifier=1; } else if (IS_AVP(davp_packet_filter_usage)) { data->packet_filter_usage = hdr->avp_value->i32; data->presence.packet_filter_usage=1; } else if (IS_AVP(davp_tos_traffic_class)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tos_traffic_class, GX_TOS_TRAFFIC_CLASS_LEN); data->presence.tos_traffic_class=1; } else if (IS_AVP(davp_security_parameter_index)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->security_parameter_index, GX_SECURITY_PARAMETER_INDEX_LEN); data->presence.security_parameter_index=1; } else if (IS_AVP(davp_flow_label)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->flow_label, GX_FLOW_LABEL_LEN); data->presence.flow_label=1; } else if (IS_AVP(davp_flow_direction)) { data->flow_direction = hdr->avp_value->i32; data->presence.flow_direction=1; } else if (IS_AVP(davp_routing_rule_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->routing_rule_identifier, GX_ROUTING_RULE_IDENTIFIER_LEN); data->presence.routing_rule_identifier=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Flow-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxTunnelInformation * * Desc: Parse Tunnel-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Tunnel-Information ::= <AVP Header: 1038> * [ Tunnel-Header-Length ] * [ Tunnel-Header-Filter ] */ static int parseGxTunnelInformation ( struct avp *avp, GxTunnelInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Tunnel-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_tunnel_header_length)) { data->tunnel_header_length = hdr->avp_value->u32; data->presence.tunnel_header_length=1; } else if (IS_AVP(davp_tunnel_header_filter)) { data->tunnel_header_filter.count++; cnt++; data->presence.tunnel_header_filter=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->tunnel_header_filter, GxTunnelHeaderFilterOctetString); /* iterate through the Tunnel-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_tunnel_header_filter)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tunnel_header_filter.list[data->tunnel_header_filter.count], GX_TUNNEL_HEADER_FILTER_LEN); data->tunnel_header_filter.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxTftPacketFilterInformation * * Desc: Parse TFT-Packet-Filter-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * TFT-Packet-Filter-Information ::= <AVP Header: 1013> * [ Precedence ] * [ TFT-Filter ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * * [ AVP ] */ static int parseGxTftPacketFilterInformation ( struct avp *avp, GxTftPacketFilterInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the TFT-Packet-Filter-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_precedence)) { data->precedence = hdr->avp_value->u32; data->presence.precedence=1; } else if (IS_AVP(davp_tft_filter)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tft_filter, GX_TFT_FILTER_LEN); data->presence.tft_filter=1; } else if (IS_AVP(davp_tos_traffic_class)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tos_traffic_class, GX_TOS_TRAFFIC_CLASS_LEN); data->presence.tos_traffic_class=1; } else if (IS_AVP(davp_security_parameter_index)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->security_parameter_index, GX_SECURITY_PARAMETER_INDEX_LEN); data->presence.security_parameter_index=1; } else if (IS_AVP(davp_flow_label)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->flow_label, GX_FLOW_LABEL_LEN); data->presence.flow_label=1; } else if (IS_AVP(davp_flow_direction)) { data->flow_direction = hdr->avp_value->i32; data->presence.flow_direction=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the TFT-Packet-Filter-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxMbsfnArea * * Desc: Parse MBSFN-Area AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * MBSFN-Area ::= <AVP Header: 1694> * { MBSFN-Area-ID } * { Carrier-Frequency } * * [ AVP ] */ static int parseGxMbsfnArea ( struct avp *avp, GxMbsfnArea *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the MBSFN-Area child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_mbsfn_area_id)) { data->mbsfn_area_id = hdr->avp_value->u32; data->presence.mbsfn_area_id=1; } else if (IS_AVP(davp_carrier_frequency)) { data->carrier_frequency = hdr->avp_value->u32; data->presence.carrier_frequency=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the MBSFN-Area child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxEventReportIndication * * Desc: Parse Event-Report-Indication AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Event-Report-Indication ::= <AVP Header: 1033> * [ AN-Trusted ] * * [ Event-Trigger ] * [ User-CSG-Information ] * [ IP-CAN-Type ] * * 2 [ AN-GW-Address ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ 3GPP-SGSN-MCC-MNC ] * [ Framed-IP-Address ] * [ RAT-Type ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ Trace-Data ] * [ Trace-Reference ] * [ 3GPP2-BSID ] * [ 3GPP-MS-TimeZone ] * [ Routing-IP-Address ] * [ UE-Local-IP-Address ] * [ HeNB-Local-IP-Address ] * [ UDP-Source-Port ] * [ Presence-Reporting-Area-Information ] * * [ AVP ] */ static int parseGxEventReportIndication ( struct avp *avp, GxEventReportIndication *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Event-Report-Indication child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_an_trusted)) { data->an_trusted = hdr->avp_value->i32; data->presence.an_trusted=1; } else if (IS_AVP(davp_event_trigger)) { data->event_trigger.count++; cnt++; data->presence.event_trigger=1; } else if (IS_AVP(davp_user_csg_information)) { FDCHECK_PARSE_DIRECT(parseGxUserCsgInformation, child_avp, &data->user_csg_information); data->presence.user_csg_information=1; } else if (IS_AVP(davp_ip_can_type)) { data->ip_can_type = hdr->avp_value->i32; data->presence.ip_can_type=1; } else if (IS_AVP(davp_an_gw_address)) { data->an_gw_address.count++; cnt++; data->presence.an_gw_address=1; } else if (IS_AVP(davp_3gpp_sgsn_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_sgsn_address, GX_3GPP_SGSN_ADDRESS_LEN); data->presence.tgpp_sgsn_address=1; } else if (IS_AVP(davp_3gpp_sgsn_ipv6_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_sgsn_ipv6_address, GX_3GPP_SGSN_IPV6_ADDRESS_LEN); data->presence.tgpp_sgsn_ipv6_address=1; } else if (IS_AVP(davp_3gpp_sgsn_mcc_mnc)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_sgsn_mcc_mnc, GX_3GPP_SGSN_MCC_MNC_LEN); data->presence.tgpp_sgsn_mcc_mnc=1; } else if (IS_AVP(davp_framed_ip_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->framed_ip_address, GX_FRAMED_IP_ADDRESS_LEN); data->presence.framed_ip_address=1; } else if (IS_AVP(davp_rat_type)) { data->rat_type = hdr->avp_value->i32; data->presence.rat_type=1; } else if (IS_AVP(davp_rai)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->rai, GX_RAI_LEN); data->presence.rai=1; } else if (IS_AVP(davp_3gpp_user_location_info)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_user_location_info, GX_3GPP_USER_LOCATION_INFO_LEN); data->presence.tgpp_user_location_info=1; } else if (IS_AVP(davp_trace_data)) { FDCHECK_PARSE_DIRECT(parseGxTraceData, child_avp, &data->trace_data); data->presence.trace_data=1; } else if (IS_AVP(davp_trace_reference)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->trace_reference, GX_TRACE_REFERENCE_LEN); data->presence.trace_reference=1; } else if (IS_AVP(davp_3gpp2_bsid)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp2_bsid, GX_3GPP2_BSID_LEN); data->presence.tgpp2_bsid=1; } else if (IS_AVP(davp_3gpp_ms_timezone)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tgpp_ms_timezone, GX_3GPP_MS_TIMEZONE_LEN); data->presence.tgpp_ms_timezone=1; } else if (IS_AVP(davp_routing_ip_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->routing_ip_address); data->presence.routing_ip_address=1; } else if (IS_AVP(davp_ue_local_ip_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->ue_local_ip_address); data->presence.ue_local_ip_address=1; } else if (IS_AVP(davp_henb_local_ip_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->henb_local_ip_address); data->presence.henb_local_ip_address=1; } else if (IS_AVP(davp_udp_source_port)) { data->udp_source_port = hdr->avp_value->u32; data->presence.udp_source_port=1; } else if (IS_AVP(davp_presence_reporting_area_information)) { FDCHECK_PARSE_DIRECT(parseGxPresenceReportingAreaInformation, child_avp, &data->presence_reporting_area_information); data->presence.presence_reporting_area_information=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->event_trigger, int32_t); FD_ALLOC_LIST(data->an_gw_address, FdAddress); /* iterate through the Event-Report-Indication child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_event_trigger)) { data->event_trigger.list[data->event_trigger.count] = hdr->avp_value->i32; data->event_trigger.count++; } else if (IS_AVP(davp_an_gw_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->an_gw_address.list[data->an_gw_address.count]); data->an_gw_address.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxTdfInformation * * Desc: Parse TDF-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * TDF-Information ::= <AVP Header: 1087> * [ TDF-Destination-Realm ] * [ TDF-Destination-Host ] * [ TDF-IP-Address ] */ static int parseGxTdfInformation ( struct avp *avp, GxTdfInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the TDF-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_tdf_destination_realm)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tdf_destination_realm, GX_TDF_DESTINATION_REALM_LEN); data->presence.tdf_destination_realm=1; } else if (IS_AVP(davp_tdf_destination_host)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tdf_destination_host, GX_TDF_DESTINATION_HOST_LEN); data->presence.tdf_destination_host=1; } else if (IS_AVP(davp_tdf_ip_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->tdf_ip_address); data->presence.tdf_ip_address=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the TDF-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxProxyInfo * * Desc: Parse Proxy-Info AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Proxy-Info ::= <AVP Header: 284> * { Proxy-Host } * { Proxy-State } * * [ AVP ] */ static int parseGxProxyInfo ( struct avp *avp, GxProxyInfo *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Proxy-Info child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_proxy_host)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->proxy_host, GX_PROXY_HOST_LEN); data->presence.proxy_host=1; } else if (IS_AVP(davp_proxy_state)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->proxy_state, GX_PROXY_STATE_LEN); data->presence.proxy_state=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Proxy-Info child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxUsedServiceUnit * * Desc: Parse Used-Service-Unit AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Used-Service-Unit ::= <AVP Header: 446> * [ Reporting-Reason ] * [ Tariff-Change-Usage ] * [ CC-Time ] * [ CC-Money ] * [ CC-Total-Octets ] * [ CC-Input-Octets ] * [ CC-Output-Octets ] * [ CC-Service-Specific-Units ] * * [ Event-Charging-TimeStamp ] * * [ AVP ] */ static int parseGxUsedServiceUnit ( struct avp *avp, GxUsedServiceUnit *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Used-Service-Unit child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_reporting_reason)) { data->reporting_reason = hdr->avp_value->i32; data->presence.reporting_reason=1; } else if (IS_AVP(davp_tariff_change_usage)) { data->tariff_change_usage = hdr->avp_value->i32; data->presence.tariff_change_usage=1; } else if (IS_AVP(davp_cc_time)) { data->cc_time = hdr->avp_value->u32; data->presence.cc_time=1; } else if (IS_AVP(davp_cc_money)) { FDCHECK_PARSE_DIRECT(parseGxCcMoney, child_avp, &data->cc_money); data->presence.cc_money=1; } else if (IS_AVP(davp_cc_total_octets)) { data->cc_total_octets = hdr->avp_value->u64; data->presence.cc_total_octets=1; } else if (IS_AVP(davp_cc_input_octets)) { data->cc_input_octets = hdr->avp_value->u64; data->presence.cc_input_octets=1; } else if (IS_AVP(davp_cc_output_octets)) { data->cc_output_octets = hdr->avp_value->u64; data->presence.cc_output_octets=1; } else if (IS_AVP(davp_cc_service_specific_units)) { data->cc_service_specific_units = hdr->avp_value->u64; data->presence.cc_service_specific_units=1; } else if (IS_AVP(davp_event_charging_timestamp)) { data->event_charging_timestamp.count++; cnt++; data->presence.event_charging_timestamp=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->event_charging_timestamp, FdTime); /* iterate through the Used-Service-Unit child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_event_charging_timestamp)) { FD_PARSE_TIME(hdr->avp_value, data->event_charging_timestamp.list[data->event_charging_timestamp.count]); data->event_charging_timestamp.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxChargingRuleInstall * * Desc: Parse Charging-Rule-Install AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Charging-Rule-Install ::= <AVP Header: 1001> * * [ Charging-Rule-Definition ] * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * [ Bearer-Identifier ] * [ Monitoring-Flags ] * [ Rule-Activation-Time ] * [ Rule-Deactivation-Time ] * [ Resource-Allocation-Notification ] * [ Charging-Correlation-Indicator ] * [ IP-CAN-Type ] * * [ AVP ] */ static int parseGxChargingRuleInstall ( struct avp *avp, GxChargingRuleInstall *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Charging-Rule-Install child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_charging_rule_definition)) { data->charging_rule_definition.count++; cnt++; data->presence.charging_rule_definition=1; } else if (IS_AVP(davp_charging_rule_name)) { data->charging_rule_name.count++; cnt++; data->presence.charging_rule_name=1; } else if (IS_AVP(davp_charging_rule_base_name)) { data->charging_rule_base_name.count++; cnt++; data->presence.charging_rule_base_name=1; } else if (IS_AVP(davp_bearer_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->bearer_identifier, GX_BEARER_IDENTIFIER_LEN); data->presence.bearer_identifier=1; } else if (IS_AVP(davp_monitoring_flags)) { data->monitoring_flags = hdr->avp_value->u32; data->presence.monitoring_flags=1; } else if (IS_AVP(davp_rule_activation_time)) { FD_PARSE_TIME(hdr->avp_value, data->rule_activation_time); data->presence.rule_activation_time=1; } else if (IS_AVP(davp_rule_deactivation_time)) { FD_PARSE_TIME(hdr->avp_value, data->rule_deactivation_time); data->presence.rule_deactivation_time=1; } else if (IS_AVP(davp_resource_allocation_notification)) { data->resource_allocation_notification = hdr->avp_value->i32; data->presence.resource_allocation_notification=1; } else if (IS_AVP(davp_charging_correlation_indicator)) { data->charging_correlation_indicator = hdr->avp_value->i32; data->presence.charging_correlation_indicator=1; } else if (IS_AVP(davp_ip_can_type)) { data->ip_can_type = hdr->avp_value->i32; data->presence.ip_can_type=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->charging_rule_definition, GxChargingRuleDefinition); FD_ALLOC_LIST(data->charging_rule_name, GxChargingRuleNameOctetString); FD_ALLOC_LIST(data->charging_rule_base_name, GxChargingRuleBaseNameOctetString); /* iterate through the Charging-Rule-Install child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_charging_rule_definition)) { FDCHECK_PARSE_DIRECT(parseGxChargingRuleDefinition, child_avp, &data->charging_rule_definition.list[data->charging_rule_definition.count]); data->charging_rule_definition.count++; } else if (IS_AVP(davp_charging_rule_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->charging_rule_name.list[data->charging_rule_name.count], GX_CHARGING_RULE_NAME_LEN); data->charging_rule_name.count++; } else if (IS_AVP(davp_charging_rule_base_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->charging_rule_base_name.list[data->charging_rule_base_name.count], GX_CHARGING_RULE_BASE_NAME_LEN); data->charging_rule_base_name.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxChargingRuleDefinition * * Desc: Parse Charging-Rule-Definition AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Charging-Rule-Definition ::= <AVP Header: 1003> * { Charging-Rule-Name } * [ Service-Identifier ] * [ Rating-Group ] * * [ Flow-Information ] * [ Default-Bearer-Indication ] * [ TDF-Application-Identifier ] * [ Flow-Status ] * [ QoS-Information ] * [ PS-to-CS-Session-Continuity ] * [ Reporting-Level ] * [ Online ] * [ Offline ] * [ Max-PLR-DL ] * [ Max-PLR-UL ] * [ Metering-Method ] * [ Precedence ] * [ AF-Charging-Identifier ] * * [ Flows ] * [ Monitoring-Key ] * [ Redirect-Information ] * [ Mute-Notification ] * [ AF-Signalling-Protocol ] * [ Sponsor-Identity ] * [ Application-Service-Provider-Identity ] * * [ Required-Access-Info ] * [ Sharing-Key-DL ] * [ Sharing-Key-UL ] * [ Traffic-Steering-Policy-Identifier-DL ] * [ Traffic-Steering-Policy-Identifier-UL ] * [ Content-Version ] * * [ AVP ] */ static int parseGxChargingRuleDefinition ( struct avp *avp, GxChargingRuleDefinition *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Charging-Rule-Definition child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_charging_rule_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->charging_rule_name, GX_CHARGING_RULE_NAME_LEN); data->presence.charging_rule_name=1; } else if (IS_AVP(davp_service_identifier)) { data->service_identifier = hdr->avp_value->u32; data->presence.service_identifier=1; } else if (IS_AVP(davp_rating_group)) { data->rating_group = hdr->avp_value->u32; data->presence.rating_group=1; } else if (IS_AVP(davp_flow_information)) { data->flow_information.count++; cnt++; data->presence.flow_information=1; } else if (IS_AVP(davp_default_bearer_indication)) { data->default_bearer_indication = hdr->avp_value->i32; data->presence.default_bearer_indication=1; } else if (IS_AVP(davp_tdf_application_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tdf_application_identifier, GX_TDF_APPLICATION_IDENTIFIER_LEN); data->presence.tdf_application_identifier=1; } else if (IS_AVP(davp_flow_status)) { data->flow_status = hdr->avp_value->i32; data->presence.flow_status=1; } else if (IS_AVP(davp_qos_information)) { FDCHECK_PARSE_DIRECT(parseGxQosInformation, child_avp, &data->qos_information); data->presence.qos_information=1; } else if (IS_AVP(davp_ps_to_cs_session_continuity)) { data->ps_to_cs_session_continuity = hdr->avp_value->i32; data->presence.ps_to_cs_session_continuity=1; } else if (IS_AVP(davp_reporting_level)) { data->reporting_level = hdr->avp_value->i32; data->presence.reporting_level=1; } else if (IS_AVP(davp_online)) { data->online = hdr->avp_value->i32; data->presence.online=1; } else if (IS_AVP(davp_offline)) { data->offline = hdr->avp_value->i32; data->presence.offline=1; } else if (IS_AVP(davp_max_plr_dl)) { data->max_plr_dl = hdr->avp_value->f32; data->presence.max_plr_dl=1; } else if (IS_AVP(davp_max_plr_ul)) { data->max_plr_ul = hdr->avp_value->f32; data->presence.max_plr_ul=1; } else if (IS_AVP(davp_metering_method)) { data->metering_method = hdr->avp_value->i32; data->presence.metering_method=1; } else if (IS_AVP(davp_precedence)) { data->precedence = hdr->avp_value->u32; data->presence.precedence=1; } else if (IS_AVP(davp_af_charging_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->af_charging_identifier, GX_AF_CHARGING_IDENTIFIER_LEN); data->presence.af_charging_identifier=1; } else if (IS_AVP(davp_flows)) { data->flows.count++; cnt++; data->presence.flows=1; } else if (IS_AVP(davp_monitoring_key)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->monitoring_key, GX_MONITORING_KEY_LEN); data->presence.monitoring_key=1; } else if (IS_AVP(davp_redirect_information)) { FDCHECK_PARSE_DIRECT(parseGxRedirectInformation, child_avp, &data->redirect_information); data->presence.redirect_information=1; } else if (IS_AVP(davp_mute_notification)) { data->mute_notification = hdr->avp_value->i32; data->presence.mute_notification=1; } else if (IS_AVP(davp_af_signalling_protocol)) { data->af_signalling_protocol = hdr->avp_value->i32; data->presence.af_signalling_protocol=1; } else if (IS_AVP(davp_sponsor_identity)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->sponsor_identity, GX_SPONSOR_IDENTITY_LEN); data->presence.sponsor_identity=1; } else if (IS_AVP(davp_application_service_provider_identity)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->application_service_provider_identity, GX_APPLICATION_SERVICE_PROVIDER_IDENTITY_LEN); data->presence.application_service_provider_identity=1; } else if (IS_AVP(davp_required_access_info)) { data->required_access_info.count++; cnt++; data->presence.required_access_info=1; } else if (IS_AVP(davp_sharing_key_dl)) { data->sharing_key_dl = hdr->avp_value->u32; data->presence.sharing_key_dl=1; } else if (IS_AVP(davp_sharing_key_ul)) { data->sharing_key_ul = hdr->avp_value->u32; data->presence.sharing_key_ul=1; } else if (IS_AVP(davp_traffic_steering_policy_identifier_dl)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->traffic_steering_policy_identifier_dl, GX_TRAFFIC_STEERING_POLICY_IDENTIFIER_DL_LEN); data->presence.traffic_steering_policy_identifier_dl=1; } else if (IS_AVP(davp_traffic_steering_policy_identifier_ul)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->traffic_steering_policy_identifier_ul, GX_TRAFFIC_STEERING_POLICY_IDENTIFIER_UL_LEN); data->presence.traffic_steering_policy_identifier_ul=1; } else if (IS_AVP(davp_content_version)) { data->content_version = hdr->avp_value->u64; data->presence.content_version=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->flow_information, GxFlowInformation); FD_ALLOC_LIST(data->flows, GxFlows); FD_ALLOC_LIST(data->required_access_info, int32_t); /* iterate through the Charging-Rule-Definition child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_flow_information)) { FDCHECK_PARSE_DIRECT(parseGxFlowInformation, child_avp, &data->flow_information.list[data->flow_information.count]); data->flow_information.count++; } else if (IS_AVP(davp_flows)) { FDCHECK_PARSE_DIRECT(parseGxFlows, child_avp, &data->flows.list[data->flows.count]); data->flows.count++; } else if (IS_AVP(davp_required_access_info)) { data->required_access_info.list[data->required_access_info.count] = hdr->avp_value->i32; data->required_access_info.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxFinalUnitIndication * * Desc: Parse Final-Unit-Indication AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Final-Unit-Indication ::= <AVP Header: 430> * { Final-Unit-Action } * * [ Restriction-Filter-Rule ] * * [ Filter-Id ] * [ Redirect-Server ] */ static int parseGxFinalUnitIndication ( struct avp *avp, GxFinalUnitIndication *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Final-Unit-Indication child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_final_unit_action)) { data->final_unit_action = hdr->avp_value->i32; data->presence.final_unit_action=1; } else if (IS_AVP(davp_restriction_filter_rule)) { data->restriction_filter_rule.count++; cnt++; data->presence.restriction_filter_rule=1; } else if (IS_AVP(davp_filter_id)) { data->filter_id.count++; cnt++; data->presence.filter_id=1; } else if (IS_AVP(davp_redirect_server)) { FDCHECK_PARSE_DIRECT(parseGxRedirectServer, child_avp, &data->redirect_server); data->presence.redirect_server=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->restriction_filter_rule, GxRestrictionFilterRuleOctetString); FD_ALLOC_LIST(data->filter_id, GxFilterIdOctetString); /* iterate through the Final-Unit-Indication child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_restriction_filter_rule)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->restriction_filter_rule.list[data->restriction_filter_rule.count], GX_RESTRICTION_FILTER_RULE_LEN); data->restriction_filter_rule.count++; } else if (IS_AVP(davp_filter_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->filter_id.list[data->filter_id.count], GX_FILTER_ID_LEN); data->filter_id.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxUnitValue * * Desc: Parse Unit-Value AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Unit-Value ::= <AVP Header: 445> * { Value-Digits } * [ Exponent ] */ static int parseGxUnitValue ( struct avp *avp, GxUnitValue *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Unit-Value child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_value_digits)) { data->value_digits = hdr->avp_value->i64; data->presence.value_digits=1; } else if (IS_AVP(davp_exponent)) { data->exponent = hdr->avp_value->i32; data->presence.exponent=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Unit-Value child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxPresenceReportingAreaInformation * * Desc: Parse Presence-Reporting-Area-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Presence-Reporting-Area-Information ::= <AVP Header: 2822> * [ Presence-Reporting-Area-Identifier ] * [ Presence-Reporting-Area-Status ] * [ Presence-Reporting-Area-Elements-List ] * [ Presence-Reporting-Area-Node ] * * [ AVP ] */ static int parseGxPresenceReportingAreaInformation ( struct avp *avp, GxPresenceReportingAreaInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Presence-Reporting-Area-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_presence_reporting_area_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->presence_reporting_area_identifier, GX_PRESENCE_REPORTING_AREA_IDENTIFIER_LEN); data->presence.presence_reporting_area_identifier=1; } else if (IS_AVP(davp_presence_reporting_area_status)) { data->presence_reporting_area_status = hdr->avp_value->u32; data->presence.presence_reporting_area_status=1; } else if (IS_AVP(davp_presence_reporting_area_elements_list)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->presence_reporting_area_elements_list, GX_PRESENCE_REPORTING_AREA_ELEMENTS_LIST_LEN); data->presence.presence_reporting_area_elements_list=1; } else if (IS_AVP(davp_presence_reporting_area_node)) { data->presence_reporting_area_node = hdr->avp_value->u32; data->presence.presence_reporting_area_node=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Presence-Reporting-Area-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxConditionalApnAggregateMaxBitrate * * Desc: Parse Conditional-APN-Aggregate-Max-Bitrate AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Conditional-APN-Aggregate-Max-Bitrate ::= <AVP Header: 2818> * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ IP-CAN-Type ] * * [ RAT-Type ] * * [ AVP ] */ static int parseGxConditionalApnAggregateMaxBitrate ( struct avp *avp, GxConditionalApnAggregateMaxBitrate *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Conditional-APN-Aggregate-Max-Bitrate child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_apn_aggregate_max_bitrate_ul)) { data->apn_aggregate_max_bitrate_ul = hdr->avp_value->u32; data->presence.apn_aggregate_max_bitrate_ul=1; } else if (IS_AVP(davp_apn_aggregate_max_bitrate_dl)) { data->apn_aggregate_max_bitrate_dl = hdr->avp_value->u32; data->presence.apn_aggregate_max_bitrate_dl=1; } else if (IS_AVP(davp_extended_apn_ambr_ul)) { data->extended_apn_ambr_ul = hdr->avp_value->u32; data->presence.extended_apn_ambr_ul=1; } else if (IS_AVP(davp_extended_apn_ambr_dl)) { data->extended_apn_ambr_dl = hdr->avp_value->u32; data->presence.extended_apn_ambr_dl=1; } else if (IS_AVP(davp_ip_can_type)) { data->ip_can_type.count++; cnt++; data->presence.ip_can_type=1; } else if (IS_AVP(davp_rat_type)) { data->rat_type.count++; cnt++; data->presence.rat_type=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->ip_can_type, int32_t); FD_ALLOC_LIST(data->rat_type, int32_t); /* iterate through the Conditional-APN-Aggregate-Max-Bitrate child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_ip_can_type)) { data->ip_can_type.list[data->ip_can_type.count] = hdr->avp_value->i32; data->ip_can_type.count++; } else if (IS_AVP(davp_rat_type)) { data->rat_type.list[data->rat_type.count] = hdr->avp_value->i32; data->rat_type.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxAccessNetworkChargingIdentifierGx * * Desc: Parse Access-Network-Charging-Identifier-Gx AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Access-Network-Charging-Identifier-Gx ::= <AVP Header: 1022> * { Access-Network-Charging-Identifier-Value } * * [ Charging-Rule-Base-Name ] * * [ Charging-Rule-Name ] * [ IP-CAN-Session-Charging-Scope ] * * [ AVP ] */ static int parseGxAccessNetworkChargingIdentifierGx ( struct avp *avp, GxAccessNetworkChargingIdentifierGx *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Access-Network-Charging-Identifier-Gx child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_access_network_charging_identifier_value)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->access_network_charging_identifier_value, GX_ACCESS_NETWORK_CHARGING_IDENTIFIER_VALUE_LEN); data->presence.access_network_charging_identifier_value=1; } else if (IS_AVP(davp_charging_rule_base_name)) { data->charging_rule_base_name.count++; cnt++; data->presence.charging_rule_base_name=1; } else if (IS_AVP(davp_charging_rule_name)) { data->charging_rule_name.count++; cnt++; data->presence.charging_rule_name=1; } else if (IS_AVP(davp_ip_can_session_charging_scope)) { data->ip_can_session_charging_scope = hdr->avp_value->i32; data->presence.ip_can_session_charging_scope=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->charging_rule_base_name, GxChargingRuleBaseNameOctetString); FD_ALLOC_LIST(data->charging_rule_name, GxChargingRuleNameOctetString); /* iterate through the Access-Network-Charging-Identifier-Gx child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_charging_rule_base_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->charging_rule_base_name.list[data->charging_rule_base_name.count], GX_CHARGING_RULE_BASE_NAME_LEN); data->charging_rule_base_name.count++; } else if (IS_AVP(davp_charging_rule_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->charging_rule_name.list[data->charging_rule_name.count], GX_CHARGING_RULE_NAME_LEN); data->charging_rule_name.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxOcOlr * * Desc: Parse OC-OLR AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * OC-OLR ::= <AVP Header: 623> * < OC-Sequence-Number > * < OC-Report-Type > * [ OC-Reduction-Percentage ] * [ OC-Validity-Duration ] * * [ AVP ] */ static int parseGxOcOlr ( struct avp *avp, GxOcOlr *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the OC-OLR child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_oc_sequence_number)) { data->oc_sequence_number = hdr->avp_value->u64; data->presence.oc_sequence_number=1; } else if (IS_AVP(davp_oc_report_type)) { data->oc_report_type = hdr->avp_value->i32; data->presence.oc_report_type=1; } else if (IS_AVP(davp_oc_reduction_percentage)) { data->oc_reduction_percentage = hdr->avp_value->u32; data->presence.oc_reduction_percentage=1; } else if (IS_AVP(davp_oc_validity_duration)) { data->oc_validity_duration = hdr->avp_value->u32; data->presence.oc_validity_duration=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the OC-OLR child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxRoutingRuleInstall * * Desc: Parse Routing-Rule-Install AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Routing-Rule-Install ::= <AVP Header: 1081> * * [ Routing-Rule-Definition ] * * [ AVP ] */ static int parseGxRoutingRuleInstall ( struct avp *avp, GxRoutingRuleInstall *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Routing-Rule-Install child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_routing_rule_definition)) { data->routing_rule_definition.count++; cnt++; data->presence.routing_rule_definition=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->routing_rule_definition, GxRoutingRuleDefinition); /* iterate through the Routing-Rule-Install child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_routing_rule_definition)) { FDCHECK_PARSE_DIRECT(parseGxRoutingRuleDefinition, child_avp, &data->routing_rule_definition.list[data->routing_rule_definition.count]); data->routing_rule_definition.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxTraceData * * Desc: Parse Trace-Data AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Trace-Data ::= <AVP Header: 1458> * { Trace-Reference } * { Trace-Depth } * { Trace-NE-Type-List } * [ Trace-Interface-List ] * { Trace-Event-List } * [ OMC-Id ] * { Trace-Collection-Entity } * [ MDT-Configuration ] * * [ AVP ] */ static int parseGxTraceData ( struct avp *avp, GxTraceData *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Trace-Data child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_trace_reference)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->trace_reference, GX_TRACE_REFERENCE_LEN); data->presence.trace_reference=1; } else if (IS_AVP(davp_trace_depth)) { data->trace_depth = hdr->avp_value->i32; data->presence.trace_depth=1; } else if (IS_AVP(davp_trace_ne_type_list)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->trace_ne_type_list, GX_TRACE_NE_TYPE_LIST_LEN); data->presence.trace_ne_type_list=1; } else if (IS_AVP(davp_trace_interface_list)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->trace_interface_list, GX_TRACE_INTERFACE_LIST_LEN); data->presence.trace_interface_list=1; } else if (IS_AVP(davp_trace_event_list)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->trace_event_list, GX_TRACE_EVENT_LIST_LEN); data->presence.trace_event_list=1; } else if (IS_AVP(davp_omc_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->omc_id, GX_OMC_ID_LEN); data->presence.omc_id=1; } else if (IS_AVP(davp_trace_collection_entity)) { FD_PARSE_ADDRESS(hdr->avp_value, data->trace_collection_entity); data->presence.trace_collection_entity=1; } else if (IS_AVP(davp_mdt_configuration)) { FDCHECK_PARSE_DIRECT(parseGxMdtConfiguration, child_avp, &data->mdt_configuration); data->presence.mdt_configuration=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Trace-Data child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxRoutingRuleDefinition * * Desc: Parse Routing-Rule-Definition AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Routing-Rule-Definition ::= <AVP Header: 1076> * { Routing-Rule-Identifier } * * [ Routing-Filter ] * [ Precedence ] * [ Routing-IP-Address ] * [ IP-CAN-Type ] * * [ AVP ] */ static int parseGxRoutingRuleDefinition ( struct avp *avp, GxRoutingRuleDefinition *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Routing-Rule-Definition child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_routing_rule_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->routing_rule_identifier, GX_ROUTING_RULE_IDENTIFIER_LEN); data->presence.routing_rule_identifier=1; } else if (IS_AVP(davp_routing_filter)) { data->routing_filter.count++; cnt++; data->presence.routing_filter=1; } else if (IS_AVP(davp_precedence)) { data->precedence = hdr->avp_value->u32; data->presence.precedence=1; } else if (IS_AVP(davp_routing_ip_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->routing_ip_address); data->presence.routing_ip_address=1; } else if (IS_AVP(davp_ip_can_type)) { data->ip_can_type = hdr->avp_value->i32; data->presence.ip_can_type=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->routing_filter, GxRoutingFilter); /* iterate through the Routing-Rule-Definition child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_routing_filter)) { FDCHECK_PARSE_DIRECT(parseGxRoutingFilter, child_avp, &data->routing_filter.list[data->routing_filter.count]); data->routing_filter.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxMdtConfiguration * * Desc: Parse MDT-Configuration AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * MDT-Configuration ::= <AVP Header: 1622> * { Job-Type } * [ Area-Scope ] * [ List-Of-Measurements ] * [ Reporting-Trigger ] * [ Report-Interval ] * [ Report-Amount ] * [ Event-Threshold-RSRP ] * [ Event-Threshold-RSRQ ] * [ Logging-Interval ] * [ Logging-Duration ] * [ Measurement-Period-LTE ] * [ Measurement-Period-UMTS ] * [ Collection-Period-RRM-LTE ] * [ Collection-Period-RRM-UMTS ] * [ Positioning-Method ] * [ Measurement-Quantity ] * [ Event-Threshold-Event-1F ] * [ Event-Threshold-Event-1I ] * * [ MDT-Allowed-PLMN-Id ] * * [ MBSFN-Area ] * * [ AVP ] */ static int parseGxMdtConfiguration ( struct avp *avp, GxMdtConfiguration *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the MDT-Configuration child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_job_type)) { data->job_type = hdr->avp_value->i32; data->presence.job_type=1; } else if (IS_AVP(davp_area_scope)) { FDCHECK_PARSE_DIRECT(parseGxAreaScope, child_avp, &data->area_scope); data->presence.area_scope=1; } else if (IS_AVP(davp_list_of_measurements)) { data->list_of_measurements = hdr->avp_value->u32; data->presence.list_of_measurements=1; } else if (IS_AVP(davp_reporting_trigger)) { data->reporting_trigger = hdr->avp_value->u32; data->presence.reporting_trigger=1; } else if (IS_AVP(davp_report_interval)) { data->report_interval = hdr->avp_value->i32; data->presence.report_interval=1; } else if (IS_AVP(davp_report_amount)) { data->report_amount = hdr->avp_value->i32; data->presence.report_amount=1; } else if (IS_AVP(davp_event_threshold_rsrp)) { data->event_threshold_rsrp = hdr->avp_value->u32; data->presence.event_threshold_rsrp=1; } else if (IS_AVP(davp_event_threshold_rsrq)) { data->event_threshold_rsrq = hdr->avp_value->u32; data->presence.event_threshold_rsrq=1; } else if (IS_AVP(davp_logging_interval)) { data->logging_interval = hdr->avp_value->i32; data->presence.logging_interval=1; } else if (IS_AVP(davp_logging_duration)) { data->logging_duration = hdr->avp_value->i32; data->presence.logging_duration=1; } else if (IS_AVP(davp_measurement_period_lte)) { data->measurement_period_lte = hdr->avp_value->i32; data->presence.measurement_period_lte=1; } else if (IS_AVP(davp_measurement_period_umts)) { data->measurement_period_umts = hdr->avp_value->i32; data->presence.measurement_period_umts=1; } else if (IS_AVP(davp_collection_period_rrm_lte)) { data->collection_period_rrm_lte = hdr->avp_value->i32; data->presence.collection_period_rrm_lte=1; } else if (IS_AVP(davp_collection_period_rrm_umts)) { data->collection_period_rrm_umts = hdr->avp_value->i32; data->presence.collection_period_rrm_umts=1; } else if (IS_AVP(davp_positioning_method)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->positioning_method, GX_POSITIONING_METHOD_LEN); data->presence.positioning_method=1; } else if (IS_AVP(davp_measurement_quantity)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->measurement_quantity, GX_MEASUREMENT_QUANTITY_LEN); data->presence.measurement_quantity=1; } else if (IS_AVP(davp_event_threshold_event_1f)) { data->event_threshold_event_1f = hdr->avp_value->i32; data->presence.event_threshold_event_1f=1; } else if (IS_AVP(davp_event_threshold_event_1i)) { data->event_threshold_event_1i = hdr->avp_value->i32; data->presence.event_threshold_event_1i=1; } else if (IS_AVP(davp_mdt_allowed_plmn_id)) { data->mdt_allowed_plmn_id.count++; cnt++; data->presence.mdt_allowed_plmn_id=1; } else if (IS_AVP(davp_mbsfn_area)) { data->mbsfn_area.count++; cnt++; data->presence.mbsfn_area=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->mdt_allowed_plmn_id, GxMdtAllowedPlmnIdOctetString); FD_ALLOC_LIST(data->mbsfn_area, GxMbsfnArea); /* iterate through the MDT-Configuration child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_mdt_allowed_plmn_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->mdt_allowed_plmn_id.list[data->mdt_allowed_plmn_id.count], GX_MDT_ALLOWED_PLMN_ID_LEN); data->mdt_allowed_plmn_id.count++; } else if (IS_AVP(davp_mbsfn_area)) { FDCHECK_PARSE_DIRECT(parseGxMbsfnArea, child_avp, &data->mbsfn_area.list[data->mbsfn_area.count]); data->mbsfn_area.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxChargingRuleRemove * * Desc: Parse Charging-Rule-Remove AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Charging-Rule-Remove ::= <AVP Header: 1002> * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * * [ Required-Access-Info ] * [ Resource-Release-Notification ] * * [ AVP ] */ static int parseGxChargingRuleRemove ( struct avp *avp, GxChargingRuleRemove *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Charging-Rule-Remove child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_charging_rule_name)) { data->charging_rule_name.count++; cnt++; data->presence.charging_rule_name=1; } else if (IS_AVP(davp_charging_rule_base_name)) { data->charging_rule_base_name.count++; cnt++; data->presence.charging_rule_base_name=1; } else if (IS_AVP(davp_required_access_info)) { data->required_access_info.count++; cnt++; data->presence.required_access_info=1; } else if (IS_AVP(davp_resource_release_notification)) { data->resource_release_notification = hdr->avp_value->i32; data->presence.resource_release_notification=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->charging_rule_name, GxChargingRuleNameOctetString); FD_ALLOC_LIST(data->charging_rule_base_name, GxChargingRuleBaseNameOctetString); FD_ALLOC_LIST(data->required_access_info, int32_t); /* iterate through the Charging-Rule-Remove child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_charging_rule_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->charging_rule_name.list[data->charging_rule_name.count], GX_CHARGING_RULE_NAME_LEN); data->charging_rule_name.count++; } else if (IS_AVP(davp_charging_rule_base_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->charging_rule_base_name.list[data->charging_rule_base_name.count], GX_CHARGING_RULE_BASE_NAME_LEN); data->charging_rule_base_name.count++; } else if (IS_AVP(davp_required_access_info)) { data->required_access_info.list[data->required_access_info.count] = hdr->avp_value->i32; data->required_access_info.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxAllocationRetentionPriority * * Desc: Parse Allocation-Retention-Priority AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Allocation-Retention-Priority ::= <AVP Header: 1034> * { Priority-Level } * [ Pre-emption-Capability ] * [ Pre-emption-Vulnerability ] */ static int parseGxAllocationRetentionPriority ( struct avp *avp, GxAllocationRetentionPriority *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Allocation-Retention-Priority child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_priority_level)) { data->priority_level = hdr->avp_value->u32; data->presence.priority_level=1; } else if (IS_AVP(davp_pre_emption_capability)) { data->pre_emption_capability = hdr->avp_value->i32; data->presence.pre_emption_capability=1; } else if (IS_AVP(davp_pre_emption_vulnerability)) { data->pre_emption_vulnerability = hdr->avp_value->i32; data->presence.pre_emption_vulnerability=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Allocation-Retention-Priority child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxDefaultEpsBearerQos * * Desc: Parse Default-EPS-Bearer-QoS AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Default-EPS-Bearer-QoS ::= <AVP Header: 1049> * [ QoS-Class-Identifier ] * [ Allocation-Retention-Priority ] * * [ AVP ] */ static int parseGxDefaultEpsBearerQos ( struct avp *avp, GxDefaultEpsBearerQos *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Default-EPS-Bearer-QoS child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_qos_class_identifier)) { data->qos_class_identifier = hdr->avp_value->i32; data->presence.qos_class_identifier=1; } else if (IS_AVP(davp_allocation_retention_priority)) { FDCHECK_PARSE_DIRECT(parseGxAllocationRetentionPriority, child_avp, &data->allocation_retention_priority); data->presence.allocation_retention_priority=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Default-EPS-Bearer-QoS child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxRoutingRuleReport * * Desc: Parse Routing-Rule-Report AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Routing-Rule-Report ::= <AVP Header: 2835> * * [ Routing-Rule-Identifier ] * [ PCC-Rule-Status ] * [ Routing-Rule-Failure-Code ] * * [ AVP ] */ static int parseGxRoutingRuleReport ( struct avp *avp, GxRoutingRuleReport *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Routing-Rule-Report child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_routing_rule_identifier)) { data->routing_rule_identifier.count++; cnt++; data->presence.routing_rule_identifier=1; } else if (IS_AVP(davp_pcc_rule_status)) { data->pcc_rule_status = hdr->avp_value->i32; data->presence.pcc_rule_status=1; } else if (IS_AVP(davp_routing_rule_failure_code)) { data->routing_rule_failure_code = hdr->avp_value->u32; data->presence.routing_rule_failure_code=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->routing_rule_identifier, GxRoutingRuleIdentifierOctetString); /* iterate through the Routing-Rule-Report child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_routing_rule_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->routing_rule_identifier.list[data->routing_rule_identifier.count], GX_ROUTING_RULE_IDENTIFIER_LEN); data->routing_rule_identifier.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxUserEquipmentInfo * * Desc: Parse User-Equipment-Info AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * User-Equipment-Info ::= <AVP Header: 458> * { User-Equipment-Info-Type } * { User-Equipment-Info-Value } */ static int parseGxUserEquipmentInfo ( struct avp *avp, GxUserEquipmentInfo *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the User-Equipment-Info child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_user_equipment_info_type)) { data->user_equipment_info_type = hdr->avp_value->i32; data->presence.user_equipment_info_type=1; } else if (IS_AVP(davp_user_equipment_info_value)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->user_equipment_info_value, GX_USER_EQUIPMENT_INFO_VALUE_LEN); data->presence.user_equipment_info_value=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the User-Equipment-Info child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxSupportedFeatures * * Desc: Parse Supported-Features AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Supported-Features ::= <AVP Header: 628> * { Vendor-Id } * { Feature-List-ID } * { Feature-List } * * [ AVP ] */ static int parseGxSupportedFeatures ( struct avp *avp, GxSupportedFeatures *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Supported-Features child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_vendor_id)) { data->vendor_id = hdr->avp_value->u32; data->presence.vendor_id=1; } else if (IS_AVP(davp_feature_list_id)) { data->feature_list_id = hdr->avp_value->u32; data->presence.feature_list_id=1; } else if (IS_AVP(davp_feature_list)) { data->feature_list = hdr->avp_value->u32; data->presence.feature_list=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Supported-Features child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxFixedUserLocationInfo * * Desc: Parse Fixed-User-Location-Info AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Fixed-User-Location-Info ::= <AVP Header: 2825> * [ SSID ] * [ BSSID ] * [ Logical-Access-Id ] * [ Physical-Access-Id ] * * [ AVP ] */ static int parseGxFixedUserLocationInfo ( struct avp *avp, GxFixedUserLocationInfo *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Fixed-User-Location-Info child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_ssid)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->ssid, GX_SSID_LEN); data->presence.ssid=1; } else if (IS_AVP(davp_bssid)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->bssid, GX_BSSID_LEN); data->presence.bssid=1; } else if (IS_AVP(davp_logical_access_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->logical_access_id, GX_LOGICAL_ACCESS_ID_LEN); data->presence.logical_access_id=1; } else if (IS_AVP(davp_physical_access_id)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->physical_access_id, GX_PHYSICAL_ACCESS_ID_LEN); data->presence.physical_access_id=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Fixed-User-Location-Info child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxDefaultQosInformation * * Desc: Parse Default-QoS-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Default-QoS-Information ::= <AVP Header: 2816> * [ QoS-Class-Identifier ] * [ Max-Requested-Bandwidth-UL ] * [ Max-Requested-Bandwidth-DL ] * [ Default-QoS-Name ] * * [ AVP ] */ static int parseGxDefaultQosInformation ( struct avp *avp, GxDefaultQosInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Default-QoS-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_qos_class_identifier)) { data->qos_class_identifier = hdr->avp_value->i32; data->presence.qos_class_identifier=1; } else if (IS_AVP(davp_max_requested_bandwidth_ul)) { data->max_requested_bandwidth_ul = hdr->avp_value->u32; data->presence.max_requested_bandwidth_ul=1; } else if (IS_AVP(davp_max_requested_bandwidth_dl)) { data->max_requested_bandwidth_dl = hdr->avp_value->u32; data->presence.max_requested_bandwidth_dl=1; } else if (IS_AVP(davp_default_qos_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->default_qos_name, GX_DEFAULT_QOS_NAME_LEN); data->presence.default_qos_name=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Default-QoS-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxLoad * * Desc: Parse Load AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Load ::= <AVP Header: 650> * [ Load-Type ] * [ Load-Value ] * [ SourceID ] * * [ AVP ] */ static int parseGxLoad ( struct avp *avp, GxLoad *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Load child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_load_type)) { data->load_type = hdr->avp_value->i32; data->presence.load_type=1; } else if (IS_AVP(davp_load_value)) { data->load_value = hdr->avp_value->u64; data->presence.load_value=1; } else if (IS_AVP(davp_sourceid)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->sourceid, GX_SOURCEID_LEN); data->presence.sourceid=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Load child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxRedirectServer * * Desc: Parse Redirect-Server AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Redirect-Server ::= <AVP Header: 434> * { Redirect-Address-Type } * { Redirect-Server-Address } */ static int parseGxRedirectServer ( struct avp *avp, GxRedirectServer *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Redirect-Server child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_redirect_address_type)) { data->redirect_address_type = hdr->avp_value->i32; data->presence.redirect_address_type=1; } else if (IS_AVP(davp_redirect_server_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->redirect_server_address, GX_REDIRECT_SERVER_ADDRESS_LEN); data->presence.redirect_server_address=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Redirect-Server child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxOcSupportedFeatures * * Desc: Parse OC-Supported-Features AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * OC-Supported-Features ::= <AVP Header: 621> * [ OC-Feature-Vector ] * * [ AVP ] */ static int parseGxOcSupportedFeatures ( struct avp *avp, GxOcSupportedFeatures *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the OC-Supported-Features child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_oc_feature_vector)) { data->oc_feature_vector = hdr->avp_value->u64; data->presence.oc_feature_vector=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the OC-Supported-Features child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxPacketFilterInformation * * Desc: Parse Packet-Filter-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Packet-Filter-Information ::= <AVP Header: 1061> * [ Packet-Filter-Identifier ] * [ Precedence ] * [ Packet-Filter-Content ] * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * [ Flow-Direction ] * * [ AVP ] */ static int parseGxPacketFilterInformation ( struct avp *avp, GxPacketFilterInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Packet-Filter-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_packet_filter_identifier)) {FD_PARSE_OCTETSTRING(hdr->avp_value, data->packet_filter_identifier, GX_PACKET_FILTER_IDENTIFIER_LEN); data->presence.packet_filter_identifier=1; } else if (IS_AVP(davp_precedence)) { data->precedence = hdr->avp_value->u32; data->presence.precedence=1; } else if (IS_AVP(davp_packet_filter_content)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->packet_filter_content, GX_PACKET_FILTER_CONTENT_LEN); data->presence.packet_filter_content=1; } else if (IS_AVP(davp_tos_traffic_class)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tos_traffic_class, GX_TOS_TRAFFIC_CLASS_LEN); data->presence.tos_traffic_class=1; } else if (IS_AVP(davp_security_parameter_index)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->security_parameter_index, GX_SECURITY_PARAMETER_INDEX_LEN); data->presence.security_parameter_index=1; } else if (IS_AVP(davp_flow_label)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->flow_label, GX_FLOW_LABEL_LEN); data->presence.flow_label=1; } else if (IS_AVP(davp_flow_direction)) { data->flow_direction = hdr->avp_value->i32; data->presence.flow_direction=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Packet-Filter-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxSubscriptionId * * Desc: Parse Subscription-Id AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Subscription-Id ::= <AVP Header: 443> * [ Subscription-Id-Type ] * [ Subscription-Id-Data ] */ static int parseGxSubscriptionId ( struct avp *avp, GxSubscriptionId *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Subscription-Id child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_subscription_id_type)) { data->subscription_id_type = hdr->avp_value->i32; data->presence.subscription_id_type=1; } else if (IS_AVP(davp_subscription_id_data)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->subscription_id_data, GX_SUBSCRIPTION_ID_DATA_LEN); data->presence.subscription_id_data=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Subscription-Id child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxChargingInformation * * Desc: Parse Charging-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Charging-Information ::= <AVP Header: 618> * [ Primary-Event-Charging-Function-Name ] * [ Secondary-Event-Charging-Function-Name ] * [ Primary-Charging-Collection-Function-Name ] * [ Secondary-Charging-Collection-Function-Name ] * * [ AVP ] */ static int parseGxChargingInformation ( struct avp *avp, GxChargingInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Charging-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_primary_event_charging_function_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->primary_event_charging_function_name, GX_PRIMARY_EVENT_CHARGING_FUNCTION_NAME_LEN); data->presence.primary_event_charging_function_name=1; } else if (IS_AVP(davp_secondary_event_charging_function_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->secondary_event_charging_function_name, GX_SECONDARY_EVENT_CHARGING_FUNCTION_NAME_LEN); data->presence.secondary_event_charging_function_name=1; } else if (IS_AVP(davp_primary_charging_collection_function_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->primary_charging_collection_function_name, GX_PRIMARY_CHARGING_COLLECTION_FUNCTION_NAME_LEN); data->presence.primary_charging_collection_function_name=1; } else if (IS_AVP(davp_secondary_charging_collection_function_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->secondary_charging_collection_function_name, GX_SECONDARY_CHARGING_COLLECTION_FUNCTION_NAME_LEN); data->presence.secondary_charging_collection_function_name=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Charging-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxUsageMonitoringInformation * * Desc: Parse Usage-Monitoring-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Usage-Monitoring-Information ::= <AVP Header: 1067> * [ Monitoring-Key ] * * 2 [ Granted-Service-Unit ] * * 2 [ Used-Service-Unit ] * [ Quota-Consumption-Time ] * [ Usage-Monitoring-Level ] * [ Usage-Monitoring-Report ] * [ Usage-Monitoring-Support ] * * [ AVP ] */ static int parseGxUsageMonitoringInformation ( struct avp *avp, GxUsageMonitoringInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Usage-Monitoring-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_monitoring_key)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->monitoring_key, GX_MONITORING_KEY_LEN); data->presence.monitoring_key=1; } else if (IS_AVP(davp_granted_service_unit)) { data->granted_service_unit.count++; cnt++; data->presence.granted_service_unit=1; } else if (IS_AVP(davp_used_service_unit)) { data->used_service_unit.count++; cnt++; data->presence.used_service_unit=1; } else if (IS_AVP(davp_quota_consumption_time)) { data->quota_consumption_time = hdr->avp_value->u32; data->presence.quota_consumption_time=1; } else if (IS_AVP(davp_usage_monitoring_level)) { data->usage_monitoring_level = hdr->avp_value->i32; data->presence.usage_monitoring_level=1; } else if (IS_AVP(davp_usage_monitoring_report)) { data->usage_monitoring_report = hdr->avp_value->i32; data->presence.usage_monitoring_report=1; } else if (IS_AVP(davp_usage_monitoring_support)) { data->usage_monitoring_support = hdr->avp_value->i32; data->presence.usage_monitoring_support=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->granted_service_unit, GxGrantedServiceUnit); FD_ALLOC_LIST(data->used_service_unit, GxUsedServiceUnit); /* iterate through the Usage-Monitoring-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_granted_service_unit)) { FDCHECK_PARSE_DIRECT(parseGxGrantedServiceUnit, child_avp, &data->granted_service_unit.list[data->granted_service_unit.count]); data->granted_service_unit.count++; } else if (IS_AVP(davp_used_service_unit)) { FDCHECK_PARSE_DIRECT(parseGxUsedServiceUnit, child_avp, &data->used_service_unit.list[data->used_service_unit.count]); data->used_service_unit.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxChargingRuleReport * * Desc: Parse Charging-Rule-Report AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Charging-Rule-Report ::= <AVP Header: 1018> * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * [ Bearer-Identifier ] * [ PCC-Rule-Status ] * [ Rule-Failure-Code ] * [ Final-Unit-Indication ] * * [ RAN-NAS-Release-Cause ] * * [ Content-Version ] * * [ AVP ] */ static int parseGxChargingRuleReport ( struct avp *avp, GxChargingRuleReport *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Charging-Rule-Report child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_charging_rule_name)) { data->charging_rule_name.count++; cnt++; data->presence.charging_rule_name=1; } else if (IS_AVP(davp_charging_rule_base_name)) { data->charging_rule_base_name.count++; cnt++; data->presence.charging_rule_base_name=1; } else if (IS_AVP(davp_bearer_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->bearer_identifier, GX_BEARER_IDENTIFIER_LEN); data->presence.bearer_identifier=1; } else if (IS_AVP(davp_pcc_rule_status)) { data->pcc_rule_status = hdr->avp_value->i32; data->presence.pcc_rule_status=1; } else if (IS_AVP(davp_rule_failure_code)) { data->rule_failure_code = hdr->avp_value->i32; data->presence.rule_failure_code=1; } else if (IS_AVP(davp_final_unit_indication)) { FDCHECK_PARSE_DIRECT(parseGxFinalUnitIndication, child_avp, &data->final_unit_indication); data->presence.final_unit_indication=1; } else if (IS_AVP(davp_ran_nas_release_cause)) { data->ran_nas_release_cause.count++; cnt++; data->presence.ran_nas_release_cause=1; } else if (IS_AVP(davp_content_version)) { data->content_version.count++; cnt++; data->presence.content_version=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->charging_rule_name, GxChargingRuleNameOctetString); FD_ALLOC_LIST(data->charging_rule_base_name, GxChargingRuleBaseNameOctetString); FD_ALLOC_LIST(data->ran_nas_release_cause, GxRanNasReleaseCauseOctetString); FD_ALLOC_LIST(data->content_version, uint64_t); /* iterate through the Charging-Rule-Report child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_charging_rule_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->charging_rule_name.list[data->charging_rule_name.count], GX_CHARGING_RULE_NAME_LEN); data->charging_rule_name.count++; } else if (IS_AVP(davp_charging_rule_base_name)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->charging_rule_base_name.list[data->charging_rule_base_name.count], GX_CHARGING_RULE_BASE_NAME_LEN); data->charging_rule_base_name.count++; } else if (IS_AVP(davp_ran_nas_release_cause)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->ran_nas_release_cause.list[data->ran_nas_release_cause.count], GX_RAN_NAS_RELEASE_CAUSE_LEN); data->ran_nas_release_cause.count++; } else if (IS_AVP(davp_content_version)) { data->content_version.list[data->content_version.count] = hdr->avp_value->u64; data->content_version.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxRedirectInformation * * Desc: Parse Redirect-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Redirect-Information ::= <AVP Header: 1085> * [ Redirect-Support ] * [ Redirect-Address-Type ] * [ Redirect-Server-Address ] * * [ AVP ] */ static int parseGxRedirectInformation ( struct avp *avp, GxRedirectInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Redirect-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_redirect_support)) { data->redirect_support = hdr->avp_value->i32; data->presence.redirect_support=1; } else if (IS_AVP(davp_redirect_address_type)) { data->redirect_address_type = hdr->avp_value->i32; data->presence.redirect_address_type=1; } else if (IS_AVP(davp_redirect_server_address)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->redirect_server_address, GX_REDIRECT_SERVER_ADDRESS_LEN); data->presence.redirect_server_address=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Redirect-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxFailedAvp * * Desc: Parse Failed-AVP AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Failed-AVP ::= <AVP Header: 279> * 1* { AVP } */ static int parseGxFailedAvp ( struct avp *avp, GxFailedAvp *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Failed-AVP child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // TODO - To be implemented by developer as this a *[AVP] only Grouped AVP /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Failed-AVP child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxRoutingRuleRemove * * Desc: Parse Routing-Rule-Remove AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Routing-Rule-Remove ::= <AVP Header: 1075> * * [ Routing-Rule-Identifier ] * * [ AVP ] */ static int parseGxRoutingRuleRemove ( struct avp *avp, GxRoutingRuleRemove *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Routing-Rule-Remove child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_routing_rule_identifier)) { data->routing_rule_identifier.count++; cnt++; data->presence.routing_rule_identifier=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->routing_rule_identifier, GxRoutingRuleIdentifierOctetString); /* iterate through the Routing-Rule-Remove child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_routing_rule_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->routing_rule_identifier.list[data->routing_rule_identifier.count], GX_ROUTING_RULE_IDENTIFIER_LEN); data->routing_rule_identifier.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxRoutingFilter * * Desc: Parse Routing-Filter AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Routing-Filter ::= <AVP Header: 1078> * { Flow-Description } * { Flow-Direction } * [ ToS-Traffic-Class ] * [ Security-Parameter-Index ] * [ Flow-Label ] * * [ AVP ] */ static int parseGxRoutingFilter ( struct avp *avp, GxRoutingFilter *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Routing-Filter child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_flow_description)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->flow_description, GX_FLOW_DESCRIPTION_LEN); data->presence.flow_description=1; } else if (IS_AVP(davp_flow_direction)) { data->flow_direction = hdr->avp_value->i32; data->presence.flow_direction=1; } else if (IS_AVP(davp_tos_traffic_class)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tos_traffic_class, GX_TOS_TRAFFIC_CLASS_LEN); data->presence.tos_traffic_class=1; } else if (IS_AVP(davp_security_parameter_index)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->security_parameter_index, GX_SECURITY_PARAMETER_INDEX_LEN); data->presence.security_parameter_index=1; } else if (IS_AVP(davp_flow_label)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->flow_label, GX_FLOW_LABEL_LEN); data->presence.flow_label=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Routing-Filter child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxCoaInformation * * Desc: Parse CoA-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * CoA-Information ::= <AVP Header: 1039> * { Tunnel-Information } * { CoA-IP-Address } * * [ AVP ] */ static int parseGxCoaInformation ( struct avp *avp, GxCoaInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the CoA-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_tunnel_information)) { FDCHECK_PARSE_DIRECT(parseGxTunnelInformation, child_avp, &data->tunnel_information); data->presence.tunnel_information=1; } else if (IS_AVP(davp_coa_ip_address)) { FD_PARSE_ADDRESS(hdr->avp_value, data->coa_ip_address); data->presence.coa_ip_address=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the CoA-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxGrantedServiceUnit * * Desc: Parse Granted-Service-Unit AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Granted-Service-Unit ::= <AVP Header: 431> * [ Tariff-Time-Change ] * [ CC-Time ] * [ CC-Money ] * [ CC-Total-Octets ] * [ CC-Input-Octets ] * [ CC-Output-Octets ] * [ CC-Service-Specific-Units ] * * [ AVP ] */ static int parseGxGrantedServiceUnit ( struct avp *avp, GxGrantedServiceUnit *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Granted-Service-Unit child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_tariff_time_change)) { FD_PARSE_TIME(hdr->avp_value, data->tariff_time_change); data->presence.tariff_time_change=1; } else if (IS_AVP(davp_cc_time)) { data->cc_time = hdr->avp_value->u32; data->presence.cc_time=1; } else if (IS_AVP(davp_cc_money)) { FDCHECK_PARSE_DIRECT(parseGxCcMoney, child_avp, &data->cc_money); data->presence.cc_money=1; } else if (IS_AVP(davp_cc_total_octets)) { data->cc_total_octets = hdr->avp_value->u64; data->presence.cc_total_octets=1; } else if (IS_AVP(davp_cc_input_octets)) { data->cc_input_octets = hdr->avp_value->u64; data->presence.cc_input_octets=1; } else if (IS_AVP(davp_cc_output_octets)) { data->cc_output_octets = hdr->avp_value->u64; data->presence.cc_output_octets=1; } else if (IS_AVP(davp_cc_service_specific_units)) { data->cc_service_specific_units = hdr->avp_value->u64; data->presence.cc_service_specific_units=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the Granted-Service-Unit child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxCcMoney * * Desc: Parse CC-Money AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * CC-Money ::= <AVP Header: 413> * { Unit-Value } * [ Currency-Code ] */ static int parseGxCcMoney ( struct avp *avp, GxCcMoney *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the CC-Money child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_unit_value)) { FDCHECK_PARSE_DIRECT(parseGxUnitValue, child_avp, &data->unit_value); data->presence.unit_value=1; } else if (IS_AVP(davp_currency_code)) { data->currency_code = hdr->avp_value->u32; data->presence.currency_code=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the CC-Money child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxApplicationDetectionInformation * * Desc: Parse Application-Detection-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Application-Detection-Information ::= <AVP Header: 1098> * { TDF-Application-Identifier } * [ TDF-Application-Instance-Identifier ] * * [ Flow-Information ] * * [ AVP ] */ static int parseGxApplicationDetectionInformation ( struct avp *avp, GxApplicationDetectionInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Application-Detection-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_tdf_application_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tdf_application_identifier, GX_TDF_APPLICATION_IDENTIFIER_LEN); data->presence.tdf_application_identifier=1; } else if (IS_AVP(davp_tdf_application_instance_identifier)) { FD_PARSE_OCTETSTRING(hdr->avp_value, data->tdf_application_instance_identifier, GX_TDF_APPLICATION_INSTANCE_IDENTIFIER_LEN); data->presence.tdf_application_instance_identifier=1; } else if (IS_AVP(davp_flow_information)) { data->flow_information.count++; cnt++; data->presence.flow_information=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->flow_information, GxFlowInformation); /* iterate through the Application-Detection-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_flow_information)) { FDCHECK_PARSE_DIRECT(parseGxFlowInformation, child_avp, &data->flow_information.list[data->flow_information.count]); data->flow_information.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxFlows * * Desc: Parse Flows AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Flows ::= <AVP Header: 510> * { Media-Component-Number } * * [ Flow-Number ] * * [ Content-Version ] * [ Final-Unit-Action ] * [ Media-Component-Status ] * * [ AVP ] */ static int parseGxFlows ( struct avp *avp, GxFlows *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the Flows child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_media_component_number)) { data->media_component_number = hdr->avp_value->u32; data->presence.media_component_number=1; } else if (IS_AVP(davp_flow_number)) { data->flow_number.count++; cnt++; data->presence.flow_number=1; } else if (IS_AVP(davp_content_version)) { data->content_version.count++; cnt++; data->presence.content_version=1; } else if (IS_AVP(davp_final_unit_action)) { data->final_unit_action = hdr->avp_value->i32; data->presence.final_unit_action=1; } else if (IS_AVP(davp_media_component_status)) { data->media_component_status = hdr->avp_value->u32; data->presence.media_component_status=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { FD_ALLOC_LIST(data->flow_number, uint32_t); FD_ALLOC_LIST(data->content_version, uint64_t); /* iterate through the Flows child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_flow_number)) { data->flow_number.list[data->flow_number.count] = hdr->avp_value->u32; data->flow_number.count++; } else if (IS_AVP(davp_content_version)) { data->content_version.list[data->content_version.count] = hdr->avp_value->u64; data->content_version.count++; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /* * * Fun: parseGxUserCsgInformation * * Desc: Parse User-CSG-Information AVP * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * User-CSG-Information ::= <AVP Header: 2319> * { CSG-Id } * { CSG-Access-Mode } * [ CSG-Membership-Indication ] */ static int parseGxUserCsgInformation ( struct avp *avp, GxUserCsgInformation *data ) { int cnt = 0; struct avp_hdr *hdr; struct avp *child_avp = NULL; /* iterate through the User-CSG-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); if (IS_AVP(davp_csg_id)) { data->csg_id = hdr->avp_value->u32; data->presence.csg_id=1; } else if (IS_AVP(davp_csg_access_mode)) { data->csg_access_mode = hdr->avp_value->i32; data->presence.csg_access_mode=1; } else if (IS_AVP(davp_csg_membership_indication)) { data->csg_membership_indication = hdr->avp_value->i32; data->presence.csg_membership_indication=1; } /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } /* process list AVP's if any are present */ if (cnt > 0) { /* iterate through the User-CSG-Information child AVP's */ FDCHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child_avp, NULL), FD_REASON_BROWSE_FIRST_FAIL); /* keep going until there are no more child AVP's */ while (child_avp) { fd_msg_avp_hdr (child_avp, &hdr); // There are no multiple occurance AVPs /* get the next child AVP */ FDCHECK_FCT(fd_msg_browse(child_avp, MSG_BRW_NEXT, &child_avp, NULL), FD_REASON_BROWSE_NEXT_FAIL); } } return FD_REASON_OK; } /*******************************************************************************/ /* free structure data functions */ /*******************************************************************************/ /* * * Fun: freeGxPraRemove * * Desc: Free the multiple occurrance AVP's for PRA-Remove * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * PRA-Remove ::= <AVP Header: 2846> * * [ Presence-Reporting-Area-Identifier ] * * [ AVP ] */ static int freeGxPraRemove ( GxPraRemove *data ) { FD_FREE_LIST( data->presence_reporting_area_identifier ); return FD_REASON_OK; } /* * * Fun: freeGxQosInformation * * Desc: Free the multiple occurrance AVP's for QoS-Information * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * QoS-Information ::= <AVP Header: 1016> * [ QoS-Class-Identifier ] * [ Max-Requested-Bandwidth-UL ] * [ Max-Requested-Bandwidth-DL ] * [ Extended-Max-Requested-BW-UL ] * [ Extended-Max-Requested-BW-DL ] * [ Guaranteed-Bitrate-UL ] * [ Guaranteed-Bitrate-DL ] * [ Extended-GBR-UL ] * [ Extended-GBR-DL ] * [ Bearer-Identifier ] * [ Allocation-Retention-Priority ] * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ Conditional-APN-Aggregate-Max-Bitrate ] * * [ AVP ] */ static int freeGxQosInformation ( GxQosInformation *data ) { FD_CALLFREE_LIST( data->conditional_apn_aggregate_max_bitrate, freeGxConditionalApnAggregateMaxBitrate ); FD_FREE_LIST( data->conditional_apn_aggregate_max_bitrate ); return FD_REASON_OK; } /* * * Fun: freeGxConditionalPolicyInformation * * Desc: Free the multiple occurrance AVP's for Conditional-Policy-Information * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Conditional-Policy-Information ::= <AVP Header: 2840> * [ Execution-Time ] * [ Default-EPS-Bearer-QoS ] * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ Conditional-APN-Aggregate-Max-Bitrate ] * * [ AVP ] */ static int freeGxConditionalPolicyInformation ( GxConditionalPolicyInformation *data ) { FD_CALLFREE_LIST( data->conditional_apn_aggregate_max_bitrate, freeGxConditionalApnAggregateMaxBitrate ); FD_FREE_LIST( data->conditional_apn_aggregate_max_bitrate ); return FD_REASON_OK; } /* * * Fun: freeGxPraInstall * * Desc: Free the multiple occurrance AVP's for PRA-Install * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * PRA-Install ::= <AVP Header: 2845> * * [ Presence-Reporting-Area-Information ] * * [ AVP ] */ static int freeGxPraInstall ( GxPraInstall *data ) { FD_FREE_LIST( data->presence_reporting_area_information ); return FD_REASON_OK; } /* * * Fun: freeGxAreaScope * * Desc: Free the multiple occurrance AVP's for Area-Scope * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Area-Scope ::= <AVP Header: 1624> * * [ Cell-Global-Identity ] * * [ E-UTRAN-Cell-Global-Identity ] * * [ Routing-Area-Identity ] * * [ Location-Area-Identity ] * * [ Tracking-Area-Identity ] * * [ AVP ] */ static int freeGxAreaScope ( GxAreaScope *data ) { FD_FREE_LIST( data->cell_global_identity ); FD_FREE_LIST( data->e_utran_cell_global_identity ); FD_FREE_LIST( data->routing_area_identity ); FD_FREE_LIST( data->location_area_identity ); FD_FREE_LIST( data->tracking_area_identity ); return FD_REASON_OK; } /* * * Fun: freeGxTunnelInformation * * Desc: Free the multiple occurrance AVP's for Tunnel-Information * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Tunnel-Information ::= <AVP Header: 1038> * [ Tunnel-Header-Length ] * [ Tunnel-Header-Filter ] */ static int freeGxTunnelInformation ( GxTunnelInformation *data ) { FD_FREE_LIST( data->tunnel_header_filter ); return FD_REASON_OK; } /* * * Fun: freeGxEventReportIndication * * Desc: Free the multiple occurrance AVP's for Event-Report-Indication * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Event-Report-Indication ::= <AVP Header: 1033> * [ AN-Trusted ] * * [ Event-Trigger ] * [ User-CSG-Information ] * [ IP-CAN-Type ] * * 2 [ AN-GW-Address ] * [ 3GPP-SGSN-Address ] * [ 3GPP-SGSN-Ipv6-Address ] * [ 3GPP-SGSN-MCC-MNC ] * [ Framed-IP-Address ] * [ RAT-Type ] * [ RAI ] * [ 3GPP-User-Location-Info ] * [ Trace-Data ] * [ Trace-Reference ] * [ 3GPP2-BSID ] * [ 3GPP-MS-TimeZone ] * [ Routing-IP-Address ] * [ UE-Local-IP-Address ] * [ HeNB-Local-IP-Address ] * [ UDP-Source-Port ] * [ Presence-Reporting-Area-Information ] * * [ AVP ] */ static int freeGxEventReportIndication ( GxEventReportIndication *data ) { FD_CALLFREE_STRUCT( data->trace_data, freeGxTraceData ); FD_FREE_LIST( data->event_trigger ); FD_FREE_LIST( data->an_gw_address ); return FD_REASON_OK; } /* * * Fun: freeGxUsedServiceUnit * * Desc: Free the multiple occurrance AVP's for Used-Service-Unit * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Used-Service-Unit ::= <AVP Header: 446> * [ Reporting-Reason ] * [ Tariff-Change-Usage ] * [ CC-Time ] * [ CC-Money ] * [ CC-Total-Octets ] * [ CC-Input-Octets ] * [ CC-Output-Octets ] * [ CC-Service-Specific-Units ] * * [ Event-Charging-TimeStamp ] * * [ AVP ] */ static int freeGxUsedServiceUnit ( GxUsedServiceUnit *data ) { FD_FREE_LIST( data->event_charging_timestamp ); return FD_REASON_OK; } /* * * Fun: freeGxChargingRuleInstall * * Desc: Free the multiple occurrance AVP's for Charging-Rule-Install * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Charging-Rule-Install ::= <AVP Header: 1001> * * [ Charging-Rule-Definition ] * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * [ Bearer-Identifier ] * [ Monitoring-Flags ] * [ Rule-Activation-Time ] * [ Rule-Deactivation-Time ] * [ Resource-Allocation-Notification ] * [ Charging-Correlation-Indicator ] * [ IP-CAN-Type ] * * [ AVP ] */ static int freeGxChargingRuleInstall ( GxChargingRuleInstall *data ) { FD_CALLFREE_LIST( data->charging_rule_definition, freeGxChargingRuleDefinition ); FD_FREE_LIST( data->charging_rule_definition ); FD_FREE_LIST( data->charging_rule_name ); FD_FREE_LIST( data->charging_rule_base_name ); return FD_REASON_OK; } /* * * Fun: freeGxChargingRuleDefinition * * Desc: Free the multiple occurrance AVP's for Charging-Rule-Definition * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Charging-Rule-Definition ::= <AVP Header: 1003> * { Charging-Rule-Name } * [ Service-Identifier ] * [ Rating-Group ] * * [ Flow-Information ] * [ Default-Bearer-Indication ] * [ TDF-Application-Identifier ] * [ Flow-Status ] * [ QoS-Information ] * [ PS-to-CS-Session-Continuity ] * [ Reporting-Level ] * [ Online ] * [ Offline ] * [ Max-PLR-DL ] * [ Max-PLR-UL ] * [ Metering-Method ] * [ Precedence ] * [ AF-Charging-Identifier ] * * [ Flows ] * [ Monitoring-Key ] * [ Redirect-Information ] * [ Mute-Notification ] * [ AF-Signalling-Protocol ] * [ Sponsor-Identity ] * [ Application-Service-Provider-Identity ] * * [ Required-Access-Info ] * [ Sharing-Key-DL ] * [ Sharing-Key-UL ] * [ Traffic-Steering-Policy-Identifier-DL ] * [ Traffic-Steering-Policy-Identifier-UL ] * [ Content-Version ] * * [ AVP ] */ static int freeGxChargingRuleDefinition ( GxChargingRuleDefinition *data ) { FD_CALLFREE_STRUCT( data->qos_information, freeGxQosInformation ); FD_CALLFREE_LIST( data->flows, freeGxFlows ); FD_FREE_LIST( data->flow_information ); FD_FREE_LIST( data->flows ); FD_FREE_LIST( data->required_access_info ); return FD_REASON_OK; } /* * * Fun: freeGxFinalUnitIndication * * Desc: Free the multiple occurrance AVP's for Final-Unit-Indication * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Final-Unit-Indication ::= <AVP Header: 430> * { Final-Unit-Action } * * [ Restriction-Filter-Rule ] * * [ Filter-Id ] * [ Redirect-Server ] */ static int freeGxFinalUnitIndication ( GxFinalUnitIndication *data ) { FD_FREE_LIST( data->restriction_filter_rule ); FD_FREE_LIST( data->filter_id ); return FD_REASON_OK; } /* * * Fun: freeGxConditionalApnAggregateMaxBitrate * * Desc: Free the multiple occurrance AVP's for Conditional-APN-Aggregate-Max-Bitrate * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Conditional-APN-Aggregate-Max-Bitrate ::= <AVP Header: 2818> * [ APN-Aggregate-Max-Bitrate-UL ] * [ APN-Aggregate-Max-Bitrate-DL ] * [ Extended-APN-AMBR-UL ] * [ Extended-APN-AMBR-DL ] * * [ IP-CAN-Type ] * * [ RAT-Type ] * * [ AVP ] */ static int freeGxConditionalApnAggregateMaxBitrate ( GxConditionalApnAggregateMaxBitrate *data ) { FD_FREE_LIST( data->ip_can_type ); FD_FREE_LIST( data->rat_type ); return FD_REASON_OK; } /* * * Fun: freeGxAccessNetworkChargingIdentifierGx * * Desc: Free the multiple occurrance AVP's for Access-Network-Charging-Identifier-Gx * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Access-Network-Charging-Identifier-Gx ::= <AVP Header: 1022> * { Access-Network-Charging-Identifier-Value } * * [ Charging-Rule-Base-Name ] * * [ Charging-Rule-Name ] * [ IP-CAN-Session-Charging-Scope ] * * [ AVP ] */ static int freeGxAccessNetworkChargingIdentifierGx ( GxAccessNetworkChargingIdentifierGx *data ) { FD_FREE_LIST( data->charging_rule_base_name ); FD_FREE_LIST( data->charging_rule_name ); return FD_REASON_OK; } /* * * Fun: freeGxRoutingRuleInstall * * Desc: Free the multiple occurrance AVP's for Routing-Rule-Install * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Routing-Rule-Install ::= <AVP Header: 1081> * * [ Routing-Rule-Definition ] * * [ AVP ] */ static int freeGxRoutingRuleInstall ( GxRoutingRuleInstall *data ) { FD_CALLFREE_LIST( data->routing_rule_definition, freeGxRoutingRuleDefinition ); FD_FREE_LIST( data->routing_rule_definition ); return FD_REASON_OK; } /* * * Fun: freeGxTraceData * * Desc: Free the multiple occurrance AVP's for Trace-Data * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Trace-Data ::= <AVP Header: 1458> * { Trace-Reference } * { Trace-Depth } * { Trace-NE-Type-List } * [ Trace-Interface-List ] * { Trace-Event-List } * [ OMC-Id ] * { Trace-Collection-Entity } * [ MDT-Configuration ] * * [ AVP ] */ static int freeGxTraceData ( GxTraceData *data ) { FD_CALLFREE_STRUCT( data->mdt_configuration, freeGxMdtConfiguration ); return FD_REASON_OK; } /* * * Fun: freeGxRoutingRuleDefinition * * Desc: Free the multiple occurrance AVP's for Routing-Rule-Definition * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Routing-Rule-Definition ::= <AVP Header: 1076> * { Routing-Rule-Identifier } * * [ Routing-Filter ] * [ Precedence ] * [ Routing-IP-Address ] * [ IP-CAN-Type ] * * [ AVP ] */ static int freeGxRoutingRuleDefinition ( GxRoutingRuleDefinition *data ) { FD_FREE_LIST( data->routing_filter ); return FD_REASON_OK; } /* * * Fun: freeGxMdtConfiguration * * Desc: Free the multiple occurrance AVP's for MDT-Configuration * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * MDT-Configuration ::= <AVP Header: 1622> * { Job-Type } * [ Area-Scope ] * [ List-Of-Measurements ] * [ Reporting-Trigger ] * [ Report-Interval ] * [ Report-Amount ] * [ Event-Threshold-RSRP ] * [ Event-Threshold-RSRQ ] * [ Logging-Interval ] * [ Logging-Duration ] * [ Measurement-Period-LTE ] * [ Measurement-Period-UMTS ] * [ Collection-Period-RRM-LTE ] * [ Collection-Period-RRM-UMTS ] * [ Positioning-Method ] * [ Measurement-Quantity ] * [ Event-Threshold-Event-1F ] * [ Event-Threshold-Event-1I ] * * [ MDT-Allowed-PLMN-Id ] * * [ MBSFN-Area ] * * [ AVP ] */ static int freeGxMdtConfiguration ( GxMdtConfiguration *data ) { FD_CALLFREE_STRUCT( data->area_scope, freeGxAreaScope ); FD_FREE_LIST( data->mdt_allowed_plmn_id ); FD_FREE_LIST( data->mbsfn_area ); return FD_REASON_OK; } /* * * Fun: freeGxChargingRuleRemove * * Desc: Free the multiple occurrance AVP's for Charging-Rule-Remove * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Charging-Rule-Remove ::= <AVP Header: 1002> * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * * [ Required-Access-Info ] * [ Resource-Release-Notification ] * * [ AVP ] */ static int freeGxChargingRuleRemove ( GxChargingRuleRemove *data ) { FD_FREE_LIST( data->charging_rule_name ); FD_FREE_LIST( data->charging_rule_base_name ); FD_FREE_LIST( data->required_access_info ); return FD_REASON_OK; } /* * * Fun: freeGxRoutingRuleReport * * Desc: Free the multiple occurrance AVP's for Routing-Rule-Report * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Routing-Rule-Report ::= <AVP Header: 2835> * * [ Routing-Rule-Identifier ] * [ PCC-Rule-Status ] * [ Routing-Rule-Failure-Code ] * * [ AVP ] */ static int freeGxRoutingRuleReport ( GxRoutingRuleReport *data ) { FD_FREE_LIST( data->routing_rule_identifier ); return FD_REASON_OK; } /* * * Fun: freeGxUsageMonitoringInformation * * Desc: Free the multiple occurrance AVP's for Usage-Monitoring-Information * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Usage-Monitoring-Information ::= <AVP Header: 1067> * [ Monitoring-Key ] * * 2 [ Granted-Service-Unit ] * * 2 [ Used-Service-Unit ] * [ Quota-Consumption-Time ] * [ Usage-Monitoring-Level ] * [ Usage-Monitoring-Report ] * [ Usage-Monitoring-Support ] * * [ AVP ] */ static int freeGxUsageMonitoringInformation ( GxUsageMonitoringInformation *data ) { FD_CALLFREE_LIST( data->used_service_unit, freeGxUsedServiceUnit ); FD_FREE_LIST( data->granted_service_unit ); FD_FREE_LIST( data->used_service_unit ); return FD_REASON_OK; } /* * * Fun: freeGxChargingRuleReport * * Desc: Free the multiple occurrance AVP's for Charging-Rule-Report * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Charging-Rule-Report ::= <AVP Header: 1018> * * [ Charging-Rule-Name ] * * [ Charging-Rule-Base-Name ] * [ Bearer-Identifier ] * [ PCC-Rule-Status ] * [ Rule-Failure-Code ] * [ Final-Unit-Indication ] * * [ RAN-NAS-Release-Cause ] * * [ Content-Version ] * * [ AVP ] */ static int freeGxChargingRuleReport ( GxChargingRuleReport *data ) { FD_CALLFREE_STRUCT( data->final_unit_indication, freeGxFinalUnitIndication ); FD_FREE_LIST( data->charging_rule_name ); FD_FREE_LIST( data->charging_rule_base_name ); FD_FREE_LIST( data->ran_nas_release_cause ); FD_FREE_LIST( data->content_version ); return FD_REASON_OK; } /* * * Fun: freeGxRoutingRuleRemove * * Desc: Free the multiple occurrance AVP's for Routing-Rule-Remove * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Routing-Rule-Remove ::= <AVP Header: 1075> * * [ Routing-Rule-Identifier ] * * [ AVP ] */ static int freeGxRoutingRuleRemove ( GxRoutingRuleRemove *data ) { FD_FREE_LIST( data->routing_rule_identifier ); return FD_REASON_OK; } /* * * Fun: freeGxCoaInformation * * Desc: Free the multiple occurrance AVP's for CoA-Information * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * CoA-Information ::= <AVP Header: 1039> * { Tunnel-Information } * { CoA-IP-Address } * * [ AVP ] */ static int freeGxCoaInformation ( GxCoaInformation *data ) { FD_CALLFREE_STRUCT( data->tunnel_information, freeGxTunnelInformation ); return FD_REASON_OK; } /* * * Fun: freeGxApplicationDetectionInformation * * Desc: Free the multiple occurrance AVP's for Application-Detection-Information * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Application-Detection-Information ::= <AVP Header: 1098> * { TDF-Application-Identifier } * [ TDF-Application-Instance-Identifier ] * * [ Flow-Information ] * * [ AVP ] */ static int freeGxApplicationDetectionInformation ( GxApplicationDetectionInformation *data ) { FD_FREE_LIST( data->flow_information ); return FD_REASON_OK; } /* * * Fun: freeGxFlows * * Desc: Free the multiple occurrance AVP's for Flows * * Ret: 0 * * Notes: None * * File: gx_parsers.c * * * * Flows ::= <AVP Header: 510> * { Media-Component-Number } * * [ Flow-Number ] * * [ Content-Version ] * [ Final-Unit-Action ] * [ Media-Component-Status ] * * [ AVP ] */ static int freeGxFlows ( GxFlows *data ) { FD_FREE_LIST( data->flow_number ); FD_FREE_LIST( data->content_version ); return FD_REASON_OK; }
abeaugustijn/dwm
config.h
<reponame>abeaugustijn/dwm<gh_stars>0 /* See LICENSE file for copyright and license details. */ #include <X11/XF86keysym.h> /* appearance */ static const unsigned int borderpx = 2; /* border pixel of windows */ static const unsigned int gappx = 5; /* gaps between windows */ static const unsigned int snap = 32; /* snap pixel */ static const int showstatus = 1; /* show status */ static const int showlabel = 0; /* show program label */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 0; /* 0 means bottom bar */ static const int vertpad = 0; /* vertical padding of bar */ static const int sidepad = 0; /* horizontal padding of bar */ static const int horizpadbar = -10; /* horizontal padding for statusbar */ static const int vertpadbar = 0; /* vertical padding for statusbar */ static const char *fonts[] = { "SauceCodePro Nerd Font Mono:size=13" }; static const char dmenufont[] = "SauceCodePro Nerd Font:size=12"; static char normbgcolor[] = "#222222"; static char normbordercolor[] = "#444444"; static char normfgcolor[] = "#bbbbbb"; static char selfgcolor[] = "#eeeeee"; static char selbordercolor[] = "#005577"; static char selbgcolor[] = "#005577"; static char *colors[][3] = { /* fg bg border */ [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor }, [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor }, }; /* tagging */ //static const char *tags[] = { "", "", "阮", "", "", "", "", "", "" }; //static const char *tags[] = { "", "", "龎", "阮", "聆", "-", "-", "-", "-", "-", }; static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", }; static const Rule rules[] = { /* xprop(1): * WM_CLASS(STRING) = instance, class * WM_NAME(STRING) = title */ /* class instance title tags mask isfloating monitor */ { NULL, NULL, "Firefox Nightly", 1 << 1, 0, -1 }, { NULL, NULL, "zathura", 1 << 2, 0, -1 }, { "Spotify", NULL, NULL, 1 << 3, 0, -1 }, { NULL, NULL, "Slack", 1 << 4, 0, -1 }, }; /* layout(s) */ static const float mfact = 0.5; /* factor of master area size [0.05..0.95] */ static const int nmaster = 1; /* number of clients in master area */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ static const Layout layouts[] = { /* symbol arrange function */ { "tile", tile }, /* first entry is default */ { "monocle", monocle }, { NULL, NULL }, /* no layout function means floating behavior */ }; /* key definitions */ #define MODKEY Mod4Mask #define TAGKEYS(KEY,TAG) \ { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, /* helper for spawning shell commands in the pre dwm-5.0 fashion */ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } /* commands */ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ static const char *dmenucmd[] = { "dmenu_run", "-b", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selfgcolor, "-sf", normfgcolor, NULL }; static const char *termcmd[] = { "alacritty", NULL }; static const char *roficmd[] = { "rofi", "-show", "run", NULL }; static const char *browsercmd[] = { "firefox-nightly", NULL }; static const char *spotify[] = { "spotify", NULL }; static Key keys[] = { /* modifier key function argument */ /* App launchers */ { MODKEY, XK_d, spawn, {.v = dmenucmd } }, { MODKEY|ShiftMask, XK_d, spawn, {.v = roficmd } }, /* Launch apps */ { MODKEY, XK_Return, spawn, {.v = termcmd } }, { MODKEY, XK_c, spawn, {.v = browsercmd } }, /* Select monitor configuration */ { MODKEY, XK_m, spawn, SHCMD("monitor_select.sh") }, /* Open a tmux session in st */ { MODKEY, XK_t, spawn, SHCMD("tmux_open.sh") }, /* Bluetooth quickcontrol */ { MODKEY, XK_p, spawn, SHCMD("bluetooth.sh") }, /* Launch an ssh shell */ { MODKEY, XK_r, spawn, SHCMD("ssh.sh") }, /* Open spotify */ { MODKEY|ShiftMask, XK_s, spawn, SHCMD("ssh.sh") }, /* Play/pause Spotify */ { MODKEY, XK_space, spawn, SHCMD("play_pause.sh") }, { 0, XF86XK_AudioNext, spawn, SHCMD("play_next.sh") }, { 0, XF86XK_AudioPrev, spawn, SHCMD("play_prev.sh") }, /* Handle backlight */ { 0, XF86XK_MonBrightnessUp, spawn, SHCMD("backlight_increase.sh") }, { 0, XF86XK_MonBrightnessDown, spawn, SHCMD("backlight_decrease.sh") }, /* Handle audio */ { 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("audio_increase.sh") }, { 0, XF86XK_AudioLowerVolume, spawn, SHCMD("audio_decrease.sh") }, { 0, XF86XK_AudioMute, spawn, SHCMD("audio_toggle.sh") }, /* Open a vm */ { MODKEY, XK_o, spawn, SHCMD("vbox.sh") }, /* Toggle bar */ { MODKEY, XK_b, togglebar, {0} }, /* Client control */ { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY, XK_q, killclient, {0} }, { MODKEY, XK_f, togglefloating, {0} }, /* Monitor control */ { MODKEY, XK_comma, focusmon, {.i = +1 } }, { MODKEY, XK_period, focusmon, {.i = -1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_period, tagmon, {.i = -1 } }, /* Reload xrdb */ { MODKEY, XK_F5, xrdb, {.v = NULL } }, /* Tags */ TAGKEYS( XK_1, 0) TAGKEYS( XK_2, 1) TAGKEYS( XK_3, 2) TAGKEYS( XK_4, 3) TAGKEYS( XK_5, 4) TAGKEYS( XK_6, 5) TAGKEYS( XK_7, 6) TAGKEYS( XK_8, 7) TAGKEYS( XK_9, 8) TAGKEYS( XK_0, 9) /* Quit and reload dwm */ { MODKEY|ShiftMask, XK_q, quit, {0} }, { MODKEY|ControlMask|ShiftMask, XK_q, quit, {1} }, /* Layouts */ { MODKEY, XK_y, setlayout, { .v = &layouts[0] }}, { MODKEY, XK_u, setlayout, { .v = &layouts[1] }}, }; /* button definitions */ /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ static Button buttons[] = { /* click event mask button function argument */ { ClkWinTitle, 0, Button2, zoom, {0} }, { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, { ClkClientWin, MODKEY, Button1, movemouse, {0} }, { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, { ClkTagBar, 0, Button1, view, {0} }, { ClkTagBar, 0, Button3, toggleview, {0} }, { ClkTagBar, MODKEY, Button1, tag, {0} }, { ClkTagBar, MODKEY, Button3, toggletag, {0} }, };
bolemo/dhcp6c
common.h
<gh_stars>1-10 /* $KAME: common.h,v 1.42 2005/09/16 11:30:13 suz Exp $ */ /* * Copyright (C) 1998 and 1999 WIDE Project. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _COMMON_H_ #define _COMMON_H_ #ifdef __KAME__ #define IN6_IFF_INVALID (IN6_IFF_ANYCAST|IN6_IFF_TENTATIVE|\ IN6_IFF_DUPLICATED|IN6_IFF_DETACHED) #else #define IN6_IFF_INVALID (0) #endif #ifdef HAVE_ANSI_FUNC #define FNAME __func__ #elif defined (HAVE_GCC_FUNCTION) #define FNAME __FUNCTION__ #else #define FNAME "" #endif /* XXX: bsdi4 does not have TAILQ_EMPTY */ #ifndef TAILQ_EMPTY #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) #endif /* and linux *_FIRST and *_NEXT */ #ifndef LIST_EMPTY #define LIST_EMPTY(head) ((head)->lh_first == NULL) #endif #ifndef LIST_FIRST #define LIST_FIRST(head) ((head)->lh_first) #endif #ifndef LIST_NEXT #define LIST_NEXT(elm, field) ((elm)->field.le_next) #endif #ifndef LIST_FOREACH #define LIST_FOREACH(var, head, field) \ for ((var) = LIST_FIRST((head)); \ (var); \ (var) = LIST_NEXT((var), field)) #endif #ifndef TAILQ_FIRST #define TAILQ_FIRST(head) ((head)->tqh_first) #endif #ifndef TAILQ_LAST #define TAILQ_LAST(head, headname) \ (*(((struct headname *)((head)->tqh_last))->tqh_last)) #endif #ifndef TAILQ_PREV #define TAILQ_PREV(elm, headname, field) \ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) #endif #ifndef TAILQ_NEXT #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) #endif #ifndef TAILQ_FOREACH #define TAILQ_FOREACH(var, head, field) \ for ((var) = TAILQ_FIRST((head)); \ (var); \ (var) = TAILQ_NEXT((var), field)) #endif #ifdef HAVE_TAILQ_FOREACH_REVERSE_OLD #undef TAILQ_FOREACH_REVERSE #endif #ifndef TAILQ_FOREACH_REVERSE #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ for ((var) = TAILQ_LAST((head), headname); \ (var); \ (var) = TAILQ_PREV((var), headname, field)) #endif #ifndef SO_REUSEPORT #define SO_REUSEPORT SO_REUSEADDR #endif /* s*_len stuff */ static __inline uint8_t sysdep_sa_len (const struct sockaddr *sa) { #ifndef HAVE_SA_LEN switch (sa->sa_family) { case AF_INET: return sizeof (struct sockaddr_in); case AF_INET6: return sizeof (struct sockaddr_in6); } return sizeof (struct sockaddr_in); #else return sa->sa_len; #endif } extern int foreground; extern int debug_thresh; extern char *device; extern int opt_norelease; /* search option for dhcp6_find_listval() */ #define MATCHLIST_PREFIXLEN 0x1 /* common.c */ typedef enum { IFADDRCONF_ADD, IFADDRCONF_REMOVE } ifaddrconf_cmd_t; int rawop_copy_list(struct rawop_list *, struct rawop_list *); void rawop_clear_list(struct rawop_list *); int dhcp6_copy_list(struct dhcp6_list *, struct dhcp6_list *); void dhcp6_move_list(struct dhcp6_list *, struct dhcp6_list *); void dhcp6_clear_list(struct dhcp6_list *); void dhcp6_clear_listval(struct dhcp6_listval *); struct dhcp6_listval *dhcp6_find_listval(struct dhcp6_list *, dhcp6_listval_type_t, void *, int); struct dhcp6_listval *dhcp6_add_listval(struct dhcp6_list *, dhcp6_listval_type_t, void *, struct dhcp6_list *); int dhcp6_vbuf_copy(struct dhcp6_vbuf *, struct dhcp6_vbuf *); void dhcp6_vbuf_free(struct dhcp6_vbuf *); int dhcp6_vbuf_cmp(struct dhcp6_vbuf *, struct dhcp6_vbuf *); struct dhcp6_event *dhcp6_create_event(struct dhcp6_if *, int); void dhcp6_remove_event(struct dhcp6_event *); void dhcp6_remove_evdata(struct dhcp6_event *); struct authparam *new_authparam(int, int, int); struct authparam *copy_authparam(struct authparam *); int dhcp6_auth_replaycheck(int, uint64_t, uint64_t); int getifaddr(struct in6_addr *, char *, struct in6_addr *, int, int, int); int getifidfromaddr(struct in6_addr *, unsigned int *); int transmit_sa(int, struct sockaddr *, char *, size_t); long random_between(long, long); int prefix6_mask(struct in6_addr *, int); int sa6_plen2mask(struct sockaddr_in6 *, int); char *addr2str(struct sockaddr *); char *in6addr2str(struct in6_addr *, int); int in6_addrscopebyif(struct in6_addr *, char *); int in6_scope(struct in6_addr *); void setloglevel(int); void d_printf(int, const char *, const char *, ...); int get_duid(const char *, struct duid *, int); void dhcp6_init_options(struct dhcp6_optinfo *); void dhcp6_clear_options(struct dhcp6_optinfo *); int dhcp6_copy_options(struct dhcp6_optinfo *, struct dhcp6_optinfo *); int dhcp6_get_options(struct dhcp6opt *, struct dhcp6opt *, struct dhcp6_optinfo *); int dhcp6_set_options(int, struct dhcp6opt *, struct dhcp6opt *, struct dhcp6_optinfo *); void dhcp6_set_timeoparam(struct dhcp6_event *); void dhcp6_reset_timer(struct dhcp6_event *); const char *dhcp6optstr(int); const char *dhcp6msgstr(int); const char *dhcp6_stcodestr(uint16_t); char *duidstr(struct duid *); const char *dhcp6_event_statestr(struct dhcp6_event *); int get_rdvalue(int, void *, size_t); int duidcpy(struct duid *, struct duid *); int duidcmp(struct duid *, struct duid *); void duidfree(struct duid *); int ifaddrconf(ifaddrconf_cmd_t, char *, struct sockaddr_in6 *, int, int, int); int safefile(const char *); /* missing */ #ifndef HAVE_STRLCAT size_t strlcat(char *, const char *, size_t); #endif #ifndef HAVE_STRLCPY size_t strlcpy(char *, const char *, size_t); #endif int get_val32(char **bpp, int *lenp, uint32_t *valp); int get_val(char **bpp, int *lenp, void *valp, size_t vallen); #endif
ppfenninger/screwball
lib/elecanisms.h
/* ** Copyright (c) 2018, <NAME> ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are met: ** ** 1. Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** 2. Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in the ** documentation and/or other materials provided with the distribution. ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ** POSSIBILITY OF SUCH DAMAGE. */ #ifndef _ELECANISMS_H_ #define _ELECANISMS_H_ #include "pic24fj.h" #include "common.h" #include <stdint.h> // LED pin definitions #define LED1 LATDbits.LATD7 #define LED2 LATFbits.LATF0 #define LED3 LATFbits.LATF1 #define LED1_DIR TRISDbits.TRISD7 #define LED2_DIR TRISFbits.TRISF0 #define LED3_DIR TRISFbits.TRISF1 // Tactile switch pin definitions #define SW1 PORTCbits.RC15 #define SW2 PORTCbits.RC12 #define SW3 PORTBbits.RB12 #define SW1_DIR TRISCbits.TRISC15 #define SW2_DIR TRISCbits.TRISC12 #define SW3_DIR TRISBbits.TRISB12 // Digital header pin definitions #define D0 PORTDbits.RD5 #define D1 PORTDbits.RD4 #define D2 PORTFbits.RF4 #define D3 PORTFbits.RF5 #define D4 PORTBbits.RB15 #define D5 PORTFbits.RF3 #define D6 PORTDbits.RD8 #define D7 PORTDbits.RD11 #define D8 PORTDbits.RD9 #define D9 PORTDbits.RD10 #define D10 PORTDbits.RD0 #define D11 PORTDbits.RD1 #define D12 PORTDbits.RD2 #define D13 PORTDbits.RD3 #define D0_DIR TRISDbits.TRISD5 #define D1_DIR TRISDbits.TRISD4 #define D2_DIR TRISFbits.TRISF4 #define D3_DIR TRISFbits.TRISF5 #define D4_DIR TRISBbits.TRISB15 #define D5_DIR TRISFbits.TRISF3 #define D6_DIR TRISDbits.TRISD8 #define D7_DIR TRISDbits.TRISD11 #define D8_DIR TRISDbits.TRISD9 #define D9_DIR TRISDbits.TRISD10 #define D10_DIR TRISDbits.TRISD0 #define D11_DIR TRISDbits.TRISD1 #define D12_DIR TRISDbits.TRISD2 #define D13_DIR TRISDbits.TRISD3 #define D0_RP 20 #define D1_RP 25 #define D2_RP 10 #define D3_RP 17 #define D4_RP 29 #define D5_RP 16 #define D6_RP 2 #define D7_RP 12 #define D8_RP 4 #define D9_RP 3 #define D10_RP 11 #define D11_RP 24 #define D12_RP 23 #define D13_RP 22 // Analog header pin definitions #define A0 PORTBbits.RB5 #define A1 PORTBbits.RB4 #define A2 PORTBbits.RB3 #define A3 PORTBbits.RB2 #define A4 PORTBbits.RB1 #define A5 PORTBbits.RB0 #define A0_DIR TRISBbits.TRISB5 #define A1_DIR TRISBbits.TRISB4 #define A2_DIR TRISBbits.TRISB3 #define A3_DIR TRISBbits.TRISB2 #define A4_DIR TRISBbits.TRISB1 #define A5_DIR TRISBbits.TRISB0 #define A0_RP 18 #define A1_RP 28 #define A3_RP 13 #define A4_RP 1 #define A5_RP 0 #define A0_AN 5 #define A1_AN 4 #define A2_AN 3 #define A3_AN 2 #define A4_AN 1 #define A5_AN 0 #define INT1_RP 1 #define INT2_RP 2 #define INT3_RP 3 #define INT4_RP 4 #define MOSI1_RP 7 #define SCK1OUT_RP 8 #define MOSI2_RP 10 #define SCK2OUT_RP 11 #define MOSI3_RP 32 #define SCK3OUT_RP 33 #define MISO1_RP 40 #define SCK1IN_RP 41 #define MISO2_RP 44 #define SCK2IN_RP 45 #define MISO3_RP 56 #define SCK3IN_RP 57 #define OC1_RP 18 #define OC2_RP 19 #define OC3_RP 20 #define OC4_RP 21 #define OC5_RP 22 #define OC6_RP 23 #define OC7_RP 24 #define OC8_RP 25 #define OC9_RP 35 #define U1TX_RP 3 #define U1RTS_RP 4 #define U2TX_RP 5 #define U2RTS_RP 6 #define U3TX_RP 28 #define U3RTS_RP 29 #define U4TX_RP 30 #define U4RTS_RP 31 #define U1RX_RP 36 #define U1CTS_RP 37 #define U2RX_RP 38 #define U2CTS_RP 39 #define U3RX_RP 35 #define U3CTS_RP 43 #define U4RX_RP 54 #define U4CTS_RP 55 #define FALSE 0 #define TRUE 1 #define OFF 0 #define ON 1 #define OUT 0 #define IN 1 void init_elecanisms(void); uint16_t read_analog(uint16_t pin_an); #endif
ppfenninger/screwball
finalCode/servos/servos.c
/* ** This microcontoller controls the start and stop conditions of our . ** This microcontroller requires 4 break beam sensors, 1 coin acceptor, 1 button, and 2 servos ** To singal to the other microcontrollers that the game is on, this microcontroller sets 2 pins high (one for each side of the game) */ #include "elecanisms.h" #define SERVO_MIN_WIDTH 900e-6 #define SERVO_MAX_WIDTH 2.1e-3 int16_t main(void) { init_elecanisms(); WORD32 servo_temp; uint16_t servo_multiplier, servo_offset, servoStartMagnet, servoStartRocket, a0_analog, a1_analog, potRange, servoRange, range, a1_old, a0_old, gameOn, servoValue; uint8_t *RPOR, *RPINR; gameOn = 0; servo_offset = (uint16_t)(FCY * SERVO_MIN_WIDTH); servo_multiplier = (uint16_t)(FCY * (SERVO_MAX_WIDTH - SERVO_MIN_WIDTH)); RPOR = (uint8_t *)&RPOR0; RPINR = (uint8_t *)&RPINR0; gameOn = 0; //Ball Pass Code potRange = 1023; servoRange = 65535; range = servoRange/potRange - 1; a0_analog = 1; a1_analog = 1; a0_old = 0; a1_old = 0; T1CON = 0x0010; // configure Timer1 to have a period of 20ms PR1 = 0x9C3F; TMR1 = 0; T1CONbits.TON = 1; D7_DIR = OUT; //rocketPass servo __asm__("nop"); __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D7_RP] = OC1_RP; // connect the OC1 module output to pin D10 __builtin_write_OSCCONL(OSCCON | 0x40); OC1CON1 = 0x1C0F; OC1CON2 = 0x008B; servoStartRocket = 22768; OC1RS = servo_offset + servoStartRocket*servo_multiplier; OC1R = 1; OC1TMR = 0; // A0_AN_DIR = IN; // __asm__("nop"); // A1_AN_DIR = IN; // __asm__("nop"); D8_DIR = OUT; //magnetPass servo __asm__("nop"); __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D8_RP] = OC2_RP; // connect the OC1 module output to pin D10 __builtin_write_OSCCONL(OSCCON | 0x40); OC2CON1 = 0x1C0F; OC2CON2 = 0x008B; servoStartMagnet = 22768; OC2RS = servo_offset + servoStartMagnet*servo_multiplier; OC2R = 1; OC2TMR = 0; A0_DIR = IN; A1_DIR = IN; D12_DIR = IN; //right in D13_DIR = IN; //left in D12 = 0; D13 = 0; T2CON = 0x0030; // set Timer1 period to 0.5s PR2 = 0x7A11; TMR2 = 0; // set Timer1 count to 0 IFS0bits.T2IF = 0; // lower Timer1 interrupt flag T2CONbits.TON = 1; // turn on Timer1 while(1) { a0_analog = read_analog(A0_AN); a1_analog = read_analog(A1_AN); OC1RS = a0_analog*range*servo_multiplier + servo_offset; OC2RS = a1_analog*range*servo_multiplier + servo_offset; servoValue = a0_analog*range; servo_temp.ul = (uint32_t)servoValue * (uint32_t)servo_multiplier; OC1RS = servo_temp.w[1] + servo_offset; // if(D12 && D13){ // gameOn = 1; // } // else if (!D12 && !D13){ // gameOn = 0; // } // if(D12 && gameOn){ // a0_analog = read_analog(A0_AN); // a1_analog = read_analog(A1_AN); // if(IFS0bits.T2IF){ // IFS0bits.T2IF = 0; // if(a0_analog - a0_old < 3){ // OC1RS = a0_analog*range*servo_multiplier + servo_offset; // LED1 = 1; // } // else if(a0_old - a0_analog < 3){ // OC1RS = a0_analog*range*servo_multiplier + servo_offset; // LED1 = 1; } // else{ // LED1 = 0; // } // if(a1_analog - a1_old < 3){ // OC2RS = a1_analog*range*servo_multiplier + servo_offset; // LED2 = 1; // } // else if(a1_old - a1_analog < 3){ // OC2RS = a0_analog*range*servo_multiplier + servo_offset; // LED2 = 1; } // else{ // LED2 = 0; // } // a0_old = a0_analog; // a1_old = a1_analog; // } // } // if(a0_old - a0_analog > 3){ // a0_old = a0_analog; // OC1RS = a0_analog*range*servo_multiplier + servo_offset;} // else if(a0_analog - a0_old > 3){ // a0_old = a0_analog; // OC1RS = a0_analog*range*servo_multiplier + servo_offset;} // if(a1_old - a1_analog > 3){ // a1_old = a1_analog; // OC2RS = a1_analog*range*servo_multiplier + servo_offset;} // else if(a1_analog - a1_old > 3){ // a1_old = a1_analog; // OC2RS = a0_analog*range*servo_multiplier + servo_offset;} // if(a0_analog > a0_old > 30){ // OC3RS = a0_analog*range*servo_multiplier + servo_offset; //magnet Pass // a0_old = a0_analog; // } // else if(a0_old - a0_analog > 30){ // OC3RS = a0_analog*range*servo_multiplier + servo_offset; //magnet Pass // a0_old = a0_analog; // } // if(a1_analog - a1_old > 30){ // OC2RS = a1_analog*range*servo_multiplier + servo_offset; //rocket Pass // a1_old = a1_analog; // } // else if(a1_old - a1_analog > 30){ // OC2RS = a1_analog*range*servo_multiplier + servo_offset; //rocket Pass // a1_old = a1_analog; // } } }
ppfenninger/screwball
finalCode/left/left.c
<filename>finalCode/left/left.c /* ** This microcontoller controls the start and stop conditions of our . ** This microcontroller requires 4 break beam sensors, 1 coin acceptor, 1 button, and 2 servos ** To singal to the other microcontrollers that the game is on, this microcontroller sets 2 pins high (one for each side of the game) */ #include "elecanisms.h" #define SERVO_MIN_WIDTH 900e-6 #define SERVO_MAX_WIDTH 2.1e-3 int16_t main(void) { init_elecanisms(); WORD32 servo_temp1, servo_temp2; uint16_t servo_multiplier, servo_offset, servoLowRocket, servoStartMagnet, servoStartRocket, OCRvalueLever, OCRvalueWeeble, goingUP, gameOn, a0_analog, a1_analog, potRange, servoRange, range, servoValue1, servoValue2; uint8_t *RPOR, *RPINR; gameOn = 0; servo_offset = (uint16_t)(FCY * SERVO_MIN_WIDTH); servo_multiplier = (uint16_t)(FCY * (SERVO_MAX_WIDTH - SERVO_MIN_WIDTH)); RPOR = (uint8_t *)&RPOR0; RPINR = (uint8_t *)&RPINR0; D0_DIR = OUT; __asm__("nop"); D1_DIR = OUT; __asm__("nop"); D2_DIR = OUT; __asm__("nop"); D3_DIR = OUT; __asm__("nop"); D4_DIR = OUT; __asm__("nop"); D0 = 0; __asm__("nop"); D1 = 0; __asm__("nop"); D2 = 0; __asm__("nop"); D3 = 0; __asm__("nop"); D4 = 0; __asm__("nop"); D5_DIR = IN; //weeble wobble switch D5 = 0; D6_DIR = OUT; //weeble wooble solenoid __asm__("nop"); D6_DIR = OUT; // configure D1 to be a digital output D6 = 0; // set D1 low __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D6_RP] = OC1_RP; __builtin_write_OSCCONL(OSCCON | 0x40); OC1CON1 = 0x1C06; OC1CON2 = 0x001F; OC1RS = (uint16_t)(FCY / 1e4 - 1.); OCRvalueWeeble = 40*OC1RS/100; OC1R = 0; OC1TMR = 0; //Ball Pass Code potRange = 1023; servoRange = 65535; range = servoRange/potRange; a0_analog = 1; a1_analog = 1; T1CON = 0x0010; // configure Timer1 to have a period of 20ms PR1 = 0x9C3F; TMR1 = 0; T1CONbits.TON = 1; D7_DIR = OUT; //rocketPass servo __asm__("nop"); __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D7_RP] = OC2_RP; // connect the OC1 module output to pin D10 __builtin_write_OSCCONL(OSCCON | 0x40); OC2CON1 = 0x1C0F; OC2CON2 = 0x008B; servoStartRocket = 22768; OC2RS = servo_offset + servoStartRocket*servo_multiplier; OC2R = 1; OC2TMR = 0; D8_DIR = OUT; //magnetPass servo __asm__("nop"); __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D8_RP] = OC3_RP; // connect the OC1 module output to pin D10 __builtin_write_OSCCONL(OSCCON | 0x40); OC3CON1 = 0x1C0F; OC3CON2 = 0x008B; servoStartMagnet = 22768; OC3RS = servo_offset + servoStartMagnet*servo_multiplier; OC3R = 1; OC3TMR = 0; //Levertoss - code D9_DIR = IN; //levertoss switch D9 = 0; D10_DIR = OUT; // lever toss solenoid T2CON = 0x0030; // set Timer1 period to 0.5s PR2 = 0x1869; TMR2 = 0; // set Timer1 count to 0 IFS0bits.T2IF = 0; // lower Timer1 interrupt flag T2CONbits.TON = 1; // turn on Timer1 __asm__("nop"); __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D10_RP] = OC4_RP; __builtin_write_OSCCONL(OSCCON | 0x40); OC4CON1 = 0x1C06; OC4CON2 = 0x001F; OC4RS = (uint16_t)(FCY / 1e4 - 1.); OCRvalueLever = 10*OC4RS/100; OC4R = 0; OC4TMR = 0; D12_DIR = IN; //right in D13_DIR = IN; //left in D12 = 0; D13 = 0; while(1) { if(D12 && D13){ gameOn = 1;} else if(!D12 && !D13){ gameOn = 0; //CHANGE BACK TO 0 D0 = 0; __asm__("nop"); D1 = 0; __asm__("nop"); D2 = 0; __asm__("nop"); D3 = 0; __asm__("nop"); D4 = 0; __asm__("nop");} if(gameOn && D12){ //and D12 //Lever toss code if (D9 == 1){ if(D4){ OC4R = 10*OCRvalueLever;} else if(D3){ OC4R = 9*OCRvalueLever;} else if(D2){ OC4R = 8*OCRvalueLever;} else if(D1) { OC4R = 7*OCRvalueLever;} else if(D0){ OC4R = 6*OCRvalueLever;} else{ OC4R = 5*OCRvalueLever;}} else { OC4R = 0; if(IFS0bits.T2IF){ IFS0bits.T2IF = 0; if (goingUP){ if(D4){ goingUP = 0; LED1 = 1; LED2 = 0;} else if(D3){ D4 = 1; } else if(D2){ D3 = 1;} else if(D1) { D2 = 1;} else if(D0){ D1 = 1;} else{ D0 = 1; }} else if(goingUP == 0){ if(D0 == 0){ goingUP = 1; LED2 = 1; LED1 = 0;} else if(D1 == 0){ D0 = 0;} else if(D2 == 0){ D1 = 0;} else if(D3 == 0){ D2 = 0;} else if(D4 == 0) { D3 = 0;} else{ D4 = 0;}}}}} if(gameOn && D13){ //Add D13 //weeble-Wobble Code if(D5){ OC1R = OCRvalueWeeble;} else{ OC1R = 0;} a0_analog = read_analog(A0_AN); a1_analog = read_analog(A1_AN); servoValue1 = a0_analog*range; servo_temp1.ul = (uint32_t)servoValue1 * (uint32_t)servo_multiplier; OC2RS = servo_temp1.w[1] + servo_offset; servoValue2 = a1_analog*range; servo_temp2.ul = (uint32_t)servoValue2 * (uint32_t)servo_multiplier; OC3RS = servo_temp2.w[1] + servo_offset; } } }
ppfenninger/screwball
joystick/joystick.c
<reponame>ppfenninger/screwball #include "elecanisms.h" int16_t main(void) { init_elecanisms(); uint8_t goneUp; LED1 = 0; LED2 = 0; LED3 = 0; while(1) { if (D1 == 1){ LED1 = 1; } else{ LED1 = 0; } if (D2 == 1){ LED2 = 1; } else{ LED2 = 0; } if (D3 == 1){ LED3 = 1; } else{ LED3 = 0; } if (D4 == 1){ D0 = 1; } else{ D0 = 0; } } }
ppfenninger/screwball
CoinAcceptor/coinTest.c
#include "elecanisms.h" int16_t main(void) { init_elecanisms(); D1_DIR = OUT; __asm__("nop"); D1_DIR = OUT; __asm__("nop"); D2_DIR = OUT; __asm__("nop"); D3_DIR = OUT; __asm__("nop"); D4_DIR = OUT; __asm__("nop"); D6_DIR = OUT; __asm__("nop"); D7_DIR = OUT; __asm__("nop"); D8_DIR = OUT; __asm__("nop"); D9_DIR = OUT; __asm__("nop"); D10_DIR = OUT; __asm__("nop"); D11_DIR = OUT; __asm__("nop"); D12_DIR = OUT; __asm__("nop"); D13_DIR = OUT; __asm__("nop"); D0 = 1; __asm__("nop"); D1 = 1; __asm__("nop"); D2 = 1; __asm__("nop"); D3 = 1; __asm__("nop"); D4 = 1; __asm__("nop"); D5 = 1; __asm__("nop"); D6 = 1; __asm__("nop"); D7 = 1; __asm__("nop"); D8 = 1; __asm__("nop"); D9 = 1; __asm__("nop"); D10 = 1; __asm__("nop"); D11 = 1; __asm__("nop"); D12 = 1; __asm__("nop"); D13 = 1; __asm__("nop"); while(1) { } }
ppfenninger/screwball
usbservo/usbservo.c
<reponame>ppfenninger/screwball<filename>usbservo/usbservo.c /* ** Copyright (c) 2018, <NAME> ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are met: ** ** 1. Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** 2. Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in the ** documentation and/or other materials provided with the distribution. ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ** POSSIBILITY OF SUCH DAMAGE. */ #include "elecanisms.h" #include "usb.h" #include <stdio.h> #define TOGGLE_LED1 0 #define TOGGLE_LED2 1 #define TOGGLE_LED3 2 #define READ_SW1 3 #define READ_SW2 4 #define READ_SW3 5 #define READ_A0 6 #define READ_A1 7 #define READ_A2 8 #define READ_A3 9 #define SET_SERVO1 10 #define SET_SERVO2 11 #define SET_SERVO3 12 #define SET_SERVO4 13 #define SET_SERVO5 14 #define READ_D0 15 #define READ_D1 16 #define READ_D2 17 #define READ_D3 18 #define READ_D4 19 #define SERVO_MIN_WIDTH 900e-6 #define SERVO_MAX_WIDTH 2.1e-3 uint16_t servo_offset, servo_multiplier; WORD32 servo_temp; void vendor_requests(void) { WORD temp; switch (USB_setup.bRequest) { case TOGGLE_LED1: LED1 = !LED1; BD[EP0IN].bytecount = 0; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case TOGGLE_LED2: LED2 = !LED2; BD[EP0IN].bytecount = 0; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case TOGGLE_LED3: LED3 = !LED3; BD[EP0IN].bytecount = 0; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_SW1: BD[EP0IN].address[0] = SW1 ? 1 : 0; BD[EP0IN].bytecount = 1; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_SW2: BD[EP0IN].address[0] = SW2 ? 1 : 0; BD[EP0IN].bytecount = 1; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_SW3: BD[EP0IN].address[0] = SW3 ? 1 : 0; BD[EP0IN].bytecount = 1; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_A0: temp.w = read_analog(A0_AN); BD[EP0IN].address[0] = temp.b[0]; BD[EP0IN].address[1] = temp.b[1]; BD[EP0IN].bytecount = 2; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_A1: temp.w = read_analog(A1_AN); BD[EP0IN].address[0] = temp.b[0]; BD[EP0IN].address[1] = temp.b[1]; BD[EP0IN].bytecount = 2; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_A2: temp.w = read_analog(A2_AN); BD[EP0IN].address[0] = temp.b[0]; BD[EP0IN].address[1] = temp.b[1]; BD[EP0IN].bytecount = 2; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_A3: temp.w = read_analog(A3_AN); BD[EP0IN].address[0] = temp.b[0]; BD[EP0IN].address[1] = temp.b[1]; BD[EP0IN].bytecount = 2; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case SET_SERVO1: servo_temp.ul = (uint32_t)USB_setup.wValue.w * (uint32_t)servo_multiplier; OC1RS = servo_offset + servo_temp.w[1]; BD[EP0IN].bytecount = 0; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case SET_SERVO2: servo_temp.ul = (uint32_t)USB_setup.wValue.w * (uint32_t)servo_multiplier; OC2RS = servo_offset + servo_temp.w[1]; BD[EP0IN].bytecount = 0; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case SET_SERVO3: servo_temp.ul = (uint32_t)USB_setup.wValue.w * (uint32_t)servo_multiplier; OC3RS = servo_offset + servo_temp.w[1]; BD[EP0IN].bytecount = 0; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case SET_SERVO4: servo_temp.ul = (uint32_t)USB_setup.wValue.w * (uint32_t)servo_multiplier; OC4RS = servo_offset + servo_temp.w[1]; BD[EP0IN].bytecount = 0; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case SET_SERVO5: servo_temp.ul = (uint32_t)USB_setup.wValue.w * (uint32_t)servo_multiplier; OC5RS = servo_offset + servo_temp.w[1]; BD[EP0IN].bytecount = 0; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_D0: BD[EP0IN].address[0] = D0 ? 1 : 0; BD[EP0IN].bytecount = 1; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_D1: BD[EP0IN].address[0] = D1 ? 1 : 0; BD[EP0IN].bytecount = 1; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_D2: BD[EP0IN].address[0] = D2 ? 1 : 0; BD[EP0IN].bytecount = 1; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_D3: BD[EP0IN].address[0] = D3 ? 1 : 0; BD[EP0IN].bytecount = 1; BD[EP0IN].status = UOWN | DTS | DTSEN; break; case READ_D4: BD[EP0IN].address[0] = D4 ? 1 : 0; BD[EP0IN].bytecount = 1; BD[EP0IN].status = UOWN | DTS | DTSEN; break; default: USB_error_flags |= REQUEST_ERROR; } } int16_t main(void) { uint8_t *RPOR, *RPINR; WORD32 temp; init_elecanisms(); servo_offset = (uint16_t)(FCY * SERVO_MIN_WIDTH); servo_multiplier = (uint16_t)(FCY * (SERVO_MAX_WIDTH - SERVO_MIN_WIDTH)); // Configure pin D13 and D12 to produce hobby servo control signals // using the OC1 and OC2 modules, respectively. D13_DIR = OUT; // configure D13 to be a digital output D13 = 0; // set D13 low D12_DIR = OUT; // configure D12 to be a digital output D12 = 0; // set D12 low D11_DIR = OUT; // configure D11 to be a digital output D11 = 0; // set D11 low D10_DIR = OUT; // configure D10 to be a digital output D10 = 0; // set D10 low D9_DIR = OUT; // configure D9 to be a digital output D9 = 0; // set D9 low A0_DIR = IN; // configure A0, A1, A2, A3 to be analog input A1_DIR = IN; A2_DIR = IN; A3_DIR = IN; RPOR = (uint8_t *)&RPOR0; RPINR = (uint8_t *)&RPINR0; __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D13_RP] = OC1_RP; // connect the OC1 module output to pin D13 RPOR[D12_RP] = OC2_RP; // connect the OC2 module output to pin D12 RPOR[D11_RP] = OC3_RP; // connect the OC3 module output to pin D11 RPOR[D10_RP] = OC4_RP; // connect the OC4 module output to pin D10 RPOR[D9_RP] = OC5_RP; // connect the OC5 module output to pin D9 __builtin_write_OSCCONL(OSCCON | 0x40); //==============Servo 1================== OC1CON1 = 0x1C0F; // configure OC1 module to use the peripheral // clock (i.e., FCY, OCTSEL<2:0> = 0b111), // TRIGSTAT = 1, and to operate in center-aligned // PWM mode (OCM<2:0> = 0b111) OC1CON2 = 0x008B; // configure OC1 module to trigger from Timer1 // (OCTRIG = 1 and SYNCSEL<4:0> = 0b01011) // set OC1 pulse width to 1.5ms (i.e. halfway between 0.9ms and 2.1ms) servo_temp.ul = 0x8000 * (uint32_t)servo_multiplier; OC1RS = servo_offset + servo_temp.w[1]; OC1R = 1; OC1TMR = 0; //==============Servo 2================== OC2CON1 = 0x1C0F; // configure OC2 module to use the peripheral // clock (i.e., FCY, OCTSEL<2:0> = 0b111), // TRIGSTAT = 1, and to operate in center-aligned // PWM mode (OCM<2:0> = 0b111) OC2CON2 = 0x008B; // configure OC2 module to trigger from Timer1 // (OCTRIG = 1 and SYNCSEL<4:0> = 0b01011) // set OC2 pulse width to 1.5ms (i.e. halfway between 0.9ms and 2.1ms) servo_temp.ul = 0x8000 * (uint32_t)servo_multiplier; OC2RS = servo_offset + servo_temp.w[1]; OC2R = 1; OC2TMR = 0; //==============Servo 3================== OC3CON1 = 0x1C0F; // configure OC3 module to use the peripheral // clock (i.e., FCY, OCTSEL<2:0> = 0b111), // TRIGSTAT = 1, and to operate in center-aligned // PWM mode (OCM<2:0> = 0b111) OC3CON2 = 0x008B; // configure OC3 module to trigger from Timer1 // (OCTRIG = 1 and SYNCSEL<4:0> = 0b01011) // set OC3 pulse width to 1.5ms (i.e. halfway between 0.9ms and 2.1ms) servo_temp.ul = 0x8000 * (uint32_t)servo_multiplier; OC3RS = servo_offset + servo_temp.w[1]; OC3R = 1; OC3TMR = 0; //==============Servo 4================== OC4CON1 = 0x1C0F; // configure OC4 module to use the peripheral // clock (i.e., FCY, OCTSEL<2:0> = 0b111), // TRIGSTAT = 1, and to operate in center-aligned // PWM mode (OCM<2:0> = 0b111) OC4CON2 = 0x008B; // configure OC4 module to trigger from Timer1 // (OCTRIG = 1 and SYNCSEL<4:0> = 0b01011) // set OC4 pulse width to 1.5ms (i.e. halfway between 0.9ms and 2.1ms) servo_temp.ul = 0x8000 * (uint32_t)servo_multiplier; OC4RS = servo_offset + servo_temp.w[1]; OC4R = 1; OC4TMR = 0; //==============Servo 5================== OC5CON1 = 0x1C0F; // configure OC5 module to use the peripheral // clock (i.e., FCY, OCTSEL<2:0> = 0b111), // TRIGSTAT = 1, and to operate in center-aligned // PWM mode (OCM<2:0> = 0b111) OC5CON2 = 0x008B; // configure OC5 module to trigger from Timer1 // (OCTRIG = 1 and SYNCSEL<4:0> = 0b01011) // set OC5 pulse width to 1.5ms (i.e. halfway between 0.9ms and 2.1ms) servo_temp.ul = 0x8000 * (uint32_t)servo_multiplier; OC5RS = servo_offset + servo_temp.w[1]; OC5R = 1; OC5TMR = 0; //======================================= T1CON = 0x0010; // configure Timer1 to have a period of 20ms PR1 = 0x9C3F; TMR1 = 0; T1CONbits.TON = 1; USB_setup_vendor_callback = vendor_requests; init_usb(); while (USB_USWSTAT != CONFIG_STATE) { #ifndef USB_INTERRUPT usb_service(); #endif } while (1) { #ifndef USB_INTERRUPT usb_service(); #endif } }
ppfenninger/screwball
swishelSwashel/swishelSwashel.c
#include "elecanisms.h" #define SERVO_MIN_WIDTH 900e-6 #define SERVO_MAX_WIDTH 2.1e-3 int16_t main(void) { init_elecanisms(); uint8_t *RPOR, *RPINR; uint16_t direction, servoHigh, servoLow, servo_offset, servo_multiplier, buttonUp; //Set up the servo - Pin D0 servo_offset = (uint16_t)(FCY * SERVO_MIN_WIDTH); servo_multiplier = (uint16_t)(FCY * (SERVO_MAX_WIDTH - SERVO_MIN_WIDTH)); servoHigh = 42000; servoLow = 22000; direction = 1; D0_DIR = OUT; // configure D13 to be a digital output D0 = 0; // set D13 low RPOR = (uint8_t *)&RPOR0; RPINR = (uint8_t *)&RPINR0; __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D0_RP] = OC1_RP; // connect the OC1 module output to pin D10 __builtin_write_OSCCONL(OSCCON | 0x40); OC1CON1 = 0x1C0F; OC1CON2 = 0x008B; OC1RS = servo_offset + servoLow*servo_multiplier; OC1R = 1; OC1TMR = 0; T1CON = 0x0010; // configure Timer1 to have a period of 20ms PR1 = 0x9C3F; TMR1 = 0; T1CONbits.TON = 1; //Set up timer for servo - Timer 2 T2CON = 0X0030; // set Timer2 period of 0.5 seconds PR2 = 0x1E847; TMR2 = 0; // set initial timer count to 0 IFS0bits.T2IF = 0; // lower Timer2 interrupt flag T2CONbits.TON = 1; // turn on Timer2 //Button setup D1 = 0; //starts low //Set up timer for button - Timer 3 T3CON = 0X0030; // set Timer2 period of 0.5 seconds PR3 = 0x1E847; TMR3 = 0; // set initial timer count to 0 IFS0bits.T3IF = 0; // lower Timer2 interrupt flag T3CONbits.TON = 1; // turn on Timer2\ //Set up Solenoid D2 = 0; // solenoid input T4CON = 0x0030; PR4 = 0x1869; TMR4 = 0; // set Timer1 count to 0 IFS0bits.T4IF = 0; // lower Timer1 interrupt flag T4CONbits.TON = 1; // turn on Timer1 // initialize the motor D3_DIR = OUT; // configure D1 to be a digital output D3 = 0; // set D1 low RPOR = (uint8_t *)&RPOR0; RPINR = (uint8_t *)&RPINR0; __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D3_RP] = OC3_RP; __builtin_write_OSCCONL(OSCCON | 0x40); OC4CON1 = 0x1C06; // configure OC1 module to use the peripheral clock (i.e., FCY, OCTSEL<2:0> = 0b111) and to operate in edge-aligned PWM mode (OCM<2:0> = 0b110) OC4CON2 = 0x001F; // configure OC1 module to syncrhonize to itself (i.e., OCTRIG = 0 and SYNCSEL<4:0> = 0b11111) OC4RS = (uint16_t)(FCY / 1e4 - 1.); // configure period register to get a frequency of 1kHz OCRvalue = 10*OC4RS/100; // configure duty cycle to 1% (i.e., period / 10)r OC4R = 0; //both are stopped OC4TMR = 0; // set OC1 timer count to while(1) { if(D1 && buttonUp && IFS0bits.T3IF){ IFS0bits.T3IF = 0; OC1R = 0; buttonUp = 0; OC1R = 0; LED1 = 1; } else if(direction && IFS0bits.T2IF && IFS0bits.T3IF){ direction = 0; OC1R = servo_offset + servoHigh*servo_multiplier; IFS0bits.T2IF = 0; LED1 = 0; } else if(IFS0bits.T2IF && IFS0bits.T3IF){ direction = 1; OC1R = servo_offset + servoLow*servo_multiplier; IFS0bits.T2IF = 0; LED1 = 0; } if(!D1){ buttonUp = 1; } if(D2){ OC4R = 6*OCRvalue; } } }
ppfenninger/screwball
iteration1/iteration1.c
#include "elecanisms.h" #include <stdlib.h> #define SERVO_MIN_WIDTH 900e-6 #define SERVO_MAX_WIDTH 2.1e-3 int16_t main(void) { init_elecanisms(); uint8_t *RPOR, *RPINR; uint16_t servo_offset, servo_multiplier, servo1, servo2, ison; WORD32 servo_temp; LED1 = 0; servo_offset = (uint16_t)(FCY * SERVO_MIN_WIDTH); servo_multiplier = (uint16_t)(FCY * (SERVO_MAX_WIDTH - SERVO_MIN_WIDTH)); servo1 = 32568; servo2 = 32788; // Configure pin D13 and D12 to produce hobby servo control signals // using the OC1 and OC2 modules, respectively. D13_DIR = OUT; // configure D13 to be a digital output D13 = 0; // set D13 low D12_DIR = OUT; // configure D12 to be a digital output D12 = 0; // set D12 low RPOR = (uint8_t *)&RPOR0; RPINR = (uint8_t *)&RPINR0; __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D13_RP] = OC1_RP; // connect the OC1 module output to pin D13 RPOR[D12_RP] = OC2_RP; // connect the OC2 module output to pin D12 __builtin_write_OSCCONL(OSCCON | 0x40); OC1CON1 = 0x1C0F; // configure OC1 module to use the peripheral // clock (i.e., FCY, OCTSEL<2:0> = 0b111), // TRIGSTAT = 1, and to operate in center-aligned // PWM mode (OCM<2:0> = 0b111) OC1CON2 = 0x008B; // configure OC1 module to trigger from Timer1 // (OCTRIG = 1 and SYNCSEL<4:0> = 0b01011) // set OC1 pulse width to 1.5ms (i.e. halfway between 0.9ms and 2.1ms) servo_temp.ul = 0x8000 * (uint32_t)servo_multiplier; OC1R = 1; OC1TMR = 0; OC2CON1 = 0x1C0F; // configure OC2 module to use the peripheral // clock (i.e., FCY, OCTSEL<2:0> = 0b111), // TRIGSTAT = 1, and to operate in center-aligned // PWM mode (OCM<2:0> = 0b111) OC2CON2 = 0x008B; // configure OC2 module to trigger from Timer1 // (OCTRIG = 1 and SYNCSEL<4:0> = 0b01011) // set OC2 pulse width to 1.5ms (i.e. halfway between 0.9ms and 2.1ms) servo_temp.ul = 0x8000 * (uint32_t)servo_multiplier; OC2RS = servo_offset + servo2*servo_multiplier; OC2R = 1; OC2TMR = 0; T1CON = 0x0010; // configure Timer1 to have a period of 20ms PR1 = 0x9C3F; TMR1 = 0; T1CONbits.TON = 1; while(1) { if (D0 == 0){ LED1 = 1; ison = 1; } while(ison){ if (D1 == 1 && servo1 < 32768){ servo1 = servo1 + 1; LED2 = 1; } else if (D2 == 1 && servo1 > 32368){ servo1 = servo1 - 1; LED2 = 0; } if (D3 == 1 && servo2 < 32988){ servo2 = servo + 1; LED3 = 1; } else if (D4 == 1 && servo2 > 32588){ servo2 = servo - 1; LED3 = 0; } OC1RS = servo1*servo_multiplier + servo_offset; OC2RS = servo2*servo_multiplier + servo_offset; } } }
ppfenninger/screwball
finalCode/startEnd/startEnd.c
<reponame>ppfenninger/screwball /* ** This microcontoller controls the start and stop conditions of our . ** This microcontroller requires 4 break beam sensors, 1 coin acceptor, 1 button, and 2 servos ** To singal to the other microcontrollers that the game is on, this microcontroller sets 2 pins high (one for each side of the game) */ #include "elecanisms.h" #define SERVO_MIN_WIDTH 900e-6 #define SERVO_MAX_WIDTH 2.1e-3 int16_t main(void) { init_elecanisms(); uint8_t gameOn, gameStart, win, winRight, winLeft, timeOver, ballExitLeft, ballExitRight, buttonUp, D5up, D6up, *RPOR, *RPINR, displayWin; uint16_t servo_multiplier, servo_offset, servo1Open, servo1Close, servo2Open, servo2Close, servo3Open, servo3Close, servo4Open, servo4Close; WORD32 servo_temp; D0 = 0; //this is the timer pin that connects to the arduino // These pins go high when a coin has been inserted and the start button has been pressed. D1_DIR = OUT; __asm__("nop"); D2_DIR = OUT; __asm__("nop"); D1 = 0; // player 1's side of the game __asm__("nop"); D2 = 0; // player 2s side of the game __asm__("nop"); // Four break beam sensors - 2 for winning conditions - 2 for loseing conditions D3 = 0; //win right - was D0 D4 = 0; //win left - was D3 D5 = 0; //exit right - was D4 D6 = 0; //exit left - was D5 //START OF SERVO SETUP D7_DIR = OUT; //right ball return __asm__("nop"); D8_DIR = OUT; //left ball return __asm__("nop"); D9_DIR = OUT; //right ball start __asm__("nop"); D10_DIR = OUT; // left ball start __asm__("nop"); servo_offset = (uint16_t)(FCY * SERVO_MIN_WIDTH); servo_multiplier = (uint16_t)(FCY * (SERVO_MAX_WIDTH - SERVO_MIN_WIDTH)); RPOR = (uint8_t *)&RPOR0; RPINR = (uint8_t *)&RPINR0; __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D9_RP] = OC1_RP; // connect the OC1 module output to pin D6 RPOR[D10_RP] = OC2_RP; // connect the OC2 module output to pin D7 RPOR[D7_RP] = OC3_RP; // connect the OC3 module output to pin D8 RPOR[D8_RP] = OC4_RP; // connect the OC4 module output to pin D9 __builtin_write_OSCCONL(OSCCON | 0x40); OC1CON1 = 0x1C0F; // configure OC1 module to use the peripheral OC1CON2 = 0x008B; OC2CON1 = 0x1C0F; // configure OC2 module to use the peripheral OC2CON2 = 0x008B; OC3CON1 = 0x1C0F; // configure OC3 module to use the peripheral OC3CON2 = 0x008B; OC4CON1 = 0x1C0F; // configure OC4 module to use the peripheral OC4CON2 = 0x008B; servo_temp.ul = 0x8000 * (uint32_t)servo_multiplier; // 4 servos - 2 for staring and 2 for ending //values for the servoes where they are closed servo1Open = 32768; servo2Open = 32768; servo3Open = 32768; servo4Open = 32768; //values for the servos where they are open servo1Close = 22768; servo2Close = 22768; servo3Close = 22768; servo4Close = 22768; OC1RS = servo_offset + servo1Close*servo_multiplier; __asm__("nop"); OC2RS = servo_offset + servo2Close*servo_multiplier; __asm__("nop"); OC3RS = servo_offset + servo3Close*servo_multiplier; __asm__("nop"); OC4RS = servo_offset + servo4Close*servo_multiplier; __asm__("nop"); OC1R = 1; __asm__("nop"); OC2R = 1; __asm__("nop"); OC3R = 1; __asm__("nop"); OC4R = 1; __asm__("nop"); OC1TMR = 0; OC2TMR = 0; OC3TMR = 0; OC4TMR = 0; T1CON = 0x0010; // configure Timer1 to have a period of 20ms PR1 = 0x9C3F; TMR1 = 0; T1CONbits.TON = 1; //END OF SERVO SETUP T2CON = 0x0030; // set Timer1 period to 0.5s PR2 = 0x7A11; TMR2 = 0; // set Timer1 count to 0 IFS0bits.T2IF = 0; // lower Timer1 interrupt flag T2CONbits.TON = 1; // turn on Timer1 //Button setup D12 = 0; //Button starts low D11_DIR = OUT; //LED in button __asm__("nop"); D11 = 0; //LED in button __asm__("nop"); //Coin Receptor Setup D13 = 0; //no coin has been inserted when this is one gameOn = 0; // the game starts off displayWin = 0; timeOver = 0; winRight = 0; winLeft = 0; D5up = 1; D6up = 1; LED1 = 0; LED2 = 0; LED3 = 0; ballExitLeft = 0; ballExitRight = 0; while(1) { //Checking for wins if(!D3){ //right side of the game has won D1 = 0; //turns off the right side of the game __asm__("nop"); winRight = 0; //CHange to 1 OC1RS = servo_offset + servo1Close*servo_multiplier; //closes the right ball returns __asm__("nop"); } if(!D4){ D2 = 0; //turns off the left side of the game __asm__("nop"); winLeft = 1; //Change to 1 OC2RS = servo_offset + servo2Close*servo_multiplier; //closes the left ball returns __asm__("nop"); } if(winLeft && winRight){ win = 0; } //What happens if you time out if(D0 && gameOn){ //time has run out / timeOver = 0; //CHANGE TO 1 } if (timeOver){ //the time has turned off OC1RS = servo_offset + servo1Close*servo_multiplier; //closes the right ball returns __asm__("nop"); OC2RS = servo_offset + servo2Close*servo_multiplier; //closes the left ball returns __asm__("nop"); } //make sure that both balls are back before turning off the game if((!D5 && D5up) && (timeOver || winRight)){//right ball return ballExitRight = 1; D5up = 0; //D1 = 01; //turns off the right side of the game } else if(D5) { D5up = 1; } if ((!D6 && D6up) && (timeOver || winLeft)){ ballExitLeft = 1; D6up = 0; //D2 = 0; //turns off the left side of the game } else if (D6){ //debouncing D6up = 1; } //both balls have been returned and the game is over -- reset everything if((ballExitLeft && ballExitRight) && (timeOver || win)){ gameOn = 0; winRight = 0; winLeft = 0; win = 0; //D11 = 0; //turns off the start button timeOver = 0; ballExitLeft = 0; ballExitRight = 0; LED3 = 0; displayWin = 1; IFS0bits.T2IF = 0; } if(displayWin && IFS0bits.T2IF){ IFS0bits.T2IF = 0; displayWin = 0; if(win){ D1 = 1; } else{ D2 = 1; } } //Starting the game if (D13 && !gameOn){ // the game has started --reset the win/lose lights? //ADD NOT GAME ON gameStart = 1; D1 = 0; D2 = 0; LED2 = 1; OC1RS = servo_offset + servo1Open*servo_multiplier; //opens the right ball returns OC2RS = servo_offset + servo2Open*servo_multiplier; //opens the left ball returns D11 = 1; //light up the start button __asm__("nop"); } if (gameStart){ OC2RS = servo_offset + servo2Open*servo_multiplier; //opens the left ball returns __asm__("nop"); OC1RS = servo_offset + servo1Open*servo_multiplier; //opens the right ball returns __asm__("nop"); } if (D12 && gameStart){ // the player has pressed the start button, so the game actual has started D1 = 1; //right side of the game is on LED1 = 1; D2 = 1; //left side of the game is on LED3 = 1; gameOn = 1; buttonUp = 0; } if ((D12 == 1) && gameOn){ // the player has pressed the start button, so the game actual has started if(D1){ OC3RS = servo_offset + servo3Open*servo_multiplier; //opens the right ball start } if(D2){ OC4RS = servo_offset + servo4Open*servo_multiplier; //opens the left ball start } gameStart = 0; } if (D12 == 0){ OC3RS = servo_offset + servo3Close*servo_multiplier; //opens the right ball start OC4RS = servo_offset + servo4Close*servo_multiplier; //opens the left ball start); } } }
ppfenninger/screwball
breakbeam/breakbeam.c
<filename>breakbeam/breakbeam.c #include "elecanisms.h" int16_t main(void) { init_elecanisms(); D1_DIR = OUT; __asm__("nop"); D2_DIR = OUT; __asm__("nop"); D1 = 0; D2 = 0; D12 = 0; while(1) { D1 = 1; __asm__("nop"); D2 = 1; __asm__("nop"); D3 = 1; __asm__("nop"); D4 = 1; __asm__("nop"); D0 = 1; __asm__("nop"); if (D12){ D1 = 1; D2 = 1; } else{ D1 = 0; D2 = 0; } } }
ppfenninger/screwball
weebleWobble/weebleWobble.c
<filename>weebleWobble/weebleWobble.c #include "elecanisms.h" int16_t main(void) { init_elecanisms(); uint16_t OCRvalue; uint8_t *RPOR, *RPINR; T1CON = 0x0030; // set Timer1 period to 0.5s PR1 = 0x1869; TMR1 = 0; // set Timer1 count to 0 IFS0bits.T1IF = 0; // lower Timer1 interrupt flag T1CONbits.TON = 1; // turn on Timer1 // initialize the motor D1_DIR = OUT; // configure D1 to be a digital output D1 = 0; // set D1 low RPOR = (uint8_t *)&RPOR0; RPINR = (uint8_t *)&RPINR0; __builtin_write_OSCCONL(OSCCON & 0xBF); RPOR[D1_RP] = OC1_RP; __builtin_write_OSCCONL(OSCCON | 0x40); OC1CON1 = 0x1C06; // configure OC1 module to use the peripheral clock (i.e., FCY, OCTSEL<2:0> = 0b111) and to operate in edge-aligned PWM mode (OCM<2:0> = 0b110) OC1CON2 = 0x001F; // configure OC1 module to syncrhonize to itself (i.e., OCTRIG = 0 and SYNCSEL<4:0> = 0b11111) OC1RS = (uint16_t)(FCY / 1e4 - 1.); // configure period register to get a frequency of 1kHz OCRvalue = 10*OC1RS/100; // configure duty cycle to 1% (i.e., period / 10)r OC1R = 0; //both are stopped OC1TMR = 0; // set OC1 timer count to while(1) { if (D0 == 1){ LED1 = 1; OC1R = 5*OCRvalue; } else { LED1 = 0; OC1R = 0; } } }
TyounanMOTI/uLowLatencyAudio
external/nativeaudioplugin/PluginList.h
DECLARE_EFFECT("WASAPI Redirector", WASAPI_redirector)
andycavatorta/pinball
notes/damwrap/lib/examples.c
<reponame>andycavatorta/pinball #include <stdio.h> #include "examples.h" void hello(const char *name) { printf("hello %s\n", name); }
andycavatorta/pinball
notes/damwrap/lib/examples.h
<gh_stars>1-10 void hello(const char *name);
osamak/course-v3
nbs/swift/SwiftVips/Sources/CSwiftVips/include/core.h
<reponame>osamak/course-v3 #include <vips/vips.h> VipsImage* vipsLoadImage(const char *name) { return vips_image_new_from_file( name, "memory", TRUE, NULL ); } VipsImage* vipsResize(VipsImage* in, double scale, double vscale) { VipsImage* out; if (vips_resize(in, &out, scale, "vscale", vscale, "kernel", VIPS_KERNEL_LINEAR, NULL)) vips_error_exit( NULL ); return out; } VipsImage* vipsShrink(VipsImage* in, double hshrink, double vshrink) { VipsImage* out; if (vips_shrink(in, &out, hshrink, vshrink, NULL)) vips_error_exit( NULL ); return out; } double vipsMax(VipsImage* in) { double d; if( vips_max( in, &d, NULL ) ) vips_error_exit( NULL ); return d; } double vipsMin(VipsImage* in) { double d; if( vips_min( in, &d, NULL ) ) vips_error_exit( NULL ); return d; } double vipsAvg(VipsImage* in) { double d; if( vips_avg( in, &d, NULL ) ) vips_error_exit( NULL ); return d; } long vipsImageGetHeight(VipsImage* in) { return vips_image_get_height(in); } long vipsImageGetBands(VipsImage* in) { return vips_image_get_bands(in); } long vipsImageGetWidth(VipsImage* in) { return vips_image_get_width(in); } unsigned char* vipsGet(VipsImage* in, size_t* sz) { return vips_image_write_to_memory(in, sz); }
bOGDy1994/linux-firewall
kernel_module/f.c
<reponame>bOGDy1994/linux-firewall //For any packets that comes, check the ip header and the protocol field. If the protocol is 17(UDP), log it, and drop it. #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/netfilter.h> #include <linux/netfilter_ipv4.h> #include <linux/skbuff.h> #include <linux/udp.h> #include <linux/ip.h> MODULE_LICENSE("GPL"); static struct nf_hook_ops nfho; struct sk_buff *sock_buff; struct udphdr *udp_header; struct iphdr *ip_header; unsigned int hook_func(unsigned int hooknum, struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *)) { /* //printk("Hello kernel world!"); sock_buff = skb; //get the socket ip_header = (struct iphdr *)skb_network_header(sock_buff);//grab the network header using accessor if(!sock_buff) return NF_ACCEPT; // accept the package. it is not a UDP packet(and we couldn't read socket...) if(ip_header->protocol == 17) // if we have a UDP packet { udp_header = (struct udphdr *)skb_transport_header(sock_buff);//read the udp header printk("got UDP header\n"); return NF_DROP;//drop the package }*/ return NF_QUEUE; // the socket was read, but the package was not UDP, accept it } int init_module(void) { nfho.hook = hook_func; nfho.hooknum = 1; nfho.pf = PF_INET; nfho.priority = NF_IP_PRI_FIRST; nf_register_hook(&nfho); return 0; } void cleanup_module(void) { nf_unregister_hook(&nfho); }
bOGDy1994/linux-firewall
userspace_module/us.c
<reponame>bOGDy1994/linux-firewall //user space code using libnetfilter_queue #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <netinet/in.h> #include <linux/types.h> #include <linux/netfilter.h> #include <libnfnetlink/libnfnetlink.h> #include <libnetfilter_queue/libnetfilter_queue.h> #include <linux/ip.h> #include <linux/tcp.h> #include <linux/udp.h> #include <arpa/inet.h> #include <string.h> #include <sys/stat.h> #define MAX_RULES 255 int noRules = 0; struct rule { char ip[INET_ADDRSTRLEN]; int protocol; int port;//-1 means we do not care about the port int action;//0 for denial, 1 for allowance }; struct nfq_handle *h; struct nfq_q_handle *qh; int fd; char buf[4096] __attribute__ ((aligned)); int rv; struct rule Rules[MAX_RULES]; void eldots(char *buffin, char*buffout) { int i = 0; int len = strlen(buffin); int n = 0; while(i < len) { if(buffin[i] != '.') { buffout[n]=buffin[i]; n++; } i++; } buffout[n] = '\0'; } static u_int32_t print_pkt (struct nfq_data *tb) { int id = 0; struct nfqnl_msg_packet_hdr *ph; struct nfqnl_msg_packet_hw *hwph; u_int32_t mark,ifi; int ret; unsigned char *data; ph = nfq_get_msg_packet_hdr(tb); if (ph) { id = ntohl(ph->packet_id); printf("hw_protocol=0x%04x hook=%u id=%u ", ntohs(ph->hw_protocol), ph->hook, id); } hwph = nfq_get_packet_hw(tb); if (hwph) { int i, hlen = ntohs(hwph->hw_addrlen); printf("hw_src_addr="); for (i = 0; i < hlen-1; i++) printf("%02x:", hwph->hw_addr[i]); printf("%02x ", hwph->hw_addr[hlen-1]); } mark = nfq_get_nfmark(tb); if (mark) printf("mark=%u ", mark); ifi = nfq_get_indev(tb); if (ifi) printf("indev=%u ", ifi); ifi = nfq_get_outdev(tb); if (ifi) printf("outdev=%u ", ifi); ifi = nfq_get_physindev(tb); if (ifi) printf("physindev=%u ", ifi); ifi = nfq_get_physoutdev(tb); if (ifi) printf("physoutdev=%u ", ifi); ret = nfq_get_payload(tb, &data); if (ret >= 0) printf("payload_len=%d ", ret); fputc('\n', stdout); return id; } static int cb(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, struct nfq_data *nfa, void *data) { FILE *f; int foundPosition; struct iphdr *ipHeader; struct tcphdr *tcpHeader; struct udphdr *udpHeader; u_int32_t id = print_pkt(nfa); int payload_len; unsigned char *payloadData; unsigned char *sourceIP; payload_len = nfq_get_payload(nfa, &payloadData); ipHeader = (struct iphdr *)payloadData; int sadd = ipHeader->saddr; sourceIP = (char *)malloc(sizeof(char) * INET_ADDRSTRLEN); inet_ntop(AF_INET, (void *)&sadd,sourceIP, INET_ADDRSTRLEN); printf("Source ip address : %s - Source ip checksum : %d\n", sourceIP, ipHeader->check); if (ipHeader->protocol == IPPROTO_TCP) { tcpHeader = (struct tcphdr *)(payloadData + (ipHeader->ihl<<2)); printf("Port is : %d\n", tcpHeader->dest); } //we build the rule based on the current packet struct rule currentRule; eldots(sourceIP, currentRule.ip); currentRule.protocol = ipHeader->protocol; currentRule.port = tcpHeader->dest; currentRule.action = 1; int i = 0; int isFound = 0; while((i<noRules)&&(!isFound)) { if(strcmp(currentRule.ip, Rules[i].ip)==0) if((Rules[i].port!=-1)&&(currentRule.port!=-1)) { if(Rules[i].port==currentRule.port) if(Rules[i].protocol == currentRule.protocol) //if(Rules[i].action == currentRule.action) isFound = 1; } else { if(Rules[i].protocol == currentRule.protocol) isFound = 1; } if(!isFound) i++; } foundPosition = i; if(!isFound) { strcpy(Rules[noRules].ip, currentRule.ip); printf("NEW RULE IP : %s\n", Rules[noRules].ip); Rules[noRules].protocol = currentRule.protocol; Rules[noRules].port = currentRule.port; Rules[noRules].action = 1;//suppose we are in permissive mode noRules++; } f = fopen("./bin/verify.in","w"); if(f == NULL) { printf("Cannot create input file for Prover9!\n"); exit(-1); } fprintf(f, "set(quiet).\n"); fprintf(f, "clear(print_proofs).\n"); fprintf(f, "formulas(sos).\n"); for(i = 0; i<noRules; i++) { if(Rules[i].port != -1) fprintf(f," rule3(%s, %d, %d) = %d.\n", Rules[i].ip, Rules[i].protocol, Rules[i].port, Rules[i].action); else fprintf(f," rule2(%s, %d) = %d.\n", Rules[i].ip, Rules[i].protocol, Rules[i].action); } /*if(!isFound) { if(currentRule.port != -1) fprintf(f," rule3(%s, %d, %d) = %d.", currentRule.ip, currentRule.protocol, currentRule.port, 1); else fprintf(f," rule2(%s, %d) = %d.", currentRule.ip, currentRule.protocol, 1); }*/ //fprintf(f,"\n"); fprintf(f,"end_of_list.\n\n"); fprintf(f,"formulas(goals).\n"); if((currentRule.port != -1)&&(!isFound)) fprintf(f, " rule3(%s, %d, %d) = %d.\n", currentRule.ip, currentRule.protocol, currentRule.port, currentRule.action); else if(isFound) { if(Rules[foundPosition].port != -1) fprintf(f," rule3(%s, %d, %d) = %d.\n", Rules[foundPosition].ip, Rules[foundPosition].protocol, Rules[foundPosition].port, currentRule.action); else fprintf(f," rule2(%s, %d) = %d.\n", Rules[foundPosition].ip, Rules[foundPosition].protocol, currentRule.action); } else fprintf(f, " rule2(%s, %d) = %d.\n", currentRule.ip, currentRule.protocol, currentRule.action); fprintf(f, "end_of_list."); fclose(f); int rv = system("./bin/prover9 -f ./bin/verify.in | grep THEOREM > ./bin/ex.out"); if((rv!=0) &&(rv!=256)) { perror("Error in reading prover9! Make sure this is in the bin subfolder!\n"); exit(-1); } struct stat st; stat("./bin/ex.out", &st); printf("Ex.out size : %d", st.st_size); if(st.st_size==0) { printf("\n DROPPING THE PACKAGE...\n"); return nfq_set_verdict(qh, id, NF_DROP, payload_len, payloadData); } else { printf("\n ACCEPTING THE PACKAGE...\n"); return nfq_set_verdict(qh, id, NF_ACCEPT, payload_len, payloadData); } } int main(int argc, char *argv[]) { noRules = 1; FILE *f; f = fopen("rules.in", "r"); if(f==NULL) { printf("Cannot open rules.in!\n"); exit(1); } fscanf(f, "%s %d %d %d", &Rules[0].ip, &Rules[0].protocol, &Rules[0].port, &Rules[0].action); eldots(Rules[0].ip, Rules[0].ip); fprintf(stdout, "%s %d %d %d \n", Rules[0].ip, Rules[0].protocol, Rules[0].port, Rules[0].action); fclose(f); printf("Opening library handle...\n"); h = nfq_open(); if(!h) { fprintf(stderr, "error at nfq_open"); exit(1); } printf("Unbinding existing nf_queue handler for AF_INET(if any)...\n"); if(nfq_unbind_pf(h, AF_INET)<0) { fprintf(stderr, "Error during nfq_unbind_pf()\n"); exit(1); } printf("Binding nfnetlink_queue as nf_queue handler for AF_INET...\n"); if(nfq_bind_pf(h, AF_INET)<0) { fprintf(stderr, "Error during nfq_bind_pf()\n"); exit(1); } printf("Binding this socket to queue 0...\n"); qh = nfq_create_queue(h,0,&cb,NULL); if(!qh) { fprintf(stderr, "error during nfq_create_queue()\n"); exit(1); } printf("Setting copy packet mode...\n"); if(nfq_set_mode(qh, NFQNL_COPY_PACKET, 0xffff) < 0) { fprintf(stderr, "error during nfq_set_mode()\n"); } fd = nfq_fd(h); while(1) { while((rv = recv(fd, buf, sizeof(buf), 0)) && rv>0) { printf("pkt_received...\n"); nfq_handle_packet(h, buf, rv); } } printf("Unbinding from queue...\n"); nfq_destroy_queue(qh); printf("Closing library handle...\n"); nfq_close(h); return 0; }
raf-andrade/pwnableweb2-test
pwntalk/tools/cmdwrapper.c
<filename>pwntalk/tools/cmdwrapper.c #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> /* Simple hex decoder */ char decode_intern(char c){ if ('0' <= c && c <= '9') return c - '0'; if ('a' <= c && c <= 'f') return (c - 'a') + 10; if ('A' <= c && c <= 'F') return (c - 'A') + 10; return 0; } char *hexdecode(const char *in){ static char buf[1024]; const char *c; char *o = buf; if (strlen(in) > sizeof(buf)*2) { return NULL; } for (c=in;*c;c+=2) { *o = (decode_intern(*c) << 4 | decode_intern(*(c+1))); o++; } *o = '\0'; return buf; } int main(int argc, char **argv){ char *cmd; setreuid(geteuid(), geteuid()); if (argc == 2) { cmd = hexdecode(argv[1]); if (!strcmp(cmd, "hostname")){ /* Fake hostname as flag. */ puts("too-many-secrets.playtronics.int\n"); return 0; } return system(cmd); } return -1; }
bobmc-rmm/UartWire
src/UartWire.h
<filename>src/UartWire.h // -*- C++ -*- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /**@file UartWire.h * @brief UartWire symbols * */ #if !defined UartWire_h # define UartWire_h // list of 1wire devices types tested enum { W1_SINGLE_DROP = 1, // only a single unit on bus W1_MULTI_DROP = 2, W1_DS18B20 = 0x28, // seen in first byte of ROM W1_BUTTON = 'x' // NA }; enum { ALARM_SEARCH = 0xEC, CONVERT_T = 0x44, COPY_PAD = 0x48, MATCH_ROM = 0x55, // select a 1wire node READ_PAD = 0xBE, READ_POWER = 0xB4, READ_ROM = 0x33, RECALL = 0xB8, SEARCH_ROM = 0xF0, SKIP_ROM = 0xCC, WRITE_PAD = 0x4E }; enum { ARRAY_LSB = 0, ARRAY_MSB = 1, ARRAY_TH = 2, // alarm ARRAY_TL = 3, ARRAY_CFG = 4, // configuration ARRAY_xFF = 5, // reserve ARRAY_RSV = 6, // reserve ARRAY_x10 = 7, // reserve ARRAY_CRC = 8, // cyclic redundancy check ARRAY_PAD_SZ = 9, // scratchpad bytes ARRAY_ROM_SZ = 8, // ROM bytes ARRAY_ROM = 1, // print choice ARRAY_PAD = 2 // print choice }; void dso_strobe(int state); int blink_pulse(CHOICE_T choice, int state); void uw_init( void ); // int uw_test( u8t t_mode, int testnum); int uw_test_single(void ); int uw_next_sample(void); int uw_list_rom(void); #endif // UartWire_h
bobmc-rmm/UartWire
src/uw_main.h
<gh_stars>1-10 // -*- C++ -*- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /**@file uw_main.h * @brief UartWire application header * */ #if !defined uw_main_h # define uw_main_h typedef uint8_t u8t; typedef int16_t i16t; typedef uint16_t u16t; typedef uint32_t u32t; typedef int32_t i32t; typedef enum{ eInit, eSet, eGet }CHOICE_T; #if USE_MCU==1 // GPIO feather32 enum{ ePIN_LED = 13, ePIN_SCOPE = 21, // NA ePIN_RX1 = 16, ePIN_TX1 = 17 }; #endif #if USE_MCU==2 // GPIO mega2560 enum{ ePIN_LED = 13, ePIN_SCOPE = 21, // NA ePIN_RX1 = 16, // NA ePIN_TX1 = 17 // NA }; #endif #if USE_MCU==3 // GPIO NodeMcu 8266 12-E enum{ ePIN_LED = 2, ePIN_SCOPE = 21, // NA ePIN_RX1 = 16, // NA ePIN_TX1 = 17 // NA }; #endif #endif // uw_main_h
GitDino/ObserverPattern
ObserverPatternDemo/ObserverPatternDemo/Model/SubscriptionServiceCenter.h
<gh_stars>0 // // SubscriptionServiceCenter.h // ObserverPatternDemo // // Created by 魏欣宇 on 2018/4/11. // Copyright © 2018年 Dino. All rights reserved. // #import <Foundation/Foundation.h> #import "SubscriptionServiceCenterProtocol.h" @interface SubscriptionServiceCenter : NSObject #pragma mark - 维护订阅信息 /** 创建订阅号 @param subscription_number 订阅号码 */ + (void)createSubscriptionNumber:(NSString *) subscription_number; /** 移除订阅号 @param subscription_number 订阅号码 */ + (void)removeSubscriptionNumber:(NSString *) subscription_number; #pragma mark - 维护客户信息 /** 添加客户到具体的订阅号当中 @param customer 客户 @param subscription_number 订阅号码 */ + (void)addCustomer:(id<SubscriptionServiceCenterProtocol>) customer withSubscriptionNumber:(NSString *) subscription_number; /** 从具体的订阅号当中移除客户 @param customer 客户 @param subscription_number 订阅号码 */ + (void)removeCustomer:(id<SubscriptionServiceCenterProtocol>) customer withSubscriptionNumber:(NSString *) subscription_number; #pragma mark - 发送消息 /** 发送消息到具体的订阅号当中 @param message 消息 @param subscription_number 订阅号码 */ + (void)sendMessage:(id) message toSubscriptionNumber:(NSString *) subscription_number; @end
GitDino/ObserverPattern
ObserverPatternDemo/ObserverPatternDemo/Protocol/SubscriptionServiceCenterProtocol.h
// // SubscriptionServiceCenterProtocol.h // ObserverPatternDemo // // Created by 魏欣宇 on 2018/4/11. // Copyright © 2018年 Dino. All rights reserved. // #import <Foundation/Foundation.h> @protocol SubscriptionServiceCenterProtocol <NSObject> - (void)subscriptionMessage:(id) message subscriptionNumber:(NSString *) subscription_number; @end