XBee Firmware Library
1.6.0
|
Files | |
file | aps.h |
file | wpan_aps.c |
Data Structures | |
struct | wpan_cluster_table_entry_t |
Information on each cluster associated with an endpoint. More... | |
struct | wpan_conversation_t |
Used to track conversations (outstanding requests) on an endpoint. More... | |
struct | wpan_dev_t |
struct | wpan_endpoint_table_entry_t |
Information on each endpoint on this device. More... | |
struct | wpan_envelope_t |
struct | wpan_ep_state_t |
Typedefs | |
typedef int(* | _wpan_config_fn) (struct wpan_dev_t *dev,...) |
typedef int(* | wpan_aps_handler_fn) (const wpan_envelope_t FAR *envelope, void FAR *context) |
General handler used in the cluster table. More... | |
typedef struct wpan_cluster_table_entry_t | wpan_cluster_table_entry_t |
Information on each cluster associated with an endpoint. More... | |
typedef struct wpan_conversation_t | wpan_conversation_t |
Used to track conversations (outstanding requests) on an endpoint. More... | |
typedef struct wpan_dev_t | wpan_dev_t |
typedef 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. More... | |
typedef 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. More... | |
typedef struct wpan_endpoint_table_entry_t | wpan_endpoint_table_entry_t |
Information on each endpoint on this device. More... | |
typedef XBEE_BEGIN_DECLS struct wpan_envelope_t | wpan_envelope_t |
typedef 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. More... | |
typedef struct wpan_ep_state_t | wpan_ep_state_t |
typedef 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. More... | |
typedef 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. More... | |
Enumerations | |
enum | wpan_clust_digi { DIGI_CLUST_SLEEP_SYNC = 0x0009, DIGI_CLUST_SERIAL = 0x0011, DIGI_CLUST_LOOPBACK = 0x0012, DIGI_CLUST_ND_COMMAND = 0x0015, DIGI_CLUST_DN_COMMAND = 0x0016, DIGI_CLUST_REMOTE_COMMAND = 0x0021, DIGI_CLUST_NR_COMMAND = 0x0022, DIGI_CLUST_IODATA = 0x0092, DIGI_CLUST_WATCHPORT = 0x0094, DIGI_CLUST_NODEID_MESSAGE = 0x0095, DIGI_CLUST_DN_RESPONSE = 0x0096, DIGI_CLUST_REMOTE_RESPONSE = 0x00A1, DIGI_CLUST_NR_RESPONSE = 0x00A2, DIGI_CLUST_INDIRECT_ROUTE_ERR = 0x00B0, DIGI_CLUST_PROG_XBEE_OTA_UPD = 0x1000, DIGI_CLUST_NBRFWUPDATE = 0x71FE, DIGI_CLUST_REMFWUPDATE = 0x71FF, DIGI_CLUST_FWUPDATERESP = (int)0xF1FF } |
Digi Data cluster IDs (endpoint #WPAN_ENDPOINT_DIGI_DATA) More... | |
Functions | |
wpan_aps_debug int | _wpan_endpoint_dispatch (wpan_envelope_t *envelope, const wpan_endpoint_table_entry_t *ep) |
void | _wpan_endpoint_expire_conversations (wpan_ep_state_t FAR *state) |
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. More... | |
void | wpan_conversation_delete (wpan_conversation_t FAR *conversation) |
Delete a conversation from an endpoint's conversation table. More... | |
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. More... | |
int | wpan_conversation_response (wpan_ep_state_t FAR *state, uint8_t transaction_id, const wpan_envelope_t FAR *envelope) |
Searches the endpoint's table of active conversations (outstanding requests waiting for responses) for a given transaction. More... | |
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's endpoint table. More... | |
const wpan_endpoint_table_entry_t * | wpan_endpoint_match (wpan_dev_t *dev, uint8_t endpoint, uint16_t profile_id) |
Walk a device's endpoint table looking for a matching endpoint ID and profile ID. More... | |
uint8_t | wpan_endpoint_next_trans (const wpan_endpoint_table_entry_t *ep) |
Increment and return the endpoint's transaction ID counter. More... | |
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's endpoint table looking for a matching profile ID and cluster ID. More... | |
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. More... | |
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 the destination. The profile ID, cluster ID, source/destination endpoints and envelope options are all be set to zero. More... | |
int | wpan_envelope_dispatch (wpan_envelope_t *envelope) |
Find the matching endpoint for the provided envelope and have it process the frame. More... | |
void | wpan_envelope_dump (const wpan_envelope_t FAR *envelope) |
Debugging function to dump the contents of an envelope to stdout. More... | |
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. More... | |
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 structure. More... | |
int | wpan_tick (wpan_dev_t *dev) |
Calls the underlying hardware tick function to process received frames, and times out expired conversations. More... | |
typedef int(* _wpan_config_fn) (struct wpan_dev_t *dev,...) |
typedef int(* wpan_aps_handler_fn) (const wpan_envelope_t FAR *envelope, void FAR *context) |
General handler used in the cluster table.
Dispatcher searches an endpoint's cluster table for a matching cluster, and hands the frame off to the cluster's handler.
If the cluster's handler is set to NULL
, or the frame is for a cluster ID that does not appear in the table, the dispatcher hands the frame off to the endpoint's handler.
[in] | envelope | information about the frame (addresses, endpoint, profile, cluster, etc.) |
[in,out] | context | user context (from cluster table) |
0 | handled data |
!0 | some sort of error processing data |
typedef struct wpan_cluster_table_entry_t wpan_cluster_table_entry_t |
Information on each cluster associated with an endpoint.
typedef struct wpan_conversation_t wpan_conversation_t |
Used to track conversations (outstanding requests) on an endpoint.
typedef struct wpan_dev_t wpan_dev_t |
Structure used by the WPAN/ZigBee layers. Contains information about the node (addresses, payload limit, capabilities) along with an endpoint list and function pointers to configure, tick and send packets through the underlying network interface.
This is the abstraction layer between a physical XBee (or some other piece of hardware or gateway/router/tunnel device) and the networking layers. Similar to a driver for an Ethernet NIC and the TCP/IP stack that runs on top of it.
typedef 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.
The application can define its own function to walk the endpoint table, possibly to support a dynamic table or a table where endpoints aren't always visible.
[in] | dev | device with endpoint table to walk |
[in] | ep | NULL to return first entry in table, or a pointer previously returned by this function to get the next entry |
NULL | dev is invalid or reached end of table |
!NULL | next entry from table |
typedef 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.
This is part of the glue that links the XBee layer with the WPAN/ZigBee layers.
[in] | envelope | information about the frame (addresses, endpoint, profile, cluster, payload, etc.) |
[in] | flags | flags related to sending, see WPAN_SEND_FLAG_* macros
|
0 | frame sent |
!0 | error sending frame |
-EMSGSIZE | payload is too large |
Add support for a broadcast radius? Don't send Tx Status? Use frame ID 0?
come up with standard error codes for the following possible errors? outbound frame buffer is full, invalid data in envelope, payload is too big
typedef struct wpan_endpoint_table_entry_t wpan_endpoint_table_entry_t |
Information on each endpoint on this device.
typedef XBEE_BEGIN_DECLS struct wpan_envelope_t wpan_envelope_t |
The "envelope" is used to gather all necessary information about a given frame on the network. Note that all members of the structure are in host byte order.
The low byte of the options field is a copy of the cluster flags for the cluster that received the data. Use #WPAN_ENVELOPE_CLUSTER_FLAGS to mask off the byte, and then compare to the various WPAN_CLUST_FLAG_* macros.
On a DigiMesh network, the 16-bit network address is always set to WPAN_NET_ADDR_UNDEFINED (0xFFFE).
typedef 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.
If a cluster's handler is set to NULL
, or the frame is for a cluster ID that does not appear in the table, the dispatcher hands the frame off to the endpoint's handler.
[in] | envelope | information about the frame (addresses, endpoint, profile, cluster, etc.) |
[in,out] | ep_state | pointer to endpoint state structure |
0 | handled data |
!0 | some sort of error processing data |
typedef struct wpan_ep_state_t wpan_ep_state_t |
Volatile part of an endpoint record used to track conversations (requests waiting for responses).
typedef 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.
[in] | conversation | Pointer to entry in conversation table. Handler can use the pointer to access the context and transaction ID from the conversation, or request deletion of the conversation via wpan_conversation_delete(). Never NULL. |
[in] | envelope | envelope with response or NULL if there was a timeout |
WPAN_CONVERSATION_END | end of conversation, no more responses expected |
WPAN_CONVERSATION_CONTINUE | leave conversation open, more responses are expected |
typedef 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.
[in] | dev | device to tick |
enum wpan_clust_digi |
Digi Data cluster IDs (endpoint #WPAN_ENDPOINT_DIGI_DATA)
wpan_aps_debug int _wpan_endpoint_dispatch | ( | wpan_envelope_t * | envelope, |
const wpan_endpoint_table_entry_t * | ep | ||
) |
wpan_aps_debug void _wpan_endpoint_expire_conversations | ( | wpan_ep_state_t FAR * | state | ) |
wpan_aps_debug 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.
[in] | match | ID to match |
[in] | mask | Flags to match against the flags member of the wpan_cluster_table_entry_t structure. If any flags match, the entry is returned. Typically one of
|
[in] | entry | pointer to list of entries to search |
@retval NULL \a entry is invalid or search reached #WPAN_CLUSTER_END_OF_LIST without finding a match. @retval !NULL Pointer to matching entry from table. @see wpan_endpoint_get_next(), wpan_endpoint_match()
wpan_aps_debug void wpan_conversation_delete | ( | wpan_conversation_t FAR * | conversation | ) |
Delete a conversation from an endpoint's conversation table.
[in,out] | conversation | conversation to delete |
wpan_aps_debug 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.
[in,out] | state | endpoint state associated with sending endpoint |
[in] | handler | handler to call when responses come back, or NULL to increment and return the endpoint's transaction ID |
[in] | context | pointer stored in conversation table and passed to callback handler |
[in] | timeout | number of seconds before generating timeout, or 0 for none |
0-255 | transaction ID to use in sent frame |
-EINVAL | state is invalid (NULL) |
-ENOSPC | table is full |
wpan_aps_debug int wpan_conversation_response | ( | wpan_ep_state_t FAR * | state, |
uint8_t | transaction_id, | ||
const wpan_envelope_t FAR * | envelope | ||
) |
Searches the endpoint's table of active conversations (outstanding requests waiting for responses) for a given transaction.
Hands the response frame off to the handler registered to the conversation with wpan_conversation_register().
[in] | state | endpoint state (from endpoint table) or NULL to look it up using the envelope |
[in] | transaction_id | transaction ID from frame payload, used to look up conversation |
[in] | envelope | envelope from response frame, passed to conversation's handler |
-EINVAL | invalid parameter passed to function, or conversation not found in table |
0 | handler processed response |
!0 | handler reported an error while processing response |
wpan_aps_debug 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's endpoint table.
For most devices, this will just walk the entries in dev->endpoint_table. For custom applications a function may dynamically return entries.
Use of this function is the only way to walk the endpoint table.
[in] | dev | device with endpoint table to walk |
[in] | ep | NULL to return first entry in table, or a pointer previously returned by this function to get the next entry |
NULL | dev is invalid or reached end of table |
!NULL | next entry from table |
wpan_aps_debug const wpan_endpoint_table_entry_t * wpan_endpoint_match | ( | wpan_dev_t * | dev, |
uint8_t | endpoint, | ||
uint16_t | profile_id | ||
) |
Walk a device's endpoint table looking for a matching endpoint ID and profile ID.
Used by the endpoint dispatcher and ZDO layer to describe available endpoints on this device.
[in] | dev | Device with endpoint table to search. |
[in] | endpoint | Endpoint number to search for. |
[in] | profile_id | Profile to match or WPAN_APS_PROFILE_ANY to search on endpoint number only. |
NULL | dev is invalid or reached end of table without finding a match |
!NULL | next entry from table |
wpan_aps_debug uint8_t wpan_endpoint_next_trans | ( | const wpan_endpoint_table_entry_t * | ep | ) |
Increment and return the endpoint's transaction ID counter.
[in] | ep | entry from endpoint table |
0-255 | current transaction ID for endpoint |
wpan_aps_debug 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's endpoint table looking for a matching profile ID and cluster ID.
Used to find the correct endpoint to use for sending ZCL client requests.
[in] | dev | Device with endpoint table to search. |
[in] | profile_id | Profile to match or WPAN_APS_PROFILE_ANY to search on cluster ID only. |
[in] | cluster_id | Cluster ID to search for. |
[in] | mask | Flags to match against the flags member of the wpan_cluster_table_entry_t structure. If any flags match, the entry is returned. Typically one of
|
NULL | dev is invalid or reached end of table without finding a match |
!NULL | matching entry from table |
wpan_aps_debug 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.
[in] | env | Envelope for lookup. Uses env->source_endpoint and env->profile_id to find the endpoint table entry for env->dev. |
NULL | invalid parameter, or reached end of table without finding a match |
!NULL | entry from table |
wpan_aps_debug 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 the destination. The profile ID, cluster ID, source/destination endpoints and envelope options are all be set to zero.
[out] | envelope | envelope to populate |
[in] | dev | device that will send this envelope |
[in] | ieee | 64-bit IEEE/MAC address of recipient or one of
|
[in] | network_addr | 16-bit network address of recipient or one of
|
When sending broadcast packets, use WPAN_IEEE_ADDR_BROADCAST and WPAN_NET_ADDR_UNDEFINED. Don't set both addresses to broadcast.
When using DigiMesh protocol, always set the network_addr
to WPAN_NET_ADDR_UNDEFINED.
wpan_aps_debug int wpan_envelope_dispatch | ( | wpan_envelope_t * | envelope | ) |
Find the matching endpoint for the provided envelope
and have it process the frame.
In the case of the broadcast endpoint (255), dispatches the frame to all endpoints matching the envelope's profile ID.
Looks up the destination endpoint and cluster ID in the device's endpoint table and passes envelope
off to the cluster handler (if a matching cluster was found) or the endpoint handler.
[in] | envelope | structure containing all necessary information about message (endpoints, cluster, profile, etc.) |
0 | successfully dispatched message |
-ENOENT | no handler for this endpoint/cluster |
!0 | error dispatching messages |
wpan_aps_debug void wpan_envelope_dump | ( | const wpan_envelope_t FAR * | envelope | ) |
Debugging function to dump the contents of an envelope to stdout.
Displays all fields from the envelope, plus the contents of the payload
[in] | envelope | envelope to dump |
wpan_aps_debug 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.
Copies the interface, addresses, profile and cluster from the original envelope, and then swaps the source and destination endpoints.
Note that it may be necessary for the caller to change the cluster_id as well, after building the reply envelope. For example, ZDO responses set the high bit of the request's cluster ID.
[out] | reply | Buffer for storing the reply envelope. |
[in] | original | Original envelope, received from a remote node, to base the reply on. |
0 | addressed reply envelope |
-EINVAL | either parameter is NULL or they point to the same address |
wpan_aps_debug 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 structure.
[in] | envelope | envelope of request to send |
0 | request sent |
!0 | error trying to send request |
wpan_aps_debug int wpan_tick | ( | wpan_dev_t * | dev | ) |
Calls the underlying hardware tick function to process received frames, and times out expired conversations.
[in] | dev | WPAN device to tick |
>=0 | number of frames processed during the tick |
-EINVAL | device does not have a tick function assigned to it |
<0 | some other error encountered during the tick |
wpan_address_t address |
IEEE/MAC and network addresses.
uint16_t cluster_id |
Cluster ID.
uint16_t cluster_id |
16-bit cluster id, in host byte order. WPAN_CLUSTER_END_OF_LIST (0xFFFF) marks the end of the list. Clusters 0x0000 to 0x7FFF are Standard ZigBee clusters, 0x8000 to 0xFBFF are reserved and 0xFC00 to 0xFFFF are manufacturer-specific (with a standard ZigBee profile).
const wpan_cluster_table_entry_t* cluster_table |
Pointers to a list of clusters that ends with WPAN_CLUST_ENTRY_LIST_END. Maximum of 255 input and 255 output clusters (Simple Descriptor uses 8-bit fields for input cluster count and output cluster count).
const void FAR* context |
Declared const
so initializers can use const
or non-const
pointers. The const
is discarded before passing the context on to wpan_aps_handler_fn(). For a ZCL endpoint, context
points to an attribute tree (zcl_attribute_tree_t).
void FAR* context |
wpan_conversation_t conversations[WPAN_MAX_CONVERSATIONS] |
uint8_t dest_endpoint |
endpoint on recipient (dest)
struct wpan_dev_t* dev |
interface received on/to send to
uint16_t device_id |
This endpoint's device ID.
uint8_t device_version |
Lower 4 bits are used, upper 4 are reserved and should be 0.
uint8_t endpoint |
Endpoint ID, 0 to 254. 255 (0xFF) is used as an end-of-table marker.
wpan_endpoint_get_next_fn endpoint_get_next |
walk endpoint table
wpan_endpoint_send_fn endpoint_send |
send frame to an endpoint
const wpan_endpoint_table_entry_t* endpoint_table |
Pointer to a table of the device's endpoints, ending with #WPAN_ENDPOINT_TABLE_END. Do not reference directly! Use wpan_endpoint_get_next() to walk the table.
struct wpan_ep_state_t FAR* ep_state |
Structure used to track transactions and conversations on ZDO/ZDP and ZCL endpoints. Should be NULL for other types of endpoints.
uint8_t flags |
flags that apply to this cluster, see WPAN_CLUST_FLAG_* macros
uint16_t flags |
Bitfield describing the device's capabilities (maybe CAN_SLEEP, nodetype, etc.) and state. Only valid if xbee_cmd_init_device() is used or ALL Modem Status messages are received from radio. User code should not access this directly, but use WPAN_DEV_IS_* macros instead.
wpan_aps_handler_fn handler |
Function to receive all frames for this cluster, or NULL to have endpoint's handler process the frame.
wpan_ep_handler_fn handler |
Function to receive all frames for invalid clusters, or clusters with a NULL
handler.
wpan_response_fn handler |
addr64 ieee_address |
remote 64-bit address
uint8_t last_transaction |
uint16_t length |
number of bytes in payload
uint16_t network_address |
remote 16-bit address
uint16_t options |
const void FAR* payload |
contents of message
uint16_t payload |
max bytes in RF payload, need to refresh if encryption enabled/disabled
uint16_t profile_id |
Profile ID.
uint16_t profile_id |
This endpoint's profile ID. See WPAN_PROFILE_* macros for some known profile IDs.
uint8_t source_endpoint |
endpoint on sender (source)
wpan_tick_fn tick |
read and dispatch frames
uint16_t timeout |
Time to expire conversation (0 for never or lower 16 bits of xbee_seconds_timer) – limited to 9 hours (32,768 seconds). We could save another byte if it's ok to limit to 2 minutes and we'll check for expirations at least every 7 seconds.
uint8_t transaction_id |