我有一个C程序,它成功地与蓝牙设备建立了rfcomm连接。
void doConnect( char const* btaddr )
{
int sock = socket( AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM );
bdaddr_t ba;
struct sockaddr_rc addr;
str2ba( btaddr, &ba );
memset( &addr, 0, sizeof(addr) );
addr.rc_family = AF_BLUETOOTH;
memcpy( &(addr.rc_bdaddr), &ba, sizeof(ba) );
addr.rc_channel = 1;
int result = connect( sock, (struct sockaddr *)&addr, sizeof(addr ) );
...
}
但是,当我运行rfcomm实用程序(http://linux.die.net/man/1/rfcomm)时,如下:
/usr/bin/rfcomm connect bt_addr
我收到错误:
"Can't find a config entry for rfcomm0"
使用命令:
rfcomm connect bt_addr
我收到错误:
"Can't connect RFCOMM socket: Host is down"
那么,rfcomm connect与我的C程序有什么不同呢?为什么它不能连接?我是否错误地使用了该实用程序?
== edit ==
来自我的C程序的结果:
socket(PF_BLUETOOTH, SOCK_STREAM, 3) = 3
...
connect(3, {sa_family=AF_BLUETOOTH, sa_data=">\16\303O!\0\1\0\0\0\0\0\0\0"}, 10) = 0
来自/ usr / bin / rfcomm程序的strace结果:
socket(PF_BLUETOOTH, SOCK_RAW, 3) = 3
socket(PF_BLUETOOTH, SOCK_STREAM, 3) = 4
bind(4, {sa_family=AF_BLUETOOTH, sa_data="\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}, 10) = 0
connect(4, {sa_family=AF_BLUETOOTH, sa_data="\0\0\0\0\0\1\1\0\0\0\0\0\0\0"}, 10) = -1 EHOSTDOWN (Host is down)