USB NCM介紹


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

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 Functional 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/

公眾號:大魚嵌入式


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM