Linux操作系统上蓝牙耳机的配置方法介绍

来源:岁月联盟 编辑:zhuzhu 时间:2007-08-16
Linux操作系统上蓝牙耳机的配置方法介绍内容简介:由于经常使用SKYPE聊天打电话,一直觉得被拴在电脑前面不是很自由,终于在一个周末,一激动买了一个蓝牙耳机。经过几天的努力在Linux/Debian上用了起来,现在就把这个配置过程和大家分享。 第一 了解蓝牙 蓝  

由于经常使用SKYPE聊天打电话,一直觉得被拴在电脑前面不是很自由,终于在一个周末,一激动买了一个蓝牙耳机。经过几天的努力在Linux/Debian上用了起来,现在就把这个配置过程和大家分享。

  第一 了解蓝牙

  蓝牙是爱立信的提出的一个近距离的无线通讯协议,由于没有INTEL的支持,它的发展一直都不是很快,在蓝牙不多的应用中,用得最多就是无线的HEADSET.其他应用还有MOUSE,CAMERA. 蓝牙耳机主要有两种PROFILE,一般用的都是Headset profile它是单声道的音频,质量只能用于做打电话。新的Advance Audio Distribution Profile 支持立体声,用来听音乐没有问题(发烧友除外)

  bluetooth 的LINUX的STACK主要有两个 Affix 和 BlueZ,我使用的是后一种。

  参考1 linux.html">http://www.tuxmobil.org/bluetooth_linux.html

  第二 环境

  thinkpad X31

  debian sarge,

  linux kernel 2.6.11

  USB Bluetooth  1.1 adaptor  (不记得是哪个公司的东东了)

  plantronic M3000 BT Headset

  第三 kernel setting

  我喜欢用比较新的KERNEL,因为低版本的经常需要打很多PATCH,很不方便。不过如果你很经常的自做debian的包,还是用sarge带的kernel.

  in Kernel 2.6

  Device Driver ->Networking Support ->(M) Bluetooth Sub system Support

  我用的是USB的adaptor所以我没有选PC卡,如果你是用的PC卡,应该把它们选上。

  第四 下载DEBIAN的BLUETOOTH的包

  你可以用apt-cache search bluetooth看一下SARGE下的和蓝牙有关的包。

  我安装了

  ii  bluez-cups     2.15-1         Bluetooth printer driver for CUPS

  ii  bluez-hcidump  1.17-1         Analyses Bluetooth HCI packets

  ii  bluez-pcmcia-s 2.15-1         PCMCIA support files for BlueZ 2.0 Bluetooth

  ii  bluez-pin      0.25-1         Bluetooth PIN helper with D-BUS support

  ii  bluez-utils    2.15-1         Bluetooth tools and daemons

  ii  libbluetooth1  2.15-2         Library to use the BlueZ Linux Bluetooth sta

  ii  libbluetooth1- 2.15-2         Development files for using the BlueZ Linux

  第五 下载KDE或者GNOME下的蓝牙的图形化管理工具

  GNOME

  http://usefulinc.com/software/gnome-bluetooth/

  APT的地址: deb http://debian.usefulinc.com/gnome ./

  如果你有蓝牙的电话,你还可以在上面的网站上找到phone manager

  http://usefulinc.com/software/phonemgr/

  我没有支持蓝牙的手机,所以没有测试它

  KDE

  http://kde-bluetooth.sourceforge.net/

  DEB 包 http://fred.hexbox.de/debian/

  deb http://fred.hexbox.de/debian ./

  第六 蓝牙的配置文件

  蓝牙的配置文件位于/etc/bluetooth目录下面。

  

hcid.conf
  # 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 user;

 

 

  这里最好改成user 一般的耳机在连接时都需要输入PIN,虽然第二次,选auto有时,经常会出现连不上死在那里的情况。

       

# Pairing mode
        #   none  - Pairing disabled
        #   multi - Allow pairing with already paired devices
        #   once  - Pair once and deny successive attempts
        pairing multi;
        # PIN helper
        #pin_helper /usr/bin/bluez-pin;
        pin_helper /usr/lib/kdebluetooth/kbluepin;

 

 

  我用的是kde的蓝牙的framework,

  pin helper,的作用是在蓝牙设备需要输入密码时,弹出对话框让你让打密码。

       

# D-Bus PIN helper
        #dbus_pin_helper;
}
# Default settings for HCI devices
device {
        # Local device name
        #   %d - device id
        #   %h - host name
        name "%h-%d";
        # Local device class
        class 0xff0100

 

  oxff0100的意思是接受任何种类的蓝牙设备的连接,

  0x200404  是指只接受audio/video device类的设备连接。

  这个主要用于你有多台蓝牙设备时,想控制他们的互相连接时使用.

  例如你有两台电脑,一个手机都带有蓝牙,而你只想让电话连到一台脑上,就可以使用这种方法来设置。

       

# 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;
        # Authentication and Encryption (Security Mode 3)
        auth enable;
        #encrypt enable;

 

  感觉还是打开验证的比较好,选AUTO,BT会记住以前的PAIR, 在连接蓝牙设备时,如果以前PAIR过了,就会直接用以前记住的PIN去连接,这个看上去不错,但我用下了经常会有连不上的情况。

  }

  第六 安装蓝牙耳机的音频程序

  前提:你的linux应该使用的是ALSA的音频系统。

  http://cgi.sfu.ca/~jdbates/debian/pool/bluetooth-alsa/

  deb包  deb http://cgi.sfu.ca/~jdbates/debian/ . .

  bluetooth-alsa_200503090-1_i386.deb   2005年5月19日

  这个包会装安装btsco的应用程序。

  现在我们还需要一个驱动程序。snd-bt-sco

  1.到bluetooth-alsa项目的主页去下载源程序 或从CVS中下最新的代码。

  http://bluetooth-alsa.sourceforge.net/

  从CVS中可以得到最新的程序

  cvs -d:pserver:anonymous@cvs.sf.net:/cvsroot/bluetooth-alsa login

  cvs -d:pserver:anonymous@cvs.sf.net:/cvsroot/bluetooth-alsa co btsco

  编译前需要的包

  

automake-1.7
  libbluetooth-dev (aka libbluetooth-devel or bluetooth-devel)
  libasound2-dev (aka alsa-devel)

 

 

  2.Compile:

       

 ./bootstrap
        ./configure
        make
        make install
        make maintainer-clean

 

 

  3. snd-bt-bco需要一个snd_hwdep_new的内核模块。 你可以通过在编辑内核时选上 emu10k1强行编译上面的内核模块。

  

device drivers ——> sound ——>Advance Linux sound Architecture——>PCI devices
  ——>(M)Em10k1
  make
  make modules_install

 

 

  4.编译snd-bt-sco

  到btsco/kernel目录下面

  cd kernel

  make

  make install

  depmod -e

  make clean

  默认的状态下会安装在/lib/modules/2.6.X/extra/目录下面。

  第七 使用蓝牙耳机

  1.modprobe snd_bt_sco

  2.hciconfig hci0 voice 0x0060

  3.btsco bdaddress

  这里需要填的是蓝牙的MAC地址

  这可以通过让你的蓝牙耳机处在查询状态。然后用hcitool scans就可以找到你的耳机,同时看到它的MAC地址。

  #hcitool scan

  Scanning ……

  第七 使用蓝牙耳机

  1.  连接

  hci scan

         00:03:89:4C:3A:2E       M3000 by Plantronics

  btsco 00:03:89:4C:3A:2E

  连接建立后,蓝牙耳机会被的音频设备会被映射到/dev/dsp1

  2 使用aplay 和arecord 测试蓝耳机

  你需要安装alsaplayer.

  aplay  -D plughw:Headset sound.wav 可以向蓝牙耳机播放音乐,

  一般需要按一下蓝牙耳机的接听键。

  录音 一般用

  arecord -d 10 -f cd -t wav -D plughw:Headset  record.wav

  alsaplayer的具体用法 man 一下吧。

  arecord -d 10 -f cd -t wav -D plughw:Headset  record.wav

  3 在SKYPE下使用蓝牙耳机

  只需把SKYPE的hand/handset变成/dev/dsp1就可以使用蓝牙的耳机了。

  4 XMMS

  LINUX下一个像 winamp的音乐播放器。 你也可以找到他的配置页,让他通过/dev/dsp1来播放音乐。

  5 立体声

  最新一些耳机支持Advance Audio Distribution Profile

  播放的质量和一般的MP3差不多,由于我的耳机不支持这个PROFILE,所以没有测试。

  6 音质

  前前后后花了大约三个晚上6个小时,但是最后的音质还是让我觉得有点失望。M3000录音时有点噪音,根本无法和有线的HEADSET相比,不过上网查了一下,M3000好像是问题很多,哎,当初就因为它的包装上写着有降噪的话筒,看来这个周末要处理掉它。