Skip to content
Snippets Groups Projects
Commit 20e036c2 authored by Yalu Zhang's avatar Yalu Zhang
Browse files

Update board and line initializations

parent f6827088
Branches
No related tags found
No related merge requests found
Pipeline #67404 failed
...@@ -54,7 +54,8 @@ static void workaround_handler(int signum __attribute__((unused)), siginfo_t *in ...@@ -54,7 +54,8 @@ static void workaround_handler(int signum __attribute__((unused)), siginfo_t *in
pid_t tid; pid_t tid;
tid = syscall(SYS_gettid); tid = syscall(SYS_gettid);
if(tid != getpid()) pthread_exit(0); if(tid != getpid())
pthread_exit(0);
return; return;
} }
...@@ -66,7 +67,7 @@ static void workaround_handler(int signum __attribute__((unused)), siginfo_t *in ...@@ -66,7 +67,7 @@ static void workaround_handler(int signum __attribute__((unused)), siginfo_t *in
int brcm_sdk_workaround(void) { int brcm_sdk_workaround(void) {
struct sigaction action; struct sigaction action;
// Install a signal handler for our overriden pthread_cancel(). // Install a signal handler for our overridden pthread_cancel()
memset(&action, 0, sizeof(action)); memset(&action, 0, sizeof(action));
action.sa_sigaction = workaround_handler; action.sa_sigaction = workaround_handler;
action.sa_flags = SA_SIGINFO | SA_RESTART; action.sa_flags = SA_SIGINFO | SA_RESTART;
...@@ -79,7 +80,3 @@ int brcm_sdk_workaround(void) { ...@@ -79,7 +80,3 @@ int brcm_sdk_workaround(void) {
return 0; return 0;
} }
int platform_init(void) {
return brcm_sdk_workaround();
}
...@@ -74,6 +74,105 @@ const char* strerror_endp(EPSTATUS code) ...@@ -74,6 +74,105 @@ const char* strerror_endp(EPSTATUS code)
} }
} }
//-------------------------------------------------------------
// Initialize endpoints
int voice_line_init(void) {
int i, j, dectSimulateBusy;
ENDPT_INIT_CFG endpt_cfg;
const char *hwHasDectStr;
EPSTATUS status;
// Keep the sequence of these hardware related initialization functions
if(brcm_sdk_workaround() != 0) {
ENDPT_DBG("Error calling brcm_sdk_workaround\n");
return -1;
}
if(bosInit() != BOS_STATUS_OK) {
ENDPT_DBG("Error initializing Broadcom BOS\n");
return -1;
}
endpt_cfg.country = config_country;
tpUpdateLocaleProfile(endpt_cfg.country);
/* Does the HW has Dect populated in factory? This is stored in the
* "db", but that can't be queried via the normal uci API so we
* export it as an environment var in the startup script. */
hwHasDectStr = getenv("hw_board_hasDect");
dectSimulateBusy = !(hwHasDectStr && *hwHasDectStr == '1');
/* Initialize Endpoint */
status = vrgEndptInit(&endpt_cfg, endpt_cb_event_handler, lineAudioRx, NULL, NULL, NULL, NULL);
if(status != EPSTATUS_SUCCESS) {
ENDPT_DBG("Failed to initialize Broadcom Endpoint: %s\n", strerror_endp(status));
return -1;
}
for (i = 0; i < terminal_info.num_terminals; i++) {
lines[i].pending_digits = pe_list_new();
// Generate a default name if not provided by high level UCI.
if(!lines[i].line_conf.name) lines[i].line_conf.name = strdup("anonymous");
// "create" the line. This maps physical line with boarparams logical line.
status = vrgEndptCreate(i, i, &lines[i].epHandle);
if(status == EPSTATUS_SUCCESS && lines[i].epHandle.lineId == i) {
ENDPT_DBG("Endpoint %d (%s) is created successfully\n", i, lines[i].line_conf.name);
lines[i].physId = i;
} else {
ENDPT_DBG("Error creating Endpoint %d (%s): %s\n", i, lines[i].line_conf.name, strerror_endp(status));
return -1;;
}
// Query line capabilies
if(vrgEndptCapabilities(&lines[i].epHandle, &lines[i].epCap) == EPSTATUS_SUCCESS) {
ENDPT_DBG("pCap 0x%x 0x%x\n", lines[i].epCap.pCap[0], lines[i].epCap.pCap[1]);
ENDPT_DBG("codecs: \n");
for(j = 0; j < CODEC_MAX_TYPES; j++) {
ENDPT_DBG("codecCap[%d]: %u\n", j, lines[i].epCap.codecCap[j]);
}
ENDPT_DBG("echo cancel %u\n", lines[i].epCap.eCap);
ENDPT_DBG("silence suppression %u\n", lines[i].epCap.sCap);
ENDPT_DBG("type ");
switch(lines[i].epCap.endptType) {
case EPTYPE_FXS:
ENDPT_DBG("FXS (phone)\n");
lines[i].type = VOICE_LINE_FXS;
break;
case EPTYPE_PSTN:
ENDPT_DBG("PSTN (operator network)\n");
lines[i].type = VOICE_LINE_UNKNOWN;
break;
case EPTYPE_DECT:
lines[i].type = VOICE_LINE_DECT;
ENDPT_DBG("DECT\n");
break;
default:
break;
}
}
// Send a phone wakeup signal?
ENDPT_DBG("line wakeup %s", lineStrobeWakeup(&lines[i].epHandle) ? "no\n" : "yes\n");
// Line appear as always busy?
if(lines[i].type == VOICE_LINE_DECT) {
lines[i].simulated_busy = dectSimulateBusy;
}
ENDPT_DBG("simulate busy %s\n", lines[i].simulated_busy ? "yes\n" : "no\n");
// Save default values of provisioned values we later modify.
status = vrgEndptProvGet(i, EPPROV_MinDisconnect, &lines[i].def_min_disconnect, sizeof(uint32_t));
if(status != EPSTATUS_SUCCESS) {
ENDPT_DBG("Error getting force onhook time %d: %s\n", i, strerror_endp(status));
lines[i].def_min_disconnect = CAS_IGNOREHOOKSTATE_ON;
}
}
return 0;
}
//------------------------------------------------------------- //-------------------------------------------------------------
// Return true if line is offhook. libvoip knows this // Return true if line is offhook. libvoip knows this
// in an internal state. // in an internal state.
......
#ifndef __BRCM_SDK_WORKAROUND_H #ifndef __BRCM_SDK_WORKAROUND_H
#define __BRCM_SDK_WORKAROUND_H #define __BRCM_SDK_WORKAROUND_H
#if defined BRCM_SDK_504 #if defined BRCM_SDK_504
int brcm_sdk_workaround(void); int brcm_sdk_workaround(void);
#else #else
...@@ -11,5 +10,4 @@ static int brcm_sdk_workaround(void) ...@@ -11,5 +10,4 @@ static int brcm_sdk_workaround(void)
}; };
#endif #endif
#endif #endif
...@@ -176,6 +176,7 @@ int voice_connection_find(int line, int conId); ...@@ -176,6 +176,7 @@ int voice_connection_find(int line, int conId);
// Line API // Line API
int voice_line_preinit(void); int voice_line_preinit(void);
int voice_line_init(void);
int voice_line_deinit(void); int voice_line_deinit(void);
int voice_line_is_offhook(int line); int voice_line_is_offhook(int line);
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <libubus.h> #include <libubus.h>
#include <sched.h> // sched_yield() #include <sched.h> // sched_yield()
#include <assert.h> #include <assert.h>
#include <alloca.h> #include <alloca.h>
#include <libpicoevent.h> // for err_exit() #include <libpicoevent.h> // for err_exit()
#include "libvoice.h" #include "libvoice.h"
#include "line.h" #include "line.h"
#include "line-dect.h" #include "line-dect.h"
...@@ -937,107 +937,3 @@ static void lineAudioRx(ENDPT_STATE *endptState, int conId, EPPACKET *epPacketp, ...@@ -937,107 +937,3 @@ static void lineAudioRx(ENDPT_STATE *endptState, int conId, EPPACKET *epPacketp,
} }
} }
} }
//-------------------------------------------------------------
// Initialize endpoints
int lineInit(void) {
int i, j, dectSimulateBusy;
ENDPT_INIT_CFG endpt_cfg;
const char *hwHasDectStr;
EPSTATUS status;
if(bosInit() != BOS_STATUS_OK) {
err_exit("Error init Broadcom BOS\n");
}
endpt_cfg.country = config_country;
tpUpdateLocaleProfile(endpt_cfg.country);
/* Does the HW has Dect populated in factory? This is stored in the
* "db", but that can't be queried via the normal uci API so we
* export it as an environment var in the startup script. */
hwHasDectStr = getenv("hw_board_hasDect");
dectSimulateBusy = !(hwHasDectStr && *hwHasDectStr == '1');
/* Intialize endpoint */
status = vrgEndptInit(&endpt_cfg, endpt_cb_event_handler, lineAudioRx,
NULL, NULL, NULL, NULL);
if(status == EPSTATUS_SUCCESS) {
ENDPT_DBG("Endpoint lib init success\n");
}
else {
err_exit("Error init endpoint lib: %s\n", strerror_endp(status));
}
for (i = 0; i < terminal_info.num_terminals; i++) {
lines[i].pending_digits = pe_list_new();
// Generate a default name if not provided by high level UCI.
if(!lines[i].line_conf.name) lines[i].line_conf.name = strdup("anonymous");
// "create" the line. This maps physical line whith boarparams logical line.
// physId VOICE_DAUGHTER_BOARD_PARMS.BP_CHAN_PCM[i] state[physId]
status = vrgEndptCreate(i, i, &lines[i].epHandle);
if(status == EPSTATUS_SUCCESS && lines[i].epHandle.lineId == i) {
ENDPT_DBG("Endpoint %d (%s) created successfully\n", i, lines[i].line_conf.name);
lines[i].physId = i;
}
else {
err_exit("Error creating endpoint %d: %s\n", i, strerror_endp(status));
continue;
}
// Query line capabilies
if(vrgEndptCapabilities(&lines[i].epHandle, &lines[i].epCap) ==
EPSTATUS_SUCCESS) {
ENDPT_DBG("pCap 0x%x 0x%x\n",
lines[i].epCap.pCap[0], lines[i].epCap.pCap[1]);
ENDPT_DBG("codecs: \n");
for(j = 0; j < CODEC_MAX_TYPES; j++) {
ENDPT_DBG("codecCap[%d]: %u\n", j, lines[i].epCap.codecCap[j]);
}
ENDPT_DBG("echo cancel %u\n", lines[i].epCap.eCap);
ENDPT_DBG("silence suppression %u\n", lines[i].epCap.sCap);
ENDPT_DBG("type ");
switch(lines[i].epCap.endptType) {
case EPTYPE_FXS:
ENDPT_DBG("FXS (phone)\n");
lines[i].type = VOICE_LINE_FXS;
break;
case EPTYPE_PSTN:
ENDPT_DBG("PSTN (operator network)\n");
lines[i].type = VOICE_LINE_UNKNOWN;
break;
case EPTYPE_DECT:
lines[i].type = VOICE_LINE_DECT;
ENDPT_DBG("DECT\n");
break;
default:
break;
}
}
// Send a phone wakeup signal?
ENDPT_DBG("line wakeup %s", lineStrobeWakeup(&lines[i].epHandle) ?
"no\n" : "yes\n");
// Line appear as always busy?
if(lines[i].type == VOICE_LINE_DECT) {
lines[i].simulated_busy = dectSimulateBusy;
}
ENDPT_DBG("simulate busy %s\n", lines[i].simulated_busy ? "yes\n" : "no\n");
// Save default values of provisioned values we later modify.
status = vrgEndptProvGet(i, EPPROV_MinDisconnect,
&lines[i].def_min_disconnect, sizeof(uint32_t));
if(status != EPSTATUS_SUCCESS) {
ENDPT_DBG("Error getting force onhook time %d: %s\n",
i, strerror_endp(status));
lines[i].def_min_disconnect = CAS_IGNOREHOOKSTATE_ON;
}
}
if(line_dect_init()) return -1;
return 0;
}
...@@ -69,6 +69,5 @@ int lineCloseConnectionByDect(int line, int pcmId, struct voice_ubus_req_t *ubus ...@@ -69,6 +69,5 @@ int lineCloseConnectionByDect(int line, int pcmId, struct voice_ubus_req_t *ubus
void lineAudioTx(pe_packet_t *p); void lineAudioTx(pe_packet_t *p);
int line_signal(int line, char *signame, const char *data, struct voice_ubus_req_t *ubusReq); int line_signal(int line, char *signame, const char *data, struct voice_ubus_req_t *ubusReq);
int voicemngr_set_country(const char *country_str); int voicemngr_set_country(const char *country_str);
int lineInit(void);
#endif #endif
...@@ -201,18 +201,17 @@ int main(void) { ...@@ -201,18 +201,17 @@ int main(void) {
// Call this first. Find out how many phone lines we have // Call this first. Find out how many phone lines we have
if(voice_get_terminal_info(&terminal_info)) goto err; if(voice_get_terminal_info(&terminal_info)) goto err;
if(voice_line_preinit()) goto err; if(voice_line_preinit()) goto err;
if(signals_init()) goto err; if(signals_init()) goto err;
if((picoBase = pe_base_new()) < 0) goto err; if((picoBase = pe_base_new()) < 0) goto err;
fifos_init(); fifos_init();
streams_and_buses_init(); streams_and_buses_init();
if(ubus_init()) goto err; if(ubus_init()) goto err;
if(platform_init()) goto err;
if(config_init(context, package)) goto err; if(config_init(context, package)) goto err;
package = NULL; // the package has been unloaded by config_init() package = NULL; // the package has been unloaded by config_init()
if(lineInit()) goto err; if(voice_line_init()) goto err;
if(line_dect_init()) goto err;
if(voice_connection_init()) goto err; if(voice_connection_init()) goto err;
if(perhaps_erase_unused_lines(context)) goto err; if(perhaps_erase_unused_lines(context)) goto err;
if(ubus_enable_receive()) goto err; if(ubus_enable_receive()) goto err;
...@@ -223,8 +222,7 @@ int main(void) { ...@@ -223,8 +222,7 @@ int main(void) {
ENDPT_DBG("voicemngr has started successfully\n"); ENDPT_DBG("voicemngr has started successfully\n");
/* Listen for events and dispatch them to handlers. /* Listen for events and dispatch them to handlers. Does not return. */
Does not return. */
pe_base_dispatch(picoBase); pe_base_dispatch(picoBase);
err: err:
......
...@@ -21,7 +21,4 @@ extern int picoBase; // libpicoevent main loop base ...@@ -21,7 +21,4 @@ extern int picoBase; // libpicoevent main loop base
int send_audio_asterisk(uint8_t *buf, int size); int send_audio_asterisk(uint8_t *buf, int size);
int send_event_main(struct line_event_t *ev, char x); int send_event_main(struct line_event_t *ev, char x);
// Platform dependent initialization
int platform_init(void);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment