This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Questin: Some Problem for Server Side using CMSIS-Driver/WIFI/ESP and WizFi Driver

Confused by some problem,
Looking into 2 Case study in ESP serires and WizFi360's CMSIS_DRIVER WIFI Driver (WiFi_WizFi360.c and WiFi_ESPxxxx.c)

1st is at AT_Notify(): updating link_id and SOCKET_STATE_CONNECTED by response for <link_id>,CONNECT
2nd is that 1st affect ARM_WIFI_SocketAccept()'s data updating.

Conditions:

Case 1: One Client Connected
0,CONNECT --->(discription: <link_id>,CONNECT)
AT+CIPSTATUS
STATUS:5
+CIPSTATUS:0,"TCP","192.168.36.2",58428,6000,1
has not a problme

Case 2: 2nd Client Connected
1,CONNECT
AT+CIPSTATUS
STATUS:5
+CIPSTATUS:0,"TCP","192.168.36.2",58428,6000,1\r\n
+CIPSTATUS:1,"TCP","192.168.36.3",55362,6000,1\r\n
has some problem

Details:

1. When 1st Client CONNECTs Server, AT_Notify() under 292 line code is not a problem.
But when 2nd Client CONNECTs Server in case that 1st Client is CONNECTED state
<refer to 292 line>
if (Socket[n].state == SOCKET_STATE_SERVER)
{
    Socket[n].conn_id = conn.link_id;
    Socket[n].state = SOCKET_STATE_CONNECTED;
}

1st client state can be updated to SOCKET_STATE_CONNECTED and Socket[n].conn_id = conn.link_id;
but 2nd client state can not be update to SOCKET_STATE_CONNECTED and Socket[n].conn_id = conn.link_id;

2. Socket's backlog is only updated under 2580 line, when ARM_WIFI_SocketAccept() is called.
and because of ARM_WIFI_SocketAccept()'s
2554 line: if (conn.link_id == Socket[n].conn_id) conditions,

the data below lines can not be updated.
/* Copy remote ip */
memcpy (Socket[n].r_ip, conn.remote_ip, 4);
/* Set remote port */
Socket[n].r_port = conn.remote_port;
/* Set local port */
Socket[n].l_port = conn.local_port;

3. To use static int32_t ARM_WIFI_SocketAccept (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
Assuming that Server application use max. 4 connection, does Server application have alway to iterate and check 4 socket, to update Socekt's data and state
example:
for (i=1 ; i<5; i++) //because 0 is server
ARM_WIFI_SocketAccept (i, , , )

This question's reason is
ARM_WIFI_SocketAccept()
{

2551 line: sock = &Socket[socket];
2534 line: n = sock->backlog;
}
"n" is dependent on ARM_WIFI_SocketAccept()'s input argument socket and backlog is updated 2580 lin


4. Can you explain or illustrate how to use "backlog"

Refer to your own code below----------------------------------------------------------------------

AT_Notify()
{


292 line start:

    else {
      /* Check server sockets and put connection on the backlog */
      for (n = 0U; n < WIFI_SOCKET_NUM; n++) {
        if (Socket[n].state == SOCKET_STATE_SERVER) {
            /* Set pointer to server socket */
            sock = &Socket[n];
                /* Find available backlog socket */
                do {
                   n = Socket[n].backlog;

                  if (Socket[n].state == SOCKET_STATE_LISTEN) {
                      /* Set connection id and change state */
                      Socket[n].conn_id = conn.link_id;
                      Socket[n].state = SOCKET_STATE_CONNECTED;
                      break;
                   }
                }
                while (Socket[n].backlog != sock->backlog);
                break;
            }
        }

        if (n != WIFI_SOCKET_NUM) {
            /* Set event */
            osEventFlagsSet (pCtrl->evflags_id, WIFI_WAIT_CONN_ACCEPT);
        }
    }

324 line end:

}


static int32_t ARM_WIFI_SocketAccept()
{

2440 line start:

    ex = AT_Cmd_GetStatus (AT_CMODE_EXEC);

    if (ex == 0) {
    /* Wait until response arrives */
    ex = WiFi_Wait (WIFI_WAIT_RESP_GENERIC, WIFI_RESP_TIMEOUT);

        if (ex == 0) {
        /* Check response */
            do {
                /* Response arrived */
                ex = AT_Resp_GetStatus (&conn);

                if (ex >= 0) {
                    /* Check if structure contains information relevant for current link id */
                    if (conn.link_id == Socket[n].conn_id) {
                    /* Copy remote ip */
                    memcpy (Socket[n].r_ip, conn.remote_ip, 4);
                    /* Set remote port */
                    Socket[n].r_port = conn.remote_port;
                    /* Set local port */
                    Socket[n].l_port = conn.local_port;
                }
            }
        }    
        while (ex > 0);
    }
}

2566 line end:


2580 line start:

/* Return socket number */
rval = n;

/* Update backlog, put current socket to the end of list */
while (Socket[n].backlog != sock->backlog) {
    n = Socket[n].backlog;
}
Socket[n].backlog = (uint8_t)rval;
Socket[rval].backlog = sock->backlog;

2588 line end:


2622 line:
return (rval);
}