您的位置:首页 > 其它

USB NCM介绍

2021-05-29 19:45 1901 查看

​1 功能概述

USB NCM,属于USB-IF定义的CDC(Communication Device Class)下的一个子类:Network Control Model,用于Host和Device之间交换以太网帧。NCM主要用于高速网络场景下比如HSPA和LTE数据服务。NCM协议规范基于ECM改进而来,支持了更高的数据率。

ECM和NCM都适用于IEEE 802.3类型的以太网功能,可以将IP流量传输到外部网络。ECM是为USB全速设备设计的,特别是支持docsis 1.0电缆调制解调器。尽管ECM功能完备,但它在吞吐量或效率上不能很好地扩展到更高的USB速度和更高的网络速度。NCM借鉴了从ECM实现中获得的经验,调整了数据传输协议,使其实质上更加高效。

使用NCM的主要优点在于它在单个USB批量传输中传输多个数据报。

NCM功能由一个NCM控制接口和一个NCM数据接口来实现,NCM控制接口用于配置和管理网络功能,NCM数据接口用于传输数据。

 

2 功能框架

NCM的框架如下图所示:

 

3 数据传输

NCM允许设备和主机使用一个USB传输有效地传输一个或多个以太网帧。USB传输被格式化为NCM传输块(NTB)。

有两种NTB格式:NTB-16和NTB-32。前者用来表示长度小于65536字节的NTB,后者用来表示不超过4GB的NTB。下图是NTB-32的格式。

 

3.1. NTH(NCM传输头)

NTH用来标识NTB,并向接收方提供有关NTB内容的基本信息。以NTB-32为例,NTH结构的字段如下:

Signature – ncmh

HeaderLength – NTH长度(字节)

SequenceNumber – NTB序列号,主要用来debug,function rest后清零。

BlockLength – NTB长度(字节)

NDPIndex – 首个NDP(NCM数据报指针)在NTB中的偏移位置

 

3.2. NDP(NCM数据报指针)

NCM数据报指针(NDPs)描述嵌入在NDP中的以太网数据报。与第NTH结构一样,定义了两种形式:NDP16和NDP32。以NDP32为例,NDP结构主要字段如下:

Signature – ncm0/ncm1

Length – NDP长度(字节)

NextNdpIndex – 下一个NDP的偏移位置

DatagramIndex[0] – 数据报偏移

DatagramLength[0] – 数据报长度(字节)

一个NDP中可以有多个Datagram,最后的DatagramIndex和DatagramLength的值为0。

 

4 关键描述符

---------------- IAD Descriptor --------------------
bLength                  : 0x08 (8 bytes)
bDescriptorType          : 0x0B
bFirstInterface          : 0x00
bInterfaceCount          : 0x02
bFunctionClass           : 0x02 (Communications and CDC Control)
bFunctionSubClass        : 0x0D
bFunctionProtocol        : 0x00
iFunction                : 0x08 (String Descriptor 8)
Language 0x0409         : "CDC NCM"
Data (HexDump)           : 08 0B 00 02 02 0D 00 08

IAD Descriptor: Interface 56c AssociationDescriptor,接口关联描述符,将多个接口组合在一起。

bDescriptorType        : 0x0B 表示描述符类型是IAD描述符。

bInterfaceCount         : 0x02表示组合的接口数目是2个。

bFunctionClass           : 0x02表示CDCclass。

bFunctionSubClass     : 0x0D表示NCM subclass.

 

---------------- Interface Descriptor -----------------
bLength                  : 0x09 (9 bytes)
bDescriptorType          : 0x04 (Interface Descriptor)
bInterfaceNumber         : 0x00
bAlternateSetting        : 0x00
bNumEndpoints            : 0x01 (1 Endpoint)
bInterfaceClass          : 0x02 (Communications and CDC Control)
bInterfaceSubClass       : 0x0D (Network Control Model)
bInterfaceProtocol       : 0x00 (No class specific protocol required)
iInterface               : 0x05 (String Descriptor 5)
Language 0x0409         : "CDC Network Control Model (NCM)"
Data (HexDump)           : 09 04 00 00 01 02 0D 00 05

Interface Descriptor       : 接口描述符

bInterfaceNumber         : 0x00 标识该接口为接口0

< ad8 p>bAlternateSetting          : 0x00 如果同一个接口有多个描述符设置,那该值就用来区分是哪个

bNumEndpoints            : 0x01表示该接口使用1个端点

bInterfaceClass              : 0x02 表示CDC class

bInterfaceSubClass        : 0x0D 表示NCM subclass

bInterfaceProtocol         : 0x00 表示使用标准协议

接口0用作NCM的control接口。

 

以下4个CDC InterfaceDescriptor属于functional descriptor,functional descriptor用来描述class-specific的信息,从属于某个标准接口描述符下。

-------------- CDC Interface Descriptor ---------------
bFunctionLength          : 0x05 (5 bytes)
bDescriptorType          : 0x24 (Interface)
bDescriptorSubType       : 0x00 (Header Functional Descriptor)
bcdCDC                   : 0x110 (CDC Version 1.10)
Data (HexDump)           : 05 24 00 10 01

HeaderFunctional Descriptor,CDC class-specific的描述符必须以这个描述符作为起始。

 

-------------- CDC Interface Descriptor ---------------
bFunctionLength          : 0x05 (5 bytes)
bDescriptorType          : 0x24 (Interface)
bDescriptorSubType       : 0x06 (Union Functional Descriptor)
bControlInterface        : 0x00
bSubordinateInterface[0] : 0x01
Data (HexDump)           : 05 24 06 00 01

Union Functional Descriptor,包含控制接口信息。

 

-------------- CDC Interface Descriptor ---------------
bFunctionLength          : 0x0D (13 bytes)
bDescriptorType          : 0x24 (Interface)
bDescriptorSubType       : 0x0F (Ethernet Networking Functional Descriptor)
Data (HexDump)           : 0D 24 0F 06 00 00 00 00 EA 05 00 00 00

Ethernet Networking Functional Descriptor,包含网卡的信息,比如MAC地址、统计能力等等。其中MAC地址是通过字符串index来间接表示的,位于该描述符第4个字节,这里是06,表示StringDescriptor 6中存放了MAC地址。

 

-------------- CDC Interface Descriptor ---------------
bFunctionLength          : 0x06 (6 bytes)
bDescriptorType          : 0x24 (Interface)
bDescriptorSubType       : 0x1A (Unknown)
Data (HexDump)           : 06 24 1A 00 01 11

NCM Functional Descriptor,0x1A表示NCM Functiona 2080 l Descriptor subtype。

  

----------------- Endpoint Descriptor -----------------
bLength                  : 0x07 (7 bytes)
bDescriptorType          : 0x05 (Endpoint Descriptor)
bEndpointAddress         : 0x82 (Direction=IN EndpointID=2)
bmAttributes             : 0x03 (TransferType=InterruptPeriodic)
wMaxPacketSize           : 0x0010
bInterval                : 0x09 (9 ms)
Data (HexDump)           : 07 05 82 03 10 00 09

接口0的端点描述符,使用IN-2端点,端点方向为IN(Device->Host),中断传输方式。

 

---------------- Interface Descriptor -----------------
bLength                  : 0x09 (9 bytes)
bDescriptorType          : 0x04 (Interface Descriptor)
bInterfaceNumber         : 0x01
bAlternateSetting        : 0x00
bNumEndpoints            : 0x00 (Default Control Pipe only)
bInterfaceClass          : 0x0A (CDC-Data)
bInterfaceSubClass       : 0x00
bInterfaceProtocol       : 0x01
iInterface               : 0x07 (String Descriptor 7)
Language 0x0409         : "CDC Network Data"
Data (HexDump)           : 09 04 01 00 00 0A 00 01 07

接口1的第一种设置(bAlternateSetting: 0x00),没有分配端点,那么就没有实际传输功能,暂不清楚其作用。

 

---------------- Interface Descriptor -----------------
bLength                  : 0x09 (9 bytes)
bDescriptorType          : 0x04 (Interface Descriptor)
bInterfaceNumber         : 0x01
bAlternateSetting        : 0x01
bNumEndpoints            : 0x02 (2 Endpoints)
bInterfaceClass          : 0x0A (CDC-Data)
bInterfaceSubClass       : 0x00
bInterfaceProtocol       : 0x01
iInterface               : 0x07 (String Descriptor 7)
Language 0x0409         : "CDC Network Data"
Data (HexDump)           : 09 04 01 01 02 0A 00 01 07

接口1第二种设置(bAlternateSetting: 0x01),用做NCM的data接口。分配了两个端点。

 

----------------- Endpoint Descriptor -----------------
bLength                  : 0x07 (7 bytes)
bDescriptorType          : 0x05 (Endpoint Descriptor)
bEndpointAddress         : 0x81 (Direction=IN EndpointID=1)
bmAttributes             : 0x02 (TransferType=Bulk)
wMaxPacketSize           : 0x0400 (max 1024 bytes)
bInterval                : 0x00 (never NAKs)
Data (HexDump)           : 07 05 81 02 00 04 00

接口1的端点描述符,使用了IN-1端点,传输类型为Bulk。

 

----------------- Endpoint Descriptor -----------------
bLength                  : 0x07 (7 bytes)
bDescriptorType          : 0x05 (Endpoint Descriptor)
bEndpointAddress         : 0x01 (Direction=OUT EndpointID=1)
bmAttributes             : 0x02 (TransferType=Bulk)
wMaxPacketSize           : 0x0400 (max 1024 bytes)
bInterval                : 0x00 (never NAKs)
Data (HexDump)           : 07 05 01 02 00 04 00

接口1的另一个端点描述符,使用了OUT-1端点,传输类型为Bulk。

 

5 NCM 相关的 Requests 与 Notifications

除了USB标准Requests外,NCM有自己特定的Requests和Notifications。

下表所列的 Requests,GetNtbParameters / GetNtbFormat / GetNtbInputSzie / SetNtbInputSize是必需的,其他是可选的,这几个必需的 Requests 是与 NCM 传输块(NTB)相关。

 NCM Notifications如下表,主要是通知网络连接状态和速率变化。

 关于以上Requests与Notifications的详细定义,比较琐碎,不在此一一列出,实际使用时可以查阅NCM协议规范。

 

以上就是对USB NCM的简要介绍。更为详细的信息,可以查阅USB-IF发布的规范:

https://www.usb.org/document-library/network-control-model-devices-specification-v10-and-errata-and-adopters-agreement

 

作者:bigfish99

博客:https://www.cnblogs.com/bigfish0506/

公众号:大鱼嵌入式

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: