Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 1 | /* OpenBSC E1 Input code */ |
| 2 | |
| 3 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 21 | #include <string.h> |
| 22 | #include <errno.h> |
| 23 | |
| 24 | #include <netinet/in.h> |
| 25 | |
| 26 | #include <openbsc/gsm_data.h> |
| 27 | #include <openbsc/e1_input.h> |
| 28 | #include <openbsc/trau_frame.h> |
| 29 | #include <openbsc/trau_mux.h> |
| 30 | #include <openbsc/misdn.h> |
Holger Hans Peter Freyther | 735cd9e | 2009-08-10 07:54:02 +0200 | [diff] [blame] | 31 | #include <openbsc/ipaccess.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 32 | #include <osmocore/talloc.h> |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 33 | #include <openbsc/debug.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 34 | |
| 35 | #define SAPI_L2ML 0 |
| 36 | #define SAPI_OML 62 |
| 37 | #define SAPI_RSL 0 /* 63 ? */ |
| 38 | |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 39 | /* The e1_reconfig_*() functions below tale the configuration present in the |
| 40 | * bts/trx/ts data structures and ensure the E1 configuration reflects the |
| 41 | * timeslot/subslot/TEI configuration */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 42 | |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 43 | int e1_reconfig_ts(struct gsm_bts_trx_ts *ts) |
| 44 | { |
| 45 | struct gsm_e1_subslot *e1_link = &ts->e1_link; |
| 46 | struct e1inp_line *line; |
| 47 | struct e1inp_ts *e1_ts; |
| 48 | |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 49 | DEBUGP(DMI, "e1_reconfig_ts(%u,%u,%u)\n", ts->trx->bts->nr, ts->trx->nr, ts->nr); |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 50 | |
| 51 | if (!e1_link->e1_ts) |
| 52 | return 0; |
| 53 | |
| 54 | line = e1inp_line_get_create(e1_link->e1_nr); |
| 55 | if (!line) |
| 56 | return -ENOMEM; |
| 57 | |
| 58 | switch (ts->pchan) { |
| 59 | case GSM_PCHAN_TCH_F: |
| 60 | case GSM_PCHAN_TCH_H: |
| 61 | e1_ts = &line->ts[e1_link->e1_ts-1]; |
| 62 | e1inp_ts_config(e1_ts, line, E1INP_TS_TYPE_TRAU); |
| 63 | subch_demux_activate(&e1_ts->trau.demux, e1_link->e1_ts_ss); |
| 64 | break; |
| 65 | default: |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | int e1_reconfig_trx(struct gsm_bts_trx *trx) |
| 73 | { |
| 74 | struct gsm_e1_subslot *e1_link = &trx->rsl_e1_link; |
| 75 | struct e1inp_ts *sign_ts; |
| 76 | struct e1inp_line *line; |
| 77 | struct e1inp_sign_link *rsl_link; |
| 78 | int i; |
| 79 | |
| 80 | if (!e1_link->e1_ts) |
| 81 | return -EINVAL; |
| 82 | |
| 83 | /* RSL Link */ |
| 84 | line = e1inp_line_get_create(e1_link->e1_nr); |
| 85 | if (!line) |
| 86 | return -ENOMEM; |
| 87 | sign_ts = &line->ts[e1_link->e1_ts-1]; |
| 88 | e1inp_ts_config(sign_ts, line, E1INP_TS_TYPE_SIGN); |
| 89 | rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL, |
| 90 | trx, trx->rsl_tei, SAPI_RSL); |
| 91 | if (!rsl_link) |
| 92 | return -ENOMEM; |
| 93 | if (trx->rsl_link) |
| 94 | e1inp_sign_link_destroy(trx->rsl_link); |
| 95 | trx->rsl_link = rsl_link; |
| 96 | |
| 97 | for (i = 0; i < TRX_NR_TS; i++) |
| 98 | e1_reconfig_ts(&trx->ts[i]); |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | int e1_reconfig_bts(struct gsm_bts *bts) |
| 104 | { |
| 105 | struct gsm_e1_subslot *e1_link = &bts->oml_e1_link; |
| 106 | struct e1inp_ts *sign_ts; |
| 107 | struct e1inp_line *line; |
| 108 | struct e1inp_sign_link *oml_link; |
| 109 | struct gsm_bts_trx *trx; |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 110 | |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 111 | DEBUGP(DMI, "e1_reconfig_bts(%u)\n", bts->nr); |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 112 | |
| 113 | if (!e1_link->e1_ts) |
| 114 | return -EINVAL; |
| 115 | |
| 116 | /* OML link */ |
| 117 | line = e1inp_line_get_create(e1_link->e1_nr); |
| 118 | if (!line) |
| 119 | return -ENOMEM; |
| 120 | sign_ts = &line->ts[e1_link->e1_ts-1]; |
| 121 | e1inp_ts_config(sign_ts, line, E1INP_TS_TYPE_SIGN); |
| 122 | oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, |
| 123 | bts->c0, bts->oml_tei, SAPI_OML); |
| 124 | if (!oml_link) |
| 125 | return -ENOMEM; |
| 126 | if (bts->oml_link) |
| 127 | e1inp_sign_link_destroy(bts->oml_link); |
| 128 | bts->oml_link = oml_link; |
| 129 | |
| 130 | llist_for_each_entry(trx, &bts->trx_list, list) |
| 131 | e1_reconfig_trx(trx); |
| 132 | |
| 133 | /* notify E1 input something has changed */ |
| 134 | return e1inp_line_update(line); |
| 135 | } |
| 136 | |
| 137 | #if 0 |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 138 | /* do some compiled-in configuration for our BTS/E1 setup */ |
| 139 | int e1_config(struct gsm_bts *bts, int cardnr, int release_l2) |
| 140 | { |
| 141 | struct e1inp_line *line; |
| 142 | struct e1inp_ts *sign_ts; |
| 143 | struct e1inp_sign_link *oml_link, *rsl_link; |
Harald Welte | 25b70c5 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 144 | struct gsm_bts_trx *trx = bts->c0; |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 145 | int base_ts; |
| 146 | |
| 147 | switch (bts->nr) { |
| 148 | case 0: |
| 149 | /* First BTS uses E1 TS 01,02,03,04,05 */ |
Harald Welte | 2d73d4e | 2009-08-06 17:38:10 +0200 | [diff] [blame] | 150 | base_ts = HARDCODED_BTS0_TS - 1; |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 151 | break; |
| 152 | case 1: |
Harald Welte | 2d73d4e | 2009-08-06 17:38:10 +0200 | [diff] [blame] | 153 | /* Second BTS uses E1 TS 06,07,08,09,10 */ |
| 154 | base_ts = HARDCODED_BTS1_TS - 1; |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 155 | break; |
| 156 | case 2: |
Harald Welte | 2d73d4e | 2009-08-06 17:38:10 +0200 | [diff] [blame] | 157 | /* Third BTS uses E1 TS 11,12,13,14,15 */ |
| 158 | base_ts = HARDCODED_BTS2_TS - 1; |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 159 | default: |
| 160 | return -EINVAL; |
| 161 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 162 | |
Harald Welte | 857e00d | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 163 | line = talloc_zero(tall_bsc_ctx, struct e1inp_line); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 164 | if (!line) |
| 165 | return -ENOMEM; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 166 | |
| 167 | /* create E1 timeslots for signalling and TRAU frames */ |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 168 | e1inp_ts_config(&line->ts[base_ts+1-1], line, E1INP_TS_TYPE_SIGN); |
| 169 | e1inp_ts_config(&line->ts[base_ts+2-1], line, E1INP_TS_TYPE_TRAU); |
| 170 | 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] | 171 | |
| 172 | /* create signalling links for TS1 */ |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 173 | sign_ts = &line->ts[base_ts+1-1]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 174 | oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, |
Harald Welte | 25b70c5 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 175 | trx, TEI_OML, SAPI_OML); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 176 | rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL, |
Harald Welte | 25b70c5 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 177 | trx, TEI_RSL, SAPI_RSL); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 178 | |
| 179 | /* create back-links from bts/trx */ |
| 180 | bts->oml_link = oml_link; |
Harald Welte | 25b70c5 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 181 | trx->rsl_link = rsl_link; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 182 | |
| 183 | /* enable subchannel demuxer on TS2 */ |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 184 | subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 1); |
| 185 | subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 2); |
| 186 | subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 3); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 187 | |
| 188 | /* enable subchannel demuxer on TS3 */ |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 189 | subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 0); |
| 190 | subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 1); |
| 191 | subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 2); |
| 192 | subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 3); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 193 | |
Harald Welte | 25b70c5 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 194 | trx = gsm_bts_trx_num(bts, 1); |
| 195 | if (trx) { |
| 196 | /* create E1 timeslots for TRAU frames of TRX1 */ |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 197 | e1inp_ts_config(&line->ts[base_ts+4-1], line, E1INP_TS_TYPE_TRAU); |
| 198 | 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] | 199 | |
Harald Welte | 25b70c5 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 200 | /* create RSL signalling link for TRX1 */ |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 201 | sign_ts = &line->ts[base_ts+1-1]; |
Harald Welte | 25b70c5 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 202 | rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL, |
| 203 | trx, TEI_RSL+1, SAPI_RSL); |
| 204 | /* create back-links from trx */ |
| 205 | trx->rsl_link = rsl_link; |
| 206 | |
| 207 | /* enable subchannel demuxer on TS2 */ |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 208 | subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 0); |
| 209 | subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 1); |
| 210 | subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 2); |
| 211 | subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 3); |
Harald Welte | 25b70c5 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 212 | |
| 213 | /* enable subchannel demuxer on TS3 */ |
Harald Welte | d1b1cda | 2009-08-04 14:13:35 +0200 | [diff] [blame] | 214 | subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 0); |
| 215 | subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 1); |
| 216 | subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 2); |
| 217 | subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 3); |
Harald Welte | 25b70c5 | 2009-07-29 16:42:16 +0200 | [diff] [blame] | 218 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 219 | |
| 220 | return mi_setup(cardnr, line, release_l2); |
| 221 | } |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 222 | #endif |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 223 | |
| 224 | /* configure pseudo E1 line in ip.access style and connect to BTS */ |
| 225 | int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin) |
| 226 | { |
| 227 | struct e1inp_line *line; |
| 228 | struct e1inp_ts *sign_ts, *rsl_ts; |
| 229 | struct e1inp_sign_link *oml_link, *rsl_link; |
| 230 | |
Harald Welte | 857e00d | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 231 | line = talloc_zero(tall_bsc_ctx, struct e1inp_line); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 232 | if (!line) |
Harald Welte | a837977 | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 233 | return -ENOMEM; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 234 | |
| 235 | /* create E1 timeslots for signalling and TRAU frames */ |
| 236 | e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN); |
| 237 | e1inp_ts_config(&line->ts[2-1], line, E1INP_TS_TYPE_SIGN); |
| 238 | |
| 239 | /* create signalling links for TS1 */ |
| 240 | sign_ts = &line->ts[1-1]; |
| 241 | rsl_ts = &line->ts[2-1]; |
| 242 | oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, |
Harald Welte | 847a335 | 2009-10-20 21:54:06 +0200 | [diff] [blame] | 243 | bts->c0, 0xff, 0); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 244 | rsl_link = e1inp_sign_link_create(rsl_ts, E1INP_SIGN_RSL, |
| 245 | bts->c0, 0, 0); |
| 246 | |
| 247 | /* create back-links from bts/trx */ |
| 248 | bts->oml_link = oml_link; |
| 249 | bts->c0->rsl_link = rsl_link; |
| 250 | |
| 251 | /* default port at BTS for incoming connections is 3006 */ |
| 252 | if (sin->sin_port == 0) |
| 253 | sin->sin_port = htons(3006); |
| 254 | |
| 255 | return ipaccess_connect(line, sin); |
| 256 | } |