blob: c9eac13f0a1b2df2308b553785a14412c3576b4a [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
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
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
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24
Harald Welte6307b852009-10-16 08:41:51 +020025/* This module defines the network-specific handling of mobile-originated
26 USSD messages. */
Harald Welte6eafe912009-10-16 08:32:58 +020027
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <errno.h>
32
33#include <openbsc/gsm_04_80.h>
34#include <openbsc/gsm_subscriber.h>
35#include <openbsc/debug.h>
Holger Hans Peter Freyther88519ea2010-06-30 12:44:07 +080036#include <openbsc/osmo_msc.h>
Harald Welte6eafe912009-10-16 08:32:58 +020037
38/* Declarations of USSD strings to be recognised */
39const char USSD_TEXT_OWN_NUMBER[] = "*#100#";
40
41/* Forward declarations of network-specific handler functions */
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080042static int send_own_number(struct gsm_subscriber_connection *conn, const struct msgb *msg, const struct ussd_request *req);
Harald Welte6eafe912009-10-16 08:32:58 +020043
44
45/* Entrypoint - handler function common to all mobile-originated USSDs */
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080046int handle_rcv_ussd(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte6eafe912009-10-16 08:32:58 +020047{
Holger Hans Peter Freyther06abe9f2010-06-30 11:30:01 +080048 int rc;
Mike Habendc329a62009-10-22 09:56:44 +020049 struct ussd_request req;
Holger Hans Peter Freyther88a5fa02010-10-11 09:31:47 +020050 struct gsm48_hdr *gh;
Harald Welte6eafe912009-10-16 08:32:58 +020051
Holger Hans Peter Freyther06abe9f2010-06-30 11:30:01 +080052 memset(&req, 0, sizeof(req));
Holger Hans Peter Freyther88a5fa02010-10-11 09:31:47 +020053 gh = msgb_l3(msg);
54 rc = gsm0480_decode_ussd_request(gh, msgb_l3len(msg), &req);
Mike Habendc329a62009-10-22 09:56:44 +020055 if (req.text[0] == 0xFF) /* Release-Complete */
Harald Welte6307b852009-10-16 08:41:51 +020056 return 0;
Harald Welte6eafe912009-10-16 08:32:58 +020057
Mike Habendc329a62009-10-22 09:56:44 +020058 if (strstr(USSD_TEXT_OWN_NUMBER, req.text) != NULL) {
Harald Welte6eafe912009-10-16 08:32:58 +020059 DEBUGP(DMM, "USSD: Own number requested\n");
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080060 rc = send_own_number(conn, msg, &req);
Harald Welte6eafe912009-10-16 08:32:58 +020061 } else {
Mike Habendc329a62009-10-22 09:56:44 +020062 DEBUGP(DMM, "Unhandled USSD %s\n", req.text);
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080063 rc = gsm0480_send_ussd_reject(conn, msg, &req);
Harald Welte6eafe912009-10-16 08:32:58 +020064 }
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080065
66 /* check if we can release it */
67 msc_release_connection(conn);
68 return rc;
Harald Welte6eafe912009-10-16 08:32:58 +020069}
70
71/* A network-specific handler function */
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080072static int send_own_number(struct gsm_subscriber_connection *conn, const struct msgb *msg, const struct ussd_request *req)
Harald Welte6eafe912009-10-16 08:32:58 +020073{
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080074 char *own_number = conn->subscr->extension;
Mike Haben2449b372009-10-26 20:36:34 +010075 char response_string[GSM_EXTENSION_LENGTH + 20];
Harald Welte6eafe912009-10-16 08:32:58 +020076
Mike Haben2449b372009-10-26 20:36:34 +010077 /* Need trailing CR as EOT character */
78 snprintf(response_string, sizeof(response_string), "Your extension is %s\r", own_number);
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080079 return gsm0480_send_ussd_response(conn, msg, response_string, req);
Harald Welte6eafe912009-10-16 08:32:58 +020080}