Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 1 | /* Test HNB */ |
| 2 | |
| 3 | /* (C) 2015 by Daniel Willmann <dwillmann@sysmocom.de> |
| 4 | * (C) 2015 by Sysmocom s.f.m.c. GmbH |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <unistd.h> |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <getopt.h> |
| 27 | #include <errno.h> |
| 28 | #include <signal.h> |
| 29 | |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/socket.h> |
| 32 | #include <netinet/in.h> |
| 33 | #include <netinet/sctp.h> |
| 34 | #include <arpa/inet.h> |
| 35 | |
| 36 | #include <osmocom/core/application.h> |
| 37 | #include <osmocom/core/talloc.h> |
| 38 | #include <osmocom/core/select.h> |
| 39 | #include <osmocom/core/logging.h> |
| 40 | #include <osmocom/core/socket.h> |
| 41 | #include <osmocom/core/msgb.h> |
| 42 | #include <osmocom/core/write_queue.h> |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 43 | #include <osmocom/netif/stream.h> |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 44 | #include <osmocom/gsm/tlv.h> |
| 45 | #include <osmocom/gsm/gsm48.h> |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 46 | |
| 47 | #include <osmocom/vty/telnet_interface.h> |
| 48 | #include <osmocom/vty/logging.h> |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 49 | #include <osmocom/vty/command.h> |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 50 | |
Neels Hofmeyr | 26779f8 | 2016-04-18 17:04:17 +0200 | [diff] [blame] | 51 | #include <osmocom/crypt/auth.h> |
| 52 | |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 53 | #include "hnb-test.h" |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 54 | #include "hnb-test-layers.h" |
Neels Hofmeyr | 8345792 | 2016-08-26 23:56:44 +0200 | [diff] [blame] | 55 | #include <osmocom/hnbap/hnbap_common.h> |
| 56 | #include <osmocom/hnbap/hnbap_ies_defs.h> |
Neels Hofmeyr | df63de2 | 2016-08-18 13:13:55 +0200 | [diff] [blame] | 57 | #include <osmocom/rua/rua_msg_factory.h> |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 58 | #include "asn1helpers.h" |
Neels Hofmeyr | 96979af | 2016-01-05 15:19:44 +0100 | [diff] [blame] | 59 | #include <osmocom/ranap/iu_helpers.h> |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 60 | #include "test_common.h" |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 61 | |
Neels Hofmeyr | 96979af | 2016-01-05 15:19:44 +0100 | [diff] [blame] | 62 | #include <osmocom/ranap/ranap_msg_factory.h> |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 63 | |
Neels Hofmeyr | 0968a58 | 2016-01-11 15:19:38 +0100 | [diff] [blame] | 64 | #include <osmocom/rua/RUA_RUA-PDU.h> |
| 65 | |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 66 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 67 | |
| 68 | #include <osmocom/ranap/RANAP_ProcedureCode.h> |
| 69 | #include <osmocom/ranap/RANAP_Criticality.h> |
| 70 | #include <osmocom/ranap/RANAP_DirectTransfer.h> |
| 71 | |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 72 | static void *tall_hnb_ctx; |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 73 | |
| 74 | struct hnb_test g_hnb_test = { |
Neels Hofmeyr | 5f9be1e | 2016-02-29 13:33:44 +0100 | [diff] [blame] | 75 | .gw_addr = "127.0.0.1", |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 76 | .gw_port = IUH_DEFAULT_SCTP_PORT, |
| 77 | }; |
| 78 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 79 | struct msgb *rua_new_udt(struct msgb *inmsg); |
| 80 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 81 | static int hnb_test_ue_de_register_tx(struct hnb_test *hnb_test) |
Daniel Willmann | 19dedbb | 2015-12-17 11:57:41 +0100 | [diff] [blame] | 82 | { |
| 83 | struct msgb *msg; |
Pau Espin Pedrol | 89f4c80 | 2021-01-14 11:13:46 +0100 | [diff] [blame] | 84 | int rc; |
Daniel Willmann | 19dedbb | 2015-12-17 11:57:41 +0100 | [diff] [blame] | 85 | uint32_t ctx_id; |
| 86 | |
| 87 | UEDe_Register_t dereg; |
| 88 | UEDe_RegisterIEs_t dereg_ies; |
| 89 | memset(&dereg_ies, 0, sizeof(dereg_ies)); |
| 90 | |
| 91 | asn1_u24_to_bitstring(&dereg_ies.context_ID, &ctx_id, hnb_test->ctx_id); |
| 92 | dereg_ies.cause.present = Cause_PR_radioNetwork; |
| 93 | dereg_ies.cause.choice.radioNetwork = CauseRadioNetwork_connection_with_UE_lost; |
| 94 | |
| 95 | memset(&dereg, 0, sizeof(dereg)); |
| 96 | rc = hnbap_encode_uede_registeries(&dereg, &dereg_ies); |
Pau Espin Pedrol | 96a94bc | 2021-01-14 11:17:19 +0100 | [diff] [blame^] | 97 | OSMO_ASSERT(rc == 0); |
Daniel Willmann | 19dedbb | 2015-12-17 11:57:41 +0100 | [diff] [blame] | 98 | |
| 99 | msg = hnbap_generate_initiating_message(ProcedureCode_id_UEDe_Register, |
| 100 | Criticality_ignore, |
| 101 | &asn_DEF_UEDe_Register, |
| 102 | &dereg); |
| 103 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 104 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_UEDe_Register, &dereg); |
Daniel Willmann | 19dedbb | 2015-12-17 11:57:41 +0100 | [diff] [blame] | 105 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 106 | msgb_sctp_ppid(msg) = IUH_PPI_HNBAP; |
Daniel Willmann | 19dedbb | 2015-12-17 11:57:41 +0100 | [diff] [blame] | 107 | |
| 108 | return osmo_wqueue_enqueue(&hnb_test->wqueue, msg); |
| 109 | } |
| 110 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 111 | static int hnb_test_ue_register_tx(struct hnb_test *hnb_test, const char *imsi_str) |
Daniel Willmann | 479cb30 | 2015-12-09 17:54:59 +0100 | [diff] [blame] | 112 | { |
Daniel Willmann | 4e31250 | 2015-12-09 17:59:24 +0100 | [diff] [blame] | 113 | struct msgb *msg; |
| 114 | int rc, imsi_len; |
| 115 | |
Pau Espin Pedrol | b4ff1f4 | 2021-01-14 11:14:54 +0100 | [diff] [blame] | 116 | uint8_t imsi_buf[16]; |
Daniel Willmann | 141a0ba | 2015-12-17 18:03:52 +0100 | [diff] [blame] | 117 | |
Daniel Willmann | 4e31250 | 2015-12-09 17:59:24 +0100 | [diff] [blame] | 118 | UERegisterRequest_t request_out; |
| 119 | UERegisterRequestIEs_t request; |
| 120 | memset(&request, 0, sizeof(request)); |
| 121 | |
| 122 | request.uE_Identity.present = UE_Identity_PR_iMSI; |
| 123 | |
Harald Welte | 056984f | 2016-01-03 16:31:31 +0100 | [diff] [blame] | 124 | imsi_len = ranap_imsi_encode(imsi_buf, sizeof(imsi_buf), imsi_str); |
Pau Espin Pedrol | b4ff1f4 | 2021-01-14 11:14:54 +0100 | [diff] [blame] | 125 | OCTET_STRING_fromBuf(&request.uE_Identity.choice.iMSI, (const char*)imsi_buf, imsi_len); |
Daniel Willmann | 4e31250 | 2015-12-09 17:59:24 +0100 | [diff] [blame] | 126 | |
| 127 | request.registration_Cause = Registration_Cause_normal; |
| 128 | request.uE_Capabilities.access_stratum_release_indicator = Access_stratum_release_indicator_rel_6; |
| 129 | request.uE_Capabilities.csg_capability = CSG_Capability_not_csg_capable; |
| 130 | |
| 131 | memset(&request_out, 0, sizeof(request_out)); |
| 132 | rc = hnbap_encode_ueregisterrequesties(&request_out, &request); |
Pau Espin Pedrol | 96a94bc | 2021-01-14 11:17:19 +0100 | [diff] [blame^] | 133 | OSMO_ASSERT(rc == 0); |
Daniel Willmann | 4e31250 | 2015-12-09 17:59:24 +0100 | [diff] [blame] | 134 | |
| 135 | msg = hnbap_generate_initiating_message(ProcedureCode_id_UERegister, |
| 136 | Criticality_reject, |
| 137 | &asn_DEF_UERegisterRequest, |
| 138 | &request_out); |
| 139 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 140 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_UERegisterRequest, &request_out); |
Daniel Willmann | 4e31250 | 2015-12-09 17:59:24 +0100 | [diff] [blame] | 141 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 142 | msgb_sctp_ppid(msg) = IUH_PPI_HNBAP; |
Daniel Willmann | 4e31250 | 2015-12-09 17:59:24 +0100 | [diff] [blame] | 143 | |
| 144 | return osmo_wqueue_enqueue(&hnb_test->wqueue, msg); |
Daniel Willmann | 479cb30 | 2015-12-09 17:54:59 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 147 | static int hnb_test_rx_hnb_register_acc(struct hnb_test *hnb, ANY_t *in) |
Daniel Willmann | 479cb30 | 2015-12-09 17:54:59 +0100 | [diff] [blame] | 148 | { |
| 149 | int rc; |
| 150 | HNBRegisterAcceptIEs_t accept; |
| 151 | |
| 152 | rc = hnbap_decode_hnbregisteraccepties(&accept, in); |
| 153 | if (rc < 0) { |
| 154 | } |
| 155 | |
| 156 | hnb->rnc_id = accept.rnc_id; |
| 157 | printf("HNB Register accept with RNC ID %u\n", hnb->rnc_id); |
| 158 | |
Daniel Willmann | 11e912a | 2016-01-07 13:19:30 +0100 | [diff] [blame] | 159 | hnbap_free_hnbregisteraccepties(&accept); |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 160 | return 0; |
Daniel Willmann | 479cb30 | 2015-12-09 17:54:59 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 163 | static int hnb_test_rx_ue_register_acc(struct hnb_test *hnb, ANY_t *in) |
Daniel Willmann | a7b0240 | 2015-12-09 19:05:09 +0100 | [diff] [blame] | 164 | { |
| 165 | int rc; |
| 166 | uint32_t ctx_id; |
| 167 | UERegisterAcceptIEs_t accept; |
| 168 | char imsi[16]; |
| 169 | |
| 170 | rc = hnbap_decode_ueregisteraccepties(&accept, in); |
| 171 | if (rc < 0) { |
| 172 | return rc; |
| 173 | } |
| 174 | |
| 175 | if (accept.uE_Identity.present != UE_Identity_PR_iMSI) { |
| 176 | printf("Wrong type in UE register accept\n"); |
| 177 | return -1; |
| 178 | } |
| 179 | |
| 180 | ctx_id = asn1bitstr_to_u24(&accept.context_ID); |
| 181 | |
Harald Welte | 056984f | 2016-01-03 16:31:31 +0100 | [diff] [blame] | 182 | ranap_bcd_decode(imsi, sizeof(imsi), accept.uE_Identity.choice.iMSI.buf, |
Daniel Willmann | a7b0240 | 2015-12-09 19:05:09 +0100 | [diff] [blame] | 183 | accept.uE_Identity.choice.iMSI.size); |
| 184 | printf("UE Register accept for IMSI %s, context %u\n", imsi, ctx_id); |
| 185 | |
Daniel Willmann | 19dedbb | 2015-12-17 11:57:41 +0100 | [diff] [blame] | 186 | hnb->ctx_id = ctx_id; |
Daniel Willmann | 11e912a | 2016-01-07 13:19:30 +0100 | [diff] [blame] | 187 | hnbap_free_ueregisteraccepties(&accept); |
Daniel Willmann | 19dedbb | 2015-12-17 11:57:41 +0100 | [diff] [blame] | 188 | |
Daniel Willmann | a7b0240 | 2015-12-09 19:05:09 +0100 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 192 | static struct msgb *gen_nas_id_resp() |
| 193 | { |
| 194 | uint8_t id_resp[] = { |
Neels Hofmeyr | 5c1cc8c | 2016-02-29 09:28:48 +0100 | [diff] [blame] | 195 | GSM48_PDISC_MM, |
| 196 | GSM48_MT_MM_ID_RESP, |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 197 | /* IMEISV */ |
| 198 | 0x09, /* len */ |
| 199 | 0x03, /* first digit (0000) + even (0) + id IMEISV (011) */ |
| 200 | 0x31, 0x91, 0x06, 0x00, 0x28, 0x47, 0x11, /* digits */ |
| 201 | 0xf2, /* filler (1111) + last digit (0010) */ |
| 202 | }; |
| 203 | |
Neels Hofmeyr | e1f709f | 2016-02-28 00:50:45 +0100 | [diff] [blame] | 204 | return ranap_new_msg_dt(0, id_resp, sizeof(id_resp)); |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 205 | } |
| 206 | |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 207 | static struct msgb *gen_nas_tmsi_realloc_compl() |
| 208 | { |
| 209 | uint8_t id_resp[] = { |
| 210 | GSM48_PDISC_MM, |
| 211 | GSM48_MT_MM_TMSI_REALL_COMPL, |
| 212 | }; |
| 213 | |
| 214 | return ranap_new_msg_dt(0, id_resp, sizeof(id_resp)); |
| 215 | } |
| 216 | |
Neels Hofmeyr | 26779f8 | 2016-04-18 17:04:17 +0200 | [diff] [blame] | 217 | static struct msgb *gen_nas_auth_resp(uint8_t *sres) |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 218 | { |
| 219 | uint8_t id_resp[] = { |
| 220 | GSM48_PDISC_MM, |
Neels Hofmeyr | 9987260 | 2016-04-05 11:51:15 +0200 | [diff] [blame] | 221 | 0x80 | GSM48_MT_MM_AUTH_RESP, /* simulate sequence nr 2 */ |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 222 | 0x61, 0xb5, 0x69, 0xf5 /* hardcoded SRES */ |
| 223 | }; |
| 224 | |
Neels Hofmeyr | 26779f8 | 2016-04-18 17:04:17 +0200 | [diff] [blame] | 225 | memcpy(id_resp + 2, sres, 4); |
| 226 | |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 227 | return ranap_new_msg_dt(0, id_resp, sizeof(id_resp)); |
| 228 | } |
| 229 | |
Neels Hofmeyr | c28ed37 | 2016-04-19 01:24:34 +0200 | [diff] [blame] | 230 | static int hnb_test_tx_dt(struct hnb_test *hnb, struct msgb *txm) |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 231 | { |
| 232 | struct hnbtest_chan *chan; |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 233 | struct msgb *rua; |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 234 | |
| 235 | chan = hnb->cs.chan; |
| 236 | if (!chan) { |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 237 | printf("hnb_test_nas_tx_tmsi_realloc_compl(): No CS channel established yet.\n"); |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 238 | return -1; |
| 239 | } |
| 240 | |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 241 | rua = rua_new_dt(chan->is_ps, chan->conn_id, txm); |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 242 | osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua); |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 243 | return 0; |
| 244 | } |
| 245 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 246 | static struct tlv_parsed *parse_mm(struct gsm48_hdr *gh, int len) |
Neels Hofmeyr | d4598fa | 2016-03-09 01:37:40 +0100 | [diff] [blame] | 247 | { |
| 248 | static struct tlv_parsed tp; |
Neels Hofmeyr | d4598fa | 2016-03-09 01:37:40 +0100 | [diff] [blame] | 249 | int parse_res; |
Neels Hofmeyr | d4598fa | 2016-03-09 01:37:40 +0100 | [diff] [blame] | 250 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 251 | len -= (const char *)&gh->data[0] - (const char *)gh; |
Neels Hofmeyr | d4598fa | 2016-03-09 01:37:40 +0100 | [diff] [blame] | 252 | |
Neels Hofmeyr | d7ad0ac | 2016-04-05 11:52:27 +0200 | [diff] [blame] | 253 | OSMO_ASSERT(gsm48_hdr_pdisc(gh) == GSM48_PDISC_MM); |
| 254 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 255 | parse_res = tlv_parse(&tp, &gsm48_mm_att_tlvdef, &gh->data[0], len, 0, 0); |
Neels Hofmeyr | d4598fa | 2016-03-09 01:37:40 +0100 | [diff] [blame] | 256 | if (parse_res <= 0) { |
Neels Hofmeyr | 7c28f6f | 2016-04-05 11:49:53 +0200 | [diff] [blame] | 257 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
Neels Hofmeyr | d4598fa | 2016-03-09 01:37:40 +0100 | [diff] [blame] | 258 | printf("Error parsing MM message 0x%hhx: %d\n", msg_type, parse_res); |
| 259 | return NULL; |
| 260 | } |
| 261 | |
| 262 | return &tp; |
| 263 | } |
| 264 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 265 | int hnb_test_nas_rx_lu_accept(struct gsm48_hdr *gh, int len, int *sent_tmsi) |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 266 | { |
| 267 | printf(" :D Location Update Accept :D\n"); |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 268 | struct gsm48_loc_area_id *lai; |
Neels Hofmeyr | c04eb53 | 2016-03-04 12:38:43 +0100 | [diff] [blame] | 269 | |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 270 | lai = (struct gsm48_loc_area_id *)&gh->data[0]; |
| 271 | |
Neels Hofmeyr | 3050864 | 2018-02-22 04:04:22 +0100 | [diff] [blame] | 272 | struct osmo_location_area_id laid; |
| 273 | gsm48_decode_lai2(lai, &laid); |
| 274 | printf("LU: mcc %s mnc %s lac %hd\n", |
| 275 | osmo_mcc_name(laid.plmn.mcc), osmo_mnc_name(laid.plmn.mnc, laid.plmn.mnc_3_digits), |
| 276 | laid.lac); |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 277 | |
Neels Hofmeyr | c04eb53 | 2016-03-04 12:38:43 +0100 | [diff] [blame] | 278 | struct tlv_parsed tp; |
| 279 | int parse_res; |
| 280 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 281 | len -= (const char *)&gh->data[0] - (const char *)gh; |
| 282 | parse_res = tlv_parse(&tp, &gsm48_mm_att_tlvdef, &gh->data[0], len, 0, 0); |
Neels Hofmeyr | c04eb53 | 2016-03-04 12:38:43 +0100 | [diff] [blame] | 283 | if (parse_res <= 0) { |
| 284 | printf("Error parsing Location Update Accept message: %d\n", parse_res); |
| 285 | return -1; |
| 286 | } |
| 287 | |
| 288 | if (TLVP_PRESENT(&tp, GSM48_IE_MOBILE_ID)) { |
| 289 | uint8_t type = TLVP_VAL(&tp, GSM48_IE_NAME_SHORT)[0] & 0x0f; |
| 290 | if (type == GSM_MI_TYPE_TMSI) |
| 291 | *sent_tmsi = 1; |
| 292 | else *sent_tmsi = 0; |
| 293 | } |
| 294 | return 0; |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 295 | } |
| 296 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 297 | void hnb_test_nas_rx_mm_info(struct gsm48_hdr *gh, int len) |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 298 | { |
| 299 | printf(" :) MM Info :)\n"); |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 300 | struct tlv_parsed *tp = parse_mm(gh, len); |
Neels Hofmeyr | d4598fa | 2016-03-09 01:37:40 +0100 | [diff] [blame] | 301 | if (!tp) |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 302 | return; |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 303 | |
Neels Hofmeyr | d4598fa | 2016-03-09 01:37:40 +0100 | [diff] [blame] | 304 | if (TLVP_PRESENT(tp, GSM48_IE_NAME_SHORT)) { |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 305 | char name[128] = {0}; |
| 306 | gsm_7bit_decode_n(name, 127, |
Neels Hofmeyr | d4598fa | 2016-03-09 01:37:40 +0100 | [diff] [blame] | 307 | TLVP_VAL(tp, GSM48_IE_NAME_SHORT)+1, |
| 308 | (TLVP_LEN(tp, GSM48_IE_NAME_SHORT)-1)*8/7); |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 309 | printf("Info: Short Network Name: %s\n", name); |
| 310 | } |
| 311 | |
Neels Hofmeyr | d4598fa | 2016-03-09 01:37:40 +0100 | [diff] [blame] | 312 | if (TLVP_PRESENT(tp, GSM48_IE_NAME_LONG)) { |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 313 | char name[128] = {0}; |
| 314 | gsm_7bit_decode_n(name, 127, |
Neels Hofmeyr | d4598fa | 2016-03-09 01:37:40 +0100 | [diff] [blame] | 315 | TLVP_VAL(tp, GSM48_IE_NAME_LONG)+1, |
| 316 | (TLVP_LEN(tp, GSM48_IE_NAME_LONG)-1)*8/7); |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 317 | printf("Info: Long Network Name: %s\n", name); |
| 318 | } |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 319 | } |
| 320 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 321 | static int hnb_test_nas_rx_auth_req(struct hnb_test *hnb, struct gsm48_hdr *gh, |
| 322 | int len) |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 323 | { |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 324 | struct gsm48_auth_req *ar; |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 325 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 326 | len -= (const char *)&gh->data[0] - (const char *)gh; |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 327 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 328 | if (len < sizeof(*ar)) { |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 329 | printf("GSM48 Auth Req does not fit.\n"); |
Martin Hauke | c593da5 | 2020-02-15 23:01:39 +0100 | [diff] [blame] | 330 | return -1; |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | printf(" :) Authentication Request :)\n"); |
| 334 | |
| 335 | ar = (struct gsm48_auth_req*) &gh->data[0]; |
| 336 | int seq = ar->key_seq; |
Neels Hofmeyr | 26779f8 | 2016-04-18 17:04:17 +0200 | [diff] [blame] | 337 | |
| 338 | /* Generate SRES from *HARDCODED* Ki for Iuh testing */ |
| 339 | struct osmo_auth_vector vec; |
| 340 | /* Ki 000102030405060708090a0b0c0d0e0f */ |
| 341 | struct osmo_sub_auth_data auth = { |
| 342 | .type = OSMO_AUTH_TYPE_GSM, |
| 343 | .algo = OSMO_AUTH_ALG_COMP128v1, |
| 344 | .u.gsm.ki = { |
| 345 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, |
| 346 | 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, |
| 347 | 0x0e, 0x0f |
| 348 | }, |
| 349 | }; |
| 350 | |
| 351 | memset(&vec, 0, sizeof(vec)); |
| 352 | osmo_auth_gen_vec(&vec, &auth, ar->rand); |
| 353 | |
| 354 | printf("seq %d rand %s", |
| 355 | seq, osmo_hexdump(ar->rand, sizeof(ar->rand))); |
| 356 | printf(" --> sres %s\n", |
| 357 | osmo_hexdump(vec.sres, 4)); |
| 358 | |
Neels Hofmeyr | c28ed37 | 2016-04-19 01:24:34 +0200 | [diff] [blame] | 359 | return hnb_test_tx_dt(hnb, gen_nas_auth_resp(vec.sres)); |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 360 | } |
| 361 | |
Neels Hofmeyr | bde4d3b | 2016-04-19 02:38:16 +0200 | [diff] [blame] | 362 | void hnb_test_tx_iu_release_req(struct hnb_test *hnb) |
| 363 | { |
| 364 | RANAP_Cause_t cause = { |
| 365 | .present = RANAP_Cause_PR_radioNetwork, |
| 366 | .choice.transmissionNetwork = RANAP_CauseRadioNetwork_release_due_to_UE_generated_signalling_connection_release, |
| 367 | }; |
| 368 | hnb_test_tx_dt(hnb, ranap_new_msg_iu_rel_req(&cause)); |
| 369 | } |
| 370 | |
| 371 | void hnb_test_tx_iu_release_compl(struct hnb_test *hnb) |
| 372 | { |
| 373 | hnb_test_tx_dt(hnb, ranap_new_msg_iu_rel_compl()); |
| 374 | } |
| 375 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 376 | static int hnb_test_nas_rx_mm(struct hnb_test *hnb, struct gsm48_hdr *gh, int len) |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 377 | { |
| 378 | struct hnbtest_chan *chan; |
| 379 | |
| 380 | chan = hnb->cs.chan; |
| 381 | if (!chan) { |
| 382 | printf("hnb_test_nas_rx_mm(): No CS channel established yet.\n"); |
| 383 | return -1; |
| 384 | } |
| 385 | |
| 386 | OSMO_ASSERT(!chan->is_ps); |
| 387 | |
Neels Hofmeyr | 7c28f6f | 2016-04-05 11:49:53 +0200 | [diff] [blame] | 388 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
Neels Hofmeyr | c04eb53 | 2016-03-04 12:38:43 +0100 | [diff] [blame] | 389 | int sent_tmsi; |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 390 | |
| 391 | switch (msg_type) { |
| 392 | case GSM48_MT_MM_ID_REQ: |
Neels Hofmeyr | c28ed37 | 2016-04-19 01:24:34 +0200 | [diff] [blame] | 393 | return hnb_test_tx_dt(hnb, gen_nas_id_resp()); |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 394 | |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 395 | case GSM48_MT_MM_LOC_UPD_ACCEPT: |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 396 | if (hnb_test_nas_rx_lu_accept(gh, len, &sent_tmsi)) |
Neels Hofmeyr | c04eb53 | 2016-03-04 12:38:43 +0100 | [diff] [blame] | 397 | return -1; |
| 398 | if (sent_tmsi) |
Neels Hofmeyr | c28ed37 | 2016-04-19 01:24:34 +0200 | [diff] [blame] | 399 | return hnb_test_tx_dt(hnb, gen_nas_tmsi_realloc_compl()); |
Neels Hofmeyr | c04eb53 | 2016-03-04 12:38:43 +0100 | [diff] [blame] | 400 | else |
| 401 | return 0; |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 402 | |
Neels Hofmeyr | 5dbb7b2 | 2016-03-09 01:38:13 +0100 | [diff] [blame] | 403 | case GSM48_MT_MM_LOC_UPD_REJECT: |
| 404 | printf("Received Location Update Reject\n"); |
| 405 | return 0; |
| 406 | |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 407 | case GSM48_MT_MM_INFO: |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 408 | hnb_test_nas_rx_mm_info(gh, len); |
Neels Hofmeyr | bde4d3b | 2016-04-19 02:38:16 +0200 | [diff] [blame] | 409 | hnb_test_tx_iu_release_req(hnb); |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 410 | return 0; |
| 411 | |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 412 | case GSM48_MT_MM_AUTH_REQ: |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 413 | return hnb_test_nas_rx_auth_req(hnb, gh, len); |
Neels Hofmeyr | 3588810 | 2016-03-09 01:39:56 +0100 | [diff] [blame] | 414 | |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 415 | default: |
Neels Hofmeyr | ae93712 | 2016-02-29 09:32:00 +0100 | [diff] [blame] | 416 | printf("04.08 message type not handled by hnb-test: 0x%x\n", |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 417 | msg_type); |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | } |
| 422 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 423 | void hnb_test_nas_rx_dtap(struct hnb_test *hnb, void *data, int len) |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 424 | { |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 425 | int rc; |
| 426 | printf("got %d bytes: %s\n", len, osmo_hexdump(data, len)); |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 427 | |
| 428 | // nas_pdu == '05 08 12' ==> IMEI Identity request |
| 429 | // '05 04 0d' ==> LU reject |
| 430 | |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 431 | struct gsm48_hdr *gh = data; |
| 432 | if (len < sizeof(*gh)) { |
| 433 | printf("hnb_test_nas_rx_dtap(): NAS PDU is too short: %d. Ignoring.\n", |
| 434 | len); |
| 435 | return; |
Neels Hofmeyr | 8c2b4ec | 2016-04-04 19:27:53 +0200 | [diff] [blame] | 436 | } |
Neels Hofmeyr | 7c28f6f | 2016-04-05 11:49:53 +0200 | [diff] [blame] | 437 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 438 | |
| 439 | switch (pdisc) { |
| 440 | case GSM48_PDISC_MM: |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 441 | rc = hnb_test_nas_rx_mm(hnb, gh, len); |
| 442 | if (rc != 0) |
| 443 | printf("Error receiving MM message: %d\n", rc); |
| 444 | return; |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 445 | default: |
| 446 | printf("04.08 discriminator not handled by hnb-test: %d\n", |
| 447 | pdisc); |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 448 | return; |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 449 | } |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 450 | } |
| 451 | |
Neels Hofmeyr | 4a0a69a | 2016-04-19 00:06:28 +0200 | [diff] [blame] | 452 | void hnb_test_rx_secmode_cmd(struct hnb_test *hnb, long ip_alg) |
| 453 | { |
| 454 | printf(" :) Security Mode Command :)\n"); |
| 455 | /* not caring about encryption yet, just pass 0 for No Encryption. */ |
| 456 | hnb_test_tx_dt(hnb, ranap_new_msg_sec_mod_compl(ip_alg, 0)); |
| 457 | } |
| 458 | |
Neels Hofmeyr | bde4d3b | 2016-04-19 02:38:16 +0200 | [diff] [blame] | 459 | void hnb_test_rx_iu_release(struct hnb_test *hnb) |
| 460 | { |
| 461 | hnb_test_tx_iu_release_compl(hnb); |
| 462 | } |
| 463 | |
Neels Hofmeyr | 5ad72b9 | 2016-04-19 18:09:05 +0200 | [diff] [blame] | 464 | void hnb_test_rx_paging(struct hnb_test *hnb, const char *imsi) |
| 465 | { |
| 466 | printf(" :) Paging Request for %s :)\n", imsi); |
| 467 | /* TODO reply */ |
| 468 | } |
| 469 | |
Daniel Willmann | 479cb30 | 2015-12-09 17:54:59 +0100 | [diff] [blame] | 470 | int hnb_test_hnbap_rx(struct hnb_test *hnb, struct msgb *msg) |
| 471 | { |
| 472 | HNBAP_PDU_t _pdu, *pdu = &_pdu; |
| 473 | asn_dec_rval_t dec_ret; |
| 474 | int rc; |
| 475 | |
| 476 | memset(pdu, 0, sizeof(*pdu)); |
| 477 | dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu, |
| 478 | msg->data, msgb_length(msg), 0, 0); |
| 479 | if (dec_ret.code != RC_OK) { |
| 480 | LOGP(DMAIN, LOGL_ERROR, "Error in ASN.1 decode\n"); |
| 481 | return rc; |
| 482 | } |
| 483 | |
| 484 | if (pdu->present != HNBAP_PDU_PR_successfulOutcome) { |
| 485 | printf("Unexpected HNBAP message received\n"); |
| 486 | } |
| 487 | |
| 488 | switch (pdu->choice.successfulOutcome.procedureCode) { |
| 489 | case ProcedureCode_id_HNBRegister: |
| 490 | /* Get HNB id and send UE Register request */ |
| 491 | rc = hnb_test_rx_hnb_register_acc(hnb, &pdu->choice.successfulOutcome.value); |
| 492 | break; |
| 493 | case ProcedureCode_id_UERegister: |
Daniel Willmann | a7b0240 | 2015-12-09 19:05:09 +0100 | [diff] [blame] | 494 | rc = hnb_test_rx_ue_register_acc(hnb, &pdu->choice.successfulOutcome.value); |
Daniel Willmann | 479cb30 | 2015-12-09 17:54:59 +0100 | [diff] [blame] | 495 | break; |
| 496 | default: |
| 497 | break; |
| 498 | } |
| 499 | |
| 500 | return rc; |
| 501 | } |
| 502 | |
Neels Hofmeyr | b984f36 | 2016-02-18 01:18:20 +0100 | [diff] [blame] | 503 | extern void direct_transfer_nas_pdu_print(ANY_t *in); |
| 504 | |
Neels Hofmeyr | 0968a58 | 2016-01-11 15:19:38 +0100 | [diff] [blame] | 505 | int hnb_test_rua_rx(struct hnb_test *hnb, struct msgb *msg) |
| 506 | { |
| 507 | RUA_RUA_PDU_t _pdu, *pdu = &_pdu; |
| 508 | asn_dec_rval_t dec_ret; |
| 509 | int rc; |
| 510 | |
| 511 | memset(pdu, 0, sizeof(*pdu)); |
| 512 | dec_ret = aper_decode(NULL, &asn_DEF_RUA_RUA_PDU, (void **) &pdu, |
| 513 | msg->data, msgb_length(msg), 0, 0); |
| 514 | if (dec_ret.code != RC_OK) { |
| 515 | LOGP(DMAIN, LOGL_ERROR, "Error in ASN.1 decode\n"); |
| 516 | return rc; |
| 517 | } |
| 518 | |
| 519 | switch (pdu->present) { |
| 520 | case RUA_RUA_PDU_PR_successfulOutcome: |
| 521 | printf("RUA_RUA_PDU_PR_successfulOutcome\n"); |
| 522 | break; |
| 523 | case RUA_RUA_PDU_PR_initiatingMessage: |
| 524 | printf("RUA_RUA_PDU_PR_initiatingMessage\n"); |
| 525 | break; |
| 526 | case RUA_RUA_PDU_PR_NOTHING: |
| 527 | printf("RUA_RUA_PDU_PR_NOTHING\n"); |
| 528 | break; |
| 529 | case RUA_RUA_PDU_PR_unsuccessfulOutcome: |
| 530 | printf("RUA_RUA_PDU_PR_unsuccessfulOutcome\n"); |
| 531 | break; |
| 532 | default: |
| 533 | printf("Unexpected RUA message received\n"); |
| 534 | break; |
| 535 | } |
| 536 | |
| 537 | switch (pdu->choice.successfulOutcome.procedureCode) { |
| 538 | case RUA_ProcedureCode_id_ConnectionlessTransfer: |
| 539 | printf("RUA rx Connectionless Transfer\n"); |
Neels Hofmeyr | 5ad72b9 | 2016-04-19 18:09:05 +0200 | [diff] [blame] | 540 | hnb_test_rua_cl_handle(hnb, &pdu->choice.successfulOutcome.value); |
Neels Hofmeyr | 0968a58 | 2016-01-11 15:19:38 +0100 | [diff] [blame] | 541 | break; |
| 542 | case RUA_ProcedureCode_id_Connect: |
| 543 | printf("RUA rx Connect\n"); |
| 544 | break; |
| 545 | case RUA_ProcedureCode_id_DirectTransfer: |
| 546 | printf("RUA rx DirectTransfer\n"); |
Neels Hofmeyr | 4470f93 | 2016-04-19 00:13:53 +0200 | [diff] [blame] | 547 | hnb_test_rua_dt_handle(hnb, &pdu->choice.successfulOutcome.value); |
Neels Hofmeyr | 0968a58 | 2016-01-11 15:19:38 +0100 | [diff] [blame] | 548 | break; |
| 549 | case RUA_ProcedureCode_id_Disconnect: |
| 550 | printf("RUA rx Disconnect\n"); |
| 551 | break; |
| 552 | case RUA_ProcedureCode_id_ErrorIndication: |
| 553 | printf("RUA rx ErrorIndication\n"); |
| 554 | break; |
| 555 | case RUA_ProcedureCode_id_privateMessage: |
| 556 | printf("RUA rx privateMessage\n"); |
| 557 | break; |
| 558 | default: |
| 559 | printf("RUA rx unknown message\n"); |
| 560 | break; |
| 561 | } |
| 562 | |
| 563 | return rc; |
| 564 | } |
| 565 | |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 566 | static int hnb_read_cb(struct osmo_fd *fd) |
| 567 | { |
| 568 | struct hnb_test *hnb_test = fd->data; |
| 569 | struct sctp_sndrcvinfo sinfo; |
| 570 | struct msgb *msg = msgb_alloc(IUH_MSGB_SIZE, "Iuh rx"); |
| 571 | int flags = 0; |
| 572 | int rc; |
| 573 | |
| 574 | if (!msg) |
| 575 | return -ENOMEM; |
| 576 | |
| 577 | rc = sctp_recvmsg(fd->fd, msgb_data(msg), msgb_tailroom(msg), |
| 578 | NULL, NULL, &sinfo, &flags); |
| 579 | if (rc < 0) { |
| 580 | LOGP(DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n"); |
| 581 | /* FIXME: clean up after disappeared HNB */ |
Daniel Willmann | 6637a28 | 2015-12-17 14:47:51 +0100 | [diff] [blame] | 582 | close(fd->fd); |
| 583 | osmo_fd_unregister(fd); |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 584 | return rc; |
Daniel Willmann | 6637a28 | 2015-12-17 14:47:51 +0100 | [diff] [blame] | 585 | } else if (rc == 0) { |
| 586 | LOGP(DMAIN, LOGL_INFO, "Connection to HNB closed\n"); |
| 587 | close(fd->fd); |
| 588 | osmo_fd_unregister(fd); |
| 589 | fd->fd = -1; |
| 590 | |
| 591 | return -1; |
| 592 | } else { |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 593 | msgb_put(msg, rc); |
Daniel Willmann | 6637a28 | 2015-12-17 14:47:51 +0100 | [diff] [blame] | 594 | } |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 595 | |
| 596 | if (flags & MSG_NOTIFICATION) { |
Daniel Willmann | 3279780 | 2015-12-17 12:53:05 +0100 | [diff] [blame] | 597 | LOGP(DMAIN, LOGL_DEBUG, "Ignoring SCTP notification\n"); |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 598 | msgb_free(msg); |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | sinfo.sinfo_ppid = ntohl(sinfo.sinfo_ppid); |
| 603 | |
| 604 | switch (sinfo.sinfo_ppid) { |
| 605 | case IUH_PPI_HNBAP: |
Neels Hofmeyr | 0968a58 | 2016-01-11 15:19:38 +0100 | [diff] [blame] | 606 | printf("HNBAP message received\n"); |
Daniel Willmann | 479cb30 | 2015-12-09 17:54:59 +0100 | [diff] [blame] | 607 | rc = hnb_test_hnbap_rx(hnb_test, msg); |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 608 | break; |
| 609 | case IUH_PPI_RUA: |
Neels Hofmeyr | 0968a58 | 2016-01-11 15:19:38 +0100 | [diff] [blame] | 610 | printf("RUA message received\n"); |
| 611 | rc = hnb_test_rua_rx(hnb_test, msg); |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 612 | break; |
| 613 | case IUH_PPI_SABP: |
| 614 | case IUH_PPI_RNA: |
| 615 | case IUH_PPI_PUA: |
| 616 | LOGP(DMAIN, LOGL_ERROR, "Unimplemented SCTP PPID=%u received\n", |
| 617 | sinfo.sinfo_ppid); |
| 618 | rc = 0; |
| 619 | break; |
| 620 | default: |
| 621 | LOGP(DMAIN, LOGL_ERROR, "Unknown SCTP PPID=%u received\n", |
| 622 | sinfo.sinfo_ppid); |
| 623 | rc = 0; |
| 624 | break; |
| 625 | } |
| 626 | |
| 627 | msgb_free(msg); |
| 628 | return rc; |
| 629 | } |
| 630 | |
| 631 | static int hnb_write_cb(struct osmo_fd *fd, struct msgb *msg) |
| 632 | { |
Pau Espin Pedrol | 89f4c80 | 2021-01-14 11:13:46 +0100 | [diff] [blame] | 633 | /* struct hnb_test *ctx = fd->data; */ |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 634 | struct sctp_sndrcvinfo sinfo = { |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 635 | .sinfo_ppid = htonl(msgb_sctp_ppid(msg)), |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 636 | .sinfo_stream = 0, |
| 637 | }; |
| 638 | int rc; |
| 639 | |
Neels Hofmeyr | e25faa8 | 2016-03-04 02:49:52 +0100 | [diff] [blame] | 640 | printf("Sending: %s\n", osmo_hexdump(msgb_data(msg), msgb_length(msg))); |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 641 | rc = sctp_send(fd->fd, msgb_data(msg), msgb_length(msg), |
| 642 | &sinfo, 0); |
| 643 | /* we don't need to msgb_free(), write_queue does this for us */ |
| 644 | return rc; |
| 645 | } |
| 646 | |
Daniel Willmann | 4aeef6c | 2015-12-03 17:02:13 +0100 | [diff] [blame] | 647 | static void hnb_send_register_req(struct hnb_test *hnb_test) |
| 648 | { |
Daniel Willmann | a1e202e | 2015-12-07 17:21:07 +0100 | [diff] [blame] | 649 | HNBRegisterRequest_t request_out; |
Daniel Willmann | 4aeef6c | 2015-12-03 17:02:13 +0100 | [diff] [blame] | 650 | struct msgb *msg; |
| 651 | int rc; |
Daniel Willmann | a1e202e | 2015-12-07 17:21:07 +0100 | [diff] [blame] | 652 | uint16_t lac, sac; |
| 653 | uint8_t rac; |
| 654 | uint32_t cid; |
| 655 | uint8_t plmn[] = {0x09, 0xf1, 0x99}; |
| 656 | char identity[50] = "ATestHNB@"; |
Daniel Willmann | 4aeef6c | 2015-12-03 17:02:13 +0100 | [diff] [blame] | 657 | |
Daniel Willmann | a1e202e | 2015-12-07 17:21:07 +0100 | [diff] [blame] | 658 | HNBRegisterRequestIEs_t request; |
| 659 | memset(&request, 0, sizeof(request)); |
Daniel Willmann | 4aeef6c | 2015-12-03 17:02:13 +0100 | [diff] [blame] | 660 | |
Daniel Willmann | a1e202e | 2015-12-07 17:21:07 +0100 | [diff] [blame] | 661 | lac = 0xc0fe; |
| 662 | sac = 0xabab; |
| 663 | rac = 0x42; |
Daniel Willmann | d6a45b4 | 2015-12-08 13:55:17 +0100 | [diff] [blame] | 664 | cid = 0xadceaab; |
Daniel Willmann | 4aeef6c | 2015-12-03 17:02:13 +0100 | [diff] [blame] | 665 | |
Daniel Willmann | a1e202e | 2015-12-07 17:21:07 +0100 | [diff] [blame] | 666 | asn1_u16_to_str(&request.lac, &lac, lac); |
| 667 | asn1_u16_to_str(&request.sac, &sac, sac); |
| 668 | asn1_u8_to_str(&request.rac, &rac, rac); |
Daniel Willmann | d6a45b4 | 2015-12-08 13:55:17 +0100 | [diff] [blame] | 669 | asn1_u28_to_bitstring(&request.cellIdentity, &cid, cid); |
Daniel Willmann | a1e202e | 2015-12-07 17:21:07 +0100 | [diff] [blame] | 670 | |
| 671 | request.hnB_Identity.hNB_Identity_Info.buf = identity; |
| 672 | request.hnB_Identity.hNB_Identity_Info.size = strlen(identity); |
| 673 | |
| 674 | request.plmNidentity.buf = plmn; |
| 675 | request.plmNidentity.size = 3; |
| 676 | |
| 677 | |
| 678 | |
| 679 | memset(&request_out, 0, sizeof(request_out)); |
| 680 | rc = hnbap_encode_hnbregisterrequesties(&request_out, &request); |
| 681 | if (rc < 0) { |
| 682 | printf("Could not encode HNB register request IEs\n"); |
| 683 | } |
| 684 | |
| 685 | msg = hnbap_generate_initiating_message(ProcedureCode_id_HNBRegister, |
| 686 | Criticality_reject, |
| 687 | &asn_DEF_HNBRegisterRequest, |
| 688 | &request_out); |
| 689 | |
Daniel Willmann | 4aeef6c | 2015-12-03 17:02:13 +0100 | [diff] [blame] | 690 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 691 | msgb_sctp_ppid(msg) = IUH_PPI_HNBAP; |
| 692 | |
| 693 | osmo_wqueue_enqueue(&hnb_test->wqueue, msg); |
| 694 | } |
| 695 | |
| 696 | static void hnb_send_deregister_req(struct hnb_test *hnb_test) |
| 697 | { |
| 698 | struct msgb *msg; |
| 699 | int rc; |
| 700 | |
| 701 | HNBDe_RegisterIEs_t request; |
| 702 | memset(&request, 0, sizeof(request)); |
| 703 | |
| 704 | request.cause.present = Cause_PR_misc; |
| 705 | request.cause.choice.misc = CauseMisc_o_and_m_intervention; |
| 706 | |
| 707 | HNBDe_Register_t request_out; |
| 708 | memset(&request_out, 0, sizeof(request_out)); |
| 709 | rc = hnbap_encode_hnbde_registeries(&request_out, &request); |
| 710 | if (rc < 0) { |
| 711 | printf("Could not encode HNB deregister request IEs\n"); |
| 712 | } |
| 713 | |
| 714 | msg = hnbap_generate_initiating_message(ProcedureCode_id_HNBDe_Register, |
| 715 | Criticality_reject, |
| 716 | &asn_DEF_HNBDe_Register, |
| 717 | &request_out); |
| 718 | |
| 719 | msgb_sctp_ppid(msg) = IUH_PPI_HNBAP; |
Daniel Willmann | 4aeef6c | 2015-12-03 17:02:13 +0100 | [diff] [blame] | 720 | |
| 721 | osmo_wqueue_enqueue(&hnb_test->wqueue, msg); |
| 722 | } |
| 723 | |
| 724 | |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 725 | static const struct log_info_cat log_cat[] = { |
| 726 | [DMAIN] = { |
Daniel Willmann | 3279780 | 2015-12-17 12:53:05 +0100 | [diff] [blame] | 727 | .name = "DMAIN", .loglevel = LOGL_INFO, .enabled = 1, |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 728 | .color = "", |
| 729 | .description = "Main program", |
| 730 | }, |
Daniel Willmann | 3279780 | 2015-12-17 12:53:05 +0100 | [diff] [blame] | 731 | [DHNBAP] = { |
| 732 | .name = "DHNBAP", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 733 | .color = "", |
| 734 | .description = "Home Node B Application Part", |
| 735 | }, |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 736 | }; |
| 737 | |
| 738 | static const struct log_info hnb_test_log_info = { |
| 739 | .cat = log_cat, |
| 740 | .num_cat = ARRAY_SIZE(log_cat), |
| 741 | }; |
| 742 | |
| 743 | static struct vty_app_info vty_info = { |
| 744 | .name = "OsmoHNB-Test", |
| 745 | .version = "0", |
| 746 | }; |
| 747 | |
Daniel Willmann | 4abdee0 | 2015-12-09 17:57:32 +0100 | [diff] [blame] | 748 | static int sctp_sock_init(int fd) |
| 749 | { |
| 750 | struct sctp_event_subscribe event; |
| 751 | int rc; |
| 752 | |
| 753 | /* subscribe for all events */ |
| 754 | memset((uint8_t *)&event, 1, sizeof(event)); |
| 755 | rc = setsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS, |
| 756 | &event, sizeof(event)); |
| 757 | |
| 758 | return rc; |
| 759 | } |
| 760 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 761 | #define HNBAP_STR "HNBAP related commands\n" |
| 762 | #define HNB_STR "HomeNodeB commands\n" |
| 763 | #define UE_STR "User Equipment commands\n" |
| 764 | #define RANAP_STR "RANAP related commands\n" |
| 765 | #define CSPS_STR "Circuit Switched\n" "Packet Switched\n" |
| 766 | |
| 767 | DEFUN(hnb_register, hnb_register_cmd, |
| 768 | "hnbap hnb register", HNBAP_STR HNB_STR "Send HNB-REGISTER REQUEST") |
| 769 | { |
| 770 | hnb_send_register_req(&g_hnb_test); |
| 771 | |
| 772 | return CMD_SUCCESS; |
| 773 | } |
| 774 | |
| 775 | DEFUN(hnb_deregister, hnb_deregister_cmd, |
| 776 | "hnbap hnb deregister", HNBAP_STR HNB_STR "Send HNB-DEREGISTER REQUEST") |
| 777 | { |
| 778 | hnb_send_deregister_req(&g_hnb_test); |
| 779 | |
| 780 | return CMD_SUCCESS; |
| 781 | } |
| 782 | |
| 783 | DEFUN(ue_register, ue_register_cmd, |
| 784 | "hnbap ue register IMSI", HNBAP_STR UE_STR "Send UE-REGISTER REQUEST") |
| 785 | { |
| 786 | hnb_test_ue_register_tx(&g_hnb_test, argv[0]); |
| 787 | |
| 788 | return CMD_SUCCESS; |
| 789 | } |
| 790 | |
| 791 | DEFUN(asn_dbg, asn_dbg_cmd, |
| 792 | "asn-debug (1|0)", "Enable or disabel libasn1c debugging") |
| 793 | { |
| 794 | asn_debug = atoi(argv[0]); |
| 795 | |
| 796 | return CMD_SUCCESS; |
| 797 | } |
| 798 | |
| 799 | DEFUN(ranap_reset, ranap_reset_cmd, |
| 800 | "ranap reset (cs|ps)", RANAP_STR "Send RANAP RESET\n" CSPS_STR) |
| 801 | { |
| 802 | int is_ps = 0; |
| 803 | struct msgb *msg, *rua; |
| 804 | |
| 805 | RANAP_Cause_t cause = { |
| 806 | .present = RANAP_Cause_PR_transmissionNetwork, |
| 807 | .choice.transmissionNetwork = RANAP_CauseTransmissionNetwork_signalling_transport_resource_failure, |
| 808 | }; |
| 809 | |
| 810 | if (!strcmp(argv[0], "ps")) |
| 811 | is_ps = 1; |
| 812 | |
| 813 | msg = ranap_new_msg_reset(is_ps, &cause); |
| 814 | rua = rua_new_udt(msg); |
| 815 | //msgb_free(msg); |
| 816 | osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua); |
| 817 | |
| 818 | return CMD_SUCCESS; |
| 819 | } |
| 820 | |
| 821 | |
| 822 | enum my_vty_nodes { |
| 823 | CHAN_NODE = _LAST_OSMOVTY_NODE, |
| 824 | }; |
| 825 | |
| 826 | static struct cmd_node chan_node = { |
| 827 | CHAN_NODE, |
| 828 | "%s(chan)> ", |
| 829 | 1, |
| 830 | }; |
| 831 | |
| 832 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 833 | static struct msgb *gen_initue_lu(int is_ps, uint32_t conn_id, const char *imsi) |
| 834 | { |
Neels Hofmeyr | 5c1cc8c | 2016-02-29 09:28:48 +0100 | [diff] [blame] | 835 | uint8_t lu[] = { GSM48_PDISC_MM, GSM48_MT_MM_LOC_UPD_REQUEST, |
| 836 | 0x70, 0x62, 0xf2, 0x30, 0xff, 0xf3, 0x57, |
Neels Hofmeyr | 3282870 | 2016-01-14 13:06:47 +0100 | [diff] [blame] | 837 | /* len, IMSI/type, IMSI-------------------------------- */ |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 838 | 0x08, 0x29, 0x26, 0x24, 0x10, 0x32, 0x54, 0x76, 0x98, |
| 839 | 0x33, 0x03, 0x57, 0x18 , 0xb2 }; |
| 840 | uint8_t plmn_id[] = { 0x09, 0x01, 0x99 }; |
| 841 | RANAP_GlobalRNC_ID_t rnc_id = { |
| 842 | .rNC_ID = 23, |
| 843 | .pLMNidentity.buf = plmn_id, |
| 844 | .pLMNidentity.size = sizeof(plmn_id), |
| 845 | }; |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 846 | |
| 847 | /* FIXME: patch imsi */ |
Neels Hofmeyr | 7b81128 | 2016-01-14 13:05:24 +0100 | [diff] [blame] | 848 | /* Note: the Mobile Identitiy IE's IMSI data has the identity type and |
| 849 | * an even/odd indicator bit encoded in the first octet. So the first |
| 850 | * octet looks like this: |
| 851 | * |
| 852 | * 8 7 6 5 | 4 | 3 2 1 |
| 853 | * IMSI-digit | even/odd | type |
| 854 | * |
| 855 | * followed by the remaining IMSI digits. |
| 856 | * If digit count is even (bit 4 == 0), that first high-nibble is 0xf. |
| 857 | * (derived from Iu pcap Location Update Request msg and TS 25.413) |
| 858 | * |
| 859 | * TODO I'm only 90% sure about this |
| 860 | */ |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 861 | |
Neels Hofmeyr | 6a62e54 | 2016-01-15 03:07:45 +0100 | [diff] [blame] | 862 | return ranap_new_msg_initial_ue(conn_id, is_ps, &rnc_id, lu, sizeof(lu)); |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | DEFUN(chan, chan_cmd, |
| 866 | "channel (cs|ps) lu imsi IMSI", |
| 867 | "Open a new Signalling Connection\n" |
| 868 | "To Circuit-Switched CN\n" |
| 869 | "To Packet-Switched CN\n" |
| 870 | "Performing a Location Update\n" |
| 871 | ) |
| 872 | { |
| 873 | struct hnbtest_chan *chan; |
| 874 | struct msgb *msg, *rua; |
Daniel Willmann | 8592716 | 2016-01-14 15:36:49 +0100 | [diff] [blame] | 875 | static uint16_t conn_id = 42; |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 876 | |
| 877 | chan = talloc_zero(tall_hnb_ctx, struct hnbtest_chan); |
| 878 | if (!strcmp(argv[0], "ps")) |
| 879 | chan->is_ps = 1; |
| 880 | chan->imsi = talloc_strdup(chan, argv[1]); |
Daniel Willmann | 8592716 | 2016-01-14 15:36:49 +0100 | [diff] [blame] | 881 | chan->conn_id = conn_id; |
| 882 | conn_id++; |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 883 | |
| 884 | msg = gen_initue_lu(chan->is_ps, chan->conn_id, chan->imsi); |
| 885 | rua = rua_new_conn(chan->is_ps, chan->conn_id, msg); |
| 886 | |
| 887 | osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua); |
| 888 | |
| 889 | vty->index = chan; |
| 890 | vty->node = CHAN_NODE; |
| 891 | |
Neels Hofmeyr | 860a129 | 2016-02-18 23:03:15 +0100 | [diff] [blame] | 892 | if (!chan->is_ps) |
| 893 | g_hnb_test.cs.chan = chan; |
| 894 | |
| 895 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 896 | return CMD_SUCCESS; |
| 897 | } |
| 898 | |
| 899 | static void hnbtest_vty_init(void) |
| 900 | { |
| 901 | install_element_ve(&asn_dbg_cmd); |
| 902 | install_element_ve(&hnb_register_cmd); |
| 903 | install_element_ve(&hnb_deregister_cmd); |
| 904 | install_element_ve(&ue_register_cmd); |
| 905 | install_element_ve(&ranap_reset_cmd); |
| 906 | install_element_ve(&chan_cmd); |
| 907 | |
| 908 | install_node(&chan_node, NULL); |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 909 | } |
| 910 | |
Daniel Willmann | 141a0ba | 2015-12-17 18:03:52 +0100 | [diff] [blame] | 911 | static void handle_options(int argc, char **argv) |
| 912 | { |
| 913 | while (1) { |
| 914 | int idx = 0, c; |
| 915 | static const struct option long_options[] = { |
| 916 | { "ues", 1, 0, 'u' }, |
Neels Hofmeyr | 5f9be1e | 2016-02-29 13:33:44 +0100 | [diff] [blame] | 917 | { "gw-addr", 1, 0, 'g' }, |
Daniel Willmann | 141a0ba | 2015-12-17 18:03:52 +0100 | [diff] [blame] | 918 | { 0, 0, 0, 0 }, |
| 919 | }; |
| 920 | |
Neels Hofmeyr | 5f9be1e | 2016-02-29 13:33:44 +0100 | [diff] [blame] | 921 | c = getopt_long(argc, argv, "u:g:", long_options, &idx); |
Daniel Willmann | 141a0ba | 2015-12-17 18:03:52 +0100 | [diff] [blame] | 922 | |
| 923 | if (c == -1) |
| 924 | break; |
| 925 | |
| 926 | switch (c) { |
| 927 | case 'u': |
| 928 | g_hnb_test.ues = atoi(optarg); |
| 929 | break; |
Neels Hofmeyr | 5f9be1e | 2016-02-29 13:33:44 +0100 | [diff] [blame] | 930 | case 'g': |
| 931 | g_hnb_test.gw_addr = optarg; |
| 932 | break; |
Daniel Willmann | 141a0ba | 2015-12-17 18:03:52 +0100 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | } |
| 936 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 937 | int main(int argc, char **argv) |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 938 | { |
| 939 | int rc; |
| 940 | |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 941 | test_common_init(); |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 942 | |
Harald Welte | 87ffeb9 | 2015-12-25 15:34:22 +0100 | [diff] [blame] | 943 | tall_hnb_ctx = talloc_named_const(NULL, 0, "hnb_context"); |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 944 | |
| 945 | vty_init(&vty_info); |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 946 | hnbtest_vty_init(); |
| 947 | |
Neels Hofmeyr | a0d2147 | 2016-02-24 20:50:31 +0100 | [diff] [blame] | 948 | rc = telnet_init_dynif(NULL, NULL, vty_get_bind_addr(), 2324); |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 949 | if (rc < 0) { |
| 950 | perror("Error binding VTY port"); |
| 951 | exit(1); |
| 952 | } |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 953 | |
Daniel Willmann | 141a0ba | 2015-12-17 18:03:52 +0100 | [diff] [blame] | 954 | handle_options(argc, argv); |
| 955 | |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 956 | osmo_wqueue_init(&g_hnb_test.wqueue, 16); |
| 957 | g_hnb_test.wqueue.bfd.data = &g_hnb_test; |
| 958 | g_hnb_test.wqueue.read_cb = hnb_read_cb; |
| 959 | g_hnb_test.wqueue.write_cb = hnb_write_cb; |
| 960 | |
| 961 | rc = osmo_sock_init_ofd(&g_hnb_test.wqueue.bfd, AF_INET, SOCK_STREAM, |
Neels Hofmeyr | 5f9be1e | 2016-02-29 13:33:44 +0100 | [diff] [blame] | 962 | IPPROTO_SCTP, g_hnb_test.gw_addr, |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 963 | g_hnb_test.gw_port, OSMO_SOCK_F_CONNECT); |
| 964 | if (rc < 0) { |
| 965 | perror("Error connecting to Iuh port"); |
| 966 | exit(1); |
| 967 | } |
Daniel Willmann | 4abdee0 | 2015-12-09 17:57:32 +0100 | [diff] [blame] | 968 | sctp_sock_init(g_hnb_test.wqueue.bfd.fd); |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 969 | |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 970 | #if 0 |
| 971 | /* some hard-coded message generation. Doesn't make sense from |
| 972 | * a protocol point of view but enables to look at the encoded |
| 973 | * results in wireshark for manual verification */ |
| 974 | { |
| 975 | struct msgb *msg, *rua; |
| 976 | const uint8_t nas[] = { 0, 1, 2, 3 }; |
| 977 | const uint8_t ik[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; |
| 978 | |
| 979 | msg = ranap_new_msg_dt(0, nas, sizeof(nas)); |
| 980 | rua = rua_new_udt(msg); |
| 981 | osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua); |
| 982 | |
Daniel Willmann | f44d12c | 2016-04-20 10:16:37 +0200 | [diff] [blame] | 983 | msg = ranap_new_msg_sec_mod_cmd(ik, ik, RANAP_KeyStatus_new); |
Harald Welte | c385122 | 2015-12-24 15:41:21 +0100 | [diff] [blame] | 984 | rua = rua_new_udt(msg); |
| 985 | osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua); |
| 986 | |
| 987 | msg = ranap_new_msg_iu_rel_cmd() |
| 988 | rua = rua_new_udt(msg); |
| 989 | osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua); |
| 990 | |
| 991 | msg = ranap_new_msg_paging_cmd("901990123456789", NULL, 0, 0); |
| 992 | rua = rua_new_udt(msg); |
| 993 | osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua); |
| 994 | |
| 995 | msg = ranap_new_msg_rab_assign_voice(1, 0x01020304, 0x1020); |
| 996 | rua = rua_new_udt(msg); |
| 997 | osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua); |
| 998 | |
| 999 | msg = ranap_new_msg_rab_assign_data(2, 0x01020304, 0x11223344); |
| 1000 | rua = rua_new_udt(msg); |
| 1001 | osmo_wqueue_enqueue(&g_hnb_test.wqueue, rua); |
| 1002 | } |
| 1003 | #endif |
Daniel Willmann | 4aeef6c | 2015-12-03 17:02:13 +0100 | [diff] [blame] | 1004 | |
Daniel Willmann | 97374c0 | 2015-12-03 09:37:58 +0100 | [diff] [blame] | 1005 | while (1) { |
| 1006 | rc = osmo_select_main(0); |
| 1007 | if (rc < 0) |
| 1008 | exit(3); |
| 1009 | } |
| 1010 | |
| 1011 | /* not reached */ |
| 1012 | exit(0); |
| 1013 | } |