Raspberry Pi FTP server

I’ve been trying to resurrect my SIP-connected Cisco 7940 as part of a review of our home telephony arrangements. In order to do this, I’ve had to configure the TFTP capabilities on my home infrastructure server (i.e .my Raspberry Pi). Previously, I’d served the phone configuration from a Windows TFTP server (long since gone) and the phone had just kept going with the old settings. Now, with configuration changes required, I’ve started to use dnsmasq for TFTP as well as DNS and DHCP (actually, that had always been configured, but without any files on the Pi to serve from TFTP)!

So, how to easily transfer the files? FTP to the rescue. I followed the Pi My Life UP guide to install vsftpd on my Pi, which meant using the following commands:

  1. Update packages and install vsftpd:
    sudo apt-get update
    sudo apt-get install vsftpd
  2. Edit the vsftpd config with sudo nano /etc/vsftpd.conf, making sure it has the following entries:
    anonymous_enable=NO
    local_enable=YES
    write_enable=YES
    local_umask=022
    chroot_local_user=YES
    user_sub_token=$USER
    local_root=/home/$USER/ftp
  3. Create the folder to use for FTP and set the permissions:
    mkdir /home/pi/ftp
    mkdir /home/pi/ftp/files
    chmod a-w /home/pi/ftp
  4. Restart the FTP service with sudo service vsftpd restart.

After this, I could easily upload the files I needed to the folder that I’m serving TFTP from (/home/pi/ftp/files) – although for some reason the FTP server was listening on port 22 (not 21), and then distribute my new phone configuration…

Lyncing to Asterisk

I’m seeing increasing interest from customers in the enterprise voice functionality in Microsoft Lync – particularly for customers who already have an investment in Microsoft products for email, instant messaging and presence (Exchange and Office Communication Server or Lync).

One of my colleagues, Garry Newsham, shared an interesting link with me recently about integrating Lync with the open source Asterisk platform. Whilst this isn’t something I expect many enterprises to be looking at, it might be a project for smaller organisations.

As for me, maybe I’ll have another go at getting IP telephony working in my house, linked to my Office 365 Lync subscription…

Configuring a Cisco IP phone for VoIP using SIP

Cisco logoOne of my projects at home has involved trying to get a variety of telephony systems to work together so that I can make voice over IP (VoIP) or plain old telephone service (POTS) as necessary to get the best call rates. In truth, it’s probably not about getting the best rates as our phone bill is already pretty small – maybe it’s just because the geek inside me wants to get an IP phone working on my desk… anyway, I still have a few pieces of the puzzle to fit in place but last week I had a major breakthrough in getting a Cisco IP phone to provide a voice over IP (VoIP) service using SIP. It was a long haul, but worth it in the end – and this is how it’s done…

Cisco IP Phone 7940GFirst of all I needed an IP Phone. I managed to pick up a brand new 7940G for £50 on eBay (a bargain) and this was perfect for me. Why a Cisco phone? Partly because we use them at work (so I know they are good phones – and I like the form factor – although I wish it had a backlit screen) but mostly because there are so many of them about – that means that plenty of people have tried to do this and there is information available on the web. Using a Cisco phone does cause a couple of problems though:

  1. The standard protocol used for VoIP is session initiation protocol (SIP) and Cisco IP phones don’t use SIP natively. Cisco has it’s own IP Telephony system (Call Manager) which uses SCCP; however they do provide SIP firmware for their 79xx IP phones.
  2. Some of the Cisco documentation and software is only available with a service contract and generating configuration details can be a challenge if you don’t have access to a Cisco Call Manager solution – thankfully everything I used for this is available on the ‘net through a variety of websites that are aimed at getting people up and running with VoIP solutions.

It’s also worth knowing that there are two types of configuration file for Cisco IP Phones:

  • The 79x0 models use a fairly simple configuration file.
  • The 79x1 models use an XML configuration, which is all very well if you have access to a Cisco Call Manager solution but not so well documented if you don’t.

I found that the 7940 is a good model to go for as it has been around for a while, there is plenty of information available, and it can be picked up for a reasonably low price (and it helped to know that one of my colleagues already had this solution working well for him!). The 7960 is similar but with support for more lines and there are other models available (e.g. cordless phones, or phones with colour screens). In addition, Linksys (owned by Cisco) sells some similar phones that do run SIP natively but I don’t know if they use the same firmware.

After choosing the phone there were a couple of other considerations:

With the phone powered on and able to download a configuration, I uploaded the necessary configuration files to the TFTP server. Cisco Document ID: 5455 – Converting a Cisco 7940/7960 CallManager Phone to a SIP Phone and the Reverse Process gives details of the required files but the main ones to know are:

  • OS79XX.TXT – tells the phone which firmware to use.
  • SIPDefault.cnf – configuration information relevant to all phones.
  • SIPmacaddress.cnf – configuration information relevant to a specific phones.

Other files that I have include:

  • RINGLIST.DAT – Lists audio files that provide the custom ring types.
  • CTU.raw – an audio file referenced by RINGLIST.DAT.
  • dialplan.xml – a dialplan.
  • Various firmware images named as follows:
    • P003x-xx-x-00.bin – universal application loader for upgrades from images earlier than 5.x.
    • P003x-xx-x-00.sbn – secure universal application loader for upgrades from images 5.x or later.
    • P0y3x-xx-x-00.loads – universal application loader and application image, where y represents the protocol of the application image (.loads) file: 0 for SCCP, and S for SIP.
    • P0y3x-xx-x-00.sb2 – application firmware image, where y represents the protocol used by the image: 0 for SCCP, and S for SIP.

With all the necessary files available on the TFTP server, I set about upgrading the firmware to the latest SIP release by editing the OS79XX.TXT file to read P0S3-08-2-00 and resetting the phone. The TFTP server log told me that the phone picked up the appropriate firmware release, but that it couldn’t find one of binary images (P0S3-08-2-00.bin)

After some research, it seems that POS3-08-x-00.bin does not seem to exist for any 8.x firmware:

Versions [6.x] and [7.x] seem to have P0S3-0xxx-00.BIN files which make it easy when upgrading from SCCP to SIP as all you have to do is rename the file it loads in OS79XX.TXT to one of these *.BIN files and its all done straight to SIP.

With version 8 series it doesn’t have these and that forces you to upgrade it in a 3 part reboot and load phase with[:]

XMLDefault.cnf.xml
[SEPmacaddress.cnf.xml]

That loads the *.loads file then it loads *.sbn and reboots
After warm reboot it loads *.sb2 which must be the sip software.

Then reboots again starting in sip and then provisions with[:]

SIPDefault.cnf
[SIPmacaddress.cnf]

Armed with this new information, I put the 7.4 SIP firmware into my TFTP root folder, edited OS79xx.TXT to read P0S3-07-4-00 and created an xmlDefault.CNF.XML file.

After booting the phone I was pleased to see a message that said Upgrading software but that pleasure soon ended as the upgrade never completed. Thankfully I hadn’t “bricked” the phone and, after another reboot, the phone showed a message which said Load ID Incorrect. The TFTP logs indicated that the phone was trying to load a file called SEPmacaddress.cnf.xml.

Googling turned up some more information and it turned out I was trying to go too far in one jump – my phone had been supplied with v3.x SCCP firmware and I was trying to go straight to v7.x firmware:

You have to upgrade to a new version of SCCP or older version of SIP before the bootloader on the phone will be able to handle the newer firmware […] you can either use an older version of SIP first, or a newer version of SCCP. Older SIP is probably easier – 6.3 is the newest you can use to then jump to 7.x and/or 8.x.

I put the v6.3 firmware on my TFTP server, edited OS79XX.TXT to read P0S3-06-3-00 and rebooted the phone. This time I saw the Upgrading Software message and watched the transfer take place.

After rebooting itself the phone came back up on the v6.3 firmware and was showing itself as Phone Unprovisioned.

I set about the second stage upgrade to v8.2 by editing OS79XX.TXT to P0S3-08-2-00 and rebooting the phone again. That didn’t help, but a further OS79XX.TXT edit from P0S3-08-2-00 to P003-08-2-00 did the trick as the Universal Application Loader booted.

Despite attempting to read non-existent files called CTLSEPmacaddress.tlv and SEPmacaddress.cnf.xml (the Cisco 7940 and 7960 IP Phones Firmware Upgrade Matrix explains the hunt algorithm employed by the Universal Application Loader) the phone downloaded the appropriate files and restarted to return as an unprovisioned device, finally running the v8.2 SIP firmware.

By this point, the TFTP logs were not much help as they didn’t indicate any errors but the status message on the phone gave me more clues:

W350 unprovisioned proxy_backup
W351 unprovisioned proxy_emergency
W362 No Valid Line Names Provisioned

The unprovisioned backup and emergency proxies didn’t bother me but I couldn’t understand why I had no valid lines provisioned. I had been trying to get the phone to use my Linksys SPA3102 as a SIP proxy but something was not quite right. In the end, I gave up and registered with SIPgate. After updating my configuration files to reflect the SIPgate account details, my phone picked up a valid line but couldn’t make or receive calls. Following advice on the SIPgate website, I made sure that the following ports were all open:

I’m not sure if all of these are strictly necessary but they seem to have got things working. The final contents of my configuration files are detailed below, after the TFTP log from a successful boot:

Connection received from ipaddress on port 50967 [25/07 00:41:32.672]
Read request for file <CTLSEP
macaddress.tlv>. Mode octet [25/07 00:41:32.672]
File <CTLSEP
macaddress.tlv> : error 2 in system call CreateFile The system cannot find the file specified. [25/07 00:41:32.672]
Connection received from
ipaddress on port 50968 [25/07 00:41:32.703]
Read request for file <SEP
macaddress.cnf.xml>. Mode octet [25/07 00:41:32.703]
File <SEP
macaddress.cnf.xml> : error 2 in system call CreateFile The system cannot find the file specified. [25/07 00:41:32.703]
Connection received from
ipaddress on port 50969 [25/07 00:41:32.719]
Read request for file <SIP
macaddress.cnf>. Mode octet [25/07 00:41:32.719]
Using local port 1203 [25/07 00:41:32.719]
<SIP
macaddress.cnf>: sent 2 blks, 632 bytes in 0 s. 0 blk resent [25/07 00:41:32.735]
Connection received from
ipaddress on port 50970 [25/07 00:41:32.766]
Read request for file <P0S3-08-2-00.loads>. Mode octet [25/07 00:41:32.781]
Using local port 1204 [25/07 00:41:32.781]
<P0S3-08-2-00.loads>: sent 1 blk, 461 bytes in 0 s. 0 blk resent [25/07 00:41:32.781]
Connection received from
ipaddress on port 50962 [25/07 00:41:54.672]
Read request for file <SIPDefault.cnf>. Mode octet [25/07 00:41:54.672]
Using local port 1205 [25/07 00:41:54.672]
<SIPDefault.cnf>: sent 2 blks, 925 bytes in 0 s. 0 blk resent [25/07 00:41:54.688]
Connection received from
ipaddress on port 50963 [25/07 00:41:54.813]
Read request for file <SIP
macaddress.cnf>. Mode octet [25/07 00:41:54.828]
Using local port 1206 [25/07 00:41:54.828]
<SIP
macaddress.cnf>: sent 2 blks, 632 bytes in 0 s. 0 blk resent [25/07 00:41:54.828]
Connection received from
ipaddress on port 50967 [25/07 00:41:56.891]
Read request for file <RINGLIST.DAT>. Mode octet [25/07 00:41:56.891]
Using local port 1207 [25/07 00:41:56.891]
Connection received from
ipaddress on port 50974 [25/07 00:41:56.907]
<RINGLIST.DAT>: sent 1 blk, 15 bytes in 0 s. 0 blk resent [25/07 00:41:56.907]
Read request for file <dialplan.xml>. Mode octet [25/07 00:41:56.907]
Using local port 1208 [25/07 00:41:56.907]
<dialplan.xml>: sent 1 blk, 104 bytes in 0 s. 0 blk resent [25/07 00:41:56.907]

OS79XX.TXT

P003-08-2-00

SIPDefault.cnf

;begin
image_version: P0S3-08-2-00
proxy_register: 1
dial_template: dialplan
tftp_cfg_dir: “”
sntp_server: “ntp.sipgate.net”
sntp_mode: unicast
time_zone: GMT
dst_offset: 1
dst_start_month: March
dst_start_day_of_week: Sun
dst_start_week_of_month: 8
dst_start_time: 01
dst_stop_month: Oct
dst_stop_day_of_week: Sun
dst_stop_week_of_month: 8
dst_stop_time: 02
dst_auto_adjust: 1
time_format_24hr: 1
date_format : D/M/Y

# NAT/Firewall Traversal
nat_enable: 1 ; 0-Disabled (default), 1-Enabled
nat_address: “” ; WAN IP address of NAT box (dotted IP or DNS A record only)
voip_control_port: 5060 ; UDP port used for SIP messages (default – 5060)
start_media_port: 8000 ; Start RTP range for media (default – 16384)
end_media_port: 8012 ; End RTP range for media (default – 32766)
nat_received_processing: 0 ; 0-Disabled (default), 1-Enabled
outbound_proxy_port: 5082
telnet_level: 2
;end

SIPmacaddress.cnf

;begin
image_version: P0S3-08-2-00
phone_label : “markwilson.it ” ; Has no effect on SIP Messaging
line1_name : “sipgateid” ; SIPgate device ID#
line1_authname : “sipgateid” ; SIPgate device ID#
line1_password : “sipgatepassword” ; SIPgate device password
line1_shortname : “phonenumber”
line1_displayname : “phonenumber”
proxy1_address : “sipgate.co.uk”
proxy1_port : 5060
line2_displayname: “”
line2_shortname: “”
line2_name: UNPROVISIONED
line2_authname: “UNPROVISIONED”
line2_password: “UNPROVISIONED”
proxy2_address : “”
proxy2_port : 5060
phone_password: “password”
logo_url: “http://webserver/sipgate.bmp”
directory_url: “http://webserver/directory.xml”
;end

RINGLIST.DAT

CTU CTU.raw

xmlDefault.CNF.XML





2000
2427 2428




P0S3-07-4-00






Further information

Here are some of the sites that I found particularly useful as I went through this process:

[update 10 September 2009: Here’s another useful resource on how to set up a cisco 7940 and 7941 IP phone to do SIP.]

[update 27 March 2010: Tyler Winfield’s article on configuring Cisco IP phones with Asterisk is very thorough and easy to read – even if you’re not using Asterisk.]