diff --git a/lib/core/ogs-conv.c b/lib/core/ogs-conv.c index d847b644f..e5db3b16d 100644 --- a/lib/core/ogs-conv.c +++ b/lib/core/ogs-conv.c @@ -54,15 +54,16 @@ void *ogs_ascii_to_hex(char *in, int in_len, void *out, int out_len) void *ogs_hex_to_ascii(void *in, int in_len, void *out, int out_len) { - char *p; + char *p, *last; int i = 0, l, off = 0; p = out; + last = p + out_len; p[0] = 0; l = (in_len - off) > out_len ? out_len : in_len - off; for (i = 0; i < l; i++) { - p += sprintf(p, "%02x", ((char*)in)[off+i] & 0xff); + p = ogs_slprintf(p, last, "%02x", ((char*)in)[off+i] & 0xff); } return out; diff --git a/lib/core/ogs-uuid.c b/lib/core/ogs-uuid.c index b6f482ff8..3ade274a6 100644 --- a/lib/core/ogs-uuid.c +++ b/lib/core/ogs-uuid.c @@ -162,7 +162,8 @@ void ogs_uuid_format(char *buffer, const ogs_uuid_t *uuid) { const unsigned char *d = uuid->data; - sprintf(buffer, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" + ogs_snprintf(buffer, OGS_UUID_FORMATTED_LENGTH + 1, + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" "%02x%02x%02x%02x%02x%02x", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]); diff --git a/lib/diameter/s6a/message.h b/lib/diameter/s6a/message.h index cf37cfbca..8144e61f3 100644 --- a/lib/diameter/s6a/message.h +++ b/lib/diameter/s6a/message.h @@ -168,7 +168,6 @@ typedef struct ogs_diam_s6a_idr_message_s { #define OGS_DIAM_S6A_IDR_FLAGS_REMOVE_SMS_REG (1 << 6) #define OGS_DIAM_S6A_IDR_FLAGS_RAT_TYPE (1 << 7) #define OGS_DIAM_S6A_IDR_FLAGS_PCSCF_Restoration (1 << 8) - uint32_t idr_flags; ogs_subscription_data_t subscription_data; } ogs_diam_s6a_idr_message_t; diff --git a/src/mme/mme-fd-path.c b/src/mme/mme-fd-path.c index cbbefcd13..b5874459c 100644 --- a/src/mme/mme-fd-path.c +++ b/src/mme/mme-fd-path.c @@ -1371,7 +1371,8 @@ static void mme_s6a_ula_cb(void *data, struct msg **msg) ((ts.tv_nsec - sess_data->ts.tv_nsec) / 1000); if (ogs_diam_logger_self()->stats.nb_recv) { /* Ponderate in the avg */ - ogs_diam_logger_self()->stats.avg = (ogs_diam_logger_self()->stats.avg * + ogs_diam_logger_self()->stats.avg = + (ogs_diam_logger_self()->stats.avg * ogs_diam_logger_self()->stats.nb_recv + dur) / (ogs_diam_logger_self()->stats.nb_recv + 1); /* Min, max */ @@ -1544,7 +1545,8 @@ out: return 0; } -/* Callback for incoming Insert-Subscriber-Data-Request messages 29.272 5.2.2.1.2 */ +/* Callback for incoming Insert-Subscriber-Data-Request messages + * 29.272 5.2.2.1.2 */ static int mme_ogs_diam_s6a_idr_cb( struct msg **msg, struct avp *avp, struct session *session, void *opaque, enum disp_action *act) { @@ -1620,9 +1622,11 @@ static int mme_ogs_diam_s6a_idr_cb( struct msg **msg, struct avp *avp, ogs_assert(ret == 0); idr_message->idr_flags = hdr->avp_value->i32; } else { - ogs_error("Insert Subscriber Data does not contain any IDR Flags for IMSI[%s]", imsi_bcd); + ogs_error("Insert Subscriber Data does not contain any IDR Flags " + "for IMSI[%s]", imsi_bcd); /* Set the Origin-Host, Origin-Realm, and Result-Code AVPs */ - ret = fd_msg_rescode_set(ans, (char*)"DIAMETER_UNABLE_TO_COMPLY", NULL, NULL, 1); + ret = fd_msg_rescode_set(ans, + (char*)"DIAMETER_UNABLE_TO_COMPLY", NULL, NULL, 1); ogs_assert(ret == 0); goto outnoexp; } @@ -1641,62 +1645,77 @@ static int mme_ogs_diam_s6a_idr_cb( struct msg **msg, struct avp *avp, uint32_t ida_cell_id = mme_ue->e_cgi.cell_id; uint16_t ida_tac = mme_ue->tai.tac; - sprintf(ida_cell_id_hex, "%08x", ida_cell_id); - memcpy(ida_ecgi, ogs_nas_from_plmn_id(&ida_plmn_buf, &mme_ue->e_cgi.plmn_id), 3); - memcpy(ida_ecgi + 3, OGS_HEX(ida_cell_id_hex,sizeof(ida_cell_id_hex),buf), 5); - - sprintf(ida_tac_hex, "%04x", ida_tac); - memcpy(ida_tai, ogs_nas_from_plmn_id(&ida_plmn_buf, &mme_ue->tai.plmn_id), 3); - memcpy(ida_tai + 3, OGS_HEX(ida_tac_hex,sizeof(ida_tac_hex),buf), 2); - - ida_age = (ogs_time_now() - mme_ue->ue_location_timestamp) / 1000000 / 60; - struct avp *avp_mme_location_information; struct avp *avp_e_utran_cell_global_identity; struct avp *avp_tracking_area_identity; struct avp *avp_age_of_location_information; + ogs_snprintf(ida_cell_id_hex, sizeof(ida_cell_id_hex), + "%08x", ida_cell_id); + memcpy(ida_ecgi, + ogs_nas_from_plmn_id(&ida_plmn_buf, &mme_ue->e_cgi.plmn_id), 3); + memcpy(ida_ecgi + 3, + OGS_HEX(ida_cell_id_hex, sizeof(ida_cell_id_hex), buf), 5); + + ogs_snprintf(ida_tac_hex, sizeof(ida_tac_hex), "%04x", ida_tac); + memcpy(ida_tai, + ogs_nas_from_plmn_id(&ida_plmn_buf, &mme_ue->tai.plmn_id), 3); + memcpy(ida_tai + 3, OGS_HEX(ida_tac_hex, sizeof(ida_tac_hex), buf), 2); + + ida_age = + (ogs_time_now() - mme_ue->ue_location_timestamp) / 1000000 / 60; + /* Set the EPS-Location-Information AVP */ ret = fd_msg_avp_new(ogs_diam_s6a_eps_location_information, 0, &avp); ogs_assert(ret == 0); - ret = fd_msg_avp_new(ogs_diam_s6a_mme_location_information, 0, &avp_mme_location_information); + ret = fd_msg_avp_new(ogs_diam_s6a_mme_location_information, + 0, &avp_mme_location_information); ogs_assert(ret == 0); - ret = fd_msg_avp_new(ogs_diam_s6a_e_utran_cell_global_identity, 0, &avp_e_utran_cell_global_identity); + ret = fd_msg_avp_new(ogs_diam_s6a_e_utran_cell_global_identity, + 0, &avp_e_utran_cell_global_identity); ogs_assert(ret == 0); val.os.data = ida_ecgi; val.os.len = 7; ret = fd_msg_avp_setvalue(avp_e_utran_cell_global_identity, &val); ogs_assert(ret == 0); - ret = fd_msg_avp_add(avp_mme_location_information, MSG_BRW_LAST_CHILD, avp_e_utran_cell_global_identity); + ret = fd_msg_avp_add(avp_mme_location_information, + MSG_BRW_LAST_CHILD, avp_e_utran_cell_global_identity); ogs_assert(ret == 0); - ret = fd_msg_avp_new(ogs_diam_s6a_tracking_area_identity, 0, &avp_tracking_area_identity); + ret = fd_msg_avp_new(ogs_diam_s6a_tracking_area_identity, + 0, &avp_tracking_area_identity); ogs_assert(ret == 0); val.os.data = ida_tai; val.os.len = 5; ret = fd_msg_avp_setvalue(avp_tracking_area_identity, &val); ogs_assert(ret == 0); - ret = fd_msg_avp_add(avp_mme_location_information, MSG_BRW_LAST_CHILD, avp_tracking_area_identity); + ret = fd_msg_avp_add(avp_mme_location_information, + MSG_BRW_LAST_CHILD, avp_tracking_area_identity); ogs_assert(ret == 0); - ret = fd_msg_avp_new(ogs_diam_s6a_age_of_location_information, 0, &avp_age_of_location_information); + ret = fd_msg_avp_new(ogs_diam_s6a_age_of_location_information, + 0, &avp_age_of_location_information); ogs_assert(ret == 0); val.i32 = ida_age; ret = fd_msg_avp_setvalue(avp_age_of_location_information, &val); ogs_assert(ret == 0); - ret = fd_msg_avp_add(avp_mme_location_information, MSG_BRW_LAST_CHILD, avp_age_of_location_information); + ret = fd_msg_avp_add(avp_mme_location_information, + MSG_BRW_LAST_CHILD, avp_age_of_location_information); ogs_assert(ret == 0); - ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avp_mme_location_information); + ret = fd_msg_avp_add(avp, + MSG_BRW_LAST_CHILD, avp_mme_location_information); ogs_assert(ret == 0); ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp); ogs_assert(ret == 0); } else { - ogs_error("Insert Subscriber Data with unsupported IDR Flags for IMSI[%s]", imsi_bcd); + ogs_error("Insert Subscriber Data " + "with unsupported IDR Flags for IMSI[%s]", imsi_bcd); /* Set the Origin-Host, Origin-Realm, and Result-Code AVPs */ - ret = fd_msg_rescode_set(ans, (char*)"DIAMETER_UNABLE_TO_COMPLY", NULL, NULL, 1); + ret = fd_msg_rescode_set( + ans, (char*)"DIAMETER_UNABLE_TO_COMPLY", NULL, NULL, 1); ogs_assert(ret == 0); goto outnoexp; }