diff --git a/Makefile b/Makefile
index fdeb6cf68aebaf24c1341bd71521d2b5a7a0ca9f..380a242cbff5adc7d2f1e40c8176f4e228381ef4 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,6 @@
#
HEADERS := $(shell ls ./*.h)
SRCS := $(shell ls ./*.c)
-LIBVOICE := ./libvoice/libvoice.so
VOICEMNGR := voicemngr
CFLAGS += -O2 -fcaller-saves -fsection-anchors
@@ -28,10 +27,10 @@ all: debug $(VOICEMNGR)
%.o: %.c $(HEADERS) Makefile
$(CC) $(CFLAGS) -c -o $@ $<
-$(LIBVOICE):
+LIBVOICE:
$(MAKE) -C libvoice
-$(VOICEMNGR): $(LIBVOICE) $(OBJS)
+$(VOICEMNGR): LIBVOICE $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
diff --git a/libvoice/common.c b/libvoice/common.c
index cee4598c612547b538d134e68b4b9c3febdb0cc4..a7d1311c149ffa0e3a9bed346c6c53cf9c3f42aa 100644
--- a/libvoice/common.c
+++ b/libvoice/common.c
@@ -81,12 +81,12 @@ void (*voice_cb_event_report)(int line, const char *event, int data) = NULL;
// Callback function which is invoked when an encoded media packet is generated by the voice engine
void (*voice_cb_egress_media)(const struct media_packet_t *packet, int size) = NULL;
-void voice_syslog(const char *fmt, ...)
+void voice_syslog(int level, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- vsyslog(LOG_DEBUG, fmt, ap);
+ vsyslog(level, fmt, ap);
va_end(ap);
}
@@ -115,7 +115,7 @@ int voice_line_preinit(void) {
// Initialize all contents as 0 by calloc
lines = calloc(terminal_info.num_voice_ports, sizeof(struct line_t));
if(!lines) {
- ENDPT_DBG("%s: out out memory\n", __func__);
+ ENDPT_ERR("%s: out out memory\n", __func__);
return -1;
}
for(i = 0; i < terminal_info.num_voice_ports; i++) {
diff --git a/libvoice/libvoice.h b/libvoice/libvoice.h
index 710014569ac88c0c3777fda0b5241f03bf104734..2920b014d72d281b1f02d4c48b3a15e40ad510e3 100644
--- a/libvoice/libvoice.h
+++ b/libvoice/libvoice.h
@@ -8,6 +8,7 @@
#include <stdint.h>
#include <sys/time.h>
#include <time.h>
+#include <syslog.h>
#include <libpicoevent.h>
#include "voice-types.h"
@@ -227,10 +228,15 @@ struct codec_capability {
printf(fmt, ##__VA_ARGS__); \
} while (0)
#else
-#define ENDPT_DBG(...) voice_syslog("voice: " __VA_ARGS__)
+#define ENDPT_DBG(format, ...) voice_syslog(LOG_DEBUG, "%s:%d %s: " format, \
+ __FILE__, __LINE__, __func__, ##__VA_ARGS__)
#endif
#define CHECK_POINT() ENDPT_DBG("Check point at %s@%s:%d\n", __func__, __FILE__, __LINE__)
+#define ENDPT_INFO(...) voice_syslog(LOG_INFO, __VA_ARGS__)
+#define ENDPT_WARN(...) voice_syslog(LOG_WARNING, __VA_ARGS__)
+#define ENDPT_ERR(...) voice_syslog(LOG_ERR, __VA_ARGS__)
+
extern struct terminal_info_t terminal_info;
extern struct line_t *lines;
extern struct connection_t *connections;
@@ -264,7 +270,7 @@ int voice_line_signal(int line, int connection, enum VOICE_SIGNAL signal, int st
int voice_line_simulate_hook(int line, enum VOICE_EVENT event);
// Misc
-void voice_syslog(const char *fmt, ...);
+void voice_syslog(int level, const char *fmt, ...);
int voice_engine_shutdown(void);
int voice_get_min_tx_gain(void);
int voice_get_max_tx_gain(void);
diff --git a/line-dect.c b/line-dect.c
index a9c97d47e786806eccad8e6fa6097c091a7e2789..efec60b56418fcb385ab3542b1a0c79f911f8c29 100644
--- a/line-dect.c
+++ b/line-dect.c
@@ -52,8 +52,8 @@ int ubus_process_queued_reqs_to_dectmngr(void) {
if (!req)
return 0;
- ENDPT_DBG("%s: Poped DECT req %p from list, action: %d pcmId: %d, caller_id: %s, callerName: %s\n", __func__, req, req->action,
- req->pcm_id, req->caller_id, req->caller_name);
+ ENDPT_DBG("Poped DECT req %p from list, action: %d pcmId: %d, caller_id: %s, callerName: %s\n",
+ req, req->action, req->pcm_id, req->caller_id, req->caller_name);
pcm_states_dump(__func__, req->line);
switch (req->action) {
@@ -102,7 +102,7 @@ int simulate_digits_pressing(int line, const char *pressed_digits) {
if(lines[line].type != VOICE_LINE_DECT)
return 0;
- ENDPT_DBG("%s(): line: %d pressed_digits: %s\n", __func__, line, (pressed_digits ? pressed_digits : ""));
+ ENDPT_DBG("line: %d pressed_digits: %s\n", line, (pressed_digits ? pressed_digits : ""));
// Store digits in a list.
if(pressed_digits && lines[line].pending_digits) {
@@ -138,7 +138,7 @@ int ubus_cb_dectmngr_replied(struct line_req_t *req, enum ubus_msg_status reply_
if(!req)
return -1;
- ENDPT_DBG("%s got answer req %p from dectmngr, action: %d, line: %d, pcmId: %d, conId: %d\n", __func__,
+ ENDPT_DBG("got answer req %p from dectmngr, action: %d, line: %d, pcmId: %d, conId: %d\n",
req, req->action, req->line, req->pcm_id, req->connection_id);
pcm_states_dump(__func__, req->line);
@@ -190,10 +190,12 @@ int ubus_cb_asterisk_replied(struct line_event_t *lineEv, enum ubus_msg_status r
struct line_req_t *req;
int epEvntIdx, dectEvntIdx;
- if(!lineEv || !voice_line_is_ready(lineEv->line))
+ if(!lineEv || !voice_line_is_ready(lineEv->line)) {
+ ENDPT_ERR("Invalid argument\n");
return -1;
+ }
- ENDPT_DBG("%s started\n", __func__);
+ ENDPT_DBG("started\n");
if(lines[lineEv->line].simulated_hook) {
voice_hook_simulation_maintain(lineEv->line);
@@ -218,7 +220,7 @@ int ubus_cb_asterisk_replied(struct line_event_t *lineEv, enum ubus_msg_status r
return 0; // None found, then do nothing
assert(req->ubus.ctx);
- ENDPT_DBG("%s: poped Asterisk req %p line %d event %s from list, action %d\n", __func__,
+ ENDPT_DBG("poped Asterisk req %p line %d event %s from list, action %d\n",
req, lineEv->line, lineEv->name, req->action);
if(reply_status == UBUS_STATUS_OK) {
diff --git a/line.c b/line.c
index 9de1438f0325776b28b8c0f0b90c17fbffa1d634..5ee913e7f2048b0411e73e8d11b88cf1dd37b6d8 100644
--- a/line.c
+++ b/line.c
@@ -87,7 +87,7 @@ static int perhaps_simulate_busy(int line, struct voice_ubus_req_t *ubus_req)
msg->line = line;
send_event_main(msg, EVENT_MAIN_LINE);
} else {
- ENDPT_DBG("%s: out of memory\n", __func__);
+ ENDPT_ERR("%s: out of memory\n", __func__);
}
return 1;
@@ -97,13 +97,13 @@ static int perhaps_simulate_busy(int line, struct voice_ubus_req_t *ubus_req)
static int dect_tone_play(int line, int pcm, enum VOICE_SIGNAL signal, const char *data, struct voice_ubus_req_t *ubus_req)
{
struct line_req_t *line_req = NULL;
- ENDPT_DBG("%s: line=%d, pcm=%d, data=%s\n", __func__, line, pcm, data);
+ ENDPT_DBG("line=%d, pcm=%d, data=%s\n", line, pcm, data);
pcm_states_dump(__func__, line);
assert(ubus_req);
line_req = calloc(1, sizeof(struct line_req_t));
if(!line_req) {
- ENDPT_DBG("%s: out of memory\n", __func__);
+ ENDPT_ERR("%s: out of memory\n", __func__);
return -1;
}
line_req->line = line;
@@ -120,7 +120,7 @@ static int dect_tone_play(int line, int pcm, enum VOICE_SIGNAL signal, const cha
return -1;
}
- ENDPT_DBG("%s: line %d set pcm to %d\n", __func__, line, line_req->pcm_id);
+ ENDPT_DBG("line %d set pcm to %d\n", line, line_req->pcm_id);
memcpy(&line_req->ubus, ubus_req, sizeof(struct voice_ubus_req_t));
assert(lines[line].type == VOICE_LINE_DECT);
@@ -158,7 +158,7 @@ static int line_signal_ring(int line, int pcm, enum VOICE_SIGNAL signal, const c
struct line_req_t *line_req = NULL;
int start_ring = data && strcmp(data, "0") != 0;
- ENDPT_DBG("%s: line=%d, pcm=%d, data=%s\n", __func__, line, pcm, data);
+ ENDPT_DBG("line=%d, pcm=%d, data=%s\n", line, pcm, data);
pcm_states_dump(__func__, line);
// Relay the request to dectmngr if the line is DECT
@@ -166,13 +166,13 @@ static int line_signal_ring(int line, int pcm, enum VOICE_SIGNAL signal, const c
assert(ubus_req);
line_req = calloc(1, sizeof(struct line_req_t));
if(!line_req) {
- ENDPT_DBG("%s: out of memory\n", __func__);
+ ENDPT_ERR("%s: out of memory\n", __func__);
return -1;
}
line_req->line = line;
line_req->connection_id = -1;
line_req->pcm_id = pcm;
- ENDPT_DBG("%s: line %d set pcm to %d\n", __func__, line, line_req->pcm_id);
+ ENDPT_DBG("line %d set pcm to %d\n", line, line_req->pcm_id);
memcpy(&line_req->ubus, ubus_req, sizeof(struct voice_ubus_req_t));
// Parse the called ID string generated by Asterisk
@@ -240,7 +240,7 @@ static int line_signal_answer(int line, int pcm, const char *data, struct voice_
{
struct line_req_t *line_req = NULL;
- ENDPT_DBG("%s() line %d pcm: %d data: %s\n", __func__, line, pcm, data);
+ ENDPT_DBG("line %d pcm: %d data: %s\n", line, pcm, data);
pcm_states_dump(__func__, line);
assert(ubus_req);
@@ -269,12 +269,12 @@ int line_signal(int line, const char *signame, const char *data, struct voice_ub
const struct voice_signal_t *sig;
int res = 0;
- ENDPT_DBG("%s: line=%d(type:%d), signame=%s, data=%s\n", __func__, line, lines[line].type, signame, data);
+ ENDPT_DBG("line=%d(type:%d), signame=%s, data=%s\n", line, lines[line].type, signame, data);
for(sig = signal_map; sig->signal != VOICE_SIG_LAST && strcmp(signame, sig->name) != 0; sig++)
continue;
if(sig->signal == VOICE_SIG_LAST) {
- ENDPT_DBG("%s: signal %s is not supported\n", __func__, signame);
+ ENDPT_ERR("%s: signal %s is not supported\n", __func__, signame);
return -1;
}
@@ -362,9 +362,9 @@ int line_signal(int line, const char *signame, const char *data, struct voice_ub
}
if (res == 0) {
- ENDPT_DBG("%s: signal %s(%s) was set for line %d\n", __func__, sig->name, data, line);
+ ENDPT_INFO("signal %s(%s) was set for line %d\n", sig->name, data, line);
} else {
- ENDPT_DBG("%s: error setting signal %s(%s)\n", __func__, sig->name, data);
+ ENDPT_ERR("%s: error setting signal %s(%s)\n", __func__, sig->name, data);
}
return res;
@@ -398,7 +398,7 @@ int line_new_connection_by_asterisk(int line, int connection, struct voice_ubus_
* chance to relay it to dectmngr. */
line_req = calloc(1, sizeof(struct line_req_t));
if(!line_req) {
- ENDPT_DBG("%s: out of memory\n", __func__);
+ ENDPT_ERR("%s: out of memory\n", __func__);
return -1;
}
line_req->line = line;
@@ -425,7 +425,7 @@ int line_connection_parm_update_by_asterisk(int line, int connection, struct con
if (!voice_line_is_ready(line))
return -1;
- ENDPT_DBG("parm_update request for %s line: %d, connection: %d, mask: %d, codec: %d, ptime: %d \n", __func__, line, connection, data->mask, data->codec, data->ptime);
+ ENDPT_DBG("parm_update request for line: %d, connection: %d, mask: %d, codec: %d, ptime: %d \n", line, connection, data->mask, data->codec, data->ptime);
pcm_states_dump(__func__, line);
res = voice_connection_parm_update(line, line, data);
@@ -554,8 +554,7 @@ int line_update_connection_by_pbx(int line, int pcm_callid)
if (!voice_line_is_ready(line))
return -1;
- ENDPT_DBG("%s Received update connection for line: %d with pcm_callid: %d\n",
- __func__, line, pcm_callid);
+ ENDPT_DBG("Received update connection for line: %d with pcm_callid: %d\n", line, pcm_callid);
pcm_states_dump(__func__, line);
if(lines[line].type != VOICE_LINE_DECT)
@@ -580,7 +579,7 @@ int line_new_connection_by_dect(int line, const char *cid, int pcm, struct voice
if (!voice_line_is_ready(line) || lines[line].type != VOICE_LINE_DECT)
return -1;
- ENDPT_DBG("%s: line=%d, pcm=%d, cid=%s\n", __func__, line, pcm, cid);
+ ENDPT_DBG("line=%d, pcm=%d, cid=%s\n", line, pcm, cid);
pcm_states_dump(__func__, line);
if (pcm <= PCM_1) {
@@ -640,17 +639,17 @@ int line_close_connection_by_dect(int line, int pcm, struct voice_ubus_req_t *ub
return -1;
if(lines[line].type != VOICE_LINE_DECT) {
- ENDPT_DBG("%s: lines[%d].type != VOICE_LINE_DECT\n", __func__, line);
+ ENDPT_ERR("%s: lines[%d].type != VOICE_LINE_DECT\n", __func__, line);
return -1;
}
- ENDPT_DBG("%s() for line %d, pcm: %d\n", __func__, line, pcm);
+ ENDPT_DBG("line %d: pcm = %d\n", line, pcm);
pcm_states_dump(__func__, line);
if (pcm == CALL_DECT_UNAVAILABLE) {
struct line_event_t *msg;
- ENDPT_DBG("%s: There is no available DECT handsets for the call. "
- "Send DECT_UNAVAILABLE event to Asterisk\n", __func__);
+ ENDPT_DBG("There is no available DECT handsets for the call. "
+ "Send DECT_UNAVAILABLE event to Asterisk\n");
msg = malloc(sizeof(struct line_event_t));
if (msg) {
@@ -668,8 +667,8 @@ int line_close_connection_by_dect(int line, int pcm, struct voice_ubus_req_t *ub
if (get_callid_state(lines[line].pcm_callid[(pcm >> 16)]) == CALLID_OBTAINING) {
struct line_event_t *msg;
- ENDPT_DBG("%s: DECT handsets may have not answered the call yet. "
- "Send CALL_REJECT event to Asterisk\n", __func__);
+ ENDPT_DBG("DECT handsets may have not answered the call yet. "
+ "Send CALL_REJECT event to Asterisk\n");
msg = malloc(sizeof(struct line_event_t));
if (msg) {
diff --git a/main.c b/main.c
index f38988ea2ddeb495b0d3ad4bd756f231b6cc2ef7..e94468f1cdd86a34cd21984d35c75cbd84b0fc3c 100644
--- a/main.c
+++ b/main.c
@@ -23,6 +23,8 @@
#define UCI_CONFIG_DIR "/etc/config/"
#endif
+
+static int log_level = LOG_INFO;
static int audio_rx_fd;
static int audio_tx_fd;
static int event_fd;
@@ -48,7 +50,7 @@ void send_media_to_voice_engine(pe_packet_t *p) {
conIdx = voice_connection_find(packet->line, packet->connection_id);
if (conIdx == -1 || (packet->rtp[0] != 0x80 && packet->rtp[0] != 0x81) || !packet->rtp_size) {
- ENDPT_DBG("%s: bad packet\n", __func__);
+ ENDPT_ERR("%s: bad packet\n", __func__);
return;
}
@@ -107,7 +109,7 @@ static void event_stream_handler(pe_stream_t *stream __attribute__((unused)), pe
break;
default:
- ENDPT_DBG("Warning: unknown event '%c'\n", *event->in);
+ ENDPT_WARN("unknown event '%c'\n", *event->in);
break;
}
}
@@ -198,7 +200,7 @@ static void voicemngr_event_report(int line, const char *event, int data) {
struct line_event_t *msg = malloc(sizeof(struct line_event_t));
if (!msg) {
- ENDPT_DBG("%s: out of memory\n", __func__);
+ ENDPT_ERR("%s: out of memory\n", __func__);
return;
}
msg->name = event;
@@ -215,7 +217,7 @@ static int voicemngr_get_voice_port_cfg(const char *hw_board_voice_names, struct
char *str, *token, *saveptr;
if (!hw_board_voice_names || *hw_board_voice_names == '\0') {
- ENDPT_DBG("%s: environmental variable hw_board_VoicePortNames is not defined or empty\n", __func__);
+ ENDPT_ERR("%s: environmental variable hw_board_VoicePortNames is not defined or empty\n", __func__);
return -1;
}
@@ -225,28 +227,28 @@ static int voicemngr_get_voice_port_cfg(const char *hw_board_voice_names, struct
* might cause the wrong value being returned when running the program multiple times */
duplication = strdup(hw_board_voice_names);
if (!duplication) {
- ENDPT_DBG("%s: out of memory\n", __func__);
+ ENDPT_ERR("%s: out of memory\n", __func__);
return -1;
}
- ENDPT_DBG("%s: hw_board_voice_names=[%s]\n", __func__, hw_board_voice_names);
+ ENDPT_DBG("hw_board_voice_names=[%s]\n", hw_board_voice_names);
for (str = duplication; (token = strtok_r(str, " ,;:\t", &saveptr)) != NULL; str = NULL) {
if ((size_t)voice_port_cfg->num_voice_ports >=
sizeof(voice_port_cfg->voice_ports) / sizeof(voice_port_cfg->voice_ports)[0]) {
- ENDPT_DBG("%s: too many voice ports\n", __func__);
+ ENDPT_ERR("%s: too many voice ports\n", __func__);
res = -1;
break;
}
if (strcasestr(token, "Tel") != NULL || strcasestr(token, "FXS") != NULL) {
- ENDPT_DBG("%s: port %d is FXS\n", __func__, voice_port_cfg->num_voice_ports);
+ ENDPT_INFO("%s: port %d is FXS\n", __func__, voice_port_cfg->num_voice_ports);
voice_port_cfg->voice_ports[voice_port_cfg->num_voice_ports++] = VOICE_LINE_FXS;
voice_port_cfg->num_fxs++;
} else if (strcasestr(token, "DECT") != NULL) {
- ENDPT_DBG("%s: port %d is DECT\n", __func__, voice_port_cfg->num_voice_ports);
+ ENDPT_INFO("%s: port %d is DECT\n", __func__, voice_port_cfg->num_voice_ports);
voice_port_cfg->voice_ports[voice_port_cfg->num_voice_ports++] = VOICE_LINE_DECT;
voice_port_cfg->num_dect++;
} else {
- ENDPT_DBG("%s: invalid port type, %s\n", __func__, token);
+ ENDPT_ERR("%s: invalid port type, %s\n", __func__, token);
res = -1;
break;
}
@@ -256,7 +258,8 @@ static int voicemngr_get_voice_port_cfg(const char *hw_board_voice_names, struct
return res;
}
-int main(void) {
+int main(int argc, char **argv) {
+ (void) argc;
struct uci_context *context = NULL;
struct uci_package *package = NULL;
struct terminal_info_t voice_port_cfg;
@@ -265,17 +268,20 @@ int main(void) {
const char *hw_board_has_dect;
const char *hw_board_voice_names;
+ openlog(argv[0], LOG_PID, LOG_DAEMON);
+ setlogmask(LOG_UPTO(log_level));
+
// Load the UCI package
context = uci_alloc_context();
if (!context) {
- ENDPT_DBG("uci_alloc_context() failed\n");
+ ENDPT_ERR("uci_alloc_context() failed\n");
return EXIT_FAILURE;
}
uci_set_confdir(context, UCI_CONFIG_DIR);
res = uci_load(context, uciStrConfig, &package);
if (res != 0 || !package) {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to load uci package %s, %s\n", uciStrConfig, error);
+ ENDPT_ERR("Failed to load uci package %s, %s\n", uciStrConfig, error);
free(error);
uci_free_context(context);
context = NULL;
@@ -288,7 +294,7 @@ int main(void) {
// Check that ASCII to DTMF convertion works.
if(!isdigit('0') || !isalpha('a')) {
- ENDPT_DBG("Source has invalid encoding.\n");
+ ENDPT_ERR("Source has invalid encoding.\n");
goto __error_ret;
}
@@ -327,12 +333,12 @@ int main(void) {
// Enable UBUS when all initializations have finished
if(ubus_enable_receive()) goto __error_ret;
- ENDPT_DBG("voicemngr has started successfully\n");
+ ENDPT_INFO("voicemngr has started successfully\n");
// Listen for events and dispatch them to handlers. Run forever and does not return.
pe_base_dispatch(picoBase);
- ENDPT_DBG("pe_base_dispatch() exited unexpectedly\n");
+ ENDPT_WARN("pe_base_dispatch() exited unexpectedly\n");
__error_ret:
if (package)
diff --git a/ubus.c b/ubus.c
index 95ff9fce05736255b8fc0ad7d15fc0c7410870f6..b10ff710c52d346fbbcb67d1f78a25d74fed7b1d 100644
--- a/ubus.c
+++ b/ubus.c
@@ -135,6 +135,7 @@ static const char broadcast_path[] = "voice.endpoint"; // UBUS path name for b
static const char uciStrComSect[] = "tel_options"; // Common endpoint section name
static const char uciStrLineSect[] = "extension"; // Line specific section name
static const char uciStrCountry[] = "country"; // Endpoint country
+static const char uciStrLoglevel[] = "vmloglevel"; // syslog level of voicemngr
static const char ubusStrObjAdd[] = "ubus.object.add"; // UBUS objects added to global context
static const char ubusStrObjRm[] = "ubus.object.remove"; // UBUS objects added removed from global context
@@ -232,7 +233,7 @@ static void timerHandler(pe_stream_t *stream, pe_event_t *event __attribute__((u
expired = 0;
res = read(outReq->timerFd, &expired, sizeof(expired));
if(res == -1 && errno != EAGAIN) {
- perror("Error, reading timer fd");
+ ENDPT_ERR("reading timer fd: %s", strerror(errno));
}
if(!expired)
return;
@@ -336,7 +337,7 @@ static void uci_query_lineX(struct uci_context *context, struct uci_section *sec
char *error;
if(phoneLine < 0 || phoneLine >= terminal_info.num_voice_ports) {
- ENDPT_DBG("Error, invalid phone line %d\n", phoneLine);
+ ENDPT_ERR("Error, invalid phone line %d\n", phoneLine);
return;
}
@@ -344,7 +345,7 @@ static void uci_query_lineX(struct uci_context *context, struct uci_section *sec
strVal = uci_lookup_option_string(context, section, option);
if (!strVal || !*strVal) {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to look up line option %s, %s\n", option, error);
+ ENDPT_ERR("Failed to look up line option %s, %s\n", option, error);
free(error);
} else {
ENDPT_DBG(" %s=%s\n", option, strVal);
@@ -356,7 +357,7 @@ static void uci_query_lineX(struct uci_context *context, struct uci_section *sec
strVal = uci_lookup_option_string(context, section, option);
if (!strVal || !*strVal) {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to look up line option %s, %s\n", option, error);
+ ENDPT_ERR("Failed to look up line option %s, %s\n", option, error);
free(error);
} else {
intVal = strtol(strVal, NULL, 10);
@@ -365,7 +366,7 @@ static void uci_query_lineX(struct uci_context *context, struct uci_section *sec
lines[phoneLine].line_conf.silence = (intVal ? 1 : 0);
ENDPT_DBG(" %s=%d\n", option, intVal);
} else {
- ENDPT_DBG(" Error: %s range is 0-1\n", option);
+ ENDPT_ERR("Error comfort_noise value: '%s', not in range '0' - '1'\n", strVal);
}
}
@@ -373,7 +374,7 @@ static void uci_query_lineX(struct uci_context *context, struct uci_section *sec
strVal = uci_lookup_option_string(context, section, option);
if (!strVal || !*strVal) {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to look up line option %s, %s\n", option, error);
+ ENDPT_ERR("Failed to look up line option %s, %s\n", option, error);
free(error);
} else {
intVal = strtol(strVal, NULL, 10);
@@ -381,7 +382,7 @@ static void uci_query_lineX(struct uci_context *context, struct uci_section *sec
lines[phoneLine].line_conf.echo_cancel = (intVal ? 1 : 0);
ENDPT_DBG(" %s=%d\n", option, intVal);
} else {
- ENDPT_DBG(" Error: %s range is 0-1\n", option);
+ ENDPT_ERR("Error echo_cancel value: '%s', not in range '0' - '1'\n", strVal);
}
}
@@ -389,7 +390,7 @@ static void uci_query_lineX(struct uci_context *context, struct uci_section *sec
strVal = uci_lookup_option_string(context, section, option);
if (!strVal || !*strVal) {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to look up line option %s, %s\n", option, error);
+ ENDPT_ERR("Failed to look up line option %s, %s\n", option, error);
free(error);
} else {
intVal = strtol(strVal, NULL, 10);
@@ -397,7 +398,7 @@ static void uci_query_lineX(struct uci_context *context, struct uci_section *sec
lines[phoneLine].line_conf.txgain = intVal;
ENDPT_DBG(" %s=%d\n", option, intVal);
} else {
- ENDPT_DBG(" Error: %s range is %d - %d\n", option, voice_get_min_tx_gain(), voice_get_max_tx_gain());
+ ENDPT_ERR("Error txgain value: '%s', not in range %d - %d\n", strVal, voice_get_min_tx_gain(), voice_get_max_tx_gain());
}
}
@@ -405,7 +406,7 @@ static void uci_query_lineX(struct uci_context *context, struct uci_section *sec
strVal = uci_lookup_option_string(context, section, option);
if (!strVal || !*strVal) {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to look up line option %s, %s\n", option, error);
+ ENDPT_ERR("Failed to look up line option %s, %s\n", option, error);
free(error);
} else {
intVal = strtol(strVal, NULL, 10);
@@ -413,7 +414,7 @@ static void uci_query_lineX(struct uci_context *context, struct uci_section *sec
lines[phoneLine].line_conf.rxgain = intVal;
ENDPT_DBG(" %s=%d\n", option, intVal);
} else {
- ENDPT_DBG(" Error: %s range is %d - %d\n", option, voice_get_min_rx_gain(), voice_get_max_rx_gain());
+ ENDPT_ERR("Error value: %s='%s', not in range %d - %d\n", option, strVal, voice_get_min_rx_gain(), voice_get_max_rx_gain());
}
}
@@ -516,19 +517,19 @@ static int ubus_request_signal(struct ubus_context *uctx, struct ubus_object *ob
/* Check that we have all arguments */
if (!keys[SIGNAL_LINE] || !keys[SIGNAL_TYPE] || !keys[SIGNAL_STATE]) {
- ENDPT_DBG("Error! missing argument\n");
+ ENDPT_ERR("Error! missing argument\n");
return UBUS_STATUS_INVALID_ARGUMENT;
}
/* Check that endpt exist */
line = blobmsg_get_u32(keys[SIGNAL_LINE]);
if (line < 0 || line >= terminal_info.num_voice_ports) {
- ENDPT_DBG("Error! No such line value: %d\n", line);
+ ENDPT_ERR("Error! No such line value: %d\n", line);
return UBUS_STATUS_INVALID_ARGUMENT;
}
signame = blobmsg_get_string(keys[SIGNAL_TYPE]);
- ENDPT_DBG("%s() %d %s\n", __func__, line, signame);
+ ENDPT_DBG("line=%d, signame=%s\n", line, signame);
// on or off signal?
enable = "0";
@@ -540,7 +541,7 @@ static int ubus_request_signal(struct ubus_context *uctx, struct ubus_object *ob
if (keys[SIGNAL_DATA])
data = blobmsg_get_string(keys[SIGNAL_DATA]);
} else if (strcmp(state, "off")) {
- ENDPT_DBG("Error! invalid state %s\n", state);
+ ENDPT_ERR("Error! invalid state %s\n", state);
return UBUS_STATUS_INVALID_ARGUMENT;
}
@@ -573,20 +574,20 @@ static int ubus_request_connection(struct ubus_context *uctx, struct ubus_object
/* Check that we have all arguments */
if (!keys[CONNECTION_LINE] || !keys[CONNECTION_ACTION] || !keys[CONNECTION_ID]) {
- ENDPT_DBG("Error! missing argument\n");
+ ENDPT_ERR("Error! missing argument\n");
return UBUS_STATUS_INVALID_ARGUMENT;
}
/* Check that endpt exist */
line = blobmsg_get_u32(keys[CONNECTION_LINE]);
if (line < 0 || line >= terminal_info.num_voice_ports) {
- ENDPT_DBG("Error! No such line value: %d\n", line);
+ ENDPT_ERR("Error! No such line value: %d\n", line);
return UBUS_STATUS_INVALID_ARGUMENT;
}
id = blobmsg_get_u32(keys[CONNECTION_ID]);
if (id < 0) {
- ENDPT_DBG("Error! Invalid connection id: %d\n", id);
+ ENDPT_ERR("Error! Invalid connection id: %d\n", id);
return UBUS_STATUS_INVALID_ARGUMENT;
}
@@ -612,7 +613,7 @@ static int ubus_request_connection(struct ubus_context *uctx, struct ubus_object
data.mask = data.mask|UBUS_DATA_PTIME_BIT;
}
- ENDPT_DBG("%s() line: %d connection_id: %d action: %s\n", __func__, line, id, action_str);
+ ENDPT_DBG("line: %d connection_id: %d action: %s\n", line, id, action_str);
if (strcmp("create", action_str) == 0) {
if(line_new_connection_by_asterisk(line, id, &ubusReq))
return UBUS_STATUS_UNKNOWN_ERROR;
@@ -632,11 +633,11 @@ static int ubus_request_connection(struct ubus_context *uctx, struct ubus_object
if(line_update_connection_by_pbx(line, id))
return UBUS_STATUS_UNKNOWN_ERROR;
} else if (strcmp("parm_update", action_str) == 0) {
- ENDPT_DBG("parm_update request for %s line: %d, id: %d, mask: %d, codec: %d, ptime: %d \n", __func__, line, id, data.mask, data.codec, data.ptime);
+ ENDPT_DBG("parm_update request for line: %d, id: %d, mask: %d, codec: %d, ptime: %d \n", line, id, data.mask, data.codec, data.ptime);
if(line_connection_parm_update_by_asterisk(line, id, &data))
return UBUS_STATUS_UNKNOWN_ERROR;
} else {
- ENDPT_DBG("Error! No such action: %s\n", action_str);
+ ENDPT_ERR("Error! No such action: %s\n", action_str);
return UBUS_STATUS_INVALID_ARGUMENT;
}
@@ -683,7 +684,7 @@ static int ubus_request_status(struct ubus_context *uctx, struct ubus_object *ob
blobmsg_add_u32(&blob, "offhook", voice_line_is_offhook(line + unpopulatedDectEndpoints));
res = UBUS_STATUS_OK;
} else {
- ENDPT_DBG("Error! No such line value: %d\n", line);
+ ENDPT_ERR("Error! No such line value: %d\n", line);
res = UBUS_STATUS_INVALID_ARGUMENT;
}
} else {
@@ -723,14 +724,14 @@ static int ubus_request_rtp_stats(struct ubus_context *uctx, struct ubus_object
/* Check that we have all arguments */
if (!keys[RTP_STATS_LINE] || !keys[RTP_STATS_RESET]) {
- ENDPT_DBG("Error! missing argument\n");
+ ENDPT_ERR("Error! missing argument\n");
return UBUS_STATUS_INVALID_ARGUMENT;
}
/* Check that endpt exist */
line = blobmsg_get_u32(keys[RTP_STATS_LINE]);
if (line < 0 || line >= terminal_info.num_voice_ports) {
- ENDPT_DBG("Error! No such line value: %d\n", line);
+ ENDPT_ERR("Error! No such line value: %d\n", line);
return UBUS_STATUS_INVALID_ARGUMENT;
}
@@ -740,7 +741,7 @@ static int ubus_request_rtp_stats(struct ubus_context *uctx, struct ubus_object
for(conIdx = 0; conIdx < max_num_connections && connections[conIdx].line != line; conIdx++)
continue;
if (conIdx >= max_num_connections) {
- ENDPT_DBG("Error: connection is not found on line %d from maximum %d existing connections\n",
+ ENDPT_ERR("Error: connection is not found on line %d from maximum %d existing connections\n",
line, max_num_connections);
return UBUS_STATUS_UNKNOWN_ERROR;
}
@@ -822,11 +823,11 @@ static int ubus_request_codec_capability(struct ubus_context *uctx, struct ubus_
{
static const char *codecfile = "/lib/voice/codecs.json";
- ENDPT_DBG("Codec capability query failed (%d) and get the information from %s\n", status, codecfile);
+ ENDPT_INFO("Codec capability query failed (%d). Use the information from %s\n", status, codecfile);
int res = blobmsg_add_json_from_file(&blob, codecfile);
if(!res)
{
- ENDPT_DBG("%s is missing or invalid\n", codecfile);
+ ENDPT_ERR("%s is missing or invalid\n", codecfile);
return UBUS_STATUS_UNKNOWN_ERROR;
}
}
@@ -930,7 +931,7 @@ static int ubus_request_call(struct ubus_context *uctx, struct ubus_object *obj
static void got_asterisk_complete(struct ubus_request *req, int ret __attribute__((unused)))
{
if(req->peer != asterisk_id || req->status_code != UBUS_STATUS_OK) {
- ENDPT_DBG("Failed sending event to Asterisk\n");
+ ENDPT_ERR("Failed sending event to Asterisk\n");
}
ubus_cb_asterisk_replied((struct line_event_t*) req->priv, req->status_code);
@@ -968,7 +969,7 @@ int ubus_call_asterisk(const struct line_event_t* const ev)
res = ubus_invoke_async(ctx, asterisk_id, "event", bb.head, req);
if(res != UBUS_STATUS_OK) {
- ENDPT_DBG("Error invoking\n");
+ ENDPT_ERR("Error ubus invoking\n");
res = -1;
goto out;
}
@@ -1004,7 +1005,7 @@ int ubus_broadcast_event(const struct line_event_t* const ev)
blobmsg_add_string(&blob, "event", ev->name);
if(ubus_send_event(ctx, broadcast_path, blob.head) != UBUS_STATUS_OK) {
- ENDPT_DBG("Error sending ubus message %s\n", ev->name);
+ ENDPT_ERR("Error sending ubus message %s\n", ev->name);
res = -1;
}
@@ -1112,7 +1113,7 @@ int ubus_call_dectmngr(int terminal, int add, int release, const char *cid, cons
res = ubus_invoke_async(ctx, dectmngr_id, "call", bb.head, req);
if(res != UBUS_STATUS_OK) {
- ENDPT_DBG("Error invoking\n");
+ ENDPT_ERR("Error ubus invoking\n");
res = -1;
goto out;
}
@@ -1149,17 +1150,17 @@ int perhaps_erase_unused_lines(struct uci_context *context)
strncpy(uciSection2, uciSection, sizeof(uciSection2)); // uci_lookup_ptr() can modify uciSection
if (uci_lookup_ptr(context, &ptr, uciSection, true) == UCI_OK) {
if(uci_delete(context, &ptr) == 0) {
- ENDPT_DBG("Remove voice line %s since DECT is not supported\n", uciSection2);
+ ENDPT_INFO("Remove voice line %s, since DECT is not supported\n", uciSection2);
didErase++;
} else {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to remove the uci section %s, %s\n", uciSection2, error);
+ ENDPT_ERR("Failed to remove the uci section %s, %s\n", uciSection2, error);
free(error);
return -1;
}
} else {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to look up the uci section %s, %s\n", uciSection2, error);
+ ENDPT_ERR("Failed to look up the uci section %s, %s\n", uciSection2, error);
free(error);
return -1;
}
@@ -1170,13 +1171,13 @@ int perhaps_erase_unused_lines(struct uci_context *context)
if (uci_lookup_ptr(context, &ptr, uciSection, true) == UCI_OK) {
if(uci_commit(context, &ptr.p, false) != UCI_OK) {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to commit uci package %s, %s\n", uciStrConfig, error);
+ ENDPT_ERR("Failed to commit uci package %s, %s\n", uciStrConfig, error);
free(error);
return -1;
}
} else {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to look up package %s, %s\n", uciStrConfig, error);
+ ENDPT_ERR("Failed to look up package %s, %s\n", uciStrConfig, error);
free(error);
return -1;
}
@@ -1191,6 +1192,7 @@ int config_init(struct uci_context *context, struct uci_package *package)
struct uci_section *section = NULL;
char *error;
const char *country;
+ const char *loglevel;
char uciSection[sizeof(uciStrLineSect) + 10];
int line;
@@ -1198,28 +1200,36 @@ int config_init(struct uci_context *context, struct uci_package *package)
section = uci_lookup_section(context, package, uciStrComSect);
if (!section) {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to look up section %s.%s, %s\n", uciStrConfig, uciStrComSect, error);
+ ENDPT_ERR("Failed to look up section %s.%s, %s\n", uciStrConfig, uciStrComSect, error);
free(error);
return -1;
}
country = uci_lookup_option_string(context, section, uciStrCountry);
if (!country || !*country) {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to look up option %s.%s.%s, %s\n", uciStrConfig, uciStrComSect, uciStrCountry, error);
+ ENDPT_ERR("Failed to look up option %s.%s.%s, %s\n", uciStrConfig, uciStrComSect, uciStrCountry, error);
free(error);
return -1;
}
if (voice_set_country(country) != 0) {
+ ENDPT_ERR("Failed to set country %s\n", country);
return -1;
}
+ // configure the syslog level for voicemngr
+ loglevel = uci_lookup_option_string(context, section, uciStrLoglevel);
+ if (loglevel && *loglevel) {
+ ENDPT_INFO("syslog level is set to %s\n", loglevel);
+ setlogmask(LOG_UPTO(atoi(loglevel) & LOG_PRIMASK));
+ }
+
// Configure the voice lines
for (line = 0; line < terminal_info.num_voice_ports; line++) {
snprintf(uciSection, sizeof(uciSection), "%s%d", uciStrLineSect, line);
section = uci_lookup_section(context, package, uciSection);
if (!section) {
uci_get_errorstr(context, &error, "");
- ENDPT_DBG("Failed to look up section %s.%s, %s\n", uciStrConfig, uciSection, error);
+ ENDPT_ERR("Failed to look up section %s.%s, %s\n", uciStrConfig, uciSection, error);
free(error);
return -1;
}
@@ -1246,17 +1256,17 @@ int ubus_disable_receive(void) {
res = 0;
if(ubus_remove_object(ctx, &rpcObj) != UBUS_STATUS_OK) {
- ENDPT_DBG("Error deregistering ubus endpt object\n");
+ ENDPT_ERR("Error deregistering ubus endpt object\n");
res = -1;
}
if(ubus_unregister_event_handler(ctx, &ObjRmListener) != UBUS_STATUS_OK) {
- ENDPT_DBG("Error deregistering ubus event handler %s", ubusStrObjRm);
+ ENDPT_ERR("Error deregistering ubus event handler %s", ubusStrObjRm);
res = -1;
}
if(ubus_unregister_event_handler(ctx, &ObjAddListener) != UBUS_STATUS_OK) {
- ENDPT_DBG("Error deregistering ubus event handler %s", ubusStrObjAdd);
+ ENDPT_ERR("Error deregistering ubus event handler %s", ubusStrObjAdd);
res = -1;
}
@@ -1279,7 +1289,7 @@ int ubus_enable_receive(void) {
ObjAddListener.cb = ubus_event_new_obj;
if(ubus_register_event_handler(ctx, &ObjAddListener,
ubusStrObjAdd) != UBUS_STATUS_OK) {
- ENDPT_DBG("Error registering ubus event handler %s", ubusStrObjAdd);
+ ENDPT_ERR("Error registering ubus event handler %s", ubusStrObjAdd);
return -1;
}
@@ -1287,13 +1297,13 @@ int ubus_enable_receive(void) {
ObjRmListener.cb = ubus_event_new_obj;
if(ubus_register_event_handler(ctx, &ObjRmListener,
ubusStrObjRm) != UBUS_STATUS_OK) {
- ENDPT_DBG("Error registering ubus event handler %s", ubusStrObjRm);
+ ENDPT_ERR("Error registering ubus event handler %s", ubusStrObjRm);
return -1;
}
// Invoke our RPC handler when ubus calls (not events) arrive
if (ubus_add_object(ctx, &rpcObj) != UBUS_STATUS_OK) {
- ENDPT_DBG("Failed to register UBUS endpt object\n");
+ ENDPT_ERR("Failed to register UBUS endpt object\n");
return -1;
}
@@ -1323,7 +1333,7 @@ int ubus_init(void) {
ubus_pending_requests = pe_list_new();
if(!ubus_pending_requests) {
- ENDPT_DBG("%s: out of memory\n", __func__);
+ ENDPT_ERR("%s: out of memory\n", __func__);
return -1;
}