blob: 3ebc7d17444720dea3a544fec1f7afca3423850e [file] [log] [blame]
Daniel Willmannc977afa2018-06-01 07:21:20 +02001/* 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
34extern vector ctrl_node_vec;
35
Alexander Couzens82182d02020-09-22 13:21:46 +020036static int ctrl_nsvc_state_cb(struct gprs_ns2_vc *nsvc, void *ctx) {
37/* FIXME: Can't get NSVC state in ns2
38 struct ctrl_cmd *cmd = (struct ctrl_cmd *)ctx;
39
40 cmd->reply = gprs_ns2_vc_state_append(cmd->reply, nsvc);
41*/
42 return 0;
43}
44
Daniel Willmannc977afa2018-06-01 07:21:20 +020045static int get_nsvc_state(struct ctrl_cmd *cmd, void *data)
46{
47 struct gbproxy_config *cfg = data;
Alexander Couzens82182d02020-09-22 13:21:46 +020048 struct gprs_ns2_inst *nsi = cfg->nsi;
49 struct gprs_ns2_nse *nse;
50 struct gbproxy_peer *peer;
Daniel Willmannc977afa2018-06-01 07:21:20 +020051
52 cmd->reply = talloc_strdup(cmd, "");
53
Alexander Couzens82182d02020-09-22 13:21:46 +020054 /* NS-VCs for SGSN */
55 nse = gprs_ns2_nse_by_nsei(nsi, cfg->nsip_sgsn_nsei);
56 if (nse)
57 gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, cmd);
58 /* NS-VCs for SGSN2 */
59 nse = gprs_ns2_nse_by_nsei(nsi, cfg->nsip_sgsn2_nsei);
60 if (nse)
61 gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, cmd);
Daniel Willmannc977afa2018-06-01 07:21:20 +020062
Alexander Couzens82182d02020-09-22 13:21:46 +020063 /* NS-VCs for BSS peers */
64 llist_for_each_entry(peer, &cfg->bts_peers, list) {
65 nse = gprs_ns2_nse_by_nsei(nsi, peer->nsei);
66 if (nse)
67 gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, cmd);
Daniel Willmannc977afa2018-06-01 07:21:20 +020068 }
Alexander Couzens82182d02020-09-22 13:21:46 +020069 cmd->reply = "Getting NSVC state not yet implemented for NS2";
70 return CTRL_CMD_ERROR;
Daniel Willmannc977afa2018-06-01 07:21:20 +020071}
72
73CTRL_CMD_DEFINE_RO(nsvc_state, "nsvc-state");
74
75static int get_gbproxy_state(struct ctrl_cmd *cmd, void *data)
76{
77 struct gbproxy_config *cfg = data;
78 struct gbproxy_peer *peer;
79
80 cmd->reply = talloc_strdup(cmd, "");
81
82 llist_for_each_entry(peer, &cfg->bts_peers, list) {
83 struct gprs_ra_id raid;
84 gsm48_parse_ra(&raid, peer->ra);
85
Max82f88462018-11-23 22:08:37 +000086 cmd->reply = talloc_asprintf_append(cmd->reply, "%u,%u,%u,%u,%u,%u,%s\n",
Daniel Willmannc977afa2018-06-01 07:21:20 +020087 peer->nsei, peer->bvci,
88 raid.mcc, raid.mnc,
89 raid.lac, raid.rac,
90 peer->blocked ? "BLOCKED" : "UNBLOCKED");
91 }
92
93 return CTRL_CMD_REPLY;
94}
95
96CTRL_CMD_DEFINE_RO(gbproxy_state, "gbproxy-state");
97
Max655ef102018-11-22 18:13:28 +010098static int get_num_peers(struct ctrl_cmd *cmd, void *data)
99{
100 struct gbproxy_config *cfg = data;
101
102 cmd->reply = talloc_strdup(cmd, "");
103 cmd->reply = talloc_asprintf_append(cmd->reply, "%u", llist_count(&cfg->bts_peers));
104
105 return CTRL_CMD_REPLY;
106}
107CTRL_CMD_DEFINE_RO(num_peers, "number-of-peers");
108
Daniel Willmannc977afa2018-06-01 07:21:20 +0200109int gb_ctrl_cmds_install(void)
110{
111 int rc = 0;
112 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_nsvc_state);
113 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_gbproxy_state);
Max655ef102018-11-22 18:13:28 +0100114 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_num_peers);
115
Daniel Willmannc977afa2018-06-01 07:21:20 +0200116 return rc;
117}