blob: 3c27646f291f00d1ec9bdb9a4be2e8fc274619d9 [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>
36
37/* Declarations of USSD strings to be recognised */
38const char USSD_TEXT_OWN_NUMBER[] = "*#100#";
39
40/* Forward declarations of network-specific handler functions */
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080041static 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 +020042
43
44/* Entrypoint - handler function common to all mobile-originated USSDs */
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080045int handle_rcv_ussd(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte6eafe912009-10-16 08:32:58 +020046{
Holger Hans Peter Freyther06abe9f2010-06-30 11:30:01 +080047 int rc;
Mike Habendc329a62009-10-22 09:56:44 +020048 struct ussd_request req;
Harald Welte6eafe912009-10-16 08:32:58 +020049
Holger Hans Peter Freyther06abe9f2010-06-30 11:30:01 +080050 memset(&req, 0, sizeof(req));
51 rc = gsm0480_decode_ussd_request(msg, &req);
Mike Habendc329a62009-10-22 09:56:44 +020052 if (req.text[0] == 0xFF) /* Release-Complete */
Harald Welte6307b852009-10-16 08:41:51 +020053 return 0;
Harald Welte6eafe912009-10-16 08:32:58 +020054
Mike Habendc329a62009-10-22 09:56:44 +020055 if (strstr(USSD_TEXT_OWN_NUMBER, req.text) != NULL) {
Harald Welte6eafe912009-10-16 08:32:58 +020056 DEBUGP(DMM, "USSD: Own number requested\n");
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080057 rc = send_own_number(conn, msg, &req);
Harald Welte6eafe912009-10-16 08:32:58 +020058 } else {
Mike Habendc329a62009-10-22 09:56:44 +020059 DEBUGP(DMM, "Unhandled USSD %s\n", req.text);
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080060 rc = gsm0480_send_ussd_reject(conn, msg, &req);
Harald Welte6eafe912009-10-16 08:32:58 +020061 }
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080062
63 /* check if we can release it */
64 msc_release_connection(conn);
65 return rc;
Harald Welte6eafe912009-10-16 08:32:58 +020066}
67
68/* A network-specific handler function */
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080069static 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 +020070{
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080071 char *own_number = conn->subscr->extension;
Mike Haben2449b372009-10-26 20:36:34 +010072 char response_string[GSM_EXTENSION_LENGTH + 20];
Harald Welte6eafe912009-10-16 08:32:58 +020073
Mike Haben2449b372009-10-26 20:36:34 +010074 /* Need trailing CR as EOT character */
75 snprintf(response_string, sizeof(response_string), "Your extension is %s\r", own_number);
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080076 return gsm0480_send_ussd_response(conn, msg, response_string, req);
Harald Welte6eafe912009-10-16 08:32:58 +020077}