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" |
| 24 | |
| 25 | #define IMSI "901700000004620" |
| 26 | |
| 27 | #define FACILITY_IE_REQ \ |
| 28 | "a113" /* Invoke component, len=19 */ \ |
| 29 | "020101" /* InvokeID=1 */ \ |
| 30 | "02013b" /* OpCode=GSM0480_OP_CODE_PROCESS_USS_REQ */ \ |
| 31 | "300b" /* Sequence tag, len=11 */ \ |
| 32 | "04010f" /* DCS: Default 7-bit alphabet */ \ |
| 33 | "0406aa510c061b01" /* USSD text: *#100#, len=6 */ |
| 34 | |
| 35 | #define FACILITY_IE_RSP \ |
| 36 | "a225" /* ReturnResult, len=37 */ \ |
| 37 | "020101" /* InvokeID=1 */ \ |
| 38 | "3020" /* Sequence tag, len=32 */ \ |
| 39 | "02013b" /* OpCode=GSM0480_OP_CODE_PROCESS_USS_REQ */ \ |
| 40 | "301b" /* Sequence tag, len=27 */ \ |
| 41 | "04010f" /* DCS: Default 7-bit alphabet */ \ |
| 42 | "0416d9775d0e2ae3e965f73cfd7683d27310cd06bbc51a0d" |
| 43 | |
| 44 | static void perform_lu(void) |
| 45 | { |
| 46 | struct vlr_subscr *vsub; |
| 47 | |
| 48 | btw("Location Update request causes a GSUP LU request to HLR"); |
| 49 | lu_result_sent = RES_NONE; |
Neels Hofmeyr | 63b2464 | 2019-12-12 01:31:04 +0100 | [diff] [blame] | 50 | gsup_expect_tx("04010809710000004026f0" CN_DOMAIN VLR_TO_HLR); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 51 | ms_sends_msg("050802008168000130089910070000006402"); |
| 52 | OSMO_ASSERT(gsup_tx_confirmed); |
| 53 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 54 | |
| 55 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 56 | gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR, |
| 57 | "12010809710000004026f0" VLR_TO_HLR); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 58 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 59 | |
| 60 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 61 | expect_bssap_clear(); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 62 | gsup_rx("06010809710000004026f0"HLR_TO_VLR, NULL); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 63 | |
| 64 | btw("LU was successful, and the conn has already been closed"); |
| 65 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 66 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
| 67 | |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 68 | vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI, __func__); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 69 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 70 | VERBOSE_ASSERT(strcmp(vsub->imsi, IMSI), == 0, "%d"); |
Max | 7d41d87 | 2018-12-19 11:48:33 +0100 | [diff] [blame] | 71 | VAL_ASSERT("LAC", vsub->cgi.lai.lac, == 23, "%u"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 72 | vlr_subscr_put(vsub, __func__); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 73 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 74 | ran_sends_clear_complete(); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 75 | EXPECT_CONN_COUNT(0); |
| 76 | } |
| 77 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 78 | static void _test_ss_ussd_mo(enum osmo_rat_type via_ran) |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 79 | { |
| 80 | /* TODO: UTRAN requires auth and ciph */ |
| 81 | rx_from_ran = via_ran; |
| 82 | |
| 83 | /* Perform Location Update */ |
| 84 | perform_lu(); |
| 85 | |
| 86 | BTW("after a while, a new conn sends a CM Service Request"); |
| 87 | |
| 88 | cm_service_result_sent = RES_NONE; |
| 89 | ms_sends_msg("05247803305886089910070000006402"); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 90 | VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d"); |
| 91 | EXPECT_ACCEPTED(true); |
| 92 | |
| 93 | /* MT: GSM 04.80 RELEASE COMPLETE with Facility IE */ |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 94 | gsup_expect_tx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */ |
| 95 | "0108" "09710000004026f0" /* IMSI TLV */ |
| 96 | "3004" "20000001" /* Session ID TLV */ |
| 97 | "3101" "01" /* Session state: BEGIN */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 98 | "3515" FACILITY_IE_REQ MSC_USSD_TO_EUSE); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 99 | dtap_expect_tx("8b2a" "1c27" FACILITY_IE_RSP); |
| 100 | expect_release_clear(via_ran); |
| 101 | |
| 102 | /* MO: GSM 04.80 REGISTER with Facility IE and SS version IE */ |
| 103 | ms_sends_msg("0b7b" "1c15" FACILITY_IE_REQ "7f0100"); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 104 | gsup_rx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */ |
| 105 | "0108" "09710000004026f0" /* IMSI TLV */ |
| 106 | "3004" "20000001" /* Session ID TLV */ |
| 107 | "3101" "03" /* Session state: END */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 108 | "3527" FACILITY_IE_RSP EUSE_TO_MSC_USSD, NULL); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 109 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 110 | ASSERT_RELEASE_CLEAR(via_ran); |
| 111 | |
| 112 | btw("all requests serviced, conn has been released"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 113 | ran_sends_clear_complete(); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 114 | EXPECT_CONN_COUNT(0); |
| 115 | } |
| 116 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 117 | static void _test_ss_ussd_no(enum osmo_rat_type via_ran) |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 118 | { |
| 119 | struct vlr_subscr *vsub; |
| 120 | |
| 121 | /* TODO: UTRAN requires auth and ciph */ |
| 122 | rx_from_ran = via_ran; |
| 123 | |
| 124 | /* Perform Location Update */ |
| 125 | perform_lu(); |
| 126 | |
| 127 | BTW("after a while, HLR initiates SS/USSD session"); |
| 128 | |
| 129 | paging_expect_imsi(IMSI); |
| 130 | paging_sent = false; |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 131 | vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI, __func__); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 132 | OSMO_ASSERT(vsub); |
| 133 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 134 | |
| 135 | /* MT: GSM 04.80 REGISTER with request */ |
| 136 | gsup_rx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */ |
| 137 | "0108" "09710000004026f0" /* IMSI TLV */ |
| 138 | "3004" "20000101" /* Session ID TLV */ |
| 139 | "3101" "01" /* Session state: BEGIN */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 140 | "3515" FACILITY_IE_REQ EUSE_TO_MSC_USSD, NULL); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 141 | |
| 142 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 143 | vlr_subscr_put(vsub, __func__); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 144 | vsub = NULL; |
| 145 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 146 | |
| 147 | btw("the subscriber and its pending request should remain"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 148 | vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI, __func__); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 149 | OSMO_ASSERT(vsub); |
| 150 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 151 | vlr_subscr_put(vsub, __func__); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 152 | |
| 153 | btw("MS replies with Paging Response, we deliver the NC/USSD"); |
| 154 | |
| 155 | dtap_expect_tx("0b3b" "1c15" FACILITY_IE_REQ); |
| 156 | ms_sends_msg("06270703305882089910070000006402"); |
| 157 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 158 | |
| 159 | btw("MS responds to SS/USSD request"); |
| 160 | |
| 161 | /* MO: GSM 04.80 FACILITY with response */ |
| 162 | gsup_expect_tx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */ |
| 163 | "0108" "09710000004026f0" /* IMSI TLV */ |
| 164 | "3004" "20000101" /* Session ID TLV */ |
| 165 | "3101" "02" /* Session state: CONTINUE */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 166 | "3527" FACILITY_IE_RSP MSC_USSD_TO_EUSE); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 167 | ms_sends_msg("8b3a" "27" FACILITY_IE_RSP); |
| 168 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 169 | |
| 170 | btw("HLR terminates the session"); |
| 171 | |
| 172 | /* MT: GSM 04.80 RELEASE COMPLETE without Facility IE */ |
| 173 | dtap_expect_tx("0b2a"); |
| 174 | expect_release_clear(via_ran); |
| 175 | gsup_rx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */ |
| 176 | "0108" "09710000004026f0" /* IMSI TLV */ |
| 177 | "3004" "20000101" /* Session ID TLV */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 178 | "3101" "03" EUSE_TO_MSC_USSD, /* Session state: END */ |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 179 | NULL); |
| 180 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 181 | ASSERT_RELEASE_CLEAR(via_ran); |
| 182 | |
| 183 | btw("all requests serviced, conn has been released"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 184 | ran_sends_clear_complete(); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 185 | EXPECT_CONN_COUNT(0); |
| 186 | } |
| 187 | |
| 188 | static void test_ss_ussd_mo_geran() |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 189 | { |
| 190 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 191 | _test_ss_ussd_mo(OSMO_RAT_GERAN_A); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 192 | clear_vlr(); |
| 193 | comment_end(); |
| 194 | } |
| 195 | |
| 196 | static void test_ss_ussd_no_geran() |
| 197 | { |
| 198 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 199 | _test_ss_ussd_no(OSMO_RAT_GERAN_A); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 200 | clear_vlr(); |
| 201 | comment_end(); |
| 202 | } |
| 203 | |
| 204 | msc_vlr_test_func_t msc_vlr_tests[] = { |
| 205 | /* TODO: UTRAN requires auth and enc */ |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 206 | test_ss_ussd_mo_geran, /* MS-originated */ |
| 207 | test_ss_ussd_no_geran, /* Network-originated */ |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 208 | NULL |
| 209 | }; |