Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 1 | /* 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 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 |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * GNU Affero General Public License for more details. |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 17 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 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/>. |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include <unistd.h> |
| 25 | #include <errno.h> |
| 26 | |
Sylvain Munaut | 9355830 | 2019-02-14 20:13:08 +0100 | [diff] [blame] | 27 | #include <osmocom/core/byteswap.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 28 | #include <osmocom/core/msgb.h> |
Philipp Maier | 9286114 | 2019-03-15 09:43:40 +0100 | [diff] [blame] | 29 | #include <osmocom/core/utils.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 30 | #include <osmocom/msc/signal.h> |
| 31 | #include <osmocom/msc/debug.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 32 | #include <osmocom/msc/gsm_data.h> |
| 33 | #include <osmocom/msc/gsm_subscriber.h> |
Alexander Couzens | eff28ab | 2024-09-12 00:55:25 +0200 | [diff] [blame] | 34 | #include <osmocom/vlr/vlr.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 35 | #include <osmocom/msc/msc_a.h> |
| 36 | #include <osmocom/msc/paging.h> |
| 37 | #include <osmocom/msc/transaction.h> |
| 38 | #include <osmocom/msc/silent_call.h> |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 39 | |
Sylvain Munaut | 9355830 | 2019-02-14 20:13:08 +0100 | [diff] [blame] | 40 | #include <osmocom/sigtran/sccp_helpers.h> |
| 41 | |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 42 | /* paging of the requested subscriber has completed */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 43 | void paging_cb_silent(struct msc_a *msc_a, struct gsm_trans *trans) |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 44 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 45 | struct scall_signal_data sigdata = { |
| 46 | .msc_a = msc_a, |
| 47 | .vty = trans->silent_call.from_vty, |
| 48 | }; |
| 49 | struct ran_msg assignment; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 50 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 51 | if (!msc_a) { |
| 52 | LOG_MSC_A(msc_a, LOGL_ERROR, "Silent call: MS not responding to Paging\n"); |
| 53 | osmo_signal_dispatch(SS_SCALL, S_SCALL_FAILED, &sigdata); |
| 54 | trans_free(trans); |
| 55 | return; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 58 | LOG_MSC_A(msc_a, LOGL_INFO, "Silent call: MS responding to Paging\n"); |
Sylvain Munaut | 9355830 | 2019-02-14 20:13:08 +0100 | [diff] [blame] | 59 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 60 | trans->msc_a = msc_a; |
| 61 | msc_a_get(msc_a, MSC_A_USE_SILENT_CALL); |
| 62 | |
| 63 | osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans); |
| 64 | |
| 65 | assignment = (struct ran_msg){ |
| 66 | .msg_type = RAN_MSG_ASSIGNMENT_COMMAND, |
| 67 | .assignment_command = { |
| 68 | .channel_type = &trans->silent_call.ct, |
| 69 | .cn_rtp = &trans->silent_call.rtp_cn, |
| 70 | }, |
| 71 | }; |
| 72 | if (msc_a_ran_down(msc_a, MSC_ROLE_I, &assignment)) { |
| 73 | LOG_MSC_A(msc_a, LOGL_ERROR, "Silent call failed\n"); |
| 74 | osmo_signal_dispatch(SS_SCALL, S_SCALL_FAILED, &sigdata); |
| 75 | trans_free(trans); |
| 76 | } else { |
| 77 | osmo_signal_dispatch(SS_SCALL, S_SCALL_SUCCESS, &sigdata); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | void trans_silent_call_free(struct gsm_trans *trans) |
| 82 | { |
| 83 | struct scall_signal_data sigdata = { |
| 84 | .msc_a = trans->msc_a, |
| 85 | .vty = trans->silent_call.from_vty, |
| 86 | }; |
| 87 | osmo_signal_dispatch(SS_SCALL, S_SCALL_DETACHED, &sigdata); |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Philipp Maier | e0d5caa | 2017-02-27 16:56:59 +0100 | [diff] [blame] | 90 | #if 0 |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 91 | /* receive a layer 3 message from a silent call */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 92 | int silent_call_rx(struct ran_conn *conn, struct msgb *msg) |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 93 | { |
| 94 | /* FIXME: do something like sending it through a UDP port */ |
Jacob Erlbeck | 8e68b56 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 95 | LOGP(DLSMS, LOGL_NOTICE, "Discarding L3 message from a silent call.\n"); |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | struct msg_match { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 100 | uint8_t pdisc; |
| 101 | uint8_t msg_type; |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | /* list of messages that are handled inside OpenBSC, even in a silent call */ |
| 105 | static const struct msg_match silent_call_accept[] = { |
| 106 | { GSM48_PDISC_MM, GSM48_MT_MM_LOC_UPD_REQUEST }, |
| 107 | { GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_REQ }, |
| 108 | }; |
| 109 | |
| 110 | /* decide if we need to reroute a message as part of a silent call */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 111 | int silent_call_reroute(struct ran_conn *conn, struct msgb *msg) |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 112 | { |
| 113 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 114 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
| 115 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 116 | int i; |
| 117 | |
| 118 | /* if we're not part of a silent call, never reroute */ |
Holger Hans Peter Freyther | 758f4df | 2010-06-21 10:34:03 +0800 | [diff] [blame] | 119 | if (!conn->silent_call) |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 120 | return 0; |
| 121 | |
| 122 | /* check if we are a special message that is handled in openbsc */ |
| 123 | for (i = 0; i < ARRAY_SIZE(silent_call_accept); i++) { |
| 124 | if (silent_call_accept[i].pdisc == pdisc && |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 125 | silent_call_accept[i].msg_type == msg_type) |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | /* otherwise, reroute */ |
Jacob Erlbeck | 8e68b56 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 130 | LOGP(DLSMS, LOGL_INFO, "Rerouting L3 message from a silent call.\n"); |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 131 | return 1; |
| 132 | } |
Philipp Maier | e0d5caa | 2017-02-27 16:56:59 +0100 | [diff] [blame] | 133 | #endif |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 134 | |
| 135 | |
| 136 | /* initiate a silent call with a given subscriber */ |
Sylvain Munaut | 9355830 | 2019-02-14 20:13:08 +0100 | [diff] [blame] | 137 | int gsm_silent_call_start(struct vlr_subscr *vsub, |
| 138 | const struct gsm0808_channel_type *ct, |
| 139 | const char *traffic_dst_ip, uint16_t traffic_dst_port, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 140 | struct vty *vty) |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 141 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 142 | struct gsm_network *net = vsub->vlr->user_ctx; |
Vadim Yanitskiy | 2984d13 | 2023-12-12 22:34:20 +0700 | [diff] [blame] | 143 | struct gsm_trans *trans; |
| 144 | |
| 145 | trans = trans_alloc(net, vsub, TRANS_SILENT_CALL, 0, 0); |
| 146 | if (trans == NULL) |
| 147 | return -ENODEV; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 148 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 149 | trans->silent_call.ct = *ct; |
Sylvain Munaut | 9355830 | 2019-02-14 20:13:08 +0100 | [diff] [blame] | 150 | if (traffic_dst_ip) { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 151 | osmo_sockaddr_str_from_str(&trans->silent_call.rtp_cn, traffic_dst_ip, traffic_dst_port); |
Sylvain Munaut | 9355830 | 2019-02-14 20:13:08 +0100 | [diff] [blame] | 152 | } |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 153 | trans->silent_call.from_vty = vty; |
Sylvain Munaut | 9355830 | 2019-02-14 20:13:08 +0100 | [diff] [blame] | 154 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 155 | if (!paging_request_start(vsub, PAGING_CAUSE_CALL_BACKGROUND, paging_cb_silent, trans, |
| 156 | "establish silent call")) { |
| 157 | trans_free(trans); |
Neels Hofmeyr | d656dff | 2018-03-09 14:59:44 +0100 | [diff] [blame] | 158 | return -ENODEV; |
Sylvain Munaut | 9355830 | 2019-02-14 20:13:08 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Neels Hofmeyr | d656dff | 2018-03-09 14:59:44 +0100 | [diff] [blame] | 161 | return 0; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 164 | /* end a silent call with a given subscriber */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 165 | int gsm_silent_call_stop(struct vlr_subscr *vsub) |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 166 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 167 | struct msc_a *msc_a = msc_a_for_vsub(vsub, true); |
| 168 | struct gsm_trans *trans; |
| 169 | if (!msc_a) { |
Neels Hofmeyr | d656dff | 2018-03-09 14:59:44 +0100 | [diff] [blame] | 170 | LOGP(DMM, LOGL_ERROR, "%s: Cannot stop silent call, no connection for subscriber\n", |
| 171 | vlr_subscr_name(vsub)); |
| 172 | return -ENODEV; |
| 173 | } |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 174 | |
Harald Welte | 83579ca | 2009-12-29 11:17:18 +0100 | [diff] [blame] | 175 | /* did we actually establish a silent call for this guy? */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 176 | trans = trans_find_by_type(msc_a, TRANS_SILENT_CALL); |
| 177 | if (!trans) { |
| 178 | LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot stop silent call, subscriber has no active silent call\n"); |
Neels Hofmeyr | d656dff | 2018-03-09 14:59:44 +0100 | [diff] [blame] | 179 | return -ENOENT; |
| 180 | } |
Harald Welte | 83579ca | 2009-12-29 11:17:18 +0100 | [diff] [blame] | 181 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 182 | trans_free(trans); |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 183 | return 0; |
| 184 | } |