esp-sdr-zephyr
Raw I/Q receive and transmit on the ESP32-S3/C6 Wi-Fi radio, for Zephyr
Loading...
Searching...
No Matches
zb_stack.h
1/*
2 * SPDX-License-Identifier: GPL-3.0-or-later
3 *
4 * The Zigbee stack behind the ZNP: MAC, network layer, endpoint registry and the MT handlers
5 * for APP_CNF, ZDO, AF and DEBUG. The app supplies a radio backend and the stack of the MAC
6 * thread; everything else is here.
7 */
8#ifndef ZIGBEE_ZB_STACK_H_
9#define ZIGBEE_ZB_STACK_H_
10
11#include <zigbee/zb_net.h>
12#include <zigbee/znp.h>
13
14#define ZB_EP_MAX 16
15#define ZB_EP_CLUSTERS 12
16#define ZB_GROUP_MAX 8
17#define ZB_GROUP_NAME 16
18
19struct zb_ep {
20 bool used;
21 uint8_t ep;
22 uint16_t profile;
23 uint16_t device;
24 uint8_t version;
25 uint8_t nin, nout;
26 uint16_t in[ZB_EP_CLUSTERS];
27 uint16_t out[ZB_EP_CLUSTERS];
28};
29
30struct zb_group {
31 bool used;
32 uint8_t ep;
33 uint16_t id;
34 uint8_t namelen;
35 char name[ZB_GROUP_NAME];
36};
37
38struct zb_stack {
39 struct znp *znp;
40 struct znp_nv *nv;
41 struct zb_mac mac;
42 struct zb_net net;
43 struct zb_ep eps[ZB_EP_MAX];
44 struct zb_group groups[ZB_GROUP_MAX];
45 uint8_t default_eui[8];
46 /* The host asked for ZDO messages as raw callbacks (zigpy-znp) rather than as AREQs. */
47 bool msg_cb;
48 uint8_t zdo_tsn;
49 /* 0 off; 1 stack events; 2 also every frame (DEBUG_MSG AREQs to the host). */
50 uint8_t trace_level;
51};
52
53/*
54 * Set up the stack, register its MT handlers with @p z and boot the network layer from NV
55 * (a formed network starts at once). Starts the MAC thread on @p mac_stack.
56 */
57int zb_stack_init(struct zb_stack *s, struct znp *z, struct znp_nv *nv,
58 const struct zb_radio_ops *radio, void *rctx, const uint8_t default_eui[8],
59 k_thread_stack_t *mac_stack, size_t mac_stack_size, int mac_prio);
60
61/* SYS_RESET_REQ: restart the stack from NV (the transport stays up), then SYS_RESET_IND. */
62void zb_stack_reset(struct zb_stack *s, uint8_t type);
63
64/* Transmit power in dBm for SYS_SET_TX_POWER and SYS_STACK_TUNE; returns what is in force. */
65int8_t zb_stack_set_txpower(struct zb_stack *s, int8_t dbm);
66
67/* A diagnostic line to the host (MT DEBUG_MSG) when tracing is on. */
68void zb_stack_trace(struct zb_stack *s, uint8_t level, const char *fmt, ...) __printf_like(3, 4);
69
70/* MT handlers (registered by zb_stack_init). */
71int znp_appcnf_handler(struct znp *z, const struct mt_frame *req, struct mt_frame *rsp);
72int znp_zdo_handler(struct znp *z, const struct mt_frame *req, struct mt_frame *rsp);
73int znp_af_handler(struct znp *z, const struct mt_frame *req, struct mt_frame *rsp);
74int znp_debug_handler(struct znp *z, const struct mt_frame *req, struct mt_frame *rsp);
75
76/* Net layer events to the host (set up by zb_stack_init). */
77extern const struct zb_net_cb zb_stack_net_cb;
78
79#endif /* ZIGBEE_ZB_STACK_H_ */
Definition mt.h:61
Definition zb_stack.h:19
Definition zb_stack.h:30
Definition zb_mac.h:78
Definition zb_net.h:163
Definition zb_net.h:211
Definition zb_radio.h:15
Definition zb_stack.h:38
Definition znp_nv.h:47
Definition znp.h:62