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 /** NetX Component                                                        */
17 /**                                                                       */
18 /**   Internet Protocol (IP)                                              */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define NX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "nx_api.h"
29 #include "nx_ip.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_ip_driver_interface_direct_command              PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function provides the application with direct access to        */
45 /*    the specific IP's link-level driver.                                */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                Pointer to IP instance        */
50 /*    command                               Driver command (NX_LINK_*)    */
51 /*    interface_index                       Index to the interface        */
52 /*    return_value_ptr                      Pointer to place return values*/
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    status                                Completion status             */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    tx_mutex_get                          Get protection mutex          */
61 /*    tx_mutex_put                          Put protection mutex          */
62 /*    (ip_link_driver)                      User supplied link driver     */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Application                                                         */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
73 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_nx_ip_driver_interface_direct_command(NX_IP * ip_ptr,UINT command,UINT interface_index,ULONG * return_value_ptr)77 UINT  _nx_ip_driver_interface_direct_command(NX_IP *ip_ptr, UINT command, UINT interface_index, ULONG *return_value_ptr)
78 {
79 
80 NX_IP_DRIVER           driver_request;
81 
82 #ifdef TX_ENABLE_EVENT_TRACE
83 TX_TRACE_BUFFER_ENTRY *trace_event;
84 ULONG                  trace_timestamp;
85 #endif
86 
87 
88     /* If trace is enabled, insert this event into the trace buffer.  */
89     NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_DRIVER_DIRECT_COMMAND, ip_ptr, command, 0, 0, NX_TRACE_IP_EVENTS, &trace_event, &trace_timestamp);
90 
91     /* Get mutex protection.  */
92     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
93 
94     /* Build the driver request structure.  */
95     driver_request.nx_ip_driver_ptr =         ip_ptr;
96     driver_request.nx_ip_driver_command =     command;
97     driver_request.nx_ip_driver_return_ptr =  return_value_ptr;
98     driver_request.nx_ip_driver_interface  =  &(ip_ptr -> nx_ip_interface[interface_index]);
99     (ip_ptr -> nx_ip_interface[interface_index].nx_interface_link_driver_entry)(&driver_request);
100 
101     /* Release mutex protection.  */
102     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
103 
104     /* Update the trace event with the status.  */
105     NX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, NX_TRACE_IP_DRIVER_DIRECT_COMMAND, 0, 0, driver_request.nx_ip_driver_status, 0);
106 
107     /* Return status to the caller.  */
108     /*lint -e{644} suppress variable might not be initialized, since "nx_ip_driver_status" was initialized in nx_interface_link_driver_entry. */
109     return(driver_request.nx_ip_driver_status);
110 }
111 
112