Holger Hans Peter Freyther | 68c6f88 | 2014-09-30 09:10:25 +0200 | [diff] [blame] | 1 | /* Test the SGSN */ |
| 2 | /* |
| 3 | * (C) 2014 by Holger Hans Peter Freyther |
| 4 | * (C) 2014 by sysmocom s.f.m.c. GmbH |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 22 | #include <openbsc/gprs_llc.h> |
| 23 | #include <openbsc/sgsn.h> |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 24 | #include <openbsc/gprs_gmm.h> |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 25 | #include <openbsc/debug.h> |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 26 | #include <openbsc/gsm_subscriber.h> |
Harald Welte | 23d77d5 | 2016-04-25 19:07:34 +0200 | [diff] [blame] | 27 | #include <osmocom/gsm/gsup.h> |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 28 | #include <openbsc/gprs_gsup_client.h> |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 29 | #include <openbsc/gprs_utils.h> |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 30 | #include <openbsc/gprs_gb_parse.h> |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 31 | |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 32 | #include <osmocom/gprs/gprs_bssgp.h> |
| 33 | |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 34 | #include <osmocom/gsm/gsm_utils.h> |
| 35 | |
| 36 | #include <osmocom/core/application.h> |
| 37 | #include <osmocom/core/msgb.h> |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 38 | #include <osmocom/core/rate_ctr.h> |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 39 | |
Holger Hans Peter Freyther | 68c6f88 | 2014-09-30 09:10:25 +0200 | [diff] [blame] | 40 | #include <stdio.h> |
| 41 | |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 42 | extern void *tall_msgb_ctx; |
| 43 | |
| 44 | void *tall_bsc_ctx; |
| 45 | static struct sgsn_instance sgsn_inst = { |
| 46 | .config_file = "osmo_sgsn.cfg", |
| 47 | .cfg = { |
| 48 | .gtp_statedir = "./", |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 49 | .auth_policy = SGSN_AUTH_POLICY_CLOSED, |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 50 | }, |
| 51 | }; |
| 52 | struct sgsn_instance *sgsn = &sgsn_inst; |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 53 | unsigned sgsn_tx_counter = 0; |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 54 | struct msgb *last_msg = NULL; |
| 55 | struct gprs_gb_parse_context last_dl_parse_ctx; |
| 56 | |
| 57 | static void reset_last_msg() |
| 58 | { |
| 59 | if (last_msg) |
| 60 | msgb_free(last_msg); |
| 61 | |
| 62 | last_msg = NULL; |
| 63 | memset(&last_dl_parse_ctx, 0, sizeof(last_dl_parse_ctx)); |
| 64 | } |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 65 | |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 66 | static void cleanup_test() |
| 67 | { |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 68 | reset_last_msg(); |
| 69 | } |
| 70 | |
| 71 | static uint32_t get_new_ptmsi(const struct gprs_gb_parse_context *parse_ctx) |
| 72 | { |
| 73 | uint32_t new_ptmsi = GSM_RESERVED_TMSI; |
| 74 | |
| 75 | if (parse_ctx->new_ptmsi_enc) |
| 76 | gprs_parse_tmsi(parse_ctx->new_ptmsi_enc, &new_ptmsi); |
| 77 | |
| 78 | return new_ptmsi; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 81 | /* override */ |
| 82 | int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, |
| 83 | struct bssgp_dl_ud_par *dup) |
| 84 | { |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 85 | int rc; |
| 86 | |
| 87 | reset_last_msg(); |
| 88 | |
| 89 | last_msg = msg; |
| 90 | OSMO_ASSERT(msgb_data(last_msg) != NULL); |
| 91 | |
| 92 | rc = gprs_gb_parse_llc(msgb_data(last_msg), msgb_length(last_msg), |
| 93 | &last_dl_parse_ctx); |
| 94 | |
| 95 | fprintf(stderr, "Got DL LLC message: %s\n", |
| 96 | gprs_gb_message_name(&last_dl_parse_ctx, "UNKNOWN")); |
| 97 | |
| 98 | OSMO_ASSERT(rc > 0); |
| 99 | |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 100 | sgsn_tx_counter += 1; |
| 101 | return 0; |
| 102 | } |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 103 | |
Max | 4011e72 | 2016-07-05 15:19:12 +0200 | [diff] [blame] | 104 | /* override, requires '-Wl,--wrap=RAND_bytes' */ |
| 105 | int __real_RAND_bytes(unsigned char *buf, int num); |
| 106 | int mock_RAND_bytes(unsigned char *buf, int num); |
| 107 | int (*RAND_bytes_cb)(unsigned char *, int) = |
| 108 | &mock_RAND_bytes; |
| 109 | |
| 110 | int __wrap_RAND_bytes(unsigned char *buf, int num) |
| 111 | { |
| 112 | return (*RAND_bytes_cb)(buf, num); |
| 113 | } |
| 114 | /* make results of A&C ref predictable */ |
| 115 | int mock_RAND_bytes(unsigned char *buf, int num) |
| 116 | { |
| 117 | if (num > 1) |
| 118 | return __real_RAND_bytes(buf, num); |
| 119 | buf[0] = 0; |
| 120 | return 1; |
| 121 | } |
| 122 | |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 123 | /* override, requires '-Wl,--wrap=sgsn_update_subscriber_data' */ |
Jacob Erlbeck | 555b2e5 | 2015-01-26 13:52:42 +0100 | [diff] [blame] | 124 | void __real_sgsn_update_subscriber_data(struct sgsn_mm_ctx *); |
| 125 | void (*update_subscriber_data_cb)(struct sgsn_mm_ctx *) = |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 126 | &__real_sgsn_update_subscriber_data; |
| 127 | |
Jacob Erlbeck | 555b2e5 | 2015-01-26 13:52:42 +0100 | [diff] [blame] | 128 | void __wrap_sgsn_update_subscriber_data(struct sgsn_mm_ctx *mmctx) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 129 | { |
Jacob Erlbeck | 555b2e5 | 2015-01-26 13:52:42 +0100 | [diff] [blame] | 130 | (*update_subscriber_data_cb)(mmctx); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 131 | } |
| 132 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 133 | /* override, requires '-Wl,--wrap=gprs_subscr_request_update_location' */ |
| 134 | int __real_gprs_subscr_request_update_location(struct sgsn_mm_ctx *mmctx); |
| 135 | int (*subscr_request_update_location_cb)(struct sgsn_mm_ctx *mmctx) = |
| 136 | &__real_gprs_subscr_request_update_location; |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 137 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 138 | int __wrap_gprs_subscr_request_update_location(struct sgsn_mm_ctx *mmctx) { |
| 139 | return (*subscr_request_update_location_cb)(mmctx); |
| 140 | }; |
| 141 | |
| 142 | /* override, requires '-Wl,--wrap=gprs_subscr_request_auth_info' */ |
| 143 | int __real_gprs_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx); |
| 144 | int (*subscr_request_auth_info_cb)(struct sgsn_mm_ctx *mmctx) = |
| 145 | &__real_gprs_subscr_request_auth_info; |
| 146 | |
| 147 | int __wrap_gprs_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx) { |
| 148 | return (*subscr_request_auth_info_cb)(mmctx); |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 149 | }; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 150 | |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 151 | /* override, requires '-Wl,--wrap=gprs_gsup_client_send' */ |
| 152 | int __real_gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg); |
| 153 | int (*gprs_gsup_client_send_cb)(struct gprs_gsup_client *gsupc, struct msgb *msg) = |
| 154 | &__real_gprs_gsup_client_send; |
| 155 | |
| 156 | int __wrap_gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg) |
| 157 | { |
| 158 | return (*gprs_gsup_client_send_cb)(gsupc, msg); |
| 159 | }; |
| 160 | |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 161 | static int count(struct llist_head *head) |
| 162 | { |
| 163 | struct llist_head *cur; |
| 164 | int count = 0; |
| 165 | |
| 166 | llist_for_each(cur, head) |
| 167 | count += 1; |
| 168 | |
| 169 | return count; |
| 170 | } |
| 171 | |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 172 | static struct msgb *create_msg(const uint8_t *data, size_t len) |
| 173 | { |
| 174 | struct msgb *msg = msgb_alloc(len + 8, "test message"); |
| 175 | msg->l1h = msgb_put(msg, 8); |
| 176 | msg->l2h = msgb_put(msg, len); |
| 177 | memcpy(msg->l2h, data, len); |
| 178 | |
| 179 | msgb_bcid(msg) = msg->l1h; |
| 180 | msgb_gmmh(msg) = msg->l2h; |
| 181 | return msg; |
| 182 | } |
| 183 | |
Jacob Erlbeck | abc16a5 | 2014-10-27 13:23:49 +0100 | [diff] [blame] | 184 | /* |
| 185 | * Create a context and search for it |
| 186 | */ |
| 187 | static struct sgsn_mm_ctx *alloc_mm_ctx(uint32_t tlli, struct gprs_ra_id *raid) |
| 188 | { |
| 189 | struct sgsn_mm_ctx *ctx, *ictx; |
| 190 | struct gprs_llc_lle *lle; |
| 191 | int old_count = count(gprs_llme_list()); |
| 192 | |
| 193 | lle = gprs_lle_get_or_create(tlli, 3); |
| 194 | ctx = sgsn_mm_ctx_alloc(tlli, raid); |
| 195 | ctx->mm_state = GMM_REGISTERED_NORMAL; |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 196 | ctx->gb.llme = lle->llme; |
Jacob Erlbeck | abc16a5 | 2014-10-27 13:23:49 +0100 | [diff] [blame] | 197 | |
| 198 | ictx = sgsn_mm_ctx_by_tlli(tlli, raid); |
| 199 | OSMO_ASSERT(ictx == ctx); |
| 200 | |
| 201 | OSMO_ASSERT(count(gprs_llme_list()) == old_count + 1); |
| 202 | |
| 203 | return ctx; |
| 204 | } |
| 205 | |
Jacob Erlbeck | 94ef1c0 | 2014-10-29 10:31:18 +0100 | [diff] [blame] | 206 | static void send_0408_message(struct gprs_llc_llme *llme, uint32_t tlli, |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 207 | const struct gprs_ra_id *bssgp_raid, |
Jacob Erlbeck | 94ef1c0 | 2014-10-29 10:31:18 +0100 | [diff] [blame] | 208 | const uint8_t *data, size_t data_len) |
| 209 | { |
| 210 | struct msgb *msg; |
| 211 | |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 212 | reset_last_msg(); |
Jacob Erlbeck | 94ef1c0 | 2014-10-29 10:31:18 +0100 | [diff] [blame] | 213 | sgsn_tx_counter = 0; |
| 214 | |
| 215 | msg = create_msg(data, data_len); |
| 216 | msgb_tlli(msg) = tlli; |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 217 | bssgp_create_cell_id(msgb_bcid(msg), bssgp_raid, 0); |
Max | 8204010 | 2016-07-06 11:59:18 +0200 | [diff] [blame] | 218 | gsm0408_gprs_rcvmsg_gb(msg, llme, false); |
Jacob Erlbeck | 94ef1c0 | 2014-10-29 10:31:18 +0100 | [diff] [blame] | 219 | msgb_free(msg); |
| 220 | } |
| 221 | |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 222 | static void test_llme(void) |
| 223 | { |
| 224 | struct gprs_llc_lle *lle, *lle_copy; |
| 225 | uint32_t local_tlli; |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 226 | |
| 227 | printf("Testing LLME allocations\n"); |
| 228 | local_tlli = gprs_tmsi2tlli(0x234, TLLI_LOCAL); |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 229 | |
| 230 | /* initial state */ |
| 231 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 232 | |
| 233 | /* Create a new entry */ |
| 234 | lle = gprs_lle_get_or_create(local_tlli, 3); |
| 235 | OSMO_ASSERT(lle); |
| 236 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 237 | |
| 238 | /* No new entry is created */ |
| 239 | lle_copy = gprs_lle_get_or_create(local_tlli, 3); |
| 240 | OSMO_ASSERT(lle == lle_copy); |
| 241 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 242 | |
| 243 | /* unassign which should delete it*/ |
Max | 3955025 | 2016-06-28 17:39:20 +0200 | [diff] [blame] | 244 | gprs_llgmm_unassign(lle->llme); |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 245 | |
| 246 | /* Check that everything was cleaned up */ |
| 247 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 248 | |
| 249 | cleanup_test(); |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 250 | } |
| 251 | |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 252 | struct gsm_subscriber *last_updated_subscr = NULL; |
Jacob Erlbeck | 555b2e5 | 2015-01-26 13:52:42 +0100 | [diff] [blame] | 253 | void my_dummy_sgsn_update_subscriber_data(struct sgsn_mm_ctx *mmctx) |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 254 | { |
Jacob Erlbeck | 555b2e5 | 2015-01-26 13:52:42 +0100 | [diff] [blame] | 255 | OSMO_ASSERT(mmctx); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 256 | fprintf(stderr, "Called %s, mmctx = %p, subscr = %p\n", |
Jacob Erlbeck | 555b2e5 | 2015-01-26 13:52:42 +0100 | [diff] [blame] | 257 | __func__, mmctx, mmctx->subscr); |
| 258 | last_updated_subscr = mmctx->subscr; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Jacob Erlbeck | b8fb140 | 2015-01-09 11:59:50 +0100 | [diff] [blame] | 261 | static void assert_subscr(const struct gsm_subscriber *subscr, const char *imsi) |
| 262 | { |
| 263 | struct gsm_subscriber *sfound; |
Jacob Erlbeck | 6be9ffa | 2015-01-19 08:57:07 +0100 | [diff] [blame] | 264 | OSMO_ASSERT(subscr); |
| 265 | OSMO_ASSERT(strcmp(subscr->imsi, imsi) == 0); |
Jacob Erlbeck | b8fb140 | 2015-01-09 11:59:50 +0100 | [diff] [blame] | 266 | |
| 267 | sfound = gprs_subscr_get_by_imsi(imsi); |
| 268 | OSMO_ASSERT(sfound == subscr); |
Jacob Erlbeck | b8fb140 | 2015-01-09 11:59:50 +0100 | [diff] [blame] | 269 | |
Jacob Erlbeck | 6be9ffa | 2015-01-19 08:57:07 +0100 | [diff] [blame] | 270 | subscr_put(sfound); |
Jacob Erlbeck | b8fb140 | 2015-01-09 11:59:50 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Jacob Erlbeck | 058bc26 | 2015-01-13 11:46:32 +0100 | [diff] [blame] | 273 | static void show_subscrs(FILE *out) |
| 274 | { |
| 275 | struct gsm_subscriber *subscr; |
| 276 | |
| 277 | llist_for_each_entry(subscr, &active_subscribers, entry) { |
| 278 | fprintf(out, " Subscriber: %s, " |
Holger Hans Peter Freyther | 1d778fd | 2015-01-20 21:14:03 +0100 | [diff] [blame] | 279 | "use count: %d\n", |
| 280 | subscr->imsi, subscr->use_count); |
Jacob Erlbeck | 058bc26 | 2015-01-13 11:46:32 +0100 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
| 284 | static void assert_no_subscrs() |
| 285 | { |
| 286 | show_subscrs(stdout); |
| 287 | fflush(stdout); |
| 288 | OSMO_ASSERT(llist_empty(&active_subscribers)); |
| 289 | } |
| 290 | |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 291 | static void test_subscriber(void) |
| 292 | { |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 293 | struct gsm_subscriber *s1, *s2, *s3, *sfound; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 294 | const char *imsi1 = "1234567890"; |
| 295 | const char *imsi2 = "9876543210"; |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 296 | const char *imsi3 = "5656565656"; |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 297 | |
| 298 | update_subscriber_data_cb = my_dummy_sgsn_update_subscriber_data; |
| 299 | |
| 300 | printf("Testing core subscriber data API\n"); |
| 301 | |
| 302 | /* Check for emptiness */ |
| 303 | OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL); |
| 304 | OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi2) == NULL); |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 305 | OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi3) == NULL); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 306 | |
| 307 | /* Allocate entry 1 */ |
| 308 | s1 = gprs_subscr_get_or_create(imsi1); |
| 309 | s1->flags |= GSM_SUBSCRIBER_FIRST_CONTACT; |
Jacob Erlbeck | b8fb140 | 2015-01-09 11:59:50 +0100 | [diff] [blame] | 310 | assert_subscr(s1, imsi1); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 311 | OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi2) == NULL); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 312 | |
| 313 | /* Allocate entry 2 */ |
| 314 | s2 = gprs_subscr_get_or_create(imsi2); |
| 315 | s2->flags |= GSM_SUBSCRIBER_FIRST_CONTACT; |
Jacob Erlbeck | b8fb140 | 2015-01-09 11:59:50 +0100 | [diff] [blame] | 316 | |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 317 | /* Allocate entry 3 */ |
| 318 | s3 = gprs_subscr_get_or_create(imsi3); |
| 319 | |
Jacob Erlbeck | b8fb140 | 2015-01-09 11:59:50 +0100 | [diff] [blame] | 320 | /* Check entries */ |
| 321 | assert_subscr(s1, imsi1); |
| 322 | assert_subscr(s2, imsi2); |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 323 | assert_subscr(s3, imsi3); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 324 | |
| 325 | /* Update entry 1 */ |
| 326 | last_updated_subscr = NULL; |
| 327 | gprs_subscr_update(s1); |
Jacob Erlbeck | 555b2e5 | 2015-01-26 13:52:42 +0100 | [diff] [blame] | 328 | OSMO_ASSERT(last_updated_subscr == NULL); |
| 329 | OSMO_ASSERT(s1->sgsn_data->mm == NULL); |
| 330 | OSMO_ASSERT((s1->flags & GSM_SUBSCRIBER_FIRST_CONTACT) == 0); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 331 | |
Holger Hans Peter Freyther | 1d778fd | 2015-01-20 21:14:03 +0100 | [diff] [blame] | 332 | /* There is no subscriber cache. Verify it */ |
Jacob Erlbeck | 3e4e58f | 2015-01-26 11:07:24 +0100 | [diff] [blame] | 333 | gprs_subscr_cleanup(s1); |
Jacob Erlbeck | 37139e5 | 2015-01-23 13:52:55 +0100 | [diff] [blame] | 334 | subscr_put(s1); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 335 | s1 = NULL; |
Holger Hans Peter Freyther | 1d778fd | 2015-01-20 21:14:03 +0100 | [diff] [blame] | 336 | sfound = gprs_subscr_get_by_imsi(imsi1); |
| 337 | OSMO_ASSERT(sfound == NULL); |
| 338 | |
Jacob Erlbeck | b8fb140 | 2015-01-09 11:59:50 +0100 | [diff] [blame] | 339 | assert_subscr(s2, imsi2); |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 340 | assert_subscr(s3, imsi3); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 341 | |
Jacob Erlbeck | b8fb140 | 2015-01-09 11:59:50 +0100 | [diff] [blame] | 342 | /* Free entry 2 (GSM_SUBSCRIBER_FIRST_CONTACT is set) */ |
Jacob Erlbeck | 3e4e58f | 2015-01-26 11:07:24 +0100 | [diff] [blame] | 343 | gprs_subscr_cleanup(s2); |
Jacob Erlbeck | 37139e5 | 2015-01-23 13:52:55 +0100 | [diff] [blame] | 344 | subscr_put(s2); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 345 | s2 = NULL; |
| 346 | OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL); |
| 347 | OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi2) == NULL); |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 348 | assert_subscr(s3, imsi3); |
| 349 | |
| 350 | /* Try to delete entry 3 */ |
Jacob Erlbeck | 3e4e58f | 2015-01-26 11:07:24 +0100 | [diff] [blame] | 351 | gprs_subscr_cleanup(s3); |
Jacob Erlbeck | 37139e5 | 2015-01-23 13:52:55 +0100 | [diff] [blame] | 352 | subscr_put(s3); |
Holger Hans Peter Freyther | 1d778fd | 2015-01-20 21:14:03 +0100 | [diff] [blame] | 353 | s3 = NULL; |
Jacob Erlbeck | 0f47b8f | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 354 | OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi3) == NULL); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 355 | |
| 356 | OSMO_ASSERT(llist_empty(&active_subscribers)); |
| 357 | |
| 358 | update_subscriber_data_cb = __real_sgsn_update_subscriber_data; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 359 | |
| 360 | cleanup_test(); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 361 | } |
| 362 | |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 363 | static void test_auth_triplets(void) |
| 364 | { |
| 365 | struct gsm_subscriber *s1, *s1found; |
| 366 | const char *imsi1 = "1234567890"; |
| 367 | struct gsm_auth_tuple *at; |
| 368 | struct sgsn_mm_ctx *ctx; |
| 369 | struct gprs_ra_id raid = { 0, }; |
| 370 | uint32_t local_tlli = 0xffeeddcc; |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 371 | |
| 372 | printf("Testing authentication triplet handling\n"); |
| 373 | |
| 374 | /* Check for emptiness */ |
| 375 | OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL); |
| 376 | |
| 377 | /* Allocate entry 1 */ |
| 378 | s1 = gprs_subscr_get_or_create(imsi1); |
| 379 | s1->flags |= GSM_SUBSCRIBER_FIRST_CONTACT; |
| 380 | s1found = gprs_subscr_get_by_imsi(imsi1); |
| 381 | OSMO_ASSERT(s1found == s1); |
| 382 | subscr_put(s1found); |
| 383 | |
| 384 | /* Create a context */ |
| 385 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 386 | ctx = alloc_mm_ctx(local_tlli, &raid); |
| 387 | |
| 388 | /* Attach s1 to ctx */ |
| 389 | ctx->subscr = subscr_get(s1); |
| 390 | ctx->subscr->sgsn_data->mm = ctx; |
| 391 | |
| 392 | /* Try to get auth tuple */ |
| 393 | at = sgsn_auth_get_tuple(ctx, GSM_KEY_SEQ_INVAL); |
| 394 | OSMO_ASSERT(at == NULL); |
| 395 | |
| 396 | /* Add triplets */ |
| 397 | s1->sgsn_data->auth_triplets[0].key_seq = 0; |
| 398 | s1->sgsn_data->auth_triplets[1].key_seq = 1; |
| 399 | s1->sgsn_data->auth_triplets[2].key_seq = 2; |
| 400 | |
| 401 | /* Try to get auth tuple */ |
| 402 | at = sgsn_auth_get_tuple(ctx, GSM_KEY_SEQ_INVAL); |
| 403 | OSMO_ASSERT(at != NULL); |
| 404 | OSMO_ASSERT(at->key_seq == 0); |
| 405 | OSMO_ASSERT(at->use_count == 1); |
| 406 | at = sgsn_auth_get_tuple(ctx, at->key_seq); |
| 407 | OSMO_ASSERT(at != NULL); |
| 408 | OSMO_ASSERT(at->key_seq == 1); |
| 409 | OSMO_ASSERT(at->use_count == 1); |
| 410 | at = sgsn_auth_get_tuple(ctx, at->key_seq); |
| 411 | OSMO_ASSERT(at != NULL); |
| 412 | OSMO_ASSERT(at->key_seq == 2); |
| 413 | OSMO_ASSERT(at->use_count == 1); |
| 414 | at = sgsn_auth_get_tuple(ctx, at->key_seq); |
| 415 | OSMO_ASSERT(at == NULL); |
| 416 | |
| 417 | /* Free MM context and subscriber */ |
| 418 | subscr_put(s1); |
Jacob Erlbeck | e671d25 | 2015-01-26 14:43:07 +0100 | [diff] [blame] | 419 | sgsn_mm_ctx_cleanup_free(ctx); |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 420 | s1found = gprs_subscr_get_by_imsi(imsi1); |
| 421 | OSMO_ASSERT(s1found == NULL); |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 422 | |
| 423 | cleanup_test(); |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 426 | #define TEST_GSUP_IMSI1_IE 0x01, 0x05, 0x21, 0x43, 0x65, 0x87, 0x09 |
| 427 | |
Jacob Erlbeck | e21e184 | 2014-12-19 18:19:50 +0100 | [diff] [blame] | 428 | static int rx_gsup_message(const uint8_t *data, size_t data_len) |
| 429 | { |
| 430 | struct msgb *msg; |
| 431 | int rc; |
| 432 | |
| 433 | msg = msgb_alloc(1024, __func__); |
| 434 | msg->l2h = msgb_put(msg, data_len); |
| 435 | OSMO_ASSERT(msg->l2h != NULL); |
| 436 | memcpy(msg->l2h, data, data_len); |
| 437 | rc = gprs_subscr_rx_gsup_message(msg); |
| 438 | msgb_free(msg); |
| 439 | |
| 440 | return rc; |
| 441 | } |
| 442 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 443 | static void test_subscriber_gsup(void) |
| 444 | { |
| 445 | struct gsm_subscriber *s1, *s1found; |
| 446 | const char *imsi1 = "1234567890"; |
| 447 | struct sgsn_mm_ctx *ctx; |
| 448 | struct gprs_ra_id raid = { 0, }; |
| 449 | uint32_t local_tlli = 0xffeeddcc; |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 450 | struct sgsn_subscriber_pdp_data *pdpd; |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 451 | int rc; |
| 452 | |
| 453 | static const uint8_t send_auth_info_res[] = { |
| 454 | 0x0a, |
| 455 | TEST_GSUP_IMSI1_IE, |
| 456 | 0x03, 0x22, /* Auth tuple */ |
| 457 | 0x20, 0x10, |
| 458 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 459 | 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, |
| 460 | 0x21, 0x04, |
| 461 | 0x21, 0x22, 0x23, 0x24, |
| 462 | 0x22, 0x08, |
| 463 | 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, |
| 464 | 0x03, 0x22, /* Auth tuple */ |
| 465 | 0x20, 0x10, |
| 466 | 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, |
| 467 | 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, |
| 468 | 0x21, 0x04, |
| 469 | 0xa1, 0xa2, 0xa3, 0xa4, |
| 470 | 0x22, 0x08, |
| 471 | 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, |
| 472 | }; |
| 473 | |
| 474 | static const uint8_t send_auth_info_err[] = { |
| 475 | 0x09, |
| 476 | TEST_GSUP_IMSI1_IE, |
| 477 | 0x02, 0x01, 0x07 /* GPRS not allowed */ |
| 478 | }; |
| 479 | |
Holger Hans Peter Freyther | 9ba273d | 2015-04-23 09:53:53 -0400 | [diff] [blame] | 480 | #define MSISDN 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 |
| 481 | |
| 482 | static const uint8_t s1_msisdn[] = { MSISDN }; |
| 483 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 484 | static const uint8_t update_location_res[] = { |
| 485 | 0x06, |
| 486 | TEST_GSUP_IMSI1_IE, |
Holger Hans Peter Freyther | 9ba273d | 2015-04-23 09:53:53 -0400 | [diff] [blame] | 487 | 0x08, 0x09, MSISDN, |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 488 | 0x04, 0x00, /* PDP info complete */ |
| 489 | 0x05, 0x12, |
| 490 | 0x10, 0x01, 0x01, |
| 491 | 0x11, 0x02, 0xf1, 0x21, /* IPv4 */ |
| 492 | 0x12, 0x09, 0x04, 't', 'e', 's', 't', 0x03, 'a', 'p', 'n', |
| 493 | 0x05, 0x11, |
| 494 | 0x10, 0x01, 0x02, |
| 495 | 0x11, 0x02, 0xf1, 0x21, /* IPv4 */ |
| 496 | 0x12, 0x08, 0x03, 'f', 'o', 'o', 0x03, 'a', 'p', 'n', |
| 497 | }; |
| 498 | |
Holger Hans Peter Freyther | 9ba273d | 2015-04-23 09:53:53 -0400 | [diff] [blame] | 499 | #undef MSISDN |
| 500 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 501 | static const uint8_t update_location_err[] = { |
| 502 | 0x05, |
| 503 | TEST_GSUP_IMSI1_IE, |
| 504 | 0x02, 0x01, 0x07 /* GPRS not allowed */ |
| 505 | }; |
| 506 | |
| 507 | static const uint8_t location_cancellation_req[] = { |
| 508 | 0x1c, |
| 509 | TEST_GSUP_IMSI1_IE, |
| 510 | 0x06, 0x01, 0x00, |
| 511 | }; |
| 512 | |
Jacob Erlbeck | 5b51205 | 2015-04-07 17:49:48 +0200 | [diff] [blame] | 513 | static const uint8_t location_cancellation_req_withdraw[] = { |
| 514 | 0x1c, |
| 515 | TEST_GSUP_IMSI1_IE, |
| 516 | 0x06, 0x01, 0x01, |
| 517 | }; |
| 518 | |
Jacob Erlbeck | 87c7ffc | 2015-01-08 15:29:01 +0100 | [diff] [blame] | 519 | static const uint8_t location_cancellation_req_other[] = { |
| 520 | 0x1c, |
| 521 | 0x01, 0x05, 0x11, 0x11, 0x11, 0x11, 0x01, |
| 522 | 0x06, 0x01, 0x00, |
| 523 | }; |
| 524 | |
Jacob Erlbeck | 466cedd | 2015-01-29 14:12:29 +0100 | [diff] [blame] | 525 | static const uint8_t purge_ms_err[] = { |
| 526 | 0x0d, |
| 527 | TEST_GSUP_IMSI1_IE, |
| 528 | 0x02, 0x01, 0x02, /* IMSI unknown in HLR */ |
| 529 | }; |
| 530 | |
Jacob Erlbeck | 9ff8289 | 2015-01-29 14:17:51 +0100 | [diff] [blame] | 531 | static const uint8_t purge_ms_err_no_cause[] = { |
| 532 | 0x0d, |
| 533 | TEST_GSUP_IMSI1_IE, |
| 534 | }; |
| 535 | |
Jacob Erlbeck | 466cedd | 2015-01-29 14:12:29 +0100 | [diff] [blame] | 536 | static const uint8_t purge_ms_res[] = { |
| 537 | 0x0e, |
| 538 | TEST_GSUP_IMSI1_IE, |
| 539 | 0x07, 0x00, |
| 540 | }; |
| 541 | |
| 542 | |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 543 | static const uint8_t insert_data_req[] = { |
| 544 | 0x10, |
| 545 | TEST_GSUP_IMSI1_IE, |
| 546 | 0x05, 0x11, |
| 547 | 0x10, 0x01, 0x03, |
| 548 | 0x11, 0x02, 0xf1, 0x21, /* IPv4 */ |
| 549 | 0x12, 0x08, 0x03, 'b', 'a', 'r', 0x03, 'a', 'p', 'n', |
| 550 | }; |
| 551 | |
| 552 | static const uint8_t delete_data_req[] = { |
| 553 | 0x14, |
| 554 | TEST_GSUP_IMSI1_IE, |
| 555 | 0x10, 0x01, 0x03, |
| 556 | }; |
| 557 | |
Neels Hofmeyr | 241bda0 | 2016-06-20 18:26:15 +0200 | [diff] [blame] | 558 | printf("Testing subscriber GSUP handling\n"); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 559 | |
| 560 | update_subscriber_data_cb = my_dummy_sgsn_update_subscriber_data; |
| 561 | |
| 562 | /* Check for emptiness */ |
| 563 | OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL); |
| 564 | |
| 565 | /* Allocate entry 1 */ |
| 566 | s1 = gprs_subscr_get_or_create(imsi1); |
| 567 | s1->flags |= GSM_SUBSCRIBER_FIRST_CONTACT; |
| 568 | s1found = gprs_subscr_get_by_imsi(imsi1); |
| 569 | OSMO_ASSERT(s1found == s1); |
| 570 | subscr_put(s1found); |
| 571 | |
| 572 | /* Create a context */ |
| 573 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 574 | ctx = alloc_mm_ctx(local_tlli, &raid); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 575 | |
| 576 | /* Attach s1 to ctx */ |
| 577 | ctx->subscr = subscr_get(s1); |
| 578 | ctx->subscr->sgsn_data->mm = ctx; |
| 579 | |
| 580 | /* Inject SendAuthInfoReq GSUP message */ |
Jacob Erlbeck | e21e184 | 2014-12-19 18:19:50 +0100 | [diff] [blame] | 581 | rc = rx_gsup_message(send_auth_info_res, sizeof(send_auth_info_res)); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 582 | OSMO_ASSERT(rc >= 0); |
| 583 | OSMO_ASSERT(last_updated_subscr == s1); |
| 584 | |
| 585 | /* Check triplets */ |
| 586 | OSMO_ASSERT(s1->sgsn_data->auth_triplets[0].key_seq == 0); |
| 587 | OSMO_ASSERT(s1->sgsn_data->auth_triplets[1].key_seq == 1); |
| 588 | OSMO_ASSERT(s1->sgsn_data->auth_triplets[2].key_seq == GSM_KEY_SEQ_INVAL); |
| 589 | |
| 590 | /* Inject SendAuthInfoErr GSUP message */ |
Jacob Erlbeck | e21e184 | 2014-12-19 18:19:50 +0100 | [diff] [blame] | 591 | rc = rx_gsup_message(send_auth_info_err, sizeof(send_auth_info_err)); |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 592 | OSMO_ASSERT(rc == -GMM_CAUSE_GPRS_NOTALLOWED); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 593 | OSMO_ASSERT(last_updated_subscr == s1); |
Jacob Erlbeck | baf0f94 | 2015-01-29 14:55:34 +0100 | [diff] [blame] | 594 | OSMO_ASSERT(s1->sgsn_data->error_cause == GMM_CAUSE_GPRS_NOTALLOWED); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 595 | |
| 596 | /* Check triplets */ |
| 597 | OSMO_ASSERT(s1->sgsn_data->auth_triplets[0].key_seq == GSM_KEY_SEQ_INVAL); |
| 598 | OSMO_ASSERT(s1->sgsn_data->auth_triplets[1].key_seq == GSM_KEY_SEQ_INVAL); |
| 599 | OSMO_ASSERT(s1->sgsn_data->auth_triplets[2].key_seq == GSM_KEY_SEQ_INVAL); |
| 600 | |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 601 | /* Inject UpdateLocRes GSUP message */ |
Jacob Erlbeck | e21e184 | 2014-12-19 18:19:50 +0100 | [diff] [blame] | 602 | rc = rx_gsup_message(update_location_res, sizeof(update_location_res)); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 603 | OSMO_ASSERT(rc >= 0); |
| 604 | OSMO_ASSERT(last_updated_subscr == s1); |
Jacob Erlbeck | 466cedd | 2015-01-29 14:12:29 +0100 | [diff] [blame] | 605 | OSMO_ASSERT(s1->flags & GPRS_SUBSCRIBER_ENABLE_PURGE); |
Jacob Erlbeck | baf0f94 | 2015-01-29 14:55:34 +0100 | [diff] [blame] | 606 | OSMO_ASSERT(s1->sgsn_data->error_cause == SGSN_ERROR_CAUSE_NONE); |
Holger Hans Peter Freyther | 9ba273d | 2015-04-23 09:53:53 -0400 | [diff] [blame] | 607 | OSMO_ASSERT(s1->sgsn_data->msisdn_len == sizeof(s1_msisdn)); |
| 608 | OSMO_ASSERT(memcmp(s1->sgsn_data->msisdn, s1_msisdn, sizeof(s1_msisdn)) == 0); |
Jacob Erlbeck | 0e8add6 | 2014-12-17 14:03:35 +0100 | [diff] [blame] | 609 | OSMO_ASSERT(!llist_empty(&s1->sgsn_data->pdp_list)); |
| 610 | pdpd = llist_entry(s1->sgsn_data->pdp_list.next, |
| 611 | struct sgsn_subscriber_pdp_data, list); |
| 612 | OSMO_ASSERT(strcmp(pdpd->apn_str, "test.apn") == 0); |
| 613 | pdpd = llist_entry(pdpd->list.next, |
| 614 | struct sgsn_subscriber_pdp_data, list); |
| 615 | OSMO_ASSERT(strcmp(pdpd->apn_str, "foo.apn") == 0); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 616 | |
| 617 | /* Check authorization */ |
| 618 | OSMO_ASSERT(s1->authorized == 1); |
| 619 | |
| 620 | /* Inject UpdateLocErr GSUP message */ |
Jacob Erlbeck | e21e184 | 2014-12-19 18:19:50 +0100 | [diff] [blame] | 621 | rc = rx_gsup_message(update_location_err, sizeof(update_location_err)); |
Jacob Erlbeck | bce2061 | 2015-01-05 18:57:32 +0100 | [diff] [blame] | 622 | OSMO_ASSERT(rc == -GMM_CAUSE_GPRS_NOTALLOWED); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 623 | OSMO_ASSERT(last_updated_subscr == s1); |
Jacob Erlbeck | baf0f94 | 2015-01-29 14:55:34 +0100 | [diff] [blame] | 624 | OSMO_ASSERT(s1->sgsn_data->error_cause == GMM_CAUSE_GPRS_NOTALLOWED); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 625 | |
| 626 | /* Check authorization */ |
| 627 | OSMO_ASSERT(s1->authorized == 0); |
| 628 | |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 629 | /* Inject InsertSubscrData GSUP message */ |
| 630 | last_updated_subscr = NULL; |
| 631 | rc = rx_gsup_message(insert_data_req, sizeof(insert_data_req)); |
Harald Welte | cd5e526 | 2016-05-06 13:46:21 +0200 | [diff] [blame] | 632 | OSMO_ASSERT(rc = -ENOTSUP); /* not connected */ |
| 633 | OSMO_ASSERT(last_updated_subscr == s1); |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 634 | |
| 635 | /* Inject DeleteSubscrData GSUP message */ |
| 636 | last_updated_subscr = NULL; |
| 637 | rc = rx_gsup_message(delete_data_req, sizeof(delete_data_req)); |
| 638 | OSMO_ASSERT(rc == -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL); |
| 639 | OSMO_ASSERT(last_updated_subscr == NULL); |
| 640 | |
Jacob Erlbeck | 87c7ffc | 2015-01-08 15:29:01 +0100 | [diff] [blame] | 641 | /* Inject wrong LocCancelReq GSUP message */ |
| 642 | last_updated_subscr = NULL; |
| 643 | rc = rx_gsup_message(location_cancellation_req_other, |
| 644 | sizeof(location_cancellation_req_other)); |
| 645 | OSMO_ASSERT(rc == -GMM_CAUSE_IMSI_UNKNOWN); |
| 646 | OSMO_ASSERT(last_updated_subscr == NULL); |
| 647 | |
| 648 | /* Check cancellation result */ |
| 649 | OSMO_ASSERT(!(s1->flags & GPRS_SUBSCRIBER_CANCELLED)); |
| 650 | OSMO_ASSERT(s1->sgsn_data->mm != NULL); |
| 651 | |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 652 | /* Inject LocCancelReq GSUP message */ |
Jacob Erlbeck | e21e184 | 2014-12-19 18:19:50 +0100 | [diff] [blame] | 653 | rc = rx_gsup_message(location_cancellation_req, |
| 654 | sizeof(location_cancellation_req)); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 655 | OSMO_ASSERT(rc >= 0); |
| 656 | OSMO_ASSERT(last_updated_subscr == s1); |
Jacob Erlbeck | baf0f94 | 2015-01-29 14:55:34 +0100 | [diff] [blame] | 657 | OSMO_ASSERT(s1->sgsn_data->error_cause == SGSN_ERROR_CAUSE_NONE); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 658 | |
| 659 | /* Check cancellation result */ |
| 660 | OSMO_ASSERT(s1->flags & GPRS_SUBSCRIBER_CANCELLED); |
| 661 | OSMO_ASSERT(s1->sgsn_data->mm == NULL); |
| 662 | |
Jacob Erlbeck | 5b51205 | 2015-04-07 17:49:48 +0200 | [diff] [blame] | 663 | /* Inject LocCancelReq(withdraw) GSUP message */ |
| 664 | rc = rx_gsup_message(location_cancellation_req_withdraw, |
| 665 | sizeof(location_cancellation_req_withdraw)); |
| 666 | OSMO_ASSERT(rc >= 0); |
| 667 | OSMO_ASSERT(s1->sgsn_data->error_cause == GMM_CAUSE_IMPL_DETACHED); |
| 668 | |
Jacob Erlbeck | 466cedd | 2015-01-29 14:12:29 +0100 | [diff] [blame] | 669 | /* Inject PurgeMsRes GSUP message */ |
| 670 | rc = rx_gsup_message(purge_ms_res, |
| 671 | sizeof(purge_ms_res)); |
| 672 | OSMO_ASSERT(rc >= 0); |
| 673 | OSMO_ASSERT(!(s1->flags & GPRS_SUBSCRIBER_ENABLE_PURGE)); |
| 674 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 675 | /* Free MM context and subscriber */ |
Jacob Erlbeck | 4b2d02d | 2015-01-30 11:57:25 +0100 | [diff] [blame] | 676 | OSMO_ASSERT(ctx->subscr == NULL); |
| 677 | sgsn_mm_ctx_cleanup_free(ctx); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 678 | subscr_put(s1); |
| 679 | s1found = gprs_subscr_get_by_imsi(imsi1); |
| 680 | OSMO_ASSERT(s1found == NULL); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 681 | |
Jacob Erlbeck | 466cedd | 2015-01-29 14:12:29 +0100 | [diff] [blame] | 682 | /* Inject PurgeMsRes GSUP message */ |
| 683 | rc = rx_gsup_message(purge_ms_res, |
| 684 | sizeof(purge_ms_res)); |
| 685 | OSMO_ASSERT(rc >= 0); |
| 686 | |
| 687 | /* Inject PurgeMsErr(IMSI unknown in HLR) GSUP message */ |
| 688 | rc = rx_gsup_message(purge_ms_err, |
| 689 | sizeof(purge_ms_err)); |
| 690 | OSMO_ASSERT(rc == -GMM_CAUSE_IMSI_UNKNOWN); |
| 691 | |
Jacob Erlbeck | 9ff8289 | 2015-01-29 14:17:51 +0100 | [diff] [blame] | 692 | /* Inject PurgeMsErr() GSUP message */ |
| 693 | rc = rx_gsup_message(purge_ms_err_no_cause, |
| 694 | sizeof(purge_ms_err_no_cause)); |
| 695 | OSMO_ASSERT(rc == -GMM_CAUSE_NET_FAIL); |
| 696 | |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 697 | /* Inject InsertSubscrData GSUP message (unknown IMSI) */ |
| 698 | last_updated_subscr = NULL; |
| 699 | rc = rx_gsup_message(insert_data_req, sizeof(insert_data_req)); |
Jacob Erlbeck | 4dedb27 | 2015-01-15 17:50:16 +0100 | [diff] [blame] | 700 | OSMO_ASSERT(rc == -GMM_CAUSE_IMSI_UNKNOWN); |
Jacob Erlbeck | 9999fd9 | 2015-01-15 17:08:30 +0100 | [diff] [blame] | 701 | OSMO_ASSERT(last_updated_subscr == NULL); |
| 702 | |
| 703 | /* Inject DeleteSubscrData GSUP message (unknown IMSI) */ |
| 704 | rc = rx_gsup_message(delete_data_req, sizeof(delete_data_req)); |
| 705 | OSMO_ASSERT(rc == -GMM_CAUSE_IMSI_UNKNOWN); |
| 706 | OSMO_ASSERT(last_updated_subscr == NULL); |
| 707 | |
| 708 | /* Inject LocCancelReq GSUP message (unknown IMSI) */ |
| 709 | rc = rx_gsup_message(location_cancellation_req, |
| 710 | sizeof(location_cancellation_req)); |
| 711 | OSMO_ASSERT(rc == -GMM_CAUSE_IMSI_UNKNOWN); |
| 712 | OSMO_ASSERT(last_updated_subscr == NULL); |
| 713 | |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 714 | update_subscriber_data_cb = __real_sgsn_update_subscriber_data; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 715 | |
| 716 | cleanup_test(); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 717 | } |
| 718 | |
Jacob Erlbeck | f81cacc | 2015-01-08 16:23:25 +0100 | [diff] [blame] | 719 | int my_gprs_gsup_client_send_dummy(struct gprs_gsup_client *gsupc, struct msgb *msg) |
| 720 | { |
| 721 | msgb_free(msg); |
| 722 | return 0; |
| 723 | }; |
| 724 | |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 725 | /* |
| 726 | * Test that a GMM Detach will remove the MMCTX and the |
| 727 | * associated LLME. |
| 728 | */ |
| 729 | static void test_gmm_detach(void) |
| 730 | { |
| 731 | struct gprs_ra_id raid = { 0, }; |
| 732 | struct sgsn_mm_ctx *ctx, *ictx; |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 733 | uint32_t local_tlli; |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 734 | |
| 735 | printf("Testing GMM detach\n"); |
| 736 | |
| 737 | /* DTAP - Detach Request (MO) */ |
| 738 | /* normal detach, power_off = 0 */ |
| 739 | static const unsigned char detach_req[] = { |
| 740 | 0x08, 0x05, 0x01, 0x18, 0x05, 0xf4, 0xef, 0xe2, |
| 741 | 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb |
| 742 | }; |
| 743 | |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 744 | local_tlli = gprs_tmsi2tlli(0x23, TLLI_LOCAL); |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 745 | |
Jacob Erlbeck | abc16a5 | 2014-10-27 13:23:49 +0100 | [diff] [blame] | 746 | /* Create a context */ |
| 747 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 748 | ctx = alloc_mm_ctx(local_tlli, &raid); |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 749 | |
| 750 | /* inject the detach */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 751 | send_0408_message(ctx->gb.llme, local_tlli, &raid, |
Jacob Erlbeck | 94ef1c0 | 2014-10-29 10:31:18 +0100 | [diff] [blame] | 752 | detach_req, ARRAY_SIZE(detach_req)); |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 753 | |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 754 | /* verify that a single message (hopefully the Detach Accept) has been |
| 755 | * sent by the SGSN */ |
Jacob Erlbeck | 94ef1c0 | 2014-10-29 10:31:18 +0100 | [diff] [blame] | 756 | OSMO_ASSERT(sgsn_tx_counter == 1); |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 757 | |
| 758 | /* verify that things are gone */ |
| 759 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 760 | ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid); |
| 761 | OSMO_ASSERT(!ictx); |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 762 | |
| 763 | cleanup_test(); |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /* |
| 767 | * Test that a GMM Detach will remove the MMCTX and the associated LLME but |
| 768 | * will not sent a Detach Accept message (power_off = 1) |
| 769 | */ |
| 770 | static void test_gmm_detach_power_off(void) |
| 771 | { |
| 772 | struct gprs_ra_id raid = { 0, }; |
| 773 | struct sgsn_mm_ctx *ctx, *ictx; |
| 774 | uint32_t local_tlli; |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 775 | |
| 776 | printf("Testing GMM detach (power off)\n"); |
| 777 | |
| 778 | /* DTAP - Detach Request (MO) */ |
| 779 | /* normal detach, power_off = 1 */ |
| 780 | static const unsigned char detach_req[] = { |
| 781 | 0x08, 0x05, 0x09, 0x18, 0x05, 0xf4, 0xef, 0xe2, |
| 782 | 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb |
| 783 | }; |
| 784 | |
| 785 | local_tlli = gprs_tmsi2tlli(0x23, TLLI_LOCAL); |
| 786 | |
| 787 | /* Create a context */ |
| 788 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 789 | ctx = alloc_mm_ctx(local_tlli, &raid); |
| 790 | |
| 791 | /* inject the detach */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 792 | send_0408_message(ctx->gb.llme, local_tlli, &raid, |
Jacob Erlbeck | 94ef1c0 | 2014-10-29 10:31:18 +0100 | [diff] [blame] | 793 | detach_req, ARRAY_SIZE(detach_req)); |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 794 | |
| 795 | /* verify that no message (and therefore no Detach Accept) has been |
| 796 | * sent by the SGSN */ |
Jacob Erlbeck | 94ef1c0 | 2014-10-29 10:31:18 +0100 | [diff] [blame] | 797 | OSMO_ASSERT(sgsn_tx_counter == 0); |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 798 | |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 799 | /* verify that things are gone */ |
| 800 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 801 | ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid); |
Jacob Erlbeck | 258ce3d | 2014-09-30 13:51:45 +0200 | [diff] [blame] | 802 | OSMO_ASSERT(!ictx); |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 803 | |
| 804 | cleanup_test(); |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 805 | } |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 806 | |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 807 | /* |
| 808 | * Test that a GMM Detach will remove the associated LLME if there is no MMCTX. |
| 809 | */ |
| 810 | static void test_gmm_detach_no_mmctx(void) |
| 811 | { |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 812 | struct gprs_ra_id raid = { 0, }; |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 813 | struct gprs_llc_lle *lle; |
| 814 | uint32_t local_tlli; |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 815 | |
| 816 | printf("Testing GMM detach (no MMCTX)\n"); |
| 817 | |
| 818 | /* DTAP - Detach Request (MO) */ |
| 819 | /* normal detach, power_off = 0 */ |
| 820 | static const unsigned char detach_req[] = { |
| 821 | 0x08, 0x05, 0x01, 0x18, 0x05, 0xf4, 0xef, 0xe2, |
| 822 | 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb |
| 823 | }; |
| 824 | |
| 825 | /* Create an LLME */ |
| 826 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 827 | local_tlli = gprs_tmsi2tlli(0x23, TLLI_LOCAL); |
| 828 | lle = gprs_lle_get_or_create(local_tlli, 3); |
| 829 | |
| 830 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 831 | |
| 832 | /* inject the detach */ |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 833 | send_0408_message(lle->llme, local_tlli, &raid, |
Jacob Erlbeck | 94ef1c0 | 2014-10-29 10:31:18 +0100 | [diff] [blame] | 834 | detach_req, ARRAY_SIZE(detach_req)); |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 835 | |
| 836 | /* verify that the LLME is gone */ |
| 837 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 838 | |
| 839 | cleanup_test(); |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 840 | } |
| 841 | |
Jacob Erlbeck | 14ae582 | 2014-10-28 09:47:03 +0100 | [diff] [blame] | 842 | /* |
Jacob Erlbeck | de4bbc7 | 2014-11-24 15:04:15 +0100 | [diff] [blame] | 843 | * Test that a single GMM Detach Accept message will not cause the SGSN to send |
| 844 | * any message or leave an MM context at the SGSN. |
| 845 | */ |
| 846 | static void test_gmm_detach_accept_unexpected(void) |
| 847 | { |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 848 | struct gprs_ra_id raid = { 0, }; |
Jacob Erlbeck | de4bbc7 | 2014-11-24 15:04:15 +0100 | [diff] [blame] | 849 | struct gprs_llc_lle *lle; |
| 850 | uint32_t local_tlli; |
| 851 | |
| 852 | printf("Testing GMM detach accept (unexpected)\n"); |
| 853 | |
| 854 | /* DTAP - Detach Accept (MT) */ |
| 855 | /* normal detach */ |
| 856 | static const unsigned char detach_acc[] = { |
| 857 | 0x08, 0x06 |
| 858 | }; |
| 859 | |
| 860 | /* Create an LLME */ |
| 861 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 862 | local_tlli = gprs_tmsi2tlli(0x23, TLLI_LOCAL); |
| 863 | lle = gprs_lle_get_or_create(local_tlli, 3); |
| 864 | |
| 865 | /* inject the detach */ |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 866 | send_0408_message(lle->llme, local_tlli, &raid, |
Jacob Erlbeck | de4bbc7 | 2014-11-24 15:04:15 +0100 | [diff] [blame] | 867 | detach_acc, ARRAY_SIZE(detach_acc)); |
| 868 | |
| 869 | /* verify that no message (and therefore no Status or XID reset) has been |
| 870 | * sent by the SGSN */ |
| 871 | OSMO_ASSERT(sgsn_tx_counter == 0); |
| 872 | |
| 873 | /* verify that things are gone */ |
| 874 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 875 | |
| 876 | cleanup_test(); |
Jacob Erlbeck | de4bbc7 | 2014-11-24 15:04:15 +0100 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | /* |
Jacob Erlbeck | 14ae582 | 2014-10-28 09:47:03 +0100 | [diff] [blame] | 880 | * Test that a GMM Status will remove the associated LLME if there is no MMCTX. |
| 881 | */ |
| 882 | static void test_gmm_status_no_mmctx(void) |
| 883 | { |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 884 | struct gprs_ra_id raid = { 0, }; |
Jacob Erlbeck | 14ae582 | 2014-10-28 09:47:03 +0100 | [diff] [blame] | 885 | struct gprs_llc_lle *lle; |
| 886 | uint32_t local_tlli; |
Jacob Erlbeck | 14ae582 | 2014-10-28 09:47:03 +0100 | [diff] [blame] | 887 | |
| 888 | printf("Testing GMM Status (no MMCTX)\n"); |
| 889 | |
| 890 | /* DTAP - GMM Status, protocol error */ |
| 891 | static const unsigned char gmm_status[] = { |
| 892 | 0x08, 0x20, 0x6f |
| 893 | }; |
| 894 | |
| 895 | /* Create an LLME */ |
| 896 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 897 | local_tlli = gprs_tmsi2tlli(0x23, TLLI_LOCAL); |
| 898 | lle = gprs_lle_get_or_create(local_tlli, 3); |
| 899 | |
| 900 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 901 | |
| 902 | /* inject the detach */ |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 903 | send_0408_message(lle->llme, local_tlli, &raid, |
Jacob Erlbeck | 94ef1c0 | 2014-10-29 10:31:18 +0100 | [diff] [blame] | 904 | gmm_status, ARRAY_SIZE(gmm_status)); |
Jacob Erlbeck | 14ae582 | 2014-10-28 09:47:03 +0100 | [diff] [blame] | 905 | |
| 906 | /* verify that no message has been sent by the SGSN */ |
Jacob Erlbeck | 94ef1c0 | 2014-10-29 10:31:18 +0100 | [diff] [blame] | 907 | OSMO_ASSERT(sgsn_tx_counter == 0); |
Jacob Erlbeck | 14ae582 | 2014-10-28 09:47:03 +0100 | [diff] [blame] | 908 | |
| 909 | /* verify that the LLME is gone */ |
| 910 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 911 | |
| 912 | cleanup_test(); |
Jacob Erlbeck | 14ae582 | 2014-10-28 09:47:03 +0100 | [diff] [blame] | 913 | } |
| 914 | |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 915 | /* |
| 916 | * Test the GMM Attach procedure |
| 917 | */ |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 918 | static void test_gmm_attach(int retry) |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 919 | { |
| 920 | struct gprs_ra_id raid = { 0, }; |
| 921 | struct sgsn_mm_ctx *ctx = NULL; |
| 922 | struct sgsn_mm_ctx *ictx; |
Jacob Erlbeck | aec03a1 | 2014-11-24 14:40:28 +0100 | [diff] [blame] | 923 | uint32_t ptmsi1; |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 924 | uint32_t foreign_tlli; |
| 925 | uint32_t local_tlli = 0; |
| 926 | struct gprs_llc_lle *lle; |
| 927 | |
| 928 | /* DTAP - Attach Request */ |
| 929 | /* The P-TMSI is not known by the SGSN */ |
| 930 | static const unsigned char attach_req[] = { |
| 931 | 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, 0x05, 0xf4, |
| 932 | 0xfb, 0xc5, 0x46, 0x79, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60, |
| 933 | 0x19, 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00, 0x60, |
| 934 | 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60, 0x80, 0xba, 0xc8, |
| 935 | 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00 |
| 936 | }; |
| 937 | |
| 938 | /* DTAP - Identity Response IMEI */ |
| 939 | static const unsigned char ident_resp_imei[] = { |
| 940 | 0x08, 0x16, 0x08, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, |
| 941 | 0x56 |
| 942 | }; |
| 943 | |
| 944 | /* DTAP - Identity Response IMSI */ |
| 945 | static const unsigned char ident_resp_imsi[] = { |
| 946 | 0x08, 0x16, 0x08, 0x19, 0x32, 0x54, 0x76, 0x98, 0x10, 0x32, |
| 947 | 0x54 |
| 948 | }; |
| 949 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 950 | /* DTAP - Authentication and Ciphering Resp */ |
| 951 | static const unsigned char auth_ciph_resp[] = { |
| 952 | 0x08, 0x13, 0x00, 0x22, 0x51, 0xe5, 0x51, 0xe5, 0x23, 0x09, |
| 953 | 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x01 |
| 954 | }; |
| 955 | |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 956 | /* DTAP - Attach Complete */ |
| 957 | static const unsigned char attach_compl[] = { |
| 958 | 0x08, 0x03 |
| 959 | }; |
| 960 | |
| 961 | /* DTAP - Detach Request (MO) */ |
| 962 | /* normal detach, power_off = 0 */ |
| 963 | static const unsigned char detach_req[] = { |
| 964 | 0x08, 0x05, 0x01, 0x18, 0x05, 0xf4, 0xeb, 0x8b, |
| 965 | 0x45, 0x67, 0x19, 0x03, 0xb9, 0x97, 0xcb |
| 966 | }; |
| 967 | |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 968 | printf("Testing GMM attach%s\n", retry ? " with retry" : ""); |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 969 | |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 970 | foreign_tlli = gprs_tmsi2tlli(0xc0000023, TLLI_FOREIGN); |
| 971 | |
| 972 | /* Create a LLE/LLME */ |
| 973 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 974 | lle = gprs_lle_get_or_create(foreign_tlli, 3); |
| 975 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 976 | |
| 977 | /* inject the attach request */ |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 978 | send_0408_message(lle->llme, foreign_tlli, &raid, |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 979 | attach_req, ARRAY_SIZE(attach_req)); |
| 980 | |
| 981 | ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid); |
| 982 | OSMO_ASSERT(ctx != NULL); |
| 983 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 984 | |
| 985 | /* we expect an identity request (IMEI) */ |
| 986 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 987 | |
| 988 | /* inject the identity response (IMEI) */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 989 | send_0408_message(ctx->gb.llme, foreign_tlli, &raid, |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 990 | ident_resp_imei, ARRAY_SIZE(ident_resp_imei)); |
| 991 | |
| 992 | /* we expect an identity request (IMSI) */ |
| 993 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 994 | |
| 995 | /* inject the identity response (IMSI) */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 996 | send_0408_message(ctx->gb.llme, foreign_tlli, &raid, |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 997 | ident_resp_imsi, ARRAY_SIZE(ident_resp_imsi)); |
| 998 | |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 999 | /* check that the MM context has not been removed due to a failed |
| 1000 | * authorization */ |
| 1001 | OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid)); |
| 1002 | |
Jacob Erlbeck | 0074a77 | 2014-10-28 16:23:46 +0100 | [diff] [blame] | 1003 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 1004 | |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1005 | retry_attach_req: |
| 1006 | |
| 1007 | if (retry && sgsn_tx_counter == 0) { |
| 1008 | fprintf(stderr, "Retrying attach request\n"); |
| 1009 | /* re-inject the attach request */ |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 1010 | send_0408_message(lle->llme, foreign_tlli, &raid, |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1011 | attach_req, ARRAY_SIZE(attach_req)); |
| 1012 | } |
| 1013 | |
| 1014 | if (ctx->auth_state == SGSN_AUTH_AUTHENTICATE && sgsn_tx_counter == 1) { |
| 1015 | /* we got an auth & ciph request */ |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1016 | |
| 1017 | /* inject the auth & ciph response */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1018 | send_0408_message(ctx->gb.llme, foreign_tlli, &raid, |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1019 | auth_ciph_resp, ARRAY_SIZE(auth_ciph_resp)); |
| 1020 | |
| 1021 | /* check that the MM context has not been removed due to a |
| 1022 | * failed authorization */ |
| 1023 | OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid)); |
Holger Hans Peter Freyther | 20de3ae | 2015-05-05 22:52:40 +0200 | [diff] [blame] | 1024 | if (ctx->subscr && ctx->subscr->sgsn_data->msisdn_len > 0) |
| 1025 | OSMO_ASSERT(strcmp(ctx->msisdn, "+49166213323") == 0); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1026 | } |
| 1027 | |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1028 | if (retry && sgsn_tx_counter == 0) |
| 1029 | goto retry_attach_req; |
| 1030 | |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 1031 | /* we expect an attach accept/reject */ |
| 1032 | OSMO_ASSERT(sgsn_tx_counter == 1); |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 1033 | ptmsi1 = get_new_ptmsi(&last_dl_parse_ctx); |
| 1034 | OSMO_ASSERT(ptmsi1 != GSM_RESERVED_TMSI); |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 1035 | |
| 1036 | /* this has been randomly assigned by the SGSN */ |
Jacob Erlbeck | aec03a1 | 2014-11-24 14:40:28 +0100 | [diff] [blame] | 1037 | local_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL); |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 1038 | |
| 1039 | /* inject the attach complete */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1040 | send_0408_message(ctx->gb.llme, local_tlli, &raid, |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 1041 | attach_compl, ARRAY_SIZE(attach_compl)); |
| 1042 | |
| 1043 | OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL); |
| 1044 | |
| 1045 | /* we don't expect a response */ |
| 1046 | OSMO_ASSERT(sgsn_tx_counter == 0); |
| 1047 | |
| 1048 | /* inject the detach */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1049 | send_0408_message(ctx->gb.llme, local_tlli, &raid, |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 1050 | detach_req, ARRAY_SIZE(detach_req)); |
| 1051 | |
| 1052 | /* verify that things are gone */ |
| 1053 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 1054 | ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid); |
| 1055 | OSMO_ASSERT(!ictx); |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 1056 | |
| 1057 | cleanup_test(); |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 1058 | } |
Jacob Erlbeck | 0c06f98 | 2014-10-29 22:12:20 +0100 | [diff] [blame] | 1059 | |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 1060 | static void test_gmm_attach_acl(void) |
| 1061 | { |
| 1062 | const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy; |
| 1063 | |
| 1064 | sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_CLOSED; |
| 1065 | sgsn_acl_add("123456789012345", &sgsn->cfg); |
| 1066 | printf("Auth policy 'closed': "); |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1067 | test_gmm_attach(0); |
Jacob Erlbeck | 0c06f98 | 2014-10-29 22:12:20 +0100 | [diff] [blame] | 1068 | sgsn_acl_del("123456789012345", &sgsn->cfg); |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 1069 | |
| 1070 | sgsn->cfg.auth_policy = saved_auth_policy; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 1071 | |
| 1072 | cleanup_test(); |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1075 | int my_subscr_request_update_location(struct sgsn_mm_ctx *mmctx) { |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 1076 | int rc; |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1077 | rc = __real_gprs_subscr_request_update_location(mmctx); |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 1078 | if (rc == -ENOTSUP) { |
| 1079 | OSMO_ASSERT(mmctx->subscr); |
| 1080 | gprs_subscr_update(mmctx->subscr); |
| 1081 | } |
| 1082 | return rc; |
| 1083 | }; |
| 1084 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1085 | int my_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx) { |
| 1086 | gprs_subscr_update(mmctx->subscr); |
| 1087 | return 0; |
| 1088 | }; |
| 1089 | |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 1090 | static void test_gmm_attach_subscr(void) |
| 1091 | { |
| 1092 | const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy; |
| 1093 | struct gsm_subscriber *subscr; |
| 1094 | |
| 1095 | sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE; |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1096 | subscr_request_update_location_cb = my_subscr_request_update_location; |
| 1097 | subscr_request_auth_info_cb = my_subscr_request_auth_info; |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 1098 | |
| 1099 | subscr = gprs_subscr_get_or_create("123456789012345"); |
| 1100 | subscr->authorized = 1; |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 1101 | |
| 1102 | printf("Auth policy 'remote': "); |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1103 | test_gmm_attach(0); |
Holger Hans Peter Freyther | 1d778fd | 2015-01-20 21:14:03 +0100 | [diff] [blame] | 1104 | subscr_put(subscr); |
Jacob Erlbeck | 058bc26 | 2015-01-13 11:46:32 +0100 | [diff] [blame] | 1105 | assert_no_subscrs(); |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 1106 | |
| 1107 | sgsn->cfg.auth_policy = saved_auth_policy; |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1108 | subscr_request_update_location_cb = __real_gprs_subscr_request_update_location; |
| 1109 | subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 1110 | |
| 1111 | cleanup_test(); |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 1112 | } |
| 1113 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1114 | int my_subscr_request_auth_info_fake_auth(struct sgsn_mm_ctx *mmctx) |
| 1115 | { |
| 1116 | /* Fake an authentication */ |
| 1117 | OSMO_ASSERT(mmctx->subscr); |
| 1118 | mmctx->is_authenticated = 1; |
| 1119 | gprs_subscr_update_auth_info(mmctx->subscr); |
Jacob Erlbeck | 2e5e94c | 2014-12-08 15:26:47 +0100 | [diff] [blame] | 1120 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1121 | return 0; |
Jacob Erlbeck | 2e5e94c | 2014-12-08 15:26:47 +0100 | [diff] [blame] | 1122 | }; |
| 1123 | |
| 1124 | static void test_gmm_attach_subscr_fake_auth(void) |
| 1125 | { |
| 1126 | const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy; |
| 1127 | struct gsm_subscriber *subscr; |
| 1128 | |
| 1129 | sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE; |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1130 | subscr_request_update_location_cb = my_subscr_request_update_location; |
| 1131 | subscr_request_auth_info_cb = my_subscr_request_auth_info_fake_auth; |
Jacob Erlbeck | 2e5e94c | 2014-12-08 15:26:47 +0100 | [diff] [blame] | 1132 | |
| 1133 | subscr = gprs_subscr_get_or_create("123456789012345"); |
| 1134 | subscr->authorized = 1; |
Jacob Erlbeck | 9d4f46c | 2014-12-17 13:20:08 +0100 | [diff] [blame] | 1135 | sgsn->cfg.require_authentication = 1; |
Jacob Erlbeck | 771573c | 2014-12-19 18:08:48 +0100 | [diff] [blame] | 1136 | sgsn->cfg.require_update_location = 1; |
Jacob Erlbeck | 2e5e94c | 2014-12-08 15:26:47 +0100 | [diff] [blame] | 1137 | |
| 1138 | printf("Auth policy 'remote', auth faked: "); |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1139 | test_gmm_attach(0); |
Holger Hans Peter Freyther | 1d778fd | 2015-01-20 21:14:03 +0100 | [diff] [blame] | 1140 | subscr_put(subscr); |
Jacob Erlbeck | 058bc26 | 2015-01-13 11:46:32 +0100 | [diff] [blame] | 1141 | assert_no_subscrs(); |
Jacob Erlbeck | 2e5e94c | 2014-12-08 15:26:47 +0100 | [diff] [blame] | 1142 | |
| 1143 | sgsn->cfg.auth_policy = saved_auth_policy; |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1144 | subscr_request_update_location_cb = __real_gprs_subscr_request_update_location; |
| 1145 | subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 1146 | |
| 1147 | cleanup_test(); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | int my_subscr_request_auth_info_real_auth(struct sgsn_mm_ctx *mmctx) |
| 1151 | { |
| 1152 | struct gsm_auth_tuple at = { |
Harald Welte | 121e9a4 | 2016-04-20 13:13:19 +0200 | [diff] [blame] | 1153 | .vec.sres = {0x51, 0xe5, 0x51, 0xe5}, |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1154 | .key_seq = 0 |
| 1155 | }; |
| 1156 | |
| 1157 | /* Fake an authentication */ |
| 1158 | OSMO_ASSERT(mmctx->subscr); |
| 1159 | mmctx->subscr->sgsn_data->auth_triplets[0] = at; |
| 1160 | |
| 1161 | gprs_subscr_update_auth_info(mmctx->subscr); |
| 1162 | |
| 1163 | return 0; |
| 1164 | }; |
| 1165 | |
| 1166 | static void test_gmm_attach_subscr_real_auth(void) |
| 1167 | { |
| 1168 | const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy; |
| 1169 | struct gsm_subscriber *subscr; |
| 1170 | |
| 1171 | sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE; |
| 1172 | subscr_request_update_location_cb = my_subscr_request_update_location; |
| 1173 | subscr_request_auth_info_cb = my_subscr_request_auth_info_real_auth; |
| 1174 | |
| 1175 | subscr = gprs_subscr_get_or_create("123456789012345"); |
| 1176 | subscr->authorized = 1; |
Jacob Erlbeck | 9d4f46c | 2014-12-17 13:20:08 +0100 | [diff] [blame] | 1177 | sgsn->cfg.require_authentication = 1; |
Jacob Erlbeck | 771573c | 2014-12-19 18:08:48 +0100 | [diff] [blame] | 1178 | sgsn->cfg.require_update_location = 1; |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1179 | |
| 1180 | printf("Auth policy 'remote', triplet based auth: "); |
Jacob Erlbeck | 058bc26 | 2015-01-13 11:46:32 +0100 | [diff] [blame] | 1181 | |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1182 | test_gmm_attach(0); |
Holger Hans Peter Freyther | 1d778fd | 2015-01-20 21:14:03 +0100 | [diff] [blame] | 1183 | subscr_put(subscr); |
Jacob Erlbeck | 058bc26 | 2015-01-13 11:46:32 +0100 | [diff] [blame] | 1184 | assert_no_subscrs(); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 1185 | |
| 1186 | sgsn->cfg.auth_policy = saved_auth_policy; |
| 1187 | subscr_request_update_location_cb = __real_gprs_subscr_request_update_location; |
| 1188 | subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 1189 | |
| 1190 | cleanup_test(); |
Jacob Erlbeck | 2e5e94c | 2014-12-08 15:26:47 +0100 | [diff] [blame] | 1191 | } |
| 1192 | |
Jacob Erlbeck | 3d72245 | 2014-12-19 18:26:09 +0100 | [diff] [blame] | 1193 | #define TEST_GSUP_IMSI_LONG_IE 0x01, 0x08, \ |
| 1194 | 0x21, 0x43, 0x65, 0x87, 0x09, 0x21, 0x43, 0xf5 |
| 1195 | |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1196 | static int auth_info_skip = 0; |
| 1197 | static int upd_loc_skip = 0; |
| 1198 | |
Jacob Erlbeck | 3d72245 | 2014-12-19 18:26:09 +0100 | [diff] [blame] | 1199 | int my_subscr_request_auth_info_gsup_auth(struct sgsn_mm_ctx *mmctx) |
| 1200 | { |
| 1201 | static const uint8_t send_auth_info_res[] = { |
| 1202 | 0x0a, |
| 1203 | TEST_GSUP_IMSI_LONG_IE, |
| 1204 | 0x03, 0x22, /* Auth tuple */ |
| 1205 | 0x20, 0x10, |
| 1206 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 1207 | 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, |
| 1208 | 0x21, 0x04, |
| 1209 | 0x51, 0xe5, 0x51, 0xe5, |
| 1210 | 0x22, 0x08, |
| 1211 | 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, |
| 1212 | }; |
| 1213 | |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1214 | OSMO_ASSERT(!mmctx || mmctx->subscr); |
Jacob Erlbeck | 3d72245 | 2014-12-19 18:26:09 +0100 | [diff] [blame] | 1215 | |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1216 | if (auth_info_skip > 0) { |
| 1217 | auth_info_skip -= 1; |
| 1218 | return -EAGAIN; |
| 1219 | } |
| 1220 | |
Jacob Erlbeck | 3d72245 | 2014-12-19 18:26:09 +0100 | [diff] [blame] | 1221 | /* Fake an SendAuthInfoRes */ |
| 1222 | rx_gsup_message(send_auth_info_res, sizeof(send_auth_info_res)); |
| 1223 | |
| 1224 | return 0; |
| 1225 | }; |
| 1226 | |
| 1227 | int my_subscr_request_update_gsup_auth(struct sgsn_mm_ctx *mmctx) { |
| 1228 | static const uint8_t update_location_res[] = { |
| 1229 | 0x06, |
| 1230 | TEST_GSUP_IMSI_LONG_IE, |
| 1231 | 0x04, 0x00, /* PDP info complete */ |
| 1232 | 0x05, 0x12, |
| 1233 | 0x10, 0x01, 0x01, |
| 1234 | 0x11, 0x02, 0xf1, 0x21, /* IPv4 */ |
| 1235 | 0x12, 0x09, 0x04, 't', 'e', 's', 't', 0x03, 'a', 'p', 'n', |
Holger Hans Peter Freyther | 20de3ae | 2015-05-05 22:52:40 +0200 | [diff] [blame] | 1236 | 0x08, 0x07, /* MSISDN 49166213323 encoded */ |
| 1237 | 0x91, 0x94, 0x61, 0x26, 0x31, 0x23, 0xF3, |
Holger Hans Peter Freyther | 10c0f56 | 2015-05-17 20:58:40 +0200 | [diff] [blame] | 1238 | 0x09, 0x07, /* MSISDN 38166213323 encoded */ |
| 1239 | 0x91, 0x83, 0x61, 0x26, 0x31, 0x23, 0xF3, |
Jacob Erlbeck | 3d72245 | 2014-12-19 18:26:09 +0100 | [diff] [blame] | 1240 | }; |
| 1241 | |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1242 | OSMO_ASSERT(!mmctx || mmctx->subscr); |
Jacob Erlbeck | 3d72245 | 2014-12-19 18:26:09 +0100 | [diff] [blame] | 1243 | |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1244 | if (upd_loc_skip > 0) { |
| 1245 | upd_loc_skip -= 1; |
| 1246 | return -EAGAIN; |
| 1247 | } |
| 1248 | |
Jacob Erlbeck | 3d72245 | 2014-12-19 18:26:09 +0100 | [diff] [blame] | 1249 | /* Fake an UpdateLocRes */ |
| 1250 | return rx_gsup_message(update_location_res, sizeof(update_location_res)); |
| 1251 | }; |
| 1252 | |
| 1253 | |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1254 | static void test_gmm_attach_subscr_gsup_auth(int retry) |
Jacob Erlbeck | 3d72245 | 2014-12-19 18:26:09 +0100 | [diff] [blame] | 1255 | { |
| 1256 | const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy; |
| 1257 | struct gsm_subscriber *subscr; |
| 1258 | |
| 1259 | sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE; |
| 1260 | subscr_request_update_location_cb = my_subscr_request_update_gsup_auth; |
| 1261 | subscr_request_auth_info_cb = my_subscr_request_auth_info_gsup_auth; |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1262 | if (retry) { |
| 1263 | upd_loc_skip = 3; |
| 1264 | auth_info_skip = 3; |
| 1265 | } |
Jacob Erlbeck | 3d72245 | 2014-12-19 18:26:09 +0100 | [diff] [blame] | 1266 | |
| 1267 | subscr = gprs_subscr_get_or_create("123456789012345"); |
| 1268 | subscr->authorized = 1; |
| 1269 | sgsn->cfg.require_authentication = 1; |
| 1270 | sgsn->cfg.require_update_location = 1; |
| 1271 | subscr_put(subscr); |
| 1272 | |
| 1273 | printf("Auth policy 'remote', GSUP based auth: "); |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1274 | test_gmm_attach(retry); |
Jacob Erlbeck | 058bc26 | 2015-01-13 11:46:32 +0100 | [diff] [blame] | 1275 | assert_no_subscrs(); |
Jacob Erlbeck | 3d72245 | 2014-12-19 18:26:09 +0100 | [diff] [blame] | 1276 | |
| 1277 | sgsn->cfg.auth_policy = saved_auth_policy; |
| 1278 | subscr_request_update_location_cb = __real_gprs_subscr_request_update_location; |
| 1279 | subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info; |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 1280 | upd_loc_skip = 0; |
| 1281 | auth_info_skip = 0; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 1282 | |
| 1283 | cleanup_test(); |
Jacob Erlbeck | 3d72245 | 2014-12-19 18:26:09 +0100 | [diff] [blame] | 1284 | } |
| 1285 | |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1286 | int my_gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg) |
| 1287 | { |
Harald Welte | 23d77d5 | 2016-04-25 19:07:34 +0200 | [diff] [blame] | 1288 | struct osmo_gsup_message to_peer = {0}; |
| 1289 | struct osmo_gsup_message from_peer = {0}; |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1290 | struct msgb *reply_msg; |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 1291 | int rc; |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1292 | |
| 1293 | /* Simulate the GSUP peer */ |
Harald Welte | 23d77d5 | 2016-04-25 19:07:34 +0200 | [diff] [blame] | 1294 | rc = osmo_gsup_decode(msgb_data(msg), msgb_length(msg), &to_peer); |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 1295 | OSMO_ASSERT(rc >= 0); |
| 1296 | OSMO_ASSERT(to_peer.imsi[0] != 0); |
| 1297 | strncpy(from_peer.imsi, to_peer.imsi, sizeof(from_peer.imsi)); |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1298 | |
| 1299 | /* This invalidates the pointers in to_peer */ |
| 1300 | msgb_free(msg); |
| 1301 | |
| 1302 | switch (to_peer.message_type) { |
Harald Welte | 23d77d5 | 2016-04-25 19:07:34 +0200 | [diff] [blame] | 1303 | case OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST: |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1304 | /* Send UPDATE_LOCATION_RESULT */ |
| 1305 | return my_subscr_request_update_gsup_auth(NULL); |
| 1306 | |
Harald Welte | 23d77d5 | 2016-04-25 19:07:34 +0200 | [diff] [blame] | 1307 | case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST: |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1308 | /* Send SEND_AUTH_INFO_RESULT */ |
| 1309 | return my_subscr_request_auth_info_gsup_auth(NULL); |
| 1310 | |
Harald Welte | 23d77d5 | 2016-04-25 19:07:34 +0200 | [diff] [blame] | 1311 | case OSMO_GSUP_MSGT_PURGE_MS_REQUEST: |
| 1312 | from_peer.message_type = OSMO_GSUP_MSGT_PURGE_MS_RESULT; |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 1313 | break; |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1314 | |
| 1315 | default: |
| 1316 | if ((to_peer.message_type & 0b00000011) == 0) { |
| 1317 | /* Unhandled request */ |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 1318 | /* Send error(NOT_IMPL) */ |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1319 | from_peer.message_type = to_peer.message_type + 1; |
| 1320 | from_peer.cause = GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL; |
| 1321 | break; |
| 1322 | } |
| 1323 | |
| 1324 | /* Ignore it */ |
| 1325 | return 0; |
| 1326 | } |
| 1327 | |
| 1328 | reply_msg = gprs_gsup_msgb_alloc(); |
| 1329 | reply_msg->l2h = reply_msg->data; |
Harald Welte | 23d77d5 | 2016-04-25 19:07:34 +0200 | [diff] [blame] | 1330 | osmo_gsup_encode(reply_msg, &from_peer); |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1331 | gprs_subscr_rx_gsup_message(reply_msg); |
| 1332 | msgb_free(reply_msg); |
| 1333 | |
| 1334 | return 0; |
| 1335 | }; |
| 1336 | |
| 1337 | static void test_gmm_attach_subscr_real_gsup_auth(int retry) |
| 1338 | { |
| 1339 | const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy; |
| 1340 | struct gsm_subscriber *subscr; |
| 1341 | |
| 1342 | sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE; |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1343 | gprs_gsup_client_send_cb = my_gprs_gsup_client_send; |
| 1344 | |
| 1345 | sgsn->gsup_client = talloc_zero(tall_bsc_ctx, struct gprs_gsup_client); |
| 1346 | |
| 1347 | if (retry) { |
| 1348 | upd_loc_skip = 3; |
| 1349 | auth_info_skip = 3; |
| 1350 | } |
| 1351 | |
| 1352 | printf("Auth policy 'remote', real GSUP based auth: "); |
| 1353 | test_gmm_attach(retry); |
| 1354 | |
| 1355 | subscr = gprs_subscr_get_by_imsi("123456789012345"); |
Holger Hans Peter Freyther | 1d778fd | 2015-01-20 21:14:03 +0100 | [diff] [blame] | 1356 | OSMO_ASSERT(subscr == NULL); |
Jacob Erlbeck | 058bc26 | 2015-01-13 11:46:32 +0100 | [diff] [blame] | 1357 | assert_no_subscrs(); |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1358 | |
| 1359 | sgsn->cfg.auth_policy = saved_auth_policy; |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1360 | gprs_gsup_client_send_cb = __real_gprs_gsup_client_send; |
| 1361 | upd_loc_skip = 0; |
| 1362 | auth_info_skip = 0; |
| 1363 | talloc_free(sgsn->gsup_client); |
| 1364 | sgsn->gsup_client = NULL; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 1365 | |
| 1366 | cleanup_test(); |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 1367 | } |
| 1368 | |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 1369 | /* |
| 1370 | * Test the GMM Rejects |
| 1371 | */ |
| 1372 | static void test_gmm_reject(void) |
| 1373 | { |
| 1374 | struct gprs_ra_id raid = { 0, }; |
| 1375 | struct sgsn_mm_ctx *ctx = NULL; |
| 1376 | uint32_t foreign_tlli; |
| 1377 | struct gprs_llc_lle *lle; |
| 1378 | int idx; |
| 1379 | |
| 1380 | /* DTAP - Attach Request */ |
| 1381 | /* Invalid MI length */ |
| 1382 | static const unsigned char attach_req_inv_mi_len[] = { |
| 1383 | 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, 0x09, 0xf4, |
| 1384 | 0xfb, 0xc5, 0x46, 0x79, 0xff, 0xff, 0xff, 0xff, 0x11, 0x22, |
| 1385 | 0x33, 0x40, 0x50, 0x60, 0x19, 0x18, 0xb3, 0x43, 0x2b, 0x25, |
| 1386 | 0x96, 0x62, 0x00, 0x60, 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, |
| 1387 | 0x60, 0x80, 0xba, 0xc8, 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00 |
| 1388 | }; |
| 1389 | |
| 1390 | /* DTAP - Attach Request */ |
| 1391 | /* Invalid MI type (IMEI) */ |
| 1392 | static const unsigned char attach_req_inv_mi_type[] = { |
| 1393 | 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, 0x05, 0xf2, |
| 1394 | 0xfb, 0xc5, 0x46, 0x79, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60, |
| 1395 | 0x19, 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00, 0x60, |
| 1396 | 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60, 0x80, 0xba, 0xc8, |
| 1397 | 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00 |
| 1398 | }; |
| 1399 | |
| 1400 | /* DTAP - Routing Area Update Request */ |
| 1401 | static const unsigned char dtap_ra_upd_req[] = { |
| 1402 | 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50, |
| 1403 | 0x60, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b, |
| 1404 | 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8, |
| 1405 | 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02, |
| 1406 | 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19, |
| 1407 | 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04, |
| 1408 | 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00 |
| 1409 | }; |
| 1410 | |
| 1411 | /* DTAP - Routing Area Update Request */ |
| 1412 | /* Invalid type: GPRS_UPD_T_RA_LA_IMSI_ATT */ |
| 1413 | static const unsigned char dtap_ra_upd_req_inv_type[] = { |
| 1414 | 0x08, 0x08, 0x12, 0x11, 0x22, 0x33, 0x40, 0x50, |
| 1415 | 0x60, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b, |
| 1416 | 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8, |
| 1417 | 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02, |
| 1418 | 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19, |
| 1419 | 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04, |
| 1420 | 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00 |
| 1421 | }; |
| 1422 | |
| 1423 | /* DTAP - Routing Area Update Request */ |
| 1424 | /* Invalid cap length */ |
| 1425 | static const unsigned char dtap_ra_upd_req_inv_cap_len[] = { |
| 1426 | 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50, |
| 1427 | 0x60, 0x3d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b, |
| 1428 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 1429 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 1430 | 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8, |
| 1431 | 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02, |
| 1432 | 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19, |
| 1433 | 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04, |
| 1434 | 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00 |
| 1435 | }; |
| 1436 | |
| 1437 | struct test { |
| 1438 | const char *title; |
| 1439 | const unsigned char *msg; |
| 1440 | unsigned msg_len; |
| 1441 | unsigned num_resp; |
| 1442 | |
| 1443 | }; |
| 1444 | static struct test tests[] = { |
| 1445 | { |
| 1446 | .title = "Attach Request (invalid MI length)", |
| 1447 | .msg = attach_req_inv_mi_len, |
| 1448 | .msg_len = sizeof(attach_req_inv_mi_len), |
| 1449 | .num_resp = 1 /* Reject */ |
| 1450 | |
| 1451 | }, |
| 1452 | { |
| 1453 | .title = "Attach Request (invalid MI type)", |
| 1454 | .msg = attach_req_inv_mi_type, |
| 1455 | .msg_len = sizeof(attach_req_inv_mi_type), |
| 1456 | .num_resp = 1 /* Reject */ |
| 1457 | }, |
| 1458 | { |
| 1459 | .title = "Routing Area Update Request (valid)", |
| 1460 | .msg = dtap_ra_upd_req, |
| 1461 | .msg_len = sizeof(dtap_ra_upd_req), |
| 1462 | .num_resp = 2 /* XID Reset + Reject */ |
| 1463 | }, |
| 1464 | { |
| 1465 | .title = "Routing Area Update Request (invalid type)", |
| 1466 | .msg = dtap_ra_upd_req_inv_type, |
| 1467 | .msg_len = sizeof(dtap_ra_upd_req_inv_type), |
| 1468 | .num_resp = 1 /* Reject */ |
| 1469 | }, |
| 1470 | { |
| 1471 | .title = "Routing Area Update Request (invalid CAP length)", |
| 1472 | .msg = dtap_ra_upd_req_inv_cap_len, |
| 1473 | .msg_len = sizeof(dtap_ra_upd_req_inv_cap_len), |
| 1474 | .num_resp = 1 /* Reject */ |
| 1475 | }, |
| 1476 | }; |
| 1477 | |
| 1478 | printf("Testing GMM reject\n"); |
| 1479 | |
| 1480 | /* reset the PRNG used by sgsn_alloc_ptmsi */ |
| 1481 | srand(1); |
| 1482 | |
| 1483 | foreign_tlli = gprs_tmsi2tlli(0xc0000023, TLLI_FOREIGN); |
| 1484 | |
| 1485 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 1486 | |
| 1487 | for (idx = 0; idx < ARRAY_SIZE(tests); idx++) { |
| 1488 | const struct test *test = &tests[idx]; |
| 1489 | printf(" - %s\n", test->title); |
| 1490 | |
| 1491 | /* Create a LLE/LLME */ |
| 1492 | lle = gprs_lle_get_or_create(foreign_tlli, 3); |
| 1493 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 1494 | |
| 1495 | /* Inject the Request message */ |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 1496 | send_0408_message(lle->llme, foreign_tlli, &raid, |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 1497 | test->msg, test->msg_len); |
| 1498 | |
| 1499 | /* We expect a Reject message */ |
| 1500 | fprintf(stderr, "sgsn_tx_counter = %d (expected %d)\n", |
| 1501 | sgsn_tx_counter, test->num_resp); |
| 1502 | OSMO_ASSERT(sgsn_tx_counter == test->num_resp); |
| 1503 | |
| 1504 | /* verify that LLME/MM are removed */ |
| 1505 | ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid); |
| 1506 | OSMO_ASSERT(ctx == NULL); |
| 1507 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 1508 | } |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 1509 | |
| 1510 | cleanup_test(); |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 1511 | } |
| 1512 | |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1513 | /* |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 1514 | * Test cancellation of attached MM contexts |
| 1515 | */ |
| 1516 | static void test_gmm_cancel(void) |
| 1517 | { |
| 1518 | struct gprs_ra_id raid = { 0, }; |
| 1519 | struct sgsn_mm_ctx *ctx = NULL; |
| 1520 | struct sgsn_mm_ctx *ictx; |
| 1521 | uint32_t ptmsi1; |
| 1522 | uint32_t foreign_tlli; |
| 1523 | uint32_t local_tlli = 0; |
| 1524 | struct gprs_llc_lle *lle; |
| 1525 | const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy; |
| 1526 | |
| 1527 | /* DTAP - Attach Request */ |
| 1528 | /* The P-TMSI is not known by the SGSN */ |
| 1529 | static const unsigned char attach_req[] = { |
| 1530 | 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, 0x05, 0xf4, |
| 1531 | 0xfb, 0xc5, 0x46, 0x79, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60, |
| 1532 | 0x19, 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00, 0x60, |
| 1533 | 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60, 0x80, 0xba, 0xc8, |
| 1534 | 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00 |
| 1535 | }; |
| 1536 | |
| 1537 | /* DTAP - Identity Response IMEI */ |
| 1538 | static const unsigned char ident_resp_imei[] = { |
| 1539 | 0x08, 0x16, 0x08, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, |
| 1540 | 0x56 |
| 1541 | }; |
| 1542 | |
| 1543 | /* DTAP - Identity Response IMSI */ |
| 1544 | static const unsigned char ident_resp_imsi[] = { |
| 1545 | 0x08, 0x16, 0x08, 0x19, 0x32, 0x54, 0x76, 0x98, 0x10, 0x32, |
| 1546 | 0x54 |
| 1547 | }; |
| 1548 | |
| 1549 | /* DTAP - Attach Complete */ |
| 1550 | static const unsigned char attach_compl[] = { |
| 1551 | 0x08, 0x03 |
| 1552 | }; |
| 1553 | |
| 1554 | printf("Testing cancellation\n"); |
| 1555 | |
| 1556 | sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_OPEN; |
| 1557 | |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 1558 | foreign_tlli = gprs_tmsi2tlli(0xc0000023, TLLI_FOREIGN); |
| 1559 | |
| 1560 | /* Create a LLE/LLME */ |
| 1561 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 1562 | lle = gprs_lle_get_or_create(foreign_tlli, 3); |
| 1563 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 1564 | |
| 1565 | /* inject the attach request */ |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 1566 | send_0408_message(lle->llme, foreign_tlli, &raid, |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 1567 | attach_req, ARRAY_SIZE(attach_req)); |
| 1568 | |
| 1569 | ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid); |
| 1570 | OSMO_ASSERT(ctx != NULL); |
| 1571 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 1572 | |
| 1573 | /* we expect an identity request (IMEI) */ |
| 1574 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 1575 | |
| 1576 | /* inject the identity response (IMEI) */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1577 | send_0408_message(ctx->gb.llme, foreign_tlli, &raid, |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 1578 | ident_resp_imei, ARRAY_SIZE(ident_resp_imei)); |
| 1579 | |
| 1580 | /* we expect an identity request (IMSI) */ |
| 1581 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 1582 | |
| 1583 | /* inject the identity response (IMSI) */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1584 | send_0408_message(ctx->gb.llme, foreign_tlli, &raid, |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 1585 | ident_resp_imsi, ARRAY_SIZE(ident_resp_imsi)); |
| 1586 | |
| 1587 | /* check that the MM context has not been removed due to a failed |
| 1588 | * authorization */ |
| 1589 | OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid)); |
| 1590 | |
| 1591 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 1592 | |
| 1593 | /* we expect an attach accept/reject */ |
| 1594 | OSMO_ASSERT(sgsn_tx_counter == 1); |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 1595 | ptmsi1 = get_new_ptmsi(&last_dl_parse_ctx); |
| 1596 | OSMO_ASSERT(ptmsi1 != GSM_RESERVED_TMSI); |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 1597 | |
| 1598 | /* this has been randomly assigned by the SGSN */ |
| 1599 | local_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL); |
| 1600 | |
| 1601 | /* inject the attach complete */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1602 | send_0408_message(ctx->gb.llme, foreign_tlli, &raid, |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 1603 | attach_compl, ARRAY_SIZE(attach_compl)); |
| 1604 | |
| 1605 | OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL); |
| 1606 | |
| 1607 | /* we don't expect a response */ |
| 1608 | OSMO_ASSERT(sgsn_tx_counter == 0); |
| 1609 | |
| 1610 | /* cancel */ |
Jacob Erlbeck | af3d5c5 | 2015-01-05 17:51:17 +0100 | [diff] [blame] | 1611 | gsm0408_gprs_access_cancelled(ctx, 0); |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 1612 | |
| 1613 | /* verify that things are gone */ |
| 1614 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 1615 | ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid); |
| 1616 | OSMO_ASSERT(!ictx); |
| 1617 | |
| 1618 | sgsn->cfg.auth_policy = saved_auth_policy; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 1619 | |
| 1620 | cleanup_test(); |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | /* |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1624 | * Test the dynamic allocation of P-TMSIs |
| 1625 | */ |
| 1626 | static void test_gmm_ptmsi_allocation(void) |
| 1627 | { |
Jacob Erlbeck | d58c033 | 2016-01-04 18:43:35 +0100 | [diff] [blame] | 1628 | struct gprs_ra_id raid = {332, 112, 16464, 96}; |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1629 | struct sgsn_mm_ctx *ctx = NULL; |
| 1630 | struct sgsn_mm_ctx *ictx; |
| 1631 | uint32_t foreign_tlli; |
| 1632 | uint32_t ptmsi1; |
| 1633 | uint32_t ptmsi2; |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 1634 | uint32_t received_ptmsi; |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1635 | uint32_t old_ptmsi; |
| 1636 | uint32_t local_tlli = 0; |
| 1637 | struct gprs_llc_lle *lle; |
| 1638 | const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy; |
| 1639 | |
| 1640 | /* DTAP - Attach Request (IMSI 12131415161718) */ |
| 1641 | static const unsigned char attach_req[] = { |
| 1642 | 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, |
| 1643 | 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1644 | 0x18, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60, 0x19, |
| 1645 | 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00, |
| 1646 | 0x60, 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60, |
| 1647 | 0x80, 0xba, 0xc8, 0xc6, 0x62, 0x00, 0x60, 0x80, |
| 1648 | 0x00, |
| 1649 | }; |
| 1650 | |
| 1651 | /* DTAP - Identity Response IMEI */ |
| 1652 | static const unsigned char ident_resp_imei[] = { |
| 1653 | 0x08, 0x16, 0x08, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, |
| 1654 | 0x56 |
| 1655 | }; |
| 1656 | |
| 1657 | /* DTAP - Attach Complete */ |
| 1658 | static const unsigned char attach_compl[] = { |
| 1659 | 0x08, 0x03 |
| 1660 | }; |
| 1661 | |
| 1662 | /* DTAP - Routing Area Update Request */ |
| 1663 | static const unsigned char ra_upd_req[] = { |
| 1664 | 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50, |
| 1665 | 0x60, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b, |
| 1666 | 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8, |
| 1667 | 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02, |
| 1668 | 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19, |
| 1669 | 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04, |
| 1670 | 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00 |
| 1671 | }; |
| 1672 | |
| 1673 | /* DTAP - Routing Area Update Complete */ |
| 1674 | static const unsigned char ra_upd_complete[] = { |
| 1675 | 0x08, 0x0a |
| 1676 | }; |
| 1677 | |
| 1678 | /* DTAP - Detach Request (MO) */ |
| 1679 | /* normal detach, power_off = 1 */ |
| 1680 | static const unsigned char detach_req[] = { |
| 1681 | 0x08, 0x05, 0x09, 0x18, 0x05, 0xf4, 0xef, 0xe2, |
| 1682 | 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb |
| 1683 | }; |
| 1684 | |
| 1685 | sgsn->cfg.auth_policy = SGSN_AUTH_POLICY_OPEN; |
| 1686 | |
| 1687 | printf("Testing P-TMSI allocation\n"); |
| 1688 | |
| 1689 | printf(" - sgsn_alloc_ptmsi\n"); |
| 1690 | |
| 1691 | /* reset the PRNG used by sgsn_alloc_ptmsi */ |
| 1692 | srand(1); |
| 1693 | |
| 1694 | ptmsi1 = sgsn_alloc_ptmsi(); |
| 1695 | OSMO_ASSERT(ptmsi1 != GSM_RESERVED_TMSI); |
| 1696 | |
| 1697 | ptmsi2 = sgsn_alloc_ptmsi(); |
| 1698 | OSMO_ASSERT(ptmsi2 != GSM_RESERVED_TMSI); |
| 1699 | |
| 1700 | OSMO_ASSERT(ptmsi1 != ptmsi2); |
| 1701 | |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 1702 | ptmsi1 = ptmsi2 = GSM_RESERVED_TMSI; |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1703 | |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 1704 | printf(" - Repeated Attach Request\n"); |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1705 | |
| 1706 | foreign_tlli = gprs_tmsi2tlli(0xc0000023, TLLI_FOREIGN); |
| 1707 | |
| 1708 | /* Create a LLE/LLME */ |
| 1709 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 1710 | lle = gprs_lle_get_or_create(foreign_tlli, 3); |
| 1711 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 1712 | |
| 1713 | /* inject the attach request */ |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 1714 | send_0408_message(lle->llme, foreign_tlli, &raid, |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1715 | attach_req, ARRAY_SIZE(attach_req)); |
| 1716 | |
| 1717 | ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid); |
| 1718 | OSMO_ASSERT(ctx != NULL); |
| 1719 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 1720 | OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI); |
| 1721 | ptmsi1 = ctx->p_tmsi; |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1722 | |
| 1723 | old_ptmsi = ctx->p_tmsi_old; |
| 1724 | |
| 1725 | /* we expect an identity request (IMEI) */ |
| 1726 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 1727 | |
| 1728 | /* inject the identity response (IMEI) */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1729 | send_0408_message(ctx->gb.llme, foreign_tlli, &raid, |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1730 | ident_resp_imei, ARRAY_SIZE(ident_resp_imei)); |
| 1731 | |
| 1732 | /* check that the MM context has not been removed due to a failed |
| 1733 | * authorization */ |
| 1734 | OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid)); |
| 1735 | |
| 1736 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 1737 | OSMO_ASSERT(ctx->p_tmsi == ptmsi1); |
| 1738 | |
| 1739 | /* we expect an attach accept */ |
| 1740 | OSMO_ASSERT(sgsn_tx_counter == 1); |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 1741 | received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx); |
| 1742 | OSMO_ASSERT(received_ptmsi == ptmsi1); |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1743 | |
| 1744 | /* we ignore this and send the attach again */ |
Jacob Erlbeck | 9158089 | 2016-01-04 18:43:33 +0100 | [diff] [blame] | 1745 | send_0408_message(lle->llme, foreign_tlli, &raid, |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1746 | attach_req, ARRAY_SIZE(attach_req)); |
| 1747 | |
| 1748 | /* the allocated P-TMSI should be the same */ |
| 1749 | ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid); |
| 1750 | OSMO_ASSERT(ctx != NULL); |
| 1751 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 1752 | OSMO_ASSERT(ctx->p_tmsi_old == old_ptmsi); |
| 1753 | OSMO_ASSERT(ctx->p_tmsi == ptmsi1); |
| 1754 | |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 1755 | /* we expect an attach accept */ |
| 1756 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 1757 | received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx); |
| 1758 | OSMO_ASSERT(received_ptmsi == ptmsi1); |
| 1759 | |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1760 | /* inject the attach complete */ |
| 1761 | local_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL); |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1762 | send_0408_message(ctx->gb.llme, local_tlli, &raid, |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1763 | attach_compl, ARRAY_SIZE(attach_compl)); |
| 1764 | |
| 1765 | /* we don't expect a response */ |
| 1766 | OSMO_ASSERT(sgsn_tx_counter == 0); |
| 1767 | |
| 1768 | OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL); |
| 1769 | OSMO_ASSERT(ctx->p_tmsi_old == 0); |
| 1770 | OSMO_ASSERT(ctx->p_tmsi == ptmsi1); |
| 1771 | |
| 1772 | printf(" - Repeated RA Update Request\n"); |
| 1773 | |
| 1774 | /* inject the RA update request */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1775 | send_0408_message(ctx->gb.llme, local_tlli, &raid, |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1776 | ra_upd_req, ARRAY_SIZE(ra_upd_req)); |
| 1777 | |
| 1778 | /* we expect an RA update accept */ |
| 1779 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 1780 | |
| 1781 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 1782 | OSMO_ASSERT(ctx->p_tmsi_old == ptmsi1); |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 1783 | OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI); |
| 1784 | OSMO_ASSERT(ctx->p_tmsi != ptmsi1); |
| 1785 | ptmsi2 = ctx->p_tmsi; |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1786 | |
| 1787 | /* repeat the RA update request */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1788 | send_0408_message(ctx->gb.llme, local_tlli, &raid, |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1789 | ra_upd_req, ARRAY_SIZE(ra_upd_req)); |
| 1790 | |
| 1791 | /* we expect an RA update accept */ |
| 1792 | OSMO_ASSERT(sgsn_tx_counter == 1); |
Jacob Erlbeck | 133e862 | 2015-10-12 19:36:32 +0200 | [diff] [blame] | 1793 | received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx); |
| 1794 | OSMO_ASSERT(received_ptmsi == ptmsi2); |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1795 | |
| 1796 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 1797 | OSMO_ASSERT(ctx->p_tmsi_old == ptmsi1); |
| 1798 | OSMO_ASSERT(ctx->p_tmsi == ptmsi2); |
| 1799 | |
| 1800 | /* inject the RA update complete */ |
| 1801 | local_tlli = gprs_tmsi2tlli(ptmsi2, TLLI_LOCAL); |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1802 | send_0408_message(ctx->gb.llme, local_tlli, &raid, |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1803 | ra_upd_complete, ARRAY_SIZE(ra_upd_complete)); |
| 1804 | |
| 1805 | /* we don't expect a response */ |
| 1806 | OSMO_ASSERT(sgsn_tx_counter == 0); |
| 1807 | |
| 1808 | OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL); |
| 1809 | OSMO_ASSERT(ctx->p_tmsi_old == 0); |
| 1810 | OSMO_ASSERT(ctx->p_tmsi == ptmsi2); |
| 1811 | |
| 1812 | /* inject the detach */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1813 | send_0408_message(ctx->gb.llme, local_tlli, &raid, |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1814 | detach_req, ARRAY_SIZE(detach_req)); |
| 1815 | |
| 1816 | /* verify that things are gone */ |
| 1817 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 1818 | ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid); |
| 1819 | OSMO_ASSERT(!ictx); |
| 1820 | |
| 1821 | sgsn->cfg.auth_policy = saved_auth_policy; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 1822 | |
| 1823 | cleanup_test(); |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 1824 | } |
| 1825 | |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 1826 | /* |
| 1827 | * Test changing of routing areas |
| 1828 | */ |
| 1829 | static void test_gmm_routing_areas(void) |
| 1830 | { |
| 1831 | struct gprs_ra_id raid1 = {332, 112, 16464, 96}; |
| 1832 | struct gprs_ra_id raid2 = {332, 112, 16464, 97}; |
| 1833 | struct sgsn_mm_ctx *ctx = NULL; |
| 1834 | struct sgsn_mm_ctx *ictx; |
| 1835 | uint32_t ptmsi1; |
| 1836 | uint32_t received_ptmsi; |
| 1837 | uint32_t ms_tlli = 0; |
| 1838 | struct gprs_llc_lle *lle; |
| 1839 | const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy; |
| 1840 | |
| 1841 | /* DTAP - Attach Request (IMSI 12131415161718) */ |
| 1842 | static const unsigned char attach_req[] = { |
| 1843 | 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, |
| 1844 | 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1845 | 0x18, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60, 0x19, |
| 1846 | 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00, |
| 1847 | 0x60, 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60, |
| 1848 | 0x80, 0xba, 0xc8, 0xc6, 0x62, 0x00, 0x60, 0x80, |
| 1849 | 0x00, |
| 1850 | }; |
| 1851 | |
| 1852 | /* DTAP - Attach Request (IMSI 12131415161718) (RA 2) */ |
| 1853 | static const unsigned char attach_req2[] = { |
| 1854 | 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, |
| 1855 | 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1856 | 0x18, 0x11, 0x22, 0x33, 0x40, 0x50, 0x61, 0x19, |
| 1857 | 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00, |
| 1858 | 0x60, 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60, |
| 1859 | 0x80, 0xba, 0xc8, 0xc6, 0x62, 0x00, 0x60, 0x80, |
| 1860 | 0x00, |
| 1861 | }; |
| 1862 | |
| 1863 | /* DTAP - Identity Response IMEI */ |
| 1864 | static const unsigned char ident_resp_imei[] = { |
| 1865 | 0x08, 0x16, 0x08, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, |
| 1866 | 0x56 |
| 1867 | }; |
| 1868 | |
| 1869 | /* DTAP - Attach Complete */ |
| 1870 | static const unsigned char attach_compl[] = { |
| 1871 | 0x08, 0x03 |
| 1872 | }; |
| 1873 | |
| 1874 | /* DTAP - Routing Area Update Request (coming from RA 1) */ |
| 1875 | static const unsigned char ra_upd_req1[] = { |
| 1876 | 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50, |
| 1877 | 0x60, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b, |
| 1878 | 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8, |
| 1879 | 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02, |
| 1880 | 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19, |
| 1881 | 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04, |
| 1882 | 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00 |
| 1883 | }; |
| 1884 | |
| 1885 | /* DTAP - Routing Area Update Request (coming from RA 2) */ |
| 1886 | static const unsigned char ra_upd_req2[] = { |
| 1887 | 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50, |
| 1888 | 0x61, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b, |
| 1889 | 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8, |
| 1890 | 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02, |
| 1891 | 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19, |
| 1892 | 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04, |
| 1893 | 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00 |
| 1894 | }; |
| 1895 | |
| 1896 | /* DTAP - Routing Area Update Request (coming from RA other) */ |
| 1897 | /* raid_other = {443, 223, 16464, 98}; */ |
| 1898 | static const unsigned char ra_upd_req_other[] = { |
| 1899 | 0x08, 0x08, 0x10, 0x22, 0x33, 0x44, 0x40, 0x50, |
| 1900 | 0x62, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b, |
| 1901 | 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8, |
| 1902 | 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02, |
| 1903 | 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19, |
| 1904 | 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04, |
| 1905 | 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00 |
| 1906 | }; |
| 1907 | |
| 1908 | /* DTAP - Routing Area Update Complete */ |
| 1909 | static const unsigned char ra_upd_complete[] = { |
| 1910 | 0x08, 0x0a |
| 1911 | }; |
| 1912 | |
| 1913 | /* DTAP - Detach Request (MO) */ |
| 1914 | /* normal detach, power_off = 1 */ |
| 1915 | static const unsigned char detach_req[] = { |
| 1916 | 0x08, 0x05, 0x09, 0x18, 0x05, 0xf4, 0xef, 0xe2, |
| 1917 | 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb |
| 1918 | }; |
| 1919 | |
| 1920 | sgsn->cfg.auth_policy = SGSN_AUTH_POLICY_OPEN; |
| 1921 | |
| 1922 | printf("Testing routing area changes\n"); |
| 1923 | |
| 1924 | /* reset the PRNG used by sgsn_alloc_ptmsi */ |
| 1925 | srand(1); |
| 1926 | |
| 1927 | ptmsi1 = GSM_RESERVED_TMSI; |
| 1928 | |
| 1929 | printf(" - Attach Request (RA 1)\n"); |
| 1930 | |
| 1931 | ms_tlli = gprs_tmsi2tlli(0x00000023, TLLI_RANDOM); |
| 1932 | |
| 1933 | /* Create a LLE/LLME */ |
| 1934 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 1935 | lle = gprs_lle_get_or_create(ms_tlli, 3); |
| 1936 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 1937 | |
| 1938 | /* inject the attach request */ |
| 1939 | send_0408_message(lle->llme, ms_tlli, &raid1, |
| 1940 | attach_req, ARRAY_SIZE(attach_req)); |
| 1941 | |
| 1942 | ctx = sgsn_mm_ctx_by_tlli(ms_tlli, &raid1); |
| 1943 | OSMO_ASSERT(ctx != NULL); |
| 1944 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 1945 | OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI); |
| 1946 | |
| 1947 | /* we expect an identity request (IMEI) */ |
| 1948 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 1949 | OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_ID_REQ); |
| 1950 | OSMO_ASSERT(last_dl_parse_ctx.tlli == ms_tlli); |
| 1951 | |
| 1952 | /* inject the identity response (IMEI) */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1953 | send_0408_message(ctx->gb.llme, ms_tlli, &raid1, |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 1954 | ident_resp_imei, ARRAY_SIZE(ident_resp_imei)); |
| 1955 | |
| 1956 | /* check that the MM context has not been removed due to a failed |
| 1957 | * authorization */ |
| 1958 | OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(ms_tlli, &raid1)); |
| 1959 | |
| 1960 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 1961 | |
| 1962 | /* we expect an attach accept */ |
| 1963 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 1964 | OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_ATTACH_ACK); |
| 1965 | OSMO_ASSERT(last_dl_parse_ctx.tlli == ms_tlli); |
| 1966 | |
| 1967 | received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx); |
| 1968 | OSMO_ASSERT(received_ptmsi == ctx->p_tmsi); |
| 1969 | ptmsi1 = received_ptmsi; |
| 1970 | |
| 1971 | /* inject the attach complete */ |
| 1972 | ms_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL); |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1973 | send_0408_message(ctx->gb.llme, ms_tlli, &raid1, |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 1974 | attach_compl, ARRAY_SIZE(attach_compl)); |
| 1975 | |
| 1976 | /* we don't expect a response */ |
| 1977 | OSMO_ASSERT(sgsn_tx_counter == 0); |
| 1978 | |
| 1979 | OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL); |
| 1980 | OSMO_ASSERT(ctx->p_tmsi_old == 0); |
| 1981 | OSMO_ASSERT(ctx->p_tmsi == ptmsi1); |
| 1982 | |
| 1983 | printf(" - RA Update Request (RA 1 -> RA 1)\n"); |
| 1984 | |
| 1985 | /* inject the RA update request */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 1986 | send_0408_message(ctx->gb.llme, ms_tlli, &raid1, |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 1987 | ra_upd_req1, ARRAY_SIZE(ra_upd_req1)); |
| 1988 | |
| 1989 | /* we expect an RA update accept */ |
| 1990 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 1991 | OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_RA_UPD_ACK); |
| 1992 | // OSMO_ASSERT(last_dl_parse_ctx.tlli == ms_tlli); |
| 1993 | |
| 1994 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 1995 | OSMO_ASSERT(ctx->p_tmsi_old == ptmsi1); |
| 1996 | OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI); |
| 1997 | OSMO_ASSERT(ctx->p_tmsi != ptmsi1); |
| 1998 | |
| 1999 | received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx); |
| 2000 | OSMO_ASSERT(received_ptmsi == ctx->p_tmsi); |
| 2001 | ptmsi1 = received_ptmsi; |
| 2002 | |
| 2003 | /* inject the RA update complete */ |
| 2004 | ms_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL); |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 2005 | send_0408_message(ctx->gb.llme, ms_tlli, &raid1, |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2006 | ra_upd_complete, ARRAY_SIZE(ra_upd_complete)); |
| 2007 | |
| 2008 | /* we don't expect a response */ |
| 2009 | OSMO_ASSERT(sgsn_tx_counter == 0); |
| 2010 | |
| 2011 | OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL); |
| 2012 | OSMO_ASSERT(ctx->p_tmsi_old == 0); |
| 2013 | OSMO_ASSERT(ctx->p_tmsi == ptmsi1); |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 2014 | OSMO_ASSERT(ctx->gb.tlli == ms_tlli); |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2015 | |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2016 | printf(" - RA Update Request (RA 1 -> RA 2)\n"); |
| 2017 | |
| 2018 | /* inject the RA update request */ |
| 2019 | ms_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_FOREIGN); |
| 2020 | |
| 2021 | /* It is coming from RA 1 => ra_upd_req1 */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 2022 | send_0408_message(ctx->gb.llme, ms_tlli, &raid2, |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2023 | ra_upd_req1, ARRAY_SIZE(ra_upd_req1)); |
| 2024 | |
Jacob Erlbeck | 5ac4aad | 2016-01-04 18:43:38 +0100 | [diff] [blame] | 2025 | /* we expect an RA update accept */ |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2026 | OSMO_ASSERT(sgsn_tx_counter == 1); |
Jacob Erlbeck | 5ac4aad | 2016-01-04 18:43:38 +0100 | [diff] [blame] | 2027 | OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_RA_UPD_ACK); |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2028 | |
| 2029 | printf(" - RA Update Request (RA other -> RA 2)\n"); |
| 2030 | |
| 2031 | /* inject the RA update request */ |
| 2032 | ms_tlli = gprs_tmsi2tlli(0x12345678, TLLI_FOREIGN); |
| 2033 | |
| 2034 | /* It is coming from RA 1 => ra_upd_req1 */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 2035 | send_0408_message(ctx->gb.llme, ms_tlli, &raid2, |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2036 | ra_upd_req_other, ARRAY_SIZE(ra_upd_req_other)); |
| 2037 | |
| 2038 | /* we expect an RA update reject (and a LLC XID RESET) */ |
| 2039 | OSMO_ASSERT(sgsn_tx_counter == 2); |
| 2040 | OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_RA_UPD_REJ); |
| 2041 | /* this has killed the LLE/LLME */ |
| 2042 | |
| 2043 | printf(" - Attach Request (RA 2)\n"); |
| 2044 | |
| 2045 | /* Create a LLE/LLME */ |
| 2046 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 2047 | lle = gprs_lle_get_or_create(ms_tlli, 3); |
| 2048 | OSMO_ASSERT(count(gprs_llme_list()) == 1); |
| 2049 | |
| 2050 | /* inject the attach request */ |
| 2051 | send_0408_message(lle->llme, ms_tlli, &raid2, |
| 2052 | attach_req2, ARRAY_SIZE(attach_req2)); |
| 2053 | |
| 2054 | ctx = sgsn_mm_ctx_by_tlli(ms_tlli, &raid2); |
| 2055 | OSMO_ASSERT(ctx != NULL); |
| 2056 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 2057 | OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI); |
| 2058 | |
| 2059 | /* we expect an attach accept */ |
| 2060 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 2061 | OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_ATTACH_ACK); |
| 2062 | |
| 2063 | received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx); |
| 2064 | OSMO_ASSERT(received_ptmsi == ctx->p_tmsi); |
| 2065 | ptmsi1 = received_ptmsi; |
| 2066 | |
| 2067 | /* inject the attach complete */ |
| 2068 | ms_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL); |
| 2069 | ictx = sgsn_mm_ctx_by_tlli(ms_tlli, &raid2); |
| 2070 | OSMO_ASSERT(ictx != NULL); |
| 2071 | OSMO_ASSERT(ictx == ctx); |
| 2072 | |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 2073 | send_0408_message(ctx->gb.llme, ms_tlli, &raid2, |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2074 | attach_compl, ARRAY_SIZE(attach_compl)); |
| 2075 | |
| 2076 | /* we don't expect a response */ |
| 2077 | OSMO_ASSERT(sgsn_tx_counter == 0); |
| 2078 | |
| 2079 | OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL); |
| 2080 | OSMO_ASSERT(ctx->p_tmsi_old == 0); |
| 2081 | OSMO_ASSERT(ctx->p_tmsi == ptmsi1); |
| 2082 | |
| 2083 | printf(" - RA Update Request (RA 2 -> RA 2)\n"); |
| 2084 | |
| 2085 | /* inject the RA update request */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 2086 | send_0408_message(ctx->gb.llme, ms_tlli, &raid2, |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2087 | ra_upd_req2, ARRAY_SIZE(ra_upd_req2)); |
| 2088 | |
| 2089 | /* we expect an RA update accept */ |
| 2090 | OSMO_ASSERT(sgsn_tx_counter == 1); |
| 2091 | OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_RA_UPD_ACK); |
| 2092 | |
| 2093 | OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT); |
| 2094 | OSMO_ASSERT(ctx->p_tmsi_old == ptmsi1); |
| 2095 | OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI); |
| 2096 | OSMO_ASSERT(ctx->p_tmsi != ptmsi1); |
| 2097 | |
| 2098 | received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx); |
| 2099 | OSMO_ASSERT(received_ptmsi == ctx->p_tmsi); |
| 2100 | ptmsi1 = received_ptmsi; |
| 2101 | |
| 2102 | /* inject the RA update complete */ |
| 2103 | ms_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL); |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 2104 | send_0408_message(ctx->gb.llme, ms_tlli, &raid2, |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2105 | ra_upd_complete, ARRAY_SIZE(ra_upd_complete)); |
| 2106 | |
| 2107 | /* we don't expect a response */ |
| 2108 | OSMO_ASSERT(sgsn_tx_counter == 0); |
| 2109 | |
| 2110 | OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL); |
| 2111 | OSMO_ASSERT(ctx->p_tmsi_old == 0); |
| 2112 | OSMO_ASSERT(ctx->p_tmsi == ptmsi1); |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 2113 | OSMO_ASSERT(ctx->gb.tlli == ms_tlli); |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2114 | |
| 2115 | |
| 2116 | /* inject the detach */ |
Harald Welte | f97ee04 | 2015-12-25 19:12:21 +0100 | [diff] [blame] | 2117 | send_0408_message(ctx->gb.llme, ms_tlli, &raid2, |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2118 | detach_req, ARRAY_SIZE(detach_req)); |
| 2119 | |
| 2120 | /* verify that things are gone */ |
| 2121 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 2122 | ictx = sgsn_mm_ctx_by_tlli(ms_tlli, &raid2); |
| 2123 | OSMO_ASSERT(!ictx); |
| 2124 | |
| 2125 | sgsn->cfg.auth_policy = saved_auth_policy; |
| 2126 | |
| 2127 | cleanup_test(); |
| 2128 | } |
| 2129 | |
Jacob Erlbeck | cb1db8b | 2015-02-03 13:47:53 +0100 | [diff] [blame] | 2130 | static void test_apn_matching(void) |
| 2131 | { |
| 2132 | struct apn_ctx *actx, *actxs[9]; |
| 2133 | |
| 2134 | printf("Testing APN matching\n"); |
| 2135 | |
| 2136 | actxs[0] = sgsn_apn_ctx_find_alloc("*.test", ""); |
| 2137 | actxs[1] = sgsn_apn_ctx_find_alloc("*.def.test", ""); |
| 2138 | actxs[2] = sgsn_apn_ctx_find_alloc("abc.def.test", ""); |
| 2139 | actxs[3] = NULL; |
| 2140 | |
| 2141 | actxs[4] = sgsn_apn_ctx_find_alloc("abc.def.test", "456"); |
| 2142 | actxs[5] = sgsn_apn_ctx_find_alloc("abc.def.test", "456123"); |
| 2143 | actxs[6] = sgsn_apn_ctx_find_alloc("*.def.test", "456"); |
| 2144 | actxs[7] = sgsn_apn_ctx_find_alloc("*.def.test", "456123"); |
| 2145 | |
| 2146 | actxs[8] = sgsn_apn_ctx_find_alloc("ghi.def.test", "456"); |
| 2147 | |
| 2148 | actx = sgsn_apn_ctx_match("abc.def.test", "12345678"); |
| 2149 | OSMO_ASSERT(actx == actxs[2]); |
| 2150 | actx = sgsn_apn_ctx_match("aBc.dEf.test", "12345678"); |
| 2151 | OSMO_ASSERT(actx == actxs[2]); |
| 2152 | actx = sgsn_apn_ctx_match("xyz.def.test", "12345678"); |
| 2153 | OSMO_ASSERT(actx == actxs[1]); |
| 2154 | actx = sgsn_apn_ctx_match("xyz.dEf.test", "12345678"); |
| 2155 | OSMO_ASSERT(actx == actxs[1]); |
| 2156 | actx = sgsn_apn_ctx_match("xyz.uvw.test", "12345678"); |
| 2157 | OSMO_ASSERT(actx == actxs[0]); |
| 2158 | actx = sgsn_apn_ctx_match("xyz.uvw.foo", "12345678"); |
| 2159 | OSMO_ASSERT(actx == NULL); |
| 2160 | |
| 2161 | actxs[3] = sgsn_apn_ctx_find_alloc("*", ""); |
| 2162 | actx = sgsn_apn_ctx_match("xyz.uvw.foo", "12345678"); |
| 2163 | OSMO_ASSERT(actx == actxs[3]); |
| 2164 | |
| 2165 | actx = sgsn_apn_ctx_match("abc.def.test", "45699900"); |
| 2166 | OSMO_ASSERT(actx == actxs[4]); |
| 2167 | |
| 2168 | actx = sgsn_apn_ctx_match("xyz.def.test", "45699900"); |
| 2169 | OSMO_ASSERT(actx == actxs[6]); |
| 2170 | |
| 2171 | actx = sgsn_apn_ctx_match("abc.def.test", "45612300"); |
| 2172 | OSMO_ASSERT(actx == actxs[5]); |
| 2173 | |
| 2174 | actx = sgsn_apn_ctx_match("xyz.def.test", "45612300"); |
| 2175 | OSMO_ASSERT(actx == actxs[7]); |
| 2176 | |
| 2177 | actx = sgsn_apn_ctx_match("ghi.def.test", "45699900"); |
| 2178 | OSMO_ASSERT(actx == actxs[8]); |
| 2179 | |
| 2180 | actx = sgsn_apn_ctx_match("ghi.def.test", "45612300"); |
| 2181 | OSMO_ASSERT(actx == actxs[7]); |
| 2182 | |
| 2183 | /* Free APN contexts and check how the matching changes */ |
| 2184 | |
| 2185 | sgsn_apn_ctx_free(actxs[7]); |
| 2186 | actx = sgsn_apn_ctx_match("ghi.def.test", "45612300"); |
| 2187 | OSMO_ASSERT(actx == actxs[8]); |
| 2188 | |
| 2189 | sgsn_apn_ctx_free(actxs[8]); |
| 2190 | actx = sgsn_apn_ctx_match("ghi.def.test", "45612300"); |
| 2191 | OSMO_ASSERT(actx == actxs[6]); |
| 2192 | |
| 2193 | sgsn_apn_ctx_free(actxs[6]); |
| 2194 | actx = sgsn_apn_ctx_match("ghi.def.test", "45612300"); |
| 2195 | OSMO_ASSERT(actx == actxs[1]); |
| 2196 | |
| 2197 | sgsn_apn_ctx_free(actxs[5]); |
| 2198 | actx = sgsn_apn_ctx_match("abc.def.test", "45612300"); |
| 2199 | OSMO_ASSERT(actx == actxs[4]); |
| 2200 | |
| 2201 | sgsn_apn_ctx_free(actxs[4]); |
| 2202 | actx = sgsn_apn_ctx_match("abc.def.test", "45612300"); |
| 2203 | OSMO_ASSERT(actx == actxs[2]); |
| 2204 | |
| 2205 | sgsn_apn_ctx_free(actxs[2]); |
| 2206 | actx = sgsn_apn_ctx_match("abc.def.test", "12345678"); |
| 2207 | OSMO_ASSERT(actx == actxs[1]); |
| 2208 | |
| 2209 | sgsn_apn_ctx_free(actxs[1]); |
| 2210 | actx = sgsn_apn_ctx_match("abc.def.test", "12345678"); |
| 2211 | OSMO_ASSERT(actx == actxs[0]); |
| 2212 | |
| 2213 | sgsn_apn_ctx_free(actxs[0]); |
| 2214 | actx = sgsn_apn_ctx_match("abc.def.test", "12345678"); |
| 2215 | OSMO_ASSERT(actx == actxs[3]); |
| 2216 | |
| 2217 | sgsn_apn_ctx_free(actxs[3]); |
| 2218 | actx = sgsn_apn_ctx_match("abc.def.test", "12345678"); |
| 2219 | OSMO_ASSERT(actx == NULL); |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 2220 | |
| 2221 | cleanup_test(); |
Jacob Erlbeck | cb1db8b | 2015-02-03 13:47:53 +0100 | [diff] [blame] | 2222 | } |
| 2223 | |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2224 | struct sgsn_subscriber_pdp_data* sgsn_subscriber_pdp_data_alloc( |
| 2225 | struct sgsn_subscriber_data *sdata); |
| 2226 | |
| 2227 | static void test_ggsn_selection(void) |
| 2228 | { |
| 2229 | struct apn_ctx *actxs[4]; |
| 2230 | struct sgsn_ggsn_ctx *ggc, *ggcs[3]; |
| 2231 | struct gsm_subscriber *s1; |
| 2232 | const char *imsi1 = "1234567890"; |
| 2233 | struct sgsn_mm_ctx *ctx; |
| 2234 | struct gprs_ra_id raid = { 0, }; |
| 2235 | uint32_t local_tlli = 0xffeeddcc; |
| 2236 | enum gsm48_gsm_cause gsm_cause; |
| 2237 | struct tlv_parsed tp; |
| 2238 | uint8_t apn_enc[GSM_APN_LENGTH + 10]; |
| 2239 | struct sgsn_subscriber_pdp_data *pdp_data; |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2240 | char apn_str[GSM_APN_LENGTH]; |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2241 | |
| 2242 | printf("Testing GGSN selection\n"); |
| 2243 | |
| 2244 | gprs_gsup_client_send_cb = my_gprs_gsup_client_send_dummy; |
| 2245 | |
| 2246 | /* Check for emptiness */ |
| 2247 | OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL); |
| 2248 | |
| 2249 | /* Create a context */ |
| 2250 | OSMO_ASSERT(count(gprs_llme_list()) == 0); |
| 2251 | ctx = alloc_mm_ctx(local_tlli, &raid); |
| 2252 | strncpy(ctx->imsi, imsi1, sizeof(ctx->imsi) - 1); |
| 2253 | |
| 2254 | /* Allocate and attach a subscriber */ |
| 2255 | s1 = gprs_subscr_get_or_create_by_mmctx(ctx); |
| 2256 | assert_subscr(s1, imsi1); |
| 2257 | |
| 2258 | tp.lv[GSM48_IE_GSM_APN].len = 0; |
| 2259 | tp.lv[GSM48_IE_GSM_APN].val = apn_enc; |
| 2260 | |
| 2261 | /* TODO: Add PDP info entries to s1 */ |
| 2262 | |
| 2263 | ggcs[0] = sgsn_ggsn_ctx_find_alloc(0); |
| 2264 | ggcs[1] = sgsn_ggsn_ctx_find_alloc(1); |
| 2265 | ggcs[2] = sgsn_ggsn_ctx_find_alloc(2); |
| 2266 | |
| 2267 | actxs[0] = sgsn_apn_ctx_find_alloc("test.apn", "123456"); |
| 2268 | actxs[0]->ggsn = ggcs[0]; |
| 2269 | actxs[1] = sgsn_apn_ctx_find_alloc("*.apn", "123456"); |
| 2270 | actxs[1]->ggsn = ggcs[1]; |
| 2271 | actxs[2] = sgsn_apn_ctx_find_alloc("*", "456789"); |
| 2272 | actxs[2]->ggsn = ggcs[2]; |
| 2273 | |
Holger Hans Peter Freyther | 9270d99 | 2015-05-24 20:51:17 +0800 | [diff] [blame] | 2274 | pdp_data = sgsn_subscriber_pdp_data_alloc(s1->sgsn_data); |
| 2275 | pdp_data->context_id = 1; |
| 2276 | pdp_data->pdp_type = 0x0121; |
| 2277 | strncpy(pdp_data->apn_str, "*", sizeof(pdp_data->apn_str)-1); |
| 2278 | |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2279 | /* Resolve GGSNs */ |
| 2280 | |
| 2281 | tp.lv[GSM48_IE_GSM_APN].len = |
| 2282 | gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Test.Apn"); |
| 2283 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2284 | ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2285 | OSMO_ASSERT(ggc != NULL); |
| 2286 | OSMO_ASSERT(ggc->id == 0); |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2287 | OSMO_ASSERT(strcmp(apn_str, "Test.Apn") == 0); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2288 | |
| 2289 | tp.lv[GSM48_IE_GSM_APN].len = |
| 2290 | gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Other.Apn"); |
| 2291 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2292 | ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2293 | OSMO_ASSERT(ggc != NULL); |
| 2294 | OSMO_ASSERT(ggc->id == 1); |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2295 | OSMO_ASSERT(strcmp(apn_str, "Other.Apn") == 0); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2296 | |
| 2297 | tp.lv[GSM48_IE_GSM_APN].len = 0; |
| 2298 | tp.lv[GSM48_IE_GSM_APN].val = NULL; |
| 2299 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2300 | ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2301 | OSMO_ASSERT(ggc != NULL); |
| 2302 | OSMO_ASSERT(ggc->id == 0); |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2303 | OSMO_ASSERT(strcmp(apn_str, "") == 0); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2304 | |
| 2305 | actxs[3] = sgsn_apn_ctx_find_alloc("*", "123456"); |
| 2306 | actxs[3]->ggsn = ggcs[2]; |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2307 | ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2308 | OSMO_ASSERT(ggc != NULL); |
| 2309 | OSMO_ASSERT(ggc->id == 2); |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2310 | OSMO_ASSERT(strcmp(apn_str, "") == 0); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2311 | |
| 2312 | sgsn_apn_ctx_free(actxs[3]); |
| 2313 | tp.lv[GSM48_IE_GSM_APN].val = apn_enc; |
| 2314 | |
| 2315 | tp.lv[GSM48_IE_GSM_APN].len = |
| 2316 | gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Foo.Bar"); |
| 2317 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2318 | ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2319 | OSMO_ASSERT(ggc == NULL); |
| 2320 | OSMO_ASSERT(gsm_cause == GSM_CAUSE_MISSING_APN); |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2321 | OSMO_ASSERT(strcmp(apn_str, "Foo.Bar") == 0); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2322 | |
| 2323 | tp.lv[GSM48_IE_GSM_APN].len = sizeof(apn_enc); |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2324 | ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2325 | OSMO_ASSERT(ggc == NULL); |
| 2326 | OSMO_ASSERT(gsm_cause == GSM_CAUSE_INV_MAND_INFO); |
| 2327 | |
| 2328 | /* Add PDP data entry to subscriber */ |
| 2329 | |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2330 | strncpy(pdp_data->apn_str, "Test.Apn", sizeof(pdp_data->apn_str)-1); |
| 2331 | |
| 2332 | tp.lv[GSM48_IE_GSM_APN].len = |
| 2333 | gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Test.Apn"); |
| 2334 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2335 | ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2336 | OSMO_ASSERT(ggc != NULL); |
| 2337 | OSMO_ASSERT(ggc->id == 0); |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2338 | OSMO_ASSERT(strcmp(apn_str, "Test.Apn") == 0); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2339 | |
| 2340 | tp.lv[GSM48_IE_GSM_APN].len = |
| 2341 | gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Other.Apn"); |
| 2342 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2343 | ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2344 | OSMO_ASSERT(ggc == NULL); |
| 2345 | OSMO_ASSERT(gsm_cause == GSM_CAUSE_REQ_SERV_OPT_NOTSUB); |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 2346 | OSMO_ASSERT(strcmp(apn_str, "") == 0); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2347 | |
| 2348 | /* Cleanup */ |
| 2349 | |
| 2350 | subscr_put(s1); |
| 2351 | sgsn_mm_ctx_cleanup_free(ctx); |
| 2352 | |
| 2353 | assert_no_subscrs(); |
| 2354 | |
| 2355 | sgsn_apn_ctx_free(actxs[0]); |
| 2356 | sgsn_apn_ctx_free(actxs[1]); |
| 2357 | sgsn_apn_ctx_free(actxs[2]); |
| 2358 | |
| 2359 | sgsn_ggsn_ctx_free(ggcs[0]); |
| 2360 | sgsn_ggsn_ctx_free(ggcs[1]); |
| 2361 | sgsn_ggsn_ctx_free(ggcs[2]); |
| 2362 | |
| 2363 | gprs_gsup_client_send_cb = __real_gprs_gsup_client_send; |
Jacob Erlbeck | cf15187 | 2015-10-12 19:36:31 +0200 | [diff] [blame] | 2364 | |
| 2365 | cleanup_test(); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2366 | } |
| 2367 | |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 2368 | static struct log_info_cat gprs_categories[] = { |
| 2369 | [DMM] = { |
| 2370 | .name = "DMM", |
| 2371 | .description = "Layer3 Mobility Management (MM)", |
| 2372 | .color = "\033[1;33m", |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 2373 | .enabled = 1, .loglevel = LOGL_DEBUG, |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 2374 | }, |
| 2375 | [DPAG] = { |
| 2376 | .name = "DPAG", |
| 2377 | .description = "Paging Subsystem", |
| 2378 | .color = "\033[1;38m", |
| 2379 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 2380 | }, |
| 2381 | [DMEAS] = { |
| 2382 | .name = "DMEAS", |
| 2383 | .description = "Radio Measurement Processing", |
| 2384 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 2385 | }, |
| 2386 | [DREF] = { |
| 2387 | .name = "DREF", |
| 2388 | .description = "Reference Counting", |
| 2389 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 2390 | }, |
| 2391 | [DGPRS] = { |
| 2392 | .name = "DGPRS", |
| 2393 | .description = "GPRS Packet Service", |
| 2394 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 2395 | }, |
| 2396 | [DNS] = { |
| 2397 | .name = "DNS", |
| 2398 | .description = "GPRS Network Service (NS)", |
| 2399 | .enabled = 1, .loglevel = LOGL_INFO, |
| 2400 | }, |
| 2401 | [DBSSGP] = { |
| 2402 | .name = "DBSSGP", |
| 2403 | .description = "GPRS BSS Gateway Protocol (BSSGP)", |
| 2404 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 2405 | }, |
| 2406 | [DLLC] = { |
| 2407 | .name = "DLLC", |
| 2408 | .description = "GPRS Logical Link Control Protocol (LLC)", |
| 2409 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 2410 | }, |
| 2411 | [DSNDCP] = { |
| 2412 | .name = "DSNDCP", |
| 2413 | .description = "GPRS Sub-Network Dependent Control Protocol (SNDCP)", |
| 2414 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 2415 | }, |
| 2416 | }; |
| 2417 | |
| 2418 | static struct log_info info = { |
| 2419 | .cat = gprs_categories, |
| 2420 | .num_cat = ARRAY_SIZE(gprs_categories), |
| 2421 | }; |
| 2422 | |
Holger Hans Peter Freyther | 68c6f88 | 2014-09-30 09:10:25 +0200 | [diff] [blame] | 2423 | int main(int argc, char **argv) |
| 2424 | { |
Jacob Erlbeck | 4b2d02d | 2015-01-30 11:57:25 +0100 | [diff] [blame] | 2425 | void *osmo_sgsn_ctx; |
| 2426 | |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 2427 | osmo_init_logging(&info); |
Jacob Erlbeck | 4b2d02d | 2015-01-30 11:57:25 +0100 | [diff] [blame] | 2428 | osmo_sgsn_ctx = talloc_named_const(NULL, 0, "osmo_sgsn"); |
| 2429 | tall_bsc_ctx = talloc_named_const(osmo_sgsn_ctx, 0, "bsc"); |
| 2430 | tall_msgb_ctx = talloc_named_const(osmo_sgsn_ctx, 0, "msgb"); |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 2431 | |
Alexander Couzens | 14314bd | 2016-07-05 09:52:52 +0200 | [diff] [blame] | 2432 | sgsn_rate_ctr_init(); |
Jacob Erlbeck | a0b6efb | 2014-11-13 10:48:39 +0100 | [diff] [blame] | 2433 | sgsn_auth_init(); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 2434 | gprs_subscr_init(sgsn); |
Jacob Erlbeck | 27cb4d5 | 2014-10-29 12:11:58 +0100 | [diff] [blame] | 2435 | |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 2436 | test_llme(); |
Jacob Erlbeck | 33b6dad | 2014-11-12 10:12:11 +0100 | [diff] [blame] | 2437 | test_subscriber(); |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 2438 | test_auth_triplets(); |
Jacob Erlbeck | a6ddc2d | 2014-12-12 15:01:37 +0100 | [diff] [blame] | 2439 | test_subscriber_gsup(); |
Holger Hans Peter Freyther | fe92133 | 2014-10-02 22:24:47 +0200 | [diff] [blame] | 2440 | test_gmm_detach(); |
Jacob Erlbeck | 189999d | 2014-10-27 14:34:13 +0100 | [diff] [blame] | 2441 | test_gmm_detach_power_off(); |
Jacob Erlbeck | 5a38f64 | 2014-10-21 13:09:55 +0200 | [diff] [blame] | 2442 | test_gmm_detach_no_mmctx(); |
Jacob Erlbeck | de4bbc7 | 2014-11-24 15:04:15 +0100 | [diff] [blame] | 2443 | test_gmm_detach_accept_unexpected(); |
Jacob Erlbeck | 14ae582 | 2014-10-28 09:47:03 +0100 | [diff] [blame] | 2444 | test_gmm_status_no_mmctx(); |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 2445 | test_gmm_attach_acl(); |
| 2446 | test_gmm_attach_subscr(); |
Jacob Erlbeck | 2e5e94c | 2014-12-08 15:26:47 +0100 | [diff] [blame] | 2447 | test_gmm_attach_subscr_fake_auth(); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 2448 | test_gmm_attach_subscr_real_auth(); |
Jacob Erlbeck | 7660ffa | 2014-12-19 18:30:41 +0100 | [diff] [blame] | 2449 | test_gmm_attach_subscr_gsup_auth(0); |
| 2450 | test_gmm_attach_subscr_gsup_auth(1); |
Jacob Erlbeck | c157ee7 | 2015-01-09 15:07:16 +0100 | [diff] [blame] | 2451 | test_gmm_attach_subscr_real_gsup_auth(0); |
Jacob Erlbeck | 80d07e3 | 2014-11-06 13:43:41 +0100 | [diff] [blame] | 2452 | test_gmm_reject(); |
Jacob Erlbeck | 98647ca | 2014-11-11 14:47:38 +0100 | [diff] [blame] | 2453 | test_gmm_cancel(); |
Jacob Erlbeck | f6e7d99 | 2014-11-06 15:43:10 +0100 | [diff] [blame] | 2454 | test_gmm_ptmsi_allocation(); |
Jacob Erlbeck | 1330478 | 2016-01-04 18:43:37 +0100 | [diff] [blame] | 2455 | test_gmm_routing_areas(); |
Jacob Erlbeck | cb1db8b | 2015-02-03 13:47:53 +0100 | [diff] [blame] | 2456 | test_apn_matching(); |
Jacob Erlbeck | 277b71e | 2015-02-02 18:03:05 +0100 | [diff] [blame] | 2457 | test_ggsn_selection(); |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 2458 | printf("Done\n"); |
Jacob Erlbeck | 07de92e | 2015-01-13 11:46:32 +0100 | [diff] [blame] | 2459 | |
Jacob Erlbeck | 4b2d02d | 2015-01-30 11:57:25 +0100 | [diff] [blame] | 2460 | talloc_report_full(osmo_sgsn_ctx, stderr); |
Jacob Erlbeck | f0b06d8 | 2015-01-13 11:56:28 +0100 | [diff] [blame] | 2461 | OSMO_ASSERT(talloc_total_blocks(tall_msgb_ctx) == 1); |
Alexander Couzens | 14314bd | 2016-07-05 09:52:52 +0200 | [diff] [blame] | 2462 | OSMO_ASSERT(talloc_total_blocks(tall_bsc_ctx) == 2); |
Holger Hans Peter Freyther | 68c6f88 | 2014-09-30 09:10:25 +0200 | [diff] [blame] | 2463 | return 0; |
| 2464 | } |
Holger Hans Peter Freyther | 4299c05 | 2014-10-02 21:27:24 +0200 | [diff] [blame] | 2465 | |
| 2466 | |
| 2467 | /* stubs */ |
| 2468 | struct osmo_prim_hdr; |
| 2469 | int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx) |
| 2470 | { |
| 2471 | abort(); |
| 2472 | } |