Hi Ron,
The issues that i’m facing are how to integrate my tcp callback functions with my mbed callback functions.
I’m still at beginning stage of this but I have written my functions as this
static int netSend(void *ctx, const unsigned char *buf, size_t len)
{
int ret;
int sd;
err_t eError;
eError = tcp_write(mypcb, buf, len,
TCP_WRITE_FLAG_COPY);
//
// Write data for sending (but does not send it immediately).
//
if(eError == ERR_OK)
{
//
// Find out what we can send and send it
//
tcp_output(mypcb);
}
return (len);
}
static int netRecv(void *ctx, unsigned char *buf, size_t len)
{
struct tcp_pcb *conn = (struct tcp_pcb *)ctx;
struct pbuf *p;
uint16_t ret;
uint16_t copy_len;
err_t err;
p = (struct pbuf *)buf;
/* limit number of bytes again to copy from first pbuf in a chain only /
copy_len = (uint16_t)LWIP_MIN(len, p->len);
/ copy the data /
ret = pbuf_copy_partial(p, buf, copy_len, 0);
LWIP_ASSERT(“ret == copy_len”, ret == copy_len);
/ hide the copied bytes from the pbuf */
err = pbuf_header(p, -ret);
LWIP_ASSERT(“error”, err == ERR_OK);
pbuf_free(p);
return ret;
}
static err_t
TCPReceive(void *pvArg, struct tcp_pcb *psPcb, struct pbuf *psBuf, err_t iErr)
{
while (psBuf->tot_len > 0) {
uint16_t recvd_part = (uint16_t)LWIP_MIN(psBuf->tot_len, 0xFFFF);
tcp_recved(psPcb, recvd_part);
psBuf->tot_len -= recvd_part;
}
return (ERR_OK);
}
static err_t
TCPSent(void *pvArg, struct tcp_pcb *psPcb, uint16_t ui16Len)
{
return(ERR_OK);
}
Am I going in correct direction or is it something that I’m missing?
When I do the SSL handshake the call flow is like this
netSend → TCPSent → TCPReceive → netRecv
then it goes into fault.
Any idea what needs to be changed or whats wrong in this code?
Regards,
Deepak