blob: 757f3f2f464fb40e02210b5a6258050d8c57e0b0 [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
73 union {
74 struct {
75 /* list of all signalling links on this TS */
76 struct llist_head sign_links;
77 /* delay for the queue */
78 int delay;
79 /* timer when to dequeue next frame */
80 struct osmo_timer_list tx_timer;
81 } sign;
82 struct {
83 /* subchannel demuxer for frames from E1 */
84 struct subch_demux demux;
85 /* subchannel muxer for frames to E1 */
86 struct subch_mux mux;
87 } trau;
88 };
89 union {
90 struct {
91 /* mISDN driver has one fd for each ts */
92 struct osmo_fd fd;
93 } misdn;
94 struct {
95 /* ip.access driver has one fd for each ts */
96 struct osmo_fd fd;
97 } ipaccess;
98 struct {
99 /* DAHDI driver has one fd for each ts */
100 struct osmo_fd fd;
101 struct lapd_instance *lapd;
102 } dahdi;
Pablo Neira Ayuso7e0d0062011-08-19 11:36:15 +0200103 struct {
104 struct osmo_fd fd;
105 } rs232;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200106 } driver;
107};
108
109struct gsm_e1_subslot {
110 /* Number of E1 link */
111 uint8_t e1_nr;
112 /* Number of E1 TS inside E1 link */
113 uint8_t e1_ts;
114 /* Sub-slot within the E1 TS, 0xff if full TS */
115 uint8_t e1_ts_ss;
116};
117
118enum e1inp_line_role {
119 E1INP_LINE_R_NONE,
120 E1INP_LINE_R_BSC,
121 E1INP_LINE_R_BTS,
122 E1INP_LINE_R_MAX
123};
124
125struct e1inp_driver {
126 struct llist_head list;
127 const char *name;
128 int (*want_write)(struct e1inp_ts *ts);
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200129 int (*line_update)(struct e1inp_line *line);
Pablo Neira Ayusoadd3ec82011-07-05 14:45:46 +0200130 void (*close)(struct e1inp_sign_link *link);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200131 int default_delay;
132};
133
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200134struct e1inp_line_ops {
Pablo Neira Ayuso4e862cb2011-08-19 18:43:38 +0200135 union {
136 struct {
137 enum e1inp_line_role role; /* BSC or BTS mode. */
138 const char *addr; /* IP address .*/
139 void *dev; /* device parameters. */
140 } ipa;
141 struct {
142 const char *port; /* e.g. /dev/ttyUSB0 */
143 unsigned int delay;
144 } rs232;
145 } cfg;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200146
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200147 struct e1inp_sign_link * (*sign_link_up)(void *unit_info, struct e1inp_line *line, enum e1inp_sign_type type);
148 void (*sign_link_down)(struct e1inp_line *line);
Pablo Neira Ayusodbd82fb2011-07-05 15:29:23 +0200149 int (*sign_link)(struct msgb *msg);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200150};
151
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200152struct e1inp_line {
153 struct llist_head list;
154 int refcnt;
155
156 unsigned int num;
157 const char *name;
Harald Weltef2737fc2011-08-16 14:30:10 +0200158 struct rate_ctr_group *rate_ctr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200159
160 /* array of timestlots */
161 struct e1inp_ts ts[NUM_E1_TS];
162
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200163 const struct e1inp_line_ops *ops;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200164
165 struct e1inp_driver *driver;
166 void *driver_data;
167};
168
Harald Weltecc2241b2011-07-19 16:06:06 +0200169/* SS_L_INPUT signals */
Pablo Neira Ayuso332a3572011-08-16 17:31:20 +0200170enum e1inp_signal_input {
Pablo Neira Ayusode668912011-08-16 17:26:23 +0200171 S_L_INP_NONE,
172 S_L_INP_TEI_UP,
173 S_L_INP_TEI_DN,
174 S_L_INP_TEI_UNKNOWN,
175 S_L_INP_LINE_INIT,
176 S_L_INP_LINE_ALARM,
177 S_L_INP_LINE_NOALARM,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200178};
179
180/* register a driver with the E1 core */
181int e1inp_driver_register(struct e1inp_driver *drv);
182
183/* fine a previously registered driver */
184struct e1inp_driver *e1inp_driver_find(const char *name);
185
186/* register a line with the E1 core */
187int e1inp_line_register(struct e1inp_line *line);
188
189/* get a line by its ID */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200190struct e1inp_line *e1inp_line_find(uint8_t e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200191
192/* create a line in the E1 input core */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200193struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
194
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200195/* clone one existing E1 input line */
196struct e1inp_line *e1inp_line_clone(void *ctx, struct e1inp_line *line);
197
198/* increment refcount use of E1 input line */
199void e1inp_line_get(struct e1inp_line *line);
200
201/* decrement refcount use of E1 input line, release if unused */
202void e1inp_line_put(struct e1inp_line *line);
203
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200204/* bind operations to one E1 input line */
205void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200206
207/* find a sign_link for given TEI and SAPI in a TS */
208struct e1inp_sign_link *
209e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
210 uint8_t sapi);
211
212/* create a new signalling link in a E1 timeslot */
213struct e1inp_sign_link *
214e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
215 struct gsm_bts_trx *trx, uint8_t tei,
216 uint8_t sapi);
217
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200218/* configure and initialize one signalling e1inp_ts */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200219int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line);
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200220
221/* configure and initialize one timeslot dedicated to TRAU frames. */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200222int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line,
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200223 int (*trau_rcv_cb)(struct subch_demux *dmx, int ch,
224 uint8_t *data, int len, void *_priv));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200225
226/* Call from the Stack: configuration of this TS has changed */
227int e1inp_update_ts(struct e1inp_ts *ts);
228
229/* Receive a packet from the E1 driver */
230int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
231 uint8_t tei, uint8_t sapi);
232
233/* called by driver if it wants to transmit on a given TS */
234struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
235 struct e1inp_sign_link **sign_link);
236
237/* called by driver in case some kind of link state event */
238int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
239
240/* Write LAPD frames to the fd. */
241void e1_set_pcap_fd(int fd);
242
243/* called by TRAU muxer to obtain the destination mux entity */
244struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
245
246void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200247int e1inp_line_update(struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200248
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200249int e1inp_vty_init(void);
250
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200251struct gsm_network;
252int ipaccess_setup(struct gsm_network *gsmnet);
253int hsl_setup(struct gsm_network *gsmnet);
254
255extern struct llist_head e1inp_driver_list;
256extern struct llist_head e1inp_line_list;
257
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200258/* XXX */
259struct input_signal_data {
260 int link_type;
261 uint8_t tei;
262 uint8_t sapi;
263 struct gsm_bts_trx *trx;
264 struct e1inp_line *line;
265};
266
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200267int abis_sendmsg(struct msgb *msg);
268
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200269#endif /* _E1_INPUT_H */