blob: 7b450a2df29afe5593b6704ac9502b0a5b01c986 [file] [log] [blame]
Harald Welte6eafe912009-10-16 08:32:58 +02001/* 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 Welte9af6ddf2011-01-01 15:25:50 +010010 * 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 Welte6eafe912009-10-16 08:32:58 +020012 * (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 Welte9af6ddf2011-01-01 15:25:50 +010017 * GNU Affero General Public License for more details.
Harald Welte6eafe912009-10-16 08:32:58 +020018 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * 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 Welte6eafe912009-10-16 08:32:58 +020021 *
22 */
23
Harald Welte6307b852009-10-16 08:41:51 +020024/* This module defines the network-specific handling of mobile-originated
25 USSD messages. */
Harald Welte6eafe912009-10-16 08:32:58 +020026
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <errno.h>
31
Neels Hofmeyr90843962017-09-04 15:04:35 +020032#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>
Max43b01b02017-09-15 11:22:30 +020037#include <osmocom/msc/gsm_04_08.h>
Harald Welte6eafe912009-10-16 08:32:58 +020038
39/* Declarations of USSD strings to be recognised */
40const char USSD_TEXT_OWN_NUMBER[] = "*#100#";
41
42/* Forward declarations of network-specific handler functions */
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +020043static int send_own_number(struct gsm_subscriber_connection *conn, const struct msgb *msg, const struct ss_request *req);
Harald Welte6eafe912009-10-16 08:32:58 +020044
45
46/* Entrypoint - handler function common to all mobile-originated USSDs */
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080047int handle_rcv_ussd(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte6eafe912009-10-16 08:32:58 +020048{
Holger Hans Peter Freyther06abe9f2010-06-30 11:30:01 +080049 int rc;
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +020050 struct ss_request req;
Holger Hans Peter Freyther88a5fa02010-10-11 09:31:47 +020051 struct gsm48_hdr *gh;
Harald Welte6eafe912009-10-16 08:32:58 +020052
Harald Welte2483f1b2016-06-19 18:06:02 +020053 /* TODO: Use subscriber_connection ref-counting if we ever want
54 * to keep the connection alive due ot ongoing USSD exchange.
55 * As we answer everytying synchronously so far, there's no need
56 * yet */
57
58 cm_service_request_concludes(conn, msg);
59
Holger Hans Peter Freyther06abe9f2010-06-30 11:30:01 +080060 memset(&req, 0, sizeof(req));
Holger Hans Peter Freyther88a5fa02010-10-11 09:31:47 +020061 gh = msgb_l3(msg);
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +020062 rc = gsm0480_decode_ss_request(gh, msgb_l3len(msg), &req);
Tobias Engelea730322013-12-28 17:03:14 +010063 if (!rc) {
64 DEBUGP(DMM, "Unhandled SS\n");
65 rc = gsm0480_send_ussd_reject(conn, msg, &req);
Tobias Engelea730322013-12-28 17:03:14 +010066 return rc;
67 }
68
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +020069 /* Interrogation or releaseComplete? */
70 if (req.ussd_text[0] == '\0' || req.ussd_text[0] == 0xFF) {
71 if (req.ss_code > 0) {
72 /* Assume interrogateSS or modification of it and reject */
73 rc = gsm0480_send_ussd_reject(conn, msg, &req);
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +020074 return rc;
75 }
76 /* Still assuming a Release-Complete and returning */
Harald Welte6307b852009-10-16 08:41:51 +020077 return 0;
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +020078 }
Harald Welte6eafe912009-10-16 08:32:58 +020079
Harald Welte2483f1b2016-06-19 18:06:02 +020080 msc_subscr_conn_communicating(conn);
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +020081 if (!strcmp(USSD_TEXT_OWN_NUMBER, (const char *)req.ussd_text)) {
Harald Welte6eafe912009-10-16 08:32:58 +020082 DEBUGP(DMM, "USSD: Own number requested\n");
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080083 rc = send_own_number(conn, msg, &req);
Harald Welte6eafe912009-10-16 08:32:58 +020084 } else {
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +020085 DEBUGP(DMM, "Unhandled USSD %s\n", req.ussd_text);
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080086 rc = gsm0480_send_ussd_reject(conn, msg, &req);
Harald Welte6eafe912009-10-16 08:32:58 +020087 }
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080088
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080089 return rc;
Harald Welte6eafe912009-10-16 08:32:58 +020090}
91
92/* A network-specific handler function */
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +020093static int send_own_number(struct gsm_subscriber_connection *conn, const struct msgb *msg, const struct ss_request *req)
Harald Welte6eafe912009-10-16 08:32:58 +020094{
Harald Welte2483f1b2016-06-19 18:06:02 +020095 char *own_number = conn->vsub->msisdn;
Mike Haben2449b372009-10-26 20:36:34 +010096 char response_string[GSM_EXTENSION_LENGTH + 20];
Harald Welte6eafe912009-10-16 08:32:58 +020097
Harald Welte2483f1b2016-06-19 18:06:02 +020098 DEBUGP(DMM, "%s: MSISDN = %s\n", vlr_subscr_name(conn->vsub),
99 own_number);
100
Mike Haben2449b372009-10-26 20:36:34 +0100101 /* Need trailing CR as EOT character */
102 snprintf(response_string, sizeof(response_string), "Your extension is %s\r", own_number);
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +0800103 return gsm0480_send_ussd_response(conn, msg, response_string, req);
Harald Welte6eafe912009-10-16 08:32:58 +0200104}