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_ipv6.h"
29 #include "nx_icmpv6.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _nxd_ipv6_stateless_address_autoconfig_enable PORTABLE C */
37 /* 6.2.1 */
38 /* AUTHOR */
39 /* */
40 /* Yuxin Zhou, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function enables the IPv6 stateless address auto configuration */
45 /* feature, */
46 /* */
47 /* INPUT */
48 /* */
49 /* ip_ptr IP instance pointer */
50 /* interface_index The interface to operate on */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* status Completion status */
55 /* */
56 /* CALLS */
57 /* */
58 /* tx_mutex_get Obtain a protection mutex */
59 /* tx_mutex_put Release protection mutex */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* Application Code */
64 /* */
65 /* RELEASE HISTORY */
66 /* */
67 /* DATE NAME DESCRIPTION */
68 /* */
69 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
70 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
71 /* resulting in version 6.1 */
72 /* 03-08-2023 Tiejun Zhou Modified comment(s), and */
73 /* fixed compiler warnings, */
74 /* resulting in version 6.2.1 */
75 /* */
76 /**************************************************************************/
_nxd_ipv6_stateless_address_autoconfig_enable(NX_IP * ip_ptr,UINT interface_index)77 UINT _nxd_ipv6_stateless_address_autoconfig_enable(NX_IP *ip_ptr, UINT interface_index)
78 {
79
80
81 #if defined(FEATURE_NX_IPV6) && defined(NX_IPV6_STATELESS_AUTOCONFIG_CONTROL)
82 NX_INTERFACE *interface_ptr;
83
84
85 /* Set interface_ptr. */
86 interface_ptr = &ip_ptr -> nx_ip_interface[interface_index];
87
88 /* Make sure IPv6 is not already enabled. */
89 if (interface_ptr -> nx_ipv6_stateless_address_autoconfig_status == NX_STATELESS_ADDRESS_AUTOCONFIG_ENABLED)
90 {
91 return(NX_ALREADY_ENABLED);
92 }
93
94 /* If trace is enabled, insert this event into the trace buffer. */
95 NX_TRACE_IN_LINE_INSERT(NXD_TRACE_IPV6_STATELESS_ADDRESS_AUTOCONFIG_ENABLE, ip_ptr, interface_ptr, 0, 0, NX_TRACE_IP_EVENTS, 0, 0);
96
97 /* Obtain the IP mutex so we can manipulate the internal routing table. */
98 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
99
100 /* Install IPv6 packet receive processing function pointer */
101 interface_ptr -> nx_ipv6_stateless_address_autoconfig_status = NX_STATELESS_ADDRESS_AUTOCONFIG_ENABLED;
102
103 #ifndef NX_DISABLE_ICMPV6_ROUTER_SOLICITATION
104 /* Reset the RS count. */
105 interface_ptr -> nx_ipv6_rtr_solicitation_count = ip_ptr -> nx_ip_interface[interface_index].nx_ipv6_rtr_solicitation_max;
106
107 interface_ptr -> nx_ipv6_rtr_solicitation_timer = NX_ICMPV6_RTR_SOLICITATION_DELAY;
108 #endif /* NX_DISABLE_ICMPV6_ROUTER_SOLICITATION */
109
110 /* Release the IP protection. */
111 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
112
113 /* Return successful completion. */
114 return(NX_SUCCESS);
115 #else
116 NX_PARAMETER_NOT_USED(ip_ptr);
117 NX_PARAMETER_NOT_USED(interface_index);
118
119 return(NX_NOT_SUPPORTED);
120 #endif /* FEATURE_NX_IPV6 && NX_IPV6_STATELESS_AUTOCONFIG_CONTROL */
121 }
122
123