Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 1 | /* OsmoHLR SS/USSD implementation */ |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 2 | |
| 3 | /* (C) 2018 Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | #include <osmocom/core/talloc.h> |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 24 | #include <osmocom/core/timer.h> |
| 25 | #include <osmocom/gsm/gsup.h> |
| 26 | #include <osmocom/gsm/gsm0480.h> |
| 27 | #include <osmocom/gsm/protocol/gsm_04_80.h> |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 28 | #include <stdint.h> |
| 29 | #include <string.h> |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 30 | #include <errno.h> |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 31 | |
Neels Hofmeyr | 2f75803 | 2019-11-20 00:37:07 +0100 | [diff] [blame] | 32 | #include <osmocom/hlr/hlr.h> |
| 33 | #include <osmocom/hlr/hlr_ussd.h> |
| 34 | #include <osmocom/hlr/gsup_server.h> |
| 35 | #include <osmocom/hlr/gsup_router.h> |
| 36 | #include <osmocom/hlr/logging.h> |
| 37 | #include <osmocom/hlr/db.h> |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 38 | |
| 39 | /*********************************************************************** |
| 40 | * core data structures expressing config from VTY |
| 41 | ***********************************************************************/ |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 42 | |
| 43 | struct hlr_euse *euse_find(struct hlr *hlr, const char *name) |
| 44 | { |
| 45 | struct hlr_euse *euse; |
| 46 | |
| 47 | llist_for_each_entry(euse, &hlr->euse_list, list) { |
| 48 | if (!strcmp(euse->name, name)) |
| 49 | return euse; |
| 50 | } |
| 51 | return NULL; |
| 52 | } |
| 53 | |
| 54 | struct hlr_euse *euse_alloc(struct hlr *hlr, const char *name) |
| 55 | { |
| 56 | struct hlr_euse *euse = euse_find(hlr, name); |
| 57 | if (euse) |
| 58 | return NULL; |
| 59 | |
| 60 | euse = talloc_zero(hlr, struct hlr_euse); |
| 61 | euse->name = talloc_strdup(euse, name); |
| 62 | euse->hlr = hlr; |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 63 | llist_add_tail(&euse->list, &hlr->euse_list); |
| 64 | |
| 65 | return euse; |
| 66 | } |
| 67 | |
| 68 | void euse_del(struct hlr_euse *euse) |
| 69 | { |
| 70 | llist_del(&euse->list); |
| 71 | talloc_free(euse); |
| 72 | } |
| 73 | |
| 74 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 75 | struct hlr_ussd_route *ussd_route_find_prefix(struct hlr *hlr, const char *prefix) |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 76 | { |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 77 | struct hlr_ussd_route *rt; |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 78 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 79 | llist_for_each_entry(rt, &hlr->ussd_routes, list) { |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 80 | if (!strcmp(rt->prefix, prefix)) |
| 81 | return rt; |
| 82 | } |
| 83 | return NULL; |
| 84 | } |
| 85 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 86 | struct hlr_ussd_route *ussd_route_prefix_alloc_int(struct hlr *hlr, const char *prefix, |
| 87 | const struct hlr_iuse *iuse) |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 88 | { |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 89 | struct hlr_ussd_route *rt; |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 90 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 91 | if (ussd_route_find_prefix(hlr, prefix)) |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 92 | return NULL; |
| 93 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 94 | rt = talloc_zero(hlr, struct hlr_ussd_route); |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 95 | rt->prefix = talloc_strdup(rt, prefix); |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 96 | rt->u.iuse = iuse; |
| 97 | llist_add_tail(&rt->list, &hlr->ussd_routes); |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 98 | |
| 99 | return rt; |
| 100 | } |
| 101 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 102 | struct hlr_ussd_route *ussd_route_prefix_alloc_ext(struct hlr *hlr, const char *prefix, |
| 103 | struct hlr_euse *euse) |
| 104 | { |
| 105 | struct hlr_ussd_route *rt; |
| 106 | |
| 107 | if (ussd_route_find_prefix(hlr, prefix)) |
| 108 | return NULL; |
| 109 | |
| 110 | rt = talloc_zero(hlr, struct hlr_ussd_route); |
| 111 | rt->prefix = talloc_strdup(rt, prefix); |
| 112 | rt->is_external = true; |
| 113 | rt->u.euse = euse; |
| 114 | llist_add_tail(&rt->list, &hlr->ussd_routes); |
| 115 | |
| 116 | return rt; |
| 117 | } |
| 118 | |
| 119 | void ussd_route_del(struct hlr_ussd_route *rt) |
Harald Welte | 4956ae1 | 2018-06-15 22:04:28 +0200 | [diff] [blame] | 120 | { |
| 121 | llist_del(&rt->list); |
| 122 | talloc_free(rt); |
| 123 | } |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 124 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 125 | static struct hlr_ussd_route *ussd_route_lookup_7bit(struct hlr *hlr, const char *ussd_code) |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 126 | { |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 127 | struct hlr_ussd_route *rt; |
| 128 | llist_for_each_entry(rt, &hlr->ussd_routes, list) { |
| 129 | if (!strncmp(ussd_code, rt->prefix, strlen(rt->prefix))) { |
Vadim Yanitskiy | e6c839e | 2018-08-02 23:59:51 +0700 | [diff] [blame] | 130 | LOGP(DSS, LOGL_DEBUG, "Found %s '%s' (prefix '%s') for USSD " |
| 131 | "Code '%s'\n", rt->is_external ? "EUSE" : "IUSE", |
| 132 | rt->is_external ? rt->u.euse->name : rt->u.iuse->name, |
| 133 | rt->prefix, ussd_code); |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 134 | return rt; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 138 | LOGP(DSS, LOGL_DEBUG, "Could not find Route for USSD Code '%s'\n", ussd_code); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 139 | return NULL; |
| 140 | } |
| 141 | |
| 142 | /*********************************************************************** |
| 143 | * handling functions for individual GSUP messages |
| 144 | ***********************************************************************/ |
| 145 | |
Harald Welte | 97bfb65 | 2018-07-29 12:28:11 +0200 | [diff] [blame] | 146 | #define LOGPSS(ss, lvl, fmt, args...) \ |
Harald Welte | 95b96d4 | 2018-07-29 12:47:39 +0200 | [diff] [blame] | 147 | LOGP(DSS, lvl, "%s/0x%08x: " fmt, (ss)->imsi, (ss)->session_id, ## args) |
Harald Welte | 97bfb65 | 2018-07-29 12:28:11 +0200 | [diff] [blame] | 148 | |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 149 | struct ss_session { |
| 150 | /* link us to hlr->ss_sessions */ |
| 151 | struct llist_head list; |
| 152 | /* imsi of this session */ |
Neels Hofmeyr | e21b45a | 2019-03-18 21:04:23 +0100 | [diff] [blame] | 153 | char imsi[OSMO_IMSI_BUF_SIZE]; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 154 | /* ID of this session (unique per IMSI) */ |
| 155 | uint32_t session_id; |
| 156 | /* state of the session */ |
| 157 | enum osmo_gsup_session_state state; |
| 158 | /* time-out when we will delete the session */ |
| 159 | struct osmo_timer_list timeout; |
| 160 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 161 | /* is this USSD for an external handler (EUSE): true */ |
| 162 | bool is_external; |
| 163 | union { |
| 164 | /* external USSD Entity responsible for this session */ |
| 165 | struct hlr_euse *euse; |
| 166 | /* internal USSD Entity responsible for this session */ |
| 167 | const struct hlr_iuse *iuse; |
| 168 | } u; |
| 169 | |
Oliver Smith | 95abc2b | 2019-04-04 12:00:24 +0200 | [diff] [blame] | 170 | /* subscriber's vlr_number |
| 171 | * MO USSD: originating MSC's vlr_number |
| 172 | * MT USSD: looked up once per session and cached here */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 173 | struct osmo_ipa_name vlr_name; |
Neels Hofmeyr | f1fe94c | 2019-04-02 04:26:55 +0200 | [diff] [blame] | 174 | |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 175 | /* we don't keep a pointer to the osmo_gsup_{route,conn} towards the MSC/VLR here, |
| 176 | * as this might change during inter-VLR hand-over, and we simply look-up the serving MSC/VLR |
| 177 | * every time we receive an USSD component from the EUSE */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 178 | |
| 179 | struct osmo_gsup_req *initial_req_from_ms; |
| 180 | struct osmo_gsup_req *initial_req_from_euse; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | struct ss_session *ss_session_find(struct hlr *hlr, const char *imsi, uint32_t session_id) |
| 184 | { |
| 185 | struct ss_session *ss; |
| 186 | llist_for_each_entry(ss, &hlr->ss_sessions, list) { |
| 187 | if (!strcmp(ss->imsi, imsi) && ss->session_id == session_id) |
| 188 | return ss; |
| 189 | } |
| 190 | return NULL; |
| 191 | } |
| 192 | |
| 193 | void ss_session_free(struct ss_session *ss) |
| 194 | { |
| 195 | osmo_timer_del(&ss->timeout); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 196 | if (ss->initial_req_from_ms) |
| 197 | osmo_gsup_req_free(ss->initial_req_from_ms); |
| 198 | if (ss->initial_req_from_euse) |
| 199 | osmo_gsup_req_free(ss->initial_req_from_euse); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 200 | llist_del(&ss->list); |
| 201 | talloc_free(ss); |
| 202 | } |
| 203 | |
| 204 | static void ss_session_timeout(void *data) |
| 205 | { |
| 206 | struct ss_session *ss = data; |
| 207 | |
Harald Welte | 97bfb65 | 2018-07-29 12:28:11 +0200 | [diff] [blame] | 208 | LOGPSS(ss, LOGL_NOTICE, "SS Session Timeout, destroying\n"); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 209 | /* FIXME: should we send a ReturnError component to the MS? */ |
| 210 | ss_session_free(ss); |
| 211 | } |
| 212 | |
| 213 | struct ss_session *ss_session_alloc(struct hlr *hlr, const char *imsi, uint32_t session_id) |
| 214 | { |
| 215 | struct ss_session *ss; |
| 216 | |
| 217 | OSMO_ASSERT(!ss_session_find(hlr, imsi, session_id)); |
| 218 | |
| 219 | ss = talloc_zero(hlr, struct ss_session); |
| 220 | OSMO_ASSERT(ss); |
| 221 | |
| 222 | OSMO_STRLCPY_ARRAY(ss->imsi, imsi); |
| 223 | ss->session_id = session_id; |
Vadim Yanitskiy | e6ce52b | 2018-12-01 00:16:44 +0700 | [diff] [blame] | 224 | |
| 225 | /* Schedule self-destruction timer */ |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 226 | osmo_timer_setup(&ss->timeout, ss_session_timeout, ss); |
Vadim Yanitskiy | d157a56 | 2018-12-01 00:03:39 +0700 | [diff] [blame] | 227 | if (g_hlr->ncss_guard_timeout > 0) |
| 228 | osmo_timer_schedule(&ss->timeout, g_hlr->ncss_guard_timeout, 0); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 229 | |
| 230 | llist_add_tail(&ss->list, &hlr->ss_sessions); |
| 231 | return ss; |
| 232 | } |
| 233 | |
| 234 | /*********************************************************************** |
Harald Welte | 7266731 | 2018-07-29 12:38:09 +0200 | [diff] [blame] | 235 | * handling functions for encoding SS messages + wrapping them in GSUP |
| 236 | ***********************************************************************/ |
| 237 | |
Neels Hofmeyr | f1fe94c | 2019-04-02 04:26:55 +0200 | [diff] [blame] | 238 | /* Resolve the target MSC by ss->imsi and send GSUP message. */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 239 | static int ss_gsup_send_to_ms(struct ss_session *ss, struct osmo_gsup_server *gs, struct osmo_gsup_message *gsup) |
Neels Hofmeyr | f1fe94c | 2019-04-02 04:26:55 +0200 | [diff] [blame] | 240 | { |
| 241 | struct hlr_subscriber subscr = {}; |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 242 | struct msgb *msg; |
Neels Hofmeyr | f1fe94c | 2019-04-02 04:26:55 +0200 | [diff] [blame] | 243 | int rc; |
| 244 | |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 245 | if (ss->initial_req_from_ms) { |
| 246 | /* Use non-final osmo_gsup_req_respond() to not deallocate the ss->initial_req_from_ms */ |
| 247 | osmo_gsup_req_respond(ss->initial_req_from_ms, gsup, false, false); |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | msg = osmo_gsup_msgb_alloc("GSUP USSD FW"); |
| 252 | rc = osmo_gsup_encode(msg, gsup); |
| 253 | if (rc) { |
| 254 | LOGPSS(ss, LOGL_ERROR, "Failed to encode GSUP message\n"); |
| 255 | msgb_free(msg); |
| 256 | return rc; |
| 257 | } |
| 258 | |
Neels Hofmeyr | f1fe94c | 2019-04-02 04:26:55 +0200 | [diff] [blame] | 259 | /* Use vlr_number as looked up by the caller, or look up now. */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 260 | if (!ss->vlr_name.len) { |
Neels Hofmeyr | f1fe94c | 2019-04-02 04:26:55 +0200 | [diff] [blame] | 261 | rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr); |
| 262 | if (rc < 0) { |
| 263 | LOGPSS(ss, LOGL_ERROR, "Cannot find subscriber, cannot route GSUP message\n"); |
| 264 | msgb_free(msg); |
| 265 | return -EINVAL; |
| 266 | } |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 267 | osmo_ipa_name_set_str(&ss->vlr_name, subscr.vlr_number); |
Neels Hofmeyr | f1fe94c | 2019-04-02 04:26:55 +0200 | [diff] [blame] | 268 | } |
| 269 | |
Oliver Smith | 95abc2b | 2019-04-04 12:00:24 +0200 | [diff] [blame] | 270 | /* Check for empty string (all vlr_number strings end in "\0", because otherwise gsup_route_find() fails) */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 271 | if (ss->vlr_name.len <= 1) { |
Neels Hofmeyr | f1fe94c | 2019-04-02 04:26:55 +0200 | [diff] [blame] | 272 | LOGPSS(ss, LOGL_ERROR, "Cannot send GSUP message, no VLR number stored for subscriber\n"); |
| 273 | msgb_free(msg); |
| 274 | return -EINVAL; |
| 275 | } |
| 276 | |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 277 | LOGPSS(ss, LOGL_DEBUG, "Tx SS/USSD to VLR %s\n", osmo_ipa_name_to_str(&ss->vlr_name)); |
| 278 | return osmo_gsup_send_to_ipa_name(gs, &ss->vlr_name, msg); |
Neels Hofmeyr | f1fe94c | 2019-04-02 04:26:55 +0200 | [diff] [blame] | 279 | } |
| 280 | |
Harald Welte | 7266731 | 2018-07-29 12:38:09 +0200 | [diff] [blame] | 281 | static int ss_tx_to_ms(struct ss_session *ss, enum osmo_gsup_message_type gsup_msg_type, |
| 282 | bool final, struct msgb *ss_msg) |
| 283 | |
| 284 | { |
| 285 | struct osmo_gsup_message resp = {0}; |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 286 | int rc; |
Harald Welte | 7266731 | 2018-07-29 12:38:09 +0200 | [diff] [blame] | 287 | |
| 288 | resp.message_type = gsup_msg_type; |
| 289 | OSMO_STRLCPY_ARRAY(resp.imsi, ss->imsi); |
| 290 | if (final) |
| 291 | resp.session_state = OSMO_GSUP_SESSION_STATE_END; |
| 292 | else |
| 293 | resp.session_state = OSMO_GSUP_SESSION_STATE_CONTINUE; |
| 294 | resp.session_id = ss->session_id; |
| 295 | if (ss_msg) { |
| 296 | resp.ss_info = msgb_data(ss_msg); |
| 297 | resp.ss_info_len = msgb_length(ss_msg); |
| 298 | } |
| 299 | |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 300 | rc = ss_gsup_send_to_ms(ss, g_hlr->gs, &resp); |
Harald Welte | 7266731 | 2018-07-29 12:38:09 +0200 | [diff] [blame] | 301 | |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 302 | msgb_free(ss_msg); |
| 303 | return rc; |
Harald Welte | 7266731 | 2018-07-29 12:38:09 +0200 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | #if 0 |
| 307 | static int ss_tx_reject(struct ss_session *ss, int invoke_id, uint8_t problem_tag, |
| 308 | uint8_t problem_code) |
| 309 | { |
| 310 | struct msgb *msg = gsm0480_gen_reject(invoke_id, problem_tag, problem_code); |
| 311 | LOGPSS(ss, LOGL_NOTICE, "Tx Reject(%u, 0x%02x, 0x%02x)\n", invoke_id, |
| 312 | problem_tag, problem_code); |
| 313 | OSMO_ASSERT(msg); |
| 314 | return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, true, msg); |
| 315 | } |
| 316 | #endif |
| 317 | |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 318 | static int ss_tx_to_ms_error(struct ss_session *ss, uint8_t invoke_id, uint8_t error_code) |
Harald Welte | 7266731 | 2018-07-29 12:38:09 +0200 | [diff] [blame] | 319 | { |
| 320 | struct msgb *msg = gsm0480_gen_return_error(invoke_id, error_code); |
| 321 | LOGPSS(ss, LOGL_NOTICE, "Tx ReturnError(%u, 0x%02x)\n", invoke_id, error_code); |
| 322 | OSMO_ASSERT(msg); |
| 323 | return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, true, msg); |
| 324 | } |
| 325 | |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 326 | static int ss_tx_to_ms_ussd_7bit(struct ss_session *ss, bool final, uint8_t invoke_id, const char *text) |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 327 | { |
| 328 | struct msgb *msg = gsm0480_gen_ussd_resp_7bit(invoke_id, text); |
| 329 | LOGPSS(ss, LOGL_INFO, "Tx USSD '%s'\n", text); |
| 330 | OSMO_ASSERT(msg); |
| 331 | return ss_tx_to_ms(ss, OSMO_GSUP_MSGT_PROC_SS_RESULT, final, msg); |
| 332 | } |
| 333 | |
| 334 | /*********************************************************************** |
| 335 | * Internal USSD Handlers |
| 336 | ***********************************************************************/ |
| 337 | |
Neels Hofmeyr | 2f75803 | 2019-11-20 00:37:07 +0100 | [diff] [blame] | 338 | #include <osmocom/hlr/db.h> |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 339 | |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 340 | static int handle_ussd_own_msisdn(struct ss_session *ss, |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 341 | const struct osmo_gsup_message *gsup, const struct ss_request *req) |
| 342 | { |
| 343 | struct hlr_subscriber subscr; |
| 344 | char buf[GSM0480_USSD_7BIT_STRING_LEN+1]; |
| 345 | int rc; |
| 346 | |
| 347 | rc = db_subscr_get_by_imsi(g_hlr->dbc, ss->imsi, &subscr); |
| 348 | switch (rc) { |
| 349 | case 0: |
| 350 | if (strlen(subscr.msisdn) == 0) |
| 351 | snprintf(buf, sizeof(buf), "You have no MSISDN!"); |
| 352 | else |
Vadim Yanitskiy | 3adb33d | 2018-08-03 00:07:54 +0700 | [diff] [blame] | 353 | snprintf(buf, sizeof(buf), "Your extension is %s", subscr.msisdn); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 354 | ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id, buf); |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 355 | break; |
| 356 | case -ENOENT: |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 357 | ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER); |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 358 | break; |
| 359 | case -EIO: |
| 360 | default: |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 361 | ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_SYSTEM_FAILURE); |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 362 | break; |
| 363 | } |
| 364 | return 0; |
| 365 | } |
| 366 | |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 367 | static int handle_ussd_own_imsi(struct ss_session *ss, |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 368 | const struct osmo_gsup_message *gsup, const struct ss_request *req) |
| 369 | { |
| 370 | char buf[GSM0480_USSD_7BIT_STRING_LEN+1]; |
Vadim Yanitskiy | 3adb33d | 2018-08-03 00:07:54 +0700 | [diff] [blame] | 371 | snprintf(buf, sizeof(buf), "Your IMSI is %s", ss->imsi); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 372 | ss_tx_to_ms_ussd_7bit(ss, true, req->invoke_id, buf); |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | static const struct hlr_iuse hlr_iuses[] = { |
| 378 | { |
| 379 | .name = "own-msisdn", |
| 380 | .handle_ussd = handle_ussd_own_msisdn, |
| 381 | }, |
| 382 | { |
| 383 | .name = "own-imsi", |
| 384 | .handle_ussd = handle_ussd_own_imsi, |
| 385 | }, |
| 386 | }; |
| 387 | |
| 388 | const struct hlr_iuse *iuse_find(const char *name) |
| 389 | { |
| 390 | unsigned int i; |
| 391 | |
| 392 | for (i = 0; i < ARRAY_SIZE(hlr_iuses); i++) { |
| 393 | const struct hlr_iuse *iuse = &hlr_iuses[i]; |
| 394 | if (!strcmp(name, iuse->name)) |
| 395 | return iuse; |
| 396 | } |
| 397 | return NULL; |
| 398 | } |
Harald Welte | 7266731 | 2018-07-29 12:38:09 +0200 | [diff] [blame] | 399 | |
| 400 | |
| 401 | /*********************************************************************** |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 402 | * handling functions for individual GSUP messages |
| 403 | ***********************************************************************/ |
| 404 | |
| 405 | static bool ss_op_is_ussd(uint8_t opcode) |
| 406 | { |
| 407 | switch (opcode) { |
| 408 | case GSM0480_OP_CODE_PROCESS_USS_DATA: |
| 409 | case GSM0480_OP_CODE_PROCESS_USS_REQ: |
| 410 | case GSM0480_OP_CODE_USS_REQUEST: |
| 411 | case GSM0480_OP_CODE_USS_NOTIFY: |
| 412 | return true; |
| 413 | default: |
| 414 | return false; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | /* is this GSUP connection an EUSE (true) or not (false)? */ |
Neels Hofmeyr | c79bcde | 2019-12-04 01:04:32 +0100 | [diff] [blame] | 419 | static bool peer_name_is_euse(const struct osmo_cni_peer_id *peer_name) |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 420 | { |
Neels Hofmeyr | c79bcde | 2019-12-04 01:04:32 +0100 | [diff] [blame] | 421 | if (peer_name->type != OSMO_CNI_PEER_ID_IPA_NAME) |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 422 | return false; |
Neels Hofmeyr | c79bcde | 2019-12-04 01:04:32 +0100 | [diff] [blame] | 423 | if (peer_name->ipa_name.len <= 5) |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 424 | return false; |
Neels Hofmeyr | c79bcde | 2019-12-04 01:04:32 +0100 | [diff] [blame] | 425 | return strncmp((char *)(peer_name->ipa_name.val), "EUSE-", 5) == 0; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 426 | } |
| 427 | |
Neels Hofmeyr | c79bcde | 2019-12-04 01:04:32 +0100 | [diff] [blame] | 428 | static struct hlr_euse *euse_by_name(const struct osmo_cni_peer_id *peer_name) |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 429 | { |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 430 | if (!peer_name_is_euse(peer_name)) |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 431 | return NULL; |
| 432 | |
Neels Hofmeyr | c79bcde | 2019-12-04 01:04:32 +0100 | [diff] [blame] | 433 | /* above peer_name_is_euse() ensures this: */ |
| 434 | OSMO_ASSERT(peer_name->type == OSMO_CNI_PEER_ID_IPA_NAME); |
| 435 | |
| 436 | return euse_find(g_hlr, (const char*)(peer_name->ipa_name.val)+5); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 437 | } |
| 438 | |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 439 | static int handle_ss(struct ss_session *ss, bool is_euse_originated, const struct osmo_gsup_message *gsup, |
| 440 | const struct ss_request *req) |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 441 | { |
| 442 | uint8_t comp_type = gsup->ss_info[0]; |
| 443 | |
Harald Welte | 7f32f5f | 2018-07-29 12:43:49 +0200 | [diff] [blame] | 444 | LOGPSS(ss, LOGL_INFO, "SS CompType=%s, OpCode=%s\n", |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 445 | gsm0480_comp_type_name(comp_type), gsm0480_op_code_name(req->opcode)); |
Vadim Yanitskiy | 4a4bdcd | 2018-10-12 21:44:07 +0200 | [diff] [blame] | 446 | |
| 447 | /** |
| 448 | * FIXME: As we don't store any SS related information |
| 449 | * (e.g. call forwarding preferences) in the database, |
| 450 | * we don't handle "structured" SS requests at all. |
| 451 | */ |
| 452 | LOGPSS(ss, LOGL_NOTICE, "Structured SS requests are not supported, rejecting...\n"); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 453 | ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_FACILITY_NOT_SUPPORTED); |
Vadim Yanitskiy | 4a4bdcd | 2018-10-12 21:44:07 +0200 | [diff] [blame] | 454 | return -ENOTSUP; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 455 | } |
| 456 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 457 | /* Handle a USSD GSUP message for a given SS Session received from VLR or EUSE */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 458 | static int handle_ussd(struct ss_session *ss, bool is_euse_originated, const struct osmo_gsup_message *gsup, |
| 459 | const struct ss_request *req) |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 460 | { |
| 461 | uint8_t comp_type = gsup->ss_info[0]; |
| 462 | struct msgb *msg_out; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 463 | |
Harald Welte | 7f32f5f | 2018-07-29 12:43:49 +0200 | [diff] [blame] | 464 | LOGPSS(ss, LOGL_INFO, "USSD CompType=%s, OpCode=%s '%s'\n", |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 465 | gsm0480_comp_type_name(comp_type), gsm0480_op_code_name(req->opcode), |
| 466 | req->ussd_text); |
| 467 | |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 468 | if ((ss->is_external && !ss->u.euse) || !ss->u.iuse) { |
Harald Welte | 7f32f5f | 2018-07-29 12:43:49 +0200 | [diff] [blame] | 469 | LOGPSS(ss, LOGL_NOTICE, "USSD for unknown code '%s'\n", req->ussd_text); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 470 | ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_SS_NOT_AVAILABLE); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | if (is_euse_originated) { |
| 475 | /* Received from EUSE, Forward to VLR */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 476 | /* Need a non-const osmo_gsup_message, because sending might modify some (routing related?) parts. */ |
| 477 | struct osmo_gsup_message forward = *gsup; |
| 478 | ss_gsup_send_to_ms(ss, g_hlr->gs, &forward); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 479 | } else { |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 480 | /* Received from VLR (MS) */ |
| 481 | if (ss->is_external) { |
| 482 | /* Forward to EUSE */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 483 | struct osmo_ipa_name euse_name; |
| 484 | struct osmo_gsup_conn *conn; |
| 485 | osmo_ipa_name_set_str(&euse_name, "EUSE-%s", ss->u.euse->name); |
| 486 | conn = gsup_route_find_by_ipa_name(g_hlr->gs, &euse_name); |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 487 | if (!conn) { |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 488 | LOGPSS(ss, LOGL_ERROR, "Cannot find conn for EUSE %s\n", |
| 489 | osmo_ipa_name_to_str(&euse_name)); |
| 490 | ss_tx_to_ms_error(ss, req->invoke_id, GSM0480_ERR_CODE_SYSTEM_FAILURE); |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 491 | } else { |
Neels Hofmeyr | a7d0f87 | 2019-10-30 02:08:28 +0100 | [diff] [blame] | 492 | msg_out = osmo_gsup_msgb_alloc("GSUP USSD FW"); |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 493 | osmo_gsup_encode(msg_out, gsup); |
| 494 | osmo_gsup_conn_send(conn, msg_out); |
| 495 | } |
Harald Welte | 7266731 | 2018-07-29 12:38:09 +0200 | [diff] [blame] | 496 | } else { |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 497 | /* Handle internally */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 498 | ss->u.iuse->handle_ussd(ss, gsup, req); |
Vadim Yanitskiy | 9c8806a | 2018-11-30 08:11:19 +0700 | [diff] [blame] | 499 | /* Release session immediately */ |
| 500 | ss_session_free(ss); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 501 | } |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | |
| 508 | /* this function is called for any SS_REQ/SS_RESP messages from both the MSC/VLR side as well |
| 509 | * as from the EUSE side */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 510 | void rx_proc_ss_req(struct osmo_gsup_req *gsup_req) |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 511 | { |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 512 | struct hlr *hlr = g_hlr; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 513 | struct ss_session *ss; |
| 514 | struct ss_request req = {0}; |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 515 | const struct osmo_gsup_message *gsup = &gsup_req->gsup; |
| 516 | /* Remember whether this function should free the incoming gsup_req: if it is placed as ss->initial_req_from_*, |
| 517 | * do not free it here. If not, free it here. */ |
| 518 | struct osmo_gsup_req *free_gsup_req = gsup_req; |
| 519 | bool is_euse_originated = peer_name_is_euse(&gsup_req->source_name); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 520 | |
Harald Welte | 95b96d4 | 2018-07-29 12:47:39 +0200 | [diff] [blame] | 521 | LOGP(DSS, LOGL_DEBUG, "%s/0x%08x: Process SS (%s)\n", gsup->imsi, gsup->session_id, |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 522 | osmo_gsup_session_state_name(gsup->session_state)); |
| 523 | |
Neels Hofmeyr | c79bcde | 2019-12-04 01:04:32 +0100 | [diff] [blame] | 524 | if (gsup_req->source_name.type != OSMO_CNI_PEER_ID_IPA_NAME) { |
| 525 | LOGP(DSS, LOGL_ERROR, "%s/0x%082x: Unable to process SS request: Unsupported GSUP peer id type%s\n", |
| 526 | gsup->imsi, gsup->session_id, |
| 527 | osmo_cni_peer_id_type_name(gsup_req->source_name.type)); |
| 528 | osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_PROTO_ERR_UNSPEC, "error processing SS request"); |
| 529 | return; |
| 530 | } |
| 531 | |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 532 | /* decode and find out what kind of SS message it is */ |
| 533 | if (gsup->ss_info && gsup->ss_info_len) { |
| 534 | if (gsm0480_parse_facility_ie(gsup->ss_info, gsup->ss_info_len, &req)) { |
Harald Welte | 95b96d4 | 2018-07-29 12:47:39 +0200 | [diff] [blame] | 535 | LOGP(DSS, LOGL_ERROR, "%s/0x%082x: Unable to parse SS request: %s\n", |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 536 | gsup->imsi, gsup->session_id, |
| 537 | osmo_hexdump(gsup->ss_info, gsup->ss_info_len)); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 538 | osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_INV_MAND_INFO, "error parsing SS request"); |
| 539 | return; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 540 | } |
Vadim Yanitskiy | 937f583 | 2019-07-24 19:14:32 +0700 | [diff] [blame] | 541 | } else if (gsup->session_state != OSMO_GSUP_SESSION_STATE_END) { |
| 542 | LOGP(DSS, LOGL_ERROR, "%s/0x%082x: Missing SS payload for '%s'\n", |
| 543 | gsup->imsi, gsup->session_id, |
| 544 | osmo_gsup_session_state_name(gsup->session_state)); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 545 | osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_INV_MAND_INFO, "missing SS payload"); |
| 546 | return; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | switch (gsup->session_state) { |
| 550 | case OSMO_GSUP_SESSION_STATE_BEGIN: |
| 551 | /* Check for overlapping Session ID usage */ |
| 552 | if (ss_session_find(hlr, gsup->imsi, gsup->session_id)) { |
Harald Welte | 95b96d4 | 2018-07-29 12:47:39 +0200 | [diff] [blame] | 553 | LOGP(DSS, LOGL_ERROR, "%s/0x%08x: BEGIN with non-unique session ID!\n", |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 554 | gsup->imsi, gsup->session_id); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 555 | osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_INV_MAND_INFO, "BEGIN with non-unique session ID"); |
| 556 | return; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 557 | } |
| 558 | ss = ss_session_alloc(hlr, gsup->imsi, gsup->session_id); |
| 559 | if (!ss) { |
Harald Welte | 95b96d4 | 2018-07-29 12:47:39 +0200 | [diff] [blame] | 560 | LOGP(DSS, LOGL_ERROR, "%s/0x%08x: Unable to allocate SS session\n", |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 561 | gsup->imsi, gsup->session_id); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 562 | osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_NET_FAIL, "Unable to allocate SS session"); |
| 563 | return; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 564 | } |
Oliver Smith | 95abc2b | 2019-04-04 12:00:24 +0200 | [diff] [blame] | 565 | /* Get IPA name from VLR conn and save as ss->vlr_number */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 566 | if (!is_euse_originated) { |
| 567 | ss->initial_req_from_ms = gsup_req; |
| 568 | free_gsup_req = NULL; |
Neels Hofmeyr | c79bcde | 2019-12-04 01:04:32 +0100 | [diff] [blame] | 569 | OSMO_ASSERT(gsup_req->source_name.type == OSMO_CNI_PEER_ID_IPA_NAME); /* checked above */ |
| 570 | ss->vlr_name = gsup_req->source_name.ipa_name; |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 571 | } else { |
| 572 | ss->initial_req_from_euse = gsup_req; |
| 573 | free_gsup_req = NULL; |
Oliver Smith | 95abc2b | 2019-04-04 12:00:24 +0200 | [diff] [blame] | 574 | } |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 575 | if (ss_op_is_ussd(req.opcode)) { |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 576 | if (is_euse_originated) { |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 577 | /* EUSE->VLR: MT USSD. EUSE is known ('conn'), VLR is to be resolved */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 578 | ss->u.euse = euse_by_name(&gsup_req->source_name); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 579 | } else { |
| 580 | /* VLR->EUSE: MO USSD. VLR is known ('conn'), EUSE is to be resolved */ |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 581 | struct hlr_ussd_route *rt; |
| 582 | rt = ussd_route_lookup_7bit(hlr, (const char *) req.ussd_text); |
| 583 | if (rt) { |
| 584 | if (rt->is_external) { |
| 585 | ss->is_external = true; |
| 586 | ss->u.euse = rt->u.euse; |
| 587 | } else if (rt) { |
| 588 | ss->is_external = false; |
| 589 | ss->u.iuse = rt->u.iuse; |
| 590 | } |
Harald Welte | 1eb9869 | 2018-08-08 08:57:26 +0200 | [diff] [blame] | 591 | } else { |
| 592 | if (hlr->euse_default) { |
| 593 | ss->is_external = true; |
| 594 | ss->u.euse = hlr->euse_default; |
| 595 | } |
Harald Welte | dab544e | 2018-07-29 16:14:48 +0200 | [diff] [blame] | 596 | } |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 597 | } |
| 598 | /* dispatch unstructured SS to routing */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 599 | handle_ussd(ss, is_euse_originated, &gsup_req->gsup, &req); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 600 | } else { |
| 601 | /* dispatch non-call SS to internal code */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 602 | handle_ss(ss, is_euse_originated, &gsup_req->gsup, &req); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 603 | } |
| 604 | break; |
| 605 | case OSMO_GSUP_SESSION_STATE_CONTINUE: |
| 606 | ss = ss_session_find(hlr, gsup->imsi, gsup->session_id); |
| 607 | if (!ss) { |
Harald Welte | 95b96d4 | 2018-07-29 12:47:39 +0200 | [diff] [blame] | 608 | LOGP(DSS, LOGL_ERROR, "%s/0x%08x: CONTINUE for unknown SS session\n", |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 609 | gsup->imsi, gsup->session_id); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 610 | osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_INV_MAND_INFO, "CONTINUE for unknown SS session"); |
| 611 | return; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 612 | } |
Vadim Yanitskiy | e6ce52b | 2018-12-01 00:16:44 +0700 | [diff] [blame] | 613 | |
| 614 | /* Reschedule self-destruction timer */ |
| 615 | if (g_hlr->ncss_guard_timeout > 0) |
| 616 | osmo_timer_schedule(&ss->timeout, g_hlr->ncss_guard_timeout, 0); |
| 617 | |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 618 | if (ss_op_is_ussd(req.opcode)) { |
| 619 | /* dispatch unstructured SS to routing */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 620 | handle_ussd(ss, is_euse_originated, &gsup_req->gsup, &req); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 621 | } else { |
| 622 | /* dispatch non-call SS to internal code */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 623 | handle_ss(ss, is_euse_originated, &gsup_req->gsup, &req); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 624 | } |
| 625 | break; |
| 626 | case OSMO_GSUP_SESSION_STATE_END: |
| 627 | ss = ss_session_find(hlr, gsup->imsi, gsup->session_id); |
| 628 | if (!ss) { |
Harald Welte | 95b96d4 | 2018-07-29 12:47:39 +0200 | [diff] [blame] | 629 | LOGP(DSS, LOGL_ERROR, "%s/0x%08x: END for unknown SS session\n", |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 630 | gsup->imsi, gsup->session_id); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 631 | return; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 632 | } |
Vadim Yanitskiy | 937f583 | 2019-07-24 19:14:32 +0700 | [diff] [blame] | 633 | |
| 634 | /* SS payload is optional for END */ |
| 635 | if (gsup->ss_info && gsup->ss_info_len) { |
| 636 | if (ss_op_is_ussd(req.opcode)) { |
| 637 | /* dispatch unstructured SS to routing */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 638 | handle_ussd(ss, is_euse_originated, &gsup_req->gsup, &req); |
Vadim Yanitskiy | 937f583 | 2019-07-24 19:14:32 +0700 | [diff] [blame] | 639 | } else { |
| 640 | /* dispatch non-call SS to internal code */ |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 641 | handle_ss(ss, is_euse_originated, &gsup_req->gsup, &req); |
Vadim Yanitskiy | 937f583 | 2019-07-24 19:14:32 +0700 | [diff] [blame] | 642 | } |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 643 | } |
Vadim Yanitskiy | 937f583 | 2019-07-24 19:14:32 +0700 | [diff] [blame] | 644 | |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 645 | ss_session_free(ss); |
| 646 | break; |
| 647 | default: |
Harald Welte | 95b96d4 | 2018-07-29 12:47:39 +0200 | [diff] [blame] | 648 | LOGP(DSS, LOGL_ERROR, "%s/0x%08x: Unknown SS State %d\n", gsup->imsi, |
Harald Welte | 7f32f5f | 2018-07-29 12:43:49 +0200 | [diff] [blame] | 649 | gsup->session_id, gsup->session_state); |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 650 | break; |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 651 | } |
| 652 | |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 653 | if (free_gsup_req) |
| 654 | osmo_gsup_req_free(free_gsup_req); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 655 | } |
| 656 | |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 657 | void rx_proc_ss_error(struct osmo_gsup_req *req) |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 658 | { |
Neels Hofmeyr | ad868e2 | 2019-11-20 02:36:45 +0100 | [diff] [blame] | 659 | LOGP(DSS, LOGL_NOTICE, "%s/0x%08x: Process SS ERROR (%s)\n", req->gsup.imsi, req->gsup.session_id, |
| 660 | osmo_gsup_session_state_name(req->gsup.session_state)); |
Harald Welte | bb77939 | 2018-06-16 20:21:10 +0200 | [diff] [blame] | 661 | } |