blob: 2813195b248c101c8ea4652a36a438fdafdc915d [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[] = {
64 0x81, 0x80, 0x00, 10,
65 NM_MT_SET_BTS_ATTR, NM_OC_BTS, 0xff, 0xff, 0xff,
66 NM_ATT_BCCH_ARFCN, 0x03, 0x67,
67 NM_ATT_BSIC, 0x00
68};
69
70static inline struct msgb *hsl_alloc_msgb(void)
71{
72 return msgb_alloc_headroom(1024, 127, "HSL");
73}
74
75static int hslfemto_bootstrap_om(struct gsm_bts *bts)
76{
77 struct msgb *msg;
78 uint8_t *cur;
79
80 msg = hsl_alloc_msgb();
81 cur = msgb_put(msg, sizeof(l1_msg));
82 memcpy(msg->data, l1_msg, sizeof(l1_msg));
83 msg->trx = bts->c0;
84 abis_rsl_sendmsg(msg);
85
86#if 1
87 msg = hsl_alloc_msgb();
88 cur = msgb_put(msg, sizeof(conn_trau_msg));
89 memcpy(msg->data, conn_trau_msg, sizeof(conn_trau_msg));
90 msg->trx = bts->c0;
91 abis_rsl_sendmsg(msg);
92#endif
93 msg = hsl_alloc_msgb();
94 cur = msgb_put(msg, sizeof(conn_trau_msg2));
95 memcpy(msg->data, conn_trau_msg2, sizeof(conn_trau_msg2));
96 msg->trx = bts->c0;
97 abis_rsl_sendmsg(msg);
98
99 *((uint16_t *)oml_arfcn_bsic+10) = htons(bts->c0->arfcn);
100 oml_arfcn_bsic[13] = bts->bsic;
101
102 msg = hsl_alloc_msgb();
103 cur = msgb_put(msg, sizeof(oml_arfcn_bsic));
104 memcpy(msg->data, oml_arfcn_bsic, sizeof(oml_arfcn_bsic));
105 msg->trx = bts->c0;
106 _abis_nm_sendmsg(msg, 0);
107
108 /* Delay the OPSTART until after SI have been set via RSL */
109 //abis_nm_opstart(bts, NM_OC_BTS, 255, 255, 255);
110
111 return 0;
112}
113
114/* Callback function to be called every time we receive a signal from INPUT */
115static int inp_sig_cb(unsigned int subsys, unsigned int signal,
116 void *handler_data, void *signal_data)
117{
118 struct input_signal_data *isd = signal_data;
119
120 if (subsys != SS_INPUT)
121 return 0;
122
123 switch (signal) {
124 case S_INP_TEI_UP:
125 switch (isd->link_type) {
126 case E1INP_SIGN_OML:
127 hslfemto_bootstrap_om(isd->trx->bts);
128 break;
129 }
130 }
131
132 return 0;
133}
134
135int bts_model_hslfemto_init(void)
136{
137 model_hslfemto.features.data = &model_hslfemto._features_data[0];
138 model_hslfemto.features.data_len = sizeof(model_hslfemto._features_data);
139
140 gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_GPRS);
141 gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_EGPRS);
142
143 register_signal_handler(SS_INPUT, inp_sig_cb, NULL);
144
145 return gsm_bts_model_register(&model_hslfemto);
146}