encode S1AP example
This commit is contained in:
parent
37b99ef99e
commit
687daafd3f
|
@ -19,8 +19,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define EMIT_ASN_DEBUG 1
|
||||
|
||||
/* Environment version might be used to avoid running with the old library */
|
||||
#define ASN1C_ENVIRONMENT_VERSION 924 /* Compile-time version */
|
||||
int get_asn1c_environment_version(void); /* Run-time version */
|
||||
|
|
|
@ -12,6 +12,8 @@ static inline int s1ap_encode_unsuccessfull_outcome(
|
|||
|
||||
static inline int s1ap_encode_initial_context_setup_request(
|
||||
s1ap_message *message_p, pkbuf_t *pkbuf);
|
||||
static inline int s1ap_encode_s1setuprequest(
|
||||
s1ap_message *message_p, pkbuf_t *pkbuf);
|
||||
static inline int s1ap_encode_s1setupresponse(
|
||||
s1ap_message *message_p, pkbuf_t *pkbuf);
|
||||
static inline int s1ap_encode_s1setupfailure(
|
||||
|
@ -76,6 +78,9 @@ static inline int s1ap_encode_initiating(
|
|||
{
|
||||
switch (message_p->procedureCode)
|
||||
{
|
||||
case S1ap_ProcedureCode_id_S1Setup:
|
||||
return s1ap_encode_s1setuprequest(message_p, pkbuf);
|
||||
|
||||
case S1ap_ProcedureCode_id_downlinkNASTransport:
|
||||
return s1ap_encode_downlink_nas_transport(message_p, pkbuf);
|
||||
|
||||
|
@ -151,6 +156,25 @@ static inline int s1ap_encode_initial_context_setup_request(
|
|||
initialContextSetupRequest_p);
|
||||
}
|
||||
|
||||
static inline int s1ap_encode_s1setuprequest(
|
||||
s1ap_message *message_p, pkbuf_t *pkbuf)
|
||||
{
|
||||
S1ap_S1SetupRequest_t s1SetupRequest;
|
||||
S1ap_S1SetupRequest_t *s1SetupRequest_p = &s1SetupRequest;
|
||||
|
||||
memset((void *)s1SetupRequest_p, 0, sizeof(s1SetupRequest));
|
||||
|
||||
if (s1ap_encode_s1ap_s1setuprequesties(
|
||||
s1SetupRequest_p, &message_p->msg.s1ap_S1SetupRequestIEs) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return s1ap_generate_initiating_message(pkbuf,
|
||||
S1ap_ProcedureCode_id_S1Setup, S1ap_Criticality_reject,
|
||||
&asn_DEF_S1ap_S1SetupRequest, s1SetupRequest_p);
|
||||
}
|
||||
|
||||
static inline int s1ap_encode_s1setupresponse(
|
||||
s1ap_message *message_p, pkbuf_t *pkbuf)
|
||||
{
|
||||
|
|
4
main.c
4
main.c
|
@ -106,7 +106,7 @@ static int check_signal(int signum)
|
|||
|
||||
core_initialize();
|
||||
|
||||
cellwire_initialize();
|
||||
cellwire_initialize(config_path);
|
||||
|
||||
threads_start();
|
||||
|
||||
|
@ -227,7 +227,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
signal_init();
|
||||
|
||||
if (cellwire_initialize() != CORE_OK)
|
||||
if (cellwire_initialize(config_path) != CORE_OK)
|
||||
{
|
||||
d_fatal("CellWire initialization failed. Aborted");
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -12,7 +12,7 @@ extern "C" {
|
|||
#define GTP_C_UDP_PORT 2123
|
||||
#define GTP_U_UDP_PORT 2152
|
||||
|
||||
CORE_DECLARE(status_t) cellwire_initialize(void);
|
||||
CORE_DECLARE(status_t) cellwire_initialize(char *config_path);
|
||||
|
||||
CORE_DECLARE_NONSTD(void) cellwire_terminate(void);
|
||||
|
||||
|
|
|
@ -3,21 +3,27 @@
|
|||
*/
|
||||
|
||||
/* Core library */
|
||||
#include "core.h"
|
||||
#define TRACE_MODULE _init
|
||||
#include "core_debug.h"
|
||||
#include "context.h"
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
status_t cellwire_initialize(char *config_path)
|
||||
{
|
||||
status_t rv;
|
||||
openlog("cellwire", 0, LOG_DAEMON);
|
||||
|
||||
srand(time(NULL)*getpid());
|
||||
|
||||
rv = context_init();
|
||||
if (rv != CORE_OK)
|
||||
return rv;
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
void cellwire_terminate(void)
|
||||
{
|
||||
context_final();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#define TRACE_MODULE _s1msg
|
||||
|
||||
#include "core_debug.h"
|
||||
#include "context.h"
|
||||
#include "s1ap_message.h"
|
||||
|
||||
|
@ -12,46 +13,52 @@ status_t s1ap_build_setup_rsp(pkbuf_t **pkbuf)
|
|||
S1ap_S1SetupResponseIEs_t *ies = NULL;
|
||||
int num_of_gummei = 0;
|
||||
S1ap_ServedGUMMEIsItem_t servedGUMMEI;
|
||||
S1ap_PLMNidentity_t plmn_id;
|
||||
S1ap_MME_Group_ID_t grp_id;
|
||||
S1ap_MME_Code_t code;
|
||||
S1ap_PLMNidentity_t plmnIdentity;
|
||||
S1ap_MME_Group_ID_t mmeGroupId;
|
||||
S1ap_MME_Code_t mmeCode;
|
||||
|
||||
uint16_t mcc = 0x1234;
|
||||
uint16_t mnc = 0x5678;
|
||||
uint16_t mnc_digit_length = 2;
|
||||
|
||||
memset(&message, 0, sizeof(s1ap_message));
|
||||
|
||||
ies = &message.msg.s1ap_S1SetupResponseIEs;
|
||||
ies->relativeMMECapacity = mme_self()->relative_capacity;
|
||||
|
||||
memset((void*)&servedGUMMEI, 0, sizeof(S1ap_ServedGUMMEIsItem_t));
|
||||
num_of_gummei = 1;
|
||||
for (i = 0; i < num_of_gummei; i++)
|
||||
{
|
||||
srvd_gummei_t *srvd_gummei = &mme_self()->srvd_gummei;
|
||||
|
||||
for (j = 0; i < srvd_gummei->num_of_plmn_id; j++)
|
||||
for (j = 0; j < srvd_gummei->num_of_plmn_id; j++)
|
||||
{
|
||||
plmn_id.buf = calloc(3, sizeof(uint8_t)); \
|
||||
plmn_id.buf[0] = 0xf1;
|
||||
plmn_id.buf[1] = 0xea;
|
||||
plmn_id.buf[2] = 0xaa;
|
||||
plmn_id.size = 3;
|
||||
ASN_SEQUENCE_ADD(&servedGUMMEI.servedPLMNs.list, &plmn_id);
|
||||
memset((void *)&plmnIdentity, 0, sizeof(S1ap_PLMNidentity_t));
|
||||
MCC_MNC_TO_TBCD(mcc, mnc, mnc_digit_length, &plmnIdentity);
|
||||
ASN_SEQUENCE_ADD(&servedGUMMEI.servedPLMNs.list, &plmnIdentity);
|
||||
}
|
||||
|
||||
for (j = 0; i < srvd_gummei->num_of_grp_id; j++)
|
||||
for (j = 0; j < srvd_gummei->num_of_grp_id; j++)
|
||||
{
|
||||
INT16_TO_OCTET_STRING(srvd_gummei->grp_id[j], &grp_id);
|
||||
ASN_SEQUENCE_ADD(&servedGUMMEI.servedGroupIDs.list, &grp_id);
|
||||
memset((void*)&mmeGroupId, 0, sizeof(S1ap_MME_Group_ID_t));
|
||||
INT16_TO_OCTET_STRING(srvd_gummei->grp_id[j], &mmeGroupId);
|
||||
ASN_SEQUENCE_ADD(&servedGUMMEI.servedGroupIDs.list, &mmeGroupId);
|
||||
}
|
||||
|
||||
for (j = 0; i < srvd_gummei->num_of_code; j++)
|
||||
for (j = 0; j < srvd_gummei->num_of_code; j++)
|
||||
{
|
||||
INT16_TO_OCTET_STRING(srvd_gummei->code[j], &code);
|
||||
ASN_SEQUENCE_ADD(&servedGUMMEI.servedMMECs.list, &code);
|
||||
memset((void*)&mmeCode, 0, sizeof(S1ap_MME_Code_t));
|
||||
INT8_TO_OCTET_STRING(srvd_gummei->code[j], &mmeCode);
|
||||
ASN_SEQUENCE_ADD(&servedGUMMEI.servedMMECs.list, &mmeCode);
|
||||
}
|
||||
}
|
||||
|
||||
ASN_SEQUENCE_ADD(&ies->servedGUMMEIs, &servedGUMMEI);
|
||||
memset(&ies->servedGUMMEIs, 0, sizeof(S1ap_ServedGUMMEIs_t));
|
||||
ASN_SEQUENCE_ADD(&ies->servedGUMMEIs.list, &servedGUMMEI);
|
||||
message.procedureCode = S1ap_ProcedureCode_id_S1Setup;
|
||||
message.direction = S1AP_PDU_PR_successfulOutcome;
|
||||
message.criticality = S1ap_Criticality_reject;
|
||||
|
||||
erval = s1ap_encode_pdu(pkbuf, &message);
|
||||
if (erval < 0)
|
||||
|
|
|
@ -74,8 +74,49 @@ static void s1ap_test4(abts_case *tc, void *data)
|
|||
pkbuf_t *pkbuf;
|
||||
|
||||
rv = s1ap_build_setup_rsp(&pkbuf);
|
||||
printf("rv = %d\n", rv);
|
||||
printf("pkbuf = %p\n", pkbuf);
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
||||
}
|
||||
|
||||
static void s1ap_test5(abts_case *tc, void *data)
|
||||
{
|
||||
int erval = -1;
|
||||
pkbuf_t *pkbuf;
|
||||
|
||||
s1ap_message message;
|
||||
S1ap_S1SetupRequestIEs_t *s1SetupRequestIEs;
|
||||
S1ap_PLMNidentity_t plmnIdentity;
|
||||
S1ap_SupportedTAs_Item_t ta;
|
||||
|
||||
uint16_t mcc = 0x1234;
|
||||
uint16_t mnc = 0x5678;
|
||||
uint16_t mnc_digit_length = 2;
|
||||
uint32_t enb_id = 0x5f123;
|
||||
uint32_t ttta = 0x1234;
|
||||
|
||||
memset(&message, 0, sizeof(s1ap_message));
|
||||
|
||||
s1SetupRequestIEs = &message.msg.s1ap_S1SetupRequestIEs;
|
||||
memset((void *)&plmnIdentity, 0, sizeof(S1ap_PLMNidentity_t));
|
||||
memset((void *)&ta, 0, sizeof(S1ap_SupportedTAs_Item_t));
|
||||
|
||||
s1SetupRequestIEs->global_ENB_ID.eNB_ID.present = S1ap_ENB_ID_PR_macroENB_ID;
|
||||
MACRO_ENB_ID_TO_BIT_STRING(enb_id,
|
||||
&s1SetupRequestIEs->global_ENB_ID.eNB_ID.choice.macroENB_ID);
|
||||
MCC_MNC_TO_PLMNID(mcc, mnc, mnc_digit_length,
|
||||
&s1SetupRequestIEs->global_ENB_ID.pLMNidentity);
|
||||
|
||||
INT16_TO_OCTET_STRING(ttta, &ta.tAC);
|
||||
MCC_MNC_TO_TBCD(mcc, mnc, mnc_digit_length, &plmnIdentity);
|
||||
|
||||
ASN_SEQUENCE_ADD(&ta.broadcastPLMNs.list, &plmnIdentity);
|
||||
ASN_SEQUENCE_ADD(&s1SetupRequestIEs->supportedTAs.list, &ta);
|
||||
|
||||
message.direction = S1AP_PDU_PR_initiatingMessage;
|
||||
message.procedureCode = S1ap_ProcedureCode_id_S1Setup;
|
||||
message.criticality = S1ap_Criticality_reject;
|
||||
|
||||
erval = s1ap_encode_pdu(&pkbuf, &message);
|
||||
ABTS_INT_EQUAL(tc, 280, erval);
|
||||
}
|
||||
|
||||
abts_suite *test_s1ap(abts_suite *suite)
|
||||
|
@ -89,9 +130,8 @@ abts_suite *test_s1ap(abts_suite *suite)
|
|||
abts_run_test(suite, s1ap_test1, NULL);
|
||||
abts_run_test(suite, s1ap_test2, NULL);
|
||||
abts_run_test(suite, s1ap_test3, NULL);
|
||||
#if 0
|
||||
abts_run_test(suite, s1ap_test4, NULL);
|
||||
#endif
|
||||
abts_run_test(suite, s1ap_test5, NULL);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include "core.h"
|
||||
#include "cellwire.h"
|
||||
#include "abts.h"
|
||||
#include "testutil.h"
|
||||
|
||||
|
@ -33,9 +34,16 @@ void core_assert_ok(abts_case* tc, const char* context, status_t rv,
|
|||
}
|
||||
}
|
||||
|
||||
void test_terminate(void)
|
||||
{
|
||||
core_terminate();
|
||||
cellwire_terminate();
|
||||
}
|
||||
|
||||
void test_initialize(void)
|
||||
{
|
||||
core_initialize();
|
||||
atexit(core_terminate);
|
||||
cellwire_initialize(NULL);
|
||||
atexit(test_terminate);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue