blob: 01119c3c5a670556269f727306ac161845043ccd [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
22#include "iu_helpers.h"
Daniel Willmannea4c0882015-11-27 16:14:09 +010023#include "asn1helpers.h"
Daniel Willmann39e643a2015-11-24 18:03:29 +010024
25#include "hnbap_common.h"
26#include "hnbap_ies_defs.h"
27
28#include <assert.h>
29#define ASSERT(x) assert(x)
30
31#include <osmocom/core/utils.h>
32#include <osmocom/core/logging.h>
33
34void *talloc_asn1_ctx;
35
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);
113
114 ASSERT(lac == 0x4020);
115 ASSERT(sac == 0x0001);
116 ASSERT(rac == 0x64);
117
118 dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu,
Daniel Willmann39e643a2015-11-24 18:03:29 +0100119 hnbap_ue_reg_req, sizeof(hnbap_ue_reg_req), 0, 0);
120
121
122 ASSERT(dec_ret.code == RC_OK);
123 ASSERT(pdu->present == HNBAP_PDU_PR_initiatingMessage);
124
125 im = &pdu->choice.initiatingMessage;
126 ASSERT(im->procedureCode == ProcedureCode_id_UERegister);
127
Daniel Willmann23c86e32015-11-30 16:03:36 +0100128 rc = hnbap_decode_ueregisterrequesties(&ue_req_ies, &im->value);
Daniel Willmann39e643a2015-11-24 18:03:29 +0100129 ASSERT(rc >= 0);
130
Daniel Willmann23c86e32015-11-30 16:03:36 +0100131 ASSERT(ue_req_ies.uE_Identity.present == UE_Identity_PR_iMSI);
132 decode_iu_bcd(imsi, sizeof(imsi), ue_req_ies.uE_Identity.choice.iMSI.buf,
133 ue_req_ies.uE_Identity.choice.iMSI.size);
Daniel Willmann39e643a2015-11-24 18:03:29 +0100134
Daniel Willmann1a869552015-11-24 18:11:03 +0100135 printf("HNBAP UE Register request from IMSI %s\n", imsi);
136
137 memset(pdu, 0, sizeof(*pdu));
138 dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu,
139 hnbap_ue_reg_acc, sizeof(hnbap_ue_reg_acc), 0, 0);
140
141
142 ASSERT(dec_ret.code == RC_OK);
143 ASSERT(pdu->present == HNBAP_PDU_PR_successfulOutcome);
144
145 so = &pdu->choice.successfulOutcome;
146 ASSERT(so->procedureCode == ProcedureCode_id_UERegister);
147
Daniel Willmann23c86e32015-11-30 16:03:36 +0100148 rc = hnbap_decode_ueregisteraccepties(&ue_acc_ies, &so->value);
Daniel Willmann1a869552015-11-24 18:11:03 +0100149 ASSERT(rc >= 0);
150
Daniel Willmann23c86e32015-11-30 16:03:36 +0100151 ASSERT(ue_acc_ies.uE_Identity.present == UE_Identity_PR_iMSI);
152 decode_iu_bcd(imsi, sizeof(imsi), ue_acc_ies.uE_Identity.choice.iMSI.buf,
153 ue_acc_ies.uE_Identity.choice.iMSI.size);
Daniel Willmann1a869552015-11-24 18:11:03 +0100154
155 printf("HNBAP UE Register accept to IMSI %s\n", imsi);
156
Daniel Willmann39e643a2015-11-24 18:03:29 +0100157}
158
159
160static const struct log_info osmo_log = {
161 .cat = NULL,
162 .num_cat = 0,
163};
164
165int main(int argc, char **argv)
166{
167 int rc;
168
169 rc = osmo_init_logging(&osmo_log);
170 if (rc < 0) {
171 printf("Error in init logging\n");
172 return -1;
173 }
174
175 test_asn1_decoding();
176
177 return 0;
178}
179