blob: 6b430af3cc4a3ae3ebeaedbcfa906bb72b9c641c [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 Willmann39e643a2015-11-24 18:03:29 +010081 UERegisterRequestIEs_t ies;
Daniel Willmannea4c0882015-11-27 16:14:09 +010082 HNBRegisterRequestIEs_t hnb_ies;
Daniel Willmann39e643a2015-11-24 18:03:29 +010083
84 char imsi[16];
85
86 asn_dec_rval_t dec_ret;
87
88 memset(pdu, 0, sizeof(*pdu));
89 printf("Testing asn.1 HNBAP decoding\n");
90
91 dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu,
Daniel Willmannea4c0882015-11-27 16:14:09 +010092 hnbap_reg_req, sizeof(hnbap_reg_req), 0, 0);
93
94
95 ASSERT(dec_ret.code == RC_OK);
96 ASSERT(pdu->present == HNBAP_PDU_PR_initiatingMessage);
97
98 im = &pdu->choice.initiatingMessage;
99
100 ASSERT(im->procedureCode == ProcedureCode_id_HNBRegister);
101
102 rc = hnbap_decode_hnbregisterrequesties(&hnb_ies, &im->value);
103 ASSERT(rc >= 0);
104
105 uint16_t lac, sac;
106 uint8_t rac;
107 uint32_t cid;
108
109 lac = asn1str_to_u16(&hnb_ies.lac);
110 sac = asn1str_to_u16(&hnb_ies.sac);
111 rac = asn1str_to_u8(&hnb_ies.rac);
112
113 ASSERT(lac == 0x4020);
114 ASSERT(sac == 0x0001);
115 ASSERT(rac == 0x64);
116
117 dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu,
Daniel Willmann39e643a2015-11-24 18:03:29 +0100118 hnbap_ue_reg_req, sizeof(hnbap_ue_reg_req), 0, 0);
119
120
121 ASSERT(dec_ret.code == RC_OK);
122 ASSERT(pdu->present == HNBAP_PDU_PR_initiatingMessage);
123
124 im = &pdu->choice.initiatingMessage;
125 ASSERT(im->procedureCode == ProcedureCode_id_UERegister);
126
127 rc = hnbap_decode_ueregisterrequesties(&ies, &im->value);
128 ASSERT(rc >= 0);
129
130 ASSERT(ies.uE_Identity.present == UE_Identity_PR_iMSI);
131 decode_iu_bcd(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSI.buf,
132 ies.uE_Identity.choice.iMSI.size);
133
Daniel Willmann1a869552015-11-24 18:11:03 +0100134 printf("HNBAP UE Register request from IMSI %s\n", imsi);
135
136 memset(pdu, 0, sizeof(*pdu));
137 dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu,
138 hnbap_ue_reg_acc, sizeof(hnbap_ue_reg_acc), 0, 0);
139
140
141 ASSERT(dec_ret.code == RC_OK);
142 ASSERT(pdu->present == HNBAP_PDU_PR_successfulOutcome);
143
144 so = &pdu->choice.successfulOutcome;
145 ASSERT(so->procedureCode == ProcedureCode_id_UERegister);
146
147 rc = hnbap_decode_ueregisteraccepties(&ies, &so->value);
148 ASSERT(rc >= 0);
149
150 ASSERT(ies.uE_Identity.present == UE_Identity_PR_iMSI);
151 decode_iu_bcd(imsi, sizeof(imsi), ies.uE_Identity.choice.iMSI.buf,
152 ies.uE_Identity.choice.iMSI.size);
153
154 printf("HNBAP UE Register accept to IMSI %s\n", imsi);
155
Daniel Willmann39e643a2015-11-24 18:03:29 +0100156}
157
158
159static const struct log_info osmo_log = {
160 .cat = NULL,
161 .num_cat = 0,
162};
163
164int main(int argc, char **argv)
165{
166 int rc;
167
168 rc = osmo_init_logging(&osmo_log);
169 if (rc < 0) {
170 printf("Error in init logging\n");
171 return -1;
172 }
173
174 test_asn1_decoding();
175
176 return 0;
177}
178