arch 0.8, KDE, 用的是bluez的驱动,适用于2.6内核。
外部蓝牙设备是我的手机,W810c
如果你的内核不支持bluetooth,可能你需要打补丁然后重新编译内核,具体内容请参阅网上的相关资料,这里不再赘述
(顺带发现一个bluez的bug……--b)
$>pacman -S bluez-libs bluez-utils bluez-firmware kdebluetooth kdemobiletools
$>sudo /etc/rc.d/bluetooth start
这个时候你本机的bluetooth设备应该已经可以识别了
$>hciconfig -a
看看有没有东西出来?应该是一个hci0的设备,没有的话看看是不是设备没有启动?(T42要手动打开bt的,Fn+F5)bluetooth这个模块是不是没有加载?
然后打开你的外围设备上的Bt(我的W810c)
$>hcitool scan
应该会输出一个bt地址,类似12:23:34:45:AB:56的形式,记下来
$>sdptool browse <你上面获得的地址>
这样就会刷出你机器上支持的服务列表,类似
Service Name: OBEX SyncML Client
Service RecHandle: 0x10001
Service Class ID List:
UUID 128: 00000002-0000-1000-8000-0002ee000002
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 1
"OBEX" (0x0008)
那个Channel的数字跟服务是对应的。待会儿连接的时候要用到,也记下来。
$>vim /etc/bluetooth/hcid.conf
########################### hcid.conf #########################
#
# HCI daemon configuration file.
#
# HCId options
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
# The passkey defined here WILL NOT WORK AT ALL :-(
passkey "0000";
#pin_helper /opt/kde/lib/kdebluetooth/kbluepin;
}
# Default settings for HCI devices
device {
# Local device name
# %d - device id
# %h - host name
name "BlueZ (%d)";
# Local device class
class 0xff0100;
# 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 hold,sniff,park;
}
######################### End #############################
$>vim /etc/bluetooth/rfcomm.conf
######################## rfcomm.conf ######################
#
# RFCOMM configuration file.
#
# You can add as many rfcomm*'s here as you like :-)
rfcomm0 {
# # Automatically bind the device at startup
bind yes;
#
# # Bluetooth address of the device
device <your bluetooth device address here>
#
# # RFCOMM channel for the connection
channel 3; # You should try your channel here :-)
#
# # Description of the connection
comment "Whatever you want";
}
rfcomm1 {
bind yes;
device <your bluetooth device address here>
channel 8;
comment "Another channel";
}
######################## End #######################
别忘了把你的用户放到tty组里
$>sudo usermod -a -G tty $USER_NAME
重新登录一下,然后重启bluetooth服务
$>sudo /etc/rc.d/bluetooth restart
这个时候你的/dev下面应该出现了一个新的设备rfcomm*,这个就是用来跟bt设备通信用的dev,如果你是按照上面的配置文件来的,那么不会有什么问题。实际上,这个rfcomm是可以手动创建的。类似下面的命令(不要忘记权限)
[Optional] $>mknod /dev/rfcomm0 c 216 0
好了,现在可以连接,这里你用GUI也好,用命令行也好,都差不多。就是连接这一步,bluez有一个bug,这个bug折腾了我整整4个小时 :-(
我们都知道蓝牙设备在连接的时候需要一个认证key的过程,两台蓝牙设备需要使用相同的key才可以连接,这个机制在bluez里面是通过一个passkey-agent的程序辅助完成的,passkey-agent向蓝牙模块注册一个pin-helper或者是一个key,用来帮助检测key的正确性,然而,目前的bluez无法调用passkey-agent注册任何pin-helper或者是key!从系统
日志里面看到的消息类似于:
can't register key-agent:/org/bluez/pinhelper doesn't exits
很明显,你的机器上应该不会存在/org/bluez/pinhelper这么奇怪的东西,这个应该是bluez的一个bug,大概是某位个指定路径的变量写错了。。。。
既然bluez无法自己调用,那么我们手动来。这里我用的是kdemobiletools,一个在kde下连接手机的东东。
1 启动KMobileTools
2 把连接设成/dev/rfcomm* (就是rfcomm.conf里面建的东西,随便哪个)
3 其他我都没有改过,目前还不是很懂其他选项都是什么意思。。。
4 然后OK
如果前面的步骤都正确的华,这里你的bt设备应该已经被发现了,然后会要你输入pin码,不要急,去控制终端运行一下这个命令
$>sudo passkey-agent 0000 <your bt address>
然后在设备里输入0000,就可以正常连接了。这个0000随便你换成其他的什么东西。只要保证两边输入的都一样就行了。
哈哈,搞定!
PS:控制台连接方法
$>rfcomm connect <rfcomm number, 0 or sth.> <your bt address> <channel id>
======================== 华丽的分割线 =======================
目前的问题还是很多的
1 编码问题。我的W810的电话簿导入KDE后全是乱码……--bb
2 每次都要手动输入一个passkey-agent,实在是麻烦……
3 对于bt设备的支持还不是很好,我的手机还是没办法发短信
4 毕竟是第三方的东东,不知道对自己的设备会不会造成损害……(这个算是杞人忧天吧,呵呵)
5 因为那个agent的问题,现在我的电脑只能主动发现别人,而不能被别人发现。。。
======================= 我是不会被[屏蔽]的分割线 ====================
写得还是很乱很简略的,详细的内容还需要大家自己发掘一下
hcitool sdptool rfcomm hciconfig hcid.conf
这个几个东西的man最好都看一边,其实还是很简单的。
