Welcome to mirror list, hosted at ThFree Co, Russian Federation.

zcl.message.h « se « zcl « include « stack « zigbee « STM32_WPAN « ST « Middlewares - github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ce9543c4464522e1ae39c8f7091411373ba9a2d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* Copyright [2009 - 2019] Exegin Technologies Limited. All rights reserved. */

/*--------------------------------------------------------------------------
 *  DESCRIPTION
 *      Interface definition for the SE Messaging cluster.
 *--------------------------------------------------------------------------
 */
#ifndef ZCL_MESSAGE_H
# define ZCL_MESSAGE_H

#include "zcl/zcl.h"

/* Server Generated Commands */
enum {
    ZCL_MESSAGE_SVR_CMD_DISPLAY_MESSAGE = 0x00,
    ZCL_MESSAGE_SVR_CMD_CANCEL_MESSAGE = 0x01,
    ZCL_MESSAGE_SVR_CMD_DISPLAY_PROTECTED_MESSAGE = 0x02,
    ZCL_MESSAGE_SVR_CMD_CANCEL_ALL_MESSAGES = 0x03
};

/* Client Generated Commands */
enum {
    ZCL_MESSAGE_CLI_CMD_GET_LAST_MESSAGE = 0x00,
    ZCL_MESSAGE_CLI_CMD_MESSAGE_CONFIRM = 0x01,
    ZCL_MESSAGE_CLI_CMD_GET_MESSAGE_CANCELLATION = 0x02
};

enum {
    ZCL_MESSAGE_CTRL_TRANS_NORMAL = 0,
    ZCL_MESSAGE_CTRL_TRANS_BOTH = 1,
    ZCL_MESSAGE_CTRL_TRANS_INTERPAN = 2
};

enum {
    ZCL_MESSAGE_CTRL_IMPTNCE_LOW = 0,
    ZCL_MESSAGE_CTRL_IMPTNCE_MEDIUM = 1,
    ZCL_MESSAGE_CTRL_IMPTNCE_HIGH = 2,
    ZCL_MESSAGE_CTRL_IMPTNCE_CRITICAL = 3
};

#define ZCL_MESSAGE_MAX_LENGTH                     59U /* D.5.2.3.1.1.1 */

struct ZbZclMsgMessageT {
    uint32_t message_id;
    uint32_t start_time; /* UTC Seconds */
    uint16_t duration; /* Minutes */
    uint8_t message_control; /* ZbZclMessageControlSet - transmission, importance, confirm required, confirm enhanced */
    char message_str[ZCL_MESSAGE_MAX_LENGTH + 1U]; /* UTF-8 */
    uint8_t extended_control;
};

#define ZCL_MESSAGE_CTRL_EXTENDED_CONFIRMED       0x01U // message has been confirmed

/* Message Control fields. */
#define ZCL_MESSAGE_CTRL_TRANS_MASK        0x03U
#define ZCL_MESSAGE_CTRL_TRANS_OFFSET      0U
#define ZCL_MESSAGE_CTRL_TRANS_GET(_c_)    (((_c_) & ZCL_MESSAGE_CTRL_TRANS_MASK) >> ZCL_MESSAGE_CTRL_TRANS_OFFSET)

#define ZCL_MESSAGE_CTRL_IMPTNCE_MASK          0x0cU
#define ZCL_MESSAGE_CTRL_IMPTNCE_OFFSET        2U
#define ZCL_MESSAGE_CTRL_IMPTNCE_GET(_c_)      (((_c_) & ZCL_MESSAGE_CTRL_IMPTNCE_MASK) >> ZCL_MESSAGE_CTRL_IMPTNCE_OFFSET)

#define ZCL_MESSAGE_CTRL_ENH_CONF_MASK            0x20U
#define ZCL_MESSAGE_CTRL_ENH_CONF_OFFSET          5U
#define ZCL_MESSAGE_CTRL_ENH_CONF_GET(_c_)        (((_c_) & ZCL_MESSAGE_CTRL_ENH_CONF_MASK) >> ZCL_MESSAGE_CTRL_ENH_CONF_OFFSET)

#define ZCL_MESSAGE_CTRL_CONFIRMATION_MASK        0x80U
#define ZCL_MESSAGE_CTRL_CONFIRMATION_OFFSET      7U
#define ZCL_MESSAGE_CTRL_CONFIRMATION_GET(_c_)    (((_c_) & ZCL_MESSAGE_CTRL_CONFIRMATION_MASK) >> ZCL_MESSAGE_CTRL_CONFIRMATION_OFFSET)

/* Message Control "Set" Helper */
static inline void
ZbZclMessageControlSet(struct ZbZclMsgMessageT *msg, uint8_t transmission,
    uint8_t importance, uint8_t confirm, uint8_t enh_confirm)
{
    msg->message_control = 0;
    msg->message_control |= ((transmission << ZCL_MESSAGE_CTRL_TRANS_OFFSET) & ZCL_MESSAGE_CTRL_TRANS_MASK);
    msg->message_control |= ((importance << ZCL_MESSAGE_CTRL_IMPTNCE_OFFSET) & ZCL_MESSAGE_CTRL_IMPTNCE_MASK);
    msg->message_control |= ((confirm << ZCL_MESSAGE_CTRL_CONFIRMATION_OFFSET) & ZCL_MESSAGE_CTRL_CONFIRMATION_MASK);
    msg->message_control |= ((enh_confirm << ZCL_MESSAGE_CTRL_ENH_CONF_OFFSET) & ZCL_MESSAGE_CTRL_ENH_CONF_MASK);
}

/* Cancel Message Descriptor */
struct ZbZclMsgMessageCancelT {
    uint32_t message_id;
    uint8_t control;
};

/* Cancel All Messages Descriptor */
struct ZbZclMsgMessageCancelAllT {
    uint32_t implementation_time;
};

/* Message Confirmation Descriptor */
struct ZbZclMsgConfirmT {
    uint32_t message_id;
    uint32_t confirm_time;
};

/* Message Confirmation Extended Optional */
/* EXEGIN - where in which spec is this message defined? */
#define ZCL_MESSAGE_CONFIRM_ENH_RSP_MAX_LEN         32U

struct ZbZclMsgConfirmEnhT {
    uint32_t message_id;
    uint32_t confirm_time;
    uint8_t confirm_control;
    char confirm_response[ZCL_MESSAGE_CONFIRM_ENH_RSP_MAX_LEN + 1U];
};

#define ZCL_MESSAGE_CONF_RSP_LEN 21U

struct ZbZclMsgMessageConfT {
    uint32_t message_id;
    uint32_t confirm_time;
    bool has_confirm_control;
    uint8_t confirm_control;
    bool has_confirm_response;
    uint8_t confirm_response[ZCL_MESSAGE_CONF_RSP_LEN];
};

struct ZbZclMsgGetMsgCancellationT {
    uint32_t earliest_impl_time;
};

/*
 * Server
 */
struct ZbZclMsgServerCallbacksT {
    enum ZclStatusCodeT (*get_last_message)(struct ZbZclClusterT *cluster, void *arg,
        struct ZbZclAddrInfoT *srcInfo);

    enum ZclStatusCodeT (*message_confirmation)(struct ZbZclClusterT *cluster, void *arg,
        struct ZbZclMsgMessageConfT *conf, struct ZbZclAddrInfoT *srcInfo);

    enum ZclStatusCodeT (*get_message_cancellation)(struct ZbZclClusterT *cluster, void *arg,
        struct ZbZclMsgGetMsgCancellationT *req, struct ZbZclAddrInfoT *source);
};

struct ZbZclClusterT * ZbZclMsgServerAlloc(struct ZigBeeT *zb, uint8_t endpoint,
    struct ZbZclMsgServerCallbacksT *callbacks, void *arg);

enum ZclStatusCodeT ZbZclMsgServerDisplayMessageReq(struct ZbZclClusterT *cluster, const struct ZbApsAddrT *dst,
    struct ZbZclMsgMessageT *msg,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

enum ZclStatusCodeT ZbZclMsgServerDisplayProtectedMsgReq(struct ZbZclClusterT *cluster, const struct ZbApsAddrT *dst,
    struct ZbZclMsgMessageT *msg,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

enum ZclStatusCodeT ZbZclMsgServerCancelMessageReq(struct ZbZclClusterT *cluster, const struct ZbApsAddrT *dst,
    struct ZbZclMsgMessageCancelT *cancel, void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

enum ZclStatusCodeT ZbZclMsgServerCancelAllReq(struct ZbZclClusterT *clusterPtr, const struct ZbApsAddrT *dst,
    struct ZbZclMsgMessageCancelAllT *cancel_all, void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

/*
 * Client
 */
struct ZbZclMsgClientCallbacksT {
    enum ZclStatusCodeT (*display_message)(struct ZbZclClusterT *cluster, void *arg,
        struct ZbZclMsgMessageT *msg, struct ZbZclAddrInfoT *srcInfo);

    enum ZclStatusCodeT (*cancel_message)(struct ZbZclClusterT *cluster, void *arg,
        struct ZbZclMsgMessageCancelT *cancel, struct ZbZclAddrInfoT *srcInfo);

    enum ZclStatusCodeT (*cancel_all_messages)(struct ZbZclClusterT *cluster, void *arg,
        struct ZbZclMsgMessageCancelAllT *cancel_all, struct ZbZclAddrInfoT *srcInfo);

    enum ZclStatusCodeT (*display_protected_message)(struct ZbZclClusterT *cluster, void *arg,
        struct ZbZclMsgMessageT *msg, struct ZbZclAddrInfoT *srcInfo);
};

struct ZbZclClusterT * ZbZclMsgClientAlloc(struct ZigBeeT *zb, uint8_t endpoint,
    struct ZbZclMsgClientCallbacksT *callbacks, void *arg);

enum ZclStatusCodeT ZbZclMsgClientGetLastReq(struct ZbZclClusterT *cluster, const struct ZbApsAddrT *dst,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

enum ZclStatusCodeT ZbZclMsgClientConfReq(struct ZbZclClusterT *cluster, const struct ZbApsAddrT *dst,
    struct ZbZclMsgConfirmT *msg_conf,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

enum ZclStatusCodeT ZbZclMsgClientGetMsgCancelReq(struct ZbZclClusterT *cluster,
    const struct ZbApsAddrT *dst, uint32_t earliestTime,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

#endif /* ZCL_MESSAGE_H */