Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 1 | /* GPRS Subscriber Update Protocol client */ |
| 2 | |
| 3 | /* (C) 2014 by Sysmocom s.f.m.c. GmbH |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * Author: Jacob Erlbeck |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Oliver Smith | a377c41 | 2019-12-03 14:51:38 +0100 | [diff] [blame] | 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Oliver Smith | a377c41 | 2019-12-03 14:51:38 +0100 | [diff] [blame] | 16 | * GNU General Public License for more details. |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 17 | * |
Oliver Smith | a377c41 | 2019-12-03 14:51:38 +0100 | [diff] [blame] | 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 20 | */ |
| 21 | #pragma once |
| 22 | |
| 23 | #include <osmocom/core/timer.h> |
| 24 | #include <osmocom/gsm/oap_client.h> |
Stefan Sperling | 55f5efa | 2018-12-04 11:40:30 +0100 | [diff] [blame] | 25 | #include <osmocom/gsm/ipa.h> |
Vadim Yanitskiy | df8d454 | 2018-11-29 01:49:57 +0700 | [diff] [blame] | 26 | #include <osmocom/gsm/gsup.h> |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 27 | |
| 28 | /* a loss of GSUP between MSC and HLR is considered quite serious, let's try to recover as quickly as |
| 29 | * possible. Even one new connection attempt per second should be quite acceptable until the link is |
| 30 | * re-established */ |
Harald Welte | 953d27c | 2018-07-23 11:11:22 +0200 | [diff] [blame] | 31 | #define OSMO_GSUP_CLIENT_RECONNECT_INTERVAL 1 |
| 32 | #define OSMO_GSUP_CLIENT_PING_INTERVAL 20 |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 33 | |
| 34 | struct msgb; |
| 35 | struct ipa_client_conn; |
Harald Welte | 953d27c | 2018-07-23 11:11:22 +0200 | [diff] [blame] | 36 | struct osmo_gsup_client; |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 37 | |
| 38 | /* Expects message in msg->l2h */ |
Harald Welte | 953d27c | 2018-07-23 11:11:22 +0200 | [diff] [blame] | 39 | typedef int (*osmo_gsup_client_read_cb_t)(struct osmo_gsup_client *gsupc, struct msgb *msg); |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 40 | |
Neels Hofmeyr | 82112ea | 2019-11-25 03:59:44 +0100 | [diff] [blame^] | 41 | typedef bool (*osmo_gsup_client_up_down_cb_t)(struct osmo_gsup_client *gsupc, bool up); |
| 42 | |
Harald Welte | 953d27c | 2018-07-23 11:11:22 +0200 | [diff] [blame] | 43 | struct osmo_gsup_client { |
Stefan Sperling | 55f5efa | 2018-12-04 11:40:30 +0100 | [diff] [blame] | 44 | const char *unit_name; /* same as ipa_dev->unit_name, for backwards compat */ |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 45 | |
| 46 | struct ipa_client_conn *link; |
Harald Welte | 953d27c | 2018-07-23 11:11:22 +0200 | [diff] [blame] | 47 | osmo_gsup_client_read_cb_t read_cb; |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 48 | void *data; |
| 49 | |
| 50 | struct osmo_oap_client_state oap_state; |
| 51 | |
| 52 | struct osmo_timer_list ping_timer; |
| 53 | struct osmo_timer_list connect_timer; |
| 54 | int is_connected; |
| 55 | int got_ipa_pong; |
Stefan Sperling | 55f5efa | 2018-12-04 11:40:30 +0100 | [diff] [blame] | 56 | |
| 57 | struct ipaccess_unit *ipa_dev; /* identification information sent to IPA server */ |
Neels Hofmeyr | 82112ea | 2019-11-25 03:59:44 +0100 | [diff] [blame^] | 58 | |
| 59 | osmo_gsup_client_up_down_cb_t up_down_cb; |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 60 | }; |
| 61 | |
Neels Hofmeyr | 82112ea | 2019-11-25 03:59:44 +0100 | [diff] [blame^] | 62 | struct osmo_gsup_client_config { |
| 63 | /*! IP access unit which contains client identification information; must be allocated in talloc_ctx as well to |
| 64 | * ensure it lives throughout the lifetime of the connection. */ |
| 65 | struct ipaccess_unit *ipa_dev; |
| 66 | /*! GSUP server IP address to connect to. */ |
| 67 | const char *ip_addr; |
| 68 | /*! GSUP server TCP port to connect to. */ |
| 69 | unsigned int tcp_port; |
| 70 | /*! OPA client configuration, or NULL. */ |
| 71 | struct osmo_oap_client_config *oapc_config; |
| 72 | /*! callback for reading from the GSUP connection. */ |
| 73 | osmo_gsup_client_read_cb_t read_cb; |
| 74 | /*! Invoked when the GSUP link is ready for communication, and when the link drops. */ |
| 75 | osmo_gsup_client_up_down_cb_t up_down_cb; |
| 76 | /*! User data stored in the returned gsupc->data, as context for the callbacks. */ |
| 77 | void *data; |
| 78 | /*! Marker for future extension, always pass this as false. */ |
| 79 | bool more; |
| 80 | }; |
| 81 | struct osmo_gsup_client *osmo_gsup_client_create3(void *talloc_ctx, struct osmo_gsup_client_config *config); |
| 82 | |
Stefan Sperling | 55f5efa | 2018-12-04 11:40:30 +0100 | [diff] [blame] | 83 | struct osmo_gsup_client *osmo_gsup_client_create2(void *talloc_ctx, |
| 84 | struct ipaccess_unit *ipa_dev, |
| 85 | const char *ip_addr, |
| 86 | unsigned int tcp_port, |
| 87 | osmo_gsup_client_read_cb_t read_cb, |
| 88 | struct osmo_oap_client_config *oapc_config); |
Harald Welte | 953d27c | 2018-07-23 11:11:22 +0200 | [diff] [blame] | 89 | struct osmo_gsup_client *osmo_gsup_client_create(void *talloc_ctx, |
| 90 | const char *unit_name, |
| 91 | const char *ip_addr, |
| 92 | unsigned int tcp_port, |
| 93 | osmo_gsup_client_read_cb_t read_cb, |
| 94 | struct osmo_oap_client_config *oapc_config); |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 95 | |
Harald Welte | 953d27c | 2018-07-23 11:11:22 +0200 | [diff] [blame] | 96 | void osmo_gsup_client_destroy(struct osmo_gsup_client *gsupc); |
| 97 | int osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg); |
Vadim Yanitskiy | df8d454 | 2018-11-29 01:49:57 +0700 | [diff] [blame] | 98 | int osmo_gsup_client_enc_send(struct osmo_gsup_client *gsupc, |
| 99 | const struct osmo_gsup_message *gsup_msg); |
Harald Welte | 953d27c | 2018-07-23 11:11:22 +0200 | [diff] [blame] | 100 | struct msgb *osmo_gsup_client_msgb_alloc(void); |
Harald Welte | ec6915a | 2018-07-23 14:25:33 +0200 | [diff] [blame] | 101 | |