blob: 1ea2305ed2c57bf155d9057ddebb57a9c29d1bdb [file] [log] [blame]
Harald Weltea1482332009-11-14 10:08:40 +01001/* GSM silent call feature */
2
3/*
4 * (C) 2009 by Harald Welte <laforge@gnumonks.org>
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01009 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
Harald Weltea1482332009-11-14 10:08:40 +010011 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * GNU Affero General Public License for more details.
Harald Weltea1482332009-11-14 10:08:40 +010017 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010018 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Weltea1482332009-11-14 10:08:40 +010020 *
21 */
22
23#include <stdlib.h>
24#include <unistd.h>
25#include <errno.h>
26
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010027#include <osmocom/core/msgb.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020028#include <osmocom/msc/signal.h>
29#include <osmocom/msc/debug.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020030#include <osmocom/msc/gsm_data.h>
31#include <osmocom/msc/gsm_subscriber.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020032#include <osmocom/msc/osmo_msc.h>
Neels Hofmeyrd656dff2018-03-09 14:59:44 +010033#include <osmocom/msc/vlr.h>
Harald Weltea1482332009-11-14 10:08:40 +010034
Harald Welte51008772009-12-29 11:49:12 +010035/* paging of the requested subscriber has completed */
Harald Weltea1482332009-11-14 10:08:40 +010036static int paging_cb_silent(unsigned int hooknum, unsigned int event,
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +080037 struct msgb *msg, void *_conn, void *_data)
Harald Weltea1482332009-11-14 10:08:40 +010038{
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +080039 struct gsm_subscriber_connection *conn = _conn;
Harald Weltea1482332009-11-14 10:08:40 +010040 struct scall_signal_data sigdata;
Holger Hans Peter Freythera97152b2010-07-23 19:34:34 +080041 int rc = 0;
Harald Weltea1482332009-11-14 10:08:40 +010042
43 if (hooknum != GSM_HOOK_RR_PAGING)
44 return -EINVAL;
45
Holger Hans Peter Freythereff409492012-11-10 19:46:58 +010046 DEBUGP(DLSMS, "paging_cb_silent: ");
Harald Weltea1482332009-11-14 10:08:40 +010047
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +080048 sigdata.conn = conn;
Harald Weltea1482332009-11-14 10:08:40 +010049 sigdata.data = _data;
50
51 switch (event) {
52 case GSM_PAGING_SUCCEEDED:
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020053#if BEFORE_MSCSPLIT
54 /* Re-enable this log output once we can obtain this information via
55 * A-interface, see OS#2391. */
Holger Hans Peter Freythereff409492012-11-10 19:46:58 +010056 DEBUGPC(DLSMS, "success, using Timeslot %u on ARFCN %u\n",
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +080057 conn->lchan->ts->nr, conn->lchan->ts->trx->arfcn);
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020058#endif
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010059 conn->silent_call = 1;
Neels Hofmeyr6166f292017-11-22 14:33:12 +010060 msc_subscr_conn_get(conn, MSC_CONN_USE_SILENT_CALL);
Harald Weltea1482332009-11-14 10:08:40 +010061 /* increment lchan reference count */
Pablo Neira Ayusobbc5b992011-05-06 12:12:31 +020062 osmo_signal_dispatch(SS_SCALL, S_SCALL_SUCCESS, &sigdata);
Harald Weltea1482332009-11-14 10:08:40 +010063 break;
64 case GSM_PAGING_EXPIRED:
Holger Hans Peter Freytherd3baf412010-12-23 18:19:17 +010065 case GSM_PAGING_BUSY:
Holger Hans Peter Freyther90c0aff2010-12-29 15:28:40 +010066 case GSM_PAGING_OOM:
Holger Hans Peter Freythereff409492012-11-10 19:46:58 +010067 DEBUGP(DLSMS, "expired\n");
Pablo Neira Ayusobbc5b992011-05-06 12:12:31 +020068 osmo_signal_dispatch(SS_SCALL, S_SCALL_EXPIRED, &sigdata);
Harald Weltea1482332009-11-14 10:08:40 +010069 break;
70 default:
71 rc = -EINVAL;
72 break;
73 }
74
75 return rc;
76}
77
Philipp Maiere0d5caa2017-02-27 16:56:59 +010078#if 0
Harald Welte51008772009-12-29 11:49:12 +010079/* receive a layer 3 message from a silent call */
Holger Hans Peter Freyther758f4df2010-06-21 10:34:03 +080080int silent_call_rx(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte51008772009-12-29 11:49:12 +010081{
82 /* FIXME: do something like sending it through a UDP port */
Jacob Erlbeck8e68b562014-01-30 21:01:12 +010083 LOGP(DLSMS, LOGL_NOTICE, "Discarding L3 message from a silent call.\n");
Harald Welte51008772009-12-29 11:49:12 +010084 return 0;
85}
86
87struct msg_match {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020088 uint8_t pdisc;
89 uint8_t msg_type;
Harald Welte51008772009-12-29 11:49:12 +010090};
91
92/* list of messages that are handled inside OpenBSC, even in a silent call */
93static const struct msg_match silent_call_accept[] = {
94 { GSM48_PDISC_MM, GSM48_MT_MM_LOC_UPD_REQUEST },
95 { GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_REQ },
96};
97
98/* decide if we need to reroute a message as part of a silent call */
Holger Hans Peter Freyther758f4df2010-06-21 10:34:03 +080099int silent_call_reroute(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte51008772009-12-29 11:49:12 +0100100{
101 struct gsm48_hdr *gh = msgb_l3(msg);
Neels Hofmeyr531734a2016-03-14 16:13:24 +0100102 uint8_t pdisc = gsm48_hdr_pdisc(gh);
103 uint8_t msg_type = gsm48_hdr_msg_type(gh);
Harald Welte51008772009-12-29 11:49:12 +0100104 int i;
105
106 /* if we're not part of a silent call, never reroute */
Holger Hans Peter Freyther758f4df2010-06-21 10:34:03 +0800107 if (!conn->silent_call)
Harald Welte51008772009-12-29 11:49:12 +0100108 return 0;
109
110 /* check if we are a special message that is handled in openbsc */
111 for (i = 0; i < ARRAY_SIZE(silent_call_accept); i++) {
112 if (silent_call_accept[i].pdisc == pdisc &&
Neels Hofmeyr531734a2016-03-14 16:13:24 +0100113 silent_call_accept[i].msg_type == msg_type)
Harald Welte51008772009-12-29 11:49:12 +0100114 return 0;
115 }
116
117 /* otherwise, reroute */
Jacob Erlbeck8e68b562014-01-30 21:01:12 +0100118 LOGP(DLSMS, LOGL_INFO, "Rerouting L3 message from a silent call.\n");
Harald Welte51008772009-12-29 11:49:12 +0100119 return 1;
120}
Philipp Maiere0d5caa2017-02-27 16:56:59 +0100121#endif
Harald Welte51008772009-12-29 11:49:12 +0100122
123
124/* initiate a silent call with a given subscriber */
Harald Welte2483f1b2016-06-19 18:06:02 +0200125int gsm_silent_call_start(struct vlr_subscr *vsub, void *data, int type)
Harald Weltea1482332009-11-14 10:08:40 +0100126{
Holger Hans Peter Freytherb618c7e2015-08-03 11:21:29 +0200127 struct subscr_request *req;
Harald Weltea1482332009-11-14 10:08:40 +0100128
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200129 /* FIXME the VTY command allows selecting a silent call channel type.
130 * This doesn't apply to the situation after MSCSPLIT with an
131 * A-interface. */
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200132 req = subscr_request_conn(vsub, paging_cb_silent, data,
133 "establish silent call");
Neels Hofmeyrd656dff2018-03-09 14:59:44 +0100134 if (!req)
135 return -ENODEV;
136 return 0;
Harald Weltea1482332009-11-14 10:08:40 +0100137}
138
Harald Welte51008772009-12-29 11:49:12 +0100139/* end a silent call with a given subscriber */
Harald Welte2483f1b2016-06-19 18:06:02 +0200140int gsm_silent_call_stop(struct vlr_subscr *vsub)
Harald Weltea1482332009-11-14 10:08:40 +0100141{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100142 struct gsm_subscriber_connection *conn;
Harald Weltea1482332009-11-14 10:08:40 +0100143
Harald Welte2483f1b2016-06-19 18:06:02 +0200144 conn = connection_for_subscr(vsub);
Neels Hofmeyrd656dff2018-03-09 14:59:44 +0100145 if (!conn) {
146 LOGP(DMM, LOGL_ERROR, "%s: Cannot stop silent call, no connection for subscriber\n",
147 vlr_subscr_name(vsub));
148 return -ENODEV;
149 }
Harald Weltea1482332009-11-14 10:08:40 +0100150
Harald Welte83579ca2009-12-29 11:17:18 +0100151 /* did we actually establish a silent call for this guy? */
Neels Hofmeyrd656dff2018-03-09 14:59:44 +0100152 if (!conn->silent_call) {
153 LOGP(DMM, LOGL_ERROR, "%s: Cannot stop silent call, subscriber has no active silent call\n",
154 vlr_subscr_name(vsub));
155 return -ENOENT;
156 }
Harald Welte83579ca2009-12-29 11:17:18 +0100157
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200158#if BEFORE_MSCSPLIT
159 /* Re-enable this log output once we can obtain this information via
160 * A-interface, see OS#2391. */
Jacob Erlbeck8e68b562014-01-30 21:01:12 +0100161 DEBUGPC(DLSMS, "Stopping silent call using Timeslot %u on ARFCN %u\n",
162 conn->lchan->ts->nr, conn->lchan->ts->trx->arfcn);
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200163#endif
Jacob Erlbeck8e68b562014-01-30 21:01:12 +0100164
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800165 conn->silent_call = 0;
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100166 msc_subscr_conn_put(conn, MSC_CONN_USE_SILENT_CALL);
Harald Weltea1482332009-11-14 10:08:40 +0100167
168 return 0;
169}