Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 1 | #include <string.h> |
| 2 | #include <errno.h> |
| 3 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 4 | #include <netinet/in.h> |
| 5 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 6 | #include <openbsc/gsm_data.h> |
| 7 | #include <openbsc/e1_input.h> |
Harald Welte | 45b407a | 2009-05-23 15:51:12 +0000 | [diff] [blame] | 8 | #include <openbsc/trau_frame.h> |
Harald Welte | 39a1b71 | 2009-02-10 17:17:09 +0000 | [diff] [blame] | 9 | #include <openbsc/trau_mux.h> |
Holger Freyther | ff9592f | 2009-03-09 16:17:14 +0000 | [diff] [blame] | 10 | #include <openbsc/misdn.h> |
Holger Hans Peter Freyther | 34e9749 | 2009-08-10 07:54:02 +0200 | [diff] [blame] | 11 | #include <openbsc/ipaccess.h> |
Harald Welte | dfe6c7d | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 12 | #include <osmocore/talloc.h> |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 13 | #include <openbsc/debug.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 14 | |
| 15 | #define SAPI_L2ML 0 |
| 16 | #define SAPI_OML 62 |
| 17 | #define SAPI_RSL 0 /* 63 ? */ |
| 18 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 19 | /* The e1_reconfig_*() functions below tale the configuration present in the |
| 20 | * bts/trx/ts data structures and ensure the E1 configuration reflects the |
| 21 | * timeslot/subslot/TEI configuration */ |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 22 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 23 | int e1_reconfig_ts(struct gsm_bts_trx_ts *ts) |
| 24 | { |
| 25 | struct gsm_e1_subslot *e1_link = &ts->e1_link; |
| 26 | struct e1inp_line *line; |
| 27 | struct e1inp_ts *e1_ts; |
| 28 | |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 29 | DEBUGP(DMI, "e1_reconfig_ts(%u,%u,%u)\n", ts->trx->bts->nr, ts->trx->nr, ts->nr); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 30 | |
| 31 | if (!e1_link->e1_ts) |
| 32 | return 0; |
| 33 | |
| 34 | line = e1inp_line_get_create(e1_link->e1_nr); |
| 35 | if (!line) |
| 36 | return -ENOMEM; |
| 37 | |
| 38 | switch (ts->pchan) { |
| 39 | case GSM_PCHAN_TCH_F: |
| 40 | case GSM_PCHAN_TCH_H: |
| 41 | e1_ts = &line->ts[e1_link->e1_ts-1]; |
| 42 | e1inp_ts_config(e1_ts, line, E1INP_TS_TYPE_TRAU); |
| 43 | subch_demux_activate(&e1_ts->trau.demux, e1_link->e1_ts_ss); |
| 44 | break; |
| 45 | default: |
| 46 | break; |
| 47 | } |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | int e1_reconfig_trx(struct gsm_bts_trx *trx) |
| 53 | { |
| 54 | struct gsm_e1_subslot *e1_link = &trx->rsl_e1_link; |
| 55 | struct e1inp_ts *sign_ts; |
| 56 | struct e1inp_line *line; |
| 57 | struct e1inp_sign_link *rsl_link; |
| 58 | int i; |
| 59 | |
| 60 | if (!e1_link->e1_ts) |
| 61 | return -EINVAL; |
| 62 | |
| 63 | /* RSL Link */ |
| 64 | line = e1inp_line_get_create(e1_link->e1_nr); |
| 65 | if (!line) |
| 66 | return -ENOMEM; |
| 67 | sign_ts = &line->ts[e1_link->e1_ts-1]; |
| 68 | e1inp_ts_config(sign_ts, line, E1INP_TS_TYPE_SIGN); |
| 69 | rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL, |
| 70 | trx, trx->rsl_tei, SAPI_RSL); |
| 71 | if (!rsl_link) |
| 72 | return -ENOMEM; |
| 73 | if (trx->rsl_link) |
| 74 | e1inp_sign_link_destroy(trx->rsl_link); |
| 75 | trx->rsl_link = rsl_link; |
| 76 | |
| 77 | for (i = 0; i < TRX_NR_TS; i++) |
| 78 | e1_reconfig_ts(&trx->ts[i]); |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | int e1_reconfig_bts(struct gsm_bts *bts) |
| 84 | { |
| 85 | struct gsm_e1_subslot *e1_link = &bts->oml_e1_link; |
| 86 | struct e1inp_ts *sign_ts; |
| 87 | struct e1inp_line *line; |
| 88 | struct e1inp_sign_link *oml_link; |
| 89 | struct gsm_bts_trx *trx; |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 90 | |
Harald Welte | b1d4c8e | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 91 | DEBUGP(DMI, "e1_reconfig_bts(%u)\n", bts->nr); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 92 | |
| 93 | if (!e1_link->e1_ts) |
| 94 | return -EINVAL; |
| 95 | |
| 96 | /* OML link */ |
| 97 | line = e1inp_line_get_create(e1_link->e1_nr); |
| 98 | if (!line) |
| 99 | return -ENOMEM; |
| 100 | sign_ts = &line->ts[e1_link->e1_ts-1]; |
| 101 | e1inp_ts_config(sign_ts, line, E1INP_TS_TYPE_SIGN); |
| 102 | oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, |
| 103 | bts->c0, bts->oml_tei, SAPI_OML); |
| 104 | if (!oml_link) |
| 105 | return -ENOMEM; |
| 106 | if (bts->oml_link) |
| 107 | e1inp_sign_link_destroy(bts->oml_link); |
| 108 | bts->oml_link = oml_link; |
| 109 | |
| 110 | llist_for_each_entry(trx, &bts->trx_list, list) |
| 111 | e1_reconfig_trx(trx); |
| 112 | |
| 113 | /* notify E1 input something has changed */ |
| 114 | return e1inp_line_update(line); |
| 115 | } |
| 116 | |
| 117 | #if 0 |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 118 | /* do some compiled-in configuration for our BTS/E1 setup */ |
Holger Freyther | b5c00f5 | 2009-04-22 22:08:07 +0000 | [diff] [blame] | 119 | int e1_config(struct gsm_bts *bts, int cardnr, int release_l2) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 120 | { |
| 121 | struct e1inp_line *line; |
| 122 | struct e1inp_ts *sign_ts; |
| 123 | struct e1inp_sign_link *oml_link, *rsl_link; |
Harald Welte | 67b4c30 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 124 | struct gsm_bts_trx *trx = bts->c0; |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 125 | int base_ts; |
| 126 | |
| 127 | switch (bts->nr) { |
| 128 | case 0: |
| 129 | /* First BTS uses E1 TS 01,02,03,04,05 */ |
Harald Welte | 63589be | 2009-08-06 17:38:10 +0200 | [diff] [blame] | 130 | base_ts = HARDCODED_BTS0_TS - 1; |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 131 | break; |
| 132 | case 1: |
Harald Welte | 63589be | 2009-08-06 17:38:10 +0200 | [diff] [blame] | 133 | /* Second BTS uses E1 TS 06,07,08,09,10 */ |
| 134 | base_ts = HARDCODED_BTS1_TS - 1; |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 135 | break; |
| 136 | case 2: |
Harald Welte | 63589be | 2009-08-06 17:38:10 +0200 | [diff] [blame] | 137 | /* Third BTS uses E1 TS 11,12,13,14,15 */ |
| 138 | base_ts = HARDCODED_BTS2_TS - 1; |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 139 | default: |
| 140 | return -EINVAL; |
| 141 | } |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 142 | |
Harald Welte | 470ec29 | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 143 | line = talloc_zero(tall_bsc_ctx, struct e1inp_line); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 144 | if (!line) |
| 145 | return -ENOMEM; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 146 | |
| 147 | /* create E1 timeslots for signalling and TRAU frames */ |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 148 | e1inp_ts_config(&line->ts[base_ts+1-1], line, E1INP_TS_TYPE_SIGN); |
| 149 | e1inp_ts_config(&line->ts[base_ts+2-1], line, E1INP_TS_TYPE_TRAU); |
| 150 | e1inp_ts_config(&line->ts[base_ts+3-1], line, E1INP_TS_TYPE_TRAU); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 151 | |
| 152 | /* create signalling links for TS1 */ |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 153 | sign_ts = &line->ts[base_ts+1-1]; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 154 | oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, |
Harald Welte | 67b4c30 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 155 | trx, TEI_OML, SAPI_OML); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 156 | rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL, |
Harald Welte | 67b4c30 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 157 | trx, TEI_RSL, SAPI_RSL); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 158 | |
| 159 | /* create back-links from bts/trx */ |
| 160 | bts->oml_link = oml_link; |
Harald Welte | 67b4c30 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 161 | trx->rsl_link = rsl_link; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 162 | |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 163 | /* enable subchannel demuxer on TS2 */ |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 164 | subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 1); |
| 165 | subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 2); |
| 166 | subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 3); |
Harald Welte | 93d3f37 | 2009-02-18 03:27:14 +0000 | [diff] [blame] | 167 | |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 168 | /* enable subchannel demuxer on TS3 */ |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 169 | subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 0); |
| 170 | subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 1); |
| 171 | subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 2); |
| 172 | subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 3); |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 173 | |
Harald Welte | 67b4c30 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 174 | trx = gsm_bts_trx_num(bts, 1); |
| 175 | if (trx) { |
| 176 | /* create E1 timeslots for TRAU frames of TRX1 */ |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 177 | e1inp_ts_config(&line->ts[base_ts+4-1], line, E1INP_TS_TYPE_TRAU); |
| 178 | e1inp_ts_config(&line->ts[base_ts+5-1], line, E1INP_TS_TYPE_TRAU); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 179 | |
Harald Welte | 67b4c30 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 180 | /* create RSL signalling link for TRX1 */ |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 181 | sign_ts = &line->ts[base_ts+1-1]; |
Harald Welte | 67b4c30 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 182 | rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL, |
| 183 | trx, TEI_RSL+1, SAPI_RSL); |
| 184 | /* create back-links from trx */ |
| 185 | trx->rsl_link = rsl_link; |
| 186 | |
| 187 | /* enable subchannel demuxer on TS2 */ |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 188 | subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 0); |
| 189 | subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 1); |
| 190 | subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 2); |
| 191 | subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 3); |
Harald Welte | 67b4c30 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 192 | |
| 193 | /* enable subchannel demuxer on TS3 */ |
Harald Welte | 4e55d68 | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 194 | subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 0); |
| 195 | subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 1); |
| 196 | subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 2); |
| 197 | subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 3); |
Harald Welte | 67b4c30 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 198 | } |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 199 | |
Holger Freyther | b5c00f5 | 2009-04-22 22:08:07 +0000 | [diff] [blame] | 200 | return mi_setup(cardnr, line, release_l2); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 201 | } |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 202 | #endif |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 203 | |
Harald Welte | edb3778 | 2009-05-01 14:59:07 +0000 | [diff] [blame] | 204 | /* configure pseudo E1 line in ip.access style and connect to BTS */ |
| 205 | int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin) |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 206 | { |
| 207 | struct e1inp_line *line; |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 208 | struct e1inp_ts *sign_ts, *rsl_ts; |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 209 | struct e1inp_sign_link *oml_link, *rsl_link; |
| 210 | |
Harald Welte | 470ec29 | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 211 | line = talloc_zero(tall_bsc_ctx, struct e1inp_line); |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 212 | if (!line) |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 213 | return -ENOMEM; |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 214 | |
| 215 | /* create E1 timeslots for signalling and TRAU frames */ |
| 216 | e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN); |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 217 | e1inp_ts_config(&line->ts[2-1], line, E1INP_TS_TYPE_SIGN); |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 218 | |
| 219 | /* create signalling links for TS1 */ |
| 220 | sign_ts = &line->ts[1-1]; |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 221 | rsl_ts = &line->ts[2-1]; |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 222 | oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, |
Harald Welte | d99fb99 | 2009-10-20 21:54:06 +0200 | [diff] [blame] | 223 | bts->c0, 0xff, 0); |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 224 | rsl_link = e1inp_sign_link_create(rsl_ts, E1INP_SIGN_RSL, |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 225 | bts->c0, 0, 0); |
| 226 | |
| 227 | /* create back-links from bts/trx */ |
| 228 | bts->oml_link = oml_link; |
| 229 | bts->c0->rsl_link = rsl_link; |
| 230 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 231 | /* default port at BTS for incoming connections is 3006 */ |
| 232 | if (sin->sin_port == 0) |
| 233 | sin->sin_port = htons(3006); |
| 234 | |
| 235 | return ipaccess_connect(line, sin); |
| 236 | } |