Compare commits

...

23 Commits

Author SHA1 Message Date
Shaun Ruffell
49361e5ce7 dahdi_cfg: Warn if idle bits are set on invalid channel type.
Hopefully will save a little time in the future if anyone ever types into
/etc/dahdi/system.conf:

  bchan=1-15,17-30:1101

when they meant:

  cas=1-15,17-30:1101

in the future.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
Signed-off-by: Russ Meyerriecks <rmeyerriecks@digium.com>
2014-07-09 15:55:37 -05:00
Shaun Ruffell
8045f7f493 dahdi_cfg: Unlink semaphore on early exit.
If dahdi_cfg is terminated while holding the named semaphore, it is possible to
leave it behind and all subsequenct invocations of dahdi_cfg will block waiting
for it.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
Signed-off-by: Russ Meyerriecks <rmeyerriecks@digium.com>
2014-07-07 17:06:16 -05:00
Tzafrir Cohen
64e7c688d3 Makefile: A typo in a comment
Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
2014-06-30 13:47:23 +03:00
Oron Peled
b28ec382bb added autoconfig.h to .gitignore
Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
2014-06-29 16:34:24 +03:00
Oron Peled
412c3f0fe3 xpp: support per-port E1/T1 EC
* Added optional '-S <span-spec>' argument to astribank_hexload:
  - Allow passing PRI span specification to EC firmware loader.
  - The span specifications is whitespace/comma separate list
    of items.
  - Each item is: <span>:<type> (Example: 3:T1)
  - The <span> may use shell-like globbing (e.g: *:E1 or [12]:T1)
  - Any span not matched in the span specification will be set
    as without the new '-S' option (i.e: depends on the '-A' option).

* Adapted xpp_fxloader:
  - Read specification for both device label and wildcard from
    /etc/dahdi/span-types.conf
  - If the result is non-empty, pass it as '-S <span-spec>' to
    the EC firmware loader.
2014-06-29 16:34:21 +03:00
Oron Peled
fc459c374c xpp: set EC firmware according to PRI settings:
* Read first from modern configuration files
  (/etc/dahdi/span-types.conf)
  - Support either exact label match or complete '*' match in the
    configuration file.

* Fallback to legacy /etc/dahdi/xpp.conf

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
2014-06-29 16:34:17 +03:00
Oron Peled
ca09f327ed xpp: better dahdi_registration
Improvements to the xpp tool dahdi_registration:

* Use the new xpp driver with support for dahdi_registration sysfs
  attribute in each device.

* Wait for UDEV to finish handling span assignments (via
  dahdi_waitfor_span_assignments).

* Still supports legacy drivers without this, by falling back
  to old style iterative "registration" on each xpd.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
2014-06-29 16:30:34 +03:00
Tzafrir Cohen
b1d55683ae xpp: Don't generate .depends if there's no libusb
Creating the The .depends file requires libusb support.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
2014-06-10 12:41:43 +03:00
Oron Peled
9285e86492 xpp: better error checking (echo_loader)
Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
2014-05-11 19:07:40 +03:00
Oron Peled
ca7c04e9cb xpp: fix usb "clear_halt" problem
* Don't use "usb_clear_halt" by default anymore
   - It caused problems with specific devices in the past
   - Now it cause problems with specific servers as well (64 bits, USB3)

 * Add an "XTALK_OPTIONS" environment variable to pass options:
   - Use it to implement a "use-clear-halt" boolean option that
     restore original behavior.
   - Also use it for "no-lock" option which replace the legacy
     environment variable "XUSB_NOLOCK".
2014-05-11 18:03:11 +03:00
Oron Peled
ae02edacb4 xpp: safer compilation
* Compile with "-Wall -Werror"
* Better dependency calculation:
  - Explicit listing of sources, don't use wildcards.
  - Pass various CFLAGS to dependency calculation as well.
  - Make sure a failure is propagated

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
2014-05-11 18:03:11 +03:00
Shaun Ruffell
2abfd165ae system.conf.sample: Remove reference to single frequency signalling.
Single frequency signalling has not been supported in dahdi_cfg since the switch
to DAHDI. Before DAHDI, in the Zaptel days, it was only suported in the
ztcfg_dude utility which wasn't mainlined. So this removes references to those
signalling modes unless support is added back into the driver.

Internal-Issue-ID: DAHLIN-335
Signed-off-by: Shaun Ruffell <sruffell@digium.com>
2014-05-05 09:45:02 -05:00
Oron Peled
1e6b2741db dahdi_genconf: remove hard-coded E1 default
* The "spantypes" generator had E1 default if no 'line-mode' parameter
  was passed.

* As a result the new logic in "dahdi_span_types dumpconfig" had no
  effect when called from dahdi_genconf, as it was always called
  with "--line-mode=" argument.

* Now "dahdi_genconf spantype" behaves just like
  "dahdi_span_types dumpconfig":
  - The "--line-mode=" forces generation of provided line-mode (E1/J1/T1)
  - Without this option, the generated config matches the current spans
    state according to new dahd_span_types default logic:
    - Wildcard rule if all spans have same line-mode.
    - Uncommented specific matches if spans have different line-modes.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
2014-04-30 22:51:58 +03:00
Oron Peled
794c8eb048 xpp: waitfor_xpds: handle missing serial numbers
Fixes a regression since 949ea4ca9f
(2.7.0) - allows using an Astribank with no serial.

* Some of the olderst Astribanks don't have a serial number burned in
  them. Thus there is no serial attribute for the sysfs USB device node.

* waitfor_xpds identifies the Astribanks by their serial numbers.

* An lone Astribank without serial number would thus block waitfor_xpds
  (until timeout).

* Now we warn about them.

* We also try to handle it gracefully. As long as there's only one
  of thease, it would be counted as "NO-SERIAL".

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
2014-04-30 22:48:06 +03:00
Oron Peled
ffe36c63e0 xpp: dahdi_registration: force re-assignment
* The system state causing the bug:
  - DAHDI has auto_assign_spans==1
  - No /etc/dahdi/assigned-spans.conf

* The bug scenario:
  - During initial device detection, they are assigned by
    DAHDI driver.
  - Later we run "dahdi_span_assignment remove"
  - Then, a "dahdi_registration on" would not assign any span.

* The fix:
  - Using the '-R' option, force "dahdi_registration on" to also
    do "dahdi_span_assignment auto" on relevant devices.
  - This is the way it's called by /usr/share/dahdi/dahdi_auto_assign_compat

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Acked-by: Shaun Ruffell <sruffell@digium.com>
2014-04-30 22:46:41 +03:00
Oron Peled
f2628eeedd improved dahdi_span_types dumpconfig
* Better defaults:
  - A wildcard match:
    - If '--line-mode' option is given, generate a wildcard entry.
      (existing behavior).

    - Otherwise, if *all spans* are of the same type (E1/T1),
      generate a wildcard entry for this type.
      This is the most common use-case and now it work without
      any command line flags.

    - Otherwise (mixed E1/T1 spans), do not generate a wildcard entry.
      This isn't common case (except from our labs), but regardless
      without '--line-mode' any guess could be wrong.

  - Specific device matches:
    - If all spans are of the same type, generate commented out
      specific entries (for manual overrides).

    - If spans have mixed E1/T1 types, generate specific entries
      In this case, specific entries MUST NOT be commented out
      otherwise, the configuration file is wrong!

* Generated header with better organization:
  - Shows what is generated:
    - Generating wildcard / Not generating wildcard
    - Generating specific lines / Generating *commented-out* specific lines

  - For each decision, show *why* it was taken.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
2014-04-01 21:23:28 +03:00
Oron Peled
1292ea9078 registration-order: Added dahdi_auto_assign_compat
Maintains the original registration order as was before span
assignments. Should allow seemless trannsition to
dahdi.auto_assign_spans=0

* The idea:
  - We stop handling in udev the case of missing
    /etc/dahdi/assigned-spans.conf
  - Instead we rely on "registration_time" dahdi_device attribute from
    DAHDI-linux
  - Then, we can sort the devices and assign their spans in
    /etc/init.d/dahdi
* Mechanics:
  - From /etc/init.d/dahdi, we run a new 'dahdi_auto_assign_compat'
    script (after "waitfor_xpds" etc.)
  - In this script we "auto" assign spans of non-Astribank devices
  - In the end of the script we run "dahdi_registration" which
    does the same for Astribank devices.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
2014-03-25 14:51:29 +02:00
Oron Peled
cfee27106b hotplug: call handle_device.d/ actions for remove
* Original actions didn't care about remove (10-span-types, 20-span-assignments)
* But others need to know about removals too.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
2014-03-25 14:48:09 +02:00
Shaun Ruffell
066fa2aff3 dahdi_cfg: error()->perror() when sem_open fails.
This fixes a confusing error message. When sem_open failed, the system.conf line
number was being printed and the system error code was not.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
2014-02-12 11:56:00 -06:00
Aslan Laoz
bce5afacf1 waitfor_xpds: handle the case of a failing AB
If an Astribank failed initialization, don't keep waiting for it.
2014-02-07 14:23:19 +02:00
Tzafrir Cohen
dd752529f0 auto_assign_spans may be true even if not '1'
auto_assign_spans is an int and may have legal values other than 1. It
is legal (though pointless) to use: modprobe dahdi auto_assign_spans=3.
Any value != 0 is true.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
2014-02-07 14:22:49 +02:00
Shaun Ruffell
27d07446ef hotplug: Check for auto_assign_spans only when ACTION is add.
Removes a potentially confusing error message. This is a reapplication of
(4f259cd569 "dahdi_handle_device, dahdi_span_config: Check for
auto_assign_spans only when ACTION is add.") which appears to have been
accidentally removed when moving the hotplug scripts into a subdirectory.

From the original commit:

When dahdi.ko is unloaded, it may be possible for the driver to be removed from
the kernel before the udev scripts are run.  When this happens, you'll see
messages like the following which are not accurate:

    'dahdi_handle_device'[24567]: Old driver (no auto_assign_spans parameter). Skip /devices/pci0000:00/0000:00:1e.0/0000:11:01.0/pci:0000:11:01.0

Now instead you will see:

    'dahdi_handle_device'[28008]: remove: /devices/pci0000:00/0000:00:1e.0/0000:11:01.0/pci:0000:11:01.0

Also, all the udev events will be logged in the system log even when they are
ignored because of legacy auto span assignment. This will help show what is
going on during the transition period to full udev configuration of spans.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
Acked-by: Oron Peled <oron.peled@xorcom.com>
2014-01-31 16:08:21 -06:00
Shaun Ruffell
8e2a5def27 hotplug: Do not run auto span configuration if spans are auto assigned.
This reapplies the change made in commit (6ed0adc08 "dahdi_span_config: Do not run auto
span configuration if spans are auto assigned.") which appears to have been
accidentally removed in (7f826a7d35 "hotplug modularization: split logic to
scriptlets").

To rationale from commit 6ed0adc08:

I have seen cases were users run:

  # modprobe <driver>; dahdi_cfg -c <custom config file>

and the spans end up misconfigured because dahdi_span_assignments ends up
running, via udev, after the user configured the span the way it wanted.

dahdi_span_assignments now looks at auto_assign_spans module parameter on
dahdi.ko, like dahdi_handle_device already does, to determine if legacy or udev
based configuration is being done.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
2014-01-31 11:16:08 -06:00
24 changed files with 700 additions and 145 deletions

1
.gitignore vendored
View File

@@ -4,6 +4,7 @@
*.asciidoc
*.html
build_tools/menuselect-deps
autoconfig.h
config.log
config.status
dahdi_cfg

View File

@@ -108,6 +108,7 @@ endif
ASSIGNED_DATA_SCRIPTS:=\
dahdi_handle_device \
dahdi_span_config \
dahdi_auto_assign_compat \
span_config.d/10-dahdi-cfg \
span_config.d/20-fxotune \
span_config.d/50-asterisk \
@@ -212,7 +213,7 @@ README.html: README system.conf.asciidoc init.conf.asciidoc tonezones.txt \
README.Astribank.html: xpp/README.Astribank
$(ASCIIDOC) -o $@ -n -a toc -a toclevels=4 $<
# on Debian: this requires the full groof, not just groff-base.
# on Debian: this requires the full groff, not just groff-base.
%.8.html: %.8
man -Thtml $^ >$@

View File

@@ -148,11 +148,6 @@ xpp_startup() {
if ! /usr/share/dahdi/waitfor_xpds; then return 0; fi
hotplug_exit_after_load
# overriding locales for the above two, as perl can be noisy
# when locales are missing.
# No register all the devices if they didn't auto-register:
LC_ALL=C dahdi_registration on
}
@@ -263,6 +258,9 @@ case "$1" in
xpp_startup
# Assign all spans that weren't handled via udev + /etc/dahdi/assigned-spans.conf
/usr/share/dahdi/dahdi_auto_assign_compat
if [ $system = debian ]; then
echo -n "Running dahdi_cfg: "
$DAHDI_CFG_CMD 2> /dev/null && echo -n "done"

View File

@@ -29,6 +29,7 @@
#include <stdio.h>
#include <getopt.h>
#include <signal.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
@@ -761,7 +762,16 @@ static int chanconfig(char *keyword, char *args)
} else {
fprintf(stderr, "Huh? (%s)\n", keyword);
}
if (is_digital)
if (cc[x].sigtype != DAHDI_SIG_CAS &&
cc[x].sigtype != DAHDI_SIG_DACS &&
cc[x].sigtype != DAHDI_SIG_DACS_RBS) {
if (NULL != idle) {
fprintf(stderr, "WARNING: idlebits are not valid on %s channels.\n", sig[x]);
}
}
if (is_digital)
chan2span[x] = current_span;
else
current_span = 0;
@@ -1540,15 +1550,27 @@ static int span_restrict(char *str)
return 1;
}
static const char *SEM_NAME = "dahdi_cfg";
static sem_t *lock = SEM_FAILED;
static void signal_handler(int signal)
{
if (SEM_FAILED != lock) {
sem_unlink(SEM_NAME);
}
/* The default handler should have been restored before this handler was
* called, so we can let the "normal" processing finish the cleanup. */
raise(signal);
}
int main(int argc, char *argv[])
{
int c;
char *buf;
char *key, *value;
int x,found;
sem_t *lock = SEM_FAILED;
const char *SEM_NAME = "dahdi_cfg";
int exit_code = 0;
struct sigaction act;
while((c = getopt(argc, argv, "fthc:vsd::C:S:")) != -1) {
switch(c) {
@@ -1670,15 +1692,28 @@ finish:
fflush(stdout);
}
sigemptyset(&act.sa_mask);
act.sa_handler = signal_handler;
act.sa_flags = SA_RESETHAND;
if (sigaction(SIGTERM, &act, NULL) == -1) {
perror("Failed to install SIGTERM handler.");
exit(1);
}
if (sigaction(SIGINT, &act, NULL) == -1) {
perror("Failed to install SIGINT handler.");
exit(1);
}
lock = sem_open(SEM_NAME, O_CREAT, O_RDWR, 1);
if (SEM_FAILED == lock) {
error("Unable to create 'dahdi_cfg' mutex.\n");
perror("Unable to create 'dahdi_cfg' mutex");
exit_code = 1;
goto release_sem;
}
if (-1 == sem_wait(lock)) {
error("Failed to wait for dahdi_cfg mutex.\n");
perror("Failed to wait for 'dahdi_cfg' mutex");
exit_code = 1;
goto unlink_sem;
}
@@ -1730,7 +1765,7 @@ finish:
}
if (-1 == sem_wait(lock)) {
error("Failed to wait for dahdi_cfg mutex after creating dynamic spans.\n");
perror("Failed to wait for 'dahdi_cfg' mutex after creating dynamic spans");
exit_code = 1;
goto unlink_sem;
}

View File

@@ -188,28 +188,57 @@ show_spantypes() {
done
}
list_pri_spantypes() {
find $DEVICES -follow -maxdepth 1 -name spantype | \
xargs cat | \
sed -n '/:[ETJ]1$/s/^.*://p' | \
sort -u | \
tr '\n' ' ' | \
sed -e 's/^ *//' -e 's/ *$//'
}
dump_config() {
pri_spantypes=`list_pri_spantypes`
num_spantypes=`echo "$pri_spantypes" | wc -w`
gen_default=''
echo '#'
echo "# Autogenerated by $0 on `date`"
echo "# Map PRI DAHDI devices to span types for E1/T1/J1"
if [ "$DEFAULT_LINE_MODE" != '' ]; then
echo "# Was run with '--line-mode=$DEFAULT_LINE_MODE' -- so will:"
echo "# * Generate default wildcard entry"
echo "# * Generate commented-out device list (for overrides)"
fi
echo ''
fmt="%-65s %s\n"
printf "$fmt" '# @location/hardware_id' 'span_type'
echo "#"
echo "# Summary:"
if [ "$DEFAULT_LINE_MODE" != '' ]; then
echo ""
echo "# Wildcard line-mode $DEFAULT_LINE_MODE".
printf "$fmt" "*" "*:$DEFAULT_LINE_MODE"
echo ""
echo "# A list of commented out configurations for spans."
echo "# Each item may be un-commented to provide an override."
gen_default="$DEFAULT_LINE_MODE"
echo "# * Generating wildcard match of $gen_default."
echo "# - Was run with '--line-mode=$DEFAULT_LINE_MODE'"
elif [ "$num_spantypes" -eq 1 ]; then
gen_default="$pri_spantypes"
echo "# * Generating wildcard match of $gen_default."
echo "# - Spans were $pri_spantypes"
else
echo "# * Not generating wildcard match."
echo "# - Was run without '--line-mode' option and span were of mixed types [$pri_spantypes]"
fi
echo "#"
if [ "$num_spantypes" -eq 1 ]; then
echo "# * Generating a list of commented out configurations for spans."
echo "# - Spans were $pri_spantypes"
echo "# - Uncomment for specific overrides"
else
echo "# * Generating a list of specific span configurations."
echo "# - Spans were of mixed types: $pri_spantypes"
fi
echo "#"
echo ''
fmt="%-65s %s"
printf "$fmt\n" '# @location/hardware_id' 'span_type'
if [ "$gen_default" != '' ]; then
printf "$fmt\t\t# Wildcard line-mode" "*" "*:$gen_default"
echo ""
fi
echo ""
for device in $DEVICES
do
devpath=`cd "$device" && pwd -P`
@@ -226,10 +255,10 @@ dump_config() {
cat "$device/spantype" | while read st; do
case "$st" in
*:[ETJ]1)
if [ "$DEFAULT_LINE_MODE" != '' ]; then
printf "#$fmt" "$id" "$st"
if [ "$num_spantypes" -eq 1 ]; then
printf "#$fmt\n" "$id" "$st"
else
printf "$fmt" "$id" "$st"
printf "$fmt\n" "$id" "$st"
fi
;;
*)
@@ -237,7 +266,7 @@ dump_config() {
;;
esac
done | sort -n
#echo ''
echo ''
done
}

View File

@@ -0,0 +1,25 @@
#! /bin/sh
devdir='/sys/bus/dahdi_devices/devices'
# DAHDI is loaded?
if [ ! -d "$devdir" ]; then
exit 0
fi
devices_by_registration_time() {
grep -H '' $devdir/*/registration_time 2>/dev/null | \
sed 's,/registration_time:,\t,' | \
sort -k 2,2
}
# First assign non-Astribank devices
devices_by_registration_time | \
grep -v '/astribanks:' | \
while read devpath time; do
echo >&2 "D: auto '$devpath'"
dahdi_span_assignments auto "$devpath"
done
# Now handle Astribanks
LC_ALL=C dahdi_registration -Rv on

View File

@@ -36,16 +36,6 @@ if [ "$DAHDI_UDEV_DISABLE_DEVICES" = 'yes' ]; then
exit 0
fi
# Check if we can safely do our job
if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then
echo "Old driver (no auto_assign_spans parameter). Skip $DEVPATH" | $LOGGER
exit 0
fi
if [ `cat /sys/module/dahdi/parameters/auto_assign_spans` -eq 1 ]; then
echo "auto_assign_spans=1. Skip $DEVPATH" | $LOGGER
exit 0
fi
# Can we pass a different value so we can use
# alternate (testing) configuration?
# Meanwhile, make it hard-coded.
@@ -72,12 +62,24 @@ run_parts() {
case "$ACTION" in
add)
echo "$ACTION: $DEVPATH" | $LOGGER
# Check if we can safely do our job
if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then
echo "Old driver (no auto_assign_spans parameter). Skip $DEVPATH" | $LOGGER
exit 0
fi
if [ `cat /sys/module/dahdi/parameters/auto_assign_spans` -ne 0 ]; then
echo "auto_assign_spans=1. Skip $DEVPATH" | $LOGGER
exit 0
fi
# Background run -- don't block udev
run_parts 2>&1 < /dev/null | $LOGGER &
;;
remove)
# Nothing to do yet...
echo "$ACTION: $DEVPATH" | $LOGGER
# Background run -- don't block udev
run_parts 2>&1 < /dev/null | $LOGGER &
;;
*)
echo "UNHANDLED: $ACTION: $DEVPATH" | $LOGGER

View File

@@ -62,6 +62,20 @@ run_parts() {
case "$ACTION" in
add)
echo "$ACTION: $DEVPATH" | $LOGGER
# Old driver. These scripts probably won't work anyway.
if [ ! -f /sys/module/dahdi/parameters/auto_assign_spans ]; then
if [ -f /sys/module/dahdi ]; then
$LOGGER "Old driver (no auto_assign_spans parameter). Skip $DEVPATH"
exit 0
fi
fi
if [ $(cat /sys/module/dahdi/parameters/auto_assign_spans) -ne 0 ]; then
$LOGGER "auto_assign_spans=1. Skip $DEVPATH"
exit 0
fi
# Set variables
span_devpath="/sys$DEVPATH"
SPANNO=`echo "$span_devpath" | sed 's,.*/span-,,'`

View File

@@ -1,5 +1,12 @@
#! /bin/sh
case "$ACTION" in
add)
;;
*)
exit 0
esac
if [ -r "$DAHDICONFDIR/span-types.conf" ]; then
dahdi_span_types set "/sys$DEVPATH"
fi

View File

@@ -1,8 +1,15 @@
#! /bin/sh
case "$ACTION" in
add)
;;
*)
exit 0
esac
# For now, handle only spans in assigned-spans.conf
# We leave other cases to /etc/init.d/dahdi, so
# legacy ordering can be preserved.
if [ -r "$DAHDICONFDIR/assigned-spans.conf" ]; then
dahdi_span_assignments add "/sys$DEVPATH"
else
# No configuration. No order guaranteed
dahdi_span_assignments auto "/sys$DEVPATH"
fi

View File

@@ -111,17 +111,6 @@
# Channel(s) are signalled using FXO Groundstart protocol.
# fxoks::
# Channel(s) are signalled using FXO Koolstart protocol.
# sf::
# Channel(s) are signalled using in-band single freq tone.
# Syntax as follows:
#
# channel# => sf:<rxfreq>,<rxbw>,<rxflag>,<txfreq>,<txlevel>,<txflag>
#
# rxfreq is rx tone freq in Hz, rxbw is rx notch (and decode)
# bandwith in hz (typically 10.0), rxflag is either 'normal' or
# 'inverted', txfreq is tx tone freq in hz, txlevel is tx tone
# level in dbm, txflag is either 'normal' or 'inverted'. Set
# rxfreq or txfreq to 0.0 if that tone is not desired.
#
# unused::
# No signalling is performed, each channel in the list remains idle

View File

@@ -54,7 +54,8 @@ OCT_DEFINES = \
-DcOCT6100_MAX_ECHO_CHANNELS=672 \
-DcOCT6100_MAX_MIXER_EVENTS=1344
ECHO_LOADER = echo_loader.o
ECHO_LOADER_SRC = echo_loader.c parse_span_specs.c
ECHO_LOADER = $(ECHO_LOADER_SRC:.c=.o)
endif
%.8: %
@@ -71,12 +72,33 @@ PERL_SCRIPTS = \
PERL_MANS = $(PERL_SCRIPTS:%=%.8)
XTALK_OBJS = xtalk/xtalk.o xtalk/xusb.o xtalk/xlist.o xtalk/debug.o
ASTRIBANK_OBJS = astribank_usb.o mpptalk.o $(XTALK_OBJS)
# List all our sources
XUSB_SRCS = xtalk/xusb.c xtalk/xlist.c xtalk/debug.c
XTALK_SRCS = xtalk/xtalk.c
MPPTALK_SRCS = mpptalk.c
ASTRIBANK_SRCS = astribank_usb.c
ABHEXLOAD_SRCS = astribank_hexload.c hexfile.c pic_loader.c
ABTOOL_SRCS = astribank_tool.c
ABALLOW_SRCS = astribank_allow.c astribank_license.c
ABHEXLOAD_OBJS = astribank_hexload.o hexfile.o pic_loader.o $(ECHO_LOADER) $(ASTRIBANK_OBJS) $(OCT_HERE_OBJS)
ABTOOL_OBJS = astribank_tool.o $(ASTRIBANK_OBJS)
ABALLOW_OBJS = astribank_allow.o astribank_license.o $(ASTRIBANK_OBJS)
SRCS = \
$(XUSB_SRCS) \
$(XTALK_SRCS) \
$(MPPTALK_SRCS) \
$(ASTRIBANK_SRCS) \
$(ABHEXLOAD_SRCS) \
$(ABTOOL_SRCS) \
$(ABALLOW_SRCS) \
$(ECHO_LOADER_SRC)
# Derive object files from source list
XUSB_OBJS = $(XUSB_SRCS:.c=.o)
XTALK_OBJS = $(XTALK_SRCS:.c=.o) $(XUSB_OBJS)
MPPTALK_OBJS = $(MPPTALK_SRCS:.c=.o) $(XTALK_OBJS)
ASTRIBANK_OBJS = $(ASTRIBANK_SRCS:.c=.o) $(MPPTALK_OBJS)
ABHEXLOAD_OBJS = $(ABHEXLOAD_SRCS:.c=.o) $(ASTRIBANK_OBJS) $(ECHO_LOADER) $(OCT_HERE_OBJS)
ABTOOL_OBJS = $(ABTOOL_SRCS:.c=.o) $(ASTRIBANK_OBJS)
ABALLOW_OBJS = $(ABALLOW_SRCS:.c=.o) $(ASTRIBANK_OBJS)
TARGETS = .perlcheck astribank_is_starting
PROG_INSTALL = astribank_is_starting
@@ -124,7 +146,7 @@ ifneq (,$(PERLLIBDIR))
done
endif
CFLAGS += -I. -Ixtalk
CFLAGS += -I. -Ixtalk -Wall -Werror
astribank_hexload: $(ABHEXLOAD_OBJS)
astribank_hexload: LIBS+=$(EXTRA_LIBS) $(USB_LIB)
@@ -170,8 +192,11 @@ clean:
$(RM) .depend .octasic.depend *.o xtalk/*.o $(OCT_HERE_OBJS) $(TARGETS)
.PHONY: depend
ifeq (1,$(PBX_USB))
depend: .depend
.depend: *.c *.h xtalk/*.c xtalk/*.h
@$(CC) $(CFLAGS) -MM *.c xtalk/*.c > $@ || rm -f $@
.depend: *.c *.h xtalk/*.c
@echo "Calculating dependencies"
@if ! $(CC) $(CFLAGS) $(OCT_CFLAGS) -MM $(SRCS) > $@; then $(RM) $@; exit 1; fi
include .depend
endif

View File

@@ -7,7 +7,7 @@ astribank_hexload \- Xorcom Astribank (xpp) firmware loader
.B astribank_hexload \-D \fIdevice-path\fR \-p [\fIoptions\fR] \fIhexfile1 .. hexfile4\fR
.B astribank_hexload \-D \fIdevice-path\fR \-O [-A] [\fIoptions\fR] \fIimagefile\fR
.B astribank_hexload \-D \fIdevice-path\fR \-O [-A] [-S \fIspan-specs\fR] [\fIoptions\fR] \fIimagefile\fR
.B astribank_hexload \-D \fIdevice-path\fR \-o [\fIoptions\fR]
@@ -29,7 +29,7 @@ It can be used to load either an FPGA firmware or a PIC
firmware. It is normally run by the script xpp_fxloader.
.SH OPTIONS
.B \-D
.B \-D
.I device-path
.RS
Required. The device to read from/write to. This is
@@ -95,13 +95,38 @@ use for BRI and E1. If not set, the default mu-Law (G.711u), which is
what you'd normally use for FXS, FXO and T1.
.RE
.B \-S \fIspan-specs\fR
.RS
This option should only be used when loading Octasic echo canceller firmware
and only if the first Astribank module is PRI.
Its goal is to allow specifying different \fIline-mode\fR (E1/T1/J1) in different
ports of the PRI module. \fBastribank_hexload\fR use the \fIspan-specs\fR argument
to select aLaw/uLaw for each of the PRI ports in the module.
The \fIspan-specs\fR is a list of items separated by whitespace or commas.
Each item is composed of a port selector, colon and a \fIline-mode\fR specifier.
This syntax follows the syntax of specifiers in \fB/etc/dahdi/span-types.conf\fR.
Examples:
.RS
3:E1 \- The 3'rd port is E1.
*:T1 \- Any unspecified port is T1 (wildcard match).
1:T1,2:T1,*:E1 \- First and second ports are T1, the rest are E1.
.RE
If the \fB\-S\fR is not given, the PRI default is determined by the existance of the \fB\-A-fR option.
.RE
.SH SEE ALSO
fxload(8), lsusb(8), astribank_tool(8)
.SH AUTHOR
This manual page was written by Tzafrir Cohen <tzafrir.cohen@xorcom.com> .
Permission is granted to copy, distribute and/or modify this document under
the terms of the GNU General Public License, Version 2 any
the terms of the GNU General Public License, Version 2 any
later version published by the Free Software Foundation.
On Debian systems, the complete text of the GNU General Public

View File

@@ -50,6 +50,7 @@ static void usage()
#if HAVE_OCTASIC
fprintf(stderr, "\t\t[-O] # Load Octasic firmware\n");
fprintf(stderr, "\t\t[-o] # Show Octasic version\n");
fprintf(stderr, "\t\t[-S <pri-spec>] # Set PRI type specification string\n");
#endif
fprintf(stderr, "\t\t[-F] # Load FPGA firmware\n");
fprintf(stderr, "\t\t[-p] # Load PIC firmware\n");
@@ -164,11 +165,12 @@ int main(int argc, char *argv[])
int opt_ecver = 0;
#if HAVE_OCTASIC
int opt_alaw = 0;
const char *span_spec = NULL;
#endif
int opt_dest = 0;
int opt_sum = 0;
enum dev_dest dest = DEST_NONE;
const char options[] = "vd:D:EFOopA";
const char options[] = "vd:D:EFOopAS:";
int iface_num;
int ret;
@@ -210,6 +212,9 @@ int main(int argc, char *argv[])
case 'A':
opt_alaw = 1;
break;
case 'S':
span_spec = optarg;
break;
#endif
case 'p':
opt_pic = 1;
@@ -290,7 +295,7 @@ int main(int argc, char *argv[])
}
#if HAVE_OCTASIC
} else if (opt_echo) {
if((ret = load_echo(astribank, argv[optind], opt_alaw)) < 0) {
if((ret = load_echo(astribank, argv[optind], opt_alaw, span_spec)) < 0) {
ERR("%s: Loading ECHO's failed\n", devpath);
return 1;
}

View File

@@ -35,12 +35,17 @@ my %opts;
getopts('vRs:', \%opts) || usage;
my $dahdi_autoreg = check_param('/sys/module/xpp/parameters/dahdi_autoreg') eq 'Y';
my $auto_assign_spans = check_param('/sys/module/dahdi/parameters/auto_assign_spans') eq '1';
my $auto_assign_spans = check_param('/sys/module/dahdi/parameters/auto_assign_spans') ne '0';
my $assigned_spans_config = $ENV{'ASSIGNED_SPANS_CONF_FILE'} || '/etc/dahdi/assigned-spans.conf';
my $span_types_config = $ENV{'SPAN_TYPES_CONF_FILE'} || '/etc/dahdi/span-types.conf';
my $have_assigned_spans_config = -f $assigned_spans_config || 0;
my $have_span_types_config = -f $span_types_config || 0;
# Spans will be auto-assigned by default if either:
# - Driver $auto_assign_spans them or
# - Udev script see that we $have_span_types_config and it "add" them
my $default_auto_assign = $auto_assign_spans || $have_assigned_spans_config;
my $sorter;
my $sort_order = $opts{'s'};
if(defined $sort_order) {
@@ -69,8 +74,6 @@ if(defined($on)) { # Translate to booleans
$should_output = 0 unless $verbose;
}
undef $on if $dahdi_autoreg and not $opts{'R'};
sub state2str($) {
return (shift)?"on":"off";
}
@@ -79,35 +82,41 @@ sub myprintf {
printf @_ if $should_output;
}
my @spans = Dahdi::spans;
foreach my $xbus (Dahdi::Xpp::xbuses($sorter)) {
myprintf "%-10s\t%3s-%s\t%s\n",
$xbus->name, $xbus->xpporder, $xbus->label, $xbus->connector;
next unless $xbus->status eq 'CONNECTED';
foreach my $xpd (Dahdi::Xpp::Xpd::telephony_devs($xbus->xpds())) {
my $prev = $xpd->dahdi_registration($on);
if(!defined($prev)) { # Failure
printf "%s: Failed %s\n", $xpd->fqn, $!;
next;
}
myprintf "\t%-10s: ", $xpd->fqn;
if(!defined($on)) { # Query only
my ($span) = grep { $_->name eq $xpd->fqn } @spans;
my $spanstr = ($span) ? ("Span " . $span->num) : "";
myprintf "%s %s\n", state2str($prev), $spanstr ;
next;
}
myprintf "%3s ==> %3s\n", state2str($prev), state2str($on);
my $prev = $xbus->dahdi_registration($on);
if(!defined($prev)) { # Failure
printf STDERR "%s: Failed %s\n", $xbus->name, $!;
next;
}
if (defined($on) && $on && ! $have_assigned_spans_config && ! $auto_assign_spans) {
# Emulate /etc/dahdi/assigned-spans.conf:
# - We iterate over $xbus according to /etc/dahdi/xpp_order
# - We "auto" assign all spans of current $xbus
my $devpath = sprintf "/sys/bus/dahdi_devices/devices/astribanks:xbus-%02d", $xbus->num;
my @cmd = ('dahdi_span_assignments', 'auto', $devpath);
system @cmd;
warn "Failed '@cmd' (status=$?)\n" if $?;
my $reg_str;
if (defined $on) {
$reg_str = ($on) ? "registering" : "unregistering";
} else {
$reg_str = ($prev) ? "registered" : "unregistered";
}
myprintf "%-10s\t%3s-%s\t%s (%s)\n",
$xbus->name, $xbus->xpporder, $xbus->label, $xbus->connector,
$reg_str;
next unless $xbus->status eq 'CONNECTED';
# Only assign if no default assignment, or forced by '-R' option
if (defined($on) && $on) {
if ($opts{'R'} || ! $default_auto_assign) {
# Emulate /etc/dahdi/assigned-spans.conf:
# - We iterate over $xbus according to /etc/dahdi/xpp_order
# - We "auto" assign all spans of current $xbus
my $devpath = sprintf "/sys/bus/dahdi_devices/devices/astribanks:xbus-%02d", $xbus->num;
my @cmd = ('dahdi_span_assignments', 'auto', $devpath);
system @cmd;
warn "Failed '@cmd' (status=$?)\n" if $?;
}
# wait for UDEV to do its stuff
system "dahdi_waitfor_span_assignments assigned";
}
foreach my $xpd (Dahdi::Xpp::Xpd::telephony_devs($xbus->xpds())) {
my $spanno = $xpd->xpd_getattr('span');
myprintf "\t%-10s: ", $xpd->fqn;
my $spanstr = ($spanno) ? ("Span " . $spanno) : "unassigned";
myprintf "%s\n", $spanstr ;
}
}
myprintf "# Sorted: $sort_order\n" if defined $sort_order;

View File

@@ -31,6 +31,7 @@
#include "echo_loader.h"
#include "debug.h"
#include <oct6100api/oct6100_api.h>
#include "parse_span_specs.h"
#define DBG_MASK 0x03
#define TIMEOUT 1000
@@ -362,7 +363,7 @@ int load_file(char *filename, unsigned char **ppBuf, UINT32 *pLen)
DBG("Loading %s file...\n", filename);
pFile = fopen(filename, "rb");
if (pFile == NULL) {
ERR("fopen\n");
ERR("fopen: %s\n", strerror(errno));
return -ENODEV;
}
@@ -378,7 +379,11 @@ int load_file(char *filename, unsigned char **ppBuf, UINT32 *pLen)
} else {
DBG("allocated mem for pbyFileData\n");
}
fread(pbyFileData, 1, *pLen, pFile);
if (fread(pbyFileData, 1, *pLen, pFile) != *pLen) {
fclose(pFile);
ERR("fread: %s\n", strerror(errno));
return -ENODEV;
}
fclose(pFile);
DBG("Successful loading %s file into memory "
"(size = %d, DUMP: first = %02X %02X, last = %02X %02X)\n",
@@ -556,7 +561,7 @@ inline int get_ver(struct astribank_device *astribank)
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
UINT32 init_octasic(char *filename, struct astribank_device *astribank, int is_alaw)
UINT32 init_octasic(char *filename, struct astribank_device *astribank, struct span_specs *span_specs)
{
int cpld_ver;
struct echo_mod *echo_mod;
@@ -576,6 +581,8 @@ UINT32 init_octasic(char *filename, struct astribank_device *astribank, int is_a
/* Channel resources.*/
tOCT6100_CHANNEL_OPEN ChannelOpen;
UINT32 ulChanHndl;
enum tdm_codec tdm_codec;
int spanno;
if (test_send(astribank) < 0)
return cOCT6100_ERR_FATAL;
@@ -725,7 +732,17 @@ UINT32 init_octasic(char *filename, struct astribank_device *astribank, int is_a
/* Set the channel to work at the echo cancellation mode.*/
ChannelOpen.ulEchoOperationMode = cOCT6100_ECHO_OP_MODE_NORMAL;
pcmLaw = (is_alaw ? cOCT6100_PCM_A_LAW: cOCT6100_PCM_U_LAW);
spanno = nChan % 4;
assert(spanno >= 0 && spanno < MAX_SPANNO);
tdm_codec = span_specs->span_is_alaw[spanno];
if (tdm_codec == TDM_CODEC_UNKNOWN) {
AB_ERR(astribank, "Calculated bad alaw/ulaw on channel %d\n", nChan);
return cOCT6100_ERR_FATAL;
}
if (nChan < 4)
AB_INFO(astribank, "ECHO PRI port %d = %s\n", spanno+1, (tdm_codec == TDM_CODEC_ALAW) ? "alaw" : "ulaw");
pcmLaw = ((tdm_codec == TDM_CODEC_ALAW) ? cOCT6100_PCM_A_LAW: cOCT6100_PCM_U_LAW);
/* Configure the TDM interface.*/
ChannelOpen.TdmConfig.ulRinPcmLaw = pcmLaw;
@@ -821,15 +838,22 @@ UINT32 init_octasic(char *filename, struct astribank_device *astribank, int is_a
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int load_echo(struct astribank_device *astribank, char *filename, int is_alaw)
int load_echo(struct astribank_device *astribank, char *filename, int default_is_alaw, const char *span_spec)
{
int ret;
UINT32 octasic_status;
struct span_specs *span_specs;
AB_INFO(astribank, "Loading ECHOCAN Firmware: %s (%s)\n",
filename, (is_alaw) ? "alaw" : "ulaw");
span_specs = parse_span_specifications(span_spec, default_is_alaw);
if (!span_specs) {
AB_ERR(astribank, "ECHO parsing span specs failed\n");
return -EFAULT;
}
AB_INFO(astribank, "Loading ECHOCAN Firmware: %s (default %s)\n",
filename, (default_is_alaw) ? "alaw" : "ulaw");
usb_buffer_init(astribank, &usb_buffer);
octasic_status = init_octasic(filename, astribank, is_alaw);
octasic_status = init_octasic(filename, astribank, span_specs);
free_span_specifications(span_specs);
if (octasic_status != cOCT6100_ERR_OK) {
AB_ERR(astribank, "ECHO %s burning failed (%08X)\n",
filename, octasic_status);

View File

@@ -26,7 +26,7 @@
#include "astribank_usb.h"
int spi_send(struct astribank_device *astribank, uint16_t addr, uint16_t data, int recv_answer, int ver);
int load_echo(struct astribank_device *astribank, char *filename, int is_alaw);
int load_echo(struct astribank_device *astribank, char *filename, int is_alaw, const char *span_spec);
int echo_ver(struct astribank_device *astribank);
#endif /* ECHO_LOADER_H */

152
xpp/parse_span_specs.c Normal file
View File

@@ -0,0 +1,152 @@
/*
* Written by Oron Peled <oron@actcom.co.il>
* Copyright (C) 2014, Xorcom
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <regex.h>
#include <fnmatch.h>
#include <sys/time.h>
#include "parse_span_specs.h"
void free_span_specifications(struct span_specs *span_specs)
{
if (span_specs) {
if (span_specs->buf)
free(span_specs->buf);
free(span_specs);
}
}
static enum tdm_codec is_alaw_span_type(const char *span_type)
{
assert(span_type);
if (strcmp(span_type, "E1") == 0)
return TDM_CODEC_ALAW;
else if (strcmp(span_type, "T1") == 0)
return TDM_CODEC_ULAW;
return TDM_CODEC_UNKNOWN;
}
struct span_specs *parse_span_specifications(const char *spec_string, int default_is_alaw)
{
struct span_specs *span_specs;
char *p;
int spanno;
int i;
if (!spec_string)
return NULL;
/* Allocate and Initialize */
span_specs = calloc(sizeof(char *), MAX_SPANNO);
if (!span_specs)
goto err;
for (spanno = 0; spanno < MAX_SPANNO; spanno++)
span_specs->span_is_alaw[spanno] = TDM_CODEC_UNKNOWN;
span_specs->buf = strdup(spec_string);
if (!span_specs->buf)
goto err;
for (i = 0;; i++) {
char *curr_item;
char *tokenize_key;
char *key;
char *value;
enum tdm_codec is_alaw;
int matched;
/* Split to items */
p = (i == 0) ? span_specs->buf : NULL;
p = strtok_r(p, " \t,", &curr_item);
if (!p)
break;
/* Split to <span>:<type> */
key = strtok_r(p, ":", &tokenize_key);
if (!key) {
fprintf(stderr,
"Missing ':' (item #%d inside '%s')\n",
i+1, spec_string);
goto err;
}
value = strtok_r(NULL, ":", &tokenize_key);
if (!value) {
fprintf(stderr,
"Missing value after ':' (item #%d inside '%s')\n",
i+1, spec_string);
goto err;
}
/* Match span specification and set alaw/ulaw */
is_alaw = is_alaw_span_type(value);
if (is_alaw == TDM_CODEC_UNKNOWN) {
fprintf(stderr,
"Illegal span type '%s' (item #%d inside '%s')\n",
value, i+1, spec_string);
goto err;
}
matched = 0;
for (spanno = 0; spanno < MAX_SPANNO; spanno++) {
char tmpbuf[BUFSIZ];
snprintf(tmpbuf, sizeof(tmpbuf), "%d", spanno + 1);
if (fnmatch(p, tmpbuf, 0) == 0) {
matched++;
span_specs->span_is_alaw[spanno] = is_alaw;
}
}
if (!matched) {
fprintf(stderr,
"Span specification '%s' does not match any span (item #%d inside '%s')\n",
key, i+1, spec_string);
goto err;
}
}
/* Set defaults */
for (spanno = 0; spanno < MAX_SPANNO; spanno++) {
if (span_specs->span_is_alaw[spanno] == TDM_CODEC_UNKNOWN) {
span_specs->span_is_alaw[spanno] = default_is_alaw;
}
}
return span_specs;
err:
free_span_specifications(span_specs);
return NULL;
}
void print_span_specifications(struct span_specs *span_specs, FILE *output)
{
int spanno;
if (!span_specs)
return;
for (spanno = 0; spanno < MAX_SPANNO; spanno++) {
enum tdm_codec is_alaw;
is_alaw = span_specs->span_is_alaw[spanno];
fprintf(output, "%d %s\n",
spanno+1, (is_alaw == TDM_CODEC_ALAW) ? "alaw" : "ulaw");
}
}

43
xpp/parse_span_specs.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef PARSE_SPAN_SPECS_H
#define PARSE_SPAN_SPECS_H
/*
* Written by Oron Peled <oron@actcom.co.il>
* Copyright (C) 2014, Xorcom
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#define MAX_SPANNO 4 /* E1/T1 spans -- always in first unit. 1-based */
enum tdm_codec {
TDM_CODEC_UNKNOWN,
TDM_CODEC_ULAW,
TDM_CODEC_ALAW,
};
struct span_specs {
char *buf;
enum tdm_codec span_is_alaw[MAX_SPANNO];
};
struct span_specs *parse_span_specifications(const char *spec_string, int default_is_alaw);
void free_span_specifications(struct span_specs *span_specs);
void print_span_specifications(struct span_specs *span_specs, FILE *output);
#endif /* PARSE_SPAN_SPECS_H */

View File

@@ -30,16 +30,21 @@ sub generate($$$) {
return if $?;
my $line_mode = $genopts->{'line-mode'};
$line_mode = 'E1' unless defined $line_mode;
$line_mode =~ /^[ETJ]1$/ or die "Bad line-mode='$line_mode'\n";
warn "Empty configuration -- no spans\n" unless @spans;
my $cmd;
if (defined $line_mode) {
$line_mode =~ /^[ETJ]1$/ or die "Bad line-mode='$line_mode'\n";
$cmd = "dahdi_span_types --line-mode=$line_mode dumpconfig > $file";
printf("Generating $file (with default line-mode %s)\n", $line_mode)
if $genopts->{verbose};
} else {
$cmd = "dahdi_span_types dumpconfig > $file";
printf("Generating $file (no --line-mode override)\n")
if $genopts->{verbose};
}
rename "$file", "$file.bak"
or $! == 2 # ENOENT (No dependency on Errno.pm)
or die "Failed to backup old config: $!\n";
#$gconfig->dump;
printf("Generating $file (with default line-mode %s)\n", $line_mode)
if $genopts->{verbose};
my $cmd = "dahdi_span_types --line-mode=$line_mode dumpconfig > $file";
system $cmd;
die "Command failed (status=$?): '$cmd'" if $?;
}

View File

@@ -146,6 +146,40 @@ sub new($$) {
return $self;
}
sub dahdi_registration($$) {
my $xbus = shift;
my $on = shift;
my $result;
my $file = sprintf("%s/dahdi_registration", $xbus->sysfs_dir);
# Handle old drivers without dahdi_registration xbus attribute
if (! -f $file) {
warn "Old xpp driver without dahdi_registration support. Emulating it using xpd/span support\n";
my @xpds = sort { $a->id <=> $b->id } $xbus->xpds();
my $prev;
foreach my $xpd (@xpds) {
$prev = $xpd->dahdi_registration($on);
}
return $prev;
}
# First query
open(F, "$file") or die "Failed to open $file for reading: $!";
$result = <F>;
chomp $result;
close F;
if(defined($on) and $on ne $result) { # Now change
open(F, ">$file") or die "Failed to open $file for writing: $!";
print F ($on)?"1":"0";
if(!close(F)) {
if($! == 17) { # EEXISTS
# good
} else {
undef $result;
}
}
}
return $result;
}
sub pretty_xpds($) {
my $xbus = shift;
my @xpds = sort { $a->id <=> $b->id } $xbus->xpds();

View File

@@ -41,18 +41,25 @@ ab_list() {
}
ab_serial_nums() {
ab_list | \
sed 's,$,/serial,' | \
xargs grep -H '' 2>/dev/null | \
sed 's,.*/serial:,,' | \
sed 's/^$/NO-SERIAL/' | \
sort -u
for i in `ab_list`; do
s=`cat "$i/serial" 2>/dev/null` || :
if [ "$s" = '' ]; then
echo "NO-SERIAL"
else
echo "$s"
fi
done | sort -u || :
}
detected_serial_nums() {
cat /sys/bus/astribanks/devices/*/transport/serial 2> /dev/null | \
sed 's/^$/NO-SERIAL/' | \
sort -u || :
for i in /sys/bus/astribanks/devices/*/transport; do
s=`cat "$i/serial" 2>/dev/null` || :
if [ "$s" = '' ]; then
echo "NO-SERIAL"
else
echo "$s"
fi
done | sort -u || :
}
calc_union() {
@@ -72,6 +79,10 @@ waitfor_ab_initialization() {
fi
test "$oldab" != "$ab"
do
if [ "$ab" = '' ]; then
echo >&2 "Astribanks disappeared"
break
fi
oldab="$ab"
cat $ab
#echo -n 1>&2 "_"
@@ -94,6 +105,14 @@ if ! astribank_is_starting; then
exit 0
fi
# Sanity check
for i in `ab_list`; do
s=`cat "$i/serial" 2>/dev/null` || :
if [ "$s" = '' ]; then
echo >&2 "WARNING! Astribank without serial number: $i"
fi
done
serial_nums=`ab_serial_nums`
# Loop until detected (hopefully) all astribanks and they are initialized

View File

@@ -68,6 +68,7 @@ FIRMWARE_DIR="${FIRMWARE_DIR:-/usr/share/dahdi}"
ASTRIBANK_HEXLOAD=${ASTRIBANK_HEXLOAD:-/usr/sbin/astribank_hexload}
ASTRIBANK_TOOL=${ASTRIBANK_TOOL:-/usr/sbin/astribank_tool}
XPP_CONFIG="${XPP_CONFIG:-/etc/dahdi/xpp.conf}"
SPAN_TYPES_CONFIG="${SPAN_TYPES_CONFIG:-/etc/dahdi/span-types.conf}"
XPP_UDEV_SLEEP_TIME="${XPP_UDEV_SLEEP_TIME:-15}"
USB_RECOV="${USB_RECOV:-USB_RECOV.hex}"
@@ -270,6 +271,15 @@ usb_firmware_all_devices() {
wait_renumeration $numdevs 'e4e4/11[3456]1/*' "usb_firmware_all_devices"
}
filter_span_types() {
l="$1"
sed < "$SPAN_TYPES_CONFIG" 2>/dev/null \
-e 's/#.*//' \
-e 's/[ \t]*$//' \
-e 's/^[ \t]*//' \
-e '/^$/d' | awk -vlabel="$l" '$1 == label { print $2 }' | tr -s ', \t\n' ','
}
load_fw_device() {
dev="$1"
fw="$2"
@@ -279,33 +289,61 @@ load_fw_device() {
FPGA_1161*.hex)
echo_file="$FIRMWARE_DIR/OCT6104E-256D.ima"
law=''
law_str='uLaw'
dev_short=`echo "$dev" | sed -e 's,.*/usb/*,,'`
abtool_output=`$ASTRIBANK_TOOL -D "$dev" -Q 2>&1`
ec_card_type=`echo "$abtool_output" | grep 'CARD 4' | sed -e 's/.*type=//' -e 's/\..*//'`
caps_num=`echo "$abtool_output" | grep 'ECHO ports' | sed -e 's/.*: *//'`
if [ "$ec_card_type" = '5' ]; then
debug "ECHO burning into $dev: $echo_file"
debug "ECHO($dev_short): Firmware $echo_file"
card_type=`echo "$abtool_output" | grep 'CARD 0' | sed -e 's/.*type=//' -e 's/\..*//'`
case "$card_type" in
3) law="-A";;
4)
pri_protocol=''
if [ -r "$XPP_CONFIG" ]; then
pri_protocol=`awk '/^pri_protocol/ {print $2}' $XPP_CONFIG`
dev_lsusb=`echo "$dev_short" | tr '/' ':'`
# Try modern configuration
if [ -r "$SPAN_TYPES_CONFIG" ]; then
# Try exact match by label
label=`lsusb -s "$dev_lsusb" -v 2>/dev/null | awk '$1 == "iSerial" && $2 == 3 { print $3 }'`
if [ "$label" != '' ]; then
label="usb:$label"
debug "ECHO($dev_short): Search span-types.conf for [$label]"
pri_spec=`filter_span_types "${label}"`
if [ "$pri_spec" != '' ]; then
debug "ECHO($dev_short): Found definitions for [$label] -- '$pri_spec'"
fi
else
debug "ECHO($dev_short): Device without a label"
fi
# Check wildcard match
pri_spec_wildcard=`filter_span_types '*'`
if [ "$pri_spec_wildcard" != '' ]; then
debug "ECHO($dev_short): Found definitions for wildcard -- $pri_spec_wildcard"
fi
pri_spec=`echo "$pri_spec_wildcard $pri_spec" | tr -s ' \t\n' ','`
if [ "$pri_spec" != '' ]; then
pri_spec_params="-S $pri_spec"
debug "ECHO($dev_short): pri_spec_params='$pri_spec_params'"
fi
fi
# "E1" or empty (implied E1) means aLaw
if [ "$pri_protocol" != 'T1' ]; then
law='-A'
# Fallback to legacy xpp.conf
default_pri_protocol=''
default_law=''
if [ -r "$XPP_CONFIG" ]; then
default_pri_protocol=`awk '/^pri_protocol/ {print $2}' $XPP_CONFIG`
if [ "$default_pri_protocol" != '' ]; then
debug "ECHO($dev_short): Found legacy xpp.conf setting -- $default_pri_protocol"
# "E1" or empty (implied E1) means aLaw
if [ "$default_pri_protocol" != 'T1' ]; then
default_law='-A'
fi
fi
fi
;;
esac
if [ "$law" = '-A' ]; then
law_str="aLaw"
fi
caps_num=`echo "$abtool_output" | grep 'ECHO ports' | sed -e 's/.*: *//'`
debug "ECHO: 1st module is $law_str, $caps_num channels allowed."
debug "ECHO($dev_short): $caps_num channels allowed."
if [ "$caps_num" != '0' ]; then
run_astribank_hexload -D "$dev" -O $law "$echo_file"
run_astribank_hexload -D "$dev" -O $default_law $pri_spec_params "$echo_file"
else
echo "WARNING: ECHO burning was skipped (no capabilities)"
fi

View File

@@ -61,6 +61,21 @@ struct xusb {
static void xusb_init();
/*
* XTALK_OPTIONS:
* A white-space separated list of options, read from the environment
* variable of that name. Existing options:
*
* - "use-clear-halt" -- force USB "clear_halt" operation during
* device initialization
* - "no-lock" -- prevent using global sempahore to serialize libusb
* initialization. Previously done via "XUSB_NOLOCK"
* environment variable.
*/
int xtalk_parse_options(void);
int xtalk_option_use_clear_halt(void);
int xtalk_option_no_lock(void);
void xusb_init_spec(struct xusb_spec *spec, char *name,
uint16_t vendor_id, uint16_t product_id,
int nifaces, int iface, int nep, int ep_out, int ep_in)
@@ -257,13 +272,16 @@ int xusb_claim_interface(struct xusb *xusb)
xusb->iProduct,
xusb->iSerialNumber,
xusb->iInterface);
if (usb_clear_halt(xusb->handle, EP_OUT(xusb)) != 0) {
ERR("Clearing output endpoint: %s\n", usb_strerror());
return 0;
}
if (usb_clear_halt(xusb->handle, EP_IN(xusb)) != 0) {
ERR("Clearing input endpoint: %s\n", usb_strerror());
return 0;
if (xtalk_option_use_clear_halt()) {
DBG("Using clear_halt()\n");
if (usb_clear_halt(xusb->handle, EP_OUT(xusb)) != 0) {
ERR("Clearing output endpoint: %s\n", usb_strerror());
return 0;
}
if (usb_clear_halt(xusb->handle, EP_IN(xusb)) != 0) {
ERR("Clearing input endpoint: %s\n", usb_strerror());
return 0;
}
}
ret = xusb_flushread(xusb);
if (ret < 0) {
@@ -857,13 +875,63 @@ static int initizalized;
static void xusb_init()
{
if (!initizalized) {
if (!getenv("XUSB_NOLOCK"))
xtalk_parse_options();
if (!xtalk_option_no_lock())
xusb_lock_usb();
usb_init();
usb_find_busses();
usb_find_devices();
initizalized = 1;
if (!getenv("XUSB_NOLOCK"))
if (!xtalk_option_no_lock())
xusb_unlock_usb();
}
}
/* XTALK option handling */
static int use_clear_halt = 0;
static int libusb_no_lock = 0;
static int xtalk_one_option(const char *option_string)
{
if (strcmp(option_string, "use-clear-halt") == 0) {
use_clear_halt = 1;
return 0;
}
if (strcmp(option_string, "no-lock") == 0) {
libusb_no_lock = 1;
return 0;
}
ERR("Unknown XTALK_OPTIONS content: '%s'\n", option_string);
return -EINVAL;
}
int xtalk_option_use_clear_halt(void)
{
return use_clear_halt;
}
int xtalk_option_no_lock(void)
{
return libusb_no_lock;
}
int xtalk_parse_options(void)
{
char *xtalk_options;
char *saveptr;
char *token;
int ret;
xtalk_options = getenv("XTALK_OPTIONS");
if (!xtalk_options)
return 0;
token = strtok_r(xtalk_options, " \t", &saveptr);
while (token) {
ret = xtalk_one_option(token);
if (ret < 0)
return ret;
token = strtok_r(NULL, " \t", &saveptr);
}
return 0;
}