X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Fcc2420%2Ftransmit%2FCC2420TransmitP.nc;h=7e12cec89ae136f5c2b5496975083e72528f2cb7;hb=5d774627c6a5f959045751f9d354257b8928313d;hp=09917c96f38e5541fdaa7113df3fe5e5859669bd;hpb=815ef3b081a7a86619e82be995eddae5c907b46a;p=tinyos-2.x.git diff --git a/tos/chips/cc2420/transmit/CC2420TransmitP.nc b/tos/chips/cc2420/transmit/CC2420TransmitP.nc index 09917c96..7e12cec8 100644 --- a/tos/chips/cc2420/transmit/CC2420TransmitP.nc +++ b/tos/chips/cc2420/transmit/CC2420TransmitP.nc @@ -258,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); } /** @@ -601,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){ @@ -625,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; } @@ -678,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(); @@ -700,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; @@ -736,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;