blob: 16e7f8bbabee3ab7200811605cc3285ec3562e07 [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
15
16enum e1inp_sign_type {
17 E1INP_SIGN_NONE,
18 E1INP_SIGN_OML,
19 E1INP_SIGN_RSL,
20};
21const char *e1inp_signtype_name(enum e1inp_sign_type tp);
22
Harald Weltef2737fc2011-08-16 14:30:10 +020023enum e1inp_ctr {
24 E1I_CTR_HDLC_ABORT,
25 E1I_CTR_HDLC_BADFCS,
26 E1I_CTR_HDLC_OVERR,
27 E1I_CTR_ALARM,
28 E1I_CTR_REMOVED,
29};
30
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020031struct e1inp_ts;
Harald Weltefe05cf52011-09-26 23:18:41 +020032struct vty;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020033
34struct e1inp_sign_link {
35 /* list of signalling links */
36 struct llist_head list;
37
38 /* to which timeslot do we belong? */
39 struct e1inp_ts *ts;
40
41 enum e1inp_sign_type type;
42
43 /* trx for msg->trx of received msgs */
44 struct gsm_bts_trx *trx;
45
46 /* msgb queue of to-be-transmitted msgs */
47 struct llist_head tx_list;
48
49 /* SAPI and TEI on the E1 TS */
50 uint8_t sapi;
51 uint8_t tei;
52
53 union {
54 struct {
55 uint8_t channel;
56 } misdn;
57 } driver;
58};
59
60enum e1inp_ts_type {
61 E1INP_TS_TYPE_NONE,
62 E1INP_TS_TYPE_SIGN,
63 E1INP_TS_TYPE_TRAU,
64};
65const char *e1inp_tstype_name(enum e1inp_ts_type tp);
66
67/* A timeslot in the E1 interface */
68struct e1inp_ts {
69 enum e1inp_ts_type type;
70 int num;
71
72 /* to which line do we belong ? */
73 struct e1inp_line *line;
74
Harald Weltefd44a5f2011-08-21 00:48:54 +020075 /* LAPD instance, if any */
76 struct lapd_instance *lapd;
77
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020078 union {
79 struct {
80 /* list of all signalling links on this TS */
81 struct llist_head sign_links;
82 /* delay for the queue */
83 int delay;
84 /* timer when to dequeue next frame */
85 struct osmo_timer_list tx_timer;
86 } sign;
87 struct {
88 /* subchannel demuxer for frames from E1 */
89 struct subch_demux demux;
90 /* subchannel muxer for frames to E1 */
91 struct subch_mux mux;
92 } trau;
93 };
94 union {
95 struct {
96 /* mISDN driver has one fd for each ts */
97 struct osmo_fd fd;
98 } misdn;
99 struct {
100 /* ip.access driver has one fd for each ts */
101 struct osmo_fd fd;
102 } ipaccess;
103 struct {
104 /* DAHDI driver has one fd for each ts */
105 struct osmo_fd fd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200106 } dahdi;
Pablo Neira Ayuso7e0d0062011-08-19 11:36:15 +0200107 struct {
108 struct osmo_fd fd;
109 } rs232;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200110 } driver;
111};
112
113struct gsm_e1_subslot {
114 /* Number of E1 link */
115 uint8_t e1_nr;
116 /* Number of E1 TS inside E1 link */
117 uint8_t e1_ts;
118 /* Sub-slot within the E1 TS, 0xff if full TS */
119 uint8_t e1_ts_ss;
120};
121
122enum e1inp_line_role {
123 E1INP_LINE_R_NONE,
124 E1INP_LINE_R_BSC,
125 E1INP_LINE_R_BTS,
126 E1INP_LINE_R_MAX
127};
128
129struct e1inp_driver {
130 struct llist_head list;
131 const char *name;
132 int (*want_write)(struct e1inp_ts *ts);
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200133 int (*line_update)(struct e1inp_line *line);
Pablo Neira Ayusoadd3ec82011-07-05 14:45:46 +0200134 void (*close)(struct e1inp_sign_link *link);
Harald Weltefe05cf52011-09-26 23:18:41 +0200135 void (*vty_show)(struct vty *vty, struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200136 int default_delay;
137};
138
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200139struct e1inp_line_ops {
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200140 union {
141 struct {
142 enum e1inp_line_role role; /* BSC or BTS mode. */
143 const char *addr; /* IP address .*/
144 void *dev; /* device parameters. */
145 } ipa;
146 struct {
147 const char *port; /* e.g. /dev/ttyUSB0 */
148 unsigned int delay;
149 } rs232;
150 } cfg;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200151
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200152 struct e1inp_sign_link * (*sign_link_up)(void *unit_info, struct e1inp_line *line, enum e1inp_sign_type type);
153 void (*sign_link_down)(struct e1inp_line *line);
Pablo Neira Ayusodbd82fb2011-07-05 15:29:23 +0200154 int (*sign_link)(struct msgb *msg);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200155};
156
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200157struct e1inp_line {
158 struct llist_head list;
159 int refcnt;
160
161 unsigned int num;
162 const char *name;
Harald Weltec2889512011-09-13 23:49:04 +0100163 unsigned int port_nr;
Harald Weltef2737fc2011-08-16 14:30:10 +0200164 struct rate_ctr_group *rate_ctr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200165
166 /* array of timestlots */
167 struct e1inp_ts ts[NUM_E1_TS];
Harald Weltec2889512011-09-13 23:49:04 +0100168 unsigned int num_ts;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200169
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200170 const struct e1inp_line_ops *ops;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200171
172 struct e1inp_driver *driver;
173 void *driver_data;
174};
175
Harald Weltecc2241b2011-07-19 16:06:06 +0200176/* SS_L_INPUT signals */
Pablo Neira Ayuso332a3572011-08-16 17:31:20 +0200177enum e1inp_signal_input {
Pablo Neira Ayusode668912011-08-16 17:26:23 +0200178 S_L_INP_NONE,
179 S_L_INP_TEI_UP,
180 S_L_INP_TEI_DN,
181 S_L_INP_TEI_UNKNOWN,
182 S_L_INP_LINE_INIT,
183 S_L_INP_LINE_ALARM,
184 S_L_INP_LINE_NOALARM,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200185};
186
187/* register a driver with the E1 core */
188int e1inp_driver_register(struct e1inp_driver *drv);
189
190/* fine a previously registered driver */
191struct e1inp_driver *e1inp_driver_find(const char *name);
192
193/* register a line with the E1 core */
194int e1inp_line_register(struct e1inp_line *line);
195
196/* get a line by its ID */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200197struct e1inp_line *e1inp_line_find(uint8_t e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200198
199/* create a line in the E1 input core */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200200struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
201
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200202/* clone one existing E1 input line */
203struct e1inp_line *e1inp_line_clone(void *ctx, struct e1inp_line *line);
204
205/* increment refcount use of E1 input line */
206void e1inp_line_get(struct e1inp_line *line);
207
208/* decrement refcount use of E1 input line, release if unused */
209void e1inp_line_put(struct e1inp_line *line);
210
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200211/* bind operations to one E1 input line */
212void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200213
214/* find a sign_link for given TEI and SAPI in a TS */
215struct e1inp_sign_link *
216e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
217 uint8_t sapi);
218
219/* create a new signalling link in a E1 timeslot */
220struct e1inp_sign_link *
221e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
222 struct gsm_bts_trx *trx, uint8_t tei,
223 uint8_t sapi);
224
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200225/* configure and initialize one signalling e1inp_ts */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200226int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line);
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200227
228/* configure and initialize one timeslot dedicated to TRAU frames. */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200229int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line,
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200230 int (*trau_rcv_cb)(struct subch_demux *dmx, int ch,
231 uint8_t *data, int len, void *_priv));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200232
233/* Call from the Stack: configuration of this TS has changed */
234int e1inp_update_ts(struct e1inp_ts *ts);
235
236/* Receive a packet from the E1 driver */
237int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
238 uint8_t tei, uint8_t sapi);
Harald Weltefd44a5f2011-08-21 00:48:54 +0200239int e1inp_rx_ts_lapd(struct e1inp_ts *e1i_ts, struct msgb *msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200240
241/* called by driver if it wants to transmit on a given TS */
242struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
243 struct e1inp_sign_link **sign_link);
244
245/* called by driver in case some kind of link state event */
246int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
247
Andreas Eversberga7ff0012011-09-26 11:29:30 +0200248/* L2->L3 */
249void e1inp_dlsap_up(struct osmo_dlsap_prim *odp, uint8_t tei, uint8_t sapi,
250 void *rx_cbdata);
251
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200252/* Write LAPD frames to the fd. */
253void e1_set_pcap_fd(int fd);
254
255/* called by TRAU muxer to obtain the destination mux entity */
256struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
257
258void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200259int e1inp_line_update(struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200260
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200261int e1inp_vty_init(void);
262
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200263struct gsm_network;
264int ipaccess_setup(struct gsm_network *gsmnet);
265int hsl_setup(struct gsm_network *gsmnet);
266
267extern struct llist_head e1inp_driver_list;
268extern struct llist_head e1inp_line_list;
269
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200270/* XXX */
271struct input_signal_data {
272 int link_type;
273 uint8_t tei;
274 uint8_t sapi;
275 struct gsm_bts_trx *trx;
276 struct e1inp_line *line;
277};
278
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200279int abis_sendmsg(struct msgb *msg);
Holger Hans Peter Freyther180ce7e2012-02-03 20:06:15 +0100280int abis_rsl_sendmsg(struct msgb *msg);
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200281
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200282#endif /* _E1_INPUT_H */