blob: 9bbf6d2cca5aa9d75978f7459c780b0beeaece06 [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
Harald Weltefd355a32011-03-04 13:41:31 +010023
24#include <arpa/inet.h>
25
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010026#include <osmocom/gsm/tlv.h>
Harald Weltefd355a32011-03-04 13:41:31 +010027#include <openbsc/gsm_data.h>
28#include <openbsc/abis_nm.h>
29#include <openbsc/abis_rsl.h>
30#include <openbsc/signal.h>
31#include <openbsc/e1_input.h>
32
33static struct gsm_bts_model model_hslfemto = {
34 .type = GSM_BTS_TYPE_HSL_FEMTO,
35 .nm_att_tlvdef = {
36 .def = {
37 /* no HSL specific OML attributes that we know of */
38 },
39 },
40};
41
42
43static const uint8_t l1_msg[] = {
Harald Welte388cbbf2011-01-15 18:07:34 +010044#ifdef HSL_SR_1_0
Harald Weltefd355a32011-03-04 13:41:31 +010045 0x80, 0x8a,
Harald Welte388cbbf2011-01-15 18:07:34 +010046#else
47 0x81, 0x8a,
48#endif
Harald Weltefd355a32011-03-04 13:41:31 +010049 0xC4, 0x0b,
50};
51
52static const uint8_t conn_trau_msg[] = {
Harald Welte388cbbf2011-01-15 18:07:34 +010053#ifdef HSL_SR_1_0
Harald Weltefd355a32011-03-04 13:41:31 +010054 0x80, 0x81,
Harald Welte388cbbf2011-01-15 18:07:34 +010055#else
56 0x81, 0x81,
57#endif
Harald Weltefd355a32011-03-04 13:41:31 +010058 0xC1, 16,
59 0x02, 0x00, 0x00, 0x00, 0xC0, 0xA8, 0xEA, 0x01,
60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
61};
62
63static const uint8_t conn_trau_msg2[] = {
Harald Welte388cbbf2011-01-15 18:07:34 +010064#ifdef HSL_SR_1_0
Harald Weltefd355a32011-03-04 13:41:31 +010065 0x80, 0x81,
Harald Welte388cbbf2011-01-15 18:07:34 +010066#else
67 0x81, 0x81,
68#endif
Harald Weltefd355a32011-03-04 13:41:31 +010069 0xC1, 16,
70 0x02, 0x00, 0xd4, 0x07, 0xC0, 0xA8, 0xEA, 0x01,
71 0x38, 0xA4, 0x45, 0x00, 0x04, 0x59, 0x40, 0x00
72};
73
74static uint8_t oml_arfcn_bsic[] = {
Harald Welte26d79072011-01-14 23:18:59 +010075#ifdef HSL_SR_1_0
Harald Weltefd355a32011-03-04 13:41:31 +010076 0x81, 0x80, 0x00, 10,
Harald Welte26d79072011-01-14 23:18:59 +010077#else
78 0x80, 0x80, 0x00, 10,
79#endif
Harald Weltefd355a32011-03-04 13:41:31 +010080 NM_MT_SET_BTS_ATTR, NM_OC_BTS, 0xff, 0xff, 0xff,
81 NM_ATT_BCCH_ARFCN, 0x03, 0x67,
82 NM_ATT_BSIC, 0x00
83};
84
85static inline struct msgb *hsl_alloc_msgb(void)
86{
87 return msgb_alloc_headroom(1024, 127, "HSL");
88}
89
90static int hslfemto_bootstrap_om(struct gsm_bts *bts)
91{
92 struct msgb *msg;
93 uint8_t *cur;
94
95 msg = hsl_alloc_msgb();
96 cur = msgb_put(msg, sizeof(l1_msg));
97 memcpy(msg->data, l1_msg, sizeof(l1_msg));
98 msg->trx = bts->c0;
99 abis_rsl_sendmsg(msg);
100
101#if 1
102 msg = hsl_alloc_msgb();
103 cur = msgb_put(msg, sizeof(conn_trau_msg));
104 memcpy(msg->data, conn_trau_msg, sizeof(conn_trau_msg));
105 msg->trx = bts->c0;
106 abis_rsl_sendmsg(msg);
107#endif
108 msg = hsl_alloc_msgb();
109 cur = msgb_put(msg, sizeof(conn_trau_msg2));
110 memcpy(msg->data, conn_trau_msg2, sizeof(conn_trau_msg2));
111 msg->trx = bts->c0;
112 abis_rsl_sendmsg(msg);
113
114 *((uint16_t *)oml_arfcn_bsic+10) = htons(bts->c0->arfcn);
115 oml_arfcn_bsic[13] = bts->bsic;
116
117 msg = hsl_alloc_msgb();
118 cur = msgb_put(msg, sizeof(oml_arfcn_bsic));
119 memcpy(msg->data, oml_arfcn_bsic, sizeof(oml_arfcn_bsic));
120 msg->trx = bts->c0;
121 _abis_nm_sendmsg(msg, 0);
122
123 /* Delay the OPSTART until after SI have been set via RSL */
124 //abis_nm_opstart(bts, NM_OC_BTS, 255, 255, 255);
125
126 return 0;
127}
128
129/* Callback function to be called every time we receive a signal from INPUT */
130static int inp_sig_cb(unsigned int subsys, unsigned int signal,
131 void *handler_data, void *signal_data)
132{
133 struct input_signal_data *isd = signal_data;
134
135 if (subsys != SS_INPUT)
136 return 0;
137
138 switch (signal) {
139 case S_INP_TEI_UP:
140 switch (isd->link_type) {
141 case E1INP_SIGN_OML:
Harald Welted4571f42011-03-05 16:24:20 +0100142 if (isd->trx->bts->type == GSM_BTS_TYPE_HSL_FEMTO)
143 hslfemto_bootstrap_om(isd->trx->bts);
Harald Weltefd355a32011-03-04 13:41:31 +0100144 break;
145 }
146 }
147
148 return 0;
149}
150
151int bts_model_hslfemto_init(void)
152{
153 model_hslfemto.features.data = &model_hslfemto._features_data[0];
154 model_hslfemto.features.data_len = sizeof(model_hslfemto._features_data);
155
156 gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_GPRS);
157 gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_EGPRS);
158
159 register_signal_handler(SS_INPUT, inp_sig_cb, NULL);
160
161 return gsm_bts_model_register(&model_hslfemto);
162}