blob: 9c9f40cffc60866a66300e8b9639ca3f983a85ec [file] [log] [blame]
Harald Welte59b04682009-06-10 05:40:52 +08001#include <string.h>
2#include <errno.h>
3
4#include <netinet/in.h>
5
6#include <openbsc/gsm_data.h>
7#include <openbsc/e1_input.h>
8#include <openbsc/trau_frame.h>
9#include <openbsc/trau_mux.h>
10#include <openbsc/misdn.h>
Harald Weltea8379772009-06-20 22:36:41 +020011#include <openbsc/talloc.h>
Harald Welte59b04682009-06-10 05:40:52 +080012
13#define SAPI_L2ML 0
14#define SAPI_OML 62
15#define SAPI_RSL 0 /* 63 ? */
16
17#define TEI_L2ML 127
18#define TEI_OML 25
19#define TEI_RSL 1
20
21/* do some compiled-in configuration for our BTS/E1 setup */
22int e1_config(struct gsm_bts *bts, int cardnr, int release_l2)
23{
24 struct e1inp_line *line;
25 struct e1inp_ts *sign_ts;
26 struct e1inp_sign_link *oml_link, *rsl_link;
27
Harald Welte857e00d2009-06-26 20:25:23 +020028 line = talloc_zero(tall_bsc_ctx, struct e1inp_line);
Harald Welte59b04682009-06-10 05:40:52 +080029 if (!line)
30 return -ENOMEM;
Harald Welte59b04682009-06-10 05:40:52 +080031
32 /* create E1 timeslots for signalling and TRAU frames */
33 e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN);
34 e1inp_ts_config(&line->ts[2-1], line, E1INP_TS_TYPE_TRAU);
35 e1inp_ts_config(&line->ts[3-1], line, E1INP_TS_TYPE_TRAU);
36
37 /* create signalling links for TS1 */
38 sign_ts = &line->ts[1-1];
39 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
40 bts->c0, TEI_OML, SAPI_OML);
41 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
42 bts->c0, TEI_RSL, SAPI_RSL);
43
44 /* create back-links from bts/trx */
45 bts->oml_link = oml_link;
46 bts->c0->rsl_link = rsl_link;
47
48 /* enable subchannel demuxer on TS2 */
49 subch_demux_activate(&line->ts[2-1].trau.demux, 1);
50 subch_demux_activate(&line->ts[2-1].trau.demux, 2);
51 subch_demux_activate(&line->ts[2-1].trau.demux, 3);
52
53 /* enable subchannel demuxer on TS3 */
54 subch_demux_activate(&line->ts[3-1].trau.demux, 0);
55 subch_demux_activate(&line->ts[3-1].trau.demux, 1);
56 subch_demux_activate(&line->ts[3-1].trau.demux, 2);
57 subch_demux_activate(&line->ts[3-1].trau.demux, 3);
58
59#ifdef HAVE_TRX1
60 /* create E1 timeslots for TRAU frames of TRX1 */
61 e1inp_ts_config(&line->ts[4-1], line, E1INP_TS_TYPE_TRAU);
62 e1inp_ts_config(&line->ts[5-1], line, E1INP_TS_TYPE_TRAU);
63
64 /* create RSL signalling link for TRX1 */
65 sign_ts = &line->ts[1-1];
66 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
67 &bts->trx[1], TEI_RSL+1, SAPI_RSL);
68 /* create back-links from trx */
69 bts->trx[1].rsl_link = rsl_link;
70#endif
71
72 return mi_setup(cardnr, line, release_l2);
73}
74
75/* configure pseudo E1 line in ip.access style and connect to BTS */
76int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin)
77{
78 struct e1inp_line *line;
79 struct e1inp_ts *sign_ts, *rsl_ts;
80 struct e1inp_sign_link *oml_link, *rsl_link;
81
Harald Welte857e00d2009-06-26 20:25:23 +020082 line = talloc_zero(tall_bsc_ctx, struct e1inp_line);
Harald Welte59b04682009-06-10 05:40:52 +080083 if (!line)
Harald Weltea8379772009-06-20 22:36:41 +020084 return -ENOMEM;
Harald Welte59b04682009-06-10 05:40:52 +080085
86 /* create E1 timeslots for signalling and TRAU frames */
87 e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN);
88 e1inp_ts_config(&line->ts[2-1], line, E1INP_TS_TYPE_SIGN);
89
90 /* create signalling links for TS1 */
91 sign_ts = &line->ts[1-1];
92 rsl_ts = &line->ts[2-1];
93 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
94 bts->c0, 0, 0xff);
95 rsl_link = e1inp_sign_link_create(rsl_ts, E1INP_SIGN_RSL,
96 bts->c0, 0, 0);
97
98 /* create back-links from bts/trx */
99 bts->oml_link = oml_link;
100 bts->c0->rsl_link = rsl_link;
101
102 /* default port at BTS for incoming connections is 3006 */
103 if (sin->sin_port == 0)
104 sin->sin_port = htons(3006);
105
106 return ipaccess_connect(line, sin);
107}