blob: 7ba451b65984b5112e2618a64132126c767d3616 [file] [log] [blame]
Harald Welteb8678a72009-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 Weltef4625b12010-02-20 16:24:02 +010028#include <osmocore/msgb.h>
Harald Welteb8678a72009-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 Welte49c79562009-11-17 06:12:16 +010035#include <openbsc/chan_alloc.h>
Harald Welteb8678a72009-11-14 10:08:40 +010036
Harald Weltef6a38ec2009-12-29 11:49:12 +010037/* paging of the requested subscriber has completed */
Harald Welteb8678a72009-11-14 10:08:40 +010038static int paging_cb_silent(unsigned int hooknum, unsigned int event,
Holger Hans Peter Freytherd3aaf662010-06-17 15:05:57 +080039 struct msgb *msg, void *_conn, void *_data)
Harald Welteb8678a72009-11-14 10:08:40 +010040{
Holger Hans Peter Freytherd3aaf662010-06-17 15:05:57 +080041 struct gsm_subscriber_connection *conn = _conn;
Harald Welteb8678a72009-11-14 10:08:40 +010042 struct scall_signal_data sigdata;
43 int rc;
44
45 if (hooknum != GSM_HOOK_RR_PAGING)
46 return -EINVAL;
47
48 DEBUGP(DSMS, "paging_cb_silent: ");
49
Holger Hans Peter Freytherd3aaf662010-06-17 15:05:57 +080050 sigdata.conn = conn;
Harald Welteb8678a72009-11-14 10:08:40 +010051 sigdata.data = _data;
52
53 switch (event) {
54 case GSM_PAGING_SUCCEEDED:
55 DEBUGPC(DSMS, "success, using Timeslot %u on ARFCN %u\n",
Holger Hans Peter Freytherd3aaf662010-06-17 15:05:57 +080056 conn->lchan->ts->nr, conn->lchan->ts->trx->arfcn);
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +010057 conn->silent_call = 1;
Harald Welteb8678a72009-11-14 10:08:40 +010058 /* increment lchan reference count */
59 dispatch_signal(SS_SCALL, S_SCALL_SUCCESS, &sigdata);
Harald Welteb8678a72009-11-14 10:08:40 +010060 break;
61 case GSM_PAGING_EXPIRED:
62 DEBUGP(DSMS, "expired\n");
63 dispatch_signal(SS_SCALL, S_SCALL_EXPIRED, &sigdata);
64 break;
65 default:
66 rc = -EINVAL;
67 break;
68 }
69
70 return rc;
71}
72
Harald Weltef6a38ec2009-12-29 11:49:12 +010073/* receive a layer 3 message from a silent call */
Holger Hans Peter Freyther48549392010-06-21 10:34:03 +080074int silent_call_rx(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Weltef6a38ec2009-12-29 11:49:12 +010075{
76 /* FIXME: do something like sending it through a UDP port */
77 return 0;
78}
79
80struct msg_match {
81 u_int8_t pdisc;
82 u_int8_t msg_type;
83};
84
85/* list of messages that are handled inside OpenBSC, even in a silent call */
86static const struct msg_match silent_call_accept[] = {
87 { GSM48_PDISC_MM, GSM48_MT_MM_LOC_UPD_REQUEST },
88 { GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_REQ },
89};
90
91/* decide if we need to reroute a message as part of a silent call */
Holger Hans Peter Freyther48549392010-06-21 10:34:03 +080092int silent_call_reroute(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Weltef6a38ec2009-12-29 11:49:12 +010093{
94 struct gsm48_hdr *gh = msgb_l3(msg);
95 u_int8_t pdisc = gh->proto_discr & 0x0f;
96 int i;
97
98 /* if we're not part of a silent call, never reroute */
Holger Hans Peter Freyther48549392010-06-21 10:34:03 +080099 if (!conn->silent_call)
Harald Weltef6a38ec2009-12-29 11:49:12 +0100100 return 0;
101
102 /* check if we are a special message that is handled in openbsc */
103 for (i = 0; i < ARRAY_SIZE(silent_call_accept); i++) {
104 if (silent_call_accept[i].pdisc == pdisc &&
105 silent_call_accept[i].msg_type == gh->msg_type)
106 return 0;
107 }
108
109 /* otherwise, reroute */
110 return 1;
111}
112
113
114/* initiate a silent call with a given subscriber */
Sylvain Munaut1c378a72010-01-02 14:29:43 +0100115int gsm_silent_call_start(struct gsm_subscriber *subscr, void *data, int type)
Harald Welteb8678a72009-11-14 10:08:40 +0100116{
117 int rc;
118
Sylvain Munaut1c378a72010-01-02 14:29:43 +0100119 rc = paging_request(subscr->net, subscr, type,
Harald Welteb8678a72009-11-14 10:08:40 +0100120 paging_cb_silent, data);
121 return rc;
122}
123
Harald Weltef6a38ec2009-12-29 11:49:12 +0100124/* end a silent call with a given subscriber */
Harald Welteb8678a72009-11-14 10:08:40 +0100125int gsm_silent_call_stop(struct gsm_subscriber *subscr)
126{
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100127 struct gsm_subscriber_connection *conn;
Harald Welteb8678a72009-11-14 10:08:40 +0100128
Holger Hans Peter Freyther2f4af772010-06-16 13:23:55 +0800129 conn = connection_for_subscr(subscr);
130 if (!conn)
Harald Welteb8678a72009-11-14 10:08:40 +0100131 return -EINVAL;
132
Harald Welte51bd0662009-12-29 11:17:18 +0100133 /* did we actually establish a silent call for this guy? */
Holger Hans Peter Freyther065b8112010-03-23 06:41:45 +0100134 if (!conn->silent_call)
Harald Welte51bd0662009-12-29 11:17:18 +0100135 return -EINVAL;
136
Holger Hans Peter Freyther6e5c50f2010-06-28 17:09:29 +0800137 conn->silent_call = 0;
138 msc_release_connection(conn);
Harald Welteb8678a72009-11-14 10:08:40 +0100139
140 return 0;
141}