forked from atlas0fd00m/rfcat
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rfcat_server
830 lines (705 loc) · 26 KB
/
rfcat_server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
#!/usr/bin/python
import re
import os
import sys
import cmd
import socket
import threading
from rflib import *
DATA_START_IDX = 4 # without the app/cmd/len bytes, the data starts at byte 4
def splitargs(cmdline):
cmdline = cmdline.replace('\\\\"', '"').replace('\\"', '')
patt = re.compile('\".+?\"|\S+')
for item in cmdline.split('\n'):
return [s.strip('"') for s in patt.findall(item)]
RX = RFST_SRX
TX = RFST_STX
IDLE = RFST_SIDLE
CAL = RFST_SCAL
SYNC_MODES = {
"NONE" : SYNCM_NONE,
"15/16" : SYNCM_15_of_16,
"16/16" : SYNCM_16_of_16,
"CS" : SYNCM_CARRIER,
"CS15/16" : SYNCM_CARRIER_15_of_16,
"CS16/16" : SYNCM_CARRIER_16_of_16,
"CS30/32" : SYNCM_CARRIER_30_of_32,
}
READLINE_MAX_READ_LEN = 1000
class FileSocket(socket.socket):
def __init__(self, sock):
self._buf = ''
self._sock = sock
def __getattr__(self, attr):
if hasattr(self._sock, attr):
return getattr(self._sock, attr)
elif hasattr(self, attr):
return getattr(self.__class__, attr)
def write(self, data):
return self.sendall(data)
def read(self, maxlen):
return self.recv(maxlen)
def readline(self):
idx = self._buf.find('\n')
while idx == -1:
self._buf += self.read(READLINE_MAX_READ_LEN)
idx = self._buf.find('\n')
data = self._buf[:idx]
self._buf = self._buf[idx+1:]
return data
def flush(self):
pass
class KillCfgLoop(Exception):
pass
class CC1111NIC_Server(cmd.Cmd):
intro = """
welcome to the cc1111usb interactive config tool. hack fun!
"""
def __init__(self, nicidx=0, ip='0.0.0.0', nicport=1900, cfgport=1899, go=True, printable=False, rawinput=False):
cmd.Cmd.__init__(self)
self.use_rawinput = rawinput
self.printable = printable
#self.nic = FHSSNIC(nicidx)
self.nic = RfCat(nicidx)
self._ip = ip
self._nicport = nicport
self._nicsock = None
self._cfgport = cfgport
self._cfgsock = None
self._cfgthread = None
self._pause = False
self.startConfigThread()
if go:
self.start()
def start(self):
self._go = True
while self._go:
# serve the NIC port
try:
buf = ''
self._nicsock = socket.socket()
s = self._nicsock
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((self._ip, self._nicport))
s.listen(100)
while True:
# implement pipe between the usb RF NIC and the TCP socket
try:
print >>sys.stderr,("Listening for NIC connection on port %d" % self._nicport)
self._nicsock = s.accept()
rs, addr = self._nicsock
rs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
print "== received DATA connection from %s:%d ==" % (addr)
# handing off the socket for rf_redirection, socket-style
self.nic.rf_redirection( (rs,) )
print >>sys.stderr,("NIC connection on port %d terminated" % self._nicport)
except KeyboardInterrupt:
self._go = False
break
except:
sys.excepthook(*sys.exc_info())
except KeyboardInterrupt:
self._go = False
except:
sys.excepthook(*sys.exc_info())
def startConfigThread(self):
self._cfgthread = threading.Thread(target=self._cfgRun)
self._cfgthread.setDaemon(True)
self._cfgthread.start()
def _cfgRun(self):
self._cfgsock = socket.socket()
s = self._cfgsock
s.bind((self._ip, self._cfgport))
s.listen(100)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
while True:
try:
self._cfgsock = s.accept()
rs,addr = self._cfgsock
rs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
print "== received CONFIG connection from %s:%d ==" % (addr)
self.stdin = FileSocket(rs)
self.stdout = self.stdin
self.stderr = self.stdin
while True:
try:
self.cmdloop()
except KillCfgLoop:
break
except:
sys.excepthook(*sys.exc_info())
except:
sys.excepthook(*sys.exc_info())
def do_EOF(self, line):
self.Print("stopping the command loop now..")
#ok so just kill the connection :)
def Print(self, info):
print >>self.stdout,(info)
def do_stop(self, line):
"""
stop the nic
"""
self._pause = True
def do_start(self, line):
"""
start the nic
"""
self._pause = False
#### configuration ####
#def do_specan(self,basefreq=902e6,inc=25e3,count=104):
def do_specan(self,line):
'''
* SPECAN - spectrum analysis mode
'''
basefreq=902e6
inc=25e3
count=104
self.nic._doSpecAn(basefreq,inc,count)
def do_stopspecan(self,line):
'''
* SPECAN - spectrum analysis mode
'''
self.nic._stopSpecAn()
def do_rfmode(self, line):
'''
* RFMODE - set the radio in RX/IDLE/TX/CAL (CAL returns to IDLE)
'''
if len(line):
try:
self.nic.poke(X_RFST, eval(line))
except:
sys.excepthook(*sys.exc_info())
else:
self.Print(repr(self.getMARCSTATE()))
def do_calibrate(self, line):
'''
* CALIBRATE - force the radio to recalibrate. VCO characteristics will change with temperature and supply voltage changes
'''
self.Print("Calibrating radio...")
self.nic.setModeCAL()
while (self.getMARCSTATE()[1] not in (MARC_STATE_IDLE, MARC_STATE_RX, MARC_STATE_TX)):
sys.stdout.write('.')
self.Print("done calibrating.")
def do_modeTX(self, line):
'''
* modeTX - force the radio to the TX state. this should transmit a CARRIER only,
since there is no data which follows quickly. when the radio is placed in TX mode,
no TX_UNF timeouts occur unless at least some data is sent
'''
self.Print("Calibrating radio...")
self.nic.setModeTX()
while (self.getMARCSTATE()[1] not in (MARC_STATE_TX)):
sys.stdout.write('.')
self.Print("Radio has reached the TX state.")
def do_modeRX(self, line):
'''
* modeRX - force the radio to the RX state. this will allow the radio to receive
transmitted data and handle it. if an RX-timeout has been configured (not default)
then the radio should return to Idle state if the RX timeout is reached without
receiving a packet. if a packet is received, the radio returns to whatever state
it is configured to in MCSM1
'''
self.Print("Radio entering RX state...")
self.nic.setModeTX()
while (self.getMARCSTATE()[1] not in (MARC_STATE_RX)):
sys.stdout.write('.')
self.Print("Radio has reached the RX state.")
def do_modeIDLE(self, line):
'''
* modeIDLE - force the radio to the Idle state. no packets will be received or sent.
when exceptions occur in the radio, it must always be placed in the Idle state before
entering RX or TX. this is done automatically in the firmware (default for RX_OVF
and TX_UNF)
'''
self.Print("Radio entering IDLE state...")
self.nic.setModeIDLE()
while (self.getMARCSTATE()[1] not in (MARC_STATE_IDLE)):
sys.stdout.write('.')
self.Print("Radio has reached the IDLE state.")
def do_modeFSTXON(self, line):
'''
* modeFSTXON
'''
self.Print("Radio entering FSTXON state...")
self.nic.setModeFSTXON()
while (self.getMARCSTATE()[1] not in (MARC_STATE_FSTXON)):
sys.stdout.write('.')
self.Print("Radio has reached the FSTXON state.")
def do_modulation(self, line):
'''
* MODULATION - set the RF modulation scheme. values include "2FSK", "GFSK", "MSK", "ASK_OOK". note: GFSK/OOK/ASK only up to 250kbaud, MSK only above 26kbaud and no manchester encoding.
'''
if not len(line) or line not in ("2FSK", "GFSK", "MSK", "ASK_OOK"):
self.Print('need to give me one of the values "2FSK", "GFSK", "MSK", "ASK_OOK" got: "%s"' % line)
return
mod = eval("MOD_"+line.strip())
self.nic.setModeIDLE()
self.nic.setMdmModulation(mod)
self.nic.setModeRX()
def complete_modulation(self, text, line, begidx, endidx):
self.Print("complete_modulation: %s %s %s %s") % (repr(text), repr(line), repr(begidx), repr(endidx))
def do_baud(self, line):
'''
* baud <BAUDRATE> - set the datarate, then recalculate channel bandwidth, intermediate frequency, deviation, and offset
'''
baud = int(line)
self.nic.setMdmDRate(baud)
self.nic.calculateMdmDeviatn()
self.nic.calculatePktChanBW()
self.nic.calculateFsIF()
self.nic.calculateFsOffset()
def do_bw(self, line):
'''
* bw [channel_bandwidth] - allow the setting of bandwidth settings separately from "baud"
'''
if len(line):
bw = int(line)
self.nic.setMdmChanBW(bw)
else:
self.Print(self.nic.getMdmChanBW())
def do_drate(self, line):
'''
* drate [datarate hz] - allow the setting of datarate settings separately from "baud"
'''
if len(line):
baud = int(line)
self.nic.setMdmDRate(baud)
else:
self.Print(self.nic.getMdmDRate())
def do_chanspc(self, line):
'''
* chanspc [spacing hz] - set channel spacing
'''
if len(line):
chanspc = int(line)
self.nic.setMdmChanSpc(chanspc)
else:
self.Print(self.nic.getMdmChanSpc())
def do_channel(self, line):
'''
* channel [chan_num] - set the channel
'''
if len(line):
channr = int(line)
self.nic.setChannel(channr)
else:
self.Print(self.nic.getChannel())
def do_freq(self, line):
'''
* freq [frequency hz] - set the base frequency. CHANNL and CHAN_SPC are used to calculate positive offset from this.
'''
if len(line):
freq = int(line)
self.nic.setFreq(freq)
else:
self.Print(self.nic.getFreq())
def do_intfreq(self, line):
'''
* intfreq [IF] - allow the setting of Intermediate Frequency separately from "baud"
'''
if len(line):
IF = int(line)
self.nic.setFsIF(IF)
else:
self.Print(self.nic.getFsIF())
def do_freqoff(self, line):
'''
* freqoff [IF] - allow the setting of Frequency Offset separately from "baud"
'''
if len(line):
fo = int(line)
self.nic.setFsOffset(fo)
else:
self.Print(self.nic.getFsOffset())
def do_vlen(self, line):
'''
* VLEN - configure the NIC for variable-length packets. provide max packet size (FLEN to switch to Fixed)
'''
maxlen = int(line)
self.nic.makePktVLEN(maxlen)
def do_flen(self, line):
'''
* FLEN # - configure the NIC for fixed-length packets. provide packet size (VLEN to switch to Variable)
'''
length = int(line)
self.nic.makePktFLEN(length)
def do_syncword(self, line):
'''
* SYNCWORD #### [double]- set the SYNC word (SYNC1 and SYNC0) (double tells the radio to repeat SYNCWORD twice)
'''
if len(line):
syncword = int(line)
self.setMdmSyncWord(syncword)
else:
self.Print(self.getMdmSyncWord())
def do_syncmode(self, line):
'''
* SYNCMODE - set the SYNCMODE. values include "NONE", "15/16", "16/16", "CS", "CS15/16", "CS16/16", "CS30/32"
'''
if len(line):
syncmode = SYNC_MODES.get(line)
if syncmode is None:
self.Print("please provide a *valid* sync-mode. see the help.")
self.Print(self.nic.setMdmSyncMode(syncmode))
else:
self.Print(self.nic.getMdmSyncMode())
def do_pqt(self, line):
'''
* PQT - set the Preamble Quality Threshold. provide the number of bits (multiple of 4) for PQT. values will be rounded down. 0-3 disables PQT checking.
'''
if len(line):
pqt = int(line)
self.setPktPQT(pqt)
else:
self.Print(self.getPktPQT())
def do_addr(self, line):
'''
* ADDR - configure the NIC's ADDRESS
'''
if len(line):
addr = int(line)
self.nic.setPktAddr(addr)
else:
self.Print(self.nic.getPktAddr())
def do_addr_chk(self, line):
'''
* ADDR_CHK - filter based on the optional address byte. values include "NOCHK", "FULL", "BCAST", indicating no filtering, full filtering, and filtering with broadcasts
'''
if len(line):
addr = int(line)
self.nic.setAddr(addr)
else:
self.Print(self.nic.getAddr())
def do_datawhiten(self, line):
'''
* DATAWHITEN - configure data whitening, include 9-bit PN9 xor sequence in command
'''
if len(line):
if line.startswith("off") or line.startswith("OFF"):
self.nic.setEnablePktDataWhitening(False)
else:
self.nic.setEnablePktDataWhitening(True)
else:
self.Print(self.nic.getPktDataWhitening())
def do_manchester(self, line):
'''
* MANCHESTER [ON | OFF] - configure Manchester encoding to enhance successful transmission. cannot use with MSK modulation or the FEC/Interleaver.
'''
if len(line):
if line.startswith("off") or line.startswith("OFF"):
self.nic.setEnableMdmManchester(False)
else:
self.nic.setEnableMdmManchester(True)
else:
self.Print(self.nic.getEnableMdmManchester())
def do_fec(self, line):
'''
* FEC - enable/disable Forward Error Correction. only works with FIXED LENGTH packets.
'''
if len(line):
if line.startswith("off") or line.startswith("OFF"):
self.nic.setEnableMdmFEC(False)
else:
self.nic.setEnableMdmFEC(True)
else:
self.Print(self.nic.getEnableMdmFEC())
def do_crc(self, line):
'''
* CRC - enable/disable Cyclic Redundancy Check. the last two bytes of a packet will be
considered CRC16 bytes, helpful for determining bad packets.
'''
if len(line):
if line.startswith("off") or line.startswith("OFF"):
self.nic.setEnablePktCRC(False)
else:
self.nic.setEnablePktCRC(True)
else:
self.Print(self.nic.getEnablePktCRC())
def do_DEM_DCFILT(self, line):
'''
* DEM_DCFILT - enable/disable digital DC blocking filter before demodulator. typically not good to muck with.
'''
if len(line):
if line.startswith("off") or line.startswith("OFF"):
self.nic.setEnableMdmDCFilter(False)
else:
self.nic.setEnableMdmDCFilter(True)
else:
self.Print(self.nic.getEnableMdmDCFilter())
def do_MAGN_TARGET(self, line):
'''
* MAGN_TARGET - configure Carrier Sense
'''
if len(line):
pass
else:
pass
def do_MAC_LNA_GAIN(self, line):
'''
* MAX_LNA_GAIN - configure Carrier Sense Threshold
'''
if len(line):
pass
else:
pass
def do_MAX_DVGA_GAIN(self, line):
'''
* MAX_DVGA_GAIN - configure Carrier Sense Threshold (use
'''
if len(line):
pass
else:
pass
def do_CARRIER_SENSE_ABS_THR (self, line):
'''
* CARRIER_SENSE_ABS_THR - configure Carrier Sense Absolute Threshold - values include "6", "10", "14" indicating the dB increase in RSSI
'''
if len(line):
pass
else:
pass
def do_CARRIER_SENSE_REL_THR (self, line):
'''
* CARRIER_SENSE_REL_THR - configure Carrier Sense Relative Threshold - values include "DISABLE", and -7 thru +7 to indicate dB from MAGN_TARGET setting
'''
if len(line):
pass
else:
pass
def do_cca_mode (self, line):
'''
* CCA_MODE - select the Clear Channel Assessment mode. values include "DISABLE", "RSSI", "RECVING", "BOTH".
'''
if len(line):
pass
else:
pass
def do_PA_POWER (self, line):
'''
* PA_POWER - select which PATABLE to use for power settings (0-7) (see CC1110/CC1111 manual SWRS033G section 13.15 and 13.16)
'''
if len(line):
pass
else:
pass
def do_FS_AUTOCAL (self, line):
'''
* FS_AUTOCAL - select mode of auto-VCO-calibration. values include "ON", "OFF", "MANUAL", indicating that calibration should be done when turning the synthesizer ON/OFF or manually
'''
if len(line):
pass
else:
pass
def do_REGS_TEST(self, line):
'''
* set register: TEST2/TEST1/TEST0
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_REGS_AGCCTRL(self, line):
'''
* set register: AGCCTRL2/1/0
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_REG_PKTCTRL(self, line):
'''
* set register: PKTCTRL1/0
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_REG_PKTLEN(self, line):
'''
* set register: PKTLEN
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_REG_PKTSTATUS(self, line):
'''
* view register: PKTSTATUS
'''
def do_REGS_MDMCFG(self, line):
'''
* set registers: MDMCFG4/3/2/1/0
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_REGS_MCSM(self, line):
'''
* set register: MCSM2/1/0
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_REG_DEVIATN(self, line):
'''
* set register: DEVIATN
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_REGS_BSCFG_F0CCFG(self, line):
'''
* set register: BSCFG / FOCCFG
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_REGS_FSCTRL(self, line):
'''
* set register: FSCTRL1/0
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_REGS_FREQ(self, line):
'''
* set register: FREQ2/1/0
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_REGS_FREND(self, line):
'''
* set register: FREND1/0
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_REGS_PATABLE(self, line):
'''
* set register: PATABLE7/6/5/4/3/2/1/0
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
def do_show_config(self, line):
'''
* show_config - Print a represented string of the radio configuration
'''
self.Print(self.nic.reprRadioConfig())
def do_dump_config(self, line):
'''
* dump_config - Print a hex representation of the radio configuration registers
'''
self.Print(repr(self.nic.getRadioConfig()))
def do_hack_loose_settings(self, line):
'''
* loose - no CRC, no FEC, no Data Whitening, no sync-word, carrier based receive, etc...
'''
def do_upload_config(self, line):
'''
* upload_config - configure the radio using a python repr string provided to the command
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
self.nic.setModeIDLE()
print "loading config from bytes: %s" % repr(line)
self.setRadioConfig(line)
self.nic.setModeRX()
def do_download_config(self, line):
'''
* download_config - pull current config bytes from radio and dump them in a python repr string
'''
self.Print(repr(self.nic.getRadioConfig()))
def do_save_config(self, line):
'''
* save_config <filename> - save the radio configuration to a file you specify
'''
file(line, "wb").write(repr(self.nic.getRadioConfig()))
def do_load_config(self, line):
'''
* load_config
(be very cautious! the firmware expects certain things like return-to-RX, and no RX-timeout, etc..)
'''
config = file(line, "rb").read()
self.nic.setModeIDLE()
print "loading config from bytes: %s" % repr(config)
self.setRadioConfig(config)
self.nic.setModeRX()
def do_peek(self, line):
'''
* peek <xaddr> [len] - view memory at whatever XDATA address (see the code for details on the memory layout)
'''
args = splitargs(line)
if 0 < len(args) < 3:
if len(args) == 1:
args.append('1')
self.Print(self.peek(int(args[0])), int(args[1]).encode('hex'))
else:
self.Print("please provide exactly one xdata address and an optional length!")
def do_poke(self, line):
'''
* poke - update memory at whatever XDATA address (see the code for details on the memory layout)
'''
args = splitargs(line)
try:
self.nic.poke(int(args[0]), args[1].decode('hex'))
except:
self.Print("please provide exactly one xdata address and hex data")
def do_ping(self, line):
'''
* ping - hello? is the dongle still responding?
'''
self.Print("Successful: %d, Failed: %d, Time: %f" % self.nic.ping())
def do_debug_codes(self, line):
'''
* debugcodes - see what the firmware has stored in it's lastCode[] array
'''
self.Print("lastcode: [%x, %x]") % (self.getDebugCodes())
def do_RESET(self, line):
'''
* reset the dongle
'''
self.Print("Sending the RESET command. Please be patient....")
self.nic.RESET()
def do_rssi(self, line):
'''
* get the last RSSI value
'''
self.Print("RSSI: %x" % (ord(self.getRSSI()) & 0x7f) )
def do_lqi(self, line):
'''
* get the last LQI value
'''
self.Print("%x") % (ord(self.getLQI()))
def do_rfregister(self, line):
'''
rfregister <reg> [value] - set or read a RF register
'''
if len(line):
args = splitargs(line)
val = eval(args[0])
try:
if len(args) > 1:
self.nic.setRFRegister(val)
else:
self.Print("%s : %x" % (args[0], ord(self.nic.peek(val))))
except:
self.Print(sys.exc_info())
else:
self.Print("must include the register to get/set")
def do_printable(self, line):
'''
printable y/n - repr() all data sent to TCP socket for readability of binary data
'''
if len(line):
args = splitargs(line)
val = (args[0])
if val.lower()[0] in ('y', '1'):
self.printable = True
else:
self.printable = False
else:
self.printable = True
self.Print("printable output is: %s" % ('disabled','enabled')[self.printable])
def do_rawinput(self, line):
'''
rawinput y/n - accept in pythonic string reprs (eg. \x80 gets translated to the actual byte '\x80')
input data is run through 'eval' before sending to get a real string from your typed binary input.
'''
if len(line):
args = splitargs(line)
val = (args[0])
if val.lower()[0] in ('y', '1'):
self.use_rawinput = True
else:
self.use_rawinput = False
else:
self.use_rawinput = True
self.Print("raw input is: %s" % ('disabled','enabled')[self.use_rawinput])
'''
def getInterruptRegisters(self):
def testTX(self, data="XYZABCDEFGHIJKL"):
def lowball(self, level=1):
def lowballRestore(self):
def getMACthreshold(self):
def setMACthreshold(self, value):
def setFHSSstate(self, state):
def getFHSSstate(self):
def mac_SyncCell(self, CellID=0x0000):
'''
if __name__ == "__main__":
dongleserver = CC1111NIC_Server()
import atexit
atexit.register(cleanupInteractiveAtExit)