Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 1 | #include <string.h> |
| 2 | #include <errno.h> |
| 3 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 4 | #include <netinet/in.h> |
| 5 | |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 6 | #include <openbsc/gsm_data.h> |
| 7 | #include <openbsc/e1_input.h> |
Harald Welte | 45b407a | 2009-05-23 15:51:12 +0000 | [diff] [blame] | 8 | #include <openbsc/trau_frame.h> |
Harald Welte | 39a1b71 | 2009-02-10 17:17:09 +0000 | [diff] [blame] | 9 | #include <openbsc/trau_mux.h> |
Holger Freyther | ff9592f | 2009-03-09 16:17:14 +0000 | [diff] [blame] | 10 | #include <openbsc/misdn.h> |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 11 | #include <openbsc/talloc.h> |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 12 | |
| 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 */ |
Holger Freyther | b5c00f5 | 2009-04-22 22:08:07 +0000 | [diff] [blame] | 22 | int e1_config(struct gsm_bts *bts, int cardnr, int release_l2) |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 23 | { |
| 24 | struct e1inp_line *line; |
| 25 | struct e1inp_ts *sign_ts; |
| 26 | struct e1inp_sign_link *oml_link, *rsl_link; |
| 27 | |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 28 | line = talloc(tall_bsc_ctx, struct e1inp_line); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 29 | if (!line) |
| 30 | return -ENOMEM; |
| 31 | memset(line, 0, sizeof(*line)); |
| 32 | |
| 33 | /* create E1 timeslots for signalling and TRAU frames */ |
| 34 | e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN); |
| 35 | e1inp_ts_config(&line->ts[2-1], line, E1INP_TS_TYPE_TRAU); |
Harald Welte | d47a4be | 2009-04-29 16:21:34 +0000 | [diff] [blame] | 36 | e1inp_ts_config(&line->ts[3-1], line, E1INP_TS_TYPE_TRAU); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 37 | |
| 38 | /* create signalling links for TS1 */ |
| 39 | sign_ts = &line->ts[1-1]; |
| 40 | oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, |
| 41 | bts->c0, TEI_OML, SAPI_OML); |
| 42 | rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL, |
| 43 | bts->c0, TEI_RSL, SAPI_RSL); |
| 44 | |
| 45 | /* create back-links from bts/trx */ |
| 46 | bts->oml_link = oml_link; |
| 47 | bts->c0->rsl_link = rsl_link; |
| 48 | |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 49 | /* enable subchannel demuxer on TS2 */ |
| 50 | subch_demux_activate(&line->ts[2-1].trau.demux, 1); |
| 51 | subch_demux_activate(&line->ts[2-1].trau.demux, 2); |
| 52 | subch_demux_activate(&line->ts[2-1].trau.demux, 3); |
Harald Welte | 93d3f37 | 2009-02-18 03:27:14 +0000 | [diff] [blame] | 53 | |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 54 | /* enable subchannel demuxer on TS3 */ |
| 55 | subch_demux_activate(&line->ts[3-1].trau.demux, 0); |
| 56 | subch_demux_activate(&line->ts[3-1].trau.demux, 1); |
| 57 | subch_demux_activate(&line->ts[3-1].trau.demux, 2); |
| 58 | subch_demux_activate(&line->ts[3-1].trau.demux, 3); |
Harald Welte | 11fa29c | 2009-02-19 17:24:39 +0000 | [diff] [blame] | 59 | |
Harald Welte | 39a1b71 | 2009-02-10 17:17:09 +0000 | [diff] [blame] | 60 | #ifdef HAVE_TRX1 |
| 61 | /* create E1 timeslots for TRAU frames of TRX1 */ |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 62 | e1inp_ts_config(&line->ts[4-1], line, E1INP_TS_TYPE_TRAU); |
| 63 | e1inp_ts_config(&line->ts[5-1], line, E1INP_TS_TYPE_TRAU); |
| 64 | |
Harald Welte | 39a1b71 | 2009-02-10 17:17:09 +0000 | [diff] [blame] | 65 | /* create RSL signalling link for TRX1 */ |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 66 | sign_ts = &line->ts[1-1]; |
| 67 | rsl_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_RSL, |
| 68 | &bts->trx[1], TEI_RSL+1, SAPI_RSL); |
| 69 | /* create back-links from trx */ |
| 70 | bts->trx[1].rsl_link = rsl_link; |
| 71 | #endif |
| 72 | |
Holger Freyther | b5c00f5 | 2009-04-22 22:08:07 +0000 | [diff] [blame] | 73 | return mi_setup(cardnr, line, release_l2); |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 74 | } |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 75 | |
Harald Welte | edb3778 | 2009-05-01 14:59:07 +0000 | [diff] [blame] | 76 | /* configure pseudo E1 line in ip.access style and connect to BTS */ |
| 77 | int ia_config_connect(struct gsm_bts *bts, struct sockaddr_in *sin) |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 78 | { |
| 79 | struct e1inp_line *line; |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 80 | struct e1inp_ts *sign_ts, *rsl_ts; |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 81 | struct e1inp_sign_link *oml_link, *rsl_link; |
| 82 | |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 83 | line = talloc(tall_bsc_ctx, struct e1inp_line); |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 84 | if (!line) |
Harald Welte | 2cf161b | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 85 | return -ENOMEM; |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 86 | memset(line, 0, sizeof(*line)); |
| 87 | |
| 88 | /* create E1 timeslots for signalling and TRAU frames */ |
| 89 | e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN); |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 90 | e1inp_ts_config(&line->ts[2-1], line, E1INP_TS_TYPE_SIGN); |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 91 | |
| 92 | /* create signalling links for TS1 */ |
| 93 | sign_ts = &line->ts[1-1]; |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 94 | rsl_ts = &line->ts[2-1]; |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 95 | oml_link = e1inp_sign_link_create(sign_ts, E1INP_SIGN_OML, |
| 96 | bts->c0, 0, 0xff); |
Harald Welte | 5c1e458 | 2009-02-15 11:57:29 +0000 | [diff] [blame] | 97 | rsl_link = e1inp_sign_link_create(rsl_ts, E1INP_SIGN_RSL, |
Harald Welte | 5fd8a54 | 2009-02-13 02:43:36 +0000 | [diff] [blame] | 98 | bts->c0, 0, 0); |
| 99 | |
| 100 | /* create back-links from bts/trx */ |
| 101 | bts->oml_link = oml_link; |
| 102 | bts->c0->rsl_link = rsl_link; |
| 103 | |
Harald Welte | 25de991 | 2009-04-30 15:53:07 +0000 | [diff] [blame] | 104 | /* default port at BTS for incoming connections is 3006 */ |
| 105 | if (sin->sin_port == 0) |
| 106 | sin->sin_port = htons(3006); |
| 107 | |
| 108 | return ipaccess_connect(line, sin); |
| 109 | } |