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_address_get                        PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function retrieves the IP address and the network mask and     */
45 /*    returns them to the caller.                                         */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                IP control block pointer      */
50 /*    interface_index                       IP Interface Index            */
51 /*    ip_address                            Pointer to interface IP       */
52 /*                                            address                     */
53 /*    network_mask                          Pointer to interface network  */
54 /*                                            mask                        */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    status                                Completion status             */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    tx_mutex_get                          Get protection mutex          */
63 /*    tx_mutex_put                          Put protection mutex          */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application Code                                                    */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
74 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_nx_ip_interface_address_get(NX_IP * ip_ptr,UINT interface_index,ULONG * ip_address,ULONG * network_mask)78 UINT  _nx_ip_interface_address_get(NX_IP *ip_ptr, UINT interface_index, ULONG *ip_address, ULONG *network_mask)
79 {
80 
81 #ifndef NX_DISABLE_IPV4
82 TX_INTERRUPT_SAVE_AREA
83 
84     /* If trace is enabled, insert this event into the trace buffer.  */
85     NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_ADDRESS_GET, ip_ptr, ip_ptr -> nx_ip_interface[interface_index].nx_interface_ip_address,
86                             ip_ptr -> nx_ip_interface[interface_index].nx_interface_ip_network_mask, 0, NX_TRACE_IP_EVENTS, 0, 0);
87 
88 
89 
90     /* Get mutex protection.  */
91     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
92 
93     /* Disable interrupts.  */
94     TX_DISABLE
95 
96 
97     /* Pickup the IP address and the network mask. */
98     *ip_address =    ip_ptr -> nx_ip_interface[interface_index].nx_interface_ip_address;
99     *network_mask =  ip_ptr -> nx_ip_interface[interface_index].nx_interface_ip_network_mask;
100 
101     /* Restore interrupts.  */
102     TX_RESTORE
103 
104     /* Release mutex protection.  */
105     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
106 
107     /* Return completion status.  */
108     return(NX_SUCCESS);
109 #else /* NX_DISABLE_IPV4  */
110     NX_PARAMETER_NOT_USED(ip_ptr);
111     NX_PARAMETER_NOT_USED(interface_index);
112     NX_PARAMETER_NOT_USED(ip_address);
113     NX_PARAMETER_NOT_USED(network_mask);
114 
115     return(NX_NOT_SUPPORTED);
116 #endif /* !NX_DISABLE_IPV4  */
117 }
118 
119