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 /** NetX Component                                                        */
15 /**                                                                       */
16 /**   Internet Protocol version 6 Default Router Table (IPv6 router)      */
17 /**                                                                       */
18 /**************************************************************************/
19 /**************************************************************************/
20 #define NX_SOURCE_CODE
21 
22 
23 /* Include necessary system files.  */
24 
25 #include "nx_api.h"
26 #include "nx_ipv6.h"
27 #include "nx_nd_cache.h"
28 #include "nx_icmpv6.h"
29 
30 
31 #ifdef FEATURE_NX_IPV6
32 
33 #ifndef NX_DISABLE_ICMPV6_ROUTER_SOLICITATION
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _nxd_ipv6_router_solicitation_check                 PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Yuxin Zhou, Microsoft Corporation                                   */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    At every time tick, this function decrement the router solicitation */
47 /*    counter.   When the counter reaches zero, the stack sends out       */
48 /*    router solicitation.                                                */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    ip_ptr                                IP instance pointer           */
53 /*    router_address                        The specific gateway address  */
54 /*                                            to search for.              */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    None                                                                */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _nx_icmpv6_send_rs                   Send router solicitation packet*/
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    nx_ip_thread_entry                    Handle IP thread task events  */
67 /*                                                                        */
68 /*  NOTE                                                                  */
69 /*                                                                        */
70 /*    Caller must obtain nx_ip_protection mutex before calling this       */
71 /*    function.                                                           */
72 /*                                                                        */
73 /*    This function cannot be called from ISR.                            */
74 /*                                                                        */
75 /*  RELEASE HISTORY                                                       */
76 /*                                                                        */
77 /*    DATE              NAME                      DESCRIPTION             */
78 /*                                                                        */
79 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
80 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
81 /*                                            resulting in version 6.1    */
82 /*                                                                        */
83 /**************************************************************************/
_nxd_ipv6_router_solicitation_check(NX_IP * ip_ptr)84 void _nxd_ipv6_router_solicitation_check(NX_IP *ip_ptr)
85 {
86 UINT i;
87 
88     for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++)
89     {
90         if (ip_ptr -> nx_ip_interface[i].nx_interface_valid == NX_TRUE)
91         {
92 
93             /* Check if max number of router solicitation messages have been sent. */
94             if (ip_ptr -> nx_ip_interface[i].nx_ipv6_rtr_solicitation_count != 0)
95             {
96 
97                 /* Check on count down timer for sending out next router solicitation message. */
98                 ip_ptr -> nx_ip_interface[i].nx_ipv6_rtr_solicitation_timer--;
99                 if (ip_ptr -> nx_ip_interface[i].nx_ipv6_rtr_solicitation_timer == 0)
100                 {
101                     if (_nx_icmpv6_send_rs(ip_ptr, i) &&
102                         (ip_ptr -> nx_ip_interface[i].nx_ipv6_rtr_solicitation_count ==
103                          ip_ptr -> nx_ip_interface[i].nx_ipv6_rtr_solicitation_max))
104                     {
105 
106                         /* Initial RS is not sent successfully. */
107                         /* Try it next round. */
108                         ip_ptr -> nx_ip_interface[i].nx_ipv6_rtr_solicitation_timer = 1;
109                     }
110                     else
111                     {
112                         ip_ptr -> nx_ip_interface[i].nx_ipv6_rtr_solicitation_count--;
113                         ip_ptr -> nx_ip_interface[i].nx_ipv6_rtr_solicitation_timer = ip_ptr -> nx_ip_interface[i].nx_ipv6_rtr_solicitation_interval;
114                     }
115                 }
116             }
117         }
118     }
119 }
120 #endif /* NX_DISABLE_ICMPV6_ROUTER_SOLICITATION */
121 #endif /* FEATURE_NX_IPV6 */
122 
123