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