1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/* Test de-/encoding of HBNAP messages */
/* (C) 2015 by Daniel Willmann <dwillmann@sysmocom.de>
* (C) 2015 by sysmocom s.f.m.c GmbH
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <osmocom/ranap/iu_helpers.h>
#include <osmocom/ranap/ranap_common_cn.h>
#include "asn1helpers.h"
#include <osmocom/hnbap/hnbap_common.h>
#include <osmocom/hnbap/hnbap_ies_defs.h>
#include <osmocom/ranap/ranap_common.h>
#include "test_common.h"
#include <assert.h>
#define ASSERT(x) assert(x)
#include <osmocom/core/utils.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/application.h>
static const unsigned char hnbap_reg_req[] = {
0x00, 0x01,
0x00, 0x57, 0x00, 0x00, 0x07, 0x00, 0x03, 0x00,
0x15, 0x04, 0x80, 0x31, 0x30, 0x30, 0x30, 0x35,
0x42, 0x39, 0x2d, 0x30, 0x30, 0x31, 0x30, 0x39,
0x34, 0x32, 0x30, 0x35, 0x30, 0x40, 0x00, 0x08,
0x00, 0x17, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x11, 0x00, 0x05, 0x00, 0xc0, 0xa8, 0x00,
0x32, 0x00, 0x09, 0x00, 0x03, 0x09, 0xf1, 0x99,
0x00, 0x0b, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
0x00, 0x06, 0x00, 0x02, 0x40, 0x20, 0x00, 0x07,
0x00, 0x01, 0x64, 0x00, 0x0a, 0x00, 0x02, 0x00,
0x01
};
static const unsigned char hnbap_ue_reg_req[] = {
0x00, 0x03,
0x00, 0x1a, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00,
0x09, 0x0a, 0x62, 0x02, 0x11, 0x32, 0x54, 0x76,
0x98, 0xf0, 0x00, 0x0c, 0x40, 0x01, 0x40, 0x00,
0x0d, 0x00, 0x01, 0x0d
};
static const unsigned char hnbap_ue_reg_acc[] = {
0x20, 0x03,
0x00, 0x17, 0x00, 0x00, 0x02, 0x00, 0x05, 0x00,
0x09, 0x0a, 0x62, 0x02, 0x11, 0x32, 0x54, 0x76,
0x98, 0xf0, 0x00, 0x04, 0x00, 0x03, 0x17, 0x00,
0x00
};
void test_asn1_decoding(void)
{
int rc;
HNBAP_HNBAP_PDU_t _pdu, *pdu = &_pdu;
HNBAP_InitiatingMessage_t *im;
HNBAP_SuccessfulOutcome_t *so;
HNBAP_UERegisterRequestIEs_t ue_req_ies;
HNBAP_UERegisterAcceptIEs_t ue_acc_ies;
HNBAP_HNBRegisterRequestIEs_t hnb_ies;
char imsi[16];
asn_dec_rval_t dec_ret;
memset(pdu, 0, sizeof(*pdu));
printf("Testing asn.1 HNBAP decoding\n");
dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_HNBAP_PDU, (void **) &pdu,
hnbap_reg_req, sizeof(hnbap_reg_req), 0, 0);
ASSERT(dec_ret.code == RC_OK);
ASSERT(pdu->present == HNBAP_HNBAP_PDU_PR_initiatingMessage);
im = &pdu->choice.initiatingMessage;
ASSERT(im->procedureCode == HNBAP_ProcedureCode_id_HNBRegister);
rc = hnbap_decode_hnbregisterrequesties(&hnb_ies, &im->value);
ASSERT(rc >= 0);
uint16_t lac, sac;
uint8_t rac;
uint32_t cid;
lac = asn1str_to_u16(&hnb_ies.lac);
sac = asn1str_to_u16(&hnb_ies.sac);
rac = asn1str_to_u8(&hnb_ies.rac);
cid = asn1bitstr_to_u32(&hnb_ies.cellIdentity);
ASSERT(lac == 0x4020);
ASSERT(sac == 0x0001);
ASSERT(rac == 0x64);
ASSERT(cid == 0x0000000);
ASSERT(!strcmp((char *) hnb_ies.hnB_Identity.hNB_Identity_Info.buf, "10005B9-0010942050@"));
printf("HNBAP register request for HNB %s\n", (char *) hnb_ies.hnB_Identity.hNB_Identity_Info.buf);
hnbap_free_hnbregisterrequesties(&hnb_ies);
dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_HNBAP_PDU, (void **) &pdu,
hnbap_ue_reg_req, sizeof(hnbap_ue_reg_req), 0, 0);
ASSERT(dec_ret.code == RC_OK);
ASSERT(pdu->present == HNBAP_HNBAP_PDU_PR_initiatingMessage);
im = &pdu->choice.initiatingMessage;
ASSERT(im->procedureCode == HNBAP_ProcedureCode_id_UERegister);
rc = hnbap_decode_ueregisterrequesties(&ue_req_ies, &im->value);
ASSERT(rc >= 0);
ASSERT(ue_req_ies.uE_Identity.present == HNBAP_UE_Identity_PR_iMSI);
ranap_bcd_decode(imsi, sizeof(imsi), ue_req_ies.uE_Identity.choice.iMSI.buf,
ue_req_ies.uE_Identity.choice.iMSI.size);
printf("HNBAP UE Register request from IMSI %s\n", imsi);
hnbap_free_ueregisterrequesties(&ue_req_ies);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_HNBAP_PDU, pdu);
memset(pdu, 0, sizeof(*pdu));
dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_HNBAP_PDU, (void **) &pdu,
hnbap_ue_reg_acc, sizeof(hnbap_ue_reg_acc), 0, 0);
ASSERT(dec_ret.code == RC_OK);
ASSERT(pdu->present == HNBAP_HNBAP_PDU_PR_successfulOutcome);
so = &pdu->choice.successfulOutcome;
ASSERT(so->procedureCode == HNBAP_ProcedureCode_id_UERegister);
rc = hnbap_decode_ueregisteraccepties(&ue_acc_ies, &so->value);
ASSERT(rc >= 0);
ASSERT(ue_acc_ies.uE_Identity.present == HNBAP_UE_Identity_PR_iMSI);
ranap_bcd_decode(imsi, sizeof(imsi), ue_acc_ies.uE_Identity.choice.iMSI.buf,
ue_acc_ies.uE_Identity.choice.iMSI.size);
printf("HNBAP UE Register accept to IMSI %s\n", imsi);
hnbap_free_ueregisteraccepties(&ue_acc_ies);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_HNBAP_PDU, pdu);
}
int main(int argc, char **argv)
{
test_common_init();
ranap_set_log_area(DRANAP);
hnbap_set_log_area(DHNBAP);
log_set_log_level(osmo_stderr_target, LOGL_INFO);
test_asn1_decoding();
test_common_cleanup();
return 0;
}
|