void smprActProcPairReq(smpCcb_t *pCcb, smpMsg_t *pMsg) { dmSecPairIndEvt_t pairInd; uint8_t *p; /* allocate scratch buffer */ if (pCcb->pScr == NULL) { if ((pCcb->pScr = WsfBufAlloc(sizeof(smpScratch_t))) == NULL) { /* alloc failed; cancel pairing */ pMsg->hdr.status = SMP_ERR_UNSPECIFIED; pMsg->hdr.event = SMP_MSG_API_CANCEL_REQ; smpSmExecute(pCcb, pMsg); return; } } else { /* should not happen */ SMP_TRACE_ERR0("pScr already allocated"); } /* set connection busy */ DmConnSetIdle(pCcb->connId, DM_IDLE_SMP_PAIR, DM_CONN_BUSY); p = pMsg->data.pPacket + L2C_PAYLOAD_START; /* store packet for later */ memcpy(pCcb->pairReq, p, SMP_PAIR_REQ_LEN); /* parse packet to callback event structure */ p++; /* skip command code */ p++; /* skip IO capabilities */ BSTREAM_TO_UINT8(pairInd.oob, p); BSTREAM_TO_UINT8(pairInd.auth, p); p++; /* skip max key len */ BSTREAM_TO_UINT8(pairInd.iKeyDist, p); BSTREAM_TO_UINT8(pairInd.rKeyDist, p); /* call app callback */ pairInd.hdr.param = pCcb->connId; pairInd.hdr.event = DM_SEC_PAIR_IND; DmSmpCbackExec((dmEvt_t *) &pairInd); }
void attsProcPrepWriteReq(attCcb_t *pCcb, uint16_t len, uint8_t *pPacket) { uint8_t *pBuf; uint8_t *p; attsAttr_t *pAttr; attsGroup_t *pGroup; attsPrepWrite_t *pPrep; uint16_t handle; uint16_t offset; uint16_t writeLen; uint8_t err = ATT_SUCCESS; /* parse handle and offset, calculate write length */ pPacket += L2C_PAYLOAD_START + ATT_HDR_LEN; BSTREAM_TO_UINT16(handle, pPacket); BSTREAM_TO_UINT16(offset, pPacket); writeLen = len - ATT_PREP_WRITE_REQ_LEN; /* length of value being written */ /* find attribute */ if ((pAttr = attsFindByHandle(handle, &pGroup)) == NULL) { /* attribute not found */ err = ATT_ERR_HANDLE; } /* verify permissions */ else if ((err = attsPermissions(pCcb->connId, ATTS_PERMIT_WRITE, handle, pAttr->permissions)) != ATT_SUCCESS) { /* err has been set; fail */ } /* verify offset is allowed */ else if ((offset != 0) && ((pAttr->settings & ATTS_SET_ALLOW_OFFSET) == 0)) { err = ATT_ERR_NOT_LONG; } /* verify write length, fixed length */ else if (((pAttr->settings & ATTS_SET_VARIABLE_LEN) == 0) && (writeLen != pAttr->maxLen)) { err = ATT_ERR_LENGTH; } /* verify prepare write queue limit not reached */ else if (WsfQueueCount(&pCcb->prepWriteQueue) >= pAttCfg->numPrepWrites) { err = ATT_ERR_QUEUE_FULL; } /* allocate new buffer to hold prepared write */ else if ((pPrep = WsfBufAlloc(sizeof(attsPrepWrite_t) - 1 + writeLen)) == NULL) { err = ATT_ERR_RESOURCES; } else if ((pAttr->settings & ATTS_SET_WRITE_CBACK) && (pGroup->writeCback != NULL)) { err = (*pGroup->writeCback)(pCcb->connId, handle, ATT_PDU_PREP_WRITE_REQ, 0, writeLen, pPacket, pAttr); } if (err == ATT_SUCCESS) { /* copy data to new buffer and queue it */ pPrep->writeLen = writeLen; pPrep->handle = handle; pPrep->offset = offset; memcpy(pPrep->packet, pPacket, writeLen); WsfQueueEnq(&pCcb->prepWriteQueue, pPrep); /* allocate response buffer */ if ((pBuf = attMsgAlloc(L2C_PAYLOAD_START + ATT_PREP_WRITE_RSP_LEN + writeLen)) != NULL) { /* build and send PDU */ p = pBuf + L2C_PAYLOAD_START; UINT8_TO_BSTREAM(p, ATT_PDU_PREP_WRITE_RSP); UINT16_TO_BSTREAM(p, handle); UINT16_TO_BSTREAM(p, offset); memcpy(p, pPacket, writeLen); L2cDataReq(L2C_CID_ATT, pCcb->handle, (ATT_PREP_WRITE_RSP_LEN + writeLen), pBuf); } } if (err) { attsErrRsp(pCcb->handle, ATT_PDU_PREP_WRITE_REQ, handle, err); } }