[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/Deluge DelugeMsgs.h, 1.3, 1.4 DelugePageTransfer.h, 1.3, 1.4 DelugePageTransferP.nc, 1.3, 1.4 DelugeStorageC.nc, 1.3, 1.4 DelugeStorageP.nc, 1.2, 1.3 ObjectTransferP.nc, 1.6, 1.7

Razvan Musaloiu-E. razvanm at users.sourceforge.net
Sat Dec 22 00:29:32 PST 2007


Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/net/Deluge
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv26823

Modified Files:
	DelugeMsgs.h DelugePageTransfer.h DelugePageTransferP.nc 
	DelugeStorageC.nc DelugeStorageP.nc ObjectTransferP.nc 
Log Message:
Add image verification at boot time. To make this possible I had to reintroduce the old meaning for some DELUGE_ constants. The ones with a new meaning are prefixed with DELUGET2 instead of DELUGE. 


Index: DelugeMsgs.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/Deluge/DelugeMsgs.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DelugeMsgs.h	10 Jul 2007 01:17:40 -0000	1.3
--- DelugeMsgs.h	22 Dec 2007 08:29:29 -0000	1.4
***************
*** 55,59 ****
    nx_object_id_t objid;
    nx_page_num_t  pgNum;
!   nx_uint8_t     requestedPkts[DELUGE_PKT_BITVEC_SIZE];
  } DelugeReqMsg;
  
--- 55,59 ----
    nx_object_id_t objid;
    nx_page_num_t  pgNum;
!   nx_uint8_t     requestedPkts[DELUGET2_PKT_BITVEC_SIZE];
  } DelugeReqMsg;
  
***************
*** 62,66 ****
    nx_page_num_t  pgNum;
    nx_uint8_t     pktNum;
!   nx_uint8_t     data[DELUGE_PKT_PAYLOAD_SIZE];
  } DelugeDataMsg;
  
--- 62,66 ----
    nx_page_num_t  pgNum;
    nx_uint8_t     pktNum;
!   nx_uint8_t     data[DELUGET2_PKT_PAYLOAD_SIZE];
  } DelugeDataMsg;
  

Index: DelugePageTransfer.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/Deluge/DelugePageTransfer.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DelugePageTransfer.h	2 Jun 2007 00:09:14 -0000	1.3
--- DelugePageTransfer.h	22 Dec 2007 08:29:30 -0000	1.4
***************
*** 54,61 ****
  
  enum {
!   DELUGE_PKT_PAYLOAD_SIZE  = TOSH_DATA_LENGTH - sizeof(nx_object_id_t) - sizeof(nx_page_num_t) - sizeof(nx_uint8_t),
!   DELUGE_BYTES_PER_PAGE    = 1024,
!   DELUGE_PKTS_PER_PAGE     = ((DELUGE_BYTES_PER_PAGE - 1) / DELUGE_PKT_PAYLOAD_SIZE) + 1,
!   
    DELUGE_VERSION                    = 2,
    DELUGE_MAX_ADV_PERIOD_LOG2        = 22,
--- 54,66 ----
  
  enum {
!   DELUGET2_PKT_PAYLOAD_SIZE  = TOSH_DATA_LENGTH - sizeof(nx_object_id_t) - sizeof(nx_page_num_t) - sizeof(nx_uint8_t),
!   DELUGET2_BYTES_PER_PAGE    = 1024,
!   DELUGET2_PKTS_PER_PAGE     = ((DELUGET2_BYTES_PER_PAGE - 1) / DELUGET2_PKT_PAYLOAD_SIZE) + 1,
!   DELUGET2_PKT_BITVEC_SIZE   = (((DELUGET2_PKTS_PER_PAGE - 1) / 8) + 1),
! 
!   DELUGE_PKT_PAYLOAD_SIZE           = 23,
!   DELUGE_PKTS_PER_PAGE              = 48,
!   DELUGE_BYTES_PER_PAGE             = (DELUGE_PKTS_PER_PAGE*DELUGE_PKT_PAYLOAD_SIZE),
! 
    DELUGE_VERSION                    = 2,
    DELUGE_MAX_ADV_PERIOD_LOG2        = 22,
***************
*** 71,75 ****
    DELUGE_MAX_REQ_DELAY              = (0x1L << (DELUGE_MIN_ADV_PERIOD_LOG2 - 1)),
    DELUGE_NACK_TIMEOUT               = (DELUGE_MAX_REQ_DELAY >> 0x1),
-   DELUGE_PKT_BITVEC_SIZE            = (((DELUGE_PKTS_PER_PAGE - 1) / 8) + 1),
    DELUGE_MAX_IMAGE_SIZE             = (128L * 1024L),
    DELUGE_MAX_PAGES                  = 128,
--- 76,79 ----

Index: DelugePageTransferP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/Deluge/DelugePageTransferP.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DelugePageTransferP.nc	13 Sep 2007 23:10:18 -0000	1.3
--- DelugePageTransferP.nc	22 Dec 2007 08:29:30 -0000	1.4
***************
*** 57,62 ****
  {
    // send/receive page buffers, and state variables for buffers
!   uint8_t pktsToSend[DELUGE_PKT_BITVEC_SIZE];    // bit vec of packets to send
!   uint8_t pktsToReceive[DELUGE_PKT_BITVEC_SIZE]; // bit vec of packets to receive
  
    DelugeDataMsg rxQueue[DELUGE_QSIZE];
--- 57,62 ----
  {
    // send/receive page buffers, and state variables for buffers
!   uint8_t pktsToSend[DELUGET2_PKT_BITVEC_SIZE];    // bit vec of packets to send
!   uint8_t pktsToReceive[DELUGET2_PKT_BITVEC_SIZE]; // bit vec of packets to receive
  
    DelugeDataMsg rxQueue[DELUGE_QSIZE];
***************
*** 134,138 ****
      else {
        uint32_t i;
!       for (i = 0; i < DELUGE_PKT_BITVEC_SIZE; i++) {
          pReqMsg->requestedPkts[i] = pktsToReceive[i];
        }
--- 134,138 ----
      else {
        uint32_t i;
!       for (i = 0; i < DELUGET2_PKT_BITVEC_SIZE; i++) {
          pReqMsg->requestedPkts[i] = pktsToReceive[i];
        }
***************
*** 147,152 ****
    storage_addr_t calcOffset(page_num_t pgNum, uint8_t pktNum)
    {
!     return (storage_addr_t)pgNum * (storage_addr_t)DELUGE_BYTES_PER_PAGE
!             + (uint16_t)pktNum * (uint16_t)DELUGE_PKT_PAYLOAD_SIZE;
              //+ DELUGE_METADATA_SIZE;
    }
--- 147,152 ----
    storage_addr_t calcOffset(page_num_t pgNum, uint8_t pktNum)
    {
!     return (storage_addr_t)pgNum * (storage_addr_t)DELUGET2_BYTES_PER_PAGE
!             + (uint16_t)pktNum * (uint16_t)DELUGET2_PKT_PAYLOAD_SIZE;
              //+ DELUGE_METADATA_SIZE;
    }
***************
*** 174,178 ****
      }
      
!     if (call BitVecUtils.indexOf(&nextPkt, pDataMsg->pktNum, pktsToSend, DELUGE_PKTS_PER_PAGE) != SUCCESS) {
        // no more packets to send
        //dbg(DBG_USR1, "DELUGE: SEND_DONE\n");
--- 174,178 ----
      }
      
!     if (call BitVecUtils.indexOf(&nextPkt, pDataMsg->pktNum, pktsToSend, DELUGET2_PKTS_PER_PAGE) != SUCCESS) {
        // no more packets to send
        //dbg(DBG_USR1, "DELUGE: SEND_DONE\n");
***************
*** 180,184 ****
      } else {
        pDataMsg->pktNum = nextPkt;
!       if (call BlockRead.read[imgNum](calcOffset(pageToSend, nextPkt), pDataMsg->data, DELUGE_PKT_PAYLOAD_SIZE) != SUCCESS) {
          call Timer.startOneShot(DELUGE_FAILED_SEND_DELAY);
        }
--- 180,184 ----
      } else {
        pDataMsg->pktNum = nextPkt;
!       if (call BlockRead.read[imgNum](calcOffset(pageToSend, nextPkt), pDataMsg->data, DELUGET2_PKT_PAYLOAD_SIZE) != SUCCESS) {
          call Timer.startOneShot(DELUGE_FAILED_SEND_DELAY);
        }
***************
*** 216,220 ****
  	uint32_t i;
  	changeState(S_IDLE);
! 	for (i = 0; i < DELUGE_PKT_BITVEC_SIZE; i++) {
            pktsToSend[i] = 0x00;
  	}
--- 216,220 ----
  	uint32_t i;
  	changeState(S_IDLE);
! 	for (i = 0; i < DELUGET2_PKT_BITVEC_SIZE; i++) {
            pktsToSend[i] = 0x00;
  	}
***************
*** 232,236 ****
    {
      if(call BlockWrite.write[imgNum](calcOffset(rxQueue[head].pgNum, rxQueue[head].pktNum),
!                             rxQueue[head].data, DELUGE_PKT_PAYLOAD_SIZE) != SUCCESS) {
        size = 0;
      }
--- 232,236 ----
    {
      if(call BlockWrite.write[imgNum](calcOffset(rxQueue[head].pgNum, rxQueue[head].pktNum),
!                             rxQueue[head].data, DELUGET2_PKT_PAYLOAD_SIZE) != SUCCESS) {
        size = 0;
      }
***************
*** 246,253 ****
      workingPgNum = DELUGE_INVALID_PGNUM;
      
!     for (i = 0; i < DELUGE_PKT_BITVEC_SIZE; i++) {
        pktsToReceive[i] = 0x00;
      }
!     for (i = 0; i < DELUGE_PKT_BITVEC_SIZE; i++) {
        pktsToSend[i] = 0x00;
      }
--- 246,253 ----
      workingPgNum = DELUGE_INVALID_PGNUM;
      
!     for (i = 0; i < DELUGET2_PKT_BITVEC_SIZE; i++) {
        pktsToReceive[i] = 0x00;
      }
!     for (i = 0; i < DELUGET2_PKT_BITVEC_SIZE; i++) {
        pktsToSend[i] = 0x00;
      }
***************
*** 269,273 ****
      workingPgNum = new_pgNum;
      
!     for (i = 0; i < DELUGE_PKT_BITVEC_SIZE; i++) {
        pktsToReceive[i] = 0xFF;
      }
--- 269,273 ----
      workingPgNum = new_pgNum;
      
!     for (i = 0; i < DELUGET2_PKT_BITVEC_SIZE; i++) {
        pktsToReceive[i] = 0xFF;
      }
***************
*** 347,351 ****
             && pgNum == pageToSend)) {
        // take union of packet bit vectors
!       for (i = 0; i < DELUGE_PKT_BITVEC_SIZE; i++) {
          pktsToSend[i] |= rxReqMsg->requestedPkts[i];
        }
--- 347,351 ----
             && pgNum == pageToSend)) {
        // take union of packet bit vectors
!       for (i = 0; i < DELUGET2_PKT_BITVEC_SIZE; i++) {
          pktsToSend[i] |= rxReqMsg->requestedPkts[i];
        }
***************
*** 461,465 ****
      if (error != SUCCESS) {
        uint32_t i;
!       for (i = 0; i < DELUGE_PKT_BITVEC_SIZE; i++) {
          pktsToReceive[i] = 0xFF;
        }
--- 461,465 ----
      if (error != SUCCESS) {
        uint32_t i;
!       for (i = 0; i < DELUGET2_PKT_BITVEC_SIZE; i++) {
          pktsToReceive[i] = 0xFF;
        }
***************
*** 473,477 ****
      size--;
      
!     if (call BitVecUtils.indexOf(&tmp, 0, pktsToReceive, DELUGE_PKTS_PER_PAGE) != SUCCESS) {
  // For collecting stats
  //call StatsCollector.endRecvPageTransTime(publisher_addr);
--- 473,477 ----
      size--;
      
!     if (call BitVecUtils.indexOf(&tmp, 0, pktsToReceive, DELUGET2_PKTS_PER_PAGE) != SUCCESS) {
  // For collecting stats
  //call StatsCollector.endRecvPageTransTime(publisher_addr);

Index: DelugeStorageC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/Deluge/DelugeStorageC.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DelugeStorageC.nc	20 Dec 2007 02:31:40 -0000	1.3
--- DelugeStorageC.nc	22 Dec 2007 08:29:30 -0000	1.4
***************
*** 35,39 ****
      interface DelugeMetadata;
      
!     interface Notify<uint8_t>;
    }
  }
--- 35,39 ----
      interface DelugeMetadata;
      
!     interface Notify<uint8_t> as ReadyNotify;
    }
  }
***************
*** 93,96 ****
    DelugeStorageP.Boot -> MainC;
    
!   Notify = DelugeStorageP.Notify;
  }
--- 93,96 ----
    DelugeStorageP.Boot -> MainC;
    
!   ReadyNotify = DelugeStorageP.ReadyNotify;
  }

Index: DelugeStorageP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/Deluge/DelugeStorageP.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DelugeStorageP.nc	2 Jun 2007 00:09:14 -0000	1.2
--- DelugeStorageP.nc	22 Dec 2007 08:29:30 -0000	1.3
***************
*** 26,29 ****
--- 26,30 ----
  
  #include "Deluge.h"
+ #include "DelugePageTransfer.h"
  
  module DelugeStorageP
***************
*** 46,50 ****
      interface DelugeMetadata;
      
!     interface Notify<uint8_t>;
    }
  }
--- 47,51 ----
      interface DelugeMetadata;
      
!     interface Notify<uint8_t> as ReadyNotify;
    }
  }
***************
*** 53,64 ****
  {
    enum {
!     S_INIT,
      S_READY,
    };
  
!   uint8_t state = S_INIT;
!   uint8_t last_init_img_num = 0;
    DelugeImgDesc imgDesc[DELUGE_NUM_VOLUMES];
  
    event void Boot.booted()
    {
--- 54,90 ----
  {
    enum {
!     S_READ_META,
!     S_READ_CRC,
!     S_CRC,
      S_READY,
    };
  
!   uint8_t state;
!   uint8_t current_image;
!   uint8_t current_page;
!   uint16_t current_crc;
    DelugeImgDesc imgDesc[DELUGE_NUM_VOLUMES];
  
+   void nextImage()
+   {
+     if (current_image < DELUGE_NUM_VOLUMES) {
+       state = S_READ_META;
+       call SubBlockRead.read[current_image](0, &(imgDesc[current_image]), sizeof(DelugeImgDesc));
+     } else {
+       signal ReadyNotify.notify(SUCCESS);
+       state = S_READY;
+     }
+   }  
+ 
+   uint32_t calcCrcAddr()
+   {
+     return DELUGE_METADATA_SIZE + current_page * sizeof(uint16_t);
+   }
+ 
+   uint32_t calcPageAddr()
+   {
+     return DELUGE_METADATA_SIZE + current_page * DELUGE_BYTES_PER_PAGE;
+   }
+ 
    event void Boot.booted()
    {
***************
*** 75,83 ****
      }
      
!     // Reads image descriptions
!     state = S_INIT;
!     if (DELUGE_NUM_VOLUMES > 0) {
!       call SubBlockRead.read[last_init_img_num](0, &(imgDesc[last_init_img_num]), sizeof(DelugeImgDesc));
!     }
    }
  
--- 101,112 ----
      }
      
!     // We are going to iterate over all the images and verify their
!     // integrity. For each image we first read the metadata to find
!     // the number of pages and then iterate over all of them, compute
!     // the CRC and check it against the corresponding value from the CRCs
!     // block.
!     state = S_READ_META;
!     current_image = 0;
!     nextImage();
    }
  
***************
*** 106,122 ****
    event void SubBlockRead.readDone[uint8_t img_num](storage_addr_t addr, void* buf, storage_len_t len, error_t error)
    {
!     if (state == S_READY) {
        signal BlockRead.readDone[img_num](addr, buf, len, error);
!     } else {
!       // Continues reading image descriptions
        if (error == SUCCESS) {
!         last_init_img_num++;
!         if (last_init_img_num >= DELUGE_NUM_VOLUMES) {
!           signal Notify.notify(SUCCESS);
!           state = S_READY;
!         } else {
!           call SubBlockRead.read[last_init_img_num](0, &(imgDesc[last_init_img_num]), sizeof(DelugeImgDesc));
!         }
        }
      }
    }
--- 135,163 ----
    event void SubBlockRead.readDone[uint8_t img_num](storage_addr_t addr, void* buf, storage_len_t len, error_t error)
    {
!     switch (state) {
!     case S_READY:
        signal BlockRead.readDone[img_num](addr, buf, len, error);
!       break;
!     case S_READ_META:
        if (error == SUCCESS) {
! 	if (imgDesc[current_image].uid != DELUGE_INVALID_UID) {
! 	  current_page = 0;
! 	  state = S_READ_CRC;
! 	  call SubBlockRead.read[current_image](calcCrcAddr(), &current_crc, sizeof(current_crc));
! 	} else {
! 	  current_image++;
! 	  nextImage();
! 	}
!       }      
!       break;
!     case S_READ_CRC:
!       state = S_CRC;
!       if (current_page == 0) {
! 	call SubBlockRead.computeCrc[current_image](calcPageAddr() + DELUGE_CRC_BLOCK_SIZE, 
! 						    DELUGE_BYTES_PER_PAGE - DELUGE_CRC_BLOCK_SIZE, 0);
!       } else {
! 	call SubBlockRead.computeCrc[current_image](calcPageAddr(), DELUGE_BYTES_PER_PAGE, 0);
        }
+       break;
      }
    }
***************
*** 124,128 ****
    event void SubBlockRead.computeCrcDone[uint8_t img_num](storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error)
    {
!     signal BlockRead.computeCrcDone[img_num](addr, len, crc, error);
    }
  
--- 165,188 ----
    event void SubBlockRead.computeCrcDone[uint8_t img_num](storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error)
    {
!     switch (state) {
!     case S_READY:
!       signal BlockRead.computeCrcDone[img_num](addr, len, crc, error);
!       break;
!     case S_CRC:
!       if (crc != current_crc) {
! 	// invalidate the image by erasing it
! 	call SubBlockWrite.erase[current_image]();
!       } else {
! 	current_page++;
! 	if (current_page < imgDesc[current_image].numPgs) {
! 	  state = S_READ_CRC;
! 	  call SubBlockRead.read[current_image](calcCrcAddr(), &current_crc, sizeof(current_crc));
! 	} else {
! 	  current_image++;
! 	  nextImage();
! 	}
!       }
!       break;
!     }
    }
  
***************
*** 168,173 ****
        imgDesc[img_num].size = 0;
      }
!     
!     signal BlockWrite.eraseDone[img_num](error);
    }
  
--- 228,241 ----
        imgDesc[img_num].size = 0;
      }
! 
!     switch (state) {
!     case S_READY:
!       signal BlockWrite.eraseDone[img_num](error);
!       break;
!     case S_CRC:
!       current_image++;
!       nextImage();
!       break;
!     }
    }
  
***************
*** 207,212 ****
    default command storage_len_t SubBlockRead.getSize[uint8_t img_num]() { return 0; }
    
!   command error_t Notify.enable() { return SUCCESS; }
!   command error_t Notify.disable() { return SUCCESS; }
    
  #if defined(PLATFORM_TELOSB)
--- 275,280 ----
    default command storage_len_t SubBlockRead.getSize[uint8_t img_num]() { return 0; }
    
!   command error_t ReadyNotify.enable() { return SUCCESS; }
!   command error_t ReadyNotify.disable() { return SUCCESS; }
    
  #if defined(PLATFORM_TELOSB)

Index: ObjectTransferP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/Deluge/ObjectTransferP.nc,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ObjectTransferP.nc	13 Sep 2007 23:10:18 -0000	1.6
--- ObjectTransferP.nc	22 Dec 2007 08:29:30 -0000	1.7
***************
*** 171,175 ****
      state = S_INITIALIZING_PUB;
      curObjDesc.objid = new_objid;
!     curObjDesc.numPgs = ((new_size - 1) / DELUGE_BYTES_PER_PAGE) + 1;   // Number of pages to transmit
      curObjDesc.numPgsComplete = curObjDesc.numPgs;   // Publisher doesn't really care about this
      curObjDesc.crc = call Crc.crc16(&curObjDesc, sizeof(object_id_t) + sizeof(page_num_t));
--- 171,175 ----
      state = S_INITIALIZING_PUB;
      curObjDesc.objid = new_objid;
!     curObjDesc.numPgs = ((new_size - 1) / DELUGET2_BYTES_PER_PAGE) + 1;   // Number of pages to transmit
      curObjDesc.numPgsComplete = curObjDesc.numPgs;   // Publisher doesn't really care about this
      curObjDesc.crc = call Crc.crc16(&curObjDesc, sizeof(object_id_t) + sizeof(page_num_t));
***************
*** 192,196 ****
      state = S_INITIALIZING_RECV;
      curObjDesc.objid = cont_receive_new_objid;
!     curObjDesc.numPgs = ((cont_receive_new_size - 1) / DELUGE_BYTES_PER_PAGE) + 1;   // Number of pages to receive
      curObjDesc.numPgsComplete = 0;
      curObjDesc.crc = call Crc.crc16(&curObjDesc, sizeof(object_id_t) + sizeof(page_num_t));
--- 192,196 ----
      state = S_INITIALIZING_RECV;
      curObjDesc.objid = cont_receive_new_objid;
!     curObjDesc.numPgs = ((cont_receive_new_size - 1) / DELUGET2_BYTES_PER_PAGE) + 1;   // Number of pages to receive
      curObjDesc.numPgsComplete = 0;
      curObjDesc.crc = call Crc.crc16(&curObjDesc, sizeof(object_id_t) + sizeof(page_num_t));



More information about the Tinyos-2-commits mailing list