void smprActSendPairRandom(smpCcb_t *pCcb, smpMsg_t *pMsg) { uint8_t *pPkt; uint8_t *p; uint8_t encKeyLen; /* get max STK length */ encKeyLen = (pCcb->pairReq[SMP_MAXKEY_POS] < pCcb->pairRsp[SMP_MAXKEY_POS]) ? pCcb->pairReq[SMP_MAXKEY_POS] : pCcb->pairRsp[SMP_MAXKEY_POS]; /* store STK and adjust based on max key length */ memcpy(pCcb->pScr->buf.b3, pMsg->aes.pCiphertext, encKeyLen); memset((pCcb->pScr->buf.b3 + encKeyLen), 0, (SMP_KEY_LEN - encKeyLen)); /* start smp response timer */ smpStartRspTimer(pCcb); /* allocate packet buffer and send pairing random packet */ if ((pPkt = smpMsgAlloc(SMP_PAIR_RAND_LEN + L2C_PAYLOAD_START)) != NULL) { /* build packet */ p = pPkt + L2C_PAYLOAD_START; UINT8_TO_BSTREAM(p, SMP_CMD_PAIR_RAND); memcpy(p, pCcb->pScr->buf.b4, SMP_RAND_LEN); /* send packet */ smpSendPkt(pCcb, pPkt); } }
void smprActSendPairRsp(smpCcb_t *pCcb, smpMsg_t *pMsg) { uint8_t *pPkt; uint8_t *p; uint8_t oob; uint8_t display; /* build packet to pairing response buffer in ccb */ p = pCcb->pairRsp; UINT8_TO_BSTREAM(p, SMP_CMD_PAIR_RSP); UINT8_TO_BSTREAM(p, pSmpCfg->ioCap); UINT8_TO_BSTREAM(p, pMsg->dm.pair.oob); UINT8_TO_BSTREAM(p, pMsg->dm.pair.auth); UINT8_TO_BSTREAM(p, pSmpCfg->maxKeyLen); UINT8_TO_BSTREAM(p, pMsg->dm.pair.iKeyDist); UINT8_TO_BSTREAM(p, pMsg->dm.pair.rKeyDist); /* process pairing request and response data */ if (smpCb.procPairing(pCcb, &oob, &display)) { /* set next expected packet */ if ((pCcb->pairReq[SMP_AUTHREQ_POS] & pMsg->dm.pair.auth & SMP_AUTH_SC_FLAG) == SMP_AUTH_SC_FLAG) { pCcb->nextCmdCode = SMP_CMD_PUBLIC_KEY; } else { pCcb->nextCmdCode = SMP_CMD_PAIR_CNF; } /* start smp response timer */ smpStartRspTimer(pCcb); /* send pairing response; allocate packet buffer */ if ((pPkt = smpMsgAlloc(SMP_PAIR_RSP_LEN + L2C_PAYLOAD_START)) != NULL) { /* build packet from pairing response buffer */ memcpy(pPkt + L2C_PAYLOAD_START, pCcb->pairRsp, SMP_PAIR_RSP_LEN); /* send packet */ smpSendPkt(pCcb, pPkt); } /* request authentication data */ smpCb.procAuthReq(pCcb, oob, display); } }
void smprActSetupKeyDist(smpCcb_t *pCcb, smpMsg_t *pMsg) { /* don't receive anything yet */ pCcb->nextCmdCode = 0; /* start smp response timer once for entire key distribution phase */ smpStartRspTimer(pCcb); /* initialize parameters in key ind struct */ pCcb->pScr->keyInd.hdr.param = pCcb->connId; pCcb->pScr->keyInd.secLevel = (pCcb->auth & SMP_AUTH_MITM_FLAG) ? DM_SEC_LEVEL_ENC_AUTH : DM_SEC_LEVEL_ENC; pCcb->pScr->keyInd.encKeyLen = (pCcb->pairReq[SMP_MAXKEY_POS] < pCcb->pairRsp[SMP_MAXKEY_POS]) ? pCcb->pairReq[SMP_MAXKEY_POS] : pCcb->pairRsp[SMP_MAXKEY_POS]; /* start key distribution */ smprActSendKey(pCcb, pMsg); }
void smprActSendSecurityReq(smpCcb_t *pCcb, smpMsg_t *pMsg) { uint8_t *pPkt; uint8_t *p; /* start smp response timer */ smpStartRspTimer(pCcb); /* allocate packet buffer */ if ((pPkt = smpMsgAlloc(SMP_SECURITY_REQ_LEN + L2C_PAYLOAD_START)) != NULL) { /* build packet */ p = pPkt + L2C_PAYLOAD_START; UINT8_TO_BSTREAM(p, SMP_CMD_SECURITY_REQ); UINT8_TO_BSTREAM(p, pMsg->dm.securityReq.auth); /* send packet */ smpSendPkt(pCcb, pPkt); } }
void smpActSendPairCnf(smpCcb_t *pCcb, smpMsg_t *pMsg) { uint8_t *pPkt; uint8_t *p; /* set next expected packet */ pCcb->nextCmdCode = (pCcb->initiator) ? SMP_CMD_PAIR_CNF : SMP_CMD_PAIR_RAND; /* start smp response timer */ smpStartRspTimer(pCcb); /* allocate packet buffer */ if ((pPkt = smpMsgAlloc(SMP_PAIR_CNF_LEN + L2C_PAYLOAD_START)) != NULL) { /* build packet */ p = pPkt + L2C_PAYLOAD_START; UINT8_TO_BSTREAM(p, SMP_CMD_PAIR_CNF); memcpy(p, pMsg->aes.pCiphertext, SMP_CONFIRM_LEN); /* send packet */ smpSendPkt(pCcb, pPkt); } }