mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-14 09:58:17 +00:00
ftmod_libpri: Initial support for BRI and various cleanups + double locking fix
Fixes: - Fix double locking in check_state(): remove ftdm_mutex_(un)lock calls. New: - Add lpwrap_init_bri() to initialize libpri in BRI mode - Use trunk type to determine PRI/BRI and PTP/PTMP mode (no additional configuration required). - Improve libpri detection code in configure.ac, check whether libpri is usable and if BRI support is available (needs more work) Cleanups: - Whitespace and indentation cleanups - Rename str2* functions to parse_* - Simplify libpri_configure_span() option parsing and bail out on error - Add "ftdm libpri help" command that displays usage information - Coding style cleanups and other (minor) changes Known issues: - BRI PTMP TE Q.921 link does not go beyond TEI ASSIGNED state, SABME requests are ignored by NT (EuroISDN DTAG, DAHDI-2.3.0.1, vzaphfc) Signed-off-by: Stefan Knoblich <s.knoblich@axsentis.de>
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2009, Anthony Minessale II
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -106,7 +106,7 @@ static struct lpwrap_pri_event_list LPWRAP_PRI_EVENT_LIST[] = {
|
||||
#define LINE "--------------------------------------------------------------------------------"
|
||||
|
||||
const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id)
|
||||
{
|
||||
{
|
||||
return LPWRAP_PRI_EVENT_LIST[event_id].name;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ static int __pri_lpwrap_read(struct pri *pri, void *buf, int buflen)
|
||||
} else {
|
||||
ftdm_log(FTDM_LOG_CRIT, "span %d D-READ TIMEOUT\n", spri->span->span_id);
|
||||
}
|
||||
|
||||
|
||||
ftdm_clear_flag(spri, LPWRAP_PRI_READY);
|
||||
return -1;
|
||||
}
|
||||
@@ -173,21 +173,56 @@ int lpwrap_init_pri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *
|
||||
int ret = -1;
|
||||
|
||||
memset(spri, 0, sizeof(struct lpwrap_pri));
|
||||
|
||||
spri->dchan = dchan;
|
||||
spri->span = span;
|
||||
spri->span = span;
|
||||
|
||||
if (spri->dchan && (spri->pri = pri_new_cb(spri->dchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){
|
||||
unsigned char buf[4] = { 0 };
|
||||
size_t buflen = sizeof(buf), len = 0;
|
||||
pri_set_debug(spri->pri, debug);
|
||||
ret = 0;
|
||||
|
||||
ftdm_channel_write(spri->dchan, buf, buflen, &len);
|
||||
} else {
|
||||
fprintf(stderr, "Unable to create PRI\n");
|
||||
if (!spri->dchan) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "No D-Channel available, unable to create PRI\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((spri->pri = pri_new_cb(spri->dchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))) {
|
||||
unsigned char buf[4] = { 0 };
|
||||
size_t buflen = sizeof(buf), len = 0;
|
||||
|
||||
pri_set_debug(spri->pri, debug);
|
||||
ftdm_channel_write(spri->dchan, buf, buflen, &len);
|
||||
|
||||
ret = 0;
|
||||
} else {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Unable to create PRI\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int lpwrap_init_bri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *dchan, int swtype, int node, int ptmp, int debug)
|
||||
{
|
||||
int ret = -1;
|
||||
#ifdef HAVE_LIBPRI_BRI
|
||||
memset(spri, 0, sizeof(struct lpwrap_pri));
|
||||
spri->dchan = dchan;
|
||||
spri->span = span;
|
||||
|
||||
if (!spri->dchan) {
|
||||
ftdm_log(FTDM_LOG_ERROR, "No D-Channel available, unable to create BRI\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((spri->pri = pri_new_bri_cb(spri->dchan->sockfd, ptmp, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))) {
|
||||
unsigned char buf[4] = { 0 };
|
||||
size_t buflen = sizeof(buf), len = 0;
|
||||
|
||||
pri_set_debug(spri->pri, debug);
|
||||
ftdm_channel_write(spri->dchan, buf, buflen, &len);
|
||||
|
||||
ret = 0;
|
||||
} else {
|
||||
ftdm_log(FTDM_LOG_ERROR, "Unable to create BRI\n");
|
||||
}
|
||||
#else
|
||||
ftdm_log(FTDM_LOG_ERROR, "Installed libpri version (%s) has no BRI support\n",
|
||||
pri_get_version());
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -198,8 +233,8 @@ int lpwrap_one_loop(struct lpwrap_pri *spri)
|
||||
struct timeval now = {0,0}, *next;
|
||||
pri_event *event;
|
||||
event_handler handler;
|
||||
int sel;
|
||||
|
||||
int sel;
|
||||
|
||||
if (spri->on_loop) {
|
||||
if ((sel = spri->on_loop(spri)) < 0) {
|
||||
return sel;
|
||||
@@ -269,7 +304,7 @@ int lpwrap_one_loop(struct lpwrap_pri *spri)
|
||||
int lpwrap_run_pri(struct lpwrap_pri *spri)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
||||
for (;;){
|
||||
ret = lpwrap_one_loop(spri);
|
||||
|
||||
@@ -280,7 +315,7 @@ int lpwrap_run_pri(struct lpwrap_pri *spri)
|
||||
/* Igonore an interrupted system call */
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
ftdm_log(FTDM_LOG_CRIT, "Error = %i [%s]\n", ret, strerror(errno));
|
||||
break;
|
||||
}
|
||||
@@ -300,4 +335,3 @@ int lpwrap_run_pri(struct lpwrap_pri *spri)
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
||||
|
||||
|
Reference in New Issue
Block a user