blob: 7568f19bc967a79ad92ef3404c6003640d53bdda [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
17enum e1inp_sign_type {
18 E1INP_SIGN_NONE,
19 E1INP_SIGN_OML,
20 E1INP_SIGN_RSL,
Harald Welte46fc7e22014-08-18 19:04:26 +020021 E1INP_SIGN_OSMO, /* IPA CCM OSMO sub-type */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020022};
23const char *e1inp_signtype_name(enum e1inp_sign_type tp);
Harald Welte4ca5c532016-07-27 23:05:03 +020024const struct value_string e1inp_sign_type_names[5];
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020025
Harald Weltef2737fc2011-08-16 14:30:10 +020026enum e1inp_ctr {
27 E1I_CTR_HDLC_ABORT,
28 E1I_CTR_HDLC_BADFCS,
29 E1I_CTR_HDLC_OVERR,
30 E1I_CTR_ALARM,
31 E1I_CTR_REMOVED,
32};
33
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020034struct e1inp_ts;
Harald Weltefe05cf52011-09-26 23:18:41 +020035struct vty;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020036
37struct e1inp_sign_link {
38 /* list of signalling links */
39 struct llist_head list;
40
41 /* to which timeslot do we belong? */
42 struct e1inp_ts *ts;
43
44 enum e1inp_sign_type type;
45
46 /* trx for msg->trx of received msgs */
47 struct gsm_bts_trx *trx;
48
49 /* msgb queue of to-be-transmitted msgs */
50 struct llist_head tx_list;
51
52 /* SAPI and TEI on the E1 TS */
53 uint8_t sapi;
54 uint8_t tei;
55
56 union {
57 struct {
58 uint8_t channel;
59 } misdn;
60 } driver;
61};
62
63enum e1inp_ts_type {
64 E1INP_TS_TYPE_NONE,
65 E1INP_TS_TYPE_SIGN,
66 E1INP_TS_TYPE_TRAU,
Harald Weltea0108e72016-07-27 21:44:50 +020067 E1INP_TS_TYPE_RAW,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020068};
69const char *e1inp_tstype_name(enum e1inp_ts_type tp);
Harald Welte4ca5c532016-07-27 23:05:03 +020070const struct value_string e1inp_ts_type_names[5];
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020071
72/* A timeslot in the E1 interface */
73struct e1inp_ts {
74 enum e1inp_ts_type type;
75 int num;
76
77 /* to which line do we belong ? */
78 struct e1inp_line *line;
79
Harald Weltefd44a5f2011-08-21 00:48:54 +020080 /* LAPD instance, if any */
81 struct lapd_instance *lapd;
82
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020083 union {
84 struct {
85 /* list of all signalling links on this TS */
86 struct llist_head sign_links;
87 /* delay for the queue */
88 int delay;
89 /* timer when to dequeue next frame */
90 struct osmo_timer_list tx_timer;
91 } sign;
92 struct {
93 /* subchannel demuxer for frames from E1 */
94 struct subch_demux demux;
95 /* subchannel muxer for frames to E1 */
96 struct subch_mux mux;
97 } trau;
Harald Weltea0108e72016-07-27 21:44:50 +020098 struct {
99 /* call-back for every received frame */
100 void (*recv_cb)(struct e1inp_ts *ts, struct msgb *msg);
101 /* queue of pending to-be-transmitted msgbs */
102 struct llist_head tx_queue;
103 } raw;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200104 };
105 union {
106 struct {
107 /* mISDN driver has one fd for each ts */
108 struct osmo_fd fd;
109 } misdn;
110 struct {
111 /* ip.access driver has one fd for each ts */
112 struct osmo_fd fd;
113 } ipaccess;
114 struct {
115 /* DAHDI driver has one fd for each ts */
116 struct osmo_fd fd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200117 } dahdi;
Pablo Neira Ayuso7e0d0062011-08-19 11:36:15 +0200118 struct {
119 struct osmo_fd fd;
120 } rs232;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200121 } driver;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +0200122
123 struct msgb *pending_msg;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200124};
125
126struct gsm_e1_subslot {
127 /* Number of E1 link */
128 uint8_t e1_nr;
129 /* Number of E1 TS inside E1 link */
130 uint8_t e1_ts;
131 /* Sub-slot within the E1 TS, 0xff if full TS */
132 uint8_t e1_ts_ss;
133};
134
135enum e1inp_line_role {
136 E1INP_LINE_R_NONE,
137 E1INP_LINE_R_BSC,
138 E1INP_LINE_R_BTS,
139 E1INP_LINE_R_MAX
140};
141
142struct e1inp_driver {
143 struct llist_head list;
144 const char *name;
145 int (*want_write)(struct e1inp_ts *ts);
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200146 int (*line_update)(struct e1inp_line *line);
Pablo Neira Ayusoadd3ec82011-07-05 14:45:46 +0200147 void (*close)(struct e1inp_sign_link *link);
Harald Weltefe05cf52011-09-26 23:18:41 +0200148 void (*vty_show)(struct vty *vty, struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200149 int default_delay;
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100150 int has_keepalive;
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100151 const char *bind_addr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200152};
153
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200154struct e1inp_line_ops {
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200155 union {
156 struct {
157 enum e1inp_line_role role; /* BSC or BTS mode. */
158 const char *addr; /* IP address .*/
159 void *dev; /* device parameters. */
160 } ipa;
161 struct {
162 const char *port; /* e.g. /dev/ttyUSB0 */
163 unsigned int delay;
164 } rs232;
165 } cfg;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200166
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200167 struct e1inp_sign_link * (*sign_link_up)(void *unit_info, struct e1inp_line *line, enum e1inp_sign_type type);
168 void (*sign_link_down)(struct e1inp_line *line);
Pablo Neira Ayusodbd82fb2011-07-05 15:29:23 +0200169 int (*sign_link)(struct msgb *msg);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200170};
171
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200172struct e1inp_line {
173 struct llist_head list;
174 int refcnt;
175
176 unsigned int num;
177 const char *name;
Harald Weltec2889512011-09-13 23:49:04 +0100178 unsigned int port_nr;
Harald Weltef2737fc2011-08-16 14:30:10 +0200179 struct rate_ctr_group *rate_ctr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200180
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100181 /* keepalive configuration */
182 int keepalive_num_probes; /* 0: disable, num, or E1INP_USE_DEFAULT */
183 int keepalive_idle_timeout; /* secs, or E1INP_USE_DEFAULT */
184 int keepalive_probe_interval; /* secs or E1INP_USE_DEFAULT */
185
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200186 /* array of timestlots */
187 struct e1inp_ts ts[NUM_E1_TS];
Harald Weltec2889512011-09-13 23:49:04 +0100188 unsigned int num_ts;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200189
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200190 const struct e1inp_line_ops *ops;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200191
192 struct e1inp_driver *driver;
193 void *driver_data;
194};
195
Harald Weltecc2241b2011-07-19 16:06:06 +0200196/* SS_L_INPUT signals */
Pablo Neira Ayuso332a3572011-08-16 17:31:20 +0200197enum e1inp_signal_input {
Pablo Neira Ayusode668912011-08-16 17:26:23 +0200198 S_L_INP_NONE,
199 S_L_INP_TEI_UP,
200 S_L_INP_TEI_DN,
201 S_L_INP_TEI_UNKNOWN,
202 S_L_INP_LINE_INIT,
203 S_L_INP_LINE_ALARM,
204 S_L_INP_LINE_NOALARM,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200205};
206
207/* register a driver with the E1 core */
208int e1inp_driver_register(struct e1inp_driver *drv);
209
210/* fine a previously registered driver */
211struct e1inp_driver *e1inp_driver_find(const char *name);
212
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200213/* get a line by its ID */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200214struct e1inp_line *e1inp_line_find(uint8_t e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200215
216/* create a line in the E1 input core */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200217struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
218
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200219/* clone one existing E1 input line */
220struct e1inp_line *e1inp_line_clone(void *ctx, struct e1inp_line *line);
221
222/* increment refcount use of E1 input line */
223void e1inp_line_get(struct e1inp_line *line);
224
225/* decrement refcount use of E1 input line, release if unused */
226void e1inp_line_put(struct e1inp_line *line);
227
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200228/* bind operations to one E1 input line */
229void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200230
231/* find a sign_link for given TEI and SAPI in a TS */
232struct e1inp_sign_link *
233e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
234 uint8_t sapi);
235
236/* create a new signalling link in a E1 timeslot */
237struct e1inp_sign_link *
238e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
239 struct gsm_bts_trx *trx, uint8_t tei,
240 uint8_t sapi);
241
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200242/* configure and initialize one signalling e1inp_ts */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200243int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line);
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200244
245/* configure and initialize one timeslot dedicated to TRAU frames. */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200246int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line,
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200247 int (*trau_rcv_cb)(struct subch_demux *dmx, int ch,
248 uint8_t *data, int len, void *_priv));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200249
Harald Weltea0108e72016-07-27 21:44:50 +0200250/* configure and initialize one timeslot dedicated to RAW frames */
251int e1inp_ts_config_raw(struct e1inp_ts *ts, struct e1inp_line *line,
252 void (*raw_recv_cb)(struct e1inp_ts *ts,
253 struct msgb *msg));
254
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200255/* Receive a packet from the E1 driver */
256int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
257 uint8_t tei, uint8_t sapi);
Harald Weltefd44a5f2011-08-21 00:48:54 +0200258int e1inp_rx_ts_lapd(struct e1inp_ts *e1i_ts, struct msgb *msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200259
260/* called by driver if it wants to transmit on a given TS */
261struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
262 struct e1inp_sign_link **sign_link);
263
264/* called by driver in case some kind of link state event */
265int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
266
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200267/* L2->L3 */
268void e1inp_dlsap_up(struct osmo_dlsap_prim *odp, uint8_t tei, uint8_t sapi,
269 void *rx_cbdata);
270
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200271/* Write LAPD frames to the fd. */
Pablo Neira Ayuso2e11f5c2013-07-05 15:08:18 +0200272int e1_set_pcap_fd(int fd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200273
274/* called by TRAU muxer to obtain the destination mux entity */
275struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
276
Harald Welte84f67b22013-06-30 13:13:59 +0200277/* on an IPA BTS, the BTS needs to establish the RSL connection much
278 * later than the OML connection. */
279int e1inp_ipa_bts_rsl_connect(struct e1inp_line *line,
280 const char *rem_addr, uint16_t rem_port);
281
Andreas Eversbergf422a752014-01-21 14:54:41 +0100282int e1inp_ipa_bts_rsl_connect_n(struct e1inp_line *line,
283 const char *rem_addr, uint16_t rem_port,
284 uint8_t trx_id);
285
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200286void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200287int e1inp_line_update(struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200288
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200289int e1inp_vty_init(void);
290
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200291struct gsm_network;
292int ipaccess_setup(struct gsm_network *gsmnet);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200293
294extern struct llist_head e1inp_driver_list;
295extern struct llist_head e1inp_line_list;
296
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200297/* XXX */
298struct input_signal_data {
299 int link_type;
300 uint8_t tei;
301 uint8_t sapi;
Harald Weltef35d8892016-10-16 15:33:52 +0200302 uint8_t ts_nr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200303 struct gsm_bts_trx *trx;
304 struct e1inp_line *line;
305};
306
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200307int abis_sendmsg(struct msgb *msg);
Holger Hans Peter Freyther180ce7e2012-02-03 20:06:15 +0100308int abis_rsl_sendmsg(struct msgb *msg);
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200309
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200310#endif /* _E1_INPUT_H */