updated some new experiment methods. you can now fuzz on all ids randomly as well...
[goodfet] / firmware / apps / radios / ccspi.c
index a124b53..dd70a3d 100644 (file)
@@ -222,8 +222,6 @@ void ccspi_handle_fn( uint8_t const app,
   unsigned long i;
   u8 j;
 
-  //debugstr("Chipcon SPI handler.");
-
   switch(verb){
   case PEEK:
     cmddata[0]|=0x40; //Set the read bit.
@@ -258,20 +256,43 @@ void ccspi_handle_fn( uint8_t const app,
                  );
     txdata(app,verb,0);
     break;
+  case CCSPI_REPEAT_RX:
+
+    /* CCSPI_REPEAT_RX repeatedly requests new packets, forwarding
+       them to the server without waiting for the next request.  This
+       allows for sniffing of packets that would otherwise overflow
+       the buffer.
+    */
+
+    //debugstr("Looping CCSPI_RX.");
+    
+    //Loop forever in RX mode.
+    while(1){
+      ccspi_handle_fn(app,CCSPI_RX,0);
+    }
+    break;
   case CCSPI_RX:
 #ifdef FIFOP
     //Has there been an overflow?
+    
     if((!FIFO)&&FIFOP){
       debugstr("Clearing overflow");
       CLRSS;
       ccspitrans8(0x08); //SFLUSHRX
+      ccspitrans8(0x08); //SFLUSHRX
       SETSS;
       txdata(app,verb,0); //no packet
       return;
     }
-
+        
+    /* Uncomment this to wait around a bit for the packet.
+       Might reduce dropped packet count.
+    i=1000; //Number of tries.
+    while(!(FIFOP&&FIFO) && i--);
+    */
+    
     //Is there a packet?
-    if(FIFOP&&FIFO){
+    if (FIFOP && FIFO){
       //Wait for completion.
       while(SFD);
       
@@ -289,8 +310,8 @@ void ccspi_handle_fn( uint8_t const app,
         A software fix is to reset the CC2420 between packets.  This
         works, but a better solution is desired.
       */
-      for(i=0;i<cmddata[0]+1;i++)
-      //for(i=0;FIFO && i<0x80;i++)
+      //for(i=0;i<cmddata[0]+1;i++)
+      for(i=0;FIFO && i<0x80;i++)
         cmddata[i]=ccspitrans8(0x00);
       SETSS;
 
@@ -301,9 +322,10 @@ void ccspi_handle_fn( uint8_t const app,
       */
       
       //Only transmit a packet if the length is legal.
-      if(cmddata[0]&0x80) i=0;
+      if(cmddata[0]&0x80 || cmddata[0]==0) i=0;
       txdata(app,verb,i);
     }else{
+      
       //No packet.
       txdata(app,verb,0);
     }