blob: d5834ef7d8a75dd95e25f15c52bc81c77398ccbe [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[] = {
45 0x80, 0x8a,
46 0xC4, 0x0b,
47};
48
49static const uint8_t conn_trau_msg[] = {
50 0x80, 0x81,
51 0xC1, 16,
52 0x02, 0x00, 0x00, 0x00, 0xC0, 0xA8, 0xEA, 0x01,
53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
54};
55
56static const uint8_t conn_trau_msg2[] = {
57 0x80, 0x81,
58 0xC1, 16,
59 0x02, 0x00, 0xd4, 0x07, 0xC0, 0xA8, 0xEA, 0x01,
60 0x38, 0xA4, 0x45, 0x00, 0x04, 0x59, 0x40, 0x00
61};
62
63static uint8_t oml_arfcn_bsic[] = {
Harald Welte26d79072011-01-14 23:18:59 +010064#ifdef HSL_SR_1_0
Harald Weltefd355a32011-03-04 13:41:31 +010065 0x81, 0x80, 0x00, 10,
Harald Welte26d79072011-01-14 23:18:59 +010066#else
67 0x80, 0x80, 0x00, 10,
68#endif
Harald Weltefd355a32011-03-04 13:41:31 +010069 NM_MT_SET_BTS_ATTR, NM_OC_BTS, 0xff, 0xff, 0xff,
70 NM_ATT_BCCH_ARFCN, 0x03, 0x67,
71 NM_ATT_BSIC, 0x00
72};
73
74static inline struct msgb *hsl_alloc_msgb(void)
75{
76 return msgb_alloc_headroom(1024, 127, "HSL");
77}
78
79static int hslfemto_bootstrap_om(struct gsm_bts *bts)
80{
81 struct msgb *msg;
82 uint8_t *cur;
83
84 msg = hsl_alloc_msgb();
85 cur = msgb_put(msg, sizeof(l1_msg));
86 memcpy(msg->data, l1_msg, sizeof(l1_msg));
87 msg->trx = bts->c0;
88 abis_rsl_sendmsg(msg);
89
90#if 1
91 msg = hsl_alloc_msgb();
92 cur = msgb_put(msg, sizeof(conn_trau_msg));
93 memcpy(msg->data, conn_trau_msg, sizeof(conn_trau_msg));
94 msg->trx = bts->c0;
95 abis_rsl_sendmsg(msg);
96#endif
97 msg = hsl_alloc_msgb();
98 cur = msgb_put(msg, sizeof(conn_trau_msg2));
99 memcpy(msg->data, conn_trau_msg2, sizeof(conn_trau_msg2));
100 msg->trx = bts->c0;
101 abis_rsl_sendmsg(msg);
102
103 *((uint16_t *)oml_arfcn_bsic+10) = htons(bts->c0->arfcn);
104 oml_arfcn_bsic[13] = bts->bsic;
105
106 msg = hsl_alloc_msgb();
107 cur = msgb_put(msg, sizeof(oml_arfcn_bsic));
108 memcpy(msg->data, oml_arfcn_bsic, sizeof(oml_arfcn_bsic));
109 msg->trx = bts->c0;
110 _abis_nm_sendmsg(msg, 0);
111
112 /* Delay the OPSTART until after SI have been set via RSL */
113 //abis_nm_opstart(bts, NM_OC_BTS, 255, 255, 255);
114
115 return 0;
116}
117
118/* Callback function to be called every time we receive a signal from INPUT */
119static int inp_sig_cb(unsigned int subsys, unsigned int signal,
120 void *handler_data, void *signal_data)
121{
122 struct input_signal_data *isd = signal_data;
123
124 if (subsys != SS_INPUT)
125 return 0;
126
127 switch (signal) {
128 case S_INP_TEI_UP:
129 switch (isd->link_type) {
130 case E1INP_SIGN_OML:
131 hslfemto_bootstrap_om(isd->trx->bts);
132 break;
133 }
134 }
135
136 return 0;
137}
138
139int bts_model_hslfemto_init(void)
140{
141 model_hslfemto.features.data = &model_hslfemto._features_data[0];
142 model_hslfemto.features.data_len = sizeof(model_hslfemto._features_data);
143
144 gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_GPRS);
145 gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_EGPRS);
146
147 register_signal_handler(SS_INPUT, inp_sig_cb, NULL);
148
149 return gsm_bts_model_register(&model_hslfemto);
150}