[ZZ]从hcid玩起
hcid进展
hcid -n 跟hcid -f /etc/f出去配置⽂件外,执⾏的程序好像是⼀样的,主要区别是⼀个在后台运⾏,⼀个在前台运⾏。
由于开发板中没有syslog⽇⾄⽂件,只能⽤hcid -n来错误了
1、当不插⼊usb蓝⽛适配器时出现以下错误:
# hcid -n
hcid[79]: Bluetooth HCI daemon
hcid[79]: syntax error line 4
hcid[79]: syntax error line 6
hcid[79]: Can't open system message bus connection: Failed to connect to socket
/usr/local/var/run/dbus/system_bus_socket: No such file or directory
但程序死在这⾥,不再执⾏,也就说程序也没有退出,猜测⼀下,是不是不插蓝⽛适配器时看似启动的hcid守护进程,也是在后台运⾏到这⾥⽽不退出,表⾯上看起来运⾏是对的
假设我现在插⼊蓝⽛适配器会出现什么错误呢
插⼊:
# hcid -n
hcid[79]: Bluetooth HCI daemon
hcid[79]: syntax error line 4
hcid[79]: syntax error line 6
hcid[79]: Can't open system message bus connection: Failed to connect to socket
/usr/local/var/run/dbus/system_bus_socket: No such file or directory
hub.c: USB new device connect on bus1/1, assigned device number 9
hcid[79]: HCI dev 0 registered
hcid[79]: Registering DBUS Path: /org/bluez/Device/hci0
process 79: arguments to dbus_connection_register_object_path() were incorrect,
assertion "connection != NULL" failed in file dbus-connection.c line 5071.
This is normally a bug in some application using the D-Bus library.
D-Bus not built with -rdynamic so unable to print a backtrace
SIGABRT
结果插⼊后hcid进程收到⼀个SIGABRT信号⽽终⽌了程序,原来如此,也就是说后台运⾏的hcid守护进程同样会收到⼀个SIGABRT信号⽽终⽌程序,所以外在表现就是直接杀死了进程,也就是说程序中有问题,但是程序是官⽅⽹站下的,不可能出现太⼤的错误,到⽹上搜了搜,有的说dbus-dameon没有开启,个⼈认为可能是正确的,有⼈说要⽤hcid进程,必须开启dbus守护进程。
下⾯的⼯作就是根据错误来解决dbus问题
被忽略的的dbus-daemon
dbus是⼀个消息传递系统,应⽤程序间可通过它来相互传递消息。dbus-daemon是⼀个守护进程,是运⾏hcid所必需
的,hcid⽤来读⼊f⽂件。
[root@localhost ~]# netstat -l | grep bus
unix 2 [ ACC ] STREAM LISTENING 5927 /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 7632 @/var/run/hald/dbus-EeHAGFabyQ
unix 2 [ ACC ] STREAM LISTENING 9576 @/tmp/dbus-nx93CegnGf
unix 2 [ ACC ] STREAM LISTENING 7631 @/var/run/hald/dbus-3FKNFZzl2Q
[root@localhost ~]# dbus-daemon --system
Failed to start message bus: The pid file "/var/run/messagebus.pid" exists, if the message bus is not running, remove this file
[root@localhost ~]# ps ax |grep bus
2194 ? Ssl 0:07 dbus-daemon --system
3390 ? Ss 0:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients
3393 ? Ssl 0:00 /bin/dbus-daemon --fork --print-pid 8 --print-address 6 --session
3394 ? S 0:00 /usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients
3446 ? Ss 0:00 bluez-pin --dbus
6316 pts/1 R+ 0:00 grep bus
[root@localhost ~]# ll /var/run/messagebus.pid
-rw-r--r-- 1 root root 5 Sep 22 08:46 /var/run/messagebus.pid
[root@localhost ~]# file /var/run/dbus/system_bus_socket
美好的⼀天hcid守护进程正确运⾏了,dbus-daemon也正常启动了
根据hcid进展得到,应该是需要⼀个dbus-dameon⼯具,也是⼀个守护进程,从前两天编译的dbus-1.0.2中竟然奇迹般的在bus下到了dbus-dameon(昨天没有到),那个滋啊
好景不长
运⾏命令:
# dbus-dameon --system
Failed to start message bus: Failed to open "/usr/local/etc/f":
No such file or directory
于是我⼜到dbus-1.0.2中了个f
# dbus-dameon --system
Failed to start message bus: Failed to open :".....system.d" No such file or directory
于是响应⽬录下建了个system.d⽂件夹
# dbus-dameon --system
Failed to start message bus: Failed to bind socket "/var/run/dbus/system_bus_soc ket
No such file or directory
⾃⼰就硬着头⽪建⼀个system_bus_soc ket,结果
# dbus-dameon --system
Failed to start message bus: Failed to bind socket "/var/run/dbus/system_bus_soc ket:Address already in use
郁闷,删掉system_bus_soc ket,只留/var/run/dbus/
# dbus-dameon --system
Failed to start message bus:Could not get UID and GID for username "messagebus"
⽹上让⽤/usr/sbin/adduser messagebus,奶奶的开发板上没有这个命令,难道在编译busy-box,还是算了吧,⿇烦,忽然看到⽹上说可以⽤添加⽂件的⽅式添加⽤户,/etc/passwd下,在pc linux下⽤⼀下/usr/sbin/adduser messagebus,发现就
在/etc/passwd下,添加了⼀⾏messagebus:x:500:500::/home/messagebus:/bin/bash,看开发板上,只
是有个root,于是复制进去,root后/bin/sh,所以为了保持⼀致,也改为messagebus:x:500:500::/home/messagebus:/bin/sh
passwd内容如下:
root::0:0:root:/:/bin/sh
bin:*:1:1:bin:/bin:
daemon:*:2:2:daemon:/sbin:
nobody:*:99:99:Nobody:/:
messagebus:x:500:500::/home/messagebus:/bin/sh
# dbus-dameon --system
哈哈,该死的错误没了,⾼兴
然后再试
#hcid -f /etc/f
oh,yes,hci 服务进程不会被usb蓝⽛适配器给杀死了
我⾼兴极了
但是,试了试蓝⽛⽿机还是连不上,向⽬标冲刺
bluez-hcid⽤途
为什么叫它demon程序,demon程序的⽤途,基本⼯作原理。
我猜hcid有⼀个⽆限循环,等待什么我就不知道了?
hcid/main.c->main
......
ctl_io = g_io_channel_unix_new(hcid.sock);
g_io_add_watch(ctl_io, G_IO_IN, io_stack_event, NULL);
g_main_run(event_loop);
.
.....
watch这个结构的由来,因为⼀个蓝⽛设备最多可以建⽴7条hci连接;watch是个链表,针对每⼀条hci链路都会有⼀个watch 结构连在链表中。
g_io_add_watch函数在hcid.sock上连接了io_stack_event函数,⽽这个函数主要的功能就是从这个sock缓冲区中读数据;
g_main_run函数去socket缓冲区中读数据,使⽤result = read (fd, buf, count);//read系统调⽤⼀个服务记录可以有很多的服务属性,bluez的实现是链表的形式;
typedef struct {//服务记录
uint32_t handle; //服务句柄
sdp_list_t *pattern;
sdp_list_t *attrlist; //属性链表
//书上的表现形式向⼀个数组,可以⽤链表完成;
} sdp_record_t;
typedef struct _sdp_list sdp_list_t;
struct _sdp_list {
sdp_list_t *next;
void *data; //实际上data指针将指向⼀个sdp_data_t结构;
};
typedef struct sdp_data_struct sdp_data_t;
struct sdp_data_struct {//属性值是⼀个数据元,
uint8_t dtd; //数据元的类型描述符
uint16_t attrId;//属性id
union {
int8_t int8;
int16_t int16;
int32_t int32;
int64_t int64;
uint128_t int128;
uint8_t uint8;
uint16_t uint16;
uint32_t uint32;
uint64_t uint64;
uint128_t uint128;
uuid_t uuid;
char *str;
sdp_data_t *dataseq;
} val;
sdp_data_t *next;
int unitSize; //数据元的数据尺⼨描述符
};
继续蓝⽛⽿机-a2play的连接问题
# ./a2play -s -d -r 44100 00:15:83:09:B2:52 /dev/sound/dsp
subbands = 8 blocks = 16 bitpool = 32
cannot set format on input /dev/sound/dsp
Sample Rate:44100
Channels:2
Using address: 00:15:83:09:B2:52
Found A2DP Sink
Found A2DP Sink at the destination
Can't connect to 52:B2:09:83:15:00. Connection refused(111)
cannot open psm_cmd = 25
本来认为是配对问题,现在hcid守护进程能守护了,为何还不能响应呢,是配对问题吗,
⼀切都是因为不能看到syslog/message
Linux下蓝⽛⽿机
简单的提纲⼀下:
Linux平台选择
Fedora 8 test
Fedora 7是不⾏的
安装
bluez-gnome-0.14-8.fc8
bluez-utils-alsa-3.20-4.fc8
bluez-utils-3.20-4.fc8
bluez-libs-devel-3.20-1.fc8
bluez-libs-3.20-1.fc8
kdebluetooth-1.0-0.34.beta8.fc8
配对&连接
打开⽿机,⾄搜索模式
⽤hcitool scan搜索出⽿机的MAC地址
在⾃⼰的home⽬录下创建.asoundrc⽂件,内容如下
pcm.bluetooth {
type bluetooth
device 00:0D:FD:0C:23:71 #根据你的⽿机的实际MAC地址修改
}
K菜单->管理->Kbluetooth
scan
确定,输⼊pin配对
打开bluez的Audio服务:运⾏/usr/lib/bluetooth/bluetoothd-service-audio
OK. Everything is Ready.
使⽤
所有播放软件使⽤设备alsa:bluetooth。
评测
headsetMplayer:播放⼀段时间后,会出现画⾯以及声⾳断断续续的问题,估计是Audio/Video同步算法不适应蓝⽛造成的。但是播放MP3很流畅。
RealPlayer:瘫痪。
Amarok:使⽤HelixPlayer引擎瘫痪;使⽤xine引擎……我的xine不⽀持MP3>_<。
to
⽀持a2dp在linux下的配置
bluetooth software: bluez-lib-3.22 bluez-utils-3.22和dbus(bluez-utils依赖的库,编译问题在本博客内查) 。 bluetooth hardware: iBook G4 内置的CSR 蓝⽛2.0芯⽚、Motorola S705蓝⽛⽴体声⽿机,也是CSR 蓝⽛2.0芯⽚。NOTE: 请在blue-utils ./configure的时候,加上--enable-audio
1)scan你的蓝⽛⽿机,得到bluetooth address,并且能够跟主机上的bluetooth正确配对,具体看前⾯blog
2)edit $(HOME)/.asoundrc 内容如下:
pcm.bluetooth{
type bluetooth
device 00:02:76:64:94:F9 //蓝⽛⽿机地址
}
3)edit /etc/f, check⼀下你配置是否正确
[General]
# SCO routing. Either PCM or HCI (in which case audio is routed to/from ALSA)
# Defaults to HCI
SCORouting=HCI
[Headset]
# Defaults to false
DisableHFP=true
[A2DP]
SourceCount=1
4 )运⾏ bluez-utils-3.22/audio 下的bluetoothd-service-audio,安装后⼀般在/usr/lib/bluetooth下
5 )运⾏mplayer来测试⼀下你的蓝⽛⽴体声⽿机,命令如下:
mplayer -ao alsa:device=bluetooth audio/demo.mp3
祝你成功!!
关于a2dp要知道的
itechs的⽴体声可以了,不过偶尔有点断续,⾳质也⽐win下差点,还是跟⼿机相连⾳质最好啊。dapper
下⾯已经有相关驱动了,我只需要个a2player执⾏⽂件。具体参考bluetooth-alsa.sourceforge/,不过我从cvs下载的包通不过,只好,到sourceforge/projects/bluetooth-alsa/下载,编译通过得到a2player⽂件,然后mpg123 --au - 1.mp3 | ./a2play
xx:xx:xx:xx:xx:xx 可以实现⽴体声播放了,不过有些mp3⽂件会出现快播效果的,就像以前walkman的快放⼀样,呵呵。
关于蓝⽛配对和PIN CODE和hcid
请求给B,B由⽤户设置好
配对的请求给
由⽤户设置好配对的密码即
配对的密码即PIN code,然后回⼀个消息给A,说先发送要求配对的
两个蓝⽛设备
蓝⽛设备A和B,A先发送要求
配对可以呀,知道我的密码吗?然后A就发送PIN code过去,B看和⾃⼰的密码相符合,就发送⼀个replyOK的消你想配对可以呀,知道我的密码吗
你想
息给A,这样两者就建⽴起来了信任关系。
配对请求给另⼀个远程设备
请求给另⼀个远程设备B,那么当B发送询问密
上,如果这个设备先发送配对
蓝⽛设备A上,如果这个设备先发送
在pc+蓝⽛适配器这个
蓝⽛适配器这个蓝⽛设备
码请求过来时,在A上运⾏的hcid后台进程就通过⼀个pin_helper的程序读取PIN code,并发送回给B;如果远程设备请求给A,hcid上⽤作验证(注意:是验证也就是看B发过来的密码与A存的密码是否⼀致)
的PIN code 配对请求给
B先发送
先发送配对
就是/etc/bluetooth/pin的内容,可以清空pin,让⽤户输⼊pin码,如果读取失败程序在启动的时候会默认地设置⼀个密码的,代码在bluez- utils/hcid/security.c中的init_security_data函数中,默认的是BlueZ。为了和我的⼿机相配,我把它改成了 123,⼿机只能输⼊数字。
关于其他f的设置,请f。
设置好以后,换上新内核,启动linux。插⼊USB蓝⽛适配器,# dmesg | tail会发现有usb.c: USB device 2 (vend/prod 0x1131/0x1001) is not claimed by any active driver.这个问题,不管它,只要有usb.c: registered new driver hci_usb的消息就可以,然后 # lsmod 会发现hci_usb的模块被安装了,再# modprobe rfcomm,这样基本上所有的模块都安装齐了。
# hciconfig hci0 up
# hcid -f /etc/f
启动hci设备和hcid精灵进程
# hciconfig -a
⼀些hcid调试问题摘录
最近移植BULEZ 碰到问题
我已经开启了1079 messageb 2212 S dbus-daemon --system
但是再运⾏hcid -n仍然显⽰为:
hcid[1089]: Bluetooth HCI daemon
hcid[1089]: Unable to get on D-Bus
# HCI daemon configuration file.
#
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论