add initial context setup response encoder for generating IPv6 packet

This commit is contained in:
Sukchan Lee 2017-12-08 23:58:50 +09:00
parent 9b5234bd5f
commit e8e6836ab8
7 changed files with 134 additions and 11 deletions

View File

@ -23,6 +23,8 @@ static inline int s1ap_encode_downlink_nas_transport(
s1ap_message_t *message_p, pkbuf_t *pkbuf);
static inline int s1ap_encode_initial_context_setup_request(
s1ap_message_t *message_p, pkbuf_t *pkbuf);
static inline int s1ap_encode_initial_context_setup_response(
s1ap_message_t *message_p, pkbuf_t *pkbuf);
static inline int s1ap_encode_e_rab_setup_request(
s1ap_message_t *message_p, pkbuf_t *pkbuf);
static inline int s1ap_encode_e_rab_release_command(
@ -180,6 +182,13 @@ static inline int s1ap_encode_successfull_outcome(
ret = s1ap_encode_s1setup_response(message_p, pkbuf);
break;
case S1ap_ProcedureCode_id_InitialContextSetup:
s1ap_encode_xer_print_message(
s1ap_xer_print_s1ap_initialcontextsetupresponse,
s1ap_xer__print2sp, message_p);
ret = s1ap_encode_initial_context_setup_response(message_p, pkbuf);
break;
case S1ap_ProcedureCode_id_PathSwitchRequest:
s1ap_encode_xer_print_message(
s1ap_xer_print_s1ap_pathswitchrequestacknowledge,
@ -437,6 +446,46 @@ static inline int s1ap_encode_initial_context_setup_request(
return enc_ret.encoded;
}
static inline int s1ap_encode_initial_context_setup_response(
s1ap_message_t *message_p, pkbuf_t *pkbuf)
{
asn_enc_rval_t enc_ret = {0};
S1AP_PDU_t pdu;
S1ap_InitialContextSetupResponse_t initialContextSetupResponse;
asn_TYPE_descriptor_t *td = &asn_DEF_S1ap_InitialContextSetupResponse;
memset(&initialContextSetupResponse, 0,
sizeof(S1ap_InitialContextSetupResponse_t));
if (s1ap_encode_s1ap_initialcontextsetupresponseies(
&initialContextSetupResponse,
&message_p->s1ap_InitialContextSetupResponseIEs) < 0)
{
d_error("Encoding of %s failed", td->name);
return -1;
}
memset(&pdu, 0, sizeof (S1AP_PDU_t));
pdu.present = S1AP_PDU_PR_successfulOutcome;
pdu.choice.initiatingMessage.procedureCode = message_p->procedureCode;
pdu.choice.initiatingMessage.criticality = S1ap_Criticality_reject;
ANY_fromType_aper(&pdu.choice.successfulOutcome.value,
td, &initialContextSetupResponse);
enc_ret = aper_encode_to_buffer(&asn_DEF_S1AP_PDU,
&pdu, pkbuf->payload, MAX_SDU_LEN);
ASN_STRUCT_FREE_CONTENTS_ONLY(*td, &initialContextSetupResponse);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_PDU, &pdu);
if (enc_ret.encoded < 0)
{
d_error("Encoding of %s failed", td->name);
}
return enc_ret.encoded;
}
static inline int s1ap_encode_e_rab_setup_request(
s1ap_message_t *message_p, pkbuf_t *pkbuf)
{

View File

@ -21,8 +21,6 @@ extern "C" {
typedef struct _gtp_node_t gtp_node_t;
typedef struct _pgw_context_t {
c_uint32_t pgw_addr; /* PGW local address */
c_uint32_t gtpc_port; /* PGW GTP-C local port */
c_uint32_t gtpu_port; /* PGW GTP-U local port */

View File

@ -277,7 +277,8 @@ static void attach_test1(abts_case *tc, void *data)
core_sleep(time_from_msec(300));
/* Send Initial Context Setup Response */
rv = tests1ap_build_initial_context_setup_response(&sendbuf, msgindex);
rv = tests1ap_build_initial_context_setup_response_static(
&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
@ -604,7 +605,8 @@ static void attach_test2(abts_case *tc, void *data)
core_sleep(time_from_msec(300));
/* Send Initial Context Setup Response */
rv = tests1ap_build_initial_context_setup_response(&sendbuf, msgindex);
rv = tests1ap_build_initial_context_setup_response_static(
&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
@ -895,7 +897,8 @@ static void attach_test3(abts_case *tc, void *data)
core_sleep(time_from_msec(300));
/* Send Initial Context Setup Response */
rv = tests1ap_build_initial_context_setup_response(&sendbuf, msgindex);
rv = tests1ap_build_initial_context_setup_response_static(
&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
@ -962,7 +965,8 @@ static void attach_test3(abts_case *tc, void *data)
core_sleep(time_from_msec(300));
/* Send Initial Context Setup Response */
rv = tests1ap_build_initial_context_setup_response(&sendbuf, msgindex+1);
rv = tests1ap_build_initial_context_setup_response_static(
&sendbuf, msgindex+1);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);

View File

@ -222,7 +222,8 @@ static void handover_test1(abts_case *tc, void *data)
core_sleep(time_from_msec(300));
/* Send Initial Context Setup Response */
rv = tests1ap_build_initial_context_setup_response(&sendbuf, msgindex);
rv = tests1ap_build_initial_context_setup_response_static(
&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock1, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
@ -554,7 +555,8 @@ static void handover_test2(abts_case *tc, void *data)
core_sleep(time_from_msec(300));
/* Send Initial Context Setup Response */
rv = tests1ap_build_initial_context_setup_response(&sendbuf, msgindex);
rv = tests1ap_build_initial_context_setup_response_static(
&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock1, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);

View File

@ -9,6 +9,7 @@
#include "s1ap_path.h"
#include "gtp_message.h"
#include "gtp_conv.h"
#include "gtp_node.h"
#include "gtp_path.h"
@ -684,7 +685,72 @@ status_t tests1ap_build_ue_capability_info_indication(pkbuf_t **pkbuf, int i)
return CORE_OK;
}
status_t tests1ap_build_initial_context_setup_response(pkbuf_t **pkbuf, int i)
status_t tests1ap_build_initial_context_setup_response(
pkbuf_t **pkbuf, c_uint8_t ebi, c_uint32_t teid)
{
int erval = -1;
status_t rv;
hash_index_t *hi = NULL;
mme_enb_t *enb = NULL;
enb_ue_t *enb_ue = NULL;
gtp_f_teid_t f_teid;
ip_t ip;
int len;
s1ap_message_t message;
S1ap_InitialContextSetupResponseIEs_t *ies = NULL;
S1ap_E_RABSetupItemCtxtSURes_t *e_rab = NULL;
memset(&message, 0, sizeof(s1ap_message_t));
ies = &message.s1ap_InitialContextSetupResponseIEs;
message.direction = S1AP_PDU_PR_successfulOutcome;
message.procedureCode = S1ap_ProcedureCode_id_InitialContextSetup;
hi = mme_enb_first();
d_assert(hi, return CORE_ERROR,);
enb = mme_enb_this(hi);
d_assert(enb, return CORE_ERROR,);
enb_ue = enb_ue_first_in_enb(enb);
d_assert(enb_ue, return CORE_ERROR,);
ies->mme_ue_s1ap_id = enb_ue->mme_ue_s1ap_id;
ies->eNB_UE_S1AP_ID = enb_ue->enb_ue_s1ap_id;
e_rab = (S1ap_E_RABSetupItemCtxtSURes_t *)
core_calloc(1, sizeof(S1ap_E_RABSetupItemCtxtSURes_t));
e_rab->e_RAB_ID = ebi;
d_assert(mme_self()->gtpc_addr, return CORE_ERROR,);
d_assert(mme_self()->gtpc_addr6, return CORE_ERROR,);
rv = gtp_sockaddr_to_f_teid(
mme_self()->gtpc_addr, mme_self()->gtpc_addr6, &f_teid, &len);
d_assert(rv == CORE_OK, return CORE_ERROR,);
rv = gtp_f_teid_to_ip(&f_teid, &ip);
d_assert(rv == CORE_OK, return CORE_ERROR,);
rv = s1ap_ip_to_BIT_STRING(&ip, &e_rab->transportLayerAddress);
d_assert(rv == CORE_OK, return CORE_ERROR,);
s1ap_uint32_to_OCTET_STRING(teid, &e_rab->gTP_TEID);
ASN_SEQUENCE_ADD(&ies->e_RABSetupListCtxtSURes, e_rab);
erval = s1ap_encode_pdu(pkbuf, &message);
s1ap_free_pdu(&message);
if (erval < 0)
{
d_error("s1ap_encode_error : (%d)", erval);
return CORE_ERROR;
}
return CORE_OK;
}
status_t tests1ap_build_initial_context_setup_response_static(
pkbuf_t **pkbuf, int i)
{
char *payload[TESTS1AP_MAX_MESSAGE] = {
"2009"

View File

@ -31,6 +31,8 @@ CORE_DECLARE(status_t) tests1ap_build_esm_information_response(
CORE_DECLARE(status_t) tests1ap_build_ue_capability_info_indication(
pkbuf_t **pkbuf, int i);
CORE_DECLARE(status_t) tests1ap_build_initial_context_setup_response(
pkbuf_t **pkbuf, c_uint8_t ebi, c_uint32_t teid);
CORE_DECLARE(status_t) tests1ap_build_initial_context_setup_response_static(
pkbuf_t **pkbuf, int i);
CORE_DECLARE(status_t) tests1ap_build_attach_complete(pkbuf_t **pkbuf, int i);
CORE_DECLARE(status_t) tests1ap_build_emm_status(pkbuf_t **pkbuf, int i);

View File

@ -197,7 +197,8 @@ static void volte_test1(abts_case *tc, void *data)
core_sleep(time_from_msec(300));
/* Send Initial Context Setup Response */
rv = tests1ap_build_initial_context_setup_response(&sendbuf, msgindex);
rv = tests1ap_build_initial_context_setup_response_static(
&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
@ -507,7 +508,8 @@ static void volte_test2(abts_case *tc, void *data)
core_sleep(time_from_msec(300));
/* Send Initial Context Setup Response */
rv = tests1ap_build_initial_context_setup_response(&sendbuf, msgindex);
rv = tests1ap_build_initial_context_setup_response_static(
&sendbuf, msgindex);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = tests1ap_enb_send(sock, sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);