blob: fe5d624dc702d4dee16abe77522ddd5b4b4b0198 [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);
24
Harald Weltef2737fc2011-08-16 14:30:10 +020025enum e1inp_ctr {
26 E1I_CTR_HDLC_ABORT,
27 E1I_CTR_HDLC_BADFCS,
28 E1I_CTR_HDLC_OVERR,
29 E1I_CTR_ALARM,
30 E1I_CTR_REMOVED,
31};
32
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020033struct e1inp_ts;
Harald Weltefe05cf52011-09-26 23:18:41 +020034struct vty;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020035
36struct e1inp_sign_link {
37 /* list of signalling links */
38 struct llist_head list;
39
40 /* to which timeslot do we belong? */
41 struct e1inp_ts *ts;
42
43 enum e1inp_sign_type type;
44
45 /* trx for msg->trx of received msgs */
46 struct gsm_bts_trx *trx;
47
48 /* msgb queue of to-be-transmitted msgs */
49 struct llist_head tx_list;
50
51 /* SAPI and TEI on the E1 TS */
52 uint8_t sapi;
53 uint8_t tei;
54
55 union {
56 struct {
57 uint8_t channel;
58 } misdn;
59 } driver;
60};
61
62enum e1inp_ts_type {
63 E1INP_TS_TYPE_NONE,
64 E1INP_TS_TYPE_SIGN,
65 E1INP_TS_TYPE_TRAU,
66};
67const char *e1inp_tstype_name(enum e1inp_ts_type tp);
68
69/* A timeslot in the E1 interface */
70struct e1inp_ts {
71 enum e1inp_ts_type type;
72 int num;
73
74 /* to which line do we belong ? */
75 struct e1inp_line *line;
76
Harald Weltefd44a5f2011-08-21 00:48:54 +020077 /* LAPD instance, if any */
78 struct lapd_instance *lapd;
79
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020080 union {
81 struct {
82 /* list of all signalling links on this TS */
83 struct llist_head sign_links;
84 /* delay for the queue */
85 int delay;
86 /* timer when to dequeue next frame */
87 struct osmo_timer_list tx_timer;
88 } sign;
89 struct {
90 /* subchannel demuxer for frames from E1 */
91 struct subch_demux demux;
92 /* subchannel muxer for frames to E1 */
93 struct subch_mux mux;
94 } trau;
95 };
96 union {
97 struct {
98 /* mISDN driver has one fd for each ts */
99 struct osmo_fd fd;
100 } misdn;
101 struct {
102 /* ip.access driver has one fd for each ts */
103 struct osmo_fd fd;
104 } ipaccess;
105 struct {
106 /* DAHDI driver has one fd for each ts */
107 struct osmo_fd fd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200108 } dahdi;
Pablo Neira Ayuso7e0d0062011-08-19 11:36:15 +0200109 struct {
110 struct osmo_fd fd;
111 } rs232;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200112 } driver;
Jacob Erlbeck98af3c32014-03-31 10:53:32 +0200113
114 struct msgb *pending_msg;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200115};
116
117struct gsm_e1_subslot {
118 /* Number of E1 link */
119 uint8_t e1_nr;
120 /* Number of E1 TS inside E1 link */
121 uint8_t e1_ts;
122 /* Sub-slot within the E1 TS, 0xff if full TS */
123 uint8_t e1_ts_ss;
124};
125
126enum e1inp_line_role {
127 E1INP_LINE_R_NONE,
128 E1INP_LINE_R_BSC,
129 E1INP_LINE_R_BTS,
130 E1INP_LINE_R_MAX
131};
132
133struct e1inp_driver {
134 struct llist_head list;
135 const char *name;
136 int (*want_write)(struct e1inp_ts *ts);
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200137 int (*line_update)(struct e1inp_line *line);
Pablo Neira Ayusoadd3ec82011-07-05 14:45:46 +0200138 void (*close)(struct e1inp_sign_link *link);
Harald Weltefe05cf52011-09-26 23:18:41 +0200139 void (*vty_show)(struct vty *vty, struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200140 int default_delay;
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100141 int has_keepalive;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200142};
143
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200144struct e1inp_line_ops {
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200145 union {
146 struct {
147 enum e1inp_line_role role; /* BSC or BTS mode. */
148 const char *addr; /* IP address .*/
149 void *dev; /* device parameters. */
150 } ipa;
151 struct {
152 const char *port; /* e.g. /dev/ttyUSB0 */
153 unsigned int delay;
154 } rs232;
155 } cfg;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200156
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200157 struct e1inp_sign_link * (*sign_link_up)(void *unit_info, struct e1inp_line *line, enum e1inp_sign_type type);
158 void (*sign_link_down)(struct e1inp_line *line);
Pablo Neira Ayusodbd82fb2011-07-05 15:29:23 +0200159 int (*sign_link)(struct msgb *msg);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200160};
161
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200162struct e1inp_line {
163 struct llist_head list;
164 int refcnt;
165
166 unsigned int num;
167 const char *name;
Harald Weltec2889512011-09-13 23:49:04 +0100168 unsigned int port_nr;
Harald Weltef2737fc2011-08-16 14:30:10 +0200169 struct rate_ctr_group *rate_ctr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200170
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100171 /* keepalive configuration */
172 int keepalive_num_probes; /* 0: disable, num, or E1INP_USE_DEFAULT */
173 int keepalive_idle_timeout; /* secs, or E1INP_USE_DEFAULT */
174 int keepalive_probe_interval; /* secs or E1INP_USE_DEFAULT */
175
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200176 /* array of timestlots */
177 struct e1inp_ts ts[NUM_E1_TS];
Harald Weltec2889512011-09-13 23:49:04 +0100178 unsigned int num_ts;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200179
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200180 const struct e1inp_line_ops *ops;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200181
182 struct e1inp_driver *driver;
183 void *driver_data;
184};
185
Harald Weltecc2241b2011-07-19 16:06:06 +0200186/* SS_L_INPUT signals */
Pablo Neira Ayuso332a3572011-08-16 17:31:20 +0200187enum e1inp_signal_input {
Pablo Neira Ayusode668912011-08-16 17:26:23 +0200188 S_L_INP_NONE,
189 S_L_INP_TEI_UP,
190 S_L_INP_TEI_DN,
191 S_L_INP_TEI_UNKNOWN,
192 S_L_INP_LINE_INIT,
193 S_L_INP_LINE_ALARM,
194 S_L_INP_LINE_NOALARM,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200195};
196
197/* register a driver with the E1 core */
198int e1inp_driver_register(struct e1inp_driver *drv);
199
200/* fine a previously registered driver */
201struct e1inp_driver *e1inp_driver_find(const char *name);
202
203/* register a line with the E1 core */
204int e1inp_line_register(struct e1inp_line *line);
205
206/* get a line by its ID */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200207struct e1inp_line *e1inp_line_find(uint8_t e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200208
209/* create a line in the E1 input core */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200210struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
211
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200212/* clone one existing E1 input line */
213struct e1inp_line *e1inp_line_clone(void *ctx, struct e1inp_line *line);
214
215/* increment refcount use of E1 input line */
216void e1inp_line_get(struct e1inp_line *line);
217
218/* decrement refcount use of E1 input line, release if unused */
219void e1inp_line_put(struct e1inp_line *line);
220
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200221/* bind operations to one E1 input line */
222void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200223
224/* find a sign_link for given TEI and SAPI in a TS */
225struct e1inp_sign_link *
226e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
227 uint8_t sapi);
228
229/* create a new signalling link in a E1 timeslot */
230struct e1inp_sign_link *
231e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
232 struct gsm_bts_trx *trx, uint8_t tei,
233 uint8_t sapi);
234
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200235/* configure and initialize one signalling e1inp_ts */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200236int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line);
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200237
238/* configure and initialize one timeslot dedicated to TRAU frames. */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200239int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line,
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200240 int (*trau_rcv_cb)(struct subch_demux *dmx, int ch,
241 uint8_t *data, int len, void *_priv));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200242
243/* Call from the Stack: configuration of this TS has changed */
244int e1inp_update_ts(struct e1inp_ts *ts);
245
246/* Receive a packet from the E1 driver */
247int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
248 uint8_t tei, uint8_t sapi);
Harald Weltefd44a5f2011-08-21 00:48:54 +0200249int e1inp_rx_ts_lapd(struct e1inp_ts *e1i_ts, struct msgb *msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200250
251/* called by driver if it wants to transmit on a given TS */
252struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
253 struct e1inp_sign_link **sign_link);
254
255/* called by driver in case some kind of link state event */
256int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
257
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200258/* L2->L3 */
259void e1inp_dlsap_up(struct osmo_dlsap_prim *odp, uint8_t tei, uint8_t sapi,
260 void *rx_cbdata);
261
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200262/* Write LAPD frames to the fd. */
Pablo Neira Ayuso2e11f5c2013-07-05 15:08:18 +0200263int e1_set_pcap_fd(int fd);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200264
265/* called by TRAU muxer to obtain the destination mux entity */
266struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
267
Harald Welte84f67b22013-06-30 13:13:59 +0200268/* on an IPA BTS, the BTS needs to establish the RSL connection much
269 * later than the OML connection. */
270int e1inp_ipa_bts_rsl_connect(struct e1inp_line *line,
271 const char *rem_addr, uint16_t rem_port);
272
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200273void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200274int e1inp_line_update(struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200275
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200276int e1inp_vty_init(void);
277
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200278struct gsm_network;
279int ipaccess_setup(struct gsm_network *gsmnet);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200280
281extern struct llist_head e1inp_driver_list;
282extern struct llist_head e1inp_line_list;
283
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200284/* XXX */
285struct input_signal_data {
286 int link_type;
287 uint8_t tei;
288 uint8_t sapi;
289 struct gsm_bts_trx *trx;
290 struct e1inp_line *line;
291};
292
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200293int abis_sendmsg(struct msgb *msg);
Holger Hans Peter Freyther180ce7e2012-02-03 20:06:15 +0100294int abis_rsl_sendmsg(struct msgb *msg);
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200295
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200296#endif /* _E1_INPUT_H */