blob: 34aa6348090a4eae072486f49fb64c1e847359fa [file] [log] [blame]
Vadim Yanitskiy27605852018-06-15 23:57:30 +07001/*
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
44static 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 Hofmeyrd0756b12018-09-28 02:41:39 +020050 gsup_expect_tx("04010809710000004026f0280102");
Vadim Yanitskiy27605852018-06-15 23:57:30 +070051 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");
56 gsup_rx("10010809710000004026f00804036470f1",
57 "12010809710000004026f0");
58 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
59
60 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
61 expect_bssap_clear();
62 gsup_rx("06010809710000004026f0", NULL);
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
68 vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI);
69 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
70 VERBOSE_ASSERT(strcmp(vsub->imsi, IMSI), == 0, "%d");
71 VERBOSE_ASSERT(vsub->lac, == 23, "%u");
72 vlr_subscr_put(vsub);
73
74 bss_sends_clear_complete();
75 EXPECT_CONN_COUNT(0);
76}
77
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +070078static void _test_ss_ussd_mo(enum ran_type via_ran)
Vadim Yanitskiy27605852018-06-15 23:57:30 +070079{
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");
90 OSMO_ASSERT(g_conn);
91 OSMO_ASSERT(g_conn->fi);
92 OSMO_ASSERT(g_conn->vsub);
93 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
94 EXPECT_ACCEPTED(true);
95
96 /* MT: GSM 04.80 RELEASE COMPLETE with Facility IE */
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +070097 gsup_expect_tx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */
98 "0108" "09710000004026f0" /* IMSI TLV */
99 "3004" "20000001" /* Session ID TLV */
100 "3101" "01" /* Session state: BEGIN */
101 "3515" FACILITY_IE_REQ);
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700102 dtap_expect_tx("8b2a" "1c27" FACILITY_IE_RSP);
103 expect_release_clear(via_ran);
104
105 /* MO: GSM 04.80 REGISTER with Facility IE and SS version IE */
106 ms_sends_msg("0b7b" "1c15" FACILITY_IE_REQ "7f0100");
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700107 gsup_rx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */
108 "0108" "09710000004026f0" /* IMSI TLV */
109 "3004" "20000001" /* Session ID TLV */
110 "3101" "03" /* Session state: END */
111 "3527" FACILITY_IE_RSP, NULL);
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700112 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
113 ASSERT_RELEASE_CLEAR(via_ran);
114
115 btw("all requests serviced, conn has been released");
116 bss_sends_clear_complete();
117 EXPECT_CONN_COUNT(0);
118}
119
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700120static void _test_ss_ussd_no(enum ran_type via_ran)
121{
122 struct vlr_subscr *vsub;
123
124 /* TODO: UTRAN requires auth and ciph */
125 rx_from_ran = via_ran;
126
127 /* Perform Location Update */
128 perform_lu();
129
130 BTW("after a while, HLR initiates SS/USSD session");
131
132 paging_expect_imsi(IMSI);
133 paging_sent = false;
134 vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI);
135 OSMO_ASSERT(vsub);
136 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
137
138 /* MT: GSM 04.80 REGISTER with request */
139 gsup_rx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */
140 "0108" "09710000004026f0" /* IMSI TLV */
141 "3004" "20000101" /* Session ID TLV */
142 "3101" "01" /* Session state: BEGIN */
143 "3515" FACILITY_IE_REQ, NULL);
144
145 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
146 vlr_subscr_put(vsub);
147 vsub = NULL;
148 VERBOSE_ASSERT(paging_sent, == true, "%d");
149 VERBOSE_ASSERT(paging_stopped, == false, "%d");
150
151 btw("the subscriber and its pending request should remain");
152 vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI);
153 OSMO_ASSERT(vsub);
154 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
155 vlr_subscr_put(vsub);
156
157 btw("MS replies with Paging Response, we deliver the NC/USSD");
158
159 dtap_expect_tx("0b3b" "1c15" FACILITY_IE_REQ);
160 ms_sends_msg("06270703305882089910070000006402");
161 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
162 VERBOSE_ASSERT(paging_stopped, == true, "%d");
163
164 btw("MS responds to SS/USSD request");
165
166 /* MO: GSM 04.80 FACILITY with response */
167 gsup_expect_tx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */
168 "0108" "09710000004026f0" /* IMSI TLV */
169 "3004" "20000101" /* Session ID TLV */
170 "3101" "02" /* Session state: CONTINUE */
171 "3527" FACILITY_IE_RSP);
172 ms_sends_msg("8b3a" "27" FACILITY_IE_RSP);
173 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
174 VERBOSE_ASSERT(paging_stopped, == true, "%d");
175
176 btw("HLR terminates the session");
177
178 /* MT: GSM 04.80 RELEASE COMPLETE without Facility IE */
179 dtap_expect_tx("0b2a");
180 expect_release_clear(via_ran);
181 gsup_rx("20" /* OSMO_GSUP_MSGT_PROC_SS_REQUEST */
182 "0108" "09710000004026f0" /* IMSI TLV */
183 "3004" "20000101" /* Session ID TLV */
184 "3101" "03", /* Session state: END */
185 NULL);
186 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
187 ASSERT_RELEASE_CLEAR(via_ran);
188
189 btw("all requests serviced, conn has been released");
190 bss_sends_clear_complete();
191 EXPECT_CONN_COUNT(0);
192}
193
194static void test_ss_ussd_mo_geran()
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700195{
196 comment_start();
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700197 _test_ss_ussd_mo(RAN_GERAN_A);
198 clear_vlr();
199 comment_end();
200}
201
202static void test_ss_ussd_no_geran()
203{
204 comment_start();
205 _test_ss_ussd_no(RAN_GERAN_A);
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700206 clear_vlr();
207 comment_end();
208}
209
210msc_vlr_test_func_t msc_vlr_tests[] = {
211 /* TODO: UTRAN requires auth and enc */
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700212 test_ss_ussd_mo_geran, /* MS-originated */
213 test_ss_ussd_no_geran, /* Network-originated */
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700214 NULL
215};