Code Search for Developers
 
 
  

link_headers.h from EmStar at Krugle


Show link_headers.h syntax highlighted

/*
 *
 * Copyright (c) 2003 The Regents of the University of California.  All 
 * rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Neither the name of the University nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include <timesync/sync_structs.h>

#ifndef __LINK_HEADERS_H__
#define __LINK_HEADERS_H__

/*
 *  Flooding Wire Protocol
 */

typedef uint16_t flood_nonce_t;

typedef struct flood_pkt {
  node_id_t original_src;	/* who sent this packet originally */
  node_id_t final_dst;		/* where it's ultimately going to */
  uint8_t hops_remaining;	/* how many more hops it can be forwarded */
  uint8_t inner_type;		/* the type of the packet once flood header is stripped */
  flood_nonce_t nonce;		/* unique id to prevent floodd looping */
  char data[0];
} __attribute__((packed)) flood_pkt_t;


/*
 *  RNP Routing Wire Protocol
 */

typedef struct rnp_pkt {
  node_id_t original_src;	/* who sent this packet originally */
  node_id_t final_dst;		/* where it's ultimately going to */
  uint8_t hops_remaining;	/* how many more hops it can be 
                                   forwarded */
  uint8_t inner_type;		/* the type of the packet once flood 
                                   header is stripped */
  conn_t arnp;                  /* acummulative rnp for this packet */
  char data[0];
} __attribute__((packed)) rnp_pkt_t;



/*
 *  Neighbors Wire Protocol
 *
 *  These are the over-the-air packet formats used by heartbeats.  Each
 *  heartbeat packet contains a header (my ID, my sequence number)
 *  followed by several "HB Acks" that ack HBs we have seen from other
 *  nodes.
 */

typedef struct heartbeat_ack_pkt {
  uint16_t if_id;	  	/* lower 16 bits of the interface id
                                   to save space */
  uint16_t last_seqno_heard;	/* last seqno we heard from you */
  uint16_t conn;                /* conn value of neigh node_id */
} __attribute__((packed)) heartbeat_ack_pkt_t;

typedef struct heartbeat_pkt {
  node_id_t src_id;		/* my node ID */
  uint16_t loc_x;		/* my location, x, in cm */
  uint16_t loc_y;		/* my location, y, in cm */
  uint16_t period;		/* my period in msec */
  uint16_t seqno;		/* the none of this heartbeat */
  heartbeat_ack_pkt_t hb_ack_list[0]; /* list of acks of other seqnos */
} __attribute__((packed)) heartbeat_pkt_t;


/*
 *  LinkStats Wire Protocol
 *
 *  This is the over-the-air packet format used by linkstats.  Each
 *  packet contains a header (my ID, my sequence number) followed by
 *  application data packet.
 */

typedef struct linkstats_pkt {
  node_id_t src_id;		/* my node ID */
  uint64_t seqno;		/* the sequence number of this packet */
  uint8_t inner_type;		/* the type of the packet once linkstats
                                   header is stripped */
  uint8_t data[0];              /* pointer to the following data packet */
} __attribute__ ((packed)) linkstats_pkt_t;


/*
 *  Linkstats NG wire protocol
 *
 *   Currently the default disables prev sends functionality (set to 0)
 *   if LS_MAX_PREV_SENDS is set to larger number, will report time since N
 *   last sends
 */

#define LS_MAX_PREV_SENDS         0
#define LS_RADIX               5000
#define LS_BYTES_PER_RADIX       12

/* length assumed for unknown losses (in radices) */
#define LS_ASSUMED_PACKET_LENGTH  (50 / LS_BYTES_PER_RADIX)

struct prev_send {
  uint16_t timing:12;
  uint16_t length:4;
} __attribute__ ((packed));

typedef struct linkstats2_pkt {
  uint8_t seq;
  uint8_t type;
  struct prev_send prev_send[LS_MAX_PREV_SENDS];
  char data[0];
} __attribute__ ((packed)) linkstats2_pkt_t;


/*
 *  LQE Wire Protocol
 *
 *  This is the over-the-air packet format used by link quality 
 *  estimator (lqe).  Each packet contains a header (my ID, my 
 *  sequence number, etc.) followed by an application data packet.
 */

typedef struct lqe_pkt {
  node_id_t src_id;		/* my node ID */
  uint64_t seqno;		/* the sequence number of this packet */
  node_id_t sender_id;          /* the original sender ID */
  uint8_t inner_type;		/* the type of the packet once lqe header 
                                   is stripped */
  uint8_t data[0];              /* pointer to the following data packet */
} __attribute__ ((packed)) lqe_pkt_t;


/*
 *  HBH Wire Protocol
 *
 *  This is the over-the-air packet format used by hop-by-hop reliable 
 *  scheme (hbh).  Each packet contains a header (my ID, my 
 *  sequence number, etc.) followed by an application data packet.
 */

#define HBH_ACK  1
#define HBH_DATA 2

typedef struct hbh_pkt {
  node_id_t src_id;		/* my node ID */
  uint8_t type;                 /* data or ack? */
  uint64_t seqno;		/* the sequence number of this packet */
  uint8_t inner_type;		/* the type of the packet once lqe header 
                                   is stripped */
  uint8_t data[0];              /* pointer to the following data packet */
} __attribute__ ((packed)) hbh_pkt_t;



/*
 *  Fragmentation Wire Protocol
 */

#define FRAG_INTRO 0
#define FRAG_DATA  1

/* header that RPC daemon sends before a fragment: the part common to
 * both fragment intro and fragment data */
typedef struct {
  u_int packet_type:1;
  u_int frag_id:7;
  u_int16_t byte_id;
} frag_common_header_t;

/* common header used for default fragmentation scheme (fragd) */
typedef struct {
  u_int16_t packet_type:1;
  u_int16_t byte_id:15;
  char pkt_struct[0];
} __attribute__ ((packed)) frag_new_common_header_t;

/* header that RPC daemon sends before a fragment: for a "fragment
 * info" type packet.  */
typedef struct {
  frag_common_header_t hdr;
  u_int32_t checksum;
  u_int8_t type;
} frag_intro_t;

/* intro header used for default fragmentation scheme (fragd) */
typedef struct {
  u_int32_t checksum;
  u_int8_t type;
  char data[0];
} __attribute__ ((packed)) frag_new_intro_t;

/*
 *  StateSync protocols
 */

typedef uint32_t ssync_seq_t;
typedef uint16_t log_seqno_t;
typedef uint64_t list_seqno_t;


typedef struct flow_id {
  if_id_t src;
  if_id_t dst;
  uint8_t src_if;
  uint8_t dst_if;
  uint8_t max_hops;
  uint8_t flow_index;
} __attribute__ ((packed)) flow_id_t;


typedef union {
  uint8_t byte;
  struct {
    uint8_t index:7;
    uint8_t head:1;
  } __attribute__ ((packed)) ci;
}  __attribute__ ((packed)) cl_index_t;


/* opcodes.. */
#define CP_OPCODE_DATA      0  /* data transmission */
#define CP_OPCODE_REFRESH   1  /* seqno refresh */
#define CP_OPCODE_REQ       2  /* request transmission */
#define CP_OPCODE_CINIT     3  /* request initial entry */

/* State Sync protocol subtypes */
#define SSYNC_FLOOD_V1     1
#define SSYNC_RETRANS_V2   4

/* log entry opcodes */
#define SSYNC_LOG_INIT  0    /* init entry (blank?) */
#define SSYNC_LOG_ADD   1    /* add in one chunk */
#define SSYNC_LOG_DEL   2    /* delete key */
#define SSYNC_LOG_FRAG  3    /* add, fragmented */
#define SSYNC_LOG_CONT  4    /* continued, fragmented */
#define SSYNC_LOG_LAST  5    /* last frag */
#define SSYNC_LOG_CHK   6    /* checksum */
#define SSYNC_LOG_TERM  7    /* term/compress/restart log */

#define SSYNC_TYPE_MAX  10 
typedef struct ssync_type {
  uint16_t fixed_len:10;
  uint16_t key_len:6;
  char type[SSYNC_TYPE_MAX];
} __attribute__ ((packed)) ssync_type_t;

/* generic header */

typedef struct ssync_hdr {
  uint8_t version:4;
  uint8_t opcode:3;
  uint8_t unicast:1;
  uint8_t data[0];
} __attribute__ ((packed)) ssync_hdr_t;


/* Multihop protocol version 1 */
typedef struct ssync_protocol {
  ssync_hdr_t hdr;
  uint8_t hops;
  node_id_t source;    /* or, we could just use pkt->src.id */
  ssync_seq_t seqno;
  ssync_type_t type;
  uint8_t data[0];
} __attribute__ ((packed)) ssync_protocol_t;


/*
 *  retrans v2
 */

/* retx command values (in addition to log commands) */
#define RETX2_CTRL_SEQNO      0x08
#define RETX2_CTRL_LIST       0x09
#define RETX2_CTRL_NACK       0x0A
#define RETX2_CTRL_ADDR       0x0B
#define RETX2_CTRL_FLOW       0x0C
#define RETX2_CTRL_NOP        0x0F

/* values for format parameter, when !code_book */
#define RETX2_FMT_SAME        0x00
#define RETX2_FMT_NEW_FID     0x01
#define RETX2_FMT_NEW_TARGET  0x02
#define RETX2_FMT_ESC         0x03

/* retrans2 control byte */
typedef struct ssync_retx2_ctrl {
  uint8_t format:2;        /* FID or codebook bits */
  uint8_t length_set:1;    /* length is set */
  uint8_t code_book:1;     /* code book mode */
  uint8_t command:4;       /* command nybble */
} __attribute__ ((packed)) ssync_retx2_ctrl_t;

/* nack init modes */
#define RETX2_NACK_NONE      0  /* normal nack */
#define RETX2_NACK_INIT_CHK  1  /* init "check" mode -- first entry only */
#define RETX2_NACK_INIT      2  /* init mode */
#define RETX2_NACK_LIST_SET  3  /* list index set */

/* retrans2 NACK control byte */
typedef struct ssync_retx2_nack_ctrl {
  uint8_t last_nack:1;     /* last nack in message */
  uint8_t mode:2;          /* init mode */
  uint8_t seq_count:5;     /* count of missing, or 0 if length set */
} __attribute__ ((packed)) ssync_retx2_nack_ctrl_t;

/* list + sequence number entry (type LIST) */
typedef struct ssync_seqno_entry {
  uint8_t list_index;
  log_seqno_t seqno;
} __attribute__ ((packed)) ssync_seqno_entry_t;

/* flow map entry */
typedef struct flow_entry {
  flow_id_t id;
  uint8_t hops;
} __attribute__ ((packed)) flow_entry_t;  


/*
 *  Acoustic range notify and trigger packet headers 
 *  (typically sent via flooding)
 */

typedef struct range_notify_pkt {
  remote_ts_t chirp_time;
  remote_ts_t chirp_time_end;
  int32_t seqno;
  uint8_t modulation:4;
  uint8_t skip_computation:1;    /* for recording raw data.. skip actual computation */
  uint8_t reserved:3;
  uint32_t seed:24;
  int32_t chirp_index;
  char notation[20];
} __attribute__ ((packed)) range_notify_pkt_t;

#define RANGE_TRIGGER_MAX_NODES  20
typedef struct range_trigger_pkt {
  remote_ts_t start_time;
  uint32_t invalidate:1;
  uint32_t reserved:31;
  node_id_t sequence[RANGE_TRIGGER_MAX_NODES];
} __attribute__ ((packed)) range_trigger_pkt_t;


/*
 *  Acoustic recording triggering packet headers 
 *  (typically sent via flooding)
 */

typedef struct audio_trigger_pkt {
  struct timeval global_start_time;
  uint32_t run_length;
} __attribute__ ((packed)) audio_trigger_pkt_t;


/*
 *  Ping Wire Protocol
 */

/* values for the 'cmd' field */
#define PING_REQUEST 1
#define PING_REPLY   2

/* NOTE: this sucks!  *** FIX ME ***
 * I put the ping wire protocol struct here so linkdump could decode 
 * it.  I am trying to compile the entire repo, and there is a conflict
 * with a ping_pkt_t define in tos-contrib... this is a naming issue. 
 * For now, I will just define it locally in ping and I will not commit
 * the new linkdump (until we fix this).
 */

#if 0
typedef struct ping_pkt {
  unsigned int cmd:2;		/* request or reply, 2 bits */
  unsigned int random_id:14;	/* random client ID, 14 bits */
  uint16_t seqno;		/* sequence number of the ping, 16 bits */
  node_id_t node_id;		/* node ID (it's not part of the link layer) */
} __attribute__ ((packed)) ping_pkt_t;
#endif

#endif




See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  conntest.h
  connview.h
  libmacinfo.h
  link.h
  link.run
  link_headers.h
  link_ioctls.h
  link_multi.h
  link_parse.h
  link_pass.h
  link_structs.h
  linkstats.h
  lqe.h
  neighbor.h
  neighbor_structs.h