Following this tutorial on how to get Chan_Mobile working with Asterisk for Bluetooth support for our headsets and mobile phones we worked out how to get it working on Asterisk 1.6.

We figured we would share this information with our readers incase they were interested in Bluetooth for Asterisk and the capabilities it will open up to their system. Just think, the server will know when you’re in the room or out of the office and other fancy things.

First you should make sure that your Bluetooth Dongle works with Asterisk, and that your Cellular Phone is known to work with Asterisk and Bluetooth. You can verify all this information over at the Voip-Info Chan_Mobile page.

Requirements:

  • Asterisk PBX
  • Bluetooth Support (Motherboard or Dongle)
  • Cellular Phone with Bluetooth support
  • Bluez Bluetooth Libraries and Development Headers

Tutorial:

So, first we have to install some pre-requisite software. We’ll assume that you already have Linux installed, your kernel is compiled, Asterisk is installed and working, and that you have a basic familiarity with Linux commands. We’ve written this tutorial for Ubuntu, using FreePBX so instructions may change based on your OS or Asterisk Configuration GUI.

So, lets get down to business shall we.

First, install Bluez Utilities on your Server

# apt-get install bluez-utils bluez-hcidump

Now Configure Bluez to work with your server and dongle. We won’t go into depth on this as it mostly “just works” but there are ample tutorials and documentation if your dongle is a little finiky on your system.

Now, open up the file hcid.conf in the Bluetooth configuration directory, and match the contents to the following.

# nano /etc/bluetooth/hcid.conf

Erase the contents, and replace it with this

# HCId options  
options {  
autoinit yes;  
security auto;  
pairing multi;  
passkey "1234";  
}

device {  
name "Our PBX System";  
class 0x3e0100;  
iscan enable; pscan enable;  
discovto 0;  
lm accept;  
lp rswitch,hold,sniff,park;  
}

options {  
autoinit yes;  
security auto;  
pairing multi;  
pin_helper /etc/bluetooth/pin;  
}

Note you can also experiment with making Asterisk a handsfree headset, but we won’t go over this in this tutorial. The following lines can be added to your hcid.conf in replacement of the “Our PBX System” device mentioned above if you want to try this:

device {  
name "Asterisk";  
class 0x200404;  
iscan enable;  
pscan enable;  
lm accept;  
lp rswitch,hold,sniff,park;  
}

Now that our bluetooth is configured, we can go back to configuring Asterisk to work with Chan Mobile for Bluetooth Support. We’ll assume you already have Asterisk 1.6 running on your machine for this to work. If not, compile it and instal it!

Now, Enter the directory with your Asterisk-Addons 1.6 source.

# cd /opt/asterisk/asterisk-addons-1.6.0/

Issue your configure line

# make distclean  
# ./configure –with-bluetooth

Now, issue the configure menu tree

# make menuselect

Now, on the left hand side, hit the down arrow button until you get to the Channel Drivers section. On the right hand side, you should see “chan_mobile” with a little “*” next to it telling us it’s enabled.

[*] chan_mobile

If you don’t, press right on your arrow keys, and then press the enter key to select chan_mobile. Exit the configuration menu by pressing F12 to save your changes.

Now, build Asterisk-Addons 1.6 as you normally would

# make  
# make install

This will place chan_mobile.so into /usr/lib/asterisk/modules so the next time you start Asterisk it will be available.

We’re pretty much done the “difficult” stuff now, and just need to go on and start bluetooth on our system and then configure Asterisk to work with it.

So, start up bluetooth

# /etc/init.d/bluetooth start

Now, lets make sure that Bluetooth is running and sees our devices

# hcitool dev

This should output some information like this:

Devices:  
hci0 00:50:B6:80:34:DD

Make a note of the “hardware” address in a text file or somewhere handy because we will need it later. The hardware address is the one that looks like a MAC address. In this case it’s “00:50:B6:80:34:DD” note that your system will be different.

Now, lets edit Asterisk’s mobile configuration file

# nano /etc/asterisk/mobile.conf

Add your Bluetooth Adapter to the file like this, using the Hardware ID from the hcitool command you ran above. There should already be an entry that looks similar to this (with an id=blue) just replace the hardware ID in this entry with yours.

[adapter]  
id=blue  
address=00:50:B6:80:34:DD  
;forcemaster=yes  
;alignmentdetection=yes

Now exit and save the file.

Before we forget, we should add bluetooth to the startup options of the server if it’s not already there. Do so like this;

# update-rc.d bluetooth defaults

Now, in order for other devices to be able to see your server and vice-versa we have to make it discoverable. That’s done with the following command.

# dbus-send –system –type=method_call –print-reply –dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.SetMode string:discoverable

The fun begins right about now. Go and get your mobile phone. Turn bluetooth on on the phone. You should see your Asterisk PBX in the list of discoverable devices. Double click on it to add it to your device, and input the security key of 1234 when prompted.

Note that on our windows mobile 6.1 devices, after adding the Asterisk PBX to our bluetooth list, we also had to click on it and then hit refresh services list a few times until it showed us “Bluetooth Headset” as a list of supported options. We selected it on the screen, and closed the bluetooth configuration on our HTC Tytn II (Kaiser) test devices.

Now it’s time to make your phone discoverable so the PBX can attach to it. Go back to your phone, and find the option to enable bluetooth discovery. Turn it on.

Now from the Asterisk Server Command Line we should be able to issue this command to search for our Bluetooth Mobile Phone.

# hcitool scan

It should show you a list of results like this

Scanning ...  
00:16:BC:1F:E1:E8 Phone1  
00:17:83:6F:BD:51 Phone2

In our example, we’ll only be connecting to Phone2. One finicky thing we noticed is that if you want to connect more than one mobile phone at a time, you need a dongle to match. So, for example if you want to connect 5 bluetooth mobile phones, you would also need 5 bluetooth dongles, and 5 free USB ports (or a USB HUB) to get it all working. We’ve never tried with more than 2 bluetooth phones, so your mileage may vary.

If you don’t see your phone, something is wrong – try the above steps again to see if it fixes it.

Now continue on by stopping Asterisk PBX, and reloading it to take advantage of our new chan_mobile module.

# /etc/init.d/asterisk stop

Now start Asterisk in debug mode so you can verify everything is working.

# asterisk -vvvvvvvvvvvvvgc

Now type this command on the Asterisk CLI to find your mobile devices

*CLImobile search

You should see something similar to the following

Address Name Usable Type Port  
00:17:83:6F:BD:51 Phone2 Yes Phone 2  
00:13:33:44:4d:23 Phone1 Yes Phone 5

The above is a listing of all Bluetooth devices available to your Asterisk PBX.

  • The Address Field is the Device Identifier Code (MAC Address)
  • The Name Field holds the name of the device (Phone1)
  • The Usable Field tells us if the phone is Usable by Asterisk or not (Yes/No)
  • The Type Field tells us if it’s a Phone (FXO) or a Headset (FXS) device
  • The Port Field tells us which port the phone is using

Make a note of this information and continue on to the next step.

Now, exit Asterisk by typing “stop now” on the command line

*CLI stop now

You’ll be back at the CLI now.

In our example, we’ll be using Phone2 to configure to work with Asterisk.

Go back and edit your mobile configuration file in /etc/asterisk to look similar to this

# nano /etc/asterisk/mobile.conf

Add something similar to the following below the adapter configuration you added earlier in the tutorial.

[TytnII]  
address=00:17:83:6F:BD:51  
port=2  
context=from-pstn  
adapter=blue  
;group=1

If you are configuring a headset, the line would look something like this instead

[headset]  
address=xx:xx:xx:xx:xx:xx ; the address of the headset  
port=x ; the port number  
type=headset ; tells asterisk it is a headset  
adapter=blue ; adapter to use

Now you can start asterisk again. I would start it in debug mode so you can verify your phone is connected.

# asterisk -vvvvvvvvvvvvvvvgc

You should see messages similar to the following on the Asterisk Console letting you know your device has connected to Asterisk

— Bluetooth Device TytnII has connected.  
— Bluetooth Device TytnII initialised and ready.

And if you issue the show devices command

*CLImobile show devices

You should see something like this

ID Address Group Adapter Connected State SMS  
TytnII 00:17:83:6F:BD:51 0 blue Yes Free No

This means your phone is now connected to Asterisk. Depending on the context you put it in, if a call comes in to your cellular phone and you are within proximity of your Asterisk server it should route over to your one of your SIP extensions. Asterisk will automatically pair and unpair with your mobile phone as you come in and out of range respectively. Cool huh?

It is worth it to mention this warning from the original article as well: “Important: Watch what your cell phone is doing the first few times. Asterisk won’t make random calls but if chan_mobile fails to hang up for some reason and you get a huge bill from your telco, don’t blame me.”

Hope you enjoyed this tutorial, let us know if you have any comments or other fun ideas to do with chan_mobile, bluetooth and Asterisk in the comments!

Comments

Comment by Khee Hong Loke on 2008-11-20 00:54:56 -0500

Hi, I followed your guide all the way until the end. when I run “mobile search” on Asterisk CLi, it shows my mobile, but it won’t auto pair it. It won’t show my mobile as initialised and ready or connected. “mobile show devices” is empty. What should I do?

Comment by Matt G on 2008-11-20 05:00:16 -0500

Hi Khee Hong Loke,

Hm, I’ve not experienced that issue. What phone are you using? Have you checked the table of compatible devices on voip-info? Also, what bluetooth adapter, is the phone and adapter seen outside of Asterisk?

Comment by vipin sahu on 2009-03-04 19:26:32 -0500

very nice tutorial actually i am newbie and using suse 10.2 i want to purchase a bluetooth dongle but dont know which one will support .if you have a similar tutorial for suse please forward it to my mailbox thanks in advance very nice tutorial

Comment by Fritte on 2009-03-08 16:53:15 -0500

Hi and thanks for this nice guide.
I’m trying to get this working on Debian but have got stuck at ./configure –with-bluetooth.
The config doesn’t run to the end. It halts with the message:
checking for ba2str in -lbluetooth… no
configure: ***
configure: *** The Bluetooth Support installation on this system appears to be broken.
configure: *** without explicitly specifying –with-bluetooth

Any idé of what could be wrong?
The bluetooth is working so far that my computer can discover my phone and vise versa.

Comment by Fritte on 2009-03-09 17:46:59 -0500

Solved it by installing libbluetooth-dev

Comment by D on 2009-05-02 14:18:57 -0500

I can’t seem to get this to work. When i pair the device with my phone no services every show up. I’m guessing since the phone doesn’t see a headset service, it isn’t able to properly initialize with asterisk. when asterisk comes up it connect with the phone but it is stuck in the init state. it never gets to. state = free. Since it is stuck in init, i can’t even stop asterisk without using amportal kill. I’ve got a samsung i760 and a dlink 120 bluetooth adapter. I could really use some help.
-D

Comment by mihai on 2009-07-26 16:31:54 -0500

Please help!
Great tutorial, but I can’t make the device discoverable :((

Suse 11.1; bluez bluez-4.19-1.5
When I run
dbus-send –system –type=method_call –print-reply –dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.SetMode string:discoverable
I recieve
Error org.freedesktop.DBus.Error.UnknownMethod: Method “SetMode” with signature “s” on interface “org.bluez.Adapter” doesn’t exist

Found no hints on google.
Thanks

Comment by Pascal on 2009-08-18 18:37:18 -0500

Hi mihai,

get the source of bluez:
apt-get source bluez

then cd to test directory in the source directory an run
./test-adapter discoverable on

hf 🙂
Pascal

Comment by Khuram Malik on 2010-10-21 10:51:17 -0500

Thanks for this tutorial.
I managed to follow it successfully all the way to the last step, which for me, is where it fails.

When i do ‘Mobile Search’ at the Asterisk CLI i can see my phone with its MAC address and port. I entered this information in mobile. conf and restarted Asterisk.
But when i type ‘Mobile Show Devices’ at the Asterisk CLI, it doesnt show list any mobile devices.

Any ideas?

Comment by Khuram Malik on 2010-10-21 11:23:22 -0500

OK, i actually found what the issue was ironically just a few minutes after posting this message.

I was using the sample mobile.conf that has many entries for other sample mobile/bluetooth devices. I commented all of them out leaving only the entry for the bluetooth adapter and phone that is present.

As soon as i did that, when i typed mobile search at the asterisk CLI, it reported that all bluetooth adapters were in use, but doing ‘mobile show devices’ now showed my mobile device.

I’ve tried initiating some calls, but they seem to fail. Asterisk is however, trying to manage them, so it is at least a start!

Hope that helps anyone. Feel free to email me if you’re stuck (im no expert though)

Comment by giang on 2011-10-26 10:49:14 -0500

Hi

I follow the instructions, Asterisk can receive call from the mobile but can detect DTMF.

Anyone meet this issues ?

Comment by Senjam Shantirani on 2012-08-10 09:31:49 -0500

I have the following output in my asterisk cli

lok-AP480-S*CLImobile show devices
ID Address Group Adapter Connected State SMS
SHANTI 9C:02:98:B1:04:70 1 computer Yes Free No
— Executing [s@iit:1] Answer(“Mobile/SHANTI-328f”, “”) in new stack
— Executing [s@iit:2] Set(“Mobile/SHANTI-328f”, “TIMEOUT(response)=20”) in new stack
— Response timeout set to 20.000
— Executing [s@iit:3] BackGround(“Mobile/SHANTI-328f”, “/var/lib/asterisk/sounds/spkrverprompt1”) in new stack
— Playing ‘/var/lib/asterisk/sounds/spkrverprompt1.slin’ (language ’en’)
— Executing [s@iit:4] BackGround(“Mobile/SHANTI-328f”, “/var/lib/asterisk/sounds/virtual_interview”) in new stack
— Playing ‘/var/lib/asterisk/sounds/virtual_interview.slin’ (language ’en’)
— Auto fallthrough, channel ‘Mobile/SHANTI-328f’ status is ‘UNKNOWN’
[Aug 10 18:59:21] WARNING[25680]: channel.c:1066 __ast_queue_frame: Unable to write to alert pipe on Mobile/SHANTI-328f (qlen = 0): Bad file descriptor!

And the call does not get automatically pick up ..it shows a busy tone and get cut.
Please help.

Comment by Ahmed on 2019-08-06 04:22:49 -0500

Hello
How I can make rules in astrasik
Like limit mint
Links limit for any port

Comment by Noble on 2020-07-05 07:13:08 -0500

Please I am kind of new to this

I got into GSM termination a few months ago.

Resently I ran into someone who told me that i could configure my laptop to become a VoIP gateway device by installing and configuring asterisk, freePBX and chang dongle on my laptop then I can use it for GSM termination. Instead of buying over expensive VoIP devices.

I did some search online and found a few tutorials. Now, for some reasons, instead of using chang dongle to hold the sims for making calls, I would like to use mobile phones and bluetooth dongle instead.

Because I am quite new to this my questions are

  1. Can this set up really work for GSM termination.
  2. After installing/configuring asterisk, freePBX and the the bluetooth dongle to work on my laptop what do I need to do to start receiving voice traffic from traffic provider
  3. Can I use this set up for SMS termination

Thank you for your anticipated positive response to my questions