Daniel Willmann | c977afa | 2018-06-01 07:21:20 +0200 | [diff] [blame] | 1 | /* Control Interface Implementation for the Gb-proxy */ |
| 2 | /* |
| 3 | * (C) 2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * Author: Daniel Willmann |
| 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 | |
| 23 | #include <osmocom/core/talloc.h> |
| 24 | |
| 25 | |
| 26 | #include <osmocom/gprs/gprs_bssgp.h> |
| 27 | #include <osmocom/gprs/gprs_ns.h> |
| 28 | |
| 29 | #include <osmocom/ctrl/control_if.h> |
| 30 | #include <osmocom/ctrl/control_cmd.h> |
| 31 | #include <osmocom/sgsn/gb_proxy.h> |
| 32 | #include <osmocom/sgsn/debug.h> |
| 33 | |
| 34 | extern vector ctrl_node_vec; |
| 35 | |
| 36 | static int get_nsvc_state(struct ctrl_cmd *cmd, void *data) |
| 37 | { |
| 38 | struct gbproxy_config *cfg = data; |
| 39 | struct gprs_ns_inst *nsi = cfg->nsi; |
| 40 | struct gprs_nsvc *nsvc; |
| 41 | |
| 42 | cmd->reply = talloc_strdup(cmd, ""); |
| 43 | |
| 44 | llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { |
| 45 | if (nsvc == nsi->unknown_nsvc) |
| 46 | continue; |
| 47 | |
| 48 | cmd->reply = gprs_nsvc_state_append(cmd->reply, nsvc); |
| 49 | } |
| 50 | |
| 51 | return CTRL_CMD_REPLY; |
| 52 | } |
| 53 | |
| 54 | CTRL_CMD_DEFINE_RO(nsvc_state, "nsvc-state"); |
| 55 | |
| 56 | static int get_gbproxy_state(struct ctrl_cmd *cmd, void *data) |
| 57 | { |
| 58 | struct gbproxy_config *cfg = data; |
| 59 | struct gbproxy_peer *peer; |
| 60 | |
| 61 | cmd->reply = talloc_strdup(cmd, ""); |
| 62 | |
| 63 | llist_for_each_entry(peer, &cfg->bts_peers, list) { |
| 64 | struct gprs_ra_id raid; |
| 65 | gsm48_parse_ra(&raid, peer->ra); |
| 66 | |
Max | 82f8846 | 2018-11-23 22:08:37 +0000 | [diff] [blame] | 67 | cmd->reply = talloc_asprintf_append(cmd->reply, "%u,%u,%u,%u,%u,%u,%s\n", |
Daniel Willmann | c977afa | 2018-06-01 07:21:20 +0200 | [diff] [blame] | 68 | peer->nsei, peer->bvci, |
| 69 | raid.mcc, raid.mnc, |
| 70 | raid.lac, raid.rac, |
| 71 | peer->blocked ? "BLOCKED" : "UNBLOCKED"); |
| 72 | } |
| 73 | |
| 74 | return CTRL_CMD_REPLY; |
| 75 | } |
| 76 | |
| 77 | CTRL_CMD_DEFINE_RO(gbproxy_state, "gbproxy-state"); |
| 78 | |
Max | 655ef10 | 2018-11-22 18:13:28 +0100 | [diff] [blame] | 79 | static int get_num_peers(struct ctrl_cmd *cmd, void *data) |
| 80 | { |
| 81 | struct gbproxy_config *cfg = data; |
| 82 | |
| 83 | cmd->reply = talloc_strdup(cmd, ""); |
| 84 | cmd->reply = talloc_asprintf_append(cmd->reply, "%u", llist_count(&cfg->bts_peers)); |
| 85 | |
| 86 | return CTRL_CMD_REPLY; |
| 87 | } |
| 88 | CTRL_CMD_DEFINE_RO(num_peers, "number-of-peers"); |
| 89 | |
Daniel Willmann | c977afa | 2018-06-01 07:21:20 +0200 | [diff] [blame] | 90 | int gb_ctrl_cmds_install(void) |
| 91 | { |
| 92 | int rc = 0; |
| 93 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_nsvc_state); |
| 94 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_gbproxy_state); |
Max | 655ef10 | 2018-11-22 18:13:28 +0100 | [diff] [blame] | 95 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_num_peers); |
| 96 | |
Daniel Willmann | c977afa | 2018-06-01 07:21:20 +0200 | [diff] [blame] | 97 | return rc; |
| 98 | } |