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