NetBurner 3.5.8
PDF Version
Toggle main menu visibility
src/ncm_protocol.h
1
11
12
#ifndef __NCM_PROTOCOL_H
13
#define __NCM_PROTOCOL_H
14
15
#include <stdint.h>
16
17
/*******************************************************************************
18
* NCM Control Request Codes (CDC class-specific)
19
******************************************************************************/
20
#define NCM_SET_ETHERNET_MULTICAST_FILTERS (0x40)
21
#define NCM_SET_ETHERNET_PM_PATTERN_FILTER (0x41)
22
#define NCM_GET_ETHERNET_PM_PATTERN_FILTER (0x42)
23
#define NCM_SET_ETHERNET_PACKET_FILTER (0x43)
24
#define NCM_GET_ETHERNET_STATISTIC (0x44)
25
#define NCM_GET_NTB_PARAMETERS (0x80)
26
#define NCM_GET_NET_ADDRESS (0x81)
27
#define NCM_SET_NET_ADDRESS (0x82)
28
#define NCM_GET_NTB_FORMAT (0x83)
29
#define NCM_SET_NTB_FORMAT (0x84)
30
#define NCM_GET_NTB_INPUT_SIZE (0x85)
31
#define NCM_SET_NTB_INPUT_SIZE (0x86)
32
#define NCM_GET_MAX_DATAGRAM_SIZE (0x87)
33
#define NCM_SET_MAX_DATAGRAM_SIZE (0x88)
34
#define NCM_GET_CRC_MODE (0x89)
35
#define NCM_SET_CRC_MODE (0x8A)
36
37
/*******************************************************************************
38
* NCM Notification Codes
39
******************************************************************************/
40
#define NCM_NOTIFICATION_NETWORK_CONNECTION (0x00)
41
#define NCM_NOTIFICATION_RESPONSE_AVAILABLE (0x01)
42
#define NCM_NOTIFICATION_CONNECTION_SPEED_CHANGE (0x2A)
43
44
/*******************************************************************************
45
* NCM NTB Signatures
46
******************************************************************************/
47
#define NCM_NTH16_SIGNATURE (0x484D434E)
// "NCMH" little-endian
48
#define NCM_NTH32_SIGNATURE (0x686D636E)
// "ncmh" little-endian
49
#define NCM_NDP16_SIGNATURE_NCM0 (0x304D434E)
// "NCM0" little-endian (no CRC)
50
#define NCM_NDP16_SIGNATURE_NCM1 (0x314D434E)
// "NCM1" little-endian (with CRC)
51
#define NCM_NDP32_SIGNATURE_NCM0 (0x306D636E)
// "ncm0" little-endian
52
#define NCM_NDP32_SIGNATURE_NCM1 (0x316D636E)
// "ncm1" little-endian
53
54
/*******************************************************************************
55
* NCM Constants
56
******************************************************************************/
57
#define NCM_MAX_SEGMENT_SIZE (1514)
// Standard Ethernet frame
58
#define NCM_MAX_DATAGRAM_SIZE (1514)
// Max datagram (Ethernet MTU + header)
59
#define NCM_MIN_NTB_SIZE (2048)
// Minimum NTB size
60
#define NCM_MAX_NTB_SIZE (2048)
// Maximum NTB size we support (reduced for DTCM)
61
#define NCM_NTB_ALIGNMENT (4)
// NTB alignment requirement
62
#define NCM_NDP_ALIGNMENT (4)
// NDP alignment requirement
63
#define NCM_DATAGRAM_ALIGNMENT (4)
// Datagram alignment
64
65
// NTH16 header size
66
#define NCM_NTH16_SIZE (12)
67
68
// NDP16 header size (without entries)
69
#define NCM_NDP16_HEADER_SIZE (8)
70
71
// Each NDP16 entry is 4 bytes (2-byte index + 2-byte length)
72
#define NCM_NDP16_ENTRY_SIZE (4)
73
74
// Ethernet frame limits
75
#define NCM_ETHER_ADDR_SIZE (6)
76
#define NCM_ETHER_MAX_FRAME_SIZE (1514)
// Without VLAN
77
#define NCM_ETHER_MTU (1500)
78
79
/*******************************************************************************
80
* NCM Format Flags
81
******************************************************************************/
82
#define NCM_NTB_FORMAT_NTB16 (0x0000)
83
#define NCM_NTB_FORMAT_NTB32 (0x0001)
84
85
/*******************************************************************************
86
* NCM bmNetworkCapabilities flags
87
******************************************************************************/
88
#define NCM_NCAP_PACKET_FILTER (1 << 0)
89
#define NCM_NCAP_NET_ADDRESS (1 << 1)
90
#define NCM_NCAP_ENCAP_COMMAND (1 << 2)
91
#define NCM_NCAP_MAX_DATAGRAM (1 << 3)
92
#define NCM_NCAP_CRC_MODE (1 << 4)
93
#define NCM_NCAP_NTB_INPUT_SIZE_8BYTE (1 << 5)
94
95
/*******************************************************************************
96
* NCM Packet Filter Bits (same as NDIS/RNDIS)
97
******************************************************************************/
98
#define NCM_PACKET_TYPE_PROMISCUOUS (1 << 0)
99
#define NCM_PACKET_TYPE_ALL_MULTICAST (1 << 1)
100
#define NCM_PACKET_TYPE_DIRECTED (1 << 2)
101
#define NCM_PACKET_TYPE_BROADCAST (1 << 3)
102
#define NCM_PACKET_TYPE_MULTICAST (1 << 4)
103
104
/*******************************************************************************
105
* NCM Structures
106
******************************************************************************/
107
108
#pragma pack(push, 1)
109
116
typedef
struct
{
117
uint16_t wLength;
// Size of this structure (28)
118
uint16_t bmNtbFormatsSupported;
// Bit 0: 16-bit NTB, Bit 1: 32-bit NTB
119
uint32_t dwNtbInMaxSize;
// Max IN NTB size
120
uint16_t wNdpInDivisor;
// Divisor for IN NDP alignment
121
uint16_t wNdpInPayloadRemainder;
// Remainder for IN NDP alignment
122
uint16_t wNdpInAlignment;
// Alignment for IN NDP
123
uint16_t wReserved;
// Reserved (0)
124
uint32_t dwNtbOutMaxSize;
// Max OUT NTB size
125
uint16_t wNdpOutDivisor;
// Divisor for OUT NDP alignment
126
uint16_t wNdpOutPayloadRemainder;
// Remainder for OUT NDP alignment
127
uint16_t wNdpOutAlignment;
// Alignment for OUT NDP
128
uint16_t wNtbOutMaxDatagrams;
// Max datagrams per OUT NTB (0 = no limit)
129
}
ncm_ntb_parameters_t
;
130
137
typedef
struct
{
138
uint32_t dwSignature;
// "NCMH" = 0x484D434E
139
uint16_t wHeaderLength;
// Size of this header (12)
140
uint16_t wSequence;
// Sequence number, wraps
141
uint16_t wBlockLength;
// Total NTB size in bytes
142
uint16_t wNdpIndex;
// Offset to first NDP16
143
}
ncm_nth16_t
;
144
151
typedef
struct
{
152
uint16_t wDatagramIndex;
// Offset of datagram in NTB
153
uint16_t wDatagramLength;
// Length of datagram
154
}
ncm_ndp16_entry_t
;
155
162
typedef
struct
{
163
uint32_t dwSignature;
// "NCM0" = 0x304D434E (no CRC)
164
uint16_t wLength;
// Size of NDP16 including entries
165
uint16_t wNextNdpIndex;
// Offset to next NDP16 or 0
166
// ncm_ndp16_entry_t entries[]; // Variable length array follows
167
}
ncm_ndp16_t
;
168
172
typedef
struct
{
173
uint8_t bmRequestType;
// 0xA1 (Device-to-host, Class, Interface)
174
uint8_t bNotificationCode;
// NETWORK_CONNECTION
175
uint16_t wValue;
// 0 = disconnected, 1 = connected
176
uint16_t wIndex;
// Interface number
177
uint16_t wLength;
// 0
178
}
ncm_notification_network_t
;
179
183
typedef
struct
{
184
uint8_t bmRequestType;
// 0xA1
185
uint8_t bNotificationCode;
// CONNECTION_SPEED_CHANGE
186
uint16_t wValue;
// 0
187
uint16_t wIndex;
// Interface number
188
uint16_t wLength;
// 8
189
uint32_t DLBitRate;
// Downstream bit rate (bps)
190
uint32_t ULBitRate;
// Upstream bit rate (bps)
191
}
ncm_notification_speed_t
;
192
196
typedef
struct
{
197
uint32_t dwNtbInMaxSize;
// Max NTB size host will send
198
uint16_t wNtbInMaxDatagrams;
// Max datagrams per NTB
199
uint16_t wReserved;
// Reserved
200
}
ncm_ntb_input_size_t
;
201
202
#pragma pack(pop)
203
207
typedef
enum
{
208
NCM_STATE_DISCONNECTED = 0,
// USB not configured or alt setting 0
209
NCM_STATE_CONFIGURED,
// USB configured, alt setting 0 (no data endpoints)
210
NCM_STATE_CONNECTED
// Alt setting 1 selected, data endpoints active
211
} ncm_state_t;
212
216
typedef
enum
{
217
NCM_TX_IDLE = 0,
218
NCM_TX_SENDING,
219
NCM_TX_COMPLETE
220
} ncm_tx_state_t;
221
225
typedef
enum
{
226
NCM_RX_IDLE = 0,
227
NCM_RX_RECEIVING,
228
NCM_RX_PROCESSING,
229
NCM_RX_COMPLETE
230
} ncm_rx_state_t;
231
232
#endif
/* __NCM_PROTOCOL_H */
ncm_ndp16_entry_t
NCM NDP16 Datagram Entry.
Definition
src/ncm_protocol.h:151
ncm_ndp16_t
NCM NDP16 - 16-bit NCM Datagram Pointer.
Definition
src/ncm_protocol.h:162
ncm_notification_network_t
NCM Network Connection Notification.
Definition
src/ncm_protocol.h:172
ncm_notification_speed_t
NCM Connection Speed Change Notification.
Definition
src/ncm_protocol.h:183
ncm_ntb_input_size_t
NCM SET_NTB_INPUT_SIZE structure (when 8-byte form is used).
Definition
src/ncm_protocol.h:196
ncm_ntb_parameters_t
NCM NTB Parameters Structure.
Definition
src/ncm_protocol.h:116
ncm_nth16_t
NCM NTH16 - 16-bit NCM Transfer Header.
Definition
src/ncm_protocol.h:137
examples
PlatformSpecific
SOMRT1061
USB
USB_NCM_NetworkInterface
src
ncm_protocol.h
Generated by
1.18.0