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 | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 30 | |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 31 | #include "test_common.h" |
| 32 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 33 | #include "hnbgw.h" |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 34 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 35 | int asn1_xer_print = 1; |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 36 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 37 | extern void *tall_msgb_ctx; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 38 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 39 | int main(int argc, char **argv) |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 40 | { |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 41 | uint8_t nas_buf[] = { 0xaa, 0xbb, 0xcc }; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 42 | struct msgb *msg; |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 43 | const char *imsi = "901700123456789"; |
| 44 | uint32_t tmsi = 0x01234567; |
| 45 | uint32_t rtp_ip = 0x0a0b0c0d; |
| 46 | uint16_t rtp_port = 2342; |
| 47 | uint32_t gtp_ip = 0x1a1b1c1d; |
| 48 | uint32_t gtp_tei = 0x11223344; |
| 49 | uint8_t ik[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; |
| 50 | 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] | 51 | int i, rc; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 52 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 53 | //asn_debug = 1; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 54 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 55 | msgb_set_talloc_ctx(talloc_named_const(NULL, 1, "msgb")); |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 56 | |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 57 | test_common_init(); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 58 | |
| 59 | for (i = 0; i < 1; i++) { |
| 60 | printf("\n==> DIRECT TRANSFER\n"); |
| 61 | msg = ranap_new_msg_dt(0, nas_buf, sizeof(nas_buf)); |
| 62 | if (msg) |
| 63 | printf("%s\n", msgb_hexdump(msg)); |
| 64 | msgb_free(msg); |
| 65 | |
| 66 | printf("\n==> SECURITY MODE COMMAND\n"); |
Daniel Willmann | f44d12c | 2016-04-20 10:16:37 +0200 | [diff] [blame] | 67 | msg = ranap_new_msg_sec_mod_cmd(ik, ck, RANAP_KeyStatus_new); |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 68 | if (msg) |
| 69 | printf("%s\n", msgb_hexdump(msg)); |
| 70 | msgb_free(msg); |
| 71 | |
| 72 | printf("\n==> COMMON ID\n"); |
| 73 | msg = ranap_new_msg_common_id(imsi); |
| 74 | if (msg) |
| 75 | printf("%s\n", msgb_hexdump(msg)); |
| 76 | msgb_free(msg); |
| 77 | |
| 78 | printf("\n==> IU RELEASE CMD\n"); |
| 79 | RANAP_Cause_t cause = { .present = RANAP_Cause_PR_radioNetwork, |
| 80 | .choice.radioNetwork = RANAP_CauseRadioNetwork_radio_connection_with_UE_Lost }; |
| 81 | msg = ranap_new_msg_iu_rel_cmd(&cause); |
| 82 | if (msg) |
| 83 | printf("%s\n", msgb_hexdump(msg)); |
| 84 | msgb_free(msg); |
| 85 | |
| 86 | printf("\n==> PAGING CMD\n"); |
| 87 | msg = ranap_new_msg_paging_cmd(imsi, &tmsi, 0, RANAP_PagingCause_terminating_conversational_call); |
| 88 | if (msg) |
| 89 | printf("%s\n", msgb_hexdump(msg)); |
| 90 | msgb_free(msg); |
| 91 | |
| 92 | printf("\n==> RAB ASSIGNMENT COMMAND (VOICE)\n"); |
| 93 | msg = ranap_new_msg_rab_assign_voice(1, rtp_ip, rtp_port); |
| 94 | if (msg) |
| 95 | printf("%s\n", msgb_hexdump(msg)); |
| 96 | msgb_free(msg); |
| 97 | |
| 98 | printf("\n==> RAB ASSIGNMENT COMMAND (DATA)\n"); |
| 99 | msg = ranap_new_msg_rab_assign_data(2, gtp_ip, gtp_tei); |
| 100 | if (msg) |
| 101 | printf("%s\n", msgb_hexdump(msg)); |
| 102 | msgb_free(msg); |
Harald Welte | a575ebf | 2016-01-01 16:46:06 +0100 | [diff] [blame] | 103 | |
| 104 | printf("\n==> RESET CMD\n"); |
| 105 | msg = ranap_new_msg_reset(RANAP_CN_DomainIndicator_cs_domain, &cause); |
| 106 | if (msg) |
| 107 | printf("%s\n", msgb_hexdump(msg)); |
| 108 | msgb_free(msg); |
| 109 | |
| 110 | printf("\n==> RESET ACK\n"); |
| 111 | uint8_t plmn_id[] = { 0x09, 0x01, 0x99 }; |
| 112 | RANAP_GlobalRNC_ID_t rnc_id; |
| 113 | rnc_id.pLMNidentity.buf = plmn_id; |
| 114 | rnc_id.pLMNidentity.size = sizeof(plmn_id); |
| 115 | rnc_id.rNC_ID = 2342; |
| 116 | msg = ranap_new_msg_reset_ack(RANAP_CN_DomainIndicator_cs_domain, &rnc_id); |
| 117 | if (msg) |
| 118 | printf("%s\n", msgb_hexdump(msg)); |
| 119 | msgb_free(msg); |
| 120 | |
| 121 | printf("\n==> INITIAL UE\n"); |
| 122 | msg = ranap_new_msg_initial_ue(23, 0, &rnc_id, nas_buf, sizeof(nas_buf)); |
| 123 | if (msg) |
| 124 | printf("%s\n", msgb_hexdump(msg)); |
| 125 | msgb_free(msg); |
| 126 | |
| 127 | printf("\n==> IU RELEASE REQ\n"); |
| 128 | msg = ranap_new_msg_iu_rel_req(&cause); |
| 129 | if (msg) |
| 130 | printf("%s\n", msgb_hexdump(msg)); |
| 131 | msgb_free(msg); |
| 132 | |
| 133 | printf("\n==> RAB RELEASE REQ\n"); |
| 134 | msg = ranap_new_msg_rab_rel_req(23, &cause); |
| 135 | if (msg) |
| 136 | printf("%s\n", msgb_hexdump(msg)); |
| 137 | msgb_free(msg); |
Harald Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 138 | } |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 139 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 140 | printf("report\n"); |
| 141 | talloc_report(talloc_asn1_ctx, stdout); |
| 142 | talloc_report(tall_msgb_ctx, stdout); |
| 143 | //talloc_report(NULL, stdout); |
| 144 | printf("exit\n"); |
| 145 | exit(0); |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 146 | } |