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 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_ip_address_change_notify                        PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function registers an application callback routine that NetX   */
45 /*    calls whenever the IP address is changed.                           */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                IP control block pointer      */
50 /*    ip_address_change_notify              Application callback function */
51 /*    additional_info                       Optional additional           */
52 /*                                            information for the         */
53 /*                                            callback function           */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    status                                Completion status             */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    tx_mutex_get                          Get protection mutex          */
62 /*    tx_mutex_put                          Put protection mutex          */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Application Code                                                    */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
73 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_nx_ip_address_change_notify(NX_IP * ip_ptr,VOID (* ip_address_change_notify)(NX_IP *,VOID *),VOID * additional_info)77 UINT  _nx_ip_address_change_notify(NX_IP *ip_ptr, VOID (*ip_address_change_notify)(NX_IP *, VOID *), VOID *additional_info)
78 {
79 
80 #ifndef NX_DISABLE_IPV4
81 TX_INTERRUPT_SAVE_AREA
82 
83 
84     /* If trace is enabled, insert this event into the trace buffer.  */
85     NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_ADDRESS_CHANGE_NOTIFY, ip_ptr, ip_address_change_notify, additional_info, 0, NX_TRACE_IP_EVENTS, 0, 0);
86 
87     /* Get mutex protection.  */
88     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
89 
90     /* Disable interrupts.  */
91     TX_DISABLE
92 
93     /* Setup the IP address change callback function and the additional information pointers. */
94     ip_ptr -> nx_ip_address_change_notify =                  ip_address_change_notify;
95     ip_ptr -> nx_ip_address_change_notify_additional_info =  additional_info;
96 
97     /* Restore interrupts.  */
98     TX_RESTORE
99 
100     /* Release mutex protection.  */
101     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
102 
103     /* Return completion status.  */
104     return(NX_SUCCESS);
105 #else /* NX_DISABLE_IPV4  */
106     NX_PARAMETER_NOT_USED(ip_ptr);
107     NX_PARAMETER_NOT_USED(ip_address_change_notify);
108     NX_PARAMETER_NOT_USED(additional_info);
109 
110     return(NX_NOT_SUPPORTED);
111 #endif /* !NX_DISABLE_IPV4  */
112 }
113 
114