Harald Welte | fd355a3 | 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 | |
Holger Hans Peter Freyther | 4dd84ff | 2012-09-11 12:33:51 +0200 | [diff] [blame] | 23 | #include <inttypes.h> |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 24 | |
| 25 | #include <arpa/inet.h> |
| 26 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 27 | #include <osmocom/gsm/tlv.h> |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 28 | #include <openbsc/gsm_data.h> |
| 29 | #include <openbsc/abis_nm.h> |
| 30 | #include <openbsc/abis_rsl.h> |
| 31 | #include <openbsc/signal.h> |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 32 | #include <openbsc/debug.h> |
| 33 | #include <osmocom/core/logging.h> |
| 34 | #include <osmocom/abis/e1_input.h> |
| 35 | #include <osmocom/abis/ipaccess.h> |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 36 | |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 37 | static int bts_model_hslfemto_start(struct gsm_network *net); |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 38 | static void bts_model_hslfemto_e1line_bind_ops(struct e1inp_line *line); |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 39 | |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 40 | static struct gsm_bts_model model_hslfemto = { |
| 41 | .type = GSM_BTS_TYPE_HSL_FEMTO, |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 42 | .start = bts_model_hslfemto_start, |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 43 | .e1line_bind_ops = &bts_model_hslfemto_e1line_bind_ops, |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 44 | .nm_att_tlvdef = { |
| 45 | .def = { |
| 46 | /* no HSL specific OML attributes that we know of */ |
| 47 | }, |
| 48 | }, |
| 49 | }; |
| 50 | |
| 51 | |
| 52 | static const uint8_t l1_msg[] = { |
Harald Welte | 388cbbf | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 53 | #ifdef HSL_SR_1_0 |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 54 | 0x80, 0x8a, |
Harald Welte | 388cbbf | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 55 | #else |
| 56 | 0x81, 0x8a, |
| 57 | #endif |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 58 | 0xC4, 0x0b, |
| 59 | }; |
| 60 | |
| 61 | static const uint8_t conn_trau_msg[] = { |
Harald Welte | 388cbbf | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 62 | #ifdef HSL_SR_1_0 |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 63 | 0x80, 0x81, |
Harald Welte | 388cbbf | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 64 | #else |
| 65 | 0x81, 0x81, |
| 66 | #endif |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 67 | 0xC1, 16, |
| 68 | 0x02, 0x00, 0x00, 0x00, 0xC0, 0xA8, 0xEA, 0x01, |
| 69 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 70 | }; |
| 71 | |
| 72 | static const uint8_t conn_trau_msg2[] = { |
Harald Welte | 388cbbf | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 73 | #ifdef HSL_SR_1_0 |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 74 | 0x80, 0x81, |
Harald Welte | 388cbbf | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 75 | #else |
| 76 | 0x81, 0x81, |
| 77 | #endif |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 78 | 0xC1, 16, |
| 79 | 0x02, 0x00, 0xd4, 0x07, 0xC0, 0xA8, 0xEA, 0x01, |
| 80 | 0x38, 0xA4, 0x45, 0x00, 0x04, 0x59, 0x40, 0x00 |
| 81 | }; |
| 82 | |
| 83 | static uint8_t oml_arfcn_bsic[] = { |
Harald Welte | 26d7907 | 2011-01-14 23:18:59 +0100 | [diff] [blame] | 84 | #ifdef HSL_SR_1_0 |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 85 | 0x81, 0x80, 0x00, 10, |
Harald Welte | 26d7907 | 2011-01-14 23:18:59 +0100 | [diff] [blame] | 86 | #else |
| 87 | 0x80, 0x80, 0x00, 10, |
| 88 | #endif |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 89 | NM_MT_SET_BTS_ATTR, NM_OC_BTS, 0xff, 0xff, 0xff, |
| 90 | NM_ATT_BCCH_ARFCN, 0x03, 0x67, |
| 91 | NM_ATT_BSIC, 0x00 |
| 92 | }; |
| 93 | |
| 94 | static inline struct msgb *hsl_alloc_msgb(void) |
| 95 | { |
| 96 | return msgb_alloc_headroom(1024, 127, "HSL"); |
| 97 | } |
| 98 | |
| 99 | static int hslfemto_bootstrap_om(struct gsm_bts *bts) |
| 100 | { |
| 101 | struct msgb *msg; |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 102 | |
| 103 | msg = hsl_alloc_msgb(); |
Holger Hans Peter Freyther | a5050b1 | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 104 | msgb_put(msg, sizeof(l1_msg)); |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 105 | memcpy(msg->data, l1_msg, sizeof(l1_msg)); |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 106 | msg->dst = bts->c0->rsl_link; |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 107 | abis_rsl_sendmsg(msg); |
| 108 | |
| 109 | #if 1 |
| 110 | msg = hsl_alloc_msgb(); |
Holger Hans Peter Freyther | a5050b1 | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 111 | msgb_put(msg, sizeof(conn_trau_msg)); |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 112 | memcpy(msg->data, conn_trau_msg, sizeof(conn_trau_msg)); |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 113 | msg->dst = bts->c0->rsl_link; |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 114 | abis_rsl_sendmsg(msg); |
| 115 | #endif |
| 116 | msg = hsl_alloc_msgb(); |
Holger Hans Peter Freyther | a5050b1 | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 117 | msgb_put(msg, sizeof(conn_trau_msg2)); |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 118 | memcpy(msg->data, conn_trau_msg2, sizeof(conn_trau_msg2)); |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 119 | msg->dst = bts->c0->rsl_link; |
Harald Welte | fd355a3 | 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(); |
Holger Hans Peter Freyther | a5050b1 | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 126 | msgb_put(msg, sizeof(oml_arfcn_bsic)); |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 127 | memcpy(msg->data, oml_arfcn_bsic, sizeof(oml_arfcn_bsic)); |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 128 | msg->dst = bts->c0->rsl_link; |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 129 | abis_sendmsg(msg); |
Harald Welte | fd355a3 | 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 | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 143 | if (subsys != SS_L_INPUT) |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 144 | return 0; |
| 145 | |
| 146 | switch (signal) { |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 147 | case S_L_INP_TEI_UP: |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 148 | switch (isd->link_type) { |
| 149 | case E1INP_SIGN_OML: |
Harald Welte | d4571f4 | 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 | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 152 | break; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 159 | static struct gsm_network *hsl_gsmnet; |
| 160 | |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 161 | static int bts_model_hslfemto_start(struct gsm_network *net) |
Harald Welte | fd355a3 | 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 | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 169 | osmo_signal_register_handler(SS_L_INPUT, inp_sig_cb, NULL); |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 170 | |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 171 | hsl_gsmnet = net; |
| 172 | return 0; |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | int bts_model_hslfemto_init(void) |
| 176 | { |
Harald Welte | fd355a3 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 177 | return gsm_bts_model_register(&model_hslfemto); |
| 178 | } |
Pablo Neira Ayuso | ed5cacb | 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 " |
Holger Hans Peter Freyther | 4dd84ff | 2012-09-11 12:33:51 +0200 | [diff] [blame] | 208 | "serial number %"PRIx64"\n", dev->serno); |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 209 | return NULL; |
| 210 | } |
Holger Hans Peter Freyther | 4dd84ff | 2012-09-11 12:33:51 +0200 | [diff] [blame] | 211 | DEBUGP(DLINP, "Identified HSL BTS Serial Number %"PRIx64"\n", dev->serno); |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 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 | { |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 232 | if (!bts->oml_link) |
| 233 | return; |
| 234 | |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 235 | e1inp_sign_link_destroy(bts->oml_link); |
| 236 | bts->oml_link = NULL; |
| 237 | |
| 238 | e1inp_sign_link_destroy(bts->c0->rsl_link); |
| 239 | bts->c0->rsl_link = NULL; |
| 240 | |
| 241 | bts->ip_access.flags = 0; |
| 242 | } |
| 243 | |
| 244 | static void hsl_sign_link_down(struct e1inp_line *line) |
| 245 | { |
| 246 | /* No matter what link went down, we close both signal links. */ |
| 247 | struct e1inp_ts *ts = &line->ts[E1INP_SIGN_OML-1]; |
| 248 | struct e1inp_sign_link *link; |
| 249 | |
| 250 | llist_for_each_entry(link, &ts->sign.sign_links, list) { |
| 251 | struct gsm_bts *bts = link->trx->bts; |
| 252 | |
| 253 | hsl_drop_oml(bts); |
| 254 | /* Yes, we only use the first element of the list. */ |
| 255 | break; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /* This function is called if we receive one OML/RSL message. */ |
| 260 | static int hsl_sign_link(struct msgb *msg) |
| 261 | { |
| 262 | int ret = 0; |
| 263 | struct e1inp_sign_link *link = msg->dst; |
| 264 | struct e1inp_ts *e1i_ts = link->ts; |
| 265 | |
| 266 | switch (link->type) { |
| 267 | case E1INP_SIGN_OML: |
| 268 | if (!(link->trx->bts->ip_access.flags & OML_UP)) { |
| 269 | e1inp_event(e1i_ts, S_L_INP_TEI_UP, |
| 270 | link->tei, link->sapi); |
| 271 | link->trx->bts->ip_access.flags |= OML_UP; |
| 272 | } |
| 273 | ret = abis_nm_rcvmsg(msg); |
| 274 | break; |
| 275 | case E1INP_SIGN_RSL: |
| 276 | if (!(link->trx->bts->ip_access.flags & |
| 277 | (RSL_UP << link->trx->nr))) { |
| 278 | e1inp_event(e1i_ts, S_L_INP_TEI_UP, |
| 279 | link->tei, link->sapi); |
| 280 | link->trx->bts->ip_access.flags |= |
| 281 | (RSL_UP << link->trx->nr); |
| 282 | } |
| 283 | ret = abis_rsl_rcvmsg(msg); |
| 284 | break; |
| 285 | default: |
| 286 | LOGP(DLINP, LOGL_ERROR, "Unknown signal link type %d\n", |
| 287 | link->type); |
| 288 | msgb_free(msg); |
| 289 | break; |
| 290 | } |
| 291 | return ret; |
| 292 | } |
| 293 | |
| 294 | static struct e1inp_line_ops hsl_e1inp_line_ops = { |
| 295 | .cfg = { |
| 296 | .ipa = { |
| 297 | .addr = "0.0.0.0", |
| 298 | .role = E1INP_LINE_R_BSC, |
| 299 | }, |
| 300 | }, |
| 301 | .sign_link_up = hsl_sign_link_up, |
| 302 | .sign_link_down = hsl_sign_link_down, |
| 303 | .sign_link = hsl_sign_link, |
| 304 | }; |
| 305 | |
| 306 | static void bts_model_hslfemto_e1line_bind_ops(struct e1inp_line *line) |
| 307 | { |
| 308 | e1inp_line_bind_ops(line, &hsl_e1inp_line_ops); |
| 309 | } |