blob: f201c4fb1af9dd2328f0c4d3e19557197cdecfb4 [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
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +01007#include <osmocom/core/linuxlist.h>
Harald Welte1fa60c82009-02-09 18:13:26 +00008#include <openbsc/gsm_data.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +01009#include <osmocom/core/msgb.h>
10#include <osmocom/core/select.h>
Harald Welte0000ca52011-08-11 12:50:13 +020011#include <osmocom/core/rate_ctr.h>
Harald Welte1fa60c82009-02-09 18:13:26 +000012#include <openbsc/subchan_demux.h>
13
14#define NUM_E1_TS 32
15
16enum e1inp_sign_type {
17 E1INP_SIGN_NONE,
18 E1INP_SIGN_OML,
19 E1INP_SIGN_RSL,
20};
Harald Welted256d4f2009-03-10 19:44:48 +000021const char *e1inp_signtype_name(enum e1inp_sign_type tp);
Harald Welte1fa60c82009-02-09 18:13:26 +000022
Harald Welte0000ca52011-08-11 12:50:13 +020023enum e1inp_ctr {
24 E1I_CTR_HDLC_ABORT,
25 E1I_CTR_HDLC_BADFCS,
26 E1I_CTR_HDLC_OVERR,
27 E1I_CTR_ALARM,
28 E1I_CTR_REMOVED,
29};
30
Harald Welte1fa60c82009-02-09 18:13:26 +000031struct e1inp_ts;
32
33struct e1inp_sign_link {
34 /* list of signalling links */
35 struct llist_head list;
36
37 /* to which timeslot do we belong? */
38 struct e1inp_ts *ts;
39
40 enum e1inp_sign_type type;
41
42 /* trx for msg->trx of received msgs */
43 struct gsm_bts_trx *trx;
44
45 /* msgb queue of to-be-transmitted msgs */
46 struct llist_head tx_list;
47
48 /* SAPI and TEI on the E1 TS */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020049 uint8_t sapi;
50 uint8_t tei;
Harald Welte1fa60c82009-02-09 18:13:26 +000051
52 union {
53 struct {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020054 uint8_t channel;
Harald Welte1fa60c82009-02-09 18:13:26 +000055 } misdn;
56 } driver;
57};
58
59enum e1inp_ts_type {
60 E1INP_TS_TYPE_NONE,
61 E1INP_TS_TYPE_SIGN,
62 E1INP_TS_TYPE_TRAU,
63};
Harald Welted256d4f2009-03-10 19:44:48 +000064const char *e1inp_tstype_name(enum e1inp_ts_type tp);
Harald Welte1fa60c82009-02-09 18:13:26 +000065
66/* A timeslot in the E1 interface */
67struct e1inp_ts {
68 enum e1inp_ts_type type;
69 int num;
70
71 /* to which line do we belong ? */
72 struct e1inp_line *line;
73
74 union {
75 struct {
Harald Weltef55b49f2009-05-23 06:20:41 +000076 /* list of all signalling links on this TS */
Harald Welte1fa60c82009-02-09 18:13:26 +000077 struct llist_head sign_links;
Holger Hans Peter Freytherd85642a2010-04-26 16:02:04 +080078 /* delay for the queue */
79 int delay;
Harald Weltef55b49f2009-05-23 06:20:41 +000080 /* timer when to dequeue next frame */
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020081 struct osmo_timer_list tx_timer;
Harald Welte1fa60c82009-02-09 18:13:26 +000082 } sign;
83 struct {
84 /* subchannel demuxer for frames from E1 */
85 struct subch_demux demux;
86 /* subchannel muxer for frames to E1 */
87 struct subch_mux mux;
88 } trau;
89 };
90 union {
91 struct {
92 /* mISDN driver has one fd for each ts */
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +020093 struct osmo_fd fd;
Harald Welte1fa60c82009-02-09 18:13:26 +000094 } misdn;
Harald Welte5fd8a542009-02-13 02:43:36 +000095 struct {
96 /* ip.access driver has one fd for each ts */
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +020097 struct osmo_fd fd;
Harald Welte5fd8a542009-02-13 02:43:36 +000098 } ipaccess;
Harald Welted38f1052011-02-05 19:13:00 +010099 struct {
100 /* DAHDI driver has one fd for each ts */
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200101 struct osmo_fd fd;
Harald Welted38f1052011-02-05 19:13:00 +0100102 struct lapd_instance *lapd;
103 } dahdi;
Harald Welte1fa60c82009-02-09 18:13:26 +0000104 } driver;
105};
106
107struct e1inp_driver {
108 struct llist_head list;
109 const char *name;
110 int (*want_write)(struct e1inp_ts *ts);
Harald Welte54552432011-02-05 12:26:55 +0100111 int (*line_update)(struct e1inp_line *line);
Holger Hans Peter Freytherd85642a2010-04-26 16:02:04 +0800112 int default_delay;
Harald Welte1fa60c82009-02-09 18:13:26 +0000113};
114
115struct e1inp_line {
116 struct llist_head list;
117 unsigned int num;
118 const char *name;
Harald Welte0000ca52011-08-11 12:50:13 +0200119 struct rate_ctr_group *rate_ctr;
Harald Welte1fa60c82009-02-09 18:13:26 +0000120
121 /* array of timestlots */
122 struct e1inp_ts ts[NUM_E1_TS];
123
124 struct e1inp_driver *driver;
125 void *driver_data;
126};
127
128/* register a driver with the E1 core */
129int e1inp_driver_register(struct e1inp_driver *drv);
130
Harald Welte3016d9f2011-02-05 13:54:41 +0100131/* fine a previously registered driver */
132struct e1inp_driver *e1inp_driver_find(const char *name);
133
Harald Welte1fa60c82009-02-09 18:13:26 +0000134/* register a line with the E1 core */
135int e1inp_line_register(struct e1inp_line *line);
136
Harald Welte3016d9f2011-02-05 13:54:41 +0100137/* get a line by its ID */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200138struct e1inp_line *e1inp_line_get(uint8_t e1_nr);
Harald Welte3016d9f2011-02-05 13:54:41 +0100139
140/* create a line in the E1 input core */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200141struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
Harald Welte42581822009-08-08 16:12:58 +0200142
Harald Welte1fa60c82009-02-09 18:13:26 +0000143/* find a sign_link for given TEI and SAPI in a TS */
144struct e1inp_sign_link *
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200145e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
146 uint8_t sapi);
Harald Welte1fa60c82009-02-09 18:13:26 +0000147
148/* create a new signalling link in a E1 timeslot */
149struct e1inp_sign_link *
150e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200151 struct gsm_bts_trx *trx, uint8_t tei,
152 uint8_t sapi);
Harald Welte1fa60c82009-02-09 18:13:26 +0000153
154/* configure and initialize one e1inp_ts */
155int e1inp_ts_config(struct e1inp_ts *ts, struct e1inp_line *line,
156 enum e1inp_ts_type type);
157
158/* Call from the Stack: configuration of this TS has changed */
159int e1inp_update_ts(struct e1inp_ts *ts);
160
161/* Receive a packet from the E1 driver */
162int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200163 uint8_t tei, uint8_t sapi);
Harald Welte1fa60c82009-02-09 18:13:26 +0000164
165/* called by driver if it wants to transmit on a given TS */
166struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
167 struct e1inp_sign_link **sign_link);
168
169/* called by driver in case some kind of link state event */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200170int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
Harald Welte1fa60c82009-02-09 18:13:26 +0000171
Holger Freyther0469cf62009-03-31 12:14:16 +0000172/* Write LAPD frames to the fd. */
173void e1_set_pcap_fd(int fd);
174
Harald Welte1fa60c82009-02-09 18:13:26 +0000175/* called by TRAU muxer to obtain the destination mux entity */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200176struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
Harald Welte1fa60c82009-02-09 18:13:26 +0000177
Holger Hans Peter Freyther34e97492009-08-10 07:54:02 +0200178void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
179int e1inp_line_update(struct e1inp_line *line);
Harald Welte42581822009-08-08 16:12:58 +0200180
Holger Freytherff9592f2009-03-09 16:17:14 +0000181/* e1_config.c */
Harald Welte42581822009-08-08 16:12:58 +0200182int e1_reconfig_ts(struct gsm_bts_trx_ts *ts);
183int e1_reconfig_trx(struct gsm_bts_trx *trx);
184int e1_reconfig_bts(struct gsm_bts *bts);
185
Harald Welte25de9912009-04-30 15:53:07 +0000186int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin);
Harald Welteedb37782009-05-01 14:59:07 +0000187int ipaccess_setup(struct gsm_network *gsmnet);
Pablo Neira Ayuso0d2881a2011-05-14 11:32:48 +0200188int hsl_setup(struct gsm_network *gsmnet);
Holger Freytherff9592f2009-03-09 16:17:14 +0000189
Harald Welte75727452009-05-23 05:26:29 +0000190extern struct llist_head e1inp_driver_list;
191extern struct llist_head e1inp_line_list;
Holger Freytherff9592f2009-03-09 16:17:14 +0000192
Harald Welte3016d9f2011-02-05 13:54:41 +0100193int e1inp_vty_init(void);
194void e1inp_init(void);
195
Harald Welted88a3872011-02-14 15:26:13 +0100196int _abis_nm_sendmsg(struct msgb *msg, int to_trx_oml);
197
Harald Welte1fa60c82009-02-09 18:13:26 +0000198#endif /* _E1_INPUT_H */