blob: 44708bb320c118e81288d2c9a562c12b49e88048 [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>
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +02008#include <osmocom/core/use_count.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02009#include <osmocom/core/timer.h>
10#include <osmocom/core/msgb.h>
11#include <osmocom/core/select.h>
Pablo Neira Ayuso177094b2011-06-07 12:21:51 +020012#include <osmocom/abis/subchan_demux.h>
Andreas Eversberga7ff0012011-09-26 11:29:30 +020013#include <osmocom/abis/lapd.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020014
15#define NUM_E1_TS 32
Jacob Erlbeck86dae842014-01-16 18:10:37 +010016#define E1INP_USE_DEFAULT (-1)
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020017
Harald Welteb5af0992020-01-12 12:59:52 +010018#define LOGPITS(e1ts, ss, level, fmt, args ...) \
19 LOGP(ss, level, "E1TS(%u:%u) " fmt, (e1ts)->line->num, (e1ts)->num, ## args)
20
21#define LOGPIL(e1l, ss, level, fmt, args ...) \
22 LOGP(ss, level, "E1L(%u) " fmt, (e1l)->num, ## args)
23
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020024enum e1inp_sign_type {
25 E1INP_SIGN_NONE,
26 E1INP_SIGN_OML,
27 E1INP_SIGN_RSL,
Harald Welte46fc7e22014-08-18 19:04:26 +020028 E1INP_SIGN_OSMO, /* IPA CCM OSMO sub-type */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020029};
30const char *e1inp_signtype_name(enum e1inp_sign_type tp);
Arran Cudbard-Bell67b81eb2016-11-02 11:48:24 -040031extern const struct value_string e1inp_sign_type_names[5];
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020032
Harald Weltef2737fc2011-08-16 14:30:10 +020033enum e1inp_ctr {
34 E1I_CTR_HDLC_ABORT,
35 E1I_CTR_HDLC_BADFCS,
36 E1I_CTR_HDLC_OVERR,
37 E1I_CTR_ALARM,
38 E1I_CTR_REMOVED,
39};
40
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020041struct e1inp_ts;
Harald Weltefe05cf52011-09-26 23:18:41 +020042struct vty;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020043
44struct e1inp_sign_link {
45 /* list of signalling links */
46 struct llist_head list;
47
48 /* to which timeslot do we belong? */
49 struct e1inp_ts *ts;
50
51 enum e1inp_sign_type type;
52
Pau Espin Pedrol837fb6e2020-07-15 15:09:36 +020053 /* trx for msg->trx of received msgs */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020054 struct gsm_bts_trx *trx;
55
56 /* msgb queue of to-be-transmitted msgs */
57 struct llist_head tx_list;
58
59 /* SAPI and TEI on the E1 TS */
60 uint8_t sapi;
61 uint8_t tei;
62
63 union {
64 struct {
65 uint8_t channel;
66 } misdn;
67 } driver;
68};
69
70enum e1inp_ts_type {
71 E1INP_TS_TYPE_NONE,
72 E1INP_TS_TYPE_SIGN,
73 E1INP_TS_TYPE_TRAU,
Harald Weltea0108e72016-07-27 21:44:50 +020074 E1INP_TS_TYPE_RAW,
Harald Welte7a228eb2016-07-28 11:09:31 +020075 E1INP_TS_TYPE_HDLC,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020076};
77const char *e1inp_tstype_name(enum e1inp_ts_type tp);
Arran Cudbard-Bell67b81eb2016-11-02 11:48:24 -040078extern const struct value_string e1inp_ts_type_names[6];
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020079
80/* A timeslot in the E1 interface */
81struct e1inp_ts {
82 enum e1inp_ts_type type;
83 int num;
84
85 /* to which line do we belong ? */
86 struct e1inp_line *line;
87
Harald Weltefd44a5f2011-08-21 00:48:54 +020088 /* LAPD instance, if any */
89 struct lapd_instance *lapd;
90
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020091 union {
92 struct {
93 /* list of all signalling links on this TS */
94 struct llist_head sign_links;
95 /* delay for the queue */
96 int delay;
97 /* timer when to dequeue next frame */
98 struct osmo_timer_list tx_timer;
99 } sign;
100 struct {
101 /* subchannel demuxer for frames from E1 */
102 struct subch_demux demux;
103 /* subchannel muxer for frames to E1 */
104 struct subch_mux mux;
105 } trau;
Harald Weltea0108e72016-07-27 21:44:50 +0200106 struct {
107 /* call-back for every received frame */
108 void (*recv_cb)(struct e1inp_ts *ts, struct msgb *msg);
109 /* queue of pending to-be-transmitted msgbs */
110 struct llist_head tx_queue;
111 } raw;
Harald Welte7a228eb2016-07-28 11:09:31 +0200112 struct {
113 /* call-back for every received frame */
114 void (*recv_cb)(struct e1inp_ts *ts, struct msgb *msg);
115 /* queue of pending to-be-transmitted msgbs */
116 struct llist_head tx_queue;
117 } hdlc;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200118 };
119 union {
120 struct {
121 /* mISDN driver has one fd for each ts */
122 struct osmo_fd fd;
123 } misdn;
124 struct {
125 /* ip.access driver has one fd for each ts */
126 struct osmo_fd fd;
Eric Wildef1f3272019-07-10 18:10:31 +0200127 /* ipa keep-alive */
128 struct osmo_fsm_inst* ka_fsm;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200129 } ipaccess;
130 struct {
131 /* DAHDI driver has one fd for each ts */
132 struct osmo_fd fd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200133 } dahdi;
Pablo Neira Ayuso7e0d0062011-08-19 11:36:15 +0200134 struct {
Sylvain Munautb559a532019-05-09 11:14:26 +0200135 /* osmo-e1d driver has one fd for each ts */
136 struct osmo_fd fd;
137 } e1d;
138 struct {
Pablo Neira Ayuso7e0d0062011-08-19 11:36:15 +0200139 struct osmo_fd fd;
140 } rs232;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200141 } driver;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +0200142
143 struct msgb *pending_msg;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200144};
145
146struct gsm_e1_subslot {
147 /* Number of E1 link */
148 uint8_t e1_nr;
149 /* Number of E1 TS inside E1 link */
150 uint8_t e1_ts;
151 /* Sub-slot within the E1 TS, 0xff if full TS */
152 uint8_t e1_ts_ss;
153};
154
155enum e1inp_line_role {
156 E1INP_LINE_R_NONE,
157 E1INP_LINE_R_BSC,
158 E1INP_LINE_R_BTS,
159 E1INP_LINE_R_MAX
160};
161
162struct e1inp_driver {
163 struct llist_head list;
164 const char *name;
165 int (*want_write)(struct e1inp_ts *ts);
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200166 int (*line_update)(struct e1inp_line *line);
Pablo Neira Ayusoadd3ec82011-07-05 14:45:46 +0200167 void (*close)(struct e1inp_sign_link *link);
Harald Weltefe05cf52011-09-26 23:18:41 +0200168 void (*vty_show)(struct vty *vty, struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200169 int default_delay;
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100170 int has_keepalive;
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100171 const char *bind_addr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200172};
173
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200174struct e1inp_line_ops {
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200175 union {
176 struct {
177 enum e1inp_line_role role; /* BSC or BTS mode. */
178 const char *addr; /* IP address .*/
179 void *dev; /* device parameters. */
180 } ipa;
181 struct {
182 const char *port; /* e.g. /dev/ttyUSB0 */
183 unsigned int delay;
184 } rs232;
185 } cfg;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200186
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200187 struct e1inp_sign_link * (*sign_link_up)(void *unit_info, struct e1inp_line *line, enum e1inp_sign_type type);
188 void (*sign_link_down)(struct e1inp_line *line);
Pau Espin Pedroled122f32018-08-28 18:25:02 +0200189 /* 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 +0200190 int (*sign_link)(struct msgb *msg);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200191};
192
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200193struct e1inp_line {
194 struct llist_head list;
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200195 int refcnt; /* unusued, kept for ABI compat, use_count is used instead */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200196
197 unsigned int num;
198 const char *name;
Harald Weltec2889512011-09-13 23:49:04 +0100199 unsigned int port_nr;
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100200 char *sock_path;
Harald Weltef2737fc2011-08-16 14:30:10 +0200201 struct rate_ctr_group *rate_ctr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200202
Eric Wildef1f3272019-07-10 18:10:31 +0200203 /* tcp keepalive configuration */
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100204 int keepalive_num_probes; /* 0: disable, num, or E1INP_USE_DEFAULT */
205 int keepalive_idle_timeout; /* secs, or E1INP_USE_DEFAULT */
206 int keepalive_probe_interval; /* secs or E1INP_USE_DEFAULT */
207
Eric Wildef1f3272019-07-10 18:10:31 +0200208 /* ipa ping/pong keepalive params */
209 struct ipa_keepalive_params *ipa_kap;
210
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200211 /* array of timestlots */
212 struct e1inp_ts ts[NUM_E1_TS];
Harald Weltec2889512011-09-13 23:49:04 +0100213 unsigned int num_ts;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200214
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200215 const struct e1inp_line_ops *ops;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200216
217 struct e1inp_driver *driver;
218 void *driver_data;
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200219
220 struct osmo_use_count use_count;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200221};
Pau Espin Pedrolb5cfc6b2018-10-02 21:22:18 +0200222#define e1inp_line_ipa_oml_ts(line) (&line->ts[0])
223#define e1inp_line_ipa_rsl_ts(line, trx_id) (&line->ts[1 + (trx_id)])
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200224
Harald Weltecc2241b2011-07-19 16:06:06 +0200225/* SS_L_INPUT signals */
Pablo Neira Ayuso332a3572011-08-16 17:31:20 +0200226enum e1inp_signal_input {
Pablo Neira Ayusode668912011-08-16 17:26:23 +0200227 S_L_INP_NONE,
228 S_L_INP_TEI_UP,
229 S_L_INP_TEI_DN,
230 S_L_INP_TEI_UNKNOWN,
231 S_L_INP_LINE_INIT,
232 S_L_INP_LINE_ALARM,
233 S_L_INP_LINE_NOALARM,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200234};
235
Harald Weltecac78fe2017-05-25 19:13:13 +0200236extern const struct value_string e1inp_signal_names[];
237
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200238/* register a driver with the E1 core */
239int e1inp_driver_register(struct e1inp_driver *drv);
240
241/* fine a previously registered driver */
242struct e1inp_driver *e1inp_driver_find(const char *name);
243
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200244/* get a line by its ID */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200245struct e1inp_line *e1inp_line_find(uint8_t e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200246
247/* create a line in the E1 input core */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200248struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
249
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200250/* clone one existing E1 input line */
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200251struct e1inp_line *e1inp_line_clone(void *ctx, struct e1inp_line *line, const char *use);
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200252
253/* increment refcount use of E1 input line */
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200254void e1inp_line_get(struct e1inp_line *line) OSMO_DEPRECATED("Use e1inp_line_get2() instead");
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200255
256/* decrement refcount use of E1 input line, release if unused */
Pau Espin Pedrol5196cd52020-07-14 17:52:09 +0200257void e1inp_line_put(struct e1inp_line *line) OSMO_DEPRECATED("Use e1inp_line_put2() instead");
258
259/* Convenience macros for struct foo instances. These are strict about use count errors. */
260#define e1inp_line_get2(line, USE) OSMO_ASSERT( osmo_use_count_get_put(&(line)->use_count, USE, 1) == 0 );
261#define e1inp_line_put2(line, USE) OSMO_ASSERT( osmo_use_count_get_put(&(line)->use_count, USE, -1) == 0 );
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200262
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200263/* bind operations to one E1 input line */
264void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200265
266/* find a sign_link for given TEI and SAPI in a TS */
267struct e1inp_sign_link *
268e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
269 uint8_t sapi);
270
271/* create a new signalling link in a E1 timeslot */
272struct e1inp_sign_link *
273e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
274 struct gsm_bts_trx *trx, uint8_t tei,
275 uint8_t sapi);
276
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200277/* configure and initialize one signalling e1inp_ts */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200278int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line);
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200279
280/* configure and initialize one timeslot dedicated to TRAU frames. */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200281int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line,
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200282 int (*trau_rcv_cb)(struct subch_demux *dmx, int ch,
Harald Welte5226e5b2020-05-07 23:09:16 +0200283 const ubit_t *data, int len, void *_priv));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200284
Harald Weltea0108e72016-07-27 21:44:50 +0200285/* configure and initialize one timeslot dedicated to RAW frames */
286int e1inp_ts_config_raw(struct e1inp_ts *ts, struct e1inp_line *line,
287 void (*raw_recv_cb)(struct e1inp_ts *ts,
288 struct msgb *msg));
289
Harald Welte7a228eb2016-07-28 11:09:31 +0200290/* configure and initialize one timeslot dedicated to HDLC frames */
291int e1inp_ts_config_hdlc(struct e1inp_ts *ts, struct e1inp_line *line,
292 void (*hdlc_recv_cb)(struct e1inp_ts *ts,
293 struct msgb *msg));
294
Harald Welteb9031882020-05-02 21:09:15 +0200295/* obtain a string identifier/name for the given timeslot */
296void e1inp_ts_name(char *out, size_t out_len, const struct e1inp_ts *ts);
297
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200298/* Receive a packet from the E1 driver */
299int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
300 uint8_t tei, uint8_t sapi);
Harald Weltefd44a5f2011-08-21 00:48:54 +0200301int e1inp_rx_ts_lapd(struct e1inp_ts *e1i_ts, struct msgb *msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200302
303/* called by driver if it wants to transmit on a given TS */
304struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
305 struct e1inp_sign_link **sign_link);
306
307/* called by driver in case some kind of link state event */
308int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
309
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200310/* L2->L3 */
311void e1inp_dlsap_up(struct osmo_dlsap_prim *odp, uint8_t tei, uint8_t sapi,
312 void *rx_cbdata);
313
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200314/* Write LAPD frames to the fd. */
Pablo Neira Ayuso2e11f5c2013-07-05 15:08:18 +0200315int e1_set_pcap_fd(int fd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200316
317/* called by TRAU muxer to obtain the destination mux entity */
318struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
319
Harald Welte84f67b22013-06-30 13:13:59 +0200320/* on an IPA BTS, the BTS needs to establish the RSL connection much
321 * later than the OML connection. */
322int e1inp_ipa_bts_rsl_connect(struct e1inp_line *line,
323 const char *rem_addr, uint16_t rem_port);
324
Andreas Eversbergf422a752014-01-21 14:54:41 +0100325int e1inp_ipa_bts_rsl_connect_n(struct e1inp_line *line,
326 const char *rem_addr, uint16_t rem_port,
327 uint8_t trx_id);
328
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200329void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200330int e1inp_line_update(struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200331
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200332int e1inp_vty_init(void);
333
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100334/* activate superchannel or deactive to use timeslots. only valid for unixsocket driver */
335void e1inp_ericsson_set_altc(struct e1inp_line *unixlinue, int superchannel);
336
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200337extern struct llist_head e1inp_driver_list;
338extern struct llist_head e1inp_line_list;
339
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200340/* XXX */
341struct input_signal_data {
Pau Espin Pedrol41792072018-10-03 13:18:37 +0200342 enum e1inp_sign_type link_type;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200343 uint8_t tei;
344 uint8_t sapi;
Harald Weltef35d8892016-10-16 15:33:52 +0200345 uint8_t ts_nr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200346 struct gsm_bts_trx *trx;
347 struct e1inp_line *line;
348};
349
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200350int abis_sendmsg(struct msgb *msg);
Holger Hans Peter Freyther180ce7e2012-02-03 20:06:15 +0100351int abis_rsl_sendmsg(struct msgb *msg);
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200352
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200353#endif /* _E1_INPUT_H */