aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/ussd.c
blob: 9dc2205f1b446fca166d4afb6f4fb9c92984e056 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Network-specific handling of mobile-originated USSDs. */

/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
 * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
 * (C) 2009 by Mike Haben <michael.haben@btinternet.com>
 *
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

/* This module defines the network-specific handling of mobile-originated
   USSD messages. */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <openbsc/gsm_04_80.h>
#include <openbsc/gsm_subscriber.h>
#include <openbsc/debug.h>

/* Declarations of USSD strings to be recognised */
const char USSD_TEXT_OWN_NUMBER[] = "*#100#";

/* Forward declarations of network-specific handler functions */
static int send_own_number(struct msgb *msg);


/* Entrypoint - handler function common to all mobile-originated USSDs */
int handle_rcv_ussd(struct msgb *msg)
{
	char *ussd_text_rcvd = gsm0480_rcv_ussd(msg);

	if (ussd_text_rcvd[0] == 0xFF)  /* Release-Complete */
		return 0;

	if (strstr(USSD_TEXT_OWN_NUMBER, ussd_text_rcvd) != NULL) {
		DEBUGP(DMM, "USSD: Own number requested\n");
		return send_own_number(msg);
	} else {
		DEBUGP(DMM, "Unhandled USSD %s\n", ussd_text_rcvd);
		return gsm0480_send_ussd_reject(msg);
	}
}

/* A network-specific handler function */
static int send_own_number(struct msgb *msg)
{
	char *own_number = msg->lchan->subscr->extension;
	/* Need trailing CR as EOT character */
	char response_string[] = "Your extension is xxxxx\r";

	memcpy(response_string + 18, own_number, 5);
	return gsm0480_send_ussd_response(msg, response_string);
}