USB --- 和苹果手机通过EAP通信

名称解释

iAP2 control session message:通过 control session 发送的指令

EAP

EAP 全拼是 External Accessory Protocol,即外部配件协议。这个是苹果推荐使用的外设连接方式。需要外设集成 MFi 芯片进行 MFi 认证。手机端开发相对简单,只要集成 iOS 系统提供的一个框架 ExternalAccessory.framework,并且在 info.plist 中配置好协议字符串 (Supported external accessory protocols),当 iOS 设备通过 USB 或者蓝牙连接到对应硬件时,iOS 系统会把符合 MFi 认证要求的外设抽象成了一个流对象,App 通过指定的协议字符串来创建一个 EASession 类的实例来访问到该流对象,就能通过 NSInputStream 和 NSOutputStream 跟硬件件进行通信了。

  • EA Session 模式:它的带宽相对较低,但是允许同时通过多个协议字符串创建多个会话,也就是说直接支持多通道

  • Native Transport 模式:它的带宽足够大,理论值是 100MB 以上,但是不支持多通道,如果业务层需要支持多数据通道的话需要 App 自己进行通道的复用与拆分,并且 Native Transport 需要 iPhone 工作在 USB Host 模式,硬件需要支持 USB 模式切换

关于如何使用 EAP 跟外部设备进行通信,可以参考苹果官方的 Demo (https://developer.apple.com/library/content/samplecode/EADemo/Introduction/Intro.html)进行入门和学习。

iAP2 EA Session

all accessories shall establish a control session for the purposes of authentication and identification. Once initial authentication and identification are complete, the accessory may use additional sessions

Accessories supporting control session version 2 may send Accessory Identification (page 279) messages before authentication completes and shall complete authentication before sending any other messages. The accessories shall fall back to control session 1 if the device does not support control session 2 or does not support those devices.

USB Host Mode (page 507) accessories shall not use control session version 2

 一个 iAP2 EA session可以实现多个 EA protocols

EA Native Transport(USB Host Mode)

To implement an EA Native Transport over USB Host Mode, an accessory shall declare one additional USB interface in its device descriptor. The interface shall have two alternate settings; alternate setting 1 shall have one bulk IN and one bulk OUT endpoint, and alternate setting 0 shall be a zero-bandwidth setting with no endpoints. The accessory shall also declare the presence of an EA Native Transport component during identification.

一个 EA Native Transport 只支持一个 EA protocol

认证

认证一共有两个步骤,authentication 和 identification

authentication 

identification

image

IOS系统弹窗(App Lanuch)

image

 

 

 control session message structure

image

示例

FF5A010D40039B0AB1
404001031D01

001B0000 - Name
546865726D616C20496D6167696E672043616D65726100

000A0001 - ModelIdentifier
544331303200

002D0002 - Manufacturer
5348454E5A48454E204C454147454E44204F50544F454C454354524F4E49435320434F2E2C4C544400

00150003 - SerialNumber
3333323032343132313630303030333800

00080004 - FirmwareVersion
312E3000

00080005 - HardwareVersion
312E3000

00060006 - MessagesSentByAccessory
EA02

00040007 - MessagesReceivedFromDevice

00050008 - PowerProvidingCapability
00

00060009 - MaximumCurrentDrawnFromDevice
0063

0028000A - SupportedExternalAccessoryProtocol
00050000 - ExternalAccessoryProtocolIdentifier
01
00140001 - ExternalAccessoryProtocolName
636F6D2E6C656167656E642E696F7300 = com.leagend.ios
00050002 - ExternalAccessoryProtocolMatchAction
01
00060003 - NativeTransportComponentIdentifier
0000

000F000B - AppMatchTeamID
465739354E414251544800

0007000C - CurrentLanguage
656E00

0007000D - SupportedLanguage
656E00

00170010 - USBHostTransportComponent
00060000 - TransportComponentIdentifier
0000
00090001 - TransportComponentName
6941503200 = iAP2
00040002

00150022 - ProductPlanUID
613733616133303761666165346233630095

 

 

 

 

 

posted @ 2025-07-10 14:35  流水灯  阅读(301)  评论(0)    收藏  举报