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 | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 29 | #include <openbsc/e1_input.h> /* for ipaccess_setup() */ |
| 30 | |
| 31 | static int bts_model_nanobts_start(struct gsm_network *net); |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 32 | |
| 33 | static struct gsm_bts_model model_nanobts = { |
| 34 | .type = GSM_BTS_TYPE_NANOBTS, |
Harald Welte | 09cefee | 2011-02-12 12:29:21 +0100 | [diff] [blame] | 35 | .name = "nanobts", |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 36 | .start = bts_model_nanobts_start, |
Harald Welte | 09cefee | 2011-02-12 12:29:21 +0100 | [diff] [blame] | 37 | .oml_rcvmsg = &abis_nm_rcvmsg, |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 38 | .nm_att_tlvdef = { |
| 39 | .def = { |
| 40 | /* ip.access specifics */ |
| 41 | [NM_ATT_IPACC_DST_IP] = { TLV_TYPE_FIXED, 4 }, |
| 42 | [NM_ATT_IPACC_DST_IP_PORT] = { TLV_TYPE_FIXED, 2 }, |
| 43 | [NM_ATT_IPACC_STREAM_ID] = { TLV_TYPE_TV, }, |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 44 | [NM_ATT_IPACC_SEC_OML_CFG] = { TLV_TYPE_FIXED, 6 }, |
| 45 | [NM_ATT_IPACC_IP_IF_CFG] = { TLV_TYPE_FIXED, 8 }, |
| 46 | [NM_ATT_IPACC_IP_GW_CFG] = { TLV_TYPE_FIXED, 12 }, |
| 47 | [NM_ATT_IPACC_IN_SERV_TIME] = { TLV_TYPE_FIXED, 4 }, |
| 48 | [NM_ATT_IPACC_LOCATION] = { TLV_TYPE_TL16V }, |
| 49 | [NM_ATT_IPACC_PAGING_CFG] = { TLV_TYPE_FIXED, 2 }, |
| 50 | [NM_ATT_IPACC_UNIT_ID] = { TLV_TYPE_TL16V }, |
| 51 | [NM_ATT_IPACC_UNIT_NAME] = { TLV_TYPE_TL16V }, |
| 52 | [NM_ATT_IPACC_SNMP_CFG] = { TLV_TYPE_TL16V }, |
| 53 | [NM_ATT_IPACC_PRIM_OML_CFG_LIST] = { TLV_TYPE_TL16V }, |
| 54 | [NM_ATT_IPACC_NV_FLAGS] = { TLV_TYPE_TL16V }, |
| 55 | [NM_ATT_IPACC_FREQ_CTRL] = { TLV_TYPE_FIXED, 2 }, |
| 56 | [NM_ATT_IPACC_PRIM_OML_FB_TOUT] = { TLV_TYPE_TL16V }, |
| 57 | [NM_ATT_IPACC_CUR_SW_CFG] = { TLV_TYPE_TL16V }, |
| 58 | [NM_ATT_IPACC_TIMING_BUS] = { TLV_TYPE_TL16V }, |
| 59 | [NM_ATT_IPACC_CGI] = { TLV_TYPE_TL16V }, |
| 60 | [NM_ATT_IPACC_RAC] = { TLV_TYPE_TL16V }, |
| 61 | [NM_ATT_IPACC_OBJ_VERSION] = { TLV_TYPE_TL16V }, |
| 62 | [NM_ATT_IPACC_GPRS_PAGING_CFG]= { TLV_TYPE_TL16V }, |
| 63 | [NM_ATT_IPACC_NSEI] = { TLV_TYPE_TL16V }, |
| 64 | [NM_ATT_IPACC_BVCI] = { TLV_TYPE_TL16V }, |
| 65 | [NM_ATT_IPACC_NSVCI] = { TLV_TYPE_TL16V }, |
| 66 | [NM_ATT_IPACC_NS_CFG] = { TLV_TYPE_TL16V }, |
| 67 | [NM_ATT_IPACC_BSSGP_CFG] = { TLV_TYPE_TL16V }, |
| 68 | [NM_ATT_IPACC_NS_LINK_CFG] = { TLV_TYPE_TL16V }, |
| 69 | [NM_ATT_IPACC_RLC_CFG] = { TLV_TYPE_TL16V }, |
| 70 | [NM_ATT_IPACC_ALM_THRESH_LIST]= { TLV_TYPE_TL16V }, |
| 71 | [NM_ATT_IPACC_MONIT_VAL_LIST] = { TLV_TYPE_TL16V }, |
| 72 | [NM_ATT_IPACC_TIB_CONTROL] = { TLV_TYPE_TL16V }, |
| 73 | [NM_ATT_IPACC_SUPP_FEATURES] = { TLV_TYPE_TL16V }, |
| 74 | [NM_ATT_IPACC_CODING_SCHEMES] = { TLV_TYPE_TL16V }, |
| 75 | [NM_ATT_IPACC_RLC_CFG_2] = { TLV_TYPE_TL16V }, |
| 76 | [NM_ATT_IPACC_HEARTB_TOUT] = { TLV_TYPE_TL16V }, |
| 77 | [NM_ATT_IPACC_UPTIME] = { TLV_TYPE_TL16V }, |
| 78 | [NM_ATT_IPACC_RLC_CFG_3] = { TLV_TYPE_TL16V }, |
| 79 | [NM_ATT_IPACC_SSL_CFG] = { TLV_TYPE_TL16V }, |
| 80 | [NM_ATT_IPACC_SEC_POSSIBLE] = { TLV_TYPE_TL16V }, |
| 81 | [NM_ATT_IPACC_IML_SSL_STATE] = { TLV_TYPE_TL16V }, |
| 82 | [NM_ATT_IPACC_REVOC_DATE] = { TLV_TYPE_TL16V }, |
| 83 | }, |
| 84 | }, |
| 85 | }; |
| 86 | |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 87 | static unsigned char nanobts_attr_bts[] = { |
| 88 | NM_ATT_INTERF_BOUND, 0x55, 0x5b, 0x61, 0x67, 0x6d, 0x73, |
| 89 | /* interference avg. period in numbers of SACCH multifr */ |
| 90 | NM_ATT_INTAVE_PARAM, 0x06, |
| 91 | /* conn fail based on SACCH error rate */ |
| 92 | NM_ATT_CONN_FAIL_CRIT, 0x00, 0x02, 0x01, 0x10, |
| 93 | NM_ATT_T200, 0x1e, 0x24, 0x24, 0xa8, 0x34, 0x21, 0xa8, |
| 94 | NM_ATT_MAX_TA, 0x3f, |
| 95 | NM_ATT_OVERL_PERIOD, 0x00, 0x01, 10, /* seconds */ |
| 96 | NM_ATT_CCCH_L_T, 10, /* percent */ |
| 97 | NM_ATT_CCCH_L_I_P, 1, /* seconds */ |
| 98 | NM_ATT_RACH_B_THRESH, 10, /* busy threshold in - dBm */ |
| 99 | NM_ATT_LDAVG_SLOTS, 0x03, 0xe8, /* rach load averaging 1000 slots */ |
| 100 | NM_ATT_BTS_AIR_TIMER, 128, /* miliseconds */ |
| 101 | NM_ATT_NY1, 10, /* 10 retransmissions of physical config */ |
| 102 | NM_ATT_BCCH_ARFCN, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff, |
| 103 | NM_ATT_BSIC, HARDCODED_BSIC, |
Harald Welte | 8b65ab9 | 2011-06-09 11:03:49 +0200 | [diff] [blame^] | 104 | //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] | 105 | }; |
| 106 | |
| 107 | static unsigned char nanobts_attr_radio[] = { |
| 108 | NM_ATT_RF_MAXPOWR_R, 0x0c, /* number of -2dB reduction steps / Pn */ |
| 109 | NM_ATT_ARFCN_LIST, 0x00, 0x02, HARDCODED_ARFCN >> 8, HARDCODED_ARFCN & 0xff, |
| 110 | }; |
| 111 | |
| 112 | static unsigned char nanobts_attr_nse[] = { |
| 113 | NM_ATT_IPACC_NSEI, 0, 2, 0x03, 0x9d, /* NSEI 925 */ |
| 114 | NM_ATT_IPACC_NS_CFG, 0, 7, 3, /* (un)blocking timer (Tns-block) */ |
| 115 | 3, /* (un)blocking retries */ |
| 116 | 3, /* reset timer (Tns-reset) */ |
| 117 | 3, /* reset retries */ |
| 118 | 30, /* test timer (Tns-test) */ |
| 119 | 3, /* alive timer (Tns-alive) */ |
| 120 | 10, /* alive retrires */ |
| 121 | NM_ATT_IPACC_BSSGP_CFG, 0, 11, |
| 122 | 3, /* blockimg timer (T1) */ |
| 123 | 3, /* blocking retries */ |
| 124 | 3, /* unblocking retries */ |
| 125 | 3, /* reset timer */ |
| 126 | 3, /* reset retries */ |
| 127 | 10, /* suspend timer (T3) in 100ms */ |
| 128 | 3, /* suspend retries */ |
| 129 | 10, /* resume timer (T4) in 100ms */ |
| 130 | 3, /* resume retries */ |
| 131 | 10, /* capability update timer (T5) */ |
| 132 | 3, /* capability update retries */ |
| 133 | }; |
| 134 | |
| 135 | static unsigned char nanobts_attr_cell[] = { |
| 136 | NM_ATT_IPACC_RAC, 0, 1, 1, /* routing area code */ |
| 137 | NM_ATT_IPACC_GPRS_PAGING_CFG, 0, 2, |
| 138 | 5, /* repeat time (50ms) */ |
| 139 | 3, /* repeat count */ |
| 140 | NM_ATT_IPACC_BVCI, 0, 2, 0x03, 0x9d, /* BVCI 925 */ |
| 141 | NM_ATT_IPACC_RLC_CFG, 0, 9, |
| 142 | 20, /* T3142 */ |
| 143 | 5, /* T3169 */ |
| 144 | 5, /* T3191 */ |
| 145 | 200, /* T3193 */ |
| 146 | 5, /* T3195 */ |
| 147 | 10, /* N3101 */ |
| 148 | 4, /* N3103 */ |
| 149 | 8, /* N3105 */ |
| 150 | 15, /* RLC CV countdown */ |
| 151 | NM_ATT_IPACC_CODING_SCHEMES, 0, 2, 0x0f, 0x00, /* CS1..CS4 */ |
| 152 | NM_ATT_IPACC_RLC_CFG_2, 0, 5, |
| 153 | 0x00, 250, /* T downlink TBF extension (0..500) */ |
| 154 | 0x00, 250, /* T uplink TBF extension (0..500) */ |
| 155 | 2, /* CS2 */ |
| 156 | #if 0 |
| 157 | /* EDGE model only, breaks older models. |
| 158 | * Should inquire the BTS capabilities */ |
| 159 | NM_ATT_IPACC_RLC_CFG_3, 0, 1, |
| 160 | 2, /* MCS2 */ |
| 161 | #endif |
| 162 | }; |
| 163 | |
| 164 | static unsigned char nanobts_attr_nsvc0[] = { |
| 165 | NM_ATT_IPACC_NSVCI, 0, 2, 0x03, 0x9d, /* 925 */ |
| 166 | NM_ATT_IPACC_NS_LINK_CFG, 0, 8, |
| 167 | 0x59, 0xd8, /* remote udp port (23000) */ |
| 168 | 192, 168, 100, 11, /* remote ip address */ |
| 169 | 0x59, 0xd8, /* local udp port (23000) */ |
| 170 | }; |
| 171 | |
| 172 | static void patch_16(uint8_t *data, const uint16_t val) |
| 173 | { |
| 174 | memcpy(data, &val, sizeof(val)); |
| 175 | } |
| 176 | |
| 177 | static void patch_32(uint8_t *data, const uint32_t val) |
| 178 | { |
| 179 | memcpy(data, &val, sizeof(val)); |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | * Patch the various SYSTEM INFORMATION tables to update |
| 184 | * the LAI |
| 185 | */ |
| 186 | static void patch_nm_tables(struct gsm_bts *bts) |
| 187 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 188 | uint8_t arfcn_low = bts->c0->arfcn & 0xff; |
| 189 | uint8_t arfcn_high = (bts->c0->arfcn >> 8) & 0x0f; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 190 | |
| 191 | /* patch ARFCN into BTS Attributes */ |
| 192 | nanobts_attr_bts[42] &= 0xf0; |
| 193 | nanobts_attr_bts[42] |= arfcn_high; |
| 194 | nanobts_attr_bts[43] = arfcn_low; |
| 195 | |
| 196 | /* patch the RACH attributes */ |
| 197 | if (bts->rach_b_thresh != -1) { |
| 198 | nanobts_attr_bts[33] = bts->rach_b_thresh & 0xff; |
| 199 | } |
| 200 | |
| 201 | if (bts->rach_ldavg_slots != -1) { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 202 | uint8_t avg_high = bts->rach_ldavg_slots & 0xff; |
| 203 | uint8_t avg_low = (bts->rach_ldavg_slots >> 8) & 0x0f; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 204 | |
| 205 | nanobts_attr_bts[35] = avg_high; |
| 206 | nanobts_attr_bts[36] = avg_low; |
| 207 | } |
| 208 | |
| 209 | /* patch BSIC */ |
| 210 | nanobts_attr_bts[sizeof(nanobts_attr_bts)-11] = bts->bsic; |
| 211 | |
| 212 | /* patch CGI */ |
Harald Welte | 8b65ab9 | 2011-06-09 11:03:49 +0200 | [diff] [blame^] | 213 | //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] | 214 | |
| 215 | /* patch the power reduction */ |
| 216 | nanobts_attr_radio[1] = bts->c0->max_power_red / 2; |
| 217 | |
| 218 | /* patch NSEI */ |
| 219 | nanobts_attr_nse[3] = bts->gprs.nse.nsei >> 8; |
| 220 | nanobts_attr_nse[4] = bts->gprs.nse.nsei & 0xff; |
| 221 | memcpy(nanobts_attr_nse+8, bts->gprs.nse.timer, |
| 222 | ARRAY_SIZE(bts->gprs.nse.timer)); |
| 223 | memcpy(nanobts_attr_nse+18, bts->gprs.cell.timer, |
| 224 | ARRAY_SIZE(bts->gprs.cell.timer)); |
| 225 | |
| 226 | /* patch NSVCI */ |
| 227 | nanobts_attr_nsvc0[3] = bts->gprs.nsvc[0].nsvci >> 8; |
| 228 | nanobts_attr_nsvc0[4] = bts->gprs.nsvc[0].nsvci & 0xff; |
| 229 | |
| 230 | /* patch IP address as SGSN IP */ |
| 231 | patch_16(nanobts_attr_nsvc0 + 8, |
| 232 | htons(bts->gprs.nsvc[0].remote_port)); |
| 233 | patch_32(nanobts_attr_nsvc0 + 10, |
| 234 | htonl(bts->gprs.nsvc[0].remote_ip)); |
| 235 | patch_16(nanobts_attr_nsvc0 + 14, |
| 236 | htons(bts->gprs.nsvc[0].local_port)); |
| 237 | |
| 238 | /* patch BVCI */ |
| 239 | nanobts_attr_cell[12] = bts->gprs.cell.bvci >> 8; |
| 240 | nanobts_attr_cell[13] = bts->gprs.cell.bvci & 0xff; |
| 241 | /* patch RAC */ |
| 242 | nanobts_attr_cell[3] = bts->gprs.rac; |
| 243 | |
| 244 | if (bts->gprs.mode == BTS_GPRS_EGPRS) { |
| 245 | /* patch EGPRS coding schemes MCS 1..9 */ |
| 246 | nanobts_attr_cell[29] = 0x8f; |
| 247 | nanobts_attr_cell[30] = 0xff; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | |
| 252 | /* Callback function to be called whenever we get a GSM 12.21 state change event */ |
| 253 | static int nm_statechg_event(int evt, struct nm_statechg_signal_data *nsd) |
| 254 | { |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 255 | uint8_t obj_class = nsd->obj_class; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 256 | void *obj = nsd->obj; |
| 257 | struct gsm_nm_state *new_state = nsd->new_state; |
| 258 | |
| 259 | struct gsm_bts *bts; |
| 260 | struct gsm_bts_trx *trx; |
| 261 | struct gsm_bts_trx_ts *ts; |
| 262 | struct gsm_bts_gprs_nsvc *nsvc; |
| 263 | |
Harald Welte | f38ca9a | 2011-03-06 22:11:32 +0100 | [diff] [blame] | 264 | if (nsd->bts->type != GSM_BTS_TYPE_NANOBTS) |
| 265 | return 0; |
| 266 | |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 267 | /* This event-driven BTS setup is currently only required on nanoBTS */ |
| 268 | |
| 269 | /* S_NM_STATECHG_ADM is called after we call chg_adm_state() and would create |
| 270 | * endless loop */ |
| 271 | if (evt != S_NM_STATECHG_OPER) |
| 272 | return 0; |
| 273 | |
| 274 | switch (obj_class) { |
| 275 | case NM_OC_SITE_MANAGER: |
| 276 | bts = container_of(obj, struct gsm_bts, site_mgr); |
| 277 | if ((new_state->operational == NM_OPSTATE_ENABLED && |
| 278 | new_state->availability == NM_AVSTATE_OK) || |
| 279 | (new_state->operational == NM_OPSTATE_DISABLED && |
| 280 | new_state->availability == NM_AVSTATE_OFF_LINE)) |
| 281 | abis_nm_opstart(bts, obj_class, 0xff, 0xff, 0xff); |
| 282 | break; |
| 283 | case NM_OC_BTS: |
| 284 | bts = obj; |
| 285 | if (new_state->availability == NM_AVSTATE_DEPENDENCY) { |
| 286 | patch_nm_tables(bts); |
| 287 | abis_nm_set_bts_attr(bts, nanobts_attr_bts, |
| 288 | sizeof(nanobts_attr_bts)); |
| 289 | abis_nm_chg_adm_state(bts, obj_class, |
| 290 | bts->bts_nr, 0xff, 0xff, |
| 291 | NM_STATE_UNLOCKED); |
| 292 | abis_nm_opstart(bts, obj_class, |
| 293 | bts->bts_nr, 0xff, 0xff); |
| 294 | } |
| 295 | break; |
| 296 | case NM_OC_CHANNEL: |
| 297 | ts = obj; |
| 298 | trx = ts->trx; |
| 299 | if (new_state->operational == NM_OPSTATE_DISABLED && |
| 300 | new_state->availability == NM_AVSTATE_DEPENDENCY) { |
| 301 | patch_nm_tables(trx->bts); |
| 302 | enum abis_nm_chan_comb ccomb = |
| 303 | abis_nm_chcomb4pchan(ts->pchan); |
| 304 | abis_nm_set_channel_attr(ts, ccomb); |
| 305 | abis_nm_chg_adm_state(trx->bts, obj_class, |
| 306 | trx->bts->bts_nr, trx->nr, ts->nr, |
| 307 | NM_STATE_UNLOCKED); |
| 308 | abis_nm_opstart(trx->bts, obj_class, |
| 309 | trx->bts->bts_nr, trx->nr, ts->nr); |
| 310 | } |
| 311 | break; |
| 312 | case NM_OC_RADIO_CARRIER: |
| 313 | trx = obj; |
| 314 | if (new_state->operational == NM_OPSTATE_DISABLED && |
| 315 | new_state->availability == NM_AVSTATE_OK) |
| 316 | abis_nm_opstart(trx->bts, obj_class, trx->bts->bts_nr, |
| 317 | trx->nr, 0xff); |
| 318 | break; |
| 319 | case NM_OC_GPRS_NSE: |
| 320 | bts = container_of(obj, struct gsm_bts, gprs.nse); |
| 321 | if (bts->gprs.mode == BTS_GPRS_NONE) |
| 322 | break; |
| 323 | if (new_state->availability == NM_AVSTATE_DEPENDENCY) { |
| 324 | abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr, |
| 325 | 0xff, 0xff, nanobts_attr_nse, |
| 326 | sizeof(nanobts_attr_nse)); |
| 327 | abis_nm_opstart(bts, obj_class, bts->bts_nr, |
| 328 | 0xff, 0xff); |
| 329 | } |
| 330 | break; |
| 331 | case NM_OC_GPRS_CELL: |
| 332 | bts = container_of(obj, struct gsm_bts, gprs.cell); |
| 333 | if (bts->gprs.mode == BTS_GPRS_NONE) |
| 334 | break; |
| 335 | if (new_state->availability == NM_AVSTATE_DEPENDENCY) { |
| 336 | abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr, |
| 337 | 0, 0xff, nanobts_attr_cell, |
| 338 | sizeof(nanobts_attr_cell)); |
| 339 | abis_nm_opstart(bts, obj_class, bts->bts_nr, |
| 340 | 0, 0xff); |
| 341 | abis_nm_chg_adm_state(bts, obj_class, bts->bts_nr, |
| 342 | 0, 0xff, NM_STATE_UNLOCKED); |
| 343 | abis_nm_chg_adm_state(bts, NM_OC_GPRS_NSE, bts->bts_nr, |
| 344 | 0xff, 0xff, NM_STATE_UNLOCKED); |
| 345 | } |
| 346 | break; |
| 347 | case NM_OC_GPRS_NSVC: |
| 348 | nsvc = obj; |
| 349 | bts = nsvc->bts; |
| 350 | if (bts->gprs.mode == BTS_GPRS_NONE) |
| 351 | break; |
| 352 | /* We skip NSVC1 since we only use NSVC0 */ |
| 353 | if (nsvc->id == 1) |
| 354 | break; |
| 355 | if (new_state->availability == NM_AVSTATE_OFF_LINE) { |
| 356 | abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr, |
| 357 | nsvc->id, 0xff, |
| 358 | nanobts_attr_nsvc0, |
| 359 | sizeof(nanobts_attr_nsvc0)); |
| 360 | abis_nm_opstart(bts, obj_class, bts->bts_nr, |
| 361 | nsvc->id, 0xff); |
| 362 | abis_nm_chg_adm_state(bts, obj_class, bts->bts_nr, |
| 363 | nsvc->id, 0xff, |
| 364 | NM_STATE_UNLOCKED); |
| 365 | } |
| 366 | default: |
| 367 | break; |
| 368 | } |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | /* Callback function to be called every time we receive a 12.21 SW activated report */ |
| 373 | static int sw_activ_rep(struct msgb *mb) |
| 374 | { |
| 375 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
| 376 | struct gsm_bts *bts = mb->trx->bts; |
| 377 | struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, foh->obj_inst.trx_nr); |
| 378 | |
| 379 | if (!trx) |
| 380 | return -EINVAL; |
| 381 | |
| 382 | if (trx->bts->type != GSM_BTS_TYPE_NANOBTS) |
| 383 | return 0; |
| 384 | |
| 385 | switch (foh->obj_class) { |
| 386 | case NM_OC_BASEB_TRANSC: |
| 387 | abis_nm_chg_adm_state(trx->bts, foh->obj_class, |
| 388 | trx->bts->bts_nr, trx->nr, 0xff, |
| 389 | NM_STATE_UNLOCKED); |
| 390 | abis_nm_opstart(trx->bts, foh->obj_class, |
| 391 | trx->bts->bts_nr, trx->nr, 0xff); |
| 392 | /* TRX software is active, tell it to initiate RSL Link */ |
| 393 | abis_nm_ipaccess_rsl_connect(trx, 0, 3003, trx->rsl_tei); |
| 394 | break; |
| 395 | case NM_OC_RADIO_CARRIER: { |
| 396 | /* |
| 397 | * Locking the radio carrier will make it go |
| 398 | * offline again and we would come here. The |
| 399 | * framework should determine that there was |
| 400 | * no change and avoid recursion. |
| 401 | * |
| 402 | * This code is here to make sure that on start |
| 403 | * a TRX remains locked. |
| 404 | */ |
Harald Welte | d64c0bc | 2011-05-30 12:07:53 +0200 | [diff] [blame] | 405 | int rc_state = trx->mo.nm_state.administrative; |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 406 | /* Patch ARFCN into radio attribute */ |
| 407 | nanobts_attr_radio[5] &= 0xf0; |
| 408 | nanobts_attr_radio[5] |= trx->arfcn >> 8; |
| 409 | nanobts_attr_radio[6] = trx->arfcn & 0xff; |
| 410 | abis_nm_set_radio_attr(trx, nanobts_attr_radio, |
| 411 | sizeof(nanobts_attr_radio)); |
| 412 | abis_nm_chg_adm_state(trx->bts, foh->obj_class, |
| 413 | trx->bts->bts_nr, trx->nr, 0xff, |
| 414 | rc_state); |
| 415 | abis_nm_opstart(trx->bts, foh->obj_class, trx->bts->bts_nr, |
| 416 | trx->nr, 0xff); |
| 417 | break; |
| 418 | } |
| 419 | } |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | /* Callback function to be called every time we receive a signal from NM */ |
| 424 | static int nm_sig_cb(unsigned int subsys, unsigned int signal, |
| 425 | void *handler_data, void *signal_data) |
| 426 | { |
| 427 | if (subsys != SS_NM) |
| 428 | return 0; |
| 429 | |
| 430 | switch (signal) { |
| 431 | case S_NM_SW_ACTIV_REP: |
| 432 | return sw_activ_rep(signal_data); |
| 433 | case S_NM_STATECHG_OPER: |
| 434 | case S_NM_STATECHG_ADM: |
| 435 | return nm_statechg_event(signal, signal_data); |
| 436 | default: |
| 437 | break; |
| 438 | } |
| 439 | return 0; |
| 440 | } |
| 441 | |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 442 | static int bts_model_nanobts_start(struct gsm_network *net) |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 443 | { |
Holger Hans Peter Freyther | c8bf3c1 | 2010-06-21 18:11:37 +0800 | [diff] [blame] | 444 | model_nanobts.features.data = &model_nanobts._features_data[0]; |
Harald Welte | f3d8e92 | 2010-06-14 22:44:42 +0200 | [diff] [blame] | 445 | model_nanobts.features.data_len = sizeof(model_nanobts._features_data); |
| 446 | |
| 447 | gsm_btsmodel_set_feature(&model_nanobts, BTS_FEAT_GPRS); |
| 448 | gsm_btsmodel_set_feature(&model_nanobts, BTS_FEAT_EGPRS); |
| 449 | |
Pablo Neira Ayuso | bbc5b99 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 450 | osmo_signal_register_handler(SS_NM, nm_sig_cb, NULL); |
Harald Welte | f338a03 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 451 | |
Pablo Neira Ayuso | 0d2881a | 2011-05-14 11:32:48 +0200 | [diff] [blame] | 452 | /* Call A-bis input driver, start server sockets for OML and RSL. */ |
| 453 | return ipaccess_setup(net); |
| 454 | } |
| 455 | |
| 456 | int bts_model_nanobts_init(void) |
| 457 | { |
Harald Welte | 39315c4 | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 458 | return gsm_bts_model_register(&model_nanobts); |
| 459 | } |