Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
- TCPHeaderOUT->Checksum = TCP_Checksum16(TCPHeaderOUT, ServerIPAddress,
- ConnectionStateTable[CSTableEntry].RemoteAddress,
+ TCPHeaderOUT->Checksum = TCP_Checksum16(TCPHeaderOUT, &ServerIPAddress,
+ &ConnectionStateTable[CSTableEntry].RemoteAddress,
/** Sets the state and callback handler of the given port, specified in big endian to the given state.
*
* \param[in] Port Port whose state and callback function to set, specified in big endian
/** Sets the state and callback handler of the given port, specified in big endian to the given state.
*
* \param[in] Port Port whose state and callback function to set, specified in big endian
* \param[in] Handler Application callback handler for the port
*
* \return Boolean true if the port state was set, false otherwise (no more space in the port state table)
* \param[in] Handler Application callback handler for the port
*
* \return Boolean true if the port state was set, false otherwise (no more space in the port state table)
/* Note, Port number should be specified in BIG endian to simplify network code */
/* Check to see if the port entry is already in the port state table */
/* Note, Port number should be specified in BIG endian to simplify network code */
/* Check to see if the port entry is already in the port state table */
{
/* Find existing entry for the port in the table, update it if found */
if (PortStateTable[PTableEntry].Port == Port)
{
/* Find existing entry for the port in the table, update it if found */
if (PortStateTable[PTableEntry].Port == Port)
/* Check if trying to open the port -- if so we need to find an unused (closed) entry and replace it */
if (State == TCP_Port_Open)
{
/* Check if trying to open the port -- if so we need to find an unused (closed) entry and replace it */
if (State == TCP_Port_Open)
{
{
/* Find a closed port entry in the table, change it to the given port and state */
if (PortStateTable[PTableEntry].State == TCP_Port_Closed)
{
/* Find a closed port entry in the table, change it to the given port and state */
if (PortStateTable[PTableEntry].State == TCP_Port_Closed)
*/
uint8_t TCP_GetPortState(const uint16_t Port)
{
/* Note, Port number should be specified in BIG endian to simplify network code */
*/
uint8_t TCP_GetPortState(const uint16_t Port)
{
/* Note, Port number should be specified in BIG endian to simplify network code */
{
/* Find existing entry for the port in the table, return the port status if found */
if (PortStateTable[PTableEntry].Port == Port)
{
/* Find existing entry for the port in the table, return the port status if found */
if (PortStateTable[PTableEntry].Port == Port)
* \param[in] Port TCP port of the connection on the device, specified in big endian
* \param[in] RemoteAddress Remote protocol IP address of the connected device
* \param[in] RemotePort TCP port of the remote device in the connection, specified in big endian
* \param[in] Port TCP port of the connection on the device, specified in big endian
* \param[in] RemoteAddress Remote protocol IP address of the connected device
* \param[in] RemotePort TCP port of the remote device in the connection, specified in big endian
*
* \return Boolean true if the connection was updated or created, false otherwise (no more space in the connection state table)
*/
bool TCP_SetConnectionState(const uint16_t Port,
*
* \return Boolean true if the connection was updated or created, false otherwise (no more space in the connection state table)
*/
bool TCP_SetConnectionState(const uint16_t Port,
ConnectionStateTable[CSTableEntry].RemotePort == RemotePort)
{
ConnectionStateTable[CSTableEntry].State = State;
ConnectionStateTable[CSTableEntry].RemotePort == RemotePort)
{
ConnectionStateTable[CSTableEntry].State = State;
if (ConnectionStateTable[CSTableEntry].State == TCP_Connection_Closed)
{
ConnectionStateTable[CSTableEntry].Port = Port;
if (ConnectionStateTable[CSTableEntry].State == TCP_Connection_Closed)
{
ConnectionStateTable[CSTableEntry].Port = Port;
ConnectionStateTable[CSTableEntry].RemotePort = RemotePort;
ConnectionStateTable[CSTableEntry].State = State;
return true;
ConnectionStateTable[CSTableEntry].RemotePort = RemotePort;
ConnectionStateTable[CSTableEntry].State = State;
return true;
* \param[in] RemoteAddress Remote protocol IP address of the connected host
* \param[in] RemotePort Remote TCP port of the connected host, specified in big endian
*
* \param[in] RemoteAddress Remote protocol IP address of the connected host
* \param[in] RemotePort Remote TCP port of the connected host, specified in big endian
*
const uint16_t RemotePort)
{
/* Note, Port number should be specified in BIG endian to simplify network code */
const uint16_t RemotePort)
{
/* Note, Port number should be specified in BIG endian to simplify network code */
* \return ConnectionInfo structure of the connection if found, NULL otherwise
*/
TCP_ConnectionInfo_t* TCP_GetConnectionInfo(const uint16_t Port,
* \return ConnectionInfo structure of the connection if found, NULL otherwise
*/
TCP_ConnectionInfo_t* TCP_GetConnectionInfo(const uint16_t Port,
const uint16_t RemotePort)
{
/* Note, Port number should be specified in BIG endian to simplify network code */
const uint16_t RemotePort)
{
/* Note, Port number should be specified in BIG endian to simplify network code */
ConnectionStateTable[CSTableEntry].RemotePort == RemotePort)
{
return &ConnectionStateTable[CSTableEntry].Info;
ConnectionStateTable[CSTableEntry].RemotePort == RemotePort)
{
return &ConnectionStateTable[CSTableEntry].Info;
- TCP_SetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort, TCP_Connection_Listen);
+ TCP_SetConnectionState(TCPHeaderIN->DestinationPort, &IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort, TCP_Connection_Listen);
TCPHeaderIN->SourcePort, TCP_Connection_Closed))
{
TCPHeaderOUT->Flags = (TCP_FLAG_RST | TCP_FLAG_ACK);
TCPHeaderIN->SourcePort, TCP_Connection_Closed))
{
TCPHeaderOUT->Flags = (TCP_FLAG_RST | TCP_FLAG_ACK);
- switch (TCP_GetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort))
+ switch (TCP_GetConnectionState(TCPHeaderIN->DestinationPort, &IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort))
{
case TCP_Connection_Listen:
if (TCPHeaderIN->Flags == TCP_FLAG_SYN)
{
/* SYN connection starts a connection with a peer */
{
case TCP_Connection_Listen:
if (TCPHeaderIN->Flags == TCP_FLAG_SYN)
{
/* SYN connection starts a connection with a peer */
TCPHeaderIN->SourcePort, TCP_Connection_SYNReceived))
{
TCPHeaderOUT->Flags = (TCP_FLAG_SYN | TCP_FLAG_ACK);
TCPHeaderIN->SourcePort, TCP_Connection_SYNReceived))
{
TCPHeaderOUT->Flags = (TCP_FLAG_SYN | TCP_FLAG_ACK);
- ConnectionInfo = TCP_GetConnectionInfo(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort);
+ ConnectionInfo = TCP_GetConnectionInfo(TCPHeaderIN->DestinationPort, &IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort);
ConnectionInfo->SequenceNumberIn = (SwapEndian_32(TCPHeaderIN->SequenceNumber) + 1);
ConnectionInfo->SequenceNumberOut = 0;
ConnectionInfo->SequenceNumberIn = (SwapEndian_32(TCPHeaderIN->SequenceNumber) + 1);
ConnectionInfo->SequenceNumberOut = 0;
TCPHeaderIN->SourcePort);
/* Check if the buffer is currently in use either by a buffered data to send, or receive */
TCPHeaderIN->SourcePort);
/* Check if the buffer is currently in use either by a buffered data to send, or receive */
TCPHeaderIN->SourcePort, TCP_Connection_FINWait1);
break;
case TCP_Connection_FINWait1:
if (TCPHeaderIN->Flags == (TCP_FLAG_FIN | TCP_FLAG_ACK))
{
TCPHeaderIN->SourcePort, TCP_Connection_FINWait1);
break;
case TCP_Connection_FINWait1:
if (TCPHeaderIN->Flags == (TCP_FLAG_FIN | TCP_FLAG_ACK))
{
TCPHeaderIN->SourcePort, TCP_Connection_Closed);
}
else if (TCPHeaderIN->Flags == TCP_FLAG_ACK)
{
TCPHeaderIN->SourcePort, TCP_Connection_Closed);
}
else if (TCPHeaderIN->Flags == TCP_FLAG_ACK)
{
- TCPHeaderOUT->Checksum = TCP_Checksum16(TCPHeaderOUT, IPHeaderIN->DestinationAddress,
- IPHeaderIN->SourceAddress, sizeof(TCP_Header_t));
+ TCPHeaderOUT->Checksum = TCP_Checksum16(TCPHeaderOUT, &IPHeaderIN->DestinationAddress,
+ &IPHeaderIN->SourceAddress, sizeof(TCP_Header_t));
* \return A 16-bit TCP checksum value
*/
static uint16_t TCP_Checksum16(void* TCPHeaderOutStart,
* \return A 16-bit TCP checksum value
*/
static uint16_t TCP_Checksum16(void* TCPHeaderOutStart,
- const IP_Address_t SourceAddress,
- const IP_Address_t DestinationAddress,
- const uint16_t TCPOutSize)
+ const IP_Address_t* SourceAddress,
+ const IP_Address_t* DestinationAddress,
+ uint16_t TCPOutSize)
- Checksum += ((uint16_t*)&SourceAddress)[0];
- Checksum += ((uint16_t*)&SourceAddress)[1];
- Checksum += ((uint16_t*)&DestinationAddress)[0];
- Checksum += ((uint16_t*)&DestinationAddress)[1];
+ Checksum += ((uint16_t*)SourceAddress)[0];
+ Checksum += ((uint16_t*)SourceAddress)[1];
+ Checksum += ((uint16_t*)DestinationAddress)[0];
+ Checksum += ((uint16_t*)DestinationAddress)[1];