Gentoo Linux on T43 (16) 蓝牙传输文件
通过蓝牙,可方便的实现与其它设备交换文件,接驳蓝牙耳机,组建局域网,甚至利用蓝牙连接移动设备进行拨号。我的需求不多,仅实现了与其它蓝牙设备双向传输文件,下面是我用到的应用程序、方法以及资源。
配置内核
内核的配置参考了Thinkwiki。
应用程序
我用到了以下软件包:
- net-wireless/bluez-libs-3.36 (库文件)
- net-wireless/bluez-utils-3.36 (基础配置工具,蓝牙系统服务)
- dev-libs/openobex-1.3 (库文件)
- app-mobilephone/obex-data-server-0.3.2 (bluez-gnome依赖它)
- gnome-extra/gnome-vfs-obexftp-0.4 (bluez-gnome依赖它)
- net-wireless/bluez-gnome-0.28 (Bluetooth applet, 文件传输gui)
- net-wireless/gnome-bluetooth-0.11.0 (文件接收Daemon: gnome-obex-server)
- app-mobilephone/obexftp-0.22 (命令行文件传输工具)
Bluetooth applet 可以在蓝牙设备打开时自动运行,可以浏览附近的蓝牙设备,提供文件发送与接收的操作,并进行基础的蓝牙属性配置。
但Bluetooth applet的文件接收功能在我的电脑上遇到问题,无法收到其它设备的发送文件请求。为此需要安装 gnome-bluetooth,这事另外一个文件接收服务器(仅接收)。
obexftp 是一个命令行ftp工具,可选安装。
将以上软件包merge到系统,然会添加蓝牙的系统服务
# rc-update add bluetooth default
gnome-obex-server 不会跟随蓝牙设备的开启自动运行,可以将其加入Gnome的启动session,令其跟随系统启动运行。
再进行接下来的配置。
配置文件
编辑修改/etc/bluetooth/hcid.conf ,对照修改黄底色的部分,密码88888改成自己的。
options {
# Automatically initialize new devices
autoinit yes;
# Security Manager mode
# none - Security manager disabled
# auto - Use local PIN for incoming connections
# user - Always ask user for a PIN
#
security auto;
# Pairing mode
# none - Pairing disabled
# multi - Allow pairing with already paired devices
# once - Pair once and deny successive attempts
pairing multi;
# Default PIN code for incoming connections
passkey "88888";
}
# Default settings for HCI devices
device {
# Local device name
# %d - device id
# %h - host name
name "BlueZ (%d)";
# Local device class
class 0x000100;
# Default packet type
#pkt_type DH1,DM1,HV1;
# Inquiry and Page scan
iscan enable; pscan enable;
# Default link mode
# none - no specific policy
# accept - always accept incoming connections
# master - become master on incoming connections,
# deny role switch on outgoing connections
lm accept;
# Default link policy
# none - no specific policy
# rswitch - allow role switch
# hold - allow hold mode
# sniff - allow sniff mode
# park - allow park mode
lp rswitch,hold,sniff,park;
}
测试
配置完成之后,启动蓝牙系统服务。
# /etc/init.d/bluetooth start
此时应该可以看到Bluetooth applet出现在托盘,右键选择发送文件,选择浏览到的目标设备,应该可以测试成功。
然后测试接收文件,从系统工具中运行Bluetooth File Sharing (即bluetooth-obex-server),托盘会出现另外一个图标。此时从其它蓝牙设备选择向这部电脑发送文件,应该可以收到确认请求。
Toggle 蓝牙开关
为了方便的开启/关闭蓝牙,我将以下脚本添加到acpi的事件处理当中,可以利用Thinkpad 的Fn+F5 toggle 蓝牙的开关。
/etc/acpi/default.sh
00001005) # Fn + F5 (Bluetooth on/off) # 2006-03-07 <pille@struction.de> # # acpi called script to toogle bluetooth # # get current bluetooth state cat /proc/acpi/ibm/bluetooth |grep "^status:.*enabled" > /dev/null if [ $? == 0 ] ; then logger -t "$0" "bluetooth is on. switching it off." logger -t "$0" "disabling bluetooth." echo disable >/proc/acpi/ibm/bluetooth else logger -t "$0" "bluetooth is off. switching it on." logger -t "$0" "enabling bluetooth." echo enable >/proc/acpi/ibm/bluetooth fi ;;
有关acp事件处理,请参考Fn + Keys获得详细信息。
有关命令行工具
以下几个是比较常用的命令行工具。
hcitool
hcitool 可用于蓝牙设备扫描,连接,认证等操作。
$ hcitool scan
如果输出扫描到的蓝牙设备名是乱码,可能是蓝牙设备与电脑环境编码不一致,可尝试将UTF-8 编码转换到GBK:
$ hcitool scan |iconv -f utf-8 -t gbk
hciconfig
类似于ifconfig,可用于配置蓝牙设备,一般设备名为hci0。
# hciconfig hci0
下载
以上脚本包含在/etc/acpi/default.sh ,请根据自己的情况提取使用。参考资料


