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 #include "nx_ipv6.h"
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _nxd_ipv6_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 at the specified address list */
45 /* index of the physical host interface specified by the interface index.*/
46 /* Returns an IPv6 address and prefix length into the specified pointers.*/
47 /* */
48 /* INPUT */
49 /* */
50 /* ip_ptr IP control block pointer */
51 /* address_index Index to the IPv6 address */
52 /* table */
53 /* ip_address Pointer to IP address */
54 /* structure to be filled */
55 /* prefix_length Pointer to prefix length */
56 /* to return */
57 /* interface_index The index to the physical */
58 /* interface this address */
59 /* belongs to */
60 /* */
61 /* OUTPUT */
62 /* */
63 /* status Completion status */
64 /* */
65 /* CALLS */
66 /* */
67 /* tx_mutex_get Get protection mutex */
68 /* tx_mutex_put Put protection mutex */
69 /* */
70 /* CALLED BY */
71 /* */
72 /* Application Code */
73 /* */
74 /* NOTE */
75 /* Application needs to fill in the ip_address.nxd_ip_version field. */
76 /* */
77 /* RELEASE HISTORY */
78 /* */
79 /* DATE NAME DESCRIPTION */
80 /* */
81 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
82 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
83 /* resulting in version 6.1 */
84 /* */
85 /**************************************************************************/
_nxd_ipv6_address_get(NX_IP * ip_ptr,UINT address_index,NXD_ADDRESS * ip_address,ULONG * prefix_length,UINT * interface_index)86 UINT _nxd_ipv6_address_get(NX_IP *ip_ptr, UINT address_index, NXD_ADDRESS *ip_address,
87 ULONG *prefix_length, UINT *interface_index)
88 {
89 #ifdef FEATURE_NX_IPV6
90
91 TX_INTERRUPT_SAVE_AREA
92
93 UINT status;
94 NXD_IPV6_ADDRESS *interface_ipv6_address_next;
95 #ifdef TX_ENABLE_EVENT_TRACE
96 ULONG ip_address_lsw;
97 #endif /* TX_ENABLE_EVENT_TRACE */
98
99
100 status = NX_SUCCESS;
101
102 /* Get mutex protection. */
103 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
104 /* Disable interrupts. */
105 TX_DISABLE
106
107 /* Get the ip address. */
108 interface_ipv6_address_next = &ip_ptr -> nx_ipv6_address[address_index];
109
110 /* Check if this is a valid IP address. */
111 if (interface_ipv6_address_next -> nxd_ipv6_address_state != NX_IPV6_ADDR_STATE_VALID)
112 {
113
114 /* No, the address is not validated yet. */
115
116 /* Zero out the return values. */
117 *prefix_length = 0;
118 SET_UNSPECIFIED_ADDRESS(ip_address -> nxd_ip_address.v6);
119
120 /* Return the error status. */
121 status = NX_NO_INTERFACE_ADDRESS;
122 }
123 else
124 {
125
126 /* Record the interface index. */
127 *interface_index = (UINT)ip_ptr -> nx_ipv6_address[address_index].nxd_ipv6_address_attached -> nx_interface_index;
128
129 /* We have a valid address. Mark with the IPv6 stamp. */
130 ip_address -> nxd_ip_version = NX_IP_VERSION_V6;
131
132 /* Copy interface IP address from the address entry in the IP address table into the return address structure. */
133 COPY_IPV6_ADDRESS(interface_ipv6_address_next -> nxd_ipv6_address,
134 ip_address -> nxd_ip_address.v6);
135
136 /* Copy interface IP address prefix length from the address entry in the IP address table into the return prefix length. */
137 *prefix_length = interface_ipv6_address_next -> nxd_ipv6_address_prefix_length;
138 }
139
140 /* Restore interrupts. */
141 TX_RESTORE
142
143 /* Release mutex protection. */
144 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
145
146 #ifdef TX_ENABLE_EVENT_TRACE
147 ip_address_lsw = ip_address -> nxd_ip_address.v6[3];
148
149 /* If trace is enabled, insert this info into the trace buffer. */
150 NX_TRACE_IN_LINE_INSERT(NXD_TRACE_IPV6_INTERFACE_ADDRESS_GET, ip_ptr, ip_address_lsw, *prefix_length, address_index, NX_TRACE_IP_EVENTS, 0, 0);
151 #endif /* TX_ENABLE_EVENT_TRACE */
152
153 /* Return completion status. */
154 return(status);
155
156 #else /* !FEATURE_NX_IPV6 */
157 NX_PARAMETER_NOT_USED(ip_ptr);
158 NX_PARAMETER_NOT_USED(address_index);
159 NX_PARAMETER_NOT_USED(ip_address);
160 NX_PARAMETER_NOT_USED(prefix_length);
161 NX_PARAMETER_NOT_USED(interface_index);
162
163 return(NX_NOT_SUPPORTED);
164
165 #endif /* FEATURE_NX_IPV6 */
166 }
167
168