Linux下蓝牙耳机的配置与测试

Linux下蓝牙耳机的配置与测试


一、在kernel中启动蓝牙支持

在kernel中使用.config作kernel setting
Device Driver -> Networking Support -> (M) Bluetooth Sub system Support

二、安装软件包

yum -y install bluez bluez-libs bluez-utils
在rpm.pbone.net下载btsco软件包,并安装:
sudo rpm -ivh btsco-0.5-39.i486.rpm

三、安装gnome下的蓝牙图形化管理工具

yum -y install gnome-bluetooth

四、修改蓝牙配置文件

进入/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码,一般默认为0000或者1234

# 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;
#pin_helper的作用是在蓝牙涩会被需要输入密码时,弹出对话框让你打开密码。fedora上的bluez-pin未找到,待确定。可以装bluez-pin包:
# http://archive.fedoraproject.org/pub/archive/fedora/Linux/core/5/source/SRPMS/repodata/repoview/bluez-pin-0-0.30-2.html

#D-Bus PIN helper
#dbus_pin_helper;
}

# Defalut settings for HCI devices
device {
# Local device name
# %d – device id
# %h – host name
name “%h-%d”;

# Local device class
class 0xff0100
# 0xff0100 指接收任何种类的蓝牙设备的连接;
# 0×200404 指只接收audio/video device类型的设备连接。

# Default packet type
# pkt_type DH1, DM1, HV1;
# Inquiry and Page scan
iscan enable; pscan enable;

# Defalut 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;
}
完成之后,重启蓝牙服务:
service bluetooth stop
service bluetooth start

五、挂载蓝牙相关模块并启动蓝牙

1.挂载sco模块

cd /lib/modules/`uname -r`/kernel/net/bluetooth/
modprobe sco.ko

2.增加声音的SDP宣告

hciconfig hci0 up #这部分不做,下边的扫描无法运行
hciconfig hci0 voice 0×0060

3.扫描蓝牙并获取MAC地址

hcitool scan

4.蓝牙配对

hcitool cc 00:21:19:A4:E0:F1

5.将蓝牙耳机绑定到相应地址上

btsco bdaddress
bdaddress是蓝牙的MAC地址
连接后输入PIN码。此时,蓝牙耳机的音频设备会被映射到/dev/dsp1,可以通过ls -l /dev/dsp1查看。

六、测试与使用蓝牙耳机

1.用alsaplayer播放向蓝牙耳机播放音乐

aplay -D plughw:Headset sound.wav
按蓝牙耳机接听键

2.arecord录音

arecord -d 10 -f cd -t wav -D plughw:Headset record.wav
plughw:Headset指明是从耳机播放,只是单声道的声音非常差。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值