使用 iOS GameKit 的“蓝牙 Bonjour”与其他平台

发布于 2024-12-14 17:08:49 字数 6590 浏览 3 评论 0原文

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

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

下面是在 OS X 下使用蓝牙资源管理器提取的 SDP 数据,同时 iOS 设备运行 Gameloft 的 Star Battalion。

    {
        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)
    },

其他部分相关的问题:


通过使用 OS X 中的 Apple 蓝牙浏览器和 GNU/Linux 中的 sdptool 进行进一步研究,我发现密钥 0x0001(代表“协议类”)包含值 0x1115,代表“PAN”的“PANU”变体——点对点变体。值得注意的是,尽管 OS X 支持创建 0x1116 网络(这是“PAN”的“NAP”变体),但 OS X 并未为此协议提供服务端(“托管”)支持 -客户端/服务器变体。

这可能是个好消息,但前提是不必使用 GameKit 的会话协议。劫持 GameKit 建立的媒体层连接以发送其他 UDP 流量将是理想的选择。

我仍然需要研究这个 GameKit 连接是否真的是 0x1115;也就是说,如果它真的是“PANU”。有人有进一步的信息吗?


请注意,虽然 Bonjour 在 iOS 3 之后自动宣布了此蓝牙服务,但这种情况在 iOS 5 中发生了变化。请参阅我在 如何建立蓝牙连接上发布的答案没有 GameKit,我可以轻松记录来自 Apple 技术问答 QA1753。


对 GNU/Linux 的少量研究并未导致成功连接。这可能是由于缺乏如何正确使用pand的知识。这也可能是由于基于蓝牙 MAC 的阻塞造成的。我希望任何人都可以提供信息。如果我进一步研究并发现一些有趣的东西,我会更新这个答案。


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)

是否需要某种授权?启用加密、身份验证、安全连接和强制成为主机似乎没有任何区别(各种组合中的 -AESM 选项)。

有人有什么想法吗?


哈!

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

I'm interested in connecting to iOS-based devices over Bluetooth. I can see that the "Local Network" service is exposed, but I cannot find any extra information about it. Property stored under key 0x0204 looks like a Bonjour key.

Which protocol is used? How can one talk to the iOS device using Linux, Mac or one's own embedded device equipped with a Bluetooth chip?

Here's SDP data extracted using Bluetooth Explorer under OS X while the iOS device runs Gameloft's Star Battalion.

    {
        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)
    },

Other partially relevant questions:


Researching further with Apple's Bluetooth Explorer in OS X and sdptool in GNU/Linux, I have discovered that key 0x0001 (standing for "protocol class"), containing value of 0x1115, stands for the "PANU" variant of "PAN" - a peer2peer variant. It is notable that OS X does not provide service-side ('hosting') support for this protocol, despite supporting creation of a 0x1116 network, which is the "NAP" variant of "PAN" - a client/server variant.

This might be good news, but only if GameKit's session protocol does not have to be used. Hijacking the media-layer connection established by GameKit in order to send other UDP traffic would be ideal.

I'll still have to research whether or not this GameKit connection really is 0x1115; that is, if it really is "PANU". Does anyone have any further information?


Note while Bonjour automatically announced this Bluetooth service after iOS 3, this has changed with iOS 5. See the answer I posted on how to establish Bluetooth connection without GameKit, where I handily documented information from Apple's Technical Q&A QA1753.


A small amount of research with GNU/Linux did not result in a successful connection. It may be due to lack of knowledge on how to properly use pand. It may also be due to Bluetooth MAC based blocking. I'd love info anyone may have to offer. If I research this further and stumble upon something interesting, I'll update this answer.


Results under Ubuntu. The service appears only when Bluetooth Bonjour is active.

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 ...

Here's the attempt to connect:

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)

Is some sort of authorization required? Enabling encryption, authentication, secure connection and forcing becoming a master doesn't seem to make any difference (-AESM options in various combinations).

Anyone has any ideas?


Huh!

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

This?

> 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满地尘埃落定 2024-12-21 17:08:55

根据这个有趣的网站:
http://code.google.com/p/btstack/wiki/iPhoneBluetooth除了蓝牙 RF 芯片之外,苹果还使用了一种特殊的芯片,它会拒绝没有该芯片的设备的任何连接 - 这意味着它在硬件级别上被锁定。

According to this interesting site :
http://code.google.com/p/btstack/wiki/iPhoneBluetooth Apple are using a special chip besides their Bluetooth RF chip which denies any connection for a device without that chip - this means its a lock on the hardware level.

盛夏尉蓝 2024-12-21 17:08:55

也许有点延迟,但技术已经发展,所以肯定有新的信息围绕这个问题提供了新的线索...

传统的 GameKit 已被 Multiper Connectivity 取代,并在 iOS 上引入了对 WiFi Direct 的支持,但该框架仍然存在仍然仅限 iOS。我认为里面有专有的东西。

此外,由于 iOS 尚未开放 WiFi Direct 的直接 API,我相信解决此问题的最佳方法是使用 BLE,这两个平台都支持(有些平台比其他平台更好)。

在 iOS 上,设备可以同时充当 BLE 中心和 BLE 外设,在 Android 上,情况更为复杂,因为并非所有设备都支持 BLE 外设状态。此外,Android BLE 堆栈(迄今为止)非常不稳定。

如果您的用例是功能驱动的,我建议您查看可以为您实现跨平台通信的框架和库,而无需从头开始构建它。

例如:http://p2pkit.io 或 google 附近

免责声明:我在 Uepaa 工作,为 Android 开发 p2pkit.io 和iOS。

Maybe a bit delayed, but technologies have evolved since so there is certainly new info around which draws fresh light on the matter...

The traditional GameKit has been replaced by Multiper Connectivity together with introducing support for WiFi Direct on iOS, however the framework still remains iOS only. I assume there is proprietary stuff going on in there.

Also, as iOS has yet to open up a direct API for WiFi Direct I believe the best way to approach this is to use BLE, which is supported by both platforms (some better than others).

On iOS a device can act both as a BLE Central and BLE Peripheral at the same time, on Android the situation is more complex as not all devices support the BLE Peripheral state. Also the Android BLE stack is very unstable (to date).

If your use case is feature driven, I would suggest to look at Frameworks and Libraries that can achieve cross platform communication for you, without you needing to build it up from scratch.

For example: http://p2pkit.io or google nearby

Disclaimer: I work for Uepaa, developing p2pkit.io for Android and iOS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文