简体   繁体   English

如何使用bluez库在蓝牙中测试sco数据包

[英]how to test sco packets in bluetooth using bluez library

Issue : Monitor sco packets between master and slave bluetooth. 问题:监视主从蓝牙之间的sco数据包。

Description of problem. 问题描述。 I have small in-house Bluetooth device (developed in Linux fedora OS) and is configured as slave device. 我有一个小型内部蓝牙设备(在Linux fedora OS中开发),并配置为从设备。

I am interested in following things: 我对以下事情感兴趣:

  1. Master to connect to our in-built device and establish an sco link. 掌握连接到我们的内置设备并建立sco链接。 How would I verify link is established? 我如何验证链接已建立?

  2. Master to send sco packets to slave and slave send back( loopback) the same packets to master. 主机将sco数据包发送到从属设备,从属设备将相同的数据包发回(回送)给主机。 Absolutely no idea how to do that? 绝对不知道该怎么做?

What I did so far: 到目前为止,我做了什么:

Well I have configured our in-built device to slave and successfully connected to windows laptop via bluetooth. 好吧,我已经将内置设备配置为从设备,并通过蓝牙成功连接到Windows笔记本电脑。

I have enabled headset profile in my in-house BT device and I can see headset icon on windows. 我已经在内部BT设备中启用了耳机配置文件,并且可以在Windows上看到耳机图标。

on Linux side via c++ code I have modified /etc/asound.conf to include mac-address of connected device( in my case windows laptop) . 在Linux上,通过c ++代码我修改了/etc/asound.conf,以包括连接设备的mac地址(在我的情况下是Windows笔记本电脑)。 sample is shown below 示例如下所示

pcm.btheadset {
   type plug
   slave {
       pcm {
           type bluetooth
           device DC:A9:71:8D:2D:C6
           profile "auto"
       }
   }

then play the sound on my in-house BT via command 然后通过命令在我的内部BT上播放声音

aplay -D btheadset " path of audio_file"

And I can successfully hear sound on my windows laptop. 而且我可以在Windows笔记本电脑上成功听到声音。

So far so good. 到现在为止还挺好。 Now when I do hciconfig -a 现在,当我执行hciconfig -a

acl packets have increase but sco remain at 0

RX bytes:1041 acl:456 sco:0 events:36 errors:0
TX bytes:1347 acl:567 sco:0 commands:34 errors:0
  1. Will this proof that audio is working but not via sco? 是否可以通过音频而不是通过sco来证明音频有效?
  2. I have found that I don't have btsco driver or hcid.conf file. 我发现我没有btsco驱动程序或hcid.conf文件。 Do you think that could be an issue? 您认为这可能是个问题吗?
  3. if my audio is working via sco could someone provide me an example of how to test via hcidump? 如果我的音频通过sco工作,有人可以给我提供如何通过hcidump测试的示例吗?
  4. how to loop it back to master? 如何将其循环回主机?

Note: 注意:
I did hcidump and save the file while music was playing. 音乐播放时,我做了hcidump并保存了文件。 I dump the save file in wireshark and use "bthci_sco" to filter packets and found no packets. 我将保存文件转储到wirehark中,并使用“ bthci_sco”过滤数据包,但未发现任何数据包。 Wondering then how does music works then? 那么想知道音乐如何运作吗?

After few days of struggle with Ubuntu crashing frequently finally it worked. 经过几天与Ubuntu频繁崩溃的斗争,终于成功了。

Below are the steps I have tried. 以下是我尝试的步骤。 Please take it as a reference as there is high chances that I might have forgotten to write some steps 请以它为参考,因为我很可能忘记编写一些步骤

................................................................................................... .................................................. .................................................
Overview of a problem: Trying to connect Linux OS to BT headset and to establish sco link to play music 问题概述:尝试将Linux OS连接到BT耳机并建立sco链接以播放音乐

UBuntu configuration: UBuntu配置:
Kernel version : 3.0.0-32-generic 内核版本: 3.0.0-32-generic
Ubuntu Verion ->11.10 Ubuntu版本 -> 11.10

Testing Device : JABRA EASY GO headset.. 测试设备: JABRA EASY GO耳机
.............................................................................. 1) Install above version of Ubuntu . ................................................... ............................ 1)安装以上版本的Ubuntu。 This Ubuntu version is out of support but since my in -house device use nearly same kernel version so I sticked with this version. 此Ubuntu版本已不受支持,但由于我的内部设备使用几乎相同的内核版本,因此我坚持使用该版本。

2) Configure apt-get sources list. 2)配置apt-get来源列表。 Since installed version is out of support , apt-get will not work. 由于安装的版本不在支持范围内,因此apt-get将无法正常工作。 To make it work, modify the /etc/apt/sources.list . 要使其工作,请修改/etc/apt/sources.list
example-> 例子->

sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

sudo apt-get update && sudo apt-get dist-upgrade

3) I would recommend to install synaptic as well to install packages and missing libraries. 3)我建议同时安装突触来安装软件包和缺少的库。

4) Install following packages --> 4) 安装以下软件包->

     bluez-hcidump 
     bluez-utils
     libbluetooth1 
     libbluetooth1-dev
     install automake-1.7 and autoconfig
     cvs

5) Google it to download source code of btsco or alternatively 5)谷歌下载btsco的源代码或替代

use following comand 使用以下命令

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

6) NOW COMPILING AND INSTALLING 6) 现在编译和安装

i) go to btsco directory i)进入btsco目录

ii) ./bootstrap issues: ii。./bootstrap问题:
if error/ warning: macro `AM_PATH_SDL' not found in library install libbsdl1.2-dev 如果错误/警告:在库安装libbsdl1.2-dev中找不到宏`AM_PATH_SDL'

once bootsrap passed execute configure ii) ./configure issues : 一旦bootsrap通过执行配置ii)./ configure问题:

  1. if bluetooth/bluetooth .h missing -> install libbluetooth-dev 如果缺少蓝牙/蓝牙.h->安装libbluetooth-dev
  2. package requirement dbus-1>=0.36 not meet & dbus-glib not found -->install libdbus-glib-1-dev 软件包要求dbus-1> = 0.36不满足&找不到dbus-glib->安装libdbus-glib-1-dev

iii) make iii)使

issues: ./libtool: line 841: X--tag=CXX: command not found and many more errors like this 问题:./ libtool:第841行:X--tag = CXX:找不到命令,并且出现了更多类似这样的错误

To resolve that error : download libtool-1.5.24 tar ball . 解决该错误的方法:下载libtool-1.5.24 tar ball。 extract it and do configure and make . 提取它并进行configure and make now again do configure on btsco and copy libtool executeable from libtool dir to btsco. 现在再次在btsco上进行配置,并将可执行的libtool从libtool目录复制到btsco。

iv) make install v) make mainatiner-clean O/p : btsco is build successfull and you can find it in /usr/local/bin. iv)make install v)进行mainatiner-clean O / p:btsco构建成功,您可以在/ usr / local / bin中找到它。

7) Build Kernel module 7)构建内核模块

i) cd /usr/src/btsco/kernel i)光盘/ usr / src / btsco / kernel

ii) make ii)使

issues: I assume you will get huge list of errors. 问题:我想您会收到大量错误。 open btsco.cand handle each error step by step 打开btsco.cand逐步处理每个错误

1 error sound/driver.h not found bla bla -> comment that in btsco.c file 找不到1个错误的声音/driver.h bla bla-> btsco.c文件中的注释
2 comment #include as this is obsolete now 2条评论#包括,因为这已经过时了
3) add 3)添加

 #include< linux/smp.h>
 #include< linux/muxtex.h>

4) DEFINE_MUTEX(os_mutex); 4)DEFINE_MUTEX(os_mutex);

5) snd_assert is obsolete so replace uit by if statment example 5)snd_assert已过时,因此如果语句示例替换uit

if( bt_sco->playback == NULL) 
{

}

6) replace kill_proc( again obsolete ) by function below 9 copied from net .. tahnks to that guy) link : http://www.linuxquestions.org/questions/linux-kernel-70/is-there-any-kill_proc-replacement-for-proprietary-linux-kernel-drivers-4175460017/ 6)将以下9个函数替换为kill_proc(再次作废),该函数将从网络.. tahnks复制到该家伙)链接: http://www.linuxquestions.org/questions/linux-kernel-70/is-there-any-kill_proc-replacement-for-proprietary-linux-kernel-drivers-4175460017/ : http://www.linuxquestions.org/questions/linux-kernel-70/is-there-any-kill_proc-replacement-for-proprietary-linux-kernel-drivers-4175460017/

int my_kill_proc(pid_t pid, int sig) {
    int error = -ESRCH;              /* default return value */
    struct task_struct* p;
    struct task_struct* t = NULL; 
    struct pid* pspid;
    rcu_read_lock();
    p = &init_task;                  /* start at init */
    do {
        if (p->pid == pid) {         /* does the pid (not tgid) match? */
        t = p;    
        break;
        }
    p = next_task(p);    /* "this isn't the task you're looking for" */
    } while (p != &init_task);   /* stop when we get back to init */
    if (t != NULL) {
        pspid = t->pids[PIDTYPE_PID].pid;
        if (pspid != NULL) error = kill_pid(pspid,sig,1);
    }
    rcu_read_unlock();
    return error;
}

and then instead of kill_proc should be 然后代替kill_proc应该是

my_kill_proc( bt_sco->thread_pid, SIGINT )  

6) replace %d to %lu for error long int 6)将%d to %lu替换%d to %lu以获取long long错误

7) replace lock_kernal to mutex_lock( &os_mutex) same for unlock 7) replace lock_kernal to mutex_lock( &os_mutex)进行解锁

hopefully make will be successful after that 希望之后会成功

8) make install 9) depmod -e 10 0 make clean 8)进行安装9)depmod -e 10 0进行清洁

11) modprobe snd_bt_sco 11)modprobe snd_bt_sco

...................................... ......................................

Now run btsco 现在运行btsco

a) hciconfig hci0 voice 0X0060 a)hciconfig hci0语音0X0060

b) hcitool scan b)hcitool扫描

get mac_addre4ss of JABRA 获取JABRA的mac_addre4ss

c) /usr/local/bin/btsco -r -v mac_addrees c)/ usr / local / bin / btsco -r -v mac_addrees

if get error ?: control open (hw:1) then jabra doesnt support sco or kernel module is not loaded 如果出现错误?:控制打开(hw:1),则jabra不支持sco或未加载内核模块

d) on another terminal do -> sudo hcidump -i hci0 sco to monitor sco packets d)在另一个终端上执行-> sudo hcidump -i hci0 sco以监视sco数据包

e) once jabr connection is established run aplay -D plughw:Headset /home/my_home_dir/my_sample_fiile.wav e)建立jabr连接后,运行aplay -D plughw:Headset /home/my_home_dir/my_sample_fiile.wav

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM