コード例 #1
0
/*************************************************
* Function: PCT_SendCloudAccessMsg3
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_SendCloudAccessMsg3(PTC_ProtocolCon *pstruContoller)
{
    u16 u16Len;
    ZC_HandShakeMsg3 struMsg3;
    ZC_SecHead struSechead;
    u8 *pu8Vesion;

    ZC_GetStoreInfor(ZC_GET_TYPE_VESION, &pu8Vesion);
    
    memcpy(struMsg3.RandMsg, pstruContoller->RandMsg, ZC_HS_MSG_LEN);
    memcpy(struMsg3.u8EqVersion, pu8Vesion, ZC_EQVERSION_LEN);
    struMsg3.u8WifiVerSion[0] = (u8)(ZC_MODULE_VERSION >> 24);
    struMsg3.u8WifiVerSion[1] = (u8)(ZC_MODULE_VERSION >> 16);
    struMsg3.u8WifiVerSion[2] = (u8)(ZC_MODULE_VERSION >> 8);
    struMsg3.u8WifiVerSion[3] = (u8)(ZC_MODULE_VERSION);

    struMsg3.u8WifiType = ZC_MODULE_TYPE;
    /*first set key recv flag*/
    g_struProtocolController.u8keyRecv = PCT_KEY_RECVED;

    EVENT_BuildMsg(ZC_CODE_HANDSHAKE_3, 1, g_u8MsgBuildBuffer, &u16Len, 
        (u8*)&struMsg3, sizeof(ZC_HandShakeMsg3));

    struSechead.u8SecType = ZC_SEC_ALG_AES;
    struSechead.u16TotalMsg = ZC_HTONS(u16Len);

    (void)PCT_SendMsgToCloud(&struSechead, g_u8MsgBuildBuffer);
    
    pstruContoller->u8MainState = PCT_STATE_WAIT_MSG4;
    pstruContoller->pstruMoudleFun->pfunSetTimer(PCT_TIMER_REACCESS, 
        PCT_TIMER_INTERVAL_RECONNECT*10, &pstruContoller->u8AccessTimer);

    return;
}
コード例 #2
0
/*************************************************
* Function: PCT_SendAckToCloud
* Description:
* Author: cxy
* Returns:
* Parameter:
* History:
*************************************************/
void PCT_SendAckToCloud(u8 u8MsgId)
{
    u16 u16Len;
    ZC_SecHead struSechead;

    EVENT_BuildMsg(ZC_CODE_ACK, u8MsgId, g_u8MsgBuildBuffer, &u16Len, NULL, 0);
    struSechead.u8SecType = ZC_SEC_ALG_AES;
    struSechead.u16TotalMsg = ZC_HTONS(u16Len);
    (void)PCT_SendMsgToCloud(&struSechead, g_u8MsgBuildBuffer);
}
コード例 #3
0
/*************************************************
* Function: PCT_SendErrorMsg
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_SendErrorMsg(u8 u8MsgId, u8 *pu8Error, u16 u16ErrorLen)
{
    u16 u16Len;
    ZC_SecHead struSecHead;

    EVENT_BuildMsg(ZC_CODE_ERR, u8MsgId, g_u8MsgBuildBuffer, &u16Len, 
        pu8Error, u16ErrorLen);
    
    /*build sec head*/
    struSecHead.u8SecType = ZC_SEC_ALG_AES;
    struSecHead.u16TotalMsg = ZC_HTONS(u16Len);
    
    (void)PCT_SendMsgToCloud(&struSecHead, (u8*)g_u8MsgBuildBuffer);
}
コード例 #4
0
ファイル: zc_protocol_controller.c プロジェクト: sdhczw/ZC
/*************************************************
* Function: PCT_SendCloudAccessMsg1
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_SendCloudAccessMsg1(PTC_ProtocolCon *pstruContoller)
{
    u16 u16Len;
    ZC_SecHead struSechead;
    ZC_HandShakeMsg1 *pstruMsg1 = (ZC_HandShakeMsg1 *)g_u8MsgBuildBuffer;
    u8 *pu8DeviceId;
    u8 *pu8Domain;
    u32 u32RetVal;
    u8 u8DeviceIdLen;
    /*stop reconnection timer*/
    if (PCT_TIMER_INVAILD != pstruContoller->u8ReconnectTimer)
    {
        ZC_Printf("msg1 stop u8ReconnectTimer\n");
        TIMER_StopTimer(pstruContoller->u8ReconnectTimer);
        pstruContoller->u8ReconnectTimer = PCT_TIMER_INVAILD;
    }
    
    ZC_GetStoreInfor(ZC_GET_TYPE_DEVICEID, &pu8DeviceId);
    ZC_GetStoreInfor(ZC_GET_TYPE_DOMAIN, &pu8Domain);
    u8DeviceIdLen = strlen((const char *)pu8DeviceId);
    memcpy(pstruMsg1->RandMsg, pstruContoller->RandMsg, ZC_HS_MSG_LEN);
    memcpy(pstruMsg1->DeviceId, pu8DeviceId, u8DeviceIdLen);
    memcpy(pstruMsg1->u8Domain, pu8Domain, ZC_DOMAIN_LEN);

   
    EVENT_BuildMsg(ZC_CODE_HANDSHAKE_1, 1, g_u8MsgBuildBuffer, &u16Len, 
        (u8*)pstruMsg1, sizeof(ZC_HandShakeMsg1)+u8DeviceIdLen);

    struSechead.u8SecType = ZC_SEC_ALG_RSA;
    struSechead.u16TotalMsg = ZC_HTONS(u16Len);
    struSechead.u8Resver = 0x5A;
    u32RetVal = PCT_SendMsgToCloud(&struSechead, g_u8MsgBuildBuffer);
    
    if (ZC_RET_ERROR == u32RetVal)
    {
        ZC_Printf("Send Msg1 fail disconnect\n");
        PCT_DisConnectCloud(pstruContoller);
        return;
    }

    ZC_Printf("Send Msg1 \n");

    pstruContoller->u8MainState = PCT_STATE_WAIT_ACCESSRSP;

    
    pstruContoller->pstruMoudleFun->pfunSetTimer(PCT_TIMER_REACCESS, 
        PCT_TIMER_INTERVAL_RECONNECT * 120, &pstruContoller->u8AccessTimer);

}
コード例 #5
0
/*************************************************
* Function: PCT_SendEmptyMsg
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_SendEmptyMsg(u8 u8MsgId, u8 u8SecType)
{
    ZC_MessageHead struMsg;
    ZC_SecHead struSecHead;
    u16 u16Len = 0;
    /*build msg*/
    EVENT_BuildEmptyMsg(u8MsgId, (u8*)&struMsg, &u16Len);
    
    /*build sec head*/
    struSecHead.u8SecType = u8SecType;
    struSecHead.u16TotalMsg = ZC_HTONS(u16Len);

    
    (void)PCT_SendMsgToCloud(&struSecHead, (u8*)&struMsg);
}
コード例 #6
0
ファイル: zc_protocol_controller.c プロジェクト: sdhczw/ZC
/*************************************************
* Function: PCT_SendHeartMsg
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_SendHeartMsg()
{
    //ZC_MessageHead struHeart;
    ZC_SecHead struSecHead;
    u16 u16Len = 0;

    EVENT_BuildHeartMsg((u8*)&struSecHead, &u16Len);

    (void)PCT_SendMsgToCloud(&struSecHead, NULL);

    g_struProtocolController.pstruMoudleFun->pfunSetTimer(PCT_TIMER_SENDHEART, 
        PCT_TIMER_INTERVAL_HEART, &g_struProtocolController.u8HeartTimer);

    g_struProtocolController.pstruMoudleFun->pfunSetTimer(PCT_TIMER_CHECK_CLOUD_ACK, 
        PCT_TIMER_INTERVAL_CLOUD_ACK, &g_struProtocolController.u8CloudAckTimer);
    
}
コード例 #7
0
/*************************************************
* Function: PCT_SendHeartMsg
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_SendHeartMsg()
{
    ZC_MessageHead struHeart;
    ZC_SecHead struSecHead;
    u16 u16Len = 0;
    
    EVENT_BuildHeartMsg((u8*)&struHeart, &u16Len);

    /*build sec head*/
    struSecHead.u8SecType = ZC_SEC_ALG_AES;
    struSecHead.u16TotalMsg = ZC_HTONS(u16Len);

    (void)PCT_SendMsgToCloud(&struSecHead, (u8*)&struHeart);

    g_struProtocolController.pstruMoudleFun->pfunSetTimer(PCT_TIMER_SENDHEART, 
        PCT_TIMER_INTERVAL_HEART, &g_struProtocolController.u8HeartTimer);
    
}
コード例 #8
0
ファイル: zc_protocol_controller.c プロジェクト: sdhczw/ZC
/*************************************************
* Function: PCT_HandleMoudleEvent
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_HandleMoudleEvent(u8 *pu8Msg, u16 u16DataLen)
{
    ZC_SecHead struHead;
    ZC_MessageHead *pstruMsg = (ZC_MessageHead *)pu8Msg;

    if ((pstruMsg->MsgCode < ZC_CODE_REPORT_BASE)&&
        (pstruMsg->MsgCode > ZC_CODE_OTA_CONFIRM))
    {
        TIMER_StopTimer(g_struProtocolController.u8SendMoudleTimer);
        g_struProtocolController.u8SendMoudleTimer = PCT_TIMER_INVAILD;
    }

    struHead.u8SecType = ZC_SEC_ALG_AES;
    struHead.u16TotalMsg = ZC_HTONS(u16DataLen);
    (void)PCT_SendMsgToCloud(&struHead, pu8Msg);
    
    return;
}
コード例 #9
0
/*************************************************
* Function: PCT_SendHeartMsg
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_SendUnbindMsg()
{
    ZC_MessageHead struUnbind;
    ZC_SecHead struSecHead;
    u16 u16Len = 0;
    u32 u32Timer = 0;
    EVENT_BuildMsg(ZC_CODE_UNBIND, 0, (u8*)&struUnbind, &u16Len, 
        NULL, 0);
    
    /*build sec head*/
    struSecHead.u8SecType = ZC_SEC_ALG_AES;
    struSecHead.u16TotalMsg = ZC_HTONS(u16Len);
    
    (void)PCT_SendMsgToCloud(&struSecHead, (u8*)&struUnbind);
     ZC_Printf("Send Unbind msg ok\n");

    u32Timer = rand();
    u32Timer = (PCT_TIMER_INTERVAL_SENDUBIND) * (u32Timer % 10 + 1);

    g_struProtocolController.pstruMoudleFun->pfunSetTimer(PCT_TIMER_SENDUBIND, 
        u32Timer, &g_struProtocolController.u8SendUnbindTimer);
    
}
コード例 #10
0
/*************************************************
* Function: PCT_HandleMoudleEvent
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_HandleMoudleEvent(u8 *pu8Msg, u16 u16DataLen)
{
    MSG_Buffer *pstruBuffer;
    ZC_SecHead struHead;

    if (PCT_TIMER_INVAILD != g_struProtocolController.u8SendMoudleTimer)
    {
        TIMER_StopTimer(g_struProtocolController.u8SendMoudleTimer);
        pstruBuffer = (MSG_Buffer *)g_struProtocolController.pu8SendMoudleBuffer;
        pstruBuffer->u32Len = 0;
        pstruBuffer->u8Status = MSG_BUFFER_IDLE;
        g_struProtocolController.u8SendMoudleTimer = PCT_TIMER_INVAILD;
        g_struProtocolController.u8ReSendMoudleNum = 0;
    }


    struHead.u8SecType = ZC_SEC_ALG_AES;
    struHead.u16TotalMsg = ZC_HTONS(u16DataLen);
    
    (void)PCT_SendMsgToCloud(&struHead, pu8Msg);
    
    return;
}
コード例 #11
0
/*************************************************
* Function: PCT_HandleMoudleEvent
* Description: 
* Author: cxy 
* Returns: 
* Parameter: 
* History:
*************************************************/
void PCT_HandleMoudleEvent(u8 *pu8Msg, u16 u16DataLen)
{
    MSG_Buffer *pstruBuffer;
    ZC_SecHead struHead;
    ZC_MessageHead *pstruMsg = (ZC_MessageHead *)pu8Msg;

    if ((PCT_TIMER_INVAILD != g_struProtocolController.u8SendMoudleTimer) &&
        (pstruMsg->MsgCode < 200))
    {
        TIMER_StopTimer(g_struProtocolController.u8SendMoudleTimer);
        pstruBuffer = (MSG_Buffer *)g_struProtocolController.pu8SendMoudleBuffer;
        pstruBuffer->u32Len = 0;
        pstruBuffer->u8Status = MSG_BUFFER_IDLE;
        g_struProtocolController.u8SendMoudleTimer = PCT_TIMER_INVAILD;
        g_struProtocolController.u8ReSendMoudleNum = 0;
        PCT_SendEmptyMsg(((ZC_MessageHead *)pu8Msg)->MsgId, ZC_SEC_ALG_AES);
    }

    struHead.u8SecType = ZC_SEC_ALG_AES;
    struHead.u16TotalMsg = ZC_HTONS(u16DataLen);
    (void)PCT_SendMsgToCloud(&struHead, pu8Msg);
    
    return;
}