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 /**   User Datagram Protocol (UDP)                                        */
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 #include "nx_udp.h"
31 
32 
33 /* Bring in externs for caller checking code.  */
34 
35 NX_CALLER_CHECKING_EXTERNS
36 
37 
38 /**************************************************************************/
39 /*                                                                        */
40 /*  FUNCTION                                               RELEASE        */
41 /*                                                                        */
42 /*    _nxe_udp_free_port_find                             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 UDP free port find           */
51 /*    function call.                                                      */
52 /*                                                                        */
53 /*  INPUT                                                                 */
54 /*                                                                        */
55 /*    ip_ptr                                IP instance pointer           */
56 /*    port                                  Starting port                 */
57 /*    free_port_ptr                         Pointer to return free port   */
58 /*                                                                        */
59 /*  OUTPUT                                                                */
60 /*                                                                        */
61 /*    status                                Completion status             */
62 /*                                                                        */
63 /*  CALLS                                                                 */
64 /*                                                                        */
65 /*    _nx_udp_free_port_find                Actual UDP free port find     */
66 /*                                            function                    */
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_udp_free_port_find(NX_IP * ip_ptr,UINT port,UINT * free_port_ptr)81 UINT  _nxe_udp_free_port_find(NX_IP *ip_ptr, UINT port, UINT *free_port_ptr)
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) || (free_port_ptr == NX_NULL))
89     {
90         return(NX_PTR_ERROR);
91     }
92 
93     /* Check to see if UDP is enabled.  */
94     if (!ip_ptr -> nx_ip_udp_packet_receive)
95     {
96         return(NX_NOT_ENABLED);
97     }
98 
99     /* Check for an invalid port.  */
100     if ((!port) || (((ULONG)port) > (ULONG)NX_MAX_PORT))
101     {
102         return(NX_INVALID_PORT);
103     }
104 
105     /* Check for appropriate caller.  */
106     NX_THREADS_ONLY_CALLER_CHECKING
107 
108     /* Call actual UDP free port find function.  */
109     status =  _nx_udp_free_port_find(ip_ptr, port, free_port_ptr);
110 
111     /* Return completion status.  */
112     return(status);
113 }
114 
115