blob: 2eb37bacec6af2200d43a8e016da08c18d944f6a [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
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <stdlib.h>
25#include <unistd.h>
26#include <errno.h>
27
Harald Weltedfe6c7d2010-02-20 16:24:02 +010028#include <osmocore/msgb.h>
Harald Weltea1482332009-11-14 10:08:40 +010029#include <openbsc/signal.h>
30#include <openbsc/debug.h>
31#include <openbsc/paging.h>
32#include <openbsc/gsm_data.h>
33#include <openbsc/gsm_subscriber.h>
34#include <openbsc/abis_rsl.h>
Harald Welte986c3d72009-11-17 06:12:16 +010035#include <openbsc/chan_alloc.h>
Holger Hans Peter Freyther88519ea2010-06-30 12:44:07 +080036#include <openbsc/osmo_msc.h>
Harald Weltea1482332009-11-14 10:08:40 +010037
Harald Welte51008772009-12-29 11:49:12 +010038/* paging of the requested subscriber has completed */
Harald Weltea1482332009-11-14 10:08:40 +010039static int paging_cb_silent(unsigned int hooknum, unsigned int event,
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +080040 struct msgb *msg, void *_conn, void *_data)
Harald Weltea1482332009-11-14 10:08:40 +010041{
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +080042 struct gsm_subscriber_connection *conn = _conn;
Harald Weltea1482332009-11-14 10:08:40 +010043 struct scall_signal_data sigdata;
Holger Hans Peter Freythera97152b2010-07-23 19:34:34 +080044 int rc = 0;
Harald Weltea1482332009-11-14 10:08:40 +010045
46 if (hooknum != GSM_HOOK_RR_PAGING)
47 return -EINVAL;
48
49 DEBUGP(DSMS, "paging_cb_silent: ");
50
Holger Hans Peter Freyther86481c22010-06-17 15:05:57 +080051 sigdata.conn = conn;
Harald Weltea1482332009-11-14 10:08:40 +010052 sigdata.data = _data;
53
54 switch (event) {
55 case GSM_PAGING_SUCCEEDED:
56 DEBUGPC(DSMS, "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);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010058 conn->silent_call = 1;
Harald Weltea1482332009-11-14 10:08:40 +010059 /* increment lchan reference count */
60 dispatch_signal(SS_SCALL, S_SCALL_SUCCESS, &sigdata);
Harald Weltea1482332009-11-14 10:08:40 +010061 break;
62 case GSM_PAGING_EXPIRED:
Holger Hans Peter Freytherd3baf412010-12-23 18:19:17 +010063 case GSM_PAGING_BUSY:
Harald Weltea1482332009-11-14 10:08:40 +010064 DEBUGP(DSMS, "expired\n");
65 dispatch_signal(SS_SCALL, S_SCALL_EXPIRED, &sigdata);
66 break;
67 default:
68 rc = -EINVAL;
69 break;
70 }
71
72 return rc;
73}
74
Harald Welte51008772009-12-29 11:49:12 +010075/* receive a layer 3 message from a silent call */
Holger Hans Peter Freyther758f4df2010-06-21 10:34:03 +080076int silent_call_rx(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte51008772009-12-29 11:49:12 +010077{
78 /* FIXME: do something like sending it through a UDP port */
79 return 0;
80}
81
82struct msg_match {
83 u_int8_t pdisc;
84 u_int8_t msg_type;
85};
86
87/* list of messages that are handled inside OpenBSC, even in a silent call */
88static const struct msg_match silent_call_accept[] = {
89 { GSM48_PDISC_MM, GSM48_MT_MM_LOC_UPD_REQUEST },
90 { GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_REQ },
91};
92
93/* decide if we need to reroute a message as part of a silent call */
Holger Hans Peter Freyther758f4df2010-06-21 10:34:03 +080094int silent_call_reroute(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte51008772009-12-29 11:49:12 +010095{
96 struct gsm48_hdr *gh = msgb_l3(msg);
97 u_int8_t pdisc = gh->proto_discr & 0x0f;
98 int i;
99
100 /* if we're not part of a silent call, never reroute */
Holger Hans Peter Freyther758f4df2010-06-21 10:34:03 +0800101 if (!conn->silent_call)
Harald Welte51008772009-12-29 11:49:12 +0100102 return 0;
103
104 /* check if we are a special message that is handled in openbsc */
105 for (i = 0; i < ARRAY_SIZE(silent_call_accept); i++) {
106 if (silent_call_accept[i].pdisc == pdisc &&
107 silent_call_accept[i].msg_type == gh->msg_type)
108 return 0;
109 }
110
111 /* otherwise, reroute */
112 return 1;
113}
114
115
116/* initiate a silent call with a given subscriber */
Sylvain Munaut50480702010-01-02 14:29:43 +0100117int gsm_silent_call_start(struct gsm_subscriber *subscr, void *data, int type)
Harald Weltea1482332009-11-14 10:08:40 +0100118{
119 int rc;
120
Sylvain Munaut50480702010-01-02 14:29:43 +0100121 rc = paging_request(subscr->net, subscr, type,
Harald Weltea1482332009-11-14 10:08:40 +0100122 paging_cb_silent, data);
123 return rc;
124}
125
Harald Welte51008772009-12-29 11:49:12 +0100126/* end a silent call with a given subscriber */
Harald Weltea1482332009-11-14 10:08:40 +0100127int gsm_silent_call_stop(struct gsm_subscriber *subscr)
128{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100129 struct gsm_subscriber_connection *conn;
Harald Weltea1482332009-11-14 10:08:40 +0100130
Holger Hans Peter Freytherb2be1952010-06-16 13:23:55 +0800131 conn = connection_for_subscr(subscr);
132 if (!conn)
Harald Weltea1482332009-11-14 10:08:40 +0100133 return -EINVAL;
134
Harald Welte83579ca2009-12-29 11:17:18 +0100135 /* did we actually establish a silent call for this guy? */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100136 if (!conn->silent_call)
Harald Welte83579ca2009-12-29 11:17:18 +0100137 return -EINVAL;
138
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800139 conn->silent_call = 0;
140 msc_release_connection(conn);
Harald Weltea1482332009-11-14 10:08:40 +0100141
142 return 0;
143}