Promiscuity can be turned off in CCSPI.
[goodfet] / client / GoodFETCCSPI.py
index 36c8bd7..5ea56be 100644 (file)
@@ -132,6 +132,11 @@ class GoodFETCCSPI(GoodFET):
         fsctrl=self.peek(0x18);
         mhz=2048+(fsctrl&0x3ff)
         return mhz*1000000;
+    def RF_setchan(self,channel):
+        if channel < 11 and channel > 26:
+            print "Only 802.15.4 channels 11 to 26 are currently supported.";
+        else:
+            self.RF_setfreq( ( (channel-11)*5 + 2405 ) * 1000000 );
     def RF_getsmac(self):
         """Return the source MAC address."""
         return 0xdeadbeef;
@@ -172,14 +177,74 @@ class GoodFETCCSPI(GoodFET):
         #self.strobe(0x09);
         return;
     
+
+    def RF_modulated_spectrum(self):
+        """Hold a carrier wave on the present frequency."""
+        # print "Don't know how to hold a carrier.";
+        # 33.1 p.55:
+        #  reset chip
+        #  SXOSCON
+        #  set MDMCTRL1.TX_MODE to 3   0x12  3:2 
+        #  STXON                            0x04
+
+        mdmctrl1=self.peek(0x12);
+        #print "mdmctrl1 was %04x" % mdmctrl1;
+        mdmctrl1=mdmctrl1|0x00c0;  #MDMCTRL1.TX_MODE = 3
+        self.poke(0x12, mdmctrl1); #MDMCTRL1
+
+        mdmctrl1=self.peek(0x12);
+        #print "mdmctrl1 is %04x" % mdmctrl1;
+
+        # http://e2e.ti.com/support/low_power_rf/f/155/t/15914.aspx?PageIndex=2
+        #   suggests this
+        self.strobe(0x02);         #STXCAL
+        #print "STXCAL status: %s" % self.status()
+
+        # is this necessary?
+        self.strobe(0x09);         #SFLUSHTX
+        #print "SFLUSHTX status: %s" % self.status()
+
+        self.strobe(0x04);         #STXON
+        #print "STXON status: %s" % self.status()
+
     def RF_carrier(self):
         """Hold a carrier wave on the present frequency."""
-        print "Don't know how to hold a carrier.";
+        # print "Don't know how to hold a carrier.";
+        # 33.1 p.54:
+        #  reset chip
+        #  SXOSCON
+        #  set MDMCTRL1.TX_MODE to 2 or 3   0x12  3:2 
+        #  set DACTST to 0x1800             0x2E
+        #  STXON                            0x04
+
+        mdmctrl1=self.peek(0x12);
+        #print "mdmctrl1 was %04x" % mdmctrl1;
+        mdmctrl1=mdmctrl1|0x0080; 
+        mdmctrl1=mdmctrl1&0x0080;  #MDMCTRL1.TX_MODE = 2
+        self.poke(0x12, mdmctrl1); #MDMCTRL1
+
+        mdmctrl1=self.peek(0x12);
+        #print "mdmctrl1 is %04x" % mdmctrl1;
+
+        self.poke(0x2E, 0x1800);   #DACTST
+        dactst=self.peek(0x2E);
+        #print "dactst is %04x" % dactst;
+
+        # see above for why this is here
+        self.strobe(0x02);         #STXCAL
+        #print "STXCAL status: %s" % self.status()
+        self.strobe(0x09);         #SFLUSHTX
+        #print "SFLUSHTX status: %s" % self.status()
+
+        self.strobe(0x04);         #STXON
+        #print "STXON status: %s" % self.status()
+
     def RF_promiscuity(self,promiscuous=1):
         mdmctrl0=self.peek(0x11);
-        #print "mdmctrl0 was %04x" % mdmctrl0;
-        mdmctrl0=mdmctrl0&(~0x800);
-        #print "mdmctrl0 is now %04x" % mdmctrl0;
+        if promiscuous>0:
+            mdmctrl0=mdmctrl0&(~0x800);
+        else:
+            mdmctrl0=mdmctrl0|0x800;
         self.poke(0x11,mdmctrl0);
         return;
         
@@ -207,3 +272,22 @@ class GoodFETCCSPI(GoodFET):
         choice=choices[len];
         self.poke(0x03,choice);
         self.maclen=len;
+    def printpacket(self,packet):
+        s="";
+        i=0;
+        for foo in packet:
+            s="%s %02x" % (s,ord(foo));
+        print "#%s" % s;
+    def printdissect(self,packet):
+        try:
+            from scapy.all import Dot15d4
+        except ImportError:
+            print "To use packet disection, Scapy must be installed and have the Dot15d4 extension present."
+            print "try: hg clone http://hg.secdev.org/scapy-com";
+            print "     sudo ./setup.py install";
+        self.printpacket(packet);
+        try:
+            scapyd = Dot15d4(packet[1:]);
+            scapyd.show();
+        except:
+            pass;