init
Embed:
(wiki syntax)
Show/hide line numbers
tcp.h
00001 /* 00002 * Copyright (c) 2013-2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef TCP_H_ 00019 #define TCP_H_ 00020 00021 00022 #define TCP_UNACK_MAX 3 00023 #define TCP_WINDOW_SIZE 300 00024 #define TCP_ETHERNET_WINDOW_SIZE 1440 00025 #define TCP_TIMER_PERIOD 150 // milliseconds 00026 00027 #define TCP_LOWPAN_MSS_LIMIT 300 00028 00029 #define TCP_MAX_RX_QLEN 1024 00030 00031 // Times in TCP_TIMER_PERIOD units 00032 #define TCP_TIME_WAIT_TO_CLOSE 1600 // 4 minutes 00033 #define TCP_FIN_WAIT_2_TIMEOUT 500 // 75s 00034 #define TCP_MINIMUM_RTO 8 // 1.05s + 1 tick round-up 00035 #define TCP_INITIAL_RTO 8 // 1.05s (RFC6298) + 1 tick round-up 00036 #define TCP_INITIAL_CONSERVATIVE_RTO 21 // 3s + 1 tick round-up 00037 #define TCP_MAXIMUM_RTO 400 // 1 minute 00038 #define TCP_MAX_RETRIES 6 // if min RTO, 1s+2s+4s+8s+16s+32s(+60s wait) = 123s - RFC1122 says at least 100 seconds 00039 #define TCP_SYN_RETRIES 7 // retry at 1s+2s+4s+8s+16s+32s+60s(+60s wait) = 3 min 3s - RFC1122 says at least 3 minutes 00040 #define TCP_PROBLEM_RETRIES 3 // report connection difficulties - RFC1122 says at least 3 retries 00041 00042 // maximum RTO should be kept below 4000 to avoid 16-bit calculation overflow 00043 00044 #define TCP_FLAG_FIN 1 00045 #define TCP_FLAG_SYN 2 00046 #define TCP_FLAG_RST 4 00047 #define TCP_FLAG_PSH 8 00048 #define TCP_FLAG_ACK 16 00049 #define TCP_FLAG_URG 32 00050 #define TCP_FLAG_ECE 64 00051 #define TCP_FLAG_CWR 128 00052 00053 #define TCP_OPTION_END 0 00054 #define TCP_OPTION_NOP 1 00055 #define TCP_OPTION_MSS 2 00056 00057 // State numbering must remain fixed, as TCP test API uses it, 00058 // and we don't expose it in public headers. The chosen 00059 // numbering is from the SNMP MIB - RFC 4022. 00060 #define TCP_STATE_CLOSED 1 00061 #define TCP_STATE_LISTEN 2 00062 #define TCP_STATE_SYN_SENT 3 00063 #define TCP_STATE_SYN_RECEIVED 4 00064 #define TCP_STATE_ESTABLISHED 5 00065 #define TCP_STATE_FIN_WAIT_1 6 00066 #define TCP_STATE_FIN_WAIT_2 7 00067 #define TCP_STATE_CLOSE_WAIT 8 00068 #define TCP_STATE_LAST_ACK 9 00069 #define TCP_STATE_CLOSING 10 00070 #define TCP_STATE_TIME_WAIT 11 00071 #define TCP_STATES 12 00072 00073 struct inet_pcb_s; 00074 00075 typedef enum tcp_error_ { 00076 00077 TCP_ERROR_NO_ERROR, 00078 TCP_ERROR_BUFFER_ALLOCATION_ERROR, 00079 TCP_ERROR_SOCKET_ALLOCATION_ERROR, 00080 TCP_ERROR_SOCKET_NOT_FOUND, 00081 TCP_ERROR_SECURE_ALLOCATION_ERROR, 00082 TCP_ERROR_WRONG_STATE, 00083 TCP_ERROR_ADDR_SELECTION, 00084 TCP_SESSION_REMOVED 00085 00086 } tcp_error; 00087 00088 typedef struct tcp_session_t { 00089 struct inet_pcb_s *inet_pcb; 00090 protocol_interface_info_entry_t *interface; 00091 uint32_t send_unacknowledged; 00092 uint32_t send_next; 00093 uint32_t send_wl1; // segment seq number at last window update 00094 uint32_t send_wl2; // segment ack number at last window update 00095 uint16_t send_window; 00096 uint16_t send_mss_peer; // peer's advertised mss (RFC 5681 RMSS) 00097 uint16_t send_mss_eff; // effective send MSS (RFC 1122 Eff.snd.MSS, RFC 5681 SMSS) 00098 uint16_t receive_mss; 00099 uint32_t receive_next; // sequence number 00100 uint32_t receive_adv; // advertised window right edge 00101 uint16_t timer; 00102 uint8_t retry; 00103 bool passive_open : 1; 00104 uint8_t state; 00105 bool busy : 1; 00106 bool persist : 1; 00107 bool sent_fin : 1; 00108 uint16_t rto; 00109 int16_t srtt8; // these should go into destination cache 00110 int16_t srttvar4; 00111 } tcp_session_t; 00112 00113 #ifdef NO_TCP 00114 NS_DUMMY_DEFINITIONS_OK 00115 #undef TCP_TEST 00116 #define tcp_info(pcb) ((struct tcp_session_t *)NULL) 00117 #define tcp_buf_save(buf) (buf) 00118 #define tcp_up(buf) buffer_free(buf) 00119 #define tcp_session_ptr_allocate(socket_id) ((tcp_session_t*) NULL) 00120 #define tcp_socket_released(tcp_info) ((void) 0) 00121 #define tcp_state_name(tcp_session) "NO_TCP" 00122 #define tcp_handle_time_event(tickUpdate) ((void) 0) 00123 #define tcp_session_data_received(tcp_info) ((void) 0) 00124 #define tcp_session_close(tcp_info) TCP_ERROR_SOCKET_NOT_FOUND 00125 #define tcp_session_shutdown_read(tcp_info) TCP_ERROR_SOCKET_NOT_FOUND 00126 #else 00127 #define tcp_info(pcb) ((struct tcp_session_t *)((pcb)->session)) 00128 extern tcp_error tcp_session_open(tcp_session_t *tcp_session); 00129 extern tcp_error tcp_session_close(tcp_session_t *tcp_session); 00130 extern tcp_error tcp_session_shutdown_read(tcp_session_t *tcp_session); 00131 extern tcp_error tcp_session_abort(tcp_session_t *tcp_session); 00132 extern tcp_error tcp_session_send(tcp_session_t *tcp_info, buffer_t *buf); 00133 extern void tcp_session_data_received(tcp_session_t *tcp_info); 00134 extern buffer_t *tcp_up(buffer_t *buf); 00135 extern tcp_session_t *tcp_session_ptr_allocate(struct inet_pcb_s *inet_pcb, tcp_session_t *from_time_wait); 00136 extern tcp_session_t *tcp_session_ptr_free(tcp_session_t *tcp_info); 00137 extern void tcp_socket_released(tcp_session_t *tcp_info); 00138 const char *tcp_state_name(const tcp_session_t *tcp_info); 00139 00140 /** 00141 * \brief Function used for handling time events. 00142 */ 00143 00144 extern void tcp_handle_time_event(uint16_t tickUpdate); 00145 #endif // NO_TCP 00146 00147 #ifdef TCP_TEST 00148 extern int8_t tcp_test_drop_tx(int state, uint8_t count); 00149 extern int8_t tcp_test_drop_rx(int state, uint8_t count); 00150 extern void tcp_test_drop_reset(void); 00151 #else 00152 #define tcp_test_drop_tx(state, count) ((int8_t) -1) 00153 #define tcp_test_drop_rx(state, codunt) ((int8_t) -1) 00154 #define tcp_test_drop_reset() ((void) 0) 00155 #endif 00156 00157 #endif /* TCP_H_ */
Generated on Tue Jul 12 2022 13:25:13 by
1.7.2