blob: 3bd4d8fcf54b2bf8ad1c14e70fece3ab6e88182d [file] [log] [blame]
Max372868b2017-03-02 12:12:00 +01001/* OsmoHLR Control Interface implementation */
2
3/* (C) 2017 sysmocom s.f.m.c. GmbH <info@sysmocom.de>
4 * All Rights Reserved
5 *
6 * Author: Max Suraev <msuraev@sysmocom.de>
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 <stdbool.h>
24
25#include <osmocom/ctrl/control_cmd.h>
26#include <osmocom/ctrl/control_if.h>
27#include <osmocom/ctrl/ports.h>
28
29#include "gsup_server.h"
30#include "logging.h"
31#include "db.h"
32#include "hlr.h"
33#include "luop.h"
34#include "ctrl.h"
35
Max9cacb6f2017-02-20 17:22:56 +010036static int handle_cmd_ps(struct hlr *ctx, struct ctrl_cmd *cmd, bool enable)
37{
Neels Hofmeyr00b1d432017-10-17 01:43:48 +020038 struct hlr_subscriber subscr;
Max9cacb6f2017-02-20 17:22:56 +010039
Neels Hofmeyr00b1d432017-10-17 01:43:48 +020040 if (db_subscr_get_by_imsi(ctx->dbc, cmd->value, &subscr) < 0) {
Max9cacb6f2017-02-20 17:22:56 +010041 cmd->reply = "Subscriber Unknown in HLR";
42 return CTRL_CMD_ERROR;
43 }
44
Neels Hofmeyr00b1d432017-10-17 01:43:48 +020045 if (hlr_subscr_nam(ctx, &subscr, enable, true) < 0) {
Max9cacb6f2017-02-20 17:22:56 +010046 cmd->reply = "Error updating DB";
47 return CTRL_CMD_ERROR;
48 }
49
Max9cacb6f2017-02-20 17:22:56 +010050 cmd->reply = "OK";
Max9cacb6f2017-02-20 17:22:56 +010051 return CTRL_CMD_REPLY;
52}
53
54CTRL_CMD_DEFINE_WO_NOVRF(enable_ps, "enable-ps");
55static int set_enable_ps(struct ctrl_cmd *cmd, void *data)
56{
57 return handle_cmd_ps(data, cmd, true);
58}
59
60CTRL_CMD_DEFINE_WO_NOVRF(disable_ps, "disable-ps");
61static int set_disable_ps(struct ctrl_cmd *cmd, void *data)
62{
63 return handle_cmd_ps(data, cmd, false);
64}
65
Max372868b2017-03-02 12:12:00 +010066CTRL_CMD_DEFINE_WO_NOVRF(status_ps, "status-ps");
67static int set_status_ps(struct ctrl_cmd *cmd, void *data)
68{
69 struct hlr *ctx = data;
70 struct lu_operation *luop = lu_op_alloc(ctx->gs);
71 if (!luop) {
72 cmd->reply = "Internal HLR error";
73 return CTRL_CMD_ERROR;
74 }
75
76 if (!lu_op_fill_subscr(luop, ctx->dbc, cmd->value)) {
77 cmd->reply = "Subscriber Unknown in HLR";
78 return CTRL_CMD_ERROR;
79 }
80
81 cmd->reply = luop->subscr.nam_ps ? "1" : "0";
82
83 return CTRL_CMD_REPLY;
84}
85
86int hlr_ctrl_cmds_install()
87{
88 int rc = 0;
89
Max9cacb6f2017-02-20 17:22:56 +010090 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_enable_ps);
91 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_disable_ps);
Max372868b2017-03-02 12:12:00 +010092 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_status_ps);
93
94 return rc;
95}
96
97struct ctrl_handle *hlr_controlif_setup(struct hlr *ctx,
98 struct osmo_gsup_server *gs)
99{
100 int rc;
101 struct ctrl_handle *hdl = ctrl_interface_setup_dynip(ctx,
102 ctx->ctrl_bind_addr,
103 OSMO_CTRL_PORT_HLR,
104 NULL);
105 if (!hdl)
106 return NULL;
107
108 rc = hlr_ctrl_cmds_install();
109 if (rc) /* FIXME: close control interface? */
110 return NULL;
111
112 return hdl;
113}