Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 1 | /* Network-specific handling of mobile-originated USSDs. */ |
| 2 | |
| 3 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
| 4 | * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 5 | * (C) 2009 by Mike Haben <michael.haben@btinternet.com> |
| 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 18 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 24 | /* This module defines the network-specific handling of mobile-originated |
| 25 | USSD messages. */ |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <errno.h> |
| 31 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 32 | #include <osmocom/msc/gsm_04_80.h> |
| 33 | #include <osmocom/msc/gsm_subscriber.h> |
| 34 | #include <osmocom/msc/debug.h> |
| 35 | #include <osmocom/msc/osmo_msc.h> |
| 36 | #include <osmocom/msc/vlr.h> |
Max | 43b01b0 | 2017-09-15 11:22:30 +0200 | [diff] [blame] | 37 | #include <osmocom/msc/gsm_04_08.h> |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 38 | |
| 39 | /* Declarations of USSD strings to be recognised */ |
| 40 | const char USSD_TEXT_OWN_NUMBER[] = "*#100#"; |
| 41 | |
Vadim Yanitskiy | b274d56 | 2018-01-10 19:47:21 +0600 | [diff] [blame] | 42 | /* A network-specific handler function */ |
Vadim Yanitskiy | 12d221f | 2018-04-04 05:30:16 +0700 | [diff] [blame] | 43 | static int send_own_number(struct gsm_subscriber_connection *conn, |
| 44 | const struct ss_request *req) |
Vadim Yanitskiy | b274d56 | 2018-01-10 19:47:21 +0600 | [diff] [blame] | 45 | { |
| 46 | char *own_number = conn->vsub->msisdn; |
| 47 | char response_string[GSM_EXTENSION_LENGTH + 20]; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 48 | |
Vadim Yanitskiy | b274d56 | 2018-01-10 19:47:21 +0600 | [diff] [blame] | 49 | DEBUGP(DMM, "%s: MSISDN = %s\n", vlr_subscr_name(conn->vsub), |
| 50 | own_number); |
| 51 | |
| 52 | /* Need trailing CR as EOT character */ |
| 53 | snprintf(response_string, sizeof(response_string), "Your extension is %s\r", own_number); |
Vadim Yanitskiy | 12d221f | 2018-04-04 05:30:16 +0700 | [diff] [blame] | 54 | return gsm0480_send_ussd_response(conn, response_string, req); |
Vadim Yanitskiy | b274d56 | 2018-01-10 19:47:21 +0600 | [diff] [blame] | 55 | } |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 56 | |
| 57 | /* Entrypoint - handler function common to all mobile-originated USSDs */ |
Holger Hans Peter Freyther | d42c3f2 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 58 | int handle_rcv_ussd(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 59 | { |
Holger Hans Peter Freyther | 06abe9f | 2010-06-30 11:30:01 +0800 | [diff] [blame] | 60 | int rc; |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 61 | struct ss_request req; |
Holger Hans Peter Freyther | 88a5fa0 | 2010-10-11 09:31:47 +0200 | [diff] [blame] | 62 | struct gsm48_hdr *gh; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 63 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 64 | /* TODO: Use subscriber_connection ref-counting if we ever want |
| 65 | * to keep the connection alive due ot ongoing USSD exchange. |
| 66 | * As we answer everytying synchronously so far, there's no need |
| 67 | * yet */ |
| 68 | |
| 69 | cm_service_request_concludes(conn, msg); |
| 70 | |
Holger Hans Peter Freyther | 06abe9f | 2010-06-30 11:30:01 +0800 | [diff] [blame] | 71 | memset(&req, 0, sizeof(req)); |
Holger Hans Peter Freyther | 88a5fa0 | 2010-10-11 09:31:47 +0200 | [diff] [blame] | 72 | gh = msgb_l3(msg); |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 73 | rc = gsm0480_decode_ss_request(gh, msgb_l3len(msg), &req); |
Tobias Engel | ea73032 | 2013-12-28 17:03:14 +0100 | [diff] [blame] | 74 | if (!rc) { |
Vadim Yanitskiy | f95d5be | 2018-04-04 06:21:00 +0700 | [diff] [blame] | 75 | LOGP(DMM, LOGL_ERROR, "SS/USSD message parsing error, " |
| 76 | "rejecting request...\n"); |
Vadim Yanitskiy | 12d221f | 2018-04-04 05:30:16 +0700 | [diff] [blame] | 77 | rc = gsm0480_send_ussd_reject(conn, &req); |
Tobias Engel | ea73032 | 2013-12-28 17:03:14 +0100 | [diff] [blame] | 78 | return rc; |
| 79 | } |
| 80 | |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 81 | /* Interrogation or releaseComplete? */ |
| 82 | if (req.ussd_text[0] == '\0' || req.ussd_text[0] == 0xFF) { |
| 83 | if (req.ss_code > 0) { |
| 84 | /* Assume interrogateSS or modification of it and reject */ |
Vadim Yanitskiy | 12d221f | 2018-04-04 05:30:16 +0700 | [diff] [blame] | 85 | rc = gsm0480_send_ussd_reject(conn, &req); |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 86 | return rc; |
| 87 | } |
| 88 | /* Still assuming a Release-Complete and returning */ |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 89 | return 0; |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 90 | } |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 91 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 92 | msc_subscr_conn_communicating(conn); |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 93 | if (!strcmp(USSD_TEXT_OWN_NUMBER, (const char *)req.ussd_text)) { |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 94 | DEBUGP(DMM, "USSD: Own number requested\n"); |
Vadim Yanitskiy | 12d221f | 2018-04-04 05:30:16 +0700 | [diff] [blame] | 95 | rc = send_own_number(conn, &req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 96 | } else { |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 97 | DEBUGP(DMM, "Unhandled USSD %s\n", req.ussd_text); |
Vadim Yanitskiy | 12d221f | 2018-04-04 05:30:16 +0700 | [diff] [blame] | 98 | rc = gsm0480_send_ussd_reject(conn, &req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 99 | } |
Holger Hans Peter Freyther | 2486663 | 2010-06-30 12:15:19 +0800 | [diff] [blame] | 100 | |
Holger Hans Peter Freyther | 2486663 | 2010-06-30 12:15:19 +0800 | [diff] [blame] | 101 | return rc; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 102 | } |