blob: d2033ef51da191657e3952005cbd80cd74d189b9 [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
22struct e1inp_ts;
23
24struct e1inp_sign_link {
25 /* list of signalling links */
26 struct llist_head list;
27
28 /* to which timeslot do we belong? */
29 struct e1inp_ts *ts;
30
31 enum e1inp_sign_type type;
32
33 /* trx for msg->trx of received msgs */
34 struct gsm_bts_trx *trx;
35
36 /* msgb queue of to-be-transmitted msgs */
37 struct llist_head tx_list;
38
39 /* SAPI and TEI on the E1 TS */
40 uint8_t sapi;
41 uint8_t tei;
42
43 union {
44 struct {
45 uint8_t channel;
46 } misdn;
47 } driver;
48};
49
50enum e1inp_ts_type {
51 E1INP_TS_TYPE_NONE,
52 E1INP_TS_TYPE_SIGN,
53 E1INP_TS_TYPE_TRAU,
54};
55const char *e1inp_tstype_name(enum e1inp_ts_type tp);
56
57/* A timeslot in the E1 interface */
58struct e1inp_ts {
59 enum e1inp_ts_type type;
60 int num;
61
62 /* to which line do we belong ? */
63 struct e1inp_line *line;
64
65 union {
66 struct {
67 /* list of all signalling links on this TS */
68 struct llist_head sign_links;
69 /* delay for the queue */
70 int delay;
71 /* timer when to dequeue next frame */
72 struct osmo_timer_list tx_timer;
73 } sign;
74 struct {
75 /* subchannel demuxer for frames from E1 */
76 struct subch_demux demux;
77 /* subchannel muxer for frames to E1 */
78 struct subch_mux mux;
79 } trau;
80 };
81 union {
82 struct {
83 /* mISDN driver has one fd for each ts */
84 struct osmo_fd fd;
85 } misdn;
86 struct {
87 /* ip.access driver has one fd for each ts */
88 struct osmo_fd fd;
89 } ipaccess;
90 struct {
91 /* DAHDI driver has one fd for each ts */
92 struct osmo_fd fd;
93 struct lapd_instance *lapd;
94 } dahdi;
95 } driver;
96};
97
98struct gsm_e1_subslot {
99 /* Number of E1 link */
100 uint8_t e1_nr;
101 /* Number of E1 TS inside E1 link */
102 uint8_t e1_ts;
103 /* Sub-slot within the E1 TS, 0xff if full TS */
104 uint8_t e1_ts_ss;
105};
106
107enum e1inp_line_role {
108 E1INP_LINE_R_NONE,
109 E1INP_LINE_R_BSC,
110 E1INP_LINE_R_BTS,
111 E1INP_LINE_R_MAX
112};
113
114struct e1inp_driver {
115 struct llist_head list;
116 const char *name;
117 int (*want_write)(struct e1inp_ts *ts);
Pablo Neira Ayusoc00ee732011-06-21 12:22:49 +0200118 int (*line_update)(struct e1inp_line *line, enum e1inp_line_role role, const char *addr);
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200119 void (*close)(struct e1inp_ts *ts);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200120 int default_delay;
121};
122
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200123struct e1inp_line_ops {
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200124 enum e1inp_line_role role;
125 char *addr;
126
Pablo Neira Ayusoc9c4fd32011-06-30 12:19:42 +0200127 struct e1inp_sign_link * (*sign_link_up)(void *unit_info, struct e1inp_line *line, enum e1inp_sign_type type);
128 void (*sign_link_down)(struct e1inp_line *line);
129 int (*sign_link)(struct msgb *msg, struct e1inp_sign_link *link);
Pablo Neira Ayuso5a4b7c52011-06-07 14:07:48 +0200130};
131
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200132struct e1inp_line {
133 struct llist_head list;
134 int refcnt;
135
136 unsigned int num;
137 const char *name;
138
139 /* array of timestlots */
140 struct e1inp_ts ts[NUM_E1_TS];
141
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200142 const struct e1inp_line_ops *ops;
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200143
144 struct e1inp_driver *driver;
145 void *driver_data;
146};
147
148/* SS_INPUT signals */
149enum signal_input {
150 S_INP_NONE,
151 S_INP_TEI_UP,
152 S_INP_TEI_DN,
153 S_INP_LINE_INIT,
154 S_INP_LINE_ALARM,
155 S_INP_LINE_NOALARM,
156};
157
158/* register a driver with the E1 core */
159int e1inp_driver_register(struct e1inp_driver *drv);
160
161/* fine a previously registered driver */
162struct e1inp_driver *e1inp_driver_find(const char *name);
163
164/* register a line with the E1 core */
165int e1inp_line_register(struct e1inp_line *line);
166
167/* get a line by its ID */
168struct e1inp_line *e1inp_line_get(uint8_t e1_nr);
169
170/* create a line in the E1 input core */
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200171struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
172
173/* bind operations to one E1 input line */
174void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200175
176/* find a sign_link for given TEI and SAPI in a TS */
177struct e1inp_sign_link *
178e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
179 uint8_t sapi);
180
181/* create a new signalling link in a E1 timeslot */
182struct e1inp_sign_link *
183e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
184 struct gsm_bts_trx *trx, uint8_t tei,
185 uint8_t sapi);
186
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200187/* configure and initialize one signalling e1inp_ts */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200188int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line);
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200189
190/* configure and initialize one timeslot dedicated to TRAU frames. */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200191int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line,
Pablo Neira Ayuso211d2ca2011-06-07 17:15:10 +0200192 int (*trau_rcv_cb)(struct subch_demux *dmx, int ch,
193 uint8_t *data, int len, void *_priv));
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200194
195/* Call from the Stack: configuration of this TS has changed */
196int e1inp_update_ts(struct e1inp_ts *ts);
197
198/* Receive a packet from the E1 driver */
199int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
200 uint8_t tei, uint8_t sapi);
201
202/* called by driver if it wants to transmit on a given TS */
203struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
204 struct e1inp_sign_link **sign_link);
205
206/* called by driver in case some kind of link state event */
207int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
208
209/* Write LAPD frames to the fd. */
210void e1_set_pcap_fd(int fd);
211
212/* called by TRAU muxer to obtain the destination mux entity */
213struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
214
215void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
Pablo Neira Ayusof163d232011-06-25 18:42:55 +0200216int e1inp_line_update(struct e1inp_line *line);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200217
218struct gsm_network;
219int ipaccess_setup(struct gsm_network *gsmnet);
220int hsl_setup(struct gsm_network *gsmnet);
221
222extern struct llist_head e1inp_driver_list;
223extern struct llist_head e1inp_line_list;
224
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200225/* XXX */
226struct input_signal_data {
227 int link_type;
228 uint8_t tei;
229 uint8_t sapi;
230 struct gsm_bts_trx *trx;
231 struct e1inp_line *line;
232};
233
Pablo Neira Ayuso96e72632011-06-26 19:08:05 +0200234int abis_sendmsg(struct msgb *msg);
235
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +0200236#endif /* _E1_INPUT_H */