Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 1 | #ifndef _E1_INPUT_H |
| 2 | #define _E1_INPUT_H |
| 3 | |
| 4 | #include <stdlib.h> |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 5 | #include <netinet/in.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 6 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 7 | #include <osmocom/core/linuxlist.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 8 | #include <openbsc/gsm_data.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 9 | #include <osmocom/core/msgb.h> |
| 10 | #include <osmocom/core/select.h> |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame^] | 11 | #include <osmocom/core/rate_ctr.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 12 | #include <openbsc/subchan_demux.h> |
| 13 | |
| 14 | #define NUM_E1_TS 32 |
| 15 | |
| 16 | enum e1inp_sign_type { |
| 17 | E1INP_SIGN_NONE, |
| 18 | E1INP_SIGN_OML, |
| 19 | E1INP_SIGN_RSL, |
| 20 | }; |
Harald Welte | d256d4f | 2009-03-10 19:44:48 +0000 | [diff] [blame] | 21 | const char *e1inp_signtype_name(enum e1inp_sign_type tp); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 22 | |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame^] | 23 | enum 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 Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 31 | struct e1inp_ts; |
| 32 | |
| 33 | struct 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 Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 49 | uint8_t sapi; |
| 50 | uint8_t tei; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 51 | |
| 52 | union { |
| 53 | struct { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 54 | uint8_t channel; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 55 | } misdn; |
| 56 | } driver; |
| 57 | }; |
| 58 | |
| 59 | enum e1inp_ts_type { |
| 60 | E1INP_TS_TYPE_NONE, |
| 61 | E1INP_TS_TYPE_SIGN, |
| 62 | E1INP_TS_TYPE_TRAU, |
| 63 | }; |
Harald Welte | d256d4f | 2009-03-10 19:44:48 +0000 | [diff] [blame] | 64 | const char *e1inp_tstype_name(enum e1inp_ts_type tp); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 65 | |
| 66 | /* A timeslot in the E1 interface */ |
| 67 | struct 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 Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 76 | /* list of all signalling links on this TS */ |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 77 | struct llist_head sign_links; |
Holger Hans Peter Freyther | d85642a | 2010-04-26 16:02:04 +0800 | [diff] [blame] | 78 | /* delay for the queue */ |
| 79 | int delay; |
Harald Welte | f55b49f | 2009-05-23 06:20:41 +0000 | [diff] [blame] | 80 | /* timer when to dequeue next frame */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 81 | struct osmo_timer_list tx_timer; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 82 | } 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 Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 93 | struct osmo_fd fd; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 94 | } misdn; |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 95 | struct { |
| 96 | /* ip.access driver has one fd for each ts */ |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 97 | struct osmo_fd fd; |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 98 | } ipaccess; |
Harald Welte | d38f105 | 2011-02-05 19:13:00 +0100 | [diff] [blame] | 99 | struct { |
| 100 | /* DAHDI driver has one fd for each ts */ |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 101 | struct osmo_fd fd; |
Harald Welte | d38f105 | 2011-02-05 19:13:00 +0100 | [diff] [blame] | 102 | struct lapd_instance *lapd; |
| 103 | } dahdi; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 104 | } driver; |
| 105 | }; |
| 106 | |
| 107 | struct e1inp_driver { |
| 108 | struct llist_head list; |
| 109 | const char *name; |
| 110 | int (*want_write)(struct e1inp_ts *ts); |
Harald Welte | 5455243 | 2011-02-05 12:26:55 +0100 | [diff] [blame] | 111 | int (*line_update)(struct e1inp_line *line); |
Holger Hans Peter Freyther | d85642a | 2010-04-26 16:02:04 +0800 | [diff] [blame] | 112 | int default_delay; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | struct e1inp_line { |
| 116 | struct llist_head list; |
| 117 | unsigned int num; |
| 118 | const char *name; |
Harald Welte | 0000ca5 | 2011-08-11 12:50:13 +0200 | [diff] [blame^] | 119 | struct rate_ctr_group *rate_ctr; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 120 | |
| 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 */ |
| 129 | int e1inp_driver_register(struct e1inp_driver *drv); |
| 130 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 131 | /* fine a previously registered driver */ |
| 132 | struct e1inp_driver *e1inp_driver_find(const char *name); |
| 133 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 134 | /* register a line with the E1 core */ |
| 135 | int e1inp_line_register(struct e1inp_line *line); |
| 136 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 137 | /* get a line by its ID */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 138 | struct e1inp_line *e1inp_line_get(uint8_t e1_nr); |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 139 | |
| 140 | /* create a line in the E1 input core */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 141 | struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 142 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 143 | /* find a sign_link for given TEI and SAPI in a TS */ |
| 144 | struct e1inp_sign_link * |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 145 | e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei, |
| 146 | uint8_t sapi); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 147 | |
| 148 | /* create a new signalling link in a E1 timeslot */ |
| 149 | struct e1inp_sign_link * |
| 150 | e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 151 | struct gsm_bts_trx *trx, uint8_t tei, |
| 152 | uint8_t sapi); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 153 | |
| 154 | /* configure and initialize one e1inp_ts */ |
| 155 | int 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 */ |
| 159 | int e1inp_update_ts(struct e1inp_ts *ts); |
| 160 | |
| 161 | /* Receive a packet from the E1 driver */ |
| 162 | int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 163 | uint8_t tei, uint8_t sapi); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 164 | |
| 165 | /* called by driver if it wants to transmit on a given TS */ |
| 166 | struct 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 Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 170 | int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 171 | |
Holger Freyther | 0469cf6 | 2009-03-31 12:14:16 +0000 | [diff] [blame] | 172 | /* Write LAPD frames to the fd. */ |
| 173 | void e1_set_pcap_fd(int fd); |
| 174 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 175 | /* called by TRAU muxer to obtain the destination mux entity */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 176 | struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 177 | |
Holger Hans Peter Freyther | 34e9749 | 2009-08-10 07:54:02 +0200 | [diff] [blame] | 178 | void e1inp_sign_link_destroy(struct e1inp_sign_link *link); |
| 179 | int e1inp_line_update(struct e1inp_line *line); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 180 | |
Holger Freyther | ff9592f | 2009-03-09 16:17:14 +0000 | [diff] [blame] | 181 | /* e1_config.c */ |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 182 | int e1_reconfig_ts(struct gsm_bts_trx_ts *ts); |
| 183 | int e1_reconfig_trx(struct gsm_bts_trx *trx); |
| 184 | int e1_reconfig_bts(struct gsm_bts *bts); |
| 185 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 186 | int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin); |
Harald Welte | edb3778 | 2009-05-01 14:59:07 +0000 | [diff] [blame] | 187 | int ipaccess_setup(struct gsm_network *gsmnet); |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 188 | int hsl_setup(struct gsm_network *gsmnet); |
Holger Freyther | ff9592f | 2009-03-09 16:17:14 +0000 | [diff] [blame] | 189 | |
Harald Welte | 7572745 | 2009-05-23 05:26:29 +0000 | [diff] [blame] | 190 | extern struct llist_head e1inp_driver_list; |
| 191 | extern struct llist_head e1inp_line_list; |
Holger Freyther | ff9592f | 2009-03-09 16:17:14 +0000 | [diff] [blame] | 192 | |
Harald Welte | 3016d9f | 2011-02-05 13:54:41 +0100 | [diff] [blame] | 193 | int e1inp_vty_init(void); |
| 194 | void e1inp_init(void); |
| 195 | |
Harald Welte | d88a387 | 2011-02-14 15:26:13 +0100 | [diff] [blame] | 196 | int _abis_nm_sendmsg(struct msgb *msg, int to_trx_oml); |
| 197 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 198 | #endif /* _E1_INPUT_H */ |