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_interface_info_get                           PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function retrieves information related to a specified          */
45 /*    interface.                                                          */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                IP control block pointer      */
50 /*    interface_index                       Index to the interface        */
51 /*    interface_name                        Name of the interface         */
52 /*    ip_address                            Pointer to interface IP       */
53 /*                                            address in host byte order  */
54 /*    network_mask                          Pointer to network mask       */
55 /*                                            destination, in host        */
56 /*                                            byte order                  */
57 /*    mtu_size                              Pointer to storage space      */
58 /*                                            for MTU                     */
59 /*    physical_address_msw                  Pointer to storage space for  */
60 /*                                            device phsyical address, MSW*/
61 /*    physical_address_lsw                  Pointer to storage space for  */
62 /*                                            device phsyical address, LSW*/
63 /*                                                                        */
64 /*  OUTPUT                                                                */
65 /*                                                                        */
66 /*    status                                Completion status             */
67 /*                                                                        */
68 /*  CALLS                                                                 */
69 /*                                                                        */
70 /*    None                                                                */
71 /*                                                                        */
72 /*  CALLED BY                                                             */
73 /*                                                                        */
74 /*    Application Code                                                    */
75 /*                                                                        */
76 /*  RELEASE HISTORY                                                       */
77 /*                                                                        */
78 /*    DATE              NAME                      DESCRIPTION             */
79 /*                                                                        */
80 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
81 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
82 /*                                            resulting in version 6.1    */
83 /*                                                                        */
84 /**************************************************************************/
_nx_ip_interface_info_get(NX_IP * ip_ptr,UINT interface_index,CHAR ** interface_name,ULONG * ip_address,ULONG * network_mask,ULONG * mtu_size,ULONG * physical_address_msw,ULONG * physical_address_lsw)85 UINT _nx_ip_interface_info_get(NX_IP *ip_ptr, UINT interface_index, CHAR **interface_name,
86                                ULONG *ip_address, ULONG *network_mask, ULONG *mtu_size,
87                                ULONG *physical_address_msw, ULONG *physical_address_lsw)
88 {
89 NX_INTERFACE *nx_interface;
90 
91 #ifdef NX_DISABLE_IPV4
92     NX_PARAMETER_NOT_USED(ip_address);
93     NX_PARAMETER_NOT_USED(network_mask);
94 #endif /* NX_DISABLE_IPV4 */
95 
96     nx_interface = &(ip_ptr -> nx_ip_interface[interface_index]);
97 
98     if (!nx_interface -> nx_interface_valid)
99     {
100         return(NX_INVALID_INTERFACE);
101     }
102 
103     if (interface_name)
104     {
105         *interface_name = nx_interface -> nx_interface_name;
106     }
107 
108 #ifndef NX_DISABLE_IPV4
109     if (ip_address)
110     {
111         *ip_address = nx_interface -> nx_interface_ip_address;
112     }
113 
114     if (network_mask)
115     {
116         *network_mask = nx_interface -> nx_interface_ip_network_mask;
117     }
118 #endif /* !NX_DISABLE_IPV4  */
119 
120     if (mtu_size)
121     {
122         *mtu_size = nx_interface -> nx_interface_ip_mtu_size;
123     }
124 
125     if (physical_address_msw)
126     {
127         *physical_address_msw = nx_interface -> nx_interface_physical_address_msw;
128     }
129 
130     if (physical_address_lsw)
131     {
132         *physical_address_lsw = nx_interface -> nx_interface_physical_address_lsw;
133     }
134 
135 #ifndef NX_DISABLE_IPV4
136     /* If trace is enabled, insert this event into the trace buffer.  */
137     NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_INTERFACE_INFO_GET, ip_ptr, nx_interface -> nx_interface_ip_address,
138                             nx_interface -> nx_interface_physical_address_msw, nx_interface -> nx_interface_physical_address_lsw,
139                             NX_TRACE_IP_EVENTS, 0, 0);
140 #else
141     /* If trace is enabled, insert this event into the trace buffer.  */
142     NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_INTERFACE_INFO_GET, ip_ptr, 0,
143                             nx_interface -> nx_interface_physical_address_msw, nx_interface -> nx_interface_physical_address_lsw,
144                             NX_TRACE_IP_EVENTS, 0, 0);
145 #endif /* NX_DISABLE_IPV4 */
146 
147 
148     return(NX_SUCCESS);
149 }
150 
151