blob: 76ee101a1f91b12e2b1f1f1b3674d20924ca2faa [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
32#include <openbsc/gsm_04_80.h>
33#include <openbsc/gsm_subscriber.h>
34#include <openbsc/debug.h>
Holger Hans Peter Freyther88519ea2010-06-30 12:44:07 +080035#include <openbsc/osmo_msc.h>
Harald Welte6eafe912009-10-16 08:32:58 +020036
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;
Holger Hans Peter Freyther88a5fa02010-10-11 09:31:47 +020049 struct gsm48_hdr *gh;
Harald Welte6eafe912009-10-16 08:32:58 +020050
Holger Hans Peter Freyther06abe9f2010-06-30 11:30:01 +080051 memset(&req, 0, sizeof(req));
Holger Hans Peter Freyther88a5fa02010-10-11 09:31:47 +020052 gh = msgb_l3(msg);
53 rc = gsm0480_decode_ussd_request(gh, msgb_l3len(msg), &req);
Mike Habendc329a62009-10-22 09:56:44 +020054 if (req.text[0] == 0xFF) /* Release-Complete */
Harald Welte6307b852009-10-16 08:41:51 +020055 return 0;
Harald Welte6eafe912009-10-16 08:32:58 +020056
Tobias Engelc33d7d72012-02-24 22:23:17 +010057 if (!strcmp(USSD_TEXT_OWN_NUMBER, (const char *)req.text)) {
Harald Welte6eafe912009-10-16 08:32:58 +020058 DEBUGP(DMM, "USSD: Own number requested\n");
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080059 rc = send_own_number(conn, msg, &req);
Harald Welte6eafe912009-10-16 08:32:58 +020060 } else {
Mike Habendc329a62009-10-22 09:56:44 +020061 DEBUGP(DMM, "Unhandled USSD %s\n", req.text);
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080062 rc = gsm0480_send_ussd_reject(conn, msg, &req);
Harald Welte6eafe912009-10-16 08:32:58 +020063 }
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +080064
65 /* check if we can release it */
66 msc_release_connection(conn);
67 return rc;
Harald Welte6eafe912009-10-16 08:32:58 +020068}
69
70/* A network-specific handler function */
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080071static 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 +020072{
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080073 char *own_number = conn->subscr->extension;
Mike Haben2449b372009-10-26 20:36:34 +010074 char response_string[GSM_EXTENSION_LENGTH + 20];
Harald Welte6eafe912009-10-16 08:32:58 +020075
Mike Haben2449b372009-10-26 20:36:34 +010076 /* Need trailing CR as EOT character */
77 snprintf(response_string, sizeof(response_string), "Your extension is %s\r", own_number);
Holger Hans Peter Freytherd42c3f22010-06-17 17:35:57 +080078 return gsm0480_send_ussd_response(conn, msg, response_string, req);
Harald Welte6eafe912009-10-16 08:32:58 +020079}