如何在其他平台上使用iOS Gamekit的“蓝牙Bonjour”?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (158)

我对通过蓝牙连接到基于iOS的设备感兴趣。我可以看到,“本地网络”服务是公开的,但我找不到任何额外的信息。存储在KEY 0x0204下的属性看起来像一个Bonjour密钥。

使用哪种协议?如何使用Linux、Mac或自己配备蓝牙芯片的嵌入式设备与IOS设备对话?

以下是OSX下使用蓝牙资源管理器提取的SDP数据

    {
        0x0000 = uint32(1330188565),
        0x0200 = uint32(2),
        0x0202 = string(004wD7l1A..0|0|0|ivucic-À'),
        0x030a = uint32(0),
        0x0009 = { { uuid16(11 15), uint16(256) } },
        0x0201 = string(_657o30a6rmst07À),
        0x0005 = { uuid16(10 02) },
        0x0100 = string(Local Network),
        0x0001 = { uuid16(11 15) },
        0x0203 = string(004wd7l1a..0|0|0|ivucic-_657o30a6rmst07À
        0xf000 = uint8(2),
        0x0204 = string(    txtvers=1state=A),
        0x0008 = uint8(255),
        0x0006 = { uint16(25966), uint16(106), uint16(256), uint16(26226), uint16(106), uint16(272), uint16(25701), uint16(106), uint16(288), uint16(27233), uint16(106), uint16(304) },
        0x0004 = { { uuid16(01 00), uint16(15) }, { uuid16(00 0f), uint16(256), { uint16(2048), uint16(2054) } } },
        0x0002 = uint32(0)
    },

Ubuntu下的结果。只有当蓝牙Bonjour处于活动状态时,该服务才会出现。

ivucica@ivucica-MacBook:~$ sdptool browse $ADDR #relevant data only
Browsing ADDRESS_HERE ...
Service Name: Local Network
Service RecHandle: 0x4f491115
Service Class ID List:
  "PAN User" (0x1115)
Protocol Descriptor List:
  "L2CAP" (0x0100)
    PSM: 15
  "BNEP" (0x000f)
    Version: 0x0100
    SEQ8: 0 6
Language Base Attr List:
  code_ISO639: 0x656e
  encoding:    0x6a
  base_offset: 0x100
  code_ISO639: 0x6672
  encoding:    0x6a
  base_offset: 0x110
  code_ISO639: 0x6465
  encoding:    0x6a
  base_offset: 0x120
  code_ISO639: 0x6a61
  encoding:    0x6a
  base_offset: 0x130
Profile Descriptor List:
  "PAN User" (0x1115)
    Version: 0x0100

... and so on ...

下面是连接的尝试:

ivucica@ivucica-MacBook:~$ pand --connect $ADDR -n
pand[3237]: Bluetooth PAN daemon version 4.98
pand[3237]: Connecting to ADDRESS_HERE
pand[3237]: Connect to ADDRESS_HERE failed. Connection refused(111)

需要某种授权吗?启用加密、身份验证、安全连接和强制成为主程序似乎没有任何区别。

有人有什么想法吗?

ivucica@ivucica-MacBook:~$ sudo hcidump
HCI sniffer - Bluetooth packet analyzer ver 2.2
device: hci0 snap_len: 1028 filter: 0xffffffff
 HCI Event: Command Status (0x0f) plen 4
    Create Connection (0x01|0x0005) status 0x00 ncmd 1
> HCI Event: Role Change (0x12) plen 8
    status 0x00 bdaddr ADDRESS_HERE role 0x01
    Role: Slave
> HCI Event: Connect Complete (0x03) plen 11
    status 0x00 handle 12 bdaddr ADDRESS_HERE type ACL encrypt 0x00
 HCI Event: Command Status (0x0f) plen 4
    Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 1
> HCI Event: Read Remote Supported Features (0x0b) plen 11
    status 0x00 handle 12
    Features: 0xbf 0xfe 0x8f 0xfe 0x9b 0xff 0x79 0x83
 HCI Event: Command Status (0x0f) plen 4
    Read Remote Extended Features (0x01|0x001c) status 0x00 ncmd 1
> HCI Event: Max Slots Change (0x1b) plen 3
    handle 12 slots 5
> HCI Event: Read Remote Extended Features (0x23) plen 13
    status 0x00 handle 12 page 1 max 1
    Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
 HCI Event: Command Status (0x0f) plen 4
    Remote Name Request (0x01|0x0019) status 0x00 ncmd 1
> HCI Event: Remote Name Req Complete (0x07) plen 255
    status 0x00 bdaddr ADDRESS_HERE name 'Evil iPad'
 HCI Event: Command Status (0x0f) plen 4
    Authentication Requested (0x01|0x0011) status 0x00 ncmd 1
> HCI Event: Link Key Request (0x17) plen 6
    bdaddr ADDRESS_HERE
 HCI Event: Command Complete (0x0e) plen 10
    Link Key Request Reply (0x01|0x000b) ncmd 1
    status 0x00 bdaddr ADDRESS_HERE
> HCI Event: Auth Complete (0x06) plen 3
    status 0x00 handle 12
 HCI Event: Command Status (0x0f) plen 4
    Set Connection Encryption (0x01|0x0013) status 0x00 ncmd 1
> HCI Event: Encrypt Change (0x08) plen 4
    status 0x00 handle 12 encrypt 0x01
 HCI Event: Number of Completed Packets (0x13) plen 5
    handle 12 packets 1
> ACL data: handle 12 flags 0x02 dlen 16
    L2CAP(s): Info rsp: type 2 result 0
      Extended feature mask 0x02a8
        Enhanced Retransmission mode
        FCS Option
        Fixed Channels
        Unicast Connectless Data Reception
 HCI Event: Number of Completed Packets (0x13) plen 5
    handle 12 packets 1
> ACL data: handle 12 flags 0x02 dlen 20
    L2CAP(s): Info rsp: type 3 result 0
      Fixed channel list 0x00000006
        L2CAP Signalling Channel
        L2CAP Connless
 HCI Event: Number of Completed Packets (0x13) plen 5
    handle 12 packets 1
> ACL data: handle 12 flags 0x02 dlen 16
    L2CAP(s): Connect rsp: dcid 0x0000 scid 0x0040 result 2 status 0
      Connection refused - PSM not supported
> HCI Event: Disconn Complete (0x05) plen 4
    status 0x00 handle 12 reason 0x13
    Reason: Remote User Terminated Connection

这是吗?

> ACL data: handle 12 flags 0x02 dlen 16
    L2CAP(s): Connect rsp: dcid 0x0000 scid 0x0040 result 2 status 0
      Connection refused - PSM not supported
提问于
用户回答回答于

也许有点延迟,但技术已经发展了,因此,肯定有新的信息,吸引了新的线索。

传统的GameKit已经被Multiper Connectivity取代,同时在IOS上引入了对WiFi Direct的支持,但是框架仍然仅限于IOS。我想里面应该有专有的东西。

另外,由于IOS还没有为WiFi Direct开发一个直接的API,我认为最好的方法是使用BLE,这是两个平台都支持的(有些比其他平台更好)。

在IOS上,设备可以同时充当BLE中央和BLE外围设备,而在Android上,情况更复杂,因为并不是所有设备都支持BLE外围设备状态。此外,AndroidBLE堆栈非常不稳定(到目前为止)。

如果你的用例是功能驱动的,我建议你考虑一下框架和库,这些框架和库可以为你实现跨平台的通信,而不需要从头开始构建它。

用户回答回答于

扫码关注云+社区

领取腾讯云代金券