Skip to content

Commit

Permalink
Merge pull request #40 from ElectronicCats/pycatsniffer
Browse files Browse the repository at this point in the history
Pycatsniffer update
  • Loading branch information
sabas1080 committed Mar 14, 2023
2 parents bcc1e08 + d6a4832 commit 610f475
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 49 deletions.
44 changes: 34 additions & 10 deletions firmware/pycatsniffer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,61 @@ How to Use
==========
Run pycatsniffer
----------------
**pycatsniffer**'s main role it to read packets captured from the CatSniffer board and pipe the packets in PCAP format to a named pipe (by default "/tmp/ccsniffpiper").
**pycatsniffer**'s main role it to read packets captured from the CatSniffer board and pipe the packets in PCAP format to a named pipe (by default `/tmp/ccsniffpiper`).

Default mode starts with Bluetooth Low Energy configuration.
For BLE, the advertising channel (`37`, `38` or `39`) must be selected, the deafult is `37`.

The capture device can be configured to follow a data connection between a specific Bluetooth Low Energy Master (Initiator) and Slave device. Type `-a` in the options menu and write the address of the Initiator (Master) device next. If this option is not setted, the capture device will start to follow the first data connection that appears on the selected advertising channel.

To get this default behaviour, just run the command:
`python pycatsniffer.py`

To see further information, run the help command:
`python pycatsniffer.py -h`
The following options will be available

Commands:
* `c: Print current RF Channel`
* `n: Trigger new pcap header before the next frame`
* `h,?: Print this message`
* `[37,39]: Change RF channel`
* `s: Start/stop the packet capture`
* `q: Quit`

To run in headless mode and pipe using /tmp/ccsniffpiper
`sudo python pycatsniffer.py -d -f /tmp/ccsniffpiper`
In this mode the output of captured packets will only be displayed on the terminal.

You can start packet capture by pressing the `s` key followed by the `Enter` key.
To stop, press the `s` key again followed by the `Enter` key again.

To run in normal mode and pipe using `/tmp/ccsniffpiper` type `sudo python pycatsniffer.py -f /tmp/ccsniffpiper` in the terminal

Start the packet capture by pressing the `s` key and then the `Enter` key in the terminal where pycatsniffer is running.
In headless mode use `sudo python pycatsniffer.py -d -f /tmp/ccsniffpiper`

To see further information, run the help command:
`python pycatsniffer.py -h`

Run Wireshark
-------------
To receive the packets from **pycatsniffer** you need to use Wireshark to start a capture using a FIFO file as the 'interface'. By default, **pycatsniffer** will use `/tmp/ccsniffpiper`.

To setup Wireshark correctly, perform the following steps:
* Go to Capture -> options -> Manage Interfaces -> New (under Pipes) -> type `/tmp/ccsniffpiper` and save.
* The pipe will then appear as an interface. Start a capture on it.

* Start Wireshark using sudo wireshark (linux)
* Add new pipe interface: Capture -> Options -> Manage Interfaces -> Pipes-> click on + to add new pipe -> type `/tmp/ccsniffpiper` and apply.
Note - The capture interface will not be saved.
* Click the start button to start a capture.
* The pipe will then appear as an interface.

General packet format
======================================
This is just * **[documentation](https://software-dl.ti.com/lprf/packet_sniffer_2/docs/user_guide/html/sniffer_fw/firmware/command_interface.html)** of the packet format from the TI firmware on CatSniffer.
This is just **[documentation](https://software-dl.ti.com/lprf/packet_sniffer_2/docs/user_guide/html/sniffer_fw/firmware/command_interface.html)** of the packet format from the TI firmware on CatSniffer.

The UART packet format is shown in the table below.

0 1 2 3 4 5 6 7 -2 -1 EOF
|_______|_______|_______|_______|_______|_______|_______|>> ... |_______|_______|_______|
|Start of Frame |Packet Packet Length |Payload >> | FCS | End of Frame|
| |Info | | | | |
| |Info | | | | |
2B 1B 2B 0-2049B 1B 2B

FAQs
Expand All @@ -63,5 +87,5 @@ FAQs

* Check that the sniffer is sniffing in the correct channel.
* Check that you have opened the named pipe that is being piped to.
*In particular, I would recommend reading the "Run Wireshark" section carefully.*
* In particular, I would recommend reading the "Run Wireshark" section carefully.*

33 changes: 0 additions & 33 deletions firmware/pycatsniffer/pingcatsniffer.py

This file was deleted.

25 changes: 19 additions & 6 deletions firmware/pycatsniffer/pycatsniffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
In interactive mode, the user can also input commands from stdin.
"""

# CC1352P1

import serial
import argparse
import binascii
Expand All @@ -62,7 +64,7 @@
'log_level': 'INFO',
'log_file': 'ccsniffpiper.log',
'channel': 37,
'initiator_address':0x000000000000,
'initiator_address':'000000000000',
'port':'/dev/ttyACM0'
}

Expand Down Expand Up @@ -478,12 +480,11 @@ def arg_parser():
in_group.add_argument(
'-a',
'--address',
type=int,
type=str,
action='store',
#choices=list(range(37, 40)),
default=defaults['initiator_address'],
help='Connect to Initiator Address. \
(Default: %s)' % (defaults['initiator_address'], ))
(Default: %s)' % (defaults['initiator_address'], ))
out_group = parser.add_argument_group('Output Options')
out_group.add_argument(
'-f',
Expand Down Expand Up @@ -625,10 +626,22 @@ def handlerDispatcher(timestamp, macPDU):
handlers.append(HexdumpHandler(args.hex_file))
if args.pcap_file is not False:
handlers.append(PcapDumpHandler(args.pcap_file))
if args.address != '000000000000':
print('Initiator: %s\n' % args.address)
address_bytes = bytearray.fromhex(args.address)
address_bytes.reverse()
initiator[5:11] = address_bytes
#adjust FCS
total = 0
for i in range(len(address_bytes)):
total += address_bytes[i]
initiator[11] = (total + 0x76) & 0xff


if args.headless is False:
h = io.StringIO()
h.write('Commands:\n')
h.write('HELL Commands:\n')
#h.write('Initiator: %s\n' % defaults['initiator_address'])
h.write('c: Print current RF Channel\n')
h.write('n: Trigger new pcap header before the next frame\n')
h.write('h,?: Print this message\n')
Expand Down Expand Up @@ -712,4 +725,4 @@ def handlerDispatcher(timestamp, macPDU):
if snifferDev.isRunning():
snifferDev.stop()
dump_stats()
sys.exit(0)
sys.exit(0)

0 comments on commit 610f475

Please sign in to comment.