blob: fc23b55e177af1b2c167679468eabfe5840370b3 [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>
Harald Welte1fa60c82009-02-09 18:13:26 +000011
12#define SAPI_L2ML 0
13#define SAPI_OML 62
14#define SAPI_RSL 0 /* 63 ? */
15
16#define TEI_L2ML 127
17#define TEI_OML 25
18#define TEI_RSL 1
19
20/* do some compiled-in configuration for our BTS/E1 setup */
Holger Freytherb5c00f52009-04-22 22:08:07 +000021int e1_config(struct gsm_bts *bts, int cardnr, int release_l2)
Harald Welte1fa60c82009-02-09 18:13:26 +000022{
23 struct e1inp_line *line;
24 struct e1inp_ts *sign_ts;
25 struct e1inp_sign_link *oml_link, *rsl_link;
26
27 line = malloc(sizeof(*line));
28 if (!line)
29 return -ENOMEM;
30 memset(line, 0, sizeof(*line));
31
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);
Harald Welted47a4be2009-04-29 16:21:34 +000035 e1inp_ts_config(&line->ts[3-1], line, E1INP_TS_TYPE_TRAU);
Harald Welte1fa60c82009-02-09 18:13:26 +000036
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
Harald Welte11fa29c2009-02-19 17:24:39 +000048 /* 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);
Harald Welte93d3f372009-02-18 03:27:14 +000052
Harald Welte11fa29c2009-02-19 17:24:39 +000053 /* 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);
Harald Welte11fa29c2009-02-19 17:24:39 +000058
Harald Welte39a1b712009-02-10 17:17:09 +000059#ifdef HAVE_TRX1
60 /* create E1 timeslots for TRAU frames of TRX1 */
Harald Welte1fa60c82009-02-09 18:13:26 +000061 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
Harald Welte39a1b712009-02-10 17:17:09 +000064 /* create RSL signalling link for TRX1 */
Harald Welte1fa60c82009-02-09 18:13:26 +000065 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
Holger Freytherb5c00f52009-04-22 22:08:07 +000072 return mi_setup(cardnr, line, release_l2);
Harald Welte1fa60c82009-02-09 18:13:26 +000073}
Harald Welte5fd8a542009-02-13 02:43:36 +000074
Harald Welteedb37782009-05-01 14:59:07 +000075/* configure pseudo E1 line in ip.access style and connect to BTS */
76int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin)
Harald Welte5fd8a542009-02-13 02:43:36 +000077{
78 struct e1inp_line *line;
Harald Welte5c1e4582009-02-15 11:57:29 +000079 struct e1inp_ts *sign_ts, *rsl_ts;
Harald Welte5fd8a542009-02-13 02:43:36 +000080 struct e1inp_sign_link *oml_link, *rsl_link;
81
82 line = malloc(sizeof(*line));
83 if (!line)
Harald Welte25de9912009-04-30 15:53:07 +000084 return NULL;
Harald Welte5fd8a542009-02-13 02:43:36 +000085 memset(line, 0, sizeof(*line));
86
87 /* create E1 timeslots for signalling and TRAU frames */
88 e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN);
Harald Welte5c1e4582009-02-15 11:57:29 +000089 e1inp_ts_config(&line->ts[2-1], line, E1INP_TS_TYPE_SIGN);
Harald Welte5fd8a542009-02-13 02:43:36 +000090
91 /* create signalling links for TS1 */
92 sign_ts = &line->ts[1-1];
Harald Welte5c1e4582009-02-15 11:57:29 +000093 rsl_ts = &line->ts[2-1];
Harald Welte5fd8a542009-02-13 02:43:36 +000094 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
95 bts->c0, 0, 0xff);
Harald Welte5c1e4582009-02-15 11:57:29 +000096 rsl_link = e1inp_sign_link_create(rsl_ts, E1INP_SIGN_RSL,
Harald Welte5fd8a542009-02-13 02:43:36 +000097 bts->c0, 0, 0);
98
99 /* create back-links from bts/trx */
100 bts->oml_link = oml_link;
101 bts->c0->rsl_link = rsl_link;
102
Harald Welte25de9912009-04-30 15:53:07 +0000103 /* default port at BTS for incoming connections is 3006 */
104 if (sin->sin_port == 0)
105 sin->sin_port = htons(3006);
106
107 return ipaccess_connect(line, sin);
108}