Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
sniffer.c File Reference

Sniffer implementation for capturing 802.15.4 packets on a given channel. More...

#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <assert.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "ca821x-posix/ca821x-posix-evbme.h"
#include "ca821x-posix/ca821x-posix.h"
#include "evbme_messages.h"
Include dependency graph for sniffer.c:

Classes

struct  PCPS_DATA_indication_pset_8211
 parameter structures which have been duplicated from mac_messages.h to be able to handle all devices More...
 
struct  PCPS_DATA_indication_pset_8212
 
struct  pcap_hdr_s
 Pcap file header struct as https://wiki.wireshark.org/Development/LibpcapFileFormat. More...
 
struct  pcaprec_hdr_s
 Pcap packet header struct as https://wiki.wireshark.org/Development/LibpcapFileFormat. More...
 

Macros

#define DEFAULT_PIPE   "/tmp/cascoda_"
 
#define LINKTYPE_ETHERNET   1
 Pcap link types, see https://www.tcpdump.org/linktypes.html. More...
 
#define LINKTYPE_IEEE802_15_4_WITHFCS   195
 
#define LINKTYPE_IEEE802_15_4_TAP   283
 
#define MAX_HEADER_LEN   512
 headers for encapsulating IEEE802.15.4 frames for pcap. More...
 
#define HEADER_LEN_ETH   14;
 
#define HEADER_LEN_TAP   28;
 
#define HEADER_POSITION_RSSI   16
 
#define HEADER_POSITION_LQI   24
 

Typedefs

typedef enum ca_device_type ca_device_type
 device type More...
 
typedef struct pcap_hdr_s pcap_hdr_t
 Pcap file header struct as https://wiki.wireshark.org/Development/LibpcapFileFormat. More...
 
typedef struct pcaprec_hdr_s pcaprec_hdr_t
 Pcap packet header struct as https://wiki.wireshark.org/Development/LibpcapFileFormat. More...
 

Enumerations

enum  ca_device_type { DEV_UNKNOWN = 0 , DEV_CA8210 = 1 , DEV_CA8211 = 2 , DEV_CA8212 = 3 }
 device type More...
 
enum  { OUT_MODE_HEX , OUT_MODE_PCAP }
 Output mode for formatting printed data. More...
 

Functions

 ca_static_assert (sizeof(pcap_hdr_t)==24)
 
 ca_static_assert (sizeof(pcaprec_hdr_t)==16)
 
int main (int argc, char *argv[])
 

Variables

ca_device_type DeviceType = DEV_UNKNOWN
 
uint32_t link_type = LINKTYPE_IEEE802_15_4_TAP
 
uint8_t ethernet_header []
 headers for encapsulating IEEE802.15.4 frames for pcap. More...
 
uint8_t tap_header []
 
enum { ... }  out_mode = OUT_MODE_HEX
 Output mode for formatting printed data. More...
 
struct ca821x_dev sDeviceRef
 static cascoda device reference More...
 
struct timespec start
 
FILE * output
 
bool debugMode = false
 Enable logging of extra info to stderr in pcap mode. More...
 
uint8_t channel = 0
 Channel we are sniffing on. More...
 
char default_pipe [30]
 Static storage for default pipe name. More...
 
char * dPipeName = NULL
 Pointer to dynamic pipe name. More...
 
uint32_t time_till_new_capture = 0
 If this is nonzero, then wireshark will be used in ring buffer mode, and a new capture will be started once every "time_till_new_capture" seconds. More...
 

Detailed Description

Sniffer implementation for capturing 802.15.4 packets on a given channel.

Macro Definition Documentation

◆ DEFAULT_PIPE

#define DEFAULT_PIPE   "/tmp/cascoda_"

◆ HEADER_LEN_ETH

#define HEADER_LEN_ETH   14;

◆ HEADER_LEN_TAP

#define HEADER_LEN_TAP   28;

◆ HEADER_POSITION_LQI

#define HEADER_POSITION_LQI   24

◆ HEADER_POSITION_RSSI

#define HEADER_POSITION_RSSI   16

◆ LINKTYPE_ETHERNET

#define LINKTYPE_ETHERNET   1

◆ LINKTYPE_IEEE802_15_4_TAP

#define LINKTYPE_IEEE802_15_4_TAP   283

◆ LINKTYPE_IEEE802_15_4_WITHFCS

#define LINKTYPE_IEEE802_15_4_WITHFCS   195

◆ MAX_HEADER_LEN

#define MAX_HEADER_LEN   512

headers for encapsulating IEEE802.15.4 frames for pcap.

Typedef Documentation

◆ ca_device_type

device type

◆ pcap_hdr_t

◆ pcaprec_hdr_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Output mode for formatting printed data.

Enumerator
OUT_MODE_HEX 

Print in hex.

OUT_MODE_PCAP 

Print binary pcap format.

◆ ca_device_type

device type

Enumerator
DEV_UNKNOWN 
DEV_CA8210 
DEV_CA8211 
DEV_CA8212 

Function Documentation

◆ ca_static_assert() [1/2]

ca_static_assert ( sizeof(pcap_hdr_t = =24)

◆ ca_static_assert() [2/2]

ca_static_assert ( sizeof(pcaprec_hdr_t = =16)

◆ main()

int main ( int  argc,
char *  argv[] 
)

Variable Documentation

◆ channel

uint8_t channel = 0

Channel we are sniffing on.

◆ debugMode

bool debugMode = false

Enable logging of extra info to stderr in pcap mode.

◆ default_pipe

char default_pipe[30]

Static storage for default pipe name.

◆ DeviceType

◆ dPipeName

char* dPipeName = NULL

Pointer to dynamic pipe name.

◆ ethernet_header

uint8_t ethernet_header[]
Initial value:
= {0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0x22,
0x22,
0x22,
0x22,
0x22,
0x22,
0x80,
0x9a}

headers for encapsulating IEEE802.15.4 frames for pcap.

for TAP header doc see: https://github.com/jkcko/ieee802.15.4-tap/blob/master/IEEE%20802.15.4%20TAP%20Link%20Type%20Specification.pdf

◆ link_type

uint32_t link_type = LINKTYPE_IEEE802_15_4_TAP

◆ 

enum { ... } out_mode

Output mode for formatting printed data.

◆ output

FILE* output

◆ sDeviceRef

struct ca821x_dev sDeviceRef

static cascoda device reference

◆ start

struct timespec start

◆ tap_header

uint8_t tap_header[]
Initial value:
= {0x00,
0x00,
0x1C,
0x00,
0x00,
0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01,
0x00, 0x04, 0x00,
0x00,
0x00, 0x00, 0x00,
0x0A,
0x00, 0x01, 0x00,
0x00,
0x00, 0x00, 0x00}

◆ time_till_new_capture

uint32_t time_till_new_capture = 0

If this is nonzero, then wireshark will be used in ring buffer mode, and a new capture will be started once every "time_till_new_capture" seconds.