blob: 5c30edff569d79a3c42c3bebb2b23320b65b8652 [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"
Neels Hofmeyr96979af2016-01-05 15:19:44 +010025#include <osmocom/ranap/iu_helpers.h>
Harald Welte091039d2015-12-17 20:37:40 +010026
Neels Hofmeyr96979af2016-01-05 15:19:44 +010027#include <osmocom/ranap/ranap_common.h>
28#include <osmocom/ranap/ranap_ies_defs.h>
29#include <osmocom/ranap/ranap_msg_factory.h>
Harald Weltef764a152016-04-30 17:47:16 +020030#include <osmocom/ranap/RANAP_MaxBitrate.h>
Harald Welted328c1a2015-12-16 23:04:21 +010031
Harald Welte87ffeb92015-12-25 15:34:22 +010032#include "test_common.h"
33
Harald Weltef8db61b2015-12-18 17:29:59 +010034#include "hnbgw.h"
Harald Welted328c1a2015-12-16 23:04:21 +010035
Harald Weltef8db61b2015-12-18 17:29:59 +010036int asn1_xer_print = 1;
Harald Welted062df52015-12-17 23:18:40 +010037
Harald Weltef8db61b2015-12-18 17:29:59 +010038extern void *tall_msgb_ctx;
Harald Welted328c1a2015-12-16 23:04:21 +010039
Harald Weltef764a152016-04-30 17:47:16 +020040static void test_aper_int(uint32_t inp)
41{
42 RANAP_MaxBitrate_t mbr = inp;
43 asn_enc_rval_t rv;
44 uint8_t buf[32];
45
46 memset(buf, 0, sizeof(buf));
47
48 rv = aper_encode_to_buffer(&asn_DEF_RANAP_MaxBitrate, &mbr, buf, sizeof(buf));
49 if (rv.encoded == -1) {
50 fprintf(stderr, "Failed\n");
51 return;
52 }
53 printf("Encoded MaxBitRate %u to %s\n", mbr, osmo_hexdump(buf, rv.encoded/8));
54}
55
Harald Weltef8db61b2015-12-18 17:29:59 +010056int main(int argc, char **argv)
Harald Welted328c1a2015-12-16 23:04:21 +010057{
Harald Weltef8db61b2015-12-18 17:29:59 +010058 uint8_t nas_buf[] = { 0xaa, 0xbb, 0xcc };
Harald Welted328c1a2015-12-16 23:04:21 +010059 struct msgb *msg;
Harald Weltef8db61b2015-12-18 17:29:59 +010060 const char *imsi = "901700123456789";
61 uint32_t tmsi = 0x01234567;
62 uint32_t rtp_ip = 0x0a0b0c0d;
63 uint16_t rtp_port = 2342;
64 uint32_t gtp_ip = 0x1a1b1c1d;
65 uint32_t gtp_tei = 0x11223344;
66 uint8_t ik[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
67 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 +010068 int i, rc;
Harald Welted328c1a2015-12-16 23:04:21 +010069
Harald Weltef8db61b2015-12-18 17:29:59 +010070 //asn_debug = 1;
Harald Welted328c1a2015-12-16 23:04:21 +010071
Harald Weltef8db61b2015-12-18 17:29:59 +010072 msgb_set_talloc_ctx(talloc_named_const(NULL, 1, "msgb"));
Harald Welted328c1a2015-12-16 23:04:21 +010073
Harald Welte87ffeb92015-12-25 15:34:22 +010074 test_common_init();
Harald Weltef8db61b2015-12-18 17:29:59 +010075
Harald Weltef764a152016-04-30 17:47:16 +020076 test_aper_int(1);
77 test_aper_int(2);
78 test_aper_int(3);
79 test_aper_int(255);
80 test_aper_int(256);
81 test_aper_int(257);
82 test_aper_int(64000);
83 test_aper_int(0xffff);
84 test_aper_int(0xffff+1);
85 test_aper_int(0xffff+2);
86 test_aper_int(16000000);
87
Harald Weltef8db61b2015-12-18 17:29:59 +010088 for (i = 0; i < 1; i++) {
89 printf("\n==> DIRECT TRANSFER\n");
90 msg = ranap_new_msg_dt(0, nas_buf, sizeof(nas_buf));
91 if (msg)
92 printf("%s\n", msgb_hexdump(msg));
93 msgb_free(msg);
94
95 printf("\n==> SECURITY MODE COMMAND\n");
Daniel Willmannf44d12c2016-04-20 10:16:37 +020096 msg = ranap_new_msg_sec_mod_cmd(ik, ck, RANAP_KeyStatus_new);
Harald Weltef8db61b2015-12-18 17:29:59 +010097 if (msg)
98 printf("%s\n", msgb_hexdump(msg));
99 msgb_free(msg);
100
101 printf("\n==> COMMON ID\n");
102 msg = ranap_new_msg_common_id(imsi);
103 if (msg)
104 printf("%s\n", msgb_hexdump(msg));
105 msgb_free(msg);
106
107 printf("\n==> IU RELEASE CMD\n");
108 RANAP_Cause_t cause = { .present = RANAP_Cause_PR_radioNetwork,
109 .choice.radioNetwork = RANAP_CauseRadioNetwork_radio_connection_with_UE_Lost };
110 msg = ranap_new_msg_iu_rel_cmd(&cause);
111 if (msg)
112 printf("%s\n", msgb_hexdump(msg));
113 msgb_free(msg);
114
115 printf("\n==> PAGING CMD\n");
116 msg = ranap_new_msg_paging_cmd(imsi, &tmsi, 0, RANAP_PagingCause_terminating_conversational_call);
117 if (msg)
118 printf("%s\n", msgb_hexdump(msg));
119 msgb_free(msg);
120
121 printf("\n==> RAB ASSIGNMENT COMMAND (VOICE)\n");
122 msg = ranap_new_msg_rab_assign_voice(1, rtp_ip, rtp_port);
123 if (msg)
124 printf("%s\n", msgb_hexdump(msg));
125 msgb_free(msg);
126
127 printf("\n==> RAB ASSIGNMENT COMMAND (DATA)\n");
Neels Hofmeyredf13672016-04-23 13:50:46 +0200128 msg = ranap_new_msg_rab_assign_data(2, gtp_ip, gtp_tei, 1);
Harald Weltef8db61b2015-12-18 17:29:59 +0100129 if (msg)
130 printf("%s\n", msgb_hexdump(msg));
131 msgb_free(msg);
Harald Weltea575ebf2016-01-01 16:46:06 +0100132
133 printf("\n==> RESET CMD\n");
134 msg = ranap_new_msg_reset(RANAP_CN_DomainIndicator_cs_domain, &cause);
135 if (msg)
136 printf("%s\n", msgb_hexdump(msg));
137 msgb_free(msg);
138
139 printf("\n==> RESET ACK\n");
140 uint8_t plmn_id[] = { 0x09, 0x01, 0x99 };
141 RANAP_GlobalRNC_ID_t rnc_id;
142 rnc_id.pLMNidentity.buf = plmn_id;
143 rnc_id.pLMNidentity.size = sizeof(plmn_id);
144 rnc_id.rNC_ID = 2342;
145 msg = ranap_new_msg_reset_ack(RANAP_CN_DomainIndicator_cs_domain, &rnc_id);
146 if (msg)
147 printf("%s\n", msgb_hexdump(msg));
148 msgb_free(msg);
149
150 printf("\n==> INITIAL UE\n");
151 msg = ranap_new_msg_initial_ue(23, 0, &rnc_id, nas_buf, sizeof(nas_buf));
152 if (msg)
153 printf("%s\n", msgb_hexdump(msg));
154 msgb_free(msg);
155
156 printf("\n==> IU RELEASE REQ\n");
157 msg = ranap_new_msg_iu_rel_req(&cause);
158 if (msg)
159 printf("%s\n", msgb_hexdump(msg));
160 msgb_free(msg);
161
162 printf("\n==> RAB RELEASE REQ\n");
163 msg = ranap_new_msg_rab_rel_req(23, &cause);
164 if (msg)
165 printf("%s\n", msgb_hexdump(msg));
166 msgb_free(msg);
Harald Welte091039d2015-12-17 20:37:40 +0100167 }
Harald Welted328c1a2015-12-16 23:04:21 +0100168
Harald Weltef8db61b2015-12-18 17:29:59 +0100169 printf("report\n");
170 talloc_report(talloc_asn1_ctx, stdout);
171 talloc_report(tall_msgb_ctx, stdout);
172 //talloc_report(NULL, stdout);
173 printf("exit\n");
174 exit(0);
Harald Welted328c1a2015-12-16 23:04:21 +0100175}