Thanks to Phil Zimmermann for the code and for the license exception
we needed to include it.
There remains some build system integration work to be done before
this code will build properly in the FreeSWITCH tree.
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>
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>