blob: b30425478992b082503534ba4f4d8996cc6d2989 [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 Weltec2889512011-09-13 23:49:04 +0100160 unsigned int port_nr;
Harald Weltef2737fc2011-08-16 14:30:10 +0200161 struct rate_ctr_group *rate_ctr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200162
163 /* array of timestlots */
164 struct e1inp_ts ts[NUM_E1_TS];
Harald Weltec2889512011-09-13 23:49:04 +0100165 unsigned int num_ts;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200166
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200167 const struct e1inp_line_ops *ops;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200168
169 struct e1inp_driver *driver;
170 void *driver_data;
171};
172
Harald Weltecc2241b2011-07-19 16:06:06 +0200173/* SS_L_INPUT signals */
Pablo Neira Ayuso332a3572011-08-16 17:31:20 +0200174enum e1inp_signal_input {
Pablo Neira Ayusode668912011-08-16 17:26:23 +0200175 S_L_INP_NONE,
176 S_L_INP_TEI_UP,
177 S_L_INP_TEI_DN,
178 S_L_INP_TEI_UNKNOWN,
179 S_L_INP_LINE_INIT,
180 S_L_INP_LINE_ALARM,
181 S_L_INP_LINE_NOALARM,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200182};
183
184/* register a driver with the E1 core */
185int e1inp_driver_register(struct e1inp_driver *drv);
186
187/* fine a previously registered driver */
188struct e1inp_driver *e1inp_driver_find(const char *name);
189
190/* register a line with the E1 core */
191int e1inp_line_register(struct e1inp_line *line);
192
193/* get a line by its ID */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200194struct e1inp_line *e1inp_line_find(uint8_t e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200195
196/* create a line in the E1 input core */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200197struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
198
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200199/* clone one existing E1 input line */
200struct e1inp_line *e1inp_line_clone(void *ctx, struct e1inp_line *line);
201
202/* increment refcount use of E1 input line */
203void e1inp_line_get(struct e1inp_line *line);
204
205/* decrement refcount use of E1 input line, release if unused */
206void e1inp_line_put(struct e1inp_line *line);
207
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200208/* bind operations to one E1 input line */
209void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200210
211/* find a sign_link for given TEI and SAPI in a TS */
212struct e1inp_sign_link *
213e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
214 uint8_t sapi);
215
216/* create a new signalling link in a E1 timeslot */
217struct e1inp_sign_link *
218e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
219 struct gsm_bts_trx *trx, uint8_t tei,
220 uint8_t sapi);
221
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200222/* configure and initialize one signalling e1inp_ts */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200223int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line);
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200224
225/* configure and initialize one timeslot dedicated to TRAU frames. */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200226int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line,
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200227 int (*trau_rcv_cb)(struct subch_demux *dmx, int ch,
228 uint8_t *data, int len, void *_priv));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200229
230/* Call from the Stack: configuration of this TS has changed */
231int e1inp_update_ts(struct e1inp_ts *ts);
232
233/* Receive a packet from the E1 driver */
234int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
235 uint8_t tei, uint8_t sapi);
Harald Weltefd44a5f2011-08-21 00:48:54 +0200236int e1inp_rx_ts_lapd(struct e1inp_ts *e1i_ts, struct msgb *msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200237
238/* called by driver if it wants to transmit on a given TS */
239struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
240 struct e1inp_sign_link **sign_link);
241
242/* called by driver in case some kind of link state event */
243int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
244
245/* Write LAPD frames to the fd. */
246void e1_set_pcap_fd(int fd);
247
248/* called by TRAU muxer to obtain the destination mux entity */
249struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
250
251void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200252int e1inp_line_update(struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200253
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200254int e1inp_vty_init(void);
255
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200256struct gsm_network;
257int ipaccess_setup(struct gsm_network *gsmnet);
258int hsl_setup(struct gsm_network *gsmnet);
259
260extern struct llist_head e1inp_driver_list;
261extern struct llist_head e1inp_line_list;
262
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200263/* XXX */
264struct input_signal_data {
265 int link_type;
266 uint8_t tei;
267 uint8_t sapi;
268 struct gsm_bts_trx *trx;
269 struct e1inp_line *line;
270};
271
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200272int abis_sendmsg(struct msgb *msg);
273
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200274#endif /* _E1_INPUT_H */