open5gs/test/tests1ap.c

113 lines
2.5 KiB
C
Raw Normal View History

2017-02-13 07:03:12 +00:00
#define TRACE_MODULE _s1enbmsg
#include "core_debug.h"
#include "core_pkbuf.h"
2017-03-05 06:02:12 +00:00
2017-02-13 07:03:12 +00:00
#include "context.h"
2017-02-20 10:46:58 +00:00
#include "s1ap_build.h"
2017-02-13 07:03:12 +00:00
#include "s1ap_conv.h"
2017-03-05 06:02:12 +00:00
#include "s1ap_path.h"
net_sock_t *tests1ap_enb_connect(void)
{
status_t rv;
mme_ctx_t *mme = mme_self();
net_sock_t *sock = NULL;
if (!mme) return NULL;
rv = net_open_with_addr(&sock, mme->enb_local_addr, "127.0.0.1", 0,
mme->enb_s1ap_port, SOCK_SEQPACKET, IPPROTO_SCTP, 0);
if (rv != CORE_OK) return NULL;
return sock;
}
status_t tests1ap_enb_close(net_sock_t *sock)
{
return net_close(sock);
}
int tests1ap_enb_send(net_sock_t *sock, pkbuf_t *sendbuf)
{
return s1ap_send(sock, sendbuf);
}
int tests1ap_enb_read(net_sock_t *sock, pkbuf_t *recvbuf)
{
int rc = 0;
while(1)
{
rc = net_read(sock, recvbuf->payload, recvbuf->len, 0);
if (rc == -2)
{
continue;
}
else if (rc <= 0)
{
if (sock->sndrcv_errno == EAGAIN)
{
continue;
}
break;
}
else
{
break;
}
}
return rc;
}
2017-02-13 07:03:12 +00:00
2017-03-05 06:02:12 +00:00
status_t tests1ap_build_setup_req(pkbuf_t **pkbuf, c_uint32_t enb_id)
2017-02-13 07:03:12 +00:00
{
int erval = -1;
s1ap_message message;
S1ap_S1SetupRequestIEs_t *ies;
S1ap_PLMNidentity_t *plmnIdentity;
S1ap_SupportedTAs_Item_t *supportedTA;
memset(&message, 0, sizeof(s1ap_message));
2017-03-05 02:46:42 +00:00
ies = &message.s1ap_S1SetupRequestIEs;
2017-02-13 07:03:12 +00:00
2017-03-05 02:29:15 +00:00
s1ap_uint32_to_ENB_ID(S1ap_ENB_ID_PR_macroENB_ID, enb_id,
&ies->global_ENB_ID.eNB_ID);
s1ap_plmn_id_to_TBCD_STRING(
2017-02-13 07:03:12 +00:00
&mme_self()->plmn_id, &ies->global_ENB_ID.pLMNidentity);
supportedTA = (S1ap_SupportedTAs_Item_t *)
core_calloc(1, sizeof(S1ap_SupportedTAs_Item_t));
2017-03-05 02:29:15 +00:00
s1ap_uint16_to_OCTET_STRING(
2017-02-14 00:09:01 +00:00
mme_self()->tracking_area_code, &supportedTA->tAC);
2017-02-13 07:03:12 +00:00
plmnIdentity = (S1ap_PLMNidentity_t *)
core_calloc(1, sizeof(S1ap_PLMNidentity_t));
2017-03-05 02:29:15 +00:00
s1ap_plmn_id_to_TBCD_STRING(
2017-02-13 07:03:12 +00:00
&mme_self()->plmn_id, plmnIdentity);
ASN_SEQUENCE_ADD(&supportedTA->broadcastPLMNs, plmnIdentity);
ASN_SEQUENCE_ADD(&ies->supportedTAs, supportedTA);
2017-02-14 00:09:01 +00:00
ies->defaultPagingDRX = mme_self()->default_paging_drx;
2017-02-13 07:03:12 +00:00
message.direction = S1AP_PDU_PR_initiatingMessage;
message.procedureCode = S1ap_ProcedureCode_id_S1Setup;
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;
}