Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 1 | /* ip.access nanoBTS specific code */ |
| 2 | |
| 3 | /* (C) 2009-2010 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 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 |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 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/>. |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 22 | #include <arpa/inet.h> |
| 23 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 24 | #include <osmocom/gsm/tlv.h> |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 25 | |
| 26 | #include <openbsc/gsm_data.h> |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 27 | #include <openbsc/signal.h> |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 28 | #include <openbsc/abis_nm.h> |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 29 | #include <osmocom/abis/e1_input.h> |
| 30 | #include <osmocom/gsm/tlv.h> |
| 31 | #include <osmocom/core/msgb.h> |
| 32 | #include <osmocom/core/talloc.h> |
| 33 | #include <openbsc/gsm_data.h> |
| 34 | #include <openbsc/abis_nm.h> |
| 35 | #include <openbsc/abis_rsl.h> |
| 36 | #include <openbsc/debug.h> |
| 37 | #include <osmocom/abis/subchan_demux.h> |
| 38 | #include <osmocom/abis/ipaccess.h> |
| 39 | #include <osmocom/core/logging.h> |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 40 | |
| 41 | static int bts_model_nanobts_start(struct gsm_network *net); |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 42 | static void bts_model_nanobts_e1line_bind_ops(struct e1inp_line *line); |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 43 | |
| 44 | static struct gsm_bts_model model_nanobts = { |
| 45 | .type = GSM_BTS_TYPE_NANOBTS, |
Harald Welte | 09cefee | 2011-02-12 12:29:21 +0100 | [diff] [blame] | 46 | .name = "nanobts", |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 47 | .start = bts_model_nanobts_start, |
Harald Welte | 09cefee | 2011-02-12 12:29:21 +0100 | [diff] [blame] | 48 | .oml_rcvmsg = &abis_nm_rcvmsg, |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 49 | .e1line_bind_ops = bts_model_nanobts_e1line_bind_ops, |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 50 | .nm_att_tlvdef = { |
| 51 | .def = { |
| 52 | /* ip.access specifics */ |
| 53 | [NM_ATT_IPACC_DST_IP] = { TLV_TYPE_FIXED, 4 }, |
| 54 | [NM_ATT_IPACC_DST_IP_PORT] = { TLV_TYPE_FIXED, 2 }, |
| 55 | [NM_ATT_IPACC_STREAM_ID] = { TLV_TYPE_TV, }, |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 56 | [NM_ATT_IPACC_SEC_OML_CFG] = { TLV_TYPE_FIXED, 6 }, |
| 57 | [NM_ATT_IPACC_IP_IF_CFG] = { TLV_TYPE_FIXED, 8 }, |
| 58 | [NM_ATT_IPACC_IP_GW_CFG] = { TLV_TYPE_FIXED, 12 }, |
| 59 | [NM_ATT_IPACC_IN_SERV_TIME] = { TLV_TYPE_FIXED, 4 }, |
| 60 | [NM_ATT_IPACC_LOCATION] = { TLV_TYPE_TL16V }, |
| 61 | [NM_ATT_IPACC_PAGING_CFG] = { TLV_TYPE_FIXED, 2 }, |
| 62 | [NM_ATT_IPACC_UNIT_ID] = { TLV_TYPE_TL16V }, |
| 63 | [NM_ATT_IPACC_UNIT_NAME] = { TLV_TYPE_TL16V }, |
| 64 | [NM_ATT_IPACC_SNMP_CFG] = { TLV_TYPE_TL16V }, |
| 65 | [NM_ATT_IPACC_PRIM_OML_CFG_LIST] = { TLV_TYPE_TL16V }, |
| 66 | [NM_ATT_IPACC_NV_FLAGS] = { TLV_TYPE_TL16V }, |
| 67 | [NM_ATT_IPACC_FREQ_CTRL] = { TLV_TYPE_FIXED, 2 }, |
| 68 | [NM_ATT_IPACC_PRIM_OML_FB_TOUT] = { TLV_TYPE_TL16V }, |
| 69 | [NM_ATT_IPACC_CUR_SW_CFG] = { TLV_TYPE_TL16V }, |
| 70 | [NM_ATT_IPACC_TIMING_BUS] = { TLV_TYPE_TL16V }, |
| 71 | [NM_ATT_IPACC_CGI] = { TLV_TYPE_TL16V }, |
| 72 | [NM_ATT_IPACC_RAC] = { TLV_TYPE_TL16V }, |
| 73 | [NM_ATT_IPACC_OBJ_VERSION] = { TLV_TYPE_TL16V }, |
| 74 | [NM_ATT_IPACC_GPRS_PAGING_CFG]= { TLV_TYPE_TL16V }, |
| 75 | [NM_ATT_IPACC_NSEI] = { TLV_TYPE_TL16V }, |
| 76 | [NM_ATT_IPACC_BVCI] = { TLV_TYPE_TL16V }, |
| 77 | [NM_ATT_IPACC_NSVCI] = { TLV_TYPE_TL16V }, |
| 78 | [NM_ATT_IPACC_NS_CFG] = { TLV_TYPE_TL16V }, |
| 79 | [NM_ATT_IPACC_BSSGP_CFG] = { TLV_TYPE_TL16V }, |
| 80 | [NM_ATT_IPACC_NS_LINK_CFG] = { TLV_TYPE_TL16V }, |
| 81 | [NM_ATT_IPACC_RLC_CFG] = { TLV_TYPE_TL16V }, |
| 82 | [NM_ATT_IPACC_ALM_THRESH_LIST]= { TLV_TYPE_TL16V }, |
| 83 | [NM_ATT_IPACC_MONIT_VAL_LIST] = { TLV_TYPE_TL16V }, |
| 84 | [NM_ATT_IPACC_TIB_CONTROL] = { TLV_TYPE_TL16V }, |
| 85 | [NM_ATT_IPACC_SUPP_FEATURES] = { TLV_TYPE_TL16V }, |
| 86 | [NM_ATT_IPACC_CODING_SCHEMES] = { TLV_TYPE_TL16V }, |
| 87 | [NM_ATT_IPACC_RLC_CFG_2] = { TLV_TYPE_TL16V }, |
| 88 | [NM_ATT_IPACC_HEARTB_TOUT] = { TLV_TYPE_TL16V }, |
| 89 | [NM_ATT_IPACC_UPTIME] = { TLV_TYPE_TL16V }, |
| 90 | [NM_ATT_IPACC_RLC_CFG_3] = { TLV_TYPE_TL16V }, |
| 91 | [NM_ATT_IPACC_SSL_CFG] = { TLV_TYPE_TL16V }, |
| 92 | [NM_ATT_IPACC_SEC_POSSIBLE] = { TLV_TYPE_TL16V }, |
| 93 | [NM_ATT_IPACC_IML_SSL_STATE] = { TLV_TYPE_TL16V }, |
| 94 | [NM_ATT_IPACC_REVOC_DATE] = { TLV_TYPE_TL16V }, |
| 95 | }, |
| 96 | }, |
| 97 | }; |
| 98 | |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 99 | static unsigned char nanobts_attr_bts[] = { |
| 100 | NM_ATT_INTERF_BOUND, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73, |
| 101 | /* interference avg. period in numbers of SACCH multifr */ |
| 102 | NM_ATT_INTAVE_PARAM, 0x06, |
| 103 | /* conn fail based on SACCH error rate */ |
| 104 | NM_ATT_CONN_FAIL_CRIT, 0x00, 0x02, 0x01, 0x10, |
| 105 | NM_ATT_T200, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21, 0xa8, |
| 106 | NM_ATT_MAX_TA, 0x3f, |
| 107 | NM_ATT_OVERL_PERIOD, 0x00, 0x01, 10, /* seconds */ |
| 108 | NM_ATT_CCCH_L_T, 10, /* percent */ |
| 109 | NM_ATT_CCCH_L_I_P, 1, /* seconds */ |
| 110 | NM_ATT_RACH_B_THRESH, 10, /* busy threshold in - dBm */ |
| 111 | NM_ATT_LDAVG_SLOTS, 0x03, 0xe8, /* rach load averaging 1000 slots */ |
| 112 | NM_ATT_BTS_AIR_TIMER, 128, /* miliseconds */ |
| 113 | NM_ATT_NY1, 10, /* 10 retransmissions of physical config */ |
| 114 | NM_ATT_BCCH_ARFCN, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff, |
| 115 | NM_ATT_BSIC, HARDCODED_BSIC, |
Harald Welte | e86b3eb | 2011-06-27 21:15:59 +0200 | [diff] [blame] | 116 | NM_ATT_IPACC_CGI, 0, 7, 0x00, 0xf1, 0x10, 0x00, 0x01, 0x00, 0x00, |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | static unsigned char nanobts_attr_radio[] = { |
| 120 | NM_ATT_RF_MAXPOWR_R, 0x0c, /* number of -2dB reduction steps / Pn */ |
| 121 | NM_ATT_ARFCN_LIST, 0x00, 0x02, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff, |
| 122 | }; |
| 123 | |
| 124 | static unsigned char nanobts_attr_nse[] = { |
| 125 | NM_ATT_IPACC_NSEI, 0, 2, 0x03, 0x9d, /* NSEI 925 */ |
Harald Welte | c95175f | 2012-06-28 08:42:37 +0200 | [diff] [blame] | 126 | /* all timers in seconds */ |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 127 | NM_ATT_IPACC_NS_CFG, 0, 7, 3, /* (un)blocking timer (Tns-block) */ |
| 128 | 3, /* (un)blocking retries */ |
| 129 | 3, /* reset timer (Tns-reset) */ |
| 130 | 3, /* reset retries */ |
| 131 | 30, /* test timer (Tns-test) */ |
| 132 | 3, /* alive timer (Tns-alive) */ |
| 133 | 10, /* alive retrires */ |
Harald Welte | c95175f | 2012-06-28 08:42:37 +0200 | [diff] [blame] | 134 | /* all timers in seconds, unless otherwise stated */ |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 135 | NM_ATT_IPACC_BSSGP_CFG, 0, 11, |
| 136 | 3, /* blockimg timer (T1) */ |
| 137 | 3, /* blocking retries */ |
| 138 | 3, /* unblocking retries */ |
Harald Welte | c95175f | 2012-06-28 08:42:37 +0200 | [diff] [blame] | 139 | 3, /* reset timer (T2) */ |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 140 | 3, /* reset retries */ |
| 141 | 10, /* suspend timer (T3) in 100ms */ |
| 142 | 3, /* suspend retries */ |
| 143 | 10, /* resume timer (T4) in 100ms */ |
| 144 | 3, /* resume retries */ |
| 145 | 10, /* capability update timer (T5) */ |
| 146 | 3, /* capability update retries */ |
| 147 | }; |
| 148 | |
| 149 | static unsigned char nanobts_attr_cell[] = { |
| 150 | NM_ATT_IPACC_RAC, 0, 1, 1, /* routing area code */ |
| 151 | NM_ATT_IPACC_GPRS_PAGING_CFG, 0, 2, |
| 152 | 5, /* repeat time (50ms) */ |
| 153 | 3, /* repeat count */ |
| 154 | NM_ATT_IPACC_BVCI, 0, 2, 0x03, 0x9d, /* BVCI 925 */ |
Harald Welte | c95175f | 2012-06-28 08:42:37 +0200 | [diff] [blame] | 155 | /* all timers in seconds, unless otherwise stated */ |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 156 | NM_ATT_IPACC_RLC_CFG, 0, 9, |
| 157 | 20, /* T3142 */ |
| 158 | 5, /* T3169 */ |
| 159 | 5, /* T3191 */ |
Harald Welte | c95175f | 2012-06-28 08:42:37 +0200 | [diff] [blame] | 160 | 200, /* T3193 (units of 10ms) */ |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 161 | 5, /* T3195 */ |
| 162 | 10, /* N3101 */ |
| 163 | 4, /* N3103 */ |
| 164 | 8, /* N3105 */ |
| 165 | 15, /* RLC CV countdown */ |
| 166 | NM_ATT_IPACC_CODING_SCHEMES, 0, 2, 0x0f, 0x00, /* CS1..CS4 */ |
| 167 | NM_ATT_IPACC_RLC_CFG_2, 0, 5, |
| 168 | 0x00, 250, /* T downlink TBF extension (0..500) */ |
| 169 | 0x00, 250, /* T uplink TBF extension (0..500) */ |
| 170 | 2, /* CS2 */ |
| 171 | #if 0 |
| 172 | /* EDGE model only, breaks older models. |
| 173 | * Should inquire the BTS capabilities */ |
| 174 | NM_ATT_IPACC_RLC_CFG_3, 0, 1, |
| 175 | 2, /* MCS2 */ |
| 176 | #endif |
| 177 | }; |
| 178 | |
| 179 | static unsigned char nanobts_attr_nsvc0[] = { |
| 180 | NM_ATT_IPACC_NSVCI, 0, 2, 0x03, 0x9d, /* 925 */ |
| 181 | NM_ATT_IPACC_NS_LINK_CFG, 0, 8, |
| 182 | 0x59, 0xd8, /* remote udp port (23000) */ |
| 183 | 192, 168, 100, 11, /* remote ip address */ |
| 184 | 0x59, 0xd8, /* local udp port (23000) */ |
| 185 | }; |
| 186 | |
| 187 | static void patch_16(uint8_t *data, const uint16_t val) |
| 188 | { |
| 189 | memcpy(data, &val, sizeof(val)); |
| 190 | } |
| 191 | |
| 192 | static void patch_32(uint8_t *data, const uint32_t val) |
| 193 | { |
| 194 | memcpy(data, &val, sizeof(val)); |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Patch the various SYSTEM INFORMATION tables to update |
| 199 | * the LAI |
| 200 | */ |
| 201 | static void patch_nm_tables(struct gsm_bts *bts) |
| 202 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 203 | uint8_t arfcn_low = bts->c0->arfcn & 0xff; |
| 204 | uint8_t arfcn_high = (bts->c0->arfcn >> 8) & 0x0f; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 205 | |
| 206 | /* patch ARFCN into BTS Attributes */ |
| 207 | nanobts_attr_bts[42] &= 0xf0; |
| 208 | nanobts_attr_bts[42] |= arfcn_high; |
| 209 | nanobts_attr_bts[43] = arfcn_low; |
| 210 | |
| 211 | /* patch the RACH attributes */ |
| 212 | if (bts->rach_b_thresh != -1) { |
| 213 | nanobts_attr_bts[33] = bts->rach_b_thresh & 0xff; |
| 214 | } |
| 215 | |
| 216 | if (bts->rach_ldavg_slots != -1) { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 217 | uint8_t avg_high = bts->rach_ldavg_slots & 0xff; |
| 218 | uint8_t avg_low = (bts->rach_ldavg_slots >> 8) & 0x0f; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 219 | |
| 220 | nanobts_attr_bts[35] = avg_high; |
| 221 | nanobts_attr_bts[36] = avg_low; |
| 222 | } |
| 223 | |
| 224 | /* patch BSIC */ |
| 225 | nanobts_attr_bts[sizeof(nanobts_attr_bts)-11] = bts->bsic; |
| 226 | |
| 227 | /* patch CGI */ |
Harald Welte | e86b3eb | 2011-06-27 21:15:59 +0200 | [diff] [blame] | 228 | abis_nm_ipaccess_cgi(nanobts_attr_bts+sizeof(nanobts_attr_bts)-7, bts); |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 229 | |
| 230 | /* patch the power reduction */ |
| 231 | nanobts_attr_radio[1] = bts->c0->max_power_red / 2; |
| 232 | |
| 233 | /* patch NSEI */ |
| 234 | nanobts_attr_nse[3] = bts->gprs.nse.nsei >> 8; |
| 235 | nanobts_attr_nse[4] = bts->gprs.nse.nsei & 0xff; |
| 236 | memcpy(nanobts_attr_nse+8, bts->gprs.nse.timer, |
| 237 | ARRAY_SIZE(bts->gprs.nse.timer)); |
| 238 | memcpy(nanobts_attr_nse+18, bts->gprs.cell.timer, |
| 239 | ARRAY_SIZE(bts->gprs.cell.timer)); |
| 240 | |
| 241 | /* patch NSVCI */ |
| 242 | nanobts_attr_nsvc0[3] = bts->gprs.nsvc[0].nsvci >> 8; |
| 243 | nanobts_attr_nsvc0[4] = bts->gprs.nsvc[0].nsvci & 0xff; |
| 244 | |
| 245 | /* patch IP address as SGSN IP */ |
| 246 | patch_16(nanobts_attr_nsvc0 + 8, |
| 247 | htons(bts->gprs.nsvc[0].remote_port)); |
| 248 | patch_32(nanobts_attr_nsvc0 + 10, |
| 249 | htonl(bts->gprs.nsvc[0].remote_ip)); |
| 250 | patch_16(nanobts_attr_nsvc0 + 14, |
| 251 | htons(bts->gprs.nsvc[0].local_port)); |
| 252 | |
| 253 | /* patch BVCI */ |
| 254 | nanobts_attr_cell[12] = bts->gprs.cell.bvci >> 8; |
| 255 | nanobts_attr_cell[13] = bts->gprs.cell.bvci & 0xff; |
| 256 | /* patch RAC */ |
| 257 | nanobts_attr_cell[3] = bts->gprs.rac; |
| 258 | |
| 259 | if (bts->gprs.mode == BTS_GPRS_EGPRS) { |
| 260 | /* patch EGPRS coding schemes MCS 1..9 */ |
| 261 | nanobts_attr_cell[29] = 0x8f; |
| 262 | nanobts_attr_cell[30] = 0xff; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | |
| 267 | /* Callback function to be called whenever we get a GSM 12.21 state change event */ |
| 268 | static int nm_statechg_event(int evt, struct nm_statechg_signal_data *nsd) |
| 269 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 270 | uint8_t obj_class = nsd->obj_class; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 271 | void *obj = nsd->obj; |
| 272 | struct gsm_nm_state *new_state = nsd->new_state; |
| 273 | |
| 274 | struct gsm_bts *bts; |
| 275 | struct gsm_bts_trx *trx; |
| 276 | struct gsm_bts_trx_ts *ts; |
| 277 | struct gsm_bts_gprs_nsvc *nsvc; |
| 278 | |
Harald Welte | f38ca9a | 2011-03-06 22:11:32 +0100 | [diff] [blame] | 279 | if (nsd->bts->type != GSM_BTS_TYPE_NANOBTS) |
| 280 | return 0; |
| 281 | |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 282 | /* This event-driven BTS setup is currently only required on nanoBTS */ |
| 283 | |
| 284 | /* S_NM_STATECHG_ADM is called after we call chg_adm_state() and would create |
| 285 | * endless loop */ |
| 286 | if (evt != S_NM_STATECHG_OPER) |
| 287 | return 0; |
| 288 | |
| 289 | switch (obj_class) { |
| 290 | case NM_OC_SITE_MANAGER: |
| 291 | bts = container_of(obj, struct gsm_bts, site_mgr); |
| 292 | if ((new_state->operational == NM_OPSTATE_ENABLED && |
| 293 | new_state->availability == NM_AVSTATE_OK) || |
| 294 | (new_state->operational == NM_OPSTATE_DISABLED && |
| 295 | new_state->availability == NM_AVSTATE_OFF_LINE)) |
| 296 | abis_nm_opstart(bts, obj_class, 0xff, 0xff, 0xff); |
| 297 | break; |
| 298 | case NM_OC_BTS: |
| 299 | bts = obj; |
| 300 | if (new_state->availability == NM_AVSTATE_DEPENDENCY) { |
| 301 | patch_nm_tables(bts); |
| 302 | abis_nm_set_bts_attr(bts, nanobts_attr_bts, |
| 303 | sizeof(nanobts_attr_bts)); |
| 304 | abis_nm_chg_adm_state(bts, obj_class, |
| 305 | bts->bts_nr, 0xff, 0xff, |
| 306 | NM_STATE_UNLOCKED); |
| 307 | abis_nm_opstart(bts, obj_class, |
| 308 | bts->bts_nr, 0xff, 0xff); |
| 309 | } |
| 310 | break; |
| 311 | case NM_OC_CHANNEL: |
| 312 | ts = obj; |
| 313 | trx = ts->trx; |
| 314 | if (new_state->operational == NM_OPSTATE_DISABLED && |
| 315 | new_state->availability == NM_AVSTATE_DEPENDENCY) { |
| 316 | patch_nm_tables(trx->bts); |
| 317 | enum abis_nm_chan_comb ccomb = |
| 318 | abis_nm_chcomb4pchan(ts->pchan); |
| 319 | abis_nm_set_channel_attr(ts, ccomb); |
| 320 | abis_nm_chg_adm_state(trx->bts, obj_class, |
| 321 | trx->bts->bts_nr, trx->nr, ts->nr, |
| 322 | NM_STATE_UNLOCKED); |
| 323 | abis_nm_opstart(trx->bts, obj_class, |
| 324 | trx->bts->bts_nr, trx->nr, ts->nr); |
| 325 | } |
| 326 | break; |
| 327 | case NM_OC_RADIO_CARRIER: |
| 328 | trx = obj; |
| 329 | if (new_state->operational == NM_OPSTATE_DISABLED && |
| 330 | new_state->availability == NM_AVSTATE_OK) |
| 331 | abis_nm_opstart(trx->bts, obj_class, trx->bts->bts_nr, |
| 332 | trx->nr, 0xff); |
| 333 | break; |
| 334 | case NM_OC_GPRS_NSE: |
| 335 | bts = container_of(obj, struct gsm_bts, gprs.nse); |
| 336 | if (bts->gprs.mode == BTS_GPRS_NONE) |
| 337 | break; |
| 338 | if (new_state->availability == NM_AVSTATE_DEPENDENCY) { |
| 339 | abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr, |
| 340 | 0xff, 0xff, nanobts_attr_nse, |
| 341 | sizeof(nanobts_attr_nse)); |
| 342 | abis_nm_opstart(bts, obj_class, bts->bts_nr, |
| 343 | 0xff, 0xff); |
| 344 | } |
| 345 | break; |
| 346 | case NM_OC_GPRS_CELL: |
| 347 | bts = container_of(obj, struct gsm_bts, gprs.cell); |
| 348 | if (bts->gprs.mode == BTS_GPRS_NONE) |
| 349 | break; |
| 350 | if (new_state->availability == NM_AVSTATE_DEPENDENCY) { |
| 351 | abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr, |
| 352 | 0, 0xff, nanobts_attr_cell, |
| 353 | sizeof(nanobts_attr_cell)); |
| 354 | abis_nm_opstart(bts, obj_class, bts->bts_nr, |
| 355 | 0, 0xff); |
| 356 | abis_nm_chg_adm_state(bts, obj_class, bts->bts_nr, |
| 357 | 0, 0xff, NM_STATE_UNLOCKED); |
| 358 | abis_nm_chg_adm_state(bts, NM_OC_GPRS_NSE, bts->bts_nr, |
| 359 | 0xff, 0xff, NM_STATE_UNLOCKED); |
| 360 | } |
| 361 | break; |
| 362 | case NM_OC_GPRS_NSVC: |
| 363 | nsvc = obj; |
| 364 | bts = nsvc->bts; |
| 365 | if (bts->gprs.mode == BTS_GPRS_NONE) |
| 366 | break; |
| 367 | /* We skip NSVC1 since we only use NSVC0 */ |
| 368 | if (nsvc->id == 1) |
| 369 | break; |
Sylvain Munaut | 67c0c7f | 2011-10-17 13:57:58 +0200 | [diff] [blame] | 370 | if ((new_state->availability == NM_AVSTATE_OFF_LINE) || |
| 371 | (new_state->availability == NM_AVSTATE_DEPENDENCY)) { |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 372 | abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr, |
| 373 | nsvc->id, 0xff, |
| 374 | nanobts_attr_nsvc0, |
| 375 | sizeof(nanobts_attr_nsvc0)); |
| 376 | abis_nm_opstart(bts, obj_class, bts->bts_nr, |
| 377 | nsvc->id, 0xff); |
| 378 | abis_nm_chg_adm_state(bts, obj_class, bts->bts_nr, |
| 379 | nsvc->id, 0xff, |
| 380 | NM_STATE_UNLOCKED); |
| 381 | } |
| 382 | default: |
| 383 | break; |
| 384 | } |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | /* Callback function to be called every time we receive a 12.21 SW activated report */ |
| 389 | static int sw_activ_rep(struct msgb *mb) |
| 390 | { |
| 391 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Pablo Neira Ayuso | 7abecfc | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 392 | struct e1inp_sign_link *sign_link = mb->dst; |
| 393 | struct gsm_bts *bts = sign_link->trx->bts; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 394 | struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, foh->obj_inst.trx_nr); |
| 395 | |
| 396 | if (!trx) |
| 397 | return -EINVAL; |
| 398 | |
| 399 | if (trx->bts->type != GSM_BTS_TYPE_NANOBTS) |
| 400 | return 0; |
| 401 | |
| 402 | switch (foh->obj_class) { |
| 403 | case NM_OC_BASEB_TRANSC: |
| 404 | abis_nm_chg_adm_state(trx->bts, foh->obj_class, |
| 405 | trx->bts->bts_nr, trx->nr, 0xff, |
| 406 | NM_STATE_UNLOCKED); |
| 407 | abis_nm_opstart(trx->bts, foh->obj_class, |
| 408 | trx->bts->bts_nr, trx->nr, 0xff); |
| 409 | /* TRX software is active, tell it to initiate RSL Link */ |
| 410 | abis_nm_ipaccess_rsl_connect(trx, 0, 3003, trx->rsl_tei); |
| 411 | break; |
| 412 | case NM_OC_RADIO_CARRIER: { |
| 413 | /* |
| 414 | * Locking the radio carrier will make it go |
| 415 | * offline again and we would come here. The |
| 416 | * framework should determine that there was |
| 417 | * no change and avoid recursion. |
| 418 | * |
| 419 | * This code is here to make sure that on start |
| 420 | * a TRX remains locked. |
| 421 | */ |
Harald Welte | d64c0bc | 2011-05-30 12:07:53 +0200 | [diff] [blame] | 422 | int rc_state = trx->mo.nm_state.administrative; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 423 | /* Patch ARFCN into radio attribute */ |
| 424 | nanobts_attr_radio[5] &= 0xf0; |
| 425 | nanobts_attr_radio[5] |= trx->arfcn >> 8; |
| 426 | nanobts_attr_radio[6] = trx->arfcn & 0xff; |
| 427 | abis_nm_set_radio_attr(trx, nanobts_attr_radio, |
| 428 | sizeof(nanobts_attr_radio)); |
| 429 | abis_nm_chg_adm_state(trx->bts, foh->obj_class, |
| 430 | trx->bts->bts_nr, trx->nr, 0xff, |
| 431 | rc_state); |
| 432 | abis_nm_opstart(trx->bts, foh->obj_class, trx->bts->bts_nr, |
| 433 | trx->nr, 0xff); |
| 434 | break; |
| 435 | } |
| 436 | } |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | /* Callback function to be called every time we receive a signal from NM */ |
| 441 | static int nm_sig_cb(unsigned int subsys, unsigned int signal, |
| 442 | void *handler_data, void *signal_data) |
| 443 | { |
| 444 | if (subsys != SS_NM) |
| 445 | return 0; |
| 446 | |
| 447 | switch (signal) { |
| 448 | case S_NM_SW_ACTIV_REP: |
| 449 | return sw_activ_rep(signal_data); |
| 450 | case S_NM_STATECHG_OPER: |
| 451 | case S_NM_STATECHG_ADM: |
| 452 | return nm_statechg_event(signal, signal_data); |
| 453 | default: |
| 454 | break; |
| 455 | } |
| 456 | return 0; |
| 457 | } |
| 458 | |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 459 | static struct gsm_network *ipaccess_gsmnet; |
| 460 | |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 461 | static int bts_model_nanobts_start(struct gsm_network *net) |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 462 | { |
Holger Hans Peter Freyther | c8bf3c1 | 2010-06-21 18:11:37 +0800 | [diff] [blame] | 463 | model_nanobts.features.data = &model_nanobts._features_data[0]; |
Harald Welte | f3d8e92 | 2010-06-14 22:44:42 +0200 | [diff] [blame] | 464 | model_nanobts.features.data_len = sizeof(model_nanobts._features_data); |
| 465 | |
| 466 | gsm_btsmodel_set_feature(&model_nanobts, BTS_FEAT_GPRS); |
| 467 | gsm_btsmodel_set_feature(&model_nanobts, BTS_FEAT_EGPRS); |
| 468 | |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 469 | osmo_signal_register_handler(SS_NM, nm_sig_cb, NULL); |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 470 | |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 471 | ipaccess_gsmnet = net; |
| 472 | return 0; |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | int bts_model_nanobts_init(void) |
| 476 | { |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 477 | return gsm_bts_model_register(&model_nanobts); |
| 478 | } |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 479 | |
| 480 | #define OML_UP 0x0001 |
| 481 | #define RSL_UP 0x0002 |
| 482 | |
| 483 | static struct gsm_bts * |
| 484 | find_bts_by_unitid(struct gsm_network *net, uint16_t site_id, uint16_t bts_id) |
| 485 | { |
| 486 | struct gsm_bts *bts; |
| 487 | |
| 488 | llist_for_each_entry(bts, &net->bts_list, list) { |
| 489 | if (!is_ipaccess_bts(bts)) |
| 490 | continue; |
| 491 | |
| 492 | if (bts->ip_access.site_id == site_id && |
| 493 | bts->ip_access.bts_id == bts_id) |
| 494 | return bts; |
| 495 | } |
| 496 | return NULL; |
| 497 | } |
| 498 | |
| 499 | /* These are exported because they are used by the VTY interface. */ |
| 500 | void ipaccess_drop_rsl(struct gsm_bts_trx *trx) |
| 501 | { |
| 502 | if (!trx->rsl_link) |
| 503 | return; |
| 504 | |
| 505 | e1inp_sign_link_destroy(trx->rsl_link); |
| 506 | trx->rsl_link = NULL; |
| 507 | } |
| 508 | |
| 509 | void ipaccess_drop_oml(struct gsm_bts *bts) |
| 510 | { |
| 511 | struct gsm_bts_trx *trx; |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 512 | |
| 513 | if (!bts->oml_link) |
| 514 | return; |
| 515 | |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 516 | e1inp_sign_link_destroy(bts->oml_link); |
| 517 | bts->oml_link = NULL; |
| 518 | |
| 519 | /* we have issues reconnecting RSL, drop everything. */ |
| 520 | llist_for_each_entry(trx, &bts->trx_list, list) |
| 521 | ipaccess_drop_rsl(trx); |
| 522 | |
| 523 | bts->ip_access.flags = 0; |
| 524 | } |
| 525 | |
| 526 | /* This function is called once the OML/RSL link becomes up. */ |
| 527 | static struct e1inp_sign_link * |
| 528 | ipaccess_sign_link_up(void *unit_data, struct e1inp_line *line, |
| 529 | enum e1inp_sign_type type) |
| 530 | { |
| 531 | struct gsm_bts *bts; |
| 532 | struct ipaccess_unit *dev = unit_data; |
| 533 | struct e1inp_sign_link *sign_link = NULL; |
| 534 | |
| 535 | bts = find_bts_by_unitid(ipaccess_gsmnet, dev->site_id, dev->bts_id); |
| 536 | if (!bts) { |
| 537 | LOGP(DLINP, LOGL_ERROR, "Unable to find BTS configuration for " |
| 538 | " %u/%u/%u, disconnecting\n", dev->site_id, |
| 539 | dev->bts_id, dev->trx_id); |
| 540 | return NULL; |
| 541 | } |
| 542 | DEBUGP(DLINP, "Identified BTS %u/%u/%u\n", |
| 543 | dev->site_id, dev->bts_id, dev->trx_id); |
| 544 | |
| 545 | switch(type) { |
| 546 | case E1INP_SIGN_OML: |
| 547 | /* remove old OML signal link for this BTS. */ |
| 548 | ipaccess_drop_oml(bts); |
| 549 | |
| 550 | /* create new OML link. */ |
| 551 | sign_link = bts->oml_link = |
| 552 | e1inp_sign_link_create(&line->ts[E1INP_SIGN_OML - 1], |
| 553 | E1INP_SIGN_OML, bts->c0, |
| 554 | bts->oml_tei, 0); |
| 555 | break; |
| 556 | case E1INP_SIGN_RSL: { |
| 557 | struct e1inp_ts *ts; |
| 558 | struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, dev->trx_id); |
| 559 | |
| 560 | /* no OML link set yet? give up. */ |
| 561 | if (!bts->oml_link) |
| 562 | return NULL; |
| 563 | |
| 564 | /* remove old RSL link for this TRX. */ |
| 565 | ipaccess_drop_rsl(trx); |
| 566 | |
| 567 | /* set new RSL link for this TRX. */ |
| 568 | line = bts->oml_link->ts->line; |
| 569 | ts = &line->ts[E1INP_SIGN_RSL + dev->trx_id - 1]; |
| 570 | e1inp_ts_config_sign(ts, line); |
| 571 | sign_link = trx->rsl_link = |
| 572 | e1inp_sign_link_create(ts, E1INP_SIGN_RSL, |
| 573 | trx, trx->rsl_tei, 0); |
| 574 | trx->rsl_link->ts->sign.delay = 0; |
| 575 | break; |
| 576 | } |
| 577 | default: |
| 578 | break; |
| 579 | } |
| 580 | return sign_link; |
| 581 | } |
| 582 | |
| 583 | static void ipaccess_sign_link_down(struct e1inp_line *line) |
| 584 | { |
| 585 | /* No matter what link went down, we close both signal links. */ |
| 586 | struct e1inp_ts *ts = &line->ts[E1INP_SIGN_OML-1]; |
| 587 | struct e1inp_sign_link *link; |
| 588 | |
| 589 | llist_for_each_entry(link, &ts->sign.sign_links, list) { |
| 590 | struct gsm_bts *bts = link->trx->bts; |
| 591 | |
| 592 | ipaccess_drop_oml(bts); |
| 593 | /* Yes, we only use the first element of the list. */ |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | /* This function is called if we receive one OML/RSL message. */ |
| 599 | static int ipaccess_sign_link(struct msgb *msg) |
| 600 | { |
| 601 | int ret = 0; |
| 602 | struct e1inp_sign_link *link = msg->dst; |
| 603 | struct e1inp_ts *e1i_ts = link->ts; |
| 604 | |
| 605 | switch (link->type) { |
| 606 | case E1INP_SIGN_RSL: |
| 607 | if (!(link->trx->bts->ip_access.flags & |
| 608 | (RSL_UP << link->trx->nr))) { |
| 609 | e1inp_event(e1i_ts, S_L_INP_TEI_UP, |
| 610 | link->tei, link->sapi); |
| 611 | link->trx->bts->ip_access.flags |= |
| 612 | (RSL_UP << link->trx->nr); |
| 613 | } |
| 614 | ret = abis_rsl_rcvmsg(msg); |
| 615 | break; |
| 616 | case E1INP_SIGN_OML: |
| 617 | if (!(link->trx->bts->ip_access.flags & OML_UP)) { |
| 618 | e1inp_event(e1i_ts, S_L_INP_TEI_UP, |
| 619 | link->tei, link->sapi); |
| 620 | link->trx->bts->ip_access.flags |= OML_UP; |
| 621 | } |
| 622 | ret = abis_nm_rcvmsg(msg); |
| 623 | break; |
| 624 | default: |
| 625 | LOGP(DLINP, LOGL_ERROR, "Unknown signal link type %d\n", |
| 626 | link->type); |
| 627 | msgb_free(msg); |
| 628 | break; |
| 629 | } |
| 630 | return ret; |
| 631 | } |
| 632 | |
| 633 | /* not static, ipaccess-config needs it. */ |
| 634 | struct e1inp_line_ops ipaccess_e1inp_line_ops = { |
| 635 | .cfg = { |
| 636 | .ipa = { |
| 637 | .addr = "0.0.0.0", |
| 638 | .role = E1INP_LINE_R_BSC, |
| 639 | }, |
| 640 | }, |
| 641 | .sign_link_up = ipaccess_sign_link_up, |
| 642 | .sign_link_down = ipaccess_sign_link_down, |
| 643 | .sign_link = ipaccess_sign_link, |
| 644 | }; |
| 645 | |
| 646 | static void bts_model_nanobts_e1line_bind_ops(struct e1inp_line *line) |
| 647 | { |
| 648 | e1inp_line_bind_ops(line, &ipaccess_e1inp_line_ops); |
| 649 | } |