aboutsummaryrefslogtreecommitdiffstats
path: root/src/e1d.h
blob: b4bb754628a9deecc45a0c2bc3dd0e494da80bc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 * e1d.h
 *
 * (C) 2019 by Sylvain Munaut <tnt@246tNt.com>
 *
 * All Rights Reserved
 *
 * SPDX-License-Identifier: GPL-2.0+
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <stdint.h>

#include <osmocom/core/isdnhdlc.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/vty/command.h>

enum e1d_vty_node {
	E1D_NODE = _LAST_OSMOVTY_NODE + 1,
	LINE_NODE
};

enum e1d_line_ctr {
	LINE_CTR_LOS,
	LINE_CTR_LOA,
	LINE_CTR_CRC_ERR,
	LINE_CTR_RX_OVFL,
	LINE_CTR_TX_UNFL,
};

enum e1_ts_mode {
	E1_TS_MODE_OFF = 0,
	E1_TS_MODE_RAW,
	E1_TS_MODE_HDLCFCS,
};
extern const struct value_string e1_ts_mode_names[];

struct e1_ts {
	struct e1_line *line;
	uint8_t id;

	/* Mode */
	enum e1_ts_mode mode;

	/* HDLC handling */
	struct {
		struct osmo_isdnhdlc_vars tx;
		struct osmo_isdnhdlc_vars rx;

		uint8_t rx_buf[264];
		uint8_t tx_buf[264];
		int tx_ofs;
		int tx_len;
	} hdlc;

	/* RAW handling */
	struct {
		uint8_t *rx_buf;		/* actual buffer storage */
		unsigned int rx_buf_size;	/* size of 'buf' in bytes */
		unsigned int rx_buf_used;	/* number of bytes used so far */
	} raw;

	/* Remote end */
	int fd;
};

enum e1_line_mode {
	/* 31 individual 64k timeslots, as used on 3GPP Abis, 3GPP A or ISDN */
	E1_LINE_MODE_CHANNELIZED,
	/* 1 channel group spanning all 31 TS, as used e.g. when using Frame Relay
	 * or raw HDLC over channelized E1. */
	E1_LINE_MODE_SUPERCHANNEL,
};

struct e1_line {
	struct llist_head list;

	struct e1_intf *intf;
	uint8_t id;

	enum e1_line_mode mode;

	void *drv_data;
	struct rate_ctr_group *ctrs;

	/* timeslots for channelized mode */
	struct e1_ts ts[32];
	/* superchannel */
	struct e1_ts superchan;
};

enum e1_driver {
	E1_DRIVER_USB,
	E1_DRIVER_VPAIR,
};

extern const struct value_string e1_driver_names[];
extern const struct value_string e1_line_mode_names[];

struct e1_intf {
	struct llist_head list;

	struct e1_daemon *e1d;
	uint8_t id;

	enum e1_driver drv;
	void *drv_data;

	struct llist_head lines;
};

struct e1_daemon {
	void *ctx;
	struct llist_head interfaces;
};


struct e1_line *
e1_intf_find_line(struct e1_intf *intf, uint8_t id);

struct e1_line *
e1_intf_find_line(struct e1_intf *intf, uint8_t id);

struct e1_intf *
e1_intf_new(struct e1_daemon *e1d, void *drv_data);

struct e1_intf *
e1d_find_intf(struct e1_daemon *e1d, uint8_t id);

void
e1_intf_destroy(struct e1_intf *intf);


struct e1_line *
e1_intf_find_line(struct e1_intf *intf, uint8_t id);

struct e1_line *
e1_line_new(struct e1_intf *intf, void *drv_data);

void
e1_line_destroy(struct e1_line *line);

int
e1_line_mux_out(struct e1_line *line, uint8_t *buf, int fts);

int
e1_line_demux_in(struct e1_line *line, const uint8_t *buf, int size);

void
e1_ts_stop(struct e1_ts *ts);

void
e1d_vty_init(struct e1_daemon *e1d);

int
e1d_vpair_create(struct e1_daemon *e1d, unsigned int num_lines);

struct e1_intf *
e1d_vpair_intf_peer(struct e1_intf *intf);