blob: 5e28ebffeda5d65b64676f83d9d45cd1c497e222 [file] [log] [blame]
Harald Weltefd355a32011-03-04 13:41:31 +01001/* OpenBSC support code for HSL Femtocell */
2
3/* (C) 2011 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2011 by OnWaves
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#include <sys/types.h>
24
25#include <arpa/inet.h>
26
27#include <osmocore/tlv.h>
28#include <openbsc/gsm_data.h>
29#include <openbsc/abis_nm.h>
30#include <openbsc/abis_rsl.h>
31#include <openbsc/signal.h>
32#include <openbsc/e1_input.h>
33
34static struct gsm_bts_model model_hslfemto = {
35 .type = GSM_BTS_TYPE_HSL_FEMTO,
36 .nm_att_tlvdef = {
37 .def = {
38 /* no HSL specific OML attributes that we know of */
39 },
40 },
41};
42
43
44static const uint8_t l1_msg[] = {
Harald Welte388cbbf2011-01-15 18:07:34 +010045#ifdef HSL_SR_1_0
Harald Weltefd355a32011-03-04 13:41:31 +010046 0x80, 0x8a,
Harald Welte388cbbf2011-01-15 18:07:34 +010047#else
48 0x81, 0x8a,
49#endif
Harald Weltefd355a32011-03-04 13:41:31 +010050 0xC4, 0x0b,
51};
52
53static const uint8_t conn_trau_msg[] = {
Harald Welte388cbbf2011-01-15 18:07:34 +010054#ifdef HSL_SR_1_0
Harald Weltefd355a32011-03-04 13:41:31 +010055 0x80, 0x81,
Harald Welte388cbbf2011-01-15 18:07:34 +010056#else
57 0x81, 0x81,
58#endif
Harald Weltefd355a32011-03-04 13:41:31 +010059 0xC1, 16,
60 0x02, 0x00, 0x00, 0x00, 0xC0, 0xA8, 0xEA, 0x01,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
62};
63
64static const uint8_t conn_trau_msg2[] = {
Harald Welte388cbbf2011-01-15 18:07:34 +010065#ifdef HSL_SR_1_0
Harald Weltefd355a32011-03-04 13:41:31 +010066 0x80, 0x81,
Harald Welte388cbbf2011-01-15 18:07:34 +010067#else
68 0x81, 0x81,
69#endif
Harald Weltefd355a32011-03-04 13:41:31 +010070 0xC1, 16,
71 0x02, 0x00, 0xd4, 0x07, 0xC0, 0xA8, 0xEA, 0x01,
72 0x38, 0xA4, 0x45, 0x00, 0x04, 0x59, 0x40, 0x00
73};
74
75static uint8_t oml_arfcn_bsic[] = {
Harald Welte26d79072011-01-14 23:18:59 +010076#ifdef HSL_SR_1_0
Harald Weltefd355a32011-03-04 13:41:31 +010077 0x81, 0x80, 0x00, 10,
Harald Welte26d79072011-01-14 23:18:59 +010078#else
79 0x80, 0x80, 0x00, 10,
80#endif
Harald Weltefd355a32011-03-04 13:41:31 +010081 NM_MT_SET_BTS_ATTR, NM_OC_BTS, 0xff, 0xff, 0xff,
82 NM_ATT_BCCH_ARFCN, 0x03, 0x67,
83 NM_ATT_BSIC, 0x00
84};
85
86static inline struct msgb *hsl_alloc_msgb(void)
87{
88 return msgb_alloc_headroom(1024, 127, "HSL");
89}
90
91static int hslfemto_bootstrap_om(struct gsm_bts *bts)
92{
93 struct msgb *msg;
94 uint8_t *cur;
95
96 msg = hsl_alloc_msgb();
97 cur = msgb_put(msg, sizeof(l1_msg));
98 memcpy(msg->data, l1_msg, sizeof(l1_msg));
99 msg->trx = bts->c0;
100 abis_rsl_sendmsg(msg);
101
102#if 1
103 msg = hsl_alloc_msgb();
104 cur = msgb_put(msg, sizeof(conn_trau_msg));
105 memcpy(msg->data, conn_trau_msg, sizeof(conn_trau_msg));
106 msg->trx = bts->c0;
107 abis_rsl_sendmsg(msg);
108#endif
109 msg = hsl_alloc_msgb();
110 cur = msgb_put(msg, sizeof(conn_trau_msg2));
111 memcpy(msg->data, conn_trau_msg2, sizeof(conn_trau_msg2));
112 msg->trx = bts->c0;
113 abis_rsl_sendmsg(msg);
114
115 *((uint16_t *)oml_arfcn_bsic+10) = htons(bts->c0->arfcn);
116 oml_arfcn_bsic[13] = bts->bsic;
117
118 msg = hsl_alloc_msgb();
119 cur = msgb_put(msg, sizeof(oml_arfcn_bsic));
120 memcpy(msg->data, oml_arfcn_bsic, sizeof(oml_arfcn_bsic));
121 msg->trx = bts->c0;
122 _abis_nm_sendmsg(msg, 0);
123
124 /* Delay the OPSTART until after SI have been set via RSL */
125 //abis_nm_opstart(bts, NM_OC_BTS, 255, 255, 255);
126
127 return 0;
128}
129
130/* Callback function to be called every time we receive a signal from INPUT */
131static int inp_sig_cb(unsigned int subsys, unsigned int signal,
132 void *handler_data, void *signal_data)
133{
134 struct input_signal_data *isd = signal_data;
135
136 if (subsys != SS_INPUT)
137 return 0;
138
139 switch (signal) {
140 case S_INP_TEI_UP:
141 switch (isd->link_type) {
142 case E1INP_SIGN_OML:
Harald Welted4571f42011-03-05 16:24:20 +0100143 if (isd->trx->bts->type == GSM_BTS_TYPE_HSL_FEMTO)
144 hslfemto_bootstrap_om(isd->trx->bts);
Harald Weltefd355a32011-03-04 13:41:31 +0100145 break;
146 }
147 }
148
149 return 0;
150}
151
152int bts_model_hslfemto_init(void)
153{
154 model_hslfemto.features.data = &model_hslfemto._features_data[0];
155 model_hslfemto.features.data_len = sizeof(model_hslfemto._features_data);
156
157 gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_GPRS);
158 gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_EGPRS);
159
160 register_signal_handler(SS_INPUT, inp_sig_cb, NULL);
161
162 return gsm_bts_model_register(&model_hslfemto);
163}