blob: 766247314ef8065b988199e93ef4950b1119bf7d [file] [log] [blame]
Harald Weltef8db61b2015-12-18 17:29:59 +01001/* (C) 2015 by Harald Welte <laforge@gnumonks.org>
2 * All Rights Reserved
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19#include <osmocom/core/utils.h>
20#include <osmocom/core/msgb.h>
21#include <osmocom/core/logging.h>
22#include <osmocom/vty/logging.h>
Harald Welted328c1a2015-12-16 23:04:21 +010023
Harald Welte091039d2015-12-17 20:37:40 +010024#include "asn1helpers.h"
25#include "iu_helpers.h"
26
27#include "ranap_common.h"
28#include "ranap_ies_defs.h"
Harald Weltef8db61b2015-12-18 17:29:59 +010029#include "ranap_msg_factory.h"
Harald Welted328c1a2015-12-16 23:04:21 +010030
Harald Weltef8db61b2015-12-18 17:29:59 +010031#include "hnbgw.h"
Harald Welted328c1a2015-12-16 23:04:21 +010032
Harald Weltef8db61b2015-12-18 17:29:59 +010033void *talloc_asn1_ctx;
34int asn1_xer_print = 1;
Harald Welted062df52015-12-17 23:18:40 +010035
Harald Weltef8db61b2015-12-18 17:29:59 +010036extern void *tall_msgb_ctx;
Harald Welted328c1a2015-12-16 23:04:21 +010037
Harald Weltef8db61b2015-12-18 17:29:59 +010038static const struct log_info_cat log_cat[] = {
39 [DMAIN] = {
40 .name = "DMAIN", .loglevel = LOGL_INFO, .enabled = 1,
41 .color = "",
42 .description = "Main program",
43 },
44 [DHNBAP] = {
45 .name = "DHNBAP", .loglevel = LOGL_DEBUG, .enabled = 1,
46 .color = "",
47 .description = "Home Node B Application Part",
48 },
Harald Welted328c1a2015-12-16 23:04:21 +010049};
50
Harald Weltef8db61b2015-12-18 17:29:59 +010051static const struct log_info hnbgw_log_info = {
52 .cat = log_cat,
53 .num_cat = ARRAY_SIZE(log_cat),
Harald Welted328c1a2015-12-16 23:04:21 +010054};
55
Harald Weltef8db61b2015-12-18 17:29:59 +010056
57int main(int argc, char **argv)
Harald Welted328c1a2015-12-16 23:04:21 +010058{
Harald Weltef8db61b2015-12-18 17:29:59 +010059 uint8_t nas_buf[] = { 0xaa, 0xbb, 0xcc };
Harald Welted328c1a2015-12-16 23:04:21 +010060 struct msgb *msg;
Harald Weltef8db61b2015-12-18 17:29:59 +010061 const char *imsi = "901700123456789";
62 uint32_t tmsi = 0x01234567;
63 uint32_t rtp_ip = 0x0a0b0c0d;
64 uint16_t rtp_port = 2342;
65 uint32_t gtp_ip = 0x1a1b1c1d;
66 uint32_t gtp_tei = 0x11223344;
67 uint8_t ik[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
68 uint8_t ck[16] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
Harald Welte091039d2015-12-17 20:37:40 +010069 int i, rc;
Harald Welted328c1a2015-12-16 23:04:21 +010070
Harald Weltef8db61b2015-12-18 17:29:59 +010071 //asn_debug = 1;
Harald Welted328c1a2015-12-16 23:04:21 +010072
Harald Weltef8db61b2015-12-18 17:29:59 +010073 talloc_asn1_ctx = talloc_named_const(NULL, 1, "ASN");
74 msgb_set_talloc_ctx(talloc_named_const(NULL, 1, "msgb"));
Harald Welted328c1a2015-12-16 23:04:21 +010075
Harald Weltef8db61b2015-12-18 17:29:59 +010076 rc = osmo_init_logging(&hnbgw_log_info);
77 if (rc < 0)
78 exit(1);
79
80 for (i = 0; i < 1; i++) {
81 printf("\n==> DIRECT TRANSFER\n");
82 msg = ranap_new_msg_dt(0, nas_buf, sizeof(nas_buf));
83 if (msg)
84 printf("%s\n", msgb_hexdump(msg));
85 msgb_free(msg);
86
87 printf("\n==> SECURITY MODE COMMAND\n");
88 msg = ranap_new_msg_sec_mod_cmd(ik, ck);
89 if (msg)
90 printf("%s\n", msgb_hexdump(msg));
91 msgb_free(msg);
92
93 printf("\n==> COMMON ID\n");
94 msg = ranap_new_msg_common_id(imsi);
95 if (msg)
96 printf("%s\n", msgb_hexdump(msg));
97 msgb_free(msg);
98
99 printf("\n==> IU RELEASE CMD\n");
100 RANAP_Cause_t cause = { .present = RANAP_Cause_PR_radioNetwork,
101 .choice.radioNetwork = RANAP_CauseRadioNetwork_radio_connection_with_UE_Lost };
102 msg = ranap_new_msg_iu_rel_cmd(&cause);
103 if (msg)
104 printf("%s\n", msgb_hexdump(msg));
105 msgb_free(msg);
106
107 printf("\n==> PAGING CMD\n");
108 msg = ranap_new_msg_paging_cmd(imsi, &tmsi, 0, RANAP_PagingCause_terminating_conversational_call);
109 if (msg)
110 printf("%s\n", msgb_hexdump(msg));
111 msgb_free(msg);
112
113 printf("\n==> RAB ASSIGNMENT COMMAND (VOICE)\n");
114 msg = ranap_new_msg_rab_assign_voice(1, rtp_ip, rtp_port);
115 if (msg)
116 printf("%s\n", msgb_hexdump(msg));
117 msgb_free(msg);
118
119 printf("\n==> RAB ASSIGNMENT COMMAND (DATA)\n");
120 msg = ranap_new_msg_rab_assign_data(2, gtp_ip, gtp_tei);
121 if (msg)
122 printf("%s\n", msgb_hexdump(msg));
123 msgb_free(msg);
Harald Welte091039d2015-12-17 20:37:40 +0100124 }
Harald Welted328c1a2015-12-16 23:04:21 +0100125
Harald Weltef8db61b2015-12-18 17:29:59 +0100126 printf("report\n");
127 talloc_report(talloc_asn1_ctx, stdout);
128 talloc_report(tall_msgb_ctx, stdout);
129 //talloc_report(NULL, stdout);
130 printf("exit\n");
131 exit(0);
Harald Welted328c1a2015-12-16 23:04:21 +0100132}