blob: f26e222bb3464e2dec2e06f42e4e61f2cf653284 [file] [log] [blame]
Daniel Willmann97374c02015-12-03 09:37:58 +01001/* Test HNB */
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 <unistd.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <getopt.h>
27#include <errno.h>
28#include <signal.h>
29
30#include <sys/types.h>
31#include <sys/socket.h>
32#include <netinet/in.h>
33#include <netinet/sctp.h>
34#include <arpa/inet.h>
35
36#include <osmocom/core/application.h>
37#include <osmocom/core/talloc.h>
38#include <osmocom/core/select.h>
39#include <osmocom/core/logging.h>
40#include <osmocom/core/socket.h>
41#include <osmocom/core/msgb.h>
42#include <osmocom/core/write_queue.h>
Harald Weltec3851222015-12-24 15:41:21 +010043#include <osmocom/netif/stream.h>
Daniel Willmann97374c02015-12-03 09:37:58 +010044
45#include <osmocom/vty/telnet_interface.h>
46#include <osmocom/vty/logging.h>
Harald Weltec3851222015-12-24 15:41:21 +010047#include <osmocom/vty/command.h>
Daniel Willmann97374c02015-12-03 09:37:58 +010048
49#include "hnb-test.h"
Daniel Willmanna1e202e2015-12-07 17:21:07 +010050#include "hnbap_common.h"
51#include "hnbap_ies_defs.h"
Harald Weltec3851222015-12-24 15:41:21 +010052#include "rua_helper.h"
53#include "asn1helpers.h"
54#include "iu_helpers.h"
Harald Welte87ffeb92015-12-25 15:34:22 +010055#include "test_common.h"
Harald Weltec3851222015-12-24 15:41:21 +010056
57#include "ranap_msg_factory.h"
Daniel Willmann97374c02015-12-03 09:37:58 +010058
59static void *tall_hnb_ctx;
Daniel Willmann97374c02015-12-03 09:37:58 +010060
61struct hnb_test g_hnb_test = {
62 .gw_port = IUH_DEFAULT_SCTP_PORT,
63};
64
Harald Weltec3851222015-12-24 15:41:21 +010065struct msgb *rua_new_udt(struct msgb *inmsg);
66
Harald Weltec3851222015-12-24 15:41:21 +010067static int hnb_test_ue_de_register_tx(struct hnb_test *hnb_test)
Daniel Willmann19dedbb2015-12-17 11:57:41 +010068{
69 struct msgb *msg;
70 int rc, imsi_len;
71 uint32_t ctx_id;
72
73 UEDe_Register_t dereg;
74 UEDe_RegisterIEs_t dereg_ies;
75 memset(&dereg_ies, 0, sizeof(dereg_ies));
76
77 asn1_u24_to_bitstring(&dereg_ies.context_ID, &ctx_id, hnb_test->ctx_id);
78 dereg_ies.cause.present = Cause_PR_radioNetwork;
79 dereg_ies.cause.choice.radioNetwork = CauseRadioNetwork_connection_with_UE_lost;
80
81 memset(&dereg, 0, sizeof(dereg));
82 rc = hnbap_encode_uede_registeries(&dereg, &dereg_ies);
83
84 msg = hnbap_generate_initiating_message(ProcedureCode_id_UEDe_Register,
85 Criticality_ignore,
86 &asn_DEF_UEDe_Register,
87 &dereg);
88
Harald Weltec3851222015-12-24 15:41:21 +010089 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_UEDe_Register, &dereg);
Daniel Willmann19dedbb2015-12-17 11:57:41 +010090
Harald Weltec3851222015-12-24 15:41:21 +010091 msgb_sctp_ppid(msg) = IUH_PPI_HNBAP;
Daniel Willmann19dedbb2015-12-17 11:57:41 +010092
93 return osmo_wqueue_enqueue(&hnb_test->wqueue, msg);
94}
95
Harald Weltec3851222015-12-24 15:41:21 +010096static int hnb_test_ue_register_tx(struct hnb_test *hnb_test, const char *imsi_str)
Daniel Willmann479cb302015-12-09 17:54:59 +010097{
Daniel Willmann4e312502015-12-09 17:59:24 +010098 struct msgb *msg;
99 int rc, imsi_len;
100
101 char imsi_buf[16];
Daniel Willmann141a0ba2015-12-17 18:03:52 +0100102
Daniel Willmann4e312502015-12-09 17:59:24 +0100103 UERegisterRequest_t request_out;
104 UERegisterRequestIEs_t request;
105 memset(&request, 0, sizeof(request));
106
107 request.uE_Identity.present = UE_Identity_PR_iMSI;
108
Harald Welte056984f2016-01-03 16:31:31 +0100109 imsi_len = ranap_imsi_encode(imsi_buf, sizeof(imsi_buf), imsi_str);
Harald Weltec3851222015-12-24 15:41:21 +0100110 OCTET_STRING_fromBuf(&request.uE_Identity.choice.iMSI, imsi_buf, imsi_len);
Daniel Willmann4e312502015-12-09 17:59:24 +0100111
112 request.registration_Cause = Registration_Cause_normal;
113 request.uE_Capabilities.access_stratum_release_indicator = Access_stratum_release_indicator_rel_6;
114 request.uE_Capabilities.csg_capability = CSG_Capability_not_csg_capable;
115
116 memset(&request_out, 0, sizeof(request_out));
117 rc = hnbap_encode_ueregisterrequesties(&request_out, &request);
118
119 msg = hnbap_generate_initiating_message(ProcedureCode_id_UERegister,
120 Criticality_reject,
121 &asn_DEF_UERegisterRequest,
122 &request_out);
123
Harald Weltec3851222015-12-24 15:41:21 +0100124 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_UERegisterRequest, &request_out);
Daniel Willmann4e312502015-12-09 17:59:24 +0100125
Harald Weltec3851222015-12-24 15:41:21 +0100126 msgb_sctp_ppid(msg) = IUH_PPI_HNBAP;
Daniel Willmann4e312502015-12-09 17:59:24 +0100127
128 return osmo_wqueue_enqueue(&hnb_test->wqueue, msg);
Daniel Willmann479cb302015-12-09 17:54:59 +0100129}
130
Harald Weltec3851222015-12-24 15:41:21 +0100131static int hnb_test_rx_hnb_register_acc(struct hnb_test *hnb, ANY_t *in)
Daniel Willmann479cb302015-12-09 17:54:59 +0100132{
133 int rc;
134 HNBRegisterAcceptIEs_t accept;
135
136 rc = hnbap_decode_hnbregisteraccepties(&accept, in);
137 if (rc < 0) {
138 }
139
140 hnb->rnc_id = accept.rnc_id;
141 printf("HNB Register accept with RNC ID %u\n", hnb->rnc_id);
142
Harald Weltec3851222015-12-24 15:41:21 +0100143 return 0;
Daniel Willmann479cb302015-12-09 17:54:59 +0100144}
145
Harald Weltec3851222015-12-24 15:41:21 +0100146static int hnb_test_rx_ue_register_acc(struct hnb_test *hnb, ANY_t *in)
Daniel Willmanna7b02402015-12-09 19:05:09 +0100147{
148 int rc;
149 uint32_t ctx_id;
150 UERegisterAcceptIEs_t accept;
151 char imsi[16];
152
153 rc = hnbap_decode_ueregisteraccepties(&accept, in);
154 if (rc < 0) {
155 return rc;
156 }
157
158 if (accept.uE_Identity.present != UE_Identity_PR_iMSI) {
159 printf("Wrong type in UE register accept\n");
160 return -1;
161 }
162
163 ctx_id = asn1bitstr_to_u24(&accept.context_ID);
164
Harald Welte056984f2016-01-03 16:31:31 +0100165 ranap_bcd_decode(imsi, sizeof(imsi), accept.uE_Identity.choice.iMSI.buf,
Daniel Willmanna7b02402015-12-09 19:05:09 +0100166 accept.uE_Identity.choice.iMSI.size);
167 printf("UE Register accept for IMSI %s, context %u\n", imsi, ctx_id);
168
Daniel Willmann19dedbb2015-12-17 11:57:41 +0100169 hnb->ctx_id = ctx_id;
170
Daniel Willmanna7b02402015-12-09 19:05:09 +0100171 return 0;
172}
173
Daniel Willmann479cb302015-12-09 17:54:59 +0100174int hnb_test_hnbap_rx(struct hnb_test *hnb, struct msgb *msg)
175{
176 HNBAP_PDU_t _pdu, *pdu = &_pdu;
177 asn_dec_rval_t dec_ret;
178 int rc;
179
180 memset(pdu, 0, sizeof(*pdu));
181 dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu,
182 msg->data, msgb_length(msg), 0, 0);
183 if (dec_ret.code != RC_OK) {
184 LOGP(DMAIN, LOGL_ERROR, "Error in ASN.1 decode\n");
185 return rc;
186 }
187
188 if (pdu->present != HNBAP_PDU_PR_successfulOutcome) {
189 printf("Unexpected HNBAP message received\n");
190 }
191
192 switch (pdu->choice.successfulOutcome.procedureCode) {
193 case ProcedureCode_id_HNBRegister:
194 /* Get HNB id and send UE Register request */
195 rc = hnb_test_rx_hnb_register_acc(hnb, &pdu->choice.successfulOutcome.value);
196 break;
197 case ProcedureCode_id_UERegister:
Daniel Willmanna7b02402015-12-09 19:05:09 +0100198 rc = hnb_test_rx_ue_register_acc(hnb, &pdu->choice.successfulOutcome.value);
Daniel Willmann479cb302015-12-09 17:54:59 +0100199 break;
200 default:
201 break;
202 }
203
204 return rc;
205}
206
Daniel Willmann97374c02015-12-03 09:37:58 +0100207static int hnb_read_cb(struct osmo_fd *fd)
208{
209 struct hnb_test *hnb_test = fd->data;
210 struct sctp_sndrcvinfo sinfo;
211 struct msgb *msg = msgb_alloc(IUH_MSGB_SIZE, "Iuh rx");
212 int flags = 0;
213 int rc;
214
215 if (!msg)
216 return -ENOMEM;
217
218 rc = sctp_recvmsg(fd->fd, msgb_data(msg), msgb_tailroom(msg),
219 NULL, NULL, &sinfo, &flags);
220 if (rc < 0) {
221 LOGP(DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n");
222 /* FIXME: clean up after disappeared HNB */
Daniel Willmann6637a282015-12-17 14:47:51 +0100223 close(fd->fd);
224 osmo_fd_unregister(fd);
Daniel Willmann97374c02015-12-03 09:37:58 +0100225 return rc;
Daniel Willmann6637a282015-12-17 14:47:51 +0100226 } else if (rc == 0) {
227 LOGP(DMAIN, LOGL_INFO, "Connection to HNB closed\n");
228 close(fd->fd);
229 osmo_fd_unregister(fd);
230 fd->fd = -1;
231
232 return -1;
233 } else {
Daniel Willmann97374c02015-12-03 09:37:58 +0100234 msgb_put(msg, rc);
Daniel Willmann6637a282015-12-17 14:47:51 +0100235 }
Daniel Willmann97374c02015-12-03 09:37:58 +0100236
237 if (flags & MSG_NOTIFICATION) {
Daniel Willmann32797802015-12-17 12:53:05 +0100238 LOGP(DMAIN, LOGL_DEBUG, "Ignoring SCTP notification\n");
Daniel Willmann97374c02015-12-03 09:37:58 +0100239 msgb_free(msg);
240 return 0;
241 }
242
243 sinfo.sinfo_ppid = ntohl(sinfo.sinfo_ppid);
244
245 switch (sinfo.sinfo_ppid) {
246 case IUH_PPI_HNBAP:
247 printf("HNBAP mesage received\n");
Daniel Willmann479cb302015-12-09 17:54:59 +0100248 rc = hnb_test_hnbap_rx(hnb_test, msg);
Daniel Willmann97374c02015-12-03 09:37:58 +0100249 break;
250 case IUH_PPI_RUA:
251 printf("RUA mesage received\n");
252// rc = hnbgw_rua_rx(hnb, msg);
253 break;
254 case IUH_PPI_SABP:
255 case IUH_PPI_RNA:
256 case IUH_PPI_PUA:
257 LOGP(DMAIN, LOGL_ERROR, "Unimplemented SCTP PPID=%u received\n",
258 sinfo.sinfo_ppid);
259 rc = 0;
260 break;
261 default:
262 LOGP(DMAIN, LOGL_ERROR, "Unknown SCTP PPID=%u received\n",
263 sinfo.sinfo_ppid);
264 rc = 0;
265 break;
266 }
267
268 msgb_free(msg);
269 return rc;
270}
271
272static int hnb_write_cb(struct osmo_fd *fd, struct msgb *msg)
273{
274 struct hnb_test *ctx = fd->data;
275 struct sctp_sndrcvinfo sinfo = {
Harald Weltec3851222015-12-24 15:41:21 +0100276 .sinfo_ppid = htonl(msgb_sctp_ppid(msg)),
Daniel Willmann97374c02015-12-03 09:37:58 +0100277 .sinfo_stream = 0,
278 };
279 int rc;
280
281 rc = sctp_send(fd->fd, msgb_data(msg), msgb_length(msg),
282 &sinfo, 0);
283 /* we don't need to msgb_free(), write_queue does this for us */
284 return rc;
285}
286
Daniel Willmann4aeef6c2015-12-03 17:02:13 +0100287static void hnb_send_register_req(struct hnb_test *hnb_test)
288{
Daniel Willmanna1e202e2015-12-07 17:21:07 +0100289 HNBRegisterRequest_t request_out;
Daniel Willmann4aeef6c2015-12-03 17:02:13 +0100290 struct msgb *msg;
291 int rc;
Daniel Willmanna1e202e2015-12-07 17:21:07 +0100292 uint16_t lac, sac;
293 uint8_t rac;
294 uint32_t cid;
295 uint8_t plmn[] = {0x09, 0xf1, 0x99};
296 char identity[50] = "ATestHNB@";
Daniel Willmann4aeef6c2015-12-03 17:02:13 +0100297
Daniel Willmanna1e202e2015-12-07 17:21:07 +0100298 HNBRegisterRequestIEs_t request;
299 memset(&request, 0, sizeof(request));
Daniel Willmann4aeef6c2015-12-03 17:02:13 +0100300
Daniel Willmanna1e202e2015-12-07 17:21:07 +0100301 lac = 0xc0fe;
302 sac = 0xabab;
303 rac = 0x42;
Daniel Willmannd6a45b42015-12-08 13:55:17 +0100304 cid = 0xadceaab;
Daniel Willmann4aeef6c2015-12-03 17:02:13 +0100305
Daniel Willmanna1e202e2015-12-07 17:21:07 +0100306 asn1_u16_to_str(&request.lac, &lac, lac);
307 asn1_u16_to_str(&request.sac, &sac, sac);
308 asn1_u8_to_str(&request.rac, &rac, rac);
Daniel Willmannd6a45b42015-12-08 13:55:17 +0100309 asn1_u28_to_bitstring(&request.cellIdentity, &cid, cid);
Daniel Willmanna1e202e2015-12-07 17:21:07 +0100310
311 request.hnB_Identity.hNB_Identity_Info.buf = identity;
312 request.hnB_Identity.hNB_Identity_Info.size = strlen(identity);
313
314 request.plmNidentity.buf = plmn;
315 request.plmNidentity.size = 3;
316
317
318
319 memset(&request_out, 0, sizeof(request_out));
320 rc = hnbap_encode_hnbregisterrequesties(&request_out, &request);
321 if (rc < 0) {
322 printf("Could not encode HNB register request IEs\n");
323 }
324
325 msg = hnbap_generate_initiating_message(ProcedureCode_id_HNBRegister,
326 Criticality_reject,
327 &asn_DEF_HNBRegisterRequest,
328 &request_out);
329
Daniel Willmann4aeef6c2015-12-03 17:02:13 +0100330
Harald Weltec3851222015-12-24 15:41:21 +0100331 msgb_sctp_ppid(msg) = IUH_PPI_HNBAP;
332
333 osmo_wqueue_enqueue(&hnb_test->wqueue, msg);
334}
335
336static void hnb_send_deregister_req(struct hnb_test *hnb_test)
337{
338 struct msgb *msg;
339 int rc;
340
341 HNBDe_RegisterIEs_t request;
342 memset(&request, 0, sizeof(request));
343
344 request.cause.present = Cause_PR_misc;
345 request.cause.choice.misc = CauseMisc_o_and_m_intervention;
346
347 HNBDe_Register_t request_out;
348 memset(&request_out, 0, sizeof(request_out));
349 rc = hnbap_encode_hnbde_registeries(&request_out, &request);
350 if (rc < 0) {
351 printf("Could not encode HNB deregister request IEs\n");
352 }
353
354 msg = hnbap_generate_initiating_message(ProcedureCode_id_HNBDe_Register,
355 Criticality_reject,
356 &asn_DEF_HNBDe_Register,
357 &request_out);
358
359 msgb_sctp_ppid(msg) = IUH_PPI_HNBAP;
Daniel Willmann4aeef6c2015-12-03 17:02:13 +0100360
361 osmo_wqueue_enqueue(&hnb_test->wqueue, msg);
362}
363
364
Daniel Willmann97374c02015-12-03 09:37:58 +0100365static const struct log_info_cat log_cat[] = {
366 [DMAIN] = {
Daniel Willmann32797802015-12-17 12:53:05 +0100367 .name = "DMAIN", .loglevel = LOGL_INFO, .enabled = 1,
Daniel Willmann97374c02015-12-03 09:37:58 +0100368 .color = "",
369 .description = "Main program",
370 },
Daniel Willmann32797802015-12-17 12:53:05 +0100371 [DHNBAP] = {
372 .name = "DHNBAP", .loglevel = LOGL_DEBUG, .enabled = 1,
373 .color = "",
374 .description = "Home Node B Application Part",
375 },
Daniel Willmann97374c02015-12-03 09:37:58 +0100376};
377
378static const struct log_info hnb_test_log_info = {
379 .cat = log_cat,
380 .num_cat = ARRAY_SIZE(log_cat),
381};
382
383static struct vty_app_info vty_info = {
384 .name = "OsmoHNB-Test",
385 .version = "0",
386};
387
Daniel Willmann4abdee02015-12-09 17:57:32 +0100388static int sctp_sock_init(int fd)
389{
390 struct sctp_event_subscribe event;
391 int rc;
392
393 /* subscribe for all events */
394 memset((uint8_t *)&event, 1, sizeof(event));
395 rc = setsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS,
396 &event, sizeof(event));
397
398 return rc;
399}
400
Harald Weltec3851222015-12-24 15:41:21 +0100401#define HNBAP_STR "HNBAP related commands\n"
402#define HNB_STR "HomeNodeB commands\n"
403#define UE_STR "User Equipment commands\n"
404#define RANAP_STR "RANAP related commands\n"
405#define CSPS_STR "Circuit Switched\n" "Packet Switched\n"
406
407DEFUN(hnb_register, hnb_register_cmd,
408 "hnbap hnb register", HNBAP_STR HNB_STR "Send HNB-REGISTER REQUEST")
409{
410 hnb_send_register_req(&g_hnb_test);
411
412 return CMD_SUCCESS;
413}
414
415DEFUN(hnb_deregister, hnb_deregister_cmd,
416 "hnbap hnb deregister", HNBAP_STR HNB_STR "Send HNB-DEREGISTER REQUEST")
417{
418 hnb_send_deregister_req(&g_hnb_test);
419
420 return CMD_SUCCESS;
421}
422
423DEFUN(ue_register, ue_register_cmd,
424 "hnbap ue register IMSI", HNBAP_STR UE_STR "Send UE-REGISTER REQUEST")
425{
426 hnb_test_ue_register_tx(&g_hnb_test, argv[0]);
427
428 return CMD_SUCCESS;
429}
430
431DEFUN(asn_dbg, asn_dbg_cmd,
432 "asn-debug (1|0)", "Enable or disabel libasn1c debugging")
433{
434 asn_debug = atoi(argv[0]);
435
436 return CMD_SUCCESS;
437}
438
439DEFUN(ranap_reset, ranap_reset_cmd,
440 "ranap reset (cs|ps)", RANAP_STR "Send RANAP RESET\n" CSPS_STR)
441{
442 int is_ps = 0;
443 struct msgb *msg, *rua;
444
445 RANAP_Cause_t cause = {
446 .present = RANAP_Cause_PR_transmissionNetwork,
447 .choice.transmissionNetwork = RANAP_CauseTransmissionNetwork_signalling_transport_resource_failure,
448 };
449
450 if (!strcmp(argv[0], "ps"))
451 is_ps = 1;
452
453 msg = ranap_new_msg_reset(is_ps, &cause);
454 rua = rua_new_udt(msg);
455 //msgb_free(msg);
456 osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua);
457
458 return CMD_SUCCESS;
459}
460
461
462enum my_vty_nodes {
463 CHAN_NODE = _LAST_OSMOVTY_NODE,
464};
465
466static struct cmd_node chan_node = {
467 CHAN_NODE,
468 "%s(chan)> ",
469 1,
470};
471
472
473struct hnbtest_chan {
474 int is_ps;
475 uint32_t conn_id;
476 char *imsi;
477};
478
479static struct msgb *gen_initue_lu(int is_ps, uint32_t conn_id, const char *imsi)
480{
481 uint8_t lu[] = { 0x05, 0x08, 0x70, 0x62, 0xf2, 0x30, 0xff, 0xf3, 0x57,
482 /* len- IMSI------------------------------------------ */
483 0x08, 0x29, 0x26, 0x24, 0x10, 0x32, 0x54, 0x76, 0x98,
484 0x33, 0x03, 0x57, 0x18 , 0xb2 };
485 uint8_t plmn_id[] = { 0x09, 0x01, 0x99 };
486 RANAP_GlobalRNC_ID_t rnc_id = {
487 .rNC_ID = 23,
488 .pLMNidentity.buf = plmn_id,
489 .pLMNidentity.size = sizeof(plmn_id),
490 };
491 struct msgb *msg;
492
493 /* FIXME: patch imsi */
494
495 return ranap_new_msg_initial_ue(is_ps, conn_id, &rnc_id, lu, sizeof(lu));
496}
497
498DEFUN(chan, chan_cmd,
499 "channel (cs|ps) lu imsi IMSI",
500 "Open a new Signalling Connection\n"
501 "To Circuit-Switched CN\n"
502 "To Packet-Switched CN\n"
503 "Performing a Location Update\n"
504 )
505{
506 struct hnbtest_chan *chan;
507 struct msgb *msg, *rua;
508
509 chan = talloc_zero(tall_hnb_ctx, struct hnbtest_chan);
510 if (!strcmp(argv[0], "ps"))
511 chan->is_ps = 1;
512 chan->imsi = talloc_strdup(chan, argv[1]);
513 chan->conn_id = 42;
514
515 msg = gen_initue_lu(chan->is_ps, chan->conn_id, chan->imsi);
516 rua = rua_new_conn(chan->is_ps, chan->conn_id, msg);
517
518 osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua);
519
520 vty->index = chan;
521 vty->node = CHAN_NODE;
522
523 return CMD_SUCCESS;
524}
525
526static void hnbtest_vty_init(void)
527{
528 install_element_ve(&asn_dbg_cmd);
529 install_element_ve(&hnb_register_cmd);
530 install_element_ve(&hnb_deregister_cmd);
531 install_element_ve(&ue_register_cmd);
532 install_element_ve(&ranap_reset_cmd);
533 install_element_ve(&chan_cmd);
534
535 install_node(&chan_node, NULL);
536 vty_install_default(CHAN_NODE);
537}
538
Daniel Willmann141a0ba2015-12-17 18:03:52 +0100539static void handle_options(int argc, char **argv)
540{
541 while (1) {
542 int idx = 0, c;
543 static const struct option long_options[] = {
544 { "ues", 1, 0, 'u' },
545 { 0, 0, 0, 0 },
546 };
547
548 c = getopt_long(argc, argv, "u:", long_options, &idx);
549
550 if (c == -1)
551 break;
552
553 switch (c) {
554 case 'u':
555 g_hnb_test.ues = atoi(optarg);
556 break;
557 }
558 }
559}
560
Harald Weltec3851222015-12-24 15:41:21 +0100561int main(int argc, char **argv)
Daniel Willmann97374c02015-12-03 09:37:58 +0100562{
563 int rc;
564
Harald Welte87ffeb92015-12-25 15:34:22 +0100565 test_common_init();
Daniel Willmann97374c02015-12-03 09:37:58 +0100566
Harald Welte87ffeb92015-12-25 15:34:22 +0100567 tall_hnb_ctx = talloc_named_const(NULL, 0, "hnb_context");
Daniel Willmann97374c02015-12-03 09:37:58 +0100568
569 vty_init(&vty_info);
Harald Weltec3851222015-12-24 15:41:21 +0100570 hnbtest_vty_init();
571
572 rc = telnet_init(NULL, NULL, 2324);
573 if (rc < 0) {
574 perror("Error binding VTY port");
575 exit(1);
576 }
Daniel Willmann97374c02015-12-03 09:37:58 +0100577
Daniel Willmann141a0ba2015-12-17 18:03:52 +0100578 handle_options(argc, argv);
579
Daniel Willmann97374c02015-12-03 09:37:58 +0100580 osmo_wqueue_init(&g_hnb_test.wqueue, 16);
581 g_hnb_test.wqueue.bfd.data = &g_hnb_test;
582 g_hnb_test.wqueue.read_cb = hnb_read_cb;
583 g_hnb_test.wqueue.write_cb = hnb_write_cb;
584
585 rc = osmo_sock_init_ofd(&g_hnb_test.wqueue.bfd, AF_INET, SOCK_STREAM,
586 IPPROTO_SCTP, "127.0.0.1",
587 g_hnb_test.gw_port, OSMO_SOCK_F_CONNECT);
588 if (rc < 0) {
589 perror("Error connecting to Iuh port");
590 exit(1);
591 }
Daniel Willmann4abdee02015-12-09 17:57:32 +0100592 sctp_sock_init(g_hnb_test.wqueue.bfd.fd);
Daniel Willmann97374c02015-12-03 09:37:58 +0100593
Harald Weltec3851222015-12-24 15:41:21 +0100594#if 0
595 /* some hard-coded message generation. Doesn't make sense from
596 * a protocol point of view but enables to look at the encoded
597 * results in wireshark for manual verification */
598 {
599 struct msgb *msg, *rua;
600 const uint8_t nas[] = { 0, 1, 2, 3 };
601 const uint8_t ik[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
602
603 msg = ranap_new_msg_dt(0, nas, sizeof(nas));
604 rua = rua_new_udt(msg);
605 osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua);
606
607 msg = ranap_new_msg_sec_mod_cmd(ik, ik);
608 rua = rua_new_udt(msg);
609 osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua);
610
611 msg = ranap_new_msg_iu_rel_cmd()
612 rua = rua_new_udt(msg);
613 osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua);
614
615 msg = ranap_new_msg_paging_cmd("901990123456789", NULL, 0, 0);
616 rua = rua_new_udt(msg);
617 osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua);
618
619 msg = ranap_new_msg_rab_assign_voice(1, 0x01020304, 0x1020);
620 rua = rua_new_udt(msg);
621 osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua);
622
623 msg = ranap_new_msg_rab_assign_data(2, 0x01020304, 0x11223344);
624 rua = rua_new_udt(msg);
625 osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua);
626 }
627#endif
Daniel Willmann4aeef6c2015-12-03 17:02:13 +0100628
Daniel Willmann97374c02015-12-03 09:37:58 +0100629 while (1) {
630 rc = osmo_select_main(0);
631 if (rc < 0)
632 exit(3);
633 }
634
635 /* not reached */
636 exit(0);
637}