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
tcp/tcb.c@156:be12b8fd5b21, 2019-08-28 (annotated)
- Committer:
- andrewboyson
- Date:
- Wed Aug 28 07:11:58 2019 +0000
- Revision:
- 156:be12b8fd5b21
- Parent:
- 93:580fc113d9e9
- Child:
- 161:89609cf070b4
Update HttpShim to pass connection status
Who changed what in which revision?
User | Revision | Line number | New 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 | 52:fbc5a46b5e16 | 6 | |
andrewboyson | 88:1ba13e6062a3 | 7 | #define TCB_COUNT 20 |
andrewboyson | 10:f0854784e960 | 8 | |
andrewboyson | 10:f0854784e960 | 9 | struct tcb tcbs[TCB_COUNT]; |
andrewboyson | 10:f0854784e960 | 10 | |
andrewboyson | 10:f0854784e960 | 11 | uint32_t TcbGetIsn() |
andrewboyson | 10:f0854784e960 | 12 | { |
andrewboyson | 10:f0854784e960 | 13 | static uint32_t isn = 0; |
andrewboyson | 10:f0854784e960 | 14 | isn += 100000; //Gives each tcb 100,000 packets and won't repeat before 42,940 tcbs. |
andrewboyson | 10:f0854784e960 | 15 | return isn; |
andrewboyson | 10:f0854784e960 | 16 | } |
andrewboyson | 80:4ef1500fca1d | 17 | struct tcb* TcbGetExisting(int ipType, int remArIndex, int locIpScope, uint16_t remPort, uint16_t locPort) |
andrewboyson | 10:f0854784e960 | 18 | { |
andrewboyson | 10:f0854784e960 | 19 | for (int i = 0; i < TCB_COUNT; i++) |
andrewboyson | 10:f0854784e960 | 20 | { |
andrewboyson | 10:f0854784e960 | 21 | struct tcb* pTcb = tcbs + i; |
andrewboyson | 78:9d8fc88df405 | 22 | if (pTcb->state && |
andrewboyson | 78:9d8fc88df405 | 23 | pTcb->ipType == ipType && |
andrewboyson | 78:9d8fc88df405 | 24 | pTcb->remArIndex == remArIndex && |
andrewboyson | 80:4ef1500fca1d | 25 | pTcb->locIpScope == locIpScope && |
andrewboyson | 80:4ef1500fca1d | 26 | pTcb->remPort == remPort && |
andrewboyson | 80:4ef1500fca1d | 27 | pTcb->locPort == locPort) return pTcb; |
andrewboyson | 10:f0854784e960 | 28 | } |
andrewboyson | 10:f0854784e960 | 29 | return NULL; |
andrewboyson | 10:f0854784e960 | 30 | } |
andrewboyson | 10:f0854784e960 | 31 | struct tcb* TcbGetEmpty() |
andrewboyson | 10:f0854784e960 | 32 | { |
andrewboyson | 10:f0854784e960 | 33 | for (int i = 0; i < TCB_COUNT; i++) |
andrewboyson | 10:f0854784e960 | 34 | { |
andrewboyson | 10:f0854784e960 | 35 | struct tcb* pTcb = tcbs + i; |
andrewboyson | 57:e0fb648acf48 | 36 | if (pTcb->state == TCB_EMPTY) return pTcb; |
andrewboyson | 10:f0854784e960 | 37 | } |
andrewboyson | 10:f0854784e960 | 38 | return NULL; |
andrewboyson | 10:f0854784e960 | 39 | } |
andrewboyson | 83:08c983006a6e | 40 | struct tcb* TcbGetNext(struct tcb* pTcb) |
andrewboyson | 74:c3756bfa960e | 41 | { |
andrewboyson | 83:08c983006a6e | 42 | if (!pTcb) return tcbs; //Initialise if passed NULL |
andrewboyson | 83:08c983006a6e | 43 | ++pTcb; //Increment |
andrewboyson | 83:08c983006a6e | 44 | if (pTcb < tcbs + TCB_COUNT) return pTcb; |
andrewboyson | 83:08c983006a6e | 45 | else return tcbs; |
andrewboyson | 83:08c983006a6e | 46 | |
andrewboyson | 74:c3756bfa960e | 47 | } |
andrewboyson | 156:be12b8fd5b21 | 48 | int TcbGetId(struct tcb* pTcb) //0 means none |
andrewboyson | 156:be12b8fd5b21 | 49 | { |
andrewboyson | 156:be12b8fd5b21 | 50 | return pTcb - tcbs + 1; |
andrewboyson | 156:be12b8fd5b21 | 51 | } |
andrewboyson | 10:f0854784e960 | 52 | void TcbInit() |
andrewboyson | 10:f0854784e960 | 53 | { |
andrewboyson | 57:e0fb648acf48 | 54 | for (int i = 0; i < TCB_COUNT; i++) tcbs[i].state = TCB_EMPTY; |
andrewboyson | 52:fbc5a46b5e16 | 55 | } |