move plmn_id structure to 3gpp

This commit is contained in:
Sukchan Lee 2017-03-03 17:33:41 +09:00
parent 5e0a045a0d
commit f6652e69a9
18 changed files with 106 additions and 39 deletions

View File

@ -257,6 +257,7 @@ esac
AC_CONFIG_FILES([lib/core/test/Makefile])
AC_CONFIG_FILES([lib/core/Makefile])
AC_CONFIG_FILES([lib/logger/Makefile])
AC_CONFIG_FILES([lib/3gpp/Makefile])
AC_CONFIG_FILES([lib/s1ap/asn1c/Makefile])
AC_CONFIG_FILES([lib/s1ap/Makefile])
AC_CONFIG_FILES([lib/nas/Makefile])

20
lib/3gpp/Makefile.am Normal file
View File

@ -0,0 +1,20 @@
## Process this file with automake to produce Makefile.in
noinst_LTLIBRARIES = lib3gpp.la
lib3gpp_la_SOURCES = \
plmn_id.h
nodist_lib3gpp_la_SOURCES = \
plmn_id.c
AM_CPPFLAGS = \
-I$(top_srcdir)/lib/core/include
AM_CFLAGS = \
-Wall -Werror
MAINTAINERCLEANFILES = Makefile.in
MOSTLYCLEANFILES = *.stackdump
EXTRA_DIST = .libs $(noinst_LTLIBRARIES)

View File

@ -1,12 +1,12 @@
#define TRACE_MODULE _cw_common
#define TRACE_MODULE _plmn_id
#include "common.h"
#include "plmn_id.h"
#define PLMN_ID_DIGIT1(x) (((x) / 100) % 10)
#define PLMN_ID_DIGIT2(x) (((x) / 10) % 10)
#define PLMN_ID_DIGIT3(x) ((x) % 10)
void encode_plmn_id(c_uint8_t *buf, plmn_id_t *plmn_id)
void plmn_id_to_buffer(plmn_id_t *plmn_id, c_uint8_t *buf)
{
buf[0] = (PLMN_ID_DIGIT2(plmn_id->mcc) << 4) | PLMN_ID_DIGIT1(plmn_id->mcc);

View File

@ -1,5 +1,5 @@
#ifndef __CELLWIRE_COMMON_H__
#define __CELLWIRE_COMMON_H__
#ifndef __PLNN_ID_H__
#define __PLNN_ID_H__
#include "core_errno.h"
@ -13,10 +13,10 @@ typedef struct _plmn_id_t {
c_uint16_t mnc_len;
} plmn_id_t;
CORE_DECLARE(void) encode_plmn_id(c_uint8_t *buf, plmn_id_t *plmn_id);
CORE_DECLARE(void) plmn_id_to_buffer(plmn_id_t *plmn_id, c_uint8_t *buf);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* !__CELLWIRE_COMMON_H__ */
#endif /* !__PLNN_ID_H__ */

View File

@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = core logger s1ap nas s6a
SUBDIRS = core logger 3gpp s1ap nas s6a
MAINTAINERCLEANFILES = Makefile.in
MOSTLYCLEANFILES = *.stackdump

View File

@ -88,7 +88,7 @@ CORE_DECLARE(status_t) core_generate_random_bytes(
unsigned char *buf, int length);
CORE_DECLARE(void *) core_ascii_to_hex(char *in, int len, char *out);
CORE_DECLARE(void *) core_uint64_to_array(c_uint8_t *array, c_uint64_t num);
CORE_DECLARE(void *) core_uint64_to_buffer(c_uint64_t num, c_uint8_t *array);
/** @} */

View File

@ -14,11 +14,11 @@ void *core_ascii_to_hex(char *in, int len, char *out)
return out;
}
void *core_uint64_to_array(c_uint8_t *array, c_uint64_t num)
void *core_uint64_to_buffer(c_uint64_t num, c_uint8_t *buffer)
{
int i;
for (i = 0; i < 8; i++)
array[i] = (num >> (8-1-i) * 8) & 0xff;
buffer[i] = (num >> (8-1-i) * 8) & 0xff;
return array;
return buffer;
}

View File

@ -36,10 +36,10 @@ static void misc_test2(abts_case *tc, void *data)
static void misc_test3(abts_case *tc, void *data)
{
c_uint64_t num = 0x0123456789abcdef;
c_uint8_t array[8];
c_uint8_t buf[8];
c_uint8_t tmp[8] = "\x01\x23\x45\x67\x89\xab\xcd\xef";
ABTS_TRUE(tc, memcmp(tmp, core_uint64_to_array(array, num), 8) == 0);
ABTS_TRUE(tc, memcmp(tmp, core_uint64_to_buffer(num, buf), 8) == 0);
}
abts_suite *testmisc(abts_suite *suite)

29
lib/s6a/3gpp_kdf.c Normal file
View File

@ -0,0 +1,29 @@
#define TRACE_MODULE _3gpp_kdf
#include "core_debug.h"
#include "core_sha2_hmac.h"
void derive_kasme(const c_uint8_t *ck, const c_uint8_t *ik,
const c_uint8_t plmn[3], const c_uint8_t *sqn, const c_uint8_t *ak,
c_uint8_t *kasme)
{
c_uint8_t s[14];
c_uint8_t k[32];
int i;
memcpy(&k[0], ck, 16);
memcpy(&k[0], ik, 16);
s[0] = 0x10;
memcpy(&s[1], plmn, 3);
s[4] = 0x00;
s[5] = 0x03;
for (i = 0; i < 6; i++)
s[6+i] = sqn[i] ^ ak[i];
s[12] = 0x00;
s[13] = 0x06;
hmac_sha256(k, 32, s, 14, kasme, 32);
}

10
lib/s6a/3gpp_kdf.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __3GPP_KDF_H__
#define __3GPP_KDF_H__
#include "core.h"
void derive_kasme(const c_uint8_t *ck, const c_uint8_t *ik,
const c_uint8_t plmn[3], const c_uint8_t *sqn, const c_uint8_t *ak,
c_uint8_t *kasme);
#endif /* __3GPP_KDF_H__ */

View File

@ -71,7 +71,7 @@ static int hss_air_cb( struct msg **msg, struct avp *avp,
core_generate_random_bytes(ue->rand, MAX_KEY_LEN);
milenage_opc(ue->k, ue->op, ue->opc);
milenage_generate(ue->opc, ue->amf, ue->k,
core_uint64_to_array(sqn, ue->sqn), ue->rand,
core_uint64_to_buffer(ue->sqn, sqn), ue->rand,
autn, ik, ck, ak, xres, &xres_len);
derive_kasme(ck, ik, plmn, sqn, ak, kasme);

15
main.c
View File

@ -10,7 +10,6 @@
#include "symtbl.h"
/* Server */
#include "s6a_auth_info.h"
#include "cellwire.h"
extern char g_compile_time[];
@ -52,18 +51,8 @@ static int check_signal(int signum)
}
case SIGUSR1:
{
s6a_auth_info_req_t air;
memset(&air, 0, sizeof(s6a_auth_info_req_t));
#define TEST_IMSI "001010123456800"
air.imsi_len = strlen(TEST_IMSI);
strcpy((char*)air.imsi, TEST_IMSI);
air.visited_plmn_id.mcc = 1;
air.visited_plmn_id.mnc = 1;
air.visited_plmn_id.mnc_len = 2;
air.auth_info.num_of_eutran_vector = 1;
air.auth_info.immediate_response_preferred = 1;
s6a_send_auth_info_req(&air);
void s6a_test_send();
s6a_test_send();
break;
}
default:

View File

@ -3,14 +3,14 @@
noinst_LTLIBRARIES = libcellwire.la
libcellwire_la_SOURCES = \
cellwire.h common.h event.h context.h \
cellwire.h event.h context.h \
s1ap_build.h s1ap_conv.h s1ap_path.h \
s6_auth_info.h \
sm.h
nodist_libcellwire_la_SOURCES = \
init.c common.c event.c context.c \
init.c event.c context.c \
s1ap_build.c s1ap_conv.c s1ap_path.c \
s6a_auth_info.c \
mme_sm.c enb_s1_sm.c
@ -18,6 +18,7 @@ nodist_libcellwire_la_SOURCES = \
libcellwire_la_DEPENDENCIES = \
$(top_srcdir)/lib/core/src/libcore.la \
$(top_srcdir)/lib/logger/liblogger.la \
$(top_srcdir)/lib/3gpp/lib3gpp.la \
$(top_srcdir)/lib/s1ap/libs1ap.la \
$(top_srcdir)/lib/nas/libnas.la \
$(top_srcdir)/lib/s6a/libs6a.la
@ -25,6 +26,7 @@ libcellwire_la_DEPENDENCIES = \
libcellwire_la_LIBADD = \
$(top_srcdir)/lib/core/src/libcore.la \
$(top_srcdir)/lib/logger/liblogger.la \
$(top_srcdir)/lib/3gpp/lib3gpp.la \
$(top_srcdir)/lib/s1ap/libs1ap.la \
$(top_srcdir)/lib/nas/libnas.la \
$(top_srcdir)/lib/s6a/libs6a.la
@ -33,6 +35,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/lib/core/include \
-I$(top_srcdir)/lib/logger \
-I$(top_srcdir)/lib/3gpp \
-I$(top_srcdir)/lib/s1ap/asn1c \
-I$(top_srcdir)/lib/s1ap \
-I$(top_srcdir)/lib/nas \

View File

@ -5,7 +5,7 @@
#include "core_errno.h"
#include "core_net.h"
#include "common.h"
#include "plmn_id.h"
#include "sm.h"
#ifdef __cplusplus

View File

@ -2,7 +2,7 @@
#include "core_debug.h"
#include "common.h"
#include "plmn_id.h"
#include "s1ap_conv.h"
CORE_DECLARE(void) s1ap_conv_uint8_to_octet_string(
@ -43,7 +43,7 @@ CORE_DECLARE(void) s1ap_conv_plmn_id_to_tbcd_string(
tbcd_string->size = 3;
tbcd_string->buf = core_calloc(tbcd_string->size, sizeof(c_uint8_t));
encode_plmn_id(tbcd_string->buf, plmn_id);
plmn_id_to_buffer(plmn_id, tbcd_string->buf);
}
CORE_DECLARE(void) s1ap_conv_macro_enb_id_to_bit_string(

View File

@ -2,8 +2,6 @@
#include "core_debug.h"
#include "common.h"
#include "s6a_app.h"
#include "s6a_auth_info.h"
@ -14,6 +12,22 @@ struct sess_state {
static void s6a_aia_cb(void *data, struct msg **msg);
void s6a_test_send()
{
s6a_auth_info_req_t air;
memset(&air, 0, sizeof(s6a_auth_info_req_t));
#define TEST_IMSI "001010123456800"
air.imsi_len = strlen(TEST_IMSI);
strcpy((char*)air.imsi, TEST_IMSI);
air.visited_plmn_id.mcc = 1;
air.visited_plmn_id.mnc = 1;
air.visited_plmn_id.mnc_len = 2;
air.auth_info.num_of_eutran_vector = 1;
air.auth_info.immediate_response_preferred = 1;
s6a_send_auth_info_req(&air);
}
/* Cb called when an answer is received */
int s6a_send_auth_info_req(s6a_auth_info_req_t *air)
{
@ -82,11 +96,11 @@ int s6a_send_auth_info_req(s6a_auth_info_req_t *air)
/* Set the Visited-PLMN-Id AVP if needed*/
{
c_uint8_t data[3] = {0, };
encode_plmn_id(data, &air->visited_plmn_id);
c_uint8_t buffer[3] = {0, };
plmn_id_to_buffer(&air->visited_plmn_id, buffer);
d_assert(fd_msg_avp_new(s6a_visited_plmn_id, 0, &avp) == 0, goto out,);
val.os.data = data;
val.os.data = buffer;
val.os.len = 3;
d_assert(fd_msg_avp_setvalue(avp, &val) == 0, goto out,);
d_assert(fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp) == 0, goto out,);

View File

@ -3,7 +3,7 @@
#include "core_errno.h"
#include "common.h"
#include "plmn_id.h"
#ifdef __cplusplus
extern "C" {

View File

@ -14,6 +14,7 @@ testcellwire_LDADD = \
AM_CPPFLAGS = \
-I$(top_srcdir)/lib/core/include \
-I$(top_srcdir)/lib/3gpp \
-I$(top_srcdir)/lib/s1ap/asn1c \
-I$(top_srcdir)/lib/s1ap \
-I$(top_srcdir)/lib/nas \