Holger Hans Peter Freyther | 857e5e6 | 2009-06-12 07:08:13 +0200 | [diff] [blame] | 1 | /* The concept of a subscriber for the MSC, roughly HLR/VLR functionality */ |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 2 | |
| 3 | /* (C) 2008 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | e7bd863 | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 4 | * (C) 2009,2013 by Holger Hans Peter Freyther <zecke@selfish.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 5 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 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 | 52b1f98 | 2008-12-23 20:25:15 +0000 | [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 | 52b1f98 | 2008-12-23 20:25:15 +0000 | [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 | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 23 | #include "../../bscconfig.h" |
| 24 | |
Harald Welte | 75a983f | 2008-12-27 21:34:06 +0000 | [diff] [blame] | 25 | #include <unistd.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <stdio.h> |
| 28 | #include <string.h> |
Holger Freyther | 85a7b36 | 2009-04-18 13:48:55 +0200 | [diff] [blame] | 29 | #include <assert.h> |
Jan Luebbe | bfbdeec | 2012-12-27 00:27:16 +0100 | [diff] [blame] | 30 | #include <time.h> |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 31 | #include <stdbool.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 32 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 33 | #include <osmocom/core/talloc.h> |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 34 | |
Holger Hans Peter Freyther | 763b42a | 2010-12-29 11:07:22 +0100 | [diff] [blame] | 35 | #include <osmocom/vty/vty.h> |
| 36 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 37 | #ifdef BUILD_IU |
| 38 | #include <osmocom/ranap/iu_client.h> |
| 39 | #else |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 40 | #include <osmocom/msc/iu_dummy.h> |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 41 | #endif |
| 42 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 43 | #include <osmocom/msc/gsm_subscriber.h> |
| 44 | #include <osmocom/msc/gsm_04_08.h> |
| 45 | #include <osmocom/msc/debug.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 46 | #include <osmocom/msc/signal.h> |
| 47 | #include <osmocom/msc/db.h> |
| 48 | #include <osmocom/msc/chan_alloc.h> |
| 49 | #include <osmocom/msc/vlr.h> |
| 50 | #include <osmocom/msc/osmo_msc.h> |
| 51 | #include <osmocom/msc/msc_ifaces.h> |
| 52 | #include <osmocom/msc/a_iface.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 53 | |
Neels Hofmeyr | facd57a | 2017-12-15 03:48:48 +0100 | [diff] [blame] | 54 | void subscr_paging_cancel(struct vlr_subscr *vsub, enum gsm_paging_event event) |
| 55 | { |
| 56 | subscr_paging_dispatch(GSM_HOOK_RR_PAGING, event, NULL, NULL, vsub); |
| 57 | } |
| 58 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 59 | int subscr_paging_dispatch(unsigned int hooknum, unsigned int event, |
| 60 | struct msgb *msg, void *data, void *param) |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 61 | { |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 62 | struct subscr_request *request, *tmp; |
Sylvain Munaut | 8a31a3f | 2010-12-01 23:04:03 +0100 | [diff] [blame] | 63 | struct gsm_subscriber_connection *conn = data; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 64 | struct vlr_subscr *vsub = param; |
Sylvain Munaut | 8a31a3f | 2010-12-01 23:04:03 +0100 | [diff] [blame] | 65 | struct paging_signal_data sig_data; |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 66 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 67 | OSMO_ASSERT(vsub); |
| 68 | OSMO_ASSERT(hooknum == GSM_HOOK_RR_PAGING); |
| 69 | OSMO_ASSERT(!(conn && (conn->vsub != vsub))); |
| 70 | OSMO_ASSERT(!((event == GSM_PAGING_SUCCEEDED) && !conn)); |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 71 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 72 | LOGP(DPAG, LOGL_DEBUG, "Paging %s for %s (event=%d)\n", |
| 73 | event == GSM_PAGING_SUCCEEDED ? "success" : "failure", |
| 74 | vlr_subscr_name(vsub), event); |
| 75 | |
| 76 | if (!vsub->cs.is_paging) { |
| 77 | LOGP(DPAG, LOGL_ERROR, |
| 78 | "Paging Response received for subscriber" |
| 79 | " that is not paging.\n"); |
| 80 | return -EINVAL; |
| 81 | } |
| 82 | |
Neels Hofmeyr | 2ff5bcd | 2017-12-15 03:02:27 +0100 | [diff] [blame] | 83 | osmo_timer_del(&vsub->cs.paging_response_timer); |
| 84 | |
| 85 | if (event == GSM_PAGING_SUCCEEDED |
| 86 | || event == GSM_PAGING_EXPIRED) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 87 | msc_stop_paging(vsub); |
Holger Hans Peter Freyther | 778c7d1 | 2015-08-03 11:18:23 +0200 | [diff] [blame] | 88 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 89 | /* Inform parts of the system we don't know */ |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 90 | sig_data.vsub = vsub; |
| 91 | sig_data.conn = conn; |
Holger Hans Peter Freyther | d3baf41 | 2010-12-23 18:19:17 +0100 | [diff] [blame] | 92 | sig_data.paging_result = event; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 93 | osmo_signal_dispatch(SS_PAGING, |
| 94 | event == GSM_PAGING_SUCCEEDED ? |
| 95 | S_PAGING_SUCCEEDED : S_PAGING_EXPIRED, |
| 96 | &sig_data); |
Sylvain Munaut | 8a31a3f | 2010-12-01 23:04:03 +0100 | [diff] [blame] | 97 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 98 | llist_for_each_entry_safe(request, tmp, &vsub->cs.requests, entry) { |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 99 | llist_del(&request->entry); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 100 | if (request->cbfn) { |
| 101 | LOGP(DPAG, LOGL_DEBUG, "Calling paging cbfn.\n"); |
| 102 | request->cbfn(hooknum, event, msg, data, request->param); |
| 103 | } else |
| 104 | LOGP(DPAG, LOGL_DEBUG, "Paging without action.\n"); |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 105 | talloc_free(request); |
Holger Hans Peter Freyther | ffccb77 | 2010-12-28 17:47:43 +0100 | [diff] [blame] | 106 | } |
Holger Hans Peter Freyther | f72b3d5 | 2010-12-28 17:27:05 +0100 | [diff] [blame] | 107 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 108 | /* balanced with the moment we start paging */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 109 | vsub->cs.is_paging = false; |
| 110 | vlr_subscr_put(vsub); |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 114 | int msc_paging_request(struct vlr_subscr *vsub) |
| 115 | { |
| 116 | /* The subscriber was last seen in subscr->lac. Find out which |
| 117 | * BSCs/RNCs are responsible and send them a paging request via open |
| 118 | * SCCP connections (if any). */ |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 119 | switch (vsub->cs.attached_via_ran) { |
| 120 | case RAN_GERAN_A: |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 121 | return a_iface_tx_paging(vsub->imsi, vsub->tmsi, vsub->lac); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 122 | case RAN_UTRAN_IU: |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 123 | return ranap_iu_page_cs(vsub->imsi, |
| 124 | vsub->tmsi == GSM_RESERVED_TMSI? |
| 125 | NULL : &vsub->tmsi, |
| 126 | vsub->lac); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 127 | default: |
| 128 | break; |
| 129 | } |
| 130 | |
| 131 | LOGP(DPAG, LOGL_ERROR, "%s: Cannot page, subscriber not attached\n", |
| 132 | vlr_subscr_name(vsub)); |
| 133 | return -EINVAL; |
| 134 | } |
| 135 | |
Neels Hofmeyr | 2ff5bcd | 2017-12-15 03:02:27 +0100 | [diff] [blame] | 136 | static void paging_response_timer_cb(void *data) |
| 137 | { |
| 138 | struct vlr_subscr *vsub = data; |
Neels Hofmeyr | facd57a | 2017-12-15 03:48:48 +0100 | [diff] [blame] | 139 | subscr_paging_cancel(vsub, GSM_PAGING_EXPIRED); |
Neels Hofmeyr | 2ff5bcd | 2017-12-15 03:02:27 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 142 | /*! \brief Start a paging request for vsub, call cbfn(param) when done. |
| 143 | * \param vsub subscriber to page. |
| 144 | * \param cbfn function to call when the conn is established. |
| 145 | * \param param caller defined param to pass to cbfn(). |
| 146 | * \param label human readable label of the request kind used for logging. |
| 147 | */ |
| 148 | struct subscr_request *subscr_request_conn(struct vlr_subscr *vsub, |
| 149 | gsm_cbfn *cbfn, void *param, |
| 150 | const char *label) |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 151 | { |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 152 | int rc; |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 153 | struct subscr_request *request; |
Neels Hofmeyr | 2ff5bcd | 2017-12-15 03:02:27 +0100 | [diff] [blame] | 154 | struct gsm_network *net = vsub->vlr->user_ctx; |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 155 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 156 | /* Start paging.. we know it is async so we can do it before */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 157 | if (!vsub->cs.is_paging) { |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 158 | LOGP(DMM, LOGL_DEBUG, "Subscriber %s not paged yet, start paging.\n", |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 159 | vlr_subscr_name(vsub)); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 160 | rc = msc_paging_request(vsub); |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 161 | if (rc <= 0) { |
| 162 | LOGP(DMM, LOGL_ERROR, "Subscriber %s paging failed: %d\n", |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 163 | vlr_subscr_name(vsub), rc); |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 164 | return NULL; |
| 165 | } |
| 166 | /* reduced on the first paging callback */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 167 | vlr_subscr_get(vsub); |
| 168 | vsub->cs.is_paging = true; |
Neels Hofmeyr | 2ff5bcd | 2017-12-15 03:02:27 +0100 | [diff] [blame] | 169 | osmo_timer_setup(&vsub->cs.paging_response_timer, paging_response_timer_cb, vsub); |
| 170 | osmo_timer_schedule(&vsub->cs.paging_response_timer, net->paging_response_timer, 0); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 171 | } else { |
| 172 | LOGP(DMM, LOGL_DEBUG, "Subscriber %s already paged.\n", |
| 173 | vlr_subscr_name(vsub)); |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 174 | } |
| 175 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 176 | /* TODO: Stop paging in case of memory allocation failure */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 177 | request = talloc_zero(vsub, struct subscr_request); |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 178 | if (!request) |
| 179 | return NULL; |
| 180 | |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 181 | request->cbfn = cbfn; |
| 182 | request->param = param; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 183 | llist_add_tail(&request->entry, &vsub->cs.requests); |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 184 | return request; |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 185 | } |
| 186 | |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 187 | void subscr_remove_request(struct subscr_request *request) |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 188 | { |
Holger Hans Peter Freyther | d6d7aff | 2015-04-06 12:03:45 +0200 | [diff] [blame] | 189 | llist_del(&request->entry); |
| 190 | talloc_free(request); |
Sylvain Munaut | 1e24550 | 2010-12-01 21:07:29 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 193 | struct gsm_subscriber_connection *connection_for_subscr(struct vlr_subscr *vsub) |
Holger Hans Peter Freyther | 7634ec1 | 2013-10-04 08:35:11 +0200 | [diff] [blame] | 194 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 195 | struct gsm_network *net = vsub->vlr->user_ctx; |
Neels Hofmeyr | 1a60644 | 2016-05-10 13:56:43 +0200 | [diff] [blame] | 196 | struct gsm_subscriber_connection *conn; |
| 197 | |
| 198 | llist_for_each_entry(conn, &net->subscr_conns, entry) { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 199 | if (conn->vsub == vsub) |
Neels Hofmeyr | 1a60644 | 2016-05-10 13:56:43 +0200 | [diff] [blame] | 200 | return conn; |
| 201 | } |
| 202 | |
| 203 | return NULL; |
| 204 | } |