Packet Sniffer 
---------------

Ubiqua Protocol Analyzer
^^^^^^^^^^^^^^^^^^^^^^^^^

Install the Required Software
==============================

- Download the Ubilogix Ubiqua packet sniffer software from:
  https://www.ubilogix.com/ubiqua/

- To get the drivers for the CC2531EMK dongle install the TI Packet sniffer from:
  http://www.ti.com/tool/packet-sniffer

- To program the CC2531EMK install TI Flash Programmer from:
  http://www.ti.com/tool/flash-programmer

- To get the drivers for the CC2650/CC2652/CC1352 LaunchPad install the TI Packet sniffer 2 from:
  http://www.ti.com/tool/packet-sniffer

- To program the CC2650/CC2652/CC1352 LaunchPad install UniFlash from:
  http://www.ti.com/tool/UNIFLASH

Required Hardware
==============================

**One of the following boards** should be used:

- TI CC2531EMK USB Dongle: http://www.ti.com/tool/CC2531USB-RD

  - (optional for programming CC2531EMK) CC-debugger http://www.ti.com/tool/cc-debugger

- TI CC2652 Launchpad: http://www.ti.com/tool/LAUNCHXL-CC26X2R1

- TI CC1352 Launchpad: http://www.ti.com/tool/LAUNCHXL-CC1352R1

- TI CC1352 PA Launchpad: http://www.ti.com/tool/LAUNCHXL-CC1352P

- TI CC2650 Launchpad: http://www.ti.com/tool/LAUNCHXL-CC2650

Hardware Setup
==============================

- Connect the CC2531EMK or CC2650/CC2652/CC1352 LaunchPad to the computer with Ubiqua installed.

- If necessary, program your relevant sniffer hardware. 

  - For CC2531EMK, use the hex
    image ``sniffer_fw_cc2531.hex`` at ``C:\Program Files (x86)\Texas Instruments
    \SmartRF Tools\Packet Sniffer\bin\general\firmware`` and Flash Programmer.

  - To use the CC2531EMK, the Cebal driver must be installed. If you have
    installed Flash Programmer, the Cebal driver should already be installed.
    However, if the driver is not installed, Ubiqua provides the necessary files
    for installing the Cebal driver. The installation files are found under
    ``C:\Program Files (x86)\Ubilogix\Drivers\TI\``, with ``cebal2.*`` files for 32\-bit
    Windows and ``cebal2_x64.*`` files for 64\-bit Windows. Depending on which
    Windows version you are using, refer to a corresponding guide for how to
    install Windows drivers.

  - For CC2650/CC2652/CC1352 LaunchPad, use ``sniffer_fw.hex`` at ``C:\Program Files (x86)\Texas 
    Instruments\SmartRF Tools\SmartRF Packet Sniffer 2\sniffer_fw\bin\{your_device}`` and
    UniFlash.

Running the Packet Sniffer
==============================

#.  Connect your sniffing hardware to your PC.

#.  Start Ubiqua.

#.  Select Menu |rarr| Device |rarr| Add Device, and the Add Device window will appear.

    .. figure:: resources/fig-ubiqua-add-device.png
       :alt: ubiqua add device

       ubiqua add device

#.  In the Available Devices column click the Local Devices expander, and select 
    your hardware, either the CC2531EMK or the Application COM Port of the CC2650/CC2652/CC1352 LaunchPad.

#.  For the CC2531EMK, follow the prompts to add the device. For the CC2650/CC2652/CC1352 LaunchPad, refer to the 
    settings below:

    .. figure:: resources/fig-ubiqua-select-device.png
      :alt: ubiqua select device

      Ubiqua select device

#.  Right click on your device in the Device Manager window, and select the 
    Protocol Stack option.

#.  Click on the Zigbee checkbox.

    .. figure:: resources/fig-ubiqua-select-zigbee-protocol.png
      :alt: ubiqua select Zigbee protocol option

      Ubiqua select Zigbee protocol option

#.  Choose the Channel

    - In Z-Stack, the channel is set by :code:`DEFAULT_CHANLIST` in :code:`ti_zstack_config.h`.
      For details, see :ref:`z-stack-overview-configuring-channel`.

    From Ubiqua, select Menu |rarr| Device Channel, and choose the matching channel:
    
    .. figure:: resources/fig-ubiqua-select-channel.png
      :alt: ubiqua select channel

      Ubiqua channel selection

#.  Enter the Default TC Link Key
    
    - In order to decrypt Zigbee traffic, you will need to enter the default Trust Center Link Key
      into the Ubiqua keychain.

    From Ubiqua, select Tools |rarr| Options |rarr| Security |rarr| Add |rarr| Application or Trust Center Link Key
    
    Enter the following key: 

    ``5a6967426565416c6c69616e63653039``

      .. figure:: resources/fig-ubiqua-tc-linkkey.png
        :alt: ubiqua tc link key entry

#.  Start Capture

    From Ubiqua, Select Menu |rarr| Device |rarr| Start Device

    .. figure:: resources/fig-ubiqua-start-sniff.png
      :alt: ubiqua start

      Starting capture

#.  If required, Select: Menu |rarr| View |rarr| Traffic View (or other selections) to
    view activity.

Wireshark
^^^^^^^^^^

Install the Required Software
==============================

- TI Packet Sniffer 2 v1.10+:
  http://www.ti.com/tool/packet-sniffer

- Wireshark 4.x:
  https://www.wireshark.org/#download

- To program the CC2650/CC2652/CC1352 LaunchPad install UniFlash from:
  http://www.ti.com/tool/UNIFLASH


Required Hardware
==============================

**One of the following boards** should be used:

- TI CC2652 Launchpad: http://www.ti.com/tool/LAUNCHXL-CC26X2R1

- TI CC1352 Launchpad: http://www.ti.com/tool/LAUNCHXL-CC1352R1

- TI CC1352 PA Launchpad: http://www.ti.com/tool/LAUNCHXL-CC1352P-2

- TI CC2650 Launchpad: http://www.ti.com/tool/LAUNCHXL-CC2650

Hardware Setup
==============================

- Connect the CC2650/CC2652/CC1352 LaunchPad to the computer with Ubiqua installed 
  and determine the correct COM Port for your LaunchPad. It will 
  be the "XDS110 Class Application/User UART" port for your device, you can 
  determine this in Windows by going to **Device Manager > Ports** 

- If necessary, program your relevant sniffer hardware. 

  - For CC2650/CC2652/CC1352 LaunchPads, use ``sniffer_fw.hex`` at ``C:\Program Files (x86)\Texas Instruments
    \SmartRF Tools\SmartRF Packet Sniffer 2\sniffer_fw\bin\{your_device}`` and
    UniFlash.

Running the Packet Sniffer
==============================

#.  Connect your sniffing hardware to your PC.

#.  Start SmartRF Packet Sniffer 2 Sniffer Agent and select **Device Configuration**

    .. figure:: resources/fig-sniffer-agent-config.png
      :alt: sniffer agent config

#. Select your IEEE channel to sniff

    .. figure:: resources/fig-sniffer-agent-channel-config.png
      :alt: sniffer agent channel config

#.  If your Sniffer Agent looks like this, you are ready to set up Wireshark:

    .. figure:: resources/fig-sniffer-agent-waiting-for-connection.png
      :alt: sniffer agent waiting for connection

#.  Add the TI 15.4 Wireshark Dissector to Wireshark (assuming x64 installation)

    Navigate to ``C:\Program Files (x86)\Texas Instruments\SmartRF Tools\
    SmartRF Packet Sniffer 2\wireshark\plugins\3.0.x\`` and copy ``ti802154ge-x64-2x.dll`` and ``tirpi-x64-2x.dll`` 
    to ``C:\Program Files\Wireshark\plugins\3.0\``


#.  Open Wireshark go to **Edit > Preferences > Protocols > Zigbee** add the Zigbee TC Link Key
    
    ``5a6967426565416c6c69616e63653039``

    .. figure:: resources/fig-wireshark-tc-link-key.png
      :alt: wireshark tc link key

#.  Close Wireshark and create a new Desktop shortcut for Wireshark 
    and add the following to the path: ``-i\\.\pipe\tiwspc_data -k``
    
    This will set up the Pipe that sends data from Sniffer Agent into Wireshark

    .. figure:: resources/fig-wireshark-shortcut-config.png
      :alt: wireshark shortcut config

#.  Open Wireshark with the new shortcut and you will see Wireshark sniffing Zigbee data.
