1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** USBX Component */ 17 /** */ 18 /** CDC ECM Class */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /**************************************************************************/ 25 /* */ 26 /* COMPONENT DEFINITION RELEASE */ 27 /* */ 28 /* ux_host_class_cdc_ecm.h PORTABLE C */ 29 /* 6.2.0 */ 30 /* AUTHOR */ 31 /* */ 32 /* Chaoqiong Xiao, Microsoft Corporation */ 33 /* */ 34 /* DESCRIPTION */ 35 /* */ 36 /* This file contains all the header and extern functions used by the */ 37 /* USBX CDC_ECM class. */ 38 /* */ 39 /* RELEASE HISTORY */ 40 /* */ 41 /* DATE NAME DESCRIPTION */ 42 /* */ 43 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 44 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 45 /* used UX prefix to refer to */ 46 /* TX symbols instead of using */ 47 /* them directly, */ 48 /* resulting in version 6.1 */ 49 /* 02-02-2021 Xiuwen Cai Modified comment(s), added */ 50 /* compile option for using */ 51 /* packet pool from NetX, */ 52 /* resulting in version 6.1.4 */ 53 /* 08-02-2021 Chaoqiong Xiao Modified comment(s), */ 54 /* added extern "C" keyword */ 55 /* for compatibility with C++, */ 56 /* resulting in version 6.1.8 */ 57 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */ 58 /* fixed standalone compile, */ 59 /* resulting in version 6.1.11 */ 60 /* 10-31-2022 Chaoqiong Xiao Modified comment(s), */ 61 /* supported NX packet chain, */ 62 /* resulting in version 6.2.0 */ 63 /* */ 64 /**************************************************************************/ 65 66 #ifndef UX_HOST_CLASS_CDC_ECM_H 67 #define UX_HOST_CLASS_CDC_ECM_H 68 69 /* Determine if a C++ compiler is being used. If so, ensure that standard 70 C is used to process the API information. */ 71 72 #ifdef __cplusplus 73 74 /* Yes, C++ compiler is present. Use standard C. */ 75 extern "C" { 76 77 #endif 78 79 #if !defined(UX_HOST_STANDALONE) 80 #include "nx_api.h" 81 #include "ux_network_driver.h" 82 #else 83 84 /* Assume NX things for compiling. */ 85 #define NX_PACKET VOID* 86 #define NX_PACKET_POOL VOID* 87 #endif 88 89 90 /* Define CDC_ECM Class constants. Insert here the PID/VID of vendors and products using the CDC ECM chipset. 91 It is a better mechanism to put this value in the ux_user.h file. */ 92 #ifndef UX_HOST_CLASS_CDC_ECM_VENDOR_ID 93 #define UX_HOST_CLASS_CDC_ECM_VENDOR_ID 0x0770 94 #define UX_HOST_CLASS_CDC_ECM_PRODUCT_ID 0x1042 95 #endif 96 97 /* Define CDC_ECM Class/subclass/protocol constants. */ 98 #define UX_HOST_CLASS_CDC_CONTROL_CLASS 0x02 99 #define UX_HOST_CLASS_CDC_DATA_CLASS 0x0A 100 #define UX_HOST_CLASS_CDC_ECM_CONTROL_SUBCLASS 0x06 101 #define UX_HOST_CLASS_CDC_ECM_CONTROL_PROTOCOL 0x00 102 #define UX_HOST_CLASS_CDC_ECM_CS_INTERFACE 0x24 103 #define UX_HOST_CLASS_CDC_ECM_FUNCTIONAL_DESCRIPTOR 0x0F 104 #define UX_HOST_CLASS_CDC_ECM_MAC_ADDRESS_STRING_LENGTH 32 105 #define UX_HOST_CLASS_CDC_ECM_MAC_ADDRESS_ASCII_LENGTH 8 106 107 #define UX_HOST_CLASS_CDC_ECM_SPEED_SELECTED_100MPBS 0x100 108 #define UX_HOST_CLASS_CDC_ECM_SPEED_SELECTED_10MPBS 0x10 109 #define UX_HOST_CLASS_CDC_ECM_LINK_STATE_DOWN 0 110 #define UX_HOST_CLASS_CDC_ECM_LINK_STATE_UP 1 111 #define UX_HOST_CLASS_CDC_ECM_LINK_STATE_PENDING_UP 2 112 #define UX_HOST_CLASS_CDC_ECM_LINK_STATE_PENDING_DOWN 3 113 #define UX_HOST_CLASS_CDC_ECM_BASE_IP_ADDRESS 0xC0A80001 114 #define UX_HOST_CLASS_CDC_ECM_BASE_IP_MASK 0xFFFFFF00 115 #define UX_HOST_CLASS_CDC_ECM_MAX_MTU 1518 116 #define UX_HOST_CLASS_CDC_ECM_ETHERNET_IP 0x0800 117 #define UX_HOST_CLASS_CDC_ECM_ETHERNET_ARP 0x0806 118 #define UX_HOST_CLASS_CDC_ECM_ETHERNET_RARP 0x8035 119 #define UX_HOST_CLASS_CDC_ECM_ETHERNET_PACKET_SIZE 1536 120 #define UX_HOST_CLASS_CDC_ECM_NX_ALIGN_PADDING 2 121 #ifndef UX_HOST_CLASS_CDC_ECM_NX_PKPOOL_ENTRIES 122 #define UX_HOST_CLASS_CDC_ECM_NX_PKPOOL_ENTRIES 16 123 #endif 124 125 #define UX_HOST_CLASS_CDC_ECM_NX_PACKET_SIZE sizeof(NX_PACKET) 126 127 #define UX_HOST_CLASS_CDC_ECM_NX_PAYLOAD_SIZE_ASSERT UX_COMPILE_TIME_ASSERT(!UX_OVERFLOW_CHECK_ADD_ULONG(UX_HOST_CLASS_CDC_ECM_ETHERNET_PACKET_SIZE, UX_HOST_CLASS_CDC_ECM_NX_ALIGN_PADDING), UX_HOST_CLASS_CDC_ECM_NX_PAYLOAD_SIZE_calc_ovf) 128 #define UX_HOST_CLASS_CDC_ECM_NX_PAYLOAD_SIZE (UX_HOST_CLASS_CDC_ECM_ETHERNET_PACKET_SIZE + UX_HOST_CLASS_CDC_ECM_NX_ALIGN_PADDING) 129 130 #define UX_HOST_CLASS_CDC_ECM_NX_BUFF_SIZE_ASSERT \ 131 UX_HOST_CLASS_CDC_ECM_NX_PAYLOAD_SIZE_ASSERT \ 132 UX_COMPILE_TIME_ASSERT(!UX_OVERFLOW_CHECK_ADD_ULONG( \ 133 UX_HOST_CLASS_CDC_ECM_NX_PAYLOAD_SIZE, \ 134 UX_HOST_CLASS_CDC_ECM_NX_PACKET_SIZE), \ 135 UX_HOST_CLASS_CDC_ECM_NX_BUFF_SIZE_calc_ovf) 136 #define UX_HOST_CLASS_CDC_ECM_NX_BUFF_SIZE (UX_HOST_CLASS_CDC_ECM_NX_PAYLOAD_SIZE + UX_HOST_CLASS_CDC_ECM_NX_PACKET_SIZE) 137 138 #define UX_HOST_CLASS_CDC_ECM_NX_ETHERNET_POOL_ALLOCSIZE_ASSERT \ 139 UX_HOST_CLASS_CDC_ECM_NX_BUFF_SIZE_ASSERT \ 140 UX_COMPILE_TIME_ASSERT(!UX_OVERFLOW_CHECK_MULC_ULONG( \ 141 UX_HOST_CLASS_CDC_ECM_NX_PKPOOL_ENTRIES, \ 142 UX_HOST_CLASS_CDC_ECM_NX_BUFF_SIZE), \ 143 UX_HOST_CLASS_CDC_ECM_NX_ETHERNET_POOL_ALLOCSIZE_calc1_ovf) \ 144 UX_COMPILE_TIME_ASSERT(!UX_OVERFLOW_CHECK_ADD_ULONG( \ 145 UX_HOST_CLASS_CDC_ECM_NX_PKPOOL_ENTRIES * \ 146 UX_HOST_CLASS_CDC_ECM_NX_BUFF_SIZE, \ 147 32), UX_HOST_CLASS_CDC_ECM_NX_ETHERNET_POOL_ALLOCSIZE_calc2_ovf) 148 #define UX_HOST_CLASS_CDC_ECM_NX_ETHERNET_POOL_ALLOCSIZE (UX_HOST_CLASS_CDC_ECM_NX_PKPOOL_ENTRIES * UX_HOST_CLASS_CDC_ECM_NX_BUFF_SIZE + 32) 149 150 #ifdef NX_DISABLE_PACKET_CHAIN 151 #undef UX_HOST_CLASS_CDC_ECM_PACKET_CHAIN_SUPPORT 152 #else 153 #define UX_HOST_CLASS_CDC_ECM_PACKET_CHAIN_SUPPORT 154 #endif 155 156 #define UX_HOST_CLASS_CDC_ECM_ETHERNET_SIZE 14 157 158 #define UX_HOST_CLASS_CDC_ECM_DEVICE_INIT_DELAY (1 * UX_PERIODIC_RATE) 159 #define UX_HOST_CLASS_CDC_ECM_CLASS_TRANSFER_TIMEOUT 300000 160 #define UX_HOST_CLASS_CDC_ECM_SETUP_BUFFER_SIZE 16 161 162 163 /* Define NetX errors inside the CDC ECM class. */ 164 #define UX_HOST_CLASS_CDC_ECM_NX_SUCCESS 0x00 165 #define UX_HOST_CLASS_CDC_ECM_NX_NO_PACKET 0x01 166 #define UX_HOST_CLASS_CDC_ECM_NX_UNDERFLOW 0x02 167 #define UX_HOST_CLASS_CDC_ECM_NX_OVERFLOW 0x03 168 #define UX_HOST_CLASS_CDC_ECM_NX_NO_MAPPING 0x04 169 #define UX_HOST_CLASS_CDC_ECM_NX_DELETED 0x05 170 #define UX_HOST_CLASS_CDC_ECM_NX_POOL_ERROR 0x06 171 #define UX_HOST_CLASS_CDC_ECM_NX_PTR_ERROR 0x07 172 #define UX_HOST_CLASS_CDC_ECM_NX_WAIT_ERROR 0x08 173 #define UX_HOST_CLASS_CDC_ECM_NX_SIZE_ERROR 0x09 174 #define UX_HOST_CLASS_CDC_ECM_NX_OPTION_ERROR 0x0a 175 #define UX_HOST_CLASS_CDC_ECM_NX_DELETE_ERROR 0x10 176 #define UX_HOST_CLASS_CDC_ECM_NX_CALLER_ERROR 0x11 177 #define UX_HOST_CLASS_CDC_ECM_NX_INVALID_PACKET 0x12 178 #define UX_HOST_CLASS_CDC_ECM_NX_INVALID_SOCKET 0x13 179 #define UX_HOST_CLASS_CDC_ECM_NX_NOT_ENABLED 0x14 180 #define UX_HOST_CLASS_CDC_ECM_NX_ALREADY_ENABLED 0x15 181 #define UX_HOST_CLASS_CDC_ECM_NX_ENTRY_NOT_FOUND 0x16 182 #define UX_HOST_CLASS_CDC_ECM_NX_NO_MORE_ENTRIES 0x17 183 #define UX_HOST_CLASS_CDC_ECM_NX_ARP_TIMER_ERROR 0x18 184 #define UX_HOST_CLASS_CDC_ECM_NX_RESERVED_CODE0 0x19 185 #define UX_HOST_CLASS_CDC_ECM_NX_WAIT_ABORTED 0x1A 186 #define UX_HOST_CLASS_CDC_ECM_NX_IP_INTERNAL_ERROR 0x20 187 #define UX_HOST_CLASS_CDC_ECM_NX_IP_ADDRESS_ERROR 0x21 188 #define UX_HOST_CLASS_CDC_ECM_NX_ALREADY_BOUND 0x22 189 #define UX_HOST_CLASS_CDC_ECM_NX_PORT_UNAVAILABLE 0x23 190 #define UX_HOST_CLASS_CDC_ECM_NX_NOT_BOUND 0x24 191 #define UX_HOST_CLASS_CDC_ECM_NX_RESERVED_CODE1 0x25 192 #define UX_HOST_CLASS_CDC_ECM_NX_SOCKET_UNBOUND 0x26 193 #define UX_HOST_CLASS_CDC_ECM_NX_NOT_CREATED 0x27 194 #define UX_HOST_CLASS_CDC_ECM_NX_SOCKETS_BOUND 0x28 195 #define UX_HOST_CLASS_CDC_ECM_NX_NO_RESPONSE 0x29 196 #define UX_HOST_CLASS_CDC_ECM_NX_POOL_DELETED 0x30 197 #define UX_HOST_CLASS_CDC_ECM_NX_ALREADY_RELEASED 0x31 198 #define UX_HOST_CLASS_CDC_ECM_NX_RESERVED_CODE2 0x32 199 #define UX_HOST_CLASS_CDC_ECM_NX_MAX_LISTEN 0x33 200 #define UX_HOST_CLASS_CDC_ECM_NX_DUPLICATE_LISTEN 0x34 201 #define UX_HOST_CLASS_CDC_ECM_NX_NOT_CLOSED 0x35 202 #define UX_HOST_CLASS_CDC_ECM_NX_NOT_LISTEN_STATE 0x36 203 #define UX_HOST_CLASS_CDC_ECM_NX_IN_PROGRESS 0x37 204 #define UX_HOST_CLASS_CDC_ECM_NX_NOT_CONNECTED 0x38 205 #define UX_HOST_CLASS_CDC_ECM_NX_WINDOW_OVERFLOW 0x39 206 #define UX_HOST_CLASS_CDC_ECM_NX_ALREADY_SUSPENDED 0x40 207 #define UX_HOST_CLASS_CDC_ECM_NX_DISCONNECT_FAILED 0x41 208 #define UX_HOST_CLASS_CDC_ECM_NX_STILL_BOUND 0x42 209 #define UX_HOST_CLASS_CDC_ECM_NX_NOT_SUCCESSFUL 0x43 210 #define UX_HOST_CLASS_CDC_ECM_NX_UNHANDLED_COMMAND 0x44 211 #define UX_HOST_CLASS_CDC_ECM_NX_NO_FREE_PORTS 0x45 212 #define UX_HOST_CLASS_CDC_ECM_NX_INVALID_PORT 0x46 213 #define UX_HOST_CLASS_CDC_ECM_NX_INVALID_RELISTEN 0x47 214 #define UX_HOST_CLASS_CDC_ECM_NX_CONNECTION_PENDING 0x48 215 #define UX_HOST_CLASS_CDC_ECM_NX_TX_QUEUE_DEPTH 0x49 216 #define UX_HOST_CLASS_CDC_ECM_NX_NOT_IMPLEMENTED 0x80 217 218 /* Define CDC_ECM Class packet equivalences. */ 219 220 #define UX_HOST_CLASS_CDC_ECM_PACKET_SIZE 128 221 #define UX_HOST_CLASS_CDC_ECM_NODE_ID_LENGTH 6 222 223 /* Define supported notification types. */ 224 225 #define UX_HOST_CLASS_CDC_ECM_NOTIFICATION_NETWORK_CONNECTION 0x00 226 #define UX_HOST_CLASS_CDC_ECM_NOTIFICATION_RESPONSE_AVAILABLE 0x01 227 #define UX_HOST_CLASS_CDC_ECM_NOTIFICATION_SERIAL_STATE 0x20 228 #define UX_HOST_CLASS_CDC_ECM_NOTIFICATION_CALL_STATE_CHANGE 0x28 229 #define UX_HOST_CLASS_CDC_ECM_NOTIFICATION_LINE_STATE_CHANGE 0x29 230 #define UX_HOST_CLASS_CDC_ECM_NOTIFICATION_SPEED_CHANGE 0x2A 231 232 /* Define notification packet format. */ 233 234 #define UX_HOST_CLASS_CDC_ECM_NPF_REQUEST_TYPE 0x00 235 #define UX_HOST_CLASS_CDC_ECM_NPF_NOTIFICATION_TYPE 0x01 236 #define UX_HOST_CLASS_CDC_ECM_NPF_VALUE 0x02 237 #define UX_HOST_CLASS_CDC_ECM_NPF_INDEX 0x04 238 #define UX_HOST_CLASS_CDC_ECM_NPF_LENGTH 0x06 239 240 /* Define supported notification values. */ 241 242 #define UX_HOST_CLASS_CDC_ECM_NOTIFICATION_NETWORK_LINK_DOWN 0x00 243 #define UX_HOST_CLASS_CDC_ECM_NOTIFICATION_NETWORK_LINK_UP 0x01 244 245 /* Define packet allocation timeout in milliseconds. */ 246 247 #ifndef UX_HOST_CLASS_CDC_ECM_PACKET_POOL_WAIT 248 #define UX_HOST_CLASS_CDC_ECM_PACKET_POOL_WAIT 1000 249 #endif 250 251 /* Define packet pool waiting time in milliseconds. */ 252 253 #ifndef UX_HOST_CLASS_CDC_ECM_PACKET_POOL_INSTANCE_WAIT 254 #define UX_HOST_CLASS_CDC_ECM_PACKET_POOL_INSTANCE_WAIT 100 255 #endif 256 257 /* Define CDC_ECM Class instance structure. */ 258 259 typedef struct UX_HOST_CLASS_CDC_ECM_STRUCT 260 { 261 struct UX_HOST_CLASS_CDC_ECM_STRUCT 262 *ux_host_class_cdc_ecm_next_instance; 263 UX_HOST_CLASS *ux_host_class_cdc_ecm_class; 264 UX_DEVICE *ux_host_class_cdc_ecm_device; 265 UX_ENDPOINT *ux_host_class_cdc_ecm_bulk_in_endpoint; 266 UX_ENDPOINT *ux_host_class_cdc_ecm_bulk_out_endpoint; 267 UX_ENDPOINT *ux_host_class_cdc_ecm_interrupt_endpoint; 268 UX_INTERFACE *ux_host_class_cdc_ecm_interface_data; 269 UX_INTERFACE *ux_host_class_cdc_ecm_interface_control; 270 UCHAR ux_host_class_cdc_ecm_bulk_in_transfer_check_and_arm_in_process; 271 UCHAR ux_host_class_cdc_ecm_bulk_in_transfer_waiting_for_check_and_arm_to_finish; 272 UX_SEMAPHORE ux_host_class_cdc_ecm_bulk_in_transfer_waiting_for_check_and_arm_to_finish_semaphore; 273 UCHAR ux_host_class_cdc_ecm_bulk_out_transfer_check_and_arm_in_process; 274 UCHAR ux_host_class_cdc_ecm_bulk_out_transfer_waiting_for_check_and_arm_to_finish; 275 UX_SEMAPHORE ux_host_class_cdc_ecm_bulk_out_transfer_waiting_for_check_and_arm_to_finish_semaphore; 276 UINT ux_host_class_cdc_ecm_instance_status; 277 UINT ux_host_class_cdc_ecm_state; 278 UX_SEMAPHORE ux_host_class_cdc_ecm_interrupt_notification_semaphore; 279 UX_THREAD ux_host_class_cdc_ecm_thread; 280 UCHAR *ux_host_class_cdc_ecm_thread_stack; 281 ULONG ux_host_class_cdc_ecm_notification_count; 282 ULONG ux_host_class_cdc_ecm_primary_phy_id; 283 ULONG ux_host_class_cdc_ecm_primary_phy_type; 284 ULONG ux_host_class_cdc_ecm_secondary_phy_id; 285 ULONG ux_host_class_cdc_ecm_secondary_phy_type; 286 ULONG ux_host_class_cdc_ecm_model_revision_number; 287 ULONG ux_host_class_cdc_ecm_vendor_model_number; 288 ULONG ux_host_class_cdc_ecm_speed_selected; 289 ULONG ux_host_class_cdc_ecm_device_state; 290 ULONG ux_host_class_cdc_ecm_link_state; 291 NX_PACKET *ux_host_class_cdc_ecm_xmit_queue_head; 292 NX_PACKET *ux_host_class_cdc_ecm_xmit_queue_tail; 293 NX_PACKET_POOL *ux_host_class_cdc_ecm_packet_pool; 294 #ifdef UX_HOST_CLASS_CDC_ECM_PACKET_CHAIN_SUPPORT 295 UCHAR *ux_host_class_cdc_ecm_xmit_buffer; 296 UCHAR *ux_host_class_cdc_ecm_receive_buffer; 297 #endif 298 299 UCHAR ux_host_class_cdc_ecm_node_id[UX_HOST_CLASS_CDC_ECM_NODE_ID_LENGTH]; 300 VOID (*ux_host_class_cdc_ecm_device_status_change_callback)(struct UX_HOST_CLASS_CDC_ECM_STRUCT *cdc_ecm, 301 ULONG device_state); 302 VOID *ux_host_class_cdc_ecm_network_handle; 303 304 } UX_HOST_CLASS_CDC_ECM; 305 306 307 /* Define ECM Interface Functional descriptor. */ 308 309 #define UX_HOST_CLASS_CDC_ECM_INTERFACE_DESCRIPTOR_ENTRIES 8 310 #define UX_HOST_CLASS_CDC_ECM_INTERFACE_DESCRIPTOR_LENGTH 13 311 312 typedef struct UX_HOST_CLASS_ECM_INTERFACE_DESCRIPTOR_STRUCT 313 { 314 ULONG bFunctionLength; 315 ULONG bDescriptorType; 316 ULONG bDescriptorSubtype; 317 ULONG iMACAddress; 318 ULONG bmEthernetStatistics; 319 ULONG wMaxSegmentSize; 320 ULONG wNumberMCFilters; 321 ULONG bNumberPowerFilters; 322 } UX_HOST_CLASS_ECM_INTERFACE_DESCRIPTOR; 323 324 /* Define CDC ECM Class function prototypes. */ 325 326 UINT _ux_host_class_cdc_ecm_activate(UX_HOST_CLASS_COMMAND *command); 327 UINT _ux_host_class_cdc_ecm_deactivate(UX_HOST_CLASS_COMMAND *command); 328 UINT _ux_host_class_cdc_ecm_endpoints_get(UX_HOST_CLASS_CDC_ECM *cdc_ecm); 329 UINT _ux_host_class_cdc_ecm_entry(UX_HOST_CLASS_COMMAND *command); 330 UINT _ux_host_class_cdc_ecm_write(VOID *cdc_ecm_class, NX_PACKET *packet); 331 VOID _ux_host_class_cdc_ecm_interrupt_notification(UX_TRANSFER *transfer_request); 332 VOID _ux_host_class_cdc_ecm_thread(ULONG parameter); 333 VOID _ux_host_class_cdc_ecm_transmission_callback(UX_TRANSFER *transfer_request); 334 VOID _ux_host_class_cdc_ecm_transmit_queue_clean(UX_HOST_CLASS_CDC_ECM *cdc_ecm_control); 335 UINT _ux_host_class_cdc_ecm_mac_address_get(UX_HOST_CLASS_CDC_ECM *cdc_ecm); 336 337 /* Define CDC ECM Class API prototypes. */ 338 339 #define ux_host_class_cdc_ecm_entry _ux_host_class_cdc_ecm_entry 340 #define ux_host_class_cdc_ecm_write _ux_host_class_cdc_ecm_write 341 342 /* Determine if a C++ compiler is being used. If so, complete the standard 343 C conditional started above. */ 344 #ifdef __cplusplus 345 } 346 #endif 347 348 #endif 349