1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** USBX Component */ 16 /** */ 17 /** USBX Network Driver for NETX 5.3 and above */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 23 /**************************************************************************/ 24 /* */ 25 /* COMPONENT DEFINITION RELEASE */ 26 /* */ 27 /* ux_network_driver.h PORTABLE C */ 28 /* 6.1.12 */ 29 /* AUTHOR */ 30 /* */ 31 /* Chaoqiong Xiao, Microsoft Corporation */ 32 /* */ 33 /* DESCRIPTION */ 34 /* */ 35 /* This file contains all the header and extern functions used by the */ 36 /* USBX Network driver. */ 37 /* */ 38 /* RELEASE HISTORY */ 39 /* */ 40 /* DATE NAME DESCRIPTION */ 41 /* */ 42 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 43 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 44 /* resulting in version 6.1 */ 45 /* 08-02-2021 Wen Wang Modified comment(s), */ 46 /* fixed spelling error, */ 47 /* added extern "C" keyword */ 48 /* for compatibility with C++, */ 49 /* resulting in version 6.1.8 */ 50 /* 07-29-2022 Yajun Xia Modified comment(s), */ 51 /* fixed ipv6 support issue, */ 52 /* resulting in version 6.1.12 */ 53 /* */ 54 /**************************************************************************/ 55 56 #ifndef UX_NETWORK_DRIVER_H 57 #define UX_NETWORK_DRIVER_H 58 59 /* Determine if a C++ compiler is being used. If so, ensure that standard 60 C is used to process the API information. */ 61 62 #ifdef __cplusplus 63 64 /* Yes, C++ compiler is present. Use standard C. */ 65 extern "C" { 66 67 #endif 68 69 #include "tx_api.h" 70 #include "nx_api.h" 71 #define USB_NETWORK_DEVICE_MAX_INSTANCES 8 72 #define USB_NETWORK_DRIVER_SUCCESS UX_SUCCESS 73 #define USB_NETWORK_DRIVER_FAILURE UX_ERROR 74 75 #define USB_NETWORK_DEVICE_MAC_HEADER_SIZE 14 76 #define NX_ETHERNET_SIZE 14 77 #define NX_ETHERNET_ARP 0x0806 78 #define NX_ETHERNET_RARP 0x0835 79 #define NX_ETHERNET_IP 0x0800 80 #define NX_ETHERNET_IPV6 0x86DD 81 #define NX_ETHERNET_MTU 1514 82 83 typedef struct USB_NETWORK_DEVICE_STRUCT 84 { 85 86 /* ip_instance is populated by NetX, as part of the interface attachment. */ 87 NX_IP *ux_network_device_ip_instance; 88 89 /* interface_ptr is populated by NetX, as part of the interface attachment. */ 90 NX_INTERFACE *ux_network_device_interface_ptr; 91 92 /* Define synchronization objects for deactivation. Note that these are only 93 used if the activation/deactivation functions are not called under interrupt. */ 94 UCHAR ux_network_device_activated_by_thread; 95 TX_MUTEX ux_network_device_deactivate_mutex; 96 TX_SEMAPHORE ux_network_device_deactivate_semaphore; 97 UCHAR ux_network_device_deactivate_thread_waiting; 98 UINT ux_network_device_num_threads_inside; 99 100 /* usb_instance is populated by USB instance activation. */ 101 VOID *ux_network_device_usb_instance_ptr; 102 103 /* The write_function is populated by USB instance activation. */ 104 UINT (*ux_network_device_write_function)(VOID *ux_instance, NX_PACKET *packet_ptr); 105 106 USHORT ux_network_device_usb_link_up; 107 USHORT ux_network_device_link_status; 108 109 ULONG ux_network_physical_address_msw; 110 ULONG ux_network_physical_address_lsw; 111 112 113 } USB_NETWORK_DEVICE_TYPE; 114 115 116 UINT _ux_network_driver_init(VOID); 117 118 UINT _ux_network_driver_activate(VOID *ux_instance, UINT(*ux_network_device_write_function)(VOID *, NX_PACKET *), 119 VOID **ux_network_handle, ULONG physical_address_msw, ULONG physical_address_lsw); 120 121 UINT _ux_network_driver_deactivate(VOID *ux_instance, VOID *ux_network_handle); 122 123 124 VOID _ux_network_driver_entry(NX_IP_DRIVER *nx_ip_driver); 125 126 VOID _ux_network_driver_link_up(VOID *ux_network_handle); 127 VOID _ux_network_driver_link_down(VOID *ux_network_handle); 128 129 VOID _ux_network_driver_packet_received(VOID *ux_network_handle, NX_PACKET *packet_ptr); 130 /* Determine if a C++ compiler is being used. If so, complete the standard 131 C conditional started above. */ 132 #ifdef __cplusplus 133 } 134 #endif 135 136 #endif 137