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_ip.h"
29 
30 /* Bring in externs for caller checking code.  */
31 
32 NX_CALLER_CHECKING_EXTERNS
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _nxe_ip_interface_status_check                      PORTABLE C      */
40 /*                                                           6.1          */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Yuxin Zhou, Microsoft Corporation                                   */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function checks for errors in the IP interface status check    */
48 /*    function call.                                                      */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    ip_ptr                                Pointer to IP instance        */
53 /*    interface_index                       Index to the interface        */
54 /*    needed_status                         Status needed request         */
55 /*    actual_status                         Pointer to return status area */
56 /*    wait_option                           Maximum suspension time       */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    status                                Completion status             */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    _nx_ip_interface_status_check         Actual IP interface status    */
65 /*                                             check function             */
66 /*                                                                        */
67 /*  CALLED BY                                                             */
68 /*                                                                        */
69 /*    Application                                                         */
70 /*                                                                        */
71 /*  RELEASE HISTORY                                                       */
72 /*                                                                        */
73 /*    DATE              NAME                      DESCRIPTION             */
74 /*                                                                        */
75 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
76 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
77 /*                                            resulting in version 6.1    */
78 /*                                                                        */
79 /**************************************************************************/
_nxe_ip_interface_status_check(NX_IP * ip_ptr,UINT interface_index,ULONG needed_status,ULONG * actual_status,ULONG wait_option)80 UINT  _nxe_ip_interface_status_check(NX_IP *ip_ptr, UINT interface_index, ULONG needed_status,
81                                      ULONG *actual_status, ULONG wait_option)
82 {
83 
84 UINT status;
85 
86 
87     /* Check for invalid input pointers.  */
88     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) || (actual_status == NX_NULL))
89     {
90         return(NX_PTR_ERROR);
91     }
92 
93     /* Check for invalid interface index. */
94     if ((interface_index >= NX_MAX_PHYSICAL_INTERFACES) ||
95         (ip_ptr -> nx_ip_interface[interface_index].nx_interface_valid) == 0)
96     {
97         return(NX_INVALID_INTERFACE);
98     }
99 
100     /* Check for valid options.  */
101     if (needed_status &
102         ~((NX_IP_INITIALIZE_DONE | NX_IP_LINK_ENABLED | NX_IP_UDP_ENABLED | NX_IP_TCP_ENABLED | NX_IP_INTERFACE_LINK_ENABLED)
103 #ifndef NX_DISABLE_IPV4
104           | (NX_IP_ADDRESS_RESOLVED | NX_IP_ARP_ENABLED | NX_IP_RARP_COMPLETE | NX_IP_IGMP_ENABLED)
105 #endif /* !NX_DISABLE_IPV4  */
106          ))
107     {
108         return(NX_OPTION_ERROR);
109     }
110 
111     /* Check for appropriate caller.  */
112     NX_THREADS_ONLY_CALLER_CHECKING
113 
114     /* Call actual IP interface status check function.  */
115     status =  _nx_ip_interface_status_check(ip_ptr, interface_index, needed_status, actual_status, wait_option);
116 
117     /* Return completion status.  */
118     return(status);
119 }
120 
121