aboutsummaryrefslogtreecommitdiffstats
path: root/tests/sgsn/sgsn_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/sgsn/sgsn_test.c')
-rw-r--r--tests/sgsn/sgsn_test.c933
1 files changed, 72 insertions, 861 deletions
diff --git a/tests/sgsn/sgsn_test.c b/tests/sgsn/sgsn_test.c
index d66c5dd84..7399573fc 100644
--- a/tests/sgsn/sgsn_test.c
+++ b/tests/sgsn/sgsn_test.c
@@ -19,15 +19,16 @@
*
*/
-#include <openbsc/gprs_llc.h>
-#include <openbsc/sgsn.h>
-#include <openbsc/gprs_gmm.h>
-#include <openbsc/debug.h>
-#include <openbsc/gprs_subscriber.h>
+#include <osmocom/sgsn/gprs_llc.h>
+#include <osmocom/sgsn/sgsn.h>
+#include <osmocom/sgsn/gprs_gmm.h>
+#include <osmocom/sgsn/debug.h>
+#include <osmocom/sgsn/gprs_subscriber.h>
#include <osmocom/gsm/gsup.h>
-#include <openbsc/gsup_client.h>
-#include <openbsc/gprs_utils.h>
-#include <openbsc/gprs_gb_parse.h>
+#include <osmocom/gsupclient/gsup_client.h>
+#include <osmocom/sgsn/gprs_utils.h>
+#include <osmocom/sgsn/gprs_gb_parse.h>
+#include <osmocom/sgsn/gprs_gmm_fsm.h>
#include <osmocom/gprs/gprs_bssgp.h>
@@ -37,10 +38,11 @@
#include <osmocom/core/msgb.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/utils.h>
+#include <osmocom/vty/vty.h>
#include <stdio.h>
-void *tall_bsc_ctx;
+void *tall_sgsn_ctx;
static struct sgsn_instance sgsn_inst = {
.config_file = "osmo_sgsn.cfg",
.cfg = {
@@ -100,21 +102,21 @@ int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime,
return 0;
}
-/* override, requires '-Wl,--wrap=RAND_bytes' */
-int __real_RAND_bytes(unsigned char *buf, int num);
-int mock_RAND_bytes(unsigned char *buf, int num);
-int (*RAND_bytes_cb)(unsigned char *, int) =
- &mock_RAND_bytes;
+/* override, requires '-Wl,--wrap=osmo_get_rand_id' */
+int __real_osmo_get_rand_id(uint8_t *data, size_t len);
+int mock_osmo_get_rand_id(uint8_t *data, size_t len);
+int (*osmo_get_rand_id_cb)(uint8_t *, size_t) =
+ &mock_osmo_get_rand_id;
-int __wrap_RAND_bytes(unsigned char *buf, int num)
+int __wrap_osmo_get_rand_id(uint8_t *buf, size_t num)
{
- return (*RAND_bytes_cb)(buf, num);
+ return (*osmo_get_rand_id_cb)(buf, num);
}
/* make results of A&C ref predictable */
-int mock_RAND_bytes(unsigned char *buf, int num)
+int mock_osmo_get_rand_id(uint8_t *buf, size_t num)
{
if (num > 1)
- return __real_RAND_bytes(buf, num);
+ return __real_osmo_get_rand_id(buf, num);
buf[0] = 0;
return 1;
}
@@ -148,13 +150,13 @@ int __wrap_gprs_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx, const uint8_
};
/* override, requires '-Wl,--wrap=gsup_client_send' */
-int __real_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg);
-int (*gsup_client_send_cb)(struct gsup_client *gsupc, struct msgb *msg) =
- &__real_gsup_client_send;
+int __real_osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg);
+int (*osmo_gsup_client_send_cb)(struct osmo_gsup_client *gsupc, struct msgb *msg) =
+ &__real_osmo_gsup_client_send;
-int __wrap_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg)
+int __wrap_osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg)
{
- return (*gsup_client_send_cb)(gsupc, msg);
+ return (*osmo_gsup_client_send_cb)(gsupc, msg);
};
static int count(struct llist_head *head)
@@ -165,7 +167,7 @@ static int count(struct llist_head *head)
llist_for_each(cur, head)
count += 1;
- return count;
+ return count;
}
static struct msgb *create_msg(const uint8_t *data, size_t len)
@@ -191,7 +193,6 @@ static struct sgsn_mm_ctx *alloc_mm_ctx(uint32_t tlli, struct gprs_ra_id *raid)
lle = gprs_lle_get_or_create(tlli, 3);
ctx = sgsn_mm_ctx_alloc_gb(tlli, raid);
- ctx->gmm_state = GMM_REGISTERED_NORMAL;
ctx->gb.llme = lle->llme;
ictx = sgsn_mm_ctx_by_tlli(tlli, raid);
@@ -729,7 +730,7 @@ static void test_subscriber_gsup(void)
cleanup_test();
}
-int my_gsup_client_send_dummy(struct gsup_client *gsupc, struct msgb *msg)
+int my_gsup_client_send_dummy(struct osmo_gsup_client *gsupc, struct msgb *msg)
{
msgb_free(msg);
return 0;
@@ -925,167 +926,8 @@ static void test_gmm_status_no_mmctx(void)
cleanup_test();
}
-/*
- * Test the GMM Attach procedure
- */
-static void test_gmm_attach(int retry)
+int my_subscr_request_update_location(struct sgsn_mm_ctx *mmctx)
{
- struct gprs_ra_id raid = { 0, };
- struct sgsn_mm_ctx *ctx = NULL;
- struct sgsn_mm_ctx *ictx;
- uint32_t ptmsi1;
- uint32_t foreign_tlli;
- uint32_t local_tlli = 0;
- struct gprs_llc_lle *lle;
-
- /* DTAP - Attach Request */
- /* The P-TMSI is not known by the SGSN */
- static const unsigned char attach_req[] = {
- 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02, 0x05, 0xf4,
- 0xfb, 0xc5, 0x46, 0x79, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60,
- 0x19, 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00, 0x60,
- 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60, 0x80, 0xba, 0xc8,
- 0xc6, 0x62, 0x00, 0x60, 0x80, 0x00
- };
-
- /* DTAP - Identity Response IMEI */
- static const unsigned char ident_resp_imei[] = {
- 0x08, 0x16, 0x08, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78,
- 0x56
- };
-
- /* DTAP - Identity Response IMSI */
- static const unsigned char ident_resp_imsi[] = {
- 0x08, 0x16, 0x08, 0x19, 0x32, 0x54, 0x76, 0x98, 0x10, 0x32,
- 0x54
- };
-
- /* DTAP - Authentication and Ciphering Resp */
- static const unsigned char auth_ciph_resp[] = {
- 0x08, 0x13, 0x00, 0x22, 0x51, 0xe5, 0x51, 0xe5, 0x23, 0x09,
- 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x01
- };
-
- /* DTAP - Attach Complete */
- static const unsigned char attach_compl[] = {
- 0x08, 0x03
- };
-
- /* DTAP - Detach Request (MO) */
- /* normal detach, power_off = 0 */
- static const unsigned char detach_req[] = {
- 0x08, 0x05, 0x01, 0x18, 0x05, 0xf4, 0xeb, 0x8b,
- 0x45, 0x67, 0x19, 0x03, 0xb9, 0x97, 0xcb
- };
-
- printf("Testing GMM attach%s\n", retry ? " with retry" : "");
-
- foreign_tlli = gprs_tmsi2tlli(0xc0000023, TLLI_FOREIGN);
-
- /* Create a LLE/LLME */
- OSMO_ASSERT(count(gprs_llme_list()) == 0);
- lle = gprs_lle_get_or_create(foreign_tlli, 3);
- OSMO_ASSERT(count(gprs_llme_list()) == 1);
-
- /* inject the attach request */
- send_0408_message(lle->llme, foreign_tlli, &raid,
- attach_req, ARRAY_SIZE(attach_req));
-
- ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid);
- OSMO_ASSERT(ctx != NULL);
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
-
- /* we expect an identity request (IMEI) */
- OSMO_ASSERT(sgsn_tx_counter == 1);
-
- /* inject the identity response (IMEI) */
- send_0408_message(ctx->gb.llme, foreign_tlli, &raid,
- ident_resp_imei, ARRAY_SIZE(ident_resp_imei));
-
- /* we expect an identity request (IMSI) */
- OSMO_ASSERT(sgsn_tx_counter == 1);
-
- /* inject the identity response (IMSI) */
- send_0408_message(ctx->gb.llme, foreign_tlli, &raid,
- ident_resp_imsi, ARRAY_SIZE(ident_resp_imsi));
-
- /* check that the MM context has not been removed due to a failed
- * authorization */
- OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid));
-
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
-
-retry_attach_req:
-
- if (retry && sgsn_tx_counter == 0) {
- fprintf(stderr, "Retrying attach request\n");
- /* re-inject the attach request */
- send_0408_message(lle->llme, foreign_tlli, &raid,
- attach_req, ARRAY_SIZE(attach_req));
- }
-
- if (ctx->auth_state == SGSN_AUTH_AUTHENTICATE && sgsn_tx_counter == 1) {
- /* we got an auth & ciph request */
-
- /* inject the auth & ciph response */
- send_0408_message(ctx->gb.llme, foreign_tlli, &raid,
- auth_ciph_resp, ARRAY_SIZE(auth_ciph_resp));
-
- /* check that the MM context has not been removed due to a
- * failed authorization */
- OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid));
- if (ctx->subscr && ctx->subscr->sgsn_data->msisdn_len > 0)
- OSMO_ASSERT(strcmp(ctx->msisdn, "+49166213323") == 0);
- }
-
- if (retry && sgsn_tx_counter == 0)
- goto retry_attach_req;
-
- /* we expect an attach accept/reject */
- OSMO_ASSERT(sgsn_tx_counter == 1);
- ptmsi1 = get_new_ptmsi(&last_dl_parse_ctx);
- OSMO_ASSERT(ptmsi1 != GSM_RESERVED_TMSI);
-
- /* this has been randomly assigned by the SGSN */
- local_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL);
-
- /* inject the attach complete */
- send_0408_message(ctx->gb.llme, local_tlli, &raid,
- attach_compl, ARRAY_SIZE(attach_compl));
-
- OSMO_ASSERT(ctx->gmm_state == GMM_REGISTERED_NORMAL);
-
- /* we don't expect a response */
- OSMO_ASSERT(sgsn_tx_counter == 0);
-
- /* inject the detach */
- send_0408_message(ctx->gb.llme, local_tlli, &raid,
- detach_req, ARRAY_SIZE(detach_req));
-
- /* verify that things are gone */
- OSMO_ASSERT(count(gprs_llme_list()) == 0);
- ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid);
- OSMO_ASSERT(!ictx);
-
- cleanup_test();
-}
-
-static void test_gmm_attach_acl(void)
-{
- const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
-
- sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_CLOSED;
- sgsn_acl_add("123456789012345", &sgsn->cfg);
- printf("Auth policy 'closed': ");
- test_gmm_attach(0);
- sgsn_acl_del("123456789012345", &sgsn->cfg);
-
- sgsn->cfg.auth_policy = saved_auth_policy;
-
- cleanup_test();
-}
-
-int my_subscr_request_update_location(struct sgsn_mm_ctx *mmctx) {
int rc;
rc = __real_gprs_subscr_request_update_location(mmctx);
if (rc == -ENOTSUP) {
@@ -1093,71 +935,24 @@ int my_subscr_request_update_location(struct sgsn_mm_ctx *mmctx) {
gprs_subscr_update(mmctx->subscr);
}
return rc;
-};
+}
-int my_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx) {
+int my_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx, const uint8_t *auts,
+ const uint8_t *auts_rand)
+{
gprs_subscr_update(mmctx->subscr);
return 0;
-};
-
-static void test_gmm_attach_subscr(void)
-{
- const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
- struct gprs_subscr *subscr;
-
- sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE;
- subscr_request_update_location_cb = my_subscr_request_update_location;
- subscr_request_auth_info_cb = my_subscr_request_auth_info;
-
- subscr = gprs_subscr_get_or_create("123456789012345");
- subscr->authorized = 1;
-
- printf("Auth policy 'remote': ");
- test_gmm_attach(0);
- gprs_subscr_put(subscr);
- assert_no_subscrs();
-
- sgsn->cfg.auth_policy = saved_auth_policy;
- subscr_request_update_location_cb = __real_gprs_subscr_request_update_location;
- subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info;
-
- cleanup_test();
}
-int my_subscr_request_auth_info_fake_auth(struct sgsn_mm_ctx *mmctx)
+int my_subscr_request_auth_info_fake_auth(struct sgsn_mm_ctx *mmctx, const uint8_t *auts,
+ const uint8_t *auts_rand)
{
/* Fake an authentication */
OSMO_ASSERT(mmctx->subscr);
- mmctx->is_authenticated = 1;
+ mmctx->sec_ctx = OSMO_AUTH_TYPE_GSM;
gprs_subscr_update_auth_info(mmctx->subscr);
return 0;
-};
-
-static void test_gmm_attach_subscr_fake_auth(void)
-{
- const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
- struct gprs_subscr *subscr;
-
- sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE;
- subscr_request_update_location_cb = my_subscr_request_update_location;
- subscr_request_auth_info_cb = my_subscr_request_auth_info_fake_auth;
-
- subscr = gprs_subscr_get_or_create("123456789012345");
- subscr->authorized = 1;
- sgsn->cfg.require_authentication = 1;
- sgsn->cfg.require_update_location = 1;
-
- printf("Auth policy 'remote', auth faked: ");
- test_gmm_attach(0);
- gprs_subscr_put(subscr);
- assert_no_subscrs();
-
- sgsn->cfg.auth_policy = saved_auth_policy;
- subscr_request_update_location_cb = __real_gprs_subscr_request_update_location;
- subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info;
-
- cleanup_test();
}
int my_subscr_request_auth_info_real_auth(struct sgsn_mm_ctx *mmctx, const uint8_t *auts, const uint8_t *auts_rand)
@@ -1175,33 +970,6 @@ int my_subscr_request_auth_info_real_auth(struct sgsn_mm_ctx *mmctx, const uint8
gprs_subscr_update_auth_info(mmctx->subscr);
return 0;
-};
-
-static void test_gmm_attach_subscr_real_auth(void)
-{
- const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
- struct gprs_subscr *subscr;
-
- sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE;
- subscr_request_update_location_cb = my_subscr_request_update_location;
- subscr_request_auth_info_cb = my_subscr_request_auth_info_real_auth;
-
- subscr = gprs_subscr_get_or_create("123456789012345");
- subscr->authorized = 1;
- sgsn->cfg.require_authentication = 1;
- sgsn->cfg.require_update_location = 1;
-
- printf("Auth policy 'remote', triplet based auth: ");
-
- test_gmm_attach(0);
- gprs_subscr_put(subscr);
- assert_no_subscrs();
-
- sgsn->cfg.auth_policy = saved_auth_policy;
- subscr_request_update_location_cb = __real_gprs_subscr_request_update_location;
- subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info;
-
- cleanup_test();
}
#define TEST_GSUP_IMSI_LONG_IE 0x01, 0x08, \
@@ -1210,7 +978,8 @@ static void test_gmm_attach_subscr_real_auth(void)
static int auth_info_skip = 0;
static int upd_loc_skip = 0;
-int my_subscr_request_auth_info_gsup_auth(struct sgsn_mm_ctx *mmctx)
+int my_subscr_request_auth_info_gsup_auth(struct sgsn_mm_ctx *mmctx, const uint8_t *auts,
+ const uint8_t *auts_rand)
{
static const uint8_t send_auth_info_res[] = {
0x0a,
@@ -1264,40 +1033,7 @@ int my_subscr_request_update_gsup_auth(struct sgsn_mm_ctx *mmctx) {
return rx_gsup_message(update_location_res, sizeof(update_location_res));
};
-
-static void test_gmm_attach_subscr_gsup_auth(int retry)
-{
- const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
- struct gprs_subscr *subscr;
-
- sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE;
- subscr_request_update_location_cb = my_subscr_request_update_gsup_auth;
- subscr_request_auth_info_cb = my_subscr_request_auth_info_gsup_auth;
- if (retry) {
- upd_loc_skip = 3;
- auth_info_skip = 3;
- }
-
- subscr = gprs_subscr_get_or_create("123456789012345");
- subscr->authorized = 1;
- sgsn->cfg.require_authentication = 1;
- sgsn->cfg.require_update_location = 1;
- gprs_subscr_put(subscr);
-
- printf("Auth policy 'remote', GSUP based auth: ");
- test_gmm_attach(retry);
- assert_no_subscrs();
-
- sgsn->cfg.auth_policy = saved_auth_policy;
- subscr_request_update_location_cb = __real_gprs_subscr_request_update_location;
- subscr_request_auth_info_cb = __real_gprs_subscr_request_auth_info;
- upd_loc_skip = 0;
- auth_info_skip = 0;
-
- cleanup_test();
-}
-
-int my_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg)
+int my_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg)
{
struct osmo_gsup_message to_peer = {0};
struct osmo_gsup_message from_peer = {0};
@@ -1320,7 +1056,7 @@ int my_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg)
case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST:
/* Send SEND_AUTH_INFO_RESULT */
- return my_subscr_request_auth_info_gsup_auth(NULL);
+ return my_subscr_request_auth_info_gsup_auth(NULL, NULL, NULL);
case OSMO_GSUP_MSGT_PURGE_MS_REQUEST:
from_peer.message_type = OSMO_GSUP_MSGT_PURGE_MS_RESULT;
@@ -1339,7 +1075,7 @@ int my_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg)
return 0;
}
- reply_msg = gsup_client_msgb_alloc();
+ reply_msg = osmo_gsup_client_msgb_alloc();
reply_msg->l2h = reply_msg->data;
osmo_gsup_encode(reply_msg, &from_peer);
gprs_subscr_rx_gsup_message(reply_msg);
@@ -1348,38 +1084,6 @@ int my_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg)
return 0;
};
-static void test_gmm_attach_subscr_real_gsup_auth(int retry)
-{
- const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
- struct gprs_subscr *subscr;
-
- sgsn_inst.cfg.auth_policy = SGSN_AUTH_POLICY_REMOTE;
- gsup_client_send_cb = my_gsup_client_send;
-
- sgsn->gsup_client = talloc_zero(tall_bsc_ctx, struct gsup_client);
-
- if (retry) {
- upd_loc_skip = 3;
- auth_info_skip = 3;
- }
-
- printf("Auth policy 'remote', real GSUP based auth: ");
- test_gmm_attach(retry);
-
- subscr = gprs_subscr_get_by_imsi("123456789012345");
- OSMO_ASSERT(subscr == NULL);
- assert_no_subscrs();
-
- sgsn->cfg.auth_policy = saved_auth_policy;
- gsup_client_send_cb = __real_gsup_client_send;
- upd_loc_skip = 0;
- auth_info_skip = 0;
- talloc_free(sgsn->gsup_client);
- sgsn->gsup_client = NULL;
-
- cleanup_test();
-}
-
/*
* Test the GMM Rejects
*/
@@ -1582,7 +1286,7 @@ static void test_gmm_cancel(void)
ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid);
OSMO_ASSERT(ctx != NULL);
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
+ OSMO_ASSERT(ctx->gmm_fsm->state == ST_GMM_COMMON_PROC_INIT);
/* we expect an identity request (IMEI) */
OSMO_ASSERT(sgsn_tx_counter == 1);
@@ -1602,7 +1306,7 @@ static void test_gmm_cancel(void)
* authorization */
OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid));
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
+ OSMO_ASSERT(ctx->gmm_fsm->state == ST_GMM_COMMON_PROC_INIT);
/* we expect an attach accept/reject */
OSMO_ASSERT(sgsn_tx_counter == 1);
@@ -1616,7 +1320,7 @@ static void test_gmm_cancel(void)
send_0408_message(ctx->gb.llme, foreign_tlli, &raid,
attach_compl, ARRAY_SIZE(attach_compl));
- OSMO_ASSERT(ctx->gmm_state == GMM_REGISTERED_NORMAL);
+ OSMO_ASSERT(ctx->gmm_fsm->state == ST_GMM_REGISTERED_NORMAL);
/* we don't expect a response */
OSMO_ASSERT(sgsn_tx_counter == 0);
@@ -1634,513 +1338,6 @@ static void test_gmm_cancel(void)
cleanup_test();
}
-/*
- * Test the dynamic allocation of P-TMSIs
- */
-static void test_gmm_ptmsi_allocation(void)
-{
- struct gprs_ra_id raid = {332, 112, 16464, 96};
- struct sgsn_mm_ctx *ctx = NULL;
- struct sgsn_mm_ctx *ictx;
- uint32_t foreign_tlli;
- uint32_t ptmsi1;
- uint32_t ptmsi2;
- uint32_t received_ptmsi;
- uint32_t old_ptmsi;
- uint32_t local_tlli = 0;
- struct gprs_llc_lle *lle;
- const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
-
- /* DTAP - Attach Request (IMSI 12131415161718) */
- static const unsigned char attach_req[] = {
- 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02,
- 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60, 0x19,
- 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00,
- 0x60, 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60,
- 0x80, 0xba, 0xc8, 0xc6, 0x62, 0x00, 0x60, 0x80,
- 0x00,
- };
-
- /* DTAP - Identity Response IMEI */
- static const unsigned char ident_resp_imei[] = {
- 0x08, 0x16, 0x08, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78,
- 0x56
- };
-
- /* DTAP - Attach Complete */
- static const unsigned char attach_compl[] = {
- 0x08, 0x03
- };
-
- /* DTAP - Routing Area Update Request */
- static const unsigned char ra_upd_req[] = {
- 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50,
- 0x60, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b,
- 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8,
- 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02,
- 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19,
- 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04,
- 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00
- };
-
- /* DTAP - Routing Area Update Complete */
- static const unsigned char ra_upd_complete[] = {
- 0x08, 0x0a
- };
-
- /* DTAP - Detach Request (MO) */
- /* normal detach, power_off = 1 */
- static const unsigned char detach_req[] = {
- 0x08, 0x05, 0x09, 0x18, 0x05, 0xf4, 0xef, 0xe2,
- 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb
- };
-
- sgsn->cfg.auth_policy = SGSN_AUTH_POLICY_OPEN;
-
- printf("Testing P-TMSI allocation\n");
-
- printf(" - sgsn_alloc_ptmsi\n");
-
- /* reset the PRNG used by sgsn_alloc_ptmsi */
- srand(1);
-
- ptmsi1 = sgsn_alloc_ptmsi();
- OSMO_ASSERT(ptmsi1 != GSM_RESERVED_TMSI);
-
- ptmsi2 = sgsn_alloc_ptmsi();
- OSMO_ASSERT(ptmsi2 != GSM_RESERVED_TMSI);
-
- OSMO_ASSERT(ptmsi1 != ptmsi2);
-
- ptmsi1 = ptmsi2 = GSM_RESERVED_TMSI;
-
- printf(" - Repeated Attach Request\n");
-
- foreign_tlli = gprs_tmsi2tlli(0xc0000023, TLLI_FOREIGN);
-
- /* Create a LLE/LLME */
- OSMO_ASSERT(count(gprs_llme_list()) == 0);
- lle = gprs_lle_get_or_create(foreign_tlli, 3);
- OSMO_ASSERT(count(gprs_llme_list()) == 1);
-
- /* inject the attach request */
- send_0408_message(lle->llme, foreign_tlli, &raid,
- attach_req, ARRAY_SIZE(attach_req));
-
- ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid);
- OSMO_ASSERT(ctx != NULL);
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
- OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI);
- ptmsi1 = ctx->p_tmsi;
-
- old_ptmsi = ctx->p_tmsi_old;
-
- /* we expect an identity request (IMEI) */
- OSMO_ASSERT(sgsn_tx_counter == 1);
-
- /* inject the identity response (IMEI) */
- send_0408_message(ctx->gb.llme, foreign_tlli, &raid,
- ident_resp_imei, ARRAY_SIZE(ident_resp_imei));
-
- /* check that the MM context has not been removed due to a failed
- * authorization */
- OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(foreign_tlli, &raid));
-
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
- OSMO_ASSERT(ctx->p_tmsi == ptmsi1);
-
- /* we expect an attach accept */
- OSMO_ASSERT(sgsn_tx_counter == 1);
- received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx);
- OSMO_ASSERT(received_ptmsi == ptmsi1);
-
- /* we ignore this and send the attach again */
- send_0408_message(lle->llme, foreign_tlli, &raid,
- attach_req, ARRAY_SIZE(attach_req));
-
- /* the allocated P-TMSI should be the same */
- ctx = sgsn_mm_ctx_by_tlli(foreign_tlli, &raid);
- OSMO_ASSERT(ctx != NULL);
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
- OSMO_ASSERT(ctx->p_tmsi_old == old_ptmsi);
- OSMO_ASSERT(ctx->p_tmsi == ptmsi1);
-
- /* we expect an attach accept */
- OSMO_ASSERT(sgsn_tx_counter == 1);
- received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx);
- OSMO_ASSERT(received_ptmsi == ptmsi1);
-
- /* inject the attach complete */
- local_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL);
- send_0408_message(ctx->gb.llme, local_tlli, &raid,
- attach_compl, ARRAY_SIZE(attach_compl));
-
- /* we don't expect a response */
- OSMO_ASSERT(sgsn_tx_counter == 0);
-
- OSMO_ASSERT(ctx->gmm_state == GMM_REGISTERED_NORMAL);
- OSMO_ASSERT(ctx->p_tmsi_old == 0);
- OSMO_ASSERT(ctx->p_tmsi == ptmsi1);
-
- printf(" - Repeated RA Update Request\n");
-
- /* inject the RA update request */
- send_0408_message(ctx->gb.llme, local_tlli, &raid,
- ra_upd_req, ARRAY_SIZE(ra_upd_req));
-
- /* we expect an RA update accept */
- OSMO_ASSERT(sgsn_tx_counter == 1);
-
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
- OSMO_ASSERT(ctx->p_tmsi_old == ptmsi1);
- OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI);
- OSMO_ASSERT(ctx->p_tmsi != ptmsi1);
- ptmsi2 = ctx->p_tmsi;
-
- /* repeat the RA update request */
- send_0408_message(ctx->gb.llme, local_tlli, &raid,
- ra_upd_req, ARRAY_SIZE(ra_upd_req));
-
- /* we expect an RA update accept */
- OSMO_ASSERT(sgsn_tx_counter == 1);
- received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx);
- OSMO_ASSERT(received_ptmsi == ptmsi2);
-
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
- OSMO_ASSERT(ctx->p_tmsi_old == ptmsi1);
- OSMO_ASSERT(ctx->p_tmsi == ptmsi2);
-
- /* inject the RA update complete */
- local_tlli = gprs_tmsi2tlli(ptmsi2, TLLI_LOCAL);
- send_0408_message(ctx->gb.llme, local_tlli, &raid,
- ra_upd_complete, ARRAY_SIZE(ra_upd_complete));
-
- /* we don't expect a response */
- OSMO_ASSERT(sgsn_tx_counter == 0);
-
- OSMO_ASSERT(ctx->gmm_state == GMM_REGISTERED_NORMAL);
- OSMO_ASSERT(ctx->p_tmsi_old == 0);
- OSMO_ASSERT(ctx->p_tmsi == ptmsi2);
-
- /* inject the detach */
- send_0408_message(ctx->gb.llme, local_tlli, &raid,
- detach_req, ARRAY_SIZE(detach_req));
-
- /* verify that things are gone */
- OSMO_ASSERT(count(gprs_llme_list()) == 0);
- ictx = sgsn_mm_ctx_by_tlli(local_tlli, &raid);
- OSMO_ASSERT(!ictx);
-
- sgsn->cfg.auth_policy = saved_auth_policy;
-
- cleanup_test();
-}
-
-/*
- * Test changing of routing areas
- */
-static void test_gmm_routing_areas(void)
-{
- struct gprs_ra_id raid1 = {332, 112, 16464, 96};
- struct gprs_ra_id raid2 = {332, 112, 16464, 97};
- struct sgsn_mm_ctx *ctx = NULL;
- struct sgsn_mm_ctx *ictx;
- uint32_t ptmsi1;
- uint32_t received_ptmsi;
- uint32_t ms_tlli = 0;
- struct gprs_llc_lle *lle;
- const enum sgsn_auth_policy saved_auth_policy = sgsn->cfg.auth_policy;
-
- /* DTAP - Attach Request (IMSI 12131415161718) */
- static const unsigned char attach_req[] = {
- 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02,
- 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x22, 0x33, 0x40, 0x50, 0x60, 0x19,
- 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00,
- 0x60, 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60,
- 0x80, 0xba, 0xc8, 0xc6, 0x62, 0x00, 0x60, 0x80,
- 0x00,
- };
-
- /* DTAP - Attach Request (IMSI 12131415161718) (RA 2) */
- static const unsigned char attach_req2[] = {
- 0x08, 0x01, 0x02, 0xf5, 0xe0, 0x21, 0x08, 0x02,
- 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x22, 0x33, 0x40, 0x50, 0x61, 0x19,
- 0x18, 0xb3, 0x43, 0x2b, 0x25, 0x96, 0x62, 0x00,
- 0x60, 0x80, 0x9a, 0xc2, 0xc6, 0x62, 0x00, 0x60,
- 0x80, 0xba, 0xc8, 0xc6, 0x62, 0x00, 0x60, 0x80,
- 0x00,
- };
-
- /* DTAP - Identity Response IMEI */
- static const unsigned char ident_resp_imei[] = {
- 0x08, 0x16, 0x08, 0x9a, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78,
- 0x56
- };
-
- /* DTAP - Attach Complete */
- static const unsigned char attach_compl[] = {
- 0x08, 0x03
- };
-
- /* DTAP - Routing Area Update Request (coming from RA 1) */
- static const unsigned char ra_upd_req1[] = {
- 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50,
- 0x60, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b,
- 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8,
- 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02,
- 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19,
- 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04,
- 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00
- };
-
- /* DTAP - Routing Area Update Request (coming from RA 2) */
- static const unsigned char ra_upd_req2[] = {
- 0x08, 0x08, 0x10, 0x11, 0x22, 0x33, 0x40, 0x50,
- 0x61, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b,
- 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8,
- 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02,
- 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19,
- 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04,
- 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00
- };
-
- /* DTAP - Routing Area Update Request (coming from RA other) */
- /* raid_other = {443, 223, 16464, 98}; */
- static const unsigned char ra_upd_req_other[] = {
- 0x08, 0x08, 0x10, 0x22, 0x33, 0x44, 0x40, 0x50,
- 0x62, 0x1d, 0x19, 0x13, 0x42, 0x33, 0x57, 0x2b,
- 0xf7, 0xc8, 0x48, 0x02, 0x13, 0x48, 0x50, 0xc8,
- 0x48, 0x02, 0x14, 0x48, 0x50, 0xc8, 0x48, 0x02,
- 0x17, 0x49, 0x10, 0xc8, 0x48, 0x02, 0x00, 0x19,
- 0x8b, 0xb2, 0x92, 0x17, 0x16, 0x27, 0x07, 0x04,
- 0x31, 0x02, 0xe5, 0xe0, 0x32, 0x02, 0x20, 0x00
- };
-
- /* DTAP - Routing Area Update Complete */
- static const unsigned char ra_upd_complete[] = {
- 0x08, 0x0a
- };
-
- /* DTAP - Detach Request (MO) */
- /* normal detach, power_off = 1 */
- static const unsigned char detach_req[] = {
- 0x08, 0x05, 0x09, 0x18, 0x05, 0xf4, 0xef, 0xe2,
- 0xb7, 0x00, 0x19, 0x03, 0xb9, 0x97, 0xcb
- };
-
- sgsn->cfg.auth_policy = SGSN_AUTH_POLICY_OPEN;
-
- printf("Testing routing area changes\n");
-
- /* reset the PRNG used by sgsn_alloc_ptmsi */
- srand(1);
-
- ptmsi1 = GSM_RESERVED_TMSI;
-
- printf(" - Attach Request (RA 1)\n");
-
- ms_tlli = gprs_tmsi2tlli(0x00000023, TLLI_RANDOM);
-
- /* Create a LLE/LLME */
- OSMO_ASSERT(count(gprs_llme_list()) == 0);
- lle = gprs_lle_get_or_create(ms_tlli, 3);
- OSMO_ASSERT(count(gprs_llme_list()) == 1);
-
- /* inject the attach request */
- send_0408_message(lle->llme, ms_tlli, &raid1,
- attach_req, ARRAY_SIZE(attach_req));
-
- ctx = sgsn_mm_ctx_by_tlli(ms_tlli, &raid1);
- OSMO_ASSERT(ctx != NULL);
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
- OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI);
-
- /* we expect an identity request (IMEI) */
- OSMO_ASSERT(sgsn_tx_counter == 1);
- OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_ID_REQ);
- OSMO_ASSERT(last_dl_parse_ctx.tlli == ms_tlli);
-
- /* inject the identity response (IMEI) */
- send_0408_message(ctx->gb.llme, ms_tlli, &raid1,
- ident_resp_imei, ARRAY_SIZE(ident_resp_imei));
-
- /* check that the MM context has not been removed due to a failed
- * authorization */
- OSMO_ASSERT(ctx == sgsn_mm_ctx_by_tlli(ms_tlli, &raid1));
-
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
-
- /* we expect an attach accept */
- OSMO_ASSERT(sgsn_tx_counter == 1);
- OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_ATTACH_ACK);
- OSMO_ASSERT(last_dl_parse_ctx.tlli == ms_tlli);
-
- received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx);
- OSMO_ASSERT(received_ptmsi == ctx->p_tmsi);
- ptmsi1 = received_ptmsi;
-
- /* inject the attach complete */
- ms_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL);
- send_0408_message(ctx->gb.llme, ms_tlli, &raid1,
- attach_compl, ARRAY_SIZE(attach_compl));
-
- /* we don't expect a response */
- OSMO_ASSERT(sgsn_tx_counter == 0);
-
- OSMO_ASSERT(ctx->gmm_state == GMM_REGISTERED_NORMAL);
- OSMO_ASSERT(ctx->p_tmsi_old == 0);
- OSMO_ASSERT(ctx->p_tmsi == ptmsi1);
-
- printf(" - RA Update Request (RA 1 -> RA 1)\n");
-
- /* inject the RA update request */
- send_0408_message(ctx->gb.llme, ms_tlli, &raid1,
- ra_upd_req1, ARRAY_SIZE(ra_upd_req1));
-
- /* we expect an RA update accept */
- OSMO_ASSERT(sgsn_tx_counter == 1);
- OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_RA_UPD_ACK);
- // OSMO_ASSERT(last_dl_parse_ctx.tlli == ms_tlli);
-
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
- OSMO_ASSERT(ctx->p_tmsi_old == ptmsi1);
- OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI);
- OSMO_ASSERT(ctx->p_tmsi != ptmsi1);
-
- received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx);
- OSMO_ASSERT(received_ptmsi == ctx->p_tmsi);
- ptmsi1 = received_ptmsi;
-
- /* inject the RA update complete */
- ms_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL);
- send_0408_message(ctx->gb.llme, ms_tlli, &raid1,
- ra_upd_complete, ARRAY_SIZE(ra_upd_complete));
-
- /* we don't expect a response */
- OSMO_ASSERT(sgsn_tx_counter == 0);
-
- OSMO_ASSERT(ctx->gmm_state == GMM_REGISTERED_NORMAL);
- OSMO_ASSERT(ctx->p_tmsi_old == 0);
- OSMO_ASSERT(ctx->p_tmsi == ptmsi1);
- OSMO_ASSERT(ctx->gb.tlli == ms_tlli);
-
- printf(" - RA Update Request (RA 1 -> RA 2)\n");
-
- /* inject the RA update request */
- ms_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_FOREIGN);
-
- /* It is coming from RA 1 => ra_upd_req1 */
- send_0408_message(ctx->gb.llme, ms_tlli, &raid2,
- ra_upd_req1, ARRAY_SIZE(ra_upd_req1));
-
- /* we expect an RA update accept */
- OSMO_ASSERT(sgsn_tx_counter == 1);
- OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_RA_UPD_ACK);
-
- printf(" - RA Update Request (RA other -> RA 2)\n");
-
- /* inject the RA update request */
- ms_tlli = gprs_tmsi2tlli(0x12345678, TLLI_FOREIGN);
-
- /* It is coming from RA 1 => ra_upd_req1 */
- send_0408_message(ctx->gb.llme, ms_tlli, &raid2,
- ra_upd_req_other, ARRAY_SIZE(ra_upd_req_other));
-
- /* we expect an RA update reject (and a LLC XID RESET) */
- OSMO_ASSERT(sgsn_tx_counter == 2);
- OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_RA_UPD_REJ);
- /* this has killed the LLE/LLME */
-
- printf(" - Attach Request (RA 2)\n");
-
- /* Create a LLE/LLME */
- OSMO_ASSERT(count(gprs_llme_list()) == 1);
- lle = gprs_lle_get_or_create(ms_tlli, 3);
- OSMO_ASSERT(count(gprs_llme_list()) == 1);
-
- /* inject the attach request */
- send_0408_message(lle->llme, ms_tlli, &raid2,
- attach_req2, ARRAY_SIZE(attach_req2));
-
- ctx = sgsn_mm_ctx_by_tlli(ms_tlli, &raid2);
- OSMO_ASSERT(ctx != NULL);
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
- OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI);
-
- /* we expect an attach accept */
- OSMO_ASSERT(sgsn_tx_counter == 1);
- OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_ATTACH_ACK);
-
- received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx);
- OSMO_ASSERT(received_ptmsi == ctx->p_tmsi);
- ptmsi1 = received_ptmsi;
-
- /* inject the attach complete */
- ms_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL);
- ictx = sgsn_mm_ctx_by_tlli(ms_tlli, &raid2);
- OSMO_ASSERT(ictx != NULL);
- OSMO_ASSERT(ictx == ctx);
-
- send_0408_message(ctx->gb.llme, ms_tlli, &raid2,
- attach_compl, ARRAY_SIZE(attach_compl));
-
- /* we don't expect a response */
- OSMO_ASSERT(sgsn_tx_counter == 0);
-
- OSMO_ASSERT(ctx->gmm_state == GMM_REGISTERED_NORMAL);
- OSMO_ASSERT(ctx->p_tmsi_old == 0);
- OSMO_ASSERT(ctx->p_tmsi == ptmsi1);
-
- printf(" - RA Update Request (RA 2 -> RA 2)\n");
-
- /* inject the RA update request */
- send_0408_message(ctx->gb.llme, ms_tlli, &raid2,
- ra_upd_req2, ARRAY_SIZE(ra_upd_req2));
-
- /* we expect an RA update accept */
- OSMO_ASSERT(sgsn_tx_counter == 1);
- OSMO_ASSERT(last_dl_parse_ctx.g48_hdr->msg_type == GSM48_MT_GMM_RA_UPD_ACK);
-
- OSMO_ASSERT(ctx->gmm_state == GMM_COMMON_PROC_INIT);
- OSMO_ASSERT(ctx->p_tmsi_old == ptmsi1);
- OSMO_ASSERT(ctx->p_tmsi != GSM_RESERVED_TMSI);
- OSMO_ASSERT(ctx->p_tmsi != ptmsi1);
-
- received_ptmsi = get_new_ptmsi(&last_dl_parse_ctx);
- OSMO_ASSERT(received_ptmsi == ctx->p_tmsi);
- ptmsi1 = received_ptmsi;
-
- /* inject the RA update complete */
- ms_tlli = gprs_tmsi2tlli(ptmsi1, TLLI_LOCAL);
- send_0408_message(ctx->gb.llme, ms_tlli, &raid2,
- ra_upd_complete, ARRAY_SIZE(ra_upd_complete));
-
- /* we don't expect a response */
- OSMO_ASSERT(sgsn_tx_counter == 0);
-
- OSMO_ASSERT(ctx->gmm_state == GMM_REGISTERED_NORMAL);
- OSMO_ASSERT(ctx->p_tmsi_old == 0);
- OSMO_ASSERT(ctx->p_tmsi == ptmsi1);
- OSMO_ASSERT(ctx->gb.tlli == ms_tlli);
-
-
- /* inject the detach */
- send_0408_message(ctx->gb.llme, ms_tlli, &raid2,
- detach_req, ARRAY_SIZE(detach_req));
-
- /* verify that things are gone */
- OSMO_ASSERT(count(gprs_llme_list()) == 0);
- ictx = sgsn_mm_ctx_by_tlli(ms_tlli, &raid2);
- OSMO_ASSERT(!ictx);
-
- sgsn->cfg.auth_policy = saved_auth_policy;
-
- cleanup_test();
-}
-
static void test_apn_matching(void)
{
struct apn_ctx *actx, *actxs[9];
@@ -2255,7 +1452,7 @@ static void test_ggsn_selection(void)
printf("Testing GGSN selection\n");
- gsup_client_send_cb = my_gsup_client_send_dummy;
+ osmo_gsup_client_send_cb = my_gsup_client_send_dummy;
/* Check for emptiness */
OSMO_ASSERT(gprs_subscr_get_by_imsi(imsi1) == NULL);
@@ -2374,11 +1571,27 @@ static void test_ggsn_selection(void)
sgsn_ggsn_ctx_free(ggcs[1]);
sgsn_ggsn_ctx_free(ggcs[2]);
- gsup_client_send_cb = __real_gsup_client_send;
+ osmo_gsup_client_send_cb = __real_osmo_gsup_client_send;
cleanup_test();
}
+bool pdp_status_has_active_nsapis(const uint8_t *pdp_status, const size_t pdp_status_len);
+
+static void test_pdp_status_has_active_nsapis(void)
+{
+ const size_t pdp_status_len = 2;
+ const uint8_t pdp_status1[] = { 0b00100000, 0b00000000 }; /* PDP NSAPI 5 active */
+ const uint8_t pdp_status2[] = { 0b00000000, 0b00000000 }; /* no active PDP NSAPI */
+ const uint8_t pdp_status3[] = { 0b00000000, 0b00000001 }; /* PDP NSAPI 8 active */
+
+ printf("Testing pdp_status_has_active_nsapis\n");
+
+ OSMO_ASSERT(pdp_status_has_active_nsapis(pdp_status1, pdp_status_len));
+ OSMO_ASSERT(!pdp_status_has_active_nsapis(pdp_status2, pdp_status_len));
+ OSMO_ASSERT(pdp_status_has_active_nsapis(pdp_status3, pdp_status_len));
+}
+
static struct log_info_cat gprs_categories[] = {
[DMM] = {
.name = "DMM",
@@ -2434,19 +1647,25 @@ static struct log_info info = {
.num_cat = ARRAY_SIZE(gprs_categories),
};
+static struct vty_app_info vty_info = {
+ .name = "testSGSN",
+};
+
int main(int argc, char **argv)
{
void *osmo_sgsn_ctx;
void *msgb_ctx;
- osmo_init_logging(&info);
osmo_sgsn_ctx = talloc_named_const(NULL, 0, "osmo_sgsn");
- tall_bsc_ctx = talloc_named_const(osmo_sgsn_ctx, 0, "bsc");
+ osmo_init_logging2(osmo_sgsn_ctx, &info);
+ tall_sgsn_ctx = talloc_named_const(osmo_sgsn_ctx, 0, "sgsn");
msgb_ctx = msgb_talloc_ctx_init(osmo_sgsn_ctx, 0);
sgsn_rate_ctr_init();
- sgsn_auth_init();
+ sgsn_auth_init(sgsn);
gprs_subscr_init(sgsn);
+ vty_init(&vty_info);
+ sgsn_vty_init(&sgsn->cfg);
test_llme();
test_subscriber();
@@ -2457,24 +1676,16 @@ int main(int argc, char **argv)
test_gmm_detach_no_mmctx();
test_gmm_detach_accept_unexpected();
test_gmm_status_no_mmctx();
- test_gmm_attach_acl();
- test_gmm_attach_subscr();
- test_gmm_attach_subscr_fake_auth();
- test_gmm_attach_subscr_real_auth();
- test_gmm_attach_subscr_gsup_auth(0);
- test_gmm_attach_subscr_gsup_auth(1);
- test_gmm_attach_subscr_real_gsup_auth(0);
test_gmm_reject();
test_gmm_cancel();
- test_gmm_ptmsi_allocation();
- test_gmm_routing_areas();
test_apn_matching();
test_ggsn_selection();
+ test_pdp_status_has_active_nsapis();
printf("Done\n");
talloc_report_full(osmo_sgsn_ctx, stderr);
OSMO_ASSERT(talloc_total_blocks(msgb_ctx) == 1);
- OSMO_ASSERT(talloc_total_blocks(tall_bsc_ctx) == 2);
+ OSMO_ASSERT(talloc_total_blocks(tall_sgsn_ctx) == 2);
return 0;
}