2019-06-11 14:16:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of Open5GS.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
#include "ogs-crypt.h"
|
2019-06-11 09:28:25 +00:00
|
|
|
#include "fd/fd-lib.h"
|
|
|
|
#include "fd/s6a/s6a-dict.h"
|
|
|
|
#include "fd/s6a/s6a-message.h"
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2019-06-11 13:10:47 +00:00
|
|
|
#include "hss-context.h"
|
|
|
|
#include "hss-auc.h"
|
2017-07-22 00:44:42 +00:00
|
|
|
#include "milenage.h"
|
|
|
|
|
|
|
|
/* handler for fallback cb */
|
2017-08-25 11:31:08 +00:00
|
|
|
static struct disp_hdl *hdl_s6a_fb = NULL;
|
2017-07-22 00:44:42 +00:00
|
|
|
/* handler for Authentication-Information-Request cb */
|
2017-08-25 11:31:08 +00:00
|
|
|
static struct disp_hdl *hdl_s6a_air = NULL;
|
2017-07-22 00:44:42 +00:00
|
|
|
/* handler for Update-Location-Request cb */
|
2017-08-25 11:31:08 +00:00
|
|
|
static struct disp_hdl *hdl_s6a_ulr = NULL;
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
/* Default callback for the application. */
|
2017-08-25 11:31:08 +00:00
|
|
|
static int hss_s6a_fb_cb(struct msg **msg, struct avp *avp,
|
2017-08-18 11:43:28 +00:00
|
|
|
struct session *session, void *opaque, enum disp_action *act)
|
2017-07-22 00:44:42 +00:00
|
|
|
{
|
|
|
|
/* This CB should never be called */
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_warn("Unexpected message received!");
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
return ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback for incoming Authentication-Information-Request messages */
|
2017-08-25 11:31:08 +00:00
|
|
|
static int hss_s6a_air_cb( struct msg **msg, struct avp *avp,
|
2017-08-18 11:43:28 +00:00
|
|
|
struct session *session, void *opaque, enum disp_action *act)
|
2017-07-22 00:44:42 +00:00
|
|
|
{
|
2018-01-10 05:15:00 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-07-22 00:44:42 +00:00
|
|
|
struct msg *ans, *qry;
|
2017-12-17 15:01:07 +00:00
|
|
|
struct avp *avpch;
|
2017-07-22 00:44:42 +00:00
|
|
|
struct avp *avp_e_utran_vector, *avp_xres, *avp_kasme, *avp_rand, *avp_autn;
|
|
|
|
struct avp_hdr *hdr;
|
|
|
|
union avp_value val;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
char imsi_bcd[MAX_IMSI_BCD_LEN+1];
|
|
|
|
uint8_t opc[HSS_KEY_LEN];
|
|
|
|
uint8_t sqn[HSS_SQN_LEN];
|
|
|
|
uint8_t autn[AUTN_LEN];
|
|
|
|
uint8_t ik[HSS_KEY_LEN];
|
|
|
|
uint8_t ck[HSS_KEY_LEN];
|
|
|
|
uint8_t ak[HSS_AK_LEN];
|
|
|
|
uint8_t xres[MAX_RES_LEN];
|
|
|
|
uint8_t kasme[OGS_SHA256_DIGEST_SIZE];
|
2017-07-22 00:44:42 +00:00
|
|
|
size_t xres_len = 8;
|
|
|
|
|
2017-12-17 15:01:07 +00:00
|
|
|
#define MAC_S_LEN 8
|
2019-04-27 14:54:30 +00:00
|
|
|
uint8_t mac_s[MAC_S_LEN];
|
2017-12-17 15:01:07 +00:00
|
|
|
|
2017-07-22 00:44:42 +00:00
|
|
|
hss_db_auth_info_t auth_info;
|
2019-04-27 14:54:30 +00:00
|
|
|
uint8_t zero[RAND_LEN];
|
|
|
|
int rv;
|
|
|
|
uint32_t result_code = 0;
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(msg);
|
2018-01-22 15:00:57 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_debug("[HSS] Authentication-Information-Request\n");
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
/* Create answer header */
|
|
|
|
qry = *msg;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
ans = *msg;
|
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_search_avp(qry, fd_user_name, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ogs_cpystrn(imsi_bcd, (char*)hdr->avp_value->os.data,
|
|
|
|
ogs_min(hdr->avp_value->os.len, MAX_IMSI_BCD_LEN)+1);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
rv = hss_db_auth_info(imsi_bcd, &auth_info);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2017-09-08 03:11:44 +00:00
|
|
|
result_code = S6A_DIAMETER_ERROR_USER_UNKNOWN;
|
2017-07-22 00:44:42 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(zero, 0, sizeof(zero));
|
2019-06-11 14:16:54 +00:00
|
|
|
if (memcmp(auth_info.rand, zero, RAND_LEN) == 0) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_random(auth_info.rand, RAND_LEN);
|
2017-07-22 00:44:42 +00:00
|
|
|
}
|
|
|
|
|
2017-12-17 15:01:07 +00:00
|
|
|
if (auth_info.use_opc)
|
|
|
|
memcpy(opc, auth_info.opc, sizeof(opc));
|
|
|
|
else
|
|
|
|
milenage_opc(auth_info.k, auth_info.op, opc);
|
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_search_avp(qry, s6a_req_eutran_auth_info, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avp) {
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_avp_search_avp(avp, s6a_re_synchronization_info, &avpch);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (avpch) {
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_hdr(avpch, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-21 11:46:02 +00:00
|
|
|
hss_auc_sqn(opc, auth_info.k, hdr->avp_value->os.data, sqn, mac_s);
|
2017-12-17 15:01:07 +00:00
|
|
|
if (memcmp(mac_s, hdr->avp_value->os.data +
|
2019-06-11 14:16:54 +00:00
|
|
|
RAND_LEN + HSS_SQN_LEN, MAC_S_LEN) == 0) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_random(auth_info.rand, RAND_LEN);
|
|
|
|
auth_info.sqn = ogs_buffer_to_uint64(sqn, HSS_SQN_LEN);
|
2017-12-18 09:21:54 +00:00
|
|
|
/* 33.102 C.3.4 Guide : IND + 1 */
|
|
|
|
auth_info.sqn = (auth_info.sqn + 32 + 1) & HSS_MAX_SQN;
|
2019-06-11 14:16:54 +00:00
|
|
|
} else {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("Re-synch MAC failed for IMSI:`%s`", imsi_bcd);
|
|
|
|
ogs_log_print(OGS_LOG_ERROR, "MAC_S: ");
|
|
|
|
ogs_log_hexdump(OGS_LOG_ERROR, mac_s, MAC_S_LEN);
|
|
|
|
ogs_log_hexdump(OGS_LOG_ERROR,
|
|
|
|
(void*)(hdr->avp_value->os.data + RAND_LEN + HSS_SQN_LEN),
|
|
|
|
MAC_S_LEN);
|
|
|
|
ogs_log_print(OGS_LOG_ERROR, "SQN: ");
|
|
|
|
ogs_log_hexdump(OGS_LOG_ERROR, sqn, HSS_SQN_LEN);
|
2017-12-17 15:01:07 +00:00
|
|
|
result_code = S6A_DIAMETER_AUTHENTICATION_DATA_UNAVAILABLE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-22 00:44:42 +00:00
|
|
|
rv = hss_db_update_rand_and_sqn(imsi_bcd, auth_info.rand, auth_info.sqn);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("Cannot update rand and sqn for IMSI:'%s'", imsi_bcd);
|
2017-08-09 05:48:44 +00:00
|
|
|
result_code = S6A_DIAMETER_AUTHENTICATION_DATA_UNAVAILABLE;
|
2017-07-22 00:44:42 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = hss_db_increment_sqn(imsi_bcd);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("Cannot increment sqn for IMSI:'%s'", imsi_bcd);
|
2017-08-09 05:48:44 +00:00
|
|
|
result_code = S6A_DIAMETER_AUTHENTICATION_DATA_UNAVAILABLE;
|
2017-07-22 00:44:42 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_search_avp(qry, s6a_visited_plmn_id, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
#if 0 // TODO : check visited_plmn_id
|
2017-08-19 07:49:44 +00:00
|
|
|
memcpy(visited_plmn_id, hdr->avp_value->os.data, hdr->avp_value->os.len);
|
2017-07-22 00:44:42 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
milenage_generate(opc, auth_info.amf, auth_info.k,
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_uint64_to_buffer(auth_info.sqn, HSS_SQN_LEN, sqn), auth_info.rand,
|
2017-07-22 00:44:42 +00:00
|
|
|
autn, ik, ck, ak, xres, &xres_len);
|
2018-01-21 11:46:02 +00:00
|
|
|
hss_auc_kasme(ck, ik, hdr->avp_value->os.data, sqn, ak, kasme);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
/* Set the Authentication-Info */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_authentication_info, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_e_utran_vector, 0, &avp_e_utran_vector);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_rand, 0, &avp_rand);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
val.os.data = auth_info.rand;
|
|
|
|
val.os.len = HSS_KEY_LEN;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp_rand, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp_e_utran_vector, MSG_BRW_LAST_CHILD, avp_rand);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_xres, 0, &avp_xres);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
val.os.data = xres;
|
|
|
|
val.os.len = xres_len;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp_xres, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp_e_utran_vector, MSG_BRW_LAST_CHILD, avp_xres);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_autn, 0, &avp_autn);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
val.os.data = autn;
|
|
|
|
val.os.len = AUTN_LEN;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp_autn, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp_e_utran_vector, MSG_BRW_LAST_CHILD, avp_autn);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_kasme, 0, &avp_kasme);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
val.os.data = kasme;
|
2019-04-27 14:54:30 +00:00
|
|
|
val.os.len = OGS_SHA256_DIGEST_SIZE;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp_kasme, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp_e_utran_vector, MSG_BRW_LAST_CHILD, avp_kasme);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-05 08:57:29 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avp_e_utran_vector);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-09 05:48:44 +00:00
|
|
|
|
|
|
|
/* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-09 05:48:44 +00:00
|
|
|
|
|
|
|
/* Set the Auth-Session-State AVP */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(fd_auth_session_state, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-09 05:48:44 +00:00
|
|
|
val.i32 = 1;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-09 05:48:44 +00:00
|
|
|
|
2017-08-27 08:38:57 +00:00
|
|
|
/* Set Vendor-Specific-Application-Id AVP */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_message_vendor_specific_appid_set(ans, S6A_APPLICATION_ID);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-27 08:38:57 +00:00
|
|
|
|
2017-07-22 00:44:42 +00:00
|
|
|
/* Send the answer */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_send(msg, NULL, NULL);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-22 15:00:57 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_debug("[HSS] Authentication-Information-Answer\n");
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
/* Add this value to the stats */
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(pthread_mutex_lock(&fd_logger_self()->stats_lock) == 0);
|
2017-08-17 00:43:33 +00:00
|
|
|
fd_logger_self()->stats.nb_echoed++;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(pthread_mutex_unlock(&fd_logger_self()->stats_lock) == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_message_experimental_rescode_set(ans, result_code);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-16 13:03:36 +00:00
|
|
|
|
|
|
|
/* Set the Auth-Session-State AVP */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(fd_auth_session_state, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-16 13:03:36 +00:00
|
|
|
val.i32 = 1;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-16 13:03:36 +00:00
|
|
|
|
2017-08-27 08:38:57 +00:00
|
|
|
/* Set Vendor-Specific-Application-Id AVP */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_message_vendor_specific_appid_set(ans, S6A_APPLICATION_ID);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-27 08:38:57 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_send(msg, NULL, NULL);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback for incoming Update-Location-Request messages */
|
2017-08-25 11:31:08 +00:00
|
|
|
static int hss_s6a_ulr_cb( struct msg **msg, struct avp *avp,
|
2017-08-18 11:43:28 +00:00
|
|
|
struct session *session, void *opaque, enum disp_action *act)
|
2017-07-22 00:44:42 +00:00
|
|
|
{
|
2018-01-10 05:15:00 +00:00
|
|
|
int ret;
|
2017-07-22 00:44:42 +00:00
|
|
|
struct msg *ans, *qry;
|
|
|
|
|
|
|
|
struct avp_hdr *hdr;
|
|
|
|
union avp_value val;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
char imsi_bcd[MAX_IMSI_BCD_LEN+1];
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int rv;
|
|
|
|
uint32_t result_code = 0;
|
2017-08-25 11:31:08 +00:00
|
|
|
s6a_subscription_data_t subscription_data;
|
2017-08-28 11:32:25 +00:00
|
|
|
struct sockaddr_in sin;
|
2017-12-15 04:47:57 +00:00
|
|
|
struct sockaddr_in6 sin6;
|
2017-08-28 11:32:25 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(msg);
|
2018-01-22 15:00:57 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_debug("[HSS] Update-Location-Request\n");
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
/* Create answer header */
|
|
|
|
qry = *msg;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
ans = *msg;
|
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_search_avp(qry, fd_user_name, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ogs_cpystrn(imsi_bcd, (char*)hdr->avp_value->os.data,
|
|
|
|
ogs_min(hdr->avp_value->os.len, MAX_IMSI_BCD_LEN)+1);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
rv = hss_db_subscription_data(imsi_bcd, &subscription_data);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (rv != OGS_OK) {
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("Cannot get Subscription-Data for IMSI:'%s'", imsi_bcd);
|
2017-09-08 03:11:44 +00:00
|
|
|
result_code = S6A_DIAMETER_ERROR_USER_UNKNOWN;
|
2017-07-22 00:44:42 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_search_avp(qry, s6a_visited_plmn_id, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
#if 0 // TODO : check visited_plmn_id
|
2017-08-19 07:49:44 +00:00
|
|
|
memcpy(visited_plmn_id, hdr->avp_value->os.data, hdr->avp_value->os.len);
|
2017-07-22 00:44:42 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2017-08-27 08:38:57 +00:00
|
|
|
/* Set the Auth-Session-State AVP */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(fd_auth_session_state, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
val.i32 = 1;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
/* Set the ULA Flags */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_ula_flags, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-25 11:31:08 +00:00
|
|
|
val.i32 = S6A_ULA_FLAGS_MME_REGISTERED_FOR_SMS;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
|
|
|
|
ret = fd_msg_search_avp(qry, s6a_ulr_flags, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_hdr(avp, &hdr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2019-06-11 14:16:54 +00:00
|
|
|
if (!(hdr->avp_value->u32 & S6A_ULR_SKIP_SUBSCRIBER_DATA)) {
|
2017-08-16 13:03:36 +00:00
|
|
|
struct avp *avp_access_restriction_data;
|
2017-07-22 00:44:42 +00:00
|
|
|
struct avp *avp_subscriber_status, *avp_network_access_mode;
|
|
|
|
struct avp *avp_ambr, *avp_max_bandwidth_ul, *avp_max_bandwidth_dl;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Set the Subscription Data */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_subscription_data, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (subscription_data.access_restriction_data) {
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_access_restriction_data, 0,
|
|
|
|
&avp_access_restriction_data);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
val.i32 = subscription_data.access_restriction_data;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue( avp_access_restriction_data, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD,
|
|
|
|
avp_access_restriction_data);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_subscriber_status, 0, &avp_subscriber_status);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
val.i32 = subscription_data.subscriber_status;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp_subscriber_status, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avp_subscriber_status);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
|
|
|
|
ret = fd_msg_avp_new(s6a_network_access_mode, 0,
|
|
|
|
&avp_network_access_mode);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
val.i32 = subscription_data.network_access_mode;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp_network_access_mode, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avp_network_access_mode);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
/* Set the AMBR */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_ambr, 0, &avp_ambr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_max_bandwidth_ul, 0, &avp_max_bandwidth_ul);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-22 05:07:37 +00:00
|
|
|
val.u32 = subscription_data.ambr.uplink;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp_max_bandwidth_ul, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp_ambr, MSG_BRW_LAST_CHILD, avp_max_bandwidth_ul);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_max_bandwidth_dl, 0, &avp_max_bandwidth_dl);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-22 05:07:37 +00:00
|
|
|
val.u32 = subscription_data.ambr.downlink;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp_max_bandwidth_dl, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp_ambr, MSG_BRW_LAST_CHILD, avp_max_bandwidth_dl);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avp_ambr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2019-07-29 22:34:55 +00:00
|
|
|
/* Set the Subscribed RAU TAU Timer */
|
|
|
|
ret = fd_msg_avp_new(s6a_subscribed_rau_tau_timer, 0, &avp_rau_tau_timer);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
val.i32 = subscription_data.subscribed_rau_tau_timer * 60; /* seconds */
|
|
|
|
ret = fd_msg_avp_setvalue(avp_rau_tau_timer, &val);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avp_rau_tau_timer);
|
|
|
|
ogs_assert(ret == 0);
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (subscription_data.num_of_pdn) {
|
2017-07-22 00:44:42 +00:00
|
|
|
/* Set the APN Configuration Profile */
|
|
|
|
struct avp *apn_configuration_profile;
|
2017-08-16 13:03:36 +00:00
|
|
|
struct avp *context_identifier;
|
|
|
|
struct avp *all_apn_configuration_included_indicator;
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_apn_configuration_profile, 0,
|
|
|
|
&apn_configuration_profile);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_context_identifier, 0,
|
|
|
|
&context_identifier);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-28 11:32:25 +00:00
|
|
|
val.i32 = 1; /* Context Identifier : 1 */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(context_identifier, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(apn_configuration_profile,
|
|
|
|
MSG_BRW_LAST_CHILD, context_identifier);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(
|
2017-08-16 13:03:36 +00:00
|
|
|
s6a_all_apn_configuration_included_indicator, 0,
|
2018-01-10 05:15:00 +00:00
|
|
|
&all_apn_configuration_included_indicator);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
val.i32 = 0;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(
|
|
|
|
all_apn_configuration_included_indicator, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(apn_configuration_profile,
|
2017-08-16 13:03:36 +00:00
|
|
|
MSG_BRW_LAST_CHILD,
|
2018-01-10 05:15:00 +00:00
|
|
|
all_apn_configuration_included_indicator);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
for (i = 0; i < subscription_data.num_of_pdn; i++) {
|
2017-07-22 00:44:42 +00:00
|
|
|
/* Set the APN Configuration */
|
|
|
|
struct avp *apn_configuration, *context_identifier;
|
|
|
|
struct avp *pdn_type, *service_selection;
|
|
|
|
struct avp *eps_subscribed_qos_profile, *qos_class_identifier;
|
|
|
|
struct avp *allocation_retention_priority, *priority_level;
|
|
|
|
struct avp *pre_emption_capability, *pre_emption_vulnerability;
|
2017-08-28 11:32:25 +00:00
|
|
|
struct avp *mip6_agent_info, *mip_home_agent_address;
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2017-08-11 10:34:27 +00:00
|
|
|
pdn_t *pdn = &subscription_data.pdn[i];
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(pdn);
|
2017-08-28 11:32:25 +00:00
|
|
|
pdn->context_identifier = i+1;
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_apn_configuration, 0,
|
|
|
|
&apn_configuration);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2017-08-28 11:32:25 +00:00
|
|
|
/* Set Context-Identifier */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_context_identifier, 0,
|
|
|
|
&context_identifier);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-11 08:16:35 +00:00
|
|
|
val.i32 = pdn->context_identifier;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(context_identifier, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(apn_configuration,
|
|
|
|
MSG_BRW_LAST_CHILD, context_identifier);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2017-08-28 11:32:25 +00:00
|
|
|
/* Set PDN-Type */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_pdn_type, 0, &pdn_type);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-11 08:16:35 +00:00
|
|
|
val.i32 = pdn->pdn_type;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(pdn_type, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(apn_configuration,
|
|
|
|
MSG_BRW_LAST_CHILD, pdn_type);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2017-08-28 11:32:25 +00:00
|
|
|
/* Set Service-Selection */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_service_selection, 0,
|
|
|
|
&service_selection);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
|
|
|
val.os.data = (uint8_t *)pdn->apn;
|
2017-08-11 08:16:35 +00:00
|
|
|
val.os.len = strlen(pdn->apn);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(service_selection, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(apn_configuration,
|
|
|
|
MSG_BRW_LAST_CHILD, service_selection);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2017-08-28 11:32:25 +00:00
|
|
|
/* Set the EPS Subscribed QoS Profile */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_eps_subscribed_qos_profile, 0,
|
|
|
|
&eps_subscribed_qos_profile);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_qos_class_identifier, 0,
|
|
|
|
&qos_class_identifier);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-11 08:16:35 +00:00
|
|
|
val.i32 = pdn->qos.qci;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(qos_class_identifier, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(eps_subscribed_qos_profile,
|
|
|
|
MSG_BRW_LAST_CHILD, qos_class_identifier);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
/* Set Allocation retention priority */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_allocation_retention_priority, 0,
|
|
|
|
&allocation_retention_priority);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_priority_level, 0, &priority_level);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-22 05:07:37 +00:00
|
|
|
val.u32 = pdn->qos.arp.priority_level;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(priority_level, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(allocation_retention_priority,
|
|
|
|
MSG_BRW_LAST_CHILD, priority_level);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
|
|
|
|
ret = fd_msg_avp_new(s6a_pre_emption_capability, 0,
|
|
|
|
&pre_emption_capability);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-22 05:07:37 +00:00
|
|
|
val.u32 = pdn->qos.arp.pre_emption_capability;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(pre_emption_capability, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(allocation_retention_priority,
|
|
|
|
MSG_BRW_LAST_CHILD, pre_emption_capability);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
|
|
|
|
ret = fd_msg_avp_new(s6a_pre_emption_vulnerability, 0,
|
|
|
|
&pre_emption_vulnerability);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-22 05:07:37 +00:00
|
|
|
val.u32 = pdn->qos.arp.pre_emption_vulnerability;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(pre_emption_vulnerability, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(allocation_retention_priority,
|
|
|
|
MSG_BRW_LAST_CHILD, pre_emption_vulnerability);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(eps_subscribed_qos_profile,
|
|
|
|
MSG_BRW_LAST_CHILD, allocation_retention_priority);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(apn_configuration,
|
|
|
|
MSG_BRW_LAST_CHILD, eps_subscribed_qos_profile);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2017-08-28 11:32:25 +00:00
|
|
|
/* Set MIP6-Agent-Info */
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pdn->pgw_ip.ipv4 || pdn->pgw_ip.ipv6) {
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(fd_mip6_agent_info, 0,
|
|
|
|
&mip6_agent_info);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-12-15 04:47:57 +00:00
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pdn->pgw_ip.ipv4) {
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(fd_mip_home_agent_address, 0,
|
|
|
|
&mip_home_agent_address);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-12-15 04:47:57 +00:00
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
sin.sin_addr.s_addr = pdn->pgw_ip.both.addr;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_value_encode (
|
|
|
|
&sin, mip_home_agent_address );
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(mip6_agent_info,
|
|
|
|
MSG_BRW_LAST_CHILD, mip_home_agent_address);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-12-15 04:47:57 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pdn->pgw_ip.ipv6) {
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(fd_mip_home_agent_address, 0,
|
|
|
|
&mip_home_agent_address);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-12-15 04:47:57 +00:00
|
|
|
sin6.sin6_family = AF_INET6;
|
|
|
|
memcpy(sin6.sin6_addr.s6_addr, pdn->pgw_ip.both.addr6,
|
|
|
|
sizeof pdn->pgw_ip.both.addr6);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_value_encode (
|
|
|
|
&sin6, mip_home_agent_address );
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(mip6_agent_info,
|
|
|
|
MSG_BRW_LAST_CHILD, mip_home_agent_address);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-12-15 04:47:57 +00:00
|
|
|
}
|
2017-08-28 11:32:25 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(apn_configuration,
|
|
|
|
MSG_BRW_LAST_CHILD, mip6_agent_info);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-28 11:32:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 00:44:42 +00:00
|
|
|
/* Set AMBR */
|
2019-06-11 14:16:54 +00:00
|
|
|
if (pdn->ambr.downlink || pdn->ambr.uplink) {
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_ambr, 0, &avp_ambr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_max_bandwidth_ul, 0,
|
|
|
|
&avp_max_bandwidth_ul);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-24 14:10:36 +00:00
|
|
|
val.u32 = pdn->ambr.uplink;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp_max_bandwidth_ul, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp_ambr, MSG_BRW_LAST_CHILD,
|
|
|
|
avp_max_bandwidth_ul);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(s6a_max_bandwidth_dl, 0,
|
|
|
|
&avp_max_bandwidth_dl);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-24 14:10:36 +00:00
|
|
|
val.u32 = pdn->ambr.downlink;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp_max_bandwidth_dl, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp_ambr, MSG_BRW_LAST_CHILD,
|
|
|
|
avp_max_bandwidth_dl);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
|
|
|
|
ret = fd_msg_avp_add(apn_configuration,
|
|
|
|
MSG_BRW_LAST_CHILD, avp_ambr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-24 14:10:36 +00:00
|
|
|
}
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(apn_configuration_profile,
|
|
|
|
MSG_BRW_LAST_CHILD, apn_configuration);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
}
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD,
|
|
|
|
apn_configuration_profile);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-27 08:38:57 +00:00
|
|
|
/* Set Vendor-Specific-Application-Id AVP */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_message_vendor_specific_appid_set(ans, S6A_APPLICATION_ID);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-27 08:38:57 +00:00
|
|
|
|
2017-07-22 00:44:42 +00:00
|
|
|
/* Send the answer */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_send(msg, NULL, NULL);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-22 15:00:57 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_debug("[HSS] Update-Location-Answer\n");
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
/* Add this value to the stats */
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert( pthread_mutex_lock(&fd_logger_self()->stats_lock) == 0);
|
2017-08-17 00:43:33 +00:00
|
|
|
fd_logger_self()->stats.nb_echoed++;
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert( pthread_mutex_unlock(&fd_logger_self()->stats_lock) == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_message_experimental_rescode_set(ans, result_code);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-27 08:38:57 +00:00
|
|
|
|
|
|
|
/* Set the Auth-Session-State AVP */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_new(fd_auth_session_state, 0, &avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-27 08:38:57 +00:00
|
|
|
val.i32 = 1;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_setvalue(avp, &val);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-27 08:38:57 +00:00
|
|
|
|
|
|
|
/* Set Vendor-Specific-Application-Id AVP */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_message_vendor_specific_appid_set(ans, S6A_APPLICATION_ID);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-27 08:38:57 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_msg_send(msg, NULL, NULL);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int hss_fd_init(void)
|
2017-07-22 00:44:42 +00:00
|
|
|
{
|
2018-01-10 05:15:00 +00:00
|
|
|
int ret;
|
2017-07-22 00:44:42 +00:00
|
|
|
struct disp_when data;
|
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_init(FD_MODE_SERVER,
|
|
|
|
hss_self()->fd_conf_path, hss_self()->fd_config);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-17 00:43:33 +00:00
|
|
|
|
2017-08-05 05:23:37 +00:00
|
|
|
/* Install objects definitions for this application */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = s6a_dict_init();
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-05 05:23:37 +00:00
|
|
|
|
2017-07-22 00:44:42 +00:00
|
|
|
memset(&data, 0, sizeof(data));
|
2017-08-09 03:52:11 +00:00
|
|
|
data.app = s6a_application;
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-15 08:25:14 +00:00
|
|
|
/* Fallback CB if command != unexpected message received */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_disp_register(hss_s6a_fb_cb, DISP_HOW_APPID, &data, NULL,
|
|
|
|
&hdl_s6a_fb);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-15 08:25:14 +00:00
|
|
|
/* Specific handler for Authentication-Information-Request */
|
2017-07-22 00:44:42 +00:00
|
|
|
data.command = s6a_cmd_air;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_disp_register(hss_s6a_air_cb, DISP_HOW_CC, &data, NULL,
|
|
|
|
&hdl_s6a_air);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2018-01-15 08:25:14 +00:00
|
|
|
/* Specific handler for Location-Update-Request */
|
2017-07-22 00:44:42 +00:00
|
|
|
data.command = s6a_cmd_ulr;
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_disp_register(hss_s6a_ulr_cb, DISP_HOW_CC, &data, NULL,
|
|
|
|
&hdl_s6a_ulr);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-07-22 00:44:42 +00:00
|
|
|
|
2017-08-05 05:23:37 +00:00
|
|
|
/* Advertise the support for the application in the peer */
|
2018-01-10 05:15:00 +00:00
|
|
|
ret = fd_disp_app_support(s6a_application, fd_vendor, 1, 0);
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(ret == 0);
|
2017-08-05 05:23:37 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2017-07-22 00:44:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 11:31:08 +00:00
|
|
|
void hss_fd_final(void)
|
2017-07-22 00:44:42 +00:00
|
|
|
{
|
2018-01-08 11:09:13 +00:00
|
|
|
if (hdl_s6a_fb)
|
2017-08-25 11:31:08 +00:00
|
|
|
(void) fd_disp_unregister(&hdl_s6a_fb, NULL);
|
2018-01-08 11:09:13 +00:00
|
|
|
if (hdl_s6a_air)
|
2017-08-25 11:31:08 +00:00
|
|
|
(void) fd_disp_unregister(&hdl_s6a_air, NULL);
|
2018-01-08 11:09:13 +00:00
|
|
|
if (hdl_s6a_ulr)
|
2017-08-25 11:31:08 +00:00
|
|
|
(void) fd_disp_unregister(&hdl_s6a_ulr, NULL);
|
2017-08-17 00:43:33 +00:00
|
|
|
|
|
|
|
fd_final();
|
2017-07-22 00:44:42 +00:00
|
|
|
}
|