blob: fda28dd73b6b97f99d8baa38c639414c159f7af9 [file] [log] [blame]
Harald Welte798418a2009-11-29 22:56:14 +01001/* Handover Logic for Inter-BTS (Intra-BSC) Handover. This does not
2 * actually implement the handover algorithm/decision, but executes a
3 * handover decision */
4
5/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
6 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +010010 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
Harald Welte798418a2009-11-29 22:56:14 +010012 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * GNU Affero General Public License for more details.
Harald Welte798418a2009-11-29 22:56:14 +010018 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte798418a2009-11-29 22:56:14 +010021 *
22 */
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <errno.h>
28#include <time.h>
29#include <netinet/in.h>
30
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010031#include <osmocom/core/msgb.h>
Neels Hofmeyrc0164792017-09-04 15:15:32 +020032#include <osmocom/bsc/debug.h>
33#include <osmocom/bsc/gsm_data.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010034#include <osmocom/gsm/gsm_utils.h>
Neels Hofmeyrc0164792017-09-04 15:15:32 +020035#include <osmocom/bsc/abis_rsl.h>
36#include <osmocom/bsc/chan_alloc.h>
37#include <osmocom/bsc/signal.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010038#include <osmocom/core/talloc.h>
Neels Hofmeyrc0164792017-09-04 15:15:32 +020039#include <osmocom/bsc/bsc_subscriber.h>
40#include <osmocom/bsc/gsm_04_08_utils.h>
Harald Welte798418a2009-11-29 22:56:14 +010041
42struct bsc_handover {
43 struct llist_head list;
44
45 struct gsm_lchan *old_lchan;
46 struct gsm_lchan *new_lchan;
47
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020048 struct osmo_timer_list T3103;
Harald Welte798418a2009-11-29 22:56:14 +010049
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020050 uint8_t ho_ref;
Neels Hofmeyr5eaa4fb2017-11-27 17:57:15 +010051
52 bool inter_cell;
53 bool async;
Harald Welte798418a2009-11-29 22:56:14 +010054};
55
56static LLIST_HEAD(bsc_handovers);
57
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +010058static void handover_free(struct bsc_handover *ho)
59{
60 osmo_timer_del(&ho->T3103);
61 llist_del(&ho->list);
62 talloc_free(ho);
63}
64
Harald Welte798418a2009-11-29 22:56:14 +010065static struct bsc_handover *bsc_ho_by_new_lchan(struct gsm_lchan *new_lchan)
66{
67 struct bsc_handover *ho;
68
69 llist_for_each_entry(ho, &bsc_handovers, list) {
70 if (ho->new_lchan == new_lchan)
71 return ho;
72 }
73
74 return NULL;
75}
76
77static struct bsc_handover *bsc_ho_by_old_lchan(struct gsm_lchan *old_lchan)
78{
79 struct bsc_handover *ho;
80
81 llist_for_each_entry(ho, &bsc_handovers, list) {
82 if (ho->old_lchan == old_lchan)
83 return ho;
84 }
85
86 return NULL;
87}
88
Neels Hofmeyr3e62d412016-05-23 17:56:57 +020089/*! \brief Hand over the specified logical channel to the specified new BTS.
90 * This is the main entry point for the actual handover algorithm, after the
91 * decision whether to initiate HO to a specific BTS. */
Harald Welte798418a2009-11-29 22:56:14 +010092int bsc_handover_start(struct gsm_lchan *old_lchan, struct gsm_bts *bts)
93{
94 struct gsm_lchan *new_lchan;
95 struct bsc_handover *ho;
Neels Hofmeyrc766c9e2017-11-27 17:58:04 +010096 static uint8_t ho_ref = 0;
Harald Welte798418a2009-11-29 22:56:14 +010097 int rc;
98
Harald Welte66706812009-12-17 22:23:21 +010099 /* don't attempt multiple handovers for the same lchan at
100 * the same time */
101 if (bsc_ho_by_old_lchan(old_lchan))
102 return -EBUSY;
103
Philipp Maier39f62bb2017-04-09 12:32:51 +0200104 DEBUGP(DHO, "Beginning with handover operation"
105 "(old_lchan on BTS %u, new BTS %u) ...\n",
Harald Welte8d77b952009-12-17 00:31:10 +0100106 old_lchan->ts->trx->bts->nr, bts->nr);
107
Alexander Couzensb847a212016-08-02 11:34:11 +0200108 rate_ctr_inc(&bts->network->bsc_ctrs->ctr[BSC_CTR_HANDOVER_ATTEMPTED]);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100109
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800110 if (!old_lchan->conn) {
111 LOGP(DHO, LOGL_ERROR, "Old lchan lacks connection data.\n");
112 return -ENOSPC;
113 }
114
Holger Hans Peter Freyther457c2a82010-09-06 08:58:42 +0800115 new_lchan = lchan_alloc(bts, old_lchan->type, 0);
Harald Welte8d77b952009-12-17 00:31:10 +0100116 if (!new_lchan) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100117 LOGP(DHO, LOGL_NOTICE, "No free channel\n");
Alexander Couzensb847a212016-08-02 11:34:11 +0200118 rate_ctr_inc(&bts->network->bsc_ctrs->ctr[BSC_CTR_HANDOVER_NO_CHANNEL]);
Harald Welte798418a2009-11-29 22:56:14 +0100119 return -ENOSPC;
Harald Welte8d77b952009-12-17 00:31:10 +0100120 }
Harald Welte798418a2009-11-29 22:56:14 +0100121
Holger Hans Peter Freyther90cdd282010-12-21 13:29:14 +0100122 ho = talloc_zero(tall_bsc_ctx, struct bsc_handover);
Harald Welte798418a2009-11-29 22:56:14 +0100123 if (!ho) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100124 LOGP(DHO, LOGL_FATAL, "Out of Memory\n");
Harald Welte798418a2009-11-29 22:56:14 +0100125 lchan_free(new_lchan);
126 return -ENOMEM;
127 }
128 ho->old_lchan = old_lchan;
129 ho->new_lchan = new_lchan;
Harald Welte8d77b952009-12-17 00:31:10 +0100130 ho->ho_ref = ho_ref++;
Neels Hofmeyr5eaa4fb2017-11-27 17:57:15 +0100131 if (old_lchan->ts->trx->bts != bts) {
132 ho->inter_cell = true;
133 ho->async = true;
134 }
Harald Welte8d77b952009-12-17 00:31:10 +0100135
136 /* copy some parameters from old lchan */
137 memcpy(&new_lchan->encr, &old_lchan->encr, sizeof(new_lchan->encr));
138 new_lchan->ms_power = old_lchan->ms_power;
139 new_lchan->bs_power = old_lchan->bs_power;
140 new_lchan->rsl_cmode = old_lchan->rsl_cmode;
141 new_lchan->tch_mode = old_lchan->tch_mode;
Andreas Eversberg73266522014-01-19 11:47:44 +0100142 memcpy(&new_lchan->mr_ms_lv, &old_lchan->mr_ms_lv, ARRAY_SIZE(new_lchan->mr_ms_lv));
143 memcpy(&new_lchan->mr_bts_lv, &old_lchan->mr_bts_lv, ARRAY_SIZE(new_lchan->mr_bts_lv));
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800144
145 new_lchan->conn = old_lchan->conn;
146 new_lchan->conn->ho_lchan = new_lchan;
Harald Welte798418a2009-11-29 22:56:14 +0100147
148 /* FIXME: do we have a better idea of the timing advance? */
Neels Hofmeyr5eaa4fb2017-11-27 17:57:15 +0100149 rc = rsl_chan_activate_lchan(new_lchan,
Neels Hofmeyr063868e2018-02-15 14:18:22 +0100150 ho->async ? RSL_ACT_INTER_ASYNC : RSL_ACT_INTER_SYNC,
Neels Hofmeyr5eaa4fb2017-11-27 17:57:15 +0100151 ho->ho_ref);
Harald Welte798418a2009-11-29 22:56:14 +0100152 if (rc < 0) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100153 LOGP(DHO, LOGL_ERROR, "could not activate channel\n");
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800154 new_lchan->conn->ho_lchan = NULL;
Holger Hans Peter Freytherc8396672010-12-26 19:59:32 +0100155 new_lchan->conn = NULL;
Harald Welte798418a2009-11-29 22:56:14 +0100156 talloc_free(ho);
157 lchan_free(new_lchan);
158 return rc;
159 }
160
Holger Hans Peter Freyther5eec9d92010-04-10 00:16:04 +0200161 rsl_lchan_set_state(new_lchan, LCHAN_S_ACT_REQ);
Harald Welte798418a2009-11-29 22:56:14 +0100162 llist_add(&ho->list, &bsc_handovers);
163 /* we continue in the SS_LCHAN handler / ho_chan_activ_ack */
164
165 return 0;
166}
167
Neels Hofmeyra2733ae2017-11-28 00:29:25 +0100168/* clear any operation for this connection */
Holger Hans Peter Freytherebd50a62010-12-27 13:46:48 +0100169void bsc_clear_handover(struct gsm_subscriber_connection *conn, int free_lchan)
Holger Hans Peter Freytherf2553a62010-06-30 12:58:14 +0800170{
171 struct bsc_handover *ho;
172
173 ho = bsc_ho_by_new_lchan(conn->ho_lchan);
174
175
176 if (!ho && conn->ho_lchan)
177 LOGP(DHO, LOGL_ERROR, "BUG: We lost some state.\n");
178
179 if (!ho) {
180 LOGP(DHO, LOGL_ERROR, "unable to find HO record\n");
181 return;
182 }
183
184 conn->ho_lchan->conn = NULL;
185 conn->ho_lchan = NULL;
Holger Hans Peter Freytherebd50a62010-12-27 13:46:48 +0100186
187 if (free_lchan)
Holger Hans Peter Freytherd66777f2012-12-06 12:20:56 +0100188 lchan_release(ho->new_lchan, 0, RSL_REL_LOCAL_END);
Holger Hans Peter Freytherf2553a62010-06-30 12:58:14 +0800189
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100190 handover_free(ho);
Holger Hans Peter Freytherf2553a62010-06-30 12:58:14 +0800191}
192
Harald Welte798418a2009-11-29 22:56:14 +0100193/* T3103 expired: Handover has failed without HO COMPLETE or HO FAIL */
194static void ho_T3103_cb(void *_ho)
195{
196 struct bsc_handover *ho = _ho;
Harald Welteffa55a42009-12-22 19:07:32 +0100197 struct gsm_network *net = ho->new_lchan->ts->trx->bts->network;
Harald Welte798418a2009-11-29 22:56:14 +0100198
Harald Welte8d77b952009-12-17 00:31:10 +0100199 DEBUGP(DHO, "HO T3103 expired\n");
Alexander Couzensb847a212016-08-02 11:34:11 +0200200 rate_ctr_inc(&net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_TIMEOUT]);
Harald Welte8d77b952009-12-17 00:31:10 +0100201
Holger Hans Peter Freytherd9c9f072010-06-30 13:04:13 +0800202 ho->new_lchan->conn->ho_lchan = NULL;
203 ho->new_lchan->conn = NULL;
Holger Hans Peter Freytherd66777f2012-12-06 12:20:56 +0100204 lchan_release(ho->new_lchan, 0, RSL_REL_LOCAL_END);
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100205 handover_free(ho);
Harald Welte798418a2009-11-29 22:56:14 +0100206}
207
208/* RSL has acknowledged activation of the new lchan */
209static int ho_chan_activ_ack(struct gsm_lchan *new_lchan)
210{
211 struct bsc_handover *ho;
Harald Welte798418a2009-11-29 22:56:14 +0100212
Harald Weltea9fa8dc2009-12-18 14:50:08 +0100213 /* we need to check if this channel activation is related to
214 * a handover at all (and if, which particular handover) */
Harald Welte798418a2009-11-29 22:56:14 +0100215 ho = bsc_ho_by_new_lchan(new_lchan);
Harald Weltea9fa8dc2009-12-18 14:50:08 +0100216 if (!ho)
Harald Welte798418a2009-11-29 22:56:14 +0100217 return -ENODEV;
Harald Weltea9fa8dc2009-12-18 14:50:08 +0100218
219 DEBUGP(DHO, "handover activate ack, send HO Command\n");
Harald Welte798418a2009-11-29 22:56:14 +0100220
221 /* we can now send the 04.08 HANDOVER COMMAND to the MS
222 * using the old lchan */
223
Holger Hans Peter Freythera5050b12012-09-11 11:55:03 +0200224 gsm48_send_ho_cmd(ho->old_lchan, new_lchan, 0, ho->ho_ref);
Harald Welte798418a2009-11-29 22:56:14 +0100225
226 /* start T3103. We can continue either with T3103 expiration,
227 * 04.08 HANDOVER COMPLETE or 04.08 HANDOVER FAIL */
Pablo Neira Ayuso51215762017-05-08 20:57:52 +0200228 osmo_timer_setup(&ho->T3103, ho_T3103_cb, ho);
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200229 osmo_timer_schedule(&ho->T3103, 10, 0);
Harald Welte798418a2009-11-29 22:56:14 +0100230
Harald Weltea0379022009-12-20 17:04:40 +0100231 /* create a RTP connection */
232 if (is_ipaccess_bts(new_lchan->ts->trx->bts))
233 rsl_ipacc_crcx(new_lchan);
234
Harald Welte798418a2009-11-29 22:56:14 +0100235 return 0;
236}
237
238/* RSL has not acknowledged activation of the new lchan */
239static int ho_chan_activ_nack(struct gsm_lchan *new_lchan)
240{
241 struct bsc_handover *ho;
242
243 ho = bsc_ho_by_new_lchan(new_lchan);
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100244 if (!ho) {
Harald Welte25cf8242012-07-06 14:21:55 +0200245 LOGP(DHO, LOGL_INFO, "ACT NACK: unable to find HO record\n");
Harald Welte798418a2009-11-29 22:56:14 +0100246 return -ENODEV;
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100247 }
Harald Welte798418a2009-11-29 22:56:14 +0100248
Holger Hans Peter Freyther2391b4c2010-12-21 13:30:17 +0100249 new_lchan->conn->ho_lchan = NULL;
250 new_lchan->conn = NULL;
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100251 handover_free(ho);
Harald Welte798418a2009-11-29 22:56:14 +0100252
253 /* FIXME: maybe we should try to allocate a new LCHAN here? */
254
255 return 0;
256}
257
258/* GSM 04.08 HANDOVER COMPLETE has been received on new channel */
259static int ho_gsm48_ho_compl(struct gsm_lchan *new_lchan)
260{
Holger Hans Peter Freyther9d3e2ec2010-12-26 20:34:26 +0100261 struct gsm_network *net;
Harald Welte798418a2009-11-29 22:56:14 +0100262 struct bsc_handover *ho;
263
264 ho = bsc_ho_by_new_lchan(new_lchan);
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100265 if (!ho) {
266 LOGP(DHO, LOGL_ERROR, "unable to find HO record\n");
Harald Welte798418a2009-11-29 22:56:14 +0100267 return -ENODEV;
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100268 }
Harald Welte798418a2009-11-29 22:56:14 +0100269
Holger Hans Peter Freyther9d3e2ec2010-12-26 20:34:26 +0100270 net = new_lchan->ts->trx->bts->network;
Harald Welte7c639a02009-12-25 23:02:50 +0100271 LOGP(DHO, LOGL_INFO, "Subscriber %s HO from BTS %u->%u on ARFCN "
Neels Hofmeyr7b656882017-07-09 22:09:18 +0200272 "%u->%u\n", bsc_subscr_name(ho->old_lchan->conn->bsub),
Harald Welte7c639a02009-12-25 23:02:50 +0100273 ho->old_lchan->ts->trx->bts->nr, new_lchan->ts->trx->bts->nr,
274 ho->old_lchan->ts->trx->arfcn, new_lchan->ts->trx->arfcn);
275
Alexander Couzensb847a212016-08-02 11:34:11 +0200276 rate_ctr_inc(&net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_COMPLETED]);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100277
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200278 osmo_timer_del(&ho->T3103);
Harald Welte798418a2009-11-29 22:56:14 +0100279
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800280 /* Replace the ho lchan with the primary one */
281 if (ho->old_lchan != new_lchan->conn->lchan)
282 LOGP(DHO, LOGL_ERROR, "Primary lchan changed during handover.\n");
283
284 if (new_lchan != new_lchan->conn->ho_lchan)
285 LOGP(DHO, LOGL_ERROR, "Handover channel changed during this handover.\n");
286
287 new_lchan->conn->ho_lchan = NULL;
288 new_lchan->conn->lchan = new_lchan;
289 ho->old_lchan->conn = NULL;
Harald Weltefe18d5c2009-12-17 17:14:43 +0100290
Holger Hans Peter Freytherd66777f2012-12-06 12:20:56 +0100291 lchan_release(ho->old_lchan, 0, RSL_REL_LOCAL_END);
Harald Welteade773f2009-12-21 13:29:19 +0100292
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100293 handover_free(ho);
Harald Welte798418a2009-11-29 22:56:14 +0100294 return 0;
295}
296
297/* GSM 04.08 HANDOVER FAIL has been received */
298static int ho_gsm48_ho_fail(struct gsm_lchan *old_lchan)
299{
Harald Welteffa55a42009-12-22 19:07:32 +0100300 struct gsm_network *net = old_lchan->ts->trx->bts->network;
Harald Welte798418a2009-11-29 22:56:14 +0100301 struct bsc_handover *ho;
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100302 struct gsm_lchan *new_lchan;
Harald Welte798418a2009-11-29 22:56:14 +0100303
304 ho = bsc_ho_by_old_lchan(old_lchan);
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100305 if (!ho) {
306 LOGP(DHO, LOGL_ERROR, "unable to find HO record\n");
Harald Welte798418a2009-11-29 22:56:14 +0100307 return -ENODEV;
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100308 }
Harald Welte798418a2009-11-29 22:56:14 +0100309
Alexander Couzensb847a212016-08-02 11:34:11 +0200310 rate_ctr_inc(&net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_FAILED]);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100311
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100312 new_lchan = ho->new_lchan;
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800313
314 /* release the channel and forget about it */
315 ho->new_lchan->conn->ho_lchan = NULL;
316 ho->new_lchan->conn = NULL;
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100317 handover_free(ho);
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800318
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100319 lchan_release(new_lchan, 0, RSL_REL_LOCAL_END);
320
Harald Welte798418a2009-11-29 22:56:14 +0100321
322 return 0;
323}
324
325/* GSM 08.58 HANDOVER DETECT has been received */
326static int ho_rsl_detect(struct gsm_lchan *new_lchan)
327{
328 struct bsc_handover *ho;
329
Harald Welte6f7a5a72009-12-18 11:52:03 +0100330 ho = bsc_ho_by_new_lchan(new_lchan);
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100331 if (!ho) {
332 LOGP(DHO, LOGL_ERROR, "unable to find HO record\n");
Harald Welte798418a2009-11-29 22:56:14 +0100333 return -ENODEV;
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100334 }
Harald Welte798418a2009-11-29 22:56:14 +0100335
Neels Hofmeyrbe1131d2018-01-19 01:23:35 +0100336 LOGP(DHO, LOGL_DEBUG, "%s Handover RACH detected\n", gsm_lchan_name(new_lchan));
337
338 /* This is just for logging on the DHO category. The actual MGCP switchover happens in
339 * osmo_bsc_mgcp.c by receiving the same S_LCHAN_HANDOVER_DETECT signal.
340 * (Calling mgcp_handover() directly currently breaks linking in utils/...) */
Harald Welte798418a2009-11-29 22:56:14 +0100341
342 return 0;
343}
344
345static int ho_logic_sig_cb(unsigned int subsys, unsigned int signal,
346 void *handler_data, void *signal_data)
347{
Holger Hans Peter Freyther08eebd52010-12-27 13:28:20 +0100348 struct lchan_signal_data *lchan_data;
Harald Welte798418a2009-11-29 22:56:14 +0100349 struct gsm_lchan *lchan;
350
Holger Hans Peter Freyther08eebd52010-12-27 13:28:20 +0100351 lchan_data = signal_data;
Harald Welte798418a2009-11-29 22:56:14 +0100352 switch (subsys) {
353 case SS_LCHAN:
Holger Hans Peter Freyther08eebd52010-12-27 13:28:20 +0100354 lchan = lchan_data->lchan;
Harald Welte798418a2009-11-29 22:56:14 +0100355 switch (signal) {
356 case S_LCHAN_ACTIVATE_ACK:
357 return ho_chan_activ_ack(lchan);
358 case S_LCHAN_ACTIVATE_NACK:
359 return ho_chan_activ_nack(lchan);
360 case S_LCHAN_HANDOVER_DETECT:
361 return ho_rsl_detect(lchan);
362 case S_LCHAN_HANDOVER_COMPL:
363 return ho_gsm48_ho_compl(lchan);
364 case S_LCHAN_HANDOVER_FAIL:
365 return ho_gsm48_ho_fail(lchan);
366 }
367 break;
368 default:
369 break;
370 }
371
372 return 0;
373}
374
Neels Hofmeyra2733ae2017-11-28 00:29:25 +0100375/* Return the old lchan or NULL. This is meant for audio handling */
Holger Hans Peter Freytherc121bb32012-12-26 10:17:42 +0100376struct gsm_lchan *bsc_handover_pending(struct gsm_lchan *new_lchan)
377{
378 struct bsc_handover *ho;
379 ho = bsc_ho_by_new_lchan(new_lchan);
380 if (!ho)
381 return NULL;
382 return ho->old_lchan;
383}
384
Harald Welte798418a2009-11-29 22:56:14 +0100385static __attribute__((constructor)) void on_dso_load_ho_logic(void)
386{
Pablo Neira Ayusobbc5b992011-05-06 12:12:31 +0200387 osmo_signal_register_handler(SS_LCHAN, ho_logic_sig_cb, NULL);
Harald Welte798418a2009-11-29 22:56:14 +0100388}
Andreas Eversberga9180002013-05-30 11:14:31 +0200389
390/* Count number of currently ongoing handovers
391 * inter_cell: if true, count only handovers between two cells. If false, count only handovers within one
392 * cell. */
393int bsc_ho_count(struct gsm_bts *bts, bool inter_cell)
394{
395 struct bsc_handover *ho;
396 int count = 0;
397
398 llist_for_each_entry(ho, &bsc_handovers, list) {
399 if (ho->inter_cell != inter_cell)
400 continue;
401 if (ho->new_lchan->ts->trx->bts == bts)
402 count++;
403 }
404
405 return count;
406}