Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- BTADAPTER=""
- function set_default_adapter() {
- RV=$(dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter)
- if [ $? -ne 0 ]; then
- return -1
- fi
- BTADAPTER=$(echo $RV | sed 's/^.*"\(.*\)".*$/\1/')
- return 0
- }
- if ! set_default_adapter ; then
- echo "error: cannot get default bluetooth adapter"
- exit 1
- fi
- if [ "$1" == "scan" ]; then
- hcitool scan
- elif [ "$1" == "list" ]; then
- for mac in `dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.bluez.Adapter.ListDevices | grep dev_ | sed 's/.*dev_\(.*\)\"/\1/' | tr _ :`; do
- cat /var/lib/bluetooth/*/names | grep $mac
- done
- elif [ "$1" == "names" ]; then
- cat /var/lib/bluetooth/*/names
- elif [ "$1" == "trusts" ]; then
- cat /var/lib/bluetooth/*/trusts
- elif [ "$1" == "props" ]; then
- if [ "$2" == "" ]; then
- echo "usage: $1 props 11:22:33:44:55:66"
- exit 1
- fi
- BTDEV=$(echo $2 | tr '[:lower:]' '[:upper:]' | tr : _)
- dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_$BTDEV org.bluez.Device.GetProperties
- elif [ "$1" == "remove" ]; then
- if [ "$2" == "" ]; then
- echo "usage: $1 remove 11:22:33:44:55:66"
- exit 1
- fi
- BTDEV=$(echo $2 | tr '[:lower:]' '[:upper:]' | tr : _)
- if ! dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.bluez.Adapter.RemoveDevice objpath:$BTADAPTER/dev_$BTDEV >/dev/null 2>&1 ; then
- echo "failed to remove $2"
- exit 1
- fi
- echo "success"
- elif [ "$1" == "pair" ]; then
- if [ "$2" == "" ]; then
- echo "usage: $1 pair 11:22:33:44:55:66"
- exit 1
- fi
- echo "pairing with $2 ..."
- if ! /hacks/bin/agent 0000 "$2" ; then
- echo failed
- exit 1
- fi
- echo "success, setting $2 as trusted ..."
- BTDEV=$(echo $2 | tr '[:lower:]' '[:upper:]' | tr : _)
- if ! dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_$BTDEV org.bluez.Device.SetProperty string:Trusted variant:boolean:true >/dev/null 2>&1 ; then
- echo "failed"
- exit 1
- fi
- echo "ok"
- elif [ "$1" == "ping" ]; then
- if [ "$2" == "" ]; then
- echo "usage: $1 ping 11:22:33:44:55:66"
- exit 1
- fi
- l2ping "$2"
- else
- echo "usage: $0 [scan|list|names|trusts|props|remove|pair|ping]"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement