So after setting up Asterisk with a working DAHDI configuration for the PBX project, next was configuration for IP phones using PJSIP and provisioning them.

Asterisk has a built-in module called res_phoneprov which handles HTTP based phone provisioning but that didn’t work for me – I just couldn’t have it generate XML configuration for the phones that we had, i.e. Grandstream GXP1625.

The server on which I had configured PBX was multi-homed, as in it was part of multiple networks. But there was no reason to run the service on all interfaces except the VLAN on which we were going to connect the phones.

First, configuration for PJSIP transport:

Now one could do configuration of the phones in the above file itself, but configuring each phone involves very verbose configuration. Instead let’s use Asterisk’s PJSIP Wizard module. It simplifies the configuration by a large amount. The PJSIP wizard can configure the phoneprov module as well but as I stated above, I could never get that thing to work so I devised my own solution for that, especially since provisioning in my case just involved generating XML configuration files for the GXP1625 phones.

That’s the wizard configuration initially, we define a user template which will be common to all phones.

Now add phone configuration to it:

The MAC and NAME parameters are used by a custom XML config generator script, more on that below.

In addition to the Grandstream phones, we had a single unit of Cisco 7940 which was bought for testing purpose, so configure that as well. But note that here, we need to add endpoint/force_rport = no otherwise the phone will not register with the server as discussed in this Asterisk forum post.

Now some configuration for ISC DHCP Server so that the phones (both Grandstream, and Cisco) can find the provisioning server. Grandstream can use HTTP based provisioning method (documented by Grandstream in this PDF file) but for Cisco you need to use TFTP server. The configuration files are different for Cisco as well; further information on TFTP based provisioning for Cisco can be found here.

I wrote a simple PHP script to generate the XML configuration file for GXP1625:

Most of the Asterisk configuration files are valid INI files, but when we introduce templates into it the syntax of INI files becomes invalid, and PHP’s INI parser cannot read the file. So after reading the file I am doing a preg_replace  in it to delete all text that contains round brackets, which is the way to use templates in the file.

All the parameter values written above, are not documented properly, so I found them out using the phone’s built-in web-interface and doing inspect-element on each form input field. There are a lot of other options but I haven’t added them to this file because they didn’t seem important.

And finally, a Nginx rewrite rule so that all requests for the cfgMAC.xml  comes to our script with a mac=  parameter.

Now you can configure your extensions.conf or extensions.lua as your prefer and do the testing if the phones are working correctly or not.

Advertisements