update it

This commit is contained in:
Sukchan Lee 2017-03-03 14:10:06 +09:00
parent 3cc810e74f
commit 13bb654552
3 changed files with 49 additions and 74 deletions

View File

@ -9,32 +9,8 @@
#include "hss_ctx.h"
#include "s6a_app.h"
static struct disp_hdl *hss_hdl_fb = NULL; /* handler for fallback cb */
static struct disp_hdl *hss_hdl_tr = NULL; /* handler for Test-Request req cb */
static void hss_auth_send_err_msg(struct msg **msg)
{
struct msg *ans;
d_assert(fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0) == 0
&& *msg, goto out1,);
ans = *msg;
/* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */
d_assert(fd_msg_rescode_set(ans, "DIAMETER_AUTHENTICATION_REJECTED",
NULL, NULL, 1) == 0, goto out2,);
/* Send the answer */
d_assert(fd_msg_send(msg, NULL, NULL) == 0, goto out2,);
return;
out2:
d_assert(fd_msg_free(ans) == 0,,);
out1:
return;
}
static struct disp_hdl *hdl_fb = NULL; /* handler for fallback cb */
static struct disp_hdl *hdl_air = NULL; /* handler for Auth-Info-Request cb */
/* Default callback for the application. */
static int hss_fb_cb(struct msg **msg, struct avp *avp,
@ -65,15 +41,23 @@ static int hss_air_cb( struct msg **msg, struct avp *avp,
d_assert(msg, return EINVAL,);
/* Parse request message */
/* Create answer header */
qry = *msg;
fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0);
ans = *msg;
d_assert(fd_msg_search_avp(qry, s6a_user_name, &avp) && avp, goto out1,);
d_assert(fd_msg_avp_hdr(avp, &hdr) && hdr,,);
d_assert(fd_msg_search_avp(qry, s6a_user_name, &avp) == 0 && avp, goto out,);
d_assert(fd_msg_avp_hdr(avp, &hdr) == 0 && hdr,,);
ue = hss_ue_ctx_find_by_imsi(
hdr->avp_value->os.data, hdr->avp_value->os.len);
d_assert(ue, goto out1,);
if (!ue)
{
char imsi[MAX_IMSI_LEN];
strncpy(imsi, (char*)hdr->avp_value->os.data, hdr->avp_value->os.len);
d_warn("Cannot find IMSI:%s\n", imsi);
goto out;
}
core_generate_random_bytes(ue->rand, MAX_KEY_LEN);
milenage_opc(ue->k, hss_self()->op, ue->opc);
@ -88,79 +72,70 @@ static int hss_air_cb( struct msg **msg, struct avp *avp,
ue->seq = (ue->seq + 32) & 0x7ffffffffff;
/* Create answer header */
d_assert(fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0) == 0
&& *msg, goto out1,);
ans = *msg;
/* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */
d_assert(fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1) == 0,
goto out2,);
goto out,);
/* Set the Auth-Session-Statee AVP */
d_assert(fd_msg_avp_new(s6a_auth_session_state, 0, &avp) == 0, goto out2,);
d_assert(fd_msg_avp_new(s6a_auth_session_state, 0, &avp) == 0, goto out,);
val.i32 = 1;
d_assert(fd_msg_avp_setvalue(avp, &val) == 0, goto out2,);
d_assert(fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp) == 0, goto out2,);
d_assert(fd_msg_avp_setvalue(avp, &val) == 0, goto out,);
d_assert(fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp) == 0, goto out,);
/* Set the Authentication-Info */
d_assert(fd_msg_avp_new(s6a_authentication_info, 0, &avp) == 0, goto out2,);
d_assert(fd_msg_avp_new(s6a_e_utran_vector, 0, &avpch1) == 0, goto out2,);
d_assert(fd_msg_avp_new(s6a_authentication_info, 0, &avp) == 0, goto out,);
d_assert(fd_msg_avp_new(s6a_e_utran_vector, 0, &avpch1) == 0, goto out,);
#define TEST_RAND "RAND_123456"
d_assert(fd_msg_avp_new(s6a_rand, 0, &avpch2) == 0, goto out2,);
d_assert(fd_msg_avp_new(s6a_rand, 0, &avpch2) == 0, goto out,);
val.os.data = (unsigned char*)TEST_RAND;
val.os.len = strlen(TEST_RAND);
d_assert(fd_msg_avp_setvalue(avpch2, &val) == 0, goto out2,);
d_assert(fd_msg_avp_setvalue(avpch2, &val) == 0, goto out,);
d_assert(fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2) == 0,
goto out2,);
goto out,);
#define TEST_XRES "XRES_123456"
d_assert(fd_msg_avp_new(s6a_xres, 0, &avpch2) == 0, goto out2,);
d_assert(fd_msg_avp_new(s6a_xres, 0, &avpch2) == 0, goto out,);
val.os.data = (unsigned char*)TEST_XRES;
val.os.len = strlen(TEST_XRES);
d_assert(fd_msg_avp_setvalue(avpch2, &val) == 0, goto out2,);
d_assert(fd_msg_avp_setvalue(avpch2, &val) == 0, goto out,);
d_assert(fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2) == 0,
goto out2,);
goto out,);
#define TEST_AUTH "AUTH_123456"
d_assert(fd_msg_avp_new(s6a_autn, 0, &avpch2) == 0, goto out2,);
d_assert(fd_msg_avp_new(s6a_autn, 0, &avpch2) == 0, goto out,);
val.os.data = (unsigned char*)TEST_AUTH;
val.os.len = strlen(TEST_AUTH);
d_assert(fd_msg_avp_setvalue(avpch2, &val) == 0, goto out2,);
d_assert(fd_msg_avp_setvalue(avpch2, &val) == 0, goto out,);
d_assert(fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2) == 0,
goto out2,);
goto out,);
#define TEST_KASME "KASME_123456"
d_assert(fd_msg_avp_new(s6a_kasme, 0, &avpch2) == 0, goto out2,);
d_assert(fd_msg_avp_new(s6a_kasme, 0, &avpch2) == 0, goto out,);
val.os.data = (unsigned char*)TEST_KASME;
val.os.len = strlen(TEST_KASME);
d_assert(fd_msg_avp_setvalue(avpch2, &val) == 0, goto out2,);
d_assert(fd_msg_avp_setvalue(avpch2, &val) == 0, goto out,);
d_assert(fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2) == 0,
goto out2,);
goto out,);
d_assert(fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avpch1) == 0, goto out2,);
d_assert(fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp) == 0, goto out2,);
d_assert(fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avpch1) == 0, goto out,);
d_assert(fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp) == 0, goto out,);
/* Send the answer */
d_assert(fd_msg_send(msg, NULL, NULL) == 0, goto out2,);
fd_msg_send(msg, NULL, NULL);
/* Add this value to the stats */
d_assert(pthread_mutex_lock(&s6a_config->stats_lock) == 0,,) ;
pthread_mutex_lock(&s6a_config->stats_lock);
s6a_config->stats.nb_echoed++;
d_assert(pthread_mutex_unlock(&s6a_config->stats_lock) == 0,,);
d_assert(fd_msg_free(qry) == 0,,);
pthread_mutex_unlock(&s6a_config->stats_lock);
return 0;
out2:
d_assert(fd_msg_free(ans) == 0,,);
out1:
hss_auth_send_err_msg(msg);
d_assert(fd_msg_free(qry) == 0,,);
out:
fd_msg_rescode_set(ans, "DIAMETER_AUTHENTICATION_REJECTED", NULL, NULL, 1);
fd_msg_send(msg, NULL, NULL);
return -1;
return 0;
}
int hss_init(void)
@ -201,22 +176,22 @@ int hss_init(void)
/* fallback CB if command != unexpected message received */
d_assert(fd_disp_register(hss_fb_cb, DISP_HOW_APPID, &data, NULL,
&hss_hdl_fb) == 0, return -1,);
&hdl_fb) == 0, return -1,);
/* Now specific handler for Authentication-Information-Request */
d_assert(fd_disp_register(hss_air_cb, DISP_HOW_CC, &data, NULL,
&hss_hdl_tr) == 0, return -1,);
&hdl_air) == 0, return -1,);
return 0;
}
void hss_final(void)
{
if (hss_hdl_fb) {
(void) fd_disp_unregister(&hss_hdl_fb, NULL);
if (hdl_fb) {
(void) fd_disp_unregister(&hdl_fb, NULL);
}
if (hss_hdl_tr) {
(void) fd_disp_unregister(&hss_hdl_tr, NULL);
if (hdl_air) {
(void) fd_disp_unregister(&hdl_air, NULL);
}
/* FIXME : this is a sample UE for testing */

View File

@ -14,7 +14,7 @@ int s6a_fd_init(const char *conffile)
{
int ret;
d_trace_level(&_s6a_fd, 100);
d_trace_level(&_s6a_fd, 0);
gnutls_global_set_log_function(s6a_gnutls_log_func);
gnutls_global_set_log_level(TRACE_MODULE);

2
main.c
View File

@ -55,7 +55,7 @@ static int check_signal(int signum)
s6a_auth_info_req_t air;
memset(&air, 0, sizeof(s6a_auth_info_req_t));
#define TEST_IMSI "01045238277"
#define TEST_IMSI "001010123456800"
air.imsi_len = strlen(TEST_IMSI);
strcpy((char*)air.imsi, TEST_IMSI);
air.visited_plmn_id.mcc = 1;