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 |
| 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 Welte | dfe6c7d | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 28 | #include <osmocore/msgb.h> |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 29 | #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 Welte | 986c3d7 | 2009-11-17 06:12:16 +0100 | [diff] [blame] | 35 | #include <openbsc/chan_alloc.h> |
Holger Hans Peter Freyther | 88519ea | 2010-06-30 12:44:07 +0800 | [diff] [blame] | 36 | #include <openbsc/osmo_msc.h> |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 37 | |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 38 | /* paging of the requested subscriber has completed */ |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 39 | 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] | 40 | struct msgb *msg, void *_conn, void *_data) |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 41 | { |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 42 | struct gsm_subscriber_connection *conn = _conn; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 43 | struct scall_signal_data sigdata; |
Holger Hans Peter Freyther | a97152b | 2010-07-23 19:34:34 +0800 | [diff] [blame] | 44 | int rc = 0; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 45 | |
| 46 | if (hooknum != GSM_HOOK_RR_PAGING) |
| 47 | return -EINVAL; |
| 48 | |
| 49 | DEBUGP(DSMS, "paging_cb_silent: "); |
| 50 | |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 51 | sigdata.conn = conn; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 52 | sigdata.data = _data; |
| 53 | |
| 54 | switch (event) { |
| 55 | case GSM_PAGING_SUCCEEDED: |
| 56 | DEBUGPC(DSMS, "success, using Timeslot %u on ARFCN %u\n", |
Holger Hans Peter Freyther | 86481c2 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 57 | conn->lchan->ts->nr, conn->lchan->ts->trx->arfcn); |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 58 | conn->silent_call = 1; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 59 | /* increment lchan reference count */ |
| 60 | dispatch_signal(SS_SCALL, S_SCALL_SUCCESS, &sigdata); |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 61 | break; |
| 62 | case GSM_PAGING_EXPIRED: |
| 63 | DEBUGP(DSMS, "expired\n"); |
| 64 | dispatch_signal(SS_SCALL, S_SCALL_EXPIRED, &sigdata); |
| 65 | break; |
| 66 | default: |
| 67 | rc = -EINVAL; |
| 68 | break; |
| 69 | } |
| 70 | |
| 71 | return rc; |
| 72 | } |
| 73 | |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 74 | /* receive a layer 3 message from a silent call */ |
Holger Hans Peter Freyther | 758f4df | 2010-06-21 10:34:03 +0800 | [diff] [blame] | 75 | int silent_call_rx(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 76 | { |
| 77 | /* FIXME: do something like sending it through a UDP port */ |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | struct msg_match { |
| 82 | u_int8_t pdisc; |
| 83 | u_int8_t msg_type; |
| 84 | }; |
| 85 | |
| 86 | /* list of messages that are handled inside OpenBSC, even in a silent call */ |
| 87 | static const struct msg_match silent_call_accept[] = { |
| 88 | { GSM48_PDISC_MM, GSM48_MT_MM_LOC_UPD_REQUEST }, |
| 89 | { GSM48_PDISC_MM, GSM48_MT_MM_CM_SERV_REQ }, |
| 90 | }; |
| 91 | |
| 92 | /* 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] | 93 | int silent_call_reroute(struct gsm_subscriber_connection *conn, struct msgb *msg) |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 94 | { |
| 95 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 96 | u_int8_t pdisc = gh->proto_discr & 0x0f; |
| 97 | int i; |
| 98 | |
| 99 | /* 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] | 100 | if (!conn->silent_call) |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 101 | return 0; |
| 102 | |
| 103 | /* check if we are a special message that is handled in openbsc */ |
| 104 | for (i = 0; i < ARRAY_SIZE(silent_call_accept); i++) { |
| 105 | if (silent_call_accept[i].pdisc == pdisc && |
| 106 | silent_call_accept[i].msg_type == gh->msg_type) |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | /* otherwise, reroute */ |
| 111 | return 1; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | /* initiate a silent call with a given subscriber */ |
Sylvain Munaut | 5048070 | 2010-01-02 14:29:43 +0100 | [diff] [blame] | 116 | int gsm_silent_call_start(struct gsm_subscriber *subscr, void *data, int type) |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 117 | { |
| 118 | int rc; |
| 119 | |
Sylvain Munaut | 5048070 | 2010-01-02 14:29:43 +0100 | [diff] [blame] | 120 | rc = paging_request(subscr->net, subscr, type, |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 121 | paging_cb_silent, data); |
| 122 | return rc; |
| 123 | } |
| 124 | |
Harald Welte | 5100877 | 2009-12-29 11:49:12 +0100 | [diff] [blame] | 125 | /* end a silent call with a given subscriber */ |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 126 | int gsm_silent_call_stop(struct gsm_subscriber *subscr) |
| 127 | { |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 128 | struct gsm_subscriber_connection *conn; |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 129 | |
Holger Hans Peter Freyther | b2be195 | 2010-06-16 13:23:55 +0800 | [diff] [blame] | 130 | conn = connection_for_subscr(subscr); |
| 131 | if (!conn) |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 132 | return -EINVAL; |
| 133 | |
Harald Welte | 83579ca | 2009-12-29 11:17:18 +0100 | [diff] [blame] | 134 | /* did we actually establish a silent call for this guy? */ |
Holger Hans Peter Freyther | 68884aa | 2010-03-23 06:41:45 +0100 | [diff] [blame] | 135 | if (!conn->silent_call) |
Harald Welte | 83579ca | 2009-12-29 11:17:18 +0100 | [diff] [blame] | 136 | return -EINVAL; |
| 137 | |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 138 | conn->silent_call = 0; |
| 139 | msc_release_connection(conn); |
Harald Welte | a148233 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 140 | |
| 141 | return 0; |
| 142 | } |