blob: ea66ca12c6761d1234cd5c86963a96fb1dc08604 [file] [log] [blame]
Harald Welteec6915a2018-07-23 14:25:33 +02001/* 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 Smitha377c412019-12-03 14:51:38 +01009 * 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 Welteec6915a2018-07-23 14:25:33 +020011 * (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 Smitha377c412019-12-03 14:51:38 +010016 * GNU General Public License for more details.
Harald Welteec6915a2018-07-23 14:25:33 +020017 *
Oliver Smitha377c412019-12-03 14:51:38 +010018 * 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 Welteec6915a2018-07-23 14:25:33 +020020 */
21#pragma once
22
23#include <osmocom/core/timer.h>
24#include <osmocom/gsm/oap_client.h>
Stefan Sperling55f5efa2018-12-04 11:40:30 +010025#include <osmocom/gsm/ipa.h>
Vadim Yanitskiydf8d4542018-11-29 01:49:57 +070026#include <osmocom/gsm/gsup.h>
Harald Welteec6915a2018-07-23 14:25:33 +020027
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 Welte953d27c2018-07-23 11:11:22 +020031#define OSMO_GSUP_CLIENT_RECONNECT_INTERVAL 1
32#define OSMO_GSUP_CLIENT_PING_INTERVAL 20
Harald Welteec6915a2018-07-23 14:25:33 +020033
34struct msgb;
35struct ipa_client_conn;
Harald Welte953d27c2018-07-23 11:11:22 +020036struct osmo_gsup_client;
Harald Welteec6915a2018-07-23 14:25:33 +020037
38/* Expects message in msg->l2h */
Harald Welte953d27c2018-07-23 11:11:22 +020039typedef int (*osmo_gsup_client_read_cb_t)(struct osmo_gsup_client *gsupc, struct msgb *msg);
Harald Welteec6915a2018-07-23 14:25:33 +020040
Neels Hofmeyr43c36f92019-11-25 03:59:44 +010041typedef bool (*osmo_gsup_client_up_down_cb_t)(struct osmo_gsup_client *gsupc, bool up);
42
Harald Welte953d27c2018-07-23 11:11:22 +020043struct osmo_gsup_client {
Stefan Sperling55f5efa2018-12-04 11:40:30 +010044 const char *unit_name; /* same as ipa_dev->unit_name, for backwards compat */
Harald Welteec6915a2018-07-23 14:25:33 +020045
46 struct ipa_client_conn *link;
Harald Welte953d27c2018-07-23 11:11:22 +020047 osmo_gsup_client_read_cb_t read_cb;
Harald Welteec6915a2018-07-23 14:25:33 +020048 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 Sperling55f5efa2018-12-04 11:40:30 +010056
57 struct ipaccess_unit *ipa_dev; /* identification information sent to IPA server */
Neels Hofmeyr43c36f92019-11-25 03:59:44 +010058
59 osmo_gsup_client_up_down_cb_t up_down_cb;
Harald Welteec6915a2018-07-23 14:25:33 +020060};
61
Neels Hofmeyr43c36f92019-11-25 03:59:44 +010062struct 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};
81struct osmo_gsup_client *osmo_gsup_client_create3(void *talloc_ctx, struct osmo_gsup_client_config *config);
82
Stefan Sperling55f5efa2018-12-04 11:40:30 +010083struct 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 Welte953d27c2018-07-23 11:11:22 +020089struct 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 Welteec6915a2018-07-23 14:25:33 +020095
Harald Welte953d27c2018-07-23 11:11:22 +020096void osmo_gsup_client_destroy(struct osmo_gsup_client *gsupc);
97int osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg);
Vadim Yanitskiydf8d4542018-11-29 01:49:57 +070098int osmo_gsup_client_enc_send(struct osmo_gsup_client *gsupc,
99 const struct osmo_gsup_message *gsup_msg);
Harald Welte953d27c2018-07-23 11:11:22 +0200100struct msgb *osmo_gsup_client_msgb_alloc(void);
Harald Welteec6915a2018-07-23 14:25:33 +0200101