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 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 27 | #include <osmocom/core/msgb.h> |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 28 | #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> |
Harald Welte | 986c3d7 | 2009-11-17 06:12:16 +0100 | [diff] [blame] | 34 | #include <openbsc/chan_alloc.h> |
Holger Hans Peter Freyther | 88519ea | 2010-06-30 12:44:07 +0800 | [diff] [blame] | 35 | #include <openbsc/osmo_msc.h> |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 36 | |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 37 | /* paging of the requested subscriber has completed */ |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 38 | static int paging_cb_silent(unsigned int hooknum, unsigned int event, |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 39 | struct msgb *msg, void *_conn, void *_data) |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 40 | { |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 41 | struct gsm_subscriber_connection *conn = _conn; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 42 | struct scall_signal_data sigdata; |
Holger Hans Peter Freyther | a97152b | 2010-07-23 19:34:34 +0800 | [diff] [blame] | 43 | int rc = 0; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 44 | |
| 45 | if (hooknum != GSM_HOOK_RR_PAGING) |
| 46 | return -EINVAL; |
| 47 | |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 48 | DEBUGP(DLSMS, "paging_cb_silent: "); |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 49 | |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 50 | sigdata.conn = conn; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 51 | sigdata.data = _data; |
| 52 | |
| 53 | switch (event) { |
| 54 | case GSM_PAGING_SUCCEEDED: |
Neels Hofmeyr | ce67be1 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 55 | #if BEFORE_MSCSPLIT |
| 56 | /* Re-enable this log output once we can obtain this information via |
| 57 | * A-interface, see OS#2391. */ |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 58 | DEBUGPC(DLSMS, "success, using Timeslot %u on ARFCN %u\n", |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 59 | conn->lchan->ts->nr, conn->lchan->ts->trx->arfcn); |
Neels Hofmeyr | ce67be1 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 60 | #endif |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 61 | conn->silent_call = 1; |
Harald Welte | 9066b74 | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 62 | msc_subscr_conn_get(conn); |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 63 | /* increment lchan reference count */ |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 64 | osmo_signal_dispatch(SS_SCALL, S_SCALL_SUCCESS, &sigdata); |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 65 | break; |
| 66 | case GSM_PAGING_EXPIRED: |
Holger Hans Peter Freyther | d3baf41 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 67 | case GSM_PAGING_BUSY: |
Holger Hans Peter Freyther | 90c0aff | 2010-12-29 15:28:40 +0100 | [diff] [blame] | 68 | case GSM_PAGING_OOM: |
Holger Hans Peter Freyther | eff4094 | 2012-11-10 19:46:58 +0100 | [diff] [blame] | 69 | DEBUGP(DLSMS, "expired\n"); |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 70 | osmo_signal_dispatch(SS_SCALL, S_SCALL_EXPIRED, &sigdata); |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 71 | break; |
| 72 | default: |
| 73 | rc = -EINVAL; |
| 74 | break; |
| 75 | } |
| 76 | |
| 77 | return rc; |
| 78 | } |
| 79 | |
Philipp Maier | e0d5caa | 2017-02-27 16:56:59 +0100 | [diff] [blame] | 80 | #if 0 |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 81 | /* receive a layer 3 message from a silent call */ |
Holger Hans Peter Freyther | 758f4df | 2010-06-21 10:34:03 +0800 | [diff] [blame] | 82 | int silent_call_rx(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 83 | { |
| 84 | /* FIXME: do something like sending it through a UDP port */ |
Jacob Erlbeck | 8e68b56 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 85 | LOGP(DLSMS, LOGL_NOTICE, "Discarding L3 message from a silent call.\n"); |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 86 | return 0; |
| 87 | } |
Philipp Maier | e0d5caa | 2017-02-27 16:56:59 +0100 | [diff] [blame] | 88 | #endif |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 89 | |
| 90 | struct msg_match { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 91 | uint8_t pdisc; |
| 92 | uint8_t msg_type; |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /* list of messages that are handled inside OpenBSC, even in a silent call */ |
| 96 | static const struct msg_match silent_call_accept[] = { |
| 97 | { GSM48_PDISC_MM, GSM48_MT_MM_LOC_UPD_REQUEST }, |
| 98 | { GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_REQ }, |
| 99 | }; |
| 100 | |
Philipp Maier | e0d5caa | 2017-02-27 16:56:59 +0100 | [diff] [blame] | 101 | #if 0 |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 102 | /* decide if we need to reroute a message as part of a silent call */ |
Holger Hans Peter Freyther | 758f4df | 2010-06-21 10:34:03 +0800 | [diff] [blame] | 103 | int silent_call_reroute(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 104 | { |
| 105 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 106 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
| 107 | uint8_t msg_type = gsm48_hdr_msg_type(gh); |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 108 | int i; |
| 109 | |
| 110 | /* 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] | 111 | if (!conn->silent_call) |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 112 | return 0; |
| 113 | |
| 114 | /* check if we are a special message that is handled in openbsc */ |
| 115 | for (i = 0; i < ARRAY_SIZE(silent_call_accept); i++) { |
| 116 | if (silent_call_accept[i].pdisc == pdisc && |
Neels Hofmeyr | 531734a | 2016-03-14 16:13:24 +0100 | [diff] [blame] | 117 | silent_call_accept[i].msg_type == msg_type) |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /* otherwise, reroute */ |
Jacob Erlbeck | 8e68b56 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 122 | LOGP(DLSMS, LOGL_INFO, "Rerouting L3 message from a silent call.\n"); |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 123 | return 1; |
| 124 | } |
Philipp Maier | e0d5caa | 2017-02-27 16:56:59 +0100 | [diff] [blame] | 125 | #endif |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 126 | |
| 127 | |
| 128 | /* initiate a silent call with a given subscriber */ |
Harald Welte | 9066b74 | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 129 | int gsm_silent_call_start(struct vlr_subscr *vsub, void *data, int type) |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 130 | { |
Holger Hans Peter Freyther | b618c7e | 2015-08-03 11:21:29 +0200 | [diff] [blame] | 131 | struct subscr_request *req; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 132 | |
Neels Hofmeyr | ce67be1 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 133 | /* FIXME the VTY command allows selecting a silent call channel type. |
| 134 | * This doesn't apply to the situation after MSCSPLIT with an |
| 135 | * A-interface. */ |
Neels Hofmeyr | 2188a77 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 136 | req = subscr_request_conn(vsub, paging_cb_silent, data, |
| 137 | "establish silent call"); |
Holger Hans Peter Freyther | b618c7e | 2015-08-03 11:21:29 +0200 | [diff] [blame] | 138 | return req != NULL; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 139 | } |
| 140 | |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 141 | /* end a silent call with a given subscriber */ |
Harald Welte | 9066b74 | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 142 | int gsm_silent_call_stop(struct vlr_subscr *vsub) |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 143 | { |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 144 | struct gsm_subscriber_connection *conn; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 145 | |
Harald Welte | 9066b74 | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 146 | conn = connection_for_subscr(vsub); |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 147 | if (!conn) |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 148 | return -EINVAL; |
| 149 | |
Harald Welte | 83579ca | 2009-12-29 11:17:18 +0100 | [diff] [blame] | 150 | /* did we actually establish a silent call for this guy? */ |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 151 | if (!conn->silent_call) |
Harald Welte | 83579ca | 2009-12-29 11:17:18 +0100 | [diff] [blame] | 152 | return -EINVAL; |
| 153 | |
Neels Hofmeyr | ce67be1 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 154 | #if BEFORE_MSCSPLIT |
| 155 | /* Re-enable this log output once we can obtain this information via |
| 156 | * A-interface, see OS#2391. */ |
Jacob Erlbeck | 8e68b56 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 157 | DEBUGPC(DLSMS, "Stopping silent call using Timeslot %u on ARFCN %u\n", |
| 158 | conn->lchan->ts->nr, conn->lchan->ts->trx->arfcn); |
Neels Hofmeyr | ce67be1 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 159 | #endif |
Jacob Erlbeck | 8e68b56 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 160 | |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 161 | conn->silent_call = 0; |
Harald Welte | 9066b74 | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 162 | msc_subscr_conn_put(conn); |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 163 | |
| 164 | return 0; |
| 165 | } |