telosb reflexive jamming, beta version, confirmed works in some testing, improvements...
authorrmspeers <rmspeers@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Mon, 18 Apr 2011 23:47:42 +0000 (23:47 +0000)
committerrmspeers <rmspeers@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Mon, 18 Apr 2011 23:47:42 +0000 (23:47 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1003 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFETCCSPI.py
client/goodfet.ccspi
firmware/apps/radios/ccspi.c
firmware/platforms/telosb.h

index 8a216b3..0283d87 100644 (file)
@@ -186,6 +186,11 @@ class GoodFETCCSPI(GoodFET):
         #self.strobe(0x09);
         return;
     
         #self.strobe(0x09);
         return;
     
+    def RF_reflexjam(self):
+        """Place the device into reflexive jamming mode."""
+        data = ""
+        self.writecmd(self.CCSPIAPP,0xA0,len(data),data);
+        return;
 
     def RF_modulated_spectrum(self):
         """Hold a carrier wave on the present frequency."""
 
     def RF_modulated_spectrum(self):
         """Hold a carrier wave on the present frequency."""
index 99dbec2..74ec740 100755 (executable)
@@ -26,10 +26,9 @@ if(len(sys.argv)==1):
     print "%s bsniff [chan]" % sys.argv[0];
     print "%s sniffdissect" % sys.argv[0];
     
     print "%s bsniff [chan]" % sys.argv[0];
     print "%s sniffdissect" % sys.argv[0];
     
-    
-    print;
-    print "%s txtoscount [-i|-r]   TinyOS BlinkToLED" % sys.argv[0];    
-    
+    print "\n%s txtoscount [-i|-r]   TinyOS BlinkToLED" % sys.argv[0];
+    print "%s reflexjam" % sys.argv[0];
+
     sys.exit();
 
 #Initialize FET and set baud rate
     sys.exit();
 
 #Initialize FET and set baud rate
@@ -57,6 +56,20 @@ if(sys.argv[1]=="modulated_spectrum"):
     while(1):
         time.sleep(1);
 
     while(1):
         time.sleep(1);
 
+if(sys.argv[1]=="reflexjam"):
+    client.RF_promiscuity(1);
+    client.RF_autocrc(0);
+    if len(sys.argv)>2:
+        freq=eval(sys.argv[2]);
+        if freq>100:
+            client.RF_setfreq(freq);
+        else:
+            client.RF_setchan(freq);
+    client.CC_RFST_RX();
+    print "Listening as %010x on %i MHz" % (client.RF_getsmac(),
+                                            client.RF_getfreq()/10**6);
+    client.RF_reflexjam();
+
 if(sys.argv[1]=="info"):
     print "Found   %s" % client.identstr();
     print "Freq:   %05f MHz" % (client.RF_getfreq()/(10**6));
 if(sys.argv[1]=="info"):
     print "Found   %s" % client.identstr();
     print "Freq:   %05f MHz" % (client.RF_getfreq()/(10**6));
index 277a440..83dfa37 100644 (file)
@@ -140,7 +140,7 @@ void ccspi_handle_fn( uint8_t const app,
     break;
   case CCSPI_RX:
 #ifdef FIFOP
     break;
   case CCSPI_RX:
 #ifdef FIFOP
-     //Has there been an overflow?
+    //Has there been an overflow?
     if((!FIFO)&&FIFOP){
       debugstr("Clearing overflow");
       CLRSS;
     if((!FIFO)&&FIFOP){
       debugstr("Clearing overflow");
       CLRSS;
@@ -159,7 +159,7 @@ void ccspi_handle_fn( uint8_t const app,
       //ccspitrans8(0x3F|0x40);
       cmddata[0]=0xff; //to be replaced with length
       for(i=0;i<cmddata[0]+2;i++)
       //ccspitrans8(0x3F|0x40);
       cmddata[0]=0xff; //to be replaced with length
       for(i=0;i<cmddata[0]+2;i++)
-       cmddata[i]=ccspitrans8(0xde);
+        cmddata[i]=ccspitrans8(0xde);
       SETSS;
       
       //Flush buffer.
       SETSS;
       
       //Flush buffer.
@@ -186,12 +186,57 @@ void ccspi_handle_fn( uint8_t const app,
     
     txdata(app,verb,0);
     break;
     
     txdata(app,verb,0);
     break;
+
   case CCSPI_REFLEX:
   case CCSPI_REFLEX:
-    debugstr("Coming soon.");
-    txdata(app,verb,0);
+    debugstr("Beta implementation.");
+    cmddata[0] = 1;
+    txdata(app,verb,cmddata[0]+1);
+
+    while(1) {
+        //Wait until a packet is received
+        while(!SFD);
+        //Turn on LED 2 (green) as signal
+           PLED2DIR |= PLED2PIN;
+           PLED2OUT &= ~PLED2PIN;
+
+        //Switch the radio to TX mode
+        CLRSS;  //Drop !SS to begin transaction.
+        ccspitrans8(0x04);
+        SETSS;  //Raise !SS to end transaction.
+        //txdata(app,verb,len);
+
+        //Load the packet.
+        CLRSS;
+        ccspitrans8(CCSPI_TXFIFO);
+        char pkt[15] = {0x0f, 0x01, 0x08, 0x82, 0xff, 0xff, 0xff, 0xff, 0xde, 0xad, 0xbe, 0xef, 0xba, 0xbe, 0xc0};
+        for(i=0;i<pkt[0];i++)
+          ccspitrans8(pkt[i]);
+        SETSS;
+        debugstr("Packet loaded for tx.");
+        //Transmit the packet.
+        CLRSS;
+        ccspitrans8(0x04); //STXON
+        SETSS;
+        //Wait for the pulse on SFD, after which the packet has been sent.
+        //while(!SFD);
+        //while(SFD);
+        msdelay(300);
+        //Flush TX buffer.
+        CLRSS;
+        ccspitrans8(0x09); //SFLUSHTX
+        SETSS;
+
+        //while(SFD);
+        //msdelay(200);
+        //Turn off LED 2 (green) as signal
+           PLED2DIR |= PLED2PIN;
+           PLED2OUT |= PLED2PIN;
+    }
+    //TODO the firmware stops staying in this mode after a while, and stops jamming... need to find a fix!
     break;
     break;
+
   case CCSPI_TX_FLUSH:
   case CCSPI_TX_FLUSH:
-     //Flush the buffer.
+    //Flush the buffer.
     CLRSS;
     ccspitrans8(CCSPI_SFLUSHTX);
     SETSS;
     CLRSS;
     ccspitrans8(CCSPI_SFLUSHTX);
     SETSS;
index 320ad11..51c0722 100644 (file)
 #include <io.h>
 #endif
 
 #include <io.h>
 #endif
 
-//LED on P5.4
+//LED on P5.4 (LED1 red)
 #define PLEDOUT P5OUT
 #define PLEDDIR P5DIR
 #define PLEDPIN BIT4
 #define PLEDOUT P5OUT
 #define PLEDDIR P5DIR
 #define PLEDPIN BIT4
+//LED on P5.5 (LED2 green)
+#define PLED2OUT P5OUT
+#define PLED2DIR P5DIR
+#define PLED2PIN BIT5
+//LED on P5.6 (LED3 blue)
+#define PLED3OUT P5OUT
+#define PLED3DIR P5DIR
+#define PLED3PIN BIT6
 
 
 #define SPIOUT P3OUT
 
 
 #define SPIOUT P3OUT
@@ -49,7 +57,6 @@
 #define CLRSS P4OUT&=~BIT2
 #define DIRSS P4DIR|=BIT2
 
 #define CLRSS P4OUT&=~BIT2
 #define DIRSS P4DIR|=BIT2
 
-
 //Flash CS is P4.4, redefine only for the SPI app.
 #ifdef SPIAPPLICATION
 #undef SETSS
 //Flash CS is P4.4, redefine only for the SPI app.
 #ifdef SPIAPPLICATION
 #undef SETSS
 #define FIFOP (P1IN&BIT0)
 #define FIFO  (P1IN&BIT3)
 
 #define FIFOP (P1IN&BIT0)
 #define FIFO  (P1IN&BIT3)
 
+//GPIO Expansion Pins
+#define GIO0  (P2OUT&BIT0)
+#define GIO0HIGH P2OUT|=BIT0
+#define GIO0LOW P2OUT&=~BIT0
+#define GIO0OUT P2OUT
+#define GIO0DIR P2DIR
+#define GIO0PIN BIT0
+
 // network byte order converters
 #define htons(x) ((((uint16_t)(x) & 0xFF00) >> 8) | \
                                 (((uint16_t)(x) & 0x00FF) << 8))
 // network byte order converters
 #define htons(x) ((((uint16_t)(x) & 0xFF00) >> 8) | \
                                 (((uint16_t)(x) & 0x00FF) << 8))