Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1 | #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 Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 8 | #include <osmocom/core/timer.h> |
| 9 | #include <osmocom/core/msgb.h> |
| 10 | #include <osmocom/core/select.h> |
Pablo Neira Ayuso | 177094b | 2011-06-07 12:21:51 +0200 | [diff] [blame] | 11 | #include <osmocom/abis/subchan_demux.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 12 | |
| 13 | #define NUM_E1_TS 32 |
| 14 | |
| 15 | enum e1inp_sign_type { |
| 16 | E1INP_SIGN_NONE, |
| 17 | E1INP_SIGN_OML, |
| 18 | E1INP_SIGN_RSL, |
| 19 | }; |
| 20 | const char *e1inp_signtype_name(enum e1inp_sign_type tp); |
| 21 | |
| 22 | struct e1inp_ts; |
| 23 | |
| 24 | struct 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 | |
| 50 | enum e1inp_ts_type { |
| 51 | E1INP_TS_TYPE_NONE, |
| 52 | E1INP_TS_TYPE_SIGN, |
| 53 | E1INP_TS_TYPE_TRAU, |
| 54 | }; |
| 55 | const char *e1inp_tstype_name(enum e1inp_ts_type tp); |
| 56 | |
| 57 | /* A timeslot in the E1 interface */ |
| 58 | struct 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 | |
| 98 | struct 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 | |
| 107 | enum 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 | |
| 114 | struct e1inp_driver { |
| 115 | struct llist_head list; |
| 116 | const char *name; |
| 117 | int (*want_write)(struct e1inp_ts *ts); |
Pablo Neira Ayuso | c00ee73 | 2011-06-21 12:22:49 +0200 | [diff] [blame] | 118 | int (*line_update)(struct e1inp_line *line, enum e1inp_line_role role, const char *addr); |
Pablo Neira Ayuso | add3ec8 | 2011-07-05 14:45:46 +0200 | [diff] [blame] | 119 | void (*close)(struct e1inp_sign_link *link); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 120 | int default_delay; |
| 121 | }; |
| 122 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 123 | struct e1inp_line_ops { |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 124 | enum e1inp_line_role role; |
| 125 | char *addr; |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 126 | void *data; |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 127 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 128 | struct e1inp_sign_link * (*sign_link_up)(void *unit_info, struct e1inp_line *line, enum e1inp_sign_type type); |
| 129 | void (*sign_link_down)(struct e1inp_line *line); |
Pablo Neira Ayuso | dbd82fb | 2011-07-05 15:29:23 +0200 | [diff] [blame] | 130 | int (*sign_link)(struct msgb *msg); |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 131 | }; |
| 132 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 133 | struct e1inp_line { |
| 134 | struct llist_head list; |
| 135 | int refcnt; |
| 136 | |
| 137 | unsigned int num; |
| 138 | const char *name; |
| 139 | |
| 140 | /* array of timestlots */ |
| 141 | struct e1inp_ts ts[NUM_E1_TS]; |
| 142 | |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 143 | const struct e1inp_line_ops *ops; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 144 | |
| 145 | struct e1inp_driver *driver; |
| 146 | void *driver_data; |
| 147 | }; |
| 148 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 149 | /* SS_L_INPUT signals */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 150 | enum signal_input { |
| 151 | S_INP_NONE, |
| 152 | S_INP_TEI_UP, |
| 153 | S_INP_TEI_DN, |
| 154 | S_INP_LINE_INIT, |
| 155 | S_INP_LINE_ALARM, |
| 156 | S_INP_LINE_NOALARM, |
| 157 | }; |
| 158 | |
| 159 | /* register a driver with the E1 core */ |
| 160 | int e1inp_driver_register(struct e1inp_driver *drv); |
| 161 | |
| 162 | /* fine a previously registered driver */ |
| 163 | struct e1inp_driver *e1inp_driver_find(const char *name); |
| 164 | |
| 165 | /* register a line with the E1 core */ |
| 166 | int e1inp_line_register(struct e1inp_line *line); |
| 167 | |
| 168 | /* get a line by its ID */ |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 169 | struct e1inp_line *e1inp_line_find(uint8_t e1_nr); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 170 | |
| 171 | /* create a line in the E1 input core */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 172 | struct e1inp_line *e1inp_line_create(uint8_t e1_nr, const char *driver_name); |
| 173 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 174 | /* clone one existing E1 input line */ |
| 175 | struct e1inp_line *e1inp_line_clone(void *ctx, struct e1inp_line *line); |
| 176 | |
| 177 | /* increment refcount use of E1 input line */ |
| 178 | void e1inp_line_get(struct e1inp_line *line); |
| 179 | |
| 180 | /* decrement refcount use of E1 input line, release if unused */ |
| 181 | void e1inp_line_put(struct e1inp_line *line); |
| 182 | |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 183 | /* bind operations to one E1 input line */ |
| 184 | void e1inp_line_bind_ops(struct e1inp_line *line, const struct e1inp_line_ops *ops); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 185 | |
| 186 | /* find a sign_link for given TEI and SAPI in a TS */ |
| 187 | struct e1inp_sign_link * |
| 188 | e1inp_lookup_sign_link(struct e1inp_ts *ts, uint8_t tei, |
| 189 | uint8_t sapi); |
| 190 | |
| 191 | /* create a new signalling link in a E1 timeslot */ |
| 192 | struct e1inp_sign_link * |
| 193 | e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type, |
| 194 | struct gsm_bts_trx *trx, uint8_t tei, |
| 195 | uint8_t sapi); |
| 196 | |
Pablo Neira Ayuso | 211d2ca | 2011-06-07 17:15:10 +0200 | [diff] [blame] | 197 | /* configure and initialize one signalling e1inp_ts */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 198 | int e1inp_ts_config_sign(struct e1inp_ts *ts, struct e1inp_line *line); |
Pablo Neira Ayuso | 211d2ca | 2011-06-07 17:15:10 +0200 | [diff] [blame] | 199 | |
| 200 | /* configure and initialize one timeslot dedicated to TRAU frames. */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 201 | int e1inp_ts_config_trau(struct e1inp_ts *ts, struct e1inp_line *line, |
Pablo Neira Ayuso | 211d2ca | 2011-06-07 17:15:10 +0200 | [diff] [blame] | 202 | int (*trau_rcv_cb)(struct subch_demux *dmx, int ch, |
| 203 | uint8_t *data, int len, void *_priv)); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 204 | |
| 205 | /* Call from the Stack: configuration of this TS has changed */ |
| 206 | int e1inp_update_ts(struct e1inp_ts *ts); |
| 207 | |
| 208 | /* Receive a packet from the E1 driver */ |
| 209 | int e1inp_rx_ts(struct e1inp_ts *ts, struct msgb *msg, |
| 210 | uint8_t tei, uint8_t sapi); |
| 211 | |
| 212 | /* called by driver if it wants to transmit on a given TS */ |
| 213 | struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts, |
| 214 | struct e1inp_sign_link **sign_link); |
| 215 | |
| 216 | /* called by driver in case some kind of link state event */ |
| 217 | int e1inp_event(struct e1inp_ts *ts, int evt, uint8_t tei, uint8_t sapi); |
| 218 | |
| 219 | /* Write LAPD frames to the fd. */ |
| 220 | void e1_set_pcap_fd(int fd); |
| 221 | |
| 222 | /* called by TRAU muxer to obtain the destination mux entity */ |
| 223 | struct subch_mux *e1inp_get_mux(uint8_t e1_nr, uint8_t ts_nr); |
| 224 | |
| 225 | void e1inp_sign_link_destroy(struct e1inp_sign_link *link); |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 226 | int e1inp_line_update(struct e1inp_line *line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 227 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 228 | int e1inp_vty_init(void); |
| 229 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 230 | struct gsm_network; |
| 231 | int ipaccess_setup(struct gsm_network *gsmnet); |
| 232 | int hsl_setup(struct gsm_network *gsmnet); |
| 233 | |
| 234 | extern struct llist_head e1inp_driver_list; |
| 235 | extern struct llist_head e1inp_line_list; |
| 236 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 237 | /* XXX */ |
| 238 | struct input_signal_data { |
| 239 | int link_type; |
| 240 | uint8_t tei; |
| 241 | uint8_t sapi; |
| 242 | struct gsm_bts_trx *trx; |
| 243 | struct e1inp_line *line; |
| 244 | }; |
| 245 | |
Pablo Neira Ayuso | 96e7263 | 2011-06-26 19:08:05 +0200 | [diff] [blame] | 246 | int abis_sendmsg(struct msgb *msg); |
| 247 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 248 | #endif /* _E1_INPUT_H */ |