Skip to content

Commit 37e48e7

Browse files
committed
res_smdr_whozz: Fix toggling settings not actually being set.
The SET_SETTING macro printed out that it was setting a setting, but wasn't actually writing anything to the serial port. This could result in the device not having the right settings and not working right. In particular, after being unplugged for a while and most likely losing its programming, the 'o' option would not be set and we would get no CDR for outgoing calls. PHREAKSCRIPT-64 #close
1 parent 6643669 commit 37e48e7

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

res/res_smdr_whozz.c

+51-7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
<description>
6464
<para>Line number of SMDR channel as configured on the WHOZZ Calling? device.</para>
6565
<para>Three-way calling is not supported. Please note that WHOZZ Calling? devices do not themselves support pulse dialing.</para>
66+
<para>Note that if you wish to log unanswered incoming calls (outgoing calls are always assumed to be answered by the WHOZZ Calling
67+
unit), you need to set <literal>unanswered = yes</literal> in <literal>cdr.conf</literal>.</para>
6668
</description>
6769
</configOption>
6870
<configOption name="device">
@@ -133,6 +135,7 @@ struct whozz_line {
133135
int lineno; /*!< Line number on WHOZZ Calling? system */
134136
struct ast_channel *chan; /*!< Dummy channel for CDR */
135137
const char *device; /*!< Asterisk device */
138+
unsigned int detect_dialing:1; /*!< Whether to detect dialing in Asterisk, instead of relying on the WHOZZ Calling hardware */
136139
enum line_state state; /*!< Current line state */
137140
enum ast_device_state startstate; /*!< Starting device state of associated FXO device, if applicable */
138141
enum ast_device_state answerstate; /*!< Device state of associated FXO device, if applicable, at time of off-hook on incoming call */
@@ -283,25 +286,33 @@ static int serial_sync(struct pollfd *pfd)
283286
return 0;
284287
}
285288

286-
static int set_settings(struct pollfd *pfd)
289+
static int set_settings(struct pollfd *pfd, int reset)
287290
{
288291
struct timeval when;
289292
struct ast_tm tm;
290293
ssize_t bufres;
291294
char buf[64];
292-
293-
SERIAL_WRITE("V", 1);
294-
SERIAL_READ_STRING(buf, sizeof(buf), 1);
295+
char ch;
295296

296297
/* Must wait at least 50 ms between setting each setting to non-volatile memory */
297298
#define SET_SETTING_DELAY 50000
298299

299300
#define SET_SETTING(c) \
300301
if (!strchr(buf, c)) { \
301302
ast_verb(5, "Setting WHOZZ Calling? register '%c'\n", c); \
303+
ch = c; \
304+
SERIAL_WRITE(&ch, 1); \
302305
usleep(SET_SETTING_DELAY); \
303306
}
304307

308+
if (reset) {
309+
buf[0] = '\0';
310+
SET_SETTING('R');
311+
}
312+
313+
SERIAL_WRITE("V", 1);
314+
SERIAL_READ_STRING(buf, sizeof(buf), 1);
315+
305316
SET_SETTING('E'); /* Echo off */
306317
SET_SETTING('c'); /* Remove dashes from phone number, leading $ */
307318
SET_SETTING('X'); /* Duration and checksum */
@@ -490,10 +501,12 @@ static int handle_hook(struct whozz_line *w, int outbound, int end, int duration
490501
/* Substitute if needed */
491502
pbx_substitute_variables_helper(w->chan, varval, subbuf, sizeof(subbuf) - 1);
492503
/* Replace or add variable */
504+
ast_debug(8, "Setting variable %s=%s\n", varkey, subbuf);
493505
pbx_builtin_setvar_helper(w->chan, varkey, subbuf);
494506
}
495507

496508
ast_channel_hangupcause_set(w->chan, AST_CAUSE_NORMAL);
509+
ast_debug(5, "Finalized CDR for channel %s\n", ast_channel_name(w->chan));
497510
ast_hangup(w->chan); /* Kill the channel and force the CDR to be processed, with variable substitution */
498511
w->chan = NULL;
499512
} else {
@@ -892,7 +905,7 @@ static int serial_monitor(void *varg)
892905
}
893906
}
894907

895-
if (set_settings(&pfd)) {
908+
if (set_settings(&pfd, 0)) {
896909
ast_log(LOG_ERROR, "Failed to initialize device with SMDR settings\n");
897910
return -1;
898911
}
@@ -946,7 +959,7 @@ static struct ast_custom_function acf_whozz = {
946959
.read = whozz_line_state_read,
947960
};
948961

949-
static char *handle_show_whozz(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
962+
static char *handle_show_lines(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
950963
{
951964
struct whozz_line *w;
952965

@@ -975,8 +988,39 @@ static char *handle_show_whozz(struct ast_cli_entry *e, int cmd, struct ast_cli_
975988
return CLI_SUCCESS;
976989
}
977990

991+
static char *handle_reset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
992+
{
993+
struct pollfd pfd;
994+
995+
switch (cmd) {
996+
case CLI_INIT:
997+
e->command = "whozz reset";
998+
e->usage =
999+
"Usage: whozz reset\n"
1000+
" Reset and reinitialize the connected unit.\n";
1001+
return NULL;
1002+
case CLI_GENERATE:
1003+
return NULL;
1004+
}
1005+
if (a->argc != 2) {
1006+
return CLI_SHOWUSAGE;
1007+
}
1008+
1009+
memset(&pfd, 0, sizeof(pfd));
1010+
pfd.fd = serial_fd;
1011+
pfd.events = POLLIN | POLLERR | POLLNVAL | POLLHUP;
1012+
1013+
if (set_settings(&pfd, 1)) {
1014+
ast_cli(a->fd, "Failed to reinitialize device with SMDR settings\n");
1015+
return CLI_FAILURE;
1016+
}
1017+
1018+
return CLI_SUCCESS;
1019+
}
1020+
9781021
static struct ast_cli_entry whozz_cli[] = {
979-
AST_CLI_DEFINE(handle_show_whozz, "List WHOZZ Calling lines"),
1022+
AST_CLI_DEFINE(handle_show_lines, "List WHOZZ Calling lines"),
1023+
AST_CLI_DEFINE(handle_reset, "Reset and reinitialize the connected unit"),
9801024
};
9811025

9821026
static int load_config(void)

0 commit comments

Comments
 (0)