blob: 8bd5341ec0d54cf42d419cdce13d0c0d52c8f2e4 [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>
Harald Weltea1482332009-11-14 10:08:40 +010036
Harald Welte51008772009-12-29 11:49:12 +010037/* paging of the requested subscriber has completed */
Harald Weltea1482332009-11-14 10:08:40 +010038static int paging_cb_silent(unsigned int hooknum, unsigned int event,
39 struct msgb *msg, void *_lchan, void *_data)
40{
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010041 struct gsm_subscriber_connection *conn;
Harald Weltea1482332009-11-14 10:08:40 +010042 struct gsm_lchan *lchan = _lchan;
43 struct scall_signal_data sigdata;
44 int rc;
45
46 if (hooknum != GSM_HOOK_RR_PAGING)
47 return -EINVAL;
48
49 DEBUGP(DSMS, "paging_cb_silent: ");
50
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010051 conn = &lchan->conn;
52
Harald Weltea1482332009-11-14 10:08:40 +010053 sigdata.lchan = lchan;
54 sigdata.data = _data;
55
56 switch (event) {
57 case GSM_PAGING_SUCCEEDED:
58 DEBUGPC(DSMS, "success, using Timeslot %u on ARFCN %u\n",
59 lchan->ts->nr, lchan->ts->trx->arfcn);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010060 conn->silent_call = 1;
Harald Weltea1482332009-11-14 10:08:40 +010061 /* increment lchan reference count */
62 dispatch_signal(SS_SCALL, S_SCALL_SUCCESS, &sigdata);
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +010063 use_subscr_con(conn);
Harald Weltea1482332009-11-14 10:08:40 +010064 break;
65 case GSM_PAGING_EXPIRED:
66 DEBUGP(DSMS, "expired\n");
67 dispatch_signal(SS_SCALL, S_SCALL_EXPIRED, &sigdata);
68 break;
69 default:
70 rc = -EINVAL;
71 break;
72 }
73
74 return rc;
75}
76
Harald Welte51008772009-12-29 11:49:12 +010077/* receive a layer 3 message from a silent call */
78int silent_call_rx(struct msgb *msg)
79{
80 /* FIXME: do something like sending it through a UDP port */
81 return 0;
82}
83
84struct msg_match {
85 u_int8_t pdisc;
86 u_int8_t msg_type;
87};
88
89/* list of messages that are handled inside OpenBSC, even in a silent call */
90static const struct msg_match silent_call_accept[] = {
91 { GSM48_PDISC_MM, GSM48_MT_MM_LOC_UPD_REQUEST },
92 { GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_REQ },
93};
94
95/* decide if we need to reroute a message as part of a silent call */
96int silent_call_reroute(struct msgb *msg)
97{
98 struct gsm48_hdr *gh = msgb_l3(msg);
99 u_int8_t pdisc = gh->proto_discr & 0x0f;
100 int i;
101
102 /* if we're not part of a silent call, never reroute */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100103 if (!msg->lchan->conn.silent_call)
Harald Welte51008772009-12-29 11:49:12 +0100104 return 0;
105
106 /* check if we are a special message that is handled in openbsc */
107 for (i = 0; i < ARRAY_SIZE(silent_call_accept); i++) {
108 if (silent_call_accept[i].pdisc == pdisc &&
109 silent_call_accept[i].msg_type == gh->msg_type)
110 return 0;
111 }
112
113 /* otherwise, reroute */
114 return 1;
115}
116
117
118/* initiate a silent call with a given subscriber */
Sylvain Munaut50480702010-01-02 14:29:43 +0100119int gsm_silent_call_start(struct gsm_subscriber *subscr, void *data, int type)
Harald Weltea1482332009-11-14 10:08:40 +0100120{
121 int rc;
122
Sylvain Munaut50480702010-01-02 14:29:43 +0100123 rc = paging_request(subscr->net, subscr, type,
Harald Weltea1482332009-11-14 10:08:40 +0100124 paging_cb_silent, data);
125 return rc;
126}
127
Harald Welte51008772009-12-29 11:49:12 +0100128/* end a silent call with a given subscriber */
Harald Weltea1482332009-11-14 10:08:40 +0100129int gsm_silent_call_stop(struct gsm_subscriber *subscr)
130{
131 struct gsm_lchan *lchan;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100132 struct gsm_subscriber_connection *conn;
Harald Weltea1482332009-11-14 10:08:40 +0100133
134 lchan = lchan_for_subscr(subscr);
135 if (!lchan)
136 return -EINVAL;
137
Harald Welte83579ca2009-12-29 11:17:18 +0100138 /* did we actually establish a silent call for this guy? */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100139 conn = &lchan->conn;
140 if (!conn->silent_call)
Harald Welte83579ca2009-12-29 11:17:18 +0100141 return -EINVAL;
142
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100143 put_subscr_con(conn);
Harald Weltea1482332009-11-14 10:08:40 +0100144
145 return 0;
146}