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 /** Transmission Control Protocol (TCP) */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define NX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "nx_api.h"
28 #include "nx_tcp.h"
29 #include "nx_ip.h"
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _nx_tcp_enable PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Yuxin Zhou, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function enables the TCP management component for the */
44 /* specified IP instance. */
45 /* */
46 /* INPUT */
47 /* */
48 /* ip_ptr IP instance pointer */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* status Completion status */
53 /* */
54 /* CALLS */
55 /* */
56 /* tx_timer_create Create fast TCP timer */
57 /* */
58 /* CALLED BY */
59 /* */
60 /* Application Code */
61 /* */
62 /* RELEASE HISTORY */
63 /* */
64 /* DATE NAME DESCRIPTION */
65 /* */
66 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
67 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
68 /* resulting in version 6.1 */
69 /* */
70 /**************************************************************************/
_nx_tcp_enable(NX_IP * ip_ptr)71 UINT _nx_tcp_enable(NX_IP *ip_ptr)
72 {
73
74 UINT i;
75 struct NX_TCP_LISTEN_STRUCT *listen_ptr;
76
77
78 /* If trace is enabled, insert this event into the trace buffer. */
79 NX_TRACE_IN_LINE_INSERT(NX_TRACE_TCP_ENABLE, ip_ptr, 0, 0, 0, NX_TRACE_TCP_EVENTS, 0, 0);
80 /* Place all server listen request structures on the available list. */
81
82 /* Setup a pointer to the first listen. */
83 listen_ptr = &(ip_ptr -> nx_ip_tcp_server_listen_reqs[0]);
84
85 /* Setup the available listen requests head pointer. */
86 ip_ptr -> nx_ip_tcp_available_listen_requests = listen_ptr;
87
88 /* Loop through the listen requests and link them on the available list. */
89 for (i = 0; i < NX_MAX_LISTEN_REQUESTS; i++)
90 {
91
92 /* Link listen request to next listen request. */
93 listen_ptr -> nx_tcp_listen_next = listen_ptr + 1;
94
95 /* Determine if we need to move to the next listen request. */
96 if (i < (NX_MAX_LISTEN_REQUESTS - 1))
97 {
98 listen_ptr++;
99 }
100 }
101
102 /* Make sure the last listen request has a NULL pointer. */
103 listen_ptr -> nx_tcp_listen_next = NX_NULL;
104
105 /* Set the TCP packet queue processing function. */
106 ip_ptr -> nx_ip_tcp_queue_process = _nx_tcp_queue_process;
107
108 /* Set the TCP periodic processing function. */
109 ip_ptr -> nx_ip_tcp_periodic_processing = _nx_tcp_periodic_processing;
110
111 /* Set the TCP fast periodic processing function. */
112 ip_ptr -> nx_ip_tcp_fast_periodic_processing = _nx_tcp_fast_periodic_processing;
113
114 /* Set the TCP deferred cleanup check function. */
115 ip_ptr -> nx_tcp_deferred_cleanup_check = _nx_tcp_deferred_cleanup_check;
116
117 /* Setup base timer variables. */
118 _nx_tcp_fast_timer_rate = (NX_IP_PERIODIC_RATE + (NX_TCP_FAST_TIMER_RATE - 1)) / NX_TCP_FAST_TIMER_RATE;
119 _nx_tcp_ack_timer_rate = (NX_IP_PERIODIC_RATE + (NX_TCP_ACK_TIMER_RATE - 1)) / NX_TCP_ACK_TIMER_RATE;
120
121 /*lint -e{778} suppress constant expression, since NX_TCP_TRANSMIT_TIMER_RATE can be redefined. */
122 /*lint -e{835} -e{845} suppress operating on zero. */
123 _nx_tcp_transmit_timer_rate = (NX_IP_PERIODIC_RATE + (NX_TCP_TRANSMIT_TIMER_RATE - 1)) / NX_TCP_TRANSMIT_TIMER_RATE;
124
125 _nx_tcp_2MSL_timer_rate = 2 * NX_IP_PERIODIC_RATE * NX_TCP_MAXIMUM_SEGMENT_LIFETIME;
126
127 _nx_ip_fast_periodic_timer_create(ip_ptr);
128
129 /* Set the TCP packet receive function in the IP structure to indicate
130 we are ready to receive TCP packets. */
131 ip_ptr -> nx_ip_tcp_packet_receive = _nx_tcp_packet_receive;
132
133 /* Return successful completion. */
134 return(NX_SUCCESS);
135 }
136
137