Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1 | /* MSC Handover API */ |
| 2 | /* |
| 3 | * (C) 2019 by sysmocom - s.m.f.c. GmbH <info@sysmocom.de> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * SPDX-License-Identifier: AGPL-3.0+ |
| 7 | * |
| 8 | * Author: Neels Hofmeyr |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU Affero General Public License as published by |
| 12 | * the Free Software Foundation; either version 3 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Affero General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Affero General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | */ |
| 23 | |
| 24 | #pragma once |
| 25 | |
| 26 | #include <osmocom/gsm/gsm_utils.h> |
| 27 | #include <osmocom/core/sockaddr_str.h> |
| 28 | |
| 29 | #include <osmocom/mgcp_client/mgcp_client.h> |
| 30 | |
| 31 | #include <osmocom/msc/neighbor_ident.h> |
| 32 | #include <osmocom/msc/ran_msg.h> |
| 33 | #include <osmocom/msc/mncc_call.h> |
| 34 | |
| 35 | |
| 36 | struct gsm0808_handover_required; |
| 37 | |
| 38 | struct msc_a; |
| 39 | struct ran_dec_handover_required; |
| 40 | |
| 41 | #define LOG_HO(msc_a, level, fmt, args...) \ |
| 42 | LOGPFSML((msc_a)? ((msc_a)->ho.fi ? : (msc_a)->c.fi) : NULL, \ |
| 43 | level, "%s" fmt, (msc_a->ho.fi ? "" : "HO: "), ##args) |
| 44 | |
| 45 | enum msc_ho_fsm_state { |
| 46 | MSC_HO_ST_REQUIRED, |
| 47 | MSC_HO_ST_WAIT_REQUEST_ACK, |
| 48 | MSC_HO_ST_WAIT_COMPLETE, |
| 49 | }; |
| 50 | |
| 51 | enum msc_ho_fsm_event { |
| 52 | MSC_HO_EV_RX_REQUEST_ACK, |
| 53 | MSC_HO_EV_RX_DETECT, |
| 54 | MSC_HO_EV_RX_COMPLETE, |
| 55 | MSC_HO_EV_RX_FAILURE, |
| 56 | MSC_HO_EV_MNCC_FORWARDING_COMPLETE, |
| 57 | MSC_HO_EV_MNCC_FORWARDING_FAILED, |
| 58 | }; |
| 59 | |
| 60 | struct msc_ho_state { |
| 61 | struct osmo_fsm_inst *fi; |
| 62 | struct ran_handover_required info; |
| 63 | unsigned int next_cil_idx; |
| 64 | bool subsequent_ho; |
| 65 | bool ready_to_switch_rtp; |
| 66 | bool rtp_switched_to_new_cell; |
| 67 | |
| 68 | struct { |
| 69 | enum osmo_rat_type ran_type; |
| 70 | struct gsm0808_cell_id cid; |
| 71 | struct osmo_cell_global_id cgi; |
| 72 | enum msc_neighbor_type type; |
| 73 | union { |
| 74 | struct ran_peer *ran_peer; |
| 75 | const char *msc_ipa_name; |
| 76 | }; |
| 77 | |
| 78 | /* The RTP address from Handover Request Acknowledge. |
| 79 | * Might be from AoIP Transport Layer Address from a BSC RAN peer, |
| 80 | * or from MNCC forwarding for inter-MSC handover. */ |
| 81 | struct osmo_sockaddr_str ran_remote_rtp; |
| 82 | /* The codec from Handover Request Acknowledge. */ |
| 83 | bool codec_present; |
| 84 | enum mgcp_codecs codec; |
| 85 | |
| 86 | /* Inter-MSC voice forwarding via MNCC, to the remote MSC. The Prepare Handover Response sent us the |
| 87 | * Handover Number the remote MSC assigned. This is a call to that Handover Number, via PBX. |
| 88 | * (NULL if not an inter-MSC Handover) */ |
| 89 | struct mncc_call *mncc_forwarding_to_remote_ran; |
| 90 | } new_cell; |
| 91 | |
| 92 | struct { |
| 93 | /* Saved RTP IP:port and codec in case we need to roll back */ |
| 94 | struct osmo_sockaddr_str ran_remote_rtp; |
| 95 | enum mgcp_codecs codec; |
| 96 | } old_cell; |
| 97 | }; |
| 98 | |
| 99 | void msc_ho_start(struct msc_a *msc_a, const struct ran_handover_required *ho_req); |
| 100 | |
| 101 | enum msc_neighbor_type msc_ho_find_target_cell(struct msc_a *msc_a, const struct gsm0808_cell_id *cid, |
| 102 | const struct neighbor_ident_entry **remote_msc, |
| 103 | struct ran_peer **ran_peer_from_neighbor_ident, |
| 104 | struct ran_peer **ran_peer_from_seen_cells); |