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