blob: a1671712da9f57610aa5574764ceb773b96a511c [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
36CTRL_CMD_DEFINE_WO_NOVRF(status_ps, "status-ps");
37static int set_status_ps(struct ctrl_cmd *cmd, void *data)
38{
39 struct hlr *ctx = data;
40 struct lu_operation *luop = lu_op_alloc(ctx->gs);
41 if (!luop) {
42 cmd->reply = "Internal HLR error";
43 return CTRL_CMD_ERROR;
44 }
45
46 if (!lu_op_fill_subscr(luop, ctx->dbc, cmd->value)) {
47 cmd->reply = "Subscriber Unknown in HLR";
48 return CTRL_CMD_ERROR;
49 }
50
51 cmd->reply = luop->subscr.nam_ps ? "1" : "0";
52
53 return CTRL_CMD_REPLY;
54}
55
56int hlr_ctrl_cmds_install()
57{
58 int rc = 0;
59
60 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_status_ps);
61
62 return rc;
63}
64
65struct ctrl_handle *hlr_controlif_setup(struct hlr *ctx,
66 struct osmo_gsup_server *gs)
67{
68 int rc;
69 struct ctrl_handle *hdl = ctrl_interface_setup_dynip(ctx,
70 ctx->ctrl_bind_addr,
71 OSMO_CTRL_PORT_HLR,
72 NULL);
73 if (!hdl)
74 return NULL;
75
76 rc = hlr_ctrl_cmds_install();
77 if (rc) /* FIXME: close control interface? */
78 return NULL;
79
80 return hdl;
81}