Author | Matthew Schinkel - borntechi.com, copyright © 2011, all rights reserved. |
Adapted-by | |
Compiler | >=2.4n |
implements TCP/IP
http://www.faqs.org/rfcs/rfc793.html http://www.8051projects.net/out.php?link=http://www.sics.se/~adam/uip/index.php/Main_Page
Works, but may still have issues. Packet must fit within transmit buffer, I have not tested large transfers.
No dependency found
const TCP_FIN = 0b00000001
const TCP_SOURCE_PORT = 0
const PSH = 0x08
const TCP_DATA_OFFSET = 12
var byte tcp_socket_status[TCP_MAX_SOCKETS]
const TCP_WINDOW = 14
const TCP_PUSH = 0b00001000
const TCP_STATUS_FIN_WAIT_1 = 5
var byte _tcp_socket_flags[TCP_MAX_SOCKETS]
const ACK = 0x10
var byte _tcp_socket_mac_1[TCP_MAX_SOCKETS]
const TCP_STATUS_CLOSED = 10
const TCP_STATUS_CLOSING = 8
const RST = 0x04
var dword _tcp_socket_sequence_number[TCP_MAX_SOCKETS]
const TCP_STATUS_SYN_RECEIVED = 3
var byte tcp_header_length = 20
var byte _tcp_socket_mac_0[TCP_MAX_SOCKETS]
const TCP_NO_ERROR = 0
const TCP_SEQUENCE_NUMBER = 4
const TCP_ACK = 0b00010000
const TCP_STATUS_CLOSE_WAIT = 7
var byte _tcp_socket_mac_3[TCP_MAX_SOCKETS]
var word tcp_socket_remote_port[TCP_MAX_SOCKETS]
const TCP_URGENT = 0b00100000
const TCP_CWR = 0b10000000
const TCP_FLAGS = 13
const SYN = 0x02
var byte _tcp_socket_mac_4[TCP_MAX_SOCKETS]
var byte TCP_CLIENT_MAC[6]
const TCP_STATUS_LAST_ACK = 9
const TCP_HEADER_SIZE = 12
var bit _tcp_error = FALSE
const FIN = 0x01
const TCP_STATUS_FIN_WAIT_2 = 6
const TCP_ECN = 0b01000000
var byte _tcp_socket_mac_2[TCP_MAX_SOCKETS]
const TCP_NO_SOCKET_AVAILABLE = 1
var byte*4 tcp_socket_ip[TCP_MAX_SOCKETS]
const TCP_RESET = 0b00000100
var byte _tcp_socket_mac_5[TCP_MAX_SOCKETS]
const TCP_ACKNOWLEDGEMENT_NUBMER = 8
const TCP_SYN = 0b00000010
var dword _tcp_socket_acnowledgement_number[TCP_MAX_SOCKETS]
const TCP_STATUS_UNKNOWN = 0
const TCP_STATUS_SYN_SENT = 2
const TCP_STATUS_ESTABLISHED = 4
const TCP_CHECKSUM = 16
const TCP_DESTINATION_PORT = 2
const URG = 0x20
const TCP_STATUS_LISTEN = 1
var word tcp_socket_local_port[TCP_MAX_SOCKETS]
const TCP_URGENT_POINTER = 18
const TCP_OPTIONS = 20
const TCP_PADDING = 23
tcp_set_checksum(word in header_size, word in data_size)
tcp_socket_remove(byte in socket)
print_tcp_socket_info(bit in received_sent, byte in socket)
tcp_send(byte in socket, word in data_size)
tcp_send_ack(byte in socket, word in data_size)
tcp_init()
tcp_data'put(word in address, byte in data)
tcp_connect(byte in socket)
tcp_read_packet()
tcp_socket_create(word in local_port, word in remote_port) return byte
tcp_data'get(word in address) return byte
tcp_error'get() return byte
const TCP_FIN = 0b00000001
bit locations of flags
const TCP_SOURCE_PORT = 0
TCP HEADER FORMAT
const PSH = 0x08
No documentation found
const TCP_DATA_OFFSET = 12
No documentation found
var byte tcp_socket_status[TCP_MAX_SOCKETS]
socket table (you can use these in your main program)
const TCP_WINDOW = 14
No documentation found
const TCP_PUSH = 0b00001000
No documentation found
const TCP_STATUS_FIN_WAIT_1 = 5
No documentation found
var byte _tcp_socket_flags[TCP_MAX_SOCKETS]
No documentation found
const ACK = 0x10
No documentation found
var byte _tcp_socket_mac_1[TCP_MAX_SOCKETS]
No documentation found
const TCP_STATUS_CLOSED = 10
No documentation found
const TCP_STATUS_CLOSING = 8
No documentation found
const RST = 0x04
No documentation found
var dword _tcp_socket_sequence_number[TCP_MAX_SOCKETS]
No documentation found
const TCP_STATUS_SYN_RECEIVED = 3
No documentation found
var byte tcp_header_length = 20
No documentation found
var byte _tcp_socket_mac_0[TCP_MAX_SOCKETS]
No documentation found
const TCP_NO_ERROR = 0
No documentation found
const TCP_SEQUENCE_NUMBER = 4
No documentation found
const TCP_ACK = 0b00010000
Acknowlegement
const TCP_STATUS_CLOSE_WAIT = 7
No documentation found
var byte _tcp_socket_mac_3[TCP_MAX_SOCKETS]
No documentation found
var word tcp_socket_remote_port[TCP_MAX_SOCKETS]
remote port
const TCP_URGENT = 0b00100000
Urgent
const TCP_CWR = 0b10000000
Congestion window reduced
const TCP_FLAGS = 13
UAPRSF
const SYN = 0x02
No documentation found
var byte _tcp_socket_mac_4[TCP_MAX_SOCKETS]
No documentation found
var byte TCP_CLIENT_MAC[6]
No documentation found
const TCP_STATUS_LAST_ACK = 9
No documentation found
const TCP_HEADER_SIZE = 12
No documentation found
var bit _tcp_error = FALSE
No documentation found
const FIN = 0x01
TCP Flags
const TCP_STATUS_FIN_WAIT_2 = 6
No documentation found
const TCP_ECN = 0b01000000
ECN-Echo
var byte _tcp_socket_mac_2[TCP_MAX_SOCKETS]
No documentation found
const TCP_NO_SOCKET_AVAILABLE = 1
No documentation found
var byte*4 tcp_socket_ip[TCP_MAX_SOCKETS]
ip of remote pc
const TCP_RESET = 0b00000100
No documentation found
var byte _tcp_socket_mac_5[TCP_MAX_SOCKETS]
No documentation found
const TCP_ACKNOWLEDGEMENT_NUBMER = 8
No documentation found
const TCP_SYN = 0b00000010
No documentation found
var dword _tcp_socket_acnowledgement_number[TCP_MAX_SOCKETS]
other socket data for internal use
const TCP_STATUS_UNKNOWN = 0
status of TCP connection
const TCP_STATUS_SYN_SENT = 2
No documentation found
const TCP_STATUS_ESTABLISHED = 4
No documentation found
const TCP_CHECKSUM = 16
No documentation found
const TCP_DESTINATION_PORT = 2
No documentation found
const URG = 0x20
No documentation found
const TCP_STATUS_LISTEN = 1
No documentation found
var word tcp_socket_local_port[TCP_MAX_SOCKETS]
local port
const TCP_URGENT_POINTER = 18
No documentation found
const TCP_OPTIONS = 20
No documentation found
const TCP_PADDING = 23
No documentation found
tcp_set_checksum(word in header_size, word in data_size)
Calculate TCP checksum
tcp_socket_remove(byte in socket)
delete/disconnect a socket.
print_tcp_socket_info(bit in received_sent, byte in socket)
No documentation found
tcp_send(byte in socket, word in data_size)
Send a TCP packet
tcp_send_ack(byte in socket, word in data_size)
Send ack or reply to TCP
tcp_init()
Init procedure
tcp_data'put(word in address, byte in data)
No documentation found
tcp_connect(byte in socket)
Connect to a TCP server. Input a blank variable to be used as a socket name.
tcp_read_packet()
Read a TCP packet
tcp_socket_create(word in local_port, word in remote_port) return byte
Create a new socket. If a socket was not created, var tcp_error gets set. remote_port - the port number the remote server uses local_port - any port number that is avalable locally.
tcp_data'get(word in address) return byte
Fake array tcp_data[] to read/write to TCP Data space.
tcp_error'get() return byte
Read TCP error status. clears error after reading