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