]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/cc2420/lowpan/CC2420TinyosNetworkP.nc
wiring the wrong resource
[tinyos-2.x.git] / tos / chips / cc2420 / lowpan / CC2420TinyosNetworkP.nc
index 8a2223953d4be0e1acb83df1b6f9f0bee40f1768..8e8061a9f8612aa70623baf49ec567b37092d66b 100644 (file)
@@ -65,22 +65,22 @@ implementation {
 
   enum {
     OWNER_NONE = 0xff,
-    TINYOS_N_NETWORKS = uniqueCount(IEEE154_SEND_CLIENT),
+    TINYOS_N_NETWORKS = uniqueCount(RADIO_SEND_RESOURCE),
   } state;
 
   norace uint8_t resource_owner = OWNER_NONE, next_owner;
 
   command error_t ActiveSend.send(message_t* msg, uint8_t len) {
     call CC2420Packet.setNetwork(msg, TINYOS_6LOWPAN_NETWORK_ID);
-    return call BareSend.send(msg, len + AM_OVERHEAD);
+    return call SubSend.send(msg, len);
   }
 
   command error_t ActiveSend.cancel(message_t* msg) {
-    return call BareSend.cancel(msg);
+    return call SubSend.cancel(msg);
   }
 
   command uint8_t ActiveSend.maxPayloadLength() {
-    return call BareSend.maxPayloadLength() - AM_OVERHEAD;
+    return call SubSend.maxPayloadLength();
   }
 
   command void* ActiveSend.getPayload(message_t* msg, uint8_t len) {
@@ -93,7 +93,7 @@ implementation {
 
   /***************** Send Commands ****************/
   command error_t BareSend.send(message_t* msg, uint8_t len) {
-    return call SubSend.send(msg, len);
+    return call SubSend.send(msg, len - AM_OVERHEAD);
   }
 
   command error_t BareSend.cancel(message_t* msg) {
@@ -101,11 +101,17 @@ implementation {
   }
 
   command uint8_t BareSend.maxPayloadLength() {
-    return call SubSend.maxPayloadLength();
+    return call SubSend.maxPayloadLength() + AM_OVERHEAD;
   }
 
   command void* BareSend.getPayload(message_t* msg, uint8_t len) {
-    return call SubSend.getPayload(msg, len);
+#ifndef TFRAMES_ENABLED                      
+    cc2420_header_t *hdr = call CC2420PacketBody.getHeader(msg);
+    return &hdr->network;
+#else
+    // you really can't use BareSend with TFRAMES
+#error "BareSend is not supported with TFRAMES: only the ActiveMessage layer is supported"
+#endif
   }
   
   /***************** SubSend Events *****************/
@@ -116,19 +122,23 @@ implementation {
       signal BareSend.sendDone(msg, error);
     }
   }
-  
+
   /***************** SubReceive Events ***************/
   event message_t *SubReceive.receive(message_t *msg, void *payload, uint8_t len) {
 
     if(!(call CC2420PacketBody.getMetadata(msg))->crc) {
       return msg;
     }
-
+#ifndef TFRAMES_ENABLED
     if (call CC2420Packet.getNetwork(msg) == TINYOS_6LOWPAN_NETWORK_ID) {
-      return signal ActiveReceive.receive(msg, msg->data, len - AM_OVERHEAD);
+      return signal ActiveReceive.receive(msg, payload, len);
     } else {
-      return signal BareReceive.receive(msg, payload, len);
+      cc2420_header_t *hdr = call CC2420PacketBody.getHeader(msg);
+      return signal BareReceive.receive(msg, &hdr->network, len + AM_OVERHEAD);
     }
+#else
+    return signal ActiveReceive.receive(msg, payload, len);
+#endif
   }
 
   /***************** Resource ****************/
@@ -159,6 +169,7 @@ implementation {
     post grantTask();
 
     if (TINYOS_N_NETWORKS > 1) {
+
       return call Queue.enqueue(id);
     } else {
       if (id == resource_owner) {