blob: 154e3e0c0bda54f43eee328ccfede0da0e1a406e [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
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
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
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22#pragma once
23
24#include <osmocom/core/timer.h>
25#include <osmocom/gsm/oap_client.h>
Stefan Sperling55f5efa2018-12-04 11:40:30 +010026#include <osmocom/gsm/ipa.h>
Vadim Yanitskiydf8d4542018-11-29 01:49:57 +070027#include <osmocom/gsm/gsup.h>
Harald Welteec6915a2018-07-23 14:25:33 +020028
29/* a loss of GSUP between MSC and HLR is considered quite serious, let's try to recover as quickly as
30 * possible. Even one new connection attempt per second should be quite acceptable until the link is
31 * re-established */
Harald Welte953d27c2018-07-23 11:11:22 +020032#define OSMO_GSUP_CLIENT_RECONNECT_INTERVAL 1
33#define OSMO_GSUP_CLIENT_PING_INTERVAL 20
Harald Welteec6915a2018-07-23 14:25:33 +020034
35struct msgb;
36struct ipa_client_conn;
Harald Welte953d27c2018-07-23 11:11:22 +020037struct osmo_gsup_client;
Harald Welteec6915a2018-07-23 14:25:33 +020038
39/* Expects message in msg->l2h */
Harald Welte953d27c2018-07-23 11:11:22 +020040typedef int (*osmo_gsup_client_read_cb_t)(struct osmo_gsup_client *gsupc, struct msgb *msg);
Harald Welteec6915a2018-07-23 14:25:33 +020041
Harald Welte953d27c2018-07-23 11:11:22 +020042struct osmo_gsup_client {
Stefan Sperling55f5efa2018-12-04 11:40:30 +010043 const char *unit_name; /* same as ipa_dev->unit_name, for backwards compat */
Harald Welteec6915a2018-07-23 14:25:33 +020044
45 struct ipa_client_conn *link;
Harald Welte953d27c2018-07-23 11:11:22 +020046 osmo_gsup_client_read_cb_t read_cb;
Harald Welteec6915a2018-07-23 14:25:33 +020047 void *data;
48
49 struct osmo_oap_client_state oap_state;
50
51 struct osmo_timer_list ping_timer;
52 struct osmo_timer_list connect_timer;
53 int is_connected;
54 int got_ipa_pong;
Stefan Sperling55f5efa2018-12-04 11:40:30 +010055
56 struct ipaccess_unit *ipa_dev; /* identification information sent to IPA server */
Harald Welteec6915a2018-07-23 14:25:33 +020057};
58
Stefan Sperling55f5efa2018-12-04 11:40:30 +010059struct osmo_gsup_client *osmo_gsup_client_create2(void *talloc_ctx,
60 struct ipaccess_unit *ipa_dev,
61 const char *ip_addr,
62 unsigned int tcp_port,
63 osmo_gsup_client_read_cb_t read_cb,
64 struct osmo_oap_client_config *oapc_config);
Harald Welte953d27c2018-07-23 11:11:22 +020065struct osmo_gsup_client *osmo_gsup_client_create(void *talloc_ctx,
66 const char *unit_name,
67 const char *ip_addr,
68 unsigned int tcp_port,
69 osmo_gsup_client_read_cb_t read_cb,
70 struct osmo_oap_client_config *oapc_config);
Harald Welteec6915a2018-07-23 14:25:33 +020071
Harald Welte953d27c2018-07-23 11:11:22 +020072void osmo_gsup_client_destroy(struct osmo_gsup_client *gsupc);
73int osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg);
Vadim Yanitskiydf8d4542018-11-29 01:49:57 +070074int osmo_gsup_client_enc_send(struct osmo_gsup_client *gsupc,
75 const struct osmo_gsup_message *gsup_msg);
Harald Welte953d27c2018-07-23 11:11:22 +020076struct msgb *osmo_gsup_client_msgb_alloc(void);
Harald Welteec6915a2018-07-23 14:25:33 +020077