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