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" |
| 25 | #include "iu_helpers.h" |
| 26 | |
| 27 | #include "ranap_common.h" |
| 28 | #include "ranap_ies_defs.h" |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 29 | #include "ranap_msg_factory.h" |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 30 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 31 | #include "hnbgw.h" |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 32 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 33 | void *talloc_asn1_ctx; |
| 34 | int asn1_xer_print = 1; |
Harald Welte | d062df5 | 2015-12-17 23:18:40 +0100 | [diff] [blame] | 35 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 36 | extern void *tall_msgb_ctx; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 37 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 38 | static 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 Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 51 | static const struct log_info hnbgw_log_info = { |
| 52 | .cat = log_cat, |
| 53 | .num_cat = ARRAY_SIZE(log_cat), |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 54 | }; |
| 55 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 56 | |
| 57 | int main(int argc, char **argv) |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 58 | { |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 59 | uint8_t nas_buf[] = { 0xaa, 0xbb, 0xcc }; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 60 | struct msgb *msg; |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 61 | 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 Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 69 | int i, rc; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 70 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 71 | //asn_debug = 1; |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 72 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 73 | talloc_asn1_ctx = talloc_named_const(NULL, 1, "ASN"); |
| 74 | msgb_set_talloc_ctx(talloc_named_const(NULL, 1, "msgb")); |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 75 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 76 | 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 Welte | 091039d | 2015-12-17 20:37:40 +0100 | [diff] [blame] | 124 | } |
Harald Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 125 | |
Harald Welte | f8db61b | 2015-12-18 17:29:59 +0100 | [diff] [blame] | 126 | 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 Welte | d328c1a | 2015-12-16 23:04:21 +0100 | [diff] [blame] | 132 | } |