update it

This commit is contained in:
Sukchan Lee 2017-03-24 22:24:09 +09:00
parent 577b865aa2
commit a6512e7a6c
8 changed files with 89 additions and 2 deletions

View File

@ -22,3 +22,33 @@ void *s1ap_plmn_id_to_buffer(plmn_id_t *plmn_id, c_uint8_t *buf)
return buf;
}
c_uint16_t plmn_id_mcc(plmn_t *plmn_id)
{
return plmn_id->mcc1 * 100 + plmn_id->mcc2 * 10 + plmn_id->mcc3;
}
c_uint16_t plmn_id_mnc(plmn_t *plmn_id)
{
return plmn_id->mnc1 == 0xf ? plmn_id->mnc2 * 10 + plmn_id->mnc3 :
plmn_id->mnc1 * 100 + plmn_id->mnc2 * 10 + plmn_id->mnc3;
}
c_uint16_t plmn_id_mnc_len(plmn_t *plmn_id)
{
return plmn_id->mnc1 == 0xf ? 2 : 3;
}
void plmn_id_build(plmn_t *plmn_id,
c_uint16_t mcc, c_uint16_t mnc, c_uint16_t mnc_len)
{
plmn_id->mcc1 = PLMN_ID_DIGIT1(mcc);
plmn_id->mcc2 = PLMN_ID_DIGIT2(mcc);
plmn_id->mcc3 = PLMN_ID_DIGIT3(mcc);
if (mnc_len == 2)
plmn_id->mnc1 = 0xf;
else
plmn_id->mnc1 = PLMN_ID_DIGIT1(mnc);
plmn_id->mnc2 = PLMN_ID_DIGIT2(mnc);
plmn_id->mnc3 = PLMN_ID_DIGIT3(mnc);
}

View File

@ -9,6 +9,14 @@ extern "C" {
CORE_DECLARE(void *) s1ap_plmn_id_to_buffer(
plmn_id_t *plmn_id, c_uint8_t *buf);
CORE_DECLARE(c_uint16_t) plmn_id_mcc(plmn_t *plmn_id);
CORE_DECLARE(c_uint16_t) plmn_id_mnc(plmn_t *plmn_id);
CORE_DECLARE(c_uint16_t) plmn_id_mnc_len(plmn_t *plmn_id);
CORE_DECLARE(void) plmn_id_build(plmn_t *plmn_id,
c_uint16_t mcc, c_uint16_t mnc, c_uint16_t mnc_len);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -7,14 +7,13 @@ extern "C" {
#define MAX_SDU_LEN 2048
#define PLMN_ID_LEN 3
#define MAX_IMSI_LEN 15
#define RAND_LEN 16
#define AUTN_LEN 16
#define MAX_RES_LEN 16
#define PLMN_ID_LEN 3
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -22,6 +22,15 @@ ED2(c_uint8_t mnc_digit2:4;,
c_uint8_t mnc_digit1:4;)
} __attribute__ ((packed)) nas_plmn_t;
typedef struct _plmn_t {
ED2(c_uint8_t mcc2:4;,
c_uint8_t mcc1:4;)
ED2(c_uint8_t mnc1:4;,
c_uint8_t mcc3:4;)
ED2(c_uint8_t mnc3:4;,
c_uint8_t mnc2:4;)
} __attribute__ ((packed)) plmn_t;
#ifdef __cplusplus
}
#endif /* __cplusplus */

38
test/3gpp_test.c Normal file
View File

@ -0,0 +1,38 @@
#include "core_lib.h"
#include "core_debug.h"
#include "3gpp_defs.h"
#include "3gpp_types.h"
#include "3gpp_conv.h"
#include "testutil.h"
static void _3gpp_test1(abts_case *tc, void *data)
{
status_t rv;
plmn_t plmn_id;
c_uint8_t *buffer = (c_uint8_t *)&plmn_id;
plmn_id_build(&plmn_id, 1, 1, 2);
ABTS_TRUE(tc, memcmp(buffer, "\x00\xf1\x10", PLMN_ID_LEN) == 0);
ABTS_INT_EQUAL(tc, 1, plmn_id_mcc(&plmn_id));
ABTS_INT_EQUAL(tc, 1, plmn_id_mnc(&plmn_id));
ABTS_INT_EQUAL(tc, 2, plmn_id_mnc_len(&plmn_id));
plmn_id_build(&plmn_id, 555, 10, 2);
ABTS_TRUE(tc, memcmp(buffer, "\x55\xf5\x01", PLMN_ID_LEN) == 0);
ABTS_INT_EQUAL(tc, 555, plmn_id_mcc(&plmn_id));
ABTS_INT_EQUAL(tc, 10, plmn_id_mnc(&plmn_id));
ABTS_INT_EQUAL(tc, 2, plmn_id_mnc_len(&plmn_id));
}
abts_suite *test_3gpp(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, _3gpp_test1, NULL);
return suite;
}

View File

@ -5,6 +5,7 @@ bin_PROGRAMS = testcellwire
testcellwire_SOURCES = \
abts.h abts_tests.h testutil.h \
abts.c testutil.c tests1ap.h tests1ap.c \
3gpp_test.c \
s1ap_message_test.c nas_message_test.c gtp_message_test.c \
security_test.c \
s1ap_sm_test.c nas_sm_test.c

View File

@ -23,6 +23,7 @@
const struct testlist {
abts_suite *(*func)(abts_suite *suite);
} alltests[] = {
{test_3gpp},
{test_s1ap_message},
{test_s1ap_sm},
{test_nas_message},

View File

@ -57,6 +57,7 @@ void core_assert_ok(abts_case* tc, const char *context,
void test_initialize(void);
abts_suite *test_3gpp(abts_suite *suite);
abts_suite *test_s1ap_message(abts_suite *suite);
abts_suite *test_s1ap_sm(abts_suite *suite);
abts_suite *test_nas_message(abts_suite *suite);