void SmpHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg) { smpCcb_t *pCcb; /* Handle message */ if (pMsg != NULL) { if (pMsg->event == SMP_DB_SERVICE_IND) { SmpDbService(); } else { if (pMsg->event == SMP_MSG_WSF_CMAC_CMPL) { secCmacMsg_t *pCmac = (secCmacMsg_t *) pMsg; /* Free the plain text buffer that was allocated and passed into SecCmac */ if (pCmac->pPlainText) { WsfBufFree(pCmac->pPlainText); } } /* get connection control block */ pCcb = smpCcbByConnId((dmConnId_t) pMsg->param); /* verify connection is open */ if (pCcb->connId != DM_CONN_ID_NONE) { /* if AES result verify it is not stale */ if (pMsg->event == SMP_MSG_WSF_AES_CMPL && pCcb->token != pMsg->status) { SMP_TRACE_WARN2("AES token mismatch: %d %d", pCcb->token, pMsg->status); } else { /* send to state machine */ smpSmExecute(pCcb, (smpMsg_t *) pMsg); } } } } /* Handle events */ else if (event) { } }
void smpCleanup(smpCcb_t *pCcb) { /* free scratch buffer */ if (pCcb->pScr != NULL) { WsfBufFree(pCcb->pScr); pCcb->pScr = NULL; } /* stop response timer */ WsfTimerStop(&pCcb->smpTimer); pCcb->secReq = FALSE; pCcb->nextCmdCode = (pCcb->initiator) ? SMP_CMD_SECURITY_REQ : SMP_CMD_PAIR_REQ; pCcb->lastSentKey = 0; }
void attsProcExecWriteReq(attCcb_t *pCcb, uint16_t len, uint8_t *pPacket) { uint8_t *pBuf; uint8_t *p; attsPrepWrite_t *pPrep; attsAttr_t *pAttr; attsGroup_t *pGroup; uint8_t err = ATT_SUCCESS; pPacket += L2C_PAYLOAD_START + ATT_HDR_LEN; /* if cancelling all prepared writes */ if (*pPacket == ATT_EXEC_WRITE_CANCEL) { /* free all queued buffers */ attsClearPrepWrites(pCcb); } /* else writing all prepared writes */ else if (*pPacket == ATT_EXEC_WRITE_ALL) { /* iterate over prepare write queue and verify offset and length */ for (pPrep = pCcb->prepWriteQueue.pHead; pPrep != NULL; pPrep = pPrep->pNext) { /* find attribute */ if ((pAttr = attsFindByHandle(pPrep->handle, &pGroup)) != NULL) { /* verify offset */ if (pPrep->offset > pAttr->maxLen) { err = ATT_ERR_OFFSET; } /* verify write length with offset */ else if ((pPrep->writeLen + pPrep->offset) > pAttr->maxLen) { err = ATT_ERR_LENGTH; } if (err) { /* verification failed; discard all prepared writes */ attsClearPrepWrites(pCcb); break; } } } /* if length and offset checks ok then write all buffers in queue */ if (err == ATT_SUCCESS) { /* for each buffer */ while ((pPrep = WsfQueueDeq(&pCcb->prepWriteQueue)) != NULL) { /* write buffer */ if ((err = attsExecPrepWrite(pCcb, pPrep)) != ATT_SUCCESS) { /* write failed; discard remaining prepared writes */ attsClearPrepWrites(pCcb); } /* free buffer */ WsfBufFree(pPrep); } } } /* else unknown operation */ else { err = ATT_ERR_INVALID_PDU; } /* send response or error response */ if (err) { attsErrRsp(pCcb->handle, ATT_PDU_EXEC_WRITE_REQ, 0, err); } else { if ((pBuf = attMsgAlloc(L2C_PAYLOAD_START + ATT_EXEC_WRITE_RSP_LEN)) != NULL) { /* build and send PDU */ p = pBuf + L2C_PAYLOAD_START; UINT8_TO_BSTREAM(p, ATT_PDU_EXEC_WRITE_RSP); L2cDataReq(L2C_CID_ATT, pCcb->handle, ATT_EXEC_WRITE_RSP_LEN, pBuf); } } }