#Bluetooth: Using USB bluetooth adapters

<div class="text-success lead">
This article illustrates how to install a Bluetooth USB adapter on the Acme boards
and how to use it to comunicate with other Bluetooth devices using the Linux standard 
utilities
</div>

<img src="bluetooth.jpg"/>

The default Linux Debian distribution has the Bluetooth driver already installed 
so plugging a Bluetooth USB adapter and typing dmesg you will obtain the 
following messages:

<pre class="minicom">
debarm:~# dmesg
...
usb 1-1: new full speed USB device using at91_ohci and address 2                
Bluetooth: Core ver 2.15                                                        
NET: Registered protocol family 31                                              
Bluetooth: HCI device and connection manager initialized                        
Bluetooth: HCI socket layer initialized                                         
Bluetooth: Generic Bluetooth USB driver ver 0.6                                 
usbcore: registered new interface driver btusb
 
debarm:~# lsusb
Bus 002 Device 002: ID 1131:1004 Integrated System Solution Corp. Bluetooth Device
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
debarm:~#
</pre>

##Install Bluez

Bluez is the Official Linux Bluetooth protocol stack 
(<a href="http://www.bluez.org/">http://www.bluez.org/</a>) 
and you need to install it to do any further 
action with Bluetooth. This stack is available as standard Debian package 
with the name <b>bluez-utils</b> so to install it simply type:

<pre class="minicom">
debarm:~# apt-get update
...
debarm:~# apt-get install bluez
...
</pre>

then type again:

<pre class="minicom">
debarm:~# dmesg
...
Bluetooth: L2CAP ver 2.15
Bluetooth: L2CAP socket layer initialized
Bluetooth: RFCOMM TTY layer initialized
Bluetooth: RFCOMM socket layer initialized
Bluetooth: RFCOMM ver 1.11
Bluetooth: BNEP (Ethernet Emulation) ver 1.3
Bridge firewalling registered
Bluetooth: SCO (Voice Link) ver 0.6
Bluetooth: SCO socket layer initialized
</pre>

##Discover the Bluetooth devices in range

Turn on you mobile phone and enable on it the Bluetooth features.

On the FOX command line type <b>hcitool scan</b> to discover the Bluetooth 
devices visible from your board:

<pre class="minicom">
debarm:~# hcitool scan
Scanning ...
        00:25:48:FC:98:6D       Sergio
</pre>
		
On this list <b>Sergio</b> is my own mobile phone name and 
<b>00:25:48:FC:98:6D</b> is its Bluetooth unique address 
(<a href="http://linuxcommand.org/man_pages/hcitool1.html">learn more about hcitool...</a>).

Let's try to check which services are available on my mobile phone typing:

<pre class="minicom">
debarm:~# sdptool search OPUSH 00:25:48:FC:98:6D                                
Inquiring ...                                                                   
Searching for OPUSH on 00:25:48:FC:98:6D ...                                    
Service Name: OBEX Object Push                                                  
Service RecHandle: 0x1000a                                                      
Service Class ID List:                                                          
  "OBEX Object Push" (0x1105)                                                   
Protocol Descriptor List:                                                       
  "L2CAP" (0x0100)                                                              
  "RFCOMM" (0x0003)                                                             
    Channel: 6                                                                  
  "OBEX" (0x0008)                                                               
Language Base Attr List:                                                        
  code_ISO639: 0x454e                                                           
  encoding:    0x6a                                                             
  base_offset: 0x100                                                            
Profile Descriptor List:                                                        
  "OBEX Object Push" (0x1105)                                                   
    Version: 0x0100
</pre>
	
<a href="http://en.wikipedia.org/wiki/OBject_EXchange">OBEX</a> 
is the first service we'll use to do the first experiment and it is on the 
<b>Channel 6</b>.

OBEX (abbreviation of OBject EXchange) is a communications protocol 
that facilitates the exchange of binary objects between devices. 
<a href="http://dev.zuckschwerdt.org/openobex/">OpenOBEX</a>, an 
open source implementation of the OBEX protocol, is used on the 
Debian Linux distribution.

##Send an image to your mobile phone

Let's try to use OBEX to send an image to our Bluetooth mobile phone.

Download on your FOX this image:

<img src="./tuxcase.jpg">

typing:


<pre class="minicom">
wget http://terzo.acmesystems.it/download/examples/tuxcase.jpg          
--2010-08-20 13:55:19--  http://terzo.acmesystems.it/download/examples/tuxcase.jpg
Resolving www.acmesystems.it... 78.47.10.198                                    
Connecting to terzo.acmesystems.it|78.47.10.198|:80... connected.                 
HTTP request sent, awaiting response... 200 OK                                  
Length: 4710 (4.6K) [image/jpeg]                                                
Saving to: `tuxcase.jpg'                                                        
                                                                                
100%[======================================>] 4,710       --.-K/s   in 0.07s    
                                                                                
2010-08-20 13:55:20 (69.0 KB/s) - `tuxcase.jpg' saved [4710/4710]               
                                                                                
debarm:~# 
</pre>

Now install <b>ObexFtp</b> an utility to transfer files using the 
OBEX protocol (learn mode about 
<a href="http://dev.zuckschwerdt.org/openobex/wiki/ObexFtp">ObexFtp...</a>).

<pre class="minicom">
debarm:~# apt-get install obexftp
...
</pre>

then send the Tux to your mobile phone typing:

<pre class="minicom">
debarm:~# obexftp --nopath --noconn --uuid none --bluetooth 00:25:48:FC:98:6D --channel 6 -p tuxcase.jpg 
Suppressing FBS.
Connecting..\done
Tried to connect for 628ms
Sending "tuxcase.jpg"...|done
Disconnecting../done
</pre>

#Enable the Linux Kernel Bluetooth support on Aria G25

<pre minicom>
$ make ARCH=arm menuconfig
[*] Networking support  --->
  <*>   Bluetooth subsystem support  ---> 
     --- Bluetooth subsystem support
       [*]   L2CAP protocol support
       [ ]   SCO links support (NEW)
       <*>   RFCOMM protocol support
       [ ]     RFCOMM TTY support (NEW)
       < >   BNEP protocol support (NEW)
       < >   HIDP protocol support (NEW)
       Bluetooth device drivers  --->
			<*> HCI USB driver
			< > HCI SDIO driver
			<*> HCI UART driver
			[ ]   UART (H4) protocol support (NEW)
			[ ]   BCSP protocol support (NEW)
			[ ]   Atheros AR300x serial support (NEW)
			[ ]   HCILL protocol support (NEW)
			< > HCI BCM203x USB driver (NEW)
			< > HCI BPA10x USB driver (NEW)
			< > HCI BlueFRITZ! USB driver (NEW)
			< > HCI VHCI (Virtual HCI device) driver (NEW)
			< > Marvell Bluetooth driver support (NEW)
			< > Atheros firmware download driver (NEW)
</pre>

@include='bio_tanzilli'
