/*********************************************************************************** * @fn halRfWriteTxBufSecure * * @brief Encrypt and authenticate plaintext then fill TX buffer * * @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 * uint8 m - integrity code (m=1,2,3 gives lenght of integrity * field 4,8,16) * * @return none */ void halRfWriteTxBufSecure(uint8* data, uint8 length, uint8 encrLength, uint8 authLength, uint8 m) { uint8 micLength; // Check range of m #if 0 // POOH HAL_ASSERT(m<=4); #else if( m > 4 ) { DEBUG_MSG_ASSERT; } #endif if(m>0) { micLength = 0x2<<m; } else if(m==0) { micLength=0; } // Write packet to work buffer CC2520_MEMWR(ADDR_TX, length, data); // skip the length byte and start from the next byte in TXBUF // Outgoing frame uses nonce_tx CC2520_CCM(HIGH_PRIORITY,ADDR_KEY/16, encrLength, ADDR_NONCE_TX/16, ADDR_TX+1, 0, authLength, m); WAIT_DPU_DONE_H(); // copy from work buffer to TX FIFO CC2520_TXBUFCP(HIGH_PRIORITY, ADDR_TX, length+micLength, NULL); WAIT_DPU_DONE_H(); }
/*********************************************************************************** * @fn halRfSecurityInit * * @brief Security init. Write nonces and key to chip. * * @param none * * @return none */ void halRfSecurityInit(uint8* key, uint8* nonceRx, uint8* nonceTx) { // Write key CC2520_MEMWR(ADDR_KEY,KEY_LENGTH,key); // Write nonce RX CC2520_MEMWR(ADDR_NONCE_RX,NONCE_LENGTH,nonceRx); // Write nonce TX CC2520_MEMWR(ADDR_NONCE_TX,NONCE_LENGTH,nonceTx); // Reverse key CC2520_MEMCPR(HIGH_PRIORITY,KEY_LENGTH,ADDR_KEY,ADDR_KEY); // Reverse nonces CC2520_MEMCPR(HIGH_PRIORITY,NONCE_LENGTH,ADDR_NONCE_RX,ADDR_NONCE_RX); CC2520_MEMCPR(HIGH_PRIORITY,NONCE_LENGTH,ADDR_NONCE_TX,ADDR_NONCE_TX); }
/*********************************************************************************** * @fn halRfSetExtAddr * * @brief Write PAN Id to chip * * @param none * * @return none */ void halRfSetExtAddr(uint8* extAddr) { CC2520_MEMWR(CC2520_RAM_EXTADDR, 8, extAddr); }