blob: b382ea8603387eb8db53f09b758545dc1662591f [file] [log] [blame]
Alexander Couzens841817e2020-11-19 00:41:29 +01001/*! \file frame_relay.h */
2
3/* (C) 2020 Harald Welte <laforge@gnumonks.org>
4 * (C) 2020 sysmocom - s.f.m.c. GmbH
5 * Author: Alexander Couzens <lynxis@fe80.eu>
6 *
7 * All Rights Reserved
8 *
9 * SPDX-License-Identifier: GPL-2.0+
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 */
25
26#pragma once
27
28#include <osmocom/core/linuxlist.h>
29#include <osmocom/core/timer.h>
30#include <osmocom/core/utils.h>
31
32#include <stdint.h>
33
34struct osmo_tdef;
35struct msgb;
36
37enum osmo_fr_role {
38 FR_ROLE_USER_EQUIPMENT,
39 FR_ROLE_NETWORK_EQUIPMENT,
40};
41
42extern const struct value_string osmo_fr_role_names[];
43
44static inline const char *osmo_fr_role_str(enum osmo_fr_role role) {
45 return get_value_string(osmo_fr_role_names, role);
46}
47
48struct osmo_fr_network {
49 struct llist_head links;
50
51 unsigned int n391; /* full status polling counter */
52 unsigned int n392; /* error threshold */
53 unsigned int n393; /* monitored events count */
54
55 struct osmo_tdef *T_defs; /* T391, T392 */
56};
57
58struct osmo_fr_dlc;
59
60/* Frame Relay Link */
61struct osmo_fr_link {
62 /* list in osmo_fr_network.links */
63 struct llist_head list;
64 struct osmo_fr_network *net;
65 enum osmo_fr_role role;
66 /* human-readable name */
67 const char *name;
68
69 /* value of the last received send sequence number field in the
70 * link integrity verification information element */
71 uint8_t last_rx_seq;
72
73 /* value of the send sequence number field of the last link
74 * integrity verification information element sent */
75 uint8_t last_tx_seq;
76
77 struct osmo_timer_list t391;
78 struct osmo_timer_list t392;
79
80 unsigned int polling_count;
81 unsigned int err_count;
82 unsigned int succeed;
83 /* the type of the last status enquiry */
84 uint8_t expected_rep;
85 bool state;
86
87 /* list of data link connections at this link */
88 struct llist_head dlc_list;
89
90 int (*unknown_dlc_rx_cb)(void *cb_data, struct msgb *msg);
91 void *unknown_dlc_rx_cb_data;
92
93 int (*tx_cb)(void *data, struct msgb *msg);
94 void *tx_cb_data;
95};
96
97/* Frame Relay Data Link Connection */
98struct osmo_fr_dlc {
99 /* entry in fr_link.dlc_list */
100 struct llist_head list;
101 struct osmo_fr_link *link;
102
103 uint16_t dlci;
104
105 /* is this DLC marked active for traffic? */
106 bool active;
107 /* was this DLC newly added? */
108 bool add;
109 /* is this DLC about to be destroyed */
110 bool del;
111
112 /* the local state needs to be transfered to the
113 * UE. The NET must wait until the UE confirms it implicited by a seq number check */
114 bool state_send;
115
116 int (*rx_cb)(void *cb_data, struct msgb *msg);
117 void *rx_cb_data;
118};
119
120/* allocate a frame relay network */
121struct osmo_fr_network *osmo_fr_network_alloc(void *ctx);
122
123/* allocate a frame relay link in a given network */
124struct osmo_fr_link *osmo_fr_link_alloc(struct osmo_fr_network *net, enum osmo_fr_role role, const char *name);
125
126/* free a frame link in a given network */
127void osmo_fr_link_free(struct osmo_fr_link *link);
128
129/* allocate a data link connectoin on a given framerelay link */
130struct osmo_fr_dlc *osmo_fr_dlc_alloc(struct osmo_fr_link *link, uint16_t dlci);
131void osmo_fr_dlc_free(struct osmo_fr_dlc *dlc);
132
133struct osmo_fr_dlc *osmo_fr_dlc_by_dlci(struct osmo_fr_link *link, uint16_t dlci);
134
135int osmo_fr_rx(struct msgb *msg);
136int osmo_fr_tx_dlc(struct msgb *msg);