Ejemplo n.º 1
0
/***********************************************************************************
 * @fn      halRfReceiveOn
 *
 * @brief   Turn receiver on
 *
 * @param   none
 *
 * @return  none
 */
void halRfReceiveOn(void) {
	/* Flush RX FIFO if needed.
	 * See bug #1 in http://www.ti.com/lit/er/swrz024/swrz024.pdf */
	halRfDisableRxInterrupt();
	CC2520_INS_STROBE(CC2520_INS_SFLUSHRX);
	uint8_t rx_fifo_cnt = CC2520_REGRD8(CC2520_RXFIFOCNT);

	CC2520_INS_STROBE(CC2520_INS_SRXON);

	if (rx_fifo_cnt != CC2520_REGRD8(CC2520_RXFIFOCNT)) {
		CC2520_INS_STROBE(CC2520_INS_SFLUSHRX);
	}
	halRfEnableRxInterrupt();
}
Ejemplo n.º 2
0
/***********************************************************************************
* @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;
    }
}
Ejemplo n.º 3
0
/***********************************************************************************
 * @fn      halRfReceiveOff
 *
 * @brief   Turn receiver off
 *
 * @param   none
 *
 * @return  none
 */
void halRfReceiveOff(void) {
	/* Flush RX FIFO if needed.
	 * See bug #1 in http://www.ti.com/lit/er/swrz024/swrz024.pdf */
	halRfDisableRxInterrupt();
	CC2520_INS_STROBE(CC2520_INS_SFLUSHRX);
	uint8_t rx_fifo_cnt = CC2520_REGRD8(CC2520_RXFIFOCNT);

	CC2520_INS_STROBE(CC2520_INS_SRFOFF);

	if (rx_fifo_cnt != CC2520_REGRD8(CC2520_RXFIFOCNT)) {
		CC2520_INS_STROBE(CC2520_INS_SFLUSHRX);
		// Software clean-up
		// Reset software for frame reception...
	}
	halRfEnableRxInterrupt();
}
Ejemplo n.º 4
0
/***********************************************************************************
* @fn          halSampleED
*
* @brief      Sample Energy Detect
*
* @param      uint8 channel - channel between 11 and 26
*             uint16 sampleTime - sample time in us
*            
* @return     int8 - sampled RSSI value      
*/
int8 halSampleED(uint8 channel, uint16 sampleTime)
{
    int8 rssi=0;
    
    CC2520_REGWR8(CC2520_FREQCTRL, 0x0B + ( (channel-11) * 5));
    CC2520_SRXON();
    while (!CC2520_REGRD8(CC2520_RSSISTAT));
    
    // Enable ED scan mode
    CC2520_BSET(CC2520_MAKE_BIT_ADDR(CC2520_FRMCTRL0, 4));
    
    // Spend sampleTime us accumulating the peak RSSI value
    halMcuWaitUs(sampleTime);
    rssi = CC2520_REGRD8(CC2520_RSSI);
    
    // Exit the current channel
    CC2520_SRFOFF();
    // Disable ED scan mode
    CC2520_BCLR(CC2520_MAKE_BIT_ADDR(CC2520_FRMCTRL0, 4));
    
    return rssi;
}