void showTTCPstatus() { printk("IF status: %s\n", (ifStatus) ? "UP":"DOWN"); printk("CONN status: %s\n", (_connected) ? "UP":"DOWN"); int i = 0; for (; i<MAX_SOCK_NUM; i++) { void* p = getTTCP(i); if (p) { ttcp_t* _ttcp = (ttcp_t* )p; printk("Socket n.:%d addr:0x%x port:%d\n", i, _ttcp->addr, _ttcp->port); if (_ttcp->tpcb){ printk("[tpcp-%p]-Status:%d\n", _ttcp->tpcb, _ttcp->tpcb->state); } if (_ttcp->lpcb){ printk("[tlcp-%p]-Status:%d\n", _ttcp->lpcb, _ttcp->lpcb->state); } ard_tcp_print_stats(_ttcp); } } tcp_debug_print_pcbs(); }
void closeConnections() { int i = 0; for (; i<MAX_SOCK_NUM; i++) { void* p = getTTCP(i); if (p) { ttcp_t* _ttcp = (ttcp_t* )p; INFO_TCP("Closing connections tpcb[%p] state:0x%x - lpcb[%p] state: 0x%x\n", _ttcp->tpcb, _ttcp->tpcb->state, _ttcp->lpcb, _ttcp->lpcb->state); //tcp_close(_ttcp->tpcb); ard_tcp_destroy(_ttcp); clearMapSockTcp(getSock(_ttcp)); } } }
uint8_t* insertBuf(uint8_t sock, uint8_t* buf, uint16_t len) { DUMP(buf,len); if (sock>= MAX_SOCK_NUM) { WARN("Sock out of range: sock=%d", sock); return NULL; } if (pBufStore[headBuf[sock]][sock].data != NULL) { WARN("Overwriting buffer %p idx:%d!\n", pBufStore[headBuf[sock]][sock].data, headBuf[sock]); // to avoid memory leak free the oldest buffer freetDataIdx(headBuf[sock], sock); } u8_t* p = (u8_t*)calloc(len,sizeof(u8_t)); if(p != NULL) { memcpy(p, buf, len); pBufStore[headBuf[sock]][sock].data = p; pBufStore[headBuf[sock]][sock].len = len; pBufStore[headBuf[sock]][sock].idx = 0; pBufStore[headBuf[sock]][sock].pcb = getTTCP(sock, TTCP_MODE_TRANSMIT); headBuf[sock]++; if (headBuf[sock] == MAX_PBUF_STORED) headBuf[sock] = 0; if (headBuf[sock] == tailBuf[sock]) { WARN("Avoid to Overwrite data [%d-%d]!\n", headBuf[sock], tailBuf[sock]); if (headBuf[sock] != 0) --headBuf[sock]; else headBuf[sock] = MAX_PBUF_STORED-1; } INFO_UTIL("Insert[%d]: %p:%d-%d [%d,%d]\n", sock, p, len, p[0], headBuf[sock], tailBuf[sock]); } return p; }