Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 1 | /* 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 Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 23 | |
| 24 | #include <arpa/inet.h> |
| 25 | |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 26 | #include <osmocom/gsm/tlv.h> |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 27 | #include <openbsc/gsm_data.h> |
| 28 | #include <openbsc/abis_nm.h> |
| 29 | #include <openbsc/abis_rsl.h> |
| 30 | #include <openbsc/signal.h> |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 31 | #include <openbsc/debug.h> |
| 32 | #include <osmocom/core/logging.h> |
| 33 | #include <osmocom/abis/e1_input.h> |
| 34 | #include <osmocom/abis/ipaccess.h> |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 35 | |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 36 | static int bts_model_hslfemto_start(struct gsm_network *net); |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 37 | static void bts_model_hslfemto_e1line_bind_ops(struct e1inp_line *line); |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 38 | |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 39 | static struct gsm_bts_model model_hslfemto = { |
| 40 | .type = GSM_BTS_TYPE_HSL_FEMTO, |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 41 | .start = bts_model_hslfemto_start, |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 42 | .e1line_bind_ops = &bts_model_hslfemto_e1line_bind_ops, |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 43 | .nm_att_tlvdef = { |
| 44 | .def = { |
| 45 | /* no HSL specific OML attributes that we know of */ |
| 46 | }, |
| 47 | }, |
| 48 | }; |
| 49 | |
| 50 | |
| 51 | static const uint8_t l1_msg[] = { |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 52 | #ifdef HSL_SR_1_0 |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 53 | 0x80, 0x8a, |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 54 | #else |
| 55 | 0x81, 0x8a, |
| 56 | #endif |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 57 | 0xC4, 0x0b, |
| 58 | }; |
| 59 | |
| 60 | static const uint8_t conn_trau_msg[] = { |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 61 | #ifdef HSL_SR_1_0 |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 62 | 0x80, 0x81, |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 63 | #else |
| 64 | 0x81, 0x81, |
| 65 | #endif |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 66 | 0xC1, 16, |
| 67 | 0x02, 0x00, 0x00, 0x00, 0xC0, 0xA8, 0xEA, 0x01, |
| 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 69 | }; |
| 70 | |
| 71 | static const uint8_t conn_trau_msg2[] = { |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 72 | #ifdef HSL_SR_1_0 |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 73 | 0x80, 0x81, |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 74 | #else |
| 75 | 0x81, 0x81, |
| 76 | #endif |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 77 | 0xC1, 16, |
| 78 | 0x02, 0x00, 0xd4, 0x07, 0xC0, 0xA8, 0xEA, 0x01, |
| 79 | 0x38, 0xA4, 0x45, 0x00, 0x04, 0x59, 0x40, 0x00 |
| 80 | }; |
| 81 | |
| 82 | static uint8_t oml_arfcn_bsic[] = { |
Harald Welte | 6bddd82 | 2011-01-14 23:18:59 +0100 | [diff] [blame] | 83 | #ifdef HSL_SR_1_0 |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 84 | 0x81, 0x80, 0x00, 10, |
Harald Welte | 6bddd82 | 2011-01-14 23:18:59 +0100 | [diff] [blame] | 85 | #else |
| 86 | 0x80, 0x80, 0x00, 10, |
| 87 | #endif |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 88 | NM_MT_SET_BTS_ATTR, NM_OC_BTS, 0xff, 0xff, 0xff, |
| 89 | NM_ATT_BCCH_ARFCN, 0x03, 0x67, |
| 90 | NM_ATT_BSIC, 0x00 |
| 91 | }; |
| 92 | |
| 93 | static inline struct msgb *hsl_alloc_msgb(void) |
| 94 | { |
| 95 | return msgb_alloc_headroom(1024, 127, "HSL"); |
| 96 | } |
| 97 | |
| 98 | static int hslfemto_bootstrap_om(struct gsm_bts *bts) |
| 99 | { |
| 100 | struct msgb *msg; |
| 101 | uint8_t *cur; |
| 102 | |
| 103 | msg = hsl_alloc_msgb(); |
| 104 | cur = msgb_put(msg, sizeof(l1_msg)); |
| 105 | memcpy(msg->data, l1_msg, sizeof(l1_msg)); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 106 | msg->dst = bts->c0->rsl_link; |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 107 | abis_rsl_sendmsg(msg); |
| 108 | |
| 109 | #if 1 |
| 110 | msg = hsl_alloc_msgb(); |
| 111 | cur = msgb_put(msg, sizeof(conn_trau_msg)); |
| 112 | memcpy(msg->data, conn_trau_msg, sizeof(conn_trau_msg)); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 113 | msg->dst = bts->c0->rsl_link; |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 114 | abis_rsl_sendmsg(msg); |
| 115 | #endif |
| 116 | msg = hsl_alloc_msgb(); |
| 117 | cur = msgb_put(msg, sizeof(conn_trau_msg2)); |
| 118 | memcpy(msg->data, conn_trau_msg2, sizeof(conn_trau_msg2)); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 119 | msg->dst = bts->c0->rsl_link; |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 120 | abis_rsl_sendmsg(msg); |
| 121 | |
| 122 | *((uint16_t *)oml_arfcn_bsic+10) = htons(bts->c0->arfcn); |
| 123 | oml_arfcn_bsic[13] = bts->bsic; |
| 124 | |
| 125 | msg = hsl_alloc_msgb(); |
| 126 | cur = msgb_put(msg, sizeof(oml_arfcn_bsic)); |
| 127 | memcpy(msg->data, oml_arfcn_bsic, sizeof(oml_arfcn_bsic)); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 128 | msg->dst = bts->c0->rsl_link; |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 129 | abis_sendmsg(msg); |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 130 | |
| 131 | /* Delay the OPSTART until after SI have been set via RSL */ |
| 132 | //abis_nm_opstart(bts, NM_OC_BTS, 255, 255, 255); |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | /* Callback function to be called every time we receive a signal from INPUT */ |
| 138 | static int inp_sig_cb(unsigned int subsys, unsigned int signal, |
| 139 | void *handler_data, void *signal_data) |
| 140 | { |
| 141 | struct input_signal_data *isd = signal_data; |
| 142 | |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 143 | if (subsys != SS_L_INPUT) |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 144 | return 0; |
| 145 | |
| 146 | switch (signal) { |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 147 | case S_L_INP_TEI_UP: |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 148 | switch (isd->link_type) { |
| 149 | case E1INP_SIGN_OML: |
Harald Welte | 51da091 | 2011-03-05 16:24:20 +0100 | [diff] [blame] | 150 | if (isd->trx->bts->type == GSM_BTS_TYPE_HSL_FEMTO) |
| 151 | hslfemto_bootstrap_om(isd->trx->bts); |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 152 | break; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 159 | static struct gsm_network *hsl_gsmnet; |
| 160 | |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 161 | static int bts_model_hslfemto_start(struct gsm_network *net) |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 162 | { |
| 163 | model_hslfemto.features.data = &model_hslfemto._features_data[0]; |
| 164 | model_hslfemto.features.data_len = sizeof(model_hslfemto._features_data); |
| 165 | |
| 166 | gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_GPRS); |
| 167 | gsm_btsmodel_set_feature(&model_hslfemto, BTS_FEAT_EGPRS); |
| 168 | |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 169 | osmo_signal_register_handler(SS_L_INPUT, inp_sig_cb, NULL); |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 170 | |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 171 | hsl_gsmnet = net; |
| 172 | return 0; |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | int bts_model_hslfemto_init(void) |
| 176 | { |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 177 | return gsm_bts_model_register(&model_hslfemto); |
| 178 | } |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 179 | |
| 180 | #define OML_UP 0x0001 |
| 181 | #define RSL_UP 0x0002 |
| 182 | |
| 183 | struct gsm_bts *find_bts_by_serno(struct gsm_network *net, uint64_t serno) |
| 184 | { |
| 185 | struct gsm_bts *bts; |
| 186 | |
| 187 | llist_for_each_entry(bts, &net->bts_list, list) { |
| 188 | if (bts->type != GSM_BTS_TYPE_HSL_FEMTO) |
| 189 | continue; |
| 190 | |
| 191 | if (serno == bts->hsl.serno) |
| 192 | return bts; |
| 193 | } |
| 194 | return NULL; |
| 195 | } |
| 196 | |
| 197 | /* This function is called once the OML/RSL link becomes up. */ |
| 198 | static struct e1inp_sign_link * |
| 199 | hsl_sign_link_up(void *unit_data, struct e1inp_line *line, |
| 200 | enum e1inp_sign_type type) |
| 201 | { |
| 202 | struct hsl_unit *dev = unit_data; |
| 203 | struct gsm_bts *bts; |
| 204 | |
| 205 | bts = find_bts_by_serno(hsl_gsmnet, dev->serno); |
| 206 | if (!bts) { |
| 207 | LOGP(DLINP, LOGL_ERROR, "Unable to find BTS config for " |
| 208 | "serial number %lx\n", dev->serno); |
| 209 | return NULL; |
| 210 | } |
| 211 | DEBUGP(DLINP, "Identified HSL BTS Serial Number %lx\n", dev->serno); |
| 212 | |
| 213 | /* we shouldn't hardcode it, but HSL femto also hardcodes it... */ |
| 214 | bts->oml_tei = 255; |
| 215 | bts->c0->rsl_tei = 0; |
| 216 | bts->oml_link = e1inp_sign_link_create(&line->ts[E1INP_SIGN_OML-1], |
| 217 | E1INP_SIGN_OML, bts->c0, |
| 218 | bts->oml_tei, 0); |
| 219 | bts->c0->rsl_link = e1inp_sign_link_create(&line->ts[E1INP_SIGN_OML-1], |
| 220 | E1INP_SIGN_RSL, bts->c0, |
| 221 | bts->c0->rsl_tei, 0); |
| 222 | e1inp_event(&line->ts[E1INP_SIGN_OML-1], S_L_INP_TEI_UP, 255, 0); |
| 223 | e1inp_event(&line->ts[E1INP_SIGN_OML-1], S_L_INP_TEI_UP, 0, 0); |
| 224 | bts->ip_access.flags |= OML_UP; |
| 225 | bts->ip_access.flags |= (RSL_UP << 0); |
| 226 | |
| 227 | return bts->oml_link; |
| 228 | } |
| 229 | |
| 230 | void hsl_drop_oml(struct gsm_bts *bts) |
| 231 | { |
| 232 | struct e1inp_line *line; |
| 233 | |
| 234 | if (!bts->oml_link) |
| 235 | return; |
| 236 | |
| 237 | line = bts->oml_link->ts->line; |
| 238 | e1inp_sign_link_destroy(bts->oml_link); |
| 239 | bts->oml_link = NULL; |
| 240 | |
| 241 | e1inp_sign_link_destroy(bts->c0->rsl_link); |
| 242 | bts->c0->rsl_link = NULL; |
| 243 | |
| 244 | bts->ip_access.flags = 0; |
| 245 | } |
| 246 | |
| 247 | static void hsl_sign_link_down(struct e1inp_line *line) |
| 248 | { |
| 249 | /* No matter what link went down, we close both signal links. */ |
| 250 | struct e1inp_ts *ts = &line->ts[E1INP_SIGN_OML-1]; |
| 251 | struct e1inp_sign_link *link; |
| 252 | |
| 253 | llist_for_each_entry(link, &ts->sign.sign_links, list) { |
| 254 | struct gsm_bts *bts = link->trx->bts; |
| 255 | |
| 256 | hsl_drop_oml(bts); |
| 257 | /* Yes, we only use the first element of the list. */ |
| 258 | break; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /* This function is called if we receive one OML/RSL message. */ |
| 263 | static int hsl_sign_link(struct msgb *msg) |
| 264 | { |
| 265 | int ret = 0; |
| 266 | struct e1inp_sign_link *link = msg->dst; |
| 267 | struct e1inp_ts *e1i_ts = link->ts; |
| 268 | |
| 269 | switch (link->type) { |
| 270 | case E1INP_SIGN_OML: |
| 271 | if (!(link->trx->bts->ip_access.flags & OML_UP)) { |
| 272 | e1inp_event(e1i_ts, S_L_INP_TEI_UP, |
| 273 | link->tei, link->sapi); |
| 274 | link->trx->bts->ip_access.flags |= OML_UP; |
| 275 | } |
| 276 | ret = abis_nm_rcvmsg(msg); |
| 277 | break; |
| 278 | case E1INP_SIGN_RSL: |
| 279 | if (!(link->trx->bts->ip_access.flags & |
| 280 | (RSL_UP << link->trx->nr))) { |
| 281 | e1inp_event(e1i_ts, S_L_INP_TEI_UP, |
| 282 | link->tei, link->sapi); |
| 283 | link->trx->bts->ip_access.flags |= |
| 284 | (RSL_UP << link->trx->nr); |
| 285 | } |
| 286 | ret = abis_rsl_rcvmsg(msg); |
| 287 | break; |
| 288 | default: |
| 289 | LOGP(DLINP, LOGL_ERROR, "Unknown signal link type %d\n", |
| 290 | link->type); |
| 291 | msgb_free(msg); |
| 292 | break; |
| 293 | } |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | static struct e1inp_line_ops hsl_e1inp_line_ops = { |
| 298 | .cfg = { |
| 299 | .ipa = { |
| 300 | .addr = "0.0.0.0", |
| 301 | .role = E1INP_LINE_R_BSC, |
| 302 | }, |
| 303 | }, |
| 304 | .sign_link_up = hsl_sign_link_up, |
| 305 | .sign_link_down = hsl_sign_link_down, |
| 306 | .sign_link = hsl_sign_link, |
| 307 | }; |
| 308 | |
| 309 | static void bts_model_hslfemto_e1line_bind_ops(struct e1inp_line *line) |
| 310 | { |
| 311 | e1inp_line_bind_ops(line, &hsl_e1inp_line_ops); |
| 312 | } |