commit 3a9571bc8203cc3d8089f49af64c6e1d1826ad2b Author: Mike Ossmann Date: Tue Oct 26 03:38:28 2010 +0000 ToorCon 12 release diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..9f1e730 --- /dev/null +++ b/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/README b/README new file mode 100644 index 0000000..65a37a9 --- /dev/null +++ b/README @@ -0,0 +1,7 @@ +This is Project Ubertooth, an open source wireless development platform +suitable for Bluetooth experimentation. Ubertooth is primarily a hardware +product, but sample firmware and host code (software to be executed on a +general purpose computer connected by USB to an Ubertooth board) are provided. + +The first hardware revision is called Ubertooth Zero and was demonstrated at +ToorCon 12 on October 24th, 2010. diff --git a/firmware/README.txt b/firmware/README.txt new file mode 100644 index 0000000..d9fe8ad --- /dev/null +++ b/firmware/README.txt @@ -0,0 +1 @@ +firmware coming soon diff --git a/hardware/README b/hardware/README new file mode 100644 index 0000000..4ca0703 --- /dev/null +++ b/hardware/README @@ -0,0 +1,18 @@ +Copyright 2010 Michael Ossmann + +This file is part of ubertooth. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, +Boston, MA 02110-1301, USA. diff --git a/hardware/ubertooth-zero.brd b/hardware/ubertooth-zero.brd new file mode 100644 index 0000000..b1af2d2 Binary files /dev/null and b/hardware/ubertooth-zero.brd differ diff --git a/hardware/ubertooth-zero.sch b/hardware/ubertooth-zero.sch new file mode 100644 index 0000000..5dbe7aa Binary files /dev/null and b/hardware/ubertooth-zero.sch differ diff --git a/host/Makefile b/host/Makefile new file mode 100644 index 0000000..8ab1dfb --- /dev/null +++ b/host/Makefile @@ -0,0 +1,30 @@ +# Copyright 2010 Michael Ossmann +# +# This file is part of ubertooth. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +CC = gcc +LIBUSB=/usr/lib/libusb.la + +all: ubertooth-dump + +ubertooth-dump: + $(CC) -g -O2 -Wall -MT ubertooth-dump.o -MD -MP -MF "./ubertooth-dump.Po" -c -o ubertooth-dump.o ubertooth-dump.c + libtool --tag=blahbah --mode=link gcc -g -O2 -g -Wall -o ubertooth-dump ubertooth-dump.o $(LIBUSB) + +clean: + rm -f ubertooth-dump *.o *.Po diff --git a/host/README b/host/README new file mode 100644 index 0000000..8bc6f81 --- /dev/null +++ b/host/README @@ -0,0 +1,25 @@ +This is proof-of-concept test code for Ubertooth. Expect many changes over +the coming months. + +Usage: + +./ubertooth-dump | ./btrx.py -b -i - + +You must have gr-bluetooth installed. This btrx.py is taken from an older +release of gr-bluetooth. We'll fix that at some point, perhaps with changes +in gr-bluetooth, perhaps by moving a bunch of the gr-bluetooth code here or +into a new library. + +If you have a USRP, you can use demod.py to produce test input for btrx.py -b. + +As an alternative to using ubertooth-dump, you can use a usb serial driver to +communicate with the Ubertooth. For example in Linux you can unload the +usbserial driver and reload it with: + +modprobe usbserial vendor=0xffff product=0x0005 + +Then you can talk to the Ubertooth with a terminal program such as minicom. +When you use the usbserial driver instead of ubertooth-dump, data transfer +speed will be restricted - too slow for streaming rx but good for testing +other things. See the firmware source code for things you can do here. All +this is subject to change, of course. diff --git a/host/btrx.py b/host/btrx.py new file mode 100755 index 0000000..c5a2dc2 --- /dev/null +++ b/host/btrx.py @@ -0,0 +1,219 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright 2008, 2009 Dominic Spill, Michael Ossmann +""" +Bluetooth monitoring utility. +Receives samples from USRP, file (as created by usrp_rx_cfile.py), or standard input. +If LAP is unspecified, LAP detection mode is enabled. +If LAP is specified without UAP, UAP detection mode is enabled. +If both LAP and UAP are specified, sniffing mode is enabled. +""" + +from gnuradio import gr, eng_notation, blks2 + +from gnuradio import bluetooth +from gnuradio.eng_option import eng_option +from optparse import OptionParser + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + usage="%prog: [options]" + parser = OptionParser(option_class=eng_option, usage=usage) + parser.add_option("-N", "--nsamples", type="eng_float", default=None, + help="number of samples to collect [default=+inf]") + parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0), + help="select USRP Rx side A or B (default=A)") + parser.add_option("-b", "--bitstream", action="store_true", default=None, + help="input data from file is already demodulated\n(Not compatible with USRP use") + parser.add_option("-c", "--ddc", type="string", default="0", + help="comma separated list of ddc frequencies (default=0)") + parser.add_option("-d", "--decim", type="int", default=32, + help="set fgpa decimation rate to DECIM (default=32)") + parser.add_option("-e", "--interface", type="string", default="eth0", + help="use specified Ethernet interface for USRP2 [default=%default]") + parser.add_option("-f", "--freq", type="eng_float", default=0, + help="set USRP frequency to FREQ", metavar="FREQ") + parser.add_option("-g", "--gain", type="eng_float", default=None, + help="set USRP gain in dB (default is midpoint)") + parser.add_option("-i", "--input-file", type="string", default=None, + help="use named input file instead of USRP") + parser.add_option("-l", "--lap", type="string", default=None, + help="LAP of the master device") + parser.add_option("-m", "--mac-addr", type="string", default="", + help="use USRP2 at specified MAC address [default=None]") + parser.add_option("-n", "--channel", type="int", default=None, + help="channel number for hop reversal (0-78) (default=None)") + parser.add_option("-r", "--sample-rate", type="eng_float", default=None, + help="sample rate of input (default: use DECIM)") + parser.add_option("-s", "--input-shorts", action="store_true", default=False, + help="input interleaved shorts instead of complex floats") + parser.add_option("-t", "--squelch", type="eng_float", default=None, + help="power squelch threshold in dB (default=None)") + parser.add_option("-u", "--uap", type="string", default=None, + help="UAP of the master device") + parser.add_option("-w","--wireshark", action="store_true", default=False, + help="direct output to a tun interface") + parser.add_option("-2","--usrp2", action="store_true", default=False, + help="use USRP2 (or file originating from USRP2) instead of USRP") + + (options, args) = parser.parse_args () + if len(args) != 0: + parser.print_help() + raise SystemExit, 1 + + if options.bitstream: + if options.input_file is None: + print "Error: bitstream processing requires file input\n" + raise SystemExit, 1 + + # Bluetooth operates at 1 million symbols per second + symbol_rate = 1e6 + + # the demodulator needs at least two samples per symbol + min_samples_per_symbol = 2 + min_sample_rate = symbol_rate * min_samples_per_symbol + + # use options.sample_rate unless not provided by user + if options.sample_rate is None: + if options.usrp2: + # original source is USRP2 + adc_rate = 100e6 + else: + # assume original source is USRP + adc_rate = 64e6 + options.sample_rate = adc_rate / options.decim + + # make sure we have a high enough sample rate + if options.sample_rate < min_sample_rate: + raise ValueError, "Sample rate (%d) below minimum (%d)\n" % (options.sample_rate, min_sample_rate) + + if options.input_shorts: + input_size = gr.sizeof_short + else: + input_size = gr.sizeof_gr_complex + + if options.bitstream: + input_size = gr.sizeof_char + + # select input source + if options.input_file is None: + # input from USRP or USRP2 + if options.usrp2: + from gnuradio import usrp2 + src = usrp2.source_32fc(options.interface, options.mac_addr) + print "Using RX board id 0x%04X" % (src.daughterboard_id(),) + src.set_decim(options.decim) + r = src.set_center_freq(options.freq) + if r == None: + raise SystemExit, "Failed to set USRP2 frequency" + if options.gain is None: + # if no gain was specified, use the mid-point in dB + g = src.gain_range() + options.gain = float(g[0]+g[1])/2 + src.set_gain(options.gain) + else: + from gnuradio import usrp + src = usrp.source_c(decim_rate=options.decim) + subdev = usrp.selected_subdev(src, options.rx_subdev_spec) + print "Using RX board %s" % (subdev.side_and_name()) + r = src.tune(0, subdev, options.freq) + if not r: + raise SystemExit, "Failed to set USRP frequency" + if options.gain is None: + # if no gain was specified, use the mid-point in dB + g = subdev.gain_range() + options.gain = float(g[0]+g[1])/2 + subdev.set_gain(options.gain) + elif options.input_file == '-': + # input from stdin + src = gr.file_descriptor_source(input_size, 0) + else: + # input from file + src = gr.file_source(input_size, options.input_file) + + # stage 1: limit input to desired number of samples + if options.nsamples is None: + stage1 = src + else: + head = gr.head(input_size, int(options.nsamples)) + self.connect(src, head) + stage1 = head + + # stage 2: convert input from shorts if necessary + if options.input_shorts: + s2c = gr.interleaved_short_to_complex() + self.connect(stage1, s2c) + stage2 = s2c + else: + stage2 = stage1 + + # stage 3: power squelch + if options.squelch is None: + stage3 = stage2 + else: + squelch = gr.pwr_squelch_cc(options.squelch, 0.01, 0, True) + self.connect(stage2, squelch) + stage3 = squelch + + # coefficients for filter to select single channel + channel_filter = gr.firdes.low_pass(1.0, options.sample_rate, 500e3, 500e3, gr.firdes.WIN_HANN) + + # we will decimate by the largest integer that results in enough samples per symbol + decimation_rate = int(options.sample_rate/(min_sample_rate)) + samples_per_symbol = (options.sample_rate/decimation_rate)/symbol_rate + + # look for packets on each channel specified by options.ddc + # this works well for a small number of channels, but a more efficient + # method should be possible for a large number of contiguous channels. + channel = 0 + for ddc_option in options.ddc.split(","): + if options.bitstream is None: + ddc_freq = int(eng_notation.str_to_num(ddc_option)) + + # digital downconverter + # does three things: + # 1. converts frequency so channel of interest is centered at 0 Hz + # 2. filters out everything outside the channel + # 3. downsamples to 2 Msps (2 samples per symbol) or so + ddc = gr.freq_xlating_fir_filter_ccf(decimation_rate, channel_filter, -ddc_freq, options.sample_rate) + + # GMSK demodulate baseband to bits + demod = blks2.gmsk_demod(mu=0.32, samples_per_symbol=samples_per_symbol) + self.connect(stage3, ddc) + self.connect(ddc, demod) + else: + # Skip demod if using a bitstream (it's already demodulated) + demod = stage3 + ddc_freq = 1 + + # bluetooth decoding + if options.lap is None: + if options.wireshark: + dst = bluetooth.tun(ddc_freq, channel) + channel = channel + 1 + else: + # print out LAP for every frame detected + dst = bluetooth.LAP(ddc_freq) + else: + if options.uap is None: + if options.channel is None: + # determine UAP from frames matching the user-specified LAP + dst = bluetooth.UAP(int(options.lap, 16)) + else: + # determine UAP and clock + dst = bluetooth.hopper(int(options.lap, 16), options.channel) + else: + # sniffer mode + dst = bluetooth.sniffer(int(options.lap, 16), int(options.uap, 16)) + + # connect the blocks + self.connect(demod, dst) + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass diff --git a/host/demod.py b/host/demod.py new file mode 100755 index 0000000..9518afb --- /dev/null +++ b/host/demod.py @@ -0,0 +1,220 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright 2008, 2009 Dominic Spill, Michael Ossmann +""" +Bluetooth monitoring utility. +Receives samples from USRP, file (as created by usrp_rx_cfile.py), or standard input. +If LAP is unspecified, LAP detection mode is enabled. +If LAP is specified without UAP, UAP detection mode is enabled. +If both LAP and UAP are specified, sniffing mode is enabled. +""" + +from gnuradio import gr, eng_notation, blks2 + +from gnuradio import bluetooth +from gnuradio.eng_option import eng_option +from optparse import OptionParser + +class my_top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self) + + usage="%prog: [options]" + parser = OptionParser(option_class=eng_option, usage=usage) + parser.add_option("-N", "--nsamples", type="eng_float", default=None, + help="number of samples to collect [default=+inf]") + parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0), + help="select USRP Rx side A or B (default=A)") + parser.add_option("-b", "--bitstream", action="store_true", default=None, + help="input data from file is already demodulated\n(Not compatible with USRP use") + parser.add_option("-c", "--ddc", type="string", default="0", + help="comma separated list of ddc frequencies (default=0)") + parser.add_option("-d", "--decim", type="int", default=32, + help="set fgpa decimation rate to DECIM (default=32)") + parser.add_option("-e", "--interface", type="string", default="eth0", + help="use specified Ethernet interface for USRP2 [default=%default]") + parser.add_option("-f", "--freq", type="eng_float", default=0, + help="set USRP frequency to FREQ", metavar="FREQ") + parser.add_option("-g", "--gain", type="eng_float", default=None, + help="set USRP gain in dB (default is midpoint)") + parser.add_option("-i", "--input-file", type="string", default=None, + help="use named input file instead of USRP") + parser.add_option("-l", "--lap", type="string", default=None, + help="LAP of the master device") + parser.add_option("-m", "--mac-addr", type="string", default="", + help="use USRP2 at specified MAC address [default=None]") + parser.add_option("-n", "--channel", type="int", default=None, + help="channel number for hop reversal (0-78) (default=None)") + parser.add_option("-r", "--sample-rate", type="eng_float", default=None, + help="sample rate of input (default: use DECIM)") + parser.add_option("-s", "--input-shorts", action="store_true", default=False, + help="input interleaved shorts instead of complex floats") + parser.add_option("-t", "--squelch", type="eng_float", default=None, + help="power squelch threshold in dB (default=None)") + parser.add_option("-u", "--uap", type="string", default=None, + help="UAP of the master device") + parser.add_option("-w","--wireshark", action="store_true", default=False, + help="direct output to a tun interface") + parser.add_option("-2","--usrp2", action="store_true", default=False, + help="use USRP2 (or file originating from USRP2) instead of USRP") + + (options, args) = parser.parse_args () + if len(args) != 0: + parser.print_help() + raise SystemExit, 1 + + if options.bitstream: + if options.input_file is None: + print "Error: bitstream processing requires file input\n" + raise SystemExit, 1 + + # Bluetooth operates at 1 million symbols per second + symbol_rate = 1e6 + + # the demodulator needs at least two samples per symbol + min_samples_per_symbol = 2 + min_sample_rate = symbol_rate * min_samples_per_symbol + + # use options.sample_rate unless not provided by user + if options.sample_rate is None: + if options.usrp2: + # original source is USRP2 + adc_rate = 100e6 + else: + # assume original source is USRP + adc_rate = 64e6 + options.sample_rate = adc_rate / options.decim + + # make sure we have a high enough sample rate + if options.sample_rate < min_sample_rate: + raise ValueError, "Sample rate (%d) below minimum (%d)\n" % (options.sample_rate, min_sample_rate) + + if options.input_shorts: + input_size = gr.sizeof_short + else: + input_size = gr.sizeof_gr_complex + + if options.bitstream: + input_size = gr.sizeof_char + + # select input source + if options.input_file is None: + # input from USRP or USRP2 + if options.usrp2: + from gnuradio import usrp2 + src = usrp2.source_32fc(options.interface, options.mac_addr) + print "Using RX board id 0x%04X" % (src.daughterboard_id(),) + src.set_decim(options.decim) + r = src.set_center_freq(options.freq) + if r == None: + raise SystemExit, "Failed to set USRP2 frequency" + if options.gain is None: + # if no gain was specified, use the mid-point in dB + g = src.gain_range() + options.gain = float(g[0]+g[1])/2 + src.set_gain(options.gain) + else: + from gnuradio import usrp + src = usrp.source_c(decim_rate=options.decim) + subdev = usrp.selected_subdev(src, options.rx_subdev_spec) + print "Using RX board %s" % (subdev.side_and_name()) + r = src.tune(0, subdev, options.freq) + if not r: + raise SystemExit, "Failed to set USRP frequency" + if options.gain is None: + # if no gain was specified, use the mid-point in dB + g = subdev.gain_range() + options.gain = float(g[0]+g[1])/2 + subdev.set_gain(options.gain) + elif options.input_file == '-': + # input from stdin + src = gr.file_descriptor_source(input_size, 0) + else: + # input from file + src = gr.file_source(input_size, options.input_file) + + # stage 1: limit input to desired number of samples + if options.nsamples is None: + stage1 = src + else: + head = gr.head(input_size, int(options.nsamples)) + self.connect(src, head) + stage1 = head + + # stage 2: convert input from shorts if necessary + if options.input_shorts: + s2c = gr.interleaved_short_to_complex() + self.connect(stage1, s2c) + stage2 = s2c + else: + stage2 = stage1 + + # stage 3: power squelch + if options.squelch is None: + stage3 = stage2 + else: + squelch = gr.pwr_squelch_cc(options.squelch, 0.01, 0, True) + self.connect(stage2, squelch) + stage3 = squelch + + # coefficients for filter to select single channel + channel_filter = gr.firdes.low_pass(1.0, options.sample_rate, 500e3, 500e3, gr.firdes.WIN_HANN) + + # we will decimate by the largest integer that results in enough samples per symbol + decimation_rate = int(options.sample_rate/(min_sample_rate)) + samples_per_symbol = (options.sample_rate/decimation_rate)/symbol_rate + + # look for packets on each channel specified by options.ddc + # this works well for a small number of channels, but a more efficient + # method should be possible for a large number of contiguous channels. + channel = 0 + for ddc_option in options.ddc.split(","): + if options.bitstream is None: + ddc_freq = int(eng_notation.str_to_num(ddc_option)) + + # digital downconverter + # does three things: + # 1. converts frequency so channel of interest is centered at 0 Hz + # 2. filters out everything outside the channel + # 3. downsamples to 2 Msps (2 samples per symbol) or so + ddc = gr.freq_xlating_fir_filter_ccf(decimation_rate, channel_filter, -ddc_freq, options.sample_rate) + + # GMSK demodulate baseband to bits + demod = blks2.gmsk_demod(mu=0.32, samples_per_symbol=samples_per_symbol) + self.connect(stage3, ddc) + self.connect(ddc, demod) + else: + # Skip demod if using a bitstream (it's already demodulated) + demod = stage3 + ddc_freq = 1 + + # bluetooth decoding + if options.lap is None: + if options.wireshark: + dst = bluetooth.tun(ddc_freq, channel) + channel = channel + 1 + else: + # print out LAP for every frame detected + #dst = bluetooth.LAP(ddc_freq) + dst = gr.file_sink(gr.sizeof_char, "/tmp/demod.dat") + else: + if options.uap is None: + if options.channel is None: + # determine UAP from frames matching the user-specified LAP + dst = bluetooth.UAP(int(options.lap, 16)) + else: + # determine UAP and clock + dst = bluetooth.hopper(int(options.lap, 16), options.channel) + else: + # sniffer mode + dst = bluetooth.sniffer(int(options.lap, 16), int(options.uap, 16)) + + # connect the blocks + self.connect(demod, dst) + +if __name__ == '__main__': + try: + my_top_block().run() + except KeyboardInterrupt: + pass diff --git a/host/ubertooth-dump.c b/host/ubertooth-dump.c new file mode 100644 index 0000000..7165a2a --- /dev/null +++ b/host/ubertooth-dump.c @@ -0,0 +1,125 @@ +/* + * Copyright 2010 Michael Ossmann + * + * This file is part of ubertooth. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + * + * adapted from TestThroughput.c from micropendous project: + * Created: 2008-08-15 by Opendous Inc. - basic Custom-Class USB communication example + * Edit: 2009-08-28 by www.ilmarin.info - all SpeedTest-related code + * Last Edit: 2009-10-04 by Opendous Inc. - minor alterations + */ +#include +#include + +#define VENDORID 0xffff +#define PRODUCTID 0x0005 +#define IN_EP 0x82 +#define IN_EP_SIZE 64 +#define OUT_EP 0x05 +#define OUT_EP_SIZE 64 +#define CONFIGNUM 1 +#define INTERFACENUM 1 +#define TIMEOUT 2000 +#define BUFFER_SIZE 102400 + +/* tell ubertooth to stream rx */ +void send_command_rx(usb_dev_handle *udev) +{ + const unsigned char command = 'r'; + int ret; + + ret = usb_bulk_write(udev, OUT_EP, &command, 1, TIMEOUT); + if (ret != 1) { + printf("[Write] returned: %d , failed to write\n", ret); + exit(1); + } +} + +/* stream ubertooth output to stdout */ +void stream_rx(usb_dev_handle *udev, int block_size) +{ + unsigned char buffer[BUFFER_SIZE]; + int ret; + int i, j; + + if (block_size > BUFFER_SIZE) + block_size = BUFFER_SIZE; + + while (1) { + ret = usb_bulk_read(udev, IN_EP, buffer, block_size, TIMEOUT); + if (ret < 0) { + printf("[Read] returned: %d , failed to read\n", ret); + continue; + } + for (i = 0; i < ret; i++) + for (j = 0; j < 8; j++) { + printf("%c", (buffer[i] & 0x80) >> 7 ); + buffer[i] <<= 1; + } + fflush(stderr); + } +} + +int main(void) +{ + struct usb_bus *bus; + struct usb_device *dev; + usb_dev_handle *udev; + int ret; + + /* let libusb print all debug messages */ + usb_set_debug(255); + + usb_init(); + usb_find_busses(); + usb_find_devices(); + + for (bus = usb_get_busses(); bus; bus = bus->next) { + for (dev=bus->devices;dev;dev=dev->next) { + + if ((dev->descriptor.idVendor==VENDORID) && (dev->descriptor.idProduct==PRODUCTID)) { + + udev = usb_open(dev); + + /* tell libusb to use the CONFIGNUM configuration of the device */ + usb_set_configuration(udev, CONFIGNUM); + + #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP + /* detach the automatically assigned kernel driver from the current interface */ + usb_detach_kernel_driver_np(udev, INTERFACENUM); + #endif + + /* claim the interface for use by this program */ + ret = usb_claim_interface(udev, INTERFACENUM); + if (ret != 0) { + printf("failed to claim interface\n"); + return ret; + } + + send_command_rx(udev); + stream_rx(udev,512); + + /* make sure other programs can still access this device */ + /* release the interface and close the device */ + usb_release_interface(udev, INTERFACENUM); + usb_close(udev); + } + } + } + return 0; +}