static CellularPktStatus_t _parseSocketOpenNextTok()

in sim70x0/cellular_sim70x0_urc_handler.c [91:175]


static CellularPktStatus_t _parseSocketOpenNextTok( const char * pToken,
                                                    uint32_t sockIndex,
                                                    CellularSocketContext_t * pSocketData )
{
    /* Handling: CAOPEN: <link-num>,<err> */
    int32_t sockStatus = 0;
    CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
    CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;

    atCoreStatus = Cellular_ATStrtoi( pToken, 10, &sockStatus );

    if( atCoreStatus == CELLULAR_AT_SUCCESS )
    {
        if( sockStatus != 0 )
        {
            const struct
            {
                uint8_t nErr;
                const char * sErr;
            }
            err_tb[] =
            {
                { 0,  "Success"                                                    },
                { 1,  "Socket error"                                               },
                { 2,  "No memory"                                                  },
                { 3,  "Connection limit"                                           },
                { 4,  "Parameter invalid"                                          },
                { 6,  "Invalid IP address"                                         },
                { 7,  "Not support the function"                                   },
                { 12, "Can�ft bind the port"                                       },
                { 13, "Can�ft listen the port"                                     },
                { 20, "Can�ft resolv the host"                                     },
                { 21, "Network not active"                                         },
                { 23, "Remote refuse"                                              },
                { 24, "Certificate�fs time expired"                                },
                { 25, "Certificate�fs common name does not match"                  },
                { 26, "Certificate�fs common name does not match and time expired" },
                { 27, "Connect failed"                                             },
            };

            const char * sErr = "unknown error";
            int i;

            pSocketData->socketState = SOCKETSTATE_DISCONNECTED;

            for( i = 0; i < sizeof( err_tb ) / sizeof( err_tb[ 0 ] ); i++ )
            {
                if( ( int32_t ) err_tb[ i ].nErr == sockStatus )
                {
                    sErr = err_tb[ i ].sErr;
                    break;
                }
            }

            LogError( ( "_parseSocketOpen: id=%d, status: [%d] %s", sockIndex, sockStatus, sErr ) );
        }
        else
        {
            pSocketData->socketState = SOCKETSTATE_CONNECTED;
            LogDebug( ( "_parseSocketOpen: Socket open success, conn %d", sockIndex ) );
        }

        /* Indicate the upper layer about the socket open status. */
        if( pSocketData->openCallback != NULL )
        {
            if( sockStatus != 0 )
            {
                pSocketData->openCallback( CELLULAR_URC_SOCKET_OPEN_FAILED,
                                           pSocketData, pSocketData->pOpenCallbackContext );
            }
            else
            {
                pSocketData->openCallback( CELLULAR_URC_SOCKET_OPENED,
                                           pSocketData, pSocketData->pOpenCallbackContext );
            }
        }
        else
        {
            LogError( ( "_parseSocketOpen: Socket open callback for conn %d is not set!!", sockIndex ) );
        }
    }

    pktStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus );
    return pktStatus;
}