Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 1 | /* 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 Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * 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 Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 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 |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 18 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * 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 Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 24 | /* This module defines the network-specific handling of mobile-originated |
| 25 | USSD messages. */ |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 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> |
Holger Hans Peter Freyther | 3a0ec17 | 2010-06-30 12:44:07 +0800 | [diff] [blame] | 35 | #include <openbsc/osmo_msc.h> |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 36 | |
| 37 | /* Declarations of USSD strings to be recognised */ |
| 38 | const char USSD_TEXT_OWN_NUMBER[] = "*#100#"; |
| 39 | |
| 40 | /* Forward declarations of network-specific handler functions */ |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 41 | static int send_own_number(struct gsm_subscriber_connection *conn, const struct msgb *msg, const struct ussd_request *req); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 42 | |
| 43 | |
| 44 | /* Entrypoint - handler function common to all mobile-originated USSDs */ |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 45 | int handle_rcv_ussd(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 46 | { |
Holger Hans Peter Freyther | 22bc339 | 2010-06-30 11:30:01 +0800 | [diff] [blame] | 47 | int rc; |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 48 | struct ussd_request req; |
Holger Hans Peter Freyther | c36f332 | 2010-10-11 09:31:47 +0200 | [diff] [blame] | 49 | struct gsm48_hdr *gh; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 50 | |
Holger Hans Peter Freyther | 22bc339 | 2010-06-30 11:30:01 +0800 | [diff] [blame] | 51 | memset(&req, 0, sizeof(req)); |
Holger Hans Peter Freyther | c36f332 | 2010-10-11 09:31:47 +0200 | [diff] [blame] | 52 | gh = msgb_l3(msg); |
| 53 | rc = gsm0480_decode_ussd_request(gh, msgb_l3len(msg), &req); |
Alexander Huemer | b8b1c2a | 2013-10-06 21:59:28 +0200 | [diff] [blame^] | 54 | if (req.text[0] == '\0') /* Release-Complete */ |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 55 | return 0; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 56 | |
Tobias Engel | 052e51f | 2012-02-24 22:23:17 +0100 | [diff] [blame] | 57 | if (!strcmp(USSD_TEXT_OWN_NUMBER, (const char *)req.text)) { |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 58 | DEBUGP(DMM, "USSD: Own number requested\n"); |
Holger Hans Peter Freyther | bd5d4ff | 2010-06-30 12:15:19 +0800 | [diff] [blame] | 59 | rc = send_own_number(conn, msg, &req); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 60 | } else { |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 61 | DEBUGP(DMM, "Unhandled USSD %s\n", req.text); |
Holger Hans Peter Freyther | bd5d4ff | 2010-06-30 12:15:19 +0800 | [diff] [blame] | 62 | rc = gsm0480_send_ussd_reject(conn, msg, &req); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 63 | } |
Holger Hans Peter Freyther | bd5d4ff | 2010-06-30 12:15:19 +0800 | [diff] [blame] | 64 | |
| 65 | /* check if we can release it */ |
| 66 | msc_release_connection(conn); |
| 67 | return rc; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /* A network-specific handler function */ |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 71 | static int send_own_number(struct gsm_subscriber_connection *conn, const struct msgb *msg, const struct ussd_request *req) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 72 | { |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 73 | char *own_number = conn->subscr->extension; |
Mike Haben | c0c5079 | 2009-10-26 20:36:34 +0100 | [diff] [blame] | 74 | char response_string[GSM_EXTENSION_LENGTH + 20]; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 75 | |
Mike Haben | c0c5079 | 2009-10-26 20:36:34 +0100 | [diff] [blame] | 76 | /* Need trailing CR as EOT character */ |
| 77 | snprintf(response_string, sizeof(response_string), "Your extension is %s\r", own_number); |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 78 | return gsm0480_send_ussd_response(conn, msg, response_string, req); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 79 | } |