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