Harald Welte | 6eafe91 | 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 |
| 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 Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 25 | /* This module defines the network-specific handling of mobile-originated |
| 26 | USSD messages. */ |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 27 | |
| 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 */ |
| 38 | const char USSD_TEXT_OWN_NUMBER[] = "*#100#"; |
| 39 | |
| 40 | /* Forward declarations of network-specific handler functions */ |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 41 | static int send_own_number(const struct msgb *msg, const struct ussd_request *req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 42 | |
| 43 | |
| 44 | /* Entrypoint - handler function common to all mobile-originated USSDs */ |
| 45 | int handle_rcv_ussd(struct msgb *msg) |
| 46 | { |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 47 | struct ussd_request req; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 48 | |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 49 | gsm0480_decode_ussd_request(msg, &req); |
| 50 | if (req.text[0] == 0xFF) /* Release-Complete */ |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 51 | return 0; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 52 | |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 53 | if (strstr(USSD_TEXT_OWN_NUMBER, req.text) != NULL) { |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 54 | DEBUGP(DMM, "USSD: Own number requested\n"); |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 55 | return send_own_number(msg, &req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 56 | } else { |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 57 | DEBUGP(DMM, "Unhandled USSD %s\n", req.text); |
| 58 | return gsm0480_send_ussd_reject(msg, &req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | /* A network-specific handler function */ |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 63 | static int send_own_number(const struct msgb *msg, const struct ussd_request *req) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 64 | { |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame^] | 65 | char *own_number = msg->lchan->conn.subscr->extension; |
Mike Haben | 2449b37 | 2009-10-26 20:36:34 +0100 | [diff] [blame] | 66 | char response_string[GSM_EXTENSION_LENGTH + 20]; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 67 | |
Mike Haben | 2449b37 | 2009-10-26 20:36:34 +0100 | [diff] [blame] | 68 | /* Need trailing CR as EOT character */ |
| 69 | snprintf(response_string, sizeof(response_string), "Your extension is %s\r", own_number); |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 70 | return gsm0480_send_ussd_response(msg, response_string, req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 71 | } |