X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2Fgoodfet.ccspi;h=f8d10bdf656b99f7a5288fe11eb92e7008c56a78;hp=74ec740701bde8f3784adb4b90261aab1ba7f26a;hb=0c3db8ce9f40190ec063347e21ed382d5486cb67;hpb=ed8fe6653a821e893857c9491d576b8c6dee8dad diff --git a/client/goodfet.ccspi b/client/goodfet.ccspi index 74ec740..f8d10bd 100755 --- a/client/goodfet.ccspi +++ b/client/goodfet.ccspi @@ -2,6 +2,7 @@ #GoodFET Chipcon SPI Client # (C) 2011 Travis Goodspeed +# Additions 2011-2012 Ryan Speers ryan@rmspeers.com #N.B., #Might be CC2420 Specific @@ -22,12 +23,16 @@ if(len(sys.argv)==1): print "%s txtest" % sys.argv[0]; print "\n%s rssi" % sys.argv[0]; + print "%s spectrum" % sys.argv[0]; + print "%s spectrumcsv" % sys.argv[0]; + + print "\n%s surf" % sys.argv[0]; print "%s sniff [chan]" % sys.argv[0]; print "%s bsniff [chan]" % sys.argv[0]; print "%s sniffdissect" % sys.argv[0]; print "\n%s txtoscount [-i|-r] TinyOS BlinkToLED" % sys.argv[0]; - print "%s reflexjam" % sys.argv[0]; + print "%s reflexjam [channel=11] [delay=0]" % sys.argv[0]; sys.exit(); @@ -56,7 +61,8 @@ if(sys.argv[1]=="modulated_spectrum"): while(1): time.sleep(1); -if(sys.argv[1]=="reflexjam"): +if(sys.argv[1]=="reflexjam" or sys.argv[1]=="reflexjamack"): + #Setup the radio to listen promiscously on a frequency client.RF_promiscuity(1); client.RF_autocrc(0); if len(sys.argv)>2: @@ -65,10 +71,21 @@ if(sys.argv[1]=="reflexjam"): client.RF_setfreq(freq); else: client.RF_setchan(freq); + duration=0; + if len(sys.argv)>3: + duration=eval(sys.argv[3]); client.CC_RFST_RX(); - print "Listening as %010x on %i MHz" % (client.RF_getsmac(), - client.RF_getfreq()/10**6); - client.RF_reflexjam(); + print "Reflexively jamming on %i MHz" % (client.RF_getfreq()/10**6); + #Now we let the firmware take over, watching for packets and jamming them. + #Standard reflexive jam is done with duration=0. + #To selectively jam packets that are above a certain length, set duration + # to the number of milliseconds needed to jam frames of that length. + # Api-Do project has script available to tune/test this duration. + # code.google.com/p/zigbeesecurity (rmspeers) + if sys.argv[1]=="reflexjam": + client.RF_reflexjam(duration); + elif sys.argv[1]=="reflexjamack": + client.RF_reflexjam_autoack(); if(sys.argv[1]=="info"): print "Found %s" % client.identstr(); @@ -105,15 +122,80 @@ if(sys.argv[1]=="rssi"): for foo in range(0,rssi>>2): string=("%s."%string); print "%02x %04i %s" % (rssi,rssi, string); +if(sys.argv[1]=="spectrum"): + for chan in range(2400000000,2480000000,5000000): + client.RF_setfreq(chan); + #print "Listening on %f MHz." % (client.RF_getfreq()/10.0**6); + + client.strobe(0x02); #Calibrate + #time.sleep(0.01); + + maxrssi=0; + for foo in range(1,10): + client.CC_RFST_RX(); + rssi=client.RF_getrssi(); + maxrssi=max(rssi,maxrssi); + string=""; + for foo in range(50,rssi): + string=("%s."%string); + print "%04i %i %s" % (client.RF_getfreq()/10.0**6,rssi, string); +if(sys.argv[1]=="spectrumcsv"): + start=time.time(); + while 1: + for freq in range(2400000000,2480000000,1000000): + client.RF_setfreq(freq); + + client.strobe(0x02); #Calibrate + client.CC_RFST_RX(); + rssi=client.RF_getrssi(); + + print "%f %i %3i" % ( + time.time()-start, + client.RF_getfreq()/10.0**6, + rssi); + sys.stdout.flush(); + +if sys.argv[1]=="surf": + print "Scanning channels [11,26]."; + + #Promiscuous mode. + client.RF_promiscuity(1); + client.RF_autocrc(1); + + chan=11; + if len(sys.argv)>2: + chan=eval(sys.argv[2]); + + client.CC_RFST_RX(); + + #Now we're ready to get packets. + while 1: + if chan>26: chan=11; + + client.setup(); #Really oughtn't be necessary, but can't hurt. + client.RF_setchan(chan); + + packet=None; + lasttime=time.time(); + while packet==None and time.time()-lasttime<0.5: + packet=client.RF_rxpacket(); + if packet!=None: + client.printpacket(packet=packet, + prefix=("%02d: "%chan)); + sys.stdout.flush(); + chan=chan+1; + if(sys.argv[1]=="sniff" or sys.argv[1]=="sniffdissect"): #Promiscuous mode. client.RF_promiscuity(1); - client.RF_autocrc(0); + client.RF_autocrc(1); if len(sys.argv)>2: freq=eval(sys.argv[2]); - if freq>100: + if freq>3000: client.RF_setfreq(freq); + elif freq>100: + client.RF_setfreq(freq*1000000); else: client.RF_setchan(freq); client.CC_RFST_RX(); @@ -121,6 +203,9 @@ if(sys.argv[1]=="sniff" or sys.argv[1]=="sniffdissect"): client.RF_getfreq()/10**6); #Now we're ready to get packets. while 1: + client.setup(); #Really oughtn't be necessary, but can't hurt. + client.CC_RFST_RX(); + packet=None; while packet==None: packet=client.RF_rxpacket(); @@ -129,6 +214,7 @@ if(sys.argv[1]=="sniff" or sys.argv[1]=="sniffdissect"): else: client.printpacket(packet); sys.stdout.flush(); + if(sys.argv[1]=="bsniff"): #Just broadcast. client.RF_promiscuity(0); @@ -168,11 +254,12 @@ if(sys.argv[1]=="txtest"): 0xff, 0xff, 0xff, 0xff, 0xde, 0xad, 0xbe, 0xef, 0xba, 0xbe, 0xc0]); + if(sys.argv[1]=="txtoscount"): ''' Clone of what TinyOS's RadioCountToLeds demo code does. Specify a channel a TinyOS mote programmed with RadioCountToLeds is on, and - this will act as the second device. + this will act as the second device. (ryan@rmspeers.com) ''' if (len(sys.argv)<=3): print "Provide -r to work via replays or -i to work via incrementing itself."; @@ -256,19 +343,18 @@ if(sys.argv[1]=="txpiptest" or sys.argv[1]=="txpipscapy"): 0xff, 0xff, 0xff, 0xff, ]); elif(sys.argv[1]=="txpipscapy"): + # NB: Requires Scapy with dot15d4.py layer. (rmspeers) try: from scapy.all import Dot15d4, Dot15d4FCS, Dot15d4Data, Raw import struct except ImportError: - print "To use packet building, Scapy must be installed and have the dot15d4 extension present." + print "To use packet building, Scapy must be installed and have the dot15d4 layer present." print "try: hg clone http://hg.secdev.org/scapy-com"; print " sudo ./setup.py install"; #Overall method is to build from the inner packet outwards in the pkt string # Make inner packet scapyinner = Dot15d4FCS(seqnum=130)/Dot15d4Data()/Raw('\xde\xad\xbe\xef'); - #pkt = str(scapyinner)[:-2] + '\xba\xbe\xc0'; pkt = str(scapyinner); #build inner pkt to bytes, adding FCS automatically - #pkt = '\x0f'+pkt pkt = struct.pack('b', len(pkt)) + pkt #prepend with its length pkt = "\x00\x00\x00\x00\xA7" + pkt #add preamble and SFD to inner packet # Make outer (wrapping) packet @@ -281,7 +367,6 @@ if(sys.argv[1]=="txpiptest" or sys.argv[1]=="txpipscapy"): client.RF_autocrc(1); client.RF_txpacket(pkt) - if(sys.argv[1]=="peek"): start=0x0000; if(len(sys.argv)>2):