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 /* Include necessary system files. */
25 #include "nx_api.h"
26 #include "nx_tcp.h"
27 #include "nx_arp.h"
28 #include "nx_icmpv6.h"
29 #include "nx_link.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_ip_diferred_link_status_process                 PORTABLE C      */
37 /*                                                           6.4.0        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function processes link status change event.                   */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    ip_ptr                                Pointer to IP control block   */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    None                                                                */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    tx_mutex_get                          Obtain protection mutex       */
57 /*    tx_mutex_put                          Release protection mutex      */
58 /*    _nx_tcp_socket_connection_reset       Reset TCP connection          */
59 /*    _nx_arp_interface_entries_delete      Remove specified ARP entries  */
60 /*    _nx_nd_cache_interface_entries_delete Delete ND cache entries assoc-*/
61 /*                                          iated with specified interface*/
62 /*    link_driver_entry                     Link driver                   */
63 /*    memset                                Zero out the interface        */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    nx_ip_thread_entry                                                  */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
74 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*  12-31-2023     Yajun Xia                Modified comment(s),          */
77 /*                                            supported VLAN and generic  */
78 /*                                            link layer,                 */
79 /*                                            resulting in version 6.4.0  */
80 /*                                                                        */
81 /**************************************************************************/
_nx_ip_deferred_link_status_process(NX_IP * ip_ptr)82 VOID _nx_ip_deferred_link_status_process(NX_IP *ip_ptr)
83 {
84 
85 UINT         i;
86 NX_IP_DRIVER driver_request;
87 ULONG        link_up;
88 
89     if (ip_ptr -> nx_ip_link_status_change_callback == NX_NULL)
90     {
91 
92         /* Callback function is not set. */
93         return;
94     }
95 
96     for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++)
97     {
98         if ((ip_ptr -> nx_ip_interface[i].nx_interface_valid) &&
99             (ip_ptr -> nx_ip_interface[i].nx_interface_link_status_change))
100         {
101 
102             /* Reset the flag. */
103             ip_ptr -> nx_ip_interface[i].nx_interface_link_status_change = NX_FALSE;
104 
105             driver_request.nx_ip_driver_ptr       = ip_ptr;
106             driver_request.nx_ip_driver_command   = NX_LINK_GET_STATUS;
107             driver_request.nx_ip_driver_interface = &(ip_ptr -> nx_ip_interface[i]);
108             driver_request.nx_ip_driver_return_ptr = &link_up;
109 
110             (ip_ptr -> nx_ip_interface[i].nx_interface_link_driver_entry)(&driver_request);
111 
112             /* Invoke the callback function. */
113             /*lint -e{644} suppress variable might not be initialized, since "link_up" was initialized in nx_interface_link_driver_entry. */
114             ip_ptr -> nx_ip_link_status_change_callback(ip_ptr, i, link_up);
115 
116 #ifdef NX_ENABLE_VLAN
117             /* Link status change need to propagate to vlan sub interface */
118             nx_link_vlan_interface_status_change(ip_ptr, i);
119 #endif /* NX_ENABLE_VLAN */
120         }
121     }
122 }
123 
124