Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1 | /* test routines for gbproxy |
| 2 | * send NS messages to the gbproxy and dumps what happens |
| 3 | * (C) 2013 by sysmocom s.f.m.c. GmbH |
| 4 | * Author: Jacob Erlbeck <jerlbeck@sysmocom.de> |
| 5 | */ |
| 6 | |
| 7 | #undef _GNU_SOURCE |
| 8 | #define _GNU_SOURCE |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <stdint.h> |
| 13 | #include <string.h> |
| 14 | #include <getopt.h> |
| 15 | #include <dlfcn.h> |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 16 | #include <time.h> |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 17 | #include <sys/types.h> |
| 18 | #include <sys/socket.h> |
| 19 | |
| 20 | #include <osmocom/core/msgb.h> |
| 21 | #include <osmocom/core/application.h> |
| 22 | #include <osmocom/core/utils.h> |
| 23 | #include <osmocom/core/logging.h> |
| 24 | #include <osmocom/core/talloc.h> |
| 25 | #include <osmocom/core/signal.h> |
| 26 | #include <osmocom/core/rate_ctr.h> |
Jacob Erlbeck | b138106 | 2014-07-01 12:41:13 +0200 | [diff] [blame] | 27 | #include <osmocom/gsm/tlv.h> |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 28 | #include <osmocom/gsm/gsm_utils.h> |
Harald Welte | 53373bc | 2016-04-20 17:11:43 +0200 | [diff] [blame] | 29 | #include <osmocom/gsm/protocol/gsm_04_08_gprs.h> |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 30 | #include <osmocom/gprs/gprs_msgb.h> |
| 31 | #include <osmocom/gprs/gprs_ns.h> |
| 32 | #include <osmocom/gprs/gprs_bssgp.h> |
| 33 | |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 34 | #include <osmocom/sgsn/gb_proxy.h> |
| 35 | #include <osmocom/sgsn/gprs_utils.h> |
| 36 | #include <osmocom/sgsn/gprs_llc.h> |
| 37 | #include <osmocom/sgsn/gprs_gb_parse.h> |
| 38 | #include <osmocom/sgsn/debug.h> |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 39 | |
| 40 | #define REMOTE_BSS_ADDR 0x01020304 |
| 41 | #define REMOTE_SGSN_ADDR 0x05060708 |
| 42 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 43 | #define SGSN_NSEI 0x0100 |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 44 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 45 | #define REMOTE_SGSN2_ADDR 0x15161718 |
| 46 | #define SGSN2_NSEI 0x0102 |
| 47 | |
Jacob Erlbeck | acfaff3 | 2014-09-22 18:54:34 +0200 | [diff] [blame] | 48 | #define MATCH_ANY (-1) |
| 49 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 50 | void *tall_bsc_ctx = NULL; |
Neels Hofmeyr | ee6cfdc | 2017-07-13 02:03:50 +0200 | [diff] [blame] | 51 | |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 52 | struct gbproxy_config gbcfg = {0}; |
| 53 | |
Jacob Erlbeck | acfaff3 | 2014-09-22 18:54:34 +0200 | [diff] [blame] | 54 | struct llist_head *received_messages = NULL; |
| 55 | |
Max | 3b6332f | 2017-11-01 13:28:38 +0100 | [diff] [blame] | 56 | /* override, requires '-Wl,--wrap=osmo_get_rand_id' */ |
| 57 | int __real_osmo_get_rand_id(uint8_t *data, size_t len); |
| 58 | int mock_osmo_get_rand_id(uint8_t *data, size_t len); |
| 59 | int (*osmo_get_rand_id_cb)(uint8_t *, size_t) = |
| 60 | &mock_osmo_get_rand_id; |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 61 | |
Max | 3b6332f | 2017-11-01 13:28:38 +0100 | [diff] [blame] | 62 | int __wrap_osmo_get_rand_id(uint8_t *buf, size_t num) |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 63 | { |
Max | 3b6332f | 2017-11-01 13:28:38 +0100 | [diff] [blame] | 64 | return (*osmo_get_rand_id_cb)(buf, num); |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static int rand_seq_num = 0; |
Max | 3b6332f | 2017-11-01 13:28:38 +0100 | [diff] [blame] | 68 | int mock_osmo_get_rand_id(uint8_t *buf, size_t num) |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 69 | { |
| 70 | uint32_t val; |
| 71 | |
| 72 | OSMO_ASSERT(num == sizeof(val)); |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 73 | |
| 74 | val = 0x00dead00 + rand_seq_num; |
| 75 | |
| 76 | rand_seq_num++; |
| 77 | |
| 78 | memcpy(buf, &val, num); |
| 79 | |
| 80 | return 1; |
| 81 | } |
| 82 | |
Daniel Willmann | d1554ec | 2015-10-12 19:36:34 +0200 | [diff] [blame] | 83 | static void cleanup_test() |
| 84 | { |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 85 | rand_seq_num = 0; |
Daniel Willmann | d1554ec | 2015-10-12 19:36:34 +0200 | [diff] [blame] | 86 | } |
| 87 | |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 88 | static int dump_global(FILE *stream, int indent) |
| 89 | { |
| 90 | unsigned int i; |
| 91 | const struct rate_ctr_group_desc *desc; |
| 92 | int rc; |
| 93 | |
| 94 | rc = fprintf(stream, "%*sGbproxy global:\n", indent, ""); |
| 95 | if (rc < 0) |
| 96 | return rc; |
| 97 | |
| 98 | desc = gbcfg.ctrg->desc; |
| 99 | |
| 100 | for (i = 0; i < desc->num_ctr; i++) { |
| 101 | struct rate_ctr *ctr = &gbcfg.ctrg->ctr[i]; |
| 102 | if (ctr->current) { |
| 103 | rc = fprintf(stream, "%*s %s: %llu\n", |
| 104 | indent, "", |
| 105 | desc->ctr_desc[i].description, |
| 106 | (long long)ctr->current); |
| 107 | |
| 108 | if (rc < 0) |
| 109 | return rc; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 116 | static int dump_peers(FILE *stream, int indent, time_t now, |
| 117 | struct gbproxy_config *cfg) |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 118 | { |
Holger Hans Peter Freyther | 1ddd9e5 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 119 | struct gbproxy_peer *peer; |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 120 | struct gprs_ra_id raid; |
| 121 | unsigned int i; |
| 122 | const struct rate_ctr_group_desc *desc; |
| 123 | int rc; |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 124 | |
| 125 | rc = fprintf(stream, "%*sPeers:\n", indent, ""); |
| 126 | if (rc < 0) |
| 127 | return rc; |
| 128 | |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 129 | llist_for_each_entry(peer, &cfg->bts_peers, list) { |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 130 | struct gbproxy_link_info *link_info; |
Holger Hans Peter Freyther | 1ddd9e5 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 131 | struct gbproxy_patch_state *state = &peer->patch_state; |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 132 | gsm48_parse_ra(&raid, peer->ra); |
| 133 | |
Neels Hofmeyr | 10719b7 | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 134 | rc = fprintf(stream, "%*s NSEI %u, BVCI %u, %sblocked, RAI %s\n", |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 135 | indent, "", |
| 136 | peer->nsei, peer->bvci, |
| 137 | peer->blocked ? "" : "not ", |
Neels Hofmeyr | 10719b7 | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 138 | osmo_rai_name(&raid)); |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 139 | |
| 140 | if (rc < 0) |
| 141 | return rc; |
| 142 | |
| 143 | desc = peer->ctrg->desc; |
| 144 | |
| 145 | for (i = 0; i < desc->num_ctr; i++) { |
| 146 | struct rate_ctr *ctr = &peer->ctrg->ctr[i]; |
| 147 | if (ctr->current) { |
| 148 | rc = fprintf(stream, "%*s %s: %llu\n", |
| 149 | indent, "", |
| 150 | desc->ctr_desc[i].description, |
| 151 | (long long)ctr->current); |
| 152 | |
| 153 | if (rc < 0) |
| 154 | return rc; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | fprintf(stream, "%*s TLLI-Cache: %d\n", |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 159 | indent, "", state->logical_link_count); |
| 160 | llist_for_each_entry(link_info, &state->logical_links, list) { |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 161 | char mi_buf[200]; |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 162 | time_t age = now ? now - link_info->timestamp : 0; |
Jacob Erlbeck | ea1698e | 2014-09-02 14:40:11 +0200 | [diff] [blame] | 163 | int stored_msgs = 0; |
| 164 | struct llist_head *iter; |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 165 | enum gbproxy_match_id match_id; |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 166 | llist_for_each(iter, &link_info->stored_msgs) |
Jacob Erlbeck | ea1698e | 2014-09-02 14:40:11 +0200 | [diff] [blame] | 167 | stored_msgs++; |
| 168 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 169 | if (link_info->imsi_len > 0) { |
Jacob Erlbeck | 89d3d34 | 2014-08-06 18:55:15 +0200 | [diff] [blame] | 170 | snprintf(mi_buf, sizeof(mi_buf), "(invalid)"); |
| 171 | gsm48_mi_to_string(mi_buf, sizeof(mi_buf), |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 172 | link_info->imsi, |
| 173 | link_info->imsi_len); |
Jacob Erlbeck | 89d3d34 | 2014-08-06 18:55:15 +0200 | [diff] [blame] | 174 | } else { |
| 175 | snprintf(mi_buf, sizeof(mi_buf), "(none)"); |
| 176 | } |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 177 | fprintf(stream, "%*s TLLI %08x", |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 178 | indent, "", link_info->tlli.current); |
| 179 | if (link_info->tlli.assigned) |
| 180 | fprintf(stream, "/%08x", link_info->tlli.assigned); |
| 181 | if (link_info->sgsn_tlli.current) { |
Jacob Erlbeck | 9057bc3 | 2014-08-12 16:30:30 +0200 | [diff] [blame] | 182 | fprintf(stream, " -> %08x", |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 183 | link_info->sgsn_tlli.current); |
| 184 | if (link_info->sgsn_tlli.assigned) |
Jacob Erlbeck | 9057bc3 | 2014-08-12 16:30:30 +0200 | [diff] [blame] | 185 | fprintf(stream, "/%08x", |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 186 | link_info->sgsn_tlli.assigned); |
Jacob Erlbeck | 9057bc3 | 2014-08-12 16:30:30 +0200 | [diff] [blame] | 187 | } |
Jacob Erlbeck | 5f4ef32 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 188 | fprintf(stream, ", IMSI %s, AGE %d", |
| 189 | mi_buf, (int)age); |
| 190 | |
Jacob Erlbeck | ea1698e | 2014-09-02 14:40:11 +0200 | [diff] [blame] | 191 | if (stored_msgs) |
| 192 | fprintf(stream, ", STORED %d", stored_msgs); |
| 193 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 194 | for (match_id = 0; match_id < ARRAY_SIZE(cfg->matches); |
| 195 | ++match_id) { |
| 196 | if (cfg->matches[match_id].enable && |
| 197 | link_info->is_matching[match_id]) { |
| 198 | fprintf(stream, ", IMSI matches"); |
| 199 | break; |
| 200 | } |
| 201 | } |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 202 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 203 | if (link_info->imsi_acq_pending) |
Jacob Erlbeck | 5f4ef32 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 204 | fprintf(stream, ", IMSI acquisition in progress"); |
| 205 | |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 206 | if (cfg->route_to_sgsn2) |
| 207 | fprintf(stream, ", SGSN NSEI %d", |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 208 | link_info->sgsn_nsei); |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 209 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 210 | if (link_info->is_deregistered) |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 211 | fprintf(stream, ", DE-REGISTERED"); |
| 212 | |
Jacob Erlbeck | 5f4ef32 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 213 | rc = fprintf(stream, "\n"); |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 214 | if (rc < 0) |
| 215 | return rc; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
Jacob Erlbeck | 7fb26c2 | 2014-09-04 11:08:50 +0200 | [diff] [blame] | 222 | const uint8_t *convert_ra(struct gprs_ra_id *raid) |
| 223 | { |
Max | 25c65c3 | 2018-01-08 14:43:53 +0100 | [diff] [blame] | 224 | static struct gsm48_ra_id r; |
| 225 | gsm48_encode_ra(&r, raid); |
| 226 | return (const uint8_t *)&r; |
Jacob Erlbeck | 7fb26c2 | 2014-09-04 11:08:50 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 229 | /* DTAP - Attach Request */ |
| 230 | static const unsigned char dtap_attach_req[] = { |
| 231 | 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, |
| 232 | 0x05, 0xf4, 0xfb, 0xc5, 0x46, 0x79, 0x11, 0x22, |
| 233 | 0x33, 0x40, 0x50, 0x60, 0x19, 0x18, 0xb3, 0x43, |
| 234 | 0x2b, 0x25, 0x96, 0x62, 0x00, 0x60, 0x80, 0x9a, |
| 235 | 0xc2, 0xc6, 0x62, 0x00, 0x60, 0x80, 0xba, 0xc8, |
| 236 | 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00, |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 237 | }; |
| 238 | |
Jacob Erlbeck | 991606b | 2014-09-12 10:33:38 +0200 | [diff] [blame] | 239 | /* DTAP - Attach Request (invalid RAI) */ |
| 240 | static const unsigned char dtap_attach_req2[] = { |
| 241 | 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, |
| 242 | 0x05, 0xf4, 0xfb, 0x00, 0xbe, 0xef, 0x99, 0x99, |
| 243 | 0x99, 0x40, 0x50, 0x60, 0x19, 0x18, 0xb3, 0x43, |
| 244 | 0x2b, 0x25, 0x96, 0x62, 0x00, 0x60, 0x80, 0x9a, |
| 245 | 0xc2, 0xc6, 0x62, 0x00, 0x60, 0x80, 0xba, 0xc8, |
| 246 | 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00, |
| 247 | }; |
| 248 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 249 | /* DTAP - Attach Request (P-TMSI 0x3f32b700) */ |
| 250 | static const unsigned char dtap_attach_req3[] = { |
| 251 | 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, |
| 252 | 0x05, 0xf4, 0xef, 0xe2, 0xb7, 0x00, 0x11, 0x22, |
| 253 | 0x33, 0x40, 0x50, 0x60, 0x19, 0x18, 0xb3, 0x43, |
| 254 | 0x2b, 0x25, 0x96, 0x62, 0x00, 0x60, 0x80, 0x9a, |
| 255 | 0xc2, 0xc6, 0x62, 0x00, 0x60, 0x80, 0xba, 0xc8, |
| 256 | 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00, |
| 257 | }; |
| 258 | |
Jacob Erlbeck | 9d0fb1e | 2014-10-31 10:43:44 +0100 | [diff] [blame] | 259 | /* DTAP - Attach Request (IMSI 12131415161718) */ |
| 260 | static const unsigned char dtap_attach_req4[] = { |
| 261 | 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, |
| 262 | 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 263 | 0x18, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60, 0x19, |
| 264 | 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00, |
| 265 | 0x60, 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60, |
| 266 | 0x80, 0xba, 0xc8, 0xc6, 0x62, 0x00, 0x60, 0x80, |
| 267 | 0x00, |
| 268 | }; |
| 269 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 270 | /* DTAP - Identity Request */ |
| 271 | static const unsigned char dtap_identity_req[] = { |
| 272 | 0x08, 0x15, 0x01 |
Jacob Erlbeck | 690768a | 2014-08-06 15:16:45 +0200 | [diff] [blame] | 273 | }; |
| 274 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 275 | /* DTAP - Identity Response */ |
| 276 | static const unsigned char dtap_identity_resp[] = { |
| 277 | 0x08, 0x16, 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, |
| 278 | 0x16, 0x17, 0x18 |
Jacob Erlbeck | 690768a | 2014-08-06 15:16:45 +0200 | [diff] [blame] | 279 | }; |
| 280 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 281 | /* DTAP - Identity Response, IMSI 2 */ |
| 282 | static const unsigned char dtap_identity2_resp[] = { |
| 283 | 0x08, 0x16, 0x08, 0x11, 0x12, 0x99, 0x99, 0x99, |
| 284 | 0x16, 0x17, 0x18 |
| 285 | }; |
| 286 | |
Jacob Erlbeck | af952ba | 2014-09-17 12:09:25 +0200 | [diff] [blame] | 287 | /* DTAP - Identity Response, IMSI 3 */ |
| 288 | static const unsigned char dtap_identity3_resp[] = { |
| 289 | 0x08, 0x16, 0x08, 0x11, 0x12, 0x99, 0x99, 0x99, |
| 290 | 0x26, 0x27, 0x28 |
| 291 | }; |
| 292 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 293 | /* DTAP - Attach Accept */ |
| 294 | static const unsigned char dtap_attach_acc[] = { |
| 295 | 0x08, 0x02, 0x01, 0x49, 0x04, 0x21, 0x63, 0x54, |
| 296 | 0x40, 0x50, 0x60, 0x19, 0xcd, 0xd7, 0x08, 0x17, |
| 297 | 0x16, 0x18, 0x05, 0xf4, 0xef, 0xe2, 0xb7, 0x00 |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 298 | }; |
| 299 | |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 300 | /* DTAP - Attach Accept, P-TMSI 2 */ |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 301 | static const unsigned char dtap_attach_acc2[] = { |
| 302 | 0x08, 0x02, 0x01, 0x49, 0x04, 0x21, 0x63, 0x54, |
| 303 | 0x40, 0x50, 0x60, 0x19, 0xcd, 0xd7, 0x08, 0x17, |
| 304 | 0x16, 0x18, 0x05, 0xf4, 0xe0, 0x98, 0x76, 0x54 |
| 305 | }; |
| 306 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 307 | /* DTAP - Attach Complete */ |
| 308 | static const unsigned char dtap_attach_complete[] = { |
| 309 | 0x08, 0x03 |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 310 | }; |
| 311 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 312 | /* DTAP - Attach Reject (GPRS services not allowed) */ |
| 313 | static const unsigned char dtap_attach_rej7[] = { |
| 314 | 0x08, 0x04, 0x07 |
| 315 | }; |
| 316 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 317 | /* DTAP - GMM Information */ |
| 318 | static const unsigned char dtap_gmm_information[] = { |
| 319 | 0x08, 0x21 |
Jacob Erlbeck | 1166974 | 2014-06-06 18:47:36 +0200 | [diff] [blame] | 320 | }; |
| 321 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 322 | /* DTAP - Routing Area Update Request */ |
| 323 | static const unsigned char dtap_ra_upd_req[] = { |
| 324 | 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50, |
| 325 | 0x60, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b, |
| 326 | 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8, |
| 327 | 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02, |
| 328 | 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19, |
| 329 | 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04, |
| 330 | 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00 |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 331 | }; |
| 332 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 333 | /* DTAP - Routing Area Update Accept */ |
| 334 | static const unsigned char dtap_ra_upd_acc[] = { |
| 335 | 0x08, 0x09, 0x00, 0x49, 0x21, 0x63, 0x54, |
| 336 | 0x40, 0x50, 0x60, 0x19, 0x54, 0xab, 0xb3, 0x18, |
| 337 | 0x05, 0xf4, 0xef, 0xe2, 0xb7, 0x00, 0x17, 0x16, |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 338 | }; |
| 339 | |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 340 | /* DTAP - Routing Area Update Accept, P-TMSI 2 */ |
| 341 | static const unsigned char dtap_ra_upd_acc2[] = { |
| 342 | 0x08, 0x09, 0x00, 0x49, 0x21, 0x63, 0x54, |
| 343 | 0x40, 0x50, 0x60, 0x19, 0x54, 0xab, 0xb3, 0x18, |
| 344 | 0x05, 0xf4, 0xe0, 0x98, 0x76, 0x54, 0x17, 0x16, |
| 345 | }; |
| 346 | |
| 347 | /* DTAP - Routing Area Update Accept, P-TMSI 3 */ |
| 348 | static const unsigned char dtap_ra_upd_acc3[] = { |
| 349 | 0x08, 0x09, 0x00, 0x49, 0x21, 0x63, 0x54, |
| 350 | 0x40, 0x50, 0x60, 0x19, 0x54, 0xab, 0xb3, 0x18, |
| 351 | 0x05, 0xf4, 0xe0, 0x54, 0x32, 0x10, 0x17, 0x16, |
| 352 | }; |
| 353 | |
| 354 | /* DTAP - Routing Area Update Complete */ |
| 355 | static const unsigned char dtap_ra_upd_complete[] = { |
| 356 | 0x08, 0x0a |
| 357 | }; |
| 358 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 359 | /* DTAP - Routing Area Update Reject */ |
| 360 | /* cause = 10 ("Implicitly detached"), force_standby = 0 */ |
| 361 | static const unsigned char dtap_ra_upd_rej[] = { |
| 362 | 0x08, 0x0b, 0x0a, 0x00, |
| 363 | }; |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 364 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 365 | /* DTAP - Activate PDP Context Request */ |
| 366 | static const unsigned char dtap_act_pdp_ctx_req[] = { |
| 367 | 0x0a, 0x41, 0x05, 0x03, 0x0c, 0x00, |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 368 | 0x00, 0x1f, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 369 | 0x00, 0x00, 0x00, 0x02, 0x01, 0x21, 0x28, 0x03, |
| 370 | 0x02, 0x61, 0x62, 0x27, 0x14, 0x80, 0x80, 0x21, |
| 371 | 0x10, 0x01, 0x00, 0x00, 0x10, 0x81, 0x06, 0x00, |
| 372 | 0x00, 0x00, 0x00, 0x83, 0x06, 0x00, 0x00, 0x00, |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 373 | 0x00 |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 374 | }; |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 375 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 376 | /* DTAP - Detach Request (MO) */ |
Jacob Erlbeck | 3e23ddf | 2014-08-11 15:07:37 +0200 | [diff] [blame] | 377 | /* normal detach, power_off = 1 */ |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 378 | static const unsigned char dtap_detach_po_req[] = { |
| 379 | 0x08, 0x05, 0x09, 0x18, 0x05, 0xf4, 0xef, 0xe2, |
| 380 | 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb |
Jacob Erlbeck | 3e23ddf | 2014-08-11 15:07:37 +0200 | [diff] [blame] | 381 | }; |
| 382 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 383 | /* DTAP - Detach Request (MO) */ |
Jacob Erlbeck | 3e23ddf | 2014-08-11 15:07:37 +0200 | [diff] [blame] | 384 | /* normal detach, power_off = 0 */ |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 385 | static const unsigned char dtap_detach_req[] = { |
| 386 | 0x08, 0x05, 0x01, 0x18, 0x05, 0xf4, 0xef, 0xe2, |
| 387 | 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb |
Jacob Erlbeck | cf02eb1 | 2014-06-19 10:23:50 +0200 | [diff] [blame] | 388 | }; |
| 389 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 390 | /* DTAP - Detach Accept (MO) */ |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 391 | static const unsigned char dtap_detach_acc[] = { |
| 392 | 0x08, 0x06, 0x00 |
Jacob Erlbeck | cf02eb1 | 2014-06-19 10:23:50 +0200 | [diff] [blame] | 393 | }; |
| 394 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 395 | /* DTAP - Detach Request (MT) */ |
| 396 | /* normal detach, reattach required, implicitly detached */ |
| 397 | static const unsigned char dtap_mt_detach_rea_req[] = { |
| 398 | 0x08, 0x05, 0x01, 0x25, 0x0a |
| 399 | }; |
| 400 | |
| 401 | /* DTAP - Detach Request (MT) */ |
| 402 | /* normal detach, reattach not required, implicitly detached */ |
| 403 | static const unsigned char dtap_mt_detach_req[] = { |
| 404 | 0x08, 0x05, 0x02, 0x25, 0x0a |
| 405 | }; |
| 406 | |
| 407 | /* DTAP - Detach Accept (MT) */ |
| 408 | static const unsigned char dtap_mt_detach_acc[] = { |
| 409 | 0x08, 0x06 |
| 410 | }; |
| 411 | |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 412 | /* GPRS-LLC - SAPI: LLGMM, U, XID */ |
| 413 | static const unsigned char llc_u_xid_ul[] = { |
| 414 | 0x41, 0xfb, 0x01, 0x00, 0x0e, 0x00, 0x64, 0x11, |
| 415 | 0x05, 0x16, 0x01, 0x90, 0x66, 0xb3, 0x28 |
| 416 | }; |
| 417 | |
| 418 | /* GPRS-LLC - SAPI: LLGMM, U, XID */ |
| 419 | static const unsigned char llc_u_xid_dl[] = { |
| 420 | 0x41, 0xfb, 0x30, 0x84, 0x10, 0x61, 0xb6, 0x64, |
| 421 | 0xe4, 0xa9, 0x1a, 0x9e |
| 422 | }; |
| 423 | |
| 424 | /* GPRS-LLC - SAPI: LL11, UI, NSAPI 5, DNS query */ |
| 425 | static const unsigned char llc_ui_ll11_dns_query_ul[] = { |
| 426 | 0x0b, 0xc0, 0x01, 0x65, 0x00, 0x00, 0x00, 0x45, |
| 427 | 0x00, 0x00, 0x38, 0x95, 0x72, 0x00, 0x00, 0x45, |
| 428 | 0x11, 0x20, 0x85, 0x0a, 0xc0, 0x07, 0xe4, 0xac, |
| 429 | 0x10, 0x01, 0x0a, 0xad, 0xab, 0x00, 0x35, 0x00, |
| 430 | 0x24, 0x0e, 0x1c, 0x3b, 0xe0, 0x01, 0x00, 0x00, |
| 431 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 432 | 0x6d, 0x05, 0x68, 0x65, 0x69, 0x73, 0x65, 0x02, |
| 433 | 0x64, 0x65, 0x00, 0x00, 0x01, 0x00, 0x01, 0x47, |
| 434 | 0x8f, 0x07 |
| 435 | }; |
| 436 | |
| 437 | /* GPRS-LLC - SAPI: LL11, UI, NSAPI 5, DNS query */ |
| 438 | static const unsigned char llc_ui_ll11_dns_resp_dl[] = { |
| 439 | 0x4b, 0xc0, 0x01, 0x65, 0x00, 0x00, 0x00, 0x45, |
| 440 | 0x00, 0x00, 0xc6, 0x00, 0x00, 0x40, 0x00, 0x3e, |
| 441 | 0x11, 0x7c, 0x69, 0xac, 0x10, 0x01, 0x0a, 0x0a, |
| 442 | 0xc0, 0x07, 0xe4, 0x00, 0x35, 0xad, 0xab, 0x00, |
| 443 | 0xb2, 0x74, 0x4e, 0x3b, 0xe0, 0x81, 0x80, 0x00, |
| 444 | 0x01, 0x00, 0x01, 0x00, 0x05, 0x00, 0x00, 0x01, |
| 445 | 0x6d, 0x05, 0x68, 0x65, 0x69, 0x73, 0x65, 0x02, |
| 446 | 0x64, 0x65, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0, |
| 447 | 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0e, |
| 448 | 0x10, 0x00, 0x04, 0xc1, 0x63, 0x90, 0x58, 0xc0, |
| 449 | 0x0e, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, |
| 450 | 0x10, 0x00, 0x16, 0x03, 0x6e, 0x73, 0x32, 0x0c, |
| 451 | 0x70, 0x6f, 0x70, 0x2d, 0x68, 0x61, 0x6e, 0x6e, |
| 452 | 0x6f, 0x76, 0x65, 0x72, 0x03, 0x6e, 0x65, 0x74, |
| 453 | 0x00, 0xc0, 0x0e, 0x00, 0x02, 0x00, 0x01, 0x00, |
| 454 | 0x00, 0x0e, 0x10, 0x00, 0x10, 0x02, 0x6e, 0x73, |
| 455 | 0x01, 0x73, 0x08, 0x70, 0x6c, 0x75, 0x73, 0x6c, |
| 456 | 0x69, 0x6e, 0x65, 0xc0, 0x14, 0xc0, 0x0e, 0x00, |
| 457 | 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10, 0x00, |
| 458 | 0x05, 0x02, 0x6e, 0x73, 0xc0, 0x0e, 0xc0, 0x0e, |
| 459 | 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, 0x10, |
| 460 | 0x00, 0x05, 0x02, 0x6e, 0x73, 0xc0, 0x5f, 0xc0, |
| 461 | 0x0e, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0e, |
| 462 | 0x10, 0x00, 0x12, 0x02, 0x6e, 0x73, 0x0c, 0x70, |
| 463 | 0x6f, 0x70, 0x2d, 0x68, 0x61, 0x6e, 0x6e, 0x6f, |
| 464 | 0x76, 0x65, 0x72, 0xc0, 0x14, 0xaa, 0xdf, 0x31 |
| 465 | }; |
| 466 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 467 | static int gprs_process_message(struct gprs_ns_inst *nsi, const char *text, |
| 468 | struct sockaddr_in *peer, const unsigned char* data, |
| 469 | size_t data_len); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 470 | |
| 471 | static void send_ns_reset(struct gprs_ns_inst *nsi, struct sockaddr_in *src_addr, |
| 472 | enum ns_cause cause, uint16_t nsvci, uint16_t nsei) |
| 473 | { |
| 474 | /* GPRS Network Service, PDU type: NS_RESET, |
| 475 | */ |
| 476 | unsigned char msg[12] = { |
| 477 | 0x02, 0x00, 0x81, 0x01, 0x01, 0x82, 0x11, 0x22, |
| 478 | 0x04, 0x82, 0x11, 0x22 |
| 479 | }; |
| 480 | |
| 481 | msg[3] = cause; |
| 482 | msg[6] = nsvci / 256; |
| 483 | msg[7] = nsvci % 256; |
| 484 | msg[10] = nsei / 256; |
| 485 | msg[11] = nsei % 256; |
| 486 | |
| 487 | gprs_process_message(nsi, "RESET", src_addr, msg, sizeof(msg)); |
| 488 | } |
| 489 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 490 | static void send_ns_reset_ack(struct gprs_ns_inst *nsi, struct sockaddr_in *src_addr, |
| 491 | uint16_t nsvci, uint16_t nsei) |
| 492 | { |
| 493 | /* GPRS Network Service, PDU type: NS_RESET_ACK, |
| 494 | */ |
| 495 | unsigned char msg[9] = { |
| 496 | 0x03, 0x01, 0x82, 0x11, 0x22, |
| 497 | 0x04, 0x82, 0x11, 0x22 |
| 498 | }; |
| 499 | |
| 500 | msg[3] = nsvci / 256; |
| 501 | msg[4] = nsvci % 256; |
| 502 | msg[7] = nsei / 256; |
| 503 | msg[8] = nsei % 256; |
| 504 | |
| 505 | gprs_process_message(nsi, "RESET_ACK", src_addr, msg, sizeof(msg)); |
| 506 | } |
| 507 | |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 508 | static void send_ns_alive(struct gprs_ns_inst *nsi, struct sockaddr_in *src_addr) |
| 509 | { |
| 510 | /* GPRS Network Service, PDU type: NS_ALIVE */ |
| 511 | unsigned char msg[1] = { |
| 512 | 0x0a |
| 513 | }; |
| 514 | |
| 515 | gprs_process_message(nsi, "ALIVE", src_addr, msg, sizeof(msg)); |
| 516 | } |
| 517 | |
| 518 | static void send_ns_alive_ack(struct gprs_ns_inst *nsi, struct sockaddr_in *src_addr) |
| 519 | { |
| 520 | /* GPRS Network Service, PDU type: NS_ALIVE_ACK */ |
| 521 | unsigned char msg[1] = { |
| 522 | 0x0b |
| 523 | }; |
| 524 | |
| 525 | gprs_process_message(nsi, "ALIVE_ACK", src_addr, msg, sizeof(msg)); |
| 526 | } |
| 527 | |
| 528 | static void send_ns_unblock(struct gprs_ns_inst *nsi, struct sockaddr_in *src_addr) |
| 529 | { |
| 530 | /* GPRS Network Service, PDU type: NS_UNBLOCK */ |
| 531 | unsigned char msg[1] = { |
| 532 | 0x06 |
| 533 | }; |
| 534 | |
| 535 | gprs_process_message(nsi, "UNBLOCK", src_addr, msg, sizeof(msg)); |
| 536 | } |
| 537 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 538 | static void send_ns_unblock_ack(struct gprs_ns_inst *nsi, struct sockaddr_in *src_addr) |
| 539 | { |
| 540 | /* GPRS Network Service, PDU type: NS_UNBLOCK_ACK */ |
| 541 | unsigned char msg[1] = { |
| 542 | 0x07 |
| 543 | }; |
| 544 | |
| 545 | gprs_process_message(nsi, "UNBLOCK_ACK", src_addr, msg, sizeof(msg)); |
| 546 | } |
| 547 | |
| 548 | static void send_ns_unitdata(struct gprs_ns_inst *nsi, const char *text, |
| 549 | struct sockaddr_in *src_addr, uint16_t nsbvci, |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 550 | const unsigned char *bssgp_msg, size_t bssgp_msg_size) |
| 551 | { |
| 552 | /* GPRS Network Service, PDU type: NS_UNITDATA */ |
| 553 | unsigned char msg[4096] = { |
| 554 | 0x00, 0x00, 0x00, 0x00 |
| 555 | }; |
| 556 | |
| 557 | OSMO_ASSERT(bssgp_msg_size <= sizeof(msg) - 4); |
| 558 | |
| 559 | msg[2] = nsbvci / 256; |
| 560 | msg[3] = nsbvci % 256; |
| 561 | memcpy(msg + 4, bssgp_msg, bssgp_msg_size); |
| 562 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 563 | gprs_process_message(nsi, text ? text : "UNITDATA", src_addr, msg, bssgp_msg_size + 4); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 564 | } |
| 565 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 566 | static void send_bssgp_ul_unitdata( |
| 567 | struct gprs_ns_inst *nsi, const char *text, |
| 568 | struct sockaddr_in *src_addr, uint16_t nsbvci, uint32_t tlli, |
| 569 | struct gprs_ra_id *raid, uint16_t cell_id, |
| 570 | const uint8_t *llc_msg, size_t llc_msg_size) |
| 571 | { |
| 572 | /* GPRS Network Service, PDU type: NS_UNITDATA */ |
| 573 | /* Base Station Subsystem GPRS Protocol: UL_UNITDATA */ |
| 574 | unsigned char msg[4096] = { |
| 575 | 0x01, /* TLLI */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, |
| 576 | 0x08, 0x88, /* RAI */ 0x11, 0x22, 0x33, 0x40, 0x50, 0x60, |
| 577 | /* CELL ID */ 0x00, 0x00, 0x00, 0x80, 0x0e, /* LLC LEN */ 0x00, 0x00, |
| 578 | }; |
| 579 | |
| 580 | size_t bssgp_msg_size = 23 + llc_msg_size; |
| 581 | |
| 582 | OSMO_ASSERT(bssgp_msg_size <= sizeof(msg)); |
| 583 | |
Max | 25c65c3 | 2018-01-08 14:43:53 +0100 | [diff] [blame] | 584 | gsm48_encode_ra((struct gsm48_ra_id *)(msg + 10), raid); |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 585 | msg[1] = (uint8_t)(tlli >> 24); |
| 586 | msg[2] = (uint8_t)(tlli >> 16); |
| 587 | msg[3] = (uint8_t)(tlli >> 8); |
| 588 | msg[4] = (uint8_t)(tlli >> 0); |
| 589 | msg[16] = cell_id / 256; |
| 590 | msg[17] = cell_id % 256; |
| 591 | msg[21] = llc_msg_size / 256; |
| 592 | msg[22] = llc_msg_size % 256; |
| 593 | memcpy(msg + 23, llc_msg, llc_msg_size); |
| 594 | |
| 595 | send_ns_unitdata(nsi, text ? text : "BSSGP UL UNITDATA", |
| 596 | src_addr, nsbvci, msg, bssgp_msg_size); |
| 597 | } |
| 598 | |
| 599 | static void send_bssgp_dl_unitdata( |
| 600 | struct gprs_ns_inst *nsi, const char *text, |
| 601 | struct sockaddr_in *src_addr, uint16_t nsbvci, uint32_t tlli, |
| 602 | int with_racap_drx, const uint8_t *imsi, size_t imsi_size, |
| 603 | const uint8_t *llc_msg, size_t llc_msg_size) |
| 604 | { |
| 605 | /* Base Station Subsystem GPRS Protocol: DL_UNITDATA */ |
| 606 | unsigned char msg[4096] = { |
| 607 | 0x00, /* TLLI */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x20, |
| 608 | 0x16, 0x82, 0x02, 0x58, |
| 609 | }; |
| 610 | unsigned char racap_drx[] = { |
| 611 | 0x13, 0x99, 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, |
| 612 | 0x62, 0x00, 0x60, 0x80, 0x9a, 0xc2, 0xc6, 0x62, |
| 613 | 0x00, 0x60, 0x80, 0xba, 0xc8, 0xc6, 0x62, 0x00, |
| 614 | 0x60, 0x80, 0x00, 0x0a, 0x82, 0x08, 0x02 |
| 615 | }; |
| 616 | |
| 617 | size_t bssgp_msg_size = 0; |
| 618 | |
| 619 | OSMO_ASSERT(51 + imsi_size + llc_msg_size <= sizeof(msg)); |
| 620 | |
| 621 | msg[1] = (uint8_t)(tlli >> 24); |
| 622 | msg[2] = (uint8_t)(tlli >> 16); |
| 623 | msg[3] = (uint8_t)(tlli >> 8); |
| 624 | msg[4] = (uint8_t)(tlli >> 0); |
| 625 | |
| 626 | bssgp_msg_size = 12; |
| 627 | |
| 628 | if (with_racap_drx) { |
| 629 | memcpy(msg + bssgp_msg_size, racap_drx, sizeof(racap_drx)); |
| 630 | bssgp_msg_size += sizeof(racap_drx); |
| 631 | } |
| 632 | |
| 633 | if (imsi) { |
| 634 | OSMO_ASSERT(imsi_size <= 127); |
| 635 | msg[bssgp_msg_size] = BSSGP_IE_IMSI; |
| 636 | msg[bssgp_msg_size + 1] = 0x80 | imsi_size; |
| 637 | memcpy(msg + bssgp_msg_size + 2, imsi, imsi_size); |
| 638 | bssgp_msg_size += 2 + imsi_size; |
| 639 | } |
| 640 | |
| 641 | if ((bssgp_msg_size % 4) != 0) { |
| 642 | size_t abytes = (4 - (bssgp_msg_size + 2) % 4) % 4; |
| 643 | msg[bssgp_msg_size] = BSSGP_IE_ALIGNMENT; |
| 644 | msg[bssgp_msg_size + 1] = 0x80 | abytes; |
| 645 | memset(msg + bssgp_msg_size + 2, 0, abytes); |
| 646 | bssgp_msg_size += 2 + abytes; |
| 647 | } |
| 648 | |
| 649 | msg[bssgp_msg_size] = BSSGP_IE_LLC_PDU; |
| 650 | if (llc_msg_size < 128) { |
| 651 | msg[bssgp_msg_size + 1] = 0x80 | llc_msg_size; |
| 652 | bssgp_msg_size += 2; |
| 653 | } else { |
| 654 | msg[bssgp_msg_size + 1] = llc_msg_size / 256; |
| 655 | msg[bssgp_msg_size + 2] = llc_msg_size % 256; |
| 656 | bssgp_msg_size += 3; |
| 657 | } |
| 658 | memcpy(msg + bssgp_msg_size, llc_msg, llc_msg_size); |
| 659 | bssgp_msg_size += llc_msg_size; |
| 660 | |
| 661 | |
| 662 | send_ns_unitdata(nsi, text ? text : "BSSGP DL UNITDATA", |
| 663 | src_addr, nsbvci, msg, bssgp_msg_size); |
| 664 | } |
| 665 | |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 666 | static void send_bssgp_reset(struct gprs_ns_inst *nsi, struct sockaddr_in *src_addr, |
| 667 | uint16_t bvci) |
| 668 | { |
| 669 | /* GPRS Network Service, PDU type: NS_UNITDATA, BVCI 0 |
| 670 | * BSSGP RESET */ |
Jacob Erlbeck | da4b492 | 2014-08-06 12:38:10 +0200 | [diff] [blame] | 671 | unsigned char msg[18] = { |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 672 | 0x22, 0x04, 0x82, 0x4a, |
Jacob Erlbeck | def0391 | 2014-06-02 10:48:59 +0200 | [diff] [blame] | 673 | 0x2e, 0x07, 0x81, 0x08, 0x08, 0x88, 0x11, 0x22, |
| 674 | 0x33, 0x40, 0x50, 0x60, 0x10, 0x00 |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 675 | }; |
| 676 | |
| 677 | msg[3] = bvci / 256; |
| 678 | msg[4] = bvci % 256; |
| 679 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 680 | send_ns_unitdata(nsi, "BVC_RESET", src_addr, 0, msg, sizeof(msg)); |
| 681 | } |
| 682 | |
| 683 | static void send_bssgp_reset_ack(struct gprs_ns_inst *nsi, |
| 684 | struct sockaddr_in *src_addr, uint16_t bvci) |
| 685 | { |
| 686 | /* GPRS Network Service, PDU type: NS_UNITDATA, BVCI 0 |
| 687 | * BSSGP RESET_ACK */ |
| 688 | static unsigned char msg[5] = { |
| 689 | 0x23, 0x04, 0x82, 0x00, |
| 690 | 0x00 |
| 691 | }; |
| 692 | |
| 693 | msg[3] = bvci / 256; |
| 694 | msg[4] = bvci % 256; |
| 695 | |
| 696 | send_ns_unitdata(nsi, "BVC_RESET_ACK", src_addr, 0, msg, sizeof(msg)); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 697 | } |
| 698 | |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 699 | static void send_bssgp_suspend(struct gprs_ns_inst *nsi, |
| 700 | struct sockaddr_in *src_addr, |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 701 | uint32_t tlli, |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 702 | struct gprs_ra_id *raid) |
| 703 | { |
| 704 | /* Base Station Subsystem GPRS Protocol, BSSGP SUSPEND */ |
| 705 | unsigned char msg[15] = { |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 706 | 0x0b, 0x1f, 0x84, /* TLLI */ 0xff, 0xff, 0xff, 0xff, 0x1b, |
| 707 | 0x86, /* RAI */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 708 | }; |
| 709 | |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 710 | msg[3] = (uint8_t)(tlli >> 24); |
| 711 | msg[4] = (uint8_t)(tlli >> 16); |
| 712 | msg[5] = (uint8_t)(tlli >> 8); |
| 713 | msg[6] = (uint8_t)(tlli >> 0); |
| 714 | |
Max | 25c65c3 | 2018-01-08 14:43:53 +0100 | [diff] [blame] | 715 | gsm48_encode_ra((struct gsm48_ra_id *)(msg + 9), raid); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 716 | |
| 717 | send_ns_unitdata(nsi, "BVC_SUSPEND", src_addr, 0, msg, sizeof(msg)); |
| 718 | } |
| 719 | |
| 720 | static void send_bssgp_suspend_ack(struct gprs_ns_inst *nsi, |
| 721 | struct sockaddr_in *src_addr, |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 722 | uint32_t tlli, |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 723 | struct gprs_ra_id *raid) |
| 724 | { |
| 725 | /* Base Station Subsystem GPRS Protocol, BSSGP SUSPEND ACK */ |
| 726 | unsigned char msg[18] = { |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 727 | 0x0c, 0x1f, 0x84, /* TLLI */ 0xff, 0xff, 0xff, 0xff, 0x1b, |
| 728 | 0x86, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1d, |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 729 | 0x81, 0x01 |
| 730 | }; |
| 731 | |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 732 | msg[3] = (uint8_t)(tlli >> 24); |
| 733 | msg[4] = (uint8_t)(tlli >> 16); |
| 734 | msg[5] = (uint8_t)(tlli >> 8); |
| 735 | msg[6] = (uint8_t)(tlli >> 0); |
| 736 | |
Max | 25c65c3 | 2018-01-08 14:43:53 +0100 | [diff] [blame] | 737 | gsm48_encode_ra((struct gsm48_ra_id *)(msg + 9), raid); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 738 | |
| 739 | send_ns_unitdata(nsi, "BVC_SUSPEND_ACK", src_addr, 0, msg, sizeof(msg)); |
| 740 | } |
| 741 | |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 742 | static void send_bssgp_llc_discarded(struct gprs_ns_inst *nsi, |
| 743 | struct sockaddr_in *src_addr, |
| 744 | uint16_t bvci, uint32_t tlli, |
| 745 | unsigned n_frames, unsigned n_octets) |
| 746 | { |
| 747 | /* Base Station Subsystem GPRS Protocol: LLC-DISCARDED (0x2c) */ |
| 748 | unsigned char msg[] = { |
| 749 | 0x2c, 0x1f, 0x84, /* TLLI */ 0xff, 0xff, 0xff, 0xff, 0x0f, |
| 750 | 0x81, /* n frames */ 0xff, 0x04, 0x82, /* BVCI */ 0xff, 0xff, 0x25, 0x83, |
| 751 | /* n octets */ 0xff, 0xff, 0xff |
| 752 | }; |
| 753 | |
| 754 | msg[3] = (uint8_t)(tlli >> 24); |
| 755 | msg[4] = (uint8_t)(tlli >> 16); |
| 756 | msg[5] = (uint8_t)(tlli >> 8); |
| 757 | msg[6] = (uint8_t)(tlli >> 0); |
| 758 | msg[9] = (uint8_t)(n_frames); |
| 759 | msg[12] = (uint8_t)(bvci >> 8); |
| 760 | msg[13] = (uint8_t)(bvci >> 0); |
| 761 | msg[16] = (uint8_t)(n_octets >> 16); |
| 762 | msg[17] = (uint8_t)(n_octets >> 8); |
| 763 | msg[18] = (uint8_t)(n_octets >> 0); |
| 764 | |
| 765 | send_ns_unitdata(nsi, "LLC_DISCARDED", src_addr, 0, msg, sizeof(msg)); |
| 766 | } |
| 767 | |
Jacob Erlbeck | c37ef6c | 2014-09-30 13:49:43 +0200 | [diff] [blame] | 768 | static void send_bssgp_paging(struct gprs_ns_inst *nsi, |
| 769 | struct sockaddr_in *src_addr, |
| 770 | const uint8_t *imsi, size_t imsi_size, |
| 771 | struct gprs_ra_id *raid, uint32_t ptmsi) |
| 772 | { |
| 773 | /* Base Station Subsystem GPRS Protocol, BSSGP SUSPEND */ |
| 774 | unsigned char msg[100] = { |
| 775 | 0x06, |
| 776 | }; |
| 777 | |
| 778 | const unsigned char drx_ie[] = {0x0a, 0x82, 0x07, 0x04}; |
| 779 | const unsigned char qos_ie[] = {0x18, 0x83, 0x00, 0x00, 0x00}; |
| 780 | |
| 781 | size_t bssgp_msg_size = 1; |
| 782 | |
| 783 | if (imsi) { |
| 784 | OSMO_ASSERT(imsi_size <= 127); |
| 785 | msg[bssgp_msg_size] = BSSGP_IE_IMSI; |
| 786 | msg[bssgp_msg_size + 1] = 0x80 | imsi_size; |
| 787 | memcpy(msg + bssgp_msg_size + 2, imsi, imsi_size); |
| 788 | bssgp_msg_size += 2 + imsi_size; |
| 789 | } |
| 790 | |
| 791 | memcpy(msg + bssgp_msg_size, drx_ie, sizeof(drx_ie)); |
| 792 | bssgp_msg_size += sizeof(drx_ie); |
| 793 | |
| 794 | if (raid) { |
| 795 | msg[bssgp_msg_size] = BSSGP_IE_ROUTEING_AREA; |
| 796 | msg[bssgp_msg_size+1] = 0x86; |
Max | 25c65c3 | 2018-01-08 14:43:53 +0100 | [diff] [blame] | 797 | gsm48_encode_ra((struct gsm48_ra_id *)(msg + bssgp_msg_size + 2), raid); |
Jacob Erlbeck | c37ef6c | 2014-09-30 13:49:43 +0200 | [diff] [blame] | 798 | bssgp_msg_size += 8; |
| 799 | } |
| 800 | |
| 801 | memcpy(msg + bssgp_msg_size, qos_ie, sizeof(qos_ie)); |
| 802 | bssgp_msg_size += sizeof(qos_ie); |
| 803 | |
| 804 | if (ptmsi != GSM_RESERVED_TMSI) { |
| 805 | const uint32_t ptmsi_be = htonl(ptmsi); |
| 806 | msg[bssgp_msg_size] = BSSGP_IE_TMSI; |
| 807 | msg[bssgp_msg_size+1] = 0x84; |
| 808 | memcpy(msg + bssgp_msg_size + 2, &ptmsi_be, 4); |
| 809 | bssgp_msg_size += 6; |
| 810 | } |
| 811 | |
| 812 | send_ns_unitdata(nsi, "PAGING_PS", src_addr, 0, msg, bssgp_msg_size); |
| 813 | } |
| 814 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 815 | static void send_bssgp_flow_control_bvc(struct gprs_ns_inst *nsi, |
| 816 | struct sockaddr_in *src_addr, |
| 817 | uint16_t bvci, uint8_t tag) |
| 818 | { |
| 819 | /* GPRS Network Service, PDU type: NS_UNITDATA, |
| 820 | * BSSGP FLOW_CONTROL_BVC */ |
| 821 | unsigned char msg[] = { |
| 822 | 0x26, 0x1e, 0x81, /* Tag */ 0xff, 0x05, 0x82, 0x01, 0xdc, |
| 823 | 0x03, 0x82, 0x02, 0x76, 0x01, 0x82, 0x00, 0x50, |
| 824 | 0x1c, 0x82, 0x02, 0x58, 0x06, 0x82, 0x00, 0x03 |
| 825 | }; |
| 826 | |
| 827 | msg[3] = tag; |
| 828 | |
| 829 | send_ns_unitdata(nsi, "FLOW_CONTROL_BVC", src_addr, bvci, |
| 830 | msg, sizeof(msg)); |
| 831 | } |
| 832 | |
| 833 | static void send_bssgp_flow_control_bvc_ack(struct gprs_ns_inst *nsi, |
| 834 | struct sockaddr_in *src_addr, |
| 835 | uint16_t bvci, uint8_t tag) |
| 836 | { |
| 837 | /* GPRS Network Service, PDU type: NS_UNITDATA, |
| 838 | * BSSGP FLOW_CONTROL_BVC_ACK */ |
| 839 | unsigned char msg[] = { |
| 840 | 0x27, 0x1e, 0x81, /* Tag */ 0xce |
| 841 | }; |
| 842 | |
| 843 | msg[3] = tag; |
| 844 | |
| 845 | send_ns_unitdata(nsi, "FLOW_CONTROL_BVC_ACK", src_addr, bvci, |
| 846 | msg, sizeof(msg)); |
| 847 | } |
| 848 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 849 | static void send_llc_ul_ui( |
| 850 | struct gprs_ns_inst *nsi, const char *text, |
| 851 | struct sockaddr_in *src_addr, uint16_t nsbvci, uint32_t tlli, |
| 852 | struct gprs_ra_id *raid, uint16_t cell_id, |
| 853 | unsigned sapi, unsigned nu, |
| 854 | const uint8_t *msg, size_t msg_size) |
| 855 | { |
| 856 | unsigned char llc_msg[4096] = { |
| 857 | 0x00, 0xc0, 0x01 |
| 858 | }; |
| 859 | |
| 860 | size_t llc_msg_size = 3 + msg_size + 3; |
| 861 | uint8_t e_bit = 0; |
| 862 | uint8_t pm_bit = 1; |
| 863 | unsigned fcs; |
| 864 | |
| 865 | nu &= 0x01ff; |
| 866 | |
| 867 | OSMO_ASSERT(llc_msg_size <= sizeof(llc_msg)); |
| 868 | |
| 869 | llc_msg[0] = (sapi & 0x0f); |
| 870 | llc_msg[1] = 0xc0 | (nu >> 6); /* UI frame */ |
| 871 | llc_msg[2] = (nu << 2) | ((e_bit & 1) << 1) | (pm_bit & 1); |
| 872 | |
| 873 | memcpy(llc_msg + 3, msg, msg_size); |
| 874 | |
| 875 | fcs = gprs_llc_fcs(llc_msg, msg_size + 3); |
| 876 | llc_msg[3 + msg_size + 0] = (uint8_t)(fcs >> 0); |
| 877 | llc_msg[3 + msg_size + 1] = (uint8_t)(fcs >> 8); |
| 878 | llc_msg[3 + msg_size + 2] = (uint8_t)(fcs >> 16); |
| 879 | |
| 880 | send_bssgp_ul_unitdata(nsi, text ? text : "LLC UI", |
| 881 | src_addr, nsbvci, tlli, raid, cell_id, |
| 882 | llc_msg, llc_msg_size); |
| 883 | } |
| 884 | |
| 885 | static void send_llc_dl_ui( |
| 886 | struct gprs_ns_inst *nsi, const char *text, |
| 887 | struct sockaddr_in *src_addr, uint16_t nsbvci, uint32_t tlli, |
| 888 | int with_racap_drx, const uint8_t *imsi, size_t imsi_size, |
| 889 | unsigned sapi, unsigned nu, |
| 890 | const uint8_t *msg, size_t msg_size) |
| 891 | { |
| 892 | /* GPRS Network Service, PDU type: NS_UNITDATA */ |
| 893 | /* Base Station Subsystem GPRS Protocol: UL_UNITDATA */ |
| 894 | unsigned char llc_msg[4096] = { |
| 895 | 0x00, 0x00, 0x01 |
| 896 | }; |
| 897 | |
| 898 | size_t llc_msg_size = 3 + msg_size + 3; |
| 899 | uint8_t e_bit = 0; |
| 900 | uint8_t pm_bit = 1; |
| 901 | unsigned fcs; |
| 902 | |
| 903 | nu &= 0x01ff; |
| 904 | |
| 905 | OSMO_ASSERT(llc_msg_size <= sizeof(llc_msg)); |
| 906 | |
| 907 | llc_msg[0] = 0x40 | (sapi & 0x0f); |
| 908 | llc_msg[1] = 0xc0 | (nu >> 6); /* UI frame */ |
| 909 | llc_msg[2] = (nu << 2) | ((e_bit & 1) << 1) | (pm_bit & 1); |
| 910 | |
| 911 | memcpy(llc_msg + 3, msg, msg_size); |
| 912 | |
| 913 | fcs = gprs_llc_fcs(llc_msg, msg_size + 3); |
| 914 | llc_msg[3 + msg_size + 0] = (uint8_t)(fcs >> 0); |
| 915 | llc_msg[3 + msg_size + 1] = (uint8_t)(fcs >> 8); |
| 916 | llc_msg[3 + msg_size + 2] = (uint8_t)(fcs >> 16); |
| 917 | |
| 918 | send_bssgp_dl_unitdata(nsi, text ? text : "LLC UI", |
| 919 | src_addr, nsbvci, tlli, |
| 920 | with_racap_drx, imsi, imsi_size, |
| 921 | llc_msg, llc_msg_size); |
| 922 | } |
| 923 | |
| 924 | |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 925 | static void setup_ns(struct gprs_ns_inst *nsi, struct sockaddr_in *src_addr, |
| 926 | uint16_t nsvci, uint16_t nsei) |
| 927 | { |
| 928 | printf("Setup NS-VC: remote 0x%08x:%d, " |
| 929 | "NSVCI 0x%04x(%d), NSEI 0x%04x(%d)\n\n", |
| 930 | ntohl(src_addr->sin_addr.s_addr), ntohs(src_addr->sin_port), |
| 931 | nsvci, nsvci, nsei, nsei); |
| 932 | |
| 933 | send_ns_reset(nsi, src_addr, NS_CAUSE_OM_INTERVENTION, nsvci, nsei); |
| 934 | send_ns_alive(nsi, src_addr); |
| 935 | send_ns_unblock(nsi, src_addr); |
| 936 | send_ns_alive_ack(nsi, src_addr); |
| 937 | } |
| 938 | |
| 939 | static void setup_bssgp(struct gprs_ns_inst *nsi, struct sockaddr_in *src_addr, |
| 940 | uint16_t bvci) |
| 941 | { |
| 942 | printf("Setup BSSGP: remote 0x%08x:%d, " |
| 943 | "BVCI 0x%04x(%d)\n\n", |
| 944 | ntohl(src_addr->sin_addr.s_addr), ntohs(src_addr->sin_port), |
| 945 | bvci, bvci); |
| 946 | |
| 947 | send_bssgp_reset(nsi, src_addr, bvci); |
| 948 | } |
| 949 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 950 | static void connect_sgsn(struct gprs_ns_inst *nsi, struct sockaddr_in *sgsn_peer, |
| 951 | uint32_t sgsn_nsei) |
Jacob Erlbeck | 2e038f7 | 2014-07-07 10:46:00 +0200 | [diff] [blame] | 952 | { |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 953 | gprs_ns_nsip_connect(nsi, sgsn_peer, sgsn_nsei, sgsn_nsei+1); |
| 954 | send_ns_reset_ack(nsi, sgsn_peer, sgsn_nsei+1, sgsn_nsei); |
Jacob Erlbeck | 2e038f7 | 2014-07-07 10:46:00 +0200 | [diff] [blame] | 955 | send_ns_alive_ack(nsi, sgsn_peer); |
| 956 | send_ns_unblock_ack(nsi, sgsn_peer); |
| 957 | send_ns_alive(nsi, sgsn_peer); |
| 958 | } |
| 959 | |
Holger Hans Peter Freyther | 99a20d6 | 2014-07-07 14:19:10 +0200 | [diff] [blame] | 960 | static void configure_sgsn_peer(struct sockaddr_in *sgsn_peer) |
| 961 | { |
| 962 | sgsn_peer->sin_family = AF_INET; |
| 963 | sgsn_peer->sin_port = htons(32000); |
| 964 | sgsn_peer->sin_addr.s_addr = htonl(REMOTE_SGSN_ADDR); |
| 965 | } |
| 966 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 967 | static void configure_sgsn2_peer(struct sockaddr_in *sgsn_peer) |
| 968 | { |
| 969 | sgsn_peer->sin_family = AF_INET; |
| 970 | sgsn_peer->sin_port = htons(32001); |
| 971 | sgsn_peer->sin_addr.s_addr = htonl(REMOTE_SGSN2_ADDR); |
| 972 | } |
| 973 | |
Holger Hans Peter Freyther | 99a20d6 | 2014-07-07 14:19:10 +0200 | [diff] [blame] | 974 | static void configure_bss_peers(struct sockaddr_in *bss_peers, size_t size) |
| 975 | { |
| 976 | size_t i; |
| 977 | |
| 978 | for (i = 0; i < size; ++i) { |
| 979 | bss_peers[i].sin_family = AF_INET; |
| 980 | bss_peers[i].sin_port = htons((i + 1) * 1111); |
| 981 | bss_peers[i].sin_addr.s_addr = htonl(REMOTE_BSS_ADDR); |
| 982 | } |
| 983 | } |
| 984 | |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 985 | int gprs_ns_rcvmsg(struct gprs_ns_inst *nsi, struct msgb *msg, |
| 986 | struct sockaddr_in *saddr, enum gprs_ns_ll ll); |
| 987 | |
| 988 | /* override */ |
| 989 | int gprs_ns_callback(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, |
| 990 | struct msgb *msg, uint16_t bvci) |
| 991 | { |
Holger Hans Peter Freyther | daaea0c | 2015-08-03 09:28:41 +0200 | [diff] [blame] | 992 | printf("CALLBACK, event %d, msg length %zu, bvci 0x%04x\n%s\n\n", |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 993 | event, msgb_bssgp_len(msg), bvci, |
Jacob Erlbeck | ff0d65a | 2014-07-09 23:19:11 +0200 | [diff] [blame] | 994 | osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 995 | |
| 996 | switch (event) { |
| 997 | case GPRS_NS_EVT_UNIT_DATA: |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 998 | return gbprox_rcvmsg(&gbcfg, msg, nsvc->nsei, bvci, nsvc->nsvci); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 999 | default: |
| 1000 | break; |
| 1001 | } |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |
| 1005 | /* override */ |
| 1006 | ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, |
| 1007 | const struct sockaddr *dest_addr, socklen_t addrlen) |
| 1008 | { |
| 1009 | typedef ssize_t (*sendto_t)(int, const void *, size_t, int, |
| 1010 | const struct sockaddr *, socklen_t); |
| 1011 | static sendto_t real_sendto = NULL; |
| 1012 | uint32_t dest_host = htonl(((struct sockaddr_in *)dest_addr)->sin_addr.s_addr); |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1013 | int dest_port = htons(((struct sockaddr_in *)dest_addr)->sin_port); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1014 | |
| 1015 | if (!real_sendto) |
| 1016 | real_sendto = dlsym(RTLD_NEXT, "sendto"); |
| 1017 | |
| 1018 | if (dest_host == REMOTE_BSS_ADDR) |
Holger Hans Peter Freyther | 8e6ecc9 | 2015-04-23 11:55:23 -0400 | [diff] [blame] | 1019 | printf("MESSAGE to BSS at 0x%08x:%d, msg length %zu\n%s\n\n", |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1020 | dest_host, dest_port, |
| 1021 | len, osmo_hexdump(buf, len)); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1022 | else if (dest_host == REMOTE_SGSN_ADDR) |
Holger Hans Peter Freyther | 8e6ecc9 | 2015-04-23 11:55:23 -0400 | [diff] [blame] | 1023 | printf("MESSAGE to SGSN at 0x%08x:%d, msg length %zu\n%s\n\n", |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1024 | dest_host, dest_port, |
| 1025 | len, osmo_hexdump(buf, len)); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 1026 | else if (dest_host == REMOTE_SGSN2_ADDR) |
Holger Hans Peter Freyther | 8e6ecc9 | 2015-04-23 11:55:23 -0400 | [diff] [blame] | 1027 | printf("MESSAGE to SGSN 2 at 0x%08x:%d, msg length %zu\n%s\n\n", |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 1028 | dest_host, dest_port, |
| 1029 | len, osmo_hexdump(buf, len)); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1030 | else |
| 1031 | return real_sendto(sockfd, buf, len, flags, dest_addr, addrlen); |
| 1032 | |
| 1033 | return len; |
| 1034 | } |
| 1035 | |
| 1036 | /* override */ |
| 1037 | int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg) |
| 1038 | { |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1039 | typedef int (*gprs_ns_sendmsg_t)(struct gprs_ns_inst *nsi, struct msgb *msg); |
| 1040 | static gprs_ns_sendmsg_t real_gprs_ns_sendmsg = NULL; |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1041 | uint16_t bvci = msgb_bvci(msg); |
| 1042 | uint16_t nsei = msgb_nsei(msg); |
| 1043 | |
Jacob Erlbeck | ff0d65a | 2014-07-09 23:19:11 +0200 | [diff] [blame] | 1044 | size_t len = msgb_length(msg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1045 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1046 | if (!real_gprs_ns_sendmsg) |
| 1047 | real_gprs_ns_sendmsg = dlsym(RTLD_NEXT, "gprs_ns_sendmsg"); |
| 1048 | |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1049 | if (nsei == SGSN_NSEI) |
Jacob Erlbeck | ff0d65a | 2014-07-09 23:19:11 +0200 | [diff] [blame] | 1050 | printf("NS UNITDATA MESSAGE to SGSN, BVCI 0x%04x, " |
Holger Hans Peter Freyther | 8e6ecc9 | 2015-04-23 11:55:23 -0400 | [diff] [blame] | 1051 | "msg length %zu (%s)\n", |
Jacob Erlbeck | ff0d65a | 2014-07-09 23:19:11 +0200 | [diff] [blame] | 1052 | bvci, len, __func__); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 1053 | else if (nsei == SGSN2_NSEI) |
| 1054 | printf("NS UNITDATA MESSAGE to SGSN 2, BVCI 0x%04x, " |
Holger Hans Peter Freyther | 8e6ecc9 | 2015-04-23 11:55:23 -0400 | [diff] [blame] | 1055 | "msg length %zu (%s)\n", |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 1056 | bvci, len, __func__); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1057 | else |
Jacob Erlbeck | ff0d65a | 2014-07-09 23:19:11 +0200 | [diff] [blame] | 1058 | printf("NS UNITDATA MESSAGE to BSS, BVCI 0x%04x, " |
Holger Hans Peter Freyther | 8e6ecc9 | 2015-04-23 11:55:23 -0400 | [diff] [blame] | 1059 | "msg length %zu (%s)\n", |
Jacob Erlbeck | ff0d65a | 2014-07-09 23:19:11 +0200 | [diff] [blame] | 1060 | bvci, len, __func__); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1061 | |
Jacob Erlbeck | acfaff3 | 2014-09-22 18:54:34 +0200 | [diff] [blame] | 1062 | if (received_messages) { |
| 1063 | struct msgb *msg_copy; |
Pau Espin Pedrol | 816a67d | 2018-08-15 13:53:48 +0200 | [diff] [blame^] | 1064 | msg_copy = bssgp_msgb_copy(msg, "received_messages"); |
Jacob Erlbeck | acfaff3 | 2014-09-22 18:54:34 +0200 | [diff] [blame] | 1065 | llist_add_tail(&msg_copy->list, received_messages); |
| 1066 | } |
| 1067 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1068 | return real_gprs_ns_sendmsg(nsi, msg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1069 | } |
| 1070 | |
Jacob Erlbeck | acfaff3 | 2014-09-22 18:54:34 +0200 | [diff] [blame] | 1071 | /* Get the next message from the receive FIFO |
| 1072 | * |
| 1073 | * \returns a pointer to the message which will be invalidated at the next call |
| 1074 | * to expect_msg. Returns NULL, if there is no message left. |
| 1075 | */ |
| 1076 | static struct msgb *expect_msg(void) |
| 1077 | { |
| 1078 | static struct msgb *msg = NULL; |
| 1079 | |
| 1080 | msgb_free(msg); |
| 1081 | msg = NULL; |
| 1082 | |
| 1083 | if (!received_messages) |
| 1084 | return NULL; |
| 1085 | |
| 1086 | if (llist_empty(received_messages)) |
| 1087 | return NULL; |
| 1088 | |
| 1089 | msg = llist_entry(received_messages->next, struct msgb, list); |
| 1090 | llist_del(&msg->list); |
| 1091 | |
| 1092 | return msg; |
| 1093 | } |
| 1094 | |
| 1095 | struct expect_result { |
| 1096 | struct msgb *msg; |
| 1097 | struct gprs_gb_parse_context parse_ctx; |
| 1098 | }; |
| 1099 | |
| 1100 | static struct expect_result *expect_bssgp_msg( |
| 1101 | int match_nsei, int match_bvci, int match_pdu_type) |
| 1102 | { |
| 1103 | static struct expect_result result; |
| 1104 | static const struct expect_result empty_result = {0,}; |
| 1105 | static struct msgb *msg; |
| 1106 | uint16_t nsei; |
| 1107 | int rc; |
| 1108 | |
| 1109 | memcpy(&result, &empty_result, sizeof(result)); |
| 1110 | |
| 1111 | msg = expect_msg(); |
| 1112 | if (!msg) |
| 1113 | return NULL; |
| 1114 | |
| 1115 | nsei = msgb_nsei(msg); |
| 1116 | |
| 1117 | if (match_nsei != MATCH_ANY && match_nsei != nsei) { |
| 1118 | fprintf(stderr, "%s: NSEI mismatch (expected %u, got %u)\n", |
| 1119 | __func__, match_nsei, nsei); |
| 1120 | return NULL; |
| 1121 | } |
| 1122 | |
| 1123 | if (match_bvci != MATCH_ANY && match_bvci != msgb_bvci(msg)) { |
| 1124 | fprintf(stderr, "%s: BVCI mismatch (expected %u, got %u)\n", |
| 1125 | __func__, match_bvci, msgb_bvci(msg)); |
| 1126 | return NULL; |
| 1127 | } |
| 1128 | |
| 1129 | result.msg = msg; |
| 1130 | |
| 1131 | result.parse_ctx.to_bss = nsei != SGSN_NSEI && nsei != SGSN2_NSEI; |
| 1132 | result.parse_ctx.peer_nsei = nsei; |
| 1133 | |
| 1134 | if (!msgb_bssgph(msg)) { |
| 1135 | fprintf(stderr, "%s: Expected BSSGP\n", __func__); |
| 1136 | return NULL; |
| 1137 | } |
| 1138 | |
| 1139 | rc = gprs_gb_parse_bssgp(msgb_bssgph(msg), msgb_bssgp_len(msg), |
| 1140 | &result.parse_ctx); |
| 1141 | |
| 1142 | if (!rc) { |
| 1143 | fprintf(stderr, "%s: Failed to parse message\n", __func__); |
| 1144 | return NULL; |
| 1145 | } |
| 1146 | |
| 1147 | if (match_pdu_type != MATCH_ANY && |
| 1148 | match_pdu_type != result.parse_ctx.pdu_type) { |
| 1149 | fprintf(stderr, "%s: PDU type mismatch (expected %u, got %u)\n", |
| 1150 | __func__, match_pdu_type, result.parse_ctx.pdu_type); |
| 1151 | return NULL; |
| 1152 | } |
| 1153 | |
| 1154 | return &result; |
| 1155 | } |
| 1156 | |
| 1157 | static struct expect_result *expect_llc_msg( |
| 1158 | int match_nsei, int match_bvci, int match_sapi, int match_type) |
| 1159 | { |
| 1160 | static struct expect_result *result; |
| 1161 | |
| 1162 | result = expect_bssgp_msg(match_nsei, match_bvci, MATCH_ANY); |
| 1163 | if (!result) |
| 1164 | return NULL; |
| 1165 | |
| 1166 | if (!result->parse_ctx.llc) { |
| 1167 | fprintf(stderr, "%s: Expected LLC message\n", __func__); |
| 1168 | return NULL; |
| 1169 | } |
| 1170 | |
| 1171 | if (match_sapi != MATCH_ANY && |
| 1172 | match_sapi != result->parse_ctx.llc_hdr_parsed.sapi) { |
| 1173 | fprintf(stderr, "%s: LLC SAPI mismatch (expected %u, got %u)\n", |
| 1174 | __func__, match_sapi, result->parse_ctx.llc_hdr_parsed.sapi); |
| 1175 | return NULL; |
| 1176 | } |
| 1177 | |
| 1178 | if (match_type != MATCH_ANY && |
| 1179 | match_type != result->parse_ctx.llc_hdr_parsed.cmd) { |
| 1180 | fprintf(stderr, |
| 1181 | "%s: LLC command/type mismatch (expected %u, got %u)\n", |
| 1182 | __func__, match_type, result->parse_ctx.llc_hdr_parsed.cmd); |
| 1183 | return NULL; |
| 1184 | } |
| 1185 | |
| 1186 | return result; |
| 1187 | } |
| 1188 | |
| 1189 | static struct expect_result *expect_gmm_msg(int match_nsei, int match_bvci, |
| 1190 | int match_type) |
| 1191 | { |
| 1192 | static struct expect_result *result; |
| 1193 | |
| 1194 | result = expect_llc_msg(match_nsei, match_bvci, GPRS_SAPI_GMM, GPRS_LLC_UI); |
| 1195 | if (!result) |
| 1196 | return NULL; |
| 1197 | |
| 1198 | if (!result->parse_ctx.g48_hdr) { |
| 1199 | fprintf(stderr, "%s: Expected GSM 04.08 message\n", __func__); |
| 1200 | return NULL; |
| 1201 | } |
| 1202 | |
| 1203 | if (match_type != MATCH_ANY && |
| 1204 | match_type != result->parse_ctx.g48_hdr->msg_type) { |
| 1205 | fprintf(stderr, |
| 1206 | "%s: GSM 04.08 message type mismatch (expected %u, got %u)\n", |
| 1207 | __func__, match_type, result->parse_ctx.g48_hdr->msg_type); |
| 1208 | return NULL; |
| 1209 | } |
| 1210 | |
| 1211 | return result; |
| 1212 | } |
| 1213 | |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1214 | static void dump_rate_ctr_group(FILE *stream, const char *prefix, |
| 1215 | struct rate_ctr_group *ctrg) |
| 1216 | { |
| 1217 | unsigned int i; |
| 1218 | |
| 1219 | for (i = 0; i < ctrg->desc->num_ctr; i++) { |
| 1220 | struct rate_ctr *ctr = &ctrg->ctr[i]; |
| 1221 | if (ctr->current && !strchr(ctrg->desc->ctr_desc[i].name, '.')) |
| 1222 | fprintf(stream, " %s%s: %llu%s", |
| 1223 | prefix, ctrg->desc->ctr_desc[i].description, |
| 1224 | (long long)ctr->current, |
| 1225 | "\n"); |
| 1226 | }; |
| 1227 | } |
| 1228 | |
| 1229 | /* Signal handler for signals from NS layer */ |
| 1230 | static int test_signal(unsigned int subsys, unsigned int signal, |
| 1231 | void *handler_data, void *signal_data) |
| 1232 | { |
| 1233 | struct ns_signal_data *nssd = signal_data; |
| 1234 | int rc; |
| 1235 | |
| 1236 | if (subsys != SS_L_NS) |
| 1237 | return 0; |
| 1238 | |
| 1239 | switch (signal) { |
| 1240 | case S_NS_RESET: |
| 1241 | printf("==> got signal NS_RESET, NS-VC 0x%04x/%s\n", |
| 1242 | nssd->nsvc->nsvci, |
| 1243 | gprs_ns_ll_str(nssd->nsvc)); |
| 1244 | break; |
| 1245 | |
| 1246 | case S_NS_ALIVE_EXP: |
| 1247 | printf("==> got signal NS_ALIVE_EXP, NS-VC 0x%04x/%s\n", |
| 1248 | nssd->nsvc->nsvci, |
| 1249 | gprs_ns_ll_str(nssd->nsvc)); |
| 1250 | break; |
| 1251 | |
| 1252 | case S_NS_BLOCK: |
| 1253 | printf("==> got signal NS_BLOCK, NS-VC 0x%04x/%s\n", |
| 1254 | nssd->nsvc->nsvci, |
| 1255 | gprs_ns_ll_str(nssd->nsvc)); |
| 1256 | break; |
| 1257 | |
| 1258 | case S_NS_UNBLOCK: |
| 1259 | printf("==> got signal NS_UNBLOCK, NS-VC 0x%04x/%s\n", |
| 1260 | nssd->nsvc->nsvci, |
| 1261 | gprs_ns_ll_str(nssd->nsvc)); |
| 1262 | break; |
| 1263 | |
| 1264 | case S_NS_REPLACED: |
| 1265 | printf("==> got signal NS_REPLACED: 0x%04x/%s", |
| 1266 | nssd->nsvc->nsvci, |
| 1267 | gprs_ns_ll_str(nssd->nsvc)); |
| 1268 | printf(" -> 0x%04x/%s\n", |
| 1269 | nssd->old_nsvc->nsvci, |
| 1270 | gprs_ns_ll_str(nssd->old_nsvc)); |
| 1271 | break; |
| 1272 | |
| 1273 | default: |
| 1274 | printf("==> got signal %d, NS-VC 0x%04x/%s\n", signal, |
| 1275 | nssd->nsvc->nsvci, |
| 1276 | gprs_ns_ll_str(nssd->nsvc)); |
| 1277 | break; |
| 1278 | } |
| 1279 | printf("\n"); |
| 1280 | rc = gbprox_signal(subsys, signal, handler_data, signal_data); |
| 1281 | return rc; |
| 1282 | } |
| 1283 | |
| 1284 | static int gprs_process_message(struct gprs_ns_inst *nsi, const char *text, struct sockaddr_in *peer, const unsigned char* data, size_t data_len) |
| 1285 | { |
| 1286 | struct msgb *msg; |
| 1287 | int ret; |
| 1288 | if (data_len > NS_ALLOC_SIZE - NS_ALLOC_HEADROOM) { |
Holger Hans Peter Freyther | 8e6ecc9 | 2015-04-23 11:55:23 -0400 | [diff] [blame] | 1289 | fprintf(stderr, "message too long: %zu\n", data_len); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1290 | return -1; |
| 1291 | } |
| 1292 | |
| 1293 | msg = gprs_ns_msgb_alloc(); |
Neels Hofmeyr | c9ac20e | 2016-04-14 15:21:33 +0200 | [diff] [blame] | 1294 | OSMO_ASSERT(msg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1295 | memmove(msg->data, data, data_len); |
| 1296 | msg->l2h = msg->data; |
| 1297 | msgb_put(msg, data_len); |
| 1298 | |
| 1299 | printf("PROCESSING %s from 0x%08x:%d\n%s\n\n", |
| 1300 | text, ntohl(peer->sin_addr.s_addr), ntohs(peer->sin_port), |
| 1301 | osmo_hexdump(data, data_len)); |
| 1302 | |
| 1303 | ret = gprs_ns_rcvmsg(nsi, msg, peer, GPRS_NS_LL_UDP); |
| 1304 | |
| 1305 | printf("result (%s) = %d\n\n", text, ret); |
| 1306 | |
| 1307 | msgb_free(msg); |
| 1308 | |
| 1309 | return ret; |
| 1310 | } |
| 1311 | |
| 1312 | static void gprs_dump_nsi(struct gprs_ns_inst *nsi) |
| 1313 | { |
| 1314 | struct gprs_nsvc *nsvc; |
| 1315 | |
| 1316 | printf("Current NS-VCIs:\n"); |
| 1317 | llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { |
| 1318 | struct sockaddr_in *peer = &(nsvc->ip.bts_addr); |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1319 | printf(" VCI 0x%04x, NSEI 0x%04x, peer 0x%08x:%d%s%s\n", |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1320 | nsvc->nsvci, nsvc->nsei, |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1321 | ntohl(peer->sin_addr.s_addr), ntohs(peer->sin_port), |
| 1322 | nsvc->state & NSE_S_BLOCKED ? ", blocked" : "", |
| 1323 | nsvc->state & NSE_S_ALIVE ? "" : ", dead" |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1324 | ); |
| 1325 | dump_rate_ctr_group(stdout, " ", nsvc->ctrg); |
| 1326 | } |
| 1327 | printf("\n"); |
| 1328 | } |
| 1329 | |
| 1330 | static void test_gbproxy() |
| 1331 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 1332 | struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1333 | struct sockaddr_in bss_peer[4] = {{0},}; |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1334 | struct sockaddr_in sgsn_peer= {0}; |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1335 | |
| 1336 | bssgp_nsi = nsi; |
| 1337 | gbcfg.nsi = bssgp_nsi; |
| 1338 | gbcfg.nsip_sgsn_nsei = SGSN_NSEI; |
| 1339 | |
Holger Hans Peter Freyther | 99a20d6 | 2014-07-07 14:19:10 +0200 | [diff] [blame] | 1340 | configure_sgsn_peer(&sgsn_peer); |
| 1341 | configure_bss_peers(bss_peer, ARRAY_SIZE(bss_peer)); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1342 | |
Jacob Erlbeck | ff0d65a | 2014-07-09 23:19:11 +0200 | [diff] [blame] | 1343 | printf("=== %s ===\n", __func__); |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1344 | printf("--- Initialise SGSN ---\n\n"); |
| 1345 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 1346 | connect_sgsn(nsi, &sgsn_peer, SGSN_NSEI); |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1347 | gprs_dump_nsi(nsi); |
| 1348 | |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1349 | printf("--- Initialise BSS 1 ---\n\n"); |
| 1350 | |
| 1351 | setup_ns(nsi, &bss_peer[0], 0x1001, 0x1000); |
| 1352 | setup_bssgp(nsi, &bss_peer[0], 0x1002); |
| 1353 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1354 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1355 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1356 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002); |
| 1357 | |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1358 | printf("--- Initialise BSS 2 ---\n\n"); |
| 1359 | |
| 1360 | setup_ns(nsi, &bss_peer[1], 0x2001, 0x2000); |
| 1361 | setup_bssgp(nsi, &bss_peer[1], 0x2002); |
| 1362 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1363 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1364 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1365 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x2002); |
| 1366 | |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1367 | printf("--- Move BSS 1 to new port ---\n\n"); |
| 1368 | |
| 1369 | setup_ns(nsi, &bss_peer[2], 0x1001, 0x1000); |
| 1370 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1371 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1372 | |
| 1373 | printf("--- Move BSS 2 to former BSS 1 port ---\n\n"); |
| 1374 | |
| 1375 | setup_ns(nsi, &bss_peer[0], 0x2001, 0x2000); |
| 1376 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1377 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1378 | |
| 1379 | printf("--- Move BSS 1 to current BSS 2 port ---\n\n"); |
| 1380 | |
| 1381 | setup_ns(nsi, &bss_peer[0], 0x2001, 0x2000); |
| 1382 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1383 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1384 | |
| 1385 | printf("--- Move BSS 2 to new port ---\n\n"); |
| 1386 | |
| 1387 | setup_ns(nsi, &bss_peer[3], 0x2001, 0x2000); |
| 1388 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1389 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1390 | |
| 1391 | printf("--- Move BSS 2 to former BSS 1 port ---\n\n"); |
| 1392 | |
| 1393 | setup_ns(nsi, &bss_peer[2], 0x2001, 0x2000); |
| 1394 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1395 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1396 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1397 | printf("--- Move BSS 1 to original BSS 1 port ---\n\n"); |
| 1398 | |
| 1399 | setup_ns(nsi, &bss_peer[0], 0x1001, 0x1000); |
| 1400 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1401 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1402 | |
| 1403 | printf("--- Reset BSS 1 with a new BVCI ---\n\n"); |
| 1404 | |
| 1405 | setup_bssgp(nsi, &bss_peer[0], 0x1012); |
| 1406 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1407 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1408 | |
| 1409 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1012); |
| 1410 | |
| 1411 | printf("--- Reset BSS 1 with the old BVCI ---\n\n"); |
| 1412 | |
| 1413 | setup_bssgp(nsi, &bss_peer[0], 0x1002); |
| 1414 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1415 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1416 | |
| 1417 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002); |
| 1418 | |
| 1419 | printf("--- Reset BSS 1 with the old BVCI again ---\n\n"); |
| 1420 | |
| 1421 | setup_bssgp(nsi, &bss_peer[0], 0x1002); |
| 1422 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1423 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1424 | |
| 1425 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002); |
| 1426 | |
| 1427 | printf("--- Send message from BSS 1 to SGSN, BVCI 0x1012 ---\n\n"); |
| 1428 | |
| 1429 | send_ns_unitdata(nsi, NULL, &bss_peer[0], 0x1012, (uint8_t *)"", 0); |
| 1430 | |
| 1431 | printf("--- Send message from SGSN to BSS 1, BVCI 0x1012 ---\n\n"); |
| 1432 | |
| 1433 | send_ns_unitdata(nsi, NULL, &sgsn_peer, 0x1012, (uint8_t *)"", 0); |
| 1434 | |
| 1435 | printf("--- Send message from BSS 1 to SGSN, BVCI 0x1002 ---\n\n"); |
| 1436 | |
| 1437 | send_ns_unitdata(nsi, NULL, &bss_peer[0], 0x1012, (uint8_t *)"", 0); |
| 1438 | |
| 1439 | printf("--- Send message from SGSN to BSS 1, BVCI 0x1002 ---\n\n"); |
| 1440 | |
| 1441 | send_ns_unitdata(nsi, NULL, &sgsn_peer, 0x1012, (uint8_t *)"", 0); |
| 1442 | |
| 1443 | printf("--- Send message from BSS 2 to SGSN, BVCI 0x2002 ---\n\n"); |
| 1444 | |
| 1445 | send_ns_unitdata(nsi, NULL, &bss_peer[0], 0x2002, (uint8_t *)"", 0); |
| 1446 | |
| 1447 | printf("--- Send message from SGSN to BSS 2, BVCI 0x2002 ---\n\n"); |
| 1448 | |
| 1449 | send_ns_unitdata(nsi, NULL, &sgsn_peer, 0x2002, (uint8_t *)"", 0); |
| 1450 | |
| 1451 | printf("--- Reset BSS 1 with the old BVCI on BSS2's link ---\n\n"); |
| 1452 | |
| 1453 | setup_bssgp(nsi, &bss_peer[2], 0x1002); |
| 1454 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1455 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1456 | |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 1457 | dump_global(stdout, 0); |
Jacob Erlbeck | da890c7 | 2013-10-18 22:12:16 +0200 | [diff] [blame] | 1458 | |
Jacob Erlbeck | 2082afa | 2013-10-18 13:04:47 +0200 | [diff] [blame] | 1459 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002); |
| 1460 | |
| 1461 | printf("--- Send message from BSS 1 to SGSN, BVCI 0x1002 ---\n\n"); |
| 1462 | |
| 1463 | send_ns_unitdata(nsi, NULL, &bss_peer[0], 0x1012, (uint8_t *)"", 0); |
| 1464 | |
| 1465 | printf("--- Send message from SGSN to BSS 1, BVCI 0x1002 ---\n\n"); |
| 1466 | |
| 1467 | send_ns_unitdata(nsi, NULL, &sgsn_peer, 0x1012, (uint8_t *)"", 0); |
| 1468 | |
Jacob Erlbeck | da890c7 | 2013-10-18 22:12:16 +0200 | [diff] [blame] | 1469 | printf("--- Send message from SGSN to BSS 1, BVCI 0x10ff (invalid) ---\n\n"); |
| 1470 | |
| 1471 | send_ns_unitdata(nsi, NULL, &sgsn_peer, 0x10ff, (uint8_t *)"", 0); |
| 1472 | |
Jacob Erlbeck | 7fb26c2 | 2014-09-04 11:08:50 +0200 | [diff] [blame] | 1473 | /* Find peer */ |
| 1474 | OSMO_ASSERT(gbproxy_peer_by_bvci(&gbcfg, 0xeeee) == NULL); |
| 1475 | OSMO_ASSERT(gbproxy_peer_by_bvci(&gbcfg, 0x1000) == NULL); |
| 1476 | OSMO_ASSERT(gbproxy_peer_by_bvci(&gbcfg, 0x1012) != NULL); |
| 1477 | OSMO_ASSERT(gbproxy_peer_by_nsei(&gbcfg, 0xeeee) == NULL); |
| 1478 | OSMO_ASSERT(gbproxy_peer_by_nsei(&gbcfg, 0x1012) == NULL); |
| 1479 | OSMO_ASSERT(gbproxy_peer_by_nsei(&gbcfg, 0x1000) != NULL); |
| 1480 | |
| 1481 | |
| 1482 | /* Cleanup */ |
| 1483 | OSMO_ASSERT(gbproxy_cleanup_peers(&gbcfg, 0, 0) == 0); |
| 1484 | OSMO_ASSERT(gbproxy_cleanup_peers(&gbcfg, 0x1000, 0xeeee) == 0); |
| 1485 | OSMO_ASSERT(gbproxy_cleanup_peers(&gbcfg, 0, 0x1002) == 0); |
| 1486 | OSMO_ASSERT(gbproxy_cleanup_peers(&gbcfg, 0x1000, 0x1012) == 1); |
| 1487 | OSMO_ASSERT(gbproxy_cleanup_peers(&gbcfg, 0x1000, 0x1012) == 0); |
| 1488 | |
| 1489 | dump_peers(stdout, 0, 0, &gbcfg); |
| 1490 | |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 1491 | dump_global(stdout, 0); |
Jacob Erlbeck | da890c7 | 2013-10-18 22:12:16 +0200 | [diff] [blame] | 1492 | |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 1493 | gbprox_reset(&gbcfg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1494 | gprs_ns_destroy(nsi); |
| 1495 | nsi = NULL; |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | static void test_gbproxy_ident_changes() |
| 1499 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 1500 | struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1501 | struct sockaddr_in bss_peer[1] = {{0},}; |
| 1502 | struct sockaddr_in sgsn_peer= {0}; |
| 1503 | uint16_t nsei[2] = {0x1000, 0x2000}; |
| 1504 | uint16_t nsvci[2] = {0x1001, 0x2001}; |
| 1505 | uint16_t bvci[4] = {0x1002, 0x2002, 0x3002, 0x4002}; |
| 1506 | |
| 1507 | bssgp_nsi = nsi; |
| 1508 | gbcfg.nsi = bssgp_nsi; |
| 1509 | gbcfg.nsip_sgsn_nsei = SGSN_NSEI; |
| 1510 | |
Holger Hans Peter Freyther | 99a20d6 | 2014-07-07 14:19:10 +0200 | [diff] [blame] | 1511 | configure_sgsn_peer(&sgsn_peer); |
| 1512 | configure_bss_peers(bss_peer, ARRAY_SIZE(bss_peer)); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1513 | |
Jacob Erlbeck | ff0d65a | 2014-07-09 23:19:11 +0200 | [diff] [blame] | 1514 | printf("=== %s ===\n", __func__); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1515 | printf("--- Initialise SGSN ---\n\n"); |
| 1516 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 1517 | connect_sgsn(nsi, &sgsn_peer, SGSN_NSEI); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1518 | gprs_dump_nsi(nsi); |
| 1519 | |
| 1520 | printf("--- Initialise BSS 1 ---\n\n"); |
| 1521 | |
| 1522 | setup_ns(nsi, &bss_peer[0], nsvci[0], nsei[0]); |
| 1523 | gprs_dump_nsi(nsi); |
| 1524 | |
| 1525 | printf("--- Setup BVCI 1 ---\n\n"); |
| 1526 | |
| 1527 | setup_bssgp(nsi, &bss_peer[0], bvci[0]); |
| 1528 | send_bssgp_reset_ack(nsi, &sgsn_peer, bvci[0]); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1529 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1530 | |
| 1531 | printf("--- Setup BVCI 2 ---\n\n"); |
| 1532 | |
| 1533 | setup_bssgp(nsi, &bss_peer[0], bvci[1]); |
| 1534 | send_bssgp_reset_ack(nsi, &sgsn_peer, bvci[1]); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1535 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1536 | |
| 1537 | printf("--- Send message from BSS 1 to SGSN and back, BVCI 1 ---\n\n"); |
| 1538 | |
| 1539 | send_ns_unitdata(nsi, NULL, &bss_peer[0], bvci[0], (uint8_t *)"", 0); |
| 1540 | send_ns_unitdata(nsi, NULL, &sgsn_peer, bvci[0], (uint8_t *)"", 0); |
| 1541 | |
| 1542 | printf("--- Send message from BSS 1 to SGSN and back, BVCI 2 ---\n\n"); |
| 1543 | |
| 1544 | send_ns_unitdata(nsi, NULL, &bss_peer[0], bvci[1], (uint8_t *)"", 0); |
| 1545 | send_ns_unitdata(nsi, NULL, &sgsn_peer, bvci[1], (uint8_t *)"", 0); |
| 1546 | |
| 1547 | printf("--- Change NSEI ---\n\n"); |
| 1548 | |
| 1549 | setup_ns(nsi, &bss_peer[0], nsvci[0], nsei[1]); |
| 1550 | gprs_dump_nsi(nsi); |
| 1551 | |
| 1552 | printf("--- Setup BVCI 1 ---\n\n"); |
| 1553 | |
| 1554 | setup_bssgp(nsi, &bss_peer[0], bvci[0]); |
| 1555 | send_bssgp_reset_ack(nsi, &sgsn_peer, bvci[0]); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1556 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1557 | |
| 1558 | printf("--- Setup BVCI 3 ---\n\n"); |
| 1559 | |
| 1560 | setup_bssgp(nsi, &bss_peer[0], bvci[2]); |
| 1561 | send_bssgp_reset_ack(nsi, &sgsn_peer, bvci[2]); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1562 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1563 | |
| 1564 | printf("--- Send message from BSS 1 to SGSN and back, BVCI 1 ---\n\n"); |
| 1565 | |
| 1566 | send_ns_unitdata(nsi, NULL, &bss_peer[0], bvci[0], (uint8_t *)"", 0); |
| 1567 | send_ns_unitdata(nsi, NULL, &sgsn_peer, bvci[0], (uint8_t *)"", 0); |
| 1568 | |
| 1569 | printf("--- Send message from BSS 1 to SGSN and back, BVCI 2 " |
| 1570 | " (should fail) ---\n\n"); |
| 1571 | |
| 1572 | send_ns_unitdata(nsi, NULL, &bss_peer[0], bvci[1], (uint8_t *)"", 0); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1573 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1574 | send_ns_unitdata(nsi, NULL, &sgsn_peer, bvci[1], (uint8_t *)"", 0); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1575 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1576 | |
| 1577 | printf("--- Send message from BSS 1 to SGSN and back, BVCI 3 ---\n\n"); |
| 1578 | |
| 1579 | send_ns_unitdata(nsi, NULL, &bss_peer[0], bvci[2], (uint8_t *)"", 0); |
| 1580 | send_ns_unitdata(nsi, NULL, &sgsn_peer, bvci[2], (uint8_t *)"", 0); |
| 1581 | |
| 1582 | printf("--- Change NSVCI ---\n\n"); |
| 1583 | |
| 1584 | setup_ns(nsi, &bss_peer[0], nsvci[1], nsei[1]); |
| 1585 | gprs_dump_nsi(nsi); |
| 1586 | |
| 1587 | printf("--- Setup BVCI 1 ---\n\n"); |
| 1588 | |
| 1589 | setup_bssgp(nsi, &bss_peer[0], bvci[0]); |
| 1590 | send_bssgp_reset_ack(nsi, &sgsn_peer, bvci[0]); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1591 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1592 | |
| 1593 | printf("--- Setup BVCI 4 ---\n\n"); |
| 1594 | |
| 1595 | setup_bssgp(nsi, &bss_peer[0], bvci[3]); |
| 1596 | send_bssgp_reset_ack(nsi, &sgsn_peer, bvci[3]); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1597 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1598 | |
| 1599 | printf("--- Send message from BSS 1 to SGSN and back, BVCI 1 ---\n\n"); |
| 1600 | |
| 1601 | send_ns_unitdata(nsi, NULL, &bss_peer[0], bvci[0], (uint8_t *)"", 0); |
| 1602 | send_ns_unitdata(nsi, NULL, &sgsn_peer, bvci[0], (uint8_t *)"", 0); |
| 1603 | |
| 1604 | printf("--- Send message from BSS 1 to SGSN and back, BVCI 2 " |
| 1605 | " (should fail) ---\n\n"); |
| 1606 | |
| 1607 | send_ns_unitdata(nsi, NULL, &bss_peer[0], bvci[1], (uint8_t *)"", 0); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1608 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1609 | send_ns_unitdata(nsi, NULL, &sgsn_peer, bvci[1], (uint8_t *)"", 0); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1610 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1611 | |
| 1612 | printf("--- Send message from BSS 1 to SGSN and back, BVCI 3 ---\n\n"); |
| 1613 | |
| 1614 | send_ns_unitdata(nsi, NULL, &bss_peer[0], bvci[2], (uint8_t *)"", 0); |
| 1615 | send_ns_unitdata(nsi, NULL, &sgsn_peer, bvci[2], (uint8_t *)"", 0); |
| 1616 | |
| 1617 | printf("--- Send message from BSS 1 to SGSN and back, BVCI 4 ---\n\n"); |
| 1618 | |
| 1619 | send_ns_unitdata(nsi, NULL, &bss_peer[0], bvci[3], (uint8_t *)"", 0); |
| 1620 | send_ns_unitdata(nsi, NULL, &sgsn_peer, bvci[3], (uint8_t *)"", 0); |
| 1621 | |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 1622 | dump_global(stdout, 0); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1623 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1624 | |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 1625 | gbprox_reset(&gbcfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1626 | gprs_ns_destroy(nsi); |
| 1627 | nsi = NULL; |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 1628 | } |
| 1629 | |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1630 | static void test_gbproxy_ra_patching() |
| 1631 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 1632 | struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1633 | struct sockaddr_in bss_peer[1] = {{0},}; |
| 1634 | struct sockaddr_in sgsn_peer= {0}; |
| 1635 | struct gprs_ra_id rai_bss = |
| 1636 | {.mcc = 112, .mnc = 332, .lac = 16464, .rac = 96}; |
| 1637 | struct gprs_ra_id rai_sgsn = |
| 1638 | {.mcc = 123, .mnc = 456, .lac = 16464, .rac = 96}; |
| 1639 | struct gprs_ra_id rai_unknown = |
| 1640 | {.mcc = 1, .mnc = 99, .lac = 99, .rac = 96}; |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1641 | uint16_t cell_id = 0x7530; |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 1642 | const char *err_msg = NULL; |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 1643 | const uint32_t ptmsi = 0xefe2b700; |
| 1644 | const uint32_t local_tlli = 0xefe2b700; |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1645 | const uint32_t foreign_tlli = 0xbbc54679; |
Jacob Erlbeck | 991606b | 2014-09-12 10:33:38 +0200 | [diff] [blame] | 1646 | const uint32_t foreign_tlli2 = 0xbb00beef; |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1647 | const uint8_t imsi[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}; |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 1648 | const char *patch_re = "^9898|^121314"; |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 1649 | struct gbproxy_link_info *link_info; |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 1650 | struct gbproxy_peer *peer; |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1651 | LLIST_HEAD(rcv_list); |
Jacob Erlbeck | c79beec | 2014-10-10 09:48:12 +0200 | [diff] [blame] | 1652 | struct expect_result *expect_res; |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 1653 | |
| 1654 | OSMO_ASSERT(local_tlli == gprs_tmsi2tlli(ptmsi, TLLI_LOCAL)); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1655 | |
| 1656 | bssgp_nsi = nsi; |
| 1657 | gbcfg.nsi = bssgp_nsi; |
| 1658 | gbcfg.nsip_sgsn_nsei = SGSN_NSEI; |
Neels Hofmeyr | 10719b7 | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 1659 | gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 }; |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 1660 | gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); |
Holger Hans Peter Freyther | ce1b22e | 2014-08-04 14:22:13 +0200 | [diff] [blame] | 1661 | gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); |
Jacob Erlbeck | 9057bc3 | 2014-08-12 16:30:30 +0200 | [diff] [blame] | 1662 | gbcfg.patch_ptmsi = 0; |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1663 | |
Holger Hans Peter Freyther | 99a20d6 | 2014-07-07 14:19:10 +0200 | [diff] [blame] | 1664 | configure_sgsn_peer(&sgsn_peer); |
| 1665 | configure_bss_peers(bss_peer, ARRAY_SIZE(bss_peer)); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1666 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 1667 | if (gbproxy_set_patch_filter(&gbcfg.matches[GBPROX_MATCH_PATCHING], |
| 1668 | patch_re, &err_msg) != 0) { |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 1669 | fprintf(stderr, "Failed to compile RE '%s': %s\n", |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 1670 | patch_re, err_msg); |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 1671 | exit(1); |
| 1672 | } |
| 1673 | |
| 1674 | |
Jacob Erlbeck | ff0d65a | 2014-07-09 23:19:11 +0200 | [diff] [blame] | 1675 | printf("=== %s ===\n", __func__); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1676 | printf("--- Initialise SGSN ---\n\n"); |
| 1677 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 1678 | connect_sgsn(nsi, &sgsn_peer, SGSN_NSEI); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1679 | gprs_dump_nsi(nsi); |
| 1680 | |
| 1681 | printf("--- Initialise BSS 1 ---\n\n"); |
| 1682 | |
| 1683 | setup_ns(nsi, &bss_peer[0], 0x1001, 0x1000); |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1684 | |
| 1685 | received_messages = &rcv_list; |
| 1686 | |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1687 | setup_bssgp(nsi, &bss_peer[0], 0x1002); |
| 1688 | gprs_dump_nsi(nsi); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1689 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1690 | |
Jacob Erlbeck | 5f1faa3 | 2014-08-21 10:01:30 +0200 | [diff] [blame] | 1691 | peer = gbproxy_peer_by_nsei(&gbcfg, 0x1000); |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 1692 | OSMO_ASSERT(peer != NULL); |
| 1693 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1694 | OSMO_ASSERT(expect_bssgp_msg(SGSN_NSEI, 0, BSSGP_PDUT_BVC_RESET)); |
| 1695 | |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1696 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002); |
| 1697 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1698 | OSMO_ASSERT(expect_bssgp_msg(0x1000, 0, BSSGP_PDUT_BVC_RESET_ACK)); |
| 1699 | |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 1700 | send_bssgp_suspend(nsi, &bss_peer[0], 0xccd1758b, &rai_bss); |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1701 | |
| 1702 | OSMO_ASSERT(expect_bssgp_msg(SGSN_NSEI, 0, BSSGP_PDUT_SUSPEND)); |
| 1703 | |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 1704 | send_bssgp_suspend_ack(nsi, &sgsn_peer, 0xccd1758b, &rai_sgsn); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1705 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1706 | OSMO_ASSERT(expect_bssgp_msg(0x1000, 0, BSSGP_PDUT_SUSPEND_ACK)); |
| 1707 | |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 1708 | dump_global(stdout, 0); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1709 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1710 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1711 | OSMO_ASSERT(2 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
| 1712 | OSMO_ASSERT(1 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_SGSN].current); |
| 1713 | |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1714 | printf("--- Send message from BSS 1 to SGSN, BVCI 0x1002 ---\n\n"); |
| 1715 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1716 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 1717 | foreign_tlli, &rai_bss, cell_id, |
| 1718 | GPRS_SAPI_GMM, 0, |
| 1719 | dtap_attach_req, sizeof(dtap_attach_req)); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1720 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1721 | OSMO_ASSERT(4 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1722 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1723 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1724 | send_llc_dl_ui(nsi, "IDENT REQUEST", &sgsn_peer, 0x1002, |
| 1725 | foreign_tlli, 0, NULL, 0, |
| 1726 | GPRS_SAPI_GMM, 0, |
| 1727 | dtap_identity_req, sizeof(dtap_identity_req)); |
Jacob Erlbeck | 690768a | 2014-08-06 15:16:45 +0200 | [diff] [blame] | 1728 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1729 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ID_REQ)); |
| 1730 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1731 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 1732 | foreign_tlli, &rai_bss, cell_id, |
| 1733 | GPRS_SAPI_GMM, 3, |
| 1734 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
Jacob Erlbeck | 690768a | 2014-08-06 15:16:45 +0200 | [diff] [blame] | 1735 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1736 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ID_RESP)); |
| 1737 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1738 | OSMO_ASSERT(5 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
| 1739 | OSMO_ASSERT(1 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_SGSN].current); |
| 1740 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1741 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 1742 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 1743 | GPRS_SAPI_GMM, 1, |
| 1744 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1745 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1746 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 1747 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1748 | OSMO_ASSERT(2 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_SGSN].current); |
| 1749 | |
Jacob Erlbeck | 7fb26c2 | 2014-09-04 11:08:50 +0200 | [diff] [blame] | 1750 | OSMO_ASSERT(gbproxy_peer_by_rai(&gbcfg, convert_ra(&rai_bss)) != NULL); |
| 1751 | OSMO_ASSERT(gbproxy_peer_by_rai(&gbcfg, convert_ra(&rai_sgsn)) == NULL); |
| 1752 | OSMO_ASSERT(gbproxy_peer_by_rai(&gbcfg, convert_ra(&rai_unknown)) == NULL); |
| 1753 | |
| 1754 | OSMO_ASSERT(gbproxy_peer_by_lai(&gbcfg, convert_ra(&rai_bss)) != NULL); |
| 1755 | OSMO_ASSERT(gbproxy_peer_by_lai(&gbcfg, convert_ra(&rai_sgsn)) == NULL); |
| 1756 | OSMO_ASSERT(gbproxy_peer_by_lai(&gbcfg, convert_ra(&rai_unknown)) == NULL); |
| 1757 | |
| 1758 | OSMO_ASSERT(gbproxy_peer_by_lac(&gbcfg, convert_ra(&rai_bss)) != NULL); |
| 1759 | OSMO_ASSERT(gbproxy_peer_by_lac(&gbcfg, convert_ra(&rai_sgsn)) != NULL); |
| 1760 | OSMO_ASSERT(gbproxy_peer_by_lac(&gbcfg, convert_ra(&rai_unknown)) == NULL); |
| 1761 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 1762 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_tlli, SGSN_NSEI); |
| 1763 | OSMO_ASSERT(link_info); |
| 1764 | OSMO_ASSERT(link_info->tlli.assigned == local_tlli); |
| 1765 | OSMO_ASSERT(link_info->tlli.current != local_tlli); |
| 1766 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 1767 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 1768 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_tlli); |
| 1769 | OSMO_ASSERT(link_info->sgsn_tlli.current != local_tlli); |
| 1770 | OSMO_ASSERT(!link_info->sgsn_tlli.bss_validated); |
| 1771 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 1772 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1773 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 1774 | local_tlli, &rai_bss, cell_id, |
| 1775 | GPRS_SAPI_GMM, 4, |
| 1776 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 1777 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1778 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 1779 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1780 | OSMO_ASSERT(6 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
| 1781 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 1782 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_tlli, SGSN_NSEI); |
| 1783 | OSMO_ASSERT(link_info); |
| 1784 | OSMO_ASSERT(link_info->tlli.assigned == local_tlli); |
| 1785 | OSMO_ASSERT(link_info->tlli.current != local_tlli); |
| 1786 | OSMO_ASSERT(link_info->tlli.bss_validated); |
| 1787 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 1788 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_tlli); |
| 1789 | OSMO_ASSERT(link_info->sgsn_tlli.current != local_tlli); |
| 1790 | OSMO_ASSERT(link_info->sgsn_tlli.bss_validated); |
| 1791 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 1792 | |
Jacob Erlbeck | aa3e334 | 2014-06-27 11:55:04 +0200 | [diff] [blame] | 1793 | /* Replace APN (1) */ |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1794 | send_llc_ul_ui(nsi, "ACT PDP CTX REQ (REPLACE APN)", &bss_peer[0], 0x1002, |
| 1795 | local_tlli, &rai_bss, cell_id, |
| 1796 | GPRS_SAPI_GMM, 3, |
| 1797 | dtap_act_pdp_ctx_req, sizeof(dtap_act_pdp_ctx_req)); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1798 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1799 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GSM_ACT_PDP_REQ)); |
| 1800 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1801 | OSMO_ASSERT(7 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
| 1802 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 1803 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_tlli, SGSN_NSEI); |
| 1804 | OSMO_ASSERT(link_info); |
| 1805 | OSMO_ASSERT(link_info->tlli.assigned == local_tlli); |
| 1806 | OSMO_ASSERT(link_info->tlli.current != local_tlli); |
| 1807 | OSMO_ASSERT(link_info->tlli.bss_validated); |
| 1808 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 1809 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_tlli); |
| 1810 | OSMO_ASSERT(link_info->sgsn_tlli.current != local_tlli); |
| 1811 | OSMO_ASSERT(link_info->sgsn_tlli.bss_validated); |
| 1812 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 1813 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1814 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 1815 | local_tlli, 1, imsi, sizeof(imsi), |
| 1816 | GPRS_SAPI_GMM, 2, |
| 1817 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
Jacob Erlbeck | 1166974 | 2014-06-06 18:47:36 +0200 | [diff] [blame] | 1818 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1819 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_INFO)); |
| 1820 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1821 | OSMO_ASSERT(2 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_SGSN].current); |
| 1822 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 1823 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_tlli, SGSN_NSEI); |
| 1824 | OSMO_ASSERT(link_info); |
| 1825 | OSMO_ASSERT(link_info->tlli.assigned == 0); |
| 1826 | OSMO_ASSERT(link_info->tlli.current == local_tlli); |
| 1827 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == 0); |
| 1828 | OSMO_ASSERT(link_info->sgsn_tlli.current == local_tlli); |
Jacob Erlbeck | 59748e6 | 2014-08-11 17:26:21 +0200 | [diff] [blame] | 1829 | |
Jacob Erlbeck | aa3e334 | 2014-06-27 11:55:04 +0200 | [diff] [blame] | 1830 | /* Replace APN (2) */ |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1831 | send_llc_ul_ui(nsi, "ACT PDP CTX REQ (REPLACE APN)", &bss_peer[0], 0x1002, |
| 1832 | local_tlli, &rai_bss, cell_id, |
| 1833 | GPRS_SAPI_GMM, 3, |
| 1834 | dtap_act_pdp_ctx_req, sizeof(dtap_act_pdp_ctx_req)); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1835 | |
Jacob Erlbeck | c79beec | 2014-10-10 09:48:12 +0200 | [diff] [blame] | 1836 | expect_res = expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GSM_ACT_PDP_REQ); |
| 1837 | OSMO_ASSERT(expect_res != NULL); |
| 1838 | OSMO_ASSERT(expect_res->parse_ctx.apn_ie_len == gbcfg.core_apn_size + 2); |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1839 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1840 | OSMO_ASSERT(8 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
| 1841 | |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 1842 | gbcfg.core_apn[0] = 0; |
| 1843 | gbcfg.core_apn_size = 0; |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1844 | |
| 1845 | /* Remove APN */ |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1846 | send_llc_ul_ui(nsi, "ACT PDP CTX REQ (REMOVE APN)", &bss_peer[0], 0x1002, |
| 1847 | local_tlli, &rai_bss, cell_id, |
| 1848 | GPRS_SAPI_GMM, 3, |
| 1849 | dtap_act_pdp_ctx_req, sizeof(dtap_act_pdp_ctx_req)); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1850 | |
Jacob Erlbeck | c79beec | 2014-10-10 09:48:12 +0200 | [diff] [blame] | 1851 | expect_res = expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GSM_ACT_PDP_REQ); |
| 1852 | OSMO_ASSERT(expect_res != NULL); |
| 1853 | OSMO_ASSERT(expect_res->parse_ctx.apn_ie_len == 0); |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1854 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1855 | OSMO_ASSERT(9 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
| 1856 | |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1857 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | aa3e334 | 2014-06-27 11:55:04 +0200 | [diff] [blame] | 1858 | |
Jacob Erlbeck | cf02eb1 | 2014-06-19 10:23:50 +0200 | [diff] [blame] | 1859 | /* Detach */ |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1860 | send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002, |
| 1861 | local_tlli, &rai_bss, cell_id, |
| 1862 | GPRS_SAPI_GMM, 6, |
| 1863 | dtap_detach_req, sizeof(dtap_detach_req)); |
Jacob Erlbeck | cf02eb1 | 2014-06-19 10:23:50 +0200 | [diff] [blame] | 1864 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1865 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_DETACH_REQ)); |
| 1866 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1867 | OSMO_ASSERT(10 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
| 1868 | OSMO_ASSERT(2 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_SGSN].current); |
| 1869 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1870 | send_llc_dl_ui(nsi, "DETACH ACC", &sgsn_peer, 0x1002, |
| 1871 | local_tlli, 1, imsi, sizeof(imsi), |
| 1872 | GPRS_SAPI_GMM, 5, |
| 1873 | dtap_detach_acc, sizeof(dtap_detach_acc)); |
Jacob Erlbeck | cf02eb1 | 2014-06-19 10:23:50 +0200 | [diff] [blame] | 1874 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1875 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_DETACH_ACK)); |
| 1876 | |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1877 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | aa3e334 | 2014-06-27 11:55:04 +0200 | [diff] [blame] | 1878 | |
| 1879 | printf("--- RA update ---\n\n"); |
| 1880 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1881 | send_llc_ul_ui(nsi, "RA UPD REQ", &bss_peer[0], 0x1002, |
| 1882 | foreign_tlli, &rai_bss, 0x7080, |
| 1883 | GPRS_SAPI_GMM, 5, |
| 1884 | dtap_ra_upd_req, sizeof(dtap_ra_upd_req)); |
Jacob Erlbeck | aa3e334 | 2014-06-27 11:55:04 +0200 | [diff] [blame] | 1885 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1886 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_RA_UPD_REQ)); |
| 1887 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1888 | OSMO_ASSERT(12 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
| 1889 | |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1890 | send_llc_dl_ui(nsi, "RA UPD ACC", &sgsn_peer, 0x1002, |
| 1891 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 1892 | GPRS_SAPI_GMM, 6, |
| 1893 | dtap_ra_upd_acc, sizeof(dtap_ra_upd_acc)); |
Jacob Erlbeck | aa3e334 | 2014-06-27 11:55:04 +0200 | [diff] [blame] | 1894 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1895 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_RA_UPD_ACK)); |
| 1896 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1897 | OSMO_ASSERT(3 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_SGSN].current); |
| 1898 | |
Jacob Erlbeck | aa3e334 | 2014-06-27 11:55:04 +0200 | [diff] [blame] | 1899 | /* Remove APN */ |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1900 | send_llc_ul_ui(nsi, "ACT PDP CTX REQ (REMOVE APN)", &bss_peer[0], 0x1002, |
| 1901 | local_tlli, &rai_bss, cell_id, |
| 1902 | GPRS_SAPI_GMM, 3, |
| 1903 | dtap_act_pdp_ctx_req, sizeof(dtap_act_pdp_ctx_req)); |
Jacob Erlbeck | aa3e334 | 2014-06-27 11:55:04 +0200 | [diff] [blame] | 1904 | |
Jacob Erlbeck | c79beec | 2014-10-10 09:48:12 +0200 | [diff] [blame] | 1905 | expect_res = expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GSM_ACT_PDP_REQ); |
| 1906 | OSMO_ASSERT(expect_res != NULL); |
| 1907 | OSMO_ASSERT(expect_res->parse_ctx.apn_ie_len == 0); |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1908 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1909 | OSMO_ASSERT(13 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
| 1910 | |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1911 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | aa3e334 | 2014-06-27 11:55:04 +0200 | [diff] [blame] | 1912 | |
Jacob Erlbeck | 3e23ddf | 2014-08-11 15:07:37 +0200 | [diff] [blame] | 1913 | /* Detach (power off -> no Detach Accept) */ |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1914 | send_llc_ul_ui(nsi, "DETACH REQ (PWR OFF)", &bss_peer[0], 0x1002, |
| 1915 | local_tlli, &rai_bss, cell_id, |
| 1916 | GPRS_SAPI_GMM, 6, |
| 1917 | dtap_detach_po_req, sizeof(dtap_detach_po_req)); |
Jacob Erlbeck | aa3e334 | 2014-06-27 11:55:04 +0200 | [diff] [blame] | 1918 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1919 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_DETACH_REQ)); |
| 1920 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1921 | OSMO_ASSERT(14 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
| 1922 | |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 1923 | dump_global(stdout, 0); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1924 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1925 | |
| 1926 | printf("--- Bad cases ---\n\n"); |
| 1927 | |
Jacob Erlbeck | 991606b | 2014-09-12 10:33:38 +0200 | [diff] [blame] | 1928 | /* The RAI in the Attach Request message differs from the RAI in the |
| 1929 | * BSSGP message, only patch the latter */ |
| 1930 | |
| 1931 | send_llc_ul_ui(nsi, "ATTACH REQUEST (foreign RAI)", &bss_peer[0], 0x1002, |
| 1932 | foreign_tlli2, &rai_bss, cell_id, |
| 1933 | GPRS_SAPI_GMM, 0, |
| 1934 | dtap_attach_req2, sizeof(dtap_attach_req2)); |
| 1935 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1936 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 1937 | |
Jacob Erlbeck | 948c07f | 2014-09-11 15:22:18 +0200 | [diff] [blame] | 1938 | OSMO_ASSERT(15 == peer->ctrg->ctr[GBPROX_PEER_CTR_RAID_PATCHED_BSS].current); |
| 1939 | |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 1940 | printf("TLLI is already detached, shouldn't patch\n"); |
Jacob Erlbeck | c53f2a6 | 2014-08-15 14:56:28 +0200 | [diff] [blame] | 1941 | send_llc_ul_ui(nsi, "ACT PDP CTX REQ", &bss_peer[0], 0x1002, |
| 1942 | local_tlli, &rai_bss, cell_id, |
| 1943 | GPRS_SAPI_GMM, 3, |
| 1944 | dtap_act_pdp_ctx_req, sizeof(dtap_act_pdp_ctx_req)); |
Jacob Erlbeck | cf02eb1 | 2014-06-19 10:23:50 +0200 | [diff] [blame] | 1945 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1946 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GSM_ACT_PDP_REQ)); |
| 1947 | |
Jacob Erlbeck | 006c038 | 2014-05-27 13:49:04 +0200 | [diff] [blame] | 1948 | printf("Invalid RAI, shouldn't patch\n"); |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 1949 | send_bssgp_suspend_ack(nsi, &sgsn_peer, 0xccd1758b, &rai_unknown); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1950 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1951 | /* TODO: The following breaks with the current libosmocore, enable it |
| 1952 | * again (and remove the plain expect_msg), when the msgb_bssgph patch |
| 1953 | * is integrated */ |
| 1954 | /* OSMO_ASSERT(expect_bssgp_msg(SGSN_NSEI, 0, BSSGP_PDUT_STATUS)); */ |
| 1955 | OSMO_ASSERT(expect_msg()); |
| 1956 | |
Holger Hans Peter Freyther | b900459 | 2014-08-04 11:26:54 +0200 | [diff] [blame] | 1957 | dump_global(stdout, 0); |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 1958 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1959 | |
Jacob Erlbeck | 55ec2bf | 2014-09-23 14:56:38 +0200 | [diff] [blame] | 1960 | OSMO_ASSERT(!expect_msg()); |
| 1961 | received_messages = NULL; |
| 1962 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 1963 | talloc_free(gbcfg.core_apn); |
| 1964 | gbcfg.core_apn = NULL; |
| 1965 | |
Jacob Erlbeck | 9ccc41e | 2014-09-25 11:21:34 +0200 | [diff] [blame] | 1966 | gbproxy_clear_patch_filter(&gbcfg.matches[GBPROX_MATCH_PATCHING]); |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 1967 | gbprox_reset(&gbcfg); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1968 | gprs_ns_destroy(nsi); |
| 1969 | nsi = NULL; |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 1970 | } |
| 1971 | |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 1972 | static void test_gbproxy_ptmsi_assignment() |
| 1973 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 1974 | struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 1975 | struct sockaddr_in bss_peer[1] = {{0},}; |
| 1976 | struct sockaddr_in sgsn_peer= {0}; |
| 1977 | struct gprs_ra_id rai_bss = |
| 1978 | {.mcc = 112, .mnc = 332, .lac = 16464, .rac = 96}; |
| 1979 | struct gprs_ra_id rai_unknown = |
| 1980 | {.mcc = 1, .mnc = 99, .lac = 99, .rac = 96}; |
| 1981 | uint16_t cell_id = 0x1234; |
| 1982 | |
| 1983 | const uint32_t ptmsi = 0xefe2b700; |
| 1984 | const uint32_t local_tlli = 0xefe2b700; |
| 1985 | |
| 1986 | const uint32_t foreign_tlli1 = 0x8000dead; |
| 1987 | const uint32_t foreign_tlli2 = 0x8000beef; |
| 1988 | |
| 1989 | const uint8_t imsi1[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}; |
| 1990 | const uint8_t imsi2[] = {0x11, 0x12, 0x99, 0x99, 0x99, 0x16, 0x17, 0x18}; |
| 1991 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 1992 | struct gbproxy_link_info *link_info, *link_info2; |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 1993 | struct gbproxy_peer *peer; |
| 1994 | unsigned bss_nu = 0; |
| 1995 | unsigned sgsn_nu = 0; |
| 1996 | |
| 1997 | OSMO_ASSERT(local_tlli == gprs_tmsi2tlli(ptmsi, TLLI_LOCAL)); |
| 1998 | |
| 1999 | bssgp_nsi = nsi; |
| 2000 | gbcfg.nsi = bssgp_nsi; |
| 2001 | gbcfg.nsip_sgsn_nsei = SGSN_NSEI; |
Neels Hofmeyr | 10719b7 | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 2002 | gbcfg.core_plmn = (struct osmo_plmn_id){}; |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 2003 | gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2004 | gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); |
| 2005 | gbcfg.patch_ptmsi = 0; |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2006 | |
| 2007 | configure_sgsn_peer(&sgsn_peer); |
| 2008 | configure_bss_peers(bss_peer, ARRAY_SIZE(bss_peer)); |
| 2009 | |
| 2010 | printf("=== %s ===\n", __func__); |
| 2011 | printf("--- Initialise SGSN ---\n\n"); |
| 2012 | |
| 2013 | connect_sgsn(nsi, &sgsn_peer, SGSN_NSEI); |
| 2014 | |
| 2015 | printf("--- Initialise BSS 1 ---\n\n"); |
| 2016 | |
| 2017 | setup_ns(nsi, &bss_peer[0], 0x1001, 0x1000); |
| 2018 | setup_bssgp(nsi, &bss_peer[0], 0x1002); |
| 2019 | |
| 2020 | peer = gbproxy_peer_by_nsei(&gbcfg, 0x1000); |
| 2021 | OSMO_ASSERT(peer != NULL); |
| 2022 | |
| 2023 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002); |
| 2024 | |
| 2025 | gprs_dump_nsi(nsi); |
| 2026 | dump_global(stdout, 0); |
| 2027 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2028 | |
| 2029 | printf("--- Establish first LLC connection ---\n\n"); |
| 2030 | |
| 2031 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 2032 | foreign_tlli1, &rai_unknown, cell_id, |
| 2033 | GPRS_SAPI_GMM, bss_nu++, |
| 2034 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 2035 | |
| 2036 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2037 | |
| 2038 | send_llc_dl_ui(nsi, "IDENT REQUEST", &sgsn_peer, 0x1002, |
| 2039 | foreign_tlli1, 0, NULL, 0, |
| 2040 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2041 | dtap_identity_req, sizeof(dtap_identity_req)); |
| 2042 | |
| 2043 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2044 | |
| 2045 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 2046 | foreign_tlli1, &rai_bss, cell_id, |
| 2047 | GPRS_SAPI_GMM, bss_nu++, |
| 2048 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 2049 | |
| 2050 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2051 | |
| 2052 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 2053 | foreign_tlli1, 1, imsi1, sizeof(imsi1), |
| 2054 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2055 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 2056 | |
| 2057 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2058 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2059 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli1); |
| 2060 | link_info2 = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 2061 | OSMO_ASSERT(link_info); |
| 2062 | OSMO_ASSERT(link_info == link_info2); |
| 2063 | OSMO_ASSERT(link_info->tlli.assigned == local_tlli); |
| 2064 | OSMO_ASSERT(link_info->tlli.current == foreign_tlli1); |
| 2065 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 2066 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2067 | OSMO_ASSERT(link_info->tlli.ptmsi == ptmsi); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2068 | |
| 2069 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 2070 | local_tlli, &rai_bss, cell_id, |
| 2071 | GPRS_SAPI_GMM, bss_nu++, |
| 2072 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 2073 | |
| 2074 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2075 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2076 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 2077 | OSMO_ASSERT(link_info); |
| 2078 | OSMO_ASSERT(link_info->tlli.assigned == local_tlli); |
| 2079 | OSMO_ASSERT(link_info->tlli.current == foreign_tlli1); |
| 2080 | OSMO_ASSERT(link_info->tlli.bss_validated); |
| 2081 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2082 | OSMO_ASSERT(link_info->tlli.ptmsi == ptmsi); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2083 | |
| 2084 | |
| 2085 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 2086 | local_tlli, 1, imsi1, sizeof(imsi1), |
| 2087 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2088 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 2089 | |
| 2090 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2091 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2092 | link_info = gbproxy_link_info_by_imsi(peer, imsi1, ARRAY_SIZE(imsi1)); |
| 2093 | OSMO_ASSERT(link_info); |
| 2094 | OSMO_ASSERT(link_info->tlli.ptmsi == ptmsi); |
| 2095 | OSMO_ASSERT(!gbproxy_link_info_by_imsi(peer, imsi2, ARRAY_SIZE(imsi2))); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2096 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2097 | link_info2 = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 2098 | OSMO_ASSERT(link_info == link_info2); |
| 2099 | OSMO_ASSERT(link_info->tlli.assigned == 0); |
| 2100 | OSMO_ASSERT(link_info->tlli.current == local_tlli); |
| 2101 | OSMO_ASSERT(link_info->tlli.ptmsi == ptmsi); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2102 | |
| 2103 | printf("--- Establish second LLC connection with the same P-TMSI ---\n\n"); |
| 2104 | |
| 2105 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 2106 | foreign_tlli2, &rai_unknown, cell_id, |
| 2107 | GPRS_SAPI_GMM, bss_nu++, |
| 2108 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 2109 | |
| 2110 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2111 | |
| 2112 | send_llc_dl_ui(nsi, "IDENT REQUEST", &sgsn_peer, 0x1002, |
| 2113 | foreign_tlli2, 0, NULL, 0, |
| 2114 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2115 | dtap_identity_req, sizeof(dtap_identity_req)); |
| 2116 | |
| 2117 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2118 | |
| 2119 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 2120 | foreign_tlli2, &rai_bss, cell_id, |
| 2121 | GPRS_SAPI_GMM, bss_nu++, |
| 2122 | dtap_identity2_resp, sizeof(dtap_identity2_resp)); |
| 2123 | |
| 2124 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2125 | |
| 2126 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 2127 | foreign_tlli2, 1, imsi2, sizeof(imsi2), |
| 2128 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2129 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 2130 | |
| 2131 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2132 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2133 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli2); |
| 2134 | link_info2 = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 2135 | OSMO_ASSERT(link_info); |
| 2136 | OSMO_ASSERT(link_info == link_info2); |
| 2137 | OSMO_ASSERT(link_info->tlli.assigned == local_tlli); |
| 2138 | OSMO_ASSERT(link_info->tlli.current == foreign_tlli2); |
| 2139 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 2140 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2141 | OSMO_ASSERT(link_info->tlli.ptmsi == ptmsi); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2142 | |
| 2143 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 2144 | local_tlli, &rai_bss, cell_id, |
| 2145 | GPRS_SAPI_GMM, bss_nu++, |
| 2146 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 2147 | |
| 2148 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2149 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2150 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 2151 | OSMO_ASSERT(link_info); |
| 2152 | OSMO_ASSERT(link_info->tlli.assigned == local_tlli); |
| 2153 | OSMO_ASSERT(link_info->tlli.current == foreign_tlli2); |
| 2154 | OSMO_ASSERT(link_info->tlli.bss_validated); |
| 2155 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2156 | OSMO_ASSERT(link_info->tlli.ptmsi == ptmsi); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2157 | |
| 2158 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 2159 | local_tlli, 1, imsi2, sizeof(imsi2), |
| 2160 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2161 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 2162 | |
| 2163 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2164 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2165 | link_info = gbproxy_link_info_by_imsi(peer, imsi2, ARRAY_SIZE(imsi2)); |
| 2166 | OSMO_ASSERT(link_info); |
| 2167 | OSMO_ASSERT(link_info->tlli.ptmsi == ptmsi); |
| 2168 | OSMO_ASSERT(!gbproxy_link_info_by_imsi(peer, imsi1, ARRAY_SIZE(imsi1))); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2169 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2170 | link_info2 = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 2171 | OSMO_ASSERT(link_info == link_info2); |
| 2172 | OSMO_ASSERT(link_info->tlli.assigned == 0); |
| 2173 | OSMO_ASSERT(link_info->tlli.current == local_tlli); |
| 2174 | OSMO_ASSERT(link_info->tlli.ptmsi == ptmsi); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2175 | |
| 2176 | dump_global(stdout, 0); |
| 2177 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 2178 | talloc_free(gbcfg.core_apn); |
| 2179 | gbcfg.core_apn = NULL; |
| 2180 | |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2181 | gbprox_reset(&gbcfg); |
| 2182 | gprs_ns_destroy(nsi); |
| 2183 | nsi = NULL; |
Daniel Willmann | d1554ec | 2015-10-12 19:36:34 +0200 | [diff] [blame] | 2184 | |
| 2185 | cleanup_test(); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 2186 | } |
| 2187 | |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2188 | static void test_gbproxy_ptmsi_patching() |
| 2189 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 2190 | struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2191 | struct sockaddr_in bss_peer[1] = {{0},}; |
| 2192 | struct sockaddr_in sgsn_peer= {0}; |
| 2193 | struct gprs_ra_id rai_bss = |
| 2194 | {.mcc = 112, .mnc = 332, .lac = 16464, .rac = 96}; |
| 2195 | struct gprs_ra_id rai_sgsn = |
| 2196 | {.mcc = 123, .mnc = 456, .lac = 16464, .rac = 96}; |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 2197 | struct gprs_ra_id rai_wrong_mcc_sgsn = |
| 2198 | {.mcc = 999, .mnc = 456, .lac = 16464, .rac = 96}; |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2199 | struct gprs_ra_id rai_unknown = |
| 2200 | {.mcc = 1, .mnc = 99, .lac = 99, .rac = 96}; |
| 2201 | uint16_t cell_id = 0x1234; |
| 2202 | |
| 2203 | const uint32_t sgsn_ptmsi = 0xefe2b700; |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2204 | const uint32_t sgsn_ptmsi2 = 0xe0987654; |
| 2205 | const uint32_t sgsn_ptmsi3 = 0xe0543210; |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2206 | const uint32_t local_sgsn_tlli = 0xefe2b700; |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2207 | const uint32_t local_sgsn_tlli2 = 0xe0987654; |
| 2208 | const uint32_t local_sgsn_tlli3 = 0xe0543210; |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 2209 | const uint32_t random_sgsn_tlli = 0x78dead00; |
Jacob Erlbeck | 7fb26c2 | 2014-09-04 11:08:50 +0200 | [diff] [blame] | 2210 | const uint32_t unknown_sgsn_tlli = 0xeebadbad; |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2211 | |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 2212 | const uint32_t bss_ptmsi = 0xc0dead01; |
| 2213 | const uint32_t bss_ptmsi2 = 0xc0dead02; |
| 2214 | const uint32_t bss_ptmsi3 = 0xc0dead03; |
| 2215 | const uint32_t local_bss_tlli = 0xc0dead01; |
| 2216 | const uint32_t local_bss_tlli2 = 0xc0dead02; |
| 2217 | const uint32_t local_bss_tlli3 = 0xc0dead03; |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2218 | const uint32_t foreign_bss_tlli = 0x8000dead; |
| 2219 | |
Jacob Erlbeck | 7fb26c2 | 2014-09-04 11:08:50 +0200 | [diff] [blame] | 2220 | |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2221 | const uint8_t imsi[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}; |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2222 | struct gbproxy_link_info *link_info; |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2223 | struct gbproxy_peer *peer; |
| 2224 | unsigned bss_nu = 0; |
| 2225 | unsigned sgsn_nu = 0; |
Jacob Erlbeck | c37ef6c | 2014-09-30 13:49:43 +0200 | [diff] [blame] | 2226 | int old_ctr; |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2227 | |
| 2228 | OSMO_ASSERT(local_sgsn_tlli == gprs_tmsi2tlli(sgsn_ptmsi, TLLI_LOCAL)); |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2229 | OSMO_ASSERT(local_sgsn_tlli2 == gprs_tmsi2tlli(sgsn_ptmsi2, TLLI_LOCAL)); |
| 2230 | OSMO_ASSERT(local_sgsn_tlli3 == gprs_tmsi2tlli(sgsn_ptmsi3, TLLI_LOCAL)); |
| 2231 | OSMO_ASSERT(local_bss_tlli == gprs_tmsi2tlli(bss_ptmsi, TLLI_LOCAL)); |
| 2232 | OSMO_ASSERT(local_bss_tlli2 == gprs_tmsi2tlli(bss_ptmsi2, TLLI_LOCAL)); |
| 2233 | OSMO_ASSERT(local_bss_tlli3 == gprs_tmsi2tlli(bss_ptmsi3, TLLI_LOCAL)); |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2234 | |
| 2235 | bssgp_nsi = nsi; |
| 2236 | gbcfg.nsi = bssgp_nsi; |
| 2237 | gbcfg.nsip_sgsn_nsei = SGSN_NSEI; |
Neels Hofmeyr | 10719b7 | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 2238 | gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 }; |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 2239 | gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2240 | gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); |
| 2241 | gbcfg.patch_ptmsi = 1; |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2242 | |
| 2243 | configure_sgsn_peer(&sgsn_peer); |
| 2244 | configure_bss_peers(bss_peer, ARRAY_SIZE(bss_peer)); |
| 2245 | |
| 2246 | printf("=== %s ===\n", __func__); |
| 2247 | printf("--- Initialise SGSN ---\n\n"); |
| 2248 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 2249 | connect_sgsn(nsi, &sgsn_peer, SGSN_NSEI); |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2250 | |
| 2251 | printf("--- Initialise BSS 1 ---\n\n"); |
| 2252 | |
| 2253 | setup_ns(nsi, &bss_peer[0], 0x1001, 0x1000); |
| 2254 | setup_bssgp(nsi, &bss_peer[0], 0x1002); |
| 2255 | |
Jacob Erlbeck | 5f1faa3 | 2014-08-21 10:01:30 +0200 | [diff] [blame] | 2256 | peer = gbproxy_peer_by_nsei(&gbcfg, 0x1000); |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2257 | OSMO_ASSERT(peer != NULL); |
| 2258 | |
| 2259 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002); |
| 2260 | |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2261 | gprs_dump_nsi(nsi); |
| 2262 | dump_global(stdout, 0); |
| 2263 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2264 | |
| 2265 | printf("--- Send message from BSS 1 to SGSN, BVCI 0x1002 ---\n\n"); |
| 2266 | |
| 2267 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 2268 | foreign_bss_tlli, &rai_unknown, cell_id, |
| 2269 | GPRS_SAPI_GMM, bss_nu++, |
| 2270 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 2271 | |
| 2272 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2273 | |
| 2274 | send_llc_dl_ui(nsi, "IDENT REQUEST", &sgsn_peer, 0x1002, |
| 2275 | random_sgsn_tlli, 0, NULL, 0, |
| 2276 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2277 | dtap_identity_req, sizeof(dtap_identity_req)); |
| 2278 | |
| 2279 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2280 | |
| 2281 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 2282 | foreign_bss_tlli, &rai_bss, cell_id, |
| 2283 | GPRS_SAPI_GMM, bss_nu++, |
| 2284 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 2285 | |
| 2286 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2287 | |
| 2288 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 2289 | random_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2290 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2291 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 2292 | |
| 2293 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2294 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2295 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, random_sgsn_tlli, SGSN_NSEI); |
| 2296 | OSMO_ASSERT(link_info); |
| 2297 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli); |
| 2298 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli); |
| 2299 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 2300 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2301 | OSMO_ASSERT(link_info->tlli.ptmsi == bss_ptmsi); |
| 2302 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli); |
| 2303 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli); |
| 2304 | OSMO_ASSERT(!link_info->sgsn_tlli.bss_validated); |
| 2305 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
| 2306 | OSMO_ASSERT(link_info->sgsn_tlli.ptmsi == sgsn_ptmsi); |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2307 | |
| 2308 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 2309 | local_bss_tlli, &rai_bss, cell_id, |
| 2310 | GPRS_SAPI_GMM, bss_nu++, |
| 2311 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 2312 | |
| 2313 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2314 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2315 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
| 2316 | OSMO_ASSERT(link_info); |
| 2317 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli); |
| 2318 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli); |
| 2319 | OSMO_ASSERT(link_info->tlli.bss_validated); |
| 2320 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2321 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli); |
| 2322 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli); |
| 2323 | OSMO_ASSERT(link_info->sgsn_tlli.bss_validated); |
| 2324 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2325 | |
| 2326 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 2327 | local_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2328 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2329 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 2330 | |
| 2331 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2332 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2333 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
| 2334 | OSMO_ASSERT(link_info); |
| 2335 | OSMO_ASSERT(link_info->tlli.current == local_bss_tlli); |
| 2336 | OSMO_ASSERT(link_info->tlli.assigned == 0); |
| 2337 | OSMO_ASSERT(link_info->sgsn_tlli.current == local_sgsn_tlli); |
| 2338 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == 0); |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2339 | |
Jacob Erlbeck | 82add78 | 2014-09-05 18:08:12 +0200 | [diff] [blame] | 2340 | send_llc_ul_ui(nsi, "ACT PDP CTX REQ (REPLACE APN)", &bss_peer[0], 0x1002, |
| 2341 | local_bss_tlli, &rai_bss, cell_id, |
| 2342 | GPRS_SAPI_GMM, bss_nu++, |
| 2343 | dtap_act_pdp_ctx_req, sizeof(dtap_act_pdp_ctx_req)); |
| 2344 | |
| 2345 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2346 | |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2347 | /* Non-DTAP */ |
| 2348 | send_bssgp_ul_unitdata(nsi, "XID (UL)", &bss_peer[0], 0x1002, |
| 2349 | local_bss_tlli, &rai_bss, cell_id, |
| 2350 | llc_u_xid_ul, sizeof(llc_u_xid_ul)); |
| 2351 | |
| 2352 | send_bssgp_dl_unitdata(nsi, "XID (DL)", &sgsn_peer, 0x1002, |
| 2353 | local_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2354 | llc_u_xid_dl, sizeof(llc_u_xid_dl)); |
| 2355 | |
| 2356 | send_bssgp_ul_unitdata(nsi, "LL11 DNS QUERY (UL)", &bss_peer[0], 0x1002, |
| 2357 | local_bss_tlli, &rai_bss, cell_id, |
| 2358 | llc_ui_ll11_dns_query_ul, |
| 2359 | sizeof(llc_ui_ll11_dns_query_ul)); |
| 2360 | |
| 2361 | send_bssgp_dl_unitdata(nsi, "LL11 DNS RESP (DL)", &sgsn_peer, 0x1002, |
| 2362 | local_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2363 | llc_ui_ll11_dns_resp_dl, |
| 2364 | sizeof(llc_ui_ll11_dns_resp_dl)); |
| 2365 | |
| 2366 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2367 | |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2368 | /* Repeated RA Update Requests */ |
| 2369 | send_llc_ul_ui(nsi, "RA UPD REQ (P-TMSI 2)", &bss_peer[0], 0x1002, |
| 2370 | local_bss_tlli, &rai_bss, 0x7080, |
| 2371 | GPRS_SAPI_GMM, bss_nu++, |
| 2372 | dtap_ra_upd_req, sizeof(dtap_ra_upd_req)); |
| 2373 | |
| 2374 | send_llc_dl_ui(nsi, "RA UDP ACC (P-TMSI 2)", &sgsn_peer, 0x1002, |
| 2375 | local_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2376 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2377 | dtap_ra_upd_acc2, sizeof(dtap_ra_upd_acc2)); |
| 2378 | |
| 2379 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2380 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2381 | OSMO_ASSERT(gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli2, SGSN_NSEI) != NULL); |
| 2382 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
| 2383 | OSMO_ASSERT(link_info); |
| 2384 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli2); |
| 2385 | OSMO_ASSERT(link_info->tlli.current == local_bss_tlli); |
| 2386 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 2387 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2388 | OSMO_ASSERT(link_info->tlli.ptmsi == bss_ptmsi2); |
| 2389 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli2); |
| 2390 | OSMO_ASSERT(link_info->sgsn_tlli.current == local_sgsn_tlli); |
| 2391 | OSMO_ASSERT(!link_info->sgsn_tlli.bss_validated); |
| 2392 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
| 2393 | OSMO_ASSERT(link_info->sgsn_tlli.ptmsi == sgsn_ptmsi2); |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2394 | |
| 2395 | send_llc_ul_ui(nsi, "RA UPD REQ (P-TMSI 3)", &bss_peer[0], 0x1002, |
| 2396 | local_bss_tlli2, &rai_bss, 0x7080, |
| 2397 | GPRS_SAPI_GMM, bss_nu++, |
| 2398 | dtap_ra_upd_req, sizeof(dtap_ra_upd_req)); |
| 2399 | |
| 2400 | send_llc_dl_ui(nsi, "RA UDP ACC (P-TMSI 3)", &sgsn_peer, 0x1002, |
| 2401 | local_sgsn_tlli2, 1, imsi, sizeof(imsi), |
| 2402 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2403 | dtap_ra_upd_acc3, sizeof(dtap_ra_upd_acc3)); |
| 2404 | |
| 2405 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2406 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2407 | OSMO_ASSERT(gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli2, SGSN_NSEI) == NULL); |
| 2408 | OSMO_ASSERT(gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli3, SGSN_NSEI) != NULL); |
| 2409 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
| 2410 | OSMO_ASSERT(link_info); |
| 2411 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli3); |
| 2412 | OSMO_ASSERT(link_info->tlli.current == local_bss_tlli); |
| 2413 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 2414 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2415 | OSMO_ASSERT(link_info->tlli.ptmsi == bss_ptmsi3); |
| 2416 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli3); |
| 2417 | OSMO_ASSERT(link_info->sgsn_tlli.current == local_sgsn_tlli); |
| 2418 | OSMO_ASSERT(!link_info->sgsn_tlli.bss_validated); |
| 2419 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
| 2420 | OSMO_ASSERT(link_info->sgsn_tlli.ptmsi == sgsn_ptmsi3); |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2421 | |
| 2422 | send_llc_ul_ui(nsi, "RA UPD COMPLETE", &bss_peer[0], 0x1002, |
| 2423 | local_bss_tlli3, &rai_bss, 0x7080, |
| 2424 | GPRS_SAPI_GMM, bss_nu++, |
| 2425 | dtap_ra_upd_complete, sizeof(dtap_ra_upd_complete)); |
| 2426 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2427 | link_info = gbproxy_link_info_by_tlli(peer, local_bss_tlli3); |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2428 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2429 | OSMO_ASSERT(link_info); |
| 2430 | OSMO_ASSERT(link_info->tlli.bss_validated); |
| 2431 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2432 | OSMO_ASSERT(link_info->sgsn_tlli.bss_validated); |
| 2433 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2434 | |
| 2435 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 2436 | local_sgsn_tlli3, 1, imsi, sizeof(imsi), |
| 2437 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2438 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 2439 | |
| 2440 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2441 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2442 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli3, SGSN_NSEI); |
| 2443 | OSMO_ASSERT(link_info); |
| 2444 | OSMO_ASSERT(link_info->tlli.current == local_bss_tlli3); |
| 2445 | OSMO_ASSERT(link_info->tlli.assigned == 0); |
| 2446 | OSMO_ASSERT(link_info->sgsn_tlli.current == local_sgsn_tlli3); |
| 2447 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == 0); |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2448 | |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 2449 | /* Other messages */ |
| 2450 | send_bssgp_llc_discarded(nsi, &bss_peer[0], 0x1002, |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2451 | local_bss_tlli3, 1, 12); |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 2452 | |
| 2453 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2454 | |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2455 | send_bssgp_suspend(nsi, &bss_peer[0], local_bss_tlli3, &rai_bss); |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 2456 | |
| 2457 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2458 | |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2459 | send_bssgp_suspend_ack(nsi, &sgsn_peer, local_sgsn_tlli3, &rai_sgsn); |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 2460 | |
| 2461 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2462 | |
Jacob Erlbeck | c37ef6c | 2014-09-30 13:49:43 +0200 | [diff] [blame] | 2463 | old_ctr = peer->ctrg->ctr[GBPROX_PEER_CTR_PTMSI_PATCHED_SGSN].current; |
| 2464 | |
| 2465 | send_bssgp_paging(nsi, &sgsn_peer, imsi, sizeof(imsi), &rai_bss, sgsn_ptmsi3); |
| 2466 | |
| 2467 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2468 | |
| 2469 | OSMO_ASSERT(old_ctr + 1 == |
| 2470 | peer->ctrg->ctr[GBPROX_PEER_CTR_PTMSI_PATCHED_SGSN].current); |
| 2471 | |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 2472 | /* Bad case: Invalid BVCI */ |
| 2473 | send_bssgp_llc_discarded(nsi, &bss_peer[0], 0xeee1, |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2474 | local_bss_tlli3, 1, 12); |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 2475 | dump_global(stdout, 0); |
| 2476 | |
| 2477 | /* Bad case: Invalid RAI */ |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2478 | send_bssgp_suspend_ack(nsi, &sgsn_peer, local_sgsn_tlli3, &rai_unknown); |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 2479 | |
| 2480 | dump_global(stdout, 0); |
| 2481 | |
| 2482 | /* Bad case: Invalid MCC (LAC ok) */ |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2483 | send_bssgp_suspend_ack(nsi, &sgsn_peer, local_sgsn_tlli3, |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 2484 | &rai_wrong_mcc_sgsn); |
| 2485 | |
| 2486 | dump_global(stdout, 0); |
| 2487 | |
Jacob Erlbeck | 7fb26c2 | 2014-09-04 11:08:50 +0200 | [diff] [blame] | 2488 | /* Bad case: Invalid TLLI from SGSN (IMSI unknown) */ |
| 2489 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 2490 | unknown_sgsn_tlli, 1, NULL, 0, |
| 2491 | GPRS_SAPI_GMM, 2, |
| 2492 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 2493 | |
| 2494 | /* Bad case: Invalid TLLI from SGSN (IMSI known) */ |
| 2495 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 2496 | unknown_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2497 | GPRS_SAPI_GMM, 3, |
| 2498 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 2499 | |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2500 | /* Detach */ |
| 2501 | send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002, |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2502 | local_bss_tlli3, &rai_bss, cell_id, |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2503 | GPRS_SAPI_GMM, bss_nu++, |
| 2504 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 2505 | |
| 2506 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2507 | |
| 2508 | send_llc_dl_ui(nsi, "DETACH ACC", &sgsn_peer, 0x1002, |
Jacob Erlbeck | 52f070a | 2014-09-04 13:45:56 +0200 | [diff] [blame] | 2509 | local_sgsn_tlli3, 1, imsi, sizeof(imsi), |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2510 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2511 | dtap_detach_acc, sizeof(dtap_detach_acc)); |
| 2512 | |
| 2513 | dump_peers(stdout, 0, 0, &gbcfg); |
Jacob Erlbeck | 299389a | 2014-08-21 16:34:18 +0200 | [diff] [blame] | 2514 | |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2515 | dump_global(stdout, 0); |
| 2516 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 2517 | talloc_free(gbcfg.core_apn); |
| 2518 | gbcfg.core_apn = NULL; |
| 2519 | |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2520 | gbprox_reset(&gbcfg); |
| 2521 | gprs_ns_destroy(nsi); |
| 2522 | nsi = NULL; |
Daniel Willmann | d1554ec | 2015-10-12 19:36:34 +0200 | [diff] [blame] | 2523 | |
| 2524 | cleanup_test(); |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 2525 | } |
| 2526 | |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2527 | static void test_gbproxy_ptmsi_patching_bad_cases() |
| 2528 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 2529 | struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2530 | struct sockaddr_in bss_peer[1] = {{0},}; |
| 2531 | struct sockaddr_in sgsn_peer= {0}; |
| 2532 | struct gprs_ra_id rai_bss = |
| 2533 | {.mcc = 112, .mnc = 332, .lac = 16464, .rac = 96}; |
| 2534 | struct gprs_ra_id rai_unknown = |
| 2535 | {.mcc = 1, .mnc = 99, .lac = 99, .rac = 96}; |
| 2536 | uint16_t cell_id = 0x1234; |
| 2537 | |
| 2538 | const uint32_t sgsn_ptmsi = 0xefe2b700; |
| 2539 | const uint32_t local_sgsn_tlli = 0xefe2b700; |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 2540 | const uint32_t random_sgsn_tlli = 0x78dead00; |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2541 | |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 2542 | const uint32_t bss_ptmsi = 0xc0dead01; |
| 2543 | const uint32_t local_bss_tlli = 0xc0dead01; |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2544 | const uint32_t foreign_bss_tlli = 0x8000dead; |
| 2545 | |
| 2546 | |
| 2547 | const uint8_t imsi[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}; |
| 2548 | struct gbproxy_link_info *link_info; |
| 2549 | struct gbproxy_peer *peer; |
| 2550 | unsigned bss_nu = 0; |
| 2551 | unsigned sgsn_nu = 0; |
| 2552 | |
| 2553 | OSMO_ASSERT(local_sgsn_tlli == gprs_tmsi2tlli(sgsn_ptmsi, TLLI_LOCAL)); |
| 2554 | OSMO_ASSERT(local_bss_tlli == gprs_tmsi2tlli(bss_ptmsi, TLLI_LOCAL)); |
| 2555 | |
| 2556 | bssgp_nsi = nsi; |
| 2557 | gbcfg.nsi = bssgp_nsi; |
| 2558 | gbcfg.nsip_sgsn_nsei = SGSN_NSEI; |
Neels Hofmeyr | 10719b7 | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 2559 | gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 }; |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 2560 | gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2561 | gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); |
| 2562 | gbcfg.patch_ptmsi = 1; |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2563 | |
| 2564 | configure_sgsn_peer(&sgsn_peer); |
| 2565 | configure_bss_peers(bss_peer, ARRAY_SIZE(bss_peer)); |
| 2566 | |
| 2567 | printf("=== %s ===\n", __func__); |
| 2568 | printf("--- Initialise SGSN ---\n\n"); |
| 2569 | |
| 2570 | connect_sgsn(nsi, &sgsn_peer, SGSN_NSEI); |
| 2571 | |
| 2572 | printf("--- Initialise BSS 1 ---\n\n"); |
| 2573 | |
| 2574 | setup_ns(nsi, &bss_peer[0], 0x1001, 0x1000); |
| 2575 | setup_bssgp(nsi, &bss_peer[0], 0x1002); |
| 2576 | |
| 2577 | peer = gbproxy_peer_by_nsei(&gbcfg, 0x1000); |
| 2578 | OSMO_ASSERT(peer != NULL); |
| 2579 | |
| 2580 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002); |
| 2581 | |
| 2582 | gprs_dump_nsi(nsi); |
| 2583 | dump_global(stdout, 0); |
| 2584 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2585 | |
| 2586 | printf("--- Send message from BSS 1 to SGSN, BVCI 0x1002 ---\n\n"); |
| 2587 | |
| 2588 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 2589 | foreign_bss_tlli, &rai_unknown, cell_id, |
| 2590 | GPRS_SAPI_GMM, bss_nu++, |
| 2591 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 2592 | |
| 2593 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2594 | |
| 2595 | send_llc_dl_ui(nsi, "IDENT REQUEST", &sgsn_peer, 0x1002, |
| 2596 | random_sgsn_tlli, 0, NULL, 0, |
| 2597 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2598 | dtap_identity_req, sizeof(dtap_identity_req)); |
| 2599 | |
| 2600 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2601 | |
| 2602 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 2603 | foreign_bss_tlli, &rai_bss, cell_id, |
| 2604 | GPRS_SAPI_GMM, bss_nu++, |
| 2605 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 2606 | |
| 2607 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2608 | |
| 2609 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 2610 | random_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2611 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2612 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 2613 | |
| 2614 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2615 | |
| 2616 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, random_sgsn_tlli, SGSN_NSEI); |
| 2617 | OSMO_ASSERT(link_info); |
| 2618 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli); |
| 2619 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli); |
| 2620 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 2621 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2622 | OSMO_ASSERT(link_info->tlli.ptmsi == bss_ptmsi); |
| 2623 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli); |
| 2624 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli); |
| 2625 | OSMO_ASSERT(!link_info->sgsn_tlli.bss_validated); |
| 2626 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
| 2627 | OSMO_ASSERT(link_info->sgsn_tlli.ptmsi == sgsn_ptmsi); |
| 2628 | |
| 2629 | send_llc_dl_ui(nsi, "ATTACH ACCEPT (duplicated)", &sgsn_peer, 0x1002, |
| 2630 | random_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2631 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2632 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 2633 | |
| 2634 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2635 | |
| 2636 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, random_sgsn_tlli, SGSN_NSEI); |
| 2637 | OSMO_ASSERT(link_info); |
Jacob Erlbeck | 91e9f55 | 2014-10-20 16:30:06 +0200 | [diff] [blame] | 2638 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli); |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2639 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli); |
| 2640 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 2641 | OSMO_ASSERT(!link_info->tlli.net_validated); |
Jacob Erlbeck | 91e9f55 | 2014-10-20 16:30:06 +0200 | [diff] [blame] | 2642 | OSMO_ASSERT(link_info->tlli.ptmsi == bss_ptmsi); |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2643 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli); |
| 2644 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli); |
| 2645 | OSMO_ASSERT(!link_info->sgsn_tlli.bss_validated); |
| 2646 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
| 2647 | OSMO_ASSERT(link_info->sgsn_tlli.ptmsi == sgsn_ptmsi); |
| 2648 | |
| 2649 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 2650 | local_bss_tlli, &rai_bss, cell_id, |
| 2651 | GPRS_SAPI_GMM, bss_nu++, |
| 2652 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 2653 | |
| 2654 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2655 | |
| 2656 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
| 2657 | OSMO_ASSERT(link_info); |
Jacob Erlbeck | 91e9f55 | 2014-10-20 16:30:06 +0200 | [diff] [blame] | 2658 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli); |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2659 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli); |
Jacob Erlbeck | 91e9f55 | 2014-10-20 16:30:06 +0200 | [diff] [blame] | 2660 | OSMO_ASSERT(link_info->tlli.bss_validated); |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2661 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2662 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli); |
| 2663 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli); |
Jacob Erlbeck | 91e9f55 | 2014-10-20 16:30:06 +0200 | [diff] [blame] | 2664 | OSMO_ASSERT(link_info->sgsn_tlli.bss_validated); |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2665 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
| 2666 | |
| 2667 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 2668 | local_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2669 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2670 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 2671 | |
| 2672 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2673 | |
| 2674 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
| 2675 | OSMO_ASSERT(link_info); |
Jacob Erlbeck | 91e9f55 | 2014-10-20 16:30:06 +0200 | [diff] [blame] | 2676 | OSMO_ASSERT(link_info->tlli.current == local_bss_tlli); |
| 2677 | OSMO_ASSERT(link_info->tlli.assigned == 0); |
| 2678 | OSMO_ASSERT(link_info->sgsn_tlli.current == local_sgsn_tlli); |
| 2679 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == 0); |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2680 | |
| 2681 | /* Detach */ |
| 2682 | send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002, |
| 2683 | local_bss_tlli, &rai_bss, cell_id, |
| 2684 | GPRS_SAPI_GMM, bss_nu++, |
| 2685 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 2686 | |
| 2687 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2688 | |
| 2689 | send_llc_dl_ui(nsi, "DETACH ACC", &sgsn_peer, 0x1002, |
| 2690 | local_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2691 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2692 | dtap_detach_acc, sizeof(dtap_detach_acc)); |
| 2693 | |
| 2694 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2695 | |
| 2696 | dump_global(stdout, 0); |
| 2697 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 2698 | talloc_free(gbcfg.core_apn); |
| 2699 | gbcfg.core_apn = NULL; |
| 2700 | |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2701 | gbprox_reset(&gbcfg); |
| 2702 | gprs_ns_destroy(nsi); |
| 2703 | nsi = NULL; |
Daniel Willmann | d1554ec | 2015-10-12 19:36:34 +0200 | [diff] [blame] | 2704 | |
| 2705 | cleanup_test(); |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2709 | static void test_gbproxy_imsi_acquisition() |
| 2710 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 2711 | struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2712 | struct sockaddr_in bss_peer[1] = {{0},}; |
| 2713 | struct sockaddr_in sgsn_peer= {0}; |
| 2714 | struct gprs_ra_id rai_bss = |
| 2715 | {.mcc = 112, .mnc = 332, .lac = 16464, .rac = 96}; |
| 2716 | struct gprs_ra_id rai_sgsn = |
| 2717 | {.mcc = 123, .mnc = 456, .lac = 16464, .rac = 96}; |
| 2718 | struct gprs_ra_id rai_wrong_mcc_sgsn = |
| 2719 | {.mcc = 999, .mnc = 456, .lac = 16464, .rac = 96}; |
| 2720 | struct gprs_ra_id rai_unknown = |
| 2721 | {.mcc = 1, .mnc = 99, .lac = 99, .rac = 96}; |
| 2722 | uint16_t cell_id = 0x1234; |
| 2723 | |
| 2724 | const uint32_t sgsn_ptmsi = 0xefe2b700; |
| 2725 | const uint32_t local_sgsn_tlli = 0xefe2b700; |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 2726 | const uint32_t random_sgsn_tlli = 0x78dead00; |
| 2727 | const uint32_t random_sgsn_tlli2 = 0x78dead02; |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2728 | |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 2729 | const uint32_t bss_ptmsi = 0xc0dead01; |
| 2730 | const uint32_t local_bss_tlli = 0xc0dead01; |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2731 | const uint32_t foreign_bss_tlli = 0x8000dead; |
Jacob Erlbeck | 991606b | 2014-09-12 10:33:38 +0200 | [diff] [blame] | 2732 | const uint32_t other_bss_tlli = 0x8000beef; |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2733 | |
| 2734 | const uint8_t imsi[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}; |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2735 | struct gbproxy_link_info *link_info; |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2736 | struct gbproxy_peer *peer; |
| 2737 | unsigned bss_nu = 0; |
| 2738 | unsigned sgsn_nu = 0; |
| 2739 | |
| 2740 | OSMO_ASSERT(local_sgsn_tlli == gprs_tmsi2tlli(sgsn_ptmsi, TLLI_LOCAL)); |
| 2741 | |
| 2742 | bssgp_nsi = nsi; |
| 2743 | gbcfg.nsi = bssgp_nsi; |
| 2744 | gbcfg.nsip_sgsn_nsei = SGSN_NSEI; |
Neels Hofmeyr | 10719b7 | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 2745 | gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 }; |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 2746 | gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2747 | gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); |
| 2748 | gbcfg.patch_ptmsi = 1; |
Jacob Erlbeck | 5f4ef32 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 2749 | gbcfg.acquire_imsi = 1; |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2750 | |
| 2751 | configure_sgsn_peer(&sgsn_peer); |
| 2752 | configure_bss_peers(bss_peer, ARRAY_SIZE(bss_peer)); |
| 2753 | |
| 2754 | printf("=== %s ===\n", __func__); |
| 2755 | printf("--- Initialise SGSN ---\n\n"); |
| 2756 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 2757 | connect_sgsn(nsi, &sgsn_peer, SGSN_NSEI); |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2758 | |
| 2759 | printf("--- Initialise BSS 1 ---\n\n"); |
| 2760 | |
| 2761 | setup_ns(nsi, &bss_peer[0], 0x1001, 0x1000); |
| 2762 | setup_bssgp(nsi, &bss_peer[0], 0x1002); |
| 2763 | |
| 2764 | peer = gbproxy_peer_by_nsei(&gbcfg, 0x1000); |
| 2765 | OSMO_ASSERT(peer != NULL); |
| 2766 | |
| 2767 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002); |
| 2768 | |
| 2769 | gprs_dump_nsi(nsi); |
| 2770 | dump_global(stdout, 0); |
| 2771 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2772 | |
| 2773 | printf("--- Send message from BSS 1 to SGSN, BVCI 0x1002 ---\n\n"); |
| 2774 | |
| 2775 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
Jacob Erlbeck | 991606b | 2014-09-12 10:33:38 +0200 | [diff] [blame] | 2776 | foreign_bss_tlli, &rai_bss, cell_id, |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2777 | GPRS_SAPI_GMM, bss_nu++, |
| 2778 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 2779 | |
| 2780 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2781 | |
Jacob Erlbeck | 5f4ef32 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 2782 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 2783 | foreign_bss_tlli, &rai_bss, cell_id, |
| 2784 | GPRS_SAPI_GMM, bss_nu++, |
| 2785 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 2786 | |
| 2787 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2788 | |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2789 | send_llc_dl_ui(nsi, "IDENT REQUEST", &sgsn_peer, 0x1002, |
| 2790 | random_sgsn_tlli, 0, NULL, 0, |
| 2791 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2792 | dtap_identity_req, sizeof(dtap_identity_req)); |
| 2793 | |
| 2794 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2795 | |
| 2796 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 2797 | foreign_bss_tlli, &rai_bss, cell_id, |
| 2798 | GPRS_SAPI_GMM, bss_nu++, |
| 2799 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 2800 | |
| 2801 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2802 | |
| 2803 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 2804 | random_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2805 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2806 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 2807 | |
| 2808 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2809 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2810 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, random_sgsn_tlli, SGSN_NSEI); |
| 2811 | OSMO_ASSERT(link_info); |
| 2812 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli); |
| 2813 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli); |
| 2814 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 2815 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2816 | OSMO_ASSERT(link_info->tlli.ptmsi == bss_ptmsi); |
| 2817 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli); |
| 2818 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli); |
| 2819 | OSMO_ASSERT(!link_info->sgsn_tlli.bss_validated); |
| 2820 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
| 2821 | OSMO_ASSERT(link_info->sgsn_tlli.ptmsi == sgsn_ptmsi); |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2822 | |
| 2823 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 2824 | local_bss_tlli, &rai_bss, cell_id, |
| 2825 | GPRS_SAPI_GMM, bss_nu++, |
| 2826 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 2827 | |
| 2828 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2829 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2830 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
| 2831 | OSMO_ASSERT(link_info); |
| 2832 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli); |
| 2833 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli); |
| 2834 | OSMO_ASSERT(link_info->tlli.bss_validated); |
| 2835 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 2836 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli); |
| 2837 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli); |
| 2838 | OSMO_ASSERT(link_info->sgsn_tlli.bss_validated); |
| 2839 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2840 | |
| 2841 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 2842 | local_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2843 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2844 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 2845 | |
| 2846 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2847 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 2848 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
| 2849 | OSMO_ASSERT(link_info); |
| 2850 | OSMO_ASSERT(link_info->tlli.current == local_bss_tlli); |
| 2851 | OSMO_ASSERT(link_info->tlli.assigned == 0); |
| 2852 | OSMO_ASSERT(link_info->sgsn_tlli.current == local_sgsn_tlli); |
| 2853 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == 0); |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 2854 | |
| 2855 | /* Non-DTAP */ |
| 2856 | send_bssgp_ul_unitdata(nsi, "XID (UL)", &bss_peer[0], 0x1002, |
| 2857 | local_bss_tlli, &rai_bss, cell_id, |
| 2858 | llc_u_xid_ul, sizeof(llc_u_xid_ul)); |
| 2859 | |
| 2860 | send_bssgp_dl_unitdata(nsi, "XID (DL)", &sgsn_peer, 0x1002, |
| 2861 | local_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2862 | llc_u_xid_dl, sizeof(llc_u_xid_dl)); |
| 2863 | |
| 2864 | send_bssgp_ul_unitdata(nsi, "LL11 DNS QUERY (UL)", &bss_peer[0], 0x1002, |
| 2865 | local_bss_tlli, &rai_bss, cell_id, |
| 2866 | llc_ui_ll11_dns_query_ul, |
| 2867 | sizeof(llc_ui_ll11_dns_query_ul)); |
| 2868 | |
| 2869 | send_bssgp_dl_unitdata(nsi, "LL11 DNS RESP (DL)", &sgsn_peer, 0x1002, |
| 2870 | local_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2871 | llc_ui_ll11_dns_resp_dl, |
| 2872 | sizeof(llc_ui_ll11_dns_resp_dl)); |
| 2873 | |
| 2874 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2875 | |
| 2876 | /* Other messages */ |
| 2877 | send_bssgp_llc_discarded(nsi, &bss_peer[0], 0x1002, |
| 2878 | local_bss_tlli, 1, 12); |
| 2879 | |
| 2880 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2881 | |
| 2882 | send_bssgp_llc_discarded(nsi, &sgsn_peer, 0x1002, |
| 2883 | local_sgsn_tlli, 1, 12); |
| 2884 | |
| 2885 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2886 | |
| 2887 | send_bssgp_suspend(nsi, &bss_peer[0], local_bss_tlli, &rai_bss); |
| 2888 | |
| 2889 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2890 | |
| 2891 | send_bssgp_suspend_ack(nsi, &sgsn_peer, local_sgsn_tlli, &rai_sgsn); |
| 2892 | |
| 2893 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2894 | |
| 2895 | /* Bad case: Invalid BVCI */ |
| 2896 | send_bssgp_llc_discarded(nsi, &bss_peer[0], 0xeee1, |
| 2897 | local_bss_tlli, 1, 12); |
| 2898 | dump_global(stdout, 0); |
| 2899 | |
| 2900 | /* Bad case: Invalid RAI */ |
| 2901 | send_bssgp_suspend_ack(nsi, &sgsn_peer, local_sgsn_tlli, &rai_unknown); |
| 2902 | |
| 2903 | dump_global(stdout, 0); |
| 2904 | |
| 2905 | /* Bad case: Invalid MCC (LAC ok) */ |
| 2906 | send_bssgp_suspend_ack(nsi, &sgsn_peer, local_sgsn_tlli, |
| 2907 | &rai_wrong_mcc_sgsn); |
| 2908 | |
| 2909 | dump_global(stdout, 0); |
| 2910 | |
| 2911 | /* Detach */ |
| 2912 | send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002, |
| 2913 | local_bss_tlli, &rai_bss, cell_id, |
| 2914 | GPRS_SAPI_GMM, bss_nu++, |
| 2915 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 2916 | |
| 2917 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2918 | |
| 2919 | send_llc_dl_ui(nsi, "DETACH ACC", &sgsn_peer, 0x1002, |
| 2920 | local_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2921 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2922 | dtap_detach_acc, sizeof(dtap_detach_acc)); |
| 2923 | |
| 2924 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2925 | |
Jacob Erlbeck | 2ec2757 | 2014-09-18 09:57:47 +0200 | [diff] [blame] | 2926 | /* RA Update request */ |
| 2927 | |
| 2928 | send_llc_ul_ui(nsi, "RA UPD REQ", &bss_peer[0], 0x1002, |
| 2929 | foreign_bss_tlli, &rai_unknown, 0x7080, |
| 2930 | GPRS_SAPI_GMM, bss_nu++, |
| 2931 | dtap_ra_upd_req, sizeof(dtap_ra_upd_req)); |
| 2932 | |
| 2933 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 2934 | foreign_bss_tlli, &rai_bss, cell_id, |
| 2935 | GPRS_SAPI_GMM, bss_nu++, |
| 2936 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 2937 | |
| 2938 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2939 | |
| 2940 | send_llc_dl_ui(nsi, "RA UDP ACC", &sgsn_peer, 0x1002, |
| 2941 | random_sgsn_tlli2, 1, imsi, sizeof(imsi), |
| 2942 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2943 | dtap_ra_upd_acc, sizeof(dtap_ra_upd_acc)); |
| 2944 | |
| 2945 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2946 | |
| 2947 | /* Detach */ |
| 2948 | |
| 2949 | send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002, |
| 2950 | local_bss_tlli, &rai_bss, cell_id, |
| 2951 | GPRS_SAPI_GMM, bss_nu++, |
| 2952 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 2953 | |
| 2954 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2955 | |
| 2956 | send_llc_dl_ui(nsi, "DETACH ACC", &sgsn_peer, 0x1002, |
| 2957 | local_sgsn_tlli, 1, imsi, sizeof(imsi), |
| 2958 | GPRS_SAPI_GMM, sgsn_nu++, |
| 2959 | dtap_detach_acc, sizeof(dtap_detach_acc)); |
| 2960 | |
| 2961 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2962 | |
Jacob Erlbeck | ea1698e | 2014-09-02 14:40:11 +0200 | [diff] [blame] | 2963 | /* Special case: Repeated Attach Requests */ |
| 2964 | |
| 2965 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 2966 | foreign_bss_tlli, &rai_unknown, cell_id, |
| 2967 | GPRS_SAPI_GMM, bss_nu++, |
| 2968 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 2969 | |
| 2970 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 2971 | foreign_bss_tlli, &rai_unknown, cell_id, |
| 2972 | GPRS_SAPI_GMM, bss_nu++, |
| 2973 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 2974 | |
Jacob Erlbeck | 991606b | 2014-09-12 10:33:38 +0200 | [diff] [blame] | 2975 | send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002, |
| 2976 | foreign_bss_tlli, &rai_bss, cell_id, |
| 2977 | GPRS_SAPI_GMM, bss_nu++, |
| 2978 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 2979 | |
| 2980 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2981 | |
| 2982 | /* Special case: Detach from an unknown TLLI */ |
| 2983 | |
| 2984 | send_llc_ul_ui(nsi, "DETACH REQ (unknown TLLI)", &bss_peer[0], 0x1002, |
| 2985 | other_bss_tlli, &rai_bss, cell_id, |
| 2986 | GPRS_SAPI_GMM, bss_nu++, |
| 2987 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 2988 | |
Jacob Erlbeck | ea1698e | 2014-09-02 14:40:11 +0200 | [diff] [blame] | 2989 | dump_peers(stdout, 0, 0, &gbcfg); |
| 2990 | |
Jacob Erlbeck | 2ec2757 | 2014-09-18 09:57:47 +0200 | [diff] [blame] | 2991 | /* Special case: Repeated RA Update Requests */ |
| 2992 | |
| 2993 | send_llc_ul_ui(nsi, "RA UPD REQ", &bss_peer[0], 0x1002, |
| 2994 | foreign_bss_tlli, &rai_unknown, 0x7080, |
| 2995 | GPRS_SAPI_GMM, bss_nu++, |
| 2996 | dtap_ra_upd_req, sizeof(dtap_ra_upd_req)); |
| 2997 | |
| 2998 | send_llc_ul_ui(nsi, "RA UPD REQ", &bss_peer[0], 0x1002, |
| 2999 | foreign_bss_tlli, &rai_unknown, 0x7080, |
| 3000 | GPRS_SAPI_GMM, bss_nu++, |
| 3001 | dtap_ra_upd_req, sizeof(dtap_ra_upd_req)); |
| 3002 | |
| 3003 | send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002, |
| 3004 | foreign_bss_tlli, &rai_bss, cell_id, |
| 3005 | GPRS_SAPI_GMM, bss_nu++, |
| 3006 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 3007 | |
| 3008 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3009 | |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 3010 | dump_global(stdout, 0); |
| 3011 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 3012 | talloc_free(gbcfg.core_apn); |
| 3013 | gbcfg.core_apn = NULL; |
| 3014 | |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 3015 | gbprox_reset(&gbcfg); |
| 3016 | gprs_ns_destroy(nsi); |
| 3017 | nsi = NULL; |
Daniel Willmann | d1554ec | 2015-10-12 19:36:34 +0200 | [diff] [blame] | 3018 | |
| 3019 | cleanup_test(); |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 3020 | } |
| 3021 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3022 | static void test_gbproxy_secondary_sgsn() |
| 3023 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 3024 | struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3025 | struct sockaddr_in bss_peer[1] = {{0},}; |
| 3026 | struct sockaddr_in sgsn_peer[2]= {{0},}; |
| 3027 | struct gprs_ra_id rai_bss = |
| 3028 | {.mcc = 112, .mnc = 332, .lac = 16464, .rac = 96}; |
| 3029 | struct gprs_ra_id rai_sgsn = |
| 3030 | {.mcc = 123, .mnc = 456, .lac = 16464, .rac = 96}; |
| 3031 | struct gprs_ra_id rai_unknown = |
| 3032 | {.mcc = 1, .mnc = 99, .lac = 99, .rac = 96}; |
| 3033 | uint16_t cell_id = 0x1234; |
| 3034 | |
| 3035 | const uint32_t sgsn_ptmsi = 0xefe2b700; |
| 3036 | const uint32_t local_sgsn_tlli = 0xefe2b700; |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 3037 | const uint32_t random_sgsn_tlli = 0x78dead00; |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3038 | |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 3039 | const uint32_t bss_ptmsi = 0xc0dead01; |
| 3040 | const uint32_t local_bss_tlli = 0xc0dead01; |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3041 | const uint32_t foreign_bss_tlli = 0x8000dead; |
| 3042 | |
| 3043 | const uint32_t sgsn_ptmsi2 = 0xe0987654; |
| 3044 | const uint32_t local_sgsn_tlli2 = 0xe0987654; |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 3045 | const uint32_t random_sgsn_tlli2 = 0x78dead02; |
| 3046 | const uint32_t bss_ptmsi2 = 0xc0dead03; |
| 3047 | const uint32_t local_bss_tlli2 = 0xc0dead03; |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3048 | const uint32_t foreign_bss_tlli2 = 0x8000beef; |
| 3049 | |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 3050 | const uint32_t random_sgsn_tlli3 = 0x78dead04; |
| 3051 | const uint32_t bss_ptmsi3 = 0xc0dead05; |
| 3052 | const uint32_t local_bss_tlli3 = 0xc0dead05; |
Jacob Erlbeck | af952ba | 2014-09-17 12:09:25 +0200 | [diff] [blame] | 3053 | const uint32_t foreign_bss_tlli3 = 0x8000feed; |
| 3054 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3055 | const uint8_t imsi1[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}; |
| 3056 | const uint8_t imsi2[] = {0x11, 0x12, 0x99, 0x99, 0x99, 0x16, 0x17, 0x18}; |
Jacob Erlbeck | af952ba | 2014-09-17 12:09:25 +0200 | [diff] [blame] | 3057 | const uint8_t imsi3[] = {0x11, 0x12, 0x99, 0x99, 0x99, 0x26, 0x27, 0x28}; |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3058 | struct gbproxy_link_info *link_info; |
| 3059 | struct gbproxy_link_info *other_info; |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3060 | struct gbproxy_peer *peer; |
| 3061 | unsigned bss_nu = 0; |
| 3062 | unsigned sgsn_nu = 0; |
| 3063 | |
| 3064 | const char *err_msg = NULL; |
| 3065 | const char *filter_re = "999999"; |
| 3066 | |
| 3067 | OSMO_ASSERT(local_sgsn_tlli == gprs_tmsi2tlli(sgsn_ptmsi, TLLI_LOCAL)); |
| 3068 | OSMO_ASSERT(local_sgsn_tlli2 == gprs_tmsi2tlli(sgsn_ptmsi2, TLLI_LOCAL)); |
| 3069 | |
| 3070 | bssgp_nsi = nsi; |
| 3071 | gbcfg.nsi = bssgp_nsi; |
| 3072 | gbcfg.nsip_sgsn_nsei = SGSN_NSEI; |
Neels Hofmeyr | 10719b7 | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 3073 | gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 }; |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 3074 | gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3075 | gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); |
| 3076 | gbcfg.patch_ptmsi = 1; |
| 3077 | gbcfg.acquire_imsi = 1; |
Daniel Willmann | 537d480 | 2015-10-12 19:36:35 +0200 | [diff] [blame] | 3078 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3079 | gbcfg.route_to_sgsn2 = 1; |
| 3080 | gbcfg.nsip_sgsn2_nsei = SGSN2_NSEI; |
| 3081 | |
Jacob Erlbeck | b36032c | 2014-09-25 13:21:48 +0200 | [diff] [blame] | 3082 | if (gbproxy_set_patch_filter(&gbcfg.matches[GBPROX_MATCH_ROUTING], |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 3083 | filter_re, &err_msg) != 0) { |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3084 | fprintf(stderr, "gbprox_set_patch_filter: got error: %s\n", |
| 3085 | err_msg); |
| 3086 | OSMO_ASSERT(err_msg == NULL); |
| 3087 | } |
| 3088 | |
| 3089 | configure_sgsn_peer(&sgsn_peer[0]); |
| 3090 | configure_sgsn2_peer(&sgsn_peer[1]); |
| 3091 | configure_bss_peers(bss_peer, ARRAY_SIZE(bss_peer)); |
| 3092 | |
| 3093 | printf("=== %s ===\n", __func__); |
| 3094 | printf("--- Initialise SGSN 1 ---\n\n"); |
| 3095 | |
| 3096 | connect_sgsn(nsi, &sgsn_peer[0], SGSN_NSEI); |
| 3097 | |
| 3098 | printf("--- Initialise SGSN 2 ---\n\n"); |
| 3099 | |
| 3100 | connect_sgsn(nsi, &sgsn_peer[1], SGSN2_NSEI); |
| 3101 | |
| 3102 | printf("--- Initialise BSS 1 ---\n\n"); |
| 3103 | |
| 3104 | setup_ns(nsi, &bss_peer[0], 0x1001, 0x1000); |
| 3105 | setup_bssgp(nsi, &bss_peer[0], 0x0); |
| 3106 | send_bssgp_reset_ack(nsi, &sgsn_peer[0], 0x0); |
| 3107 | setup_bssgp(nsi, &bss_peer[0], 0x1002); |
| 3108 | send_bssgp_reset_ack(nsi, &sgsn_peer[0], 0x1002); |
| 3109 | send_bssgp_reset_ack(nsi, &sgsn_peer[1], 0x1002); |
| 3110 | |
| 3111 | peer = gbproxy_peer_by_nsei(&gbcfg, 0x1000); |
| 3112 | OSMO_ASSERT(peer != NULL); |
| 3113 | |
| 3114 | gprs_dump_nsi(nsi); |
| 3115 | dump_global(stdout, 0); |
| 3116 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3117 | |
| 3118 | printf("--- Flow control ---\n\n"); |
| 3119 | |
| 3120 | send_bssgp_flow_control_bvc(nsi, &bss_peer[0], 0x1002, 1); |
| 3121 | send_bssgp_flow_control_bvc_ack(nsi, &sgsn_peer[0], 0x1002, 1); |
| 3122 | send_bssgp_flow_control_bvc_ack(nsi, &sgsn_peer[1], 0x1002, 1); |
| 3123 | |
| 3124 | printf("--- Establish GPRS connection (SGSN 1) ---\n\n"); |
| 3125 | |
| 3126 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 3127 | foreign_bss_tlli, &rai_unknown, cell_id, |
| 3128 | GPRS_SAPI_GMM, bss_nu++, |
| 3129 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 3130 | |
| 3131 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3132 | |
| 3133 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 3134 | foreign_bss_tlli, &rai_bss, cell_id, |
| 3135 | GPRS_SAPI_GMM, bss_nu++, |
| 3136 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 3137 | |
| 3138 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3139 | |
| 3140 | send_llc_dl_ui(nsi, "IDENT REQUEST", &sgsn_peer[0], 0x1002, |
| 3141 | random_sgsn_tlli, 0, NULL, 0, |
| 3142 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3143 | dtap_identity_req, sizeof(dtap_identity_req)); |
| 3144 | |
| 3145 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3146 | |
| 3147 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 3148 | foreign_bss_tlli, &rai_bss, cell_id, |
| 3149 | GPRS_SAPI_GMM, bss_nu++, |
| 3150 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 3151 | |
| 3152 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3153 | |
| 3154 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer[0], 0x1002, |
| 3155 | random_sgsn_tlli, 1, imsi1, sizeof(imsi1), |
| 3156 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3157 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 3158 | |
| 3159 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3160 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3161 | OSMO_ASSERT(!gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN2_NSEI)); |
| 3162 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, random_sgsn_tlli, SGSN_NSEI); |
| 3163 | OSMO_ASSERT(link_info); |
| 3164 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli); |
| 3165 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli); |
| 3166 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 3167 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 3168 | OSMO_ASSERT(link_info->tlli.ptmsi == bss_ptmsi); |
| 3169 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli); |
| 3170 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli); |
| 3171 | OSMO_ASSERT(!link_info->sgsn_tlli.bss_validated); |
| 3172 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
| 3173 | OSMO_ASSERT(link_info->sgsn_tlli.ptmsi == sgsn_ptmsi); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3174 | |
| 3175 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 3176 | local_bss_tlli, &rai_bss, cell_id, |
| 3177 | GPRS_SAPI_GMM, bss_nu++, |
| 3178 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 3179 | |
| 3180 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3181 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3182 | OSMO_ASSERT(!gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN2_NSEI)); |
| 3183 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
| 3184 | OSMO_ASSERT(link_info); |
| 3185 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli); |
| 3186 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli); |
| 3187 | OSMO_ASSERT(link_info->tlli.bss_validated); |
| 3188 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 3189 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli); |
| 3190 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli); |
| 3191 | OSMO_ASSERT(link_info->sgsn_tlli.bss_validated); |
| 3192 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3193 | |
| 3194 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer[0], 0x1002, |
| 3195 | local_sgsn_tlli, 1, imsi1, sizeof(imsi1), |
| 3196 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3197 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 3198 | |
| 3199 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3200 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3201 | OSMO_ASSERT(!gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN2_NSEI)); |
| 3202 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
| 3203 | OSMO_ASSERT(link_info); |
| 3204 | OSMO_ASSERT(link_info->tlli.current == local_bss_tlli); |
| 3205 | OSMO_ASSERT(link_info->tlli.assigned == 0); |
| 3206 | OSMO_ASSERT(link_info->sgsn_tlli.current == local_sgsn_tlli); |
| 3207 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == 0); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3208 | |
| 3209 | /* Non-DTAP */ |
| 3210 | send_bssgp_ul_unitdata(nsi, "XID (UL)", &bss_peer[0], 0x1002, |
| 3211 | local_bss_tlli, &rai_bss, cell_id, |
| 3212 | llc_u_xid_ul, sizeof(llc_u_xid_ul)); |
| 3213 | |
| 3214 | send_bssgp_dl_unitdata(nsi, "XID (DL)", &sgsn_peer[0], 0x1002, |
| 3215 | local_sgsn_tlli, 1, imsi1, sizeof(imsi1), |
| 3216 | llc_u_xid_dl, sizeof(llc_u_xid_dl)); |
| 3217 | |
| 3218 | send_bssgp_ul_unitdata(nsi, "LL11 DNS QUERY (UL)", &bss_peer[0], 0x1002, |
| 3219 | local_bss_tlli, &rai_bss, cell_id, |
| 3220 | llc_ui_ll11_dns_query_ul, |
| 3221 | sizeof(llc_ui_ll11_dns_query_ul)); |
| 3222 | |
| 3223 | send_bssgp_dl_unitdata(nsi, "LL11 DNS RESP (DL)", &sgsn_peer[0], 0x1002, |
| 3224 | local_sgsn_tlli, 1, imsi1, sizeof(imsi1), |
| 3225 | llc_ui_ll11_dns_resp_dl, |
| 3226 | sizeof(llc_ui_ll11_dns_resp_dl)); |
| 3227 | |
| 3228 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3229 | |
| 3230 | /* Other messages */ |
| 3231 | send_bssgp_llc_discarded(nsi, &bss_peer[0], 0x1002, |
| 3232 | local_bss_tlli, 1, 12); |
| 3233 | |
| 3234 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3235 | |
| 3236 | send_bssgp_llc_discarded(nsi, &sgsn_peer[0], 0x1002, |
| 3237 | local_sgsn_tlli, 1, 12); |
| 3238 | |
| 3239 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3240 | |
| 3241 | send_bssgp_suspend(nsi, &bss_peer[0], local_bss_tlli, &rai_bss); |
| 3242 | |
| 3243 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3244 | |
| 3245 | send_bssgp_suspend_ack(nsi, &sgsn_peer[0], local_sgsn_tlli, &rai_sgsn); |
| 3246 | |
| 3247 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3248 | |
| 3249 | printf("--- Establish GPRS connection (SGSN 2) ---\n\n"); |
| 3250 | |
| 3251 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 3252 | foreign_bss_tlli2, &rai_unknown, cell_id, |
| 3253 | GPRS_SAPI_GMM, bss_nu++, |
| 3254 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 3255 | |
| 3256 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3257 | |
| 3258 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 3259 | foreign_bss_tlli2, &rai_bss, cell_id, |
| 3260 | GPRS_SAPI_GMM, bss_nu++, |
| 3261 | dtap_identity2_resp, sizeof(dtap_identity2_resp)); |
| 3262 | |
| 3263 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3264 | |
| 3265 | send_llc_dl_ui(nsi, "IDENT REQUEST", &sgsn_peer[1], 0x1002, |
| 3266 | random_sgsn_tlli2, 0, NULL, 0, |
| 3267 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3268 | dtap_identity_req, sizeof(dtap_identity_req)); |
| 3269 | |
| 3270 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3271 | |
| 3272 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 3273 | foreign_bss_tlli2, &rai_bss, cell_id, |
| 3274 | GPRS_SAPI_GMM, bss_nu++, |
Jacob Erlbeck | 2bb4543 | 2014-09-17 12:05:08 +0200 | [diff] [blame] | 3275 | dtap_identity2_resp, sizeof(dtap_identity2_resp)); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3276 | |
| 3277 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3278 | |
| 3279 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer[1], 0x1002, |
| 3280 | random_sgsn_tlli2, 1, imsi2, sizeof(imsi2), |
| 3281 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3282 | dtap_attach_acc2, sizeof(dtap_attach_acc2)); |
| 3283 | |
| 3284 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3285 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3286 | OSMO_ASSERT(!gbproxy_link_info_by_sgsn_tlli(peer, random_sgsn_tlli2, SGSN_NSEI)); |
| 3287 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, random_sgsn_tlli2, SGSN2_NSEI); |
| 3288 | OSMO_ASSERT(link_info); |
| 3289 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli2); |
| 3290 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli2); |
| 3291 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 3292 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 3293 | OSMO_ASSERT(link_info->tlli.ptmsi == bss_ptmsi2); |
| 3294 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli2); |
| 3295 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli2); |
| 3296 | OSMO_ASSERT(!link_info->sgsn_tlli.bss_validated); |
| 3297 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
| 3298 | OSMO_ASSERT(link_info->sgsn_tlli.ptmsi == sgsn_ptmsi2); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3299 | |
| 3300 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 3301 | local_bss_tlli2, &rai_bss, cell_id, |
| 3302 | GPRS_SAPI_GMM, bss_nu++, |
| 3303 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 3304 | |
| 3305 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3306 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3307 | OSMO_ASSERT(!gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli2, SGSN_NSEI)); |
| 3308 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli2, SGSN2_NSEI); |
| 3309 | OSMO_ASSERT(link_info); |
| 3310 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli2); |
| 3311 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli2); |
| 3312 | OSMO_ASSERT(link_info->tlli.bss_validated); |
| 3313 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 3314 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli2); |
| 3315 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli2); |
| 3316 | OSMO_ASSERT(link_info->sgsn_tlli.bss_validated); |
| 3317 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3318 | |
| 3319 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer[1], 0x1002, |
| 3320 | local_sgsn_tlli2, 1, imsi2, sizeof(imsi2), |
| 3321 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3322 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 3323 | |
| 3324 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3325 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3326 | OSMO_ASSERT(!gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli2, SGSN_NSEI)); |
| 3327 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli2, SGSN2_NSEI); |
| 3328 | OSMO_ASSERT(link_info); |
| 3329 | OSMO_ASSERT(link_info->tlli.current == local_bss_tlli2); |
| 3330 | OSMO_ASSERT(link_info->tlli.assigned == 0); |
| 3331 | OSMO_ASSERT(link_info->sgsn_tlli.current == local_sgsn_tlli2); |
| 3332 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == 0); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3333 | |
| 3334 | /* Non-DTAP */ |
| 3335 | send_bssgp_ul_unitdata(nsi, "XID (UL)", &bss_peer[0], 0x1002, |
| 3336 | local_bss_tlli2, &rai_bss, cell_id, |
| 3337 | llc_u_xid_ul, sizeof(llc_u_xid_ul)); |
| 3338 | |
| 3339 | send_bssgp_dl_unitdata(nsi, "XID (DL)", &sgsn_peer[1], 0x1002, |
| 3340 | local_sgsn_tlli2, 1, imsi2, sizeof(imsi2), |
| 3341 | llc_u_xid_dl, sizeof(llc_u_xid_dl)); |
| 3342 | |
| 3343 | send_bssgp_ul_unitdata(nsi, "LL11 DNS QUERY (UL)", &bss_peer[0], 0x1002, |
| 3344 | local_bss_tlli2, &rai_bss, cell_id, |
| 3345 | llc_ui_ll11_dns_query_ul, |
| 3346 | sizeof(llc_ui_ll11_dns_query_ul)); |
| 3347 | |
| 3348 | send_bssgp_dl_unitdata(nsi, "LL11 DNS RESP (DL)", &sgsn_peer[1], 0x1002, |
| 3349 | local_sgsn_tlli2, 1, imsi2, sizeof(imsi2), |
| 3350 | llc_ui_ll11_dns_resp_dl, |
| 3351 | sizeof(llc_ui_ll11_dns_resp_dl)); |
| 3352 | |
| 3353 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3354 | |
| 3355 | /* Other messages */ |
| 3356 | send_bssgp_llc_discarded(nsi, &bss_peer[0], 0x1002, |
| 3357 | local_bss_tlli2, 1, 12); |
| 3358 | |
| 3359 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3360 | |
| 3361 | send_bssgp_llc_discarded(nsi, &sgsn_peer[1], 0x1002, |
| 3362 | local_sgsn_tlli2, 1, 12); |
| 3363 | |
| 3364 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3365 | |
| 3366 | send_bssgp_suspend(nsi, &bss_peer[0], local_bss_tlli2, &rai_bss); |
| 3367 | |
| 3368 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3369 | |
| 3370 | send_bssgp_suspend_ack(nsi, &sgsn_peer[1], local_sgsn_tlli2, &rai_sgsn); |
| 3371 | |
| 3372 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3373 | |
Jacob Erlbeck | af952ba | 2014-09-17 12:09:25 +0200 | [diff] [blame] | 3374 | printf("--- Establish GPRS connection (SGSN 2, P-TMSI collision) ---\n\n"); |
| 3375 | |
| 3376 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 3377 | foreign_bss_tlli3, &rai_unknown, cell_id, |
| 3378 | GPRS_SAPI_GMM, bss_nu++, |
| 3379 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 3380 | |
| 3381 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3382 | |
| 3383 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 3384 | foreign_bss_tlli3, &rai_bss, cell_id, |
| 3385 | GPRS_SAPI_GMM, bss_nu++, |
| 3386 | dtap_identity3_resp, sizeof(dtap_identity3_resp)); |
| 3387 | |
| 3388 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3389 | |
| 3390 | send_llc_dl_ui(nsi, "IDENT REQUEST", &sgsn_peer[1], 0x1002, |
| 3391 | random_sgsn_tlli3, 0, NULL, 0, |
| 3392 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3393 | dtap_identity_req, sizeof(dtap_identity_req)); |
| 3394 | |
| 3395 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3396 | |
| 3397 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 3398 | foreign_bss_tlli3, &rai_bss, cell_id, |
| 3399 | GPRS_SAPI_GMM, bss_nu++, |
| 3400 | dtap_identity3_resp, sizeof(dtap_identity3_resp)); |
| 3401 | |
| 3402 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3403 | |
| 3404 | send_llc_dl_ui(nsi, "ATTACH ACCEPT (P-TMSI 1)", &sgsn_peer[1], 0x1002, |
| 3405 | random_sgsn_tlli3, 1, imsi3, sizeof(imsi3), |
| 3406 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3407 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 3408 | |
| 3409 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3410 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3411 | OSMO_ASSERT(!gbproxy_link_info_by_sgsn_tlli(peer, random_sgsn_tlli3, SGSN_NSEI)); |
| 3412 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, random_sgsn_tlli3, SGSN2_NSEI); |
| 3413 | OSMO_ASSERT(link_info); |
| 3414 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli3); |
| 3415 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli3); |
| 3416 | OSMO_ASSERT(!link_info->tlli.bss_validated); |
| 3417 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 3418 | OSMO_ASSERT(link_info->tlli.ptmsi == bss_ptmsi3); |
| 3419 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli); |
| 3420 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli3); |
| 3421 | OSMO_ASSERT(!link_info->sgsn_tlli.bss_validated); |
| 3422 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
| 3423 | OSMO_ASSERT(link_info->sgsn_tlli.ptmsi == sgsn_ptmsi); |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 3424 | |
Jacob Erlbeck | af952ba | 2014-09-17 12:09:25 +0200 | [diff] [blame] | 3425 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 3426 | local_bss_tlli3, &rai_bss, cell_id, |
| 3427 | GPRS_SAPI_GMM, bss_nu++, |
| 3428 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 3429 | |
| 3430 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3431 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3432 | other_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 3433 | OSMO_ASSERT(other_info); |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3434 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN2_NSEI); |
| 3435 | OSMO_ASSERT(link_info); |
| 3436 | OSMO_ASSERT(link_info != other_info); |
| 3437 | OSMO_ASSERT(link_info->tlli.assigned == local_bss_tlli3); |
| 3438 | OSMO_ASSERT(link_info->tlli.current == foreign_bss_tlli3); |
| 3439 | OSMO_ASSERT(link_info->tlli.bss_validated); |
| 3440 | OSMO_ASSERT(!link_info->tlli.net_validated); |
| 3441 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == local_sgsn_tlli); |
| 3442 | OSMO_ASSERT(link_info->sgsn_tlli.current == random_sgsn_tlli3); |
| 3443 | OSMO_ASSERT(link_info->sgsn_tlli.bss_validated); |
| 3444 | OSMO_ASSERT(!link_info->sgsn_tlli.net_validated); |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 3445 | |
Jacob Erlbeck | af952ba | 2014-09-17 12:09:25 +0200 | [diff] [blame] | 3446 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer[1], 0x1002, |
| 3447 | local_sgsn_tlli, 1, imsi3, sizeof(imsi3), |
| 3448 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3449 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 3450 | |
| 3451 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3452 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3453 | other_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN_NSEI); |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 3454 | OSMO_ASSERT(other_info); |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3455 | link_info = gbproxy_link_info_by_sgsn_tlli(peer, local_sgsn_tlli, SGSN2_NSEI); |
| 3456 | OSMO_ASSERT(link_info); |
| 3457 | OSMO_ASSERT(link_info != other_info); |
| 3458 | OSMO_ASSERT(link_info->tlli.current == local_bss_tlli3); |
| 3459 | OSMO_ASSERT(link_info->tlli.assigned == 0); |
| 3460 | OSMO_ASSERT(link_info->sgsn_tlli.current == local_sgsn_tlli); |
| 3461 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == 0); |
Jacob Erlbeck | 91a0e86 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 3462 | |
| 3463 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3464 | printf("--- Shutdown GPRS connection (SGSN 1) ---\n\n"); |
| 3465 | |
| 3466 | /* Detach */ |
| 3467 | send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002, |
| 3468 | local_bss_tlli, &rai_bss, cell_id, |
| 3469 | GPRS_SAPI_GMM, bss_nu++, |
| 3470 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 3471 | |
| 3472 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3473 | |
| 3474 | send_llc_dl_ui(nsi, "DETACH ACC", &sgsn_peer[0], 0x1002, |
| 3475 | local_sgsn_tlli, 1, imsi1, sizeof(imsi1), |
| 3476 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3477 | dtap_detach_acc, sizeof(dtap_detach_acc)); |
| 3478 | |
| 3479 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3480 | |
| 3481 | printf("--- Shutdown GPRS connection (SGSN 2) ---\n\n"); |
| 3482 | |
| 3483 | send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002, |
| 3484 | local_bss_tlli2, &rai_bss, cell_id, |
| 3485 | GPRS_SAPI_GMM, bss_nu++, |
| 3486 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 3487 | |
| 3488 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3489 | |
| 3490 | send_llc_dl_ui(nsi, "DETACH ACC", &sgsn_peer[1], 0x1002, |
| 3491 | local_sgsn_tlli2, 1, imsi2, sizeof(imsi2), |
| 3492 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3493 | dtap_detach_acc, sizeof(dtap_detach_acc)); |
| 3494 | |
| 3495 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3496 | |
Jacob Erlbeck | af952ba | 2014-09-17 12:09:25 +0200 | [diff] [blame] | 3497 | printf("--- Shutdown GPRS connection (SGSN 2, P-TMSI 1) ---\n\n"); |
| 3498 | |
| 3499 | send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002, |
| 3500 | local_bss_tlli3, &rai_bss, cell_id, |
| 3501 | GPRS_SAPI_GMM, bss_nu++, |
| 3502 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 3503 | |
| 3504 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3505 | |
| 3506 | send_llc_dl_ui(nsi, "DETACH ACC", &sgsn_peer[1], 0x1002, |
| 3507 | local_sgsn_tlli, 1, imsi3, sizeof(imsi3), |
| 3508 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3509 | dtap_detach_acc, sizeof(dtap_detach_acc)); |
| 3510 | |
| 3511 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3512 | |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3513 | dump_global(stdout, 0); |
| 3514 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 3515 | talloc_free(gbcfg.core_apn); |
| 3516 | gbcfg.core_apn = NULL; |
| 3517 | |
Jacob Erlbeck | b36032c | 2014-09-25 13:21:48 +0200 | [diff] [blame] | 3518 | gbproxy_clear_patch_filter(&gbcfg.matches[GBPROX_MATCH_ROUTING]); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3519 | gbprox_reset(&gbcfg); |
| 3520 | gprs_ns_destroy(nsi); |
| 3521 | nsi = NULL; |
Daniel Willmann | d1554ec | 2015-10-12 19:36:34 +0200 | [diff] [blame] | 3522 | |
| 3523 | cleanup_test(); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 3524 | } |
| 3525 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3526 | static void test_gbproxy_keep_info() |
| 3527 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 3528 | struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3529 | struct sockaddr_in bss_peer[1] = {{0},}; |
| 3530 | struct sockaddr_in sgsn_peer= {0}; |
| 3531 | struct gprs_ra_id rai_bss = |
| 3532 | {.mcc = 112, .mnc = 332, .lac = 16464, .rac = 96}; |
| 3533 | uint16_t cell_id = 0x1234; |
| 3534 | |
| 3535 | const uint32_t ptmsi = 0xefe2b700; |
| 3536 | const uint32_t local_tlli = 0xefe2b700; |
| 3537 | const uint32_t foreign_tlli = 0xafe2b700; |
| 3538 | |
| 3539 | const uint8_t imsi[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}; |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3540 | struct gbproxy_link_info *link_info, *link_info2; |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3541 | struct gbproxy_peer *peer; |
| 3542 | unsigned bss_nu = 0; |
| 3543 | unsigned sgsn_nu = 0; |
| 3544 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3545 | LLIST_HEAD(rcv_list); |
| 3546 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3547 | OSMO_ASSERT(local_tlli == gprs_tmsi2tlli(ptmsi, TLLI_LOCAL)); |
| 3548 | |
| 3549 | bssgp_nsi = nsi; |
| 3550 | gbcfg.nsi = bssgp_nsi; |
| 3551 | gbcfg.nsip_sgsn_nsei = SGSN_NSEI; |
| 3552 | gbcfg.patch_ptmsi = 0; |
| 3553 | gbcfg.acquire_imsi = 1; |
Neels Hofmeyr | 10719b7 | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 3554 | gbcfg.core_plmn = (struct osmo_plmn_id){}; |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3555 | gbcfg.core_apn = NULL; |
| 3556 | gbcfg.core_apn_size = 0; |
| 3557 | gbcfg.route_to_sgsn2 = 0; |
| 3558 | gbcfg.nsip_sgsn2_nsei = 0xffff; |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3559 | gbcfg.keep_link_infos = GBPROX_KEEP_ALWAYS; |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3560 | |
| 3561 | configure_sgsn_peer(&sgsn_peer); |
| 3562 | configure_bss_peers(bss_peer, ARRAY_SIZE(bss_peer)); |
| 3563 | |
| 3564 | printf("=== %s ===\n", __func__); |
| 3565 | printf("--- Initialise SGSN ---\n\n"); |
| 3566 | |
| 3567 | connect_sgsn(nsi, &sgsn_peer, SGSN_NSEI); |
| 3568 | |
| 3569 | printf("--- Initialise BSS 1 ---\n\n"); |
| 3570 | |
| 3571 | setup_ns(nsi, &bss_peer[0], 0x1001, 0x1000); |
| 3572 | setup_bssgp(nsi, &bss_peer[0], 0x1002); |
| 3573 | |
| 3574 | peer = gbproxy_peer_by_nsei(&gbcfg, 0x1000); |
| 3575 | OSMO_ASSERT(peer != NULL); |
| 3576 | |
| 3577 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002); |
| 3578 | |
| 3579 | gprs_dump_nsi(nsi); |
| 3580 | dump_global(stdout, 0); |
| 3581 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3582 | |
| 3583 | printf("--- Send message from BSS 1 to SGSN, BVCI 0x1002 ---\n\n"); |
| 3584 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3585 | received_messages = &rcv_list; |
| 3586 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3587 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 3588 | foreign_tlli, &rai_bss, cell_id, |
| 3589 | GPRS_SAPI_GMM, bss_nu++, |
| 3590 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 3591 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3592 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ID_REQ)); |
| 3593 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3594 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3595 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3596 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 3597 | OSMO_ASSERT(link_info); |
| 3598 | OSMO_ASSERT(link_info->imsi_len == 0); |
| 3599 | OSMO_ASSERT(!link_info->is_deregistered); |
| 3600 | OSMO_ASSERT(link_info->imsi_acq_pending); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3601 | |
| 3602 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 3603 | foreign_tlli, &rai_bss, cell_id, |
| 3604 | GPRS_SAPI_GMM, bss_nu++, |
| 3605 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 3606 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3607 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 3608 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3609 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3610 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3611 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 3612 | OSMO_ASSERT(link_info); |
| 3613 | OSMO_ASSERT(link_info->imsi_len > 0); |
| 3614 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
Jacob Erlbeck | 9d0fb1e | 2014-10-31 10:43:44 +0100 | [diff] [blame] | 3615 | OSMO_ASSERT(gprs_tlli_type(link_info->sgsn_tlli.current) == TLLI_FOREIGN); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 3616 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3617 | send_llc_dl_ui(nsi, "IDENT REQUEST", &sgsn_peer, 0x1002, |
| 3618 | foreign_tlli, 0, NULL, 0, |
| 3619 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3620 | dtap_identity_req, sizeof(dtap_identity_req)); |
| 3621 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3622 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ID_REQ)); |
| 3623 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3624 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3625 | |
| 3626 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 3627 | foreign_tlli, &rai_bss, cell_id, |
| 3628 | GPRS_SAPI_GMM, bss_nu++, |
| 3629 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 3630 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3631 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ID_RESP)); |
| 3632 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3633 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3634 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3635 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 3636 | OSMO_ASSERT(link_info); |
| 3637 | OSMO_ASSERT(link_info->imsi_len > 0); |
| 3638 | OSMO_ASSERT(gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi))); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3639 | |
| 3640 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 3641 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 3642 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3643 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 3644 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3645 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 3646 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3647 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3648 | |
| 3649 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 3650 | local_tlli, &rai_bss, cell_id, |
| 3651 | GPRS_SAPI_GMM, bss_nu++, |
| 3652 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 3653 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3654 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 3655 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3656 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3657 | |
| 3658 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 3659 | local_tlli, 1, imsi, sizeof(imsi), |
| 3660 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3661 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 3662 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3663 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_INFO)); |
| 3664 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3665 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3666 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3667 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 3668 | OSMO_ASSERT(link_info); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3669 | |
| 3670 | /* Detach (MO) */ |
| 3671 | send_llc_ul_ui(nsi, "DETACH REQ", &bss_peer[0], 0x1002, |
| 3672 | local_tlli, &rai_bss, cell_id, |
| 3673 | GPRS_SAPI_GMM, bss_nu++, |
| 3674 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 3675 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3676 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_DETACH_REQ)); |
| 3677 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3678 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 3679 | OSMO_ASSERT(link_info); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3680 | |
| 3681 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3682 | |
| 3683 | send_llc_dl_ui(nsi, "DETACH ACC", &sgsn_peer, 0x1002, |
| 3684 | local_tlli, 1, imsi, sizeof(imsi), |
| 3685 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3686 | dtap_detach_acc, sizeof(dtap_detach_acc)); |
| 3687 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3688 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_DETACH_ACK)); |
| 3689 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3690 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3691 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3692 | OSMO_ASSERT(!gbproxy_link_info_by_tlli(peer, local_tlli)); |
| 3693 | link_info = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3694 | OSMO_ASSERT(link_info); |
| 3695 | OSMO_ASSERT(link_info->is_deregistered); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3696 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3697 | OSMO_ASSERT(!expect_msg()); |
| 3698 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3699 | /* Re-Attach */ |
| 3700 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 3701 | foreign_tlli, &rai_bss, cell_id, |
| 3702 | GPRS_SAPI_GMM, bss_nu++, |
| 3703 | dtap_attach_req3, sizeof(dtap_attach_req3)); |
| 3704 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3705 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 3706 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3707 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3708 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3709 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3710 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 3711 | OSMO_ASSERT(link_info); |
| 3712 | OSMO_ASSERT(link_info == link_info2); |
| 3713 | OSMO_ASSERT(link_info->imsi_len != 0); |
| 3714 | OSMO_ASSERT(!link_info->is_deregistered); |
| 3715 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
Jacob Erlbeck | 9d0fb1e | 2014-10-31 10:43:44 +0100 | [diff] [blame] | 3716 | OSMO_ASSERT(gprs_tlli_type(link_info->sgsn_tlli.current) == TLLI_FOREIGN); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 3717 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3718 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 3719 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 3720 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3721 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 3722 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3723 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 3724 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3725 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3726 | |
| 3727 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 3728 | local_tlli, &rai_bss, cell_id, |
| 3729 | GPRS_SAPI_GMM, bss_nu++, |
| 3730 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 3731 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3732 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 3733 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3734 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3735 | |
| 3736 | /* Detach (MT) */ |
| 3737 | send_llc_dl_ui(nsi, "DETACH REQ (re-attach)", &sgsn_peer, 0x1002, |
| 3738 | local_tlli, 1, imsi, sizeof(imsi), |
| 3739 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3740 | dtap_mt_detach_rea_req, sizeof(dtap_mt_detach_rea_req)); |
| 3741 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3742 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_DETACH_REQ)); |
| 3743 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3744 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3745 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3746 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 3747 | OSMO_ASSERT(link_info); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3748 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3749 | send_llc_ul_ui(nsi, "DETACH ACC", &bss_peer[0], 0x1002, |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3750 | local_tlli, &rai_bss, cell_id, |
| 3751 | GPRS_SAPI_GMM, bss_nu++, |
| 3752 | dtap_mt_detach_acc, sizeof(dtap_mt_detach_acc)); |
| 3753 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3754 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_DETACH_ACK)); |
| 3755 | OSMO_ASSERT(!expect_msg()); |
| 3756 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3757 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3758 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3759 | OSMO_ASSERT(!gbproxy_link_info_by_tlli(peer, local_tlli)); |
| 3760 | link_info = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3761 | OSMO_ASSERT(link_info); |
| 3762 | OSMO_ASSERT(link_info->is_deregistered); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3763 | |
| 3764 | /* Re-Attach */ |
| 3765 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 3766 | foreign_tlli, &rai_bss, cell_id, |
| 3767 | GPRS_SAPI_GMM, bss_nu++, |
| 3768 | dtap_attach_req3, sizeof(dtap_attach_req3)); |
| 3769 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3770 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 3771 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3772 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3773 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3774 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3775 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 3776 | OSMO_ASSERT(link_info); |
| 3777 | OSMO_ASSERT(link_info == link_info2); |
| 3778 | OSMO_ASSERT(link_info->imsi_len != 0); |
| 3779 | OSMO_ASSERT(!link_info->is_deregistered); |
| 3780 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 3781 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3782 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 3783 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 3784 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3785 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 3786 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3787 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 3788 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3789 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3790 | |
| 3791 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 3792 | local_tlli, &rai_bss, cell_id, |
| 3793 | GPRS_SAPI_GMM, bss_nu++, |
| 3794 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 3795 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3796 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 3797 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3798 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3799 | |
| 3800 | /* Detach (MT) */ |
| 3801 | send_llc_dl_ui(nsi, "DETACH REQ", &sgsn_peer, 0x1002, |
| 3802 | local_tlli, 1, imsi, sizeof(imsi), |
| 3803 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3804 | dtap_mt_detach_req, sizeof(dtap_mt_detach_req)); |
| 3805 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3806 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_DETACH_REQ)); |
| 3807 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3808 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3809 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3810 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 3811 | OSMO_ASSERT(link_info); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3812 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3813 | send_llc_ul_ui(nsi, "DETACH ACC", &bss_peer[0], 0x1002, |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3814 | local_tlli, &rai_bss, cell_id, |
| 3815 | GPRS_SAPI_GMM, bss_nu++, |
| 3816 | dtap_mt_detach_acc, sizeof(dtap_mt_detach_acc)); |
| 3817 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3818 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_DETACH_ACK)); |
| 3819 | OSMO_ASSERT(!expect_msg()); |
| 3820 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3821 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3822 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3823 | OSMO_ASSERT(!gbproxy_link_info_by_tlli(peer, local_tlli)); |
| 3824 | link_info = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3825 | OSMO_ASSERT(link_info); |
| 3826 | OSMO_ASSERT(link_info->is_deregistered); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3827 | |
Jacob Erlbeck | 9d0fb1e | 2014-10-31 10:43:44 +0100 | [diff] [blame] | 3828 | /* Re-Attach with IMSI */ |
| 3829 | send_llc_ul_ui(nsi, "ATTACH REQUEST (IMSI)", &bss_peer[0], 0x1002, |
| 3830 | foreign_tlli, &rai_bss, cell_id, |
| 3831 | GPRS_SAPI_GMM, bss_nu++, |
| 3832 | dtap_attach_req4, sizeof(dtap_attach_req4)); |
| 3833 | |
| 3834 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 3835 | |
| 3836 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3837 | |
| 3838 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3839 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 3840 | OSMO_ASSERT(link_info); |
| 3841 | OSMO_ASSERT(link_info == link_info2); |
| 3842 | OSMO_ASSERT(link_info->imsi_len != 0); |
| 3843 | OSMO_ASSERT(!link_info->is_deregistered); |
| 3844 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
| 3845 | OSMO_ASSERT(link_info->sgsn_tlli.current == foreign_tlli); |
| 3846 | |
| 3847 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 3848 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 3849 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3850 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 3851 | |
| 3852 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 3853 | |
| 3854 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3855 | |
| 3856 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 3857 | local_tlli, &rai_bss, cell_id, |
| 3858 | GPRS_SAPI_GMM, bss_nu++, |
| 3859 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 3860 | |
| 3861 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 3862 | |
| 3863 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3864 | |
| 3865 | /* Detach (MT) */ |
| 3866 | send_llc_dl_ui(nsi, "DETACH REQ", &sgsn_peer, 0x1002, |
| 3867 | local_tlli, 1, imsi, sizeof(imsi), |
| 3868 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3869 | dtap_mt_detach_req, sizeof(dtap_mt_detach_req)); |
| 3870 | |
| 3871 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_DETACH_REQ)); |
| 3872 | |
| 3873 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3874 | |
| 3875 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 3876 | OSMO_ASSERT(link_info); |
| 3877 | |
| 3878 | send_llc_ul_ui(nsi, "DETACH ACC", &bss_peer[0], 0x1002, |
| 3879 | local_tlli, &rai_bss, cell_id, |
| 3880 | GPRS_SAPI_GMM, bss_nu++, |
| 3881 | dtap_mt_detach_acc, sizeof(dtap_mt_detach_acc)); |
| 3882 | |
| 3883 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_DETACH_ACK)); |
| 3884 | OSMO_ASSERT(!expect_msg()); |
| 3885 | |
| 3886 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3887 | |
| 3888 | OSMO_ASSERT(!gbproxy_link_info_by_tlli(peer, local_tlli)); |
| 3889 | link_info = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3890 | OSMO_ASSERT(link_info); |
| 3891 | OSMO_ASSERT(link_info->is_deregistered); |
| 3892 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3893 | /* Re-Attach */ |
| 3894 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 3895 | foreign_tlli, &rai_bss, cell_id, |
| 3896 | GPRS_SAPI_GMM, bss_nu++, |
| 3897 | dtap_attach_req3, sizeof(dtap_attach_req3)); |
| 3898 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3899 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 3900 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3901 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3902 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3903 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3904 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 3905 | OSMO_ASSERT(link_info); |
| 3906 | OSMO_ASSERT(link_info == link_info2); |
| 3907 | OSMO_ASSERT(link_info->imsi_len != 0); |
| 3908 | OSMO_ASSERT(!link_info->is_deregistered); |
| 3909 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 3910 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3911 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 3912 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 3913 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3914 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 3915 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3916 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 3917 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3918 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3919 | |
| 3920 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 3921 | local_tlli, &rai_bss, cell_id, |
| 3922 | GPRS_SAPI_GMM, bss_nu++, |
| 3923 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 3924 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3925 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 3926 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3927 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3928 | |
| 3929 | /* RA update procedure (reject -> Detach) */ |
| 3930 | send_llc_ul_ui(nsi, "RA UPD REQ", &bss_peer[0], 0x1002, |
| 3931 | local_tlli, &rai_bss, 0x7080, |
| 3932 | GPRS_SAPI_GMM, bss_nu++, |
| 3933 | dtap_ra_upd_req, sizeof(dtap_ra_upd_req)); |
| 3934 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3935 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_RA_UPD_REQ)); |
| 3936 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3937 | send_llc_dl_ui(nsi, "RA UDP REJ", &sgsn_peer, 0x1002, |
| 3938 | local_tlli, 1, imsi, sizeof(imsi), |
| 3939 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3940 | dtap_ra_upd_rej, sizeof(dtap_ra_upd_rej)); |
| 3941 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3942 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_RA_UPD_REJ)); |
| 3943 | OSMO_ASSERT(!expect_msg()); |
| 3944 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3945 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3946 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3947 | OSMO_ASSERT(!gbproxy_link_info_by_tlli(peer, local_tlli)); |
| 3948 | link_info = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3949 | OSMO_ASSERT(link_info); |
| 3950 | OSMO_ASSERT(link_info->is_deregistered); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 3951 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3952 | /* Bad case: Re-Attach with wrong (initial) P-TMSI */ |
| 3953 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 3954 | foreign_tlli, &rai_bss, cell_id, |
| 3955 | GPRS_SAPI_GMM, bss_nu++, |
| 3956 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 3957 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3958 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ID_REQ)); |
| 3959 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3960 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3961 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3962 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3963 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 3964 | OSMO_ASSERT(link_info); |
| 3965 | OSMO_ASSERT(link_info != link_info2); |
| 3966 | OSMO_ASSERT(link_info->imsi_len == 0); |
| 3967 | OSMO_ASSERT(!link_info->is_deregistered); |
| 3968 | OSMO_ASSERT(link_info->imsi_acq_pending); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 3969 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 3970 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 3971 | foreign_tlli, &rai_bss, cell_id, |
| 3972 | GPRS_SAPI_GMM, bss_nu++, |
| 3973 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 3974 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3975 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 3976 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 3977 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3978 | |
| 3979 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3980 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 3981 | OSMO_ASSERT(link_info); |
| 3982 | OSMO_ASSERT(link_info == link_info2); |
| 3983 | OSMO_ASSERT(link_info->imsi_len != 0); |
| 3984 | OSMO_ASSERT(!link_info->is_deregistered); |
| 3985 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
| 3986 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3987 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 3988 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 3989 | GPRS_SAPI_GMM, sgsn_nu++, |
| 3990 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 3991 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 3992 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 3993 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 3994 | dump_peers(stdout, 0, 0, &gbcfg); |
| 3995 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 3996 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 3997 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 3998 | OSMO_ASSERT(link_info); |
| 3999 | OSMO_ASSERT(link_info == link_info2); |
Jacob Erlbeck | ea71b48 | 2014-09-22 09:28:27 +0200 | [diff] [blame] | 4000 | OSMO_ASSERT(link_info->imsi_len > 0); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 4001 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 4002 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 4003 | local_tlli, &rai_bss, cell_id, |
| 4004 | GPRS_SAPI_GMM, bss_nu++, |
| 4005 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 4006 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4007 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 4008 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 4009 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4010 | |
| 4011 | /* Detach (MT) */ |
| 4012 | send_llc_dl_ui(nsi, "DETACH REQ", &sgsn_peer, 0x1002, |
| 4013 | local_tlli, 1, imsi, sizeof(imsi), |
| 4014 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4015 | dtap_mt_detach_req, sizeof(dtap_mt_detach_req)); |
| 4016 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4017 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_DETACH_REQ)); |
| 4018 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 4019 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4020 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4021 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 4022 | OSMO_ASSERT(link_info); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 4023 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4024 | send_llc_ul_ui(nsi, "DETACH ACC", &bss_peer[0], 0x1002, |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 4025 | local_tlli, &rai_bss, cell_id, |
| 4026 | GPRS_SAPI_GMM, bss_nu++, |
| 4027 | dtap_mt_detach_acc, sizeof(dtap_mt_detach_acc)); |
| 4028 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4029 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_DETACH_ACK)); |
| 4030 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 4031 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4032 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4033 | OSMO_ASSERT(!gbproxy_link_info_by_tlli(peer, local_tlli)); |
| 4034 | link_info = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 4035 | OSMO_ASSERT(link_info); |
| 4036 | OSMO_ASSERT(link_info->is_deregistered); |
Jacob Erlbeck | 7430da6 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 4037 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4038 | OSMO_ASSERT(!expect_msg()); |
| 4039 | |
Jacob Erlbeck | 9d0fb1e | 2014-10-31 10:43:44 +0100 | [diff] [blame] | 4040 | /* Bad case: Re-Attach with local TLLI */ |
| 4041 | send_llc_ul_ui(nsi, "ATTACH REQUEST (local TLLI)", &bss_peer[0], 0x1002, |
| 4042 | local_tlli, &rai_bss, cell_id, |
| 4043 | GPRS_SAPI_GMM, bss_nu++, |
| 4044 | dtap_attach_req3, sizeof(dtap_attach_req3)); |
| 4045 | |
| 4046 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 4047 | |
| 4048 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4049 | |
| 4050 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 4051 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 4052 | OSMO_ASSERT(link_info); |
| 4053 | OSMO_ASSERT(link_info == link_info2); |
| 4054 | OSMO_ASSERT(link_info->imsi_len != 0); |
| 4055 | OSMO_ASSERT(!link_info->is_deregistered); |
| 4056 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
| 4057 | OSMO_ASSERT(link_info->sgsn_tlli.current == local_tlli); |
| 4058 | |
| 4059 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 4060 | local_tlli, 1, imsi, sizeof(imsi), |
| 4061 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4062 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 4063 | |
| 4064 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 4065 | |
| 4066 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4067 | |
| 4068 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 4069 | local_tlli, &rai_bss, cell_id, |
| 4070 | GPRS_SAPI_GMM, bss_nu++, |
| 4071 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 4072 | |
| 4073 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 4074 | |
| 4075 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4076 | |
| 4077 | /* Detach (MT) */ |
| 4078 | send_llc_dl_ui(nsi, "DETACH REQ (re-attach)", &sgsn_peer, 0x1002, |
| 4079 | local_tlli, 1, imsi, sizeof(imsi), |
| 4080 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4081 | dtap_mt_detach_rea_req, sizeof(dtap_mt_detach_rea_req)); |
| 4082 | |
| 4083 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_DETACH_REQ)); |
| 4084 | |
| 4085 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4086 | |
| 4087 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 4088 | OSMO_ASSERT(link_info); |
| 4089 | |
| 4090 | send_llc_ul_ui(nsi, "DETACH ACC", &bss_peer[0], 0x1002, |
| 4091 | local_tlli, &rai_bss, cell_id, |
| 4092 | GPRS_SAPI_GMM, bss_nu++, |
| 4093 | dtap_mt_detach_acc, sizeof(dtap_mt_detach_acc)); |
| 4094 | |
| 4095 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_DETACH_ACK)); |
| 4096 | OSMO_ASSERT(!expect_msg()); |
| 4097 | |
| 4098 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4099 | |
| 4100 | OSMO_ASSERT(!gbproxy_link_info_by_tlli(peer, local_tlli)); |
| 4101 | link_info = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 4102 | OSMO_ASSERT(link_info); |
| 4103 | OSMO_ASSERT(link_info->is_deregistered); |
| 4104 | |
| 4105 | /* Bad case: Unexpected Re-Attach with IMSI after completed attachment |
| 4106 | * procedure */ |
| 4107 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 4108 | foreign_tlli, &rai_bss, cell_id, |
| 4109 | GPRS_SAPI_GMM, bss_nu++, |
| 4110 | dtap_attach_req3, sizeof(dtap_attach_req3)); |
| 4111 | |
| 4112 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 4113 | |
| 4114 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4115 | |
| 4116 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 4117 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 4118 | OSMO_ASSERT(link_info); |
| 4119 | OSMO_ASSERT(link_info == link_info2); |
| 4120 | OSMO_ASSERT(link_info->imsi_len != 0); |
| 4121 | OSMO_ASSERT(!link_info->is_deregistered); |
| 4122 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
| 4123 | |
| 4124 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 4125 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 4126 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4127 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 4128 | |
| 4129 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 4130 | |
| 4131 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4132 | |
| 4133 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 4134 | local_tlli, &rai_bss, cell_id, |
| 4135 | GPRS_SAPI_GMM, bss_nu++, |
| 4136 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 4137 | |
| 4138 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 4139 | |
| 4140 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4141 | |
| 4142 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 4143 | local_tlli, 1, imsi, sizeof(imsi), |
| 4144 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4145 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 4146 | |
| 4147 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_INFO)); |
| 4148 | |
| 4149 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4150 | |
| 4151 | send_llc_ul_ui(nsi, "ATTACH REQUEST (unexpected, IMSI)", |
| 4152 | &bss_peer[0], 0x1002, |
| 4153 | foreign_tlli, &rai_bss, cell_id, |
| 4154 | GPRS_SAPI_GMM, bss_nu++, |
| 4155 | dtap_attach_req4, sizeof(dtap_attach_req4)); |
| 4156 | |
| 4157 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 4158 | |
| 4159 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4160 | |
| 4161 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 4162 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
Jacob Erlbeck | 59ac49d | 2014-10-30 17:15:43 +0100 | [diff] [blame] | 4163 | OSMO_ASSERT(link_info); |
Jacob Erlbeck | 9d0fb1e | 2014-10-31 10:43:44 +0100 | [diff] [blame] | 4164 | OSMO_ASSERT(link_info == link_info2); |
| 4165 | OSMO_ASSERT(link_info->imsi_len != 0); |
| 4166 | OSMO_ASSERT(!link_info->is_deregistered); |
| 4167 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
Jacob Erlbeck | 59ac49d | 2014-10-30 17:15:43 +0100 | [diff] [blame] | 4168 | OSMO_ASSERT(link_info->sgsn_tlli.current == foreign_tlli); |
Jacob Erlbeck | 9d0fb1e | 2014-10-31 10:43:44 +0100 | [diff] [blame] | 4169 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == 0); |
| 4170 | |
| 4171 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 4172 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 4173 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4174 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 4175 | |
| 4176 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 4177 | |
| 4178 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4179 | |
| 4180 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 4181 | local_tlli, &rai_bss, cell_id, |
| 4182 | GPRS_SAPI_GMM, bss_nu++, |
| 4183 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 4184 | |
| 4185 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 4186 | |
| 4187 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4188 | |
| 4189 | /* Detach (MT) */ |
| 4190 | send_llc_dl_ui(nsi, "DETACH REQ", &sgsn_peer, 0x1002, |
| 4191 | local_tlli, 1, imsi, sizeof(imsi), |
| 4192 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4193 | dtap_mt_detach_req, sizeof(dtap_mt_detach_req)); |
| 4194 | |
| 4195 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_DETACH_REQ)); |
| 4196 | |
| 4197 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4198 | |
| 4199 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 4200 | OSMO_ASSERT(link_info); |
| 4201 | |
| 4202 | send_llc_ul_ui(nsi, "DETACH ACC", &bss_peer[0], 0x1002, |
| 4203 | local_tlli, &rai_bss, cell_id, |
| 4204 | GPRS_SAPI_GMM, bss_nu++, |
| 4205 | dtap_mt_detach_acc, sizeof(dtap_mt_detach_acc)); |
| 4206 | |
| 4207 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_DETACH_ACK)); |
| 4208 | OSMO_ASSERT(!expect_msg()); |
| 4209 | |
| 4210 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4211 | |
| 4212 | OSMO_ASSERT(!gbproxy_link_info_by_tlli(peer, local_tlli)); |
| 4213 | link_info = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 4214 | OSMO_ASSERT(link_info); |
| 4215 | OSMO_ASSERT(link_info->is_deregistered); |
| 4216 | |
| 4217 | /* Bad case: Unexpected Re-Attach with P-TMSI after completed attachment |
| 4218 | * procedure */ |
| 4219 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 4220 | foreign_tlli, &rai_bss, cell_id, |
| 4221 | GPRS_SAPI_GMM, bss_nu++, |
| 4222 | dtap_attach_req3, sizeof(dtap_attach_req3)); |
| 4223 | |
| 4224 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 4225 | |
| 4226 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4227 | |
| 4228 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 4229 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 4230 | OSMO_ASSERT(link_info); |
| 4231 | OSMO_ASSERT(link_info == link_info2); |
| 4232 | OSMO_ASSERT(link_info->imsi_len != 0); |
| 4233 | OSMO_ASSERT(!link_info->is_deregistered); |
| 4234 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
| 4235 | |
| 4236 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 4237 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 4238 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4239 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 4240 | |
| 4241 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 4242 | |
| 4243 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4244 | |
| 4245 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 4246 | local_tlli, &rai_bss, cell_id, |
| 4247 | GPRS_SAPI_GMM, bss_nu++, |
| 4248 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 4249 | |
| 4250 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 4251 | |
| 4252 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4253 | |
| 4254 | send_llc_dl_ui(nsi, "GMM INFO", &sgsn_peer, 0x1002, |
| 4255 | local_tlli, 1, imsi, sizeof(imsi), |
| 4256 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4257 | dtap_gmm_information, sizeof(dtap_gmm_information)); |
| 4258 | |
| 4259 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_INFO)); |
| 4260 | |
| 4261 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4262 | |
| 4263 | send_llc_ul_ui(nsi, "ATTACH REQUEST (unexpected)", &bss_peer[0], 0x1002, |
| 4264 | foreign_tlli, &rai_bss, cell_id, |
| 4265 | GPRS_SAPI_GMM, bss_nu++, |
| 4266 | dtap_attach_req3, sizeof(dtap_attach_req3)); |
| 4267 | |
| 4268 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 4269 | |
| 4270 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4271 | |
| 4272 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 4273 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
Jacob Erlbeck | 59ac49d | 2014-10-30 17:15:43 +0100 | [diff] [blame] | 4274 | OSMO_ASSERT(link_info); |
Jacob Erlbeck | 9d0fb1e | 2014-10-31 10:43:44 +0100 | [diff] [blame] | 4275 | OSMO_ASSERT(link_info == link_info2); |
| 4276 | OSMO_ASSERT(link_info->imsi_len != 0); |
| 4277 | OSMO_ASSERT(!link_info->is_deregistered); |
| 4278 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
Jacob Erlbeck | 59ac49d | 2014-10-30 17:15:43 +0100 | [diff] [blame] | 4279 | OSMO_ASSERT(link_info->sgsn_tlli.current == foreign_tlli); |
Jacob Erlbeck | 9d0fb1e | 2014-10-31 10:43:44 +0100 | [diff] [blame] | 4280 | OSMO_ASSERT(link_info->sgsn_tlli.assigned == 0); |
| 4281 | |
| 4282 | send_llc_dl_ui(nsi, "ATTACH ACCEPT", &sgsn_peer, 0x1002, |
| 4283 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 4284 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4285 | dtap_attach_acc, sizeof(dtap_attach_acc)); |
| 4286 | |
| 4287 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_ACK)); |
| 4288 | |
| 4289 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4290 | |
| 4291 | send_llc_ul_ui(nsi, "ATTACH COMPLETE", &bss_peer[0], 0x1002, |
| 4292 | local_tlli, &rai_bss, cell_id, |
| 4293 | GPRS_SAPI_GMM, bss_nu++, |
| 4294 | dtap_attach_complete, sizeof(dtap_attach_complete)); |
| 4295 | |
| 4296 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_COMPL)); |
| 4297 | |
| 4298 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4299 | |
| 4300 | /* Detach (MT) */ |
| 4301 | send_llc_dl_ui(nsi, "DETACH REQ", &sgsn_peer, 0x1002, |
| 4302 | local_tlli, 1, imsi, sizeof(imsi), |
| 4303 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4304 | dtap_mt_detach_req, sizeof(dtap_mt_detach_req)); |
| 4305 | |
| 4306 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_DETACH_REQ)); |
| 4307 | |
| 4308 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4309 | |
| 4310 | link_info = gbproxy_link_info_by_tlli(peer, local_tlli); |
| 4311 | OSMO_ASSERT(link_info); |
| 4312 | |
| 4313 | send_llc_ul_ui(nsi, "DETACH ACC", &bss_peer[0], 0x1002, |
| 4314 | local_tlli, &rai_bss, cell_id, |
| 4315 | GPRS_SAPI_GMM, bss_nu++, |
| 4316 | dtap_mt_detach_acc, sizeof(dtap_mt_detach_acc)); |
| 4317 | |
| 4318 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_DETACH_ACK)); |
| 4319 | OSMO_ASSERT(!expect_msg()); |
| 4320 | |
| 4321 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4322 | |
| 4323 | OSMO_ASSERT(!gbproxy_link_info_by_tlli(peer, local_tlli)); |
| 4324 | link_info = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 4325 | OSMO_ASSERT(link_info); |
| 4326 | OSMO_ASSERT(link_info->is_deregistered); |
| 4327 | |
| 4328 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4329 | /* Attach rejected */ |
| 4330 | |
| 4331 | gbproxy_delete_link_infos(peer); |
| 4332 | |
| 4333 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 4334 | foreign_tlli, &rai_bss, cell_id, |
| 4335 | GPRS_SAPI_GMM, bss_nu++, |
| 4336 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 4337 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4338 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ID_REQ)); |
| 4339 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4340 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4341 | |
| 4342 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 4343 | OSMO_ASSERT(link_info); |
| 4344 | OSMO_ASSERT(link_info->imsi_len == 0); |
| 4345 | OSMO_ASSERT(!link_info->is_deregistered); |
| 4346 | OSMO_ASSERT(link_info->imsi_acq_pending); |
| 4347 | |
| 4348 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 4349 | foreign_tlli, &rai_bss, cell_id, |
| 4350 | GPRS_SAPI_GMM, bss_nu++, |
| 4351 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 4352 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4353 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 4354 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4355 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4356 | |
| 4357 | link_info2 = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 4358 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 4359 | OSMO_ASSERT(link_info); |
| 4360 | OSMO_ASSERT(link_info == link_info2); |
| 4361 | OSMO_ASSERT(link_info->imsi_len != 0); |
| 4362 | OSMO_ASSERT(!link_info->is_deregistered); |
| 4363 | OSMO_ASSERT(!link_info->imsi_acq_pending); |
| 4364 | |
| 4365 | send_llc_dl_ui(nsi, "ATTACH REJECT", &sgsn_peer, 0x1002, |
| 4366 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 4367 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4368 | dtap_attach_rej7, sizeof(dtap_attach_rej7)); |
| 4369 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4370 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ATTACH_REJ)); |
| 4371 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4372 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4373 | |
Jacob Erlbeck | 9c65c81 | 2014-09-22 10:42:05 +0200 | [diff] [blame] | 4374 | OSMO_ASSERT(!gbproxy_link_info_by_tlli(peer, foreign_tlli)); |
| 4375 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4376 | OSMO_ASSERT(!expect_msg()); |
| 4377 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4378 | /* Attach (incomplete) and Detach (MO) */ |
| 4379 | |
| 4380 | gbproxy_delete_link_infos(peer); |
| 4381 | |
| 4382 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 4383 | foreign_tlli, &rai_bss, cell_id, |
| 4384 | GPRS_SAPI_GMM, bss_nu++, |
| 4385 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 4386 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4387 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ID_REQ)); |
| 4388 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4389 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4390 | |
| 4391 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 4392 | OSMO_ASSERT(link_info); |
| 4393 | OSMO_ASSERT(link_info->imsi_len == 0); |
| 4394 | OSMO_ASSERT(!link_info->is_deregistered); |
| 4395 | OSMO_ASSERT(link_info->imsi_acq_pending); |
| 4396 | |
| 4397 | send_llc_ul_ui(nsi, "DETACH REQ (MO)", &bss_peer[0], 0x1002, |
| 4398 | foreign_tlli, &rai_bss, cell_id, |
| 4399 | GPRS_SAPI_GMM, bss_nu++, |
| 4400 | dtap_detach_req, sizeof(dtap_detach_req)); |
| 4401 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4402 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_DETACH_ACK)); |
| 4403 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4404 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4405 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4406 | OSMO_ASSERT(!expect_msg()); |
| 4407 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4408 | /* Attach (incomplete) and Detach (MT) */ |
| 4409 | |
| 4410 | gbproxy_delete_link_infos(peer); |
| 4411 | |
| 4412 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 4413 | foreign_tlli, &rai_bss, cell_id, |
| 4414 | GPRS_SAPI_GMM, bss_nu++, |
| 4415 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 4416 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4417 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_ID_REQ)); |
| 4418 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4419 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4420 | |
| 4421 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 4422 | OSMO_ASSERT(link_info); |
| 4423 | OSMO_ASSERT(link_info->imsi_len == 0); |
| 4424 | OSMO_ASSERT(!link_info->is_deregistered); |
| 4425 | OSMO_ASSERT(link_info->imsi_acq_pending); |
| 4426 | |
| 4427 | send_llc_dl_ui(nsi, "DETACH REQ (MT)", &sgsn_peer, 0x1002, |
| 4428 | foreign_tlli, 1, imsi, sizeof(imsi), |
| 4429 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4430 | dtap_mt_detach_req, sizeof(dtap_mt_detach_req)); |
| 4431 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4432 | OSMO_ASSERT(expect_gmm_msg(0x1000, 0x1002, GSM48_MT_GMM_DETACH_REQ)); |
| 4433 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4434 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4435 | |
| 4436 | link_info = gbproxy_link_info_by_tlli(peer, foreign_tlli); |
| 4437 | OSMO_ASSERT(link_info); |
| 4438 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4439 | send_llc_ul_ui(nsi, "DETACH ACC", &bss_peer[0], 0x1002, |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4440 | foreign_tlli, &rai_bss, cell_id, |
| 4441 | GPRS_SAPI_GMM, bss_nu++, |
| 4442 | dtap_mt_detach_acc, sizeof(dtap_mt_detach_acc)); |
| 4443 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4444 | /* TODO: The stored messaged should be cleaned when receiving a Detach |
| 4445 | * Ack. Remove the first OSMO_ASSERT when this is fixed. */ |
| 4446 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_ATTACH_REQ)); |
| 4447 | OSMO_ASSERT(expect_gmm_msg(SGSN_NSEI, 0x1002, GSM48_MT_GMM_DETACH_ACK)); |
| 4448 | |
Jacob Erlbeck | 2bf3261 | 2014-09-22 11:26:58 +0200 | [diff] [blame] | 4449 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4450 | |
| 4451 | OSMO_ASSERT(!gbproxy_link_info_by_tlli(peer, foreign_tlli)); |
| 4452 | link_info = gbproxy_link_info_by_imsi(peer, imsi, sizeof(imsi)); |
| 4453 | OSMO_ASSERT(link_info); |
| 4454 | OSMO_ASSERT(link_info->is_deregistered); |
| 4455 | |
Jacob Erlbeck | fb83ed3 | 2014-09-22 19:16:06 +0200 | [diff] [blame] | 4456 | OSMO_ASSERT(!expect_msg()); |
| 4457 | received_messages = NULL; |
| 4458 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 4459 | dump_global(stdout, 0); |
| 4460 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 4461 | talloc_free(gbcfg.core_apn); |
| 4462 | gbcfg.core_apn = NULL; |
| 4463 | |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 4464 | gbprox_reset(&gbcfg); |
| 4465 | gprs_ns_destroy(nsi); |
| 4466 | nsi = NULL; |
Daniel Willmann | d1554ec | 2015-10-12 19:36:34 +0200 | [diff] [blame] | 4467 | |
| 4468 | cleanup_test(); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 4469 | } |
| 4470 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4471 | struct gbproxy_link_info *register_tlli( |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4472 | struct gbproxy_peer *peer, uint32_t tlli, |
| 4473 | const uint8_t *imsi, size_t imsi_len, time_t now) |
| 4474 | { |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4475 | struct gbproxy_link_info *link_info; |
Jacob Erlbeck | 8992f30 | 2014-09-19 13:17:55 +0200 | [diff] [blame] | 4476 | int imsi_matches = -1; |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4477 | int tlli_already_known = 0; |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4478 | struct gbproxy_config *cfg = peer->cfg; |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4479 | |
| 4480 | /* Check, whether the IMSI matches */ |
| 4481 | if (gprs_is_mi_imsi(imsi, imsi_len)) { |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4482 | imsi_matches = gbproxy_check_imsi( |
| 4483 | &cfg->matches[GBPROX_MATCH_PATCHING], imsi, imsi_len); |
Jacob Erlbeck | 8992f30 | 2014-09-19 13:17:55 +0200 | [diff] [blame] | 4484 | if (imsi_matches < 0) |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4485 | return NULL; |
| 4486 | } |
| 4487 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4488 | link_info = gbproxy_link_info_by_tlli(peer, tlli); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4489 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4490 | if (!link_info) { |
| 4491 | link_info = gbproxy_link_info_by_imsi(peer, imsi, imsi_len); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4492 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4493 | if (link_info) { |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4494 | /* TLLI has changed somehow, adjust it */ |
| 4495 | LOGP(DGPRS, LOGL_INFO, |
| 4496 | "The TLLI has changed from %08x to %08x\n", |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4497 | link_info->tlli.current, tlli); |
| 4498 | link_info->tlli.current = tlli; |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4499 | } |
| 4500 | } |
| 4501 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4502 | if (!link_info) { |
| 4503 | link_info = gbproxy_link_info_alloc(peer); |
| 4504 | link_info->tlli.current = tlli; |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4505 | } else { |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4506 | gbproxy_detach_link_info(peer, link_info); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4507 | tlli_already_known = 1; |
| 4508 | } |
| 4509 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4510 | OSMO_ASSERT(link_info != NULL); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4511 | |
| 4512 | if (!tlli_already_known) |
| 4513 | LOGP(DGPRS, LOGL_INFO, "Adding TLLI %08x to list\n", tlli); |
| 4514 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4515 | gbproxy_attach_link_info(peer, now, link_info); |
| 4516 | gbproxy_update_link_info(link_info, imsi, imsi_len); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4517 | |
Jacob Erlbeck | 8992f30 | 2014-09-19 13:17:55 +0200 | [diff] [blame] | 4518 | if (imsi_matches >= 0) |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4519 | link_info->is_matching[GBPROX_MATCH_PATCHING] = imsi_matches; |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4520 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4521 | return link_info; |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4522 | } |
| 4523 | |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4524 | static void test_gbproxy_tlli_expire(void) |
| 4525 | { |
| 4526 | struct gbproxy_config cfg = {0}; |
| 4527 | struct gbproxy_peer *peer; |
| 4528 | const char *err_msg = NULL; |
| 4529 | const uint8_t imsi1[] = { GSM_MI_TYPE_IMSI, 0x23, 0x24, 0x25, 0x26 }; |
| 4530 | const uint8_t imsi2[] = { GSM_MI_TYPE_IMSI, 0x26, 0x27, 0x28, 0x29 }; |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4531 | const uint8_t imsi3[] = { GSM_MI_TYPE_IMSI | 0x10, 0x32, 0x54, 0x76, 0xf8 }; |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4532 | const uint32_t tlli1 = 1234 | 0xc0000000; |
| 4533 | const uint32_t tlli2 = 5678 | 0xc0000000; |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4534 | const uint32_t tlli3 = 3456 | 0xc0000000; |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4535 | const char *filter_re = ".*"; |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 4536 | time_t now = 1407479214; |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4537 | |
| 4538 | printf("Test TLLI info expiry\n\n"); |
| 4539 | |
| 4540 | gbproxy_init_config(&cfg); |
| 4541 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4542 | if (gbproxy_set_patch_filter(&cfg.matches[GBPROX_MATCH_PATCHING], |
| 4543 | filter_re, &err_msg) != 0) { |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4544 | fprintf(stderr, "gbprox_set_patch_filter: got error: %s\n", |
| 4545 | err_msg); |
| 4546 | OSMO_ASSERT(err_msg == NULL); |
| 4547 | } |
| 4548 | |
| 4549 | { |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4550 | struct gbproxy_link_info *link_info; |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4551 | |
| 4552 | printf("Test TLLI replacement:\n"); |
| 4553 | |
| 4554 | cfg.tlli_max_len = 0; |
| 4555 | cfg.tlli_max_age = 0; |
| 4556 | peer = gbproxy_peer_alloc(&cfg, 20); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4557 | OSMO_ASSERT(peer->patch_state.logical_link_count == 0); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4558 | |
| 4559 | printf(" Add TLLI 1, IMSI 1\n"); |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4560 | link_info = register_tlli(peer, tlli1, |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 4561 | imsi1, ARRAY_SIZE(imsi1), now); |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4562 | OSMO_ASSERT(link_info); |
| 4563 | OSMO_ASSERT(link_info->tlli.current == tlli1); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4564 | OSMO_ASSERT(peer->patch_state.logical_link_count == 1); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4565 | |
| 4566 | /* replace the old entry */ |
| 4567 | printf(" Add TLLI 2, IMSI 1 (should replace TLLI 1)\n"); |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4568 | link_info = register_tlli(peer, tlli2, |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 4569 | imsi1, ARRAY_SIZE(imsi1), now); |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4570 | OSMO_ASSERT(link_info); |
| 4571 | OSMO_ASSERT(link_info->tlli.current == tlli2); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4572 | OSMO_ASSERT(peer->patch_state.logical_link_count == 1); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4573 | |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 4574 | dump_peers(stdout, 2, now, &cfg); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4575 | |
| 4576 | /* verify that 5678 has survived */ |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4577 | link_info = gbproxy_link_info_by_imsi(peer, imsi1, ARRAY_SIZE(imsi1)); |
| 4578 | OSMO_ASSERT(link_info); |
| 4579 | OSMO_ASSERT(link_info->tlli.current == tlli2); |
| 4580 | link_info = gbproxy_link_info_by_imsi(peer, imsi2, ARRAY_SIZE(imsi2)); |
| 4581 | OSMO_ASSERT(!link_info); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4582 | |
| 4583 | printf("\n"); |
| 4584 | |
| 4585 | gbproxy_peer_free(peer); |
| 4586 | } |
| 4587 | |
| 4588 | { |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4589 | struct gbproxy_link_info *link_info; |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4590 | |
| 4591 | printf("Test IMSI replacement:\n"); |
| 4592 | |
| 4593 | cfg.tlli_max_len = 0; |
| 4594 | cfg.tlli_max_age = 0; |
| 4595 | peer = gbproxy_peer_alloc(&cfg, 20); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4596 | OSMO_ASSERT(peer->patch_state.logical_link_count == 0); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4597 | |
| 4598 | printf(" Add TLLI 1, IMSI 1\n"); |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4599 | link_info = register_tlli(peer, tlli1, |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 4600 | imsi1, ARRAY_SIZE(imsi1), now); |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4601 | OSMO_ASSERT(link_info); |
| 4602 | OSMO_ASSERT(link_info->tlli.current == tlli1); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4603 | OSMO_ASSERT(peer->patch_state.logical_link_count == 1); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4604 | |
| 4605 | /* try to replace the old entry */ |
| 4606 | printf(" Add TLLI 1, IMSI 2 (should replace IMSI 1)\n"); |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4607 | link_info = register_tlli(peer, tlli1, |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 4608 | imsi2, ARRAY_SIZE(imsi2), now); |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4609 | OSMO_ASSERT(link_info); |
| 4610 | OSMO_ASSERT(link_info->tlli.current == tlli1); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4611 | OSMO_ASSERT(peer->patch_state.logical_link_count == 1); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4612 | |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 4613 | dump_peers(stdout, 2, now, &cfg); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4614 | |
| 4615 | /* verify that 5678 has survived */ |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4616 | link_info = gbproxy_link_info_by_imsi(peer, imsi1, ARRAY_SIZE(imsi1)); |
| 4617 | OSMO_ASSERT(!link_info); |
| 4618 | link_info = gbproxy_link_info_by_imsi(peer, imsi2, ARRAY_SIZE(imsi2)); |
| 4619 | OSMO_ASSERT(link_info); |
| 4620 | OSMO_ASSERT(link_info->tlli.current == tlli1); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4621 | |
| 4622 | printf("\n"); |
| 4623 | |
| 4624 | gbproxy_peer_free(peer); |
| 4625 | } |
| 4626 | |
| 4627 | { |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4628 | struct gbproxy_link_info *link_info; |
Jacob Erlbeck | aad32bc | 2014-08-07 17:23:00 +0200 | [diff] [blame] | 4629 | int num_removed; |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4630 | |
| 4631 | printf("Test TLLI expiry, max_len == 1:\n"); |
| 4632 | |
| 4633 | cfg.tlli_max_len = 1; |
| 4634 | cfg.tlli_max_age = 0; |
| 4635 | peer = gbproxy_peer_alloc(&cfg, 20); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4636 | OSMO_ASSERT(peer->patch_state.logical_link_count == 0); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4637 | |
| 4638 | printf(" Add TLLI 1, IMSI 1\n"); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4639 | register_tlli(peer, tlli1, imsi1, ARRAY_SIZE(imsi1), now); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4640 | OSMO_ASSERT(peer->patch_state.logical_link_count == 1); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4641 | |
| 4642 | /* replace the old entry */ |
| 4643 | printf(" Add TLLI 2, IMSI 2 (should replace IMSI 1)\n"); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4644 | register_tlli(peer, tlli2, imsi2, ARRAY_SIZE(imsi2), now); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4645 | OSMO_ASSERT(peer->patch_state.logical_link_count == 2); |
Jacob Erlbeck | aad32bc | 2014-08-07 17:23:00 +0200 | [diff] [blame] | 4646 | |
Jacob Erlbeck | 51fde08 | 2014-09-19 16:40:21 +0200 | [diff] [blame] | 4647 | num_removed = gbproxy_remove_stale_link_infos(peer, now + 2); |
Jacob Erlbeck | aad32bc | 2014-08-07 17:23:00 +0200 | [diff] [blame] | 4648 | OSMO_ASSERT(num_removed == 1); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4649 | OSMO_ASSERT(peer->patch_state.logical_link_count == 1); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4650 | |
Jacob Erlbeck | 7b821d0 | 2014-08-08 08:37:37 +0200 | [diff] [blame] | 4651 | dump_peers(stdout, 2, now, &cfg); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4652 | |
| 4653 | /* verify that 5678 has survived */ |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4654 | link_info = gbproxy_link_info_by_imsi(peer, imsi1, ARRAY_SIZE(imsi1)); |
| 4655 | OSMO_ASSERT(!link_info); |
| 4656 | link_info = gbproxy_link_info_by_imsi(peer, imsi2, ARRAY_SIZE(imsi2)); |
| 4657 | OSMO_ASSERT(link_info); |
| 4658 | OSMO_ASSERT(link_info->tlli.current == tlli2); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4659 | |
| 4660 | printf("\n"); |
| 4661 | |
| 4662 | gbproxy_peer_free(peer); |
| 4663 | } |
| 4664 | |
| 4665 | { |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4666 | struct gbproxy_link_info *link_info; |
Jacob Erlbeck | aad32bc | 2014-08-07 17:23:00 +0200 | [diff] [blame] | 4667 | int num_removed; |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4668 | |
| 4669 | printf("Test TLLI expiry, max_age == 1:\n"); |
| 4670 | |
| 4671 | cfg.tlli_max_len = 0; |
| 4672 | cfg.tlli_max_age = 1; |
| 4673 | peer = gbproxy_peer_alloc(&cfg, 20); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4674 | OSMO_ASSERT(peer->patch_state.logical_link_count == 0); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4675 | |
| 4676 | printf(" Add TLLI 1, IMSI 1 (should expire after timeout)\n"); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4677 | register_tlli(peer, tlli1, imsi1, ARRAY_SIZE(imsi1), now); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4678 | OSMO_ASSERT(peer->patch_state.logical_link_count == 1); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4679 | |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4680 | printf(" Add TLLI 2, IMSI 2 (should not expire after timeout)\n"); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4681 | register_tlli(peer, tlli2, imsi2, ARRAY_SIZE(imsi2), |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4682 | now + 1); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4683 | OSMO_ASSERT(peer->patch_state.logical_link_count == 2); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4684 | |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4685 | num_removed = gbproxy_remove_stale_link_infos(peer, now + 2); |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4686 | OSMO_ASSERT(num_removed == 1); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4687 | OSMO_ASSERT(peer->patch_state.logical_link_count == 1); |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4688 | |
| 4689 | dump_peers(stdout, 2, now + 2, &cfg); |
| 4690 | |
Jacob Erlbeck | 9057bc3 | 2014-08-12 16:30:30 +0200 | [diff] [blame] | 4691 | /* verify that 5678 has survived */ |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4692 | link_info = gbproxy_link_info_by_imsi(peer, imsi1, ARRAY_SIZE(imsi1)); |
| 4693 | OSMO_ASSERT(!link_info); |
| 4694 | link_info = gbproxy_link_info_by_imsi(peer, imsi2, ARRAY_SIZE(imsi2)); |
| 4695 | OSMO_ASSERT(link_info); |
| 4696 | OSMO_ASSERT(link_info->tlli.current == tlli2); |
Jacob Erlbeck | 9057bc3 | 2014-08-12 16:30:30 +0200 | [diff] [blame] | 4697 | |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4698 | printf("\n"); |
| 4699 | |
| 4700 | gbproxy_peer_free(peer); |
| 4701 | } |
| 4702 | |
| 4703 | { |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4704 | struct gbproxy_link_info *link_info; |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4705 | int num_removed; |
| 4706 | |
| 4707 | printf("Test TLLI expiry, max_len == 2, max_age == 1:\n"); |
| 4708 | |
| 4709 | cfg.tlli_max_len = 0; |
| 4710 | cfg.tlli_max_age = 1; |
| 4711 | peer = gbproxy_peer_alloc(&cfg, 20); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4712 | OSMO_ASSERT(peer->patch_state.logical_link_count == 0); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4713 | |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4714 | printf(" Add TLLI 1, IMSI 1 (should expire)\n"); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4715 | register_tlli(peer, tlli1, imsi1, ARRAY_SIZE(imsi1), now); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4716 | OSMO_ASSERT(peer->patch_state.logical_link_count == 1); |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4717 | |
| 4718 | printf(" Add TLLI 2, IMSI 2 (should expire after timeout)\n"); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4719 | register_tlli(peer, tlli2, imsi2, ARRAY_SIZE(imsi2), |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4720 | now + 1); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4721 | OSMO_ASSERT(peer->patch_state.logical_link_count == 2); |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4722 | |
| 4723 | printf(" Add TLLI 3, IMSI 3 (should not expire after timeout)\n"); |
Jacob Erlbeck | a42fe9f | 2014-09-12 14:15:02 +0200 | [diff] [blame] | 4724 | register_tlli(peer, tlli3, imsi3, ARRAY_SIZE(imsi3), |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 4725 | now + 2); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4726 | OSMO_ASSERT(peer->patch_state.logical_link_count == 3); |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4727 | |
| 4728 | dump_peers(stdout, 2, now + 2, &cfg); |
| 4729 | |
| 4730 | printf(" Remove stale TLLIs\n"); |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4731 | num_removed = gbproxy_remove_stale_link_infos(peer, now + 3); |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4732 | OSMO_ASSERT(num_removed == 2); |
Jacob Erlbeck | f8562e3 | 2014-09-19 16:03:07 +0200 | [diff] [blame] | 4733 | OSMO_ASSERT(peer->patch_state.logical_link_count == 1); |
Jacob Erlbeck | f494620 | 2014-08-08 09:33:06 +0200 | [diff] [blame] | 4734 | |
| 4735 | dump_peers(stdout, 2, now + 2, &cfg); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4736 | |
Jacob Erlbeck | 9057bc3 | 2014-08-12 16:30:30 +0200 | [diff] [blame] | 4737 | /* verify that tlli3 has survived */ |
Jacob Erlbeck | 91d2f8a | 2014-09-19 15:07:27 +0200 | [diff] [blame] | 4738 | link_info = gbproxy_link_info_by_imsi(peer, imsi1, ARRAY_SIZE(imsi1)); |
| 4739 | OSMO_ASSERT(!link_info); |
| 4740 | link_info = gbproxy_link_info_by_imsi(peer, imsi2, ARRAY_SIZE(imsi2)); |
| 4741 | OSMO_ASSERT(!link_info); |
| 4742 | link_info = gbproxy_link_info_by_imsi(peer, imsi3, ARRAY_SIZE(imsi3)); |
| 4743 | OSMO_ASSERT(link_info); |
| 4744 | OSMO_ASSERT(link_info->tlli.current == tlli3); |
Jacob Erlbeck | 9057bc3 | 2014-08-12 16:30:30 +0200 | [diff] [blame] | 4745 | |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4746 | printf("\n"); |
| 4747 | |
| 4748 | gbproxy_peer_free(peer); |
| 4749 | } |
Jacob Erlbeck | 9ccc41e | 2014-09-25 11:21:34 +0200 | [diff] [blame] | 4750 | gbproxy_clear_patch_filter(&cfg.matches[GBPROX_MATCH_PATCHING]); |
| 4751 | gbprox_reset(&cfg); |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 4752 | /* gbprox_reset() frees the rate_ctr, but re-allocates it again. */ |
| 4753 | rate_ctr_group_free(cfg.ctrg); |
Daniel Willmann | d1554ec | 2015-10-12 19:36:34 +0200 | [diff] [blame] | 4754 | |
| 4755 | cleanup_test(); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 4756 | } |
| 4757 | |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4758 | static void test_gbproxy_imsi_matching(void) |
| 4759 | { |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4760 | const char *err_msg = NULL; |
| 4761 | const uint8_t imsi1[] = { GSM_MI_TYPE_IMSI | 0x10, 0x32, 0x54, 0xf6 }; |
| 4762 | const uint8_t imsi2[] = { GSM_MI_TYPE_IMSI | GSM_MI_ODD | 0x10, 0x32, 0x54, 0x76 }; |
| 4763 | const uint8_t imsi3_bad[] = { GSM_MI_TYPE_IMSI | 0x10, 0xee, 0x54, 0xff }; |
| 4764 | const uint8_t tmsi1[] = { GSM_MI_TYPE_TMSI | 0xf0, 0x11, 0x22, 0x33, 0x44 }; |
| 4765 | const uint8_t tmsi2_bad[] = { GSM_MI_TYPE_TMSI | 0xf0, 0x11, 0x22 }; |
| 4766 | const uint8_t imei1[] = { GSM_MI_TYPE_IMEI | 0x10, 0x32, 0x54, 0xf6 }; |
| 4767 | const uint8_t imei2[] = { GSM_MI_TYPE_IMEI | GSM_MI_ODD | 0x10, 0x32, 0x54, 0x76 }; |
| 4768 | const char *filter_re1 = ".*"; |
| 4769 | const char *filter_re2 = "^1234"; |
| 4770 | const char *filter_re3 = "^4321"; |
| 4771 | const char *filter_re4_bad = "^12["; |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4772 | struct gbproxy_match match = {0,}; |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4773 | |
| 4774 | printf("=== Test IMSI/TMSI matching ===\n\n"); |
| 4775 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4776 | OSMO_ASSERT(match.enable == 0); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4777 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4778 | OSMO_ASSERT(gbproxy_set_patch_filter(&match, filter_re1, &err_msg) == 0); |
| 4779 | OSMO_ASSERT(match.enable == 1); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4780 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4781 | OSMO_ASSERT(gbproxy_set_patch_filter(&match, filter_re2, &err_msg) == 0); |
| 4782 | OSMO_ASSERT(match.enable == 1); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4783 | |
| 4784 | err_msg = NULL; |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4785 | OSMO_ASSERT(gbproxy_set_patch_filter(&match, filter_re4_bad, &err_msg) == -1); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4786 | OSMO_ASSERT(err_msg != NULL); |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4787 | OSMO_ASSERT(match.enable == 0); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4788 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4789 | OSMO_ASSERT(gbproxy_set_patch_filter(&match, filter_re2, &err_msg) == 0); |
| 4790 | OSMO_ASSERT(match.enable == 1); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4791 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4792 | OSMO_ASSERT(gbproxy_set_patch_filter(&match, NULL, &err_msg) == 0); |
| 4793 | OSMO_ASSERT(match.enable == 0); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4794 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4795 | OSMO_ASSERT(gbproxy_set_patch_filter(&match, filter_re2, &err_msg) == 0); |
| 4796 | OSMO_ASSERT(match.enable == 1); |
Jacob Erlbeck | 29805da | 2014-08-14 08:57:04 +0200 | [diff] [blame] | 4797 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4798 | gbproxy_clear_patch_filter(&match); |
| 4799 | OSMO_ASSERT(match.enable == 0); |
Jacob Erlbeck | 29805da | 2014-08-14 08:57:04 +0200 | [diff] [blame] | 4800 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4801 | OSMO_ASSERT(gbproxy_set_patch_filter(&match, filter_re2, &err_msg) == 0); |
| 4802 | OSMO_ASSERT(match.enable == 1); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4803 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4804 | OSMO_ASSERT(gbproxy_check_imsi(&match, imsi1, ARRAY_SIZE(imsi1)) == 1); |
| 4805 | OSMO_ASSERT(gbproxy_check_imsi(&match, imsi2, ARRAY_SIZE(imsi2)) == 1); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4806 | /* imsi3_bad contains 0xE and 0xF digits, but the conversion function |
Jacob Erlbeck | 9114bee | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 4807 | * doesn't complain, so gbproxy_check_imsi() doesn't return -1 in this |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4808 | * case. */ |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4809 | OSMO_ASSERT(gbproxy_check_imsi(&match, imsi3_bad, ARRAY_SIZE(imsi3_bad)) == 0); |
| 4810 | OSMO_ASSERT(gbproxy_check_imsi(&match, tmsi1, ARRAY_SIZE(tmsi1)) == -1); |
| 4811 | OSMO_ASSERT(gbproxy_check_imsi(&match, tmsi2_bad, ARRAY_SIZE(tmsi2_bad)) == -1); |
| 4812 | OSMO_ASSERT(gbproxy_check_imsi(&match, imei1, ARRAY_SIZE(imei1)) == -1); |
| 4813 | OSMO_ASSERT(gbproxy_check_imsi(&match, imei2, ARRAY_SIZE(imei2)) == -1); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4814 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4815 | OSMO_ASSERT(gbproxy_set_patch_filter(&match, filter_re3, &err_msg) == 0); |
| 4816 | OSMO_ASSERT(match.enable == 1); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4817 | |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 4818 | OSMO_ASSERT(gbproxy_check_imsi(&match, imsi1, ARRAY_SIZE(imsi1)) == 0); |
| 4819 | OSMO_ASSERT(gbproxy_check_imsi(&match, imsi2, ARRAY_SIZE(imsi2)) == 0); |
| 4820 | OSMO_ASSERT(gbproxy_check_imsi(&match, imsi3_bad, ARRAY_SIZE(imsi3_bad)) == 0); |
| 4821 | OSMO_ASSERT(gbproxy_check_imsi(&match, tmsi1, ARRAY_SIZE(tmsi1)) == -1); |
| 4822 | OSMO_ASSERT(gbproxy_check_imsi(&match, tmsi2_bad, ARRAY_SIZE(tmsi2_bad)) == -1); |
| 4823 | OSMO_ASSERT(gbproxy_check_imsi(&match, imei1, ARRAY_SIZE(imei1)) == -1); |
| 4824 | OSMO_ASSERT(gbproxy_check_imsi(&match, imei2, ARRAY_SIZE(imei2)) == -1); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4825 | |
| 4826 | /* TODO: Check correct length but wrong type with is_mi_tmsi */ |
Jacob Erlbeck | 9ccc41e | 2014-09-25 11:21:34 +0200 | [diff] [blame] | 4827 | |
| 4828 | gbproxy_clear_patch_filter(&match); |
| 4829 | OSMO_ASSERT(match.enable == 0); |
Daniel Willmann | d1554ec | 2015-10-12 19:36:34 +0200 | [diff] [blame] | 4830 | |
| 4831 | cleanup_test(); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 4832 | } |
| 4833 | |
Daniel Willmann | bb42eee | 2016-11-08 15:29:30 +0100 | [diff] [blame] | 4834 | static void test_gbproxy_stored_messages() |
| 4835 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 4836 | struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); |
Daniel Willmann | bb42eee | 2016-11-08 15:29:30 +0100 | [diff] [blame] | 4837 | struct sockaddr_in bss_peer[1] = {{0},}; |
| 4838 | struct sockaddr_in sgsn_peer= {0}; |
| 4839 | struct gprs_ra_id rai_bss = |
| 4840 | {.mcc = 112, .mnc = 332, .lac = 16464, .rac = 96}; |
| 4841 | struct gprs_ra_id rai_unknown = |
| 4842 | {.mcc = 1, .mnc = 99, .lac = 99, .rac = 96}; |
| 4843 | uint16_t cell_id = 0x1234; |
| 4844 | |
| 4845 | const uint32_t ptmsi = 0xefe2b700; |
| 4846 | const uint32_t local_tlli = 0xefe2b700; |
| 4847 | |
| 4848 | const uint32_t foreign_tlli1 = 0x8000dead; |
| 4849 | |
| 4850 | struct gbproxy_peer *peer; |
| 4851 | unsigned bss_nu = 0; |
| 4852 | unsigned sgsn_nu = 0; |
| 4853 | |
| 4854 | OSMO_ASSERT(local_tlli == gprs_tmsi2tlli(ptmsi, TLLI_LOCAL)); |
| 4855 | |
| 4856 | bssgp_nsi = nsi; |
| 4857 | gbcfg.nsi = bssgp_nsi; |
| 4858 | gbcfg.nsip_sgsn_nsei = SGSN_NSEI; |
Neels Hofmeyr | 10719b7 | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 4859 | gbcfg.core_plmn = (struct osmo_plmn_id){}; |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 4860 | gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); |
Daniel Willmann | bb42eee | 2016-11-08 15:29:30 +0100 | [diff] [blame] | 4861 | gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); |
| 4862 | gbcfg.patch_ptmsi = 0; |
| 4863 | gbcfg.acquire_imsi = 1; |
| 4864 | gbcfg.keep_link_infos = 0; |
| 4865 | |
| 4866 | configure_sgsn_peer(&sgsn_peer); |
| 4867 | configure_bss_peers(bss_peer, ARRAY_SIZE(bss_peer)); |
| 4868 | |
| 4869 | printf("=== %s ===\n", __func__); |
| 4870 | printf("--- Initialise SGSN ---\n\n"); |
| 4871 | |
| 4872 | connect_sgsn(nsi, &sgsn_peer, SGSN_NSEI); |
| 4873 | |
| 4874 | printf("--- Initialise BSS 1 ---\n\n"); |
| 4875 | |
| 4876 | setup_ns(nsi, &bss_peer[0], 0x1001, 0x1000); |
| 4877 | setup_bssgp(nsi, &bss_peer[0], 0x1002); |
| 4878 | |
| 4879 | peer = gbproxy_peer_by_nsei(&gbcfg, 0x1000); |
| 4880 | OSMO_ASSERT(peer != NULL); |
| 4881 | |
| 4882 | send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002); |
| 4883 | |
| 4884 | gprs_dump_nsi(nsi); |
| 4885 | dump_global(stdout, 0); |
| 4886 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4887 | |
| 4888 | printf("--- Establish first LLC connection ---\n\n"); |
| 4889 | |
| 4890 | send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002, |
| 4891 | foreign_tlli1, &rai_unknown, cell_id, |
| 4892 | GPRS_SAPI_GMM, bss_nu++, |
| 4893 | dtap_attach_req, sizeof(dtap_attach_req)); |
| 4894 | |
| 4895 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4896 | |
| 4897 | send_llc_dl_ui(nsi, "IDENT REQUEST", &sgsn_peer, 0x1002, |
| 4898 | foreign_tlli1, 0, NULL, 0, |
| 4899 | GPRS_SAPI_GMM, sgsn_nu++, |
| 4900 | dtap_identity_req, sizeof(dtap_identity_req)); |
| 4901 | |
| 4902 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4903 | |
| 4904 | send_llc_ul_ui(nsi, "DETACH ACCEPT", &bss_peer[0], 0x1002, |
| 4905 | foreign_tlli1, &rai_bss, cell_id, |
| 4906 | GPRS_SAPI_GMM, bss_nu++, |
| 4907 | dtap_detach_acc, sizeof(dtap_detach_acc)); |
| 4908 | |
| 4909 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4910 | |
| 4911 | send_llc_ul_ui(nsi, "IDENT RESPONSE", &bss_peer[0], 0x1002, |
| 4912 | foreign_tlli1, &rai_bss, cell_id, |
| 4913 | GPRS_SAPI_GMM, bss_nu++, |
| 4914 | dtap_identity_resp, sizeof(dtap_identity_resp)); |
| 4915 | |
| 4916 | dump_peers(stdout, 0, 0, &gbcfg); |
| 4917 | |
| 4918 | dump_global(stdout, 0); |
| 4919 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 4920 | talloc_free(gbcfg.core_apn); |
| 4921 | gbcfg.core_apn = NULL; |
| 4922 | |
Daniel Willmann | bb42eee | 2016-11-08 15:29:30 +0100 | [diff] [blame] | 4923 | gbprox_reset(&gbcfg); |
| 4924 | gprs_ns_destroy(nsi); |
| 4925 | nsi = NULL; |
| 4926 | |
| 4927 | cleanup_test(); |
| 4928 | } |
| 4929 | |
Stefan Sperling | aaa3e2b | 2018-06-07 19:12:25 +0200 | [diff] [blame] | 4930 | /* See OS#3178 "gbproxy: failed to parse invalid BSSGP-UNITDATA message" */ |
| 4931 | static void test_gbproxy_parse_bssgp_unitdata() |
| 4932 | { |
| 4933 | const char *hex = "0000239401e155cfea000004088872f4801018009c4000800e000601c0416c4338"; |
| 4934 | struct msgb *msg = msgb_alloc(1034, "bssgp_unitdata"); |
| 4935 | struct gprs_gb_parse_context parse_ctx; |
| 4936 | int rc; |
| 4937 | |
| 4938 | memset(&parse_ctx, 0, sizeof(parse_ctx)); |
| 4939 | |
| 4940 | OSMO_ASSERT(msg); |
| 4941 | msgb_bssgph(msg) = msg->head; |
| 4942 | msgb_put(msg, osmo_hexparse(hex, msg->head, msgb_tailroom(msg))); |
| 4943 | |
| 4944 | parse_ctx.to_bss = 0; |
| 4945 | parse_ctx.peer_nsei = msgb_nsei(msg); |
| 4946 | |
Stefan Sperling | aaa3e2b | 2018-06-07 19:12:25 +0200 | [diff] [blame] | 4947 | rc = gprs_gb_parse_bssgp(msg->data, msg->len, &parse_ctx); |
Stefan Sperling | 322643f | 2018-06-23 16:50:06 +0200 | [diff] [blame] | 4948 | if (!rc) |
| 4949 | fprintf(stderr, "%s: Test passed; Failed to parse invalid message %s\n", __func__, msgb_hexdump(msg)); |
| 4950 | else |
| 4951 | fprintf(stderr, "%s: Test failed; invalid message was accepted by parser: %s\n", __func__, msgb_hexdump(msg)); |
| 4952 | |
| 4953 | OSMO_ASSERT(!rc); |
| 4954 | |
| 4955 | /* Manually decoded message according to: |
| 4956 | ETSI TS 148 018 V10.6.0 (2012 07) 96 |
| 4957 | 3GPP TS 48.018 version 10.6.0 Release 10 |
| 4958 | Table 10.2.2: UL-UNITDATA PDU content |
| 4959 | |
| 4960 | 00 - PDU type UL-UNITDATA (ok) |
| 4961 | |
| 4962 | 11.3.35 Temporary logical link Identity (TLLI) |
| 4963 | 00 - TLLI[0] |
| 4964 | 23 - TLLI[1] |
| 4965 | 94 - TLLI[2] |
| 4966 | 01 - TLLI[3] |
| 4967 | TLLI == "00239401" |
| 4968 | |
| 4969 | e1 - QOS[0] (bit rate MSB) |
| 4970 | 55 - QOS[1] (bit rate LSB) |
| 4971 | bit rate = "57685" (57685*100000 bit/s per PBRG) |
| 4972 | cf - QOS[2] PBRG = 11 (bit rate is expressed in 100000 bit/s increments), |
| 4973 | C/R 0 (contains LLC ACK/SACK), |
| 4974 | T 0 (contains signalling), |
| 4975 | A 1 (radio if uses MAC/UNITDATA, |
| 4976 | Precedence 111 (reserved value) |
| 4977 | |
| 4978 | ea - CELL_ID[0] (TLV IEI: wrong, should be 0x08) |
| 4979 | 00 - CELL_ID[1] (length 1) |
| 4980 | 00 - CELL_ID[2] (length 2) |
| 4981 | lenth == 0 |
| 4982 | 04 -- CELL_ID[3] |
| 4983 | 08 -- CELL_ID[4] |
| 4984 | 88 -- CELL_ID[5] |
| 4985 | 72 -- CELL_ID[6] |
| 4986 | f4 -- CELL_ID[7] |
| 4987 | 80 -- CELL_ID[8] |
| 4988 | 10 -- CELL_DI[9] |
| 4989 | |
| 4990 | 18 -- QOSP[0] OoS Profile IEI |
| 4991 | not allowed in BSSGP Userdata |
| 4992 | 00 -- QOSP[1] |
| 4993 | 9c -- QOSP[2] |
| 4994 | 40 -- QOSP[3] |
| 4995 | 00 -- QOSP[4] |
| 4996 | |
| 4997 | 80 -- IEI for "E-UTRAN Inter RAT Handover Info" |
| 4998 | not allowed in BSSGP Userdata |
| 4999 | 0e -- length (14 bytes -- only 8 bytes remain) |
| 5000 | 00 06 01 c0 41 6c 43 38 */ |
Stefan Sperling | aaa3e2b | 2018-06-07 19:12:25 +0200 | [diff] [blame] | 5001 | |
| 5002 | msgb_free(msg); |
Stefan Sperling | 322643f | 2018-06-23 16:50:06 +0200 | [diff] [blame] | 5003 | |
| 5004 | cleanup_test(); |
Stefan Sperling | aaa3e2b | 2018-06-07 19:12:25 +0200 | [diff] [blame] | 5005 | } |
| 5006 | |
Jacob Erlbeck | 627e7d9 | 2014-07-03 13:28:13 +0200 | [diff] [blame] | 5007 | static struct log_info_cat gprs_categories[] = { |
| 5008 | [DGPRS] = { |
| 5009 | .name = "DGPRS", |
| 5010 | .description = "GPRS Packet Service", |
| 5011 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 5012 | }, |
| 5013 | [DNS] = { |
| 5014 | .name = "DNS", |
| 5015 | .description = "GPRS Network Service (NS)", |
| 5016 | .enabled = 1, .loglevel = LOGL_INFO, |
| 5017 | }, |
| 5018 | [DBSSGP] = { |
| 5019 | .name = "DBSSGP", |
| 5020 | .description = "GPRS BSS Gateway Protocol (BSSGP)", |
| 5021 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 5022 | }, |
Holger Hans Peter Freyther | 2840b3f | 2014-07-07 19:48:14 +0200 | [diff] [blame] | 5023 | }; |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 5024 | |
Holger Hans Peter Freyther | 2840b3f | 2014-07-07 19:48:14 +0200 | [diff] [blame] | 5025 | static struct log_info info = { |
Jacob Erlbeck | 627e7d9 | 2014-07-03 13:28:13 +0200 | [diff] [blame] | 5026 | .cat = gprs_categories, |
| 5027 | .num_cat = ARRAY_SIZE(gprs_categories), |
Holger Hans Peter Freyther | 2840b3f | 2014-07-07 19:48:14 +0200 | [diff] [blame] | 5028 | }; |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 5029 | |
| 5030 | int main(int argc, char **argv) |
| 5031 | { |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 5032 | talloc_enable_leak_report(); |
| 5033 | tall_bsc_ctx = talloc_named_const(NULL, 0, "gbproxy_test"); |
| 5034 | void *log_ctx = talloc_named_const(tall_bsc_ctx, 0, "log"); |
Neels Hofmeyr | 4c2d4ab | 2016-09-16 02:31:17 +0200 | [diff] [blame] | 5035 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 5036 | msgb_talloc_ctx_init(tall_bsc_ctx, 0); |
| 5037 | |
| 5038 | osmo_init_logging2(log_ctx, &info); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 5039 | log_set_use_color(osmo_stderr_target, 0); |
| 5040 | log_set_print_filename(osmo_stderr_target, 0); |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 5041 | osmo_signal_register_handler(SS_L_NS, &test_signal, &gbcfg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 5042 | |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 5043 | log_set_print_filename(osmo_stderr_target, 0); |
Jacob Erlbeck | 627e7d9 | 2014-07-03 13:28:13 +0200 | [diff] [blame] | 5044 | log_set_log_level(osmo_stderr_target, LOGL_DEBUG); |
| 5045 | log_set_all_filter(osmo_stderr_target, 1); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 5046 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 5047 | rate_ctr_init(tall_bsc_ctx); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 5048 | |
| 5049 | setlinebuf(stdout); |
| 5050 | |
| 5051 | printf("===== GbProxy test START\n"); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 5052 | gbproxy_init_config(&gbcfg); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 5053 | test_gbproxy(); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 5054 | test_gbproxy_ident_changes(); |
Jacob Erlbeck | 291f050 | 2014-08-07 10:46:29 +0200 | [diff] [blame] | 5055 | test_gbproxy_imsi_matching(); |
Jacob Erlbeck | 04f679b | 2014-09-18 09:21:20 +0200 | [diff] [blame] | 5056 | test_gbproxy_ptmsi_assignment(); |
Jacob Erlbeck | 7fb42db | 2014-07-07 10:46:01 +0200 | [diff] [blame] | 5057 | test_gbproxy_ra_patching(); |
Jacob Erlbeck | 6bd7ded | 2014-08-15 17:20:06 +0200 | [diff] [blame] | 5058 | test_gbproxy_ptmsi_patching(); |
Jacob Erlbeck | e99c333 | 2014-10-20 16:25:01 +0200 | [diff] [blame] | 5059 | test_gbproxy_ptmsi_patching_bad_cases(); |
Jacob Erlbeck | 28fe988 | 2014-08-26 13:33:36 +0200 | [diff] [blame] | 5060 | test_gbproxy_imsi_acquisition(); |
Jacob Erlbeck | f181f9e | 2014-08-27 12:44:25 +0200 | [diff] [blame] | 5061 | test_gbproxy_secondary_sgsn(); |
Jacob Erlbeck | 772a22b | 2014-09-15 14:18:09 +0200 | [diff] [blame] | 5062 | test_gbproxy_keep_info(); |
Holger Hans Peter Freyther | 0196c99 | 2014-08-04 17:10:08 +0200 | [diff] [blame] | 5063 | test_gbproxy_tlli_expire(); |
Daniel Willmann | bb42eee | 2016-11-08 15:29:30 +0100 | [diff] [blame] | 5064 | test_gbproxy_stored_messages(); |
Stefan Sperling | aaa3e2b | 2018-06-07 19:12:25 +0200 | [diff] [blame] | 5065 | test_gbproxy_parse_bssgp_unitdata(); |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 5066 | gbprox_reset(&gbcfg); |
| 5067 | /* gbprox_reset() frees the rate_ctr, but re-allocates it again. */ |
| 5068 | rate_ctr_group_free(gbcfg.ctrg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 5069 | printf("===== GbProxy test END\n\n"); |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 5070 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 5071 | talloc_free(log_ctx); |
| 5072 | /* expecting root and msgb ctx, empty */ |
| 5073 | OSMO_ASSERT(talloc_total_blocks(tall_bsc_ctx) == 2); |
| 5074 | talloc_free(tall_bsc_ctx); |
| 5075 | |
| 5076 | return 0; |
Jacob Erlbeck | 51a869c | 2013-10-15 12:00:26 +0200 | [diff] [blame] | 5077 | } |