+static char *dahdi_set_mwi(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ int channel;
+ int on;
+ int override = 1;
+ struct dahdi_pvt *dahdi_chan = NULL;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dahdi set mwi";
+ e->usage =
+ "Usage: dahdi set mwi <chan#> <on|off|reset>\n"
+ " Sets/unsets MWI (Message Waiting Indicator) manually on a channel.\n"
+ " This may be used regardless of whether the channel is assigned any mailboxes.\n"
+ " When active, this setting will override the voicemail status to set MWI.\n"
+ " Once cleared, the voicemail status will resume control of MWI.\n"
+ " Changes are queued for when the channel is idle and persist until cleared.\n"
+ " <chan num> is the channel number\n"
+ " <on|off|reset> Enable, disable, or reset Message Waiting Indicator override?\n"
+ ;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 5)
+ return CLI_SHOWUSAGE;
+
+ if ((channel = atoi(a->argv[3])) <= 0) {
+ ast_cli(a->fd, "Expected channel number, got '%s'\n", a->argv[3]);
+ return CLI_SHOWUSAGE;
+ }
+
+ if (ast_true(a->argv[4])) {
+ on = 1;
+ } else if (ast_false(a->argv[4])) {
+ on = 0;
+ } else if (!strcmp(a->argv[4], "reset")) {
+ override = 0;
+ } else {
+ ast_cli(a->fd, "Expected 'on' or 'off' or 'reset', got '%s'\n", a->argv[4]);
+ return CLI_SHOWUSAGE;
+ }
+
+ ast_mutex_lock(&iflock);
+ for (dahdi_chan = iflist; dahdi_chan; dahdi_chan = dahdi_chan->next) {
+ if (dahdi_chan->channel != channel)
+ continue;
+
+ /* Found the channel. Actually set it */
+ if (override) {
+ dahdi_chan->mwioverride_disposition = on;
+ ast_cli(a->fd, "MWI '%s' queued for channel %d\n", on ? "enable" : "disable", channel);
+ }
+ dahdi_chan->mwioverride_active = override;
+ /* The do_monitor thread will take care of actually sending the MWI
+ * at an appropriate time for the channel. */
+ break;
+ }
+ ast_mutex_unlock(&iflock);
+
+ if (!dahdi_chan) {
+ ast_cli(a->fd, "Unable to find given channel %d\n", channel);
+ return CLI_FAILURE;
+ }
+
+ return CLI_SUCCESS;
+}
+