blob: 02fdb5d8334bd790af126f233f0f8a965e3709eb [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 Welte39a1b712009-02-10 17:17:09 +00008#include <openbsc/trau_mux.h>
Holger Freytherff9592f2009-03-09 16:17:14 +00009#include <openbsc/misdn.h>
Harald Welte1fa60c82009-02-09 18:13:26 +000010
11#define SAPI_L2ML 0
12#define SAPI_OML 62
13#define SAPI_RSL 0 /* 63 ? */
14
15#define TEI_L2ML 127
16#define TEI_OML 25
17#define TEI_RSL 1
18
19/* do some compiled-in configuration for our BTS/E1 setup */
Holger Freytherb5c00f52009-04-22 22:08:07 +000020int e1_config(struct gsm_bts *bts, int cardnr, int release_l2)
Harald Welte1fa60c82009-02-09 18:13:26 +000021{
22 struct e1inp_line *line;
23 struct e1inp_ts *sign_ts;
24 struct e1inp_sign_link *oml_link, *rsl_link;
25
26 line = malloc(sizeof(*line));
27 if (!line)
28 return -ENOMEM;
29 memset(line, 0, sizeof(*line));
30
31 /* create E1 timeslots for signalling and TRAU frames */
32 e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN);
33 e1inp_ts_config(&line->ts[2-1], line, E1INP_TS_TYPE_TRAU);
Harald Welted47a4be2009-04-29 16:21:34 +000034 e1inp_ts_config(&line->ts[3-1], line, E1INP_TS_TYPE_TRAU);
Harald Welte1fa60c82009-02-09 18:13:26 +000035
36 /* create signalling links for TS1 */
37 sign_ts = &line->ts[1-1];
38 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
39 bts->c0, TEI_OML, SAPI_OML);
40 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
41 bts->c0, TEI_RSL, SAPI_RSL);
42
43 /* create back-links from bts/trx */
44 bts->oml_link = oml_link;
45 bts->c0->rsl_link = rsl_link;
46
Harald Welte11fa29c2009-02-19 17:24:39 +000047 /* enable subchannel demuxer on TS2 */
48 subch_demux_activate(&line->ts[2-1].trau.demux, 1);
49 subch_demux_activate(&line->ts[2-1].trau.demux, 2);
50 subch_demux_activate(&line->ts[2-1].trau.demux, 3);
Harald Welte93d3f372009-02-18 03:27:14 +000051
Harald Welte11fa29c2009-02-19 17:24:39 +000052 /* enable subchannel demuxer on TS3 */
53 subch_demux_activate(&line->ts[3-1].trau.demux, 0);
54 subch_demux_activate(&line->ts[3-1].trau.demux, 1);
55 subch_demux_activate(&line->ts[3-1].trau.demux, 2);
56 subch_demux_activate(&line->ts[3-1].trau.demux, 3);
Harald Welte11fa29c2009-02-19 17:24:39 +000057
Harald Welte39a1b712009-02-10 17:17:09 +000058#ifdef HAVE_TRX1
59 /* create E1 timeslots for TRAU frames of TRX1 */
Harald Welte1fa60c82009-02-09 18:13:26 +000060 e1inp_ts_config(&line->ts[4-1], line, E1INP_TS_TYPE_TRAU);
61 e1inp_ts_config(&line->ts[5-1], line, E1INP_TS_TYPE_TRAU);
62
Harald Welte39a1b712009-02-10 17:17:09 +000063 /* create RSL signalling link for TRX1 */
Harald Welte1fa60c82009-02-09 18:13:26 +000064 sign_ts = &line->ts[1-1];
65 rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL,
66 &bts->trx[1], TEI_RSL+1, SAPI_RSL);
67 /* create back-links from trx */
68 bts->trx[1].rsl_link = rsl_link;
69#endif
70
Holger Freytherb5c00f52009-04-22 22:08:07 +000071 return mi_setup(cardnr, line, release_l2);
Harald Welte1fa60c82009-02-09 18:13:26 +000072}
Harald Welte5fd8a542009-02-13 02:43:36 +000073
74/* do some compiled-in configuration for our BTS/E1 setup */
Harald Welte25de9912009-04-30 15:53:07 +000075static struct e1inp_line *__ia_config(struct gsm_bts *bts)
Harald Welte5fd8a542009-02-13 02:43:36 +000076{
77 struct e1inp_line *line;
Harald Welte5c1e4582009-02-15 11:57:29 +000078 struct e1inp_ts *sign_ts, *rsl_ts;
Harald Welte5fd8a542009-02-13 02:43:36 +000079 struct e1inp_sign_link *oml_link, *rsl_link;
80
81 line = malloc(sizeof(*line));
82 if (!line)
Harald Welte25de9912009-04-30 15:53:07 +000083 return NULL;
Harald Welte5fd8a542009-02-13 02:43:36 +000084 memset(line, 0, sizeof(*line));
85
86 /* create E1 timeslots for signalling and TRAU frames */
87 e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN);
Harald Welte5c1e4582009-02-15 11:57:29 +000088 e1inp_ts_config(&line->ts[2-1], line, E1INP_TS_TYPE_SIGN);
Harald Welte5fd8a542009-02-13 02:43:36 +000089
90 /* create signalling links for TS1 */
91 sign_ts = &line->ts[1-1];
Harald Welte5c1e4582009-02-15 11:57:29 +000092 rsl_ts = &line->ts[2-1];
Harald Welte5fd8a542009-02-13 02:43:36 +000093 oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML,
94 bts->c0, 0, 0xff);
Harald Welte5c1e4582009-02-15 11:57:29 +000095 rsl_link = e1inp_sign_link_create(rsl_ts, E1INP_SIGN_RSL,
Harald Welte5fd8a542009-02-13 02:43:36 +000096 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
Harald Welte25de9912009-04-30 15:53:07 +0000102 return line;
103}
104
105/* configure pseudo E1 line in ip.access style and create listening socket */
106int ia_config(struct gsm_bts *bts)
107{
108 struct e1inp_line *line;
109
110 line = __ia_config(bts);
111 if (!line)
112 return -ENOMEM;
113
Harald Welte5fd8a542009-02-13 02:43:36 +0000114 return ipaccess_setup(line);
115}
Harald Welte25de9912009-04-30 15:53:07 +0000116
117/* configure pseudo E1 line in ip.access style and connect to BTS */
118int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin)
119{
120 struct e1inp_line *line;
121
122 line = __ia_config(bts);
123 if (!line)
124 return -ENOMEM;
125
126 /* default port at BTS for incoming connections is 3006 */
127 if (sin->sin_port == 0)
128 sin->sin_port = htons(3006);
129
130 return ipaccess_connect(line, sin);
131}