blob: 0d79c7d1eca8c8fa5d147c4e4490e187f9bd1263 [file] [log] [blame]
Jonathan Santos03fd8d02011-05-25 13:54:02 -04001#ifndef _E1_INPUT_H
2#define _E1_INPUT_H
3
4#include <stdlib.h>
5#include <netinet/in.h>
6
Jonathan Santos5a45b152011-08-17 15:33:57 -04007#include <osmocom/core/linuxlist.h>
Jonathan Santos03fd8d02011-05-25 13:54:02 -04008#include <openbsc/gsm_data.h>
Jonathan Santos5a45b152011-08-17 15:33:57 -04009#include <osmocom/core/msgb.h>
10#include <osmocom/core/select.h>
Jonathan Santos03fd8d02011-05-25 13:54:02 -040011#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};
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 */
Jonathan Santos5a45b152011-08-17 15:33:57 -040040 uint8_t sapi;
41 uint8_t tei;
Jonathan Santos03fd8d02011-05-25 13:54:02 -040042
43 union {
44 struct {
Jonathan Santos5a45b152011-08-17 15:33:57 -040045 uint8_t channel;
Jonathan Santos03fd8d02011-05-25 13:54:02 -040046 } 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 */
Jonathan Santos5a45b152011-08-17 15:33:57 -040072 struct osmo_timer_list tx_timer;
Jonathan Santos03fd8d02011-05-25 13:54:02 -040073 } 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 */
Jonathan Santos5a45b152011-08-17 15:33:57 -040084 struct osmo_fd fd;
Jonathan Santos03fd8d02011-05-25 13:54:02 -040085 } misdn;
86 struct {
87 /* ip.access driver has one fd for each ts */
Jonathan Santos5a45b152011-08-17 15:33:57 -040088 struct osmo_fd fd;
Jonathan Santos03fd8d02011-05-25 13:54:02 -040089 } ipaccess;
90 struct {
91 /* DAHDI driver has one fd for each ts */
Jonathan Santos5a45b152011-08-17 15:33:57 -040092 struct osmo_fd fd;
Jonathan Santos03fd8d02011-05-25 13:54:02 -040093 struct lapd_instance *lapd;
94 } dahdi;
95 } driver;
96};
97
98struct e1inp_driver {
99 struct llist_head list;
100 const char *name;
101 int (*want_write)(struct e1inp_ts *ts);
102 int (*line_update)(struct e1inp_line *line);
103 int default_delay;
104};
105
106struct e1inp_line {
107 struct llist_head list;
108 unsigned int num;
109 const char *name;
110
111 /* array of timestlots */
112 struct e1inp_ts ts[NUM_E1_TS];
113
114 struct e1inp_driver *driver;
115 void *driver_data;
116};
117
118/* register a driver with the E1 core */
119int e1inp_driver_register(struct e1inp_driver *drv);
120
121/* fine a previously registered driver */
122struct e1inp_driver *e1inp_driver_find(const char *name);
123
124/* register a line with the E1 core */
125int e1inp_line_register(struct e1inp_line *line);
126
127/* get a line by its ID */
Jonathan Santos5a45b152011-08-17 15:33:57 -0400128struct e1inp_line *e1inp_line_get(uint8_t e1_nr);
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400129
130/* create a line in the E1 input core */
Jonathan Santos5a45b152011-08-17 15:33:57 -0400131struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name);
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400132
133/* find a sign_link for given TEI and SAPI in a TS */
134struct e1inp_sign_link *
Jonathan Santos5a45b152011-08-17 15:33:57 -0400135e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei,
136 uint8_t sapi);
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400137
138/* create a new signalling link in a E1 timeslot */
139struct e1inp_sign_link *
140e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
Jonathan Santos5a45b152011-08-17 15:33:57 -0400141 struct gsm_bts_trx *trx, uint8_t tei,
142 uint8_t sapi);
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400143
144/* configure and initialize one e1inp_ts */
145int e1inp_ts_config(struct e1inp_ts *ts, struct e1inp_line *line,
146 enum e1inp_ts_type type);
147
148/* Call from the Stack: configuration of this TS has changed */
149int e1inp_update_ts(struct e1inp_ts *ts);
150
151/* Receive a packet from the E1 driver */
152int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg,
Jonathan Santos5a45b152011-08-17 15:33:57 -0400153 uint8_t tei, uint8_t sapi);
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400154
155/* called by driver if it wants to transmit on a given TS */
156struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
157 struct e1inp_sign_link **sign_link);
158
159/* called by driver in case some kind of link state event */
Jonathan Santos5a45b152011-08-17 15:33:57 -0400160int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi);
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400161
162/* Write LAPD frames to the fd. */
163void e1_set_pcap_fd(int fd);
164
165/* called by TRAU muxer to obtain the destination mux entity */
Jonathan Santos5a45b152011-08-17 15:33:57 -0400166struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr);
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400167
168void e1inp_sign_link_destroy(struct e1inp_sign_link *link);
169int e1inp_line_update(struct e1inp_line *line);
170
171/* e1_config.c */
172int e1_reconfig_ts(struct gsm_bts_trx_ts *ts);
173int e1_reconfig_trx(struct gsm_bts_trx *trx);
174int e1_reconfig_bts(struct gsm_bts *bts);
175
176int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin);
177int ipaccess_setup(struct gsm_network *gsmnet);
Jonathan Santos5a45b152011-08-17 15:33:57 -0400178int hsl_setup(struct gsm_network *gsmnet);
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400179
180extern struct llist_head e1inp_driver_list;
181extern struct llist_head e1inp_line_list;
182
183int e1inp_vty_init(void);
184void e1inp_init(void);
185
186int _abis_nm_sendmsg(struct msgb *msg, int to_trx_oml);
187
188#endif /* _E1_INPUT_H */