blob: dfd5ae9af7420b68bf349f0a18d06232cde2a8fb [file] [log] [blame]
Daniel Willmann39e643a2015-11-24 18:03:29 +01001/* Test de-/encoding of HBNAP messages */
2
3/* (C) 2015 by Daniel Willmann <dwillmann@sysmocom.de>
4 * (C) 2015 by sysmocom s.f.m.c GmbH
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
Neels Hofmeyr96979af2016-01-05 15:19:44 +010022#include <osmocom/ranap/iu_helpers.h>
Daniel Willmannea4c0882015-11-27 16:14:09 +010023#include "asn1helpers.h"
Daniel Willmann39e643a2015-11-24 18:03:29 +010024
Neels Hofmeyr83457922016-08-26 23:56:44 +020025#include <osmocom/hnbap/hnbap_common.h>
26#include <osmocom/hnbap/hnbap_ies_defs.h>
Harald Welte87ffeb92015-12-25 15:34:22 +010027#include "test_common.h"
Daniel Willmann39e643a2015-11-24 18:03:29 +010028
29#include <assert.h>
30#define ASSERT(x) assert(x)
31
32#include <osmocom/core/utils.h>
33#include <osmocom/core/logging.h>
Harald Welte87ffeb92015-12-25 15:34:22 +010034#include <osmocom/core/application.h>
Daniel Willmann39e643a2015-11-24 18:03:29 +010035
Daniel Willmannea4c0882015-11-27 16:14:09 +010036static const unsigned char hnbap_reg_req[] = {
370x00, 0x01,
380x00, 0x57, 0x00, 0x00, 0x07, 0x00, 0x03, 0x00,
390x15, 0x04, 0x80, 0x31, 0x30, 0x30, 0x30, 0x35,
400x42, 0x39, 0x2d, 0x30, 0x30, 0x31, 0x30, 0x39,
410x34, 0x32, 0x30, 0x35, 0x30, 0x40, 0x00, 0x08,
420x00, 0x17, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
430xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
440x00, 0x11, 0x00, 0x05, 0x00, 0xc0, 0xa8, 0x00,
450x32, 0x00, 0x09, 0x00, 0x03, 0x09, 0xf1, 0x99,
460x00, 0x0b, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
470x00, 0x06, 0x00, 0x02, 0x40, 0x20, 0x00, 0x07,
480x00, 0x01, 0x64, 0x00, 0x0a, 0x00, 0x02, 0x00,
490x01
50};
51
52static const unsigned char hnbap_reg_acc[] = {
530x20, 0x01,
540x00, 0x09, 0x00, 0x00, 0x01, 0x00, 0x0e, 0x00,
550x02, 0x00, 0x00
56};
57
Daniel Willmann39e643a2015-11-24 18:03:29 +010058static const unsigned char hnbap_ue_reg_req[] = {
590x00, 0x03,
600x00, 0x1a, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00,
610x09, 0x0a, 0x62, 0x02, 0x11, 0x32, 0x54, 0x76,
620x98, 0xf0, 0x00, 0x0c, 0x40, 0x01, 0x40, 0x00,
630x0d, 0x00, 0x01, 0x0d
64};
65
66static const unsigned char hnbap_ue_reg_acc[] = {
670x20, 0x03,
680x00, 0x17, 0x00, 0x00, 0x02, 0x00, 0x05, 0x00,
690x09, 0x0a, 0x62, 0x02, 0x11, 0x32, 0x54, 0x76,
700x98, 0xf0, 0x00, 0x04, 0x00, 0x03, 0x17, 0x00,
710x00
72};
73
74void test_asn1_decoding(void)
75{
76 int rc;
77
78 HNBAP_PDU_t _pdu, *pdu = &_pdu;
79 InitiatingMessage_t *im;
Daniel Willmann1a869552015-11-24 18:11:03 +010080 SuccessfulOutcome_t *so;
Daniel Willmann23c86e32015-11-30 16:03:36 +010081 UERegisterRequestIEs_t ue_req_ies;
82 UERegisterAcceptIEs_t ue_acc_ies;
Daniel Willmannea4c0882015-11-27 16:14:09 +010083 HNBRegisterRequestIEs_t hnb_ies;
Daniel Willmann39e643a2015-11-24 18:03:29 +010084
85 char imsi[16];
86
87 asn_dec_rval_t dec_ret;
88
89 memset(pdu, 0, sizeof(*pdu));
90 printf("Testing asn.1 HNBAP decoding\n");
91
92 dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu,
Daniel Willmannea4c0882015-11-27 16:14:09 +010093 hnbap_reg_req, sizeof(hnbap_reg_req), 0, 0);
94
95
96 ASSERT(dec_ret.code == RC_OK);
97 ASSERT(pdu->present == HNBAP_PDU_PR_initiatingMessage);
98
99 im = &pdu->choice.initiatingMessage;
100
101 ASSERT(im->procedureCode == ProcedureCode_id_HNBRegister);
102
103 rc = hnbap_decode_hnbregisterrequesties(&hnb_ies, &im->value);
104 ASSERT(rc >= 0);
105
106 uint16_t lac, sac;
107 uint8_t rac;
108 uint32_t cid;
109
110 lac = asn1str_to_u16(&hnb_ies.lac);
111 sac = asn1str_to_u16(&hnb_ies.sac);
112 rac = asn1str_to_u8(&hnb_ies.rac);
Daniel Willmanne2956432015-11-30 16:05:51 +0100113 cid = asn1bitstr_to_u32(&hnb_ies.cellIdentity);
Daniel Willmannea4c0882015-11-27 16:14:09 +0100114
115 ASSERT(lac == 0x4020);
116 ASSERT(sac == 0x0001);
117 ASSERT(rac == 0x64);
Daniel Willmanne2956432015-11-30 16:05:51 +0100118 ASSERT(cid == 0x0000000);
Daniel Willmannea4c0882015-11-27 16:14:09 +0100119
Daniel Willmanne2956432015-11-30 16:05:51 +0100120 ASSERT(!strcmp((char *) hnb_ies.hnB_Identity.hNB_Identity_Info.buf, "10005B9-0010942050@"));
121
122 printf("HNBAP register request for HNB %s\n", (char *) hnb_ies.hnB_Identity.hNB_Identity_Info.buf);
Daniel Willmann11e912a2016-01-07 13:19:30 +0100123 hnbap_free_hnbregisterrequesties(&hnb_ies);
124
Daniel Willmannea4c0882015-11-27 16:14:09 +0100125 dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu,
Daniel Willmann39e643a2015-11-24 18:03:29 +0100126 hnbap_ue_reg_req, sizeof(hnbap_ue_reg_req), 0, 0);
127
128
129 ASSERT(dec_ret.code == RC_OK);
130 ASSERT(pdu->present == HNBAP_PDU_PR_initiatingMessage);
131
132 im = &pdu->choice.initiatingMessage;
133 ASSERT(im->procedureCode == ProcedureCode_id_UERegister);
134
Daniel Willmann23c86e32015-11-30 16:03:36 +0100135 rc = hnbap_decode_ueregisterrequesties(&ue_req_ies, &im->value);
Daniel Willmann39e643a2015-11-24 18:03:29 +0100136 ASSERT(rc >= 0);
137
Daniel Willmann23c86e32015-11-30 16:03:36 +0100138 ASSERT(ue_req_ies.uE_Identity.present == UE_Identity_PR_iMSI);
Harald Welte056984f2016-01-03 16:31:31 +0100139 ranap_bcd_decode(imsi, sizeof(imsi), ue_req_ies.uE_Identity.choice.iMSI.buf,
Daniel Willmann23c86e32015-11-30 16:03:36 +0100140 ue_req_ies.uE_Identity.choice.iMSI.size);
Daniel Willmann39e643a2015-11-24 18:03:29 +0100141
Daniel Willmann1a869552015-11-24 18:11:03 +0100142 printf("HNBAP UE Register request from IMSI %s\n", imsi);
Daniel Willmann11e912a2016-01-07 13:19:30 +0100143 hnbap_free_ueregisterrequesties(&ue_req_ies);
Daniel Willmann1a869552015-11-24 18:11:03 +0100144
Neels Hofmeyrd9cb19a2017-11-18 18:47:55 +0100145 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_PDU, pdu);
146
Daniel Willmann1a869552015-11-24 18:11:03 +0100147 memset(pdu, 0, sizeof(*pdu));
148 dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu,
149 hnbap_ue_reg_acc, sizeof(hnbap_ue_reg_acc), 0, 0);
150
151
152 ASSERT(dec_ret.code == RC_OK);
153 ASSERT(pdu->present == HNBAP_PDU_PR_successfulOutcome);
154
155 so = &pdu->choice.successfulOutcome;
156 ASSERT(so->procedureCode == ProcedureCode_id_UERegister);
157
Daniel Willmann23c86e32015-11-30 16:03:36 +0100158 rc = hnbap_decode_ueregisteraccepties(&ue_acc_ies, &so->value);
Daniel Willmann1a869552015-11-24 18:11:03 +0100159 ASSERT(rc >= 0);
160
Daniel Willmann23c86e32015-11-30 16:03:36 +0100161 ASSERT(ue_acc_ies.uE_Identity.present == UE_Identity_PR_iMSI);
Harald Welte056984f2016-01-03 16:31:31 +0100162 ranap_bcd_decode(imsi, sizeof(imsi), ue_acc_ies.uE_Identity.choice.iMSI.buf,
Daniel Willmann23c86e32015-11-30 16:03:36 +0100163 ue_acc_ies.uE_Identity.choice.iMSI.size);
Daniel Willmann1a869552015-11-24 18:11:03 +0100164
165 printf("HNBAP UE Register accept to IMSI %s\n", imsi);
Daniel Willmann11e912a2016-01-07 13:19:30 +0100166 hnbap_free_ueregisteraccepties(&ue_acc_ies);
Daniel Willmann1a869552015-11-24 18:11:03 +0100167
Neels Hofmeyrd9cb19a2017-11-18 18:47:55 +0100168 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBAP_PDU, pdu);
Daniel Willmann39e643a2015-11-24 18:03:29 +0100169}
170
Daniel Willmann39e643a2015-11-24 18:03:29 +0100171int main(int argc, char **argv)
172{
173 int rc;
174
Harald Welte87ffeb92015-12-25 15:34:22 +0100175 test_common_init();
176 log_set_log_level(osmo_stderr_target, LOGL_INFO);
177
Daniel Willmann39e643a2015-11-24 18:03:29 +0100178
179 test_asn1_decoding();
180
Neels Hofmeyrd9cb19a2017-11-18 18:47:55 +0100181 test_common_cleanup();
Daniel Willmann39e643a2015-11-24 18:03:29 +0100182 return 0;
183}
184