blob: 8d2f7bc270e0b6514830561498c311277125a1ac [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;
103 } driver;
104};
105
106struct gsm_e1_subslot {
107 /* Number of E1 link */
108 uint8_t e1_nr;
109 /* Number of E1 TS inside E1 link */
110 uint8_t e1_ts;
111 /* Sub-slot within the E1 TS, 0xff if full TS */
112 uint8_t e1_ts_ss;
113};
114
115enum e1inp_line_role {
116 E1INP_LINE_R_NONE,
117 E1INP_LINE_R_BSC,
118 E1INP_LINE_R_BTS,
119 E1INP_LINE_R_MAX
120};
121
122struct e1inp_driver {
123 struct llist_head list;
124 const char *name;
125 int (*want_write)(struct e1inp_ts *ts);
Pablo Neira Ayusoc00ee732011-06-21 12:22:49 +0200126 int (*line_update)(struct e1inp_line *line, enum e1inp_line_role role, const char *addr);
Pablo Neira Ayusoadd3ec82011-07-05 14:45:46 +0200127 void (*close)(struct e1inp_sign_link *link);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200128 int default_delay;
129};
130
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200131struct e1inp_line_ops {
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200132 enum e1inp_line_role role;
133 char *addr;
Pablo Neira Ayusodfafe682011-07-02 14:32:32 +0200134 void *data;
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200135
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200136 struct e1inp_sign_link * (*sign_link_up)(void *unit_info, struct e1inp_line *line, enum e1inp_sign_type type);
137 void (*sign_link_down)(struct e1inp_line *line);
Pablo Neira Ayusodbd82fb2011-07-05 15:29:23 +0200138 int (*sign_link)(struct msgb *msg);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200139};
140
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200141struct e1inp_line {
142 struct llist_head list;
143 int refcnt;
144
145 unsigned int num;
146 const char *name;
Harald Weltef2737fc2011-08-16 14:30:10 +0200147 struct rate_ctr_group *rate_ctr;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200148
149 /* array of timestlots */
150 struct e1inp_ts ts[NUM_E1_TS];
151
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200152 const struct e1inp_line_ops *ops;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200153
154 struct e1inp_driver *driver;
155 void *driver_data;
156};
157
Harald Weltecc2241b2011-07-19 16:06:06 +0200158/* SS_L_INPUT signals */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200159enum signal_input {
Pablo Neira Ayusode668912011-08-16 17:26:23 +0200160 S_L_INP_NONE,
161 S_L_INP_TEI_UP,
162 S_L_INP_TEI_DN,
163 S_L_INP_TEI_UNKNOWN,
164 S_L_INP_LINE_INIT,
165 S_L_INP_LINE_ALARM,
166 S_L_INP_LINE_NOALARM,
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200167};
168
169/* register a driver with the E1 core */
170int e1inp_driver_register(struct e1inp_driver *drv);
171
172/* fine a previously registered driver */
173struct e1inp_driver *e1inp_driver_find(const char *name);
174
175/* register a line with the E1 core */
176int e1inp_line_register(struct e1inp_line *line);
177
178/* get a line by its ID */
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200179struct e1inp_line *e1inp_line_find(uint8_t e1_nr);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200180
181/* create a line in the E1 input core */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200182struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
183
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +0200184/* clone one existing E1 input line */
185struct e1inp_line *e1inp_line_clone(void *ctx, struct e1inp_line *line);
186
187/* increment refcount use of E1 input line */
188void e1inp_line_get(struct e1inp_line *line);
189
190/* decrement refcount use of E1 input line, release if unused */
191void e1inp_line_put(struct e1inp_line *line);
192
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200193/* bind operations to one E1 input line */
194void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200195
196/* find a sign_link for given TEI and SAPI in a TS */
197struct e1inp_sign_link *
198e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
199 uint8_t sapi);
200
201/* create a new signalling link in a E1 timeslot */
202struct e1inp_sign_link *
203e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
204 struct gsm_bts_trx *trx, uint8_t tei,
205 uint8_t sapi);
206
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200207/* configure and initialize one signalling e1inp_ts */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200208int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line);
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200209
210/* configure and initialize one timeslot dedicated to TRAU frames. */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200211int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line,
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200212 int (*trau_rcv_cb)(struct subch_demux *dmx, int ch,
213 uint8_t *data, int len, void *_priv));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200214
215/* Call from the Stack: configuration of this TS has changed */
216int e1inp_update_ts(struct e1inp_ts *ts);
217
218/* Receive a packet from the E1 driver */
219int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
220 uint8_t tei, uint8_t sapi);
221
222/* called by driver if it wants to transmit on a given TS */
223struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
224 struct e1inp_sign_link **sign_link);
225
226/* called by driver in case some kind of link state event */
227int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
228
229/* Write LAPD frames to the fd. */
230void e1_set_pcap_fd(int fd);
231
232/* called by TRAU muxer to obtain the destination mux entity */
233struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
234
235void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200236int e1inp_line_update(struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200237
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200238int e1inp_vty_init(void);
239
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200240struct gsm_network;
241int ipaccess_setup(struct gsm_network *gsmnet);
242int hsl_setup(struct gsm_network *gsmnet);
243
244extern struct llist_head e1inp_driver_list;
245extern struct llist_head e1inp_line_list;
246
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200247/* XXX */
248struct input_signal_data {
249 int link_type;
250 uint8_t tei;
251 uint8_t sapi;
252 struct gsm_bts_trx *trx;
253 struct e1inp_line *line;
254};
255
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200256int abis_sendmsg(struct msgb *msg);
257
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200258#endif /* _E1_INPUT_H */