Sunday, September 24, 2006

Step by Step Blutooth in Fedora 5

Require Packages

->bluez_libs_2.25_1
->gnome_bluetooth_libs-0.7.0_2
->bluez_pin=0.30-2
->bluez_utils_2.25-4
->kdebluetooth_1.0_0.14.svn 20060621.fc5
(great tool for transfering data from mobile to pc and pc to mobile)
->openbex_1.1_1

(Other packages might be requied like bluez_sdp,bluez_pan,bluez_hcidump,bluez_bluefw but works fine without all these)

If your kernel version is greater than 2.6 all is set.

1. hcid daemon should be running

2. Examining local devices

# hciconfig -a
hci0: Type: USB
BD Address: 00:80:98:24:15:6D ACL MTU: 128:8 SCO MTU: 64:8
UP RUNNING PSCAN ISCAN
RX bytes:4923 acl:129 sco:0 events:168 errors:0
TX bytes:2326 acl:87 sco:0 commands:40 errors:0
Features: 0xff 0xff 0x05 0x00
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: HOLD SNIFF PARK
Link mode: SLAVE ACCEPT
Name: 'saag-0'
Class: 0x100100
Service Classes: Object Transfer
Device Class: Computer, Uncategorized
HCI Ver: 1.1 (0x1) HCI Rev: 0x73 LMP Ver: 1.1 (0x1) LMP Subver: 0x73
Manufacturer: Cambridge Silicon Radio (10)

3. Scanning for remote Devices

# hcitool scan
Scanning …
00:15:A0:51:9A:6B ED P800
00:40:05:D0:DD:69 saag-1

4. Paring between mobile and PC

PIN is located in /etc/bluetooth/pin

note:
In some distributions of bluez-utils, the PIN code is set to the alphabetical string BlueZ. This is troublesome, because many Bluetooth devices, including most cell phones, are capable of delivering only numeric PINs. It is therefore recommended that you alter the contents of /etc/bluetooth/pin to reflect a numeric code.


5. Pinging Remote Device (as root)
The ping command is an incredibly useful tool for discovering whether remote computers are reachable over a TCP/IP network. BlueZ has an analog to ping, called l2ping. Its name refers to the fact that it attempts to create a connection to the device using the logical link control and adaptation protocol (L2CAP), the lowest-level link-based protocol in Bluetooth

# l2ping 00:15:A0:51:9A:6B
Ping: 00:15:A0:51:9A:6B from 00:80:98:24:15:6D (data size 20) …
0 bytes from 00:15:A0:51:9A:6B id 200 time 54.85ms
0 bytes from 00:15:A0:51:9A:6B id 201 time 49.35ms
0 bytes from 00:15:A0:51:9A:6B id 202 time 34.35ms
0 bytes from 00:15:A0:51:9A:6B id 203 time 28.33ms
4 sent, 4 received, 0% loss

6. Connect a Linux Computer

Determine the RFCOMM service is available

$ sdptool browse
00:60:57:50:AB:9C


Service Name: Dial-up Networking
Service Description: Dial-up Networking
Service Class ID List:
"Dialup Networking" (0x1103)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 1

# rfcomm bind 0 00:15:A0:51:9A:6B 1

# rfcomm
rfcomm0: 00:60:57:50:AB:9C channel 1 clean

7. Create a file /etc/ppp/peers/btnokia

# File: /etc/ppp/peers/btnokia
#
/dev/rfcomm0 # The Nokia phone
115200 # speed
defaultroute # use the cellular network for the default route
usepeerdns # use the DNS servers from the remote network
nodetach # keep pppd in the foreground
nocrtscts # no hardware flow control
lock # lock the serial port
noauth # don't expect the modem to authenticate itself
local # don't use Carrier Detect or Data Terminal Ready

connect "/usr/sbin/chat -v -f /etc/chatscripts/connect"
disconnect "/usr/sbin/chat -v -f /etc/chatscripts/disconnect"

If you use the USB data cable, the connection script could look something like the following:

# File: /etc/ppp/peers/usbnokia
#
/dev/ttyUSB0 # USB-serial port to the Nokia phone
230400 # speed
defaultroute # use the cellular network for the default route
usepeerdns # use the DNS servers from the remote network
nodetach # keep pppd in the foreground
crtscts # hardware flow control
lock # lock the serial port
noauth # don't expect the modem to authenticate itself

connect "/usr/sbin/chat -v -f /etc/chatscripts/connect"
disconnect "/usr/sbin/chat -v -f /etc/chatscripts/disconnect"

8. The connect and disconnect script will be like these :

#file connect

TIMEOUT 5
ECHO ON
ABORT '\nBUSY\r'
ABORT '\nERROR\r'
ABORT '\nNO ANSWER\r'
ABORT '\nNO CARRIER\r'
ABORT '\nNO DIALTONE\r'
ABORT '\nRINGING\r\n\r\nRINGING\r'
'' ATZ
OK ATH
OK ATE1
OK 'AT+CGDCONT=1,"IP","internet","",0,0'
OK ATD*99#

#file disconnect
"" "\K"
"" "+++ATHO"
SAY "GPRS disconnected"

9. Now connect to the Internet

#ppd call btnokia

Do this first for confirmation

#/etc/rc.d/init.d/bluetooth restart
Shutting down Bluetooth [ok]
Starting Bluetooth [ok]

#rfcomm
rfcomm0 00:15:A0:51:9A:6B


Congrate your gprs shoud be running from your mobile.

10. Automatic binding of rfcomm

#file /etc/bluetooth/rfcomm.conf

rfcomm0 {
# Automatically bind the device at startup
bind yes;

# Bluetooth address of the device
device 00:15:A0:51:9A:6B;

# RFCOMM channel for the connection
channel 1;

# Description of the connection
comment "Nokia 6630";
}

11. Automatically connect to the phone with bluetooth RFCOMM at startup
-put rfcomm bind all command to the end of start function in /etc/rc.d/init.d/bluetooth and rfcomm realease all command to he end of stop function
like as :

start()
{
echo -n $"Starting $prog: "
daemon /sbin/hcid

if [ -x /usr/sbin/sdpd ]; then
daemon /usr/sbin/sdpd
fi

start_uarts
touch /var/lock/subsys/bluetooth
# bind all rfcomm connectins from /etc/bluetooth/rfcomm.conf
rfcomm bind all
echo
}
stop()
{
echo -n $"Shutting down $prog: "
killproc hcid

if [ -x /usr/sbin/sdpd ]; then
killproc sdpd
fi

stop_uarts
rm -f /var/lock/subsys/bluetooth

# release all rfcomm connections
rfcomm release all
echo
}

11. To automatically start Bluetooth at boot time, add a symlink from the corresponding runlevel directory to the bluetooth startup script.

#ln -s /etc/rc.d/init.d/bluetooth /etc/rc5.c/k90bluetooth

At this point, when the bluetooth daemons are up and running, it may be wise to pair the phone and the Linux host. With Nokia it goes something like this: start Bluetooth from the phone, scan for other Bluetooth hosts, select the Linux host, insert the correct pin (the same is in /etc/bluetooth/pin) and set the host as 'Authorized'. The authorized part means, that the phone does not ask for a pin code anymore. This is insecure but handy when testing the Bluetooth connection.

Plese feel free to comment on the post.

0 Comments:

Post a Comment

<< Home