blob: f943693560e4172d6987605c1756e4a119bb7ce4 [file] [log] [blame]
Jonathan Santos03fd8d02011-05-25 13:54:02 -04001/* 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
Jonathan Santos03fd8d02011-05-25 13:54:02 -040023
24#include <arpa/inet.h>
25
Jonathan Santos5a45b152011-08-17 15:33:57 -040026#include <osmocom/gsm/tlv.h>
Jonathan Santos03fd8d02011-05-25 13:54:02 -040027#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
Jonathan Santos5a45b152011-08-17 15:33:57 -040033static int bts_model_hslfemto_start(struct gsm_network *net);
34
Jonathan Santos03fd8d02011-05-25 13:54:02 -040035static struct gsm_bts_model model_hslfemto = {
36 .type = GSM_BTS_TYPE_HSL_FEMTO,
Jonathan Santos5a45b152011-08-17 15:33:57 -040037 .start = bts_model_hslfemto_start,
Jonathan Santos03fd8d02011-05-25 13:54:02 -040038 .nm_att_tlvdef = {
39 .def = {
40 /* no HSL specific OML attributes that we know of */
41 },
42 },
43};
44
45
46static const uint8_t l1_msg[] = {
47#ifdef HSL_SR_1_0
48 0x80, 0x8a,
49#else
50 0x81, 0x8a,
51#endif
52 0xC4, 0x0b,
53};
54
55static const uint8_t conn_trau_msg[] = {
56#ifdef HSL_SR_1_0
57 0x80, 0x81,
58#else
59 0x81, 0x81,
60#endif
61 0xC1, 16,
62 0x02, 0x00, 0x00, 0x00, 0xC0, 0xA8, 0xEA, 0x01,
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
64};
65
66static const uint8_t conn_trau_msg2[] = {
67#ifdef HSL_SR_1_0
68 0x80, 0x81,
69#else
70 0x81, 0x81,
71#endif
72 0xC1, 16,
73 0x02, 0x00, 0xd4, 0x07, 0xC0, 0xA8, 0xEA, 0x01,
74 0x38, 0xA4, 0x45, 0x00, 0x04, 0x59, 0x40, 0x00
75};
76
77static uint8_t oml_arfcn_bsic[] = {
78#ifdef HSL_SR_1_0
79 0x81, 0x80, 0x00, 10,
80#else
81 0x80, 0x80, 0x00, 10,
82#endif
83 NM_MT_SET_BTS_ATTR, NM_OC_BTS, 0xff, 0xff, 0xff,
84 NM_ATT_BCCH_ARFCN, 0x03, 0x67,
85 NM_ATT_BSIC, 0x00
86};
87
88static inline struct msgb *hsl_alloc_msgb(void)
89{
90 return msgb_alloc_headroom(1024, 127, "HSL");
91}
92
93static int hslfemto_bootstrap_om(struct gsm_bts *bts)
94{
95 struct msgb *msg;
96 uint8_t *cur;
97
98 msg = hsl_alloc_msgb();
99 cur = msgb_put(msg, sizeof(l1_msg));
100 memcpy(msg->data, l1_msg, sizeof(l1_msg));
101 msg->trx = bts->c0;
102 abis_rsl_sendmsg(msg);
103
104#if 1
105 msg = hsl_alloc_msgb();
106 cur = msgb_put(msg, sizeof(conn_trau_msg));
107 memcpy(msg->data, conn_trau_msg, sizeof(conn_trau_msg));
108 msg->trx = bts->c0;
109 abis_rsl_sendmsg(msg);
110#endif
111 msg = hsl_alloc_msgb();
112 cur = msgb_put(msg, sizeof(conn_trau_msg2));
113 memcpy(msg->data, conn_trau_msg2, sizeof(conn_trau_msg2));
114 msg->trx = bts->c0;
115 abis_rsl_sendmsg(msg);
116
117 *((uint16_t *)oml_arfcn_bsic+10) = htons(bts->c0->arfcn);
118 oml_arfcn_bsic[13] = bts->bsic;
119
120 msg = hsl_alloc_msgb();
121 cur = msgb_put(msg, sizeof(oml_arfcn_bsic));
122 memcpy(msg->data, oml_arfcn_bsic, sizeof(oml_arfcn_bsic));
123 msg->trx = bts->c0;
124 _abis_nm_sendmsg(msg, 0);
125
126 /* Delay the OPSTART until after SI have been set via RSL */
127 //abis_nm_opstart(bts, NM_OC_BTS, 255, 255, 255);
128
129 return 0;
130}
131
132/* Callback function to be called every time we receive a signal from INPUT */
133static int inp_sig_cb(unsigned int subsys, unsigned int signal,
134 void *handler_data, void *signal_data)
135{
136 struct input_signal_data *isd = signal_data;
137
138 if (subsys != SS_INPUT)
139 return 0;
140
141 switch (signal) {
142 case S_INP_TEI_UP:
143 switch (isd->link_type) {
144 case E1INP_SIGN_OML:
Jonathan Santos5a45b152011-08-17 15:33:57 -0400145 if (isd->trx->bts->type == GSM_BTS_TYPE_HSL_FEMTO)
146 hslfemto_bootstrap_om(isd->trx->bts);
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400147 break;
148 }
149 }
150
151 return 0;
152}
153
Jonathan Santos5a45b152011-08-17 15:33:57 -0400154static int bts_model_hslfemto_start(struct gsm_network *net)
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400155{
156 model_hslfemto.features.data = &model_hslfemto._features_data[0];
157 model_hslfemto.features.data_len = sizeof(model_hslfemto._features_data);
158
159 gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_GPRS);
160 gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_EGPRS);
161
Jonathan Santos5a45b152011-08-17 15:33:57 -0400162 osmo_signal_register_handler(SS_INPUT, inp_sig_cb, NULL);
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400163
Jonathan Santos5a45b152011-08-17 15:33:57 -0400164 /* Call A-bis input driver, start socket for OML and RSL. */
165 return hsl_setup(net);
166}
167
168int bts_model_hslfemto_init(void)
169{
Jonathan Santos03fd8d02011-05-25 13:54:02 -0400170 return gsm_bts_model_register(&model_hslfemto);
171}