安装 bluez-utils工具包,以确保一下命令可用:
hciconfig;hcitool;sdptool;obex_test
安装蓝牙工具包:
#pacman -S bluez-utils
然后使用一下命令查看蓝牙设备:
#hciconfig -a
hci0: Type: USB
BD Address: 00:23:4D:F6:7A:04 ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:9292 acl:168 sco:0 events:220 errors:0
TX bytes:3331 acl:134 sco:0 commands:65 errors:0
Features: 0xff 0xff 0x8f 0xfe 0x9b 0xff 0x79 0x83
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy:
Link mode: SLAVE ACCEPT
Name: 'ThinkPad Bluetooth 2.1 with Enhanced Data Rate'
Class: 0x000000
Service Classes: Unspecified
Device Class: Miscellaneous,
HCI Ver: 2.1 (0x4) HCI Rev: 0x518f LMP Ver: 2.1 (0x4) LMP Subver: 0x424c
Manufacturer: Broadcom Corporation (15)
如果蓝牙设备的状态为down,需要将该设备启动;
#hciconfig hci0 up
查看附近的蓝牙设备:
#hcitool scan
Scanning ...
00:1F:5D:87:0C:40 Ruby
根据一下命令查看一下OBEX Object Push服务是否存在:
#sdptool search OPUSH
Inquiring ...
Searching for OPUSH on 00:1F:5D:87:0C:40 ...
Service Name: OBEX Object Push
Service RecHandle: 0x10098
Service Class ID List:
"OBEX Object Push" (0x1105)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 9
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"OBEX Object Push" (0x1105)
Version: 0x0100
根据以上显示的Channel号9,输入一下命令:
#obex_test -b 00:1F:5D:87:0C:40 9
Using Bluetooth RFCOMM transport
OBEX Interactive test client/server.
> c
Connect OK!
Version: 0x10. Flags: 0x00
> p a
PUT file (local, remote)> a a
name=a, size=18
Going to send 18 bytes
PUT successful!
这样在Archlinux下配置bluetooth就初步成功了!!!
-------------------------------------------
可参考一下脚本:bt
#!/bin/bash
# Version:0.1
# --------------------------------
# root user to run this script
# --------------------------------
if [ $UID -ne 0 ];then
echo "Must be root to run! "
exit 9
fi
# --------------------------------
# get bluetooth name & status
# --------------------------------
BTName=$(hciconfig|sed -n '1p' |awk -F':' '{print$1}')
BTStatus=$(hciconfig |sed -n '3p'|tr [a-z] [A-Z])
# --------------------------------
# start up the bluetooth
# --------------------------------
if [ "$BTStatus" == "DOWN" ];then
#echo "++++"
hciconfig $BTName up >/dev/null
if [ $? -ne 0 ];then
echo "Start bluetooth failed!"
exit 9
fi
fi
# --------------------------------
# get other bluetooth by scanning
# --------------------------------
ScanBT=$(hcitool scan|grep -v "Scanning"|awk '{print$1}')
ChannelNumber=$(sdptool browse $ScanBT|awk 'BEGIN{FS=":"}{
if($0~/Service Name: OBEX Object Push/){
getline;
while($0!~/Channel:/){
getline;}
{print$2}
}
}'
)
#echo "Channel Number : $ChannelNumber"
# --------------------------------
# transformer the file on obex protocol
# --------------------------------
obex_test -b $ScanBT $ChannelNumber
------------------------------------
另总结的配额linux bluetooth步骤:
# 1: hciconfig wlan0 up
# 2: hcitool scan
# 3: sdptool browse DEV
# 4: rfcomm bind /dev/rfcomm0 DEV 9
# 5: ussp-push /dev/rfcomm0 local_file remote_file
阅读(4232) | 评论(0) | 转发(0) |