Add ErrorIndication for S1AP decode error (#218)

This commit is contained in:
Sukchan Lee 2019-07-12 16:22:40 +09:00
parent 74c1e1d481
commit f20a1a6e2b
5 changed files with 56 additions and 4 deletions

View File

@ -35,9 +35,9 @@ int s1ap_decode_pdu(s1ap_message_t *message, ogs_pkbuf_t *pkbuf)
dec_ret = aper_decode(NULL, &asn_DEF_S1AP_S1AP_PDU, (void **)&message,
pkbuf->data, pkbuf->len, 0, 0);
if (dec_ret.code != RC_OK)
{
ogs_error("Failed to decode S1AP-PDU[%d]", dec_ret.code);
if (dec_ret.code != RC_OK) {
ogs_warn("Failed to decode S1AP-PDU[code:%d,consumed:%d]",
dec_ret.code, dec_ret.consumed);
return OGS_ERROR;
}

View File

@ -201,7 +201,11 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e)
e->s1ap_message = &s1ap_message;
ogs_fsm_dispatch(&enb->sm, e);
} else {
ogs_error("Cannot process S1AP message");
ogs_warn("Cannot process S1AP message");
rv = s1ap_send_error_indication(
enb, NULL, NULL, S1AP_Cause_PR_protocol,
S1AP_CauseProtocol_abstract_syntax_error_falsely_constructed_message);
ogs_assert(rv == OGS_OK);
}
s1ap_free_pdu(&s1ap_message);

View File

@ -318,6 +318,28 @@ int tests1ap_build_setup_req(
#define TESTS1AP_MAX_MESSAGE 64
int tests1ap_build_invalid_packet(ogs_pkbuf_t **pkbuf, int i)
{
char *payload[TESTS1AP_MAX_MESSAGE] = {
"0011002100000300 3b40080062f22400 0001700040000700 00004062f224002c"
"00030a0100",
"",
};
uint16_t len[TESTS1AP_MAX_MESSAGE] = {
37,
0,
};
char hexbuf[MAX_SDU_LEN];
*pkbuf = ogs_pkbuf_alloc(NULL, MAX_SDU_LEN);
ogs_pkbuf_put_data(*pkbuf,
OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]);
return OGS_OK;
}
int tests1ap_build_initial_ue_msg(ogs_pkbuf_t **pkbuf, int i)
{
char *payload[TESTS1AP_MAX_MESSAGE] = {

View File

@ -48,6 +48,8 @@ ogs_pkbuf_t *testenb_gtpu_read(ogs_socknode_t *node);
int testenb_gtpu_send(ogs_socknode_t *node, ogs_pkbuf_t *sendbuf);
void testenb_gtpu_close(ogs_socknode_t *node);
int tests1ap_build_invalid_packet(ogs_pkbuf_t **pkbuf, int i);
int tests1ap_build_setup_req(
ogs_pkbuf_t **pkbuf, S1AP_ENB_ID_PR present, uint32_t enb_id,
int tac, uint16_t mcc, uint16_t mnc, uint16_t mnc_len);

View File

@ -87,12 +87,36 @@ static void s1setup_test2(abts_case *tc, void *data)
ogs_pkbuf_free(recvbuf);
}
static void s1setup_test3(abts_case *tc, void *data)
{
int rv;
ogs_socknode_t *s1ap;
ogs_pkbuf_t *sendbuf;
ogs_pkbuf_t *recvbuf;
s1ap = testenb_s1ap_client("127.0.0.1");
ABTS_PTR_NOTNULL(tc, s1ap);
rv = tests1ap_build_invalid_packet(&sendbuf, 0);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
rv = testenb_s1ap_send(s1ap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
recvbuf = testenb_s1ap_read(s1ap);
ABTS_PTR_NOTNULL(tc, recvbuf);
ogs_pkbuf_free(recvbuf);
testenb_s1ap_close(s1ap);
}
abts_suite *test_s1setup(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, s1setup_test1, NULL);
abts_run_test(suite, s1setup_test2, NULL);
abts_run_test(suite, s1setup_test3, NULL);
return suite;
}