Friday, January 20, 2012

Integrate Asterisk with SIP enabled Wireless phone: Polycom SpectraLink 8030

If you are looking for SIP and 802.11a/b/g compatible wireless phone, SpectraLink 8030 can be one of your choices. It is compatible with Asterisk.  It has also Push-To-Talk (PTT) functionality that allows group communication just like Walky Talky.

Product information of SpectraLink 8030 can be found at
http://www.polycom.com/products/voice/wireless_solutions/wifi_communications/handsets/spectralink_8030_wireless.html

Software and documents for SpectraLink 8030 can be downloaded from following link from Polycom
http://support.polycom.com/PolycomService/support/us/support/voice/wi-fi/spectralink_8030_wireless.html

If you are using Polycom SpectraLink VIEW certified Wireless Access Point, you can call 1-800-Polycom and get the support. If not, there is no luck to get any kind of support from them.

In my case, we have
  • DHCP , DNS, NTP and TFTP server running on Linux
  • Xirrus Array - XN4, XN8   (Make sure your wireless AP supports WMM- Wi-Fi Multimedia; sometime you might have to upgrade to the latest firmware. Contact your  Wireless AP vendor if your AP doesn't have WMM enabled)
  • Asterisk Server (SIP server + PBX) : IP address 192.168.1.10
  • SpectraLink 8030 ( one has an extension 2000 and other has an extension 3000)
  • Voicemail (Extension 2100)
In this article, I am not going to show you how to configure DHCP, DNS, NTP, TFTP server. If you need any help, contact your Server Administrator or look for online help.

Step1: Publish the required firmwares and configs to  TFTP server
Download SIP software of SpectraLink 8030 from above link  
Unzip it and publish the content to TFTP server

You will see various .bin files and .cfg files.

In my case, I have following files
#tftpshare
 MIBs
 pd14csi.bin
 pd14odsi.bin
 pd14shim.bin
 pd14shsi.bin
 pd14udsi.bin
 pi1400si.bin
settings.txt
slnk_cfg.cfg
sip_allusers.cfg
sip_2000.cfg
sip_3000.cfg

You don't have to touch .bin files.  You don't even have to touch slnk_cfg.cfg file

All you need to do is edit sip_allusers.cfg and create the config files for individual extensions (in my case I have two SpectraLink. I want to extensions: 2000 and 3000)


#vi sip_allusers.cfg
#--------Configuration for Asterisk based system-------------
PROXY1_TYPE            = Asterisk
PROXY1_ADDR            = 192.168.1.10:5060  #IP address of Asterisk Server
PROXY1_KEYPRESS_2833   = enable
PROXY1_KEYPRESS_INFO   = disable
PROXY1_HOLD_IP0        = disable
PROXY1_PRACK           = enable
PROXY1_REREG_SECS      = 3600
PROXY1_KEEPALIVE_SECS  = 14
PROXY1_CALLID_PER_LINE = disable
PROXY1_MAIL_ACCESS     = 2100



Create a config file for an extension 2000
#vi sip_2000.cfg
LINE1         = 2000
LINE1_PROXY   = 1
LINE1_CALLID  = Spectralink x2000
LINE1_AUTH    = 2000; myp@ssw0rd


#Note- Password follows extension in LINE1_AUTH line


Similarly create a config file for an extension 3000

#vi sip_3000.cfg
LINE1         = 3000
LINE1_PROXY   = 1
LINE1_CALLID  = Spectralink x3000
LINE1_AUTH    = 3000; myp@ssw0rd

#Note- Password follows extension in LINE1_AUTH line


Step2: Configure Asterisk Server

Spectralink 8030 wouldn't register to Asterisk server. I have to go thru' rigorous troubleshooting before I could figure out the fact that SpectraLink 8030's latest SIP software is still based on the original SIP RFC 2543. [ Polycom support didn't want to talk about anything as I wasn't using their VIEW certified AP. ]

[Please read about fundamental SIP request header if you haven't done so far]

However Asterisk is designed on the basis of latest SIP RFC 3261. Asterisk server drops the REGISTER request coming from SpectraLink 8030 because as per RFC 2543 standard SpectraLink doesn't send tag id in SIP REQUEST FROM header.

Thus you have to tell Asterisk to ignore the tags in SIP request headers. You can do that by using global option in sip.conf

Asterisk 1.8 has pedantic=yes by default

;pedantic=yes ; Enable checking of tags in headers,
                                ; international character conversions in URIs
                                ; and multiline formatted headers for strict
                                ; SIP compatibility (defaults to "yes")


You have to use   pedantic=no  for SpectraLink 8030 to work with Asterisk


#vi sip.conf
[general]
bindport=5060
bindaddr=192.168.1.10
canreinvite=no
dtmfmode=auto
pedantic=no

 [2000]
type=friend
host=dynamic
context=YourContextinDialplan
username=2000
callerid="Dave One" <2000>
secret=myp@ssw0rd
mailbox=2000

 [3000]
type=friend
host=dynamic
context=YourContextinDialplan
username=3000
callerid="John One" <3000>
secret=myp@ssw0rd
mailbox=3000




Step3: Configure AP 
Different APs have different tools for wireless configuration. Make sure you are using 802.11a/b/g wireless APs. AP must be configured as WMM-PowerSave. Please go thru' the product guide that came along with your AP to enable WMM-PowerSave.

Create a SSID for your voice network. [You many not want to broadcast this SSID to minimize easy access to SSID by intruders]

You can use any kind of encryption you want to. I prefer WPA2 as it uses Pre-Shared Key(PSK) and it allows user to manually enter keys to initiate WPA security.

Example: 
SSID: spectralinknetwork
WPA2 passphrase: myp@ssword

Make sure various Radio bands are available  for use. I have enabled a/g band and I am going to use '802.11a standard'  for my SpectraLink phones. 

BONUS INFORMATION: Brief introduction on various wireless standards:
  • 802.11a standard operates in 5GHz band with maximum data rate of 54Mbps. It's range is lower than the range of 802.11b but offers higher number of channels and also higher data rate.
  • 802.11b standard operates in 2.4GHz band with maximum data rate of 11Mbps. It's range is higher range than 802.11a but it suffers interference from other devices like Bluetooth, cordless telephonesc etc operating at 2.4 GHz. Data rate offered is less than 802.11a.
  • 802.11g standard operates in 2.4GHz just like 802.11b, but operates at maximum data rate of 54Mbps. 
  • 802.11n standard operates in 5GHz and/or 2.4GHz using MIMO technology. 



Step4: Use SIP HAT(Handset Administration Tool) provided by Polycom to configure the initial configuration for SpectraLink 8030. You can download SIP HAT from above provided link 





Network Configuration of SpectraLink via SIP HAT Tool
  • Enable DHCP
  • Use SSID:spectralinknetwork  and WPA2 passphrase: myp@ssword and click on 'Generate PSK from Passphrase + SSID' button
  • Use QoS Type 'Wi-Fi Standard'
  • Admission Control: Optional
  • 802.11 Config: a
  • Enable the bands you want to use





SIP configuration and others via SIP HAT Tool
  • Change the TimeZone as required
  • Enter the SIP username: 3000 and password: myp@ssword
Follow the procedure as per instructed by SIP HAT Software to write the settings to SpectraLink 8030 handset. It might prompt for the password before you can write the settings to the handset. Default password is '123456'. Ignore any minor errors while writing the settings to handset as handset will download the latest firmware from your TFTP server anyway.

 Step5: Powercycle the handset. If your ducks are in row, it will work without hassle. If come across any issues, follow the SpectraLink 8020/8030 Wireless Telephone Administration Guide for SIP.

SpectraLink 8030 displays Startup Sequence: 1 thru' 9.  Let's say your handset is stuck at '1234567', it means it has successfully gone thru '8' and '9', but it is stuck at '7'. If you look on the administrative guide, '1234567' means DHCP response with bad DNS server configuration. So, you have to fix possible DNS/DHCP server issue.


If you need further help, you can email me at erdevendra@gmail.com or simply post the comment.

Saturday, January 14, 2012

SIP Request Header explained

SIP Request header explained for UAC behavior outside of a dialog.

Valid SIP request formulated by UAC must contain following seven header fields:

Mandatory Request Line: method, Request-URI and SIP version

To

From

Call-ID

CSeq

Max-Forwards

Via

Those headers are the fundamental building blocks of SIP message and are jointly used to provide Critical Message Routing Services including the addressing of messages, the routing of responses, limiting message propagation, ordering of messages and unique id of transactions.


Let's look at SIP NOTIFY message
=================
Server sending the NOTIFY message to IP phone ( Extension 57644)

NOTIFY sip:57644@192.168.2.10 SIP/2.0
Via: SIP/2.0/UDP sipserver.phone:5060;branch=z9hG4bK490bfd1d
Max-Forwards: 70
From: "pbx" <sip:pbx@sipserver.phone&gt;;tag=as5bea1e93
To: <sip:57644@192.168.2.10>
Contact: <sip:pbx@sipserver.phone:5060>
Call-ID: 154a4e1246b2d33f7257e1c965625efa@sipserver.phone:5060
CSeq: 102 NOTIFY
User-Agent: Asterisk PBX 1.8.7.1
Event: message-summary
Content-Type: application/simple-message-summary
Content-Length: 93

Messages-Waiting: no
Message-Account: sip:pbx@sipserver.phone:5060
Voice-Message: 0/2 (0/0)

---

IP Phone responding to the server by sending 200 OK

<--- SIP read from UDP:192.168.2.10:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP sipserver.phone:5060;branch=z9hG4bK490bfd1d
From: "pbx" <sip:pbx@sipserver.phone>;tag=as5bea1e93
To: "57644" <sip:57644@192.168.2.10>;tag=886BDB1C-E1C3AFC1
CSeq: 102 NOTIFY
Call-ID: 154a4e1246b2d33f7257e1c965625efa@sipserver.phone:5060
Contact: <sip:57644@192.168.2.10>
Event: message-summary
User-Agent: PolycomSoundPointIP-SPIP_331-UA/3.3.2.0413
Accept-Language: en
Content-Length: 0
=====================

Request-URI should be set to the value of URI in TO field [ Except Request-URI of REGISTER]

To: Specifies the desired 'logical' recipient of the request or 'address-of-record' of the target. This may or may not be the ultimate recipient of the request. To header field allows for a display name. Request outside of a dialog shouldn't contain To tag;

Example:
To: <sip:57644@192.168.2.10>

From: indicates the logical identity of the initiator of the request. This field is used by SIP elements to determine which processing rules to apply to a request. From field must contain a new 'tag' parameter, chosen by UAC.

Example:
From: "pbx" <sip:pbx@sipserver.phone>;tag=as5bea1e93



Call-ID: acts as a unique identifier to group together a series of messages. It must be the same for all requests and responses sent by either UA in a dialog.

Example:
Call-ID: 154a4e1246b2d33f7257e1c965625efa@sipserver.phone:5060


CSeq: serves as a way to identify and order transactions. It consists of a sequence number and a method. The method MUST match that of the request.

Example:
CSeq: 102 NOTIFY



Max-Forwards: It serves to limit the number of hops a request can transit on the way to its destination. UAC must insert a Max-Forwards header field in each request it originates with a value that SHOULD be 70.

Via: It indicates the transport used for the transaction and identifies the location where the response is to be sent.

Via: SIP/2.0/UDP sipserver.phone:5060;branch=z9hG4bK490bfd1d


When UAC creates a request, it must insert a Via header into that request. Via header must contain a branch parameter. Branch parameter is used to identify the transaction created by that request. This parameter is used by both the client and the server. Branch ID should always start with "z9hG4bk".


Contact: It provides a SIP URI at which the UA would like to receive requests.


Contact: <sip:57644@192.168.2.10>


Why 'tag' is introduced as mandatory in RFC 3261?

'tag' parameter is used in "To" and "From" header fields of SIP messages. Two 'tags' (one from each participant) along with Call-ID serves as a general mechanism to identify a dialog.

When UA sends a request outside of a dialog, it contains a From tag only, providing 'half' of the dialog ID. The dialog is completed from the response(s), each of which contributes the second half in the To header field.

The forking of SIP requests means that multiple dialogs can be established form a single request. This also explains the need for the two-sided dialog identifier.

'tag' must be globally unique 32 bits random string generated by UA. This uniqueness results different tag in To and From header of an INVITE request. This is essential for an UA to invite itself to a session Example: Hairpinning of calls in PSTN gateways.

Tags are useful for fault tolerant systems, where a dialog is to be recovered on an alternate server after a failure. UAS can select the tag in such a way that backup can recognize a request as part of a dialog on the failed server, and therefore determine that it should attempt to recover the dialog and any other state associated with it.




References:
http://rfc-ref.org/RFC-TEXTS/3261/chapter8.html

Friday, January 6, 2012

Asterisk "hint" explained

As we all know that Asterisk acts as a SIP server and it supports SUBSCRIBE/NOTIFY mechanism for the event notification. Asterisk is aware of the state of various things attached to it like phones, voicemail boxes, queues and more.
SIP protocol allows us to use the general framework for event notification without defining the actual events or device names. Asterisk uses 'hint' to map an extension number or name to a device.

[subscribers]
exten => 57644,hint,SIP/57644

In this example, SIP device SIP/57644 is mapped to 57644 using hint.

[subscribers]
exten => john,hint,SIP/57644

SIP/57644 can also be mapped to name 'john' using hint. It's all up to you, how you want to name it.


Asterisk receives a SIP SUBSCRIBE request, it checks for a 'hint' in a dialplan that matches the name of the device to be monitored. 'hint' tells Asterisk which device this corresponds to.

The connection between an extension and a device in Asterisk is called a hint.

Hint can also map special internal states (virtual devices) like Agent, SLA, park, Meetme and more.

It is very important to specify the location/context of the hints. It is recommended to use subscribecontext parameter in your sip.conf to identify the location of all hints within extensions.conf.

Asterisk CLI command #core show hints can be issued to list all defined hints.
#sip show subscriptions command can be used to list the current status of each subscriptions

Asterisk: SIP Subscribe/Notify and MWI event

SIP specific event notification is described well in RFC 3265
SIP Message Wait Indication Event (MWI) is described well in RFC 3842

Event notification allows any SIP client (IP Phones) to monitor the state of another device. If UA1 wants to know the status of UA2, it sends a SUBSCRIBE request to a server that is aware of the state of UA2 or it can directly send a SUBSCRIBE request to UA2. If the SUBSCRIBE request is successful, then UA1 is notified with SIP NOTIFY message every time UA2 changes the state.
This mechanism is widely used to control Busy Lamp Field (BLF) lamps.

Message Waiting Lamps or MWI are controlled by NOTIFY message, and as per RFC3842 explicit subscription is not required.

SIP signalling for MWI (captured on server/pbx):

Server sending the NOTIFY message to IP phone ( Extension 57644)

NOTIFY sip:57644@192.168.2.10 SIP/2.0
Via: SIP/2.0/UDP sipserver.phone:5060;branch=z9hG4bK490bfd1d
Max-Forwards: 70
From: "pbx" <sip:pbx@sipserver.phone&gt;;tag=as5bea1e93
To: <sip:57644@192.168.2.10>
Contact: <sip:pbx@sipserver.phone:5060>
Call-ID: 154a4e1246b2d33f7257e1c965625efa@sipserver.phone:5060
CSeq: 102 NOTIFY
User-Agent: Asterisk PBX 1.8.7.1
Event: message-summary
Content-Type: application/simple-message-summary
Content-Length: 93

Messages-Waiting: no
Message-Account: sip:pbx@sipserver.phone:5060
Voice-Message: 0/2 (0/0)

---

IP Phone responding to the server by sending 200 OK

<--- SIP read from UDP:192.168.2.10:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP sipserver.phone:5060;branch=z9hG4bK490bfd1d
From: "pbx" <sip:pbx@sipserver.phone>;tag=as5bea1e93
To: "57644" <sip:57644@192.168.2.10>;tag=886BDB1C-E1C3AFC1
CSeq: 102 NOTIFY
Call-ID: 154a4e1246b2d33f7257e1c965625efa@sipserver.phone:5060
Contact: <sip:57644@192.168.2.10>
Event: message-summary
User-Agent: PolycomSoundPointIP-SPIP_331-UA/3.3.2.0413
Accept-Language: en
Content-Length: 0

MWI activation in Polycom phone and Asterisk:

#vi /etc/asterisk/voicemail.conf
[default]
57644 => 1234,John Doe, John.Doe@xyz.com

#vi /etc/aterisk/sip.conf
[
57644 ]
type=friend
host=dynamic
username=
57644
callerid="John Doe" <57644 >
secret=mypassword
mailbox=
57644

pbx CLI> sip show peer 57644
* Name : 57644
- - - -
- - - -
Mailbox : 57644
Call limit : 0
Max forwards : 0
Dynamic : Yes
Callerid : "John Doe" <57644>
MaxCallBR : 384 kbps
Expire : 205
- - - -
- - - -
Addr->IP : 192.168.2.10:5060
Defaddr->IP : (null)
Prim.Transp. : UDP
Allowed.Trsp : UDP
Reg. exten :
Def. Username: 57644
SIP Options : (none)
Codecs : 0x4 (ulaw)
Codec Order : (ulaw:20)
Auto-Framing : No
100 on REG : No
Status : Unmonitored
Useragent : PolycomSoundPointIP-SPIP_331-UA/3.3.2.0413
Reg. Contact : sip:57644@192.168.2.10


Asterisk automatically sends NOTIFY message to IP phone provided that the phone is registered correctly with Asterisk and Asterisk knows which voicemail box is associated with that extension. You can check that by issuing the asterisk CLI command #sip show peer

Reg. Contact : sip:57644@192.168.2.10 tells you that phone is successfully registered.
Mailbox : 57644
tells you that Asterisk knows that voicemail box 57644 is associated with that phone. That association is defined in sip.conf.