From: John Hodge Date: Sun, 14 Feb 2010 03:48:38 +0000 (+0800) Subject: More work on TCP, splitted UDI arch dependent out of udi.h, slight work on AxWin X-Git-Tag: rel0.06~298 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3c85c92afe3f506a921447ef07963525d796137b;p=tpg%2Facess2.git More work on TCP, splitted UDI arch dependent out of udi.h, slight work on AxWin --- diff --git a/Modules/IPStack/ipv4.c b/Modules/IPStack/ipv4.c index 5fe99abc..15cf65f8 100644 --- a/Modules/IPStack/ipv4.c +++ b/Modules/IPStack/ipv4.c @@ -51,6 +51,12 @@ int IPv4_RegisterCallback(int ID, tIPCallback Callback) /** * \brief Creates and sends an IPv4 Packet + * \param Iface Interface + * \param Address Destination IP + * \param Protocol Protocol ID + * \param ID Some random ID number + * \param Length Data Length + * \param Data Packet Data */ int IPv4_SendPacket(tInterface *Iface, tIPv4 Address, int Protocol, int ID, int Length, void *Data) { @@ -70,7 +76,7 @@ int IPv4_SendPacket(tInterface *Iface, tIPv4 Address, int Protocol, int ID, int hdr->HeaderChecksum = 0; // Will be set later hdr->Source = Iface->IP4.Address; hdr->Destination = Address; - hdr->HeaderChecksum = htons( IPv4_Checksum(hdr, sizeof(tIPv4Header)) ); + hdr->HeaderChecksum = IPv4_Checksum(hdr, sizeof(tIPv4Header)); Log("[IPv4 ] Sending packet to %i.%i.%i.%i", Address.B[0], Address.B[1], Address.B[2], Address.B[3]); @@ -211,7 +217,7 @@ Uint16 IPv4_Checksum(void *Buf, int Size) sum ++; // Simulate 1's complement sum += arr[i]; } - return htons( ~sum ); + return ~sum ; } /** diff --git a/Modules/IPStack/tcp.c b/Modules/IPStack/tcp.c index 7537a4b4..dd94b923 100644 --- a/Modules/IPStack/tcp.c +++ b/Modules/IPStack/tcp.c @@ -64,14 +64,45 @@ void TCP_StartConnection(tTCPConnection *Conn) hdr->SourcePort = Conn->LocalPort; hdr->DestPort = Conn->RemotePort; - hdr->SequenceNumber = rand(); + Conn->NextSequenceSend = rand(); + hdr->SequenceNumber = Conn->NextSequenceSend; hdr->DataOffset = (sizeof(tTCPHeader)+3)/4; hdr->Flags = TCP_FLAG_SYN; + hdr->WindowSize = 0; // TODO + hdr->Checksum = 0; // TODO + hdr->UrgentPointer = 0; // SEND PACKET - // Send a TCP SYN to the target to open the connection + TCP_SendPacket( Conn, sizeof(tTCPHeader), &hdr ); return ; } +/** + * \brief Sends a packet from the specified connection, calculating the checksums + * \param Conn Connection + * \param Length Length of data + * \param Data Packet data + */ +void TCP_SendPacket( tTCPConnection *Conn, size_t Length, tTCPHeader *Data ) +{ + size_t buflen; + Uint32 *buf; + switch( Conn->Interface.Type ) + { + case 4: + buflen = 4 + 4 + 4 + ((Length+1)&1); + buf = malloc( buflen ); + buf[0] = Conn->Interface.IP4.Address.L; + buf[1] = Conn->RemoteIP.v4.L; + buf[2] = (htons(Length)<<16) | (6<<8) | 0; + Data->Checksum = 0; + memcpy( &buf[3], Data, buflen ); + Data->Checksum = IPv4_Checksum( buf, buflen ); + free(buf); + IPv4_SendPacket(Conn->Interface, Conn->RemoteIP.v4, IP4PROT_TCP, 0, sizeof(tTCPHeader), &hdr); + break; + } +} + /** * \fn void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer) * \brief Handles a packet from the IP Layer diff --git a/Modules/Interfaces/UDI/include/udi.h b/Modules/Interfaces/UDI/include/udi.h index fa5cac30..53953c07 100644 --- a/Modules/Interfaces/UDI/include/udi.h +++ b/Modules/Interfaces/UDI/include/udi.h @@ -1,73 +1,13 @@ /** * \file udi.h */ -#ifndef _UDI_ARCH_H_ -#define _UDI_ARCH_H_ +#ifndef _UDI_H_ +#define _UDI_H_ // Use the core acess file to use the specific size types (plus va_arg) #include -typedef Sint8 udi_sbit8_t; /* signed 8-bit: -2^7..2^7-1 */ -typedef Sint16 udi_sbit16_t; /* signed 16-bit: -2^15..2^15-1 */ -typedef Sint32 udi_sbit32_t; /* signed 32-bit: -2^31..2^31-1 */ -typedef Uint8 udi_ubit8_t; /* unsigned 8-bit: 0..28-1 */ -typedef Uint16 udi_ubit16_t; /* unsigned 16-bit: 0..216-1 */ -typedef Uint32 udi_ubit32_t; /* unsigned 32-bit: 0..232-1 */ - -typedef udi_ubit8_t udi_boolean_t; /* 0=False; 1..28-1=True */ -#define FALSE 0 -#define TRUE 1 - -typedef size_t udi_size_t; /* buffer size */ -typedef size_t udi_index_t; /* zero-based index type */ - -typedef void *_udi_handle_t; -#define _NULL_HANDLE NULL - -/* Channel Handle */ -typedef _udi_handle_t *udi_channel_t; -#define UDI_NULL_CHANNEL _NULL_HANDLE - -/** - * \brief Buffer Path - */ -typedef _udi_handle_t udi_buf_path_t; -#define UDI_NULL_BUF_PATH _NULL_HANDLE - -typedef _udi_handle_t udi_origin_t; -#define UDI_NULL_ORIGIN _NULL_HANDLE - -typedef Sint64 udi_timestamp_t; - -#define UDI_HANDLE_IS_NULL(handle, handle_type) (handle == NULL) -#define UDI_HANDLE_ID(handle, handle_type) ((Uint32)handle) - -/** - * \name va_arg wrapper - * \{ - */ -#define UDI_VA_ARG(pvar, type, va_code) va_arg(pvar,type) -#define UDI_VA_UBIT8_T -#define UDI_VA_SBIT8_T -#define UDI_VA_UBIT16_T -#define UDI_VA_SBIT16_T -#define UDI_VA_UBIT32_T -#define UDI_VA_SBIT32_T -#define UDI_VA_BOOLEAN_T -#define UDI_VA_INDEX_T -#define UDI_VA_SIZE_T -#define UDI_VA_STATUS_T -#define UDI_VA_CHANNEL_T -#define UDI_VA_ORIGIN_T -#define UDI_VA_POINTER -/** - * \} - */ - -/** - * \brief Status Type - */ -typedef udi_ubit32_t udi_status_t; +#include "udi/arch/x86.h" /** * \name Values and Flags for udi_status_t diff --git a/Modules/Interfaces/UDI/include/udi/arch/x86.h b/Modules/Interfaces/UDI/include/udi/arch/x86.h new file mode 100644 index 00000000..9c505d33 --- /dev/null +++ b/Modules/Interfaces/UDI/include/udi/arch/x86.h @@ -0,0 +1,67 @@ + +#ifndef _UDI_ARCH_x86_H_ +#define _UDI_ARCH_x86_H_ + +typedef Sint8 udi_sbit8_t; /* signed 8-bit: -2^7..2^7-1 */ +typedef Sint16 udi_sbit16_t; /* signed 16-bit: -2^15..2^15-1 */ +typedef Sint32 udi_sbit32_t; /* signed 32-bit: -2^31..2^31-1 */ +typedef Uint8 udi_ubit8_t; /* unsigned 8-bit: 0..28-1 */ +typedef Uint16 udi_ubit16_t; /* unsigned 16-bit: 0..216-1 */ +typedef Uint32 udi_ubit32_t; /* unsigned 32-bit: 0..232-1 */ + +typedef udi_ubit8_t udi_boolean_t; /* 0=False; 1..28-1=True */ +#define FALSE 0 +#define TRUE 1 + +typedef size_t udi_size_t; /* buffer size */ +typedef size_t udi_index_t; /* zero-based index type */ + +typedef void *_udi_handle_t; +#define _NULL_HANDLE NULL + +/* Channel Handle */ +typedef _udi_handle_t *udi_channel_t; +#define UDI_NULL_CHANNEL _NULL_HANDLE + +/** + * \brief Buffer Path + */ +typedef _udi_handle_t udi_buf_path_t; +#define UDI_NULL_BUF_PATH _NULL_HANDLE + +typedef _udi_handle_t udi_origin_t; +#define UDI_NULL_ORIGIN _NULL_HANDLE + +typedef Sint64 udi_timestamp_t; + +#define UDI_HANDLE_IS_NULL(handle, handle_type) (handle == NULL) +#define UDI_HANDLE_ID(handle, handle_type) ((Uint32)handle) + +/** + * \name va_arg wrapper + * \{ + */ +#define UDI_VA_ARG(pvar, type, va_code) va_arg(pvar,type) +#define UDI_VA_UBIT8_T +#define UDI_VA_SBIT8_T +#define UDI_VA_UBIT16_T +#define UDI_VA_SBIT16_T +#define UDI_VA_UBIT32_T +#define UDI_VA_SBIT32_T +#define UDI_VA_BOOLEAN_T +#define UDI_VA_INDEX_T +#define UDI_VA_SIZE_T +#define UDI_VA_STATUS_T +#define UDI_VA_CHANNEL_T +#define UDI_VA_ORIGIN_T +#define UDI_VA_POINTER +/** + * \} + */ + +/** + * \brief Status Type + */ +typedef udi_ubit32_t udi_status_t; + +#endif diff --git a/Usermode/Applications/axwin2_src/WM/messages.c b/Usermode/Applications/axwin2_src/WM/messages.c index f10e6bb1..bf2d2b89 100644 --- a/Usermode/Applications/axwin2_src/WM/messages.c +++ b/Usermode/Applications/axwin2_src/WM/messages.c @@ -60,13 +60,13 @@ void Messages_Handle(tAxWin_Message *Msg, tMessages_Handle_Callback *Respond, in { switch(Msg->ID) { - case MSG_REQ_PING: - Msg->ID = MSG_RSP_PONG; + case MSG_SREQ_PING: + Msg->ID = MSG_SRSP_PONG; Respond(ID, sizeof(Msg->ID), Msg); break; default: - fprintf(stderr, "WARNING: Unknown message %i from %i (%p)\n", - Msg->ID, ID, Respond); + fprintf(stderr, "WARNING: Unknown message %i from %i (%p)\n", Msg->ID, ID, Respond); + _SysDebug("WARNING: Unknown message %i from %i (%p)\n", Msg->ID, ID, Respond); break; } }