Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 1 | /* (C) 2018-2019 by sysmocom s.f.m.c. GmbH |
| 2 | * All Rights Reserved |
| 3 | * |
| 4 | * Author: Harald Welte, Philipp Maier |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #pragma once |
| 22 | |
| 23 | #include <osmocom/gsm/protocol/gsm_23_003.h> |
| 24 | #include <osmocom/gsm/protocol/gsm_29_118.h> |
| 25 | #include <osmocom/msc/vlr.h> |
| 26 | #include <osmocom/msc/vlr_sgs.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 27 | #include <osmocom/msc/paging.h> |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 28 | #include <osmocom/core/socket.h> |
| 29 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 30 | struct msc_a; |
| 31 | |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 32 | static const unsigned int sgs_state_timer_defaults[_NUM_SGS_STATE_TIMERS] = { |
| 33 | [SGS_STATE_TS5] = SGS_TS5_DEFAULT, |
| 34 | [SGS_STATE_TS6_2] = SGS_TS6_2_DEFAULT, |
| 35 | [SGS_STATE_TS7] = SGS_TS7_DEFAULT, |
| 36 | [SGS_STATE_TS11] = SGS_TS11_DEFAULT, |
| 37 | [SGS_STATE_TS14] = SGS_TS14_DEFAULT, |
| 38 | [SGS_STATE_TS15] = SGS_TS15_DEFAULT, |
| 39 | }; |
| 40 | |
| 41 | static const unsigned int sgs_state_counter_defaults[_NUM_SGS_STATE_COUNTERS] = { |
| 42 | [SGS_STATE_NS7] = SGS_NS7_DEFAULT, |
| 43 | [SGS_STATE_NS11] = SGS_NS11_DEFAULT, |
| 44 | }; |
| 45 | |
| 46 | struct sgs_connection { |
| 47 | /* global list of SGs connections */ |
| 48 | struct llist_head entry; |
| 49 | |
| 50 | /* back-pointer */ |
| 51 | struct sgs_state *sgs; |
| 52 | |
| 53 | /* Socket name from osmo_sock_get_name() */ |
| 54 | char sockname[OSMO_SOCK_NAME_MAXLEN]; |
| 55 | |
| 56 | /* MME for this connection, if any. This field is NULL until we |
| 57 | * receive the first "MME name" IE from the MME, which could be part |
| 58 | * of the RESET procedure, but also just a normal LU request. */ |
| 59 | struct sgs_mme_ctx *mme; |
| 60 | |
| 61 | /* represents the SCTP connection we accept()ed from this MME */ |
| 62 | struct osmo_stream_srv *srv; |
| 63 | }; |
| 64 | |
| 65 | struct sgs_mme_ctx { |
| 66 | /* global list of MME contexts */ |
| 67 | struct llist_head entry; |
| 68 | |
| 69 | /* back-pointer */ |
| 70 | struct sgs_state *sgs; |
| 71 | |
| 72 | /* MME name as string representation */ |
| 73 | char fqdn[GSM23003_MME_DOMAIN_LEN + 1]; |
| 74 | |
| 75 | /* current connection for this MME, if any. Can be NULL if the SCTP |
| 76 | * connection to the MME was lost and hasn't been re-established yet */ |
| 77 | struct sgs_connection *conn; |
| 78 | |
| 79 | /* FSM for the "VLR reset" procedure" */ |
| 80 | struct osmo_fsm_inst *fi; |
| 81 | unsigned int ns11_remaining; |
| 82 | }; |
| 83 | |
| 84 | extern struct sgs_state *g_sgs; |
| 85 | |
| 86 | struct sgs_state *sgs_iface_init(void *ctx, struct gsm_network *network); |
| 87 | int sgs_iface_rx(struct sgs_connection *sgc, struct msgb *msg); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 88 | enum sgsap_service_ind sgs_serv_ind_from_paging_cause(enum paging_cause); |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 89 | int sgs_iface_tx_paging(struct vlr_subscr *vsub, enum sgsap_service_ind serv_ind); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 90 | int sgs_iface_tx_dtap_ud(struct msc_a *msc_a, struct msgb *msg); |
| 91 | void sgs_iface_tx_release(struct vlr_subscr *vsub); |
| 92 | |