HanishKVC’s General Blog zone

May 16, 2007

Short and simple commandline Bluetooth in any new Linux distros

Filed under: bluetooth,debian,linux,Nokia,OpenSource,technology — hanishkvc @ 7:22 pm

Yesterday I had to transfer some files/S60 Opensource programs to my Nokia 6630 mobile and so picked up my usb bluetooth dongle (after ages) and connected to my Linux PC to achieve the same. I had forgotten the things which I had done long time back to get it working (Also one of these days I have to find out where I had noted those steps down).

Either way I started by remembering that I have to try and use obex logic to put those files on the mobile (now come on remembering that isn’t that difficult;-). Soon I remembered most of the things to do through aptitude search/show bluetooth/bluetooth packages, dpkg -L <bluetooth related packages>, some trail_N_error and net searching (googling).

But to my horror what ever I do the connection wouldn’t establish has the bluetooth stack on the PC wasn’t pickup the PIN which I just configured on the PC. After some more rtfm and dpkg -L bluez-utils and cross verification on the bluez website I realised that the way the PIN to be used is specified to the bluetooth stack has changed on the PC and now instead of the pin_handler it uses a dbus based passkey handler. So I compiled the given passkey_agent.c and resolved it. And thus could achieve the file transfer without going into windows thou with some deficit of sleep ;-)

So here are the commands one could use to work with bluetooth devices in a linux based pc =>

hciconfig
– Gives info about the bluetooth hci on your pc
– Ensure the device is up and running and has required scan modes
– hcitool dev should also give some of this info

hcitool inq and hcitool scan
– Gives info about or rather identifies nearby bluetooth devices

hcitool info <BTAddr>
– Get info about remote bluetooth device

l2ping <BTAddr>
– One way to see if we can communicate with a remote bluetooth device

sdptool browse <BTAddr> or sdptool records <BTAddr>
– Gives info about the services provided by a remote bluetooth device

obexftp –nopath –noconn –uuid none –bluetooth <BTAddr> –channel <OPUSHChann
elNo> –put <FileToPut>
– Allows one to send file without specifying the pin on the remote device side
– The OPush channel number for device is got from sdptool above

passkey-agent –default <Pin>
– Pin specified here is what the remote BT device should provide
or its user enter on that device when requested.

obexftp -b <BTAddr> -v -p <FileToPut>
– Allows one to put a file onto the specified BT device
– obexftp could also be used to get or list the files on the BT device
– also allows one to identify a nearby BT device by just giving -b option

obexpushd
– Allows one to recieve files sent from a bluetooth device.
– Depending on who started it, the recieved files will be stored in the corresponding home directory

Note: The old style pin_handler doesn’t work with latest bluez, you require a
dbus based passkey handler and there is one provided by default by bluez-utils
called passkey-agent
Hope this helps anyone who is trying to use bluetooth devices from the commandline on a new linux distro, as well as it would help me to remember for the future for my own use.

About these ads

6 Comments »

  1. Thanks, this really helped me out a lot. I’m surprised obexftp works the way it does, responding with XML to one command at a time instead of presenting a more familiar ftp interface.

    Comment by Gabriel Farrell — July 4, 2008 @ 5:11 pm | Reply

  2. Nice post :)
    I’ve thrown together an ugly script to automate sync (a dumb enough sync) of files from my phone.
    And make an ugly blog post about the ugly script also:

    http://gaoithe.livejournal.com/33541.html

    It would be nice to sync properly like rsync (i.e. check files size and date/times on host and device).
    It would be nice to use rsync itself! :)
    Possibly obexftp could be improved, commands like “get-if-changed, put-if-not-up-to-date”, recursive ability.
    Hmm. Hmm.

    Comment by James Coleman — September 3, 2009 @ 12:32 am | Reply

  3. I meant to say in reply to Gabriel:
    You can pass multiple (lots of!) files to get or delete or put at one time to obexftp.
    Maybe that is because it is now 2009!?
    I’m using ObexFTP 0.19

    Comment by James Coleman — September 3, 2009 @ 12:41 am | Reply

  4. [...] – Backtrack – Oracle WM Virtualbox – MacBook Pro Well you must not have searched very hard. Short and simple commandline Bluetooth in any new Linux distros Try the above for starters. Reply With Quote   + Reply to Thread [...]

    Pingback by Bluetooth - Backtrack - Oracle WM Virtualbox - MacBook Pro — June 11, 2010 @ 7:56 pm | Reply

  5. How to set default passkey using passkey-agent.c

    I tried i got error output

    root /home/dhana013/passkey # ./passkey-agent –default 1234
    Can’t register passkey agent
    Method “RegisterDefaultPasskeyAgent” with signature “s” on interface “org.bluez.Security” doesn’t exist

    How to resolve this issue, please guide me…

    Comment by Dhanasekaran Anbalagan — September 9, 2011 @ 2:42 pm | Reply

  6. chintan@chintan-ubuntu:~$ obexftp -b BC:CF:CC:1D:87:4D -B 12 -put /home/ck.txt
    Browsing BC:CF:CC:1D:87:4D …
    Connecting…failed: connect
    Tried to connect for 4ms
    error on connect(): Invalid argument
    Still trying to connect
    Connecting…failed: connect
    Tried to connect for 3ms
    error on connect(): Invalid argument
    Still trying to connect
    Connecting…failed: connect
    Tried to connect for 3ms
    error on connect(): Invalid argument
    Still trying to connect

    Hello help me to solve this error …for sending a file through command window,…

    Comment by chintan — April 7, 2014 @ 11:57 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: