Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 1 | /* 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 | |
Max | 9cacb6f | 2017-02-20 17:22:56 +0100 | [diff] [blame] | 36 | static int handle_cmd_ps(struct hlr *ctx, struct ctrl_cmd *cmd, bool enable) |
| 37 | { |
Neels Hofmeyr | 00b1d43 | 2017-10-17 01:43:48 +0200 | [diff] [blame^] | 38 | struct hlr_subscriber subscr; |
Max | 9cacb6f | 2017-02-20 17:22:56 +0100 | [diff] [blame] | 39 | |
Neels Hofmeyr | 00b1d43 | 2017-10-17 01:43:48 +0200 | [diff] [blame^] | 40 | if (db_subscr_get_by_imsi(ctx->dbc, cmd->value, &subscr) < 0) { |
Max | 9cacb6f | 2017-02-20 17:22:56 +0100 | [diff] [blame] | 41 | cmd->reply = "Subscriber Unknown in HLR"; |
| 42 | return CTRL_CMD_ERROR; |
| 43 | } |
| 44 | |
Neels Hofmeyr | 00b1d43 | 2017-10-17 01:43:48 +0200 | [diff] [blame^] | 45 | if (hlr_subscr_nam(ctx, &subscr, enable, true) < 0) { |
Max | 9cacb6f | 2017-02-20 17:22:56 +0100 | [diff] [blame] | 46 | cmd->reply = "Error updating DB"; |
| 47 | return CTRL_CMD_ERROR; |
| 48 | } |
| 49 | |
Max | 9cacb6f | 2017-02-20 17:22:56 +0100 | [diff] [blame] | 50 | cmd->reply = "OK"; |
Max | 9cacb6f | 2017-02-20 17:22:56 +0100 | [diff] [blame] | 51 | return CTRL_CMD_REPLY; |
| 52 | } |
| 53 | |
| 54 | CTRL_CMD_DEFINE_WO_NOVRF(enable_ps, "enable-ps"); |
| 55 | static int set_enable_ps(struct ctrl_cmd *cmd, void *data) |
| 56 | { |
| 57 | return handle_cmd_ps(data, cmd, true); |
| 58 | } |
| 59 | |
| 60 | CTRL_CMD_DEFINE_WO_NOVRF(disable_ps, "disable-ps"); |
| 61 | static int set_disable_ps(struct ctrl_cmd *cmd, void *data) |
| 62 | { |
| 63 | return handle_cmd_ps(data, cmd, false); |
| 64 | } |
| 65 | |
Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 66 | CTRL_CMD_DEFINE_WO_NOVRF(status_ps, "status-ps"); |
| 67 | static 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 | |
| 86 | int hlr_ctrl_cmds_install() |
| 87 | { |
| 88 | int rc = 0; |
| 89 | |
Max | 9cacb6f | 2017-02-20 17:22:56 +0100 | [diff] [blame] | 90 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_enable_ps); |
| 91 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_disable_ps); |
Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 92 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_status_ps); |
| 93 | |
| 94 | return rc; |
| 95 | } |
| 96 | |
| 97 | struct 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 | } |