Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 1 | /*! \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 | |
| 34 | struct osmo_tdef; |
| 35 | struct msgb; |
| 36 | |
| 37 | enum osmo_fr_role { |
| 38 | FR_ROLE_USER_EQUIPMENT, |
| 39 | FR_ROLE_NETWORK_EQUIPMENT, |
| 40 | }; |
| 41 | |
Alexander Couzens | 4f1128f | 2021-01-20 17:42:48 +0100 | [diff] [blame] | 42 | /* 48.016 ยง 6.1.4.2 default maximum information field size of 1600 octets */ |
| 43 | #define FRAME_RELAY_MTU 1600 |
| 44 | /* FR DLC header is 2 byte */ |
| 45 | #define FRAME_RELAY_SDU (FRAME_RELAY_MTU - 2) |
| 46 | |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 47 | extern const struct value_string osmo_fr_role_names[]; |
| 48 | |
| 49 | static inline const char *osmo_fr_role_str(enum osmo_fr_role role) { |
| 50 | return get_value_string(osmo_fr_role_names, role); |
| 51 | } |
| 52 | |
| 53 | struct osmo_fr_network { |
| 54 | struct llist_head links; |
| 55 | |
| 56 | unsigned int n391; /* full status polling counter */ |
| 57 | unsigned int n392; /* error threshold */ |
| 58 | unsigned int n393; /* monitored events count */ |
| 59 | |
| 60 | struct osmo_tdef *T_defs; /* T391, T392 */ |
| 61 | }; |
| 62 | |
| 63 | struct osmo_fr_dlc; |
| 64 | |
| 65 | /* Frame Relay Link */ |
| 66 | struct osmo_fr_link { |
| 67 | /* list in osmo_fr_network.links */ |
| 68 | struct llist_head list; |
| 69 | struct osmo_fr_network *net; |
| 70 | enum osmo_fr_role role; |
| 71 | /* human-readable name */ |
| 72 | const char *name; |
| 73 | |
| 74 | /* value of the last received send sequence number field in the |
| 75 | * link integrity verification information element */ |
| 76 | uint8_t last_rx_seq; |
| 77 | |
| 78 | /* value of the send sequence number field of the last link |
| 79 | * integrity verification information element sent */ |
| 80 | uint8_t last_tx_seq; |
| 81 | |
| 82 | struct osmo_timer_list t391; |
| 83 | struct osmo_timer_list t392; |
| 84 | |
| 85 | unsigned int polling_count; |
| 86 | unsigned int err_count; |
| 87 | unsigned int succeed; |
| 88 | /* the type of the last status enquiry */ |
| 89 | uint8_t expected_rep; |
| 90 | bool state; |
| 91 | |
| 92 | /* list of data link connections at this link */ |
| 93 | struct llist_head dlc_list; |
| 94 | |
Harald Welte | 2cc1d4d | 2021-01-31 18:33:31 +0100 | [diff] [blame] | 95 | /* optional call-back to be called for each PDU received on an unknown DLC */ |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 96 | int (*unknown_dlc_rx_cb)(void *cb_data, struct msgb *msg); |
| 97 | void *unknown_dlc_rx_cb_data; |
| 98 | |
Harald Welte | 2cc1d4d | 2021-01-31 18:33:31 +0100 | [diff] [blame] | 99 | /* call-back to be called for transmitting on the underlying hardware */ |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 100 | int (*tx_cb)(void *data, struct msgb *msg); |
Harald Welte | 2cc1d4d | 2021-01-31 18:33:31 +0100 | [diff] [blame] | 101 | /* optional call-back to be called each time the status changes active/inactive */ |
| 102 | void (*status_cb)(struct osmo_fr_link *link, void *cb_data, bool active); |
| 103 | void *cb_data; |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | /* Frame Relay Data Link Connection */ |
| 107 | struct osmo_fr_dlc { |
| 108 | /* entry in fr_link.dlc_list */ |
| 109 | struct llist_head list; |
| 110 | struct osmo_fr_link *link; |
| 111 | |
| 112 | uint16_t dlci; |
| 113 | |
| 114 | /* is this DLC marked active for traffic? */ |
| 115 | bool active; |
| 116 | /* was this DLC newly added? */ |
| 117 | bool add; |
| 118 | /* is this DLC about to be destroyed */ |
| 119 | bool del; |
| 120 | |
Harald Welte | a20248a | 2020-12-01 17:50:48 +0100 | [diff] [blame] | 121 | /* The local state needs to be transferred to the USER; |
| 122 | * NET must wait until USER confirms it implicitly by a seq number check */ |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 123 | bool state_send; |
| 124 | |
Harald Welte | 2cc1d4d | 2021-01-31 18:33:31 +0100 | [diff] [blame] | 125 | /* call-back to be called for each PDU received on this DLC */ |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 126 | int (*rx_cb)(void *cb_data, struct msgb *msg); |
Harald Welte | 2cc1d4d | 2021-01-31 18:33:31 +0100 | [diff] [blame] | 127 | /* optional call-back to be called each time the status changes active/inactive */ |
| 128 | void (*status_cb)(struct osmo_fr_dlc *dlc, void *cb_data, bool active); |
| 129 | void *cb_data; |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | /* allocate a frame relay network */ |
| 133 | struct osmo_fr_network *osmo_fr_network_alloc(void *ctx); |
| 134 | |
| 135 | /* allocate a frame relay link in a given network */ |
| 136 | struct osmo_fr_link *osmo_fr_link_alloc(struct osmo_fr_network *net, enum osmo_fr_role role, const char *name); |
| 137 | |
| 138 | /* free a frame link in a given network */ |
| 139 | void osmo_fr_link_free(struct osmo_fr_link *link); |
| 140 | |
| 141 | /* allocate a data link connectoin on a given framerelay link */ |
| 142 | struct osmo_fr_dlc *osmo_fr_dlc_alloc(struct osmo_fr_link *link, uint16_t dlci); |
| 143 | void osmo_fr_dlc_free(struct osmo_fr_dlc *dlc); |
| 144 | |
| 145 | struct osmo_fr_dlc *osmo_fr_dlc_by_dlci(struct osmo_fr_link *link, uint16_t dlci); |
| 146 | |
| 147 | int osmo_fr_rx(struct msgb *msg); |
| 148 | int osmo_fr_tx_dlc(struct msgb *msg); |