blob: 9dc2205f1b446fca166d4afb6f4fb9c92984e056 [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 */
41static int send_own_number(struct msgb *msg);
42
43
44/* Entrypoint - handler function common to all mobile-originated USSDs */
45int handle_rcv_ussd(struct msgb *msg)
46{
Harald Welte6307b852009-10-16 08:41:51 +020047 char *ussd_text_rcvd = gsm0480_rcv_ussd(msg);
Harald Welte6eafe912009-10-16 08:32:58 +020048
Harald Welte6307b852009-10-16 08:41:51 +020049 if (ussd_text_rcvd[0] == 0xFF) /* Release-Complete */
50 return 0;
Harald Welte6eafe912009-10-16 08:32:58 +020051
Harald Welte6307b852009-10-16 08:41:51 +020052 if (strstr(USSD_TEXT_OWN_NUMBER, ussd_text_rcvd) != NULL) {
Harald Welte6eafe912009-10-16 08:32:58 +020053 DEBUGP(DMM, "USSD: Own number requested\n");
54 return send_own_number(msg);
55 } else {
56 DEBUGP(DMM, "Unhandled USSD %s\n", ussd_text_rcvd);
57 return gsm0480_send_ussd_reject(msg);
58 }
59}
60
61/* A network-specific handler function */
62static int send_own_number(struct msgb *msg)
63{
Harald Welte6307b852009-10-16 08:41:51 +020064 char *own_number = msg->lchan->subscr->extension;
65 /* Need trailing CR as EOT character */
66 char response_string[] = "Your extension is xxxxx\r";
Harald Welte6eafe912009-10-16 08:32:58 +020067
Harald Welte6eafe912009-10-16 08:32:58 +020068 memcpy(response_string + 18, own_number, 5);
69 return gsm0480_send_ussd_response(msg, response_string);
70}