X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Fcc2420%2Ftransmit%2FCC2420TransmitP.nc;h=7e12cec89ae136f5c2b5496975083e72528f2cb7;hb=5d774627c6a5f959045751f9d354257b8928313d;hp=d51cd72dccc3415fcd2c052b1b7efe2bdfc48e5b;hpb=f91d3f6c0122c7ce849c47305add585be3ea210f;p=tinyos-2.x.git diff --git a/tos/chips/cc2420/transmit/CC2420TransmitP.nc b/tos/chips/cc2420/transmit/CC2420TransmitP.nc index d51cd72d..7e12cec8 100644 --- a/tos/chips/cc2420/transmit/CC2420TransmitP.nc +++ b/tos/chips/cc2420/transmit/CC2420TransmitP.nc @@ -106,11 +106,16 @@ implementation { CC2420_ABORT_PERIOD = 320 }; +#ifdef CC2420_HW_SECURITY uint16_t startTime = 0; norace uint8_t secCtrlMode = 0; norace uint8_t nonceValue[16] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; norace uint8_t skip; norace uint16_t CTR_SECCTRL0, CTR_SECCTRL1; + uint8_t securityChecked = 0; + + void securityCheck(); +#endif norace message_t * ONE_NOK m_msg; @@ -120,8 +125,6 @@ implementation { cc2420_transmit_state_t m_state = S_STOPPED; - uint8_t securityChecked = 0; - bool m_receiving = FALSE; uint16_t m_prev_time; @@ -147,7 +150,6 @@ implementation { error_t resend( bool cca ); void loadTXFIFO(); void attemptSend(); - void securityCheck(); void congestionBackoff(); error_t acquireSpiResource(); error_t releaseSpiResource(); @@ -256,8 +258,9 @@ implementation { inline uint32_t getTime32(uint16_t time) { - uint32_t recent_time=call BackoffTimer.getNow(); - return recent_time + (int16_t)(time - recent_time); + uint32_t recent_time = call BackoffTimer.getNow(); + + return recent_time - (uint16_t)(recent_time - time); } /** @@ -550,7 +553,9 @@ implementation { return FAIL; } +#ifdef CC2420_HW_SECURITY securityChecked = 0; +#endif m_state = S_LOAD; m_cca = cca; m_msg = p_msg; @@ -597,13 +602,6 @@ implementation { } #ifdef CC2420_HW_SECURITY - /* - inline void uwait(uint16_t u) { - uint16_t t0 = TAR; - while((TAR - t0) <= u); - } - */ - task void waitTask(){ call Leds.led2Toggle(); if(SECURITYLOCK == 1){ @@ -621,11 +619,21 @@ implementation { uint8_t mode; uint8_t key; uint8_t micLength; - uint16_t currentStatus; msg_header = call CC2420PacketBody.getHeader( m_msg ); if(!(msg_header->fcf & (1 << IEEE154_FCF_SECURITY_ENABLED))){ + // Security is not used for this packet + // Make sure to set mode to 0 and the others to the default values + CTR_SECCTRL0 = ((0 << CC2420_SECCTRL0_SEC_MODE) | + (1 << CC2420_SECCTRL0_SEC_M) | + (1 << CC2420_SECCTRL0_SEC_TXKEYSEL) | + (1 << CC2420_SECCTRL0_SEC_CBC_HEAD)) ; + + call CSN.clr(); + call SECCTRL0.write(CTR_SECCTRL0); + call CSN.set(); + return; } @@ -674,9 +682,9 @@ implementation { (key << CC2420_SECCTRL0_SEC_TXKEYSEL) | (1 << CC2420_SECCTRL0_SEC_CBC_HEAD)) ; #ifndef TFRAMES_ENABLED - CTR_SECCTRL1 = (skip+11+sizeof(security_header_t))+((skip+11+sizeof(security_header_t))<<8); + CTR_SECCTRL1 = (skip+11+sizeof(security_header_t)+((skip+11+sizeof(security_header_t))<<8)); #else - CTR_SECCTRL1 = (skip+10+sizeof(security_header_t))+((skip+10+sizeof(security_header_t))<<8); + CTR_SECCTRL1 = (skip+10+sizeof(security_header_t)+((skip+10+sizeof(security_header_t))<<8)); #endif call CSN.clr(); @@ -696,23 +704,12 @@ implementation { call CSN.set(); while(status & CC2420_STATUS_ENC_BUSY){ - //uwait(1*1024); call CSN.clr(); status = call SNOP.strobe(); call CSN.set(); } - - call CSN.clr(); - call STXENC.strobe(); - call CSN.set(); - - call CSN.clr(); - call SECCTRL0.read(¤tStatus); - call CSN.set(); - - call CSN.clr(); - call SECCTRL0.write(currentStatus && ~(3 << CC2420_SECCTRL0_SEC_MODE)); - call CSN.set(); + + // Inline security will be activated by STXON or STXONCCA strobes atomic SECURITYLOCK = 0; @@ -732,6 +729,9 @@ implementation { * * If the packet got sent, we should expect an SFD interrupt to take * over, signifying the packet is getting sent. + * + * If security is enabled, STXONCCA or STXON will perform inline security + * options before transmitting the packet. */ void attemptSend() { uint8_t status;