summaryrefslogtreecommitdiffstats
path: root/openbsc/src/silent_call.c
blob: f81bdc51e6fdaa71ae1d5eb11adaa03e47259f02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* GSM silent call feature */

/*
 * (C) 2009 by Harald Welte <laforge@gnumonks.org>
 *
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

#include <osmocore/msgb.h>
#include <openbsc/signal.h>
#include <openbsc/debug.h>
#include <openbsc/paging.h>
#include <openbsc/gsm_data.h>
#include <openbsc/gsm_subscriber.h>
#include <openbsc/abis_rsl.h>
#include <openbsc/chan_alloc.h>

/* paging of the requested subscriber has completed */
static int paging_cb_silent(unsigned int hooknum, unsigned int event,
			    struct msgb *msg, void *_lchan, void *_data)
{
	struct gsm_lchan *lchan = _lchan;
	struct scall_signal_data sigdata;
	int rc;

	if (hooknum != GSM_HOOK_RR_PAGING)
		return -EINVAL;

	DEBUGP(DSMS, "paging_cb_silent: ");

	sigdata.lchan = lchan;
	sigdata.data = _data;

	switch (event) {
	case GSM_PAGING_SUCCEEDED:
		DEBUGPC(DSMS, "success, using Timeslot %u on ARFCN %u\n",
			lchan->ts->nr, lchan->ts->trx->arfcn);
		lchan->silent_call = 1;
		/* increment lchan reference count */
		dispatch_signal(SS_SCALL, S_SCALL_SUCCESS, &sigdata);
		use_lchan(lchan);
		break;
	case GSM_PAGING_EXPIRED:
		DEBUGP(DSMS, "expired\n");
		dispatch_signal(SS_SCALL, S_SCALL_EXPIRED, &sigdata);
		break;
	default:
		rc = -EINVAL;
		break;
	}

	return rc;
}

/* receive a layer 3 message from a silent call */
int silent_call_rx(struct msgb *msg)
{
	/* FIXME: do something like sending it through a UDP port */
	return 0;
}

struct msg_match {
	u_int8_t pdisc;
	u_int8_t msg_type;
};

/* list of messages that are handled inside OpenBSC, even in a silent call */
static const struct msg_match silent_call_accept[] = {
	{ GSM48_PDISC_MM, GSM48_MT_MM_LOC_UPD_REQUEST },
	{ GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_REQ },
};

/* decide if we need to reroute a message as part of a silent call */
int silent_call_reroute(struct msgb *msg)
{
	struct gsm48_hdr *gh = msgb_l3(msg);
	u_int8_t pdisc = gh->proto_discr & 0x0f;
	int i;

	/* if we're not part of a silent call, never reroute */
	if (!msg->lchan->silent_call)
		return 0;

	/* check if we are a special message that is handled in openbsc */
	for (i = 0; i < ARRAY_SIZE(silent_call_accept); i++) {
		if (silent_call_accept[i].pdisc == pdisc &&
		    silent_call_accept[i].msg_type == gh->msg_type)
			return 0;
	}

	/* otherwise, reroute */
	return 1;
}


/* initiate a silent call with a given subscriber */
int gsm_silent_call_start(struct gsm_subscriber *subscr, void *data, int type)
{
	int rc;

	rc = paging_request(subscr->net, subscr, type,
			    paging_cb_silent, data);
	return rc;
}

/* end a silent call with a given subscriber */
int gsm_silent_call_stop(struct gsm_subscriber *subscr)
{
	struct gsm_lchan *lchan;

	lchan = lchan_for_subscr(subscr);
	if (!lchan)
		return -EINVAL;

	/* did we actually establish a silent call for this guy? */
	if (!lchan->silent_call)
		return -EINVAL;

	put_lchan(lchan, 0);

	return 0;
}