blob: a3d11f0808c472d4052df12631df7eec463d62af [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 */
Mike Habendc329a62009-10-22 09:56:44 +020041static int send_own_number(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 */
45int handle_rcv_ussd(struct msgb *msg)
46{
Mike Habendc329a62009-10-22 09:56:44 +020047 struct ussd_request req;
Harald Welte6eafe912009-10-16 08:32:58 +020048
Mike Habendc329a62009-10-22 09:56:44 +020049 gsm0480_decode_ussd_request(msg, &req);
50 if (req.text[0] == 0xFF) /* Release-Complete */
Harald Welte6307b852009-10-16 08:41:51 +020051 return 0;
Harald Welte6eafe912009-10-16 08:32:58 +020052
Mike Habendc329a62009-10-22 09:56:44 +020053 if (strstr(USSD_TEXT_OWN_NUMBER, req.text) != NULL) {
Harald Welte6eafe912009-10-16 08:32:58 +020054 DEBUGP(DMM, "USSD: Own number requested\n");
Mike Habendc329a62009-10-22 09:56:44 +020055 return send_own_number(msg, &req);
Harald Welte6eafe912009-10-16 08:32:58 +020056 } else {
Mike Habendc329a62009-10-22 09:56:44 +020057 DEBUGP(DMM, "Unhandled USSD %s\n", req.text);
58 return gsm0480_send_ussd_reject(msg, &req);
Harald Welte6eafe912009-10-16 08:32:58 +020059 }
60}
61
62/* A network-specific handler function */
Mike Habendc329a62009-10-22 09:56:44 +020063static int send_own_number(const struct msgb *msg, const struct ussd_request *req)
Harald Welte6eafe912009-10-16 08:32:58 +020064{
Harald Welte6307b852009-10-16 08:41:51 +020065 char *own_number = msg->lchan->subscr->extension;
Mike Haben2449b372009-10-26 20:36:34 +010066 char response_string[GSM_EXTENSION_LENGTH + 20];
Harald Welte6eafe912009-10-16 08:32:58 +020067
Mike Haben2449b372009-10-26 20:36:34 +010068 /* Need trailing CR as EOT character */
69 snprintf(response_string, sizeof(response_string), "Your extension is %s\r", own_number);
Mike Habendc329a62009-10-22 09:56:44 +020070 return gsm0480_send_ussd_response(msg, response_string, req);
Harald Welte6eafe912009-10-16 08:32:58 +020071}