blob: 90e29d3cf3d8f32928a003e7b1177847be373b82 [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>
Maxd1f70ed2017-09-21 16:15:32 +020023#include <time.h>
Harald Welte25de9912009-04-30 15:53:07 +000024#include <netinet/in.h>
25
Neels Hofmeyrc0164792017-09-04 15:15:32 +020026#include <osmocom/bsc/gsm_data.h>
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020027#include <osmocom/abis/e1_input.h>
Neels Hofmeyrc0164792017-09-04 15:15:32 +020028#include <osmocom/bsc/misdn.h>
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020029#include <osmocom/abis/ipaccess.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010030#include <osmocom/core/talloc.h>
Neels Hofmeyrc0164792017-09-04 15:15:32 +020031#include <osmocom/bsc/debug.h>
32#include <osmocom/bsc/abis_rsl.h>
Harald Welte1fa60c82009-02-09 18:13:26 +000033
34#define SAPI_L2ML 0
35#define SAPI_OML 62
36#define SAPI_RSL 0 /* 63 ? */
37
Neels Hofmeyr57e8a1f2016-09-25 15:18:39 +020038/* The e1_reconfig_*() functions below take the configuration present in the
Harald Welte42581822009-08-08 16:12:58 +020039 * bts/trx/ts data structures and ensure the E1 configuration reflects the
40 * timeslot/subslot/TEI configuration */
Harald Welte1fa60c82009-02-09 18:13:26 +000041
Harald Welte42581822009-08-08 16:12:58 +020042int e1_reconfig_ts(struct gsm_bts_trx_ts *ts)
43{
44 struct gsm_e1_subslot *e1_link = &ts->e1_link;
45 struct e1inp_line *line;
Harald Welte42581822009-08-08 16:12:58 +020046
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020047 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 +020048
Harald Welte889f16e2011-02-05 15:41:24 +010049 if (!e1_link->e1_ts) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020050 LOGP(DLINP, LOGL_ERROR, "TS (%u/%u/%u) without E1 timeslot?\n",
Harald Welte889f16e2011-02-05 15:41:24 +010051 ts->nr, ts->trx->nr, ts->trx->bts->nr);
Harald Welte42581822009-08-08 16:12:58 +020052 return 0;
Harald Welte889f16e2011-02-05 15:41:24 +010053 }
Harald Welte42581822009-08-08 16:12:58 +020054
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020055 line = e1inp_line_find(e1_link->e1_nr);
Harald Welte889f16e2011-02-05 15:41:24 +010056 if (!line) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020057 LOGP(DLINP, LOGL_ERROR, "TS (%u/%u/%u) referring to "
Harald Welte889f16e2011-02-05 15:41:24 +010058 "non-existing E1 line %u\n", ts->nr, ts->trx->nr,
59 ts->trx->bts->nr, e1_link->e1_nr);
Harald Welte42581822009-08-08 16:12:58 +020060 return -ENOMEM;
Harald Welte889f16e2011-02-05 15:41:24 +010061 }
Harald Welte42581822009-08-08 16:12:58 +020062
Harald Welte42581822009-08-08 16:12:58 +020063 return 0;
64}
65
66int e1_reconfig_trx(struct gsm_bts_trx *trx)
67{
68 struct gsm_e1_subslot *e1_link = &trx->rsl_e1_link;
69 struct e1inp_ts *sign_ts;
70 struct e1inp_line *line;
71 struct e1inp_sign_link *rsl_link;
72 int i;
73
Harald Welte889f16e2011-02-05 15:41:24 +010074 if (!e1_link->e1_ts) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020075 LOGP(DLINP, LOGL_ERROR, "TRX (%u/%u) RSL link without "
Harald Welte889f16e2011-02-05 15:41:24 +010076 "timeslot?\n", trx->bts->nr, trx->nr);
Harald Welte42581822009-08-08 16:12:58 +020077 return -EINVAL;
Harald Welte889f16e2011-02-05 15:41:24 +010078 }
Harald Welte42581822009-08-08 16:12:58 +020079
80 /* RSL Link */
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020081 line = e1inp_line_find(e1_link->e1_nr);
Harald Welte889f16e2011-02-05 15:41:24 +010082 if (!line) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020083 LOGP(DLINP, LOGL_ERROR, "TRX (%u/%u) RSL link referring "
Harald Welte889f16e2011-02-05 15:41:24 +010084 "to non-existing E1 line %u\n", trx->bts->nr,
85 trx->nr, e1_link->e1_nr);
Harald Welte42581822009-08-08 16:12:58 +020086 return -ENOMEM;
Harald Welte889f16e2011-02-05 15:41:24 +010087 }
Harald Welte42581822009-08-08 16:12:58 +020088 sign_ts = &line->ts[e1_link->e1_ts-1];
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020089 e1inp_ts_config_sign(sign_ts, line);
Harald Welte15ccc772011-02-13 19:36:18 +010090 /* Ericsson RBS have a per-TRX OML link in parallel to RSL */
Harald Weltec834b702011-02-13 15:41:09 +010091 if (trx->bts->type == GSM_BTS_TYPE_RBS2000) {
Harald Welte15ccc772011-02-13 19:36:18 +010092 struct e1inp_sign_link *oml_link;
93 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, trx,
94 trx->rsl_tei, SAPI_OML);
95 if (!oml_link) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +020096 LOGP(DLINP, LOGL_ERROR, "TRX (%u/%u) OML link creation "
Harald Welte15ccc772011-02-13 19:36:18 +010097 "failed\n", trx->bts->nr, trx->nr);
98 return -ENOMEM;
99 }
100 if (trx->oml_link)
101 e1inp_sign_link_destroy(trx->oml_link);
102 trx->oml_link = oml_link;
Harald Weltec834b702011-02-13 15:41:09 +0100103 }
Harald Welte42581822009-08-08 16:12:58 +0200104 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
105 trx, trx->rsl_tei, SAPI_RSL);
Harald Welte889f16e2011-02-05 15:41:24 +0100106 if (!rsl_link) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200107 LOGP(DLINP, LOGL_ERROR, "TRX (%u/%u) RSL link creation "
Harald Welte889f16e2011-02-05 15:41:24 +0100108 "failed\n", trx->bts->nr, trx->nr);
Harald Welte42581822009-08-08 16:12:58 +0200109 return -ENOMEM;
Harald Welte889f16e2011-02-05 15:41:24 +0100110 }
Harald Welte42581822009-08-08 16:12:58 +0200111 if (trx->rsl_link)
112 e1inp_sign_link_destroy(trx->rsl_link);
113 trx->rsl_link = rsl_link;
114
115 for (i = 0; i < TRX_NR_TS; i++)
116 e1_reconfig_ts(&trx->ts[i]);
117
118 return 0;
119}
120
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200121/* this is the generic callback for all ISDN-based BTS. */
122static int bts_isdn_sign_link(struct msgb *msg)
123{
124 int ret = -EINVAL;
125 struct e1inp_sign_link *link = msg->dst;
126 struct gsm_bts *bts;
127
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200128 switch (link->type) {
129 case E1INP_SIGN_OML:
130 bts = link->trx->bts;
131 ret = bts->model->oml_rcvmsg(msg);
132 break;
133 case E1INP_SIGN_RSL:
134 ret = abis_rsl_rcvmsg(msg);
135 break;
136 default:
137 LOGP(DLMI, LOGL_ERROR, "unknown link type %u\n", link->type);
138 break;
139 }
140 return ret;
141}
142
143struct e1inp_line_ops bts_isdn_e1inp_line_ops = {
144 .sign_link = bts_isdn_sign_link,
145};
146
Harald Welte42581822009-08-08 16:12:58 +0200147int e1_reconfig_bts(struct gsm_bts *bts)
148{
149 struct gsm_e1_subslot *e1_link = &bts->oml_e1_link;
150 struct e1inp_ts *sign_ts;
151 struct e1inp_line *line;
152 struct e1inp_sign_link *oml_link;
153 struct gsm_bts_trx *trx;
Maxd1f70ed2017-09-21 16:15:32 +0200154 struct timespec tp;
155 int rc;
Harald Welte42581822009-08-08 16:12:58 +0200156
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200157 DEBUGP(DLMI, "e1_reconfig_bts(%u)\n", bts->nr);
Harald Welte42581822009-08-08 16:12:58 +0200158
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200159 line = e1inp_line_find(e1_link->e1_nr);
160 if (!line) {
161 LOGP(DLINP, LOGL_ERROR, "BTS %u OML link referring to "
162 "non-existing E1 line %u\n", bts->nr, e1_link->e1_nr);
163 return -ENOMEM;
164 }
165
166 if (!bts->model->e1line_bind_ops) {
167 LOGP(DLINP, LOGL_ERROR, "no callback to bind E1 line operations\n");
168 return -EINVAL;
169 }
170 if (!line->ops)
171 bts->model->e1line_bind_ops(line);
172
173 /* skip signal link initialization, this is done later for these BTS. */
174 if (bts->type == GSM_BTS_TYPE_NANOBTS ||
Maxf9685c12017-03-23 12:01:07 +0100175 bts->type == GSM_BTS_TYPE_OSMOBTS)
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200176 return e1inp_line_update(line);
177
178 /* OML link */
Harald Welte889f16e2011-02-05 15:41:24 +0100179 if (!e1_link->e1_ts) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200180 LOGP(DLINP, LOGL_ERROR, "BTS %u OML link without timeslot?\n",
Harald Welte889f16e2011-02-05 15:41:24 +0100181 bts->nr);
Harald Welte42581822009-08-08 16:12:58 +0200182 return -EINVAL;
Harald Welte889f16e2011-02-05 15:41:24 +0100183 }
Harald Welte42581822009-08-08 16:12:58 +0200184
Harald Welte42581822009-08-08 16:12:58 +0200185 sign_ts = &line->ts[e1_link->e1_ts-1];
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200186 e1inp_ts_config_sign(sign_ts, line);
Harald Welte42581822009-08-08 16:12:58 +0200187 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
188 bts->c0, bts->oml_tei, SAPI_OML);
Harald Welte889f16e2011-02-05 15:41:24 +0100189 if (!oml_link) {
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200190 LOGP(DLINP, LOGL_ERROR, "BTS %u OML link creation failed\n",
Harald Welte889f16e2011-02-05 15:41:24 +0100191 bts->nr);
Harald Welte42581822009-08-08 16:12:58 +0200192 return -ENOMEM;
Harald Welte889f16e2011-02-05 15:41:24 +0100193 }
Harald Welte42581822009-08-08 16:12:58 +0200194 if (bts->oml_link)
195 e1inp_sign_link_destroy(bts->oml_link);
196 bts->oml_link = oml_link;
Maxd1f70ed2017-09-21 16:15:32 +0200197 rc = clock_gettime(CLOCK_MONOTONIC, &tp);
198 bts->uptime = (rc < 0) ? 0 : tp.tv_sec; /* we don't need sub-second precision for uptime */
Harald Welte42581822009-08-08 16:12:58 +0200199
200 llist_for_each_entry(trx, &bts->trx_list, list)
201 e1_reconfig_trx(trx);
202
203 /* notify E1 input something has changed */
204 return e1inp_line_update(line);
205}
206
207#if 0
Harald Welte1fa60c82009-02-09 18:13:26 +0000208/* do some compiled-in configuration for our BTS/E1 setup */
Holger Freytherb5c00f52009-04-22 22:08:07 +0000209int e1_config(struct gsm_bts *bts, int cardnr, int release_l2)
Harald Welte1fa60c82009-02-09 18:13:26 +0000210{
211 struct e1inp_line *line;
212 struct e1inp_ts *sign_ts;
213 struct e1inp_sign_link *oml_link, *rsl_link;
Harald Welte67b4c302009-07-29 16:42:16 +0200214 struct gsm_bts_trx *trx = bts->c0;
Harald Welte4e55d682009-08-04 14:13:35 +0200215 int base_ts;
216
217 switch (bts->nr) {
218 case 0:
219 /* First BTS uses E1 TS 01,02,03,04,05 */
Harald Welte63589be2009-08-06 17:38:10 +0200220 base_ts = HARDCODED_BTS0_TS - 1;
Harald Welte4e55d682009-08-04 14:13:35 +0200221 break;
222 case 1:
Harald Welte63589be2009-08-06 17:38:10 +0200223 /* Second BTS uses E1 TS 06,07,08,09,10 */
224 base_ts = HARDCODED_BTS1_TS - 1;
Harald Welte4e55d682009-08-04 14:13:35 +0200225 break;
226 case 2:
Harald Welte63589be2009-08-06 17:38:10 +0200227 /* Third BTS uses E1 TS 11,12,13,14,15 */
228 base_ts = HARDCODED_BTS2_TS - 1;
Harald Welte4e55d682009-08-04 14:13:35 +0200229 default:
230 return -EINVAL;
231 }
Harald Welte1fa60c82009-02-09 18:13:26 +0000232
Harald Welte470ec292009-06-26 20:25:23 +0200233 line = talloc_zero(tall_bsc_ctx, struct e1inp_line);
Harald Welte1fa60c82009-02-09 18:13:26 +0000234 if (!line)
235 return -ENOMEM;
Harald Welte1fa60c82009-02-09 18:13:26 +0000236
237 /* create E1 timeslots for signalling and TRAU frames */
Harald Welte4e55d682009-08-04 14:13:35 +0200238 e1inp_ts_config(&line->ts[base_ts+1-1], line, E1INP_TS_TYPE_SIGN);
239 e1inp_ts_config(&line->ts[base_ts+2-1], line, E1INP_TS_TYPE_TRAU);
240 e1inp_ts_config(&line->ts[base_ts+3-1], line, E1INP_TS_TYPE_TRAU);
Harald Welte1fa60c82009-02-09 18:13:26 +0000241
242 /* create signalling links for TS1 */
Harald Welte4e55d682009-08-04 14:13:35 +0200243 sign_ts = &line->ts[base_ts+1-1];
Harald Welte1fa60c82009-02-09 18:13:26 +0000244 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
Harald Welte67b4c302009-07-29 16:42:16 +0200245 trx, TEI_OML, SAPI_OML);
Harald Welte1fa60c82009-02-09 18:13:26 +0000246 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
Harald Welte67b4c302009-07-29 16:42:16 +0200247 trx, TEI_RSL, SAPI_RSL);
Harald Welte1fa60c82009-02-09 18:13:26 +0000248
249 /* create back-links from bts/trx */
250 bts->oml_link = oml_link;
Harald Welte67b4c302009-07-29 16:42:16 +0200251 trx->rsl_link = rsl_link;
Harald Welte1fa60c82009-02-09 18:13:26 +0000252
Harald Welte11fa29c2009-02-19 17:24:39 +0000253 /* enable subchannel demuxer on TS2 */
Harald Welte4e55d682009-08-04 14:13:35 +0200254 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 1);
255 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 2);
256 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 3);
Harald Welte93d3f372009-02-18 03:27:14 +0000257
Harald Welte11fa29c2009-02-19 17:24:39 +0000258 /* enable subchannel demuxer on TS3 */
Harald Welte4e55d682009-08-04 14:13:35 +0200259 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 0);
260 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 1);
261 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 2);
262 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 3);
Harald Welte11fa29c2009-02-19 17:24:39 +0000263
Harald Welte67b4c302009-07-29 16:42:16 +0200264 trx = gsm_bts_trx_num(bts, 1);
265 if (trx) {
266 /* create E1 timeslots for TRAU frames of TRX1 */
Harald Welte4e55d682009-08-04 14:13:35 +0200267 e1inp_ts_config(&line->ts[base_ts+4-1], line, E1INP_TS_TYPE_TRAU);
268 e1inp_ts_config(&line->ts[base_ts+5-1], line, E1INP_TS_TYPE_TRAU);
Harald Welte1fa60c82009-02-09 18:13:26 +0000269
Harald Welte67b4c302009-07-29 16:42:16 +0200270 /* create RSL signalling link for TRX1 */
Harald Welte4e55d682009-08-04 14:13:35 +0200271 sign_ts = &line->ts[base_ts+1-1];
Harald Welte67b4c302009-07-29 16:42:16 +0200272 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
273 trx, TEI_RSL+1, SAPI_RSL);
274 /* create back-links from trx */
275 trx->rsl_link = rsl_link;
276
277 /* enable subchannel demuxer on TS2 */
Harald Welte4e55d682009-08-04 14:13:35 +0200278 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 0);
279 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 1);
280 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 2);
281 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 3);
Harald Welte67b4c302009-07-29 16:42:16 +0200282
283 /* enable subchannel demuxer on TS3 */
Harald Welte4e55d682009-08-04 14:13:35 +0200284 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 0);
285 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 1);
286 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 2);
287 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 3);
Harald Welte67b4c302009-07-29 16:42:16 +0200288 }
Harald Welte1fa60c82009-02-09 18:13:26 +0000289
Holger Freytherb5c00f52009-04-22 22:08:07 +0000290 return mi_setup(cardnr, line, release_l2);
Harald Welte1fa60c82009-02-09 18:13:26 +0000291}
Harald Welte42581822009-08-08 16:12:58 +0200292#endif