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 "tx_thread.h"
30 #include "nx_ip.h"
31 #include "nx_packet.h"
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _nx_ip_raw_packet_disable PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* Yuxin Zhou, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function disables raw IP packet sending and receiving */
47 /* capability. */
48 /* */
49 /* INPUT */
50 /* */
51 /* ip_ptr Pointer to IP control block */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* status Completion status */
56 /* */
57 /* CALLS */
58 /* */
59 /* _nx_packet_release Release data packet */
60 /* _nx_ip_raw_packet_cleanup Release suspended threads */
61 /* _tx_thread_system_preempt_check Check for preemption */
62 /* tx_mutex_get Get protection mutex */
63 /* tx_mutex_put Put protection mutex */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
74 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
75 /* resulting in version 6.1 */
76 /* */
77 /**************************************************************************/
_nx_ip_raw_packet_disable(NX_IP * ip_ptr)78 UINT _nx_ip_raw_packet_disable(NX_IP *ip_ptr)
79 {
80
81 TX_INTERRUPT_SAVE_AREA
82
83 NX_PACKET *current_packet;
84 NX_PACKET *next_packet;
85
86
87 /* If trace is enabled, insert this event into the trace buffer. */
88 NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_RAW_PACKET_DISABLE, ip_ptr, 0, 0, 0, NX_TRACE_IP_EVENTS, 0, 0);
89
90 /* Get mutex protection. */
91 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
92
93 /* Disable interrupts. */
94 TX_DISABLE
95
96 /* Disable raw IP packet sending/receiving. */
97 ip_ptr -> nx_ip_raw_ip_processing = NX_NULL;
98
99 /* Pickup the head pointer to any raw IP packets queued up. */
100 next_packet = ip_ptr -> nx_ip_raw_received_packet_head;
101
102 /* Clear the head and tail pointers. */
103 ip_ptr -> nx_ip_raw_received_packet_head = NX_NULL;
104 ip_ptr -> nx_ip_raw_received_packet_tail = NX_NULL;
105 ip_ptr -> nx_ip_raw_received_packet_count = 0;
106
107 /* Temporarily disable preemption. */
108 _tx_thread_preempt_disable++;
109
110 /* Restore interrupts. */
111 TX_RESTORE
112
113 /* Loop to release any queued up raw IP packets. */
114 while (next_packet)
115 {
116
117 /* Setup the current packet pointer. */
118 current_packet = next_packet;
119
120 /* Move to the next packet. */
121 next_packet = next_packet -> nx_packet_queue_next;
122
123 /* Release the current packet. */
124 _nx_packet_release(current_packet);
125 }
126
127 /* Lift any suspension on RAW IP packet receives. */
128 while (ip_ptr -> nx_ip_raw_packet_suspension_list)
129 {
130
131 /* Release the suspended thread. */
132 _nx_ip_raw_packet_cleanup(ip_ptr -> nx_ip_raw_packet_suspension_list NX_CLEANUP_ARGUMENT);
133 }
134
135 /* Release mutex protection. */
136 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
137
138 /* Disable interrupts. */
139 TX_DISABLE
140
141 /* Restore preemption. */
142 _tx_thread_preempt_disable--;
143
144 /* Restore interrupts. */
145 TX_RESTORE
146
147 /* Check for preemption. */
148 _tx_thread_system_preempt_check();
149
150 /* Return a successful status! */
151 return(NX_SUCCESS);
152 }
153
154