]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/net/Deluge/DelugeManagerP.nc
Merge of the latest Deluge T2.
[tinyos-2.x.git] / tos / lib / net / Deluge / DelugeManagerP.nc
index 15dbeedc0989f9c01178414f57cebba93e275347..4a25388fa3afd3f2973816557ececb39a3204fcb 100644 (file)
@@ -24,6 +24,8 @@
  * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
  */
 
+#include "imgNum2volumeId.h"
+
 generic module DelugeManagerP()
 {
   uses {
@@ -71,9 +73,10 @@ implementation
   {
     SerialReqPacket *request = (SerialReqPacket *)payload;
     memset(&delugeCmd, 0, sizeof(DelugeCmd));
-
     call stop();
     delugeCmd.type = request->cmd;
+    // Converts the image number that the user wants to the real image number
+    request->imgNum = imgNum2volumeId(request->imgNum);
 
     switch (request->cmd) {
     case DELUGE_CMD_STOP:
@@ -84,7 +87,9 @@ implementation
       break;
     case DELUGE_CMD_ONLY_DISSEMINATE:
     case DELUGE_CMD_DISSEMINATE_AND_REPROGRAM:
-      if (call Resource.immediateRequest() == SUCCESS) {
+      if (request->imgNum != NON_DELUGE_VOLUME &&
+         (call Resource.isOwner() || 
+          call Resource.immediateRequest() == SUCCESS)) {
        call DelugeMetadata.read(request->imgNum);
       } else {
        sendReply(FAIL);
@@ -92,6 +97,10 @@ implementation
       break;
     case DELUGE_CMD_REPROGRAM:
     case DELUGE_CMD_REBOOT:
+      if (request->imgNum == NON_DELUGE_VOLUME) {
+       sendReply(FAIL);
+       break;
+      }
       delugeCmd.imgNum = request->imgNum;
       call DelayTimer.startOneShot(1024);
       sendReply(SUCCESS);