blob: a38bab84a447895fc4425c3c32061f803d7b26ac [file] [log] [blame]
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001#ifndef _E1_INPUT_H
2#define _E1_INPUT_H
3
4#include <stdlib.h>
5#include <netinet/in.h>
6
7#include <osmocom/core/linuxlist.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02008#include <osmocom/core/timer.h>
9#include <osmocom/core/msgb.h>
10#include <osmocom/core/select.h>
Pablo Neira Ayuso177094b2011-06-07 12:21:51 +020011#include <osmocom/abis/subchan_demux.h>
Andreas Eversberga7ff0012011-09-26 11:29:30 +020012#include <osmocom/abis/lapd.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020013
14#define NUM_E1_TS 32
Jacob Erlbeck86dae842014-01-16 18:10:37 +010015#define E1INP_USE_DEFAULT (-1)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020016
Harald Welteb5af0992020-01-12 12:59:52 +010017#define LOGPITS(e1ts, ss, level, fmt, args ...) \
18 LOGP(ss, level, "E1TS(%u:%u) " fmt, (e1ts)->line->num, (e1ts)->num, ## args)
19
20#define LOGPIL(e1l, ss, level, fmt, args ...) \
21 LOGP(ss, level, "E1L(%u) " fmt, (e1l)->num, ## args)
22
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020023enum e1inp_sign_type {
24 E1INP_SIGN_NONE,
25 E1INP_SIGN_OML,
26 E1INP_SIGN_RSL,
Harald Welte46fc7e22014-08-18 19:04:26 +020027 E1INP_SIGN_OSMO, /* IPA CCM OSMO sub-type */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020028};
29const char *e1inp_signtype_name(enum e1inp_sign_type tp);
Arran Cudbard-Bell67b81eb2016-11-02 11:48:24 -040030extern const struct value_string e1inp_sign_type_names[5];
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020031
Harald Weltef2737fc2011-08-16 14:30:10 +020032enum e1inp_ctr {
33 E1I_CTR_HDLC_ABORT,
34 E1I_CTR_HDLC_BADFCS,
35 E1I_CTR_HDLC_OVERR,
36 E1I_CTR_ALARM,
37 E1I_CTR_REMOVED,
38};
39
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020040struct e1inp_ts;
Harald Weltefe05cf52011-09-26 23:18:41 +020041struct vty;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020042
43struct e1inp_sign_link {
44 /* list of signalling links */
45 struct llist_head list;
46
47 /* to which timeslot do we belong? */
48 struct e1inp_ts *ts;
49
50 enum e1inp_sign_type type;
51
52 /* trx for msg->trx of received msgs */
53 struct gsm_bts_trx *trx;
54
55 /* msgb queue of to-be-transmitted msgs */
56 struct llist_head tx_list;
57
58 /* SAPI and TEI on the E1 TS */
59 uint8_t sapi;
60 uint8_t tei;
61
62 union {
63 struct {
64 uint8_t channel;
65 } misdn;
66 } driver;
67};
68
69enum e1inp_ts_type {
70 E1INP_TS_TYPE_NONE,
71 E1INP_TS_TYPE_SIGN,
72 E1INP_TS_TYPE_TRAU,
Harald Weltea0108e72016-07-27 21:44:50 +020073 E1INP_TS_TYPE_RAW,
Harald Welte7a228eb2016-07-28 11:09:31 +020074 E1INP_TS_TYPE_HDLC,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020075};
76const char *e1inp_tstype_name(enum e1inp_ts_type tp);
Arran Cudbard-Bell67b81eb2016-11-02 11:48:24 -040077extern const struct value_string e1inp_ts_type_names[6];
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020078
79/* A timeslot in the E1 interface */
80struct e1inp_ts {
81 enum e1inp_ts_type type;
82 int num;
83
84 /* to which line do we belong ? */
85 struct e1inp_line *line;
86
Harald Weltefd44a5f2011-08-21 00:48:54 +020087 /* LAPD instance, if any */
88 struct lapd_instance *lapd;
89
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020090 union {
91 struct {
92 /* list of all signalling links on this TS */
93 struct llist_head sign_links;
94 /* delay for the queue */
95 int delay;
96 /* timer when to dequeue next frame */
97 struct osmo_timer_list tx_timer;
98 } sign;
99 struct {
100 /* subchannel demuxer for frames from E1 */
101 struct subch_demux demux;
102 /* subchannel muxer for frames to E1 */
103 struct subch_mux mux;
104 } trau;
Harald Weltea0108e72016-07-27 21:44:50 +0200105 struct {
106 /* call-back for every received frame */
107 void (*recv_cb)(struct e1inp_ts *ts, struct msgb *msg);
108 /* queue of pending to-be-transmitted msgbs */
109 struct llist_head tx_queue;
110 } raw;
Harald Welte7a228eb2016-07-28 11:09:31 +0200111 struct {
112 /* call-back for every received frame */
113 void (*recv_cb)(struct e1inp_ts *ts, struct msgb *msg);
114 /* queue of pending to-be-transmitted msgbs */
115 struct llist_head tx_queue;
116 } hdlc;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200117 };
118 union {
119 struct {
120 /* mISDN driver has one fd for each ts */
121 struct osmo_fd fd;
122 } misdn;
123 struct {
124 /* ip.access driver has one fd for each ts */
125 struct osmo_fd fd;
Eric Wildef1f3272019-07-10 18:10:31 +0200126 /* ipa keep-alive */
127 struct osmo_fsm_inst* ka_fsm;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200128 } ipaccess;
129 struct {
130 /* DAHDI driver has one fd for each ts */
131 struct osmo_fd fd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200132 } dahdi;
Pablo Neira Ayuso7e0d0062011-08-19 11:36:15 +0200133 struct {
Sylvain Munautb559a532019-05-09 11:14:26 +0200134 /* osmo-e1d driver has one fd for each ts */
135 struct osmo_fd fd;
136 } e1d;
137 struct {
Pablo Neira Ayuso7e0d0062011-08-19 11:36:15 +0200138 struct osmo_fd fd;
139 } rs232;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200140 } driver;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +0200141
142 struct msgb *pending_msg;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200143};
144
145struct gsm_e1_subslot {
146 /* Number of E1 link */
147 uint8_t e1_nr;
148 /* Number of E1 TS inside E1 link */
149 uint8_t e1_ts;
150 /* Sub-slot within the E1 TS, 0xff if full TS */
151 uint8_t e1_ts_ss;
152};
153
154enum e1inp_line_role {
155 E1INP_LINE_R_NONE,
156 E1INP_LINE_R_BSC,
157 E1INP_LINE_R_BTS,
158 E1INP_LINE_R_MAX
159};
160
161struct e1inp_driver {
162 struct llist_head list;
163 const char *name;
164 int (*want_write)(struct e1inp_ts *ts);
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200165 int (*line_update)(struct e1inp_line *line);
Pablo Neira Ayusoadd3ec82011-07-05 14:45:46 +0200166 void (*close)(struct e1inp_sign_link *link);
Harald Weltefe05cf52011-09-26 23:18:41 +0200167 void (*vty_show)(struct vty *vty, struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200168 int default_delay;
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100169 int has_keepalive;
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100170 const char *bind_addr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200171};
172
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200173struct e1inp_line_ops {
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200174 union {
175 struct {
176 enum e1inp_line_role role; /* BSC or BTS mode. */
177 const char *addr; /* IP address .*/
178 void *dev; /* device parameters. */
179 } ipa;
180 struct {
181 const char *port; /* e.g. /dev/ttyUSB0 */
182 unsigned int delay;
183 } rs232;
184 } cfg;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200185
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200186 struct e1inp_sign_link * (*sign_link_up)(void *unit_info, struct e1inp_line *line, enum e1inp_sign_type type);
187 void (*sign_link_down)(struct e1inp_line *line);
Pau Espin Pedroled122f32018-08-28 18:25:02 +0200188 /* Called when a new message arrives. -EBADF must be returned if the osmo_fd in link (msg->dst) is destroyed. */
Pablo Neira Ayusodbd82fb2011-07-05 15:29:23 +0200189 int (*sign_link)(struct msgb *msg);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200190};
191
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200192struct e1inp_line {
193 struct llist_head list;
194 int refcnt;
195
196 unsigned int num;
197 const char *name;
Harald Weltec2889512011-09-13 23:49:04 +0100198 unsigned int port_nr;
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100199 char *sock_path;
Harald Weltef2737fc2011-08-16 14:30:10 +0200200 struct rate_ctr_group *rate_ctr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200201
Eric Wildef1f3272019-07-10 18:10:31 +0200202 /* tcp keepalive configuration */
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100203 int keepalive_num_probes; /* 0: disable, num, or E1INP_USE_DEFAULT */
204 int keepalive_idle_timeout; /* secs, or E1INP_USE_DEFAULT */
205 int keepalive_probe_interval; /* secs or E1INP_USE_DEFAULT */
206
Eric Wildef1f3272019-07-10 18:10:31 +0200207 /* ipa ping/pong keepalive params */
208 struct ipa_keepalive_params *ipa_kap;
209
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200210 /* array of timestlots */
211 struct e1inp_ts ts[NUM_E1_TS];
Harald Weltec2889512011-09-13 23:49:04 +0100212 unsigned int num_ts;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200213
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200214 const struct e1inp_line_ops *ops;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200215
216 struct e1inp_driver *driver;
217 void *driver_data;
218};
Pau Espin Pedrolb5cfc6b2018-10-02 21:22:18 +0200219#define e1inp_line_ipa_oml_ts(line) (&line->ts[0])
220#define e1inp_line_ipa_rsl_ts(line, trx_id) (&line->ts[1 + (trx_id)])
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200221
Harald Weltecc2241b2011-07-19 16:06:06 +0200222/* SS_L_INPUT signals */
Pablo Neira Ayuso332a3572011-08-16 17:31:20 +0200223enum e1inp_signal_input {
Pablo Neira Ayusode668912011-08-16 17:26:23 +0200224 S_L_INP_NONE,
225 S_L_INP_TEI_UP,
226 S_L_INP_TEI_DN,
227 S_L_INP_TEI_UNKNOWN,
228 S_L_INP_LINE_INIT,
229 S_L_INP_LINE_ALARM,
230 S_L_INP_LINE_NOALARM,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200231};
232
Harald Weltecac78fe2017-05-25 19:13:13 +0200233extern const struct value_string e1inp_signal_names[];
234
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200235/* register a driver with the E1 core */
236int e1inp_driver_register(struct e1inp_driver *drv);
237
238/* fine a previously registered driver */
239struct e1inp_driver *e1inp_driver_find(const char *name);
240
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200241/* get a line by its ID */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200242struct e1inp_line *e1inp_line_find(uint8_t e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200243
244/* create a line in the E1 input core */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200245struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
246
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200247/* clone one existing E1 input line */
248struct e1inp_line *e1inp_line_clone(void *ctx, struct e1inp_line *line);
249
250/* increment refcount use of E1 input line */
251void e1inp_line_get(struct e1inp_line *line);
252
253/* decrement refcount use of E1 input line, release if unused */
254void e1inp_line_put(struct e1inp_line *line);
255
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200256/* bind operations to one E1 input line */
257void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200258
259/* find a sign_link for given TEI and SAPI in a TS */
260struct e1inp_sign_link *
261e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
262 uint8_t sapi);
263
264/* create a new signalling link in a E1 timeslot */
265struct e1inp_sign_link *
266e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
267 struct gsm_bts_trx *trx, uint8_t tei,
268 uint8_t sapi);
269
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200270/* configure and initialize one signalling e1inp_ts */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200271int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line);
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200272
273/* configure and initialize one timeslot dedicated to TRAU frames. */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200274int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line,
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200275 int (*trau_rcv_cb)(struct subch_demux *dmx, int ch,
Harald Welte5226e5b2020-05-07 23:09:16 +0200276 const ubit_t *data, int len, void *_priv));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200277
Harald Weltea0108e72016-07-27 21:44:50 +0200278/* configure and initialize one timeslot dedicated to RAW frames */
279int e1inp_ts_config_raw(struct e1inp_ts *ts, struct e1inp_line *line,
280 void (*raw_recv_cb)(struct e1inp_ts *ts,
281 struct msgb *msg));
282
Harald Welte7a228eb2016-07-28 11:09:31 +0200283/* configure and initialize one timeslot dedicated to HDLC frames */
284int e1inp_ts_config_hdlc(struct e1inp_ts *ts, struct e1inp_line *line,
285 void (*hdlc_recv_cb)(struct e1inp_ts *ts,
286 struct msgb *msg));
287
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200288/* Receive a packet from the E1 driver */
289int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
290 uint8_t tei, uint8_t sapi);
Harald Weltefd44a5f2011-08-21 00:48:54 +0200291int e1inp_rx_ts_lapd(struct e1inp_ts *e1i_ts, struct msgb *msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200292
293/* called by driver if it wants to transmit on a given TS */
294struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
295 struct e1inp_sign_link **sign_link);
296
297/* called by driver in case some kind of link state event */
298int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
299
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200300/* L2->L3 */
301void e1inp_dlsap_up(struct osmo_dlsap_prim *odp, uint8_t tei, uint8_t sapi,
302 void *rx_cbdata);
303
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200304/* Write LAPD frames to the fd. */
Pablo Neira Ayuso2e11f5c2013-07-05 15:08:18 +0200305int e1_set_pcap_fd(int fd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200306
307/* called by TRAU muxer to obtain the destination mux entity */
308struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
309
Harald Welte84f67b22013-06-30 13:13:59 +0200310/* on an IPA BTS, the BTS needs to establish the RSL connection much
311 * later than the OML connection. */
312int e1inp_ipa_bts_rsl_connect(struct e1inp_line *line,
313 const char *rem_addr, uint16_t rem_port);
314
Andreas Eversbergf422a752014-01-21 14:54:41 +0100315int e1inp_ipa_bts_rsl_connect_n(struct e1inp_line *line,
316 const char *rem_addr, uint16_t rem_port,
317 uint8_t trx_id);
318
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200319void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200320int e1inp_line_update(struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200321
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200322int e1inp_vty_init(void);
323
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100324/* activate superchannel or deactive to use timeslots. only valid for unixsocket driver */
325void e1inp_ericsson_set_altc(struct e1inp_line *unixlinue, int superchannel);
326
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200327extern struct llist_head e1inp_driver_list;
328extern struct llist_head e1inp_line_list;
329
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200330/* XXX */
331struct input_signal_data {
Pau Espin Pedrol41792072018-10-03 13:18:37 +0200332 enum e1inp_sign_type link_type;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200333 uint8_t tei;
334 uint8_t sapi;
Harald Weltef35d8892016-10-16 15:33:52 +0200335 uint8_t ts_nr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200336 struct gsm_bts_trx *trx;
337 struct e1inp_line *line;
338};
339
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200340int abis_sendmsg(struct msgb *msg);
Holger Hans Peter Freyther180ce7e2012-02-03 20:06:15 +0100341int abis_rsl_sendmsg(struct msgb *msg);
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200342
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200343#endif /* _E1_INPUT_H */