blob: 42b17587ff48ee69c296fac9fae3dc247a615824 [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>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020012
13#define NUM_E1_TS 32
14
15enum e1inp_sign_type {
16 E1INP_SIGN_NONE,
17 E1INP_SIGN_OML,
18 E1INP_SIGN_RSL,
19};
20const char *e1inp_signtype_name(enum e1inp_sign_type tp);
21
Harald Weltef2737fc2011-08-16 14:30:10 +020022enum e1inp_ctr {
23 E1I_CTR_HDLC_ABORT,
24 E1I_CTR_HDLC_BADFCS,
25 E1I_CTR_HDLC_OVERR,
26 E1I_CTR_ALARM,
27 E1I_CTR_REMOVED,
28};
29
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020030struct e1inp_ts;
31
32struct e1inp_sign_link {
33 /* list of signalling links */
34 struct llist_head list;
35
36 /* to which timeslot do we belong? */
37 struct e1inp_ts *ts;
38
39 enum e1inp_sign_type type;
40
41 /* trx for msg->trx of received msgs */
42 struct gsm_bts_trx *trx;
43
44 /* msgb queue of to-be-transmitted msgs */
45 struct llist_head tx_list;
46
47 /* SAPI and TEI on the E1 TS */
48 uint8_t sapi;
49 uint8_t tei;
50
51 union {
52 struct {
53 uint8_t channel;
54 } misdn;
55 } driver;
56};
57
58enum e1inp_ts_type {
59 E1INP_TS_TYPE_NONE,
60 E1INP_TS_TYPE_SIGN,
61 E1INP_TS_TYPE_TRAU,
62};
63const char *e1inp_tstype_name(enum e1inp_ts_type tp);
64
65/* A timeslot in the E1 interface */
66struct e1inp_ts {
67 enum e1inp_ts_type type;
68 int num;
69
70 /* to which line do we belong ? */
71 struct e1inp_line *line;
72
Harald Weltefd44a5f2011-08-21 00:48:54 +020073 /* LAPD instance, if any */
74 struct lapd_instance *lapd;
75
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020076 union {
77 struct {
78 /* list of all signalling links on this TS */
79 struct llist_head sign_links;
80 /* delay for the queue */
81 int delay;
82 /* timer when to dequeue next frame */
83 struct osmo_timer_list tx_timer;
84 } sign;
85 struct {
86 /* subchannel demuxer for frames from E1 */
87 struct subch_demux demux;
88 /* subchannel muxer for frames to E1 */
89 struct subch_mux mux;
90 } trau;
91 };
92 union {
93 struct {
94 /* mISDN driver has one fd for each ts */
95 struct osmo_fd fd;
96 } misdn;
97 struct {
98 /* ip.access driver has one fd for each ts */
99 struct osmo_fd fd;
100 } ipaccess;
101 struct {
102 /* DAHDI driver has one fd for each ts */
103 struct osmo_fd fd;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200104 } dahdi;
Pablo Neira Ayuso7e0d0062011-08-19 11:36:15 +0200105 struct {
106 struct osmo_fd fd;
107 } rs232;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200108 } driver;
109};
110
111struct gsm_e1_subslot {
112 /* Number of E1 link */
113 uint8_t e1_nr;
114 /* Number of E1 TS inside E1 link */
115 uint8_t e1_ts;
116 /* Sub-slot within the E1 TS, 0xff if full TS */
117 uint8_t e1_ts_ss;
118};
119
120enum e1inp_line_role {
121 E1INP_LINE_R_NONE,
122 E1INP_LINE_R_BSC,
123 E1INP_LINE_R_BTS,
124 E1INP_LINE_R_MAX
125};
126
127struct e1inp_driver {
128 struct llist_head list;
129 const char *name;
130 int (*want_write)(struct e1inp_ts *ts);
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200131 int (*line_update)(struct e1inp_line *line);
Pablo Neira Ayusoadd3ec82011-07-05 14:45:46 +0200132 void (*close)(struct e1inp_sign_link *link);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200133 int default_delay;
134};
135
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200136struct e1inp_line_ops {
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200137 union {
138 struct {
139 enum e1inp_line_role role; /* BSC or BTS mode. */
140 const char *addr; /* IP address .*/
141 void *dev; /* device parameters. */
142 } ipa;
143 struct {
144 const char *port; /* e.g. /dev/ttyUSB0 */
145 unsigned int delay;
146 } rs232;
147 } cfg;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200148
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200149 struct e1inp_sign_link * (*sign_link_up)(void *unit_info, struct e1inp_line *line, enum e1inp_sign_type type);
150 void (*sign_link_down)(struct e1inp_line *line);
Pablo Neira Ayusodbd82fb2011-07-05 15:29:23 +0200151 int (*sign_link)(struct msgb *msg);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200152};
153
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200154struct e1inp_line {
155 struct llist_head list;
156 int refcnt;
157
158 unsigned int num;
159 const char *name;
Harald Weltef2737fc2011-08-16 14:30:10 +0200160 struct rate_ctr_group *rate_ctr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200161
162 /* array of timestlots */
163 struct e1inp_ts ts[NUM_E1_TS];
164
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200165 const struct e1inp_line_ops *ops;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200166
167 struct e1inp_driver *driver;
168 void *driver_data;
169};
170
Harald Weltecc2241b2011-07-19 16:06:06 +0200171/* SS_L_INPUT signals */
Pablo Neira Ayuso332a3572011-08-16 17:31:20 +0200172enum e1inp_signal_input {
Pablo Neira Ayusode668912011-08-16 17:26:23 +0200173 S_L_INP_NONE,
174 S_L_INP_TEI_UP,
175 S_L_INP_TEI_DN,
176 S_L_INP_TEI_UNKNOWN,
177 S_L_INP_LINE_INIT,
178 S_L_INP_LINE_ALARM,
179 S_L_INP_LINE_NOALARM,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200180};
181
182/* register a driver with the E1 core */
183int e1inp_driver_register(struct e1inp_driver *drv);
184
185/* fine a previously registered driver */
186struct e1inp_driver *e1inp_driver_find(const char *name);
187
188/* register a line with the E1 core */
189int e1inp_line_register(struct e1inp_line *line);
190
191/* get a line by its ID */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200192struct e1inp_line *e1inp_line_find(uint8_t e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200193
194/* create a line in the E1 input core */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200195struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
196
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200197/* clone one existing E1 input line */
198struct e1inp_line *e1inp_line_clone(void *ctx, struct e1inp_line *line);
199
200/* increment refcount use of E1 input line */
201void e1inp_line_get(struct e1inp_line *line);
202
203/* decrement refcount use of E1 input line, release if unused */
204void e1inp_line_put(struct e1inp_line *line);
205
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200206/* bind operations to one E1 input line */
207void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200208
209/* find a sign_link for given TEI and SAPI in a TS */
210struct e1inp_sign_link *
211e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
212 uint8_t sapi);
213
214/* create a new signalling link in a E1 timeslot */
215struct e1inp_sign_link *
216e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
217 struct gsm_bts_trx *trx, uint8_t tei,
218 uint8_t sapi);
219
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200220/* configure and initialize one signalling e1inp_ts */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200221int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line);
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200222
223/* configure and initialize one timeslot dedicated to TRAU frames. */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200224int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line,
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200225 int (*trau_rcv_cb)(struct subch_demux *dmx, int ch,
226 uint8_t *data, int len, void *_priv));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200227
228/* Call from the Stack: configuration of this TS has changed */
229int e1inp_update_ts(struct e1inp_ts *ts);
230
231/* Receive a packet from the E1 driver */
232int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
233 uint8_t tei, uint8_t sapi);
Harald Weltefd44a5f2011-08-21 00:48:54 +0200234int e1inp_rx_ts_lapd(struct e1inp_ts *e1i_ts, struct msgb *msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200235
236/* called by driver if it wants to transmit on a given TS */
237struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
238 struct e1inp_sign_link **sign_link);
239
240/* called by driver in case some kind of link state event */
241int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
242
243/* Write LAPD frames to the fd. */
244void e1_set_pcap_fd(int fd);
245
246/* called by TRAU muxer to obtain the destination mux entity */
247struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
248
249void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200250int e1inp_line_update(struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200251
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200252int e1inp_vty_init(void);
253
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200254struct gsm_network;
255int ipaccess_setup(struct gsm_network *gsmnet);
256int hsl_setup(struct gsm_network *gsmnet);
257
258extern struct llist_head e1inp_driver_list;
259extern struct llist_head e1inp_line_list;
260
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200261/* XXX */
262struct input_signal_data {
263 int link_type;
264 uint8_t tei;
265 uint8_t sapi;
266 struct gsm_bts_trx *trx;
267 struct e1inp_line *line;
268};
269
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200270int abis_sendmsg(struct msgb *msg);
271
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200272#endif /* _E1_INPUT_H */