1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** NetX Component */
16 /** */
17 /** Internet Protocol (IP) */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define NX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "nx_api.h"
28 #include "tx_thread.h"
29 #include "nx_ip.h"
30 #include "nx_packet.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _nx_ip_raw_packet_disable PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Yuxin Zhou, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function disables raw IP packet sending and receiving */
46 /* capability. */
47 /* */
48 /* INPUT */
49 /* */
50 /* ip_ptr Pointer to IP control block */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* status Completion status */
55 /* */
56 /* CALLS */
57 /* */
58 /* _nx_packet_release Release data packet */
59 /* _nx_ip_raw_packet_cleanup Release suspended threads */
60 /* _tx_thread_system_preempt_check Check for preemption */
61 /* tx_mutex_get Get protection mutex */
62 /* tx_mutex_put Put protection mutex */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* Application */
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_raw_packet_disable(NX_IP * ip_ptr)77 UINT _nx_ip_raw_packet_disable(NX_IP *ip_ptr)
78 {
79
80 TX_INTERRUPT_SAVE_AREA
81
82 NX_PACKET *current_packet;
83 NX_PACKET *next_packet;
84
85
86 /* If trace is enabled, insert this event into the trace buffer. */
87 NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_RAW_PACKET_DISABLE, ip_ptr, 0, 0, 0, NX_TRACE_IP_EVENTS, 0, 0);
88
89 /* Get mutex protection. */
90 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
91
92 /* Disable interrupts. */
93 TX_DISABLE
94
95 /* Disable raw IP packet sending/receiving. */
96 ip_ptr -> nx_ip_raw_ip_processing = NX_NULL;
97
98 /* Pickup the head pointer to any raw IP packets queued up. */
99 next_packet = ip_ptr -> nx_ip_raw_received_packet_head;
100
101 /* Clear the head and tail pointers. */
102 ip_ptr -> nx_ip_raw_received_packet_head = NX_NULL;
103 ip_ptr -> nx_ip_raw_received_packet_tail = NX_NULL;
104 ip_ptr -> nx_ip_raw_received_packet_count = 0;
105
106 /* Temporarily disable preemption. */
107 _tx_thread_preempt_disable++;
108
109 /* Restore interrupts. */
110 TX_RESTORE
111
112 /* Loop to release any queued up raw IP packets. */
113 while (next_packet)
114 {
115
116 /* Setup the current packet pointer. */
117 current_packet = next_packet;
118
119 /* Move to the next packet. */
120 next_packet = next_packet -> nx_packet_queue_next;
121
122 /* Release the current packet. */
123 _nx_packet_release(current_packet);
124 }
125
126 /* Lift any suspension on RAW IP packet receives. */
127 while (ip_ptr -> nx_ip_raw_packet_suspension_list)
128 {
129
130 /* Release the suspended thread. */
131 _nx_ip_raw_packet_cleanup(ip_ptr -> nx_ip_raw_packet_suspension_list NX_CLEANUP_ARGUMENT);
132 }
133
134 /* Release mutex protection. */
135 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
136
137 /* Disable interrupts. */
138 TX_DISABLE
139
140 /* Restore preemption. */
141 _tx_thread_preempt_disable--;
142
143 /* Restore interrupts. */
144 TX_RESTORE
145
146 /* Check for preemption. */
147 _tx_thread_system_preempt_check();
148
149 /* Return a successful status! */
150 return(NX_SUCCESS);
151 }
152
153