blob: 52e5dd3851d8ec2c5905895d13d308347d9cab16 [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>
Neels Hofmeyr6dff51d2018-02-12 16:56:41 +010041#include <osmocom/bsc/handover.h>
Harald Welte798418a2009-11-29 22:56:14 +010042
43struct bsc_handover {
44 struct llist_head list;
45
46 struct gsm_lchan *old_lchan;
47 struct gsm_lchan *new_lchan;
48
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020049 struct osmo_timer_list T3103;
Harald Welte798418a2009-11-29 22:56:14 +010050
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020051 uint8_t ho_ref;
Neels Hofmeyr5eaa4fb2017-11-27 17:57:15 +010052
53 bool inter_cell;
54 bool async;
Harald Welte798418a2009-11-29 22:56:14 +010055};
56
57static LLIST_HEAD(bsc_handovers);
58
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +010059static void handover_free(struct bsc_handover *ho)
60{
61 osmo_timer_del(&ho->T3103);
62 llist_del(&ho->list);
63 talloc_free(ho);
64}
65
Harald Welte798418a2009-11-29 22:56:14 +010066static struct bsc_handover *bsc_ho_by_new_lchan(struct gsm_lchan *new_lchan)
67{
68 struct bsc_handover *ho;
69
70 llist_for_each_entry(ho, &bsc_handovers, list) {
71 if (ho->new_lchan == new_lchan)
72 return ho;
73 }
74
75 return NULL;
76}
77
78static struct bsc_handover *bsc_ho_by_old_lchan(struct gsm_lchan *old_lchan)
79{
80 struct bsc_handover *ho;
81
82 llist_for_each_entry(ho, &bsc_handovers, list) {
83 if (ho->old_lchan == old_lchan)
84 return ho;
85 }
86
87 return NULL;
88}
89
Neels Hofmeyr6dff51d2018-02-12 16:56:41 +010090/*! Hand over the specified logical channel to the specified new BTS and possibly change the lchan type.
91 * This is the main entry point for the actual handover algorithm, after the decision whether to initiate
92 * HO to a specific BTS. To not change the lchan type, pass old_lchan->type. */
93int bsc_handover_start(struct gsm_lchan *old_lchan, struct gsm_bts *new_bts,
94 enum gsm_chan_t new_lchan_type)
Harald Welte798418a2009-11-29 22:56:14 +010095{
Neels Hofmeyr4e3db632018-02-12 17:25:04 +010096 struct gsm_network *network;
Harald Welte798418a2009-11-29 22:56:14 +010097 struct gsm_lchan *new_lchan;
98 struct bsc_handover *ho;
Neels Hofmeyrc766c9e2017-11-27 17:58:04 +010099 static uint8_t ho_ref = 0;
Harald Welte798418a2009-11-29 22:56:14 +0100100 int rc;
Neels Hofmeyr4e3db632018-02-12 17:25:04 +0100101 bool do_assignment = false;
Harald Welte798418a2009-11-29 22:56:14 +0100102
Harald Welte66706812009-12-17 22:23:21 +0100103 /* don't attempt multiple handovers for the same lchan at
104 * the same time */
105 if (bsc_ho_by_old_lchan(old_lchan))
106 return -EBUSY;
107
Philipp Maier39f62bb2017-04-09 12:32:51 +0200108 DEBUGP(DHO, "Beginning with handover operation"
109 "(old_lchan on BTS %u, new BTS %u) ...\n",
Neels Hofmeyr6dff51d2018-02-12 16:56:41 +0100110 old_lchan->ts->trx->bts->nr, new_bts->nr);
Neels Hofmeyr4e3db632018-02-12 17:25:04 +0100111 /* No new BTS? Then it shall be assignment within the same BTS. */
112 if (!new_bts)
113 new_bts = old_lchan->ts->trx->bts;
114 do_assignment = (new_bts == old_lchan->ts->trx->bts);
Harald Welte8d77b952009-12-17 00:31:10 +0100115
Neels Hofmeyr4e3db632018-02-12 17:25:04 +0100116 network = new_bts->network;
117
118 rate_ctr_inc(&network->bsc_ctrs->ctr[BSC_CTR_HANDOVER_ATTEMPTED]);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100119
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800120 if (!old_lchan->conn) {
121 LOGP(DHO, LOGL_ERROR, "Old lchan lacks connection data.\n");
122 return -ENOSPC;
123 }
124
Neels Hofmeyr6dff51d2018-02-12 16:56:41 +0100125 new_lchan = lchan_alloc(new_bts, new_lchan_type, 0);
Harald Welte8d77b952009-12-17 00:31:10 +0100126 if (!new_lchan) {
Neels Hofmeyr6dff51d2018-02-12 16:56:41 +0100127 LOGP(DHO, LOGL_NOTICE, "No free channel for %s\n", gsm_lchant_name(new_lchan_type));
Neels Hofmeyr4e3db632018-02-12 17:25:04 +0100128 rate_ctr_inc(&network->bsc_ctrs->ctr[BSC_CTR_HANDOVER_NO_CHANNEL]);
Harald Welte798418a2009-11-29 22:56:14 +0100129 return -ENOSPC;
Harald Welte8d77b952009-12-17 00:31:10 +0100130 }
Harald Welte798418a2009-11-29 22:56:14 +0100131
Holger Hans Peter Freyther90cdd282010-12-21 13:29:14 +0100132 ho = talloc_zero(tall_bsc_ctx, struct bsc_handover);
Harald Welte798418a2009-11-29 22:56:14 +0100133 if (!ho) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100134 LOGP(DHO, LOGL_FATAL, "Out of Memory\n");
Harald Welte798418a2009-11-29 22:56:14 +0100135 lchan_free(new_lchan);
136 return -ENOMEM;
137 }
138 ho->old_lchan = old_lchan;
139 ho->new_lchan = new_lchan;
Harald Welte8d77b952009-12-17 00:31:10 +0100140 ho->ho_ref = ho_ref++;
Neels Hofmeyr3fb5dcf2018-02-14 13:51:36 +0100141 ho->inter_cell = !do_assignment;
142 ho->async = true;
Harald Welte8d77b952009-12-17 00:31:10 +0100143
144 /* copy some parameters from old lchan */
145 memcpy(&new_lchan->encr, &old_lchan->encr, sizeof(new_lchan->encr));
Neels Hofmeyr05a3a2d2018-02-12 17:25:04 +0100146 if (do_assignment) {
147 new_lchan->ms_power = old_lchan->ms_power;
148 new_lchan->rqd_ta = old_lchan->rqd_ta;
149 } else {
150 new_lchan->ms_power =
151 ms_pwr_ctl_lvl(new_bts->band, new_bts->ms_max_power);
152 /* FIXME: do we have a better idea of the timing advance? */
153 //new_lchan->rqd_ta = old_lchan->rqd_ta;
154 }
Harald Welte8d77b952009-12-17 00:31:10 +0100155 new_lchan->bs_power = old_lchan->bs_power;
156 new_lchan->rsl_cmode = old_lchan->rsl_cmode;
157 new_lchan->tch_mode = old_lchan->tch_mode;
Neels Hofmeyref497b82018-02-12 17:28:07 +0100158 memcpy(&new_lchan->mr_ms_lv, &old_lchan->mr_ms_lv, sizeof(new_lchan->mr_ms_lv));
159 memcpy(&new_lchan->mr_bts_lv, &old_lchan->mr_bts_lv, sizeof(new_lchan->mr_bts_lv));
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800160
161 new_lchan->conn = old_lchan->conn;
162 new_lchan->conn->ho_lchan = new_lchan;
Harald Welte798418a2009-11-29 22:56:14 +0100163
Neels Hofmeyr5eaa4fb2017-11-27 17:57:15 +0100164 rc = rsl_chan_activate_lchan(new_lchan,
Neels Hofmeyr063868e2018-02-15 14:18:22 +0100165 ho->async ? RSL_ACT_INTER_ASYNC : RSL_ACT_INTER_SYNC,
Neels Hofmeyr5eaa4fb2017-11-27 17:57:15 +0100166 ho->ho_ref);
Harald Welte798418a2009-11-29 22:56:14 +0100167 if (rc < 0) {
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100168 LOGP(DHO, LOGL_ERROR, "could not activate channel\n");
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800169 new_lchan->conn->ho_lchan = NULL;
Holger Hans Peter Freytherc8396672010-12-26 19:59:32 +0100170 new_lchan->conn = NULL;
Harald Welte798418a2009-11-29 22:56:14 +0100171 talloc_free(ho);
172 lchan_free(new_lchan);
173 return rc;
174 }
175
Holger Hans Peter Freyther5eec9d92010-04-10 00:16:04 +0200176 rsl_lchan_set_state(new_lchan, LCHAN_S_ACT_REQ);
Harald Welte798418a2009-11-29 22:56:14 +0100177 llist_add(&ho->list, &bsc_handovers);
178 /* we continue in the SS_LCHAN handler / ho_chan_activ_ack */
179
180 return 0;
181}
182
Neels Hofmeyra2733ae2017-11-28 00:29:25 +0100183/* clear any operation for this connection */
Holger Hans Peter Freytherebd50a62010-12-27 13:46:48 +0100184void bsc_clear_handover(struct gsm_subscriber_connection *conn, int free_lchan)
Holger Hans Peter Freytherf2553a62010-06-30 12:58:14 +0800185{
186 struct bsc_handover *ho;
187
188 ho = bsc_ho_by_new_lchan(conn->ho_lchan);
189
190
191 if (!ho && conn->ho_lchan)
192 LOGP(DHO, LOGL_ERROR, "BUG: We lost some state.\n");
193
194 if (!ho) {
195 LOGP(DHO, LOGL_ERROR, "unable to find HO record\n");
196 return;
197 }
198
199 conn->ho_lchan->conn = NULL;
200 conn->ho_lchan = NULL;
Holger Hans Peter Freytherebd50a62010-12-27 13:46:48 +0100201
202 if (free_lchan)
Holger Hans Peter Freytherd66777f2012-12-06 12:20:56 +0100203 lchan_release(ho->new_lchan, 0, RSL_REL_LOCAL_END);
Holger Hans Peter Freytherf2553a62010-06-30 12:58:14 +0800204
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100205 handover_free(ho);
Holger Hans Peter Freytherf2553a62010-06-30 12:58:14 +0800206}
207
Harald Welte798418a2009-11-29 22:56:14 +0100208/* T3103 expired: Handover has failed without HO COMPLETE or HO FAIL */
209static void ho_T3103_cb(void *_ho)
210{
211 struct bsc_handover *ho = _ho;
Harald Welteffa55a42009-12-22 19:07:32 +0100212 struct gsm_network *net = ho->new_lchan->ts->trx->bts->network;
Harald Welte798418a2009-11-29 22:56:14 +0100213
Harald Welte8d77b952009-12-17 00:31:10 +0100214 DEBUGP(DHO, "HO T3103 expired\n");
Alexander Couzensb847a212016-08-02 11:34:11 +0200215 rate_ctr_inc(&net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_TIMEOUT]);
Harald Welte8d77b952009-12-17 00:31:10 +0100216
Holger Hans Peter Freytherd9c9f072010-06-30 13:04:13 +0800217 ho->new_lchan->conn->ho_lchan = NULL;
218 ho->new_lchan->conn = NULL;
Holger Hans Peter Freytherd66777f2012-12-06 12:20:56 +0100219 lchan_release(ho->new_lchan, 0, RSL_REL_LOCAL_END);
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100220 handover_free(ho);
Harald Welte798418a2009-11-29 22:56:14 +0100221}
222
223/* RSL has acknowledged activation of the new lchan */
224static int ho_chan_activ_ack(struct gsm_lchan *new_lchan)
225{
226 struct bsc_handover *ho;
Harald Welte798418a2009-11-29 22:56:14 +0100227
Harald Weltea9fa8dc2009-12-18 14:50:08 +0100228 /* we need to check if this channel activation is related to
229 * a handover at all (and if, which particular handover) */
Harald Welte798418a2009-11-29 22:56:14 +0100230 ho = bsc_ho_by_new_lchan(new_lchan);
Harald Weltea9fa8dc2009-12-18 14:50:08 +0100231 if (!ho)
Harald Welte798418a2009-11-29 22:56:14 +0100232 return -ENODEV;
Harald Weltea9fa8dc2009-12-18 14:50:08 +0100233
234 DEBUGP(DHO, "handover activate ack, send HO Command\n");
Harald Welte798418a2009-11-29 22:56:14 +0100235
236 /* we can now send the 04.08 HANDOVER COMMAND to the MS
237 * using the old lchan */
238
Neels Hofmeyrb0370532018-02-15 14:18:58 +0100239 gsm48_send_ho_cmd(ho->old_lchan, new_lchan, new_lchan->ms_power, ho->ho_ref);
Harald Welte798418a2009-11-29 22:56:14 +0100240
241 /* start T3103. We can continue either with T3103 expiration,
242 * 04.08 HANDOVER COMPLETE or 04.08 HANDOVER FAIL */
Pablo Neira Ayuso51215762017-05-08 20:57:52 +0200243 osmo_timer_setup(&ho->T3103, ho_T3103_cb, ho);
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200244 osmo_timer_schedule(&ho->T3103, 10, 0);
Harald Welte798418a2009-11-29 22:56:14 +0100245
Harald Weltea0379022009-12-20 17:04:40 +0100246 /* create a RTP connection */
247 if (is_ipaccess_bts(new_lchan->ts->trx->bts))
248 rsl_ipacc_crcx(new_lchan);
249
Harald Welte798418a2009-11-29 22:56:14 +0100250 return 0;
251}
252
253/* RSL has not acknowledged activation of the new lchan */
254static int ho_chan_activ_nack(struct gsm_lchan *new_lchan)
255{
256 struct bsc_handover *ho;
257
258 ho = bsc_ho_by_new_lchan(new_lchan);
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100259 if (!ho) {
Harald Welte25cf8242012-07-06 14:21:55 +0200260 LOGP(DHO, LOGL_INFO, "ACT NACK: unable to find HO record\n");
Harald Welte798418a2009-11-29 22:56:14 +0100261 return -ENODEV;
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100262 }
Harald Welte798418a2009-11-29 22:56:14 +0100263
Holger Hans Peter Freyther2391b4c2010-12-21 13:30:17 +0100264 new_lchan->conn->ho_lchan = NULL;
265 new_lchan->conn = NULL;
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100266 handover_free(ho);
Harald Welte798418a2009-11-29 22:56:14 +0100267
268 /* FIXME: maybe we should try to allocate a new LCHAN here? */
269
270 return 0;
271}
272
273/* GSM 04.08 HANDOVER COMPLETE has been received on new channel */
274static int ho_gsm48_ho_compl(struct gsm_lchan *new_lchan)
275{
Holger Hans Peter Freyther9d3e2ec2010-12-26 20:34:26 +0100276 struct gsm_network *net;
Harald Welte798418a2009-11-29 22:56:14 +0100277 struct bsc_handover *ho;
278
279 ho = bsc_ho_by_new_lchan(new_lchan);
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100280 if (!ho) {
281 LOGP(DHO, LOGL_ERROR, "unable to find HO record\n");
Harald Welte798418a2009-11-29 22:56:14 +0100282 return -ENODEV;
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100283 }
Harald Welte798418a2009-11-29 22:56:14 +0100284
Holger Hans Peter Freyther9d3e2ec2010-12-26 20:34:26 +0100285 net = new_lchan->ts->trx->bts->network;
Harald Welte7c639a02009-12-25 23:02:50 +0100286 LOGP(DHO, LOGL_INFO, "Subscriber %s HO from BTS %u->%u on ARFCN "
Neels Hofmeyr7b656882017-07-09 22:09:18 +0200287 "%u->%u\n", bsc_subscr_name(ho->old_lchan->conn->bsub),
Harald Welte7c639a02009-12-25 23:02:50 +0100288 ho->old_lchan->ts->trx->bts->nr, new_lchan->ts->trx->bts->nr,
289 ho->old_lchan->ts->trx->arfcn, new_lchan->ts->trx->arfcn);
290
Alexander Couzensb847a212016-08-02 11:34:11 +0200291 rate_ctr_inc(&net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_COMPLETED]);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100292
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200293 osmo_timer_del(&ho->T3103);
Harald Welte798418a2009-11-29 22:56:14 +0100294
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800295 /* Replace the ho lchan with the primary one */
296 if (ho->old_lchan != new_lchan->conn->lchan)
297 LOGP(DHO, LOGL_ERROR, "Primary lchan changed during handover.\n");
298
299 if (new_lchan != new_lchan->conn->ho_lchan)
300 LOGP(DHO, LOGL_ERROR, "Handover channel changed during this handover.\n");
301
302 new_lchan->conn->ho_lchan = NULL;
303 new_lchan->conn->lchan = new_lchan;
304 ho->old_lchan->conn = NULL;
Harald Weltefe18d5c2009-12-17 17:14:43 +0100305
Holger Hans Peter Freytherd66777f2012-12-06 12:20:56 +0100306 lchan_release(ho->old_lchan, 0, RSL_REL_LOCAL_END);
Harald Welteade773f2009-12-21 13:29:19 +0100307
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100308 handover_free(ho);
Harald Welte798418a2009-11-29 22:56:14 +0100309 return 0;
310}
311
312/* GSM 04.08 HANDOVER FAIL has been received */
313static int ho_gsm48_ho_fail(struct gsm_lchan *old_lchan)
314{
Harald Welteffa55a42009-12-22 19:07:32 +0100315 struct gsm_network *net = old_lchan->ts->trx->bts->network;
Harald Welte798418a2009-11-29 22:56:14 +0100316 struct bsc_handover *ho;
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100317 struct gsm_lchan *new_lchan;
Harald Welte798418a2009-11-29 22:56:14 +0100318
319 ho = bsc_ho_by_old_lchan(old_lchan);
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100320 if (!ho) {
321 LOGP(DHO, LOGL_ERROR, "unable to find HO record\n");
Harald Welte798418a2009-11-29 22:56:14 +0100322 return -ENODEV;
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100323 }
Harald Welte798418a2009-11-29 22:56:14 +0100324
Alexander Couzensb847a212016-08-02 11:34:11 +0200325 rate_ctr_inc(&net->bsc_ctrs->ctr[BSC_CTR_HANDOVER_FAILED]);
Harald Welte24ff6ee2009-12-22 00:41:05 +0100326
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100327 new_lchan = ho->new_lchan;
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800328
329 /* release the channel and forget about it */
330 ho->new_lchan->conn->ho_lchan = NULL;
331 ho->new_lchan->conn = NULL;
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100332 handover_free(ho);
Holger Hans Peter Freythere071ab72010-06-30 12:40:10 +0800333
Holger Hans Peter Freytherd30ed6b2014-12-17 21:21:36 +0100334 lchan_release(new_lchan, 0, RSL_REL_LOCAL_END);
335
Harald Welte798418a2009-11-29 22:56:14 +0100336
337 return 0;
338}
339
340/* GSM 08.58 HANDOVER DETECT has been received */
341static int ho_rsl_detect(struct gsm_lchan *new_lchan)
342{
343 struct bsc_handover *ho;
344
Harald Welte6f7a5a72009-12-18 11:52:03 +0100345 ho = bsc_ho_by_new_lchan(new_lchan);
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100346 if (!ho) {
347 LOGP(DHO, LOGL_ERROR, "unable to find HO record\n");
Harald Welte798418a2009-11-29 22:56:14 +0100348 return -ENODEV;
Harald Welteb1d4c8e2009-12-17 23:10:46 +0100349 }
Harald Welte798418a2009-11-29 22:56:14 +0100350
Neels Hofmeyrbe1131d2018-01-19 01:23:35 +0100351 LOGP(DHO, LOGL_DEBUG, "%s Handover RACH detected\n", gsm_lchan_name(new_lchan));
352
353 /* This is just for logging on the DHO category. The actual MGCP switchover happens in
354 * osmo_bsc_mgcp.c by receiving the same S_LCHAN_HANDOVER_DETECT signal.
355 * (Calling mgcp_handover() directly currently breaks linking in utils/...) */
Harald Welte798418a2009-11-29 22:56:14 +0100356
357 return 0;
358}
359
360static int ho_logic_sig_cb(unsigned int subsys, unsigned int signal,
361 void *handler_data, void *signal_data)
362{
Holger Hans Peter Freyther08eebd52010-12-27 13:28:20 +0100363 struct lchan_signal_data *lchan_data;
Harald Welte798418a2009-11-29 22:56:14 +0100364 struct gsm_lchan *lchan;
365
Holger Hans Peter Freyther08eebd52010-12-27 13:28:20 +0100366 lchan_data = signal_data;
Harald Welte798418a2009-11-29 22:56:14 +0100367 switch (subsys) {
368 case SS_LCHAN:
Holger Hans Peter Freyther08eebd52010-12-27 13:28:20 +0100369 lchan = lchan_data->lchan;
Harald Welte798418a2009-11-29 22:56:14 +0100370 switch (signal) {
371 case S_LCHAN_ACTIVATE_ACK:
372 return ho_chan_activ_ack(lchan);
373 case S_LCHAN_ACTIVATE_NACK:
374 return ho_chan_activ_nack(lchan);
375 case S_LCHAN_HANDOVER_DETECT:
376 return ho_rsl_detect(lchan);
377 case S_LCHAN_HANDOVER_COMPL:
378 return ho_gsm48_ho_compl(lchan);
379 case S_LCHAN_HANDOVER_FAIL:
380 return ho_gsm48_ho_fail(lchan);
381 }
382 break;
383 default:
384 break;
385 }
386
387 return 0;
388}
389
Neels Hofmeyra2733ae2017-11-28 00:29:25 +0100390/* Return the old lchan or NULL. This is meant for audio handling */
Holger Hans Peter Freytherc121bb32012-12-26 10:17:42 +0100391struct gsm_lchan *bsc_handover_pending(struct gsm_lchan *new_lchan)
392{
393 struct bsc_handover *ho;
394 ho = bsc_ho_by_new_lchan(new_lchan);
395 if (!ho)
396 return NULL;
397 return ho->old_lchan;
398}
399
Harald Welte798418a2009-11-29 22:56:14 +0100400static __attribute__((constructor)) void on_dso_load_ho_logic(void)
401{
Pablo Neira Ayusobbc5b992011-05-06 12:12:31 +0200402 osmo_signal_register_handler(SS_LCHAN, ho_logic_sig_cb, NULL);
Harald Welte798418a2009-11-29 22:56:14 +0100403}
Andreas Eversberga9180002013-05-30 11:14:31 +0200404
405/* Count number of currently ongoing handovers
406 * inter_cell: if true, count only handovers between two cells. If false, count only handovers within one
407 * cell. */
408int bsc_ho_count(struct gsm_bts *bts, bool inter_cell)
409{
410 struct bsc_handover *ho;
411 int count = 0;
412
413 llist_for_each_entry(ho, &bsc_handovers, list) {
414 if (ho->inter_cell != inter_cell)
415 continue;
416 if (ho->new_lchan->ts->trx->bts == bts)
417 count++;
418 }
419
420 return count;
421}