[asterisk-dev] Sending control frame outside a call

Mark Michelson mmichelson at digium.com
Thu Nov 10 10:27:10 CST 2016


On 11/09/2016 01:11 PM, wferrell1 at nc.rr.com wrote:
> Hi,
>
> I have a customer who is running 12.8.2 and since their software needs to be certified at considerable expense and time will not be upgrading Asterisk anytime soon. In addition due to security requirements the only connection between their Asterisks is a single IAX2 peer. They would like to support BFCP (Binary Floor Control Protocol – RFC 4582). The issue is BFCP sends information in the SIP SDP such as TCP connection and port info and then assumes the two endpoints have set up a socket between them to exchange BFCP protocol messages. I am not allowed to open a direct socket between the BFCP endpoints due to security concerns, all traffic, signaling, messaging must go over the single IAX2 connection. So I can open a socket from asterisk to the BFCP client/server using the port information received the SIP SDP. Then the BFCP endpoint sends the protocol message to the asterisk and I need to send it across the IAX2 connection to the other asterisk who will then send it on to its intended destination. What I am trying to do is create a new  ast_control_frame_type and send the BFCP protocol message as data in a control frame. The problem I am running into is determining how to send a message to a peer outside a call. All the methods I have found such as ast_queue_control_data assume an active call that has been bridged. I also tried to use the socket send method using the sockfd defined in the iax2_peer structure, but it returned a -1. So what I am looking for is the base methods for sending/reading data to/from an IAX2 peer. Is this possible? If so, can anyone point me to some code that does what I want?

The hard part for answering this determining what you mean when you say 
you want to convey information to another party "outside a call" . I can 
read this a couple of ways:

1) A SIP endpoint will send Asterisk arbitrary data in some sort of 
request (like maybe an OPTIONS request), and you then want to send this 
data over IAX2 to the other side. The endpoints involved are not calling 
each other at all. It's just that information received in Asterisk by 
one endpoint has to then be conveyed out another interface.

2) A SIP endpoint will initiate a call that will end up going out the 
IAX2 side. Prior to call establishment, you need to send information out 
the IAX2 side

Let's go over each of these.

For situation (1), there are no ast_channel structures involved at all. 
So there's no way to be queuing frames or sending frames between 
channels. Instead, you'll need to use other methods within Asterisk. 
Since you're using Asterisk 12, your best bet is to make use o the 
Stasis message bus. The idea would be that the SIP channel driver that 
receives the incoming messages would raise a Stasis event. The IAX2 
channel driver would be subscribed to those events and potentially react 
by sending messages out where necessary. If you want to learn more about 
the Stasis message bus, there is a real good explanation of the API in 
include/asterisk/stasis.h in the comments at the top of the file. If you 
want to see examples of it in action, I think device state is a good 
place to look. You can look in main/devicestate.c to see where the 
topics and messages get created, as well as transmission of events. You 
can grep for "ast_device_state_message_type()" to find places that 
subscribe to device state messages.

For situation (2), You'll have a channel making an incoming call, 
presumably with some BFCP information in the incoming SDP. However at 
the point where you want to make an outbound call, the channels involved 
are not communicating via frames. That doesn't start happening until the 
outbound call gets established. In such a case, you'll have several 
options for getting the necessary information from the inbound channel 
to the outbound channel. One way I'll recommend is to make dialplan 
functions to retrieve BFCP information, set channel variables (preceded 
by "__" so they get inherited on the outbound channels), and then have 
chan_iax2 read those channel variables and communicate what is necessary 
prior to making the outbound call.

As far as the mechanics for sending information on the IAX2 socket, I'm 
afraid I can't help you there. I don't have much direct experience with 
the inner workings of chan_iax2, and the best I could offer would be 
speculation of what might work based on my reading of the code.




More information about the asterisk-dev mailing list