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> |
| 31 | #include <openbsc/e1_input.h> |
| 32 | |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 33 | static int bts_model_hslfemto_start(struct gsm_network *net); |
| 34 | |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 35 | static struct gsm_bts_model model_hslfemto = { |
| 36 | .type = GSM_BTS_TYPE_HSL_FEMTO, |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 37 | .start = bts_model_hslfemto_start, |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 38 | .nm_att_tlvdef = { |
| 39 | .def = { |
| 40 | /* no HSL specific OML attributes that we know of */ |
| 41 | }, |
| 42 | }, |
| 43 | }; |
| 44 | |
| 45 | |
| 46 | static const uint8_t l1_msg[] = { |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 47 | #ifdef HSL_SR_1_0 |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 48 | 0x80, 0x8a, |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 49 | #else |
| 50 | 0x81, 0x8a, |
| 51 | #endif |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 52 | 0xC4, 0x0b, |
| 53 | }; |
| 54 | |
| 55 | static const uint8_t conn_trau_msg[] = { |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 56 | #ifdef HSL_SR_1_0 |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 57 | 0x80, 0x81, |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 58 | #else |
| 59 | 0x81, 0x81, |
| 60 | #endif |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 61 | 0xC1, 16, |
| 62 | 0x02, 0x00, 0x00, 0x00, 0xC0, 0xA8, 0xEA, 0x01, |
| 63 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 64 | }; |
| 65 | |
| 66 | static const uint8_t conn_trau_msg2[] = { |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 67 | #ifdef HSL_SR_1_0 |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 68 | 0x80, 0x81, |
Harald Welte | 7ce7bc5 | 2011-01-15 18:07:34 +0100 | [diff] [blame] | 69 | #else |
| 70 | 0x81, 0x81, |
| 71 | #endif |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 72 | 0xC1, 16, |
| 73 | 0x02, 0x00, 0xd4, 0x07, 0xC0, 0xA8, 0xEA, 0x01, |
| 74 | 0x38, 0xA4, 0x45, 0x00, 0x04, 0x59, 0x40, 0x00 |
| 75 | }; |
| 76 | |
| 77 | static uint8_t oml_arfcn_bsic[] = { |
Harald Welte | 6bddd82 | 2011-01-14 23:18:59 +0100 | [diff] [blame] | 78 | #ifdef HSL_SR_1_0 |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 79 | 0x81, 0x80, 0x00, 10, |
Harald Welte | 6bddd82 | 2011-01-14 23:18:59 +0100 | [diff] [blame] | 80 | #else |
| 81 | 0x80, 0x80, 0x00, 10, |
| 82 | #endif |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 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 | |
| 88 | static inline struct msgb *hsl_alloc_msgb(void) |
| 89 | { |
| 90 | return msgb_alloc_headroom(1024, 127, "HSL"); |
| 91 | } |
| 92 | |
| 93 | static 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 */ |
| 133 | static 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: |
Harald Welte | 51da091 | 2011-03-05 16:24:20 +0100 | [diff] [blame] | 145 | if (isd->trx->bts->type == GSM_BTS_TYPE_HSL_FEMTO) |
| 146 | hslfemto_bootstrap_om(isd->trx->bts); |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 147 | break; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 154 | static int bts_model_hslfemto_start(struct gsm_network *net) |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 155 | { |
| 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 | |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 162 | osmo_signal_register_handler(SS_INPUT, inp_sig_cb, NULL); |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 163 | |
Pablo Neira Ayuso | 5bd96a7 | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 164 | /* Call A-bis input driver, start socket for OML and RSL. */ |
| 165 | return hsl_setup(net); |
| 166 | } |
| 167 | |
| 168 | int bts_model_hslfemto_init(void) |
| 169 | { |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 170 | return gsm_bts_model_register(&model_hslfemto); |
| 171 | } |