s1ap_conv is added to convert ASN1C structure

This commit is contained in:
Sukchan Lee 2017-02-10 21:51:56 +09:00
parent 2041f65c83
commit a199a7528f
8 changed files with 150 additions and 391 deletions

View File

@ -3,10 +3,10 @@
noinst_LTLIBRARIES = libcellwire.la
libcellwire_la_SOURCES = \
cellwire.h context.h s1ap_message.h
cellwire.h context.h s1ap_message.h s1ap_conv.h
nodist_libcellwire_la_SOURCES = \
init.c context.c s1ap_message.c
init.c context.c s1ap_message.c s1ap_conv.c
AM_CPPFLAGS = \
-I$(top_srcdir)/include \

View File

@ -25,18 +25,15 @@ status_t context_init()
/* Initialize MME context */
memset(&self, 0, sizeof(mme_ctx_t));
self.plmn_id.mnc_digit_len = 2;
self.plmn_id.mcc[2] = 1;
self.plmn_id.mnc[1] = 1;
self.plmn_id.mnc_len = 2;
self.plmn_id.mcc = 1; /* 001 */
self.plmn_id.mnc = 1; /* 01 */
self.relative_capacity = 0xff;
self.srvd_gummei.num_of_plmn_id = 1;
self.srvd_gummei.plmn_id[0].mnc_digit_len = 2;
self.srvd_gummei.plmn_id[0].mcc[0] = 0;
self.srvd_gummei.plmn_id[0].mcc[1] = 0;
self.srvd_gummei.plmn_id[0].mcc[2] = 1;
self.srvd_gummei.plmn_id[0].mnc[0] = 0;
self.srvd_gummei.plmn_id[0].mnc[1] = 1;
self.srvd_gummei.plmn_id[0].mnc_len = 2;
self.srvd_gummei.plmn_id[0].mcc = 1; /* 001 */
self.srvd_gummei.plmn_id[0].mnc = 1; /* 01 */
self.srvd_gummei.num_of_grp_id = 1;
self.srvd_gummei.grp_id[0] = 2;

View File

@ -13,9 +13,9 @@ extern "C" {
#define CODE_PER_MME 256 /* According to spec it is 256*/
typedef struct _plmn_id_t {
c_uint8_t mnc_digit_len;
c_uint8_t mcc[3];
c_uint8_t mnc[3];
c_uint16_t mcc;
c_uint16_t mnc;
c_uint16_t mnc_len;
} plmn_id_t;
typedef struct _served_gummei {
@ -32,10 +32,9 @@ typedef struct _served_gummei {
* This structure represents HypcerCell */
typedef struct _mme_ctx_t {
plmn_id_t plmn_id;
c_uint8_t relative_capacity;
srvd_gummei_t srvd_gummei;
c_uint16_t tac;
} mme_ctx_t;
CORE_DECLARE(status_t) context_init(void);

85
src/s1ap_conv.c Normal file
View File

@ -0,0 +1,85 @@
#define TRACE_MODULE _s1conv
#include "s1ap_conv.h"
CORE_DECLARE(void) s1ap_conv_uint8_to_octet_string(
c_uint8_t uint8, OCTET_STRING_t *octet_string)
{
octet_string->size = 1;
octet_string->buf = core_calloc(octet_string->size, sizeof(c_uint8_t));
octet_string->buf[0] = uint8;
}
CORE_DECLARE(void) s1ap_conv_uint16_to_octet_string(
c_uint16_t uint16, OCTET_STRING_t *octet_string)
{
octet_string->size = 2;
octet_string->buf = core_calloc(octet_string->size, sizeof(c_uint8_t));
octet_string->buf[0] = uint16 >> 8;
octet_string->buf[1] = uint16;
}
CORE_DECLARE(void) s1ap_conv_uint32_to_octet_string(
c_uint32_t uint32, OCTET_STRING_t *octet_string)
{
octet_string->size = 4;
octet_string->buf = core_calloc(octet_string->size, sizeof(c_uint8_t));
octet_string->buf[0] = uint32 >> 24;
octet_string->buf[0] = uint32 >> 16;
octet_string->buf[0] = uint32 >> 8;
octet_string->buf[0] = uint32;
}
#define S1AP_CONV_DECIMAL100(x) (((x) / 100) % 10)
#define S1AP_CONV_DECIMAL10(x) (((x) / 10) % 10)
#define S1AP_CONV_DECIMAL1(x) ((x) % 10)
CORE_DECLARE(void) s1ap_conv_plmn_id_to_tbcd_string(
plmn_id_t *plmn_id, S1ap_TBCD_STRING_t *tbcd_string)
{
tbcd_string->size = 3;
tbcd_string->buf = core_calloc(tbcd_string->size, sizeof(c_uint8_t));
tbcd_string->buf[0] = (S1AP_CONV_DECIMAL10(plmn_id->mcc) << 4) |
S1AP_CONV_DECIMAL100(plmn_id->mcc);
if (plmn_id->mnc_len == 2)
tbcd_string->buf[1] = (0xf << 4);
else
tbcd_string->buf[1] = (S1AP_CONV_DECIMAL100(plmn_id->mnc) << 4);
tbcd_string->buf[1] |= S1AP_CONV_DECIMAL1(plmn_id->mcc);
tbcd_string->buf[2] = (S1AP_CONV_DECIMAL1(plmn_id->mnc) << 4) |
S1AP_CONV_DECIMAL10(plmn_id->mnc);
}
CORE_DECLARE(void) s1ap_conv_macro_enb_id_to_bit_string(
c_uint32_t enb_id, BIT_STRING_t *bit_string)
{
bit_string->size = 3;
bit_string->buf = core_calloc(bit_string->size, sizeof(c_uint8_t));
bit_string->buf[0] = enb_id >> 12;
bit_string->buf[1] = enb_id >> 4;
bit_string->buf[2] = (enb_id & 0xf) << 4;
bit_string->bits_unused = 4;
}
CORE_DECLARE(void) s1ap_conv_home_enb_id_to_bit_string(
c_uint32_t enb_id, BIT_STRING_t *bit_string)
{
bit_string->size = 4;
bit_string->buf = core_calloc(bit_string->size, sizeof(c_uint8_t));
bit_string->buf[0] = enb_id >> 20;
bit_string->buf[1] = enb_id >> 12;
bit_string->buf[2] = enb_id >> 4;
bit_string->buf[3] = (enb_id & 0xf) << 4;
bit_string->bits_unused = 4;
}

32
src/s1ap_conv.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef _S1AP_CONV_H__
#define _S1AP_CONV_H__
#include "s1ap_codecs.h"
#include "context.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
CORE_DECLARE(void) s1ap_conv_uint8_to_octet_string(
c_uint8_t uint8, OCTET_STRING_t *octet_string);
CORE_DECLARE(void) s1ap_conv_uint16_to_octet_string(
c_uint16_t uint16, OCTET_STRING_t *octet_string);
CORE_DECLARE(void) s1ap_conv_uint32_to_octet_string(
c_uint32_t uint32, OCTET_STRING_t *octet_string);
CORE_DECLARE(void) s1ap_conv_plmn_id_to_tbcd_string(
plmn_id_t *plmn_id, S1ap_TBCD_STRING_t *tbcd_string);
CORE_DECLARE(void) s1ap_conv_macro_enb_id_to_bit_string(
c_uint32_t enb_id, BIT_STRING_t *bit_string);
CORE_DECLARE(void) s1ap_conv_home_enb_id_to_bit_string(
c_uint32_t enb_id, BIT_STRING_t *bit_string);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

View File

@ -3,6 +3,7 @@
#include "core_debug.h"
#include "context.h"
#include "s1ap_message.h"
#include "s1ap_conv.h"
status_t s1ap_build_setup_rsp(pkbuf_t **pkbuf)
{
@ -17,10 +18,6 @@ status_t s1ap_build_setup_rsp(pkbuf_t **pkbuf)
S1ap_MME_Group_ID_t *mmeGroupId;
S1ap_MME_Code_t *mmeCode;
uint16_t mcc = 0x1234;
uint16_t mnc = 0x5678;
uint16_t mnc_digit_len = 2;
memset(&message, 0, sizeof(s1ap_message));
ies = &message.msg.s1ap_S1SetupResponseIEs;
@ -29,7 +26,7 @@ status_t s1ap_build_setup_rsp(pkbuf_t **pkbuf)
numServedGUMMEI = 1;
servedGUMMEI = (S1ap_ServedGUMMEIsItem_t *)
CALLOC(numServedGUMMEI, sizeof(S1ap_ServedGUMMEIsItem_t));
core_calloc(numServedGUMMEI, sizeof(S1ap_ServedGUMMEIsItem_t));
for (i = 0; i < numServedGUMMEI; i++)
{
srvd_gummei_t *srvd_gummei = &mme_self()->srvd_gummei;
@ -37,27 +34,30 @@ status_t s1ap_build_setup_rsp(pkbuf_t **pkbuf)
for (j = 0; j < srvd_gummei->num_of_plmn_id; j++)
{
plmnIdentity = (S1ap_PLMNidentity_t *)
CALLOC(srvd_gummei->num_of_plmn_id,
core_calloc(srvd_gummei->num_of_plmn_id,
sizeof(S1ap_PLMNidentity_t));
MCC_MNC_TO_TBCD(mcc, mnc, mnc_digit_len, plmnIdentity);
s1ap_conv_plmn_id_to_tbcd_string(
&srvd_gummei->plmn_id[j], plmnIdentity);
ASN_SEQUENCE_ADD(&servedGUMMEI->servedPLMNs, plmnIdentity);
}
for (j = 0; j < srvd_gummei->num_of_grp_id; j++)
{
mmeGroupId = (S1ap_MME_Group_ID_t *)
CALLOC(srvd_gummei->num_of_grp_id,
core_calloc(srvd_gummei->num_of_grp_id,
sizeof(S1ap_MME_Group_ID_t));
INT16_TO_OCTET_STRING(srvd_gummei->grp_id[j], mmeGroupId);
s1ap_conv_uint16_to_octet_string(
srvd_gummei->grp_id[j], mmeGroupId);
ASN_SEQUENCE_ADD(&servedGUMMEI->servedGroupIDs, mmeGroupId);
}
for (j = 0; j < srvd_gummei->num_of_code; j++)
{
mmeCode = (S1ap_MME_Code_t *)
CALLOC(srvd_gummei->num_of_grp_id,
core_calloc(srvd_gummei->num_of_grp_id,
sizeof(S1ap_MME_Code_t));
INT8_TO_OCTET_STRING(srvd_gummei->code[j], mmeCode);
s1ap_conv_uint8_to_octet_string(
srvd_gummei->code[j], mmeCode);
ASN_SEQUENCE_ADD(&servedGUMMEI->servedMMECs, mmeCode);
}
}

View File

@ -9,359 +9,6 @@ extern "C" {
#define S1AP_SDU_SIZE 2048
#define BUFFER_TO_INT8(buf, x) (x = ((buf)[0]))
#define INT8_TO_BUFFER(x, buf) ((buf)[0] = (x))
/* Convert an integer on 16 bits to the given bUFFER */
#define INT16_TO_BUFFER(x, buf) \
do { \
(buf)[0] = (x) >> 8; \
(buf)[1] = (x); \
} while(0)
/* Convert an array of char containing vALUE to x */
#define BUFFER_TO_INT16(buf, x) \
do { \
x = ((buf)[0] << 8) | \
((buf)[1]); \
} while(0)
/* Convert an integer on 32 bits to the given bUFFER */
#define INT32_TO_BUFFER(x, buf) \
do { \
(buf)[0] = (x) >> 24; \
(buf)[1] = (x) >> 16; \
(buf)[2] = (x) >> 8; \
(buf)[3] = (x); \
} while(0)
/* Convert an array of char containing vALUE to x */
#define BUFFER_TO_INT32(buf, x) \
do { \
x = ((buf)[0] << 24) | \
((buf)[1] << 16) | \
((buf)[2] << 8) | \
((buf)[3]); \
} while(0)
/* Convert an integer on 32 bits to an octet string from aSN1c tool */
#define INT32_TO_OCTET_STRING(x, aSN) \
do { \
(aSN)->buf = CALLOC(4, sizeof(uint8_t)); \
INT32_TO_BUFFER(x, ((aSN)->buf)); \
(aSN)->size = 4; \
} while(0)
#define INT32_TO_BIT_STRING(x, aSN) \
do { \
INT32_TO_OCTET_STRING(x, aSN); \
(aSN)->bits_unused = 0; \
} while(0)
#define INT16_TO_OCTET_STRING(x, aSN) \
do { \
(aSN)->buf = CALLOC(2, sizeof(uint8_t)); \
(aSN)->size = 2; \
INT16_TO_BUFFER(x, (aSN)->buf); \
} while(0)
#define INT8_TO_OCTET_STRING(x, aSN) \
do { \
(aSN)->buf = CALLOC(1, sizeof(uint8_t)); \
(aSN)->size = 1; \
INT8_TO_BUFFER(x, (aSN)->buf); \
} while(0)
#define MME_CODE_TO_OCTET_STRING INT8_TO_OCTET_STRING
#define M_TMSI_TO_OCTET_STRING INT32_TO_OCTET_STRING
#define MME_GID_TO_OCTET_STRING INT16_TO_OCTET_STRING
#define OCTET_STRING_TO_INT8(aSN, x) \
do { \
d_assert((aSN)->size == 1, , "invalid size(%d)", (aSN)->size); \
BUFFER_TO_INT8((aSN)->buf, x); \
} while(0)
#define OCTET_STRING_TO_INT16(aSN, x) \
do { \
d_assert((aSN)->size == 2, , "invalid size(%d)", (aSN)->size); \
BUFFER_TO_INT16((aSN)->buf, x); \
} while(0)
#define OCTET_STRING_TO_INT32(aSN, x) \
do { \
d_assert((aSN)->size == 4, , "invalid size(%d)", (aSN)->size); \
BUFFER_TO_INT32((aSN)->buf, x); \
} while(0)
#define BIT_STRING_TO_INT32(aSN, x) \
do { \
d_assert((aSN)->bits_unused == 0, , "unused bits(%d)", (aSN)->bits_unused); \
OCTET_STRING_TO_INT32(aSN, x); \
} while(0)
#define BIT_STRING_TO_CELL_IDENTITY(aSN, vALUE) \
do { \
d_assert((aSN)->bits_unused == 4, , "unused bits(%d)", (aSN)->bits_unused); \
vALUE.enb_id = ((aSN)->buf[0] << 12) | ((aSN)->buf[1] << 4) | \
((aSN)->buf[2] >> 4); \
vALUE.cell_id = ((aSN)->buf[2] << 4) | ((aSN)->buf[3] >> 4); \
} while(0)
#define MCC_HUNDREDS(vALUE) \
((vALUE) / 100)
/* When MNC is only composed of 2 digits, set the hundreds unit to 0xf */
#define MNC_HUNDREDS(vALUE, mNCdIGITlENGTH) \
( mNCdIGITlENGTH == 2 ? 15 : (vALUE) / 100)
#define MCC_MNC_DECIMAL(vALUE) \
(((vALUE) / 10) % 10)
#define MCC_MNC_DIGIT(vALUE) \
((vALUE) % 10)
#define MCC_TO_BUFFER(mCC, bUFFER) \
do { \
d_assert(bUFFER, , "Null param"); \
(bUFFER)[0] = MCC_HUNDREDS(mCC); \
(bUFFER)[1] = MCC_MNC_DECIMAL(mCC); \
(bUFFER)[2] = MCC_MNC_DIGIT(mCC); \
} while(0)
#define MCC_MNC_TO_PLMNID(mCC, mNC, mNCdIGITlENGTH, oCTETsTRING) \
do { \
(oCTETsTRING)->buf = CALLOC(3, sizeof(uint8_t)); \
(oCTETsTRING)->buf[0] = (MCC_MNC_DECIMAL(mCC) << 4) | MCC_HUNDREDS(mCC); \
(oCTETsTRING)->buf[1] = (MNC_HUNDREDS(mNC,mNCdIGITlENGTH) << 4) | MCC_MNC_DIGIT(mCC); \
(oCTETsTRING)->buf[2] = (MCC_MNC_DIGIT(mNC) << 4) | MCC_MNC_DECIMAL(mNC); \
(oCTETsTRING)->size = 3; \
} while(0)
#define MCC_MNC_TO_TBCD(mCC, mNC, mNCdIGITlENGTH, tBCDsTRING) \
do { \
char _buf[3]; \
d_assert((mNCdIGITlENGTH == 3) || (mNCdIGITlENGTH == 2),, "Invalid Length(%d)", mNCdIGITlENGTH); \
_buf[0] = (MCC_MNC_DECIMAL(mCC) << 4) | MCC_HUNDREDS(mCC); \
_buf[1] = (MNC_HUNDREDS(mNC,mNCdIGITlENGTH) << 4) | MCC_MNC_DIGIT(mCC);\
_buf[2] = (MCC_MNC_DIGIT(mNC) << 4) | MCC_MNC_DECIMAL(mNC); \
OCTET_STRING_fromBuf(tBCDsTRING, _buf, 3); \
} while(0)
#define TBCD_TO_MCC_MNC(tBCDsTRING, mCC, mNC, mNCdIGITlENGTH) \
do { \
int mNC_hundred; \
d_assert((tBCDsTRING)->size == 3, , "invalid size(%d)", (tBCDsTRING)->size); \
mNC_hundred = (((tBCDsTRING)->buf[1] & 0xf0) >> 4); \
if (mNC_hundred == 0xf) { \
mNC_hundred = 0; \
mNCdIGITlENGTH = 2; \
} else { \
mNCdIGITlENGTH = 3; \
} \
mCC = (((((tBCDsTRING)->buf[0]) & 0xf0) >> 4) * 10) + \
((((tBCDsTRING)->buf[0]) & 0x0f) * 100) + \
(((tBCDsTRING)->buf[1]) & 0x0f); \
mNC = (mNC_hundred * 100) + \
((((tBCDsTRING)->buf[2]) & 0xf0) >> 4) + \
((((tBCDsTRING)->buf[2]) & 0x0f) * 10); \
} while(0)
#define TBCD_TO_PLMN_T(tBCDsTRING, pLMN) \
do { \
d_assert((tBCDsTRING)->size == 3, , "invalid size(%d)", (tBCDsTRING)->size); \
(pLMN)->mcc_digit2 = (((tBCDsTRING)->buf[0] & 0xf0) >> 4); \
(pLMN)->mcc_digit1 = ((tBCDsTRING)->buf[0] & 0x0f); \
(pLMN)->mnc_digit3 = (((tBCDsTRING)->buf[1] & 0xf0) >> 4); \
(pLMN)->mcc_digit3 = ((tBCDsTRING)->buf[1] & 0x0f); \
(pLMN)->mnc_digit2 = (((tBCDsTRING)->buf[2] & 0xf0) >> 4); \
(pLMN)->mnc_digit1 = ((tBCDsTRING)->buf[2] & 0x0f); \
} while(0)
#define PLMN_T_TO_TBCD(pLMN, tBCDsTRING, mNClENGTH) \
do { \
tBCDsTRING[0] = (pLMN.mcc_digit2 << 4) | pLMN.mcc_digit1; \
/* ambiguous (think about len 2) */ \
if (mNClENGTH == 2) { \
tBCDsTRING[1] = (0x0F << 4) | pLMN.mcc_digit3; \
tBCDsTRING[2] = (pLMN.mnc_digit2 << 4) | pLMN.mnc_digit1; \
} else { \
tBCDsTRING[1] = (pLMN.mnc_digit3 << 4) | pLMN.mcc_digit3; \
tBCDsTRING[2] = (pLMN.mnc_digit2 << 4) | pLMN.mnc_digit1; \
} \
} while(0)
#define PLMN_T_TO_MCC_MNC(pLMN, mCC, mNC, mNCdIGITlENGTH) \
do { \
mCC = pLMN.mcc_digit3 * 100 + pLMN.mcc_digit2 * 10 + pLMN.mcc_digit1; \
mNCdIGITlENGTH = (pLMN.mnc_digit3 == 0xF ? 2 : 3); \
mNC = (mNCdIGITlENGTH == 2 ? 0 : pLMN.mnc_digit3 * 100) \
+ pLMN.mnc_digit2 * 10 + pLMN.mnc_digit1; \
} while(0)
/*
* TS 36.413 v10.9.0 section 9.2.1.37:
* Macro eNB ID:
* Equal to the 20 leftmost bits of the Cell
* Identity IE contained in the E-UTRAN CGI
* IE (see subclause 9.2.1.38) of each cell
* served by the eNB.
*/
#define MACRO_ENB_ID_TO_BIT_STRING(mACRO, bITsTRING) \
do { \
(bITsTRING)->buf = CALLOC(3, sizeof(uint8_t)); \
(bITsTRING)->buf[0] = ((mACRO) >> 12); \
(bITsTRING)->buf[1] = (mACRO) >> 4; \
(bITsTRING)->buf[2] = ((mACRO) & 0x0f) << 4; \
(bITsTRING)->size = 3; \
(bITsTRING)->bits_unused = 4; \
} while(0)
/*
* TS 36.413 v10.9.0 section 9.2.1.38:
* E-UTRAN CGI/Cell Identity
* The leftmost bits of the Cell
* Identity correspond to the eNB
* ID (defined in subclause 9.2.1.37).
*/
#define MACRO_ENB_ID_TO_CELL_IDENTITY(mACRO, cELL_iD, bITsTRING) \
do { \
(bITsTRING)->buf = CALLOC(4, sizeof(uint8_t)); \
(bITsTRING)->buf[0] = ((mACRO) >> 12); \
(bITsTRING)->buf[1] = (mACRO) >> 4; \
(bITsTRING)->buf[2] = (((mACRO) & 0x0f) << 4) | ((cELL_iD) >> 4); \
(bITsTRING)->buf[3] = ((cELL_iD) & 0x0f) << 4; \
(bITsTRING)->size = 4; \
(bITsTRING)->bits_unused = 4; \
} while(0)
/* Used to format an uint32_t containing an ipv4 address */
#define IPV4_ADDR "%u.%u.%u.%u"
#define IPV4_ADDR_FORMAT(aDDRESS) \
(uint8_t)((aDDRESS) & 0x000000ff), \
(uint8_t)(((aDDRESS) & 0x0000ff00) >> 8 ), \
(uint8_t)(((aDDRESS) & 0x00ff0000) >> 16), \
(uint8_t)(((aDDRESS) & 0xff000000) >> 24)
#define IPV4_ADDR_DISPLAY_8(aDDRESS) \
(aDDRESS)[0], (aDDRESS)[1], (aDDRESS)[2], (aDDRESS)[3]
#define TAC_TO_ASN1 INT16_TO_OCTET_STRING
#define GTP_TEID_TO_ASN1 INT32_TO_OCTET_STRING
#define OCTET_STRING_TO_TAC OCTET_STRING_TO_INT16
#define OCTET_STRING_TO_MME_CODE OCTET_STRING_TO_INT8
#define OCTET_STRING_TO_M_TMSI OCTET_STRING_TO_INT32
#define OCTET_STRING_TO_MME_GID OCTET_STRING_TO_INT16
#define OCTET_STRING_TO_CSG_ID OCTET_STRING_TO_INT27
/* Convert the IMSI contained by a char string NULL terminated to uint64_t */
#define IMSI_STRING_TO_IMSI64(sTRING, iMSI64_pTr) sscanf(sTRING, IMSI_64_FMT, iMSI64_pTr)
#define IMSI64_TO_STRING(iMSI64, sTRING) snprintf(sTRING, IMSI_BCD_DIGITS_MAX+1, IMSI_64_FMT, iMSI64)
#define IMSI_TO_IMSI64(iMsI_t_PtR,iMsI_u64) \
{\
uint64_t mUlT = 1; \
iMsI_u64 = (iMsI_t_PtR)->u.num.digit1; \
if ((iMsI_t_PtR)->u.num.digit15 != 0xf) { \
iMsI_u64 = (iMsI_t_PtR)->u.num.digit15 + \
(iMsI_t_PtR)->u.num.digit14 *10 + \
(iMsI_t_PtR)->u.num.digit13 *100 + \
(iMsI_t_PtR)->u.num.digit12 *1000 + \
(iMsI_t_PtR)->u.num.digit11 *10000 + \
(iMsI_t_PtR)->u.num.digit10 *100000 + \
(iMsI_t_PtR)->u.num.digit9 *1000000 + \
(iMsI_t_PtR)->u.num.digit8 *10000000 + \
(iMsI_t_PtR)->u.num.digit7 *100000000; \
mUlT = 1000000000; \
} else { \
iMsI_u64 = (iMsI_t_PtR)->u.num.digit14 + \
(iMsI_t_PtR)->u.num.digit13 *10 + \
(iMsI_t_PtR)->u.num.digit12 *100 + \
(iMsI_t_PtR)->u.num.digit11 *1000 + \
(iMsI_t_PtR)->u.num.digit10 *10000 + \
(iMsI_t_PtR)->u.num.digit9 *100000 + \
(iMsI_t_PtR)->u.num.digit8 *1000000 + \
(iMsI_t_PtR)->u.num.digit7 *10000000; \
mUlT = 100000000; \
} \
if ((iMsI_t_PtR)->u.num.digit6 != 0xf) {\
iMsI_u64 += (iMsI_t_PtR)->u.num.digit6 *mUlT; \
iMsI_u64 += (iMsI_t_PtR)->u.num.digit5 *mUlT*10; \
iMsI_u64 += (iMsI_t_PtR)->u.num.digit4 *mUlT*100; \
iMsI_u64 += (iMsI_t_PtR)->u.num.digit3 *mUlT*1000; \
iMsI_u64 += (iMsI_t_PtR)->u.num.digit2 *mUlT*10000; \
iMsI_u64 += (iMsI_t_PtR)->u.num.digit1 *mUlT*100000; \
} else { \
iMsI_u64 += (iMsI_t_PtR)->u.num.digit5 *mUlT; \
iMsI_u64 += (iMsI_t_PtR)->u.num.digit4 *mUlT*10; \
iMsI_u64 += (iMsI_t_PtR)->u.num.digit3 *mUlT*100; \
iMsI_u64 += (iMsI_t_PtR)->u.num.digit2 *mUlT*1000; \
iMsI_u64 += (iMsI_t_PtR)->u.num.digit1 *mUlT*10000; \
} \
}
/*#define IMSI_TO_STRING(iMsI_t_PtR,iMsI_sTr, MaXlEn) \
{\
int l_offset = 0;\
int l_ret = 0;\
l_ret = snprintf(iMsI_sTr + l_offset, MaXlEn - l_offset, "%u%u%u%u%u",\
(iMsI_t_PtR)->u.num.digit1, (iMsI_t_PtR)->u.num.digit2,\
(iMsI_t_PtR)->u.num.digit3, (iMsI_t_PtR)->u.num.digit4,\
(iMsI_t_PtR)->u.num.digit5);\
if (((iMsI_t_PtR)->u.num.digit6 != 0xf) && (l_ret > 0)) {\
l_offset += l_ret;\
l_ret = snprintf(iMsI_sTr + l_offset, MaXlEn - l_offset, "%u", (iMsI_t_PtR)->u.num.digit6);\
}\
if (l_ret > 0) {\
l_offset += l_ret;\
l_ret = snprintf(iMsI_sTr + l_offset, MaXlEn - l_offset, "%u%u%u%u%u%u%u%u",\
(iMsI_t_PtR)->u.num.digit7, (iMsI_t_PtR)->u.num.digit8,\
(iMsI_t_PtR)->u.num.digit9, (iMsI_t_PtR)->u.num.digit10,\
(iMsI_t_PtR)->u.num.digit11, (iMsI_t_PtR)->u.num.digit12,\
(iMsI_t_PtR)->u.num.digit13, (iMsI_t_PtR)->u.num.digit14);\
}\
if (((iMsI_t_PtR)->u.num.digit15 != 0x0) && (l_ret > 0)) {\
l_offset += l_ret;\
l_ret = snprintf(iMsI_sTr + l_offset, MaXlEn - l_offset, "%u", (iMsI_t_PtR)->u.num.digit15);\
}\
}*/
#define IMSI_TO_STRING(iMsI_t_PtR,iMsI_sTr, MaXlEn) \
do { \
int l_i = 0; \
int l_j = 0; \
while((l_i < IMSI_BCD8_SIZE) && (l_j < MaXlEn - 1)){ \
if((((iMsI_t_PtR)->u.value[l_i] & 0xf0) >> 4) > 9) \
break; \
sprintf(((iMsI_sTr) + l_j), "%u",(((iMsI_t_PtR)->u.value[l_i] & 0xf0) >> 4)); \
l_j++; \
if(((iMsI_t_PtR)->u.value[l_i] & 0xf) > 9 || (l_j >= MaXlEn - 1)) \
break; \
sprintf(((iMsI_sTr) + l_j), "%u", ((iMsI_t_PtR)->u.value[l_i] & 0xf)); \
l_j++; \
l_i++; \
} \
for(; l_j < MaXlEn; l_j++) \
iMsI_sTr[l_j] = '\0'; \
} while (0);\
#define IMEI_TO_STRING(iMeI_t_PtR,iMeI_sTr, MaXlEn) \
{\
int l_offset = 0;\
int l_ret = 0;\
l_ret = snprintf(iMeI_sTr + l_offset, MaXlEn - l_offset, "%u%u%u%u%u%u%u%u",\
(iMeI_t_PtR)->u.num.tac1, (iMeI_t_PtR)->u.num.tac2,\
(iMeI_t_PtR)->u.num.tac3, (iMeI_t_PtR)->u.num.tac4,\
(iMeI_t_PtR)->u.num.tac5, (iMeI_t_PtR)->u.num.tac6,\
(iMeI_t_PtR)->u.num.tac7, (iMeI_t_PtR)->u.num.tac8);\
if (l_ret > 0) {\
l_offset += l_ret;\
l_ret = snprintf(iMeI_sTr + l_offset, MaXlEn - l_offset, "%u%u%u%u%u%u",\
(iMeI_t_PtR)->u.num.snr1, (iMeI_t_PtR)->u.num.snr2,\
(iMeI_t_PtR)->u.num.snr3, (iMeI_t_PtR)->u.num.snr4,\
(iMeI_t_PtR)->u.num.snr5, (iMeI_t_PtR)->u.num.snr6);\
}\
if (((iMeI_t_PtR)->u.num.parity != 0x0) && (l_ret > 0)) {\
l_offset += l_ret;\
l_ret = snprintf(iMeI_sTr + l_offset, MaXlEn - l_offset, "%u", (iMeI_t_PtR)->u.num.cdsd);\
}\
}
CORE_DECLARE(status_t) s1ap_build_setup_rsp(pkbuf_t **pkbuf);
#ifdef __cplusplus

View File

@ -7,6 +7,7 @@
#include "testutil.h"
#include "s1ap_message.h"
#include "s1ap_conv.h"
static void s1ap_test1(abts_case *tc, void *data)
{
@ -102,11 +103,7 @@ static void s1ap_test5(abts_case *tc, void *data)
S1ap_PLMNidentity_t *plmnIdentity;
S1ap_SupportedTAs_Item_t *supportedTA;
uint16_t mcc = 0x1234;
uint16_t mnc = 0x5678;
uint16_t mnc_digit_len = 2;
uint32_t enb_id = 0x5f123;
uint32_t tac = 0x1234;
memset(&message, 0, sizeof(s1ap_message));
@ -114,17 +111,19 @@ static void s1ap_test5(abts_case *tc, void *data)
s1SetupRequestIEs->global_ENB_ID.eNB_ID.present =
S1ap_ENB_ID_PR_macroENB_ID;
MACRO_ENB_ID_TO_BIT_STRING(enb_id,
s1ap_conv_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_len,
&s1SetupRequestIEs->global_ENB_ID.pLMNidentity);
s1ap_conv_plmn_id_to_tbcd_string(
&mme_self()->plmn_id, &s1SetupRequestIEs->global_ENB_ID.pLMNidentity);
supportedTA = (S1ap_SupportedTAs_Item_t *)
CALLOC(1, sizeof(S1ap_SupportedTAs_Item_t));
INT16_TO_OCTET_STRING(tac, &supportedTA->tAC);
core_calloc(1, sizeof(S1ap_SupportedTAs_Item_t));
s1ap_conv_uint16_to_octet_string(mme_self()->tac, &supportedTA->tAC);
plmnIdentity = (S1ap_PLMNidentity_t *)
CALLOC(1, sizeof(S1ap_PLMNidentity_t));
MCC_MNC_TO_TBCD(mcc, mnc, mnc_digit_len, plmnIdentity);
core_calloc(1, sizeof(S1ap_PLMNidentity_t));
s1ap_conv_plmn_id_to_tbcd_string(
&mme_self()->plmn_id, plmnIdentity);
ASN_SEQUENCE_ADD(&supportedTA->broadcastPLMNs, plmnIdentity);
ASN_SEQUENCE_ADD(&s1SetupRequestIEs->supportedTAs, supportedTA);