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