aboutsummaryrefslogtreecommitdiff
path: root/firmwares/wifishield/wifiHD/src/ard_tcp.h
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2013-03-28 12:27:11 +0100
committerCristian Maglie <c.maglie@bug.st>2013-03-28 12:27:11 +0100
commitc6dcde62afdfa6b90d7427fa1e6ecbac51c35a05 (patch)
tree372eec1b28967be869e8f3b9dcfd305d0bfc80b2 /firmwares/wifishield/wifiHD/src/ard_tcp.h
parentf567db75733f539bf064b7ca639f52e823823c06 (diff)
parent802eaa96c74918255dcca264e9f0ca39885d1090 (diff)
Merge branch 'wifishield-bugfix'
Diffstat (limited to 'firmwares/wifishield/wifiHD/src/ard_tcp.h')
-rw-r--r--firmwares/wifishield/wifiHD/src/ard_tcp.h61
1 files changed, 57 insertions, 4 deletions
diff --git a/firmwares/wifishield/wifiHD/src/ard_tcp.h b/firmwares/wifishield/wifiHD/src/ard_tcp.h
index 010b976..078e0b0 100644
--- a/firmwares/wifishield/wifiHD/src/ard_tcp.h
+++ b/firmwares/wifishield/wifiHD/src/ard_tcp.h
@@ -15,6 +15,41 @@ typedef void (ard_tcp_done_cb_t)(void *opaque, int result);
#define TTCP_MODE_TRANSMIT 0
#define TTCP_MODE_RECEIVE 1
+#define MAX_MODE_NUM 2
+
+#define GET_TCP_MODE(X) ((X!=NULL)?((struct ttcp*)(X))->mode:0)
+#define IS_VALID_SOCK(SOCK) ((SOCK>=0)&&(SOCK<MAX_SOCK_NUM))
+#define IS_UDP_SOCK(SOCK) ((getTTCP(SOCK, TTCP_MODE_RECEIVE)!=NULL)?((struct ttcp*)(getTTCP(SOCK, TTCP_MODE_RECEIVE)))->udp:0)
+
+// Maximum number of client connection accepted by server
+#define MAX_CLIENT_ACCEPTED 4
+#define NO_VALID_ID 0xff
+
+#define GET_FIRST_CLIENT_TCP(TTCP) getFirstClient(TTCP, 1)
+#define GET_FIRST_CLIENT_TCP_NV(TTCP) getFirstClient(TTCP, 0)
+#define GET_CLIENT_TCP(TTCP,ID) (((TTCP!=NULL)&&(ID>=0)&&(ID<MAX_CLIENT_ACCEPTED))?TTCP->tpcb[ID] : NULL)
+#define GET_CLIENT_ID(TTCP, PCB) uint8_t id = NO_VALID_ID; do { \
+ id = getNewClientConnId(TTCP, PCB); \
+ if (id == NO_VALID_ID) return ERR_MEM; \
+ }while(0);
+#define GET_IDX_CONN(I) ((I+currConnId)<MAX_CLIENT_ACCEPTED ? (I+currConnId) : (I+currConnId-MAX_CLIENT_ACCEPTED))
+#define GET_CURR_PCB(TTCP) GET_CLIENT_TCP(TTCP,getCurrClientConnId())
+
+#define FREE_PAYLOAD(TTCP) do { \
+ int id = getCurrClientConnId(); \
+ INFO_TCP("Freeing payload %d-%p\n", id, TTCP->payload[id]); \
+ if (TTCP->payload[id]) { \
+ free(TTCP->payload[id]); \
+ TTCP->payload[id] = NULL; } \
+}while(0);
+
+#define FREE_PAYLOAD_ID(TTCP,ID) do { \
+ INFO_TCP("Freeing payload %d-%p\n", ID, TTCP->payload[ID]); \
+ if (TTCP->payload[ID]) { \
+ free(TTCP->payload[ID]); \
+ TTCP->payload[ID] = NULL; } \
+}while(0);
+
typedef struct ttcp {
@@ -26,12 +61,12 @@ typedef struct ttcp {
int verbose; /* -v */
int udp; /* -u */
uint8_t sock;
- uint8_t buff_sent;
+ uint8_t buff_sent[MAX_CLIENT_ACCEPTED];
/* common */
uint16_t print_cnt;
uint32_t start_time;
- uint32_t left;
+ uint32_t left[MAX_CLIENT_ACCEPTED];
uint32_t recved;
ard_tcp_done_cb_t* done_cb;
void* opaque;
@@ -39,9 +74,11 @@ typedef struct ttcp {
uint32_t tid;
/* TCP specific */
- struct tcp_pcb* tpcb;
+ struct tcp_pcb* tpcb[MAX_CLIENT_ACCEPTED];
struct tcp_pcb* lpcb;
- char* payload;
+ char* payload[MAX_CLIENT_ACCEPTED];
+ uint8_t tcp_poll_retries[MAX_CLIENT_ACCEPTED];
+ bool pending_close[MAX_CLIENT_ACCEPTED];
/* UDP specific */
int udp_started;
@@ -62,10 +99,26 @@ uint8_t getModeTcp(void* p);
int sendTcpData(void* p, uint8_t* buf, uint16_t len);
+int sendUdpData(void* p, uint8_t* buf, uint16_t len);
+
uint8_t isDataSent(void* p );
cmd_state_t cmd_ttcp(int argc, char* argv[], void* ctx);
+int8_t setNewClientConn(struct ttcp* _ttcp, struct tcp_pcb *newpcb, uint8_t id);
+
+int8_t insertNewClientConn(struct ttcp* _ttcp, struct tcp_pcb *newpcb);
+
+int8_t removeNewClientConn(struct ttcp* _ttcp, struct tcp_pcb *newpcb);
+
+bool cleanNewClientConn(struct ttcp* _ttcp);
+
+int8_t getNewClientConnId(struct ttcp* _ttcp, struct tcp_pcb *newpcb);
+
+int8_t getCurrClientConnId();
+
+struct tcp_pcb * getFirstClient(struct ttcp* _ttcp, bool verbose);
+
void closeConnections();
#endif