Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions FreeRTOS_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,8 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor

iptraceNETWORK_INTERFACE_INPUT( pxNetworkBuffer->xDataLength, pxNetworkBuffer->pucEthernetBuffer );

FreeRTOS_debug_printf(("Processing network buffer of size %u", pxNetworkBuffer->xDataLength));

/* Interpret the Ethernet frame. */
if( pxNetworkBuffer->xDataLength >= sizeof( EthernetHeader_t ) )
{
Expand Down Expand Up @@ -1808,6 +1810,8 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor

case ipIPv4_FRAME_TYPE:

FreeRTOS_debug_printf(("It's an IP type...\n"));

/* The Ethernet frame contains an IP packet. */
if( pxNetworkBuffer->xDataLength >= sizeof( IPPacket_t ) )
{
Expand Down Expand Up @@ -1930,6 +1934,13 @@ void vSetMultiCastIPv4MacAddress( uint32_t ulIPAddress,
}
/*-----------------------------------------------------------*/

void print_ip_address(uint32_t ulIPAddress) {
char cBuffer[17];
cBuffer[16] = '\0';
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
FreeRTOS_debug_printf( ( "IP Address: %s\n", cBuffer ) );
}

/**
* @brief Check whether this IP packet is to be allowed or to be dropped.
*
Expand Down Expand Up @@ -1993,6 +2004,12 @@ static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPP
/* Or (during DHCP negotiation) we have no IP-address yet? */
( *ipLOCAL_IP_ADDRESS_POINTER != 0U ) )
{
FreeRTOS_debug_printf(("Destination IP Address\n"));
print_ip_address(ulDestinationIPAddress);
FreeRTOS_debug_printf(("Correct IP Address\n"));
print_ip_address(*ipLOCAL_IP_ADDRESS_POINTER);
FreeRTOS_debug_printf(("Broadcast IP Address"));
print_ip_address(ipBROADCAST_IP_ADDRESS);
/* Packet is not for this node, release it */
eReturn = eReleaseBuffer;
}
Expand Down
29 changes: 28 additions & 1 deletion FreeRTOS_Sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain,
{
FreeRTOS_Socket_t * pxSocket;

FreeRTOS_debug_printf(("FreeRTOS_socket called...\n"));

/* Note that this value will be over-written by the call to prvDetermineSocketSize. */
size_t uxSocketSize = 1;
EventGroupHandle_t xEventGroup;
Expand Down Expand Up @@ -462,6 +464,7 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain,
pxSocket->u.xTCP.usMSS = ( uint16_t ) ipconfigTCP_MSS;
pxSocket->u.xTCP.uxRxStreamSize = ( size_t ) ipconfigTCP_RX_BUFFER_LENGTH;
pxSocket->u.xTCP.uxTxStreamSize = ( size_t ) FreeRTOS_round_up( ipconfigTCP_TX_BUFFER_LENGTH, ipconfigTCP_MSS );
FreeRTOS_debug_printf(("Tx Stream size is %d...\n", pxSocket->u.xTCP.uxTxStreamSize));
/* Use half of the buffer size of the TCP windows */
#if ( ipconfigUSE_TCP_WIN == 1 )
{
Expand Down Expand Up @@ -1207,6 +1210,7 @@ BaseType_t FreeRTOS_bind( Socket_t xSocket,
struct freertos_sockaddr const * pxAddress,
socklen_t xAddressLength )
{
FreeRTOS_debug_printf(("FreeRTOS_bind called\n"));
IPStackEvent_t xBindEvent;
FreeRTOS_Socket_t * pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
BaseType_t xReturn = 0;
Expand Down Expand Up @@ -1507,6 +1511,8 @@ void * vSocketClose( FreeRTOS_Socket_t * pxSocket )
{
NetworkBufferDescriptor_t * pxNetworkBuffer;

FreeRTOS_debug_printf(("vSocketClose called...\n"));

#if ( ipconfigUSE_TCP == 1 )
{
/* For TCP: clean up a little more. */
Expand Down Expand Up @@ -3036,6 +3042,8 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
BaseType_t xResult = -pdFREERTOS_ERRNO_EINVAL;
TimeOut_t xTimeOut;

FreeRTOS_debug_printf(("FreeRTOS_connect called\n"));

( void ) xAddressLength;

xResult = prvTCPConnectStart( pxSocket, pxAddress );
Expand Down Expand Up @@ -3089,7 +3097,10 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
}

/* Go sleeping until we get any down-stream event */
( void ) xEventGroupWaitBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_CONNECT, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime );
( void ) xEventGroupWaitBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_CONNECT /*|
( EventBits_t ) eSOCKET_CLOSED*/, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime );

FreeRTOS_debug_printf(("Waking up from sleep...\n"));
}
}

Expand Down Expand Up @@ -3117,6 +3128,8 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
struct freertos_sockaddr * pxAddress,
socklen_t * pxAddressLength )
{

FreeRTOS_debug_printf(("FreeRTOS_accept called\n"));
FreeRTOS_Socket_t * pxSocket = ( FreeRTOS_Socket_t * ) xServerSocket;
FreeRTOS_Socket_t * pxClientSocket = NULL;
TickType_t xRemainingTime;
Expand Down Expand Up @@ -3617,6 +3630,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
/* While there are still bytes to be sent. */
while( xBytesLeft > 0 )
{

FreeRTOS_debug_printf(("xBytesLeft: %d --- xByteCount: %d\n", xBytesLeft, xByteCount));

/* If txStream has space. */
if( xByteCount > 0 )
{
Expand Down Expand Up @@ -3694,6 +3710,8 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
/* Only in the first round, check for non-blocking. */
xRemainingTime = pxSocket->xSendBlockTime;

FreeRTOS_debug_printf(("xRemainingTime: %d\n", xRemainingTime));

#if ( ipconfigUSE_CALLBACKS != 0 )
{
if( xIsCallingFromIPTask() != pdFALSE )
Expand Down Expand Up @@ -3787,6 +3805,8 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
FreeRTOS_Socket_t * pxSocket;
BaseType_t xResult = 0;

FreeRTOS_debug_printf(("FreeRTOS_listen called\n"));

pxSocket = ( FreeRTOS_Socket_t * ) xSocket;

/* listen() is allowed for a valid TCP socket in Closed state and already
Expand Down Expand Up @@ -4124,8 +4144,12 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
/* And make the length a multiple of sizeof( size_t ). */
uxLength &= ~( sizeof( size_t ) - 1U );

FreeRTOS_debug_printf(("Creating socket stream. uxLength is %d", uxLength));

uxSize = ( sizeof( *pxBuffer ) + uxLength ) - sizeof( pxBuffer->ucArray );

FreeRTOS_debug_printf(("Creating socket stream. uxSize is %d", uxSize));

pxBuffer = ipCAST_PTR_TO_TYPE_PTR( StreamBuffer_t, pvPortMallocLarge( uxSize ) );

if( pxBuffer == NULL )
Expand Down Expand Up @@ -4504,6 +4528,9 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket )
{
xReturn = pdTRUE;
}
/*else {
xReturn = -pdFREERTOS_ERRNO_ETIMEDOUT;
}*/
}
}

Expand Down
19 changes: 19 additions & 0 deletions FreeRTOS_TCP_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
{
/* The API FreeRTOS_send() might have added data to the TX stream. Add
* this data to the windowing system so it can be transmitted. */
FreeRTOS_debug_printf(("Calling prvTCPAddTxData from xTCPSocketCheck...\n"));
prvTCPAddTxData( pxSocket );
}

Expand Down Expand Up @@ -678,6 +679,7 @@
*/
static int32_t prvTCPSendPacket( FreeRTOS_Socket_t * pxSocket )
{
FreeRTOS_debug_printf(("prvTCPSendPacket called...\n"));
int32_t lResult = 0;
UBaseType_t uxOptionsLength, uxIntermediateResult = 0;
NetworkBufferDescriptor_t * pxNetworkBuffer;
Expand Down Expand Up @@ -776,6 +778,7 @@
{
/* prvTCPPrepareSend() might allocate a network buffer if there is data
* to be sent. */
FreeRTOS_debug_printf(("Calling prvTCPPrepareSend from prvTCPSendRepeated...\n"));
xSendLength = prvTCPPrepareSend( pxSocket, ppxNetworkBuffer, uxOptionsLength );

if( xSendLength <= 0 )
Expand Down Expand Up @@ -1624,6 +1627,7 @@
{
/* Just advancing the tail index, 'ulCount' bytes have been confirmed. */
( void ) uxStreamBufferGet( pxSocket->u.xTCP.txStream, 0, NULL, ( size_t ) ulCount, pdFALSE );
FreeRTOS_debug_printf(("eSOCKET_SEND send in prvReadSackOption"));
pxSocket->xEventBits |= ( EventBits_t ) eSOCKET_SEND;

#if ipconfigSUPPORT_SELECT_FUNCTION == 1
Expand Down Expand Up @@ -1916,6 +1920,7 @@
if( ( eTCPState == eCLOSED ) ||
( eTCPState == eCLOSE_WAIT ) )
{
//pxSocket->xEventBits |= ( EventBits_t ) eSOCKET_CLOSED;
/* Socket goes to status eCLOSED because of a RST.
* When nobody owns the socket yet, delete it. */
if( ( pxSocket->u.xTCP.bits.bPassQueued != pdFALSE_UNSIGNED ) ||
Expand Down Expand Up @@ -2127,6 +2132,7 @@
if( pxSocket->u.xTCP.usMSS > 1U )
{
lDataLen = ( int32_t ) ulTCPWindowTxGet( pxTCPWindow, pxSocket->u.xTCP.ulWindowSize, &lStreamPos );
FreeRTOS_debug_printf(("TCP window amount data to be sent: %d...\n", lDataLen));
}

if( lDataLen > 0 )
Expand Down Expand Up @@ -2229,6 +2235,7 @@

if( ( lDataLen == 0 ) && ( pxSocket->u.xTCP.bits.bWinChange == pdFALSE_UNSIGNED ) )
{
FreeRTOS_debug_printf(("pxSocket->u.xTCP.bits.bWinChange == pdFALSE_UNSIGNED"));
/* If there is no data to be sent, and no window-update message,
* we might want to send a keep-alive message. */
TickType_t xAge = xTaskGetTickCount() - pxSocket->u.xTCP.xLastAliveTime;
Expand Down Expand Up @@ -2331,6 +2338,7 @@
/* Let the sliding window mechanism decide what time-out is appropriate. */
BaseType_t xResult = xTCPWindowTxHasData( &pxSocket->u.xTCP.xTCPWindow, pxSocket->u.xTCP.ulWindowSize, &ulDelayMs );

FreeRTOS_debug_printf(("ulDelayMs in prvTCPNextTimeout is %d", ulDelayMs));
if( ulDelayMs == 0U )
{
if( xResult != ( BaseType_t ) 0 )
Expand All @@ -2347,6 +2355,7 @@
/* ulDelayMs contains the time to wait before a re-transmission. */
}


pxSocket->u.xTCP.usTimeout = ( uint16_t ) ipMS_TO_MIN_TICKS( ulDelayMs );
}
else
Expand Down Expand Up @@ -2391,6 +2400,8 @@
( int32_t ) pxSocket->u.xTCP.txStream->uxMid,
( int32_t ) pxSocket->u.xTCP.txStream->LENGTH );

FreeRTOS_debug_printf(("Adding %d to the sliding window...\n", lCount));

/* Move the rxMid pointer forward up to rxHead. */
if( lCount > 0 )
{
Expand Down Expand Up @@ -2918,6 +2929,7 @@
uint32_t ulReceiveLength,
UBaseType_t uxOptionsLength )
{
FreeRTOS_debug_printf(("prvHandleEstablished called...\n"));
/* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */
ProtocolHeaders_t * pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
Expand Down Expand Up @@ -2955,6 +2967,7 @@
/* _HT_ : only in case the socket's waiting? */
if( uxStreamBufferGet( pxSocket->u.xTCP.txStream, 0U, NULL, ( size_t ) ulCount, pdFALSE ) != 0U )
{
FreeRTOS_debug_printf(("eSOCKET_SEND set...\n"));
pxSocket->xEventBits |= ( EventBits_t ) eSOCKET_SEND;

#if ipconfigSUPPORT_SELECT_FUNCTION == 1
Expand Down Expand Up @@ -2991,6 +3004,7 @@

if( ( pxSocket->u.xTCP.bits.bFinAccepted != pdFALSE_UNSIGNED ) || ( ( ucTCPFlags & ( uint8_t ) tcpTCP_FLAG_FIN ) != 0U ) )
{
FreeRTOS_debug_printf(("FIN flag is set...\n"));
/* Peer is requesting to stop, see if we're really finished. */
xMayClose = pdTRUE;

Expand Down Expand Up @@ -3039,6 +3053,7 @@

if( xMayClose != pdFALSE )
{
FreeRTOS_debug_printf(("Calling prvTCPHandleFin from prvHandleEstablished"));
pxSocket->u.xTCP.bits.bFinAccepted = pdTRUE_UNSIGNED;
xSendLength = prvTCPHandleFin( pxSocket, *ppxNetworkBuffer );
}
Expand Down Expand Up @@ -3266,6 +3281,7 @@
static BaseType_t prvTCPHandleState( FreeRTOS_Socket_t * pxSocket,
NetworkBufferDescriptor_t ** ppxNetworkBuffer )
{
FreeRTOS_debug_printf(("prvTCPHandleState called...\n"));
/* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */
ProtocolHeaders_t * pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) );
Expand Down Expand Up @@ -3401,6 +3417,7 @@
* state for the data transfer phase of the connection
* The closing states are also handled here with the
* use of some flags. */
FreeRTOS_debug_printf(("eESTABLISHED reached...\n"));
xSendLength = prvHandleEstablished( pxSocket, ppxNetworkBuffer, ulReceiveLength, uxOptionsLength );
break;

Expand Down Expand Up @@ -3446,6 +3463,7 @@

if( xSendLength > 0 )
{
FreeRTOS_debug_printf(("prvSendData called..\n"));
xSendLength = prvSendData( pxSocket, ppxNetworkBuffer, ulReceiveLength, xSendLength );
}

Expand Down Expand Up @@ -3777,6 +3795,7 @@

/* In prvTCPHandleState() the incoming messages will be handled
* depending on the current state of the connection. */
FreeRTOS_debug_printf(("prvTCPHandleState called from xProcessReceivedTCPPacket...\n"));
if( prvTCPHandleState( pxSocket, &pxNetworkBuffer ) > 0 )
{
/* prvTCPHandleState() has sent a message, see if there are more to
Expand Down