Digi XBee(R) ANSI C Host Library
ipv4.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Digi International Inc.,
3  * All rights not expressly granted are reserved.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
7  * You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
10  * =======================================================================
11  */
12 
20 /*
21  Dev notes:
22 
23  Consider this a starting point. I think we could develop something
24  based on the wpan/aps.h APIs for using "envelope" structures to
25  route frames. Implementing Berkeley sockets is going to take a bit
26  of work (and buffering), but keeping tables for open and listening
27  sockets with handlers to receive ipv4_envelope_t structures should
28  work well for typical use cases.
29 */
30 
31 #ifndef XBEE_IPV4_H
32 #define XBEE_IPV4_H
33 
34 #include "xbee/platform.h"
35 #include "xbee/device.h"
36 
37 #if (!XBEE_WIFI_ENABLED) && (!XBEE_CELLULAR_ENABLED)
38  #error "At least one of XBEE_WIFI_ENABLED and XBEE_CELLULAR_ENABLED " \
39  "must be defined as non-zero to use this header."
40 #endif
41 
43 
45 #define XBEE_FRAME_TRANSMIT_IPV4 0x20
46 
48 #define XBEE_FRAME_RECEIVE_IPV4 0xB0
49 
55 #define XBEE_IPV4_PROTOCOL_UDP 0
56 #define XBEE_IPV4_PROTOCOL_TCP 1
57 #define XBEE_IPV4_PROTOCOL_SSL 4
58 
60 
64 #define XBEE_IPV4_TX_OPT_NONE 0
65 #define XBEE_IPV4_TX_OPT_TCP_CLOSE (1<<1)
66 
68 #define XBEE_IPV4_MAX_PAYLOAD 1500
70 
73 typedef XBEE_PACKED(xbee_header_transmit_ipv4_t, {
74  uint8_t frame_type;
75  uint8_t frame_id;
76  uint32_t remote_addr_be;
77  uint16_t remote_port_be;
78  uint16_t local_port_be;
79  uint8_t protocol;
80  uint8_t options;
82 
85 typedef XBEE_PACKED(xbee_frame_receive_ipv4_t, {
86  uint8_t frame_type;
87  uint32_t remote_addr_be;
88  uint16_t local_port_be;
89  uint16_t remote_port_be;
90  uint8_t protocol;
91  uint8_t status;
92  uint8_t payload[1];
94 
95 /*
96  Dev notes:
97  - We'll keep remote address in big-endian format, since it's easier to
98  always deal with it that way, and we always used 64-bit IEEE addresses
99  on 802.15.4 networks in big-endian byte order.
100  - Easy to reply to a message, just copy the start of the envelope.
101  (offsetof(ipv4_envelope_t, options) bytes)
102 
103  For docs:
104  @sa xbee_ipv4_ntoa(), xbee_ipv4_protocol_str()
105 */
106 /* Similar concept to wpan_envelope_t, needs some more documentation. */
107 typedef struct xbee_ipv4_envelope_t {
108  // first group of members are common when creating reply envelope
114 
115  // second group of members are modified when creating reply envelope
116  uint16_t options;
117  const void FAR *payload;
120 
121 
132  const xbee_ipv4_envelope_t FAR *original);
133 
134 
139  bool_t include_payload);
140 
141 
155 
167 int xbee_ipv4_receive_dump(xbee_dev_t *xbee, const void FAR *raw,
168  uint16_t length, void FAR *context);
169 
180 int xbee_ipv4_ntoa(char buffer[16], uint32_t ip_be);
181 
192 int xbee_ipv4_aton(const char * cp, uint32_t *ip_be);
193 
206 char *xbee_ipv4_protocol_str(char buffer[8], uint8_t protocol);
207 
209 
210 // If compiling in Dynamic C, automatically #use the appropriate C file.
211 #ifdef __DC__
212  #use "xbee_sms.c"
213 #endif
214 
215 #endif
216 
uint8_t protocol
protocol for message
Definition: ipv4.h:113
unsigned long uint32_t
32-bit unsigned integer
Definition: platform_config.h:43
int xbee_ipv4_receive_dump(xbee_dev_t *xbee, const void FAR *raw, uint16_t length, void FAR *context)
Dump received IPv4 frame to stdout.
Definition: xbee_ipv4.c:166
uint16_t length
number of bytes in payload
Definition: ipv4.h:118
#define FAR
On platforms with "far" pointers, define to the proper keyword; empty definition if not required...
Definition: platform.h:396
uint32_t remote_addr_be
remote device&#39;s IP address
Definition: ipv4.h:110
void xbee_ipv4_envelope_dump(const xbee_ipv4_envelope_t FAR *envelope, bool_t include_payload)
Print the contents of an IPv4 envelope to stdout.
Definition: xbee_ipv4.c:143
#define XBEE_BEGIN_DECLS
Macro defined to.
Definition: platform.h:41
Common header for Hardware Abstraction Layer.
int xbee_ipv4_ntoa(char buffer[16], uint32_t ip_be)
Format a big-endian IP address from an XBee frame as a "dotted quad", four decimal numbers separated ...
Definition: xbee_ipv4.c:26
Header of XBee API frame type 0x20 (XBEE_FRAME_TRANSMIT_IPV4); sent from host to XBee.
Definition: ipv4.h:81
const void FAR * payload
contents of message
Definition: ipv4.h:117
int xbee_ipv4_envelope_send(const xbee_ipv4_envelope_t FAR *envelope)
Send an IPv4 packet.
Definition: xbee_ipv4.c:96
unsigned short uint16_t
16-bit unsigned integer
Definition: platform_config.h:41
unsigned char uint8_t
8-bit unsigned integer
Definition: platform_config.h:39
Definition: ipv4.h:107
int xbee_ipv4_envelope_reply(xbee_ipv4_envelope_t FAR *reply, const xbee_ipv4_envelope_t FAR *original)
Address a reply envelope using fields from a received envelope.
Definition: xbee_ipv4.c:82
Format of XBee API frame type 0xB0 (XBEE_FRAME_RECEIVE_IPV4); received from XBee by host...
Definition: ipv4.h:93
Definition: device.h:361
xbee_dev_t * xbee
interface received on/to send to
Definition: ipv4.h:109
#define XBEE_END_DECLS
Macro defined to.
Definition: platform.h:42
int xbee_ipv4_aton(const char *cp, uint32_t *ip_be)
Takes an address separated by &#39;.
Definition: xbee_ipv4.c:36
uint16_t remote_port
port on remote device
Definition: ipv4.h:112
uint16_t local_port
port on this device
Definition: ipv4.h:111
int bool_t
Variable that can hold 0 or 1, may be an int for speed purporses or uint8_t for size optimization...
Definition: platform_config.h:51
char * xbee_ipv4_protocol_str(char buffer[8], uint8_t protocol)
A string description of the "protocol" byte from an XBee IPv4 frame.
Definition: xbee_ipv4.c:61