]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
safe tinyos annotations
authorregehr <regehr>
Tue, 3 Jun 2008 04:43:02 +0000 (04:43 +0000)
committerregehr <regehr>
Tue, 3 Jun 2008 04:43:02 +0000 (04:43 +0000)
12 files changed:
tos/chips/cc2420/CC2420ActiveMessageP.nc
tos/chips/cc2420/csma/CC2420CsmaP.nc
tos/chips/cc2420/interfaces/CC2420Fifo.nc
tos/chips/cc2420/interfaces/CC2420PacketBody.nc
tos/chips/cc2420/interfaces/CC2420Ram.nc
tos/chips/cc2420/interfaces/CC2420Receive.nc
tos/chips/cc2420/interfaces/CC2420Transmit.nc
tos/chips/cc2420/interfaces/RadioBackoff.nc
tos/chips/cc2420/packet/CC2420PacketC.nc
tos/chips/cc2420/receive/CC2420ReceiveP.nc
tos/chips/cc2420/spi/CC2420SpiP.nc
tos/chips/cc2420/transmit/CC2420TransmitP.nc

index d6a6fbd09466c775e56b74a8b92295d260370179..002aa3367433db2768fd582c8298bec6a2f3214c 100644 (file)
@@ -199,18 +199,18 @@ implementation {
   /***************** RadioBackoff ***********************/
 
   async event void SubBackoff.requestInitialBackoff(message_t *msg) {
-    signal RadioBackoff.requestInitialBackoff[((cc2420_header_t*)(msg->data - 
-                                        sizeof(cc2420_header_t)))->type](msg);
+    signal RadioBackoff.requestInitialBackoff[(TCAST(cc2420_header_t* ONE,
+        (uint8_t*)msg + offsetof(message_t, data) - sizeof(cc2420_header_t)))->type](msg);
   }
 
   async event void SubBackoff.requestCongestionBackoff(message_t *msg) {
-    signal RadioBackoff.requestCongestionBackoff[((cc2420_header_t*)(msg->data - 
-        sizeof(cc2420_header_t)))->type](msg);
+    signal RadioBackoff.requestCongestionBackoff[(TCAST(cc2420_header_t* ONE,
+        (uint8_t*)msg + offsetof(message_t, data) - sizeof(cc2420_header_t)))->type](msg);
   }
   async event void SubBackoff.requestCca(message_t *msg) {
     // Lower layers than this do not configure the CCA settings
-    signal RadioBackoff.requestCca[((cc2420_header_t*)(msg->data - 
-        sizeof(cc2420_header_t)))->type](msg);
+    signal RadioBackoff.requestCca[(TCAST(cc2420_header_t* ONE,
+        (uint8_t*)msg + offsetof(message_t, data) - sizeof(cc2420_header_t)))->type](msg);
   }
 
   async command void RadioBackoff.setInitialBackoff[am_id_t amId](uint16_t backoffTime) {
index 64a9852433ae71fd685d0359665dd2437d0ef8d8..284313ee0d09806642174f5a7e6ad64238f33be1 100644 (file)
@@ -63,7 +63,7 @@ implementation {
     S_TRANSMITTING,
   };
 
-  message_t* m_msg;
+  message_t* ONE_NOK m_msg;
   
   error_t sendErr = SUCCESS;
   
@@ -156,7 +156,7 @@ implementation {
 
   command void* Send.getPayload(message_t* m, uint8_t len) {
     if (len <= call Send.maxPayloadLength()) {
-      return m->data;
+      return (void* COUNT_NOK(len))m->data;
     }
     else {
       return NULL;
index 115a0d392fe458edd6e74c6c71f8f73404c5c661..ecf9e3c1fdd9ada7319778898e6d223dbaff2ca5 100644 (file)
@@ -48,7 +48,7 @@ interface CC2420Fifo {
    * @return status byte returned when sending the last address byte
    * of the SPI transaction.
    */
-  async command cc2420_status_t beginRead( uint8_t* data, uint8_t length );
+  async command cc2420_status_t beginRead( uint8_t* COUNT_NOK(length) data, uint8_t length );
 
   /**
    * Continue reading from the FIFO without having to send the address
@@ -59,7 +59,7 @@ interface CC2420Fifo {
    * @param length number of bytes to read.
    * @return SUCCESS always.
    */
-  async command error_t continueRead( uint8_t* data, uint8_t length );
+  async command error_t continueRead( uint8_t* COUNT_NOK(length) data, uint8_t length );
 
   /**
    * Signals the completion of a read operation.
@@ -68,7 +68,7 @@ interface CC2420Fifo {
    * @param length number of bytes read.
    * @param error notification of how the operation went
    */
-  async event void readDone( uint8_t* data, uint8_t length, error_t error );
+  async event void readDone( uint8_t* COUNT_NOK(length) data, uint8_t length, error_t error );
 
   /**
    * Start writing the FIFO. The <code>writeDone</code> event will be
@@ -79,7 +79,7 @@ interface CC2420Fifo {
    * @return status byte returned when sending the last address byte
    * of the SPI transaction.
    */
-  async command cc2420_status_t write( uint8_t* data, uint8_t length );
+  async command cc2420_status_t write( uint8_t* COUNT_NOK(length) data, uint8_t length );
 
   /**
    * Signals the completion of a write operation.
@@ -88,6 +88,6 @@ interface CC2420Fifo {
    * @param length number of bytes written.
    * @param error notification of how the operation went
    */
-  async event void writeDone( uint8_t* data, uint8_t length, error_t error );
+  async event void writeDone( uint8_t* COUNT_NOK(length) data, uint8_t length, error_t error );
 
 }
index c61cd4a3d1ce9f13b527ac0217ebe67f1b7a9c91..6ed0633c38973de1da727966ca031dbc690b09e9 100644 (file)
@@ -39,12 +39,12 @@ interface CC2420PacketBody {
   /**
    * @return pointer to the cc2420_header_t of the given message
    */
-  async command cc2420_header_t *getHeader(message_t *msg);
+  async command cc2420_header_t * ONE getHeader(message_t * ONE msg);
   
   /**
    * @return pointer to the cc2420_metadata_t of the given message
    */
-  async command cc2420_metadata_t *getMetadata(message_t *msg);
+  async command cc2420_metadata_t * ONE getMetadata(message_t * ONE msg);
   
 }
 
index a41712d560a23f98e6febc4db644ab205998547c..3d5e3b8a1740f2208b772617d2f4035ab68a7219 100644 (file)
@@ -49,7 +49,7 @@ interface CC2420Ram {
    * @return status byte returned when sending the last byte
    * of the SPI transaction.
    */
-  async command cc2420_status_t read( uint8_t offset, uint8_t* data, uint8_t length );
+  async command cc2420_status_t read( uint8_t offset, uint8_t* COUNT_NOK(length) data, uint8_t length );
 
   /**
    * Write data to RAM. This operation is sychronous.
@@ -60,6 +60,6 @@ interface CC2420Ram {
    * @return status byte returned when sending the last address byte
    * of the SPI transaction.
    */
-  async command cc2420_status_t write( uint8_t offset, uint8_t* data, uint8_t length );
+  async command cc2420_status_t write( uint8_t offset, uint8_t* COUNT_NOK(length) data, uint8_t length );
 
 }
index 4401e4731308fc5f64db109cbaf5c582328074e1..257f942ade524ab4ae4f8f5a407b551cb6099aac 100644 (file)
@@ -60,7 +60,7 @@ interface CC2420Receive {
    * @param type of the message received.
    * @param message pointer to message received.
    */
-  async event void receive( uint8_t type, message_t* message );
+  async event void receive( uint8_t type, message_t* ONE_NOK message );
 
 }
 
index 0052a6bb595cf5f9a7da900e7ac29c712a1f6440..39c9d75218b5757469ffefaba5702b10214bd1a0 100644 (file)
@@ -48,7 +48,7 @@ interface CC2420Transmit {
    * @param useCca TRUE if this Tx should use clear channel assessments
    * @return SUCCESS if the request was accepted, FAIL otherwise.
    */
-  async command error_t send( message_t* p_msg, bool useCca );
+  async command error_t send( message_t* ONE p_msg, bool useCca );
 
   /**
    * Send the previous message again
@@ -70,7 +70,7 @@ interface CC2420Transmit {
    * @param p_msg message to send.
    * @param error notifaction of how the operation went.
    */
-  async event void sendDone( message_t* p_msg, error_t error );
+  async event void sendDone( message_t* ONE_NOK p_msg, error_t error );
 
   /**
    * Modify the contents of a packet. This command can only be used
@@ -81,7 +81,7 @@ interface CC2420Transmit {
    * @param len of bytes to write
    * @return SUCCESS if the request was accepted, FAIL otherwise.
    */
-  async command error_t modify( uint8_t offset, uint8_t* buf, uint8_t len );
+  async command error_t modify( uint8_t offset, uint8_t* COUNT_NOK(len) buf, uint8_t len );
 
 }
 
index 26071b95e95710db03a5f1f3e5202b6b8734462e..a9cb5ec867baf639de99e208e1d09997108270a5 100644 (file)
@@ -78,20 +78,20 @@ interface RadioBackoff {
    * Reply using setInitialBackoff(..)
    * @param msg pointer to the message being sent
    */
-  async event void requestInitialBackoff(message_t *msg);
+  async event void requestInitialBackoff(message_t * ONE msg);
   
   /**
    * Request for input on the congestion backoff
    * Reply using setCongestionBackoff(..)
    * @param msg pointer to the message being sent
    */
-  async event void requestCongestionBackoff(message_t *msg);
+  async event void requestCongestionBackoff(message_t * ONE msg);
   
   /**
    * Request for input on whether or not to use CCA on the outbound packet.
    * Replies should come in the form of setCca(..)
    * @param msg pointer to the message being sent
    */
-  async event void requestCca(message_t *msg);
+  async event void requestCca(message_t * ONE msg);
 }
 
index 5bbaee6dfe93443be6fee63c1f412dd8f540ff2a..8eeb8a629aba06dce923c7b886395d6bce8399a3 100644 (file)
@@ -87,8 +87,8 @@ implementation {
   }
 
   /***************** CC2420PacketBody Commands ****************/
-  async command cc2420_header_t *CC2420PacketBody.getHeader( message_t* msg ) {
-    return (cc2420_header_t*)( msg->data - sizeof( cc2420_header_t ) );
+  async command cc2420_header_t * ONE CC2420PacketBody.getHeader( message_t* ONE msg ) {
+    return TCAST(cc2420_header_t* ONE, (uint8_t *)msg + offsetof(message_t, data) - sizeof( cc2420_header_t ));
   }
 
   async command cc2420_metadata_t *CC2420PacketBody.getMetadata( message_t* msg ) {
index 812bd79126797a31bf49280ce16c985e39724c78..f7ca6baf9d572d8f0005d9b5eded6f58732045eb 100644 (file)
@@ -97,7 +97,7 @@ implementation {
   
   norace uint8_t m_bytes_left;
   
-  norace message_t* m_p_rx_buf;
+  norace message_t* ONE_NOK m_p_rx_buf;
 
   message_t m_rx_buf;
   
@@ -195,7 +195,8 @@ implementation {
                                     error_t error ) {
     cc2420_header_t* header = call CC2420PacketBody.getHeader( m_p_rx_buf );
     cc2420_metadata_t* metadata = call CC2420PacketBody.getMetadata( m_p_rx_buf );
-    uint8_t* buf = (uint8_t*) header;
+    uint8_t tmpLen = sizeof(message_t) - (offsetof(message_t, data) - sizeof(cc2420_header_t));
+    uint8_t* COUNT(tmpLen) buf = TCAST(uint8_t* COUNT(tmpLen), header);
     rxFrameLength = buf[ 0 ];
 
     switch( m_state ) {
@@ -324,7 +325,9 @@ implementation {
    */
   task void receiveDone_task() {
     cc2420_metadata_t* metadata = call CC2420PacketBody.getMetadata( m_p_rx_buf );
-    uint8_t* buf = (uint8_t*) call CC2420PacketBody.getHeader( m_p_rx_buf );;
+    cc2420_header_t* header = call CC2420PacketBody.getHeader( m_p_rx_buf);
+    uint8_t tmpLen = sizeof(message_t) - (offsetof(message_t, data) - sizeof(cc2420_header_t));
+    uint8_t* COUNT(tmpLen) buf = TCAST(uint8_t* COUNT(tmpLen), header);
     
     metadata->crc = buf[ rxFrameLength ] >> 7;
     metadata->lqi = buf[ rxFrameLength ] & 0x7f;
index 6db6a4ed3a9170eedb2f8681f03779d5caa88765..8249891960f9c1c409513539066f9868a317e29c 100644 (file)
@@ -262,6 +262,8 @@ implementation {
                                                             uint8_t len ) {
 
     cc2420_status_t status = 0;
+    uint8_t tmpLen = len;
+    uint8_t * COUNT(tmpLen) tmpData = (uint8_t * COUNT(tmpLen))data;
 
     atomic {
       if(call WorkingState.isIdle()) {
@@ -274,7 +276,7 @@ implementation {
     status = call SpiByte.write( addr | 0x80 );
     call SpiByte.write( ( addr >> 1 ) & 0xc0 );
     for ( ; len; len-- ) {
-      call SpiByte.write( *data++ );
+      call SpiByte.write( tmpData[tmpLen-len] );
     }
 
     return status;
index 8bd55a4ddc647dad40956445e4aa5921ab01ef0f..c312fef5b37d689aba4652a64c1ac4044aa57c64 100644 (file)
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2005-2006 Arch Rock Corporation
+/* 
+ * Copyright (c) 2005-2006 Arch Rock Corporation 
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -95,7 +95,7 @@ implementation {
     CC2420_ABORT_PERIOD = 320
   };
   
-  norace message_t *m_msg;
+  norace message_t * ONE_NOK m_msg;
   
   norace bool m_cca;
   
@@ -124,7 +124,7 @@ implementation {
   
 
   /***************** Prototypes ****************/
-  error_t send( message_t *p_msg, bool cca );
+  error_t send( message_t * ONE p_msg, bool cca );
   error_t resend( bool cca );
   void loadTXFIFO();
   void attemptSend();
@@ -167,7 +167,7 @@ implementation {
 
 
   /**************** Send Commands ****************/
-  async command error_t Send.send( message_t* p_msg, bool useCca ) {
+  async command error_t Send.send( message_t* ONE p_msg, bool useCca ) {
     return send( p_msg, useCca );
   }
 
@@ -488,7 +488,7 @@ implementation {
    * @param *p_msg Pointer to the message that needs to be sent
    * @param cca TRUE if this transmit should use clear channel assessment
    */
-  error_t send( message_t* p_msg, bool cca ) {
+  error_t send( message_t* ONE p_msg, bool cca ) {
     atomic {
       if (m_state == S_CANCEL) {
         return ECANCEL;
@@ -654,7 +654,10 @@ implementation {
     
     m_tx_power = tx_power;
     
-    call TXFIFO.write( (uint8_t*)header, header->length - 1);
+    {
+      uint8_t tmpLen = header->length - 1;
+      call TXFIFO.write(TCAST(uint8_t * COUNT(tmpLen), header), header->length - 1);
+    }
   }
   
   void signalDone( error_t err ) {