本文主要是介绍MirrorLink(二 USB),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、MirrorLink底层的架构
这里我们使用的是USB2.0
车机是MirrorLink Client,手机是MirrorLink Server
1、当使用USB2.0时,MirrorLink Client必须是USB host,MirrorLink Server必须是USB device
所以为了达到这个目的,我们直接使用libusb的库,具体API看http://libusb.sourceforge.net/api-1.0/libusb_api.html。
2、MirrorLink Server通过usb连接MirrorLink Client以后,MirrorLink Client首先需要发送MirrorLink USB Command给MirrorLink Server,用来通知MirrorLink Server,我们支持MirrorLink。
3、MirrorLink USB Command的格式如下:
注意:上图中wValue=0x0001,表示的是1.0版本。
4、MirrorLink Client必须支持CDC/NCM,这个我们是在编译内核的时候直接将CDC/NCM编译进去的
5、如果MirrorLink Server不支持CDC/NCM或者无法切换到CDC/NCM,则MirrorLink Server会回复STALL PID,从libusb来看,libusb_control_transfer会返回失败。
6、如果MirrorLink Client想要从其他模式切换到MirrorLink,也需要发送MirrorLink USB Command,如果想从MirrorLink切换到其他模式,MirrorLink Client需要reset USB connection
7、MirrorLink Client发现MirrorLink Server必须满足以下条件:
(1)MirrorLink USB command必须发送成功
(2)USB device descriptor中需要显示支持USB CDC/NCM
usb device第一次attach的时候,usb host获取到的usb device descriptor中是不支持CDC/NCM的。当usb host发送了MirrorLink USB command以后,usb device会detach,然后重新attach,此时usb host再次获取到的usb device descriptor中就会显示支持CDC/NCM,检测标准是
USB device descriptor中的CDC/NCM descriptor包含下面信息
bInterfaceClass : 0x02
bInterfaceSubclass: 0x0D
对应的数据包解析如下:其中bFuncionClass就是bInterfaceClass,bFunctionSubClass就是bInterfaceSubclass
Communication Control对应的值就是0x02,具体查看USB Device Class,网址:https://usb-ids.gowdy.us/read/UC/ |
注意:device descriptor其实是usb device自动发送给usb host的,数据都存放在kernel里面,libusb也是去kernel里面copy这些数据
(3)MirrorLink Client可以通过UPnP发现MirrorLink Server。
做到这里为止,三星手机会自动建立网络连接并分配IP地址,华为手机可以通过ifconfig -a找到对应的网卡,需要我们自己执行dhclient来挂在网卡获取网络地址。
这篇关于MirrorLink(二 USB)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!