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 /* FUNCTION RELEASE */
38 /* */
39 /* _nxe_ip_interface_attach 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 attach */
48 /* function call. */
49 /* */
50 /* */
51 /* INPUT */
52 /* */
53 /* ip_ptr_value Pointer to IP control block */
54 /* interface_name Name of this interface */
55 /* ip_address IP Address, in host byte order*/
56 /* network_mask Network Mask, in host byte */
57 /* order */
58 /* ip_link_driver User supplied link driver */
59 /* */
60 /* OUTPUT */
61 /* */
62 /* status Completion status */
63 /* */
64 /* CALLS */
65 /* */
66 /* _nx_ip_interface_attach Attaches the interface */
67 /* */
68 /* CALLED BY */
69 /* */
70 /* Application Code */
71 /* */
72 /* RELEASE HISTORY */
73 /* */
74 /* DATE NAME DESCRIPTION */
75 /* */
76 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
77 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
78 /* resulting in version 6.1 */
79 /* */
80 /**************************************************************************/
_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 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 *))
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) || (ip_link_driver == NX_NULL) || (interface_name == NX_NULL))
89 {
90 return(NX_PTR_ERROR);
91 }
92
93 /* Check for invalid IP address. Note that Interface with DHCP enabled
94 would start with 0.0.0.0. Therefore the 0 IP address is allowed. */
95 if ((ip_address != 0) &&
96 ((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 appropriate caller. */
104 NX_INIT_AND_THREADS_CALLER_CHECKING
105
106 /* Call actual IP interface attach function. */
107 status = _nx_ip_interface_attach(ip_ptr, interface_name, ip_address, network_mask, ip_link_driver);
108
109 /* Return completion status. */
110 return(status);
111 }
112
113