blob: a6df18666152196d2a9423172a4d38260aa9da3b [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 Welte14da5412016-05-01 15:42:19 +020031#include <osmocom/ranap/RANAP_CauseMisc.h>
Harald Welted328c1a2015-12-16 23:04:21 +010032
Harald Welte87ffeb92015-12-25 15:34:22 +010033#include "test_common.h"
34
Neels Hofmeyrdf63de22016-08-18 13:13:55 +020035#include <osmocom/iuh/hnbgw.h>
Harald Welted328c1a2015-12-16 23:04:21 +010036
Harald Weltef8db61b2015-12-18 17:29:59 +010037extern void *tall_msgb_ctx;
Harald Welted328c1a2015-12-16 23:04:21 +010038
Harald Weltef764a152016-04-30 17:47:16 +020039static void test_aper_int(uint32_t inp)
40{
41 RANAP_MaxBitrate_t mbr = inp;
42 asn_enc_rval_t rv;
43 uint8_t buf[32];
44
45 memset(buf, 0, sizeof(buf));
46
47 rv = aper_encode_to_buffer(&asn_DEF_RANAP_MaxBitrate, &mbr, buf, sizeof(buf));
48 if (rv.encoded == -1) {
49 fprintf(stderr, "Failed\n");
50 return;
51 }
Pau Espin Pedrolca741262020-03-20 20:22:03 +010052 printf("Encoded MaxBitRate %ld to %s\n", mbr, osmo_hexdump(buf, rv.encoded/8));
Harald Weltef764a152016-04-30 17:47:16 +020053}
54
Harald Welte14da5412016-05-01 15:42:19 +020055static void test_aper_causemisc(uint32_t inp, uint8_t exp_enc)
56{
57 RANAP_Cause_t c = { .present = RANAP_Cause_PR_misc, .choice.misc = inp };
Neels Hofmeyr802acd02016-05-03 13:11:40 +020058 RANAP_Cause_t *c_dec = NULL;
Harald Welte14da5412016-05-01 15:42:19 +020059 asn_enc_rval_t rv;
60 uint8_t buf[32];
61
62 memset(buf, 0, sizeof(buf));
63
64 rv = aper_encode_to_buffer(&asn_DEF_RANAP_Cause, &c, buf, sizeof(buf));
65 if (rv.encoded == -1) {
66 fprintf(stderr, "Failed\n");
67 return;
68 }
69 /* test encoding */
70 printf("Encoded Cause Misc=%u to %s\n", inp, osmo_hexdump(buf, rv.encoded/8));
71 OSMO_ASSERT(buf[0] == exp_enc);
72 OSMO_ASSERT(rv.encoded == 8);
73
74 /* test re-decoding */
75 aper_decode(NULL, &asn_DEF_RANAP_Cause, &c_dec, buf, 1, 0, 0);
Pau Espin Pedrolca741262020-03-20 20:22:03 +010076 printf("Decoded Cause Misc=%ld\n", c_dec->choice.misc);
Harald Welte14da5412016-05-01 15:42:19 +020077 OSMO_ASSERT(c_dec->present == RANAP_Cause_PR_misc);
78 OSMO_ASSERT(c_dec->choice.misc == inp);
Neels Hofmeyr95d0ba52016-05-02 14:44:51 +020079 ASN_STRUCT_FREE(asn_DEF_RANAP_Cause, c_dec);
Harald Welte14da5412016-05-01 15:42:19 +020080}
81
Harald Weltef8db61b2015-12-18 17:29:59 +010082int main(int argc, char **argv)
Harald Welted328c1a2015-12-16 23:04:21 +010083{
Harald Weltef8db61b2015-12-18 17:29:59 +010084 uint8_t nas_buf[] = { 0xaa, 0xbb, 0xcc };
Harald Welted328c1a2015-12-16 23:04:21 +010085 struct msgb *msg;
Harald Weltef8db61b2015-12-18 17:29:59 +010086 const char *imsi = "901700123456789";
87 uint32_t tmsi = 0x01234567;
88 uint32_t rtp_ip = 0x0a0b0c0d;
89 uint16_t rtp_port = 2342;
90 uint32_t gtp_ip = 0x1a1b1c1d;
91 uint32_t gtp_tei = 0x11223344;
92 uint8_t ik[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
93 uint8_t ck[16] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
Vadim Yanitskiy065c1922020-04-07 21:11:13 +070094 int i;
Harald Welted328c1a2015-12-16 23:04:21 +010095
Pau Espin Pedrol4f356652020-05-18 10:34:43 +020096 asn1_xer_print = 1;
97
Harald Weltef8db61b2015-12-18 17:29:59 +010098 //asn_debug = 1;
Harald Welted328c1a2015-12-16 23:04:21 +010099
Harald Welte87ffeb92015-12-25 15:34:22 +0100100 test_common_init();
Harald Weltef8db61b2015-12-18 17:29:59 +0100101
Harald Weltef764a152016-04-30 17:47:16 +0200102 test_aper_int(1);
103 test_aper_int(2);
104 test_aper_int(3);
105 test_aper_int(255);
106 test_aper_int(256);
107 test_aper_int(257);
108 test_aper_int(64000);
109 test_aper_int(0xffff);
110 test_aper_int(0xffff+1);
111 test_aper_int(0xffff+2);
112 test_aper_int(16000000);
Harald Welte14da5412016-05-01 15:42:19 +0200113 test_aper_causemisc(RANAP_CauseMisc_unspecified_failure, 0x42);
Harald Weltef764a152016-04-30 17:47:16 +0200114
Harald Weltef8db61b2015-12-18 17:29:59 +0100115 for (i = 0; i < 1; i++) {
116 printf("\n==> DIRECT TRANSFER\n");
117 msg = ranap_new_msg_dt(0, nas_buf, sizeof(nas_buf));
118 if (msg)
119 printf("%s\n", msgb_hexdump(msg));
120 msgb_free(msg);
121
122 printf("\n==> SECURITY MODE COMMAND\n");
Daniel Willmannf44d12c2016-04-20 10:16:37 +0200123 msg = ranap_new_msg_sec_mod_cmd(ik, ck, RANAP_KeyStatus_new);
Harald Weltef8db61b2015-12-18 17:29:59 +0100124 if (msg)
125 printf("%s\n", msgb_hexdump(msg));
126 msgb_free(msg);
127
128 printf("\n==> COMMON ID\n");
129 msg = ranap_new_msg_common_id(imsi);
130 if (msg)
131 printf("%s\n", msgb_hexdump(msg));
132 msgb_free(msg);
133
134 printf("\n==> IU RELEASE CMD\n");
135 RANAP_Cause_t cause = { .present = RANAP_Cause_PR_radioNetwork,
136 .choice.radioNetwork = RANAP_CauseRadioNetwork_radio_connection_with_UE_Lost };
137 msg = ranap_new_msg_iu_rel_cmd(&cause);
138 if (msg)
139 printf("%s\n", msgb_hexdump(msg));
140 msgb_free(msg);
141
142 printf("\n==> PAGING CMD\n");
143 msg = ranap_new_msg_paging_cmd(imsi, &tmsi, 0, RANAP_PagingCause_terminating_conversational_call);
144 if (msg)
145 printf("%s\n", msgb_hexdump(msg));
146 msgb_free(msg);
147
148 printf("\n==> RAB ASSIGNMENT COMMAND (VOICE)\n");
Neels Hofmeyrf6673b72016-09-08 15:39:18 +0200149 msg = ranap_new_msg_rab_assign_voice(1, rtp_ip, rtp_port, 1);
Harald Weltef8db61b2015-12-18 17:29:59 +0100150 if (msg)
151 printf("%s\n", msgb_hexdump(msg));
152 msgb_free(msg);
153
154 printf("\n==> RAB ASSIGNMENT COMMAND (DATA)\n");
Neels Hofmeyredf13672016-04-23 13:50:46 +0200155 msg = ranap_new_msg_rab_assign_data(2, gtp_ip, gtp_tei, 1);
Harald Weltef8db61b2015-12-18 17:29:59 +0100156 if (msg)
157 printf("%s\n", msgb_hexdump(msg));
158 msgb_free(msg);
Harald Weltea575ebf2016-01-01 16:46:06 +0100159
160 printf("\n==> RESET CMD\n");
161 msg = ranap_new_msg_reset(RANAP_CN_DomainIndicator_cs_domain, &cause);
162 if (msg)
163 printf("%s\n", msgb_hexdump(msg));
164 msgb_free(msg);
165
166 printf("\n==> RESET ACK\n");
167 uint8_t plmn_id[] = { 0x09, 0x01, 0x99 };
168 RANAP_GlobalRNC_ID_t rnc_id;
169 rnc_id.pLMNidentity.buf = plmn_id;
170 rnc_id.pLMNidentity.size = sizeof(plmn_id);
171 rnc_id.rNC_ID = 2342;
172 msg = ranap_new_msg_reset_ack(RANAP_CN_DomainIndicator_cs_domain, &rnc_id);
173 if (msg)
174 printf("%s\n", msgb_hexdump(msg));
175 msgb_free(msg);
176
177 printf("\n==> INITIAL UE\n");
178 msg = ranap_new_msg_initial_ue(23, 0, &rnc_id, nas_buf, sizeof(nas_buf));
179 if (msg)
180 printf("%s\n", msgb_hexdump(msg));
181 msgb_free(msg);
182
183 printf("\n==> IU RELEASE REQ\n");
184 msg = ranap_new_msg_iu_rel_req(&cause);
185 if (msg)
186 printf("%s\n", msgb_hexdump(msg));
187 msgb_free(msg);
188
189 printf("\n==> RAB RELEASE REQ\n");
190 msg = ranap_new_msg_rab_rel_req(23, &cause);
191 if (msg)
192 printf("%s\n", msgb_hexdump(msg));
193 msgb_free(msg);
Harald Welte091039d2015-12-17 20:37:40 +0100194 }
Harald Welted328c1a2015-12-16 23:04:21 +0100195
Harald Weltef8db61b2015-12-18 17:29:59 +0100196 printf("report\n");
197 talloc_report(talloc_asn1_ctx, stdout);
198 talloc_report(tall_msgb_ctx, stdout);
199 //talloc_report(NULL, stdout);
Neels Hofmeyrd9cb19a2017-11-18 18:47:55 +0100200
201 test_common_cleanup();
Harald Weltef8db61b2015-12-18 17:29:59 +0100202 printf("exit\n");
203 exit(0);
Harald Welted328c1a2015-12-16 23:04:21 +0100204}