2009-10-16 06:32:58 +00:00
|
|
|
/* (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
|
2011-01-01 14:25:50 +00:00
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2009-10-16 06:32:58 +00:00
|
|
|
* (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
|
2011-01-01 14:25:50 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2009-10-16 06:32:58 +00:00
|
|
|
*
|
2011-01-01 14:25:50 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-10-16 06:32:58 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-06-11 22:24:52 +00:00
|
|
|
/**
|
|
|
|
* MSC-specific handling of call independent Supplementary
|
|
|
|
* Services messages (NC_SS) according to GSM TS 09.11
|
|
|
|
* "Signalling interworking for supplementary services".
|
|
|
|
*/
|
2009-10-16 06:32:58 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2017-09-04 13:04:35 +00:00
|
|
|
#include <osmocom/msc/gsm_04_80.h>
|
|
|
|
#include <osmocom/msc/gsm_subscriber.h>
|
|
|
|
#include <osmocom/msc/debug.h>
|
|
|
|
#include <osmocom/msc/osmo_msc.h>
|
|
|
|
#include <osmocom/msc/vlr.h>
|
2017-09-15 09:22:30 +00:00
|
|
|
#include <osmocom/msc/gsm_04_08.h>
|
2018-04-17 12:17:11 +00:00
|
|
|
#include <osmocom/msc/transaction.h>
|
|
|
|
|
|
|
|
/* FIXME: choose a proper range */
|
|
|
|
static uint32_t new_callref = 0x20000001;
|
2009-10-16 06:32:58 +00:00
|
|
|
|
|
|
|
/* Declarations of USSD strings to be recognised */
|
|
|
|
const char USSD_TEXT_OWN_NUMBER[] = "*#100#";
|
|
|
|
|
2018-01-10 13:47:21 +00:00
|
|
|
/* A network-specific handler function */
|
2018-04-03 22:30:16 +00:00
|
|
|
static int send_own_number(struct gsm_subscriber_connection *conn,
|
|
|
|
const struct ss_request *req)
|
2018-01-10 13:47:21 +00:00
|
|
|
{
|
|
|
|
char *own_number = conn->vsub->msisdn;
|
|
|
|
char response_string[GSM_EXTENSION_LENGTH + 20];
|
2009-10-16 06:32:58 +00:00
|
|
|
|
2018-01-10 13:47:21 +00:00
|
|
|
DEBUGP(DMM, "%s: MSISDN = %s\n", vlr_subscr_name(conn->vsub),
|
|
|
|
own_number);
|
|
|
|
|
|
|
|
/* Need trailing CR as EOT character */
|
|
|
|
snprintf(response_string, sizeof(response_string), "Your extension is %s\r", own_number);
|
2018-04-03 22:30:16 +00:00
|
|
|
return gsm0480_send_ussd_response(conn, response_string, req);
|
2018-01-10 13:47:21 +00:00
|
|
|
}
|
2009-10-16 06:32:58 +00:00
|
|
|
|
2018-06-11 22:24:52 +00:00
|
|
|
/* Entry point for call independent MO SS messages */
|
|
|
|
int gsm0911_rcv_nc_ss(struct gsm_subscriber_connection *conn, struct msgb *msg)
|
2009-10-16 06:32:58 +00:00
|
|
|
{
|
2018-04-17 12:17:11 +00:00
|
|
|
struct gsm48_hdr *gh = msgb_l3(msg);
|
|
|
|
struct gsm_trans *trans;
|
2016-07-12 15:53:26 +00:00
|
|
|
struct ss_request req;
|
2018-04-17 12:17:11 +00:00
|
|
|
uint8_t pdisc, tid;
|
|
|
|
uint8_t msg_type;
|
|
|
|
int rc;
|
2009-10-16 06:32:58 +00:00
|
|
|
|
2018-04-17 12:17:11 +00:00
|
|
|
pdisc = gsm48_hdr_pdisc(gh);
|
|
|
|
msg_type = gsm48_hdr_msg_type(gh);
|
|
|
|
tid = gsm48_hdr_trans_id_flip_ti(gh);
|
2016-06-19 16:06:02 +00:00
|
|
|
|
2018-04-17 12:17:11 +00:00
|
|
|
/* Associate logging messages with this subscriber */
|
|
|
|
log_set_context(LOG_CTX_VLR_SUBSCR, conn->vsub);
|
|
|
|
|
|
|
|
DEBUGP(DMM, "Received SS/USSD data (trans_id=%x, msg_type=%s)\n",
|
|
|
|
tid, gsm48_pdisc_msgtype_name(pdisc, msg_type));
|
|
|
|
|
|
|
|
/* Reuse existing transaction, or create a new one */
|
|
|
|
trans = trans_find_by_id(conn, pdisc, tid);
|
|
|
|
if (!trans) {
|
|
|
|
/**
|
|
|
|
* According to GSM TS 04.80, section 2.4.2 "Register
|
|
|
|
* (mobile station to network direction)", the REGISTER
|
|
|
|
* message is sent by the mobile station to the network
|
|
|
|
* to assign a new transaction identifier for call independent
|
|
|
|
* supplementary service control and to request or acknowledge
|
|
|
|
* a supplementary service.
|
|
|
|
*/
|
|
|
|
if (msg_type != GSM0480_MTYPE_REGISTER) {
|
|
|
|
LOGP(DMM, LOGL_ERROR, "Unexpected message (msg_type=%s), "
|
|
|
|
"transaction is not allocated yet\n",
|
|
|
|
gsm48_pdisc_msgtype_name(pdisc, msg_type));
|
|
|
|
gsm0480_send_ussd_reject(conn, &req,
|
|
|
|
GSM_0480_PROBLEM_CODE_TAG_GENERAL,
|
|
|
|
GSM_0480_GEN_PROB_CODE_UNRECOGNISED);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUGP(DMM, " -> (new transaction)\n");
|
|
|
|
trans = trans_alloc(conn->network, conn->vsub,
|
|
|
|
pdisc, tid, new_callref++);
|
|
|
|
if (!trans) {
|
|
|
|
DEBUGP(DMM, " -> No memory for trans\n");
|
|
|
|
gsm0480_send_ussd_return_error(conn, &req,
|
|
|
|
GSM0480_ERR_CODE_SYSTEM_FAILURE);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
trans->conn = msc_subscr_conn_get(conn, MSC_CONN_USE_TRANS_NC_SS);
|
|
|
|
trans->dlci = OMSC_LINKID_CB(msg);
|
|
|
|
cm_service_request_concludes(conn, msg);
|
|
|
|
}
|
2016-06-19 16:06:02 +00:00
|
|
|
|
2010-06-30 03:30:01 +00:00
|
|
|
memset(&req, 0, sizeof(req));
|
2016-07-12 15:53:26 +00:00
|
|
|
rc = gsm0480_decode_ss_request(gh, msgb_l3len(msg), &req);
|
2013-12-28 16:03:14 +00:00
|
|
|
if (!rc) {
|
2018-04-03 23:21:00 +00:00
|
|
|
LOGP(DMM, LOGL_ERROR, "SS/USSD message parsing error, "
|
|
|
|
"rejecting request...\n");
|
libmsc/ussd.c: FIX: properly indicate errors
There are error and problem codes defined by GSM TS 04.80:
- Error codes are used when a message is structured correctly,
but something is wrong in context of the current operation.
Usually they are carried by 'Return Error' component.
- Problem codes are used when something is wrong with the
message structure, or with carried values. They are
carried by 'Reject' component.
There are three groups of them (see table 3.13):
- General Problem Codes (table 3.14),
- Invoke Problem Codes (table 3.15),
- Return Result Problem Codes (table 3.16),
- Return Error Problem Codes (table 3.17).
The first group is general purpose, and can be sent in
response to any kind of message, excluding 'Reject' itself.
Other ones are bound to specific component types, such as
'Invoke', 'Return Result' and 'Return Error'.
For some reason, a 'Reject' component with the general problem
code 'GSM_0480_GEN_PROB_CODE_UNRECOGNISED' was always used in
OsmoMSC. Even when the message structure is correct.
Let's properly indicate errors in the following way:
- 'Reject' with GSM_0480_GEN_PROB_CODE_UNRECOGNISED
when the gsm0480_decode_ss_request() fails to decode
a message. It can only return 0 or 1, so it's hard to
guess which exact part of message caused the error.
- 'Return Error' with GSM0480_ERR_CODE_ILLEGAL_SS_OPERATION
when the operation code is not related to USSD.
- 'Return Error' with GSM0480_ERR_CODE_UNEXPECTED_DATA_VALUE
when the requested USSD code is unhandled (not supported).
There is a TTCN-3 testcase for this:
https://gerrit.osmocom.org/9470/
Change-Id: I800e7ec98dc9d0bca2d45a8b8255d60253d63e14
2018-06-08 10:13:44 +00:00
|
|
|
gsm0480_send_ussd_reject(conn, &req, GSM_0480_PROBLEM_CODE_TAG_GENERAL,
|
|
|
|
GSM_0480_GEN_PROB_CODE_UNRECOGNISED);
|
2018-04-03 23:21:45 +00:00
|
|
|
/* The GSM 04.80 API uses inverted codes (0 means error) */
|
|
|
|
return -EPROTO;
|
2013-12-28 16:03:14 +00:00
|
|
|
}
|
|
|
|
|
2016-07-12 15:53:26 +00:00
|
|
|
/* Interrogation or releaseComplete? */
|
|
|
|
if (req.ussd_text[0] == '\0' || req.ussd_text[0] == 0xFF) {
|
|
|
|
if (req.ss_code > 0) {
|
|
|
|
/* Assume interrogateSS or modification of it and reject */
|
libmsc/ussd.c: FIX: properly indicate errors
There are error and problem codes defined by GSM TS 04.80:
- Error codes are used when a message is structured correctly,
but something is wrong in context of the current operation.
Usually they are carried by 'Return Error' component.
- Problem codes are used when something is wrong with the
message structure, or with carried values. They are
carried by 'Reject' component.
There are three groups of them (see table 3.13):
- General Problem Codes (table 3.14),
- Invoke Problem Codes (table 3.15),
- Return Result Problem Codes (table 3.16),
- Return Error Problem Codes (table 3.17).
The first group is general purpose, and can be sent in
response to any kind of message, excluding 'Reject' itself.
Other ones are bound to specific component types, such as
'Invoke', 'Return Result' and 'Return Error'.
For some reason, a 'Reject' component with the general problem
code 'GSM_0480_GEN_PROB_CODE_UNRECOGNISED' was always used in
OsmoMSC. Even when the message structure is correct.
Let's properly indicate errors in the following way:
- 'Reject' with GSM_0480_GEN_PROB_CODE_UNRECOGNISED
when the gsm0480_decode_ss_request() fails to decode
a message. It can only return 0 or 1, so it's hard to
guess which exact part of message caused the error.
- 'Return Error' with GSM0480_ERR_CODE_ILLEGAL_SS_OPERATION
when the operation code is not related to USSD.
- 'Return Error' with GSM0480_ERR_CODE_UNEXPECTED_DATA_VALUE
when the requested USSD code is unhandled (not supported).
There is a TTCN-3 testcase for this:
https://gerrit.osmocom.org/9470/
Change-Id: I800e7ec98dc9d0bca2d45a8b8255d60253d63e14
2018-06-08 10:13:44 +00:00
|
|
|
return gsm0480_send_ussd_return_error(conn, &req,
|
|
|
|
GSM0480_ERR_CODE_ILLEGAL_SS_OPERATION);
|
2016-07-12 15:53:26 +00:00
|
|
|
}
|
|
|
|
/* Still assuming a Release-Complete and returning */
|
2009-10-16 06:41:51 +00:00
|
|
|
return 0;
|
2016-07-12 15:53:26 +00:00
|
|
|
}
|
2009-10-16 06:32:58 +00:00
|
|
|
|
2016-06-19 16:06:02 +00:00
|
|
|
msc_subscr_conn_communicating(conn);
|
2016-07-12 15:53:26 +00:00
|
|
|
if (!strcmp(USSD_TEXT_OWN_NUMBER, (const char *)req.ussd_text)) {
|
2009-10-16 06:32:58 +00:00
|
|
|
DEBUGP(DMM, "USSD: Own number requested\n");
|
2018-04-03 22:30:16 +00:00
|
|
|
rc = send_own_number(conn, &req);
|
2009-10-16 06:32:58 +00:00
|
|
|
} else {
|
2016-07-12 15:53:26 +00:00
|
|
|
DEBUGP(DMM, "Unhandled USSD %s\n", req.ussd_text);
|
libmsc/ussd.c: FIX: properly indicate errors
There are error and problem codes defined by GSM TS 04.80:
- Error codes are used when a message is structured correctly,
but something is wrong in context of the current operation.
Usually they are carried by 'Return Error' component.
- Problem codes are used when something is wrong with the
message structure, or with carried values. They are
carried by 'Reject' component.
There are three groups of them (see table 3.13):
- General Problem Codes (table 3.14),
- Invoke Problem Codes (table 3.15),
- Return Result Problem Codes (table 3.16),
- Return Error Problem Codes (table 3.17).
The first group is general purpose, and can be sent in
response to any kind of message, excluding 'Reject' itself.
Other ones are bound to specific component types, such as
'Invoke', 'Return Result' and 'Return Error'.
For some reason, a 'Reject' component with the general problem
code 'GSM_0480_GEN_PROB_CODE_UNRECOGNISED' was always used in
OsmoMSC. Even when the message structure is correct.
Let's properly indicate errors in the following way:
- 'Reject' with GSM_0480_GEN_PROB_CODE_UNRECOGNISED
when the gsm0480_decode_ss_request() fails to decode
a message. It can only return 0 or 1, so it's hard to
guess which exact part of message caused the error.
- 'Return Error' with GSM0480_ERR_CODE_ILLEGAL_SS_OPERATION
when the operation code is not related to USSD.
- 'Return Error' with GSM0480_ERR_CODE_UNEXPECTED_DATA_VALUE
when the requested USSD code is unhandled (not supported).
There is a TTCN-3 testcase for this:
https://gerrit.osmocom.org/9470/
Change-Id: I800e7ec98dc9d0bca2d45a8b8255d60253d63e14
2018-06-08 10:13:44 +00:00
|
|
|
rc = gsm0480_send_ussd_return_error(conn, &req,
|
|
|
|
GSM0480_ERR_CODE_UNEXPECTED_DATA_VALUE);
|
2009-10-16 06:32:58 +00:00
|
|
|
}
|
2010-06-30 04:15:19 +00:00
|
|
|
|
2018-04-17 12:17:11 +00:00
|
|
|
/**
|
|
|
|
* TODO: as we only handle *#100# for now, and always
|
|
|
|
* respond with RELEASE COMPLETE, let's manually free
|
|
|
|
* the transaction here, until the external interface
|
|
|
|
* is implemented.
|
|
|
|
*/
|
|
|
|
trans_free(trans);
|
|
|
|
|
2010-06-30 04:15:19 +00:00
|
|
|
return rc;
|
2009-10-16 06:32:58 +00:00
|
|
|
}
|