blob: f1962c737f754c975e44f846e04c3c2e804041b6 [file] [log] [blame]
Harald Welte9af6ddf2011-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 Welte1fa60c82009-02-09 18:13:26 +000021#include <string.h>
22#include <errno.h>
23
Harald Welte25de9912009-04-30 15:53:07 +000024#include <netinet/in.h>
25
Harald Welte1fa60c82009-02-09 18:13:26 +000026#include <openbsc/gsm_data.h>
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020027#include <osmocom/abis/e1_input.h>
28#include <osmocom/abis/trau_frame.h>
Harald Welte39a1b712009-02-10 17:17:09 +000029#include <openbsc/trau_mux.h>
Holger Freytherff9592f2009-03-09 16:17:14 +000030#include <openbsc/misdn.h>
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020031#include <osmocom/abis/ipaccess.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010032#include <osmocom/core/talloc.h>
Harald Welteb1d4c8e2009-12-17 23:10:46 +010033#include <openbsc/debug.h>
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020034#include <openbsc/abis_rsl.h>
Harald Welte1fa60c82009-02-09 18:13:26 +000035
36#define SAPI_L2ML 0
37#define SAPI_OML 62
38#define SAPI_RSL 0 /* 63 ? */
39
Neels Hofmeyr57e8a1f2016-09-25 15:18:39 +020040/* The e1_reconfig_*() functions below take the configuration present in the
Harald Welte42581822009-08-08 16:12:58 +020041 * bts/trx/ts data structures and ensure the E1 configuration reflects the
42 * timeslot/subslot/TEI configuration */
Harald Welte1fa60c82009-02-09 18:13:26 +000043
Harald Welte42581822009-08-08 16:12:58 +020044int e1_reconfig_ts(struct gsm_bts_trx_ts *ts)
45{
46 struct gsm_e1_subslot *e1_link = &ts->e1_link;
47 struct e1inp_line *line;
48 struct e1inp_ts *e1_ts;
49
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020050 DEBUGP(DLMI, "e1_reconfig_ts(%u,%u,%u)\n", ts->trx->bts->nr, ts->trx->nr, ts->nr);
Harald Welte42581822009-08-08 16:12:58 +020051
Harald Welte889f16e2011-02-05 15:41:24 +010052 if (!e1_link->e1_ts) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020053 LOGP(DLINP, LOGL_ERROR, "TS (%u/%u/%u) without E1 timeslot?\n",
Harald Welte889f16e2011-02-05 15:41:24 +010054 ts->nr, ts->trx->nr, ts->trx->bts->nr);
Harald Welte42581822009-08-08 16:12:58 +020055 return 0;
Harald Welte889f16e2011-02-05 15:41:24 +010056 }
Harald Welte42581822009-08-08 16:12:58 +020057
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020058 line = e1inp_line_find(e1_link->e1_nr);
Harald Welte889f16e2011-02-05 15:41:24 +010059 if (!line) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020060 LOGP(DLINP, LOGL_ERROR, "TS (%u/%u/%u) referring to "
Harald Welte889f16e2011-02-05 15:41:24 +010061 "non-existing E1 line %u\n", ts->nr, ts->trx->nr,
62 ts->trx->bts->nr, e1_link->e1_nr);
Harald Welte42581822009-08-08 16:12:58 +020063 return -ENOMEM;
Harald Welte889f16e2011-02-05 15:41:24 +010064 }
Harald Welte42581822009-08-08 16:12:58 +020065
Neels Hofmeyr255dbfe2016-09-25 15:07:01 +020066 if (ts_is_tch(ts)) {
Harald Welte42581822009-08-08 16:12:58 +020067 e1_ts = &line->ts[e1_link->e1_ts-1];
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020068 e1inp_ts_config_trau(e1_ts, line, subch_cb);
Harald Welte42581822009-08-08 16:12:58 +020069 subch_demux_activate(&e1_ts->trau.demux, e1_link->e1_ts_ss);
Harald Welte42581822009-08-08 16:12:58 +020070 }
71
72 return 0;
73}
74
75int e1_reconfig_trx(struct gsm_bts_trx *trx)
76{
77 struct gsm_e1_subslot *e1_link = &trx->rsl_e1_link;
78 struct e1inp_ts *sign_ts;
79 struct e1inp_line *line;
80 struct e1inp_sign_link *rsl_link;
81 int i;
82
Harald Welte889f16e2011-02-05 15:41:24 +010083 if (!e1_link->e1_ts) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020084 LOGP(DLINP, LOGL_ERROR, "TRX (%u/%u) RSL link without "
Harald Welte889f16e2011-02-05 15:41:24 +010085 "timeslot?\n", trx->bts->nr, trx->nr);
Harald Welte42581822009-08-08 16:12:58 +020086 return -EINVAL;
Harald Welte889f16e2011-02-05 15:41:24 +010087 }
Harald Welte42581822009-08-08 16:12:58 +020088
89 /* RSL Link */
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020090 line = e1inp_line_find(e1_link->e1_nr);
Harald Welte889f16e2011-02-05 15:41:24 +010091 if (!line) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020092 LOGP(DLINP, LOGL_ERROR, "TRX (%u/%u) RSL link referring "
Harald Welte889f16e2011-02-05 15:41:24 +010093 "to non-existing E1 line %u\n", trx->bts->nr,
94 trx->nr, e1_link->e1_nr);
Harald Welte42581822009-08-08 16:12:58 +020095 return -ENOMEM;
Harald Welte889f16e2011-02-05 15:41:24 +010096 }
Harald Welte42581822009-08-08 16:12:58 +020097 sign_ts = &line->ts[e1_link->e1_ts-1];
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020098 e1inp_ts_config_sign(sign_ts, line);
Harald Welte15ccc772011-02-13 19:36:18 +010099 /* Ericsson RBS have a per-TRX OML link in parallel to RSL */
Harald Weltec834b702011-02-13 15:41:09 +0100100 if (trx->bts->type == GSM_BTS_TYPE_RBS2000) {
Harald Welte15ccc772011-02-13 19:36:18 +0100101 struct e1inp_sign_link *oml_link;
102 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, trx,
103 trx->rsl_tei, SAPI_OML);
104 if (!oml_link) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200105 LOGP(DLINP, LOGL_ERROR, "TRX (%u/%u) OML link creation "
Harald Welte15ccc772011-02-13 19:36:18 +0100106 "failed\n", trx->bts->nr, trx->nr);
107 return -ENOMEM;
108 }
109 if (trx->oml_link)
110 e1inp_sign_link_destroy(trx->oml_link);
111 trx->oml_link = oml_link;
Harald Weltec834b702011-02-13 15:41:09 +0100112 }
Harald Welte42581822009-08-08 16:12:58 +0200113 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
114 trx, trx->rsl_tei, SAPI_RSL);
Harald Welte889f16e2011-02-05 15:41:24 +0100115 if (!rsl_link) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200116 LOGP(DLINP, LOGL_ERROR, "TRX (%u/%u) RSL link creation "
Harald Welte889f16e2011-02-05 15:41:24 +0100117 "failed\n", trx->bts->nr, trx->nr);
Harald Welte42581822009-08-08 16:12:58 +0200118 return -ENOMEM;
Harald Welte889f16e2011-02-05 15:41:24 +0100119 }
Harald Welte42581822009-08-08 16:12:58 +0200120 if (trx->rsl_link)
121 e1inp_sign_link_destroy(trx->rsl_link);
122 trx->rsl_link = rsl_link;
123
124 for (i = 0; i < TRX_NR_TS; i++)
125 e1_reconfig_ts(&trx->ts[i]);
126
127 return 0;
128}
129
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200130/* this is the generic callback for all ISDN-based BTS. */
131static int bts_isdn_sign_link(struct msgb *msg)
132{
133 int ret = -EINVAL;
134 struct e1inp_sign_link *link = msg->dst;
135 struct gsm_bts *bts;
136
137 log_set_context(BSC_CTX_BTS, link->trx->bts);
138 switch (link->type) {
139 case E1INP_SIGN_OML:
140 bts = link->trx->bts;
141 ret = bts->model->oml_rcvmsg(msg);
142 break;
143 case E1INP_SIGN_RSL:
144 ret = abis_rsl_rcvmsg(msg);
145 break;
146 default:
147 LOGP(DLMI, LOGL_ERROR, "unknown link type %u\n", link->type);
148 break;
149 }
150 return ret;
151}
152
153struct e1inp_line_ops bts_isdn_e1inp_line_ops = {
154 .sign_link = bts_isdn_sign_link,
155};
156
Harald Welte42581822009-08-08 16:12:58 +0200157int e1_reconfig_bts(struct gsm_bts *bts)
158{
159 struct gsm_e1_subslot *e1_link = &bts->oml_e1_link;
160 struct e1inp_ts *sign_ts;
161 struct e1inp_line *line;
162 struct e1inp_sign_link *oml_link;
163 struct gsm_bts_trx *trx;
Harald Welte42581822009-08-08 16:12:58 +0200164
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200165 DEBUGP(DLMI, "e1_reconfig_bts(%u)\n", bts->nr);
Harald Welte42581822009-08-08 16:12:58 +0200166
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200167 line = e1inp_line_find(e1_link->e1_nr);
168 if (!line) {
169 LOGP(DLINP, LOGL_ERROR, "BTS %u OML link referring to "
170 "non-existing E1 line %u\n", bts->nr, e1_link->e1_nr);
171 return -ENOMEM;
172 }
173
174 if (!bts->model->e1line_bind_ops) {
175 LOGP(DLINP, LOGL_ERROR, "no callback to bind E1 line operations\n");
176 return -EINVAL;
177 }
178 if (!line->ops)
179 bts->model->e1line_bind_ops(line);
180
181 /* skip signal link initialization, this is done later for these BTS. */
182 if (bts->type == GSM_BTS_TYPE_NANOBTS ||
Holger Hans Peter Freytherf0167dd2013-07-03 16:06:20 +0200183 bts->type == GSM_BTS_TYPE_OSMO_SYSMO)
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200184 return e1inp_line_update(line);
185
186 /* OML link */
Harald Welte889f16e2011-02-05 15:41:24 +0100187 if (!e1_link->e1_ts) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200188 LOGP(DLINP, LOGL_ERROR, "BTS %u OML link without timeslot?\n",
Harald Welte889f16e2011-02-05 15:41:24 +0100189 bts->nr);
Harald Welte42581822009-08-08 16:12:58 +0200190 return -EINVAL;
Harald Welte889f16e2011-02-05 15:41:24 +0100191 }
Harald Welte42581822009-08-08 16:12:58 +0200192
Harald Welte42581822009-08-08 16:12:58 +0200193 sign_ts = &line->ts[e1_link->e1_ts-1];
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200194 e1inp_ts_config_sign(sign_ts, line);
Harald Welte42581822009-08-08 16:12:58 +0200195 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
196 bts->c0, bts->oml_tei, SAPI_OML);
Harald Welte889f16e2011-02-05 15:41:24 +0100197 if (!oml_link) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200198 LOGP(DLINP, LOGL_ERROR, "BTS %u OML link creation failed\n",
Harald Welte889f16e2011-02-05 15:41:24 +0100199 bts->nr);
Harald Welte42581822009-08-08 16:12:58 +0200200 return -ENOMEM;
Harald Welte889f16e2011-02-05 15:41:24 +0100201 }
Harald Welte42581822009-08-08 16:12:58 +0200202 if (bts->oml_link)
203 e1inp_sign_link_destroy(bts->oml_link);
204 bts->oml_link = oml_link;
205
206 llist_for_each_entry(trx, &bts->trx_list, list)
207 e1_reconfig_trx(trx);
208
209 /* notify E1 input something has changed */
210 return e1inp_line_update(line);
211}
212
213#if 0
Harald Welte1fa60c82009-02-09 18:13:26 +0000214/* do some compiled-in configuration for our BTS/E1 setup */
Holger Freytherb5c00f52009-04-22 22:08:07 +0000215int e1_config(struct gsm_bts *bts, int cardnr, int release_l2)
Harald Welte1fa60c82009-02-09 18:13:26 +0000216{
217 struct e1inp_line *line;
218 struct e1inp_ts *sign_ts;
219 struct e1inp_sign_link *oml_link, *rsl_link;
Harald Welte67b4c302009-07-29 16:42:16 +0200220 struct gsm_bts_trx *trx = bts->c0;
Harald Welte4e55d682009-08-04 14:13:35 +0200221 int base_ts;
222
223 switch (bts->nr) {
224 case 0:
225 /* First BTS uses E1 TS 01,02,03,04,05 */
Harald Welte63589be2009-08-06 17:38:10 +0200226 base_ts = HARDCODED_BTS0_TS - 1;
Harald Welte4e55d682009-08-04 14:13:35 +0200227 break;
228 case 1:
Harald Welte63589be2009-08-06 17:38:10 +0200229 /* Second BTS uses E1 TS 06,07,08,09,10 */
230 base_ts = HARDCODED_BTS1_TS - 1;
Harald Welte4e55d682009-08-04 14:13:35 +0200231 break;
232 case 2:
Harald Welte63589be2009-08-06 17:38:10 +0200233 /* Third BTS uses E1 TS 11,12,13,14,15 */
234 base_ts = HARDCODED_BTS2_TS - 1;
Harald Welte4e55d682009-08-04 14:13:35 +0200235 default:
236 return -EINVAL;
237 }
Harald Welte1fa60c82009-02-09 18:13:26 +0000238
Harald Welte470ec292009-06-26 20:25:23 +0200239 line = talloc_zero(tall_bsc_ctx, struct e1inp_line);
Harald Welte1fa60c82009-02-09 18:13:26 +0000240 if (!line)
241 return -ENOMEM;
Harald Welte1fa60c82009-02-09 18:13:26 +0000242
243 /* create E1 timeslots for signalling and TRAU frames */
Harald Welte4e55d682009-08-04 14:13:35 +0200244 e1inp_ts_config(&line->ts[base_ts+1-1], line, E1INP_TS_TYPE_SIGN);
245 e1inp_ts_config(&line->ts[base_ts+2-1], line, E1INP_TS_TYPE_TRAU);
246 e1inp_ts_config(&line->ts[base_ts+3-1], line, E1INP_TS_TYPE_TRAU);
Harald Welte1fa60c82009-02-09 18:13:26 +0000247
248 /* create signalling links for TS1 */
Harald Welte4e55d682009-08-04 14:13:35 +0200249 sign_ts = &line->ts[base_ts+1-1];
Harald Welte1fa60c82009-02-09 18:13:26 +0000250 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
Harald Welte67b4c302009-07-29 16:42:16 +0200251 trx, TEI_OML, SAPI_OML);
Harald Welte1fa60c82009-02-09 18:13:26 +0000252 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
Harald Welte67b4c302009-07-29 16:42:16 +0200253 trx, TEI_RSL, SAPI_RSL);
Harald Welte1fa60c82009-02-09 18:13:26 +0000254
255 /* create back-links from bts/trx */
256 bts->oml_link = oml_link;
Harald Welte67b4c302009-07-29 16:42:16 +0200257 trx->rsl_link = rsl_link;
Harald Welte1fa60c82009-02-09 18:13:26 +0000258
Harald Welte11fa29c2009-02-19 17:24:39 +0000259 /* enable subchannel demuxer on TS2 */
Harald Welte4e55d682009-08-04 14:13:35 +0200260 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 1);
261 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 2);
262 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 3);
Harald Welte93d3f372009-02-18 03:27:14 +0000263
Harald Welte11fa29c2009-02-19 17:24:39 +0000264 /* enable subchannel demuxer on TS3 */
Harald Welte4e55d682009-08-04 14:13:35 +0200265 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 0);
266 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 1);
267 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 2);
268 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 3);
Harald Welte11fa29c2009-02-19 17:24:39 +0000269
Harald Welte67b4c302009-07-29 16:42:16 +0200270 trx = gsm_bts_trx_num(bts, 1);
271 if (trx) {
272 /* create E1 timeslots for TRAU frames of TRX1 */
Harald Welte4e55d682009-08-04 14:13:35 +0200273 e1inp_ts_config(&line->ts[base_ts+4-1], line, E1INP_TS_TYPE_TRAU);
274 e1inp_ts_config(&line->ts[base_ts+5-1], line, E1INP_TS_TYPE_TRAU);
Harald Welte1fa60c82009-02-09 18:13:26 +0000275
Harald Welte67b4c302009-07-29 16:42:16 +0200276 /* create RSL signalling link for TRX1 */
Harald Welte4e55d682009-08-04 14:13:35 +0200277 sign_ts = &line->ts[base_ts+1-1];
Harald Welte67b4c302009-07-29 16:42:16 +0200278 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
279 trx, TEI_RSL+1, SAPI_RSL);
280 /* create back-links from trx */
281 trx->rsl_link = rsl_link;
282
283 /* enable subchannel demuxer on TS2 */
Harald Welte4e55d682009-08-04 14:13:35 +0200284 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 0);
285 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 1);
286 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 2);
287 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 3);
Harald Welte67b4c302009-07-29 16:42:16 +0200288
289 /* enable subchannel demuxer on TS3 */
Harald Welte4e55d682009-08-04 14:13:35 +0200290 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 0);
291 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 1);
292 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 2);
293 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 3);
Harald Welte67b4c302009-07-29 16:42:16 +0200294 }
Harald Welte1fa60c82009-02-09 18:13:26 +0000295
Holger Freytherb5c00f52009-04-22 22:08:07 +0000296 return mi_setup(cardnr, line, release_l2);
Harald Welte1fa60c82009-02-09 18:13:26 +0000297}
Harald Welte42581822009-08-08 16:12:58 +0200298#endif