Digi XBee(R) ANSI C Host Library
aps.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2013 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 #ifndef __WPAN_APS_H
21 #define __WPAN_APS_H
22 
23 #include "wpan/types.h"
24 
26 
40 typedef struct wpan_envelope_t {
41  // first group of members are common when creating reply envelope
42  struct wpan_dev_t *dev;
47 
48  // second group of members are modified when creating reply envelope
51  uint16_t options;
53  #define WPAN_ENVELOPE_CLUSTER_FLAGS 0x00FF
54  #define WPAN_ENVELOPE_BROADCAST_ADDR 0x0100
56  #define WPAN_ENVELOPE_BROADCAST_EP 0x0200
58  #define WPAN_ENVELOPE_RX_APS_ENCRYPT 0x0400
60 
61  const void FAR *payload;
64 
69 #define WPAN_STACK_PROFILE_PROPRIETARY 0x0
71 #define WPAN_STACK_PROFILE_ZIGBEE 0x1
73 #define WPAN_STACK_PROFILE_ZIGBEE_PRO 0x2
75 
80 #define WPAN_PROFILE_ZDO 0x0000
82 
84 #define WPAN_PROFILE_SMART_ENERGY 0x0109
85 
87 #define WPAN_PROFILE_DIGI 0xC105
88 
96 #define WPAN_MANUFACTURER_DIGI 0x101E
98 #define WPAN_MANUFACTURER_DIGI2 0x1087
100 
102 #define WPAN_MANUFACTURER_TEST1 0xFFF1
103 #define WPAN_MANUFACTURER_TEST2 0xFFF2
105 #define WPAN_MANUFACTURER_TEST3 0xFFF3
107 
112 #define WPAN_ENDPOINT_ZDO 0x00
114 #define WPAN_ENDPOINT_DIGI_SE 0x5E
116 #define WPAN_ENDPOINT_DDO 0xE6
118 #define WPAN_ENDPOINT_DIGI_DEVICE WPAN_ENDPOINT_DDO
119 #define WPAN_ENDPOINT_DIGI_DATA 0xE8
121 #define WPAN_ENDPOINT_BROADCAST 0xFF
123 
126 // (cast to int required by Codewarrior/HCS08 platform if enum is signed)
128 {
130  DIGI_CLUST_SERIAL = 0x0011,
136  DIGI_CLUST_IODATA = 0x0092,
142  DIGI_CLUST_INDIRECT_ROUTE_ERR = 0x00B0,
144 
145  // Unsure of how these clusters are used.
148  DIGI_CLUST_FWUPDATERESP = (int)0xF1FF,
149 };
150 
169 typedef int (*wpan_aps_handler_fn)(
170  const wpan_envelope_t FAR *envelope,
171  void FAR *context
172 );
173 
174 // Actual definition comes later, declare here so we can use it in
175 // function pointer typedefs.
176 struct wpan_ep_state_t;
177 
193 typedef int (*wpan_ep_handler_fn)(
194  const wpan_envelope_t FAR *envelope,
195  struct wpan_ep_state_t FAR *ep_state
196 );
197 
206 
210 
215  const void FAR *context;
216 
220 
225 #define WPAN_CLUST_FLAG_NONE 0x00
227 #define WPAN_CLUST_FLAG_INPUT 0x01
229 #define WPAN_CLUST_FLAG_OUTPUT 0x02
231 #define WPAN_CLUST_FLAG_INOUT 0x03
233 #define WPAN_CLUST_FLAG_SERVER WPAN_CLUST_FLAG_INPUT
235 #define WPAN_CLUST_FLAG_CLIENT WPAN_CLUST_FLAG_OUTPUT
237 #define WPAN_CLUST_FLAG_ENCRYPT 0x10
242 #define WPAN_CLUST_FLAG_ENCRYPT_UNICAST 0x20
247 #define WPAN_CLUST_FLAG_NOT_ZCL 0x80
249 
253 {
256 
260 
264 
268 
271 
274 
280 
283 #define WPAN_CLUSTER_END_OF_LIST 0xFFFF
284 
287 #define WPAN_CLUST_ENTRY_LIST_END { WPAN_CLUSTER_END_OF_LIST }
288 
289 // All wpan-capable devices need to start with the wpan_dev_t struct so that the
290 // wpan layer can share some elements (ieee_address, network_address, payload)
291 // and have access to the function pointers.
292 // Set function pointers to NULL if not implemented on a particular device.
293 
318 typedef int (*wpan_endpoint_send_fn)( const wpan_envelope_t FAR *envelope,
319  uint16_t flags);
320 
325 #define WPAN_SEND_FLAG_NONE 0x0000
326 
327 #define WPAN_SEND_FLAG_ENCRYPTED 0x0001
328 
330 
345 typedef int (*_wpan_config_fn)( struct wpan_dev_t *dev, ...);
346 
356 typedef int (*wpan_tick_fn)( struct wpan_dev_t *dev);
357 
376 typedef const wpan_endpoint_table_entry_t *(*wpan_endpoint_get_next_fn)(
377  struct wpan_dev_t *dev, const wpan_endpoint_table_entry_t *ep);
378 
390 typedef struct wpan_dev_t {
391 // _wpan_config_fn config; ///< change device's cfg
395 
397 
400 
407  #define WPAN_FLAG_NONE 0x0000
408  #define WPAN_FLAG_JOINED 0x0001
410  #define WPAN_FLAG_AUTHENTICATED 0x0002
412  #define WPAN_FLAG_AUTHENTICATION_ENABLED 0x0004
414 
419 
420 } wpan_dev_t;
421 
426 #define WPAN_DEV_IS_JOINED(dev) ((dev)->flags & WPAN_FLAG_JOINED)
427 
432 #define WPAN_DEV_IS_AUTHENTICATED(dev) ((dev)->flags & WPAN_FLAG_AUTHENTICATED)
433 
435 #define WPAN_ENDPOINT_END_OF_LIST 0xFF
436 
439 #define WPAN_ENDPOINT_TABLE_END { WPAN_ENDPOINT_END_OF_LIST }
440 
441 
442 int wpan_tick( wpan_dev_t *dev);
443 
445  uint8_t mask, const wpan_cluster_table_entry_t *entry);
446 
448  const wpan_endpoint_table_entry_t *ep);
449 
451  uint8_t endpoint, uint16_t profile_id);
452 
455 
458 
459 // DEVNOTE: Do we need to use the platform-independent casting macros
460 // to cast this value to uint16_t?
461 #define WPAN_APS_PROFILE_ANY 0xFFFF
462 
463 void wpan_envelope_create( wpan_envelope_t *envelope, wpan_dev_t *dev,
464  const addr64 FAR *ieee, uint16_t network_addr);
465 
467  const wpan_envelope_t FAR *original);
468 
469 int wpan_envelope_send( const wpan_envelope_t FAR *envelope);
470 
471 void wpan_envelope_dump( const wpan_envelope_t FAR *envelope);
472 
473 // Forward declaration of struct for use in function pointer declaration.
474 struct wpan_conversation_t;
493 typedef int (*wpan_response_fn)(
494  struct wpan_conversation_t FAR *conversation,
495  const wpan_envelope_t FAR *envelope);
496 
497 // WPAN_CONVERSATION_*: Return values for wpan_response_fn() function handlers.
498 // Reserve 0 for invalid response and negative for error responses.
500 #define WPAN_CONVERSATION_END 1
501 #define WPAN_CONVERSATION_CONTINUE 2
503 
505 typedef struct wpan_conversation_t {
506  uint8_t transaction_id;
507  void FAR *context;
512  uint16_t timeout; // time to expire converstation
513  wpan_response_fn handler; // if NULL, record is unused
515 
518 #ifndef WPAN_MAX_CONVERSATIONS
519  #define WPAN_MAX_CONVERSATIONS 3
520 #endif
521 
523 #ifndef WPAN_CONVERSATION_TIMEOUT
524  #define WPAN_CONVERSATION_TIMEOUT 30
525 #endif
526 
529 typedef struct wpan_ep_state_t {
530  uint8_t last_transaction;
533 
535  wpan_response_fn handler, const void FAR *context, uint16_t timeout);
537  uint8_t transaction_id, const wpan_envelope_t FAR *envelope);
539 
541 
543 
545 
546 // If compiling in Dynamic C, automatically #use the appropriate C file.
547 #ifdef __DC__
548  #use "wpan_aps.c"
549 #endif
550 
551 #endif // __WPAN_APS_H
552 
int wpan_conversation_register(wpan_ep_state_t FAR *state, wpan_response_fn handler, const void FAR *context, uint16_t timeout)
Add a conversation to the table of tracked conversations.
Definition: wpan_aps.c:299
uint8_t flags
flags that apply to this cluster, see WPAN_CLUST_FLAG_* macros
Definition: aps.h:218
Used to track conversations (outstanding requests) on an endpoint.
Definition: aps.h:505
Unsolicited Watchport sensor.
Definition: aps.h:137
int wpan_envelope_dispatch(wpan_envelope_t *envelope)
Find the matching endpoint for the provided envelope and have it process the frame.
Definition: wpan_aps.c:622
uint8_t device_version
Lower 4 bits are used, upper 4 are reserved and should be 0.
Definition: aps.h:273
uint16_t flags
Bitfield describing the device&#39;s capabilities (maybe CAN_SLEEP, nodetype, etc.) and state...
Definition: aps.h:406
WPAN datatypes and support functions, valid for ZigBee and DigiMesh.
const wpan_cluster_table_entry_t * cluster_table
Pointers to a list of clusters that ends with WPAN_CLUST_ENTRY_LIST_END.
Definition: aps.h:278
#define FAR
On platforms with "far" pointers, define to the proper keyword; empty definition if not required...
Definition: platform.h:396
int wpan_tick(wpan_dev_t *dev)
Calls the underlying hardware tick function to process received frames, and times out expired convers...
Definition: wpan_aps.c:860
Information on each cluster associated with an endpoint.
Definition: aps.h:199
Serial data.
Definition: aps.h:130
#define WPAN_MAX_CONVERSATIONS
Number of outstanding requests to track in a wpan_ep_state_t associated with an endpoint.
Definition: aps.h:519
Neighbor FW update.
Definition: aps.h:146
int(* wpan_response_fn)(struct wpan_conversation_t FAR *conversation, const wpan_envelope_t FAR *envelope)
Handler registered with wpan_conversation_register() to process responses to outstanding requests...
Definition: aps.h:493
FW update response.
Definition: aps.h:148
#define XBEE_BEGIN_DECLS
Macro defined to.
Definition: platform.h:41
void wpan_envelope_dump(const wpan_envelope_t FAR *envelope)
Debugging function to dump the contents of an envelope to stdout.
Definition: wpan_aps.c:823
wpan_endpoint_send_fn endpoint_send
send frame to an endpoint
Definition: aps.h:393
uint16_t profile_id
This endpoint&#39;s profile ID.
Definition: aps.h:259
Remote Command Request.
Definition: aps.h:134
Remote FW update.
Definition: aps.h:147
Digi NR Command.
Definition: aps.h:135
uint16_t cluster_id
16-bit cluster id, in host byte order.
Definition: aps.h:205
int(* wpan_ep_handler_fn)(const wpan_envelope_t FAR *envelope, struct wpan_ep_state_t FAR *ep_state)
General handler used in the endpoint table.
Definition: aps.h:193
const wpan_endpoint_table_entry_t * endpoint_table
Pointer to a table of the device&#39;s endpoints, ending with WPAN_ENDPOINT_TABLE_END.
Definition: aps.h:418
uint16_t network_address
remote 16-bit address
Definition: aps.h:44
void wpan_conversation_delete(wpan_conversation_t FAR *conversation)
Delete a conversation from an endpoint&#39;s conversation table.
Definition: wpan_aps.c:349
uint16_t device_id
This endpoint&#39;s device ID.
Definition: aps.h:270
wpan_address_t address
IEEE/MAC and network addresses.
Definition: aps.h:396
Volatile part of an endpoint record used to track conversations (requests waiting for responses)...
Definition: aps.h:529
int wpan_envelope_reply(wpan_envelope_t FAR *reply, const wpan_envelope_t FAR *original)
Create a reply envelope based on the envelope received from a remote node.
Definition: wpan_aps.c:752
const wpan_endpoint_table_entry_t * wpan_endpoint_match(wpan_dev_t *dev, uint8_t endpoint, uint16_t profile_id)
Walk a device&#39;s endpoint table looking for a matching endpoint ID and profile ID. ...
Definition: wpan_aps.c:160
const wpan_endpoint_table_entry_t * wpan_endpoint_get_next(wpan_dev_t *dev, const wpan_endpoint_table_entry_t *ep)
Function used to walk a device&#39;s endpoint table.
Definition: wpan_aps.c:105
uint8_t dest_endpoint
endpoint on recipient (dest)
Definition: aps.h:50
struct wpan_ep_state_t FAR * ep_state
Structure used to track transactions and conversations on ZDO/ZDP and ZCL endpoints.
Definition: aps.h:267
Unsolicited I/O data sample.
Definition: aps.h:136
wpan_tick_fn tick
read and dispatch frames
Definition: aps.h:392
uint16_t length
number of bytes in payload
Definition: aps.h:62
const void FAR * payload
contents of message
Definition: aps.h:61
wpan_endpoint_get_next_fn endpoint_get_next
walk endpoint table
Definition: aps.h:394
int(* wpan_endpoint_send_fn)(const wpan_envelope_t FAR *envelope, uint16_t flags)
Function called by the WPAN APS layer to send a frame out on the network.
Definition: aps.h:318
unsigned short uint16_t
16-bit unsigned integer
Definition: platform_config.h:41
Start OTA update of PXBee App.
Definition: aps.h:143
int wpan_envelope_send(const wpan_envelope_t FAR *envelope)
Send a message to an endpoint using address and payload information stored in a wpan_envelope_t struc...
Definition: wpan_aps.c:790
addr64 ieee_address
remote 64-bit address
Definition: aps.h:43
int(* _wpan_config_fn)(struct wpan_dev_t *dev,...)
Function called by the WPAN APS layer to configure the underlying network device. ...
Definition: aps.h:345
unsigned char uint8_t
8-bit unsigned integer
Definition: platform_config.h:39
const wpan_endpoint_table_entry_t * wpan_endpoint_of_envelope(const wpan_envelope_t *env)
Look up the endpoint table entry for the source endpoint of an envelope.
Definition: wpan_aps.c:204
wpan_aps_handler_fn handler
Function to receive all frames for this cluster, or NULL to have endpoint&#39;s handler process the frame...
Definition: aps.h:209
Single structure to hold an 802.15.4 device&#39;s 64-bit IEEE/MAC address and 16-bit network address...
Definition: types.h:98
Node ID Message.
Definition: aps.h:138
Digi ND Command.
Definition: aps.h:132
struct wpan_dev_t * dev
interface received on/to send to
Definition: aps.h:42
uint16_t timeout
Time to expire conversation (0 for never or lower 16 bits of xbee_seconds_timer) – limited to 9 hour...
Definition: aps.h:512
wpan_ep_handler_fn handler
Function to receive all frames for invalid clusters, or clusters with a NULL handler.
Definition: aps.h:263
uint16_t profile_id
Profile ID.
Definition: aps.h:45
const wpan_cluster_table_entry_t * wpan_cluster_match(uint16_t match, uint8_t mask, const wpan_cluster_table_entry_t *entry)
Search a cluster table for a matching cluster ID.
Definition: wpan_aps.c:62
const wpan_endpoint_table_entry_t *(* wpan_endpoint_get_next_fn)(struct wpan_dev_t *dev, const wpan_endpoint_table_entry_t *ep)
Custom function for walking the endpoint table.
Definition: aps.h:376
Serial loopback transmit.
Definition: aps.h:131
Digi NR Response.
Definition: aps.h:141
uint8_t wpan_endpoint_next_trans(const wpan_endpoint_table_entry_t *ep)
Increment and return the endpoint&#39;s transaction ID counter.
Definition: wpan_aps.c:493
uint8_t endpoint
Endpoint ID, 0 to 254. 255 (0xFF) is used as an end-of-table marker.
Definition: aps.h:255
int(* wpan_aps_handler_fn)(const wpan_envelope_t FAR *envelope, void FAR *context)
General handler used in the cluster table.
Definition: aps.h:169
Typedef used to hold a 64-bit IEEE address, represented as 8 bytes, 4 16-bit values or 2 32-bit value...
Definition: types.h:34
Digi Remote Command Response.
Definition: aps.h:140
Digi DN Response.
Definition: aps.h:139
uint8_t source_endpoint
endpoint on sender (source)
Definition: aps.h:49
#define XBEE_END_DECLS
Macro defined to.
Definition: platform.h:42
uint16_t payload
max bytes in RF payload, need to refresh if encryption enabled/disabled
Definition: aps.h:399
const void FAR * context
Declared const so initializers can use const or non-const pointers.
Definition: aps.h:215
Digi DN Command.
Definition: aps.h:133
int(* wpan_tick_fn)(struct wpan_dev_t *dev)
Function called by the WPAN APS layer to have the underlying device read and dispatch frames...
Definition: aps.h:356
Information on each endpoint on this device.
Definition: aps.h:252
const wpan_endpoint_table_entry_t * wpan_endpoint_of_cluster(wpan_dev_t *dev, uint16_t profile_id, uint16_t cluster_id, uint8_t mask)
Walk a device&#39;s endpoint table looking for a matching profile ID and cluster ID.
Definition: wpan_aps.c:243
DigiMesh Sleeping Router Sync.
Definition: aps.h:129
The "envelope" is used to gather all necessary information about a given frame on the network...
Definition: aps.h:40
Structure used by the WPAN/ZigBee layers.
Definition: aps.h:390
wpan_clust_digi
Digi Data cluster IDs (endpoint WPAN_ENDPOINT_DIGI_DATA)
Definition: aps.h:127
uint16_t cluster_id
Cluster ID.
Definition: aps.h:46
int wpan_conversation_response(wpan_ep_state_t FAR *state, uint8_t transaction_id, const wpan_envelope_t FAR *envelope)
Searches the endpoint&#39;s table of active conversations (outstanding requests waiting for responses) fo...
Definition: wpan_aps.c:427
void wpan_envelope_create(wpan_envelope_t *envelope, wpan_dev_t *dev, const addr64 FAR *ieee, uint16_t network_addr)
Starting with a blank envelope, fill in the device, 64-bit IEEE address and 16-bit network address of...
Definition: wpan_aps.c:712