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

zigbee.startup.h « 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: a4674f15d145267954efc8954dfb18d3b8b173d1 (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
/* Copyright [2009 - 2020] Exegin Technologies Limited. All rights reserved. */

#ifndef ZIGBEE_STARTUP_H
# define ZIGBEE_STARTUP_H

#include "zcl/zcl.touchlink.h"

/* Startup control-codes as per the ZCL. */
enum ZbStartType {
    ZbStartTypePreconfigured = 0x00,
    ZbStartTypeForm = 0x01,
    ZbStartTypeRejoin = 0x02,
    ZbStartTypeJoin = 0x03,
    /* Exegin add-ons (Internal use only) */
    ZbStartTypeTouchlink = 0xfd,
    ZbStartTypeFindBind = 0xfe,
    ZbStartTypeNone = 0xff
};

struct ZbStartupCbkeT {
    uint8_t endpoint; /* e.g. ZB_ENDPOINT_MAX */
    uint16_t deviceId; /* e.g. ZCL_DEVICE_METER */
    uint16_t suite_mask; /* e.g. ZCL_KEY_SUITE_CBKE_ECMQV */
    struct ZbZclCbkeInfoT cbke_v1; /* if (suite & ZCL_KEY_SUITE_CBKE_ECMQV) */
    struct ZbZclCbke2InfoT cbke_v2; /* if (suite & ZCL_KEY_SUITE_CBKE2_ECMQV) */

    /* Keep Alive Server or Client */
    bool tc_keepalive_server_enable; /* true for server, false for client */
    /* Keep Alive Server attributes */
    uint8_t tc_keepalive_base; /* minutes. If zero, use stack defaults for BASE and JITTER. */
    uint16_t tc_keepalive_jitter; /* seconds */

    /* Trust Center Swap Out status callback, so application is informed of any TCSO process
     * initiated by the Keep Alive Client cluster. */
    void (*tcso_callback)(enum ZbTcsoStatusT status, void *arg);
    void *tcso_arg;
};

/* The set of parameters to form or join a ZigBee Network Stack.
 * Should be initialized using ZbStartupConfigGetProDefaults or ZbStartupConfigGetProSeDefaults. */
struct ZbStartupT {
    /* shortAddress is only used if:
     * startupControl = ZbStartTypePreconfigured or ZbStartTypeRejoin */
    uint16_t shortAddress;
    /* panId and networkManagerAddress are only used if:
     * startupControl = ZbStartTypePreconfigured */
    uint16_t panId;
    uint16_t networkManagerAddress;
    /* Extended PAN ID. See note1 below. */
    uint64_t extendedPanId;

    /* Specify the channel masks to use. If no channel masks are specified,
     * ZB_BDB_PrimaryChannelSet and ZB_BDB_SecondaryChannelSet are used instead. */
    struct ZbChannelListT channelList;

    /* Stack Profile.
     * If not ZB_NWK_STACK_PROFILE_PRO, application must configure the following
     * NIB parameters before calling ZbStartup:
     *      nwkMaxDepth, nwkMaxChildren, nwkReportConstantCost, nwkLinkStatusPeriod,
     *      nwkTransactionPersistenceTime, nwkPassiveAckTimeout, nwkMaxBroadcastRetries,
     *      nwkSecureAllFrames, nwkSecurityLevel */
    uint8_t stackProfile;

    /* BDB Commissioning Mode - see BDB_COMMISSION_MODE_MASK */
    uint8_t bdbCommissioningMode;

    /* Startup Type (used if not BDB_COMMISSION_MODE_TOUCHLINK)
     * Notes:
     *  ZbStartTypePreconfigured    - extendedPanId must be provided.
     *  ZbStartTypeForm             - if extendedPanId = 0 then the stack will use the EUI as the Extended PAN ID.
     *  ZbStartTypeRejoin           - extendedPanId must be provided.
     *  ZbStartTypeJoin             - if extendedPanId = 0 then the stack will try join any available network.
     */
    enum ZbStartType startupControl;

    /* Security Parameters (security level, preconfigured keys, etc) */
    struct {
        uint8_t level;
        bool useInsecureRejoin;
        uint64_t trustCenterAddress;
        uint8_t preconfiguredLinkKey[ZB_SEC_KEYSIZE]; /* 16 bytes */
        uint8_t distributedGlobalKey[ZB_SEC_KEYSIZE]; /* 16 bytes */
        uint8_t networkKey[ZB_SEC_KEYSIZE]; /* 16 bytes */
        uint8_t networkKeySeqNum;
        enum ZbSecKeyTypeT networkKeyType;

        struct ZbStartupCbkeT cbke;
    } security;

    /* The set of parameters related to joining a network. */
    struct {
        /* scanAttempts removed, use ZB_APS_IB_ID_SCAN_COUNT instead */
        uint16_t timeBetweenScans; /* in milliseconds */
        uint16_t rejoinInterval; /* in seconds */
        uint16_t maxRejoinInterval; /* in seconds */
    } join;

    /* Device Capability (FFD vs RFD, RX-ON) */
    uint8_t capability; /* e.g. MCP_ASSOC_CAP_RXONIDLE */

    /* End-device timeout is only used by end-devices. It configures the
     * time used to periodically update the Parent device so this
     * device is not removed from the Parent's NWK Neighbor Table.
     * Configures ZB_NWK_NIB_ID_EndDeviceTimeoutDefault.
     *
     * Timeout = (60 * 2^n) seconds for n > 0. If n = 0, timeout = 10 seconds.
     * Setting to ZB_NWK_CONST_ENDDEV_TIMEOUT_DISABLED (0xff) disables end-device timeout.*/
    uint8_t endDeviceTimeout;
    uint16_t fastPollPeriod;

    /* Touchlink (requires BDB_COMMISSION_MODE_TOUCHLINK) */
    struct {
        uint8_t tl_endpoint; /* Endpoint for the Touchlink Cluster (e.g. ) */
        uint8_t bind_endpoint; /* Endpoint to use when binding clusters from Initiator to Target. */
        uint16_t deviceId; /* e.g. ZCL_DEVICE_ONOFF_SWITCH */
        uint8_t zb_info; /* e.g. ZCL_TL_ZBINFO_TYPE_ROUTER */
        uint8_t flags; /* e.g. ZCL_TL_FLAGS_IS_TARGET */
        const void *persist_buf; /* if ZCL_TL_ZBINFO_USE_PERSIST */
        unsigned int persist_len;
    } touchlink;
};

/* Non-blocking startup function */
enum ZbStatusCodeT ZB_WARN_UNUSED ZbStartup(struct ZigBeeT *zb, struct ZbStartupT *configPtr, void (*callback)(enum ZbStatusCodeT status, void *cb_arg), void *arg);

/* If Touchlink Target was started with ZbStartup, this API can be used to stop it. */
enum ZbStatusCodeT ZbStartupTouchlinkTargetStop(struct ZigBeeT *zb);

/* Manually start Finding & Binding. F&B is also started automatically after joining
 * the network. */
enum ZbStatusCodeT ZB_WARN_UNUSED ZbStartupFindBindStart(struct ZigBeeT *zb,
    void (*callback)(enum ZbStatusCodeT status, void *arg), void *arg);

/* Same as ZbStartupFindBindStart, but only for a single endpoint. */
enum ZbStatusCodeT ZB_WARN_UNUSED ZbStartupFindBindStartEndpoint(struct ZigBeeT *zb, uint8_t endpoint,
    void (*callback)(enum ZbStatusCodeT status, void *arg), void *arg);

/* ZbStartupRejoin is a wrapper for ZbNlmeJoinReq(ZB_NWK_REJOIN_TYPE_NWKREJOIN).
 * Use ZbStartupRejoin instead, because the internal startup handler will restart
 * any timers we need to maintain our parent.
 *
 * Must already be connected to a network. If not on a network and want to
 * rejoin as way to connect, use ZbStartup with ZbStartTypeRejoin.*/
enum ZbStatusCodeT ZB_WARN_UNUSED ZbStartupRejoin(struct ZigBeeT *zb, void (*callback)(struct ZbNlmeJoinConfT *conf, void *arg), void *cbarg);

/* Trust Center Rejoin - unsecured rejoin (already joined to network, but
 * missed a NWK key update). */
enum ZbStatusCodeT ZB_WARN_UNUSED ZbTrustCenterRejoin(struct ZigBeeT *zb, void (*callback)(enum ZbStatusCodeT status, void *arg), void *cbarg);

/* Try starting stack using persistence data provided. */
enum ZbStatusCodeT ZbStartupPersist(struct ZigBeeT *zb, const void *pdata, unsigned int plen, struct ZbStartupCbkeT *cbke_config);

/* Get the default configuration for a PRO network. */
void ZbStartupConfigGetProDefaults(struct ZbStartupT *configPtr);
/* Same as ZbStartupConfigGetProDefaults, but clears the preconfigured global link keys. */
void ZbStartupConfigGetProSeDefaults(struct ZbStartupT *configPtr);

/* The application can call ZbStartupTcsoStart if it thinks it as lost communication with the
 * Trust Center. The Trust Center Swap Out process will be performed.
 * The callback status is set to ZB_STATUS_SUCCESS if the stack is operational. */
bool ZB_WARN_UNUSED ZbStartupTcsoStart(struct ZigBeeT *zb, void (*callback)(enum ZbTcsoStatusT status, void *arg), void *arg);
bool ZbStartupTcsoAbort(struct ZigBeeT *zb);

#endif /* ZIGBEE_STARTUP_H */