update it
This commit is contained in:
parent
6000a4305c
commit
3ee227328b
|
@ -5,6 +5,10 @@
|
|||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define MAX_UE_PER_ENB 128
|
||||
#define MAX_NUM_OF_ENB 128
|
||||
#define MAX_NUM_OF_UE (MAX_NUM_OF_ENB * MAX_UE_PER_ENB)
|
||||
|
||||
#define IPV6_LEN 16
|
||||
|
||||
#define MAX_SDU_LEN 2048
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
__type *free[__size], pool[__size]; \
|
||||
mutex_id mut; \
|
||||
} pool_##__name##_t; \
|
||||
static pool_##__name##_t __name
|
||||
pool_##__name##_t __name
|
||||
|
||||
#define pool_init(__pname, __size) do { \
|
||||
int __i; \
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
static hss_ctx_t self;
|
||||
|
||||
pool_declare(ue_pool, ue_ctx_t, SIZE_OF_UE_POOL);
|
||||
pool_declare(user_pool, user_ctx_t, MAX_NUM_OF_UE);
|
||||
|
||||
static list_t g_ue_list;
|
||||
static list_t g_user_list;
|
||||
|
||||
hss_ctx_t* hss_self()
|
||||
{
|
||||
|
@ -24,9 +24,9 @@ hss_ctx_t* hss_self()
|
|||
status_t hss_ctx_init(void)
|
||||
{
|
||||
char buf[HSS_KEY_LEN];
|
||||
ue_ctx_t *ue;
|
||||
user_ctx_t *user;
|
||||
|
||||
pool_init(&ue_pool, SIZE_OF_UE_POOL);
|
||||
pool_init(&user_pool, MAX_NUM_OF_UE);
|
||||
|
||||
memset(&self, 0, sizeof(hss_ctx_t));
|
||||
|
||||
|
@ -40,115 +40,115 @@ status_t hss_ctx_init(void)
|
|||
#define UE3_IMSI "001010123456819"
|
||||
#define UE3_RAND "20080c3818183b52 2614162c07601d0d"
|
||||
|
||||
ue = hss_ctx_ue_add();
|
||||
d_assert(ue, return -1, "UE context add failed");
|
||||
user = hss_ctx_user_add();
|
||||
d_assert(user, return -1, "UE context add failed");
|
||||
|
||||
strcpy((char*)ue->imsi, UE1_IMSI);
|
||||
ue->imsi_len = strlen(UE1_IMSI);
|
||||
memcpy(ue->k, CORE_HEX(K, strlen(K), buf), HSS_KEY_LEN);
|
||||
core_generate_random_bytes(ue->rand, RAND_LEN);
|
||||
ue->sqn = 64;
|
||||
strcpy((char*)user->imsi, UE1_IMSI);
|
||||
user->imsi_len = strlen(UE1_IMSI);
|
||||
memcpy(user->k, CORE_HEX(K, strlen(K), buf), HSS_KEY_LEN);
|
||||
core_generate_random_bytes(user->rand, RAND_LEN);
|
||||
user->sqn = 64;
|
||||
|
||||
ue = hss_ctx_ue_add();
|
||||
d_assert(ue, return -1, "UE context add failed");
|
||||
user = hss_ctx_user_add();
|
||||
d_assert(user, return -1, "UE context add failed");
|
||||
|
||||
strcpy((char*)ue->imsi, UE2_IMSI);
|
||||
ue->imsi_len = strlen(UE2_IMSI);
|
||||
memcpy(ue->k, CORE_HEX(K, strlen(K), buf), HSS_KEY_LEN);
|
||||
core_generate_random_bytes(ue->rand, RAND_LEN);
|
||||
ue->sqn = 64;
|
||||
strcpy((char*)user->imsi, UE2_IMSI);
|
||||
user->imsi_len = strlen(UE2_IMSI);
|
||||
memcpy(user->k, CORE_HEX(K, strlen(K), buf), HSS_KEY_LEN);
|
||||
core_generate_random_bytes(user->rand, RAND_LEN);
|
||||
user->sqn = 64;
|
||||
|
||||
ue = hss_ctx_ue_add();
|
||||
d_assert(ue, return -1, "UE context add failed");
|
||||
user = hss_ctx_user_add();
|
||||
d_assert(user, return -1, "UE context add failed");
|
||||
|
||||
strcpy((char*)ue->imsi, UE3_IMSI);
|
||||
ue->imsi_len = strlen(UE3_IMSI);
|
||||
memcpy(ue->k, CORE_HEX(K, strlen(K), buf), HSS_KEY_LEN);
|
||||
memcpy(ue->rand, CORE_HEX(UE3_RAND, strlen(UE3_RAND), buf),
|
||||
strcpy((char*)user->imsi, UE3_IMSI);
|
||||
user->imsi_len = strlen(UE3_IMSI);
|
||||
memcpy(user->k, CORE_HEX(K, strlen(K), buf), HSS_KEY_LEN);
|
||||
memcpy(user->rand, CORE_HEX(UE3_RAND, strlen(UE3_RAND), buf),
|
||||
RAND_LEN);
|
||||
ue->sqn = 64;
|
||||
user->sqn = 64;
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
void hss_ctx_final(void)
|
||||
{
|
||||
hss_ctx_ue_remove_all();
|
||||
hss_ctx_user_remove_all();
|
||||
|
||||
pool_final(&ue_pool);
|
||||
pool_final(&user_pool);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ue_ctx_t* hss_ctx_ue_add()
|
||||
user_ctx_t* hss_ctx_user_add()
|
||||
{
|
||||
ue_ctx_t *ue = NULL;
|
||||
user_ctx_t *user = NULL;
|
||||
|
||||
/* Allocate new eNB context */
|
||||
pool_alloc_node(&ue_pool, &ue);
|
||||
d_assert(ue, return NULL, "HSS-UE context allocation failed");
|
||||
pool_alloc_node(&user_pool, &user);
|
||||
d_assert(user, return NULL, "HSS-UE context allocation failed");
|
||||
|
||||
/* Initialize eNB context */
|
||||
memset(ue, 0, sizeof(ue_ctx_t));
|
||||
memset(user, 0, sizeof(user_ctx_t));
|
||||
|
||||
/* Add new eNB context to list */
|
||||
list_append(&g_ue_list, ue);
|
||||
list_append(&g_user_list, user);
|
||||
|
||||
memcpy(ue->op, self.op, HSS_KEY_LEN);
|
||||
memcpy(ue->amf, self.amf, HSS_AMF_LEN);
|
||||
memcpy(user->op, self.op, HSS_KEY_LEN);
|
||||
memcpy(user->amf, self.amf, HSS_AMF_LEN);
|
||||
|
||||
return ue;
|
||||
return user;
|
||||
}
|
||||
|
||||
status_t hss_ctx_ue_remove(ue_ctx_t *ue)
|
||||
status_t hss_ctx_user_remove(user_ctx_t *user)
|
||||
{
|
||||
d_assert(ue, return CORE_ERROR, "Null param");
|
||||
d_assert(user, return CORE_ERROR, "Null param");
|
||||
|
||||
list_remove(&g_ue_list, ue);
|
||||
pool_free_node(&ue_pool, ue);
|
||||
list_remove(&g_user_list, user);
|
||||
pool_free_node(&user_pool, user);
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t hss_ctx_ue_remove_all()
|
||||
status_t hss_ctx_user_remove_all()
|
||||
{
|
||||
ue_ctx_t *ue = NULL, *next_ue = NULL;
|
||||
user_ctx_t *user = NULL, *next_user = NULL;
|
||||
|
||||
ue = list_first(&g_ue_list);
|
||||
while (ue)
|
||||
user = list_first(&g_user_list);
|
||||
while (user)
|
||||
{
|
||||
next_ue = list_next(ue);
|
||||
next_user = list_next(user);
|
||||
|
||||
hss_ctx_ue_remove(ue);
|
||||
hss_ctx_user_remove(user);
|
||||
|
||||
ue = next_ue;
|
||||
user = next_user;
|
||||
}
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
ue_ctx_t* hss_ctx_ue_find_by_imsi(c_uint8_t *imsi, c_uint8_t imsi_len)
|
||||
user_ctx_t* hss_ctx_user_find_by_imsi(c_uint8_t *imsi, c_uint8_t imsi_len)
|
||||
{
|
||||
ue_ctx_t *ue = NULL;
|
||||
user_ctx_t *user = NULL;
|
||||
|
||||
ue = list_first(&g_ue_list);
|
||||
while (ue)
|
||||
user = list_first(&g_user_list);
|
||||
while (user)
|
||||
{
|
||||
if (memcmp(ue->imsi, imsi, imsi_len) == 0)
|
||||
if (memcmp(user->imsi, imsi, imsi_len) == 0)
|
||||
break;
|
||||
|
||||
ue = list_next(ue);
|
||||
user = list_next(user);
|
||||
}
|
||||
|
||||
return ue;
|
||||
return user;
|
||||
}
|
||||
|
||||
ue_ctx_t* hss_ctx_ue_first()
|
||||
user_ctx_t* hss_ctx_user_first()
|
||||
{
|
||||
return list_first(&g_ue_list);
|
||||
return list_first(&g_user_list);
|
||||
}
|
||||
|
||||
ue_ctx_t* hss_ctx_ue_next(ue_ctx_t *ue)
|
||||
user_ctx_t* hss_ctx_user_next(user_ctx_t *user)
|
||||
{
|
||||
return list_next(ue);
|
||||
return list_next(user);
|
||||
}
|
||||
|
|
|
@ -9,12 +9,10 @@
|
|||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define SIZE_OF_UE_POOL 128
|
||||
|
||||
#define HSS_KEY_LEN 16
|
||||
#define HSS_AMF_LEN 2
|
||||
|
||||
typedef struct _ue_ctx_t {
|
||||
typedef struct _user_ctx_t {
|
||||
lnode_t node; /**< A node of list_t */
|
||||
|
||||
c_uint8_t imsi[MAX_IMSI_LEN+1];
|
||||
|
@ -26,7 +24,7 @@ typedef struct _ue_ctx_t {
|
|||
c_uint8_t opc[HSS_KEY_LEN];
|
||||
c_uint8_t op[HSS_KEY_LEN];
|
||||
c_uint8_t amf[HSS_AMF_LEN];
|
||||
} ue_ctx_t;
|
||||
} user_ctx_t;
|
||||
|
||||
typedef struct _hss_ctx_t {
|
||||
c_uint8_t op[HSS_KEY_LEN];
|
||||
|
@ -39,13 +37,13 @@ CORE_DECLARE(hss_ctx_t*) hss_self(void);
|
|||
CORE_DECLARE(status_t) hss_ctx_init(void);
|
||||
CORE_DECLARE(void) hss_ctx_final(void);
|
||||
|
||||
CORE_DECLARE(ue_ctx_t*) hss_ctx_ue_add(void);
|
||||
CORE_DECLARE(status_t) hss_ctx_ue_remove(ue_ctx_t *ue);
|
||||
CORE_DECLARE(status_t) hss_ctx_ue_remove_all(void);
|
||||
CORE_DECLARE(ue_ctx_t*) hss_ctx_ue_find_by_imsi(
|
||||
CORE_DECLARE(user_ctx_t*) hss_ctx_user_add(void);
|
||||
CORE_DECLARE(status_t) hss_ctx_user_remove(user_ctx_t *user);
|
||||
CORE_DECLARE(status_t) hss_ctx_user_remove_all(void);
|
||||
CORE_DECLARE(user_ctx_t*) hss_ctx_user_find_by_imsi(
|
||||
c_uint8_t *imsi, c_uint8_t imsi_len);
|
||||
CORE_DECLARE(ue_ctx_t*) hss_ctx_ue_first(void);
|
||||
CORE_DECLARE(ue_ctx_t*) hss_ctx_ue_next(ue_ctx_t *ue);
|
||||
CORE_DECLARE(user_ctx_t*) hss_ctx_user_first(void);
|
||||
CORE_DECLARE(user_ctx_t*) hss_ctx_user_next(user_ctx_t *user);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ static int hss_air_cb( struct msg **msg, struct avp *avp,
|
|||
struct avp_hdr *hdr;
|
||||
union avp_value val;
|
||||
|
||||
ue_ctx_t *ue = NULL;
|
||||
user_ctx_t *user = NULL;
|
||||
c_uint8_t sqn[HSS_SQN_LEN];
|
||||
c_uint8_t autn[AUTN_LEN];
|
||||
c_uint8_t ik[HSS_KEY_LEN];
|
||||
|
@ -56,9 +56,9 @@ static int hss_air_cb( struct msg **msg, struct avp *avp,
|
|||
goto out,);
|
||||
d_assert(fd_msg_avp_hdr(avp, &hdr) == 0 && hdr,,);
|
||||
|
||||
ue = hss_ctx_ue_find_by_imsi(
|
||||
user = hss_ctx_user_find_by_imsi(
|
||||
hdr->avp_value->os.data, hdr->avp_value->os.len);
|
||||
if (!ue)
|
||||
if (!user)
|
||||
{
|
||||
char imsi[MAX_IMSI_LEN];
|
||||
strncpy(imsi, (char*)hdr->avp_value->os.data, hdr->avp_value->os.len);
|
||||
|
@ -70,13 +70,13 @@ static int hss_air_cb( struct msg **msg, struct avp *avp,
|
|||
avp, goto out,);
|
||||
d_assert(fd_msg_avp_hdr(avp, &hdr) == 0 && hdr,,);
|
||||
|
||||
milenage_opc(ue->k, ue->op, ue->opc);
|
||||
milenage_generate(ue->opc, ue->amf, ue->k,
|
||||
core_uint64_to_buffer(ue->sqn, HSS_SQN_LEN, sqn), ue->rand,
|
||||
milenage_opc(user->k, user->op, user->opc);
|
||||
milenage_generate(user->opc, user->amf, user->k,
|
||||
core_uint64_to_buffer(user->sqn, HSS_SQN_LEN, sqn), user->rand,
|
||||
autn, ik, ck, ak, xres, &xres_len);
|
||||
hss_kdf_kasme(ck, ik, hdr->avp_value->os.data, sqn, ak, kasme);
|
||||
|
||||
ue->sqn = (ue->sqn + 32) & 0x7ffffffffff;
|
||||
user->sqn = (user->sqn + 32) & 0x7ffffffffff;
|
||||
|
||||
/* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */
|
||||
d_assert(fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1) == 0,
|
||||
|
@ -93,7 +93,7 @@ static int hss_air_cb( struct msg **msg, struct avp *avp,
|
|||
d_assert(fd_msg_avp_new(s6a_e_utran_vector, 0, &avpch1) == 0, goto out,);
|
||||
|
||||
d_assert(fd_msg_avp_new(s6a_rand, 0, &avpch2) == 0, goto out,);
|
||||
val.os.data = ue->rand;
|
||||
val.os.data = user->rand;
|
||||
val.os.len = HSS_KEY_LEN;
|
||||
d_assert(fd_msg_avp_setvalue(avpch2, &val) == 0, goto out,);
|
||||
d_assert(fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2) == 0,
|
||||
|
|
|
@ -9,26 +9,20 @@
|
|||
|
||||
#include "mme_ctx.h"
|
||||
|
||||
#define CELL_PER_ENB 8
|
||||
#define UE_PER_ENB 128
|
||||
#define ERAB_PER_UE 16
|
||||
#define S11_PER_UE 8
|
||||
#define MAX_CELL_PER_ENB 8
|
||||
#define MAX_ERAB_PER_UE 16
|
||||
|
||||
#define SIZE_OF_SGW_POOL 8
|
||||
#define SIZE_OF_ENB_POOL 128
|
||||
#define SIZE_OF_UE_POOL (SIZE_OF_ENB_POOL * UE_PER_ENB)
|
||||
#define SIZE_OF_ERAB_POOL (SIZE_OF_UE_POOL * ERAB_PER_UE)
|
||||
#define SIZE_OF_S11_POOL (SIZE_OF_UE_POOL * S11_PER_UE)
|
||||
#define MAX_NUM_OF_SGW 8
|
||||
#define MAX_NUM_OF_ERAB (MAX_NUM_OF_UE * MAX_ERAB_PER_UE)
|
||||
|
||||
#define S1AP_SCTP_PORT 36412
|
||||
|
||||
static mme_ctx_t self;
|
||||
|
||||
pool_declare(sgw_pool, sgw_ctx_t, SIZE_OF_SGW_POOL);
|
||||
pool_declare(enb_pool, enb_ctx_t, SIZE_OF_ENB_POOL);
|
||||
pool_declare(ue_pool, ue_ctx_t, SIZE_OF_UE_POOL);
|
||||
pool_declare(erab_pool, erab_ctx_t, SIZE_OF_ERAB_POOL);
|
||||
pool_declare(s11_pool, s11_ctx_t, SIZE_OF_S11_POOL);
|
||||
pool_declare(sgw_pool, sgw_ctx_t, MAX_NUM_OF_SGW);
|
||||
pool_declare(enb_pool, enb_ctx_t, MAX_NUM_OF_ENB);
|
||||
pool_declare(ue_pool, ue_ctx_t, MAX_NUM_OF_UE);
|
||||
pool_declare(erab_pool, erab_ctx_t, MAX_NUM_OF_ERAB);
|
||||
|
||||
static int ctx_initialized = 0;
|
||||
|
||||
|
@ -40,11 +34,10 @@ status_t mme_ctx_init()
|
|||
d_assert(ctx_initialized == 0, return CORE_ERROR,
|
||||
"MME context already has been ctx_initialized");
|
||||
|
||||
pool_init(&sgw_pool, SIZE_OF_SGW_POOL);
|
||||
pool_init(&enb_pool, SIZE_OF_ENB_POOL);
|
||||
pool_init(&ue_pool, SIZE_OF_UE_POOL);
|
||||
pool_init(&erab_pool, SIZE_OF_ERAB_POOL);
|
||||
pool_init(&s11_pool, SIZE_OF_ERAB_POOL);
|
||||
pool_init(&sgw_pool, MAX_NUM_OF_SGW);
|
||||
pool_init(&enb_pool, MAX_NUM_OF_ENB);
|
||||
pool_init(&ue_pool, MAX_NUM_OF_UE);
|
||||
pool_init(&erab_pool, MAX_NUM_OF_ERAB);
|
||||
|
||||
list_init(&sgw_list);
|
||||
list_init(&enb_list);
|
||||
|
@ -99,7 +92,6 @@ status_t mme_ctx_final()
|
|||
pool_final(&enb_pool);
|
||||
pool_final(&ue_pool);
|
||||
pool_final(&erab_pool);
|
||||
pool_final(&s11_pool);
|
||||
|
||||
ctx_initialized = 0;
|
||||
|
||||
|
@ -299,7 +291,6 @@ status_t mme_ctx_ue_remove(ue_ctx_t *ue)
|
|||
d_assert(ue->enb, return CORE_ERROR, "Null param");
|
||||
|
||||
mme_ctx_erab_remove_all(ue);
|
||||
mme_ctx_s11_remove_all(ue);
|
||||
|
||||
if (FSM_STATE(&ue->emm_sm))
|
||||
{
|
||||
|
@ -449,81 +440,3 @@ erab_ctx_t* mme_ctx_erab_next(erab_ctx_t *erab)
|
|||
{
|
||||
return list_next(erab);
|
||||
}
|
||||
|
||||
s11_ctx_t* mme_ctx_s11_add(ue_ctx_t *ue)
|
||||
{
|
||||
s11_ctx_t *s11 = NULL;
|
||||
|
||||
d_assert(ue, return NULL, "Null param");
|
||||
|
||||
pool_alloc_node(&s11_pool, &s11);
|
||||
d_assert(s11, return NULL, "Null param");
|
||||
|
||||
memset(s11, 0, sizeof(s11_ctx_t));
|
||||
|
||||
s11->ue = ue;
|
||||
|
||||
list_append(&ue->s11_list, s11);
|
||||
|
||||
return s11;
|
||||
}
|
||||
|
||||
status_t mme_ctx_s11_remove(s11_ctx_t *s11)
|
||||
{
|
||||
d_assert(s11, return CORE_ERROR, "Null param");
|
||||
d_assert(s11->ue, return CORE_ERROR, "Null param");
|
||||
|
||||
if (FSM_STATE(&s11->s11_sm))
|
||||
{
|
||||
fsm_final((fsm_t*)&s11->s11_sm, 0);
|
||||
fsm_clear((fsm_t*)&s11->s11_sm);
|
||||
}
|
||||
|
||||
list_remove(&s11->ue->s11_list, s11);
|
||||
pool_free_node(&s11_pool, s11);
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t mme_ctx_s11_remove_all(ue_ctx_t *ue)
|
||||
{
|
||||
s11_ctx_t *s11 = NULL, *next_s11 = NULL;
|
||||
|
||||
s11 = mme_ctx_s11_first(ue);
|
||||
while (s11)
|
||||
{
|
||||
next_s11 = mme_ctx_s11_next(s11);
|
||||
|
||||
mme_ctx_s11_remove(s11);
|
||||
|
||||
s11 = next_s11;
|
||||
}
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
s11_ctx_t* mme_ctx_s11_find_by_teid(ue_ctx_t *ue, c_uint32_t teid)
|
||||
{
|
||||
s11_ctx_t *s11 = NULL;
|
||||
|
||||
s11 = mme_ctx_s11_first(ue);
|
||||
while (s11)
|
||||
{
|
||||
if (teid == s11->teid)
|
||||
break;
|
||||
|
||||
s11 = mme_ctx_s11_next(s11);
|
||||
}
|
||||
|
||||
return s11;
|
||||
}
|
||||
|
||||
s11_ctx_t* mme_ctx_s11_first(ue_ctx_t *ue)
|
||||
{
|
||||
return list_first(&ue->s11_list);
|
||||
}
|
||||
|
||||
s11_ctx_t* mme_ctx_s11_next(s11_ctx_t *s11)
|
||||
{
|
||||
return list_next(s11);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "mme_s6a_handler.h"
|
||||
|
||||
#define SIZE_OF_SESS_STATE_POOL 32
|
||||
#define MAX_NUM_SESSION_STATE 32
|
||||
|
||||
static struct session_handler *mme_s6a_reg = NULL;
|
||||
|
||||
|
@ -19,7 +19,7 @@ struct sess_state {
|
|||
struct timespec ts; /* Time of sending the message */
|
||||
};
|
||||
|
||||
pool_declare(sess_state_pool, struct sess_state, SIZE_OF_SESS_STATE_POOL);
|
||||
pool_declare(sess_state_pool, struct sess_state, MAX_NUM_SESSION_STATE);
|
||||
|
||||
static void mme_s6a_aia_cb(void *data, struct msg **msg);
|
||||
|
||||
|
@ -272,7 +272,7 @@ status_t mme_s6a_init(void)
|
|||
rv = s6a_init(MODE_MME);
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
pool_init(&sess_state_pool, SIZE_OF_SESS_STATE_POOL);
|
||||
pool_init(&sess_state_pool, MAX_NUM_SESSION_STATE);
|
||||
|
||||
d_assert(fd_sess_handler_create(&mme_s6a_reg,
|
||||
(void *)free, NULL, NULL) == 0, return -1,);
|
||||
|
|
Loading…
Reference in New Issue