I think this will add support for decryption of incoming packets, but I might be...
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 20 Sep 2012 13:59:28 +0000 (13:59 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 20 Sep 2012 13:59:28 +0000 (13:59 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1264 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

firmware/apps/radios/ccspi.c
firmware/include/ccspi.h

index 9c6b09c..5d40f11 100644 (file)
@@ -259,6 +259,60 @@ void ccspi_handle_fn( uint8_t const app,
 #else
     debugstr("Can't RX a packet with SFD and FIFOP definitions.");
     txdata(app,NOK,0);
+#endif
+    break;
+  case CCSPI_RXDEC:
+#ifdef FIFOP
+    //Has there been an overflow?
+    if((!FIFO)&&FIFOP){
+      debugstr("Clearing overflow");
+      CLRSS;
+      ccspitrans8(0x08); //SFLUSHRX
+      SETSS;
+      txdata(app,verb,0); //no packet
+      return;
+    }
+
+    //Is there a packet?
+    if(FIFOP&&FIFO){
+      //Wait for completion.
+      while(SFD);
+      
+      //Decrypt the packet.
+      CLRSS; ccspitrans8(CCSPI_SRXDEC); SETSS;
+      
+      //Wait for decryption to complete.
+      while(!FIFO);
+      
+      //Get the packet.
+      CLRSS;
+      ccspitrans8(CCSPI_RXFIFO | 0x40);
+      //ccspitrans8(0x3F|0x40);
+      cmddata[0]=0x20; //to be replaced with length
+      
+      
+      /* This reads too far on some CC2420 revisions, but on others it
+        works fine.  It probably has to do with whether FIFO drops
+        before or after the SPI clocking.
+        
+        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++)
+        cmddata[i]=ccspitrans8(0x00);
+      SETSS;
+      
+      //Only should transmit a packet if the length is legal.
+      if(cmddata[0]&0x80) i=0;
+      txdata(app,verb,i);
+    }else{
+      //No packet.
+      txdata(app,verb,0);
+    }
+#else
+    debugstr("Can't RX a packet with SFD and FIFOP definitions.");
+    txdata(app,NOK,0);
 #endif
     break;
   case CCSPI_RX_FLUSH:
index b831bf3..216a496 100644 (file)
@@ -14,6 +14,8 @@
 
 //Grab a packet, if one is available.
 #define CCSPI_RX 0x80
+//Grab and decrypt a packet, if one is available.
+#define CCSPI_RXDEC 0x90
 //Send a packet.
 #define CCSPI_TX 0x81
 //Flush RX
@@ -41,6 +43,8 @@
 #define CCSPI_RXFIFO  0x3F
 #define CCSPI_SFLUSHRX 0x08
 #define CCSPI_SFLUSHTX 0x09
+#define CCSPI_SRXDEC 0x0C
+#define CCSPI_STXENC 0x0D
 
 extern app_t const ccspi_app;