3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 * Copyright (c) 2020 Silicon Labs
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
26 * http://www.apache.org/licenses/LICENSE-2.0
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 /***************************************************************************/
37 * @brief It implements and manages the ESI table. The
38 *ESI table is shared among other plugins.
39 *******************************************************************************
40 ******************************************************************************/
46 #ifndef EMBER_AF_PLUGIN_ESI_MANAGEMENT_ESI_TABLE_SIZE
47 #define EMBER_AF_PLUGIN_ESI_MANAGEMENT_ESI_TABLE_SIZE 3
48 #endif // EMBER_AF_PLUGIN_ESI_MANAGEMENT_ESI_TABLE_SIZE
50 #ifndef EMBER_AF_PLUGIN_ESI_MANAGEMENT_MIN_ERASING_AGE
51 #define EMBER_AF_PLUGIN_ESI_MANAGEMENT_MIN_ERASING_AGE 3
52 #endif // EMBER_AF_PLUGIN_ESI_MANAGEMENT_MIN_ERASING_AGE
54 #ifndef EMBER_AF_PLUGIN_ESI_MANAGEMENT_PLUGIN_CALLBACK_TABLE_SIZE
55 #define EMBER_AF_PLUGIN_ESI_MANAGEMENT_PLUGIN_CALLBACK_TABLE_SIZE 5
56 #endif // EMBER_AF_PLUGIN_ESI_MANAGEMENT_PLUGIN_CALLBACK_TABLE_SIZE
63 chip::EndpointId endpoint;
64 uint8_t age; // The number of discovery cycles the ESI has not been discovered.
65 } EmberAfPluginEsiManagementEsiEntry;
67 typedef void (*EmberAfEsiManagementDeletionCallback)(uint8_t);
70 * Searches in the ESI table by the pair node (short ID, endopoint).
72 * Returns a pointer to the entry if a matching entry was found, otherwise it
75 EmberAfPluginEsiManagementEsiEntry * emberAfPluginEsiManagementEsiLookUpByShortIdAndEndpoint(EmberNodeId shortId,
76 chip::EndpointId endpoint);
79 * Searches in the ESI table by the pair node (long ID, endopoint).
81 * Returns a pointer to the entry if a matching entry was found, otherwise it
84 EmberAfPluginEsiManagementEsiEntry * emberAfPluginEsiManagementEsiLookUpByLongIdAndEndpoint(EmberEUI64 longId,
85 chip::EndpointId endpoint);
88 * Allows retrieving the index of an entry that matches the passed short ID
91 * It returns the index of the matching entry if a matching entry was found,
92 * otherwise it returns 0xFF.
94 uint8_t emberAfPluginEsiManagementIndexLookUpByShortIdAndEndpoint(EmberNodeId shortId, chip::EndpointId endpoint);
97 * Allows retrieving the index of an entry that matches the passed long ID
100 * It returns the index of the matching entry if a matching entry was found,
101 * otherwise it returns 0xFF.
103 uint8_t emberAfPluginEsiManagementIndexLookUpByLongIdAndEndpoint(EmberEUI64 longId, chip::EndpointId endpoint);
106 * Searches in the ESI table by the table index.
108 * Returns a pointer to the ESI entry stored at the index passed as
111 EmberAfPluginEsiManagementEsiEntry * emberAfPluginEsiManagementEsiLookUpByIndex(uint8_t index);
114 * Iterates through the entries in the
115 * table that are within a certain age threshold.
117 * If the passed pointer is NULL, it returns the first active entry with age
118 * lesser or equal than the passed age parameter (if any). Otherwise, it returns
119 * the next active entry that satisfy the age requirement. If the are no entries
120 * after the passed entry that satisfy the age requirement, it returns NULL.
122 EmberAfPluginEsiManagementEsiEntry * emberAfPluginEsiManagementGetNextEntry(EmberAfPluginEsiManagementEsiEntry * entry,
126 * Allows obtaining a free entry in the ESI table. It is the
127 * requester responsibility to properly set all the fields in the obtained free
128 * entry such as nodeId, age, and so on to avoid inconsistencies in the
131 * Returns a free entry (if any), otherwise it clears the oldest entry whose age
132 * is at least EMBER_AF_PLUGIN_ESI_MANAGEMENT_MIN_ERASING_AGE (if any) and
133 * returns it, otherwise it returns NULL.
135 EmberAfPluginEsiManagementEsiEntry * emberAfPluginEsiManagementGetFreeEntry(void);
138 * Deletes the entry indicated by the parameter 'index' from the
141 void emberAfPluginEsiManagementDeleteEntry(uint8_t index);
144 * Increases the age of all the active entries in the table. A
145 * non-active entry is an entry whose short ID is set to EMBER_NULL_NODE_ID.
147 void emberAfPluginEsiManagementAgeAllEntries(void);
150 * Clears the ESI table, i.e., it sets the short ID of each entry
151 * to EMBER_NULL_NODE_ID.
153 void emberAfPluginEsiManagementClearTable(void);
156 * Allows a plugin to subscribe to ESI entries deletion
157 * announcements by passing its own deletion callback function. Upon an entry
158 * deletion, all the deletion callback function are called passing the index
159 * of the deleted entry.
161 * It returns true if the subscription was successful, false otherwise.
163 bool emberAfPluginEsiManagementSubscribeToDeletionAnnouncements(EmberAfEsiManagementDeletionCallback callback);
166 * Performs the following steps:
167 * - Search for the source node of the passed command in the ESI table.
168 * - Adds a new entry in the ESI table if the source node is not present in the
169 * ESI table yet, or updates the current entry if needed.
171 * @return The index of the source node of the passed command in the ESI
172 * table, or it returns 0xFF if the ESI was not present in the table and a new
173 * entry could not be added since the table was full.
175 uint8_t emberAfPluginEsiManagementUpdateEsiAndGetIndex(const EmberAfClusterCommand * cmd);