blob: eb03f6a7b328e21e5c109a25f67decbe8321de4b [file] [log] [blame]
Neels Hofmeyra2733ae2017-11-28 00:29:25 +01001#pragma once
Holger Hans Peter Freytherf2553a62010-06-30 12:58:14 +08002
Neels Hofmeyr45e46d22018-02-15 14:10:12 +01003#include <stdint.h>
4
5#include <osmocom/core/linuxlist.h>
6#include <osmocom/core/timer.h>
Harald Welte3561bd42018-01-28 03:04:16 +01007#include <osmocom/gsm/gsm_utils.h>
Neels Hofmeyr45e46d22018-02-15 14:10:12 +01008
Neels Hofmeyra2733ae2017-11-28 00:29:25 +01009struct gsm_lchan;
10struct gsm_bts;
Holger Hans Peter Freytherf2553a62010-06-30 12:58:14 +080011struct gsm_subscriber_connection;
Harald Welte3561bd42018-01-28 03:04:16 +010012struct gsm_meas_rep mr;
Holger Hans Peter Freytherf2553a62010-06-30 12:58:14 +080013
Neels Hofmeyr45e46d22018-02-15 14:10:12 +010014#define LOGPHOLCHANTOLCHAN(old_lchan, new_lchan, level, fmt, args...) \
15 LOGP(DHODEC, level, "(BTS %u trx %u arfcn %u ts %u lchan %u %s)->(BTS %u trx %u arfcn %u ts %u lchan %u %s) (subscr %s) " fmt, \
16 old_lchan->ts->trx->bts->nr, \
17 old_lchan->ts->trx->nr, \
18 old_lchan->ts->trx->arfcn, \
19 old_lchan->ts->nr, \
20 old_lchan->nr, \
21 gsm_pchan_name(old_lchan->ts->pchan), \
22 new_lchan->ts->trx->bts->nr, \
23 new_lchan->ts->trx->nr, \
24 new_lchan->ts->trx->arfcn, \
25 new_lchan->ts->nr, \
26 new_lchan->nr, \
27 gsm_pchan_name(new_lchan->ts->pchan), \
28 bsc_subscr_name(old_lchan->conn? old_lchan->conn->bsub : NULL), \
29 ## args)
30
31#define LOGPHO(struct_bsc_handover, level, fmt, args ...) \
32 LOGPHOLCHANTOLCHAN(struct_bsc_handover->old_lchan, struct_bsc_handover->new_lchan, level, fmt, ## args)
33
34enum hodec_id {
35 HODEC_NONE,
36 HODEC1 = 1,
37 HODEC2 = 2,
38};
39
40struct bsc_handover {
41 struct llist_head list;
42
Harald Welte3561bd42018-01-28 03:04:16 +010043 /* Initial details of what is requested */
Neels Hofmeyr45e46d22018-02-15 14:10:12 +010044 struct gsm_lchan *old_lchan;
Harald Welte3561bd42018-01-28 03:04:16 +010045 struct gsm_bts *new_bts;
46 enum gsm_chan_t new_lchan_type;
Neels Hofmeyr45e46d22018-02-15 14:10:12 +010047 bool async;
Harald Welte3561bd42018-01-28 03:04:16 +010048
49 /* Derived and resulting state */
50 bool inter_cell;
51 uint8_t ho_ref;
52 enum hodec_id from_hodec_id;
53 struct gsm_lchan *new_lchan;
54 struct osmo_timer_list T3103;
Neels Hofmeyr45e46d22018-02-15 14:10:12 +010055};
56
57int bsc_handover_start(enum hodec_id from_hodec_id, struct gsm_lchan *old_lchan, struct gsm_bts *new_bts,
Neels Hofmeyr6dff51d2018-02-12 16:56:41 +010058 enum gsm_chan_t new_lchan_type);
Harald Welte3561bd42018-01-28 03:04:16 +010059int bsc_handover_start_gscon(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freytherebd50a62010-12-27 13:46:48 +010060void bsc_clear_handover(struct gsm_subscriber_connection *conn, int free_lchan);
Holger Hans Peter Freytherc121bb32012-12-26 10:17:42 +010061struct gsm_lchan *bsc_handover_pending(struct gsm_lchan *new_lchan);
Andreas Eversberga9180002013-05-30 11:14:31 +020062
63int bsc_ho_count(struct gsm_bts *bts, bool inter_cell);
Neels Hofmeyr45e46d22018-02-15 14:10:12 +010064
65/* Handover decision algorithms' actions to take on incoming handover-relevant events.
66 *
67 * All events that are interesting for handover decision are actually communicated by S_LCHAN_* signals,
68 * so theoretically, each handover algorithm could evaluate those. However, handover_logic.c cleans up
69 * handover operation state upon receiving some of these signals. To allow a handover decision algorithm
70 * to take advantage of e.g. the struct bsc_handover before it is discarded, the handover decision event
71 * handler needs to be invoked before handover_logic.c discards the state. For example, if the handover
72 * decision wants to place a penalty timer upon a handover failure, it still needs to know which target
73 * cell the handover failed for; handover_logic.c erases that knowledge on handover failure, since it
74 * needs to clean up the lchan's handover state.
75 *
76 * The most explicit and safest way to ensure the correct order of event handling is to invoke the
77 * handover decision algorithm's actions from handover_logic.c itself, before cleaning up. This struct
78 * provides the callback functions for this purpose.
79 *
80 * For consistency, also handle signals in this way that aren't actually in danger of interference from
81 * handover_logic.c (which also saves repeated lookup of handover state for lchans). Thus, handover
82 * decision algorithms should not register any signal handler at all.
83 */
84struct handover_decision_callbacks {
85 struct llist_head entry;
86
87 int hodec_id;
88
89 void (*on_measurement_report)(struct gsm_meas_rep *mr);
90 void (*on_ho_chan_activ_nack)(struct bsc_handover *ho);
91 void (*on_ho_failure)(struct bsc_handover *ho);
92};
93
94void handover_decision_callbacks_register(struct handover_decision_callbacks *hdc);
95struct handover_decision_callbacks *handover_decision_callbacks_get(int hodec_id);