blob: db290cbae74b661551d264948ed9358e4aee6dd6 [file] [log] [blame]
Harald Welte0e3e88e2011-01-01 15:25:50 +01001/* 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 Welte59b04682009-06-10 05:40:52 +080021#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 Freyther735cd9e2009-08-10 07:54:02 +020031#include <openbsc/ipaccess.h>
Harald Weltef4625b12010-02-20 16:24:02 +010032#include <osmocore/talloc.h>
Harald Weltecf2ec4a2009-12-17 23:10:46 +010033#include <openbsc/debug.h>
Harald Welte59b04682009-06-10 05:40:52 +080034
35#define SAPI_L2ML 0
36#define SAPI_OML 62
37#define SAPI_RSL 0 /* 63 ? */
38
Harald Welte62868882009-08-08 16:12:58 +020039/* 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 Welte59b04682009-06-10 05:40:52 +080042
Harald Welte62868882009-08-08 16:12:58 +020043int 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 Weltecf2ec4a2009-12-17 23:10:46 +010049 DEBUGP(DMI, "e1_reconfig_ts(%u,%u,%u)\n", ts->trx->bts->nr, ts->trx->nr, ts->nr);
Harald Welte62868882009-08-08 16:12:58 +020050
Harald Weltea8497822011-02-05 15:41:24 +010051 if (!e1_link->e1_ts) {
52 LOGP(DINP, LOGL_ERROR, "TS (%u/%u/%u) without E1 timeslot?\n",
53 ts->nr, ts->trx->nr, ts->trx->bts->nr);
Harald Welte62868882009-08-08 16:12:58 +020054 return 0;
Harald Weltea8497822011-02-05 15:41:24 +010055 }
Harald Welte62868882009-08-08 16:12:58 +020056
Harald Weltee76bea02011-02-05 13:54:41 +010057 line = e1inp_line_get(e1_link->e1_nr);
Harald Weltea8497822011-02-05 15:41:24 +010058 if (!line) {
59 LOGP(DINP, LOGL_ERROR, "TS (%u/%u/%u) referring to "
60 "non-existing E1 line %u\n", ts->nr, ts->trx->nr,
61 ts->trx->bts->nr, e1_link->e1_nr);
Harald Welte62868882009-08-08 16:12:58 +020062 return -ENOMEM;
Harald Weltea8497822011-02-05 15:41:24 +010063 }
Harald Welte62868882009-08-08 16:12:58 +020064
65 switch (ts->pchan) {
66 case GSM_PCHAN_TCH_F:
67 case GSM_PCHAN_TCH_H:
68 e1_ts = &line->ts[e1_link->e1_ts-1];
69 e1inp_ts_config(e1_ts, line, E1INP_TS_TYPE_TRAU);
70 subch_demux_activate(&e1_ts->trau.demux, e1_link->e1_ts_ss);
71 break;
72 default:
73 break;
74 }
75
76 return 0;
77}
78
79int e1_reconfig_trx(struct gsm_bts_trx *trx)
80{
81 struct gsm_e1_subslot *e1_link = &trx->rsl_e1_link;
82 struct e1inp_ts *sign_ts;
83 struct e1inp_line *line;
84 struct e1inp_sign_link *rsl_link;
85 int i;
86
Harald Weltea8497822011-02-05 15:41:24 +010087 if (!e1_link->e1_ts) {
88 LOGP(DINP, LOGL_ERROR, "TRX (%u/%u) RSL link without "
89 "timeslot?\n", trx->bts->nr, trx->nr);
Harald Welte62868882009-08-08 16:12:58 +020090 return -EINVAL;
Harald Weltea8497822011-02-05 15:41:24 +010091 }
Harald Welte62868882009-08-08 16:12:58 +020092
93 /* RSL Link */
Harald Weltee76bea02011-02-05 13:54:41 +010094 line = e1inp_line_get(e1_link->e1_nr);
Harald Weltea8497822011-02-05 15:41:24 +010095 if (!line) {
96 LOGP(DINP, LOGL_ERROR, "TRX (%u/%u) RSL link referring "
97 "to non-existing E1 line %u\n", trx->bts->nr,
98 trx->nr, e1_link->e1_nr);
Harald Welte62868882009-08-08 16:12:58 +020099 return -ENOMEM;
Harald Weltea8497822011-02-05 15:41:24 +0100100 }
Harald Welte62868882009-08-08 16:12:58 +0200101 sign_ts = &line->ts[e1_link->e1_ts-1];
102 e1inp_ts_config(sign_ts, line, E1INP_TS_TYPE_SIGN);
Harald Welte6e4fd612011-02-13 15:41:09 +0100103 if (trx->bts->type == GSM_BTS_TYPE_RBS2000) {
104 /* FIXME: where to put the reference of the per-TRX OML? */
105 e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, trx,
106 trx->rsl_tei, SAPI_OML);
107 }
Harald Welte62868882009-08-08 16:12:58 +0200108 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
109 trx, trx->rsl_tei, SAPI_RSL);
Harald Weltea8497822011-02-05 15:41:24 +0100110 if (!rsl_link) {
111 LOGP(DINP, LOGL_ERROR, "TRX (%u/%u) RSL link creation "
112 "failed\n", trx->bts->nr, trx->nr);
Harald Welte62868882009-08-08 16:12:58 +0200113 return -ENOMEM;
Harald Weltea8497822011-02-05 15:41:24 +0100114 }
Harald Welte62868882009-08-08 16:12:58 +0200115 if (trx->rsl_link)
116 e1inp_sign_link_destroy(trx->rsl_link);
117 trx->rsl_link = rsl_link;
118
119 for (i = 0; i < TRX_NR_TS; i++)
120 e1_reconfig_ts(&trx->ts[i]);
121
122 return 0;
123}
124
125int e1_reconfig_bts(struct gsm_bts *bts)
126{
127 struct gsm_e1_subslot *e1_link = &bts->oml_e1_link;
128 struct e1inp_ts *sign_ts;
129 struct e1inp_line *line;
130 struct e1inp_sign_link *oml_link;
131 struct gsm_bts_trx *trx;
Harald Welte62868882009-08-08 16:12:58 +0200132
Harald Weltecf2ec4a2009-12-17 23:10:46 +0100133 DEBUGP(DMI, "e1_reconfig_bts(%u)\n", bts->nr);
Harald Welte62868882009-08-08 16:12:58 +0200134
Harald Weltea8497822011-02-05 15:41:24 +0100135 if (!e1_link->e1_ts) {
136 LOGP(DINP, LOGL_ERROR, "BTS %u OML link without timeslot?\n",
137 bts->nr);
Harald Welte62868882009-08-08 16:12:58 +0200138 return -EINVAL;
Harald Weltea8497822011-02-05 15:41:24 +0100139 }
Harald Welte62868882009-08-08 16:12:58 +0200140
141 /* OML link */
Harald Weltee76bea02011-02-05 13:54:41 +0100142 line = e1inp_line_get(e1_link->e1_nr);
Harald Weltea8497822011-02-05 15:41:24 +0100143 if (!line) {
144 LOGP(DINP, LOGL_ERROR, "BTS %u OML link referring to "
145 "non-existing E1 line %u\n", bts->nr, e1_link->e1_nr);
Harald Welte62868882009-08-08 16:12:58 +0200146 return -ENOMEM;
Harald Weltea8497822011-02-05 15:41:24 +0100147 }
Harald Welte62868882009-08-08 16:12:58 +0200148 sign_ts = &line->ts[e1_link->e1_ts-1];
149 e1inp_ts_config(sign_ts, line, E1INP_TS_TYPE_SIGN);
150 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
151 bts->c0, bts->oml_tei, SAPI_OML);
Harald Weltea8497822011-02-05 15:41:24 +0100152 if (!oml_link) {
153 LOGP(DINP, LOGL_ERROR, "BTS %u OML link creation failed\n",
154 bts->nr);
Harald Welte62868882009-08-08 16:12:58 +0200155 return -ENOMEM;
Harald Weltea8497822011-02-05 15:41:24 +0100156 }
Harald Welte62868882009-08-08 16:12:58 +0200157 if (bts->oml_link)
158 e1inp_sign_link_destroy(bts->oml_link);
159 bts->oml_link = oml_link;
160
161 llist_for_each_entry(trx, &bts->trx_list, list)
162 e1_reconfig_trx(trx);
163
164 /* notify E1 input something has changed */
165 return e1inp_line_update(line);
166}
167
168#if 0
Harald Welte59b04682009-06-10 05:40:52 +0800169/* do some compiled-in configuration for our BTS/E1 setup */
170int e1_config(struct gsm_bts *bts, int cardnr, int release_l2)
171{
172 struct e1inp_line *line;
173 struct e1inp_ts *sign_ts;
174 struct e1inp_sign_link *oml_link, *rsl_link;
Harald Welte25b70c52009-07-29 16:42:16 +0200175 struct gsm_bts_trx *trx = bts->c0;
Harald Welted1b1cda2009-08-04 14:13:35 +0200176 int base_ts;
177
178 switch (bts->nr) {
179 case 0:
180 /* First BTS uses E1 TS 01,02,03,04,05 */
Harald Welte2d73d4e2009-08-06 17:38:10 +0200181 base_ts = HARDCODED_BTS0_TS - 1;
Harald Welted1b1cda2009-08-04 14:13:35 +0200182 break;
183 case 1:
Harald Welte2d73d4e2009-08-06 17:38:10 +0200184 /* Second BTS uses E1 TS 06,07,08,09,10 */
185 base_ts = HARDCODED_BTS1_TS - 1;
Harald Welted1b1cda2009-08-04 14:13:35 +0200186 break;
187 case 2:
Harald Welte2d73d4e2009-08-06 17:38:10 +0200188 /* Third BTS uses E1 TS 11,12,13,14,15 */
189 base_ts = HARDCODED_BTS2_TS - 1;
Harald Welted1b1cda2009-08-04 14:13:35 +0200190 default:
191 return -EINVAL;
192 }
Harald Welte59b04682009-06-10 05:40:52 +0800193
Harald Welte857e00d2009-06-26 20:25:23 +0200194 line = talloc_zero(tall_bsc_ctx, struct e1inp_line);
Harald Welte59b04682009-06-10 05:40:52 +0800195 if (!line)
196 return -ENOMEM;
Harald Welte59b04682009-06-10 05:40:52 +0800197
198 /* create E1 timeslots for signalling and TRAU frames */
Harald Welted1b1cda2009-08-04 14:13:35 +0200199 e1inp_ts_config(&line->ts[base_ts+1-1], line, E1INP_TS_TYPE_SIGN);
200 e1inp_ts_config(&line->ts[base_ts+2-1], line, E1INP_TS_TYPE_TRAU);
201 e1inp_ts_config(&line->ts[base_ts+3-1], line, E1INP_TS_TYPE_TRAU);
Harald Welte59b04682009-06-10 05:40:52 +0800202
203 /* create signalling links for TS1 */
Harald Welted1b1cda2009-08-04 14:13:35 +0200204 sign_ts = &line->ts[base_ts+1-1];
Harald Welte59b04682009-06-10 05:40:52 +0800205 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
Harald Welte25b70c52009-07-29 16:42:16 +0200206 trx, TEI_OML, SAPI_OML);
Harald Welte59b04682009-06-10 05:40:52 +0800207 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
Harald Welte25b70c52009-07-29 16:42:16 +0200208 trx, TEI_RSL, SAPI_RSL);
Harald Welte59b04682009-06-10 05:40:52 +0800209
210 /* create back-links from bts/trx */
211 bts->oml_link = oml_link;
Harald Welte25b70c52009-07-29 16:42:16 +0200212 trx->rsl_link = rsl_link;
Harald Welte59b04682009-06-10 05:40:52 +0800213
214 /* enable subchannel demuxer on TS2 */
Harald Welted1b1cda2009-08-04 14:13:35 +0200215 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 1);
216 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 2);
217 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 3);
Harald Welte59b04682009-06-10 05:40:52 +0800218
219 /* enable subchannel demuxer on TS3 */
Harald Welted1b1cda2009-08-04 14:13:35 +0200220 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 0);
221 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 1);
222 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 2);
223 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 3);
Harald Welte59b04682009-06-10 05:40:52 +0800224
Harald Welte25b70c52009-07-29 16:42:16 +0200225 trx = gsm_bts_trx_num(bts, 1);
226 if (trx) {
227 /* create E1 timeslots for TRAU frames of TRX1 */
Harald Welted1b1cda2009-08-04 14:13:35 +0200228 e1inp_ts_config(&line->ts[base_ts+4-1], line, E1INP_TS_TYPE_TRAU);
229 e1inp_ts_config(&line->ts[base_ts+5-1], line, E1INP_TS_TYPE_TRAU);
Harald Welte59b04682009-06-10 05:40:52 +0800230
Harald Welte25b70c52009-07-29 16:42:16 +0200231 /* create RSL signalling link for TRX1 */
Harald Welted1b1cda2009-08-04 14:13:35 +0200232 sign_ts = &line->ts[base_ts+1-1];
Harald Welte25b70c52009-07-29 16:42:16 +0200233 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
234 trx, TEI_RSL+1, SAPI_RSL);
235 /* create back-links from trx */
236 trx->rsl_link = rsl_link;
237
238 /* enable subchannel demuxer on TS2 */
Harald Welted1b1cda2009-08-04 14:13:35 +0200239 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 0);
240 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 1);
241 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 2);
242 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 3);
Harald Welte25b70c52009-07-29 16:42:16 +0200243
244 /* enable subchannel demuxer on TS3 */
Harald Welted1b1cda2009-08-04 14:13:35 +0200245 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 0);
246 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 1);
247 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 2);
248 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 3);
Harald Welte25b70c52009-07-29 16:42:16 +0200249 }
Harald Welte59b04682009-06-10 05:40:52 +0800250
251 return mi_setup(cardnr, line, release_l2);
252}
Harald Welte62868882009-08-08 16:12:58 +0200253#endif
Harald Welte59b04682009-06-10 05:40:52 +0800254
255/* configure pseudo E1 line in ip.access style and connect to BTS */
256int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin)
257{
258 struct e1inp_line *line;
259 struct e1inp_ts *sign_ts, *rsl_ts;
260 struct e1inp_sign_link *oml_link, *rsl_link;
261
Harald Welte857e00d2009-06-26 20:25:23 +0200262 line = talloc_zero(tall_bsc_ctx, struct e1inp_line);
Harald Welte59b04682009-06-10 05:40:52 +0800263 if (!line)
Harald Weltea8379772009-06-20 22:36:41 +0200264 return -ENOMEM;
Harald Welte59b04682009-06-10 05:40:52 +0800265
266 /* create E1 timeslots for signalling and TRAU frames */
267 e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN);
268 e1inp_ts_config(&line->ts[2-1], line, E1INP_TS_TYPE_SIGN);
269
270 /* create signalling links for TS1 */
271 sign_ts = &line->ts[1-1];
272 rsl_ts = &line->ts[2-1];
273 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
Harald Welte847a3352009-10-20 21:54:06 +0200274 bts->c0, 0xff, 0);
Harald Welte59b04682009-06-10 05:40:52 +0800275 rsl_link = e1inp_sign_link_create(rsl_ts, E1INP_SIGN_RSL,
276 bts->c0, 0, 0);
277
278 /* create back-links from bts/trx */
279 bts->oml_link = oml_link;
280 bts->c0->rsl_link = rsl_link;
281
282 /* default port at BTS for incoming connections is 3006 */
283 if (sin->sin_port == 0)
284 sin->sin_port = htons(3006);
285
286 return ipaccess_connect(line, sin);
287}