aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmsc/silent_call.c
blob: 3b95a901fc88ab01095e899efd53d469f8df202f (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* 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 Affero General Public License as published by
 * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

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

#include <osmocom/core/byteswap.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/utils.h>
#include <osmocom/msc/signal.h>
#include <osmocom/msc/debug.h>
#include <osmocom/msc/gsm_data.h>
#include <osmocom/msc/gsm_subscriber.h>
#include <osmocom/msc/vlr.h>
#include <osmocom/msc/msc_a.h>
#include <osmocom/msc/paging.h>
#include <osmocom/msc/transaction.h>
#include <osmocom/msc/silent_call.h>

#include <osmocom/sigtran/sccp_helpers.h>

/* paging of the requested subscriber has completed */
void paging_cb_silent(struct msc_a *msc_a, struct gsm_trans *trans)
{
	struct scall_signal_data sigdata = {
		.msc_a = msc_a,
		.vty = trans->silent_call.from_vty,
	};
	struct ran_msg assignment;

	if (!msc_a) {
		LOG_MSC_A(msc_a, LOGL_ERROR, "Silent call: MS not responding to Paging\n");
		osmo_signal_dispatch(SS_SCALL, S_SCALL_FAILED, &sigdata);
		trans_free(trans);
		return;
	}

	LOG_MSC_A(msc_a, LOGL_INFO, "Silent call: MS responding to Paging\n");

	trans->msc_a = msc_a;
	msc_a_get(msc_a, MSC_A_USE_SILENT_CALL);

	osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans);

	assignment = (struct ran_msg){
		.msg_type = RAN_MSG_ASSIGNMENT_COMMAND,
		.assignment_command = {
			.channel_type = &trans->silent_call.ct,
			.cn_rtp = &trans->silent_call.rtp_cn,
		},
	};
	if (msc_a_ran_down(msc_a, MSC_ROLE_I, &assignment)) {
		LOG_MSC_A(msc_a, LOGL_ERROR, "Silent call failed\n");
		osmo_signal_dispatch(SS_SCALL, S_SCALL_FAILED, &sigdata);
		trans_free(trans);
	} else {
		osmo_signal_dispatch(SS_SCALL, S_SCALL_SUCCESS, &sigdata);
	}
}

void trans_silent_call_free(struct gsm_trans *trans)
{
	struct scall_signal_data sigdata = {
		.msc_a = trans->msc_a,
		.vty = trans->silent_call.from_vty,
	};
	osmo_signal_dispatch(SS_SCALL, S_SCALL_DETACHED, &sigdata);
}

#if 0
/* receive a layer 3 message from a silent call */
int silent_call_rx(struct ran_conn *conn, struct msgb *msg)
{
	/* FIXME: do something like sending it through a UDP port */
	LOGP(DLSMS, LOGL_NOTICE, "Discarding L3 message from a silent call.\n");
	return 0;
}

struct msg_match {
	uint8_t pdisc;
	uint8_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 ran_conn *conn, struct msgb *msg)
{
	struct gsm48_hdr *gh = msgb_l3(msg);
	uint8_t pdisc = gsm48_hdr_pdisc(gh);
	uint8_t msg_type = gsm48_hdr_msg_type(gh);
	int i;

	/* if we're not part of a silent call, never reroute */
	if (!conn->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 == msg_type)
			return 0;
	}

	/* otherwise, reroute */
	LOGP(DLSMS, LOGL_INFO, "Rerouting L3 message from a silent call.\n");
	return 1;
}
#endif


/* initiate a silent call with a given subscriber */
int gsm_silent_call_start(struct vlr_subscr *vsub,
	const struct gsm0808_channel_type *ct,
	const char *traffic_dst_ip, uint16_t traffic_dst_port,
	struct vty *vty)
{
	struct gsm_network *net = vsub->vlr->user_ctx;
	struct gsm_trans *trans = trans_alloc(net, vsub, TRANS_SILENT_CALL, 0, 0);

	trans->silent_call.ct = *ct;
	if (traffic_dst_ip) {
		osmo_sockaddr_str_from_str(&trans->silent_call.rtp_cn, traffic_dst_ip, traffic_dst_port);
	}
	trans->silent_call.from_vty = vty;

	if (!paging_request_start(vsub, PAGING_CAUSE_CALL_BACKGROUND, paging_cb_silent, trans,
				  "establish silent call")) {
		trans_free(trans);
		return -ENODEV;
	}

	return 0;
}

/* end a silent call with a given subscriber */
int gsm_silent_call_stop(struct vlr_subscr *vsub)
{
	struct msc_a *msc_a = msc_a_for_vsub(vsub, true);
	struct gsm_trans *trans;
	if (!msc_a) {
		LOGP(DMM, LOGL_ERROR, "%s: Cannot stop silent call, no connection for subscriber\n",
		     vlr_subscr_name(vsub));
		return -ENODEV;
	}

	/* did we actually establish a silent call for this guy? */
	trans = trans_find_by_type(msc_a, TRANS_SILENT_CALL);
	if (!trans) {
		LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot stop silent call, subscriber has no active silent call\n");
		return -ENOENT;
	}

	trans_free(trans);
	return 0;
}