]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/serial/SerialDispatcherP.nc
The big interface switchover for Packet, Send, Receive, and AMSend.
[tinyos-2.x.git] / tos / lib / serial / SerialDispatcherP.nc
index cc85a3f3f530c511019ace6bc721ada7e588077b..5f1a9b6badae105959668534a25d22f25964d16c 100644 (file)
@@ -102,13 +102,21 @@ implementation {
       return EBUSY;
     }
 
-    sendState = SEND_STATE_DATA;
-    sendId = id;
-    sendCancelled = FALSE;
     atomic {
+      sendIndex = call PacketInfo.offset[id]();
+      if (sendIndex > sizeof(message_header_t)) {
+       return ESIZE;
+      }
+      
       sendError = SUCCESS;
       sendBuffer = (uint8_t*)msg;
-      sendIndex = call PacketInfo.offset[id]();
+      sendState = SEND_STATE_DATA;
+      sendId = id;
+      sendCancelled = FALSE;
+      // If something we're starting past the header, something is wrong
+      // Bug fix from John Regehr
+
+
       // sendLen is where in the buffer the packet stops.
       // This is the length of the packet, plus its start point
       sendLen = call PacketInfo.dataLinkLength[id](msg, len) + sendIndex;
@@ -126,21 +134,16 @@ implementation {
     return (sizeof(message_t));
   }
 
-  command void* Send.getPayload[uint8_t id](message_t* m) {
-    return m;
-  }
-
-  command void* Receive.getPayload[uint8_t id](message_t* m, uint8_t* len) {
-    if (len != NULL) {
-      *len = 0;
+  command void* Send.getPayload[uint8_t id](message_t* m, uint8_t len) {
+    if (len > sizeof(message_t)) {
+      return NULL;
+    }
+    else {
+      return m;
     }
-    return m;
-  }
-
-  command uint8_t Receive.payloadLength[uint8_t id](message_t* m) {
-    return 0;
   }
 
+    
   task void signalSendDone(){
     error_t error;