Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2014 by Holger Hans Peter Freyther |
| 3 | * (C) 2014 by sysmocom s.f.m.c. GmbH |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
Max | 0fcd2e2 | 2016-06-07 15:32:16 +0200 | [diff] [blame] | 21 | |
Harald Welte | ba874b8 | 2014-08-20 23:47:15 +0200 | [diff] [blame] | 22 | #include <osmocom/ctrl/control_cmd.h> |
Neels Hofmeyr | 93bafb6 | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 23 | #include <osmocom/core/utils.h> |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 24 | #include <openbsc/gsm_data.h> |
| 25 | #include <openbsc/gsm_subscriber.h> |
| 26 | #include <openbsc/db.h> |
Holger Hans Peter Freyther | 2d99eeb | 2014-03-23 14:01:08 +0100 | [diff] [blame] | 27 | #include <openbsc/debug.h> |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 28 | #include <openbsc/vlr.h> |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 29 | |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 30 | #include <stdbool.h> |
| 31 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 32 | static struct gsm_network *msc_ctrl_net = NULL; |
Holger Hans Peter Freyther | 9bcb1a5 | 2016-04-06 22:41:12 +0200 | [diff] [blame] | 33 | |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 34 | static int verify_subscriber_modify(struct ctrl_cmd *cmd, const char *value, void *d) |
| 35 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 36 | return 0; |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 37 | } |
| 38 | |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 39 | static int set_subscriber_modify(struct ctrl_cmd *cmd, void *data) |
| 40 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 41 | cmd->reply = "Command moved to osmo-hlr, no longer available here"; |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 42 | return CTRL_CMD_ERROR; |
| 43 | } |
| 44 | |
Max | f6e5170 | 2017-01-11 18:37:55 +0100 | [diff] [blame] | 45 | CTRL_CMD_DEFINE_WO(subscriber_modify, "subscriber-modify-v1"); |
Holger Hans Peter Freyther | 2d99eeb | 2014-03-23 14:01:08 +0100 | [diff] [blame] | 46 | |
| 47 | static int set_subscriber_delete(struct ctrl_cmd *cmd, void *data) |
| 48 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 49 | cmd->reply = "Command moved to osmo-hlr, no longer available here"; |
| 50 | return CTRL_CMD_ERROR; |
Holger Hans Peter Freyther | 2d99eeb | 2014-03-23 14:01:08 +0100 | [diff] [blame] | 51 | } |
Max | f6e5170 | 2017-01-11 18:37:55 +0100 | [diff] [blame] | 52 | CTRL_CMD_DEFINE_WO_NOVRF(subscriber_delete, "subscriber-delete-v1"); |
Holger Hans Peter Freyther | 2d99eeb | 2014-03-23 14:01:08 +0100 | [diff] [blame] | 53 | |
Holger Hans Peter Freyther | d883db0 | 2014-03-23 16:22:55 +0100 | [diff] [blame] | 54 | static int get_subscriber_list(struct ctrl_cmd *cmd, void *d) |
| 55 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 56 | struct vlr_subscr *vsub; |
| 57 | |
| 58 | if (!msc_ctrl_net) { |
| 59 | cmd->reply = "MSC CTRL commands not initialized"; |
| 60 | return CTRL_CMD_ERROR; |
| 61 | } |
| 62 | |
| 63 | if (!msc_ctrl_net->vlr) { |
| 64 | cmd->reply = "VLR not initialized"; |
| 65 | return CTRL_CMD_ERROR; |
| 66 | } |
| 67 | |
Holger Hans Peter Freyther | d883db0 | 2014-03-23 16:22:55 +0100 | [diff] [blame] | 68 | cmd->reply = talloc_strdup(cmd, ""); |
| 69 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 70 | llist_for_each_entry(vsub, &msc_ctrl_net->vlr->subscribers, list) { |
| 71 | cmd->reply = talloc_asprintf_append(cmd->reply, "%s,%s\n", |
| 72 | vsub->imsi, vsub->msisdn); |
| 73 | } |
| 74 | printf("%s\n", cmd->reply); /* <-- what? */ |
Holger Hans Peter Freyther | d883db0 | 2014-03-23 16:22:55 +0100 | [diff] [blame] | 75 | return CTRL_CMD_REPLY; |
| 76 | } |
Max | 50eb669 | 2017-05-02 16:44:43 +0200 | [diff] [blame] | 77 | CTRL_CMD_DEFINE_RO(subscriber_list, "subscriber-list-active-v1"); |
Holger Hans Peter Freyther | d883db0 | 2014-03-23 16:22:55 +0100 | [diff] [blame] | 78 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 79 | int msc_ctrl_cmds_install(struct gsm_network *net) |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 80 | { |
| 81 | int rc = 0; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 82 | msc_ctrl_net = net; |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 83 | |
| 84 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_subscriber_modify); |
Holger Hans Peter Freyther | 2d99eeb | 2014-03-23 14:01:08 +0100 | [diff] [blame] | 85 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_subscriber_delete); |
Holger Hans Peter Freyther | d883db0 | 2014-03-23 16:22:55 +0100 | [diff] [blame] | 86 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_subscriber_list); |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 87 | return rc; |
| 88 | } |