A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Sun Nov 11 15:44:23 2018 +0000
Revision:
79:f50e02fb5c94
Parent:
78:9d8fc88df405
Child:
80:4ef1500fca1d
Added RTO support to TCP and fixed a problem with polling of different IP versions.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 61:aad055f1b0d1 1 #include <stdint.h>
andrewboyson 61:aad055f1b0d1 2
andrewboyson 66:18a10c0b6d93 3 #include "log.h"
andrewboyson 66:18a10c0b6d93 4 #include "tcp.h"
andrewboyson 66:18a10c0b6d93 5 #include "tcb.h"
andrewboyson 66:18a10c0b6d93 6 #include "clock.h"
andrewboyson 52:fbc5a46b5e16 7
andrewboyson 10:f0854784e960 8 #define TCB_COUNT 10
andrewboyson 10:f0854784e960 9
andrewboyson 10:f0854784e960 10 struct tcb tcbs[TCB_COUNT];
andrewboyson 10:f0854784e960 11
andrewboyson 10:f0854784e960 12 uint32_t TcbGetIsn()
andrewboyson 10:f0854784e960 13 {
andrewboyson 10:f0854784e960 14 static uint32_t isn = 0;
andrewboyson 10:f0854784e960 15 isn += 100000; //Gives each tcb 100,000 packets and won't repeat before 42,940 tcbs.
andrewboyson 10:f0854784e960 16 return isn;
andrewboyson 10:f0854784e960 17 }
andrewboyson 78:9d8fc88df405 18 struct tcb* TcbGetExisting(int ipType, int remArIndex, uint16_t port)
andrewboyson 10:f0854784e960 19 {
andrewboyson 10:f0854784e960 20 for (int i = 0; i < TCB_COUNT; i++)
andrewboyson 10:f0854784e960 21 {
andrewboyson 10:f0854784e960 22 struct tcb* pTcb = tcbs + i;
andrewboyson 78:9d8fc88df405 23 if (pTcb->state &&
andrewboyson 78:9d8fc88df405 24 pTcb->ipType == ipType &&
andrewboyson 78:9d8fc88df405 25 pTcb->remArIndex == remArIndex &&
andrewboyson 78:9d8fc88df405 26 pTcb->remPort == port) return pTcb;
andrewboyson 10:f0854784e960 27 }
andrewboyson 10:f0854784e960 28 return NULL;
andrewboyson 10:f0854784e960 29 }
andrewboyson 10:f0854784e960 30 struct tcb* TcbGetEmpty()
andrewboyson 10:f0854784e960 31 {
andrewboyson 10:f0854784e960 32 for (int i = 0; i < TCB_COUNT; i++)
andrewboyson 10:f0854784e960 33 {
andrewboyson 10:f0854784e960 34 struct tcb* pTcb = tcbs + i;
andrewboyson 57:e0fb648acf48 35 if (pTcb->state == TCB_EMPTY) return pTcb;
andrewboyson 10:f0854784e960 36 }
andrewboyson 10:f0854784e960 37 return NULL;
andrewboyson 10:f0854784e960 38 }
andrewboyson 78:9d8fc88df405 39 void TcbGetNext(struct tcb** ppTcb)
andrewboyson 74:c3756bfa960e 40 {
andrewboyson 78:9d8fc88df405 41 if (!*ppTcb) //Initialise if passed NULL
andrewboyson 78:9d8fc88df405 42 {
andrewboyson 78:9d8fc88df405 43 *ppTcb = tcbs;
andrewboyson 78:9d8fc88df405 44 return;
andrewboyson 78:9d8fc88df405 45 }
andrewboyson 78:9d8fc88df405 46 ++*ppTcb; //Increment
andrewboyson 78:9d8fc88df405 47 if (*ppTcb >= tcbs + TCB_COUNT) *ppTcb = tcbs;
andrewboyson 74:c3756bfa960e 48 }
andrewboyson 10:f0854784e960 49
andrewboyson 52:fbc5a46b5e16 50 uint32_t TcbElapsed = 0;
andrewboyson 52:fbc5a46b5e16 51
andrewboyson 52:fbc5a46b5e16 52 void TcbMain()
andrewboyson 52:fbc5a46b5e16 53 {
andrewboyson 66:18a10c0b6d93 54 if (ClockTicked) TcbElapsed++;
andrewboyson 10:f0854784e960 55 }
andrewboyson 10:f0854784e960 56 void TcbInit()
andrewboyson 10:f0854784e960 57 {
andrewboyson 57:e0fb648acf48 58 for (int i = 0; i < TCB_COUNT; i++) tcbs[i].state = TCB_EMPTY;
andrewboyson 52:fbc5a46b5e16 59 }