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> |
| 27 | #include <osmocom/core/socket.h> |
| 28 | |
| 29 | static const unsigned int sgs_state_timer_defaults[_NUM_SGS_STATE_TIMERS] = { |
| 30 | [SGS_STATE_TS5] = SGS_TS5_DEFAULT, |
| 31 | [SGS_STATE_TS6_2] = SGS_TS6_2_DEFAULT, |
| 32 | [SGS_STATE_TS7] = SGS_TS7_DEFAULT, |
| 33 | [SGS_STATE_TS11] = SGS_TS11_DEFAULT, |
| 34 | [SGS_STATE_TS14] = SGS_TS14_DEFAULT, |
| 35 | [SGS_STATE_TS15] = SGS_TS15_DEFAULT, |
| 36 | }; |
| 37 | |
| 38 | static const unsigned int sgs_state_counter_defaults[_NUM_SGS_STATE_COUNTERS] = { |
| 39 | [SGS_STATE_NS7] = SGS_NS7_DEFAULT, |
| 40 | [SGS_STATE_NS11] = SGS_NS11_DEFAULT, |
| 41 | }; |
| 42 | |
| 43 | struct sgs_connection { |
| 44 | /* global list of SGs connections */ |
| 45 | struct llist_head entry; |
| 46 | |
| 47 | /* back-pointer */ |
| 48 | struct sgs_state *sgs; |
| 49 | |
| 50 | /* Socket name from osmo_sock_get_name() */ |
| 51 | char sockname[OSMO_SOCK_NAME_MAXLEN]; |
| 52 | |
| 53 | /* MME for this connection, if any. This field is NULL until we |
| 54 | * receive the first "MME name" IE from the MME, which could be part |
| 55 | * of the RESET procedure, but also just a normal LU request. */ |
| 56 | struct sgs_mme_ctx *mme; |
| 57 | |
| 58 | /* represents the SCTP connection we accept()ed from this MME */ |
| 59 | struct osmo_stream_srv *srv; |
| 60 | }; |
| 61 | |
| 62 | struct sgs_mme_ctx { |
| 63 | /* global list of MME contexts */ |
| 64 | struct llist_head entry; |
| 65 | |
| 66 | /* back-pointer */ |
| 67 | struct sgs_state *sgs; |
| 68 | |
| 69 | /* MME name as string representation */ |
| 70 | char fqdn[GSM23003_MME_DOMAIN_LEN + 1]; |
| 71 | |
| 72 | /* current connection for this MME, if any. Can be NULL if the SCTP |
| 73 | * connection to the MME was lost and hasn't been re-established yet */ |
| 74 | struct sgs_connection *conn; |
| 75 | |
| 76 | /* FSM for the "VLR reset" procedure" */ |
| 77 | struct osmo_fsm_inst *fi; |
| 78 | unsigned int ns11_remaining; |
| 79 | }; |
| 80 | |
| 81 | extern struct sgs_state *g_sgs; |
| 82 | |
| 83 | struct sgs_state *sgs_iface_init(void *ctx, struct gsm_network *network); |
| 84 | int sgs_iface_rx(struct sgs_connection *sgc, struct msgb *msg); |
| 85 | int sgs_iface_tx_paging(struct vlr_subscr *vsub, enum sgsap_service_ind serv_ind); |
| 86 | int sgs_iface_tx_dtap_ud(struct msgb *msg); |
| 87 | void sgs_iface_tx_release(struct ran_conn *conn); |