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> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 24 | #include <osmocom/msc/gsm_data.h> |
| 25 | #include <osmocom/msc/gsm_subscriber.h> |
| 26 | #include <osmocom/msc/db.h> |
| 27 | #include <osmocom/msc/debug.h> |
| 28 | #include <osmocom/msc/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 | |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 32 | #define VSUB_USE_CTRL "CTRL" |
| 33 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 34 | static struct gsm_network *msc_ctrl_net = NULL; |
Holger Hans Peter Freyther | 9bcb1a5 | 2016-04-06 22:41:12 +0200 | [diff] [blame] | 35 | |
Holger Hans Peter Freyther | d883db0 | 2014-03-23 16:22:55 +0100 | [diff] [blame] | 36 | static int get_subscriber_list(struct ctrl_cmd *cmd, void *d) |
| 37 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 38 | struct vlr_subscr *vsub; |
| 39 | |
| 40 | if (!msc_ctrl_net) { |
| 41 | cmd->reply = "MSC CTRL commands not initialized"; |
| 42 | return CTRL_CMD_ERROR; |
| 43 | } |
| 44 | |
| 45 | if (!msc_ctrl_net->vlr) { |
| 46 | cmd->reply = "VLR not initialized"; |
| 47 | return CTRL_CMD_ERROR; |
| 48 | } |
| 49 | |
Holger Hans Peter Freyther | d883db0 | 2014-03-23 16:22:55 +0100 | [diff] [blame] | 50 | cmd->reply = talloc_strdup(cmd, ""); |
| 51 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 52 | llist_for_each_entry(vsub, &msc_ctrl_net->vlr->subscribers, list) { |
Neels Hofmeyr | b305a00 | 2017-09-09 17:00:21 +0200 | [diff] [blame] | 53 | /* Do not list subscribers that aren't successfully attached. */ |
| 54 | if (!vsub->lu_complete) |
| 55 | continue; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 56 | cmd->reply = talloc_asprintf_append(cmd->reply, "%s,%s\n", |
| 57 | vsub->imsi, vsub->msisdn); |
| 58 | } |
Holger Hans Peter Freyther | d883db0 | 2014-03-23 16:22:55 +0100 | [diff] [blame] | 59 | return CTRL_CMD_REPLY; |
| 60 | } |
Max | 50eb669 | 2017-05-02 16:44:43 +0200 | [diff] [blame] | 61 | CTRL_CMD_DEFINE_RO(subscriber_list, "subscriber-list-active-v1"); |
Holger Hans Peter Freyther | d883db0 | 2014-03-23 16:22:55 +0100 | [diff] [blame] | 62 | |
Max | dcc193d | 2017-12-27 19:34:15 +0100 | [diff] [blame] | 63 | CTRL_CMD_DEFINE_WO_NOVRF(sub_expire, "subscriber-expire"); |
| 64 | static int set_sub_expire(struct ctrl_cmd *cmd, void *data) |
| 65 | { |
| 66 | struct vlr_subscr *vsub; |
| 67 | |
| 68 | if (!msc_ctrl_net) { |
| 69 | cmd->reply = "MSC CTRL commands not initialized"; |
| 70 | return CTRL_CMD_ERROR; |
| 71 | } |
| 72 | |
| 73 | if (!msc_ctrl_net->vlr) { |
| 74 | cmd->reply = "VLR not initialized"; |
| 75 | return CTRL_CMD_ERROR; |
| 76 | } |
| 77 | |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 78 | vsub = vlr_subscr_find_by_imsi(msc_ctrl_net->vlr, cmd->value, VSUB_USE_CTRL); |
Max | dcc193d | 2017-12-27 19:34:15 +0100 | [diff] [blame] | 79 | if (!vsub) { |
| 80 | LOGP(DCTRL, LOGL_ERROR, "Attempt to expire unknown subscriber IMSI=%s\n", cmd->value); |
| 81 | cmd->reply = "IMSI unknown"; |
| 82 | return CTRL_CMD_ERROR; |
| 83 | } |
| 84 | |
| 85 | LOGP(DCTRL, LOGL_NOTICE, "Expiring subscriber IMSI=%s\n", cmd->value); |
| 86 | |
| 87 | if (vlr_subscr_expire(vsub)) |
| 88 | LOGP(DCTRL, LOGL_NOTICE, "VLR released subscriber %s\n", vlr_subscr_name(vsub)); |
| 89 | |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 90 | if (osmo_use_count_total(&vsub->use_count) > 1) |
Max | dcc193d | 2017-12-27 19:34:15 +0100 | [diff] [blame] | 91 | LOGP(DCTRL, LOGL_NOTICE, "Subscriber %s is still in use, should be released soon\n", |
| 92 | vlr_subscr_name(vsub)); |
| 93 | |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 94 | vlr_subscr_put(vsub, VSUB_USE_CTRL); |
Max | dcc193d | 2017-12-27 19:34:15 +0100 | [diff] [blame] | 95 | |
| 96 | return CTRL_CMD_REPLY; |
| 97 | } |
| 98 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 99 | int msc_ctrl_cmds_install(struct gsm_network *net) |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 100 | { |
| 101 | int rc = 0; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 102 | msc_ctrl_net = net; |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 103 | |
Holger Hans Peter Freyther | d883db0 | 2014-03-23 16:22:55 +0100 | [diff] [blame] | 104 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_subscriber_list); |
Max | dcc193d | 2017-12-27 19:34:15 +0100 | [diff] [blame] | 105 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_sub_expire); |
| 106 | |
Holger Hans Peter Freyther | 9dbc3f8 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 107 | return rc; |
| 108 | } |