Holger Hans Peter Freyther | 1ba8fa6 | 2013-01-09 17:03:27 +0100 | [diff] [blame] | 1 | /* |
Holger Hans Peter Freyther | 611f775 | 2015-01-31 22:16:00 +0100 | [diff] [blame] | 2 | * (C) 2013-2015 by Holger Hans Peter Freyther |
| 3 | * (C) 2013-2015 by sysmocom s.f.m.c. GmbH |
Holger Hans Peter Freyther | 1ba8fa6 | 2013-01-09 17:03:27 +0100 | [diff] [blame] | 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 | */ |
Harald Welte | 5919b6a | 2014-08-20 23:47:15 +0200 | [diff] [blame] | 21 | #include <errno.h> |
Holger Hans Peter Freyther | 9edd06d | 2015-02-10 21:37:16 +0100 | [diff] [blame] | 22 | #include <time.h> |
Holger Hans Peter Freyther | 1ba8fa6 | 2013-01-09 17:03:27 +0100 | [diff] [blame] | 23 | |
Harald Welte | 5919b6a | 2014-08-20 23:47:15 +0200 | [diff] [blame] | 24 | #include <osmocom/ctrl/control_cmd.h> |
Holger Hans Peter Freyther | 5ff537c | 2013-01-09 17:30:11 +0100 | [diff] [blame] | 25 | #include <openbsc/ipaccess.h> |
Holger Hans Peter Freyther | 1ba8fa6 | 2013-01-09 17:03:27 +0100 | [diff] [blame] | 26 | #include <openbsc/gsm_data.h> |
Holger Hans Peter Freyther | 1f67232 | 2014-03-26 14:24:42 +0100 | [diff] [blame] | 27 | #include <openbsc/abis_nm.h> |
| 28 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | 9fe9846 | 2014-12-05 12:03:24 +0100 | [diff] [blame] | 29 | #include <openbsc/chan_alloc.h> |
Holger Hans Peter Freyther | 9edd06d | 2015-02-10 21:37:16 +0100 | [diff] [blame] | 30 | #include <openbsc/osmo_bsc_rf.h> |
| 31 | #include <openbsc/osmo_msc_data.h> |
Holger Hans Peter Freyther | 1ba8fa6 | 2013-01-09 17:03:27 +0100 | [diff] [blame] | 32 | |
| 33 | #define CTRL_CMD_VTY_STRING(cmdname, cmdstr, dtype, element) \ |
| 34 | CTRL_HELPER_GET_STRING(cmdname, dtype, element) \ |
| 35 | CTRL_HELPER_SET_STRING(cmdname, dtype, element) \ |
| 36 | static struct ctrl_cmd_element cmd_##cmdname = { \ |
| 37 | .name = cmdstr, \ |
Holger Hans Peter Freyther | 1ba8fa6 | 2013-01-09 17:03:27 +0100 | [diff] [blame] | 38 | .get = get_##cmdname, \ |
| 39 | .set = set_##cmdname, \ |
| 40 | .verify = verify_vty_description_string, \ |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Check that there are no newlines or comments or other things |
| 45 | * that could make the VTY configuration unparsable. |
| 46 | */ |
| 47 | static int verify_vty_description_string(struct ctrl_cmd *cmd, |
| 48 | const char *value, void *data) |
| 49 | { |
| 50 | int i; |
| 51 | const size_t len = strlen(value); |
| 52 | |
| 53 | for (i = 0; i < len; ++i) { |
| 54 | switch(value[i]) { |
| 55 | case '#': |
| 56 | case '\n': |
| 57 | case '\r': |
| 58 | cmd->reply = "String includes illegal character"; |
| 59 | return -1; |
| 60 | default: |
| 61 | break; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | CTRL_CMD_DEFINE_RANGE(net_mnc, "mnc", struct gsm_network, network_code, 0, 999); |
| 69 | CTRL_CMD_DEFINE_RANGE(net_mcc, "mcc", struct gsm_network, country_code, 1, 999); |
| 70 | CTRL_CMD_VTY_STRING(net_short_name, "short-name", struct gsm_network, name_short); |
| 71 | CTRL_CMD_VTY_STRING(net_long_name, "long-name", struct gsm_network, name_long); |
| 72 | |
Holger Hans Peter Freyther | 5ff537c | 2013-01-09 17:30:11 +0100 | [diff] [blame] | 73 | static int verify_net_apply_config(struct ctrl_cmd *cmd, const char *v, void *d) |
| 74 | { |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static int get_net_apply_config(struct ctrl_cmd *cmd, void *data) |
| 79 | { |
| 80 | cmd->reply = "Write only attribute"; |
| 81 | return CTRL_CMD_ERROR; |
| 82 | } |
| 83 | |
| 84 | static int set_net_apply_config(struct ctrl_cmd *cmd, void *data) |
| 85 | { |
| 86 | struct gsm_network *net = cmd->node; |
| 87 | struct gsm_bts *bts; |
| 88 | |
| 89 | llist_for_each_entry(bts, &net->bts_list, list) { |
| 90 | if (!is_ipaccess_bts(bts)) |
| 91 | continue; |
| 92 | |
Holger Hans Peter Freyther | fb508c6 | 2016-03-16 15:27:38 +0100 | [diff] [blame] | 93 | /* |
| 94 | * The ip.access nanoBTS seems to be unrelaible on BSSGP |
| 95 | * so let's us just reboot it. For the sysmoBTS we can just |
| 96 | * restart the process as all state is gone. |
| 97 | */ |
| 98 | if (!is_sysmobts_v2(bts) && strcmp(cmd->value, "restart") == 0) { |
| 99 | struct gsm_bts_trx *trx; |
| 100 | llist_for_each_entry_reverse(trx, &bts->trx_list, list) |
| 101 | abis_nm_ipaccess_restart(trx); |
| 102 | } else |
| 103 | ipaccess_drop_oml(bts); |
Holger Hans Peter Freyther | 5ff537c | 2013-01-09 17:30:11 +0100 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | cmd->reply = "Tried to drop the BTS"; |
| 107 | return CTRL_CMD_REPLY; |
| 108 | } |
| 109 | |
| 110 | CTRL_CMD_DEFINE(net_apply_config, "apply-configuration"); |
| 111 | |
Holger Hans Peter Freyther | eab2a3f | 2014-03-04 17:16:58 +0100 | [diff] [blame] | 112 | static int verify_net_mcc_mnc_apply(struct ctrl_cmd *cmd, const char *value, void *d) |
| 113 | { |
| 114 | char *tmp, *saveptr, *mcc, *mnc; |
| 115 | |
| 116 | tmp = talloc_strdup(cmd, value); |
| 117 | if (!tmp) |
| 118 | return 1; |
| 119 | |
| 120 | mcc = strtok_r(tmp, ",", &saveptr); |
| 121 | mnc = strtok_r(NULL, ",", &saveptr); |
| 122 | talloc_free(tmp); |
| 123 | |
| 124 | if (!mcc || !mnc) |
| 125 | return 1; |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static int get_net_mcc_mnc_apply(struct ctrl_cmd *cmd, void *data) |
| 130 | { |
| 131 | cmd->reply = "Write only attribute"; |
| 132 | return CTRL_CMD_ERROR; |
| 133 | } |
| 134 | |
| 135 | static int set_net_mcc_mnc_apply(struct ctrl_cmd *cmd, void *data) |
| 136 | { |
| 137 | struct gsm_network *net = cmd->node; |
| 138 | char *tmp, *saveptr, *mcc_str, *mnc_str; |
| 139 | int mcc, mnc; |
| 140 | |
| 141 | tmp = talloc_strdup(cmd, cmd->value); |
| 142 | if (!tmp) |
| 143 | goto oom; |
| 144 | |
| 145 | |
| 146 | mcc_str = strtok_r(tmp, ",", &saveptr); |
| 147 | mnc_str = strtok_r(NULL, ",", &saveptr); |
| 148 | |
| 149 | mcc = atoi(mcc_str); |
| 150 | mnc = atoi(mnc_str); |
| 151 | |
| 152 | talloc_free(tmp); |
| 153 | |
| 154 | if (net->network_code == mnc && net->country_code == mcc) { |
| 155 | cmd->reply = "Nothing changed"; |
| 156 | return CTRL_CMD_REPLY; |
| 157 | } |
| 158 | |
| 159 | net->network_code = mnc; |
| 160 | net->country_code = mcc; |
| 161 | |
| 162 | return set_net_apply_config(cmd, data); |
| 163 | |
| 164 | oom: |
| 165 | cmd->reply = "OOM"; |
| 166 | return CTRL_CMD_ERROR; |
| 167 | } |
| 168 | CTRL_CMD_DEFINE(net_mcc_mnc_apply, "mcc-mnc-apply"); |
| 169 | |
Holger Hans Peter Freyther | ba8679d | 2014-11-10 11:41:03 +0100 | [diff] [blame] | 170 | /* BTS related commands below */ |
| 171 | CTRL_CMD_DEFINE_RANGE(bts_lac, "location-area-code", struct gsm_bts, location_area_code, 0, 65535); |
Holger Hans Peter Freyther | 982bb29 | 2014-11-21 10:54:42 +0100 | [diff] [blame] | 172 | CTRL_CMD_DEFINE_RANGE(bts_ci, "cell-identity", struct gsm_bts, cell_identity, 0, 65535); |
Holger Hans Peter Freyther | ba8679d | 2014-11-10 11:41:03 +0100 | [diff] [blame] | 173 | |
Holger Hans Peter Freyther | 87b35d5 | 2014-11-21 10:20:29 +0100 | [diff] [blame] | 174 | static int verify_bts_apply_config(struct ctrl_cmd *cmd, const char *v, void *d) |
| 175 | { |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | static int get_bts_apply_config(struct ctrl_cmd *cmd, void *data) |
| 180 | { |
| 181 | cmd->reply = "Write only attribute"; |
| 182 | return CTRL_CMD_ERROR; |
| 183 | } |
| 184 | |
| 185 | static int set_bts_apply_config(struct ctrl_cmd *cmd, void *data) |
| 186 | { |
| 187 | struct gsm_bts *bts = cmd->node; |
| 188 | |
| 189 | if (!is_ipaccess_bts(bts)) { |
| 190 | cmd->reply = "BTS is not IP based"; |
| 191 | return CTRL_CMD_ERROR; |
| 192 | } |
| 193 | |
| 194 | ipaccess_drop_oml(bts); |
| 195 | cmd->reply = "Tried to drop the BTS"; |
| 196 | return CTRL_CMD_REPLY; |
| 197 | } |
| 198 | |
| 199 | CTRL_CMD_DEFINE(bts_apply_config, "apply-configuration"); |
| 200 | |
Holger Hans Peter Freyther | d0284c8 | 2014-11-21 11:18:45 +0100 | [diff] [blame] | 201 | static int verify_bts_si(struct ctrl_cmd *cmd, const char *v, void *d) |
| 202 | { |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | static int get_bts_si(struct ctrl_cmd *cmd, void *data) |
| 207 | { |
| 208 | cmd->reply = "Write only attribute"; |
| 209 | return CTRL_CMD_ERROR; |
| 210 | } |
| 211 | |
| 212 | static int set_bts_si(struct ctrl_cmd *cmd, void *data) |
| 213 | { |
| 214 | struct gsm_bts *bts = cmd->node; |
Alexander Chemeris | 143ac5f | 2015-05-30 14:40:54 -0400 | [diff] [blame] | 215 | int rc; |
Holger Hans Peter Freyther | d0284c8 | 2014-11-21 11:18:45 +0100 | [diff] [blame] | 216 | |
Alexander Chemeris | 143ac5f | 2015-05-30 14:40:54 -0400 | [diff] [blame] | 217 | rc = gsm_bts_set_system_infos(bts); |
| 218 | if (rc != 0) { |
| 219 | cmd->reply = "Failed to generate SI"; |
| 220 | return CTRL_CMD_ERROR; |
Holger Hans Peter Freyther | d0284c8 | 2014-11-21 11:18:45 +0100 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | cmd->reply = "Generated new System Information"; |
| 224 | return CTRL_CMD_REPLY; |
| 225 | } |
| 226 | CTRL_CMD_DEFINE(bts_si, "send-new-system-informations"); |
| 227 | |
Holger Hans Peter Freyther | 9fe9846 | 2014-12-05 12:03:24 +0100 | [diff] [blame] | 228 | static int verify_bts_chan_load(struct ctrl_cmd *cmd, const char *v, void *d) |
| 229 | { |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | static int get_bts_chan_load(struct ctrl_cmd *cmd, void *data) |
| 234 | { |
| 235 | int i; |
| 236 | struct pchan_load pl; |
| 237 | struct gsm_bts *bts; |
| 238 | const char *space = ""; |
| 239 | |
| 240 | bts = cmd->node; |
| 241 | memset(&pl, 0, sizeof(pl)); |
Alexander Couzens | 92866f0 | 2016-08-29 18:45:42 +0200 | [diff] [blame^] | 242 | bts_chan_load(&pl, bts, 0); |
Holger Hans Peter Freyther | 9fe9846 | 2014-12-05 12:03:24 +0100 | [diff] [blame] | 243 | |
| 244 | cmd->reply = talloc_strdup(cmd, ""); |
| 245 | |
| 246 | for (i = 0; i < ARRAY_SIZE(pl.pchan); ++i) { |
| 247 | const struct load_counter *lc = &pl.pchan[i]; |
| 248 | |
| 249 | /* These can never have user load */ |
| 250 | if (i == GSM_PCHAN_NONE) |
| 251 | continue; |
| 252 | if (i == GSM_PCHAN_CCCH) |
| 253 | continue; |
| 254 | if (i == GSM_PCHAN_PDCH) |
| 255 | continue; |
Holger Hans Peter Freyther | 5f3657d | 2015-01-31 19:42:42 +0100 | [diff] [blame] | 256 | if (i == GSM_PCHAN_UNKNOWN) |
| 257 | continue; |
Holger Hans Peter Freyther | 9fe9846 | 2014-12-05 12:03:24 +0100 | [diff] [blame] | 258 | |
| 259 | cmd->reply = talloc_asprintf_append(cmd->reply, |
| 260 | "%s%s,%u,%u", |
| 261 | space, gsm_pchan_name(i), lc->used, lc->total); |
| 262 | if (!cmd->reply) |
| 263 | goto error; |
| 264 | space = " "; |
| 265 | } |
| 266 | |
| 267 | return CTRL_CMD_REPLY; |
| 268 | |
| 269 | error: |
| 270 | cmd->reply = "Memory allocation failure"; |
| 271 | return CTRL_CMD_ERROR; |
| 272 | } |
| 273 | |
| 274 | static int set_bts_chan_load(struct ctrl_cmd *cmd, void *data) |
| 275 | { |
| 276 | cmd->reply = "Read only attribute"; |
| 277 | return CTRL_CMD_ERROR; |
| 278 | } |
| 279 | CTRL_CMD_DEFINE(bts_chan_load, "channel-load"); |
| 280 | |
Holger Hans Peter Freyther | 0c47d9e | 2014-12-05 14:44:21 +0100 | [diff] [blame] | 281 | static int verify_bts_oml_conn(struct ctrl_cmd *cmd, const char *value, void *_data) |
| 282 | { |
| 283 | struct gsm_bts *bts = cmd->node; |
| 284 | |
| 285 | if (!is_ipaccess_bts(bts)) { |
| 286 | cmd->reply = ""; |
| 287 | return -1; |
| 288 | } |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | static int get_bts_oml_conn(struct ctrl_cmd *cmd, void *data) |
| 293 | { |
| 294 | struct gsm_bts *bts = cmd->node; |
| 295 | |
| 296 | cmd->reply = bts->oml_link ? "connected" : "disconnected"; |
| 297 | return CTRL_CMD_REPLY; |
| 298 | } |
| 299 | |
| 300 | static int set_bts_oml_conn(struct ctrl_cmd *cmd, void *data) |
| 301 | { |
| 302 | cmd->reply = "Read only attribute"; |
| 303 | return CTRL_CMD_ERROR; |
| 304 | } |
| 305 | CTRL_CMD_DEFINE(bts_oml_conn, "oml-connection-state"); |
| 306 | |
Holger Hans Peter Freyther | 611f775 | 2015-01-31 22:16:00 +0100 | [diff] [blame] | 307 | static int verify_bts_gprs_mode(struct ctrl_cmd *cmd, const char *value, void *_data) |
| 308 | { |
| 309 | int valid; |
| 310 | enum bts_gprs_mode mode; |
| 311 | struct gsm_bts *bts = cmd->node; |
| 312 | |
| 313 | mode = bts_gprs_mode_parse(value, &valid); |
| 314 | if (!valid) { |
| 315 | cmd->reply = "Mode is not known"; |
| 316 | return 1; |
| 317 | } |
| 318 | |
| 319 | if (!bts_gprs_mode_is_compat(bts, mode)) { |
| 320 | cmd->reply = "bts does not support this mode"; |
| 321 | return 1; |
| 322 | } |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | static int get_bts_gprs_mode(struct ctrl_cmd *cmd, void *data) |
| 328 | { |
| 329 | struct gsm_bts *bts = cmd->node; |
| 330 | |
| 331 | cmd->reply = talloc_strdup(cmd, bts_gprs_mode_name(bts->gprs.mode)); |
| 332 | return CTRL_CMD_REPLY; |
| 333 | } |
| 334 | |
| 335 | static int set_bts_gprs_mode(struct ctrl_cmd *cmd, void *data) |
| 336 | { |
| 337 | struct gsm_bts *bts = cmd->node; |
| 338 | |
| 339 | bts->gprs.mode = bts_gprs_mode_parse(cmd->value, NULL); |
| 340 | return get_bts_gprs_mode(cmd, data); |
| 341 | } |
| 342 | |
| 343 | CTRL_CMD_DEFINE(bts_gprs_mode, "gprs-mode"); |
| 344 | |
Holger Hans Peter Freyther | 9edd06d | 2015-02-10 21:37:16 +0100 | [diff] [blame] | 345 | static int get_bts_rf_state(struct ctrl_cmd *cmd, void *data) |
| 346 | { |
| 347 | const char *oper, *admin, *policy; |
| 348 | struct gsm_bts *bts = cmd->node; |
| 349 | |
| 350 | if (!bts) { |
| 351 | cmd->reply = "bts not found."; |
| 352 | return CTRL_CMD_ERROR; |
| 353 | } |
| 354 | |
| 355 | oper = osmo_bsc_rf_get_opstate_name(osmo_bsc_rf_get_opstate_by_bts(bts)); |
| 356 | admin = osmo_bsc_rf_get_adminstate_name(osmo_bsc_rf_get_adminstate_by_bts(bts)); |
| 357 | policy = osmo_bsc_rf_get_policy_name(osmo_bsc_rf_get_policy_by_bts(bts)); |
| 358 | |
| 359 | cmd->reply = talloc_asprintf(cmd, "%s,%s,%s", oper, admin, policy); |
| 360 | if (!cmd->reply) { |
| 361 | cmd->reply = "OOM."; |
| 362 | return CTRL_CMD_ERROR; |
| 363 | } |
| 364 | |
| 365 | return CTRL_CMD_REPLY; |
| 366 | } |
| 367 | CTRL_CMD_DEFINE_RO(bts_rf_state, "rf_state"); |
| 368 | |
| 369 | static int get_net_rf_lock(struct ctrl_cmd *cmd, void *data) |
| 370 | { |
Holger Hans Peter Freyther | d476a80 | 2015-02-10 23:03:25 +0100 | [diff] [blame] | 371 | struct gsm_network *net = cmd->node; |
| 372 | struct gsm_bts *bts; |
| 373 | const char *policy_name; |
| 374 | |
| 375 | policy_name = osmo_bsc_rf_get_policy_name(net->bsc_data->rf_ctrl->policy); |
| 376 | |
| 377 | llist_for_each_entry(bts, &net->bts_list, list) { |
| 378 | struct gsm_bts_trx *trx; |
| 379 | |
| 380 | /* Exclude the BTS from the global lock */ |
| 381 | if (bts->excl_from_rf_lock) |
| 382 | continue; |
| 383 | |
| 384 | llist_for_each_entry(trx, &bts->trx_list, list) { |
| 385 | if (trx->mo.nm_state.availability == NM_AVSTATE_OK && |
| 386 | trx->mo.nm_state.operational != NM_OPSTATE_DISABLED) { |
| 387 | cmd->reply = talloc_asprintf(cmd, |
| 388 | "state=on,policy=%s,bts=%u,trx=%u", |
| 389 | policy_name, bts->nr, trx->nr); |
| 390 | return CTRL_CMD_REPLY; |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | cmd->reply = talloc_asprintf(cmd, "state=off,policy=%s", |
| 396 | policy_name); |
| 397 | return CTRL_CMD_REPLY; |
Holger Hans Peter Freyther | 9edd06d | 2015-02-10 21:37:16 +0100 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | #define TIME_FORMAT_RFC2822 "%a, %d %b %Y %T %z" |
| 401 | |
| 402 | static int set_net_rf_lock(struct ctrl_cmd *cmd, void *data) |
| 403 | { |
| 404 | int locked = atoi(cmd->value); |
| 405 | struct gsm_network *net = cmd->node; |
| 406 | time_t now = time(NULL); |
| 407 | char now_buf[64]; |
| 408 | struct osmo_bsc_rf *rf; |
| 409 | |
| 410 | if (!net) { |
| 411 | cmd->reply = "net not found."; |
| 412 | return CTRL_CMD_ERROR; |
| 413 | } |
| 414 | |
| 415 | rf = net->bsc_data->rf_ctrl; |
| 416 | |
| 417 | if (!rf) { |
| 418 | cmd->reply = "RF Ctrl is not enabled in the BSC Configuration"; |
| 419 | return CTRL_CMD_ERROR; |
| 420 | } |
| 421 | |
| 422 | talloc_free(rf->last_rf_lock_ctrl_command); |
| 423 | strftime(now_buf, sizeof(now_buf), TIME_FORMAT_RFC2822, gmtime(&now)); |
| 424 | rf->last_rf_lock_ctrl_command = |
| 425 | talloc_asprintf(rf, "rf_locked %u (%s)", locked, now_buf); |
| 426 | |
| 427 | osmo_bsc_rf_schedule_lock(rf, locked == 1 ? '0' : '1'); |
| 428 | |
| 429 | cmd->reply = talloc_asprintf(cmd, "%u", locked); |
| 430 | if (!cmd->reply) { |
| 431 | cmd->reply = "OOM."; |
| 432 | return CTRL_CMD_ERROR; |
| 433 | } |
| 434 | |
| 435 | return CTRL_CMD_REPLY; |
| 436 | } |
| 437 | |
| 438 | static int verify_net_rf_lock(struct ctrl_cmd *cmd, const char *value, void *data) |
| 439 | { |
| 440 | int locked = atoi(cmd->value); |
| 441 | |
| 442 | if ((locked != 0) && (locked != 1)) |
| 443 | return 1; |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | CTRL_CMD_DEFINE(net_rf_lock, "rf_locked"); |
Holger Hans Peter Freyther | 611f775 | 2015-01-31 22:16:00 +0100 | [diff] [blame] | 448 | |
Holger Hans Peter Freyther | bbd8ea1 | 2015-02-10 21:55:37 +0100 | [diff] [blame] | 449 | static int get_net_bts_num(struct ctrl_cmd *cmd, void *data) |
| 450 | { |
| 451 | struct gsm_network *net = cmd->node; |
| 452 | |
| 453 | cmd->reply = talloc_asprintf(cmd, "%u", net->num_bts); |
| 454 | return CTRL_CMD_REPLY; |
| 455 | } |
| 456 | CTRL_CMD_DEFINE_RO(net_bts_num, "number-of-bts"); |
| 457 | |
Holger Hans Peter Freyther | 2de4689 | 2014-03-23 11:17:27 +0100 | [diff] [blame] | 458 | /* TRX related commands below here */ |
| 459 | CTRL_HELPER_GET_INT(trx_max_power, struct gsm_bts_trx, max_power_red); |
Holger Hans Peter Freyther | 2de4689 | 2014-03-23 11:17:27 +0100 | [diff] [blame] | 460 | static int verify_trx_max_power(struct ctrl_cmd *cmd, const char *value, void *_data) |
| 461 | { |
| 462 | int tmp = atoi(value); |
| 463 | |
| 464 | if (tmp < 0 || tmp > 22) { |
| 465 | cmd->reply = "Value must be between 0 and 22"; |
| 466 | return -1; |
| 467 | } |
| 468 | |
| 469 | if (tmp & 1) { |
| 470 | cmd->reply = "Value must be even"; |
| 471 | return -1; |
| 472 | } |
| 473 | |
| 474 | return 0; |
| 475 | } |
Holger Hans Peter Freyther | b96705b | 2013-01-09 19:55:04 +0100 | [diff] [blame] | 476 | CTRL_CMD_DEFINE_RANGE(trx_arfcn, "arfcn", struct gsm_bts_trx, arfcn, 0, 1023); |
Holger Hans Peter Freyther | 1f67232 | 2014-03-26 14:24:42 +0100 | [diff] [blame] | 477 | |
| 478 | static int set_trx_max_power(struct ctrl_cmd *cmd, void *_data) |
| 479 | { |
| 480 | struct gsm_bts_trx *trx = cmd->node; |
| 481 | int old_power; |
| 482 | |
| 483 | /* remember the old value, set the new one */ |
| 484 | old_power = trx->max_power_red; |
| 485 | trx->max_power_red = atoi(cmd->value); |
| 486 | |
| 487 | /* Maybe update the value */ |
| 488 | if (old_power != trx->max_power_red) { |
| 489 | LOGP(DCTRL, LOGL_NOTICE, |
| 490 | "%s updating max_pwr_red(%d)\n", |
| 491 | gsm_trx_name(trx), trx->max_power_red); |
| 492 | abis_nm_update_max_power_red(trx); |
| 493 | } |
| 494 | |
| 495 | return get_trx_max_power(cmd, _data); |
| 496 | } |
Holger Hans Peter Freyther | 2de4689 | 2014-03-23 11:17:27 +0100 | [diff] [blame] | 497 | CTRL_CMD_DEFINE(trx_max_power, "max-power-reduction"); |
| 498 | |
Holger Hans Peter Freyther | 1ba8fa6 | 2013-01-09 17:03:27 +0100 | [diff] [blame] | 499 | int bsc_base_ctrl_cmds_install(void) |
| 500 | { |
| 501 | int rc = 0; |
| 502 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mnc); |
| 503 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mcc); |
| 504 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_short_name); |
| 505 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_long_name); |
Holger Hans Peter Freyther | 5ff537c | 2013-01-09 17:30:11 +0100 | [diff] [blame] | 506 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_apply_config); |
Holger Hans Peter Freyther | eab2a3f | 2014-03-04 17:16:58 +0100 | [diff] [blame] | 507 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mcc_mnc_apply); |
Holger Hans Peter Freyther | 9edd06d | 2015-02-10 21:37:16 +0100 | [diff] [blame] | 508 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_rf_lock); |
Holger Hans Peter Freyther | bbd8ea1 | 2015-02-10 21:55:37 +0100 | [diff] [blame] | 509 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_bts_num); |
Holger Hans Peter Freyther | 1ba8fa6 | 2013-01-09 17:03:27 +0100 | [diff] [blame] | 510 | |
Holger Hans Peter Freyther | ba8679d | 2014-11-10 11:41:03 +0100 | [diff] [blame] | 511 | rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_lac); |
Holger Hans Peter Freyther | 982bb29 | 2014-11-21 10:54:42 +0100 | [diff] [blame] | 512 | rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_ci); |
Holger Hans Peter Freyther | 87b35d5 | 2014-11-21 10:20:29 +0100 | [diff] [blame] | 513 | rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_apply_config); |
Holger Hans Peter Freyther | d0284c8 | 2014-11-21 11:18:45 +0100 | [diff] [blame] | 514 | rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_si); |
Holger Hans Peter Freyther | 9fe9846 | 2014-12-05 12:03:24 +0100 | [diff] [blame] | 515 | rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_chan_load); |
Holger Hans Peter Freyther | 0c47d9e | 2014-12-05 14:44:21 +0100 | [diff] [blame] | 516 | rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_oml_conn); |
Holger Hans Peter Freyther | 611f775 | 2015-01-31 22:16:00 +0100 | [diff] [blame] | 517 | rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_gprs_mode); |
Holger Hans Peter Freyther | 9edd06d | 2015-02-10 21:37:16 +0100 | [diff] [blame] | 518 | rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_rf_state); |
Holger Hans Peter Freyther | ba8679d | 2014-11-10 11:41:03 +0100 | [diff] [blame] | 519 | |
Holger Hans Peter Freyther | 2de4689 | 2014-03-23 11:17:27 +0100 | [diff] [blame] | 520 | rc |= ctrl_cmd_install(CTRL_NODE_TRX, &cmd_trx_max_power); |
Holger Hans Peter Freyther | b96705b | 2013-01-09 19:55:04 +0100 | [diff] [blame] | 521 | rc |= ctrl_cmd_install(CTRL_NODE_TRX, &cmd_trx_arfcn); |
| 522 | |
Holger Hans Peter Freyther | 1ba8fa6 | 2013-01-09 17:03:27 +0100 | [diff] [blame] | 523 | return rc; |
| 524 | } |