blob: 6a188c892a3d0c31bb446cf417fc86e914c12d2a [file] [log] [blame]
Jonathan Santos03fd8d02011-05-25 13:54:02 -04001/* 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 Affero General Public License as published by
10 * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
17 *
18 * 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/>.
20 *
21 */
22
23#include <stdlib.h>
24#include <unistd.h>
25#include <errno.h>
26
Jonathan Santos5a45b152011-08-17 15:33:57 -040027#include <osmocom/core/msgb.h>
Jonathan Santos03fd8d02011-05-25 13:54:02 -040028#include <openbsc/signal.h>
29#include <openbsc/debug.h>
30#include <openbsc/paging.h>
31#include <openbsc/gsm_data.h>
32#include <openbsc/gsm_subscriber.h>
33#include <openbsc/abis_rsl.h>
34#include <openbsc/chan_alloc.h>
35#include <openbsc/osmo_msc.h>
36
37/* paging of the requested subscriber has completed */
38static int paging_cb_silent(unsigned int hooknum, unsigned int event,
39 struct msgb *msg, void *_conn, void *_data)
40{
41 struct gsm_subscriber_connection *conn = _conn;
42 struct scall_signal_data sigdata;
43 int rc = 0;
44
45 if (hooknum != GSM_HOOK_RR_PAGING)
46 return -EINVAL;
47
48 DEBUGP(DSMS, "paging_cb_silent: ");
49
50 sigdata.conn = conn;
51 sigdata.data = _data;
52
53 switch (event) {
54 case GSM_PAGING_SUCCEEDED:
55 DEBUGPC(DSMS, "success, using Timeslot %u on ARFCN %u\n",
56 conn->lchan->ts->nr, conn->lchan->ts->trx->arfcn);
57 conn->silent_call = 1;
58 /* increment lchan reference count */
Jonathan Santos5a45b152011-08-17 15:33:57 -040059 osmo_signal_dispatch(SS_SCALL, S_SCALL_SUCCESS, &sigdata);
Jonathan Santos03fd8d02011-05-25 13:54:02 -040060 break;
61 case GSM_PAGING_EXPIRED:
62 case GSM_PAGING_BUSY:
63 case GSM_PAGING_OOM:
64 DEBUGP(DSMS, "expired\n");
Jonathan Santos5a45b152011-08-17 15:33:57 -040065 osmo_signal_dispatch(SS_SCALL, S_SCALL_EXPIRED, &sigdata);
Jonathan Santos03fd8d02011-05-25 13:54:02 -040066 break;
67 default:
68 rc = -EINVAL;
69 break;
70 }
71
72 return rc;
73}
74
75/* receive a layer 3 message from a silent call */
76int silent_call_rx(struct gsm_subscriber_connection *conn, struct msgb *msg)
77{
78 /* FIXME: do something like sending it through a UDP port */
79 return 0;
80}
81
82struct msg_match {
Jonathan Santos5a45b152011-08-17 15:33:57 -040083 uint8_t pdisc;
84 uint8_t msg_type;
Jonathan Santos03fd8d02011-05-25 13:54:02 -040085};
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 */
94int silent_call_reroute(struct gsm_subscriber_connection *conn, struct msgb *msg)
95{
96 struct gsm48_hdr *gh = msgb_l3(msg);
Jonathan Santos5a45b152011-08-17 15:33:57 -040097 uint8_t pdisc = gh->proto_discr & 0x0f;
Jonathan Santos03fd8d02011-05-25 13:54:02 -040098 int i;
99
100 /* if we're not part of a silent call, never reroute */
101 if (!conn->silent_call)
102 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 */
117int gsm_silent_call_start(struct gsm_subscriber *subscr, void *data, int type)
118{
119 int rc;
120
121 rc = paging_request(subscr->net, subscr, type,
122 paging_cb_silent, data);
123 return rc;
124}
125
126/* end a silent call with a given subscriber */
127int gsm_silent_call_stop(struct gsm_subscriber *subscr)
128{
129 struct gsm_subscriber_connection *conn;
130
131 conn = connection_for_subscr(subscr);
132 if (!conn)
133 return -EINVAL;
134
135 /* did we actually establish a silent call for this guy? */
136 if (!conn->silent_call)
137 return -EINVAL;
138
139 conn->silent_call = 0;
140 msc_release_connection(conn);
141
142 return 0;
143}