blob: aa4aa392fc7dc6c27db22ae7e46516b1f304bf28 [file] [log] [blame]
Harald Welte1fa60c82009-02-09 18:13:26 +00001#ifndef _E1_INPUT_H
2#define _E1_INPUT_H
3
4#include <stdlib.h>
Harald Welte25de9912009-04-30 15:53:07 +00005#include <netinet/in.h>
Harald Welte1fa60c82009-02-09 18:13:26 +00006
Harald Weltedfe6c7d2010-02-20 16:24:02 +01007#include <osmocore/linuxlist.h>
Harald Welte1fa60c82009-02-09 18:13:26 +00008#include <openbsc/gsm_data.h>
Harald Weltedfe6c7d2010-02-20 16:24:02 +01009#include <osmocore/msgb.h>
10#include <osmocore/select.h>
Harald Welte1fa60c82009-02-09 18:13:26 +000011#include <openbsc/subchan_demux.h>
12
13#define NUM_E1_TS 32
14
15enum e1inp_sign_type {
16 E1INP_SIGN_NONE,
17 E1INP_SIGN_OML,
18 E1INP_SIGN_RSL,
19};
Harald Welted256d4f2009-03-10 19:44:48 +000020const char *e1inp_signtype_name(enum e1inp_sign_type tp);
Harald Welte1fa60c82009-02-09 18:13:26 +000021
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 u_int8_t sapi;
41 u_int8_t tei;
42
43 union {
44 struct {
45 u_int8_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};
Harald Welted256d4f2009-03-10 19:44:48 +000055const char *e1inp_tstype_name(enum e1inp_ts_type tp);
Harald Welte1fa60c82009-02-09 18:13:26 +000056
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 {
Harald Weltef55b49f2009-05-23 06:20:41 +000067 /* list of all signalling links on this TS */
Harald Welte1fa60c82009-02-09 18:13:26 +000068 struct llist_head sign_links;
Holger Hans Peter Freytherd85642a2010-04-26 16:02:04 +080069 /* delay for the queue */
70 int delay;
Harald Weltef55b49f2009-05-23 06:20:41 +000071 /* timer when to dequeue next frame */
72 struct timer_list tx_timer;
Harald Welte1fa60c82009-02-09 18:13:26 +000073 } 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 bsc_fd fd;
85 } misdn;
Harald Welte5fd8a542009-02-13 02:43:36 +000086 struct {
87 /* ip.access driver has one fd for each ts */
88 struct bsc_fd fd;
89 } ipaccess;
90
Harald Welte1fa60c82009-02-09 18:13:26 +000091 } driver;
92};
93
94struct e1inp_driver {
95 struct llist_head list;
96 const char *name;
97 int (*want_write)(struct e1inp_ts *ts);
Holger Hans Peter Freytherd85642a2010-04-26 16:02:04 +080098 int default_delay;
Harald Welte1fa60c82009-02-09 18:13:26 +000099};
100
101struct e1inp_line {
102 struct llist_head list;
103 unsigned int num;
104 const char *name;
105
106 /* array of timestlots */
107 struct e1inp_ts ts[NUM_E1_TS];
108
109 struct e1inp_driver *driver;
110 void *driver_data;
111};
112
113/* register a driver with the E1 core */
114int e1inp_driver_register(struct e1inp_driver *drv);
115
116/* register a line with the E1 core */
117int e1inp_line_register(struct e1inp_line *line);
118
Harald Welte42581822009-08-08 16:12:58 +0200119/* ensure a certain line exists, return pointer to it */
120struct e1inp_line *e1inp_line_get_create(u_int8_t e1_nr);
121
Harald Welte1fa60c82009-02-09 18:13:26 +0000122/* find a sign_link for given TEI and SAPI in a TS */
123struct e1inp_sign_link *
124e1inp_lookup_sign_link(struct e1inp_ts *ts, u_int8_t tei,
125 u_int8_t sapi);
126
127/* create a new signalling link in a E1 timeslot */
128struct e1inp_sign_link *
129e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
130 struct gsm_bts_trx *trx, u_int8_t tei,
131 u_int8_t sapi);
132
133/* configure and initialize one e1inp_ts */
134int e1inp_ts_config(struct e1inp_ts *ts, struct e1inp_line *line,
135 enum e1inp_ts_type type);
136
137/* Call from the Stack: configuration of this TS has changed */
138int e1inp_update_ts(struct e1inp_ts *ts);
139
140/* Receive a packet from the E1 driver */
141int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
142 u_int8_t tei, u_int8_t sapi);
143
144/* called by driver if it wants to transmit on a given TS */
145struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
146 struct e1inp_sign_link **sign_link);
147
148/* called by driver in case some kind of link state event */
149int e1inp_event(struct e1inp_ts *ts, int evt, u_int8_t tei, u_int8_t sapi);
150
Holger Freyther0469cf62009-03-31 12:14:16 +0000151/* Write LAPD frames to the fd. */
152void e1_set_pcap_fd(int fd);
153
Harald Welte1fa60c82009-02-09 18:13:26 +0000154/* called by TRAU muxer to obtain the destination mux entity */
155struct subch_mux *e1inp_get_mux(u_int8_t e1_nr, u_int8_t ts_nr);
156
Holger Hans Peter Freyther34e97492009-08-10 07:54:02 +0200157void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
158int e1inp_line_update(struct e1inp_line *line);
Harald Welte42581822009-08-08 16:12:58 +0200159
Holger Freytherff9592f2009-03-09 16:17:14 +0000160/* e1_config.c */
Harald Welte42581822009-08-08 16:12:58 +0200161int e1_reconfig_ts(struct gsm_bts_trx_ts *ts);
162int e1_reconfig_trx(struct gsm_bts_trx *trx);
163int e1_reconfig_bts(struct gsm_bts *bts);
164
Harald Welte25de9912009-04-30 15:53:07 +0000165int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin);
Harald Welteedb37782009-05-01 14:59:07 +0000166int ipaccess_setup(struct gsm_network *gsmnet);
Holger Freytherff9592f2009-03-09 16:17:14 +0000167
Harald Welte75727452009-05-23 05:26:29 +0000168extern struct llist_head e1inp_driver_list;
169extern struct llist_head e1inp_line_list;
Holger Freytherff9592f2009-03-09 16:17:14 +0000170
Harald Welte1fa60c82009-02-09 18:13:26 +0000171#endif /* _E1_INPUT_H */