Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 1 | /* (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 Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 23 | |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 24 | #include "asn1helpers.h" |
Neels Hofmeyr | 96979af | 2016-01-05 15:19:44 +0100 | [diff] [blame] | 25 | #include <osmocom/ranap/iu_helpers.h> |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 26 | |
Neels Hofmeyr | 96979af | 2016-01-05 15:19:44 +0100 | [diff] [blame] | 27 | #include <osmocom/ranap/ranap_common.h> |
| 28 | #include <osmocom/ranap/ranap_ies_defs.h> |
| 29 | #include <osmocom/ranap/ranap_msg_factory.h> |
Harald Welte | f764a15 | 2016-04-30 17:47:16 +0200 | [diff] [blame] | 30 | #include <osmocom/ranap/RANAP_MaxBitrate.h> |
Harald Welte | 14da541 | 2016-05-01 15:42:19 +0200 | [diff] [blame] | 31 | #include <osmocom/ranap/RANAP_CauseMisc.h> |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 32 | |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 33 | #include "test_common.h" |
| 34 | |
Neels Hofmeyr | df63de2 | 2016-08-18 13:13:55 +0200 | [diff] [blame] | 35 | #include <osmocom/iuh/hnbgw.h> |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 36 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 37 | int asn1_xer_print = 1; |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 38 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 39 | extern void *tall_msgb_ctx; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 40 | |
Harald Welte | f764a15 | 2016-04-30 17:47:16 +0200 | [diff] [blame] | 41 | static void test_aper_int(uint32_t inp) |
| 42 | { |
| 43 | RANAP_MaxBitrate_t mbr = inp; |
| 44 | asn_enc_rval_t rv; |
| 45 | uint8_t buf[32]; |
| 46 | |
| 47 | memset(buf, 0, sizeof(buf)); |
| 48 | |
| 49 | rv = aper_encode_to_buffer(&asn_DEF_RANAP_MaxBitrate, &mbr, buf, sizeof(buf)); |
| 50 | if (rv.encoded == -1) { |
| 51 | fprintf(stderr, "Failed\n"); |
| 52 | return; |
| 53 | } |
| 54 | printf("Encoded MaxBitRate %u to %s\n", mbr, osmo_hexdump(buf, rv.encoded/8)); |
| 55 | } |
| 56 | |
Harald Welte | 14da541 | 2016-05-01 15:42:19 +0200 | [diff] [blame] | 57 | static void test_aper_causemisc(uint32_t inp, uint8_t exp_enc) |
| 58 | { |
| 59 | RANAP_Cause_t c = { .present = RANAP_Cause_PR_misc, .choice.misc = inp }; |
Neels Hofmeyr | 802acd0 | 2016-05-03 13:11:40 +0200 | [diff] [blame] | 60 | RANAP_Cause_t *c_dec = NULL; |
Harald Welte | 14da541 | 2016-05-01 15:42:19 +0200 | [diff] [blame] | 61 | asn_enc_rval_t rv; |
| 62 | uint8_t buf[32]; |
| 63 | |
| 64 | memset(buf, 0, sizeof(buf)); |
| 65 | |
| 66 | rv = aper_encode_to_buffer(&asn_DEF_RANAP_Cause, &c, buf, sizeof(buf)); |
| 67 | if (rv.encoded == -1) { |
| 68 | fprintf(stderr, "Failed\n"); |
| 69 | return; |
| 70 | } |
| 71 | /* test encoding */ |
| 72 | printf("Encoded Cause Misc=%u to %s\n", inp, osmo_hexdump(buf, rv.encoded/8)); |
| 73 | OSMO_ASSERT(buf[0] == exp_enc); |
| 74 | OSMO_ASSERT(rv.encoded == 8); |
| 75 | |
| 76 | /* test re-decoding */ |
| 77 | aper_decode(NULL, &asn_DEF_RANAP_Cause, &c_dec, buf, 1, 0, 0); |
| 78 | printf("Decoded Cause Misc=%u\n", c_dec->choice.misc); |
| 79 | OSMO_ASSERT(c_dec->present == RANAP_Cause_PR_misc); |
| 80 | OSMO_ASSERT(c_dec->choice.misc == inp); |
Neels Hofmeyr | 95d0ba5 | 2016-05-02 14:44:51 +0200 | [diff] [blame] | 81 | ASN_STRUCT_FREE(asn_DEF_RANAP_Cause, c_dec); |
Harald Welte | 14da541 | 2016-05-01 15:42:19 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 84 | int main(int argc, char **argv) |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 85 | { |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 86 | uint8_t nas_buf[] = { 0xaa, 0xbb, 0xcc }; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 87 | struct msgb *msg; |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 88 | const char *imsi = "901700123456789"; |
| 89 | uint32_t tmsi = 0x01234567; |
| 90 | uint32_t rtp_ip = 0x0a0b0c0d; |
| 91 | uint16_t rtp_port = 2342; |
| 92 | uint32_t gtp_ip = 0x1a1b1c1d; |
| 93 | uint32_t gtp_tei = 0x11223344; |
| 94 | uint8_t ik[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; |
| 95 | uint8_t ck[16] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 96 | int i, rc; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 97 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 98 | //asn_debug = 1; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 99 | |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 100 | test_common_init(); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 101 | |
Harald Welte | f764a15 | 2016-04-30 17:47:16 +0200 | [diff] [blame] | 102 | 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 Welte | 14da541 | 2016-05-01 15:42:19 +0200 | [diff] [blame] | 113 | test_aper_causemisc(RANAP_CauseMisc_unspecified_failure, 0x42); |
Harald Welte | f764a15 | 2016-04-30 17:47:16 +0200 | [diff] [blame] | 114 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 115 | 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 Willmann | f44d12c | 2016-04-20 10:16:37 +0200 | [diff] [blame] | 123 | msg = ranap_new_msg_sec_mod_cmd(ik, ck, RANAP_KeyStatus_new); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 124 | 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 Hofmeyr | f6673b7 | 2016-09-08 15:39:18 +0200 | [diff] [blame] | 149 | msg = ranap_new_msg_rab_assign_voice(1, rtp_ip, rtp_port, 1); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 150 | if (msg) |
| 151 | printf("%s\n", msgb_hexdump(msg)); |
| 152 | msgb_free(msg); |
| 153 | |
| 154 | printf("\n==> RAB ASSIGNMENT COMMAND (DATA)\n"); |
Neels Hofmeyr | edf1367 | 2016-04-23 13:50:46 +0200 | [diff] [blame] | 155 | msg = ranap_new_msg_rab_assign_data(2, gtp_ip, gtp_tei, 1); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 156 | if (msg) |
| 157 | printf("%s\n", msgb_hexdump(msg)); |
| 158 | msgb_free(msg); |
Harald Welte | a575ebf | 2016-01-01 16:46:06 +0100 | [diff] [blame] | 159 | |
| 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 Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 194 | } |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 195 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 196 | printf("report\n"); |
| 197 | talloc_report(talloc_asn1_ctx, stdout); |
| 198 | talloc_report(tall_msgb_ctx, stdout); |
| 199 | //talloc_report(NULL, stdout); |
| 200 | printf("exit\n"); |
| 201 | exit(0); |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 202 | } |