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_interface_physical_address_set               PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function sets the physical address to driver.                  */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    ip_ptr                                IP control block pointer      */
49 /*    interface_index                       Index of interface            */
50 /*    physical_msw                          Physical address MSW          */
51 /*    physical_lsw                          Physical address LSW          */
52 /*    update_driver                         Update driver or not          */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    status                                Completion status             */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    tx_mutex_get                          Get protection mutex          */
61 /*    tx_mutex_put                          Put protection mutex          */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
72 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_nx_ip_interface_physical_address_set(NX_IP * ip_ptr,UINT interface_index,ULONG physical_msw,ULONG physical_lsw,UINT update_driver)76 UINT  _nx_ip_interface_physical_address_set(NX_IP *ip_ptr, UINT interface_index,
77                                             ULONG physical_msw, ULONG physical_lsw, UINT update_driver)
78 {
79 NX_INTERFACE *if_ptr = &(ip_ptr -> nx_ip_interface[interface_index]);
80 NX_IP_DRIVER  driver_request;
81 
82     /* Initialize the status. */
83     driver_request.nx_ip_driver_status = NX_SUCCESS;
84 
85     /* Obtain the IP internal mutex before calling the driver.  */
86     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
87 
88     if (update_driver == NX_TRUE)
89     {
90 
91         /* Set driver request. */
92         driver_request.nx_ip_driver_physical_address_msw = physical_msw;
93         driver_request.nx_ip_driver_physical_address_lsw = physical_lsw;
94         driver_request.nx_ip_driver_ptr         = ip_ptr;
95         driver_request.nx_ip_driver_command     = NX_LINK_SET_PHYSICAL_ADDRESS;
96         driver_request.nx_ip_driver_interface   = if_ptr;
97 
98         /* Call the link driver to set physical address. */
99         (if_ptr -> nx_interface_link_driver_entry)(&driver_request);
100     }
101 
102     /* Check status. */
103     if (driver_request.nx_ip_driver_status == NX_SUCCESS)
104     {
105 
106         /* Set physical address to interface. */
107         if_ptr -> nx_interface_physical_address_msw = physical_msw;
108         if_ptr -> nx_interface_physical_address_lsw = physical_lsw;
109     }
110 
111     /* Release the IP internal mutex.  */
112     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
113 
114     /* Return completion status.  */
115     return(driver_request.nx_ip_driver_status);
116 }
117 
118