/*********************************************************************************** * @fn halRfReadRxBufSecure * * @brief Decrypts and reverse authenticates with CCM then reads out received * frame * * @param uint8* data - data buffer. This must be allocated by caller. * uint8 length - number of bytes * uint8 encrLength - number of bytes to decrypt * uint8 authLength - number of bytes to reverse authenticate * uuint8 m - integrity code (m=1,2,3 gives lenght of integrity * field 4,8,16) * * @return HAL_RF_SUCCESS or HAL_RF_FAILED */ uint8 halRfReadRxBufSecure(uint8* data, uint8 length, uint8 encrLength, \ uint8 authLength, uint8 m) { uint8 dpuStat; CC2520_RXBUFMOV(HIGH_PRIORITY, ADDR_RX, length, NULL); WAIT_DPU_DONE_H(); // Find Framecounter value in received packet starting from 10th byte // Copy in to nonce bytes (3-6) frame counter bytes // Incoming frame uses nonce Rx CC2520_MEMCP(HIGH_PRIORITY, 4, ADDR_RX+10, ADDR_NONCE_RX+3); WAIT_DPU_DONE_H(); // Copy in short address to nonce bytes (7-8) CC2520_MEMCP(HIGH_PRIORITY, 2, ADDR_RX+7, ADDR_NONCE_RX+7); WAIT_DPU_DONE_H(); // Perform decryption and authentication CC2520_UCCM(HIGH_PRIORITY,ADDR_KEY/16, encrLength, ADDR_NONCE_RX/16, ADDR_RX, ADDR_RX+authLength, authLength, m); WAIT_DPU_DONE_H(); // Check authentication status dpuStat = CC2520_REGRD8(CC2520_DPUSTAT); // Read from RX work buffer into data buffer CC2520_MEMRD(ADDR_RX, length, data); if( (dpuStat & AUTHSTAT_H_BM) != AUTHSTAT_H_BM ) { // Authentication failed return HAL_RF_FAILED; } else { return HAL_RF_SUCCESS; } }
/*********************************************************************************** * @fn halRfReadMemory * * @brief Read RF device memory * * @param uint16 addr - memory address * uint8* pData - data buffer. This must be allocated by caller. * uint8 length - number of bytes * * @return Number of bytes read */ uint8 halRfReadMemory(uint16 addr, uint8* pData, uint8 length) { if (addr>=CC2520_MEMORY_SIZE) length= 0; else if (addr+length>CC2520_MEMORY_SIZE) length= CC2520_MEMORY_SIZE - addr; CC2520_MEMRD(addr, length, pData); return length; }