提交 3d5ccf05 authored 作者: Stefan Knoblich's avatar Stefan Knoblich

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: 's avatarStefan Knoblich <s.knoblich@axsentis.de>
上级 6787710b
......@@ -144,21 +144,6 @@ fi
##
AC_MSG_RESULT([${as_nl}<<>> Modules and optional features])
##
# libpri (TODO: add checks)
#
HAVE_LIBPRI="no"
AC_ARG_WITH([libpri],
[AS_HELP_STRING([--with-libpri], [Install ftmod_libpri])],
[case "${withval}" in
no) enable_libpri="no" ;;
*) enable_libpri="yes" ;;
esac],
[enable_libpri="no"]
)
HAVE_LIBPRI="${enable_libpri}"
AM_CONDITIONAL([HAVE_LIBPRI],[test "${enable_libpri}" = "yes"])
##
# pritap (TODO: add checks)
#
......@@ -193,6 +178,50 @@ AC_CHECK_LIB([openr2], [openr2_context_set_io_type], [HAVE_OPENR2="yes"])
AC_MSG_RESULT([checking whether to build ftmod_r2... ${HAVE_OPENR2}])
AM_CONDITIONAL([HAVE_OPENR2], [test "${HAVE_OPENR2}" = "yes"])
##
# Digium libpri (TODO: add checks)
#
HAVE_LIBPRI="no"
AC_ARG_WITH([libpri],
[AS_HELP_STRING([--with-libpri], [Install ftmod_libpri])],
[case "${withval}" in
no) enable_libpri="no" ;;
*) enable_libpri="yes" ;;
esac],
[enable_libpri="no"]
)
if test "${enable_libpri}" != "no"
then
AC_MSG_RESULT([${as_nl}<<>> Digium libpri])
save_LIBS="${LIBS}"
LIBS="${LIBS} -lpri"
AC_MSG_CHECKING([whether libpri is usable])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[#include <libpri.h>],
[const char *version = pri_get_version();]
)],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([libpri is not installed or unusable (see config.log for details)])]
)
AC_MSG_CHECKING([whether libpri has BRI support])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[extern void pri_new_bri_cb(void);],
[pri_new_bri_cb();]
)],
[AC_DEFINE([HAVE_LIBPRI_BRI], [1], [libpri has bri support])
AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])]
)
LIBS="${save_LIBS}"
fi
HAVE_LIBPRI="${enable_libpri}"
AM_CONDITIONAL([HAVE_LIBPRI],[test "${enable_libpri}" = "yes"])
##
# Sangoma Wanpipe
#
......
/*
* 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) {
ftdm_log(FTDM_LOG_ERROR, "No D-Channel available, unable to create PRI\n");
return ret;
}
if (spri->dchan && (spri->pri = pri_new_cb(spri->dchan->sockfd, node, swtype, __pri_lpwrap_read, __pri_lpwrap_write, spri))){
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);
ret = 0;
ftdm_channel_write(spri->dchan, buf, buflen, &len);
ret = 0;
} else {
fprintf(stderr, "Unable to create PRI\n");
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:
*/
......@@ -121,6 +121,8 @@ struct lpwrap_pri_event_list {
const char *lpwrap_pri_event_str(lpwrap_pri_event_t event_id);
int lpwrap_one_loop(struct lpwrap_pri *spri);
int lpwrap_init_pri(struct lpwrap_pri *spri, ftdm_span_t *span, ftdm_channel_t *dchan, int swtype, int node, int debug);
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 lpwrap_run_pri(struct lpwrap_pri *spri);
#define lpwrap_run_bri(x) lpwrap_run_pri(x)
#endif
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论