首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BlueZ SCO应用程序和Linux不能连接到SCO套接字

BlueZ SCO应用程序和Linux不能连接到SCO套接字
EN

Stack Overflow用户
提问于 2015-02-20 14:47:46
回答 1查看 1.4K关注 0票数 3

我在一个带有内核BlueZ的嵌入式Linux项目上使用3.4.79+ 4.101。正常的蓝牙操作很好,我可以用很多耳机和我的设备传输音频。现在我正在努力实现蓝牙兼容,所以我使用了蓝牙SIG的USB。我是通过每一个测试,除了部分的来电测试,我需要打开上海合作组织连接后,接受电话与PTS dongle。

SCO连接尝试与耳机一起工作,但与PTS dongle不工作。此错误来自蓝牙,如下所示:

代码语言:javascript
复制
bluetoothd[6306]: audio/headset.c:headset_set_state() State changed /org/bluez/6306/hci0/dev_00_1B_DC_07_30_40: HEADSET_STATE_PLAY_IN_PROGRESS -> HEADSET_STATE_CONNECTED
bluetoothd[6306]: audio/headset.c:headset_set_state() State changed /org/bluez/6306/hci0/dev_00_1B_DC_07_30_40: HEADSET_STATE_CONNECTED -> HEADSET_STATE_PLAY_IN_PROGRESS
bluetoothd[6306]: Protocol not supported (93)

因此,我从BlueZ的测试目录编译了scotest,并在连接dongle之后运行它,得到了相同的结果:

代码语言:javascript
复制
# ./scotest -s -b HELLO 00:1B:DC:07:30:40
scotest[1687]: Can't connect: Protocol not supported (93)
scotest[1687]: Can't connect to the server: Protocol not supported (93)

下面是scotest.c中的do_connect函数,它失败了:

代码语言:javascript
复制
static int do_connect(char *svr)
{
    struct sockaddr_sco addr;
    struct sco_conninfo conn;
    socklen_t optlen;
    int sk;

    /* Create socket */
    sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
    if (sk < 0) {
        syslog(LOG_ERR, "Can't create socket: %s (%d)",
                            strerror(errno), errno);
        return -1;
    }

    /* Bind to local address */
    memset(&addr, 0, sizeof(addr));
    addr.sco_family = AF_BLUETOOTH;
    bacpy(&addr.sco_bdaddr, &bdaddr);

    if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
        syslog(LOG_ERR, "Can't bind socket: %s (%d)",
                            strerror(errno), errno);
        goto error;
    }

    /* Connect to remote device */
    memset(&addr, 0, sizeof(addr));
    addr.sco_family = AF_BLUETOOTH;
    str2ba(svr, &addr.sco_bdaddr);

    if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
        syslog(LOG_ERR, "Can't connect: %s (%d)",
                            strerror(errno), errno);
        goto error;
    }

    /* Get connection information */
    memset(&conn, 0, sizeof(conn));
    optlen = sizeof(conn);

    if (getsockopt(sk, SOL_SCO, SCO_CONNINFO, &conn, &optlen) < 0) {
        syslog(LOG_ERR, "Can't get SCO connection information: %s (%d)",
                            strerror(errno), errno);
        goto error;
    }

    syslog(LOG_INFO, "Connected [handle %d, class 0x%02x%02x%02x]",
        conn.hci_handle,
        conn.dev_class[2], conn.dev_class[1], conn.dev_class[0]);

    return sk;

error:
    close(sk);
    return -1;
}

我在内核Config中遗漏了什么,允许PTS dongle进入一个开放的SCO连接的播放状态?

下面是我的Linux .config (我使用backport-3.13.2-1支持TI WL1271 BT/WiFi模块):

代码语言:javascript
复制
CPTCFG_IPV6_SUBTREES=y
CPTCFG_NFT_RBTREE=m
CPTCFG_BRIDGE_NF_EBTABLES=m
CPTCFG_BRIDGE_EBT_BROUTE=m
CPTCFG_BRIDGE_EBT_T_FILTER=m
CPTCFG_BRIDGE_EBT_T_NAT=m
CPTCFG_BRIDGE_EBT_802_3=m
CPTCFG_BRIDGE_EBT_AMONG=m
CPTCFG_BRIDGE_EBT_ARP=m
CPTCFG_BRIDGE_EBT_IP=m
CPTCFG_BRIDGE_EBT_IP6=m
CPTCFG_BRIDGE_EBT_LIMIT=m
CPTCFG_BRIDGE_EBT_MARK=m
CPTCFG_BRIDGE_EBT_PKTTYPE=m
CPTCFG_BRIDGE_EBT_STP=m
CPTCFG_BRIDGE_EBT_VLAN=m
CPTCFG_BRIDGE_EBT_ARPREPLY=m
CPTCFG_BRIDGE_EBT_DNAT=m
CPTCFG_BRIDGE_EBT_MARK_T=m
CPTCFG_BRIDGE_EBT_REDIRECT=m
CPTCFG_BRIDGE_EBT_SNAT=m
CPTCFG_BRIDGE_EBT_LOG=m
CPTCFG_BRIDGE_EBT_NFLOG=m
CPTCFG_MAC_EMUMOUSEBTN=m
CPTCFG_RTLBTCOEXIST=m
CPTCFG_TABLET_USB_KBTAB=m
CPTCFG_INPUT_ATLAS_BTNS=m
CPTCFG_SND_BT87X=m
CPTCFG_LIRC_BT829=m
CPTCFG_USB_BTMTK=m
CPTCFG_TOSHIBA_BT_RFKILL=m
CPTCFG_BTRFS_FS=m
CPTCFG_BTRFS_FS_POSIX_ACL=y
CPTCFG_RBTREE_TEST=m
CPTCFG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=y
CPTCFG_BTREE=y
CPTCFG_BACKPORT_OPTION_BT_SOCK_CREATE_NEEDS_KERN=y
CPTCFG_BT=m
CPTCFG_BT_RFCOMM=m
# CPTCFG_BT_RFCOMM_TTY is not set
CPTCFG_BT_BNEP=m
CPTCFG_BT_BNEP_MC_FILTER=y
CPTCFG_BT_BNEP_PROTO_FILTER=y
# CPTCFG_BT_CMTP is not set
CPTCFG_BT_HIDP=m
CPTCFG_BT_HCIBTUSB=m
CPTCFG_BT_HCIBTSDIO=m
CPTCFG_BT_HCIUART=m
CPTCFG_BT_HCIUART_H4=y
CPTCFG_BT_HCIUART_BCSP=y
# CPTCFG_BT_HCIUART_ATH3K is not set
CPTCFG_BT_HCIUART_LL=y
CPTCFG_BT_HCIUART_3WIRE=y
# CPTCFG_BT_HCIBCM203X is not set
# CPTCFG_BT_HCIBPA10X is not set
# CPTCFG_BT_HCIBFUSB is not set
# CPTCFG_BT_HCIDTL1 is not set
# CPTCFG_BT_HCIBT3C is not set
# CPTCFG_BT_HCIBLUECARD is not set
CPTCFG_BT_HCIBTUART=m
CPTCFG_BT_HCIVHCI=m
# CPTCFG_BT_MRVL is not set
# CPTCFG_BT_ATH3K is not set
CPTCFG_BT_WILINK=m

我用printks检测内核中的sco.c文件。

在成功使用普通耳机时,在成功打开SCO连接后,它看起来如下:

代码语言:javascript
复制
*** sco_sock_create
*** sco_sock_alloc
*** sco_sock_init
*** sco_sock_bind
*** sco_sock_connect
*** sco_connect
*** sco_conn_add
*** sco_chan_add
*** __sco_chan_add
*** sco_sock_set_timer
*** sco_connect_cfm
*** sco_conn_add
*** sco_conn_ready
*** sco_sock_clear_timer
*** sco_sock_getsockopt
*** sco_sock_setsockopt_old
*** sco_sock_getsockopt
*** sco_sock_setsockopt_old
*** sco_sock_sendmsg
*** sco_send_frame
*** sco_sock_sendmsg
*** sco_send_frame
*** sco_sock_sendmsg
*** sco_send_frame

如果失败,它看起来是这样的:

代码语言:javascript
复制
*** sco_sock_create
*** sco_sock_alloc
*** sco_sock_init
*** sco_sock_bind
*** sco_sock_connect
*** sco_connect
*** sco_conn_add
*** sco_chan_add
*** __sco_chan_add
*** sco_sock_set_timer
*** sco_connect_cfm
*** sco_conn_del
*** sco_chan_get
*** sco_sock_clear_timer
*** sco_chan_del
*** sco_sock_release
*** sco_sock_close
*** sco_sock_kill
*** sco_sock_clear_timer
*** __sco_sock_connect
*** sco_sock_kill
*** sco_sock_kill
*** sco_sock_destruct

进一步的测试表明在这个sco.c函数中正在发生故障:

代码语言:javascript
复制
void sco_connect_cfm(struct hci_conn *hcon, __u8 status)
{

    printk("*** sco_connect_cfm start\n");

    BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst, status);
    printk("*** sco_connect_cfm_stat hcon %p bdaddr %pMR status %d\n", hcon, &hcon->dst, status);
    if (!status) {
        struct sco_conn *conn;

        conn = sco_conn_add(hcon);
        printk("*** sco_connect_cfm sco_conn_add: %d\n",conn);
        if (conn)
            printk("*** sco_connect_cfm ready\n");
            sco_conn_ready(conn);
    } else
        printk("*** sco_connect_delete: %d\n",status);
        sco_conn_del(hcon, bt_to_errno(status));
}

该输出如下所示:

代码语言:javascript
复制
*** sco_sock_create
*** sco_sock_alloc
*** sco_sock_init
*** sco_sock_bind
*** sco_sock_connect
*** sco_connect
*** sco_conn_add
*** sco_chan_add
*** __sco_chan_add
*** sco_sock_set_timer
*** sco_connect_cfm start
*** sco_connect_cfm_stat hcon d9ec2400 bdaddr 40:30:07:dc:1b:00 status 26
*** sco_connect_delete: 26
*** sco_conn_del
*** sco_chan_get
*** sco_sock_clear_timer
*** sco_chan_del
*** sco_sock_release
*** sco_sock_close
*** sco_sock_clear_timer
*** sco_sock_kill
*** __sco_sock_connect
*** sco_sock_kill
*** sco_sock_kill
*** sco_sock_destruct
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-04 17:16:42

问题不是内核的配置,而是我正在使用的一组驱动程序。我已经编译了蓝牙驱动程序的linux ( http://drvbp1.linux-foundation.org/~mcgrof/rel-html/backports/)版本,因为我需要支持的wifi驱动程序,这给了我协议不支持(93)错误。我切换到了与内核3.4.79+一起分发的驱动程序,它起了作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28631721

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档