コード例 #1
0
/*************************************************
* Function: PCT_SendMsgToCloud
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
u32 PCT_SendMsgToCloud(ZC_SecHead *pstruSecHead, u8 *pu8PlainData)
{
    u32 u32Index;
    u32 u32RetVal;
    u16 u16Len;
    u16 u16PaddingLen;
    
    u32RetVal = SEC_PaddingCheck(pstruSecHead->u8SecType, ZC_HTONS(pstruSecHead->u16TotalMsg), &u16PaddingLen);
    
    if (ZC_RET_ERROR == u32RetVal)
    {
        return ZC_RET_ERROR;
    }

    u16Len = ZC_HTONS(pstruSecHead->u16TotalMsg) + sizeof(ZC_SecHead) + u16PaddingLen;    
    
    if (u16Len > MSG_BUFFER_MAXLEN)
    {
        return ZC_RET_ERROR;
    }

    for (u32Index = 0; u32Index < MSG_BUFFER_SEND_MAX_NUM; u32Index++)
    {
        if (MSG_BUFFER_IDLE == g_struSendBuffer[u32Index].u8Status)
        {
            u16Len = ZC_HTONS(pstruSecHead->u16TotalMsg) + u16PaddingLen;

            /*first check padding,then Encrypt, final copy sechead*/
            u32RetVal = SEC_Encrypt(pstruSecHead, g_struSendBuffer[u32Index].u8MsgBuffer + sizeof(ZC_SecHead), pu8PlainData, &u16Len);
            
            if (ZC_RET_ERROR == u32RetVal)
            {
                return ZC_RET_ERROR;
            }
            
            pstruSecHead->u16TotalMsg = ZC_HTONS(u16Len);
            /*copy sechead*/
            memcpy(g_struSendBuffer[u32Index].u8MsgBuffer, (u8*)pstruSecHead, sizeof(ZC_SecHead));
        
            g_struSendBuffer[u32Index].u32Len = u16Len + sizeof(ZC_SecHead);
            g_struSendBuffer[u32Index].u8Status = MSG_BUFFER_FULL;
            MSG_PushMsg(&g_struSendQueue, (u8*)&g_struSendBuffer[u32Index]);

            return ZC_RET_OK;
        }
    }

    return ZC_RET_ERROR;
}
コード例 #2
0
/*************************************************
* Function: PCT_SendMsgToCloud
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
u32 PCT_SendMsgToCloud(ZC_SecHead *pstruSecHead, u8 *pu8PlainData)
{
    //u32 u32Index;
    u32 u32RetVal;
    u16 u16Len;
    u16 u16PaddingLen;
    ZC_SendParam struParam;
    u32RetVal = SEC_PaddingCheck(pstruSecHead->u8SecType, ZC_HTONS(pstruSecHead->u16TotalMsg), &u16PaddingLen);
    
    if (ZC_RET_ERROR == u32RetVal)
    {
        return ZC_RET_ERROR;
    }

    u16Len = ZC_HTONS(pstruSecHead->u16TotalMsg) + sizeof(ZC_SecHead) + u16PaddingLen;    
    
    if (u16Len > MSG_BUFFER_MAXLEN)
    {
        return ZC_RET_ERROR;
    }
    
#if 1
    if (MSG_BUFFER_IDLE == g_struSendBuffer[0].u8Status)
    {
        u16Len = ZC_HTONS(pstruSecHead->u16TotalMsg) + u16PaddingLen;

        /*first check padding,then Encrypt, final copy sechead*/
        u32RetVal = SEC_Encrypt(pstruSecHead, g_struSendBuffer[0].u8MsgBuffer + sizeof(ZC_SecHead), pu8PlainData, &u16Len);
        
        if (ZC_RET_ERROR == u32RetVal)
        {
            return ZC_RET_ERROR;
        }
        
        pstruSecHead->u16TotalMsg = ZC_HTONS(u16Len);
        /*copy sechead*/
        memcpy(g_struSendBuffer[0].u8MsgBuffer, (u8*)pstruSecHead, sizeof(ZC_SecHead));
    
        g_struSendBuffer[0].u32Len = u16Len + sizeof(ZC_SecHead);
        g_struSendBuffer[0].u8Status = MSG_BUFFER_FULL;
        //MSG_PushMsg(&g_struSendQueue, (u8*)&g_struSendBuffer[0]);
        /* ·¢ËÍ */
        struParam.u8NeedPoll = 0;
        g_struProtocolController.pstruMoudleFun->pfunSendTcpData(g_struProtocolController.struCloudConnection.u32Socket,
                                                                    g_struSendBuffer[0].u8MsgBuffer, 
                                                                    g_struSendBuffer[0].u32Len,
                                                                    &struParam);
     
        //ZC_Printf("send data len = %d\n", u16DataLen);  
        g_struSendBuffer[0].u8Status = MSG_BUFFER_IDLE;
        g_struSendBuffer[0].u32Len = 0;
        return ZC_RET_OK;
    }

#else
    for (u32Index = 0; u32Index < MSG_BUFFER_SEND_MAX_NUM; u32Index++)
    {
        if (MSG_BUFFER_IDLE == g_struSendBuffer[u32Index].u8Status)
        {
            u16Len = ZC_HTONS(pstruSecHead->u16TotalMsg) + u16PaddingLen;

            /*first check padding,then Encrypt, final copy sechead*/
            u32RetVal = SEC_Encrypt(pstruSecHead, g_struSendBuffer[u32Index].u8MsgBuffer + sizeof(ZC_SecHead), pu8PlainData, &u16Len);
            
            if (ZC_RET_ERROR == u32RetVal)
            {
                return ZC_RET_ERROR;
            }
            
            pstruSecHead->u16TotalMsg = ZC_HTONS(u16Len);
            /*copy sechead*/
            memcpy(g_struSendBuffer[u32Index].u8MsgBuffer, (u8*)pstruSecHead, sizeof(ZC_SecHead));
        
            g_struSendBuffer[u32Index].u32Len = u16Len + sizeof(ZC_SecHead);
            g_struSendBuffer[u32Index].u8Status = MSG_BUFFER_FULL;
            MSG_PushMsg(&g_struSendQueue, (u8*)&g_struSendBuffer[u32Index]);

            return ZC_RET_OK;
        }
    }
#endif
    return ZC_RET_ERROR;
}