blob: 5f9a45725c64fd50ffe13436da816f1d8ea75a1d [file] [log] [blame]
Harald Welte03115042009-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
25/* This module defines the network-specific handling of mobile-originated USSD messages. */
26
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>
35
36/* Declarations of USSD strings to be recognised */
37const char USSD_TEXT_OWN_NUMBER[] = "*#100#";
38
39/* Forward declarations of network-specific handler functions */
40static int send_own_number(struct msgb *msg);
41
42
43/* Entrypoint - handler function common to all mobile-originated USSDs */
44int handle_rcv_ussd(struct msgb *msg)
45{
46 char* ussd_text_rcvd = gsm0480_rcv_ussd(msg);
47
48 if(ussd_text_rcvd[0] == 0xFF) /* Release-Complete */
49 return 0;
50
51 if(strstr(USSD_TEXT_OWN_NUMBER, ussd_text_rcvd) != NULL) {
52 DEBUGP(DMM, "USSD: Own number requested\n");
53 return send_own_number(msg);
54 } else {
55 DEBUGP(DMM, "Unhandled USSD %s\n", ussd_text_rcvd);
56 return gsm0480_send_ussd_reject(msg);
57 }
58}
59
60/* A network-specific handler function */
61static int send_own_number(struct msgb *msg)
62{
63 char response_string[] = "Your extension is xxxxx\r"; /* Need trailing CR as EOT character */
64
65 char* own_number = msg->lchan->subscr->extension;
66 memcpy(response_string + 18, own_number, 5);
67 return gsm0480_send_ussd_response(msg, response_string);
68}