Implementing a VoIP gateway with wireless capability

update: 2008.3.9

Project description

Asterisk is a open source IP PBX software that can handle various protocols, such as SIP, H323, IAX..etc. in telephony world.
With Asterisk, we can build up a VoIP gateway to serve multiple and various kinds of phone calls.
Now we enhance the Asterisk with Bluetooth capability, and connect to cell phone with Bluetooth (acts as Audio Gateway, AG), which in turn gives the wireless capability to the traditional wired gateway.
Below is a simple scenario graph to represent the architecture.
                           WLAN              Bluetooth                        PSTN
Ekiga (soft phone1) -------\        /----------- Audio Gateway ------ Steve's cell phone
                                     Asterisk
Ekiga (soft phone2) -------/        \ -----------Audio Gateway ------ Gino's cell phone

The Audio Gateway in the middle is a cell phone connecting to the bluetooth adapter on Asterisk by using the Bluetooth HandsFree profile.
The Ekiga is a VoIP soft phone, and communicate with Asterisk by SIP protocol.
Besides, we use an Asterisk add-on channel driver, chan_mobile, to handle the bluetooth connection of Asterisk.
The test scenario is to make phone call from Ekiga to My cell phone, and simultaneously use another Ekiga to call Gino's cell phone

Planning phase

Project planning

Chan_mobile code tracing 

BlueZ HCI_USB driver tracing

BlueZ Core tracing

USB Note

PESQ and CVSD

Hardware and SCO socket problems

Hardware setup

1. Bluetooth dongle
Cyber-Blue Bluetooth Wireless Slim Adapter, V1.2 Super Slim Space Saving Design, Class 2, Range Up To 20 m (65 Feet), Retail Blister Pack
2. Motorola Razr V3
3. Personal computer or laptop with wireless card support and with usb port for bluetooth dongle

Operating system and software version

Ubuntu 7.10 (Gusty), Desktop edition for Standard personal computer (x86 architecture, PentiumTM, CeleronTM, AthlonTM, SempronTM). 8.04 Hardy is also tested

Linux 2.6.22-14-generic #1 SMP
Bluetooth Core ver 2.11

asterisk-1.6.0-beta4:
svn checkout http://svn.digium.com/svn/asterisk/tags/1.6.0-beta4/ asterisk-1.6.0-beta4

asterisk-addons-1.6.0-beta4:
svn checkout http://svn.digium.com/svn/asterisk-addons/tags/1.6.0-beta4/ asterisk-addons-1.6.0-beta4

If we want to download revision 416 of asterisk-addons:
svn checkout -r 416 http://svn.digium.com/svn/asterisk-addons/trunk asterisk-addons-rev416

[additional setup for synchronizing the time between PCs]
apt-get install msntp (for NTP)
On server, add "msntp -S" in /etc/rc.local
On client, add "msntp -r -P no -x server_address" in /etc/rc.local
[-S means "server" "daemon"]
[-r means "settimeofday", -P no means "no Prompt", -x means "daemon"]

Asterisk setup

1. Be sure to build up the following
apt-get install g++
apt-get install libncurses5-dev
apt-get install bluez*
2. Build  Asterisk 1.6.0-beta4

chan_mobile setup

The section is directly copied from http://www.chan-mobile.org/

In order to use the development version, checkout the trunk version of asterisk-addons from digiums subversion repository.
svn checkout http://svn.digium.com/svn/asterisk-addons/trunk asterisk-addons

  1. cd asterisk-addons
  2. ./configure
  3. make menuselect
  4. choose chan_mobile
  5. press x to exit
  6. make
  7. make install (as root)

chan-mobile requires that the bluez headers and libraries are installed on your system. If the configure step above does not detect them, then you will be unable to select chan_mobile in the menu.

Most distributions provide a package that contains the blue-z development libraries. It is probably called something like libbluetooth-dev.

Asterisk Config

1. Setting up hardware.
(a) find out bluetooth adapter address
use "hciconfig -a"

(b) find out the information of AG
The first thing is to find out the address of these AGs.
Turn on the AG (discoverable)
Use "hcitool scan" to find out the address of them
Then use "sdptool browse $ADDRESS" to find out the services the AG provides.
In the listing, we can find out the Handsfree profile settings and the channel number, which will be later used as port number in mobile.conf.

(c) write mobile.conf (configure bluetooth adapters and audio gateway)
[adapter]
id=black    ; the name here will match the "adapter" field of the AG's setting.
address=00:11:67:5A:9E:5C    ; address of bluetooth adapater
[adapter]
id=white
address=00:11:67:63:E9:EE
[Voip1]
address=00:19:2C:D5:90:DF    ; address of the first AG
port=7                                ; the channel number of Handsfree profile
context=voip1-sip                   ; handle the call (Cellular --> SIP)
adapter=black                      ;adapter name
group=1                              ; group number
; each adapter can be assigned to a specific group
; Then when you write dialup plan, you can use command to call a group instead of a specific phone
; Asterisk will choose the first available phone in this group to call out
[Voip2]                               ; second AG
address=00:1C:C1:DD:83:BE
port=7
context=voip2-sip
adapter=white
group=2

(d) Pairing up the adapter with AG

Plug in ONLY ONE adapter at a time and turn on bluetooth of one cell phone.
Then run "asterisk -cvvv", you will receive the message of pairing on cell phone.
Type a pin code on cell phone, and then type the same on the Asterisk server

Another way to bond is to use dbus interface
//bond hci0 with device AA:BB:CC:DD:EE:FF
$dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.CreateBonding string:AA:BB:CC:DD:EE:FF
//unbond hci0 with device AA:BB:CC:DD:EE:FF
$dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.RemoveBonding string:AA:BB:CC:DD:EE:FF

2. Configure sip.conf (sip setting and user account)
disallow=all                    ; First disallow all codecs
allow=ulaw                      ; Allow codecs in order of preference
allow=ilbc                      ; see doc/rtp-packetization for framing options
allow=gsm
allow=h261

[steve]
type=friend             ; This device takes and makes calls
;username=steve         ; Username on device
secret=steve            ; Password for device
qaulify=yes
nat=no
host=dynamic            ; This host is not on the same IP addr every time
canreinvite=no
context=sip-black      ; Inbound calls from this host go here. This context name will match the extensions.conf
port=5062                ; Uncomment this line if Ekiga and Asterisk are on the same host
                             ; this port number is used for Asterisk to send the sip signaling to the SIP soft (Ekiga)
                             ; The Ekiga must be configured to listen on this port also
[gino]
type=friend              ; This device takes and makes calls
;username=gino        ; Username on device
secret=gino             ; Password for device
qaulify=yes
nat=no
host=dynamic            ; This host is not on the same IP addr every time
canreinvite=no
context=sip-white       ; Inbound calls from this host go here
;port=5062


3. Configure extensions.conf (setup the context that is defined in the "context" field of user account in sip.conf)
[sip-black]
exten => 501,1,Dial(Mobile/Voip1/6319056472)    ; the user of sip-black context will call steve's cellphone via Voip1
exten => 401,1,Dial(Mobile/Voip2/6313320099)    ; the user of sip-black context will call gino's cellphone via Voip2

[sip-white]
exten => 501,1,Dial(Mobile/Voip1/6319056472)    ; steve's cellphone
exten => 401,1,Dial(Mobile/Voip2/6313320099)    ; gino's cellphone

[voip1-sip]
exten => s,1,Dial(SIP/steve, 10)        ; Cellular-->steve on SIP

[voip2-sip]
exten => s,1,Dial(SIP/gino, 10)           ; Cellular --> gino on SIP

Ekiga setup

1. Install Ekiga
2. In ubuntu, use gconf-editor, find apps->ekiga->protocols->sip
change "listen port" to 5062 (match the port number in the context of the login user account; /etc/asterisk/sip.conf)
3. In the ekiga program, go to Edit -> Accounts. Then in the Accounts window, click "Add" button. From this, we can add a new account where ekiga can connect.
4. Create a new account with giving any account name for the "Name" field. For the remaining fields, provide
Registrar: IP address of the Asterisk machine
Name: test (match /etc/asterisk/sip.conf)
Password: test (match /etc/asterisk/sip.conf)
Then click "Ok" button to add the account. Now in the accounts window, the status column should show "registered". This means ekiga is connected to asterisk and you can make calls. If it shows "Registration failed", then the setup is not correct. Just check the IP address which is normally the issue. If the machine running asterisk connects to different network, then the IP address will have to be changed for the account.

Experiment result

Scenario (1 and 2 are at the same time):
1. Soft phone 2 calls gino's cell phone via "white" bluetooth adapter
2. Soft phone 1 calls steve's cell phone via "black" bluetooth adapter
3. steve hangup
4. gino hangup

Output of Asterisk command line interface
*CLI> mobile show devices
ID              Address           Group Adapter         Connected State SMS
Voip2           00:1C:C1:DD:83:BE 2     white           Yes       Free  No
Voip1           00:19:2C:D5:90:DF 1     black           Yes       Free  No

*CLI>   == Using SIP RTP CoS mark 5
    -- Executing [401@sip-white:1] Dial("SIP/gino-0821f968", "Mobile/Voip2/6313320099") in new stack
    -- Called Voip2/6313320099
    -- Mobile/Voip2-fd1d is ringing
    -- Mobile/Voip2-fd1d answered SIP/gino-0821f968
  == Using SIP RTP CoS mark 5
    -- Executing [501@sip-black:1] Dial("SIP/steve-0821c718", "Mobile/Voip1/6319056472") in new stack
    -- Called Voip1/6319056472
    -- Mobile/Voip1-f726 is ringing
    -- Mobile/Voip1-f726 answered SIP/steve-0821c718
  == Spawn extension (sip-black, 501, 1) exited non-zero on 'SIP/steve-0821c718'
  == Spawn extension (sip-white, 401, 1) exited non-zero on 'SIP/gino-0821f968'

Short conclusion
currently we need one pair of bluetooth adapter and AG to serve a sip phone call.
So if we need to serve 2 phone call, we need 2 pairs of these equipments.
Since one bluetooth connection can support up to 3 SCO links, the further work is to extend the ability for one adapter to communicate 3 audio gateways, so that it can serve 3 sip phone calls at the same time.

Old works

Asterisk 1.4+chan_bluetooth Setup
Telephony System Technology

Other references

How bluetooth works
Asterisk bluetooth channel
Bluez official website
Bluetooth 1.2
Bluetooth class 1, 2, or 3?
USB wiki