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 /**   USBX Network Driver for NETX 5.3 and above                          */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    ux_network_driver.h                                 PORTABLE C      */
29 /*                                                           6.1.12       */
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 Network driver.                                                */
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 /*                                            resulting in version 6.1    */
46 /*  08-02-2021     Wen Wang                 Modified comment(s),          */
47 /*                                            fixed spelling error,       */
48 /*                                            added extern "C" keyword    */
49 /*                                            for compatibility with C++, */
50 /*                                            resulting in version 6.1.8  */
51 /*  07-29-2022     Yajun Xia                Modified comment(s),          */
52 /*                                            fixed ipv6 support issue,   */
53 /*                                            resulting in version 6.1.12 */
54 /*                                                                        */
55 /**************************************************************************/
56 
57 #ifndef UX_NETWORK_DRIVER_H
58 #define UX_NETWORK_DRIVER_H
59 
60 /* Determine if a C++ compiler is being used.  If so, ensure that standard
61    C is used to process the API information.  */
62 
63 #ifdef   __cplusplus
64 
65 /* Yes, C++ compiler is present.  Use standard C.  */
66 extern   "C" {
67 
68 #endif
69 
70 #include "tx_api.h"
71 #include "nx_api.h"
72 #define USB_NETWORK_DEVICE_MAX_INSTANCES    8
73 #define USB_NETWORK_DRIVER_SUCCESS          UX_SUCCESS
74 #define USB_NETWORK_DRIVER_FAILURE          UX_ERROR
75 
76 #define USB_NETWORK_DEVICE_MAC_HEADER_SIZE  14
77 #define NX_ETHERNET_SIZE                    14
78 #define NX_ETHERNET_ARP                     0x0806
79 #define NX_ETHERNET_RARP                    0x0835
80 #define NX_ETHERNET_IP                      0x0800
81 #define NX_ETHERNET_IPV6                    0x86DD
82 #define NX_ETHERNET_MTU                     1514
83 
84 typedef struct USB_NETWORK_DEVICE_STRUCT
85 {
86 
87     /* ip_instance is populated by NetX, as part of the interface attachment. */
88     NX_IP           *ux_network_device_ip_instance;
89 
90     /* interface_ptr is populated by NetX, as part of the interface attachment. */
91     NX_INTERFACE    *ux_network_device_interface_ptr;
92 
93     /* Define synchronization objects for deactivation. Note that these are only
94        used if the activation/deactivation functions are not called under interrupt.  */
95     UCHAR           ux_network_device_activated_by_thread;
96     TX_MUTEX        ux_network_device_deactivate_mutex;
97     TX_SEMAPHORE    ux_network_device_deactivate_semaphore;
98     UCHAR           ux_network_device_deactivate_thread_waiting;
99     UINT            ux_network_device_num_threads_inside;
100 
101     /* usb_instance is populated by USB instance activation. */
102     VOID            *ux_network_device_usb_instance_ptr;
103 
104     /* The write_function is populated by USB instance activation. */
105     UINT            (*ux_network_device_write_function)(VOID *ux_instance, NX_PACKET *packet_ptr);
106 
107     USHORT          ux_network_device_usb_link_up;
108     USHORT          ux_network_device_link_status;
109 
110     ULONG           ux_network_physical_address_msw;
111     ULONG           ux_network_physical_address_lsw;
112 
113 
114 } USB_NETWORK_DEVICE_TYPE;
115 
116 
117 UINT  _ux_network_driver_init(VOID);
118 
119 UINT  _ux_network_driver_activate(VOID *ux_instance, UINT(*ux_network_device_write_function)(VOID *, NX_PACKET *),
120                                 VOID **ux_network_handle, ULONG physical_address_msw, ULONG physical_address_lsw);
121 
122 UINT  _ux_network_driver_deactivate(VOID *ux_instance, VOID *ux_network_handle);
123 
124 
125 VOID  _ux_network_driver_entry(NX_IP_DRIVER *nx_ip_driver);
126 
127 VOID  _ux_network_driver_link_up(VOID *ux_network_handle);
128 VOID  _ux_network_driver_link_down(VOID *ux_network_handle);
129 
130 VOID  _ux_network_driver_packet_received(VOID *ux_network_handle, NX_PACKET *packet_ptr);
131 /* Determine if a C++ compiler is being used.  If so, complete the standard
132    C conditional started above.  */
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif
138