796207cffebac2fdc928034d9c53b15c0d95e137
[platform/upstream/connectedhomeip.git] / src / app / zap-templates / call-command-handler-src.zapt
1 {{chip_header}}
2
3 #include <stdint.h>
4
5 #include "af-structs.h"
6 #include "call-command-handler.h"
7 #include "callback.h"
8 #include "command-id.h"
9 #include "util.h"
10
11 using namespace chip;
12
13 {{#all_user_clusters}}
14 {{#if (isEnabled enabled)}}
15 EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(EmberAfClusterCommand * cmd);
16 {{/if}}
17 {{/all_user_clusters}}
18
19
20 static EmberAfStatus status(bool wasHandled, bool clusterExists, bool mfgSpecific)
21 {
22     if (wasHandled)
23     {
24         return EMBER_ZCL_STATUS_SUCCESS;
25     }
26     else if (mfgSpecific)
27     {
28         return EMBER_ZCL_STATUS_UNSUP_MANUF_CLUSTER_COMMAND;
29     }
30     else if (clusterExists)
31     {
32         return EMBER_ZCL_STATUS_UNSUP_COMMAND;
33     }
34     else
35     {
36         return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER;
37     }
38 }
39
40
41 // Main command parsing controller.
42 EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd)
43 {
44     EmberAfStatus result = status(false, false, cmd->mfgSpecific);
45     if (cmd->direction == (uint8_t) ZCL_DIRECTION_SERVER_TO_CLIENT &&
46         emberAfContainsClientWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
47     {
48         switch (cmd->apsFrame->clusterId)
49         {
50         {{#all_user_clusters}}
51         {{#if (isEnabled enabled)}}
52         {{#if (isClient side) }}
53         case ZCL_{{asDelimitedMacro define}}_ID :
54             result = emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(cmd);
55             break;
56         {{/if}}
57         {{/if}}
58         {{/all_user_clusters}}
59         default:
60             // Unrecognized cluster ID, error status will apply.
61             break;
62         }
63     }
64     else if (cmd->direction == (uint8_t) ZCL_DIRECTION_CLIENT_TO_SERVER &&
65              emberAfContainsServerWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
66     {
67         switch (cmd->apsFrame->clusterId)
68         {
69         {{#all_user_clusters}}
70         {{#if (isEnabled enabled)}}
71         {{#unless (isClient  side) }}
72         case ZCL_{{asDelimitedMacro define}}_ID :
73             result = emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(cmd);
74             break;
75         {{/unless}}
76         {{/if}}
77         {{/all_user_clusters}}
78         default:
79             // Unrecognized cluster ID, error status will apply.
80             break;
81         }
82     }
83     return result;
84 }
85
86 // Cluster specific command parsing
87
88 {{#all_user_clusters}}
89 {{#if (isEnabled enabled)}}
90 EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(EmberAfClusterCommand * cmd)
91 {
92     bool wasHandled = false;
93
94     if (!cmd->mfgSpecific)
95     {
96         switch (cmd->commandId)
97         {
98         {{#all_user_cluster_commands}}
99         {{#if (isStrEqual clusterName parent.name)}}
100         {{#if (isCommandAvailable parent.side incoming outgoing commandSource name)}}
101         case ZCL_{{asDelimitedMacro name}}_COMMAND_ID: {
102             {{#if (zcl_command_arguments_count this.id)}}
103             uint32_t argOffset = 0;
104             {{#zcl_command_arguments}}
105             {{asUnderlyingType type}} * {{asSymbol label}} = ({{asUnderlyingType type}} *)(cmd->buffer + argOffset);
106             {{#unless (isLastElement index count)}}
107             argOffset+= sizeof({{asUnderlyingType type}});
108             {{/unless}}
109             {{/zcl_command_arguments}}
110
111             wasHandled = emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback({{#zcl_command_arguments}} *{{asSymbol label}}{{#unless (isLastElement index count)}}, {{/unless}}{{/zcl_command_arguments}});
112             {{else}}
113             wasHandled = emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback();
114             {{/if}}
115             break;
116         }
117         {{/if}}
118         {{/if}}
119         {{/all_user_cluster_commands}}
120         default: {
121             // Unrecognized command ID, error status will apply.
122             break;
123         }
124         }
125     }
126     return status(wasHandled, true, cmd->mfgSpecific);
127 }
128 {{/if}}
129 {{/all_user_clusters}}