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_ip.h"
30 
31 /* Bring in externs for caller checking code.  */
32 
33 NX_CALLER_CHECKING_EXTERNS
34 
35 
36 /**************************************************************************/
37 /*                                                                        */
38 /*  FUNCTION                                               RELEASE        */
39 /*                                                                        */
40 /*    _nxe_ip_interface_address_set                       PORTABLE C      */
41 /*                                                           6.1          */
42 /*  AUTHOR                                                                */
43 /*                                                                        */
44 /*    Yuxin Zhou, Microsoft Corporation                                   */
45 /*                                                                        */
46 /*  DESCRIPTION                                                           */
47 /*                                                                        */
48 /*    This function checks for errors in the IP address set               */
49 /*    function call.                                                      */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    ip_ptr                                IP control block pointer      */
54 /*    interface_index                       IP Interface Index            */
55 /*    ip_address                            IP address, in host byte      */
56 /*                                            order                       */
57 /*    network_mask                          Network mask, in host byte    */
58 /*                                            order                       */
59 /*                                                                        */
60 /*  OUTPUT                                                                */
61 /*                                                                        */
62 /*    status                                Completion status             */
63 /*                                                                        */
64 /*  CALLS                                                                 */
65 /*                                                                        */
66 /*    _nx_ip_interface_address_set          Actual IP address set         */
67 /*                                            function                    */
68 /*                                                                        */
69 /*  CALLED BY                                                             */
70 /*                                                                        */
71 /*    Application Code                                                    */
72 /*                                                                        */
73 /*  RELEASE HISTORY                                                       */
74 /*                                                                        */
75 /*    DATE              NAME                      DESCRIPTION             */
76 /*                                                                        */
77 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
78 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
79 /*                                            resulting in version 6.1    */
80 /*                                                                        */
81 /**************************************************************************/
_nxe_ip_interface_address_set(NX_IP * ip_ptr,UINT interface_index,ULONG ip_address,ULONG network_mask)82 UINT  _nxe_ip_interface_address_set(NX_IP *ip_ptr, UINT interface_index,  ULONG ip_address, ULONG network_mask)
83 {
84 
85 #ifndef NX_DISABLE_IPV4
86 UINT status;
87 
88 
89     /* Check for invalid input pointers.  */
90     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID))
91     {
92         return(NX_PTR_ERROR);
93     }
94 
95     /* Check for invalid IP address.  */
96     if (((ip_address & NX_IP_CLASS_A_MASK) != NX_IP_CLASS_A_TYPE) &&
97         ((ip_address & NX_IP_CLASS_B_MASK) != NX_IP_CLASS_B_TYPE) &&
98         ((ip_address & NX_IP_CLASS_C_MASK) != NX_IP_CLASS_C_TYPE))
99     {
100         return(NX_IP_ADDRESS_ERROR);
101     }
102 
103     /* Check for invalid interface ID */
104     if (interface_index >= NX_MAX_PHYSICAL_INTERFACES)
105     {
106         return(NX_INVALID_INTERFACE);
107     }
108 
109     /* Check for interface being valid. */
110     if (!ip_ptr -> nx_ip_interface[interface_index].nx_interface_valid)
111     {
112         return(NX_INVALID_INTERFACE);
113     }
114 
115     /* Check for appropriate caller.  */
116     NX_INIT_AND_THREADS_CALLER_CHECKING
117 
118     /* Call actual IP address set function.  */
119     status =  _nx_ip_interface_address_set(ip_ptr, interface_index, ip_address, network_mask);
120 
121     /* Return completion status.  */
122     return(status);
123 #else /* NX_DISABLE_IPV4  */
124     NX_PARAMETER_NOT_USED(ip_ptr);
125     NX_PARAMETER_NOT_USED(interface_index);
126     NX_PARAMETER_NOT_USED(ip_address);
127     NX_PARAMETER_NOT_USED(network_mask);
128 
129     return(NX_NOT_SUPPORTED);
130 #endif /* !NX_DISABLE_IPV4  */
131 }
132 
133