summaryrefslogtreecommitdiffstats
path: root/openbsc/tests/msc_vlr/msc_vlr_tests.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-05-20 21:59:55 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-06-18 17:49:00 +0200
commit61692adb2b0cd090c8fb8c81376a28bca099d079 (patch)
treebee3b3fde06ec8dc2a4cb9208ceae3465cea25a5 /openbsc/tests/msc_vlr/msc_vlr_tests.c
parent58774cba12ec4675e32fa524cfa631bdc690a9da (diff)
Implement IuCS (large refactoring and addition)
osmo-nitb becomes osmo-msc add DIUCS debug log constant add iucs.[hc] add msc vty, remove nitb vty add libiudummy, to avoid linking Iu deps in tests Use new msc_tx_dtap() instead of gsm0808_submit_dtap() libmgcp: add mgcpgw client API bridge calls via mgcpgw mgcp: hack RAB success from nano3G: patch first RTP payload The ip.access nano3G needs the first RTP payload's first two bytes to read hex 'e400', or it will reject the RAB assignment. Add flag patched_first_rtp_payload to mgcp_rtp_state to detect the first RTP payload on a stream, and overwrite its first bytes with e400. This should probably be configurable, but seems to not harm other femto cells (as long as we patch only the first RTP payload in each stream). Only do this when sending to the BTS side. Change-Id: Ie13ff348117e892d41b8355ab6c24915301eaeaf
Diffstat (limited to 'openbsc/tests/msc_vlr/msc_vlr_tests.c')
-rw-r--r--openbsc/tests/msc_vlr/msc_vlr_tests.c135
1 files changed, 98 insertions, 37 deletions
diff --git a/openbsc/tests/msc_vlr/msc_vlr_tests.c b/openbsc/tests/msc_vlr/msc_vlr_tests.c
index 8f045932e..8c25fe3f2 100644
--- a/openbsc/tests/msc_vlr/msc_vlr_tests.c
+++ b/openbsc/tests/msc_vlr/msc_vlr_tests.c
@@ -34,6 +34,8 @@
#include <openbsc/gsm_04_11.h>
#include <openbsc/bsc_subscriber.h>
#include <openbsc/debug.h>
+#include <openbsc/iu.h>
+#include <openbsc/iucs_ranap.h>
#include "msc_vlr_tests.h"
@@ -69,6 +71,7 @@ struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex)
void dtap_expect_tx(const char *hex)
{
+ /* Has the previously expected dtap been received? */
OSMO_ASSERT(!dtap_tx_expected);
if (!hex)
return;
@@ -132,6 +135,14 @@ struct gsm_subscriber_connection *conn_new(void)
conn = msc_subscr_con_allocate(net);
conn->bts = the_bts;
conn->via_ran = rx_from_ran;
+ if (conn->via_ran == RAN_UTRAN_IU) {
+ struct ue_conn_ctx *ue_ctx = talloc_zero(conn, struct ue_conn_ctx);
+ *ue_ctx = (struct ue_conn_ctx){
+ .link = (void*)0x23,
+ .conn_id = 42,
+ };
+ conn->iu.ue_ctx = ue_ctx;
+ }
return conn;
}
@@ -151,7 +162,7 @@ void rx_from_ms(struct msgb *msg)
if (!g_conn) {
log("new conn");
g_conn = conn_new();
- rc = net->bsc_api->compl_l3(g_conn, msg, 23);
+ rc = msc_compl_l3(g_conn, msg, 23);
if (rc == BSC_API_CONN_POL_REJECT) {
msc_subscr_con_free(g_conn);
g_conn = NULL;
@@ -159,9 +170,9 @@ void rx_from_ms(struct msgb *msg)
} else {
if ((gsm48_hdr_pdisc(gh) == GSM48_PDISC_RR)
&& (gsm48_hdr_msg_type(gh) == GSM48_MT_RR_CIPH_M_COMPL))
- net->bsc_api->cipher_mode_compl(g_conn, msg, 0);
+ msc_cipher_mode_compl(g_conn, msg, 0);
else
- net->bsc_api->dtap(g_conn, 23, msg);
+ msc_dtap(g_conn, 23, msg);
}
if (g_conn && !conn_exists(g_conn))
@@ -252,33 +263,38 @@ void paging_expect_tmsi(uint32_t tmsi)
paging_expecting_imsi = NULL;
}
-/* override, requires '-Wl,--wrap=paging_request' */
-int __real_paging_request(struct gsm_network *network, struct bsc_subscr *sub,
- int type, gsm_cbfn *cbfn, void *data);
-int __wrap_paging_request(struct gsm_network *network, struct bsc_subscr *sub,
- int type, gsm_cbfn *cbfn, void *data)
+int _paging_sent(enum ran_type via_ran, const char *imsi, uint32_t tmsi, uint32_t lac)
{
- log("BTS/BSC sends out paging request to %s for channel type %d",
- bsc_subscr_name(sub), type);
+ log("%s sends out paging request to IMSI %s, TMSI 0x%08x, LAC %u",
+ ran_type_name(via_ran), imsi, tmsi, lac);
OSMO_ASSERT(paging_expecting_imsi || (paging_expecting_tmsi != GSM_RESERVED_TMSI));
if (paging_expecting_imsi)
- VERBOSE_ASSERT(strcmp(paging_expecting_imsi, sub->imsi), == 0, "%d");
- if (paging_expecting_tmsi != GSM_RESERVED_TMSI)
- VERBOSE_ASSERT(paging_expecting_tmsi, == sub->tmsi, "0x%08x");
+ VERBOSE_ASSERT(strcmp(paging_expecting_imsi, imsi), == 0, "%d");
+ if (paging_expecting_tmsi != GSM_RESERVED_TMSI) {
+ VERBOSE_ASSERT(paging_expecting_tmsi, == tmsi, "0x%08x");
+ }
paging_sent = true;
paging_stopped = false;
return 1;
}
-/* override, requires '-Wl,--wrap=paging_request_stop' */
-void __real_paging_request_stop(struct gsm_bts *_bts,
- struct vlr_subscr *vsub,
- struct gsm_subscriber_connection *conn,
- struct msgb *msg);
-void __wrap_paging_request_stop(struct gsm_bts *_bts,
- struct vlr_subscr *vsub,
- struct gsm_subscriber_connection *conn,
- struct msgb *msg)
+/* override, requires '-Wl,--wrap=iu_page_cs' */
+int __real_iu_page_cs(const char *imsi, const uint32_t *tmsi, uint16_t lac);
+int __wrap_iu_page_cs(const char *imsi, const uint32_t *tmsi, uint16_t lac)
+{
+ return _paging_sent(RAN_UTRAN_IU, imsi, tmsi ? *tmsi : GSM_RESERVED_TMSI, lac);
+}
+
+/* override, requires '-Wl,--wrap=a_page' */
+int __real_a_page(const char *imsi, uint32_t tmsi, uint16_t lac);
+int __wrap_a_page(const char *imsi, uint32_t tmsi, uint16_t lac)
+{
+ return _paging_sent(RAN_GERAN_A, imsi, tmsi, lac);
+}
+
+/* override, requires '-Wl,--wrap=msc_stop_paging' */
+void __real_msc_stop_paging(struct vlr_subscr *vsub);
+void __wrap_msc_stop_paging(struct vlr_subscr *vsub)
{
paging_stopped = true;
}
@@ -347,6 +363,16 @@ static struct log_info_cat test_categories[] = {
.description = "Reference Counting",
.enabled = 1, .loglevel = LOGL_DEBUG,
},
+ [DPAG] = {
+ .name = "DPAG",
+ .description = "Paging Subsystem",
+ .enabled = 1, .loglevel = LOGL_DEBUG,
+ },
+ [DIUCS] = {
+ .name = "DIUCS",
+ .description = "Iu-CS Protocol",
+ .enabled = 1, .loglevel = LOGL_DEBUG,
+ },
};
static struct log_info info = {
@@ -398,13 +424,11 @@ int __wrap_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg)
return 0;
}
-/* override, requires '-Wl,--wrap=gsm0808_submit_dtap' */
-int __real_gsm0808_submit_dtap(struct gsm_subscriber_connection *conn,
- struct msgb *msg, int link_id, int allow_sacch);
-int __wrap_gsm0808_submit_dtap(struct gsm_subscriber_connection *conn,
- struct msgb *msg, int link_id, int allow_sacch)
+int _validate_dtap(struct msgb *msg, enum ran_type to_ran)
{
- btw("DTAP --> MS: %s", osmo_hexdump_nospc(msg->data, msg->len));
+ btw("DTAP --%s--> MS: %s",
+ ran_type_name(to_ran),
+ osmo_hexdump_nospc(msg->data, msg->len));
OSMO_ASSERT(dtap_tx_expected);
if (msg->len != dtap_tx_expected->len
@@ -424,6 +448,20 @@ int __wrap_gsm0808_submit_dtap(struct gsm_subscriber_connection *conn,
return 0;
}
+/* override, requires '-Wl,--wrap=iu_tx' */
+int __real_iu_tx(struct msgb *msg, uint8_t sapi);
+int __wrap_iu_tx(struct msgb *msg, uint8_t sapi)
+{
+ return _validate_dtap(msg, RAN_UTRAN_IU);
+}
+
+/* override, requires '-Wl,--wrap=a_tx' */
+int __real_a_tx(struct msgb *msg, uint8_t sapi);
+int __wrap_a_tx(struct msgb *msg, uint8_t sapi)
+{
+ return _validate_dtap(msg, RAN_GERAN_A);
+}
+
static int fake_vlr_tx_lu_acc(void *msc_conn_ref, uint32_t send_tmsi)
{
struct gsm_subscriber_connection *conn = msc_conn_ref;
@@ -523,17 +561,40 @@ static int fake_vlr_tx_ciph_mode_cmd(void *msc_conn_ref, enum vlr_ciph ciph,
* gsm0808_cipher_mode() directly. When the MSCSPLIT is ready, check
* the tx bytes in the sense of dtap_expect_tx() above. */
struct gsm_subscriber_connection *conn = msc_conn_ref;
- btw("sending Ciphering Mode Command for %s: cipher=%s kc=%s"
- " retrieve_imeisv=%d",
- vlr_subscr_name(conn->vsub),
- vlr_ciph_name(conn->network->a5_encryption),
- osmo_hexdump_nospc(conn->vsub->last_tuple->vec.kc, 8),
- retrieve_imeisv);
+ switch (conn->via_ran) {
+ case RAN_GERAN_A:
+ btw("sending Ciphering Mode Command for %s: cipher=%s kc=%s"
+ " retrieve_imeisv=%d",
+ vlr_subscr_name(conn->vsub),
+ vlr_ciph_name(conn->network->a5_encryption),
+ osmo_hexdump_nospc(conn->vsub->last_tuple->vec.kc, 8),
+ retrieve_imeisv);
+ break;
+ case RAN_UTRAN_IU:
+ btw("sending SecurityModeControl for %s",
+ vlr_subscr_name(conn->vsub));
+ break;
+ default:
+ btw("UNKNOWN RAN TYPE %d", conn->via_ran);
+ OSMO_ASSERT(false);
+ return -1;
+ }
cipher_mode_cmd_sent = true;
cipher_mode_cmd_sent_with_imeisv = retrieve_imeisv;
return 0;
}
+void ms_sends_security_mode_complete()
+{
+ OSMO_ASSERT(g_conn);
+ OSMO_ASSERT(g_conn->via_ran == RAN_UTRAN_IU);
+ OSMO_ASSERT(g_conn->iu.ue_ctx);
+ /* TODO mock IEs or call vlr callback directly */
+ iucs_rx_ranap_event(g_conn->network, g_conn->iu.ue_ctx,
+ IU_EVENT_SECURITY_MODE_COMPLETE,
+ NULL);
+}
+
const struct timeval fake_time_start_time = { 123, 456 };
void fake_time_start()
@@ -622,7 +683,7 @@ void run_tests(int nr)
if (cmdline_opts.verbose)
fprintf(stderr, "(test nr %d)\n", test_nr + 1);
- check_talloc(msgb_ctx, tall_bsc_ctx, 75);
+ check_talloc(msgb_ctx, tall_bsc_ctx, 9);
} while(0);
}
@@ -643,8 +704,6 @@ int main(int argc, char **argv)
log_set_print_category(osmo_stderr_target, 1);
net = gsm_network_init(tall_bsc_ctx, 1, 1, fake_mncc_recv);
- bsc_api_init(net, msc_bsc_api());
- the_bts = gsm_bts_alloc(net);
net->gsup_server_addr_str = talloc_strdup(net, "no_gsup_server");
net->gsup_server_port = 0;
@@ -663,6 +722,8 @@ int main(int argc, char **argv)
net->vlr->ops.tx_auth_rej = fake_vlr_tx_auth_rej;
net->vlr->ops.set_ciph_mode = fake_vlr_tx_ciph_mode_cmd;
+ clear_vlr();
+
if (optind >= argc)
run_tests(-1);
else {