Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 1 | /* Ericsson RBS-2xxx specific code */ |
| 2 | |
| 3 | /* (C) 2011 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <osmocore/tlv.h> |
| 25 | |
| 26 | #include <openbsc/debug.h> |
| 27 | #include <openbsc/gsm_data.h> |
Harald Welte | 9a311ec | 2011-02-12 12:33:06 +0100 | [diff] [blame] | 28 | #include <openbsc/abis_om2000.h> |
Harald Welte | 1484d88 | 2011-03-06 22:12:24 +0100 | [diff] [blame^] | 29 | #include <openbsc/abis_nm.h> |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 30 | #include <openbsc/e1_input.h> |
| 31 | #include <openbsc/signal.h> |
| 32 | |
Harald Welte | 89579b4 | 2011-03-04 13:18:30 +0100 | [diff] [blame] | 33 | #include "../libabis/input/lapd.h" |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 34 | |
Harald Welte | 9f0866c | 2011-02-13 19:44:47 +0100 | [diff] [blame] | 35 | static void bootstrap_om_bts(struct gsm_bts *bts) |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 36 | { |
| 37 | LOGP(DNM, LOGL_NOTICE, "bootstrapping OML for BTS %u\n", bts->nr); |
Harald Welte | 7354107 | 2011-02-12 13:44:14 +0100 | [diff] [blame] | 38 | abis_om2k_tx_start_req(bts, &om2k_mo_cf); |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 39 | /* FIXME */ |
| 40 | } |
| 41 | |
Harald Welte | 9f0866c | 2011-02-13 19:44:47 +0100 | [diff] [blame] | 42 | static void bootstrap_om_trx(struct gsm_bts_trx *trx) |
| 43 | { |
Harald Welte | 1484d88 | 2011-03-06 22:12:24 +0100 | [diff] [blame^] | 44 | struct abis_om2k_mo trx_mo = { OM2K_MO_CLS_TRXC, 0, 255, trx->nr }; |
| 45 | |
Harald Welte | 9f0866c | 2011-02-13 19:44:47 +0100 | [diff] [blame] | 46 | LOGP(DNM, LOGL_NOTICE, "bootstrapping OML for TRX %u/%u\n", |
| 47 | trx->bts->nr, trx->nr); |
Harald Welte | 1484d88 | 2011-03-06 22:12:24 +0100 | [diff] [blame^] | 48 | |
| 49 | abis_om2k_tx_reset_cmd(trx->bts, &trx_mo); |
Harald Welte | 9f0866c | 2011-02-13 19:44:47 +0100 | [diff] [blame] | 50 | } |
| 51 | |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 52 | static int shutdown_om(struct gsm_bts *bts) |
| 53 | { |
| 54 | /* FIXME */ |
| 55 | return 0; |
| 56 | } |
| 57 | |
Harald Welte | dcf42e6 | 2011-02-13 11:58:21 +0100 | [diff] [blame] | 58 | |
| 59 | /* Tell LAPD to start start the SAP (send SABM requests) for all signalling |
| 60 | * timeslots in this line */ |
Harald Welte | 174a51a | 2011-02-13 14:26:54 +0100 | [diff] [blame] | 61 | static void start_sabm_in_line(struct e1inp_line *line, int start) |
Harald Welte | dcf42e6 | 2011-02-13 11:58:21 +0100 | [diff] [blame] | 62 | { |
| 63 | struct e1inp_sign_link *link; |
| 64 | int i; |
| 65 | |
| 66 | for (i = 0; i < ARRAY_SIZE(line->ts); i++) { |
| 67 | struct e1inp_ts *ts = &line->ts[i]; |
| 68 | |
| 69 | if (ts->type != E1INP_TS_TYPE_SIGN) |
| 70 | continue; |
| 71 | |
| 72 | llist_for_each_entry(link, &ts->sign.sign_links, list) { |
Harald Welte | 174a51a | 2011-02-13 14:26:54 +0100 | [diff] [blame] | 73 | if (start) |
| 74 | lapd_sap_start(ts->driver.dahdi.lapd, link->tei, link->sapi); |
| 75 | else |
| 76 | lapd_sap_stop(ts->driver.dahdi.lapd, link->tei, link->sapi); |
Harald Welte | dcf42e6 | 2011-02-13 11:58:21 +0100 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 81 | /* Callback function to be called every time we receive a signal from INPUT */ |
| 82 | static int gbl_sig_cb(unsigned int subsys, unsigned int signal, |
| 83 | void *handler_data, void *signal_data) |
| 84 | { |
| 85 | struct gsm_bts *bts; |
| 86 | |
| 87 | if (subsys != SS_GLOBAL) |
| 88 | return 0; |
| 89 | |
| 90 | switch (signal) { |
| 91 | case S_GLOBAL_BTS_CLOSE_OM: |
| 92 | bts = signal_data; |
| 93 | if (bts->type == GSM_BTS_TYPE_RBS2000) |
| 94 | shutdown_om(signal_data); |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 101 | /* Callback function to be called every time we receive a signal from INPUT */ |
| 102 | static int inp_sig_cb(unsigned int subsys, unsigned int signal, |
| 103 | void *handler_data, void *signal_data) |
| 104 | { |
| 105 | struct input_signal_data *isd = signal_data; |
| 106 | |
| 107 | if (subsys != SS_INPUT) |
| 108 | return 0; |
| 109 | |
| 110 | switch (signal) { |
| 111 | case S_INP_TEI_UP: |
| 112 | switch (isd->link_type) { |
| 113 | case E1INP_SIGN_OML: |
Harald Welte | 9f0866c | 2011-02-13 19:44:47 +0100 | [diff] [blame] | 114 | if (isd->trx->bts->type != GSM_BTS_TYPE_RBS2000) |
| 115 | break; |
| 116 | if (isd->tei == isd->trx->bts->oml_tei) |
| 117 | bootstrap_om_bts(isd->trx->bts); |
| 118 | else |
| 119 | bootstrap_om_trx(isd->trx); |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 120 | break; |
| 121 | } |
Harald Welte | 03cc8a8 | 2011-02-11 18:59:31 +0100 | [diff] [blame] | 122 | break; |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 123 | case S_INP_LINE_INIT: |
| 124 | /* Right now Ericsson RBS are only supported on DAHDI */ |
| 125 | if (strcasecmp(isd->line->driver->name, "DAHDI")) |
| 126 | break; |
Harald Welte | 174a51a | 2011-02-13 14:26:54 +0100 | [diff] [blame] | 127 | start_sabm_in_line(isd->line, 1); |
| 128 | break; |
| 129 | case S_INP_LINE_ALARM: |
| 130 | if (strcasecmp(isd->line->driver->name, "DAHDI")) |
| 131 | break; |
| 132 | start_sabm_in_line(isd->line, 0); |
| 133 | break; |
| 134 | case S_INP_LINE_NOALARM: |
| 135 | if (strcasecmp(isd->line->driver->name, "DAHDI")) |
| 136 | break; |
| 137 | start_sabm_in_line(isd->line, 1); |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 138 | break; |
| 139 | } |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
Harald Welte | 1484d88 | 2011-03-06 22:12:24 +0100 | [diff] [blame^] | 144 | static void nm_statechg_evt(unsigned int signal, |
| 145 | struct nm_statechg_signal_data *nsd) |
| 146 | { |
| 147 | struct abis_om2k_mo mo; |
| 148 | |
| 149 | if (nsd->bts->type != GSM_BTS_TYPE_RBS2000) |
| 150 | return; |
| 151 | |
| 152 | switch (nsd->om2k_mo->class) { |
| 153 | case OM2K_MO_CLS_CF: |
| 154 | if (nsd->new_state->operational != NM_OPSTATE_ENABLED || |
| 155 | nsd->new_state->availability != OM2K_MO_S_STARTED) |
| 156 | break; |
| 157 | /* CF has started, we can trigger IS and TF start */ |
| 158 | abis_om2k_tx_connect_cmd(nsd->bts, &om2k_mo_is); |
| 159 | abis_om2k_tx_connect_cmd(nsd->bts, &om2k_mo_tf); |
| 160 | break; |
| 161 | case OM2K_MO_CLS_IS: |
| 162 | if (nsd->new_state->availability == OM2K_MO_S_ENABLED) { |
| 163 | /* IS is enabled, we can proceed with TRXC/RX/TX/TS */ |
| 164 | } |
| 165 | if (nsd->new_state->operational != NM_OPSTATE_ENABLED || |
| 166 | nsd->new_state->availability == OM2K_MO_S_DISABLED) |
| 167 | break; |
| 168 | /* IS has started, we can configure + enable it */ |
| 169 | abis_om2k_tx_is_conf_req(nsd->bts); |
| 170 | abis_om2k_tx_enable_req(nsd->bts, nsd->om2k_mo); |
| 171 | break; |
| 172 | case OM2K_MO_CLS_TF: |
| 173 | if (nsd->new_state->operational != NM_OPSTATE_ENABLED || |
| 174 | nsd->new_state->availability == OM2K_MO_S_DISABLED) |
| 175 | break; |
| 176 | if (nsd->new_state->availability == OM2K_MO_S_STARTED) { |
| 177 | /* TF has started, configure + enable it */ |
| 178 | abis_om2k_tx_is_conf_req(nsd->bts); |
| 179 | abis_om2k_tx_enable_req(nsd->bts, nsd->om2k_mo); |
| 180 | } |
| 181 | break; |
| 182 | case OM2K_MO_CLS_TRXC: |
| 183 | if (nsd->new_state->operational != NM_OPSTATE_ENABLED || |
| 184 | nsd->new_state->availability != OM2K_MO_S_STARTED) |
| 185 | break; |
| 186 | /* TRXC is started, connect the TX and RX objects */ |
| 187 | memcpy(&mo, nsd->om2k_mo, sizeof(mo)); |
| 188 | mo.class = OM2K_MO_CLS_TX; |
| 189 | abis_om2k_tx_connect_cmd(nsd->bts, &mo); |
| 190 | mo.class = OM2K_MO_CLS_RX; |
| 191 | abis_om2k_tx_connect_cmd(nsd->bts, &mo); |
| 192 | break; |
| 193 | case OM2K_MO_CLS_RX: |
| 194 | if (nsd->new_state->operational != NM_OPSTATE_ENABLED || |
| 195 | nsd->new_state->availability != OM2K_MO_S_STARTED) |
| 196 | break; |
| 197 | /* RX is started, configure + enable it */ |
| 198 | abis_om2k_tx_rx_conf_req(nsd->obj); |
| 199 | abis_om2k_tx_enable_req(nsd->bts, nsd->om2k_mo); |
| 200 | break; |
| 201 | case OM2K_MO_CLS_TX: |
| 202 | if (nsd->new_state->operational != NM_OPSTATE_ENABLED || |
| 203 | nsd->new_state->availability != OM2K_MO_S_STARTED) |
| 204 | break; |
| 205 | /* RX is started, configure + enable it */ |
| 206 | abis_om2k_tx_tx_conf_req(nsd->obj); |
| 207 | abis_om2k_tx_enable_req(nsd->bts, nsd->om2k_mo); |
| 208 | break; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | static int nm_sig_cb(unsigned int subsys, unsigned int signal, |
| 213 | void *handler_data, void *signal_data) |
| 214 | { |
| 215 | if (subsys != SS_NM) |
| 216 | return 0; |
| 217 | |
| 218 | switch (signal) { |
| 219 | case S_NM_STATECHG_OPER: |
| 220 | case S_NM_STATECHG_ADM: |
| 221 | nm_statechg_evt(signal, signal_data); |
| 222 | default: |
| 223 | break; |
| 224 | } |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
Harald Welte | 59eee42 | 2011-02-14 16:17:49 +0100 | [diff] [blame] | 229 | static void config_write_bts(struct vty *vty, struct gsm_bts *bts) |
| 230 | { |
| 231 | abis_om2k_config_write_bts(vty, bts); |
| 232 | } |
| 233 | |
| 234 | static struct gsm_bts_model model_rbs2k = { |
| 235 | .type = GSM_BTS_TYPE_RBS2000, |
| 236 | .name = "rbs2000", |
| 237 | .oml_rcvmsg = &abis_om2k_rcvmsg, |
| 238 | .config_write_bts = &config_write_bts, |
| 239 | }; |
| 240 | |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 241 | int bts_model_rbs2k_init(void) |
| 242 | { |
| 243 | model_rbs2k.features.data = &model_rbs2k._features_data[0]; |
| 244 | model_rbs2k.features.data_len = sizeof(model_rbs2k._features_data); |
| 245 | |
| 246 | gsm_btsmodel_set_feature(&model_rbs2k, BTS_FEAT_HOPPING); |
| 247 | gsm_btsmodel_set_feature(&model_rbs2k, BTS_FEAT_HSCSD); |
| 248 | |
| 249 | register_signal_handler(SS_INPUT, inp_sig_cb, NULL); |
| 250 | register_signal_handler(SS_GLOBAL, gbl_sig_cb, NULL); |
Harald Welte | 1484d88 | 2011-03-06 22:12:24 +0100 | [diff] [blame^] | 251 | register_signal_handler(SS_NM, nm_sig_cb, NULL); |
Harald Welte | db44f60 | 2011-02-11 18:36:18 +0100 | [diff] [blame] | 252 | |
| 253 | return gsm_bts_model_register(&model_rbs2k); |
| 254 | } |