blob: 5d142da904de26497d833689af7cca7e742112a6 [file] [log] [blame]
Holger Hans Peter Freyther68c6f882014-09-30 09:10:25 +02001/* 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 Freyther4299c052014-10-02 21:27:24 +020022#include <openbsc/gprs_llc.h>
23#include <openbsc/sgsn.h>
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +020024#include <openbsc/gprs_gmm.h>
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +020025#include <openbsc/debug.h>
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010026#include <openbsc/gsm_subscriber.h>
Jacob Erlbeckc157ee72015-01-09 15:07:16 +010027#include <openbsc/gprs_gsup_messages.h>
28#include <openbsc/gprs_gsup_client.h>
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +020029
Jacob Erlbeck189999d2014-10-27 14:34:13 +010030#include <osmocom/gprs/gprs_bssgp.h>
31
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +020032#include <osmocom/gsm/gsm_utils.h>
Jacob Erlbeckbce20612015-01-05 18:57:32 +010033#include <openbsc/gsm_04_08_gprs.h>
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +020034
35#include <osmocom/core/application.h>
36#include <osmocom/core/msgb.h>
Jacob Erlbeck189999d2014-10-27 14:34:13 +010037#include <osmocom/core/rate_ctr.h>
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +020038
Holger Hans Peter Freyther68c6f882014-09-30 09:10:25 +020039#include <stdio.h>
40
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +020041extern void *tall_msgb_ctx;
42
43void *tall_bsc_ctx;
44static struct sgsn_instance sgsn_inst = {
45 .config_file = "osmo_sgsn.cfg",
46 .cfg = {
47 .gtp_statedir = "./",
Jacob Erlbeck106f5472014-11-04 10:08:37 +010048 .auth_policy = SGSN_AUTH_POLICY_CLOSED,
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +020049 },
50};
51struct sgsn_instance *sgsn = &sgsn_inst;
Jacob Erlbeck189999d2014-10-27 14:34:13 +010052unsigned sgsn_tx_counter = 0;
53
54/* override */
55int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime,
56 struct bssgp_dl_ud_par *dup)
57{
58 sgsn_tx_counter += 1;
Jacob Erlbeckf0b06d82015-01-13 11:56:28 +010059 msgb_free(msg);
Jacob Erlbeck189999d2014-10-27 14:34:13 +010060 return 0;
61}
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +020062
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010063/* override, requires '-Wl,--wrap=sgsn_update_subscriber_data' */
64void __real_sgsn_update_subscriber_data(struct sgsn_mm_ctx *, struct gsm_subscriber *);
65void (*update_subscriber_data_cb)(struct sgsn_mm_ctx *, struct gsm_subscriber *) =
66 &__real_sgsn_update_subscriber_data;
67
68void __wrap_sgsn_update_subscriber_data(struct sgsn_mm_ctx *mmctx,
69 struct gsm_subscriber *subscr)
70{
71 (*update_subscriber_data_cb)(mmctx, subscr);
72}
73
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +010074/* override, requires '-Wl,--wrap=gprs_subscr_request_update_location' */
75int __real_gprs_subscr_request_update_location(struct sgsn_mm_ctx *mmctx);
76int (*subscr_request_update_location_cb)(struct sgsn_mm_ctx *mmctx) =
77 &__real_gprs_subscr_request_update_location;
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +010078
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +010079int __wrap_gprs_subscr_request_update_location(struct sgsn_mm_ctx *mmctx) {
80 return (*subscr_request_update_location_cb)(mmctx);
81};
82
83/* override, requires '-Wl,--wrap=gprs_subscr_request_auth_info' */
84int __real_gprs_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx);
85int (*subscr_request_auth_info_cb)(struct sgsn_mm_ctx *mmctx) =
86 &__real_gprs_subscr_request_auth_info;
87
88int __wrap_gprs_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx) {
89 return (*subscr_request_auth_info_cb)(mmctx);
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +010090};
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +010091
Jacob Erlbeckc157ee72015-01-09 15:07:16 +010092/* override, requires '-Wl,--wrap=gprs_gsup_client_send' */
93int __real_gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg);
94int (*gprs_gsup_client_send_cb)(struct gprs_gsup_client *gsupc, struct msgb *msg) =
95 &__real_gprs_gsup_client_send;
96
97int __wrap_gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg)
98{
99 return (*gprs_gsup_client_send_cb)(gsupc, msg);
100};
101
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +0200102static int count(struct llist_head *head)
103{
104 struct llist_head *cur;
105 int count = 0;
106
107 llist_for_each(cur, head)
108 count += 1;
109
110 return count;
111}
112
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +0200113static struct msgb *create_msg(const uint8_t *data, size_t len)
114{
115 struct msgb *msg = msgb_alloc(len + 8, "test message");
116 msg->l1h = msgb_put(msg, 8);
117 msg->l2h = msgb_put(msg, len);
118 memcpy(msg->l2h, data, len);
119
120 msgb_bcid(msg) = msg->l1h;
121 msgb_gmmh(msg) = msg->l2h;
122 return msg;
123}
124
Jacob Erlbeckabc16a52014-10-27 13:23:49 +0100125/*
126 * Create a context and search for it
127 */
128static struct sgsn_mm_ctx *alloc_mm_ctx(uint32_t tlli, struct gprs_ra_id *raid)
129{
130 struct sgsn_mm_ctx *ctx, *ictx;
131 struct gprs_llc_lle *lle;
132 int old_count = count(gprs_llme_list());
133
134 lle = gprs_lle_get_or_create(tlli, 3);
135 ctx = sgsn_mm_ctx_alloc(tlli, raid);
136 ctx->mm_state = GMM_REGISTERED_NORMAL;
137 ctx->llme = lle->llme;
138
139 ictx = sgsn_mm_ctx_by_tlli(tlli, raid);
140 OSMO_ASSERT(ictx == ctx);
141
142 OSMO_ASSERT(count(gprs_llme_list()) == old_count + 1);
143
144 return ctx;
145}
146
Jacob Erlbeck94ef1c02014-10-29 10:31:18 +0100147static void send_0408_message(struct gprs_llc_llme *llme, uint32_t tlli,
148 const uint8_t *data, size_t data_len)
149{
150 struct msgb *msg;
151
152 sgsn_tx_counter = 0;
153
154 msg = create_msg(data, data_len);
155 msgb_tlli(msg) = tlli;
156 gsm0408_gprs_rcvmsg(msg, llme);
157 msgb_free(msg);
158}
159
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +0200160static void test_llme(void)
161{
162 struct gprs_llc_lle *lle, *lle_copy;
163 uint32_t local_tlli;
164 uint32_t foreign_tlli;
165
166 printf("Testing LLME allocations\n");
167 local_tlli = gprs_tmsi2tlli(0x234, TLLI_LOCAL);
168 foreign_tlli = gprs_tmsi2tlli(0x234, TLLI_FOREIGN);
169
170 /* initial state */
171 OSMO_ASSERT(count(gprs_llme_list()) == 0);
172
173 /* Create a new entry */
174 lle = gprs_lle_get_or_create(local_tlli, 3);
175 OSMO_ASSERT(lle);
176 OSMO_ASSERT(count(gprs_llme_list()) == 1);
177
178 /* No new entry is created */
179 lle_copy = gprs_lle_get_or_create(local_tlli, 3);
180 OSMO_ASSERT(lle == lle_copy);
181 OSMO_ASSERT(count(gprs_llme_list()) == 1);
182 lle_copy = gprs_lle_get_or_create(foreign_tlli, 3);
183 OSMO_ASSERT(lle == lle_copy);
184 OSMO_ASSERT(count(gprs_llme_list()) == 1);
185
186 /* unassign which should delete it*/
187 gprs_llgmm_assign(lle->llme, lle->llme->tlli, 0xffffffff, GPRS_ALGO_GEA0, NULL);
188
189 /* Check that everything was cleaned up */
190 OSMO_ASSERT(count(gprs_llme_list()) == 0);
191}
192
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100193struct gsm_subscriber *last_updated_subscr = NULL;
194void my_dummy_sgsn_update_subscriber_data(struct sgsn_mm_ctx *mmctx,
195 struct gsm_subscriber *subscr)
196{
197 fprintf(stderr, "Called %s, mmctx = %p, subscr = %p\n",
198 __func__, mmctx, subscr);
199 last_updated_subscr = subscr;
200}
201
Jacob Erlbeckb8fb1402015-01-09 11:59:50 +0100202static void assert_subscr(const struct gsm_subscriber *subscr, const char *imsi)
203{
204 struct gsm_subscriber *sfound;
Jacob Erlbeck6be9ffa2015-01-19 08:57:07 +0100205 OSMO_ASSERT(subscr);
206 OSMO_ASSERT(strcmp(subscr->imsi, imsi) == 0);
Jacob Erlbeckb8fb1402015-01-09 11:59:50 +0100207
208 sfound = gprs_subscr_get_by_imsi(imsi);
209 OSMO_ASSERT(sfound == subscr);
Jacob Erlbeckb8fb1402015-01-09 11:59:50 +0100210
Jacob Erlbeck6be9ffa2015-01-19 08:57:07 +0100211 subscr_put(sfound);
Jacob Erlbeckb8fb1402015-01-09 11:59:50 +0100212}
213
Jacob Erlbeck058bc262015-01-13 11:46:32 +0100214static void show_subscrs(FILE *out)
215{
216 struct gsm_subscriber *subscr;
217
218 llist_for_each_entry(subscr, &active_subscribers, entry) {
219 fprintf(out, " Subscriber: %s, "
Holger Hans Peter Freyther1d778fd2015-01-20 21:14:03 +0100220 "use count: %d\n",
221 subscr->imsi, subscr->use_count);
Jacob Erlbeck058bc262015-01-13 11:46:32 +0100222 }
223}
224
225static void assert_no_subscrs()
226{
227 show_subscrs(stdout);
228 fflush(stdout);
229 OSMO_ASSERT(llist_empty(&active_subscribers));
230}
231
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100232static void test_subscriber(void)
233{
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +0100234 struct gsm_subscriber *s1, *s2, *s3, *sfound;
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100235 const char *imsi1 = "1234567890";
236 const char *imsi2 = "9876543210";
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +0100237 const char *imsi3 = "5656565656";
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100238
239 update_subscriber_data_cb = my_dummy_sgsn_update_subscriber_data;
240
241 printf("Testing core subscriber data API\n");
242
243 /* Check for emptiness */
244 OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL);
245 OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi2) == NULL);
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +0100246 OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi3) == NULL);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100247
248 /* Allocate entry 1 */
249 s1 = gprs_subscr_get_or_create(imsi1);
250 s1->flags |= GSM_SUBSCRIBER_FIRST_CONTACT;
Jacob Erlbeckb8fb1402015-01-09 11:59:50 +0100251 assert_subscr(s1, imsi1);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100252 OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi2) == NULL);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100253
254 /* Allocate entry 2 */
255 s2 = gprs_subscr_get_or_create(imsi2);
256 s2->flags |= GSM_SUBSCRIBER_FIRST_CONTACT;
Jacob Erlbeckb8fb1402015-01-09 11:59:50 +0100257
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +0100258 /* Allocate entry 3 */
259 s3 = gprs_subscr_get_or_create(imsi3);
260
Jacob Erlbeckb8fb1402015-01-09 11:59:50 +0100261 /* Check entries */
262 assert_subscr(s1, imsi1);
263 assert_subscr(s2, imsi2);
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +0100264 assert_subscr(s3, imsi3);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100265
266 /* Update entry 1 */
267 last_updated_subscr = NULL;
268 gprs_subscr_update(s1);
269 OSMO_ASSERT(last_updated_subscr == s1);
270
Holger Hans Peter Freyther1d778fd2015-01-20 21:14:03 +0100271 /* There is no subscriber cache. Verify it */
Jacob Erlbeck3e4e58f2015-01-26 11:07:24 +0100272 gprs_subscr_cleanup(s1);
Jacob Erlbeck37139e52015-01-23 13:52:55 +0100273 subscr_put(s1);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100274 s1 = NULL;
Holger Hans Peter Freyther1d778fd2015-01-20 21:14:03 +0100275 sfound = gprs_subscr_get_by_imsi(imsi1);
276 OSMO_ASSERT(sfound == NULL);
277
Jacob Erlbeckb8fb1402015-01-09 11:59:50 +0100278 assert_subscr(s2, imsi2);
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +0100279 assert_subscr(s3, imsi3);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100280
Jacob Erlbeckb8fb1402015-01-09 11:59:50 +0100281 /* Free entry 2 (GSM_SUBSCRIBER_FIRST_CONTACT is set) */
Jacob Erlbeck3e4e58f2015-01-26 11:07:24 +0100282 gprs_subscr_cleanup(s2);
Jacob Erlbeck37139e52015-01-23 13:52:55 +0100283 subscr_put(s2);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100284 s2 = NULL;
285 OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL);
286 OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi2) == NULL);
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +0100287 assert_subscr(s3, imsi3);
288
289 /* Try to delete entry 3 */
Jacob Erlbeck3e4e58f2015-01-26 11:07:24 +0100290 gprs_subscr_cleanup(s3);
Jacob Erlbeck37139e52015-01-23 13:52:55 +0100291 subscr_put(s3);
Holger Hans Peter Freyther1d778fd2015-01-20 21:14:03 +0100292 s3 = NULL;
Jacob Erlbeck0f47b8f2015-01-06 16:32:41 +0100293 OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi3) == NULL);
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +0100294
295 OSMO_ASSERT(llist_empty(&active_subscribers));
296
297 update_subscriber_data_cb = __real_sgsn_update_subscriber_data;
298}
299
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100300static void test_auth_triplets(void)
301{
302 struct gsm_subscriber *s1, *s1found;
303 const char *imsi1 = "1234567890";
304 struct gsm_auth_tuple *at;
305 struct sgsn_mm_ctx *ctx;
306 struct gprs_ra_id raid = { 0, };
307 uint32_t local_tlli = 0xffeeddcc;
308 struct gprs_llc_llme *llme;
309
310 printf("Testing authentication triplet handling\n");
311
312 /* Check for emptiness */
313 OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL);
314
315 /* Allocate entry 1 */
316 s1 = gprs_subscr_get_or_create(imsi1);
317 s1->flags |= GSM_SUBSCRIBER_FIRST_CONTACT;
318 s1found = gprs_subscr_get_by_imsi(imsi1);
319 OSMO_ASSERT(s1found == s1);
320 subscr_put(s1found);
321
322 /* Create a context */
323 OSMO_ASSERT(count(gprs_llme_list()) == 0);
324 ctx = alloc_mm_ctx(local_tlli, &raid);
325
326 /* Attach s1 to ctx */
327 ctx->subscr = subscr_get(s1);
328 ctx->subscr->sgsn_data->mm = ctx;
329
330 /* Try to get auth tuple */
331 at = sgsn_auth_get_tuple(ctx, GSM_KEY_SEQ_INVAL);
332 OSMO_ASSERT(at == NULL);
333
334 /* Add triplets */
335 s1->sgsn_data->auth_triplets[0].key_seq = 0;
336 s1->sgsn_data->auth_triplets[1].key_seq = 1;
337 s1->sgsn_data->auth_triplets[2].key_seq = 2;
338
339 /* Try to get auth tuple */
340 at = sgsn_auth_get_tuple(ctx, GSM_KEY_SEQ_INVAL);
341 OSMO_ASSERT(at != NULL);
342 OSMO_ASSERT(at->key_seq == 0);
343 OSMO_ASSERT(at->use_count == 1);
344 at = sgsn_auth_get_tuple(ctx, at->key_seq);
345 OSMO_ASSERT(at != NULL);
346 OSMO_ASSERT(at->key_seq == 1);
347 OSMO_ASSERT(at->use_count == 1);
348 at = sgsn_auth_get_tuple(ctx, at->key_seq);
349 OSMO_ASSERT(at != NULL);
350 OSMO_ASSERT(at->key_seq == 2);
351 OSMO_ASSERT(at->use_count == 1);
352 at = sgsn_auth_get_tuple(ctx, at->key_seq);
353 OSMO_ASSERT(at == NULL);
354
355 /* Free MM context and subscriber */
356 subscr_put(s1);
357 llme = ctx->llme;
358 sgsn_mm_ctx_free(ctx);
359 s1found = gprs_subscr_get_by_imsi(imsi1);
360 OSMO_ASSERT(s1found == NULL);
361 gprs_llgmm_assign(llme, local_tlli, 0xffffffff, GPRS_ALGO_GEA0, NULL);
362}
363
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100364#define TEST_GSUP_IMSI1_IE 0x01, 0x05, 0x21, 0x43, 0x65, 0x87, 0x09
365
Jacob Erlbecke21e1842014-12-19 18:19:50 +0100366static int rx_gsup_message(const uint8_t *data, size_t data_len)
367{
368 struct msgb *msg;
369 int rc;
370
371 msg = msgb_alloc(1024, __func__);
372 msg->l2h = msgb_put(msg, data_len);
373 OSMO_ASSERT(msg->l2h != NULL);
374 memcpy(msg->l2h, data, data_len);
375 rc = gprs_subscr_rx_gsup_message(msg);
376 msgb_free(msg);
377
378 return rc;
379}
380
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100381static void test_subscriber_gsup(void)
382{
383 struct gsm_subscriber *s1, *s1found;
384 const char *imsi1 = "1234567890";
385 struct sgsn_mm_ctx *ctx;
386 struct gprs_ra_id raid = { 0, };
387 uint32_t local_tlli = 0xffeeddcc;
388 struct gprs_llc_llme *llme;
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100389 int rc;
390
391 static const uint8_t send_auth_info_res[] = {
392 0x0a,
393 TEST_GSUP_IMSI1_IE,
394 0x03, 0x22, /* Auth tuple */
395 0x20, 0x10,
396 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
397 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
398 0x21, 0x04,
399 0x21, 0x22, 0x23, 0x24,
400 0x22, 0x08,
401 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
402 0x03, 0x22, /* Auth tuple */
403 0x20, 0x10,
404 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
405 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90,
406 0x21, 0x04,
407 0xa1, 0xa2, 0xa3, 0xa4,
408 0x22, 0x08,
409 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8,
410 };
411
412 static const uint8_t send_auth_info_err[] = {
413 0x09,
414 TEST_GSUP_IMSI1_IE,
415 0x02, 0x01, 0x07 /* GPRS not allowed */
416 };
417
418 static const uint8_t update_location_res[] = {
419 0x06,
420 TEST_GSUP_IMSI1_IE,
421 0x04, 0x00, /* PDP info complete */
422 0x05, 0x12,
423 0x10, 0x01, 0x01,
424 0x11, 0x02, 0xf1, 0x21, /* IPv4 */
425 0x12, 0x09, 0x04, 't', 'e', 's', 't', 0x03, 'a', 'p', 'n',
426 0x05, 0x11,
427 0x10, 0x01, 0x02,
428 0x11, 0x02, 0xf1, 0x21, /* IPv4 */
429 0x12, 0x08, 0x03, 'f', 'o', 'o', 0x03, 'a', 'p', 'n',
430 };
431
432 static const uint8_t update_location_err[] = {
433 0x05,
434 TEST_GSUP_IMSI1_IE,
435 0x02, 0x01, 0x07 /* GPRS not allowed */
436 };
437
438 static const uint8_t location_cancellation_req[] = {
439 0x1c,
440 TEST_GSUP_IMSI1_IE,
441 0x06, 0x01, 0x00,
442 };
443
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100444 static const uint8_t location_cancellation_req_other[] = {
445 0x1c,
446 0x01, 0x05, 0x11, 0x11, 0x11, 0x11, 0x01,
447 0x06, 0x01, 0x00,
448 };
449
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100450 static const uint8_t insert_data_req[] = {
451 0x10,
452 TEST_GSUP_IMSI1_IE,
453 0x05, 0x11,
454 0x10, 0x01, 0x03,
455 0x11, 0x02, 0xf1, 0x21, /* IPv4 */
456 0x12, 0x08, 0x03, 'b', 'a', 'r', 0x03, 'a', 'p', 'n',
457 };
458
459 static const uint8_t delete_data_req[] = {
460 0x14,
461 TEST_GSUP_IMSI1_IE,
462 0x10, 0x01, 0x03,
463 };
464
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100465 printf("Testing subcriber GSUP handling\n");
466
467 update_subscriber_data_cb = my_dummy_sgsn_update_subscriber_data;
468
469 /* Check for emptiness */
470 OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL);
471
472 /* Allocate entry 1 */
473 s1 = gprs_subscr_get_or_create(imsi1);
474 s1->flags |= GSM_SUBSCRIBER_FIRST_CONTACT;
475 s1found = gprs_subscr_get_by_imsi(imsi1);
476 OSMO_ASSERT(s1found == s1);
477 subscr_put(s1found);
478
479 /* Create a context */
480 OSMO_ASSERT(count(gprs_llme_list()) == 0);
481 ctx = alloc_mm_ctx(local_tlli, &raid);
482 llme = ctx->llme;
483
484 /* Attach s1 to ctx */
485 ctx->subscr = subscr_get(s1);
486 ctx->subscr->sgsn_data->mm = ctx;
487
488 /* Inject SendAuthInfoReq GSUP message */
Jacob Erlbecke21e1842014-12-19 18:19:50 +0100489 rc = rx_gsup_message(send_auth_info_res, sizeof(send_auth_info_res));
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100490 OSMO_ASSERT(rc >= 0);
491 OSMO_ASSERT(last_updated_subscr == s1);
492
493 /* Check triplets */
494 OSMO_ASSERT(s1->sgsn_data->auth_triplets[0].key_seq == 0);
495 OSMO_ASSERT(s1->sgsn_data->auth_triplets[1].key_seq == 1);
496 OSMO_ASSERT(s1->sgsn_data->auth_triplets[2].key_seq == GSM_KEY_SEQ_INVAL);
497
498 /* Inject SendAuthInfoErr GSUP message */
Jacob Erlbecke21e1842014-12-19 18:19:50 +0100499 rc = rx_gsup_message(send_auth_info_err, sizeof(send_auth_info_err));
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100500 OSMO_ASSERT(rc == -GMM_CAUSE_GPRS_NOTALLOWED);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100501 OSMO_ASSERT(last_updated_subscr == s1);
502
503 /* Check triplets */
504 OSMO_ASSERT(s1->sgsn_data->auth_triplets[0].key_seq == GSM_KEY_SEQ_INVAL);
505 OSMO_ASSERT(s1->sgsn_data->auth_triplets[1].key_seq == GSM_KEY_SEQ_INVAL);
506 OSMO_ASSERT(s1->sgsn_data->auth_triplets[2].key_seq == GSM_KEY_SEQ_INVAL);
507
508 /* Inject UpdateLocReq GSUP message */
Jacob Erlbecke21e1842014-12-19 18:19:50 +0100509 rc = rx_gsup_message(update_location_res, sizeof(update_location_res));
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100510 OSMO_ASSERT(rc >= 0);
511 OSMO_ASSERT(last_updated_subscr == s1);
512
513 /* Check authorization */
514 OSMO_ASSERT(s1->authorized == 1);
515
516 /* Inject UpdateLocErr GSUP message */
Jacob Erlbecke21e1842014-12-19 18:19:50 +0100517 rc = rx_gsup_message(update_location_err, sizeof(update_location_err));
Jacob Erlbeckbce20612015-01-05 18:57:32 +0100518 OSMO_ASSERT(rc == -GMM_CAUSE_GPRS_NOTALLOWED);
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100519 OSMO_ASSERT(last_updated_subscr == s1);
520
521 /* Check authorization */
522 OSMO_ASSERT(s1->authorized == 0);
523
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100524 /* Inject InsertSubscrData GSUP message */
525 last_updated_subscr = NULL;
526 rc = rx_gsup_message(insert_data_req, sizeof(insert_data_req));
527 OSMO_ASSERT(rc == -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL);
528 OSMO_ASSERT(last_updated_subscr == NULL);
529
530 /* Inject DeleteSubscrData GSUP message */
531 last_updated_subscr = NULL;
532 rc = rx_gsup_message(delete_data_req, sizeof(delete_data_req));
533 OSMO_ASSERT(rc == -GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL);
534 OSMO_ASSERT(last_updated_subscr == NULL);
535
Jacob Erlbeck87c7ffc2015-01-08 15:29:01 +0100536 /* Inject wrong LocCancelReq GSUP message */
537 last_updated_subscr = NULL;
538 rc = rx_gsup_message(location_cancellation_req_other,
539 sizeof(location_cancellation_req_other));
540 OSMO_ASSERT(rc == -GMM_CAUSE_IMSI_UNKNOWN);
541 OSMO_ASSERT(last_updated_subscr == NULL);
542
543 /* Check cancellation result */
544 OSMO_ASSERT(!(s1->flags & GPRS_SUBSCRIBER_CANCELLED));
545 OSMO_ASSERT(s1->sgsn_data->mm != NULL);
546
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100547 /* Inject LocCancelReq GSUP message */
Jacob Erlbecke21e1842014-12-19 18:19:50 +0100548 rc = rx_gsup_message(location_cancellation_req,
549 sizeof(location_cancellation_req));
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100550 OSMO_ASSERT(rc >= 0);
551 OSMO_ASSERT(last_updated_subscr == s1);
552
553 /* Check cancellation result */
554 OSMO_ASSERT(s1->flags & GPRS_SUBSCRIBER_CANCELLED);
555 OSMO_ASSERT(s1->sgsn_data->mm == NULL);
556
557 /* Free MM context and subscriber */
558 subscr_put(s1);
559 s1found = gprs_subscr_get_by_imsi(imsi1);
560 OSMO_ASSERT(s1found == NULL);
561 gprs_llgmm_assign(llme, local_tlli, 0xffffffff, GPRS_ALGO_GEA0, NULL);
562
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100563 /* Inject InsertSubscrData GSUP message (unknown IMSI) */
564 last_updated_subscr = NULL;
565 rc = rx_gsup_message(insert_data_req, sizeof(insert_data_req));
Jacob Erlbeck4dedb272015-01-15 17:50:16 +0100566 OSMO_ASSERT(rc == -GMM_CAUSE_IMSI_UNKNOWN);
Jacob Erlbeck9999fd92015-01-15 17:08:30 +0100567 OSMO_ASSERT(last_updated_subscr == NULL);
568
569 /* Inject DeleteSubscrData GSUP message (unknown IMSI) */
570 rc = rx_gsup_message(delete_data_req, sizeof(delete_data_req));
571 OSMO_ASSERT(rc == -GMM_CAUSE_IMSI_UNKNOWN);
572 OSMO_ASSERT(last_updated_subscr == NULL);
573
574 /* Inject LocCancelReq GSUP message (unknown IMSI) */
575 rc = rx_gsup_message(location_cancellation_req,
576 sizeof(location_cancellation_req));
577 OSMO_ASSERT(rc == -GMM_CAUSE_IMSI_UNKNOWN);
578 OSMO_ASSERT(last_updated_subscr == NULL);
579
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +0100580 update_subscriber_data_cb = __real_sgsn_update_subscriber_data;
581}
582
Jacob Erlbeckf81cacc2015-01-08 16:23:25 +0100583int my_gprs_gsup_client_send_dummy(struct gprs_gsup_client *gsupc, struct msgb *msg)
584{
585 msgb_free(msg);
586 return 0;
587};
588
589
590static void test_subscriber_blocking(void)
591{
592 struct gsm_subscriber *s1;
593 const char *imsi1 = "1234567890";
594 struct sgsn_mm_ctx *ctx;
595 struct gprs_ra_id raid = { 0, };
596 uint32_t local_tlli = 0xffeeddcc;
597 struct gprs_llc_llme *llme;
598 int rc;
599
600 printf("Testing subcriber procedure blocking\n");
601
602 gprs_gsup_client_send_cb = my_gprs_gsup_client_send_dummy;
603 sgsn->gsup_client = talloc_zero(tall_bsc_ctx, struct gprs_gsup_client);
604
605 /* Check for emptiness */
606 OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL);
607
608 /* Create a context */
609 OSMO_ASSERT(count(gprs_llme_list()) == 0);
610 ctx = alloc_mm_ctx(local_tlli, &raid);
611 llme = ctx->llme;
612 strncpy(ctx->imsi, imsi1, sizeof(ctx->imsi) - 1);
613
614 /* Allocate and attach a subscriber */
615 s1 = gprs_subscr_get_or_create_by_mmctx(ctx);
616 assert_subscr(s1, imsi1);
617
618 /* Start SendAuthInfoRequest procedure */
619 rc = gprs_subscr_query_auth_info(s1);
620 /* Not blocking */
621 OSMO_ASSERT(rc == 0);
622
623 /* Start UpdateLocation procedure */
624 rc = gprs_subscr_location_update(s1);
625 /* Blocking */
626 OSMO_ASSERT(rc == 0);
627
628 /* Start PurgeMS procedure */
629 rc = gprs_subscr_purge(s1);
630 /* Not blocking */
631 OSMO_ASSERT(rc == 0);
632 OSMO_ASSERT(s1->sgsn_data->blocked_by == SGSN_SUBSCR_PROC_PURGE);
633
634 /* Start PurgeMS procedure (retry) */
635 rc = gprs_subscr_purge(s1);
636 /* Not blocking */
637 OSMO_ASSERT(rc == 0);
638
639 /* Start SendAuthInfoRequest procedure */
640 rc = gprs_subscr_query_auth_info(s1);
641 /* Blocking */
642 OSMO_ASSERT(rc == -EAGAIN);
643
644 /* Start UpdateLocation procedure */
645 rc = gprs_subscr_location_update(s1);
646 /* Blocking */
647 OSMO_ASSERT(rc == -EAGAIN);
648
649 /* Unblock manually (normally done by the caller of gprs_subscr_purge) */
650 s1->sgsn_data->blocked_by = SGSN_SUBSCR_PROC_NONE;
651
652 /* Start SendAuthInfoRequest procedure */
653 rc = gprs_subscr_query_auth_info(s1);
654 /* Not blocking */
655 OSMO_ASSERT(rc == 0);
656
657 /* Start UpdateLocation procedure */
658 rc = gprs_subscr_location_update(s1);
659 /* Blocking */
660 OSMO_ASSERT(rc == 0);
661
662 subscr_put(s1);
663 sgsn_mm_ctx_free(ctx);
664 gprs_llgmm_assign(llme, local_tlli, 0xffffffff, GPRS_ALGO_GEA0, NULL);
665
666 assert_no_subscrs();
667
668 gprs_gsup_client_send_cb = __real_gprs_gsup_client_send;
669 talloc_free(sgsn->gsup_client);
670 sgsn->gsup_client = NULL;
671}
672
673
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +0200674/*
675 * Test that a GMM Detach will remove the MMCTX and the
676 * associated LLME.
677 */
678static void test_gmm_detach(void)
679{
680 struct gprs_ra_id raid = { 0, };
681 struct sgsn_mm_ctx *ctx, *ictx;
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +0200682 uint32_t local_tlli;
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +0200683
684 printf("Testing GMM detach\n");
685
686 /* DTAP - Detach Request (MO) */
687 /* normal detach, power_off = 0 */
688 static const unsigned char detach_req[] = {
689 0x08, 0x05, 0x01, 0x18, 0x05, 0xf4, 0xef, 0xe2,
690 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb
691 };
692
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +0200693 local_tlli = gprs_tmsi2tlli(0x23, TLLI_LOCAL);
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +0200694
Jacob Erlbeckabc16a52014-10-27 13:23:49 +0100695 /* Create a context */
696 OSMO_ASSERT(count(gprs_llme_list()) == 0);
697 ctx = alloc_mm_ctx(local_tlli, &raid);
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +0200698
699 /* inject the detach */
Jacob Erlbeck94ef1c02014-10-29 10:31:18 +0100700 send_0408_message(ctx->llme, local_tlli,
701 detach_req, ARRAY_SIZE(detach_req));
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +0200702
Jacob Erlbeck189999d2014-10-27 14:34:13 +0100703 /* verify that a single message (hopefully the Detach Accept) has been
704 * sent by the SGSN */
Jacob Erlbeck94ef1c02014-10-29 10:31:18 +0100705 OSMO_ASSERT(sgsn_tx_counter == 1);
Jacob Erlbeck189999d2014-10-27 14:34:13 +0100706
707 /* verify that things are gone */
708 OSMO_ASSERT(count(gprs_llme_list()) == 0);
709 ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid);
710 OSMO_ASSERT(!ictx);
711}
712
713/*
714 * Test that a GMM Detach will remove the MMCTX and the associated LLME but
715 * will not sent a Detach Accept message (power_off = 1)
716 */
717static void test_gmm_detach_power_off(void)
718{
719 struct gprs_ra_id raid = { 0, };
720 struct sgsn_mm_ctx *ctx, *ictx;
721 uint32_t local_tlli;
Jacob Erlbeck189999d2014-10-27 14:34:13 +0100722
723 printf("Testing GMM detach (power off)\n");
724
725 /* DTAP - Detach Request (MO) */
726 /* normal detach, power_off = 1 */
727 static const unsigned char detach_req[] = {
728 0x08, 0x05, 0x09, 0x18, 0x05, 0xf4, 0xef, 0xe2,
729 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb
730 };
731
732 local_tlli = gprs_tmsi2tlli(0x23, TLLI_LOCAL);
733
734 /* Create a context */
735 OSMO_ASSERT(count(gprs_llme_list()) == 0);
736 ctx = alloc_mm_ctx(local_tlli, &raid);
737
738 /* inject the detach */
Jacob Erlbeck94ef1c02014-10-29 10:31:18 +0100739 send_0408_message(ctx->llme, local_tlli,
740 detach_req, ARRAY_SIZE(detach_req));
Jacob Erlbeck189999d2014-10-27 14:34:13 +0100741
742 /* verify that no message (and therefore no Detach Accept) has been
743 * sent by the SGSN */
Jacob Erlbeck94ef1c02014-10-29 10:31:18 +0100744 OSMO_ASSERT(sgsn_tx_counter == 0);
Jacob Erlbeck189999d2014-10-27 14:34:13 +0100745
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +0200746 /* verify that things are gone */
747 OSMO_ASSERT(count(gprs_llme_list()) == 0);
748 ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid);
Jacob Erlbeck258ce3d2014-09-30 13:51:45 +0200749 OSMO_ASSERT(!ictx);
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +0200750}
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +0200751
Jacob Erlbeck5a38f642014-10-21 13:09:55 +0200752/*
753 * Test that a GMM Detach will remove the associated LLME if there is no MMCTX.
754 */
755static void test_gmm_detach_no_mmctx(void)
756{
757 struct gprs_llc_lle *lle;
758 uint32_t local_tlli;
Jacob Erlbeck5a38f642014-10-21 13:09:55 +0200759
760 printf("Testing GMM detach (no MMCTX)\n");
761
762 /* DTAP - Detach Request (MO) */
763 /* normal detach, power_off = 0 */
764 static const unsigned char detach_req[] = {
765 0x08, 0x05, 0x01, 0x18, 0x05, 0xf4, 0xef, 0xe2,
766 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb
767 };
768
769 /* Create an LLME */
770 OSMO_ASSERT(count(gprs_llme_list()) == 0);
771 local_tlli = gprs_tmsi2tlli(0x23, TLLI_LOCAL);
772 lle = gprs_lle_get_or_create(local_tlli, 3);
773
774 OSMO_ASSERT(count(gprs_llme_list()) == 1);
775
776 /* inject the detach */
Jacob Erlbeck94ef1c02014-10-29 10:31:18 +0100777 send_0408_message(lle->llme, local_tlli,
778 detach_req, ARRAY_SIZE(detach_req));
Jacob Erlbeck5a38f642014-10-21 13:09:55 +0200779
780 /* verify that the LLME is gone */
781 OSMO_ASSERT(count(gprs_llme_list()) == 0);
782}
783
Jacob Erlbeck14ae5822014-10-28 09:47:03 +0100784/*
Jacob Erlbeckde4bbc72014-11-24 15:04:15 +0100785 * Test that a single GMM Detach Accept message will not cause the SGSN to send
786 * any message or leave an MM context at the SGSN.
787 */
788static void test_gmm_detach_accept_unexpected(void)
789{
790 struct gprs_llc_lle *lle;
791 uint32_t local_tlli;
792
793 printf("Testing GMM detach accept (unexpected)\n");
794
795 /* DTAP - Detach Accept (MT) */
796 /* normal detach */
797 static const unsigned char detach_acc[] = {
798 0x08, 0x06
799 };
800
801 /* Create an LLME */
802 OSMO_ASSERT(count(gprs_llme_list()) == 0);
803 local_tlli = gprs_tmsi2tlli(0x23, TLLI_LOCAL);
804 lle = gprs_lle_get_or_create(local_tlli, 3);
805
806 /* inject the detach */
807 send_0408_message(lle->llme, local_tlli,
808 detach_acc, ARRAY_SIZE(detach_acc));
809
810 /* verify that no message (and therefore no Status or XID reset) has been
811 * sent by the SGSN */
812 OSMO_ASSERT(sgsn_tx_counter == 0);
813
814 /* verify that things are gone */
815 OSMO_ASSERT(count(gprs_llme_list()) == 0);
816}
817
818/*
Jacob Erlbeck14ae5822014-10-28 09:47:03 +0100819 * Test that a GMM Status will remove the associated LLME if there is no MMCTX.
820 */
821static void test_gmm_status_no_mmctx(void)
822{
823 struct gprs_llc_lle *lle;
824 uint32_t local_tlli;
Jacob Erlbeck14ae5822014-10-28 09:47:03 +0100825
826 printf("Testing GMM Status (no MMCTX)\n");
827
828 /* DTAP - GMM Status, protocol error */
829 static const unsigned char gmm_status[] = {
830 0x08, 0x20, 0x6f
831 };
832
833 /* Create an LLME */
834 OSMO_ASSERT(count(gprs_llme_list()) == 0);
835 local_tlli = gprs_tmsi2tlli(0x23, TLLI_LOCAL);
836 lle = gprs_lle_get_or_create(local_tlli, 3);
837
838 OSMO_ASSERT(count(gprs_llme_list()) == 1);
839
840 /* inject the detach */
Jacob Erlbeck94ef1c02014-10-29 10:31:18 +0100841 send_0408_message(lle->llme, local_tlli,
842 gmm_status, ARRAY_SIZE(gmm_status));
Jacob Erlbeck14ae5822014-10-28 09:47:03 +0100843
844 /* verify that no message has been sent by the SGSN */
Jacob Erlbeck94ef1c02014-10-29 10:31:18 +0100845 OSMO_ASSERT(sgsn_tx_counter == 0);
Jacob Erlbeck14ae5822014-10-28 09:47:03 +0100846
847 /* verify that the LLME is gone */
848 OSMO_ASSERT(count(gprs_llme_list()) == 0);
849}
850
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +0100851/*
852 * Test the GMM Attach procedure
853 */
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +0100854static void test_gmm_attach(int retry)
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +0100855{
856 struct gprs_ra_id raid = { 0, };
857 struct sgsn_mm_ctx *ctx = NULL;
858 struct sgsn_mm_ctx *ictx;
Jacob Erlbeckaec03a12014-11-24 14:40:28 +0100859 uint32_t ptmsi1;
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +0100860 uint32_t foreign_tlli;
861 uint32_t local_tlli = 0;
862 struct gprs_llc_lle *lle;
863
864 /* DTAP - Attach Request */
865 /* The P-TMSI is not known by the SGSN */
866 static const unsigned char attach_req[] = {
867 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, 0x05, 0xf4,
868 0xfb, 0xc5, 0x46, 0x79, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60,
869 0x19, 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00, 0x60,
870 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60, 0x80, 0xba, 0xc8,
871 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00
872 };
873
874 /* DTAP - Identity Response IMEI */
875 static const unsigned char ident_resp_imei[] = {
876 0x08, 0x16, 0x08, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78,
877 0x56
878 };
879
880 /* DTAP - Identity Response IMSI */
881 static const unsigned char ident_resp_imsi[] = {
882 0x08, 0x16, 0x08, 0x19, 0x32, 0x54, 0x76, 0x98, 0x10, 0x32,
883 0x54
884 };
885
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100886 /* DTAP - Authentication and Ciphering Resp */
887 static const unsigned char auth_ciph_resp[] = {
888 0x08, 0x13, 0x00, 0x22, 0x51, 0xe5, 0x51, 0xe5, 0x23, 0x09,
889 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x01
890 };
891
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +0100892 /* DTAP - Attach Complete */
893 static const unsigned char attach_compl[] = {
894 0x08, 0x03
895 };
896
897 /* DTAP - Detach Request (MO) */
898 /* normal detach, power_off = 0 */
899 static const unsigned char detach_req[] = {
900 0x08, 0x05, 0x01, 0x18, 0x05, 0xf4, 0xeb, 0x8b,
901 0x45, 0x67, 0x19, 0x03, 0xb9, 0x97, 0xcb
902 };
903
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +0100904 printf("Testing GMM attach%s\n", retry ? " with retry" : "");
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +0100905
906 /* reset the PRNG used by sgsn_alloc_ptmsi */
907 srand(1);
908
Jacob Erlbeckaec03a12014-11-24 14:40:28 +0100909 ptmsi1 = sgsn_alloc_ptmsi();
910 OSMO_ASSERT(ptmsi1 != GSM_RESERVED_TMSI);
911
912 /* reset the PRNG, so that the same P-TMSI sequence will be generated
913 * again */
914 srand(1);
915
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +0100916 foreign_tlli = gprs_tmsi2tlli(0xc0000023, TLLI_FOREIGN);
917
918 /* Create a LLE/LLME */
919 OSMO_ASSERT(count(gprs_llme_list()) == 0);
920 lle = gprs_lle_get_or_create(foreign_tlli, 3);
921 OSMO_ASSERT(count(gprs_llme_list()) == 1);
922
923 /* inject the attach request */
924 send_0408_message(lle->llme, foreign_tlli,
925 attach_req, ARRAY_SIZE(attach_req));
926
927 ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid);
928 OSMO_ASSERT(ctx != NULL);
929 OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT);
930
931 /* we expect an identity request (IMEI) */
932 OSMO_ASSERT(sgsn_tx_counter == 1);
933
934 /* inject the identity response (IMEI) */
935 send_0408_message(ctx->llme, foreign_tlli,
936 ident_resp_imei, ARRAY_SIZE(ident_resp_imei));
937
938 /* we expect an identity request (IMSI) */
939 OSMO_ASSERT(sgsn_tx_counter == 1);
940
941 /* inject the identity response (IMSI) */
942 send_0408_message(ctx->llme, foreign_tlli,
943 ident_resp_imsi, ARRAY_SIZE(ident_resp_imsi));
944
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +0100945 /* check that the MM context has not been removed due to a failed
946 * authorization */
947 OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid));
948
Jacob Erlbeck0074a772014-10-28 16:23:46 +0100949 OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT);
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +0100950
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +0100951retry_attach_req:
952
953 if (retry && sgsn_tx_counter == 0) {
954 fprintf(stderr, "Retrying attach request\n");
955 /* re-inject the attach request */
956 send_0408_message(lle->llme, foreign_tlli,
957 attach_req, ARRAY_SIZE(attach_req));
958 }
959
960 if (ctx->auth_state == SGSN_AUTH_AUTHENTICATE && sgsn_tx_counter == 1) {
961 /* we got an auth & ciph request */
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100962
963 /* inject the auth & ciph response */
964 send_0408_message(ctx->llme, foreign_tlli,
965 auth_ciph_resp, ARRAY_SIZE(auth_ciph_resp));
966
967 /* check that the MM context has not been removed due to a
968 * failed authorization */
969 OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid));
970 }
971
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +0100972 if (retry && sgsn_tx_counter == 0)
973 goto retry_attach_req;
974
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +0100975 /* we expect an attach accept/reject */
976 OSMO_ASSERT(sgsn_tx_counter == 1);
977
978 /* this has been randomly assigned by the SGSN */
Jacob Erlbeckaec03a12014-11-24 14:40:28 +0100979 local_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL);
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +0100980
981 /* inject the attach complete */
982 send_0408_message(ctx->llme, local_tlli,
983 attach_compl, ARRAY_SIZE(attach_compl));
984
985 OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL);
986
987 /* we don't expect a response */
988 OSMO_ASSERT(sgsn_tx_counter == 0);
989
990 /* inject the detach */
991 send_0408_message(ctx->llme, local_tlli,
992 detach_req, ARRAY_SIZE(detach_req));
993
994 /* verify that things are gone */
995 OSMO_ASSERT(count(gprs_llme_list()) == 0);
996 ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid);
997 OSMO_ASSERT(!ictx);
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +0100998}
Jacob Erlbeck0c06f982014-10-29 22:12:20 +0100999
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001000static void test_gmm_attach_acl(void)
1001{
1002 const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
1003
1004 sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_CLOSED;
1005 sgsn_acl_add("123456789012345", &sgsn->cfg);
1006 printf("Auth policy 'closed': ");
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001007 test_gmm_attach(0);
Jacob Erlbeck0c06f982014-10-29 22:12:20 +01001008 sgsn_acl_del("123456789012345", &sgsn->cfg);
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001009
1010 sgsn->cfg.auth_policy = saved_auth_policy;
1011}
1012
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001013int my_subscr_request_update_location(struct sgsn_mm_ctx *mmctx) {
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001014 int rc;
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001015 rc = __real_gprs_subscr_request_update_location(mmctx);
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001016 if (rc == -ENOTSUP) {
1017 OSMO_ASSERT(mmctx->subscr);
1018 gprs_subscr_update(mmctx->subscr);
1019 }
1020 return rc;
1021};
1022
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001023int my_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx) {
1024 gprs_subscr_update(mmctx->subscr);
1025 return 0;
1026};
1027
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001028static void test_gmm_attach_subscr(void)
1029{
1030 const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
1031 struct gsm_subscriber *subscr;
1032
1033 sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE;
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001034 subscr_request_update_location_cb = my_subscr_request_update_location;
1035 subscr_request_auth_info_cb = my_subscr_request_auth_info;
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001036
1037 subscr = gprs_subscr_get_or_create("123456789012345");
1038 subscr->authorized = 1;
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001039
1040 printf("Auth policy 'remote': ");
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001041 test_gmm_attach(0);
Holger Hans Peter Freyther1d778fd2015-01-20 21:14:03 +01001042 subscr_put(subscr);
Jacob Erlbeck058bc262015-01-13 11:46:32 +01001043 assert_no_subscrs();
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001044
1045 sgsn->cfg.auth_policy = saved_auth_policy;
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001046 subscr_request_update_location_cb = __real_gprs_subscr_request_update_location;
1047 subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info;
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +01001048}
1049
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001050int my_subscr_request_auth_info_fake_auth(struct sgsn_mm_ctx *mmctx)
1051{
1052 /* Fake an authentication */
1053 OSMO_ASSERT(mmctx->subscr);
1054 mmctx->is_authenticated = 1;
1055 gprs_subscr_update_auth_info(mmctx->subscr);
Jacob Erlbeck2e5e94c2014-12-08 15:26:47 +01001056
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001057 return 0;
Jacob Erlbeck2e5e94c2014-12-08 15:26:47 +01001058};
1059
1060static void test_gmm_attach_subscr_fake_auth(void)
1061{
1062 const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
1063 struct gsm_subscriber *subscr;
1064
1065 sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE;
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001066 subscr_request_update_location_cb = my_subscr_request_update_location;
1067 subscr_request_auth_info_cb = my_subscr_request_auth_info_fake_auth;
Jacob Erlbeck2e5e94c2014-12-08 15:26:47 +01001068
1069 subscr = gprs_subscr_get_or_create("123456789012345");
1070 subscr->authorized = 1;
Jacob Erlbeck9d4f46c2014-12-17 13:20:08 +01001071 sgsn->cfg.require_authentication = 1;
Jacob Erlbeck771573c2014-12-19 18:08:48 +01001072 sgsn->cfg.require_update_location = 1;
Jacob Erlbeck2e5e94c2014-12-08 15:26:47 +01001073
1074 printf("Auth policy 'remote', auth faked: ");
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001075 test_gmm_attach(0);
Holger Hans Peter Freyther1d778fd2015-01-20 21:14:03 +01001076 subscr_put(subscr);
Jacob Erlbeck058bc262015-01-13 11:46:32 +01001077 assert_no_subscrs();
Jacob Erlbeck2e5e94c2014-12-08 15:26:47 +01001078
1079 sgsn->cfg.auth_policy = saved_auth_policy;
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001080 subscr_request_update_location_cb = __real_gprs_subscr_request_update_location;
1081 subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info;
1082}
1083
1084int my_subscr_request_auth_info_real_auth(struct sgsn_mm_ctx *mmctx)
1085{
1086 struct gsm_auth_tuple at = {
1087 .sres = {0x51, 0xe5, 0x51, 0xe5},
1088 .key_seq = 0
1089 };
1090
1091 /* Fake an authentication */
1092 OSMO_ASSERT(mmctx->subscr);
1093 mmctx->subscr->sgsn_data->auth_triplets[0] = at;
1094
1095 gprs_subscr_update_auth_info(mmctx->subscr);
1096
1097 return 0;
1098};
1099
1100static void test_gmm_attach_subscr_real_auth(void)
1101{
1102 const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
1103 struct gsm_subscriber *subscr;
1104
1105 sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE;
1106 subscr_request_update_location_cb = my_subscr_request_update_location;
1107 subscr_request_auth_info_cb = my_subscr_request_auth_info_real_auth;
1108
1109 subscr = gprs_subscr_get_or_create("123456789012345");
1110 subscr->authorized = 1;
Jacob Erlbeck9d4f46c2014-12-17 13:20:08 +01001111 sgsn->cfg.require_authentication = 1;
Jacob Erlbeck771573c2014-12-19 18:08:48 +01001112 sgsn->cfg.require_update_location = 1;
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001113
1114 printf("Auth policy 'remote', triplet based auth: ");
Jacob Erlbeck058bc262015-01-13 11:46:32 +01001115
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001116 test_gmm_attach(0);
Holger Hans Peter Freyther1d778fd2015-01-20 21:14:03 +01001117 subscr_put(subscr);
Jacob Erlbeck058bc262015-01-13 11:46:32 +01001118 assert_no_subscrs();
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001119
1120 sgsn->cfg.auth_policy = saved_auth_policy;
1121 subscr_request_update_location_cb = __real_gprs_subscr_request_update_location;
1122 subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info;
Jacob Erlbeck2e5e94c2014-12-08 15:26:47 +01001123}
1124
Jacob Erlbeck3d722452014-12-19 18:26:09 +01001125#define TEST_GSUP_IMSI_LONG_IE 0x01, 0x08, \
1126 0x21, 0x43, 0x65, 0x87, 0x09, 0x21, 0x43, 0xf5
1127
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001128static int auth_info_skip = 0;
1129static int upd_loc_skip = 0;
1130
Jacob Erlbeck3d722452014-12-19 18:26:09 +01001131int my_subscr_request_auth_info_gsup_auth(struct sgsn_mm_ctx *mmctx)
1132{
1133 static const uint8_t send_auth_info_res[] = {
1134 0x0a,
1135 TEST_GSUP_IMSI_LONG_IE,
1136 0x03, 0x22, /* Auth tuple */
1137 0x20, 0x10,
1138 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
1139 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
1140 0x21, 0x04,
1141 0x51, 0xe5, 0x51, 0xe5,
1142 0x22, 0x08,
1143 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
1144 };
1145
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001146 OSMO_ASSERT(!mmctx || mmctx->subscr);
Jacob Erlbeck3d722452014-12-19 18:26:09 +01001147
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001148 if (auth_info_skip > 0) {
1149 auth_info_skip -= 1;
1150 return -EAGAIN;
1151 }
1152
Jacob Erlbeck3d722452014-12-19 18:26:09 +01001153 /* Fake an SendAuthInfoRes */
1154 rx_gsup_message(send_auth_info_res, sizeof(send_auth_info_res));
1155
1156 return 0;
1157};
1158
1159int my_subscr_request_update_gsup_auth(struct sgsn_mm_ctx *mmctx) {
1160 static const uint8_t update_location_res[] = {
1161 0x06,
1162 TEST_GSUP_IMSI_LONG_IE,
1163 0x04, 0x00, /* PDP info complete */
1164 0x05, 0x12,
1165 0x10, 0x01, 0x01,
1166 0x11, 0x02, 0xf1, 0x21, /* IPv4 */
1167 0x12, 0x09, 0x04, 't', 'e', 's', 't', 0x03, 'a', 'p', 'n',
1168 };
1169
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001170 OSMO_ASSERT(!mmctx || mmctx->subscr);
Jacob Erlbeck3d722452014-12-19 18:26:09 +01001171
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001172 if (upd_loc_skip > 0) {
1173 upd_loc_skip -= 1;
1174 return -EAGAIN;
1175 }
1176
Jacob Erlbeck3d722452014-12-19 18:26:09 +01001177 /* Fake an UpdateLocRes */
1178 return rx_gsup_message(update_location_res, sizeof(update_location_res));
1179};
1180
1181
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001182static void test_gmm_attach_subscr_gsup_auth(int retry)
Jacob Erlbeck3d722452014-12-19 18:26:09 +01001183{
1184 const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
1185 struct gsm_subscriber *subscr;
1186
1187 sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE;
1188 subscr_request_update_location_cb = my_subscr_request_update_gsup_auth;
1189 subscr_request_auth_info_cb = my_subscr_request_auth_info_gsup_auth;
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001190 if (retry) {
1191 upd_loc_skip = 3;
1192 auth_info_skip = 3;
1193 }
Jacob Erlbeck3d722452014-12-19 18:26:09 +01001194
1195 subscr = gprs_subscr_get_or_create("123456789012345");
1196 subscr->authorized = 1;
1197 sgsn->cfg.require_authentication = 1;
1198 sgsn->cfg.require_update_location = 1;
1199 subscr_put(subscr);
1200
1201 printf("Auth policy 'remote', GSUP based auth: ");
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001202 test_gmm_attach(retry);
Jacob Erlbeck058bc262015-01-13 11:46:32 +01001203 assert_no_subscrs();
Jacob Erlbeck3d722452014-12-19 18:26:09 +01001204
1205 sgsn->cfg.auth_policy = saved_auth_policy;
1206 subscr_request_update_location_cb = __real_gprs_subscr_request_update_location;
1207 subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info;
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001208 upd_loc_skip = 0;
1209 auth_info_skip = 0;
Jacob Erlbeck3d722452014-12-19 18:26:09 +01001210}
1211
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001212int my_gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg)
1213{
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +01001214 struct gprs_gsup_message to_peer = {0};
1215 struct gprs_gsup_message from_peer = {0};
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001216 struct msgb *reply_msg;
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +01001217 int rc;
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001218
1219 /* Simulate the GSUP peer */
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +01001220 rc = gprs_gsup_decode(msgb_data(msg), msgb_length(msg), &to_peer);
1221 OSMO_ASSERT(rc >= 0);
1222 OSMO_ASSERT(to_peer.imsi[0] != 0);
1223 strncpy(from_peer.imsi, to_peer.imsi, sizeof(from_peer.imsi));
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001224
1225 /* This invalidates the pointers in to_peer */
1226 msgb_free(msg);
1227
1228 switch (to_peer.message_type) {
1229 case GPRS_GSUP_MSGT_UPDATE_LOCATION_REQUEST:
1230 /* Send UPDATE_LOCATION_RESULT */
1231 return my_subscr_request_update_gsup_auth(NULL);
1232
1233 case GPRS_GSUP_MSGT_SEND_AUTH_INFO_REQUEST:
1234 /* Send SEND_AUTH_INFO_RESULT */
1235 return my_subscr_request_auth_info_gsup_auth(NULL);
1236
1237 case GPRS_GSUP_MSGT_PURGE_MS_REQUEST:
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +01001238 from_peer.message_type = GPRS_GSUP_MSGT_PURGE_MS_RESULT;
1239 break;
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001240
1241 default:
1242 if ((to_peer.message_type & 0b00000011) == 0) {
1243 /* Unhandled request */
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +01001244 /* Send error(NOT_IMPL) */
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001245 from_peer.message_type = to_peer.message_type + 1;
1246 from_peer.cause = GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL;
1247 break;
1248 }
1249
1250 /* Ignore it */
1251 return 0;
1252 }
1253
1254 reply_msg = gprs_gsup_msgb_alloc();
1255 reply_msg->l2h = reply_msg->data;
1256 gprs_gsup_encode(reply_msg, &from_peer);
1257 gprs_subscr_rx_gsup_message(reply_msg);
1258 msgb_free(reply_msg);
1259
1260 return 0;
1261};
1262
1263static void test_gmm_attach_subscr_real_gsup_auth(int retry)
1264{
1265 const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
1266 struct gsm_subscriber *subscr;
1267
1268 sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE;
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001269 gprs_gsup_client_send_cb = my_gprs_gsup_client_send;
1270
1271 sgsn->gsup_client = talloc_zero(tall_bsc_ctx, struct gprs_gsup_client);
1272
1273 if (retry) {
1274 upd_loc_skip = 3;
1275 auth_info_skip = 3;
1276 }
1277
1278 printf("Auth policy 'remote', real GSUP based auth: ");
1279 test_gmm_attach(retry);
1280
1281 subscr = gprs_subscr_get_by_imsi("123456789012345");
Holger Hans Peter Freyther1d778fd2015-01-20 21:14:03 +01001282 OSMO_ASSERT(subscr == NULL);
Jacob Erlbeck058bc262015-01-13 11:46:32 +01001283 assert_no_subscrs();
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001284
1285 sgsn->cfg.auth_policy = saved_auth_policy;
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001286 gprs_gsup_client_send_cb = __real_gprs_gsup_client_send;
1287 upd_loc_skip = 0;
1288 auth_info_skip = 0;
1289 talloc_free(sgsn->gsup_client);
1290 sgsn->gsup_client = NULL;
1291}
1292
Jacob Erlbeck80d07e32014-11-06 13:43:41 +01001293/*
1294 * Test the GMM Rejects
1295 */
1296static void test_gmm_reject(void)
1297{
1298 struct gprs_ra_id raid = { 0, };
1299 struct sgsn_mm_ctx *ctx = NULL;
1300 uint32_t foreign_tlli;
1301 struct gprs_llc_lle *lle;
1302 int idx;
1303
1304 /* DTAP - Attach Request */
1305 /* Invalid MI length */
1306 static const unsigned char attach_req_inv_mi_len[] = {
1307 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, 0x09, 0xf4,
1308 0xfb, 0xc5, 0x46, 0x79, 0xff, 0xff, 0xff, 0xff, 0x11, 0x22,
1309 0x33, 0x40, 0x50, 0x60, 0x19, 0x18, 0xb3, 0x43, 0x2b, 0x25,
1310 0x96, 0x62, 0x00, 0x60, 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00,
1311 0x60, 0x80, 0xba, 0xc8, 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00
1312 };
1313
1314 /* DTAP - Attach Request */
1315 /* Invalid MI type (IMEI) */
1316 static const unsigned char attach_req_inv_mi_type[] = {
1317 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, 0x05, 0xf2,
1318 0xfb, 0xc5, 0x46, 0x79, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60,
1319 0x19, 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00, 0x60,
1320 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60, 0x80, 0xba, 0xc8,
1321 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00
1322 };
1323
1324 /* DTAP - Routing Area Update Request */
1325 static const unsigned char dtap_ra_upd_req[] = {
1326 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50,
1327 0x60, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b,
1328 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8,
1329 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02,
1330 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19,
1331 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04,
1332 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00
1333 };
1334
1335 /* DTAP - Routing Area Update Request */
1336 /* Invalid type: GPRS_UPD_T_RA_LA_IMSI_ATT */
1337 static const unsigned char dtap_ra_upd_req_inv_type[] = {
1338 0x08, 0x08, 0x12, 0x11, 0x22, 0x33, 0x40, 0x50,
1339 0x60, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b,
1340 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8,
1341 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02,
1342 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19,
1343 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04,
1344 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00
1345 };
1346
1347 /* DTAP - Routing Area Update Request */
1348 /* Invalid cap length */
1349 static const unsigned char dtap_ra_upd_req_inv_cap_len[] = {
1350 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50,
1351 0x60, 0x3d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b,
1352 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1353 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1354 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8,
1355 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02,
1356 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19,
1357 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04,
1358 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00
1359 };
1360
1361 struct test {
1362 const char *title;
1363 const unsigned char *msg;
1364 unsigned msg_len;
1365 unsigned num_resp;
1366
1367 };
1368 static struct test tests[] = {
1369 {
1370 .title = "Attach Request (invalid MI length)",
1371 .msg = attach_req_inv_mi_len,
1372 .msg_len = sizeof(attach_req_inv_mi_len),
1373 .num_resp = 1 /* Reject */
1374
1375 },
1376 {
1377 .title = "Attach Request (invalid MI type)",
1378 .msg = attach_req_inv_mi_type,
1379 .msg_len = sizeof(attach_req_inv_mi_type),
1380 .num_resp = 1 /* Reject */
1381 },
1382 {
1383 .title = "Routing Area Update Request (valid)",
1384 .msg = dtap_ra_upd_req,
1385 .msg_len = sizeof(dtap_ra_upd_req),
1386 .num_resp = 2 /* XID Reset + Reject */
1387 },
1388 {
1389 .title = "Routing Area Update Request (invalid type)",
1390 .msg = dtap_ra_upd_req_inv_type,
1391 .msg_len = sizeof(dtap_ra_upd_req_inv_type),
1392 .num_resp = 1 /* Reject */
1393 },
1394 {
1395 .title = "Routing Area Update Request (invalid CAP length)",
1396 .msg = dtap_ra_upd_req_inv_cap_len,
1397 .msg_len = sizeof(dtap_ra_upd_req_inv_cap_len),
1398 .num_resp = 1 /* Reject */
1399 },
1400 };
1401
1402 printf("Testing GMM reject\n");
1403
1404 /* reset the PRNG used by sgsn_alloc_ptmsi */
1405 srand(1);
1406
1407 foreign_tlli = gprs_tmsi2tlli(0xc0000023, TLLI_FOREIGN);
1408
1409 OSMO_ASSERT(count(gprs_llme_list()) == 0);
1410
1411 for (idx = 0; idx < ARRAY_SIZE(tests); idx++) {
1412 const struct test *test = &tests[idx];
1413 printf(" - %s\n", test->title);
1414
1415 /* Create a LLE/LLME */
1416 lle = gprs_lle_get_or_create(foreign_tlli, 3);
1417 OSMO_ASSERT(count(gprs_llme_list()) == 1);
1418
1419 /* Inject the Request message */
1420 send_0408_message(lle->llme, foreign_tlli,
1421 test->msg, test->msg_len);
1422
1423 /* We expect a Reject message */
1424 fprintf(stderr, "sgsn_tx_counter = %d (expected %d)\n",
1425 sgsn_tx_counter, test->num_resp);
1426 OSMO_ASSERT(sgsn_tx_counter == test->num_resp);
1427
1428 /* verify that LLME/MM are removed */
1429 ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid);
1430 OSMO_ASSERT(ctx == NULL);
1431 OSMO_ASSERT(count(gprs_llme_list()) == 0);
1432 }
1433}
1434
Jacob Erlbeckf6e7d992014-11-06 15:43:10 +01001435/*
Jacob Erlbeck98647ca2014-11-11 14:47:38 +01001436 * Test cancellation of attached MM contexts
1437 */
1438static void test_gmm_cancel(void)
1439{
1440 struct gprs_ra_id raid = { 0, };
1441 struct sgsn_mm_ctx *ctx = NULL;
1442 struct sgsn_mm_ctx *ictx;
1443 uint32_t ptmsi1;
1444 uint32_t foreign_tlli;
1445 uint32_t local_tlli = 0;
1446 struct gprs_llc_lle *lle;
1447 const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
1448
1449 /* DTAP - Attach Request */
1450 /* The P-TMSI is not known by the SGSN */
1451 static const unsigned char attach_req[] = {
1452 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, 0x05, 0xf4,
1453 0xfb, 0xc5, 0x46, 0x79, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60,
1454 0x19, 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00, 0x60,
1455 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60, 0x80, 0xba, 0xc8,
1456 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00
1457 };
1458
1459 /* DTAP - Identity Response IMEI */
1460 static const unsigned char ident_resp_imei[] = {
1461 0x08, 0x16, 0x08, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78,
1462 0x56
1463 };
1464
1465 /* DTAP - Identity Response IMSI */
1466 static const unsigned char ident_resp_imsi[] = {
1467 0x08, 0x16, 0x08, 0x19, 0x32, 0x54, 0x76, 0x98, 0x10, 0x32,
1468 0x54
1469 };
1470
1471 /* DTAP - Attach Complete */
1472 static const unsigned char attach_compl[] = {
1473 0x08, 0x03
1474 };
1475
1476 printf("Testing cancellation\n");
1477
1478 sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_OPEN;
1479
1480 /* reset the PRNG used by sgsn_alloc_ptmsi */
1481 srand(1);
1482
1483 ptmsi1 = sgsn_alloc_ptmsi();
1484 OSMO_ASSERT(ptmsi1 != GSM_RESERVED_TMSI);
1485
1486 /* reset the PRNG, so that the same P-TMSI sequence will be generated
1487 * again */
1488 srand(1);
1489
1490 foreign_tlli = gprs_tmsi2tlli(0xc0000023, TLLI_FOREIGN);
1491
1492 /* Create a LLE/LLME */
1493 OSMO_ASSERT(count(gprs_llme_list()) == 0);
1494 lle = gprs_lle_get_or_create(foreign_tlli, 3);
1495 OSMO_ASSERT(count(gprs_llme_list()) == 1);
1496
1497 /* inject the attach request */
1498 send_0408_message(lle->llme, foreign_tlli,
1499 attach_req, ARRAY_SIZE(attach_req));
1500
1501 ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid);
1502 OSMO_ASSERT(ctx != NULL);
1503 OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT);
1504
1505 /* we expect an identity request (IMEI) */
1506 OSMO_ASSERT(sgsn_tx_counter == 1);
1507
1508 /* inject the identity response (IMEI) */
1509 send_0408_message(ctx->llme, foreign_tlli,
1510 ident_resp_imei, ARRAY_SIZE(ident_resp_imei));
1511
1512 /* we expect an identity request (IMSI) */
1513 OSMO_ASSERT(sgsn_tx_counter == 1);
1514
1515 /* inject the identity response (IMSI) */
1516 send_0408_message(ctx->llme, foreign_tlli,
1517 ident_resp_imsi, ARRAY_SIZE(ident_resp_imsi));
1518
1519 /* check that the MM context has not been removed due to a failed
1520 * authorization */
1521 OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid));
1522
1523 OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT);
1524
1525 /* we expect an attach accept/reject */
1526 OSMO_ASSERT(sgsn_tx_counter == 1);
1527
1528 /* this has been randomly assigned by the SGSN */
1529 local_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL);
1530
1531 /* inject the attach complete */
1532 send_0408_message(ctx->llme, local_tlli,
1533 attach_compl, ARRAY_SIZE(attach_compl));
1534
1535 OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL);
1536
1537 /* we don't expect a response */
1538 OSMO_ASSERT(sgsn_tx_counter == 0);
1539
1540 /* cancel */
Jacob Erlbeckaf3d5c52015-01-05 17:51:17 +01001541 gsm0408_gprs_access_cancelled(ctx, 0);
Jacob Erlbeck98647ca2014-11-11 14:47:38 +01001542
1543 /* verify that things are gone */
1544 OSMO_ASSERT(count(gprs_llme_list()) == 0);
1545 ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid);
1546 OSMO_ASSERT(!ictx);
1547
1548 sgsn->cfg.auth_policy = saved_auth_policy;
1549}
1550
1551/*
Jacob Erlbeckf6e7d992014-11-06 15:43:10 +01001552 * Test the dynamic allocation of P-TMSIs
1553 */
1554static void test_gmm_ptmsi_allocation(void)
1555{
1556 struct gprs_ra_id raid = { 0, };
1557 struct sgsn_mm_ctx *ctx = NULL;
1558 struct sgsn_mm_ctx *ictx;
1559 uint32_t foreign_tlli;
1560 uint32_t ptmsi1;
1561 uint32_t ptmsi2;
1562 uint32_t old_ptmsi;
1563 uint32_t local_tlli = 0;
1564 struct gprs_llc_lle *lle;
1565 const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
1566
1567 /* DTAP - Attach Request (IMSI 12131415161718) */
1568 static const unsigned char attach_req[] = {
1569 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02,
1570 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1571 0x18, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60, 0x19,
1572 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00,
1573 0x60, 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60,
1574 0x80, 0xba, 0xc8, 0xc6, 0x62, 0x00, 0x60, 0x80,
1575 0x00,
1576 };
1577
1578 /* DTAP - Identity Response IMEI */
1579 static const unsigned char ident_resp_imei[] = {
1580 0x08, 0x16, 0x08, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78,
1581 0x56
1582 };
1583
1584 /* DTAP - Attach Complete */
1585 static const unsigned char attach_compl[] = {
1586 0x08, 0x03
1587 };
1588
1589 /* DTAP - Routing Area Update Request */
1590 static const unsigned char ra_upd_req[] = {
1591 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50,
1592 0x60, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b,
1593 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8,
1594 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02,
1595 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19,
1596 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04,
1597 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00
1598 };
1599
1600 /* DTAP - Routing Area Update Complete */
1601 static const unsigned char ra_upd_complete[] = {
1602 0x08, 0x0a
1603 };
1604
1605 /* DTAP - Detach Request (MO) */
1606 /* normal detach, power_off = 1 */
1607 static const unsigned char detach_req[] = {
1608 0x08, 0x05, 0x09, 0x18, 0x05, 0xf4, 0xef, 0xe2,
1609 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb
1610 };
1611
1612 sgsn->cfg.auth_policy = SGSN_AUTH_POLICY_OPEN;
1613
1614 printf("Testing P-TMSI allocation\n");
1615
1616 printf(" - sgsn_alloc_ptmsi\n");
1617
1618 /* reset the PRNG used by sgsn_alloc_ptmsi */
1619 srand(1);
1620
1621 ptmsi1 = sgsn_alloc_ptmsi();
1622 OSMO_ASSERT(ptmsi1 != GSM_RESERVED_TMSI);
1623
1624 ptmsi2 = sgsn_alloc_ptmsi();
1625 OSMO_ASSERT(ptmsi2 != GSM_RESERVED_TMSI);
1626
1627 OSMO_ASSERT(ptmsi1 != ptmsi2);
1628
1629 printf(" - Repeated Attach Request\n");
1630
1631 /* reset the PRNG, so that the same P-TMSI will be generated
1632 * again */
1633 srand(1);
1634
1635 foreign_tlli = gprs_tmsi2tlli(0xc0000023, TLLI_FOREIGN);
1636
1637 /* Create a LLE/LLME */
1638 OSMO_ASSERT(count(gprs_llme_list()) == 0);
1639 lle = gprs_lle_get_or_create(foreign_tlli, 3);
1640 OSMO_ASSERT(count(gprs_llme_list()) == 1);
1641
1642 /* inject the attach request */
1643 send_0408_message(lle->llme, foreign_tlli,
1644 attach_req, ARRAY_SIZE(attach_req));
1645
1646 ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid);
1647 OSMO_ASSERT(ctx != NULL);
1648 OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT);
1649 OSMO_ASSERT(ctx->p_tmsi == ptmsi1);
1650
1651 old_ptmsi = ctx->p_tmsi_old;
1652
1653 /* we expect an identity request (IMEI) */
1654 OSMO_ASSERT(sgsn_tx_counter == 1);
1655
1656 /* inject the identity response (IMEI) */
1657 send_0408_message(ctx->llme, foreign_tlli,
1658 ident_resp_imei, ARRAY_SIZE(ident_resp_imei));
1659
1660 /* check that the MM context has not been removed due to a failed
1661 * authorization */
1662 OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid));
1663
1664 OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT);
1665 OSMO_ASSERT(ctx->p_tmsi == ptmsi1);
1666
1667 /* we expect an attach accept */
1668 OSMO_ASSERT(sgsn_tx_counter == 1);
1669
1670 /* we ignore this and send the attach again */
1671 send_0408_message(lle->llme, foreign_tlli,
1672 attach_req, ARRAY_SIZE(attach_req));
1673
1674 /* the allocated P-TMSI should be the same */
1675 ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid);
1676 OSMO_ASSERT(ctx != NULL);
1677 OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT);
1678 OSMO_ASSERT(ctx->p_tmsi_old == old_ptmsi);
1679 OSMO_ASSERT(ctx->p_tmsi == ptmsi1);
1680
1681 /* inject the attach complete */
1682 local_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL);
1683 send_0408_message(ctx->llme, local_tlli,
1684 attach_compl, ARRAY_SIZE(attach_compl));
1685
1686 /* we don't expect a response */
1687 OSMO_ASSERT(sgsn_tx_counter == 0);
1688
1689 OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL);
1690 OSMO_ASSERT(ctx->p_tmsi_old == 0);
1691 OSMO_ASSERT(ctx->p_tmsi == ptmsi1);
1692
1693 printf(" - Repeated RA Update Request\n");
1694
1695 /* inject the RA update request */
1696 send_0408_message(ctx->llme, local_tlli,
1697 ra_upd_req, ARRAY_SIZE(ra_upd_req));
1698
1699 /* we expect an RA update accept */
1700 OSMO_ASSERT(sgsn_tx_counter == 1);
1701
1702 OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT);
1703 OSMO_ASSERT(ctx->p_tmsi_old == ptmsi1);
1704 OSMO_ASSERT(ctx->p_tmsi == ptmsi2);
1705
1706 /* repeat the RA update request */
1707 send_0408_message(ctx->llme, local_tlli,
1708 ra_upd_req, ARRAY_SIZE(ra_upd_req));
1709
1710 /* we expect an RA update accept */
1711 OSMO_ASSERT(sgsn_tx_counter == 1);
1712
1713 OSMO_ASSERT(ctx->mm_state == GMM_COMMON_PROC_INIT);
1714 OSMO_ASSERT(ctx->p_tmsi_old == ptmsi1);
1715 OSMO_ASSERT(ctx->p_tmsi == ptmsi2);
1716
1717 /* inject the RA update complete */
1718 local_tlli = gprs_tmsi2tlli(ptmsi2, TLLI_LOCAL);
1719 send_0408_message(ctx->llme, local_tlli,
1720 ra_upd_complete, ARRAY_SIZE(ra_upd_complete));
1721
1722 /* we don't expect a response */
1723 OSMO_ASSERT(sgsn_tx_counter == 0);
1724
1725 OSMO_ASSERT(ctx->mm_state == GMM_REGISTERED_NORMAL);
1726 OSMO_ASSERT(ctx->p_tmsi_old == 0);
1727 OSMO_ASSERT(ctx->p_tmsi == ptmsi2);
1728
1729 /* inject the detach */
1730 send_0408_message(ctx->llme, local_tlli,
1731 detach_req, ARRAY_SIZE(detach_req));
1732
1733 /* verify that things are gone */
1734 OSMO_ASSERT(count(gprs_llme_list()) == 0);
1735 ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid);
1736 OSMO_ASSERT(!ictx);
1737
1738 sgsn->cfg.auth_policy = saved_auth_policy;
1739}
1740
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +02001741static struct log_info_cat gprs_categories[] = {
1742 [DMM] = {
1743 .name = "DMM",
1744 .description = "Layer3 Mobility Management (MM)",
1745 .color = "\033[1;33m",
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +01001746 .enabled = 1, .loglevel = LOGL_DEBUG,
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +02001747 },
1748 [DPAG] = {
1749 .name = "DPAG",
1750 .description = "Paging Subsystem",
1751 .color = "\033[1;38m",
1752 .enabled = 1, .loglevel = LOGL_NOTICE,
1753 },
1754 [DMEAS] = {
1755 .name = "DMEAS",
1756 .description = "Radio Measurement Processing",
1757 .enabled = 0, .loglevel = LOGL_NOTICE,
1758 },
1759 [DREF] = {
1760 .name = "DREF",
1761 .description = "Reference Counting",
1762 .enabled = 0, .loglevel = LOGL_NOTICE,
1763 },
1764 [DGPRS] = {
1765 .name = "DGPRS",
1766 .description = "GPRS Packet Service",
1767 .enabled = 1, .loglevel = LOGL_DEBUG,
1768 },
1769 [DNS] = {
1770 .name = "DNS",
1771 .description = "GPRS Network Service (NS)",
1772 .enabled = 1, .loglevel = LOGL_INFO,
1773 },
1774 [DBSSGP] = {
1775 .name = "DBSSGP",
1776 .description = "GPRS BSS Gateway Protocol (BSSGP)",
1777 .enabled = 1, .loglevel = LOGL_DEBUG,
1778 },
1779 [DLLC] = {
1780 .name = "DLLC",
1781 .description = "GPRS Logical Link Control Protocol (LLC)",
1782 .enabled = 1, .loglevel = LOGL_DEBUG,
1783 },
1784 [DSNDCP] = {
1785 .name = "DSNDCP",
1786 .description = "GPRS Sub-Network Dependent Control Protocol (SNDCP)",
1787 .enabled = 1, .loglevel = LOGL_DEBUG,
1788 },
1789};
1790
1791static struct log_info info = {
1792 .cat = gprs_categories,
1793 .num_cat = ARRAY_SIZE(gprs_categories),
1794};
1795
Holger Hans Peter Freyther68c6f882014-09-30 09:10:25 +02001796int main(int argc, char **argv)
1797{
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +02001798 osmo_init_logging(&info);
1799 tall_bsc_ctx = talloc_named_const(NULL, 0, "osmo_sgsn");
1800 tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 0, "msgb");
1801
Jacob Erlbecka0b6efb2014-11-13 10:48:39 +01001802 sgsn_auth_init();
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +01001803 gprs_subscr_init(sgsn);
Jacob Erlbeck27cb4d52014-10-29 12:11:58 +01001804
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +02001805 test_llme();
Jacob Erlbeck33b6dad2014-11-12 10:12:11 +01001806 test_subscriber();
Jacob Erlbeck7921ab12014-12-08 15:52:00 +01001807 test_auth_triplets();
Jacob Erlbecka6ddc2d2014-12-12 15:01:37 +01001808 test_subscriber_gsup();
Jacob Erlbeckf81cacc2015-01-08 16:23:25 +01001809 test_subscriber_blocking();
Holger Hans Peter Freytherfe921332014-10-02 22:24:47 +02001810 test_gmm_detach();
Jacob Erlbeck189999d2014-10-27 14:34:13 +01001811 test_gmm_detach_power_off();
Jacob Erlbeck5a38f642014-10-21 13:09:55 +02001812 test_gmm_detach_no_mmctx();
Jacob Erlbeckde4bbc72014-11-24 15:04:15 +01001813 test_gmm_detach_accept_unexpected();
Jacob Erlbeck14ae5822014-10-28 09:47:03 +01001814 test_gmm_status_no_mmctx();
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +01001815 test_gmm_attach_acl();
1816 test_gmm_attach_subscr();
Jacob Erlbeck2e5e94c2014-12-08 15:26:47 +01001817 test_gmm_attach_subscr_fake_auth();
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001818 test_gmm_attach_subscr_real_auth();
Jacob Erlbeck7660ffa2014-12-19 18:30:41 +01001819 test_gmm_attach_subscr_gsup_auth(0);
1820 test_gmm_attach_subscr_gsup_auth(1);
Jacob Erlbeckc157ee72015-01-09 15:07:16 +01001821 test_gmm_attach_subscr_real_gsup_auth(0);
Jacob Erlbeck80d07e32014-11-06 13:43:41 +01001822 test_gmm_reject();
Jacob Erlbeck98647ca2014-11-11 14:47:38 +01001823 test_gmm_cancel();
Jacob Erlbeckf6e7d992014-11-06 15:43:10 +01001824 test_gmm_ptmsi_allocation();
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +02001825 printf("Done\n");
Jacob Erlbeck07de92e2015-01-13 11:46:32 +01001826
1827 talloc_report_full(tall_bsc_ctx, stderr);
Jacob Erlbeckf0b06d82015-01-13 11:56:28 +01001828 OSMO_ASSERT(talloc_total_blocks(tall_msgb_ctx) == 1);
Holger Hans Peter Freyther68c6f882014-09-30 09:10:25 +02001829 return 0;
1830}
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +02001831
1832
1833/* stubs */
1834struct osmo_prim_hdr;
1835int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
1836{
1837 abort();
1838}