blob: b417adeada9d74a3eb589f8b3b7f5d0b858c830a [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
Harald Welte953d27c2018-07-23 11:11:22 +020041struct osmo_gsup_client {
Stefan Sperling55f5efa2018-12-04 11:40:30 +010042 const char *unit_name; /* same as ipa_dev->unit_name, for backwards compat */
Harald Welteec6915a2018-07-23 14:25:33 +020043
44 struct ipa_client_conn *link;
Harald Welte953d27c2018-07-23 11:11:22 +020045 osmo_gsup_client_read_cb_t read_cb;
Harald Welteec6915a2018-07-23 14:25:33 +020046 void *data;
47
48 struct osmo_oap_client_state oap_state;
49
50 struct osmo_timer_list ping_timer;
51 struct osmo_timer_list connect_timer;
52 int is_connected;
53 int got_ipa_pong;
Stefan Sperling55f5efa2018-12-04 11:40:30 +010054
55 struct ipaccess_unit *ipa_dev; /* identification information sent to IPA server */
Harald Welteec6915a2018-07-23 14:25:33 +020056};
57
Stefan Sperling55f5efa2018-12-04 11:40:30 +010058struct osmo_gsup_client *osmo_gsup_client_create2(void *talloc_ctx,
59 struct ipaccess_unit *ipa_dev,
60 const char *ip_addr,
61 unsigned int tcp_port,
62 osmo_gsup_client_read_cb_t read_cb,
63 struct osmo_oap_client_config *oapc_config);
Harald Welte953d27c2018-07-23 11:11:22 +020064struct osmo_gsup_client *osmo_gsup_client_create(void *talloc_ctx,
65 const char *unit_name,
66 const char *ip_addr,
67 unsigned int tcp_port,
68 osmo_gsup_client_read_cb_t read_cb,
69 struct osmo_oap_client_config *oapc_config);
Harald Welteec6915a2018-07-23 14:25:33 +020070
Harald Welte953d27c2018-07-23 11:11:22 +020071void osmo_gsup_client_destroy(struct osmo_gsup_client *gsupc);
72int osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg);
Vadim Yanitskiydf8d4542018-11-29 01:49:57 +070073int osmo_gsup_client_enc_send(struct osmo_gsup_client *gsupc,
74 const struct osmo_gsup_message *gsup_msg);
Harald Welte953d27c2018-07-23 11:11:22 +020075struct msgb *osmo_gsup_client_msgb_alloc(void);
Harald Welteec6915a2018-07-23 14:25:33 +020076