SIP parameter exchange with Asterisk
When interconnecting two PBX, it can be useful to transport special information in addition to standard call signalling messages. When using such an open protocol as SIP, which supports parameters inclusion in INVITE messages, we can imagine new features for our open telephony. Here are some tips for doing this with an Asterisk solution.
Usage
Most of the time SIP calls are exchanged between phones and subsystem or between a system and a Centrex operator, but now with open source PBX solution we can easily install multiple PBX in various location within an enterprise or a corporation. Asterisk is allowing us to do this through either IAX or SIP. Within a PBX network, it can be useful to exchange, in addition to call setup information, some additional required in order to exchange a context or specific information related to the customer on the line. With these information, crossing the network, it will be possible for the CTI application, or simply the billing one to know more about the call which has been forwarded from one site to the other.
Inserting parameter in SIP INVITE message
The SIPAddHeader application command is allowing us to enhance a call parameter with specific one. This application should be called prior to the Dial one. The common usage is to prefix internal parameters with a X- in order to avoid collision with other parameters and allow an easy debugging. If multiple parameters needs to be exchanged, the application command will be called multiple times, like in:
exten => s,2,SIPAddHeader(X-ast-param1: value1)
exten => s,3,SIPAddHeader(X-ast-param2: value2)
Extracting parameter from SIP INVITE message
On the Asterisk getting the SIP call (INVITE message), any header is accessible through the array SIP_HEADER. One can get the parameter from the previous example using the following:
exten => s,2,Verbose(${SIP_HEADER(X-ast-param1)})
One step beyond
In order to ease parameter exchange within an Asterisk environment, I do propose the following macros1:
; ---------Start: [macro-sipargs-push] ----------------
[macro-sipargs-push]
exten => s,1,set(_SIP_ARGS_LIST=${SIP_ARGS_LIST} ${ARG1})
exten => s,2,SIPAddHeader(X-ast-${ARG1}: ${ARG2})
exten => s,3,SIPAddHeader(X-ast-list: ${SIP_ARGS_LIST})
; ---------End: [macro-sipargs-push] ------------------
; ---------Start: [macro-sipargs-pop] ----------------
[macro-sipargs-pop]
exten => s,1,Set(sipargs_list=${SIP_HEADER(X-ast-list)})
exten => s,2,Set(i=1)
exten => s,3,Set(siparg=${CUT(sipargs_list,' ',${i})})
exten => s,4,While($["${siparg}" != ""])
exten => s,5,Set(${siparg}=${SIP_HEADER(X-ast-${siparg})})
exten => s,6,Set(i=$[${i}+1])
exten => s,7,Set(siparg=${CUT(sipargs_list,' ',${i})})
exten => s,8,EndWhile
; ---------End: [macro-sipargs-pop] ------------------
sipargs-push
This macro can push a parameter and its associated value on the SIP INVITE stack, it should be called for each parameter and before the Dial application command. Parameter name will be prefixed by a X-ast- and each one will be add to a specific hidden parameter called X-ast-list which is also passed with the call. This list will allow the receiver side to know which parameters have been passed. Here is an example:
exten => _931.,1,Macro(sipargs-push,SIPCALLID,${SIPCALLID})
exten => _931.,2,Macro(sipargs-push,ID_CUSTOMER,12)
exten => _931.,3,Dial(SIP/${EXTEN:3}@to-asterisk-paris,20,t)
The first parameter in this specific example is SIPCALLID (parameter extracted from the initial call, let say from the IP Phone, the second one is an internal CTI variable (ID_CUSTOMER).
sipargs-pop
The second macro is to be used on the receiver side of the call and will extract any additional parameter and insert their values in the channel variable stack. It first explodes the X-ast-list value in order to gather the list and then re-inject each one in the channel, therefor we could use these afterwards as for standard channel variables.
exten => _[12].,1,Macro(sipargs-pop)
exten => _[12].,2,Verbose(${SIPCALLID})
exten => _[12].,3,Verbose(${ID_CUSTOMER})
exten => _[12].,4,Dial(SIP/${EXTEN},20,t)
Conclusion
We can really imagine new features as soon as we interconnect two or more SIP PBX in order to enhance our telephony application.
- built with Asterisk::Configure [↩]
|
Posted by: Alexandre Chauvin-Hameau, on 06/04/2007 Trackback | Popularity: 11% tagged 1.4, asterisk, configuration, extensions.conf and SIP |
|






