Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 1 | /* |
| 2 | * Osmocom MSC+VLR end-to-end tests |
| 3 | * |
| 4 | * (C) 2018 by Vadim Yanitskiy <axilirator@gmail.com> |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU Affero General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include "msc_vlr_tests.h" |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 24 | #include "stubs.h" |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 25 | |
| 26 | #define IMSI "901700000004620" |
| 27 | |
| 28 | #define FACILITY_IE_REQ \ |
| 29 | "a113" /* Invoke component, len=19 */ \ |
| 30 | "020101" /* InvokeID=1 */ \ |
| 31 | "02013b" /* OpCode=GSM0480_OP_CODE_PROCESS_USS_REQ */ \ |
| 32 | "300b" /* Sequence tag, len=11 */ \ |
| 33 | "04010f" /* DCS: Default 7-bit alphabet */ \ |
| 34 | "0406aa510c061b01" /* USSD text: *#100#, len=6 */ |
| 35 | |
| 36 | #define FACILITY_IE_RSP \ |
| 37 | "a225" /* ReturnResult, len=37 */ \ |
| 38 | "020101" /* InvokeID=1 */ \ |
| 39 | "3020" /* Sequence tag, len=32 */ \ |
| 40 | "02013b" /* OpCode=GSM0480_OP_CODE_PROCESS_USS_REQ */ \ |
| 41 | "301b" /* Sequence tag, len=27 */ \ |
| 42 | "04010f" /* DCS: Default 7-bit alphabet */ \ |
| 43 | "0416d9775d0e2ae3e965f73cfd7683d27310cd06bbc51a0d" |
| 44 | |
| 45 | static void perform_lu(void) |
| 46 | { |
| 47 | struct vlr_subscr *vsub; |
| 48 | |
| 49 | btw("Location Update request causes a GSUP LU request to HLR"); |
| 50 | lu_result_sent = RES_NONE; |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 51 | gsup_expect_tx("04010809710000004026f0280102"); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 52 | ms_sends_msg("050802008168000130089910070000006402"); |
| 53 | OSMO_ASSERT(gsup_tx_confirmed); |
| 54 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 55 | |
| 56 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 57 | gsup_rx("10010809710000004026f00804036470f1", |
| 58 | "12010809710000004026f0"); |
| 59 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 60 | |
| 61 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 62 | expect_bssap_clear(); |
| 63 | gsup_rx("06010809710000004026f0", NULL); |
| 64 | |
| 65 | btw("LU was successful, and the conn has already been closed"); |
| 66 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 67 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
| 68 | |
| 69 | vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI); |
| 70 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 71 | VERBOSE_ASSERT(strcmp(vsub->imsi, IMSI), == 0, "%d"); |
Max | 7d41d87 | 2018-12-19 11:48:33 +0100 | [diff] [blame] | 72 | VAL_ASSERT("LAC", vsub->cgi.lai.lac, == 23, "%u"); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 73 | vlr_subscr_put(vsub); |
| 74 | |
| 75 | bss_sends_clear_complete(); |
| 76 | EXPECT_CONN_COUNT(0); |
| 77 | } |
| 78 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 79 | static void _test_ss_ussd_mo(enum osmo_rat_type via_ran) |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 80 | { |
| 81 | /* TODO: UTRAN requires auth and ciph */ |
| 82 | rx_from_ran = via_ran; |
| 83 | |
| 84 | /* Perform Location Update */ |
| 85 | perform_lu(); |
| 86 | |
| 87 | BTW("after a while, a new conn sends a CM Service Request"); |
| 88 | |
| 89 | cm_service_result_sent = RES_NONE; |
| 90 | ms_sends_msg("05247803305886089910070000006402"); |
| 91 | OSMO_ASSERT(g_conn); |
| 92 | OSMO_ASSERT(g_conn->fi); |
| 93 | OSMO_ASSERT(g_conn->vsub); |
| 94 | VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d"); |
| 95 | EXPECT_ACCEPTED(true); |
| 96 | |
| 97 | /* MT: GSM 04.80 RELEASE COMPLETE with Facility IE */ |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 98 | gsup_expect_tx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */ |
| 99 | "0108" "09710000004026f0" /* IMSI TLV */ |
| 100 | "3004" "20000001" /* Session ID TLV */ |
| 101 | "3101" "01" /* Session state: BEGIN */ |
| 102 | "3515" FACILITY_IE_REQ); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 103 | dtap_expect_tx("8b2a" "1c27" FACILITY_IE_RSP); |
| 104 | expect_release_clear(via_ran); |
| 105 | |
| 106 | /* MO: GSM 04.80 REGISTER with Facility IE and SS version IE */ |
| 107 | ms_sends_msg("0b7b" "1c15" FACILITY_IE_REQ "7f0100"); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 108 | gsup_rx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */ |
| 109 | "0108" "09710000004026f0" /* IMSI TLV */ |
| 110 | "3004" "20000001" /* Session ID TLV */ |
| 111 | "3101" "03" /* Session state: END */ |
| 112 | "3527" FACILITY_IE_RSP, NULL); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 113 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 114 | ASSERT_RELEASE_CLEAR(via_ran); |
| 115 | |
| 116 | btw("all requests serviced, conn has been released"); |
| 117 | bss_sends_clear_complete(); |
| 118 | EXPECT_CONN_COUNT(0); |
| 119 | } |
| 120 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 121 | static void _test_ss_ussd_no(enum osmo_rat_type via_ran) |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 122 | { |
| 123 | struct vlr_subscr *vsub; |
| 124 | |
| 125 | /* TODO: UTRAN requires auth and ciph */ |
| 126 | rx_from_ran = via_ran; |
| 127 | |
| 128 | /* Perform Location Update */ |
| 129 | perform_lu(); |
| 130 | |
| 131 | BTW("after a while, HLR initiates SS/USSD session"); |
| 132 | |
| 133 | paging_expect_imsi(IMSI); |
| 134 | paging_sent = false; |
| 135 | vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI); |
| 136 | OSMO_ASSERT(vsub); |
| 137 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 138 | |
| 139 | /* MT: GSM 04.80 REGISTER with request */ |
| 140 | gsup_rx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */ |
| 141 | "0108" "09710000004026f0" /* IMSI TLV */ |
| 142 | "3004" "20000101" /* Session ID TLV */ |
| 143 | "3101" "01" /* Session state: BEGIN */ |
| 144 | "3515" FACILITY_IE_REQ, NULL); |
| 145 | |
| 146 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 147 | vlr_subscr_put(vsub); |
| 148 | vsub = NULL; |
| 149 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 150 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 151 | |
| 152 | btw("the subscriber and its pending request should remain"); |
| 153 | vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI); |
| 154 | OSMO_ASSERT(vsub); |
| 155 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 156 | vlr_subscr_put(vsub); |
| 157 | |
| 158 | btw("MS replies with Paging Response, we deliver the NC/USSD"); |
| 159 | |
| 160 | dtap_expect_tx("0b3b" "1c15" FACILITY_IE_REQ); |
| 161 | ms_sends_msg("06270703305882089910070000006402"); |
| 162 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 163 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 164 | |
| 165 | btw("MS responds to SS/USSD request"); |
| 166 | |
| 167 | /* MO: GSM 04.80 FACILITY with response */ |
| 168 | gsup_expect_tx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */ |
| 169 | "0108" "09710000004026f0" /* IMSI TLV */ |
| 170 | "3004" "20000101" /* Session ID TLV */ |
| 171 | "3101" "02" /* Session state: CONTINUE */ |
| 172 | "3527" FACILITY_IE_RSP); |
| 173 | ms_sends_msg("8b3a" "27" FACILITY_IE_RSP); |
| 174 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 175 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 176 | |
| 177 | btw("HLR terminates the session"); |
| 178 | |
| 179 | /* MT: GSM 04.80 RELEASE COMPLETE without Facility IE */ |
| 180 | dtap_expect_tx("0b2a"); |
| 181 | expect_release_clear(via_ran); |
| 182 | gsup_rx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */ |
| 183 | "0108" "09710000004026f0" /* IMSI TLV */ |
| 184 | "3004" "20000101" /* Session ID TLV */ |
| 185 | "3101" "03", /* Session state: END */ |
| 186 | NULL); |
| 187 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 188 | ASSERT_RELEASE_CLEAR(via_ran); |
| 189 | |
| 190 | btw("all requests serviced, conn has been released"); |
| 191 | bss_sends_clear_complete(); |
| 192 | EXPECT_CONN_COUNT(0); |
| 193 | } |
| 194 | |
| 195 | static void test_ss_ussd_mo_geran() |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 196 | { |
| 197 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 198 | _test_ss_ussd_mo(OSMO_RAT_GERAN_A); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 199 | clear_vlr(); |
| 200 | comment_end(); |
| 201 | } |
| 202 | |
| 203 | static void test_ss_ussd_no_geran() |
| 204 | { |
| 205 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 206 | _test_ss_ussd_no(OSMO_RAT_GERAN_A); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 207 | clear_vlr(); |
| 208 | comment_end(); |
| 209 | } |
| 210 | |
| 211 | msc_vlr_test_func_t msc_vlr_tests[] = { |
| 212 | /* TODO: UTRAN requires auth and enc */ |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 213 | test_ss_ussd_mo_geran, /* MS-originated */ |
| 214 | test_ss_ussd_no_geran, /* Network-originated */ |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 215 | NULL |
| 216 | }; |