Line 18... |
Line 18... |
* IPChecksum()
|
* IPChecksum()
|
* IPSendFrame()
|
* IPSendFrame()
|
* FrameInsert()
|
* FrameInsert()
|
*--------------------------------------------------------------------*/
|
*--------------------------------------------------------------------*/
|
#include "rtos.h"
|
#include "rtos.h"
|
#define IPPRINTF
|
#define INSIDE_TCPIP
|
#include "tcpip.h"
|
#include "tcpip.h"
|
|
|
//ETHER FIELD OFFSET LENGTH VALUE
|
//ETHER FIELD OFFSET LENGTH VALUE
|
#define ETHERNET_DEST 0 //6
|
#define ETHERNET_DEST 0 //6
|
#define ETHERNET_SOURCE 6 //6
|
#define ETHERNET_SOURCE 6 //6
|
Line 659... |
Line 659... |
|
|
|
|
static int IPProcessTCPPacket(IPFrame *frameIn)
|
static int IPProcessTCPPacket(IPFrame *frameIn)
|
{
|
{
|
uint32 seq, ack;
|
uint32 seq, ack;
|
int length, ip_length, bytes, rc=0, notify=0;
|
int length, ip_length, bytes, rc=0, notify=0, window;
|
IPSocket *socket, *socketNew;
|
IPSocket *socket, *socketNew;
|
IPFrame *frameOut, *frame2, *framePrev;
|
IPFrame *frameOut, *frame2, *framePrev;
|
uint8 *packet, *packetOut;
|
uint8 *packet, *packetOut;
|
|
|
packet = frameIn->packet;
|
packet = frameIn->packet;
|
Line 871... |
Line 871... |
if(frameIn->length > ip_length + IP_VERSION_LENGTH)
|
if(frameIn->length > ip_length + IP_VERSION_LENGTH)
|
frameIn->length = (uint16)(ip_length + IP_VERSION_LENGTH);
|
frameIn->length = (uint16)(ip_length + IP_VERSION_LENGTH);
|
FrameInsert(&socket->frameReadHead, &socket->frameReadTail, frameIn);
|
FrameInsert(&socket->frameReadHead, &socket->frameReadTail, frameIn);
|
socket->ack += bytes;
|
socket->ack += bytes;
|
|
|
|
window = RECEIVE_WINDOW - (socket->ack - socket->ackProcessed);
|
|
if(window >= 536)
|
|
{
|
//Ack data
|
//Ack data
|
frameOut = IPFrameGet(FRAME_COUNT_SEND);
|
frameOut = IPFrameGet(FRAME_COUNT_SEND);
|
if(frameOut)
|
if(frameOut)
|
{
|
{
|
frameOut->packet[TCP_FLAGS] = TCP_FLAGS_ACK;
|
frameOut->packet[TCP_FLAGS] = TCP_FLAGS_ACK;
|
TCPSendPacket(socket, frameOut, TCP_DATA);
|
TCPSendPacket(socket, frameOut, TCP_DATA);
|
}
|
}
|
|
}
|
|
|
//Using frame
|
//Using frame
|
rc = 1;
|
rc = 1;
|
}
|
}
|
else if(bytes)
|
else if(bytes)
|
Line 1308... |
Line 1312... |
|
|
|
|
void IPWriteFlush(IPSocket *socket)
|
void IPWriteFlush(IPSocket *socket)
|
{
|
{
|
uint8 *packetOut;
|
uint8 *packetOut;
|
|
|
|
if(socket == NULL)
|
|
socket = (IPSocket*)OS_ThreadInfoGet(OS_ThreadSelf(), 0);
|
if(socket->frameSend && socket->state != IP_UDP &&
|
if(socket->frameSend && socket->state != IP_UDP &&
|
socket->state != IP_PING)
|
socket->state != IP_PING)
|
{
|
{
|
packetOut = socket->frameSend->packet;
|
packetOut = socket->frameSend->packet;
|
packetOut[TCP_FLAGS] = TCP_FLAGS_ACK | TCP_FLAGS_PSH;
|
packetOut[TCP_FLAGS] = TCP_FLAGS_ACK | TCP_FLAGS_PSH;
|
Line 1329... |
Line 1336... |
uint8 *packetOut;
|
uint8 *packetOut;
|
uint32 bytes, count=0, tries=0;
|
uint32 bytes, count=0, tries=0;
|
int offset;
|
int offset;
|
OS_Thread_t *self;
|
OS_Thread_t *self;
|
|
|
|
if(socket == NULL)
|
|
socket = (IPSocket*)OS_ThreadInfoGet(OS_ThreadSelf(), 0);
|
|
|
if(socket->state > IP_TCP)
|
if(socket->state > IP_TCP)
|
return 0;
|
return 0;
|
|
|
if(socket->timeout)
|
if(socket->timeout)
|
socket->timeout = socket->timeoutReset;
|
socket->timeout = socket->timeoutReset;
|
|
|
#ifdef INCLUDE_FILESYS
|
#ifndef EXCLUDE_FILESYS
|
if(socket->fileOut) //override stdout
|
if(socket->fileOut) //override stdout
|
return fwrite((char*)buf, 1, length, socket->fileOut);
|
return fwrite((char*)buf, 1, length, socket->fileOut);
|
#endif
|
#endif
|
|
|
//printf("IPWrite(0x%x, %d)", Socket, Length);
|
//printf("IPWrite(0x%x, %d)", Socket, Length);
|
Line 1418... |
Line 1428... |
uint32 IPRead(IPSocket *socket, uint8 *buf, uint32 length)
|
uint32 IPRead(IPSocket *socket, uint8 *buf, uint32 length)
|
{
|
{
|
IPFrame *frame, *frame2;
|
IPFrame *frame, *frame2;
|
int count=0, bytes, offset;
|
int count=0, bytes, offset;
|
|
|
#ifdef INCLUDE_FILESYS
|
if(socket == NULL)
|
|
socket = (IPSocket*)OS_ThreadInfoGet(OS_ThreadSelf(), 0);
|
|
|
|
#ifndef EXCLUDE_FILESYS
|
if(socket->fileIn) //override stdin
|
if(socket->fileIn) //override stdin
|
{
|
{
|
bytes = fread(buf, 1, 1, socket->fileIn);
|
bytes = fread(buf, 1, 1, socket->fileIn);
|
if(bytes == 0)
|
if(bytes == 0)
|
{
|
{
|
Line 1548... |
Line 1561... |
socket->timeoutReset = SOCKET_TIMEOUT;
|
socket->timeoutReset = SOCKET_TIMEOUT;
|
socket->state = IP_FIN_SERVER;
|
socket->state = IP_FIN_SERVER;
|
}
|
}
|
|
|
|
|
void IPPrintf(IPSocket *socket, char *message,
|
int IPPrintf(IPSocket *socket, char *format,
|
int arg0, int arg1, int arg2, int arg3)
|
int arg0, int arg1, int arg2, int arg3,
|
|
int arg4, int arg5, int arg6, int arg7)
|
{
|
{
|
char buf[500];
|
char buffer[256], *ptr = buffer;
|
|
int rc = 1;
|
|
int length;
|
|
|
if(socket == NULL)
|
if(socket == NULL)
|
{
|
socket = (IPSocket*)OS_ThreadInfoGet(OS_ThreadSelf(), 0);
|
printf(message, arg0, arg1, arg2, arg3);
|
if(strcmp(format, "%s") == 0)
|
return;
|
ptr = (char*)arg0;
|
}
|
|
if(strcmp(message, "%s") == 0)
|
|
IPWrite(socket, (uint8*)arg0, (int)strlen((char*)arg0));
|
|
else
|
else
|
{
|
rc = sprintf(buffer, format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
|
sprintf(buf, message, arg0, arg1, arg2, arg3, 0, 0, 0, 0);
|
length = strlen(ptr);
|
IPWrite(socket, (uint8*)buf, (int)strlen(buf));
|
IPWrite(socket, (unsigned char*)ptr, length);
|
}
|
if(socket->dontFlush == 0 || strstr(format, "\n"))
|
if(socket->dontFlush == 0 || strstr(message, "\n"))
|
|
IPWriteFlush(socket);
|
IPWriteFlush(socket);
|
|
return rc;
|
}
|
}
|
|
|
|
|
|
|
void IPTick(void)
|
void IPTick(void)
|
{
|
{
|
IPFrame *frame, *frame2;
|
IPFrame *frame, *frame2;
|
IPSocket *socket, *socket2;
|
IPSocket *socket, *socket2;
|
unsigned long ticks;
|
unsigned long ticks;
|