Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: initial import of the ZEP protocol #2627

Merged
merged 3 commits into from
Jul 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ ifneq (,$(filter xbee,$(USEMODULE)))
USEMODULE += ng_ieee802154
endif

ifneq (,$(filter ng_zep,$(USEMODULE)))
USEMODULE += hashes
USEMODULE += ng_ieee802154
USEMODULE += ng_udp
USEMODULE += random
USEMODULE += vtimer
endif

ifneq (,$(filter ng_ieee802154,$(USEMODULE)))
ifneq (,$(filter ng_ipv6, $(USEMODULE)))
USEMODULE += ng_sixlowpan
Expand Down
3 changes: 3 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ endif
ifneq (,$(filter ng_pktbuf,$(USEMODULE)))
DIRS += net/crosslayer/ng_pktbuf
endif
ifneq (,$(filter ng_zep,$(USEMODULE)))
DIRS += net/application_layer/ng_zep
endif
ifneq (,$(filter ng_rpl_srh,$(USEMODULE)))
DIRS += net/routing/ng_rpl/srh
endif
Expand Down
242 changes: 242 additions & 0 deletions sys/include/net/ng_zep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
/*
* Copyright (C) 2015 Martine Lenders <[email protected]>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for
* more details.
*/

/**
* @defgroup net_ng_zep Zigbee Encapsulation Protocol
* @ingroup net
* @brief Transports IEEE 802.15.4 frames over UDP (can be parsed by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a link to Wireshark documentation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* Wireshark)
* @note Stability uncertain
* @see <a href="https://www.wireshark.org/docs/dfref/z/zep.html">
* ZigBee Encapsulation Protocol in the Wireshark docs
* </a>
* @see <a href="https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob;f=epan/dissectors/packet-zep.c;h=3422eb7876f973f191da98cc4c02aecbd0dbaaeb;hb=HEAD">
* ZEP packet definition in the Wireshark code base.
* </a>
* @{
*
* @file
* @brief ZEP definitions
*
* @author Martine Lenders <[email protected]>
*/


#ifndef NG_ZEP_H_
#define NG_ZEP_H_

#include <inttypes.h>

#include "byteorder.h"
#include "kernel_types.h"
#include "net/ng_ipv6/addr.h"
#include "net/ng_nettype.h"
#include "thread.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Maximum possible packet size in byte
*/
#define NG_ZEP_MAX_PKT_LENGTH (116)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this smaller than IEEE 802.15.4's max packet length?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is it defined? What is it exactly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this defines the frame length, not the payload length.


/**
* @brief Default stack size to use for the ZEP thread
*/
#ifndef NG_ZEP_STACK_SIZE
#define NG_ZEP_STACK_SIZE (THREAD_STACKSIZE_DEFAULT)
#endif

/**
* @brief Default priority for the ZEP thread
*/
#ifndef NG_ZEP_PRIO
#define NG_ZEP_PRIO (THREAD_PRIORITY_MAIN - 5)
#endif

/**
* @brief Default message queue size to use for the ZEP thread.
*/
#ifndef NG_ZEP_MSG_QUEUE_SIZE
#define NG_ZEP_MSG_QUEUE_SIZE (8U)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that this is big enough? Since we're only using this feature on native currently, we don't have to be modest with memory here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think is a big enough value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dunno, but with 32 or 64 we should be on the safe side, I would guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a little big, considering that this should emulate real IEEE 802.15.4 device drivers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this working first and then think about realism (which is probably difficult for ZEP anyway) and optimization. Better be safe than sorry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I would say if 8 or 64 does probably not make too much of a difference. If there is data coming in/going out faster then it is progressed, either sized message queue will fill up fast...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For fragmentation this might be relevant.

#endif

/**
* @brief Default addresses if the CPUID module is not present
* @{
*/
#define NG_ZEP_DEFAULT_ADDR_SHORT (0x98b0)
#define NG_ZEP_DEFAULT_ADDR_LONG (0x4a8a6377552b4249)
/**
* @}
*/

/**
* @brief Channel configuration
* @{
*/
#define NG_ZEP_MIN_CHANNEL (11U)
#define NG_ZEP_MAX_CHANNEL (26U)
#define NG_ZEP_DEFAULT_CHANNEL (17U)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to define these values here again? What makes them different from IEEE 802.15.4 defines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are those defined? Aren't there also versions of the at86… device that excepts different channels.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I realized that there are not yet centralized.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there actually an issue for this open? Otherwise we probably should open one...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* @}
*/

/**
* @brief Default PAN ID
*
* TODO: Read some global network stack specific configuration value
*/
#define NG_ZEP_DEFAULT_PANID (0x0023)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here.


/**
* @brief Option flags for the ZEP device
* @{
*/
#define NG_ZEP_FLAGS_AUTOACK (0x0001) /**< auto ACKS active */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who's actually in charge of sending the ACK for ZEP?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some future implementation of this mechanism ;-)

#define NG_ZEP_FLAGS_SRC_ADDR_LONG (0x0002) /**< send data using long source address */
#define NG_ZEP_FLAGS_DST_ADDR_LONG (0x0004) /**< send data using long destination address */
#define NG_ZEP_FLAGS_USE_SRC_PAN (0x0008) /**< do not compress source PAN ID */
/**
* @}
*/

/**
* @brief Default UDP port for ZEP
*/
#define NG_ZEP_DEFAULT_PORT (17754)

/**
* @brief Type == Data for ZEPv2 header
*/
#define NG_ZEP_V2_TYPE_DATA (1)

/**
* @brief Type == Ack for ZEPv2 header
*/
#define NG_ZEP_V2_TYPE_ACK (2)

/**
* @brief Mask for length field
*/
#define ZEP_LENGTH_MASK (0x7f)

/**
* @brief ZEP header definition
*/
typedef struct __attribute__((packed)) {
char preamble[2]; /**< Preamble code (must be "EX") */
uint8_t version; /**< Protocol Version (must be 1 or 2) */
} ng_zep_hdr_t;

/**
* @brief ZEPv1 header definition
* @extends ng_zep_hdr_t
*/
typedef struct __attribute__((packed)) {
char preamble[2]; /**< preamble code (must be "EX") */
uint8_t version; /**< protocol Version (must be 1) */
uint8_t chan; /**< channel ID */
network_uint16_t dev; /**< device ID */
uint8_t lqi_mode; /**< CRC/LQI Mode */
uint8_t lqi_val; /**< LQI value */
uint8_t resv[7]; /**< reserved field, must always be 0 */
uint8_t length; /**< length of the frame */
} ng_zep_v1_hdr_t;

/**
* @brief ZEPv2 header definition (type == Data)
* @extends ng_zep_hdr_t
*/
typedef struct __attribute__((packed)) {
char preamble[2]; /**< preamble code (must be "EX") */
uint8_t version; /**< protocol Version (must be 2) */
uint8_t type; /**< type (must be 1/Data) */
uint8_t chan; /**< channel ID */
network_uint16_t dev; /**< device ID */
uint8_t lqi_mode; /**< CRC/LQI Mode */
uint8_t lqi_val; /**< LQI value */
network_uint64_t time; /**< NTP timestamp */
network_uint32_t seq; /**< Sequence number */
uint8_t resv[10]; /**< reserved field, must always be 0 */
uint8_t length; /**< length of the frame */
} ng_zep_v2_data_hdr_t;

/**
* @brief ZEPv2 header definition (type == Ack)
* @extends ng_zep_hdr_t
*/
typedef struct __attribute__((packed)) {
char preamble[2]; /**< preamble code (must be "EX") */
uint8_t version; /**< protocol Version (must be 2) */
uint8_t type; /**< type (must be 2/Ack) */
network_uint32_t seq; /**< Sequence number */
} ng_zep_v2_ack_hdr_t;

/**
* @brief ZEP device descriptor.
*
* @extends ng_netdev_t
*/
typedef struct {
ng_netdev_driver_t *driver; /**< pointer to the device's interface */
ng_netdev_event_cb_t event_cb; /**< netdev event callback */
kernel_pid_t mac_pid; /**< the driver's thread's PID */
/**
* @brief @ref ng_zep_t specific members
* @{
*/
le_uint16_t addr; /**< the device's short address */
le_uint64_t eui64; /**< the device's EUI-64 */
le_uint16_t pan; /**< the device's PAN ID */
uint16_t flags; /**< the device's option flags */
uint32_t seq; /**< the current sequence number for frames */
ng_ipv6_addr_t dst; /**< destination IPv6 address */
uint16_t src_port; /**< source UDP port */
uint16_t dst_port; /**< destination UDP port */
ng_nettype_t proto; /**< the target protocol for received packets */
uint8_t chan; /**< the device's channel */
uint8_t version; /**< ZEP version to use (default 2) */
uint8_t lqi_mode; /**< LQI mode for send packets (default 1) */
/**
* @}
*/
} ng_zep_t;

/**
* @brief Initializion of the ZEP thread and device.
*
* @param[in] dev Network device, will be initialized.
* @param[in] src_port Source port to use in UDP datagrams. Also the port
* @ref net_ng_zep registers to in @ref net_ng_netreg.
* @param[in] dst Destination address to use in IPv6 packets.
* @param[in] dst_port Destination port to use in UDP datagrams.
*
* @return PID of the ZEP thread on success.
* @return -EADDRINUSE, if @p src_port is already ready registered to
* @ref net_ng_netreg.
* @return -EEXIST, if ZEP thread was already created.
* @return -EINVAL, if @ref NG_ZEP_PRIO is greater than or equal to
* @ref SCHED_PRIO_LEVELS
* @return -ENODEV, if @p dev is NULL.
* @return -ENOTSUP, if @p dst is NULL or unspecified address (::).
* @return -EOVERFLOW, if there are too many threads running already
*/
kernel_pid_t ng_zep_init(ng_zep_t *dev, uint16_t src_port, ng_ipv6_addr_t *dst,
uint16_t dst_port);

#ifdef __cplusplus
}
#endif

#endif /* NG_ZEP_H_ */
/**
* @}
*/
1 change: 1 addition & 0 deletions sys/net/application_layer/ng_zep/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
Loading