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 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _nxe_ip_interface_attach                            PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Yuxin Zhou, Microsoft Corporation                                   */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function checks for errors in the IP interface attach          */
47 /*    function call.                                                      */
48 /*                                                                        */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    ip_ptr_value                          Pointer to IP control block   */
53 /*    interface_name                        Name of this interface        */
54 /*    ip_address                            IP Address, in host byte order*/
55 /*    network_mask                          Network Mask, in host byte    */
56 /*                                             order                      */
57 /*    ip_link_driver                        User supplied link driver     */
58 /*                                                                        */
59 /*  OUTPUT                                                                */
60 /*                                                                        */
61 /*    status                                Completion status             */
62 /*                                                                        */
63 /*  CALLS                                                                 */
64 /*                                                                        */
65 /*    _nx_ip_interface_attach               Attaches the interface        */
66 /*                                                                        */
67 /*  CALLED BY                                                             */
68 /*                                                                        */
69 /*    Application Code                                                    */
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_attach(NX_IP * ip_ptr,CHAR * interface_name,ULONG ip_address,ULONG network_mask,VOID (* ip_link_driver)(struct NX_IP_DRIVER_STRUCT *))80 UINT _nxe_ip_interface_attach(NX_IP *ip_ptr, CHAR *interface_name, ULONG ip_address, ULONG network_mask, VOID (*ip_link_driver)(struct NX_IP_DRIVER_STRUCT *))
81 {
82 
83 UINT status;
84 
85 
86     /* Check for invalid input pointers.  */
87     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) || (ip_link_driver == NX_NULL) || (interface_name == NX_NULL))
88     {
89         return(NX_PTR_ERROR);
90     }
91 
92     /* Check for invalid IP address.  Note that Interface with DHCP enabled
93        would start with 0.0.0.0.  Therefore the 0 IP address is allowed. */
94     if ((ip_address != 0) &&
95         ((ip_address & NX_IP_CLASS_A_MASK) != NX_IP_CLASS_A_TYPE) &&
96         ((ip_address & NX_IP_CLASS_B_MASK) != NX_IP_CLASS_B_TYPE) &&
97         ((ip_address & NX_IP_CLASS_C_MASK) != NX_IP_CLASS_C_TYPE))
98     {
99         return(NX_IP_ADDRESS_ERROR);
100     }
101 
102     /* Check for appropriate caller.  */
103     NX_INIT_AND_THREADS_CALLER_CHECKING
104 
105     /* Call actual IP interface attach function.  */
106     status =  _nx_ip_interface_attach(ip_ptr, interface_name, ip_address, network_mask, ip_link_driver);
107 
108     /* Return completion status.  */
109     return(status);
110 }
111 
112