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

zcl_custom_ls_client.c « st_custom « zcl « stack « zigbee « STM32_WPAN « ST « Middlewares - github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 271c91d8b1f673fd6e2b4e3f9464edaa372fb830 (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
/*****************************************************************************
 * @file    zcl_custom_ls_client.c
 * @author  MCD Application Team
 * @brief   This file contains the implementation of the Custom Long String
 *          cluster (client part).
 *****************************************************************************
 * @attention
 *
 * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under Ultimate Liberty license
 * SLA0044, the "License"; You may not use this file except in compliance with
 * the License. You may obtain a copy of the License at:
 *                             www.st.com/SLA0044
 *
 ******************************************************************************
 */

#include <string.h>

#include "zigbee.h"
#include "zcl/zcl.h"
#include "zcl/st_custom/zcl.custom_ls.h"

struct zcl_custom_ls_client_cluster_t {
    struct ZbZclClusterT cluster;
};

/* Custom cluster long string allocation */
struct ZbZclClusterT *
ZbZcl_custom_ls_ClientAlloc(struct ZigBeeT *zb, uint8_t endpoint)
{
    struct zcl_custom_ls_client_cluster_t *clusterPtr;

    clusterPtr = ZbZclClusterAlloc(zb, sizeof(struct zcl_custom_ls_client_cluster_t),\
              ZCL_CLUSTER_CUSTOM_LS, endpoint, ZCL_DIRECTION_TO_CLIENT);
    if (clusterPtr == NULL) {
        return NULL;
    }
    
    /* This is the flags for Fragmentation */
    clusterPtr->cluster.txOptions |= (uint16_t)(ZB_APSDE_DATAREQ_TXOPTIONS_SECURITY | ZB_APSDE_DATAREQ_TXOPTIONS_ACK | ZB_APSDE_DATAREQ_TXOPTIONS_FRAG);
    //ZbZclClusterSetTxOptions(&clusterPtr->cluster, ZB_APSDE_DATAREQ_TXOPTIONS_FRAG); 
    (void)ZbZclAttrIntegerWrite(&clusterPtr->cluster, ZCL_GLOBAL_ATTR_CLUSTER_REV, 1);

    ZbZclClusterAttach(&clusterPtr->cluster);
    return &clusterPtr->cluster;
}

/* Client command */
enum ZclStatusCodeT
ZbZclSet_custom_ls_ClientCommand(struct ZbZclClusterT *cluster, struct ZbApsAddrT *dst, char *string,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg)
{
    struct ZbZclClusterCommandReqT req;
    uint8_t payload[2050];
    uint16_t len;
    
    len = (uint16_t)strlen(string);
    if (len > 2048) {
      return ZCL_STATUS_INVALID_VALUE;
    }
    
    putle16(&payload[0], len);
    memcpy(&payload[2], string, len);
    
    (void)memset(&req, 0, sizeof(req));
    req.dst = *dst;
    req.cmdId = ZCL_SET_CUSTOM_LS_COMMAND_REQ;
    req.noDefaultResp = /*ZCL_NO_DEFAULT_RESPONSE_FALSE*/ZCL_NO_DEFAULT_RESPONSE_TRUE;
    req.payload = payload;
    req.length = len + 2;
    ZbZclClusterCommandReq(cluster, &req, callback, arg);
    return ZCL_STATUS_SUCCESS;
}