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 | { |
| 38 | struct lu_operation *luop = NULL; |
| 39 | struct osmo_gsup_conn *co; |
| 40 | |
| 41 | if (db_subscr_get(ctx->dbc, cmd->value, NULL) < 0) { |
| 42 | cmd->reply = "Subscriber Unknown in HLR"; |
| 43 | return CTRL_CMD_ERROR; |
| 44 | } |
| 45 | |
| 46 | if (db_subscr_ps(ctx->dbc, cmd->value, enable) < 0) { |
| 47 | cmd->reply = "Error updating DB"; |
| 48 | return CTRL_CMD_ERROR; |
| 49 | } |
| 50 | |
| 51 | /* FIXME: only send to single SGSN where latest update for IMSI came from */ |
| 52 | if (!enable) { |
| 53 | llist_for_each_entry(co, &ctx->gs->clients, list) { |
| 54 | luop = lu_op_alloc_conn(co); |
| 55 | lu_op_fill_subscr(luop, ctx->dbc, cmd->value); |
| 56 | lu_op_tx_del_subscr_data(luop); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | cmd->reply = "OK"; |
| 61 | |
| 62 | return CTRL_CMD_REPLY; |
| 63 | } |
| 64 | |
| 65 | CTRL_CMD_DEFINE_WO_NOVRF(enable_ps, "enable-ps"); |
| 66 | static int set_enable_ps(struct ctrl_cmd *cmd, void *data) |
| 67 | { |
| 68 | return handle_cmd_ps(data, cmd, true); |
| 69 | } |
| 70 | |
| 71 | CTRL_CMD_DEFINE_WO_NOVRF(disable_ps, "disable-ps"); |
| 72 | static int set_disable_ps(struct ctrl_cmd *cmd, void *data) |
| 73 | { |
| 74 | return handle_cmd_ps(data, cmd, false); |
| 75 | } |
| 76 | |
Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 77 | CTRL_CMD_DEFINE_WO_NOVRF(status_ps, "status-ps"); |
| 78 | static int set_status_ps(struct ctrl_cmd *cmd, void *data) |
| 79 | { |
| 80 | struct hlr *ctx = data; |
| 81 | struct lu_operation *luop = lu_op_alloc(ctx->gs); |
| 82 | if (!luop) { |
| 83 | cmd->reply = "Internal HLR error"; |
| 84 | return CTRL_CMD_ERROR; |
| 85 | } |
| 86 | |
| 87 | if (!lu_op_fill_subscr(luop, ctx->dbc, cmd->value)) { |
| 88 | cmd->reply = "Subscriber Unknown in HLR"; |
| 89 | return CTRL_CMD_ERROR; |
| 90 | } |
| 91 | |
| 92 | cmd->reply = luop->subscr.nam_ps ? "1" : "0"; |
| 93 | |
| 94 | return CTRL_CMD_REPLY; |
| 95 | } |
| 96 | |
| 97 | int hlr_ctrl_cmds_install() |
| 98 | { |
| 99 | int rc = 0; |
| 100 | |
Max | 9cacb6f | 2017-02-20 17:22:56 +0100 | [diff] [blame] | 101 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_enable_ps); |
| 102 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_disable_ps); |
Max | 372868b | 2017-03-02 12:12:00 +0100 | [diff] [blame] | 103 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_status_ps); |
| 104 | |
| 105 | return rc; |
| 106 | } |
| 107 | |
| 108 | struct ctrl_handle *hlr_controlif_setup(struct hlr *ctx, |
| 109 | struct osmo_gsup_server *gs) |
| 110 | { |
| 111 | int rc; |
| 112 | struct ctrl_handle *hdl = ctrl_interface_setup_dynip(ctx, |
| 113 | ctx->ctrl_bind_addr, |
| 114 | OSMO_CTRL_PORT_HLR, |
| 115 | NULL); |
| 116 | if (!hdl) |
| 117 | return NULL; |
| 118 | |
| 119 | rc = hlr_ctrl_cmds_install(); |
| 120 | if (rc) /* FIXME: close control interface? */ |
| 121 | return NULL; |
| 122 | |
| 123 | return hdl; |
| 124 | } |