blob: 4a1cbb059706fec5b5b7cac8de4f8d1bae8ef410 [file] [log] [blame]
Harald Welte1fa60c82009-02-09 18:13:26 +00001#include <string.h>
2#include <errno.h>
3
Harald Welte25de9912009-04-30 15:53:07 +00004#include <netinet/in.h>
5
Harald Welte1fa60c82009-02-09 18:13:26 +00006#include <openbsc/gsm_data.h>
7#include <openbsc/e1_input.h>
Harald Welte45b407a2009-05-23 15:51:12 +00008#include <openbsc/trau_frame.h>
Harald Welte39a1b712009-02-10 17:17:09 +00009#include <openbsc/trau_mux.h>
Holger Freytherff9592f2009-03-09 16:17:14 +000010#include <openbsc/misdn.h>
Holger Hans Peter Freyther34e97492009-08-10 07:54:02 +020011#include <openbsc/ipaccess.h>
Harald Welte2cf161b2009-06-20 22:36:41 +020012#include <openbsc/talloc.h>
Harald Welte1fa60c82009-02-09 18:13:26 +000013
14#define SAPI_L2ML 0
15#define SAPI_OML 62
16#define SAPI_RSL 0 /* 63 ? */
17
Harald Welte42581822009-08-08 16:12:58 +020018/* 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 Welte1fa60c82009-02-09 18:13:26 +000021
Harald Welte42581822009-08-08 16:12:58 +020022int 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
51int 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
82int 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;
89 int rc;
90
91 printf("e1_reconfig_bts(%u)\n", bts->nr);
92
93 if (!e1_link->e1_ts)
94 return -EINVAL;
95
96 /* OML link */
97 line = e1inp_line_get_create(e1_link->e1_nr);
98 if (!line)
99 return -ENOMEM;
100 sign_ts = &line->ts[e1_link->e1_ts-1];
101 e1inp_ts_config(sign_ts, line, E1INP_TS_TYPE_SIGN);
102 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
103 bts->c0, bts->oml_tei, SAPI_OML);
104 if (!oml_link)
105 return -ENOMEM;
106 if (bts->oml_link)
107 e1inp_sign_link_destroy(bts->oml_link);
108 bts->oml_link = oml_link;
109
110 llist_for_each_entry(trx, &bts->trx_list, list)
111 e1_reconfig_trx(trx);
112
113 /* notify E1 input something has changed */
114 return e1inp_line_update(line);
115}
116
117#if 0
Harald Welte1fa60c82009-02-09 18:13:26 +0000118/* do some compiled-in configuration for our BTS/E1 setup */
Holger Freytherb5c00f52009-04-22 22:08:07 +0000119int e1_config(struct gsm_bts *bts, int cardnr, int release_l2)
Harald Welte1fa60c82009-02-09 18:13:26 +0000120{
121 struct e1inp_line *line;
122 struct e1inp_ts *sign_ts;
123 struct e1inp_sign_link *oml_link, *rsl_link;
Harald Welte67b4c302009-07-29 16:42:16 +0200124 struct gsm_bts_trx *trx = bts->c0;
Harald Welte4e55d682009-08-04 14:13:35 +0200125 int base_ts;
126
127 switch (bts->nr) {
128 case 0:
129 /* First BTS uses E1 TS 01,02,03,04,05 */
Harald Welte63589be2009-08-06 17:38:10 +0200130 base_ts = HARDCODED_BTS0_TS - 1;
Harald Welte4e55d682009-08-04 14:13:35 +0200131 break;
132 case 1:
Harald Welte63589be2009-08-06 17:38:10 +0200133 /* Second BTS uses E1 TS 06,07,08,09,10 */
134 base_ts = HARDCODED_BTS1_TS - 1;
Harald Welte4e55d682009-08-04 14:13:35 +0200135 break;
136 case 2:
Harald Welte63589be2009-08-06 17:38:10 +0200137 /* Third BTS uses E1 TS 11,12,13,14,15 */
138 base_ts = HARDCODED_BTS2_TS - 1;
Harald Welte4e55d682009-08-04 14:13:35 +0200139 default:
140 return -EINVAL;
141 }
Harald Welte1fa60c82009-02-09 18:13:26 +0000142
Harald Welte470ec292009-06-26 20:25:23 +0200143 line = talloc_zero(tall_bsc_ctx, struct e1inp_line);
Harald Welte1fa60c82009-02-09 18:13:26 +0000144 if (!line)
145 return -ENOMEM;
Harald Welte1fa60c82009-02-09 18:13:26 +0000146
147 /* create E1 timeslots for signalling and TRAU frames */
Harald Welte4e55d682009-08-04 14:13:35 +0200148 e1inp_ts_config(&line->ts[base_ts+1-1], line, E1INP_TS_TYPE_SIGN);
149 e1inp_ts_config(&line->ts[base_ts+2-1], line, E1INP_TS_TYPE_TRAU);
150 e1inp_ts_config(&line->ts[base_ts+3-1], line, E1INP_TS_TYPE_TRAU);
Harald Welte1fa60c82009-02-09 18:13:26 +0000151
152 /* create signalling links for TS1 */
Harald Welte4e55d682009-08-04 14:13:35 +0200153 sign_ts = &line->ts[base_ts+1-1];
Harald Welte1fa60c82009-02-09 18:13:26 +0000154 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
Harald Welte67b4c302009-07-29 16:42:16 +0200155 trx, TEI_OML, SAPI_OML);
Harald Welte1fa60c82009-02-09 18:13:26 +0000156 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
Harald Welte67b4c302009-07-29 16:42:16 +0200157 trx, TEI_RSL, SAPI_RSL);
Harald Welte1fa60c82009-02-09 18:13:26 +0000158
159 /* create back-links from bts/trx */
160 bts->oml_link = oml_link;
Harald Welte67b4c302009-07-29 16:42:16 +0200161 trx->rsl_link = rsl_link;
Harald Welte1fa60c82009-02-09 18:13:26 +0000162
Harald Welte11fa29c2009-02-19 17:24:39 +0000163 /* enable subchannel demuxer on TS2 */
Harald Welte4e55d682009-08-04 14:13:35 +0200164 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 1);
165 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 2);
166 subch_demux_activate(&line->ts[base_ts+2-1].trau.demux, 3);
Harald Welte93d3f372009-02-18 03:27:14 +0000167
Harald Welte11fa29c2009-02-19 17:24:39 +0000168 /* enable subchannel demuxer on TS3 */
Harald Welte4e55d682009-08-04 14:13:35 +0200169 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 0);
170 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 1);
171 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 2);
172 subch_demux_activate(&line->ts[base_ts+3-1].trau.demux, 3);
Harald Welte11fa29c2009-02-19 17:24:39 +0000173
Harald Welte67b4c302009-07-29 16:42:16 +0200174 trx = gsm_bts_trx_num(bts, 1);
175 if (trx) {
176 /* create E1 timeslots for TRAU frames of TRX1 */
Harald Welte4e55d682009-08-04 14:13:35 +0200177 e1inp_ts_config(&line->ts[base_ts+4-1], line, E1INP_TS_TYPE_TRAU);
178 e1inp_ts_config(&line->ts[base_ts+5-1], line, E1INP_TS_TYPE_TRAU);
Harald Welte1fa60c82009-02-09 18:13:26 +0000179
Harald Welte67b4c302009-07-29 16:42:16 +0200180 /* create RSL signalling link for TRX1 */
Harald Welte4e55d682009-08-04 14:13:35 +0200181 sign_ts = &line->ts[base_ts+1-1];
Harald Welte67b4c302009-07-29 16:42:16 +0200182 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
183 trx, TEI_RSL+1, SAPI_RSL);
184 /* create back-links from trx */
185 trx->rsl_link = rsl_link;
186
187 /* enable subchannel demuxer on TS2 */
Harald Welte4e55d682009-08-04 14:13:35 +0200188 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 0);
189 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 1);
190 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 2);
191 subch_demux_activate(&line->ts[base_ts+4-1].trau.demux, 3);
Harald Welte67b4c302009-07-29 16:42:16 +0200192
193 /* enable subchannel demuxer on TS3 */
Harald Welte4e55d682009-08-04 14:13:35 +0200194 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 0);
195 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 1);
196 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 2);
197 subch_demux_activate(&line->ts[base_ts+5-1].trau.demux, 3);
Harald Welte67b4c302009-07-29 16:42:16 +0200198 }
Harald Welte1fa60c82009-02-09 18:13:26 +0000199
Holger Freytherb5c00f52009-04-22 22:08:07 +0000200 return mi_setup(cardnr, line, release_l2);
Harald Welte1fa60c82009-02-09 18:13:26 +0000201}
Harald Welte42581822009-08-08 16:12:58 +0200202#endif
Harald Welte5fd8a542009-02-13 02:43:36 +0000203
Harald Welteedb37782009-05-01 14:59:07 +0000204/* configure pseudo E1 line in ip.access style and connect to BTS */
205int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin)
Harald Welte5fd8a542009-02-13 02:43:36 +0000206{
207 struct e1inp_line *line;
Harald Welte5c1e4582009-02-15 11:57:29 +0000208 struct e1inp_ts *sign_ts, *rsl_ts;
Harald Welte5fd8a542009-02-13 02:43:36 +0000209 struct e1inp_sign_link *oml_link, *rsl_link;
210
Harald Welte470ec292009-06-26 20:25:23 +0200211 line = talloc_zero(tall_bsc_ctx, struct e1inp_line);
Harald Welte5fd8a542009-02-13 02:43:36 +0000212 if (!line)
Harald Welte2cf161b2009-06-20 22:36:41 +0200213 return -ENOMEM;
Harald Welte5fd8a542009-02-13 02:43:36 +0000214
215 /* create E1 timeslots for signalling and TRAU frames */
216 e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN);
Harald Welte5c1e4582009-02-15 11:57:29 +0000217 e1inp_ts_config(&line->ts[2-1], line, E1INP_TS_TYPE_SIGN);
Harald Welte5fd8a542009-02-13 02:43:36 +0000218
219 /* create signalling links for TS1 */
220 sign_ts = &line->ts[1-1];
Harald Welte5c1e4582009-02-15 11:57:29 +0000221 rsl_ts = &line->ts[2-1];
Harald Welte5fd8a542009-02-13 02:43:36 +0000222 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
223 bts->c0, 0, 0xff);
Harald Welte5c1e4582009-02-15 11:57:29 +0000224 rsl_link = e1inp_sign_link_create(rsl_ts, E1INP_SIGN_RSL,
Harald Welte5fd8a542009-02-13 02:43:36 +0000225 bts->c0, 0, 0);
226
227 /* create back-links from bts/trx */
228 bts->oml_link = oml_link;
229 bts->c0->rsl_link = rsl_link;
230
Harald Welte25de9912009-04-30 15:53:07 +0000231 /* default port at BTS for incoming connections is 3006 */
232 if (sin->sin_port == 0)
233 sin->sin_port = htons(3006);
234
235 return ipaccess_connect(line, sin);
236}