Fixes:
src/ftmod/ftmod_misdn/ftmod_misdn.c: In function 'misdn_handle_mph_information_ind':
src/ftmod/ftmod_misdn/ftmod_misdn.c:871:3: error: format '%lx' expects argument of type 'long unsigned int', but argument 13 has type 'uint64_t' [-Werror=format]
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Do a "soft" wraparound with modulo, removes the ~0.5s tone glitch.
(Multiply ts.rate (samples) by two to match the offset unit (bytes, 2 per sample).)
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Store the offset in the teletone buffer in the b-channel private data.
An NT-mode setup with ftmod_misdn showed severe (dial-)tone distortions
in a sound editor (330Hz sine wave phase errors), caused by
using a global teletone buffer offset.
Switching to a per-channel offset, that is advanced by the amount
of data actually written to the channel, removes (almost) all
distortions.
There is still a minimal phase error every ~500ms (audible) that
needs more investigating.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Might as well import these too...
ftdm_offset_of() - Get offset of member in structure.
ftdm_container_of() - Get pointer to enclosing structure from pointer to structure member.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
ftdm_min(x,y) - Returns the smaller of the two values x and y.
ftdm_max(x,y) - Returns the larger of the two values x and y.
ftdm_clamp(val, min, max) - Returns value that is in the range [vmin,vmax].
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Remove the 'state' variable of per-channel data, use active flag exclusively to track
open/close state.
Add misdn_activate_channel()/misdn_deactivate_channel() helper functions, rename old
one to _misdn_toggle_channel() (internal).
Add _nowait variant of channel de-/activation function, that just sends the mISDN request message.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Store call CRV in caller_data.call_reference and use call private to hold the
FreeTDM channel object.
Remove isdn_data->channels_{local,remote,outbound}_crv arrays.
Allow (and force) inbound call state transition DIALTONE -> DOWN for
incoming RELEASE COMPLETE messages in NT mode.
Dialtone in NT mode works, everything else needs more testing.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
ftmod_misdn currently returns len == 0 if the incoming message,
that triggered the read() call, does not contain any data.
Users of ftdm_channel_read() need to handle this case, or they
may possibly end up in an endless loop.
This patch reworks the ftdm_channel_read() handling in ftmod_isdn
and prevents it from entering an endless loop. The read error counter
is reset on first sucessful read w/ data.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
cc1: warnings being treated as errors
./src/ftmod/ftmod_libpri/ftmod_libpri.c: In function 'msn_filter_foreach':
./src/ftmod/ftmod_libpri/ftmod_libpri.c:422: warning: dereferencing type-punned pointer will break strict-aliasing rules
make: *** [ftmod_libpri_la-ftmod_libpri.lo] Error 1
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Two fixes:
Use ftdm_set_string() instead of sprintf() (seriously, wtf?).
Drop invalid, needless argument to ftdm_log().
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Neither of them accepts extra arguments and ftmod_sangoma_isdn is calling
ftmod_assert() with a char * msg argument.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
The format string checks already caught a couple crash-worthy bugs and this
commit fixes a couple more.
Also includes __ftdm_check_scanf(), for completeness (currently unused).
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Output the current trunk_type in "add X-channel vs. trunk_type" error messages and
check this for B-/D-channels too.
ISDN (= digital) spans need to have a trunk_type set before adding channels,
bail out early with an error message (actually two) if this is not the case.
(Adding channels should really be moved out of the parsing loop, to catch
certain types of errors easier.)
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Some I/O implementations (e.g. mISDN) need this information to correctly
set up the port configuration. In FreeTDM, the mode of a span has been.
up until now, a part of the signalling module configuration ("node" or "mode"
for libpri and isdn spans), which is parsed _after_ the I/O part of a span
has been initialized. This limitation currently prevents us from using mISDN
in NT mode.
To work around this problem (without adding a lot of new tunk_type values like "E1_NET" etc.),
add a new "trunk_mode" parameter to the span categories in freetdm.conf, which by default
is "CPE" for all trunk types, except "FXS" (which defaults to "NET").
ftmod_misdn uses trunk_type + trunk_mode to correctly choose the d-channel protocol
for a port.
ftmod_libpri uses trunk_mode as a hint for the default "mode" setting.
(NOTE: It will print a warning if trunk_mode and signalling mode do not match.)
All other modules currently ignore the value of trunk_mode.
Example freetdm.conf snippet for a mISDN span in NET/NT mode
(using a HFC-S USB dongle):
[span misdn MBRI_1]
trunk_type => BRI_PTMP
trunk_mode => NET
b-channel => HFC-S_USB.1:1-2
d-channel => HFC-S_USB.1:3
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Portability fix for uClibc and other (linux) environments that lack execinfo.h.
ftdm_backtrace_walk() and related return FTDM_NOTIMPL and print a message
if backtraces are not available in the current environment.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Indicator in IAM message.
- ss7_iam_nature_connection_hex is the channel variable to carry
HEX value from/to IAM message
- X-FreeTDM-IAM-NATURE-CONN-HEX is the x-header string to carry
HEX value from/to sip invite message
- This IE is 8 bit hex, which turns into 2 chars
- Only Satellite indicator, Continuity check indicator, and Echo
control device indicator are supported. Spare value are not taken.
Spare value is always set to all zero.
- example:
To set 00010101 (bit H-A), set X-FreeTDM-IAM-NATURE-CONN-HEX string
value to 15 in the sip invite message to NSG.
When NSG send out sip invite, if the incoming IAM message comes with
Nature of Connection IE, NSG will put X-FreeTDM-IAM-NATURE-CONN-HEX
in the invite x-header. For example, if the IE value is 00001010 in
the IAM, NSG will send X-FreeTDM-IAM-NATURE-CONN-HEX with value string
of "0A".
- Two characters are madatory. "0A" must be specified rather than "A". If
invalid format or characters are found, this x-header will be ommited.
- Valid characters include 0-9, A-F, and a-f
This feature allows ftmod_libpri to ignore calls with non-matching destination number.
You may want to use this on BRI PTMP lines (Point-to-MultiPoint),
to avoid conflicts between your FreeSWITCH server and other devices connected to the line.
The filter is disabled by default (all calls will be accepted),
setting one (or more) "local-number" parameters on the span configuration enables it.
Example configuration snippet:
<libpri_spans>
<span name="example01">
<!-- ... other span settings omitted ... -->
<param name="local-number" value="123456"/>
<param name="local-number" value="654321"/>
</span>
</libpri_spans>
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Read the forward call indicator IE and print it into channel variable
ss7_iam_fwd_ind_hex. If this variable exists, put it in the x-header.
This implementation takes bits of A, CB, D, E, F, HG, I from the hex
value. Bits of KJ, L, P-M are not taken and set to 0.
The hex value is H-A-P-I, H is the highest bit to A, and next is P-I.
I is the lowest bit in the whole field, and H is the highest bit in
the whole field. Refer to Q.763 chapter 3.23.
IE's heximal value.
- add <action application="export" data="freetdm_iam_fwd_ind_HEX=2301"/>
to dialplan with expected hex value. If the outgoing ftdm channel's
forward indicator needs to be changed, "export" needs to be put in the
incoming channel's dialplan to set this variable value accordingly.
- this implementation takes bits of A, CB, D, E, F, HG, I from the hex
value. Bits of KJ, L, P-M are not taken from the hex.
- How to calculate hex value with wanted bits:
. the hex value is H-A-P-I, H is the highest bit to A, and next is P-I.
I is the lowest bit in the whole field, and H is the highest bit in
the whole field. Refer to Q.763 chapter 3.23.
. use a text pad to fill in the bits with 0 and 1. eventually fill all
the 16 bits
. copy the binary value into a calculator and convert it to hex
native bridge mode
- This is supposed to be included in commit of
b324f86797. Somehow it's
not included in that commit. Without this change, the
REL receiving leg always stay in TERMINATING state when
received an incoming REL message.
Non-PRI_NEW_SET_API logging callbacks were only available in libpri-1.0 and older,
which also lacks PRI_IO_FUNCS (required) and wouldn't work anyway.
Explicitly check for both PRI_* feature defines at configure time and reject libpri
versions that lack them.
Remove the non-PRI_NEW_SET_API logging callbacks in ftmod_libpri.c.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Use the PRI_NEW_SET_API define provided by >=libpri-1.2 to distinguish
between old style and new style pri_set_error() and pri_set_message()
callback functions.
Improve message logging by using ftdm_log_chan() if per-span
data with a valid (d-)channel object is available.
NOTE: pri_get_userdata() returns NULL if pri is NULL.
This will reduce the horizontal space for libpri output a bit, but allows
us to see which span the message/error came from.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
is down and recovered later
To re-produce this bug:
1. do CGB on one side
2. unplug signaling link cable
3. plug signaling link cable back
4. do CGU on the blocking side
5. cic state stay in RESTART for ever
Fix this problem by sending cic to SUSPENDED state after
receiving/sending CGU message
Timer-based b-channel tx gating won't work anyway, so remove all those
"#if 0"-ed bits of cruft.
Also remove the mISDN-specific timerfd_create() check in configure.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
- When NSG receives INR from network, send back INF with calling
party category information IE and calling number information IE.
- Introduced a new global setting of "force-inr" for testing
purpose. Stinga generated INR/INF packets are not acceptable by
trillium stack since it misses call related information in the
packets. If configure force-inr to true in freetdm.conf.xml, when
NSG receives an incoming IAM, it'll send out INR packet regardless
of incoming IAM's IEs, and keep waiting for INF response from the
calling side.
- T.39 timer is introduced in order to handle INR timeout. The
default value of T.39 is 12 seconds and is configurable according
to spec.
- Only supports calling number IE and calling party category IE in
current fix. The customer only needs the calling number IE right now.
In ISUP spec, there are 6 optional IEs. NSG only supports calling
party number and calling category information IE since the other
IEs are not configurable in freetdm.conf.xml or included in IAM
message.
- In collect state, INR/INF implementation needs to work with existed
SAM messages. If NSG sent out INR and wait for SAM, collect state
check both INF received and enough dialed numbers received. If one
of these conditions are not met, it'll stay in collect state and wait
until either conditions met or timeout. After received INF and enough
dailed number, state moves to dailing and proceed as regular calls.
resource-cleanup responsibilities clearly between the 2 channels involved in the bridge
- Each channel is responsible for clearning its own peer_data and event queue
at the end of the call (when moving to DOWN state)
- Each channel dequeues messages only from its own queue and enqueues messages
in the peer's queue, with the only exception being messages received before
the bridge is stablished (IAM for sure and possible SAM messages) because
if the bridge is not yet stablished the messages must be queued by the channel
in its own queue temporarily until the bridge is ready
- When the bridge is ready it is the responsibility of the incoming channel to
move the messages that stored temporarily in its own queue to the bridged peer queue
- During hangup, each channel is responsible for moving itself to DOWN. The procedure
however differs slightly depending on the hangup conditions
If the user requests hangup (ie, FreeSWITCH) the request will be noted by setting the
FTDM_CHANNEL_USER_HANGUP flag but will not be processed yet because call control is
driven only by the link messages (so no hangup from ESL or command line allowed)
When REL message comes, the channel receiving it must move to TERMINATING state and:
- If the user has not hangup yet (FTDM_CHANNEL_USER_HANGUP flag not set) then
notify the user via SIGEVENT_STOP and wait for the user to move to HANGUP
state by calling ftdm_channel_call_hangup() before sending RLC
- If the user did hangup already (FTDM_CHANNEL_USER_HANGUP flag is set) then
skip user notification and move to HANGUP state directly where the RLC message
will be sent
- On HANGUP state the RLC is sent and the channel is moved to DOWN, final state
The peer channel will forward the REL message and wait for RLC from the network, when
RLC is received the channel can move straight to DOWN itself because the peer channel
is completing its own shutdown procedure when it received the REL message
This fixes an issue where ss7 native bridge was accidentally enabled
any time two freetdm channels were bridged regardless of the freetdm_native_sigbridge
variable value.
Use the amount of audio data received in misdn_read() to determine how many
bytes we need to send to the b-channel (= how much free space is left
in the b-channel tx queue). (This is how libosmo-abis and LCR handle it too.)
A pipe is used as a poll()-able audio tx buffer (filled in misdn_write()):
FTDM_WRITE wait requests are currently poll()-ed on the input side of the pipe,
whereas FTDM_READ and _EVENT requests are poll()-ed on the b-channel socket itself.
For every N-bytes of audio data read from the b-channel in misdn_read(),
we try to get as much out of the tx pipe, convert it into the ISDN_P_B_RAW
format and send it to the b-channel socket.
If there's less than N-bytes left in the pipe, we fill the remaining buffer
with silence to avoid buffer underflows.
B-Channel handling overview:
- misdn_wait(FTDM_WRITE) on audio pipe
- misdn_write() put audio data into pipe
- misdn_wait(FTDM_READ) for next incoming mISDN
message on b-channel socket
- misdn_read() handle mISDN event, for PH_DATA_IND:
- Write data into channel buffer and convert
to a/u-law using misdn_convert_audio_bits()
- Try to fetch N-bytes from audio pipe
- If not enough bytes in pipe: fill remaining space with silence
- Convert audio to raw format
- Send to b-channel (PH_DATA_REQ)
Known problems / bugs / further investigation:
1. Bridge aborted by "Write Buffer 0 bytes Failed!" error from switch_core_io.c.
This is "fixed" by _not_ setting the b-channel sockfd to non-blocking mode.
2. Audio glitches (maybe caused by FTDM_WRITE misdn_wait() handling or blocking I/O on sockfd?)
3. misdn_read() EBUSY error messages from sending data to b-channel sockfd after enabling channel.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
The former fixes a strange "bug" with hfcsusb, where a b-channel deactivation
on a inactive channel (caused by a reset cycle) would cause the port to
lock up and stop processing events.
NOTE: this still needs to be investigated further, but this workaround will
at least prevent it from breaking completely.
We'll now keep track of the channel activation state and not send any
PH_ACTIVATE_REQ / PH_DEACTIVATE_REQ requests, if the channel already has the
desired state.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Use POLLIN on the socket instead, the b-channel should be able
to write when there is something to read.
Several other projects handle it this way, e.g. libosmo-abis.
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
The code was improperly using peer_data as an indicator that the sigbridge
ss7 mode was enabled. The channel flag FTDM_CHANNEL_NATIVE_SIGBRDIGE should
be used instead
- The outgoing tdm leg should not move to UP until
after the IAM is sent at the end of the function
- The UP state should be processed immediately otherwise
the state processor is not run due to the way the main
ss7 processing loop currently works
Use FTDM_SIZE_FMT where needed, don't treat ftdm_event_t as an int
(even if the e_type enum is the first member), datalen vs. *datalen fix
and other warnings.
All reported by __check_printf() (GCC + __attribute__((format(printf,x,y))) ).
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
... that could cause segmentation faults.
Caught while working on __check_printf() support for ftdm_log().
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
For compilers that seem to do the wrong thing(tm).
Speculative fix for:
segfault at 1 ip b72145d3 sp b58f8bfc error 4 in libc-2.11.3.so
#0 0xb7a5d5d3 in vfprintf () from /lib/i686/cmov/libc.so.6
#1 0xb7a7cec7 in vasprintf () from /lib/i686/cmov/libc.so.6
#2 0xb7dd7c5b in switch_vasprintf (...)
#3 0xb6296de2 in ftdm_logger (...)
#4 0xb621625d in misdn_handle_mph_information_ind (...) at ftmod_misdn.c:658
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Only two mISDN hardware drivers emit MPH_INFORMATION_IND messages and both use a different payload:
- hfcsusb (HFC-based USB dongle) sends a set of ph_info + ph_info_ch structures
which contain the complete state information of the port
(including internal hw-specific state and flags).
- hfcmulti which sends a single integer, a single L1_SIGNAL_* event.
We now try to guess the type of message from the payload length.
The hfcmulti signals are converted to FreeTDM alarm flags; the hfcsusb
state/flags are defined in kernel internal hw-specific headers and are ignored ATM (todo).
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Add MISDN_MSG_DATA() helper macro for easy access to mISDN message
payload.
Add forward declaration of misdn_handle_mph_information_ind() and use
it in misdn_activate_channel().
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
Add missing mISDN event/message types (e.g. MPH_INFORMATION_IND)
and use a helper macro (MISDN_EVENT_TYPE) to define the entries,
like we already do for misdn_control_types[].
Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
- The queue size has been bumped again, long calls could potentially require more elements (multiple resume/suspend)
- The queue is only used when there is a call active
- redirect number in Transparent IAM
- redirect information in Transparent IAM
- called party number in Transparent IAM
- adding incoming uuid to x-header to check loop calls