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_ipv6.h"
30 #ifdef FEATURE_NX_IPV6
31 #include "nx_ip.h"
32 
33 /* Bring in externs for caller checking code.  */
34 
35 NX_CALLER_CHECKING_EXTERNS
36 #endif /* FEATURE_NX_IPV6 */
37 
38 /**************************************************************************/
39 /*                                                                        */
40 /*  FUNCTION                                               RELEASE        */
41 /*                                                                        */
42 /*    _nxde_ipv6_address_set                              PORTABLE C      */
43 /*                                                           6.1          */
44 /*  AUTHOR                                                                */
45 /*                                                                        */
46 /*    Yuxin Zhou, Microsoft Corporation                                   */
47 /*                                                                        */
48 /*  DESCRIPTION                                                           */
49 /*                                                                        */
50 /*    This function checks for errors in the IP address set               */
51 /*    function call.                                                      */
52 /*                                                                        */
53 /*  INPUT                                                                 */
54 /*                                                                        */
55 /*    ip_ptr                                IP control block pointer      */
56 /*    interface_index                       The index to the physical     */
57 /*                                            interface this address      */
58 /*                                            belongs to                  */
59 /*    ip_address                            Pointer to IP address         */
60 /*                                            structure                   */
61 /*    prefix_length                         Prefix length                 */
62 /*    address_index                         Index to the IPv6 address     */
63 /*                                            table                       */
64 /*                                                                        */
65 /*  OUTPUT                                                                */
66 /*                                                                        */
67 /*    status                                Completion status             */
68 /*                                                                        */
69 /*  CALLS                                                                 */
70 /*                                                                        */
71 /*    IPv6_Address_Type                     Find IPv6 address type.       */
72 /*    _nxd_ipv6_address_set                 Actual IP address set function*/
73 /*                                                                        */
74 /*  CALLED BY                                                             */
75 /*                                                                        */
76 /*    Application Code                                                    */
77 /*                                                                        */
78 /*  RELEASE HISTORY                                                       */
79 /*                                                                        */
80 /*    DATE              NAME                      DESCRIPTION             */
81 /*                                                                        */
82 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
83 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
84 /*                                            resulting in version 6.1    */
85 /*                                                                        */
86 /**************************************************************************/
_nxde_ipv6_address_set(NX_IP * ip_ptr,UINT if_index,NXD_ADDRESS * ip_address,ULONG prefix_length,UINT * address_index)87 UINT  _nxde_ipv6_address_set(NX_IP *ip_ptr, UINT if_index, NXD_ADDRESS *ip_address, ULONG prefix_length, UINT *address_index)
88 {
89 #ifdef FEATURE_NX_IPV6
90 
91 UINT  status;
92 ULONG AddressType;
93 
94 
95     /* Check for invalid input pointers.  */
96     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID))
97     {
98         return(NX_PTR_ERROR);
99     }
100 
101     /* Check for invalid IP addresses.  */
102 
103     /* (Do not apply to autoconfigured linklocal addresses) */
104     if ((ip_address != NULL) && (prefix_length != 10))
105     {
106 
107         /* A non null IP address must have the version set. */
108         if (ip_address -> nxd_ip_version != NX_IP_VERSION_V6)
109         {
110             return(NX_IP_ADDRESS_ERROR);
111         }
112     }
113 
114     if ((if_index >= NX_MAX_PHYSICAL_INTERFACES) ||
115         (ip_ptr -> nx_ip_interface[if_index].nx_interface_valid != NX_TRUE))
116     {
117         return(NX_INVALID_INTERFACE);
118     }
119 
120 
121     /* Make sure the address is unicast address. */
122     /* Find out the type of the incoming IP address. */
123     if (ip_address)
124     {
125         AddressType = IPv6_Address_Type(ip_address -> nxd_ip_address.v6);
126 
127         if ((AddressType & IPV6_ADDRESS_UNICAST) == 0)
128         {
129             return(NX_IP_ADDRESS_ERROR);
130         }
131     }
132 
133     /* Check for appropriate caller.  */
134     NX_INIT_AND_THREADS_CALLER_CHECKING
135 
136     /* Call actual IP address set function.  */
137     status =  _nxd_ipv6_address_set(ip_ptr, if_index, ip_address, prefix_length, address_index);
138 
139     /* Return completion status.  */
140     return(status);
141 
142 #else /* !FEATURE_NX_IPV6 */
143     NX_PARAMETER_NOT_USED(ip_ptr);
144     NX_PARAMETER_NOT_USED(if_index);
145     NX_PARAMETER_NOT_USED(ip_address);
146     NX_PARAMETER_NOT_USED(prefix_length);
147     NX_PARAMETER_NOT_USED(address_index);
148 
149     return(NX_NOT_SUPPORTED);
150 
151 #endif /* FEATURE_NX_IPV6 */
152 }
153 
154