Andrew Boyson / net

Dependents:   oldheating gps motorhome heating

tcp/tcb.h

Committer:
andrewboyson
Date:
2019-02-25
Revision:
126:62edacc9f14d
Parent:
93:580fc113d9e9
Child:
131:774f7f367031

File content as of revision 126:62edacc9f14d:

#ifndef TCB_H
#define TCB_H

#include <stdint.h>
#include <stdbool.h>

#define TCB_EMPTY          0
#define TCB_SYN_RECEIVED   1
#define TCB_ESTABLISHED    2
#define TCB_CLOSE_FIN_WAIT 3

struct tcb
{
    int      state;
    uint32_t timeSendsBeingAcked; //Used for RTO
    int      countSendsNotAcked;  //Used for RTO
    uint32_t timeLastRcvd;        //Used for detect idle links
    int      ipType;
    int      remArIndex;          //Unique per remote ip when taken with the ipType
    int      locIpScope;          //Unique per local ip
    uint16_t remPort;
    uint16_t locPort;
    uint32_t remMss;
    uint32_t window;
    
    uint32_t remIsn;
    uint32_t bytesRcvdFromRem;
    uint32_t bytesAckdToRem;
    bool     rcvdFin;
    
    uint32_t locIsn;
    uint32_t bytesSentToRem;
    uint32_t bytesAckdByRem;
    bool     sentFin;
    
    /*
    Communicates between application (HTTP) and TCP.
    Application usually works out what to do from the first packet and so it stores that in todo to remember what it is doing for subsequent packets.
    Once all packets have been received the application sets postCompleted to indicate that TCP should start sending data.
    Once all packets have been sent the application returns a data size less than MSS.
    Note that TCP needs to keep todo in case data has to be resent after the application thinks it has finished.
    */
     int32_t todo;
     bool    postComplete;
};

extern uint32_t    TcbGetIsn(void);
extern struct tcb* TcbGetExisting(int ipType, int remArIndex, int locIpScope, uint16_t remPort, uint16_t locPort);
extern struct tcb* TcbGetEmpty(void);
extern struct tcb* TcbGetNext(struct tcb* pTcb);
extern void        TcbInit(void);

#endif