Add zb_get_endpoint_list / zb_get_cluster_list APIs
authorJiwan Kim <ji-wan.kim@samsung.com>
Thu, 9 Feb 2017 05:16:03 +0000 (14:16 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 11 May 2017 09:07:20 +0000 (18:07 +0900)
- These functions are intended to get endpoint list
  and cluster list from specific device.

Change-Id: I819bafb43e99d6ceacc25b277c3adf97d373cfbf
Signed-off-by: Jiwan Kim <ji-wan.kim@samsung.com>
include/zigbee.h
lib/zbl-dbus.c
lib/zbl-dbus.h
lib/zbl-zdo.c
test/main.c

index 856af35..14753d4 100644 (file)
@@ -397,6 +397,46 @@ int zb_get_network_info(zigbee_h handle, ieee_addr addr64, nwk_addr *nodeid,
 int zb_get_all_device_list(zigbee_h handle, int *count, zb_end_device_info_h **list);
 
 /**
+ * @brief Get endpoint list information.
+ * @details This function return end-point list at each device.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] handle The handle of zigbee
+ * @param[in] addr64 the Zigbee IEEE MAC address
+ * @param[out] count The number of endpoints
+ * @param[out] ep_list The device endpoint list
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ZIGBEE_ERROR_NONE Successful
+ * @retval #ZIGBEE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ZIGBEE_ERROR_IO_ERROR Unexpected d-bus error
+ */
+int zb_get_endpoint_list(zigbee_h handle, ieee_addr addr64, int *count,
+               unsigned char *ep_list);
+
+/**
+ * @brief Get cluster list information.
+ * @details This function return in and out cluster list at each device.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] handle The handle of zigbee
+ * @param[in] addr64 the Zigbee IEEE MAC address
+ * @param[out] in_cluster_count The number of in-clusters
+ * @param[out] in_cluster_count The number of out-clusters
+ * @param[out] list The device information list
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #ZIGBEE_ERROR_NONE Successful
+ * @retval #ZIGBEE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ZIGBEE_ERROR_IO_ERROR Unexpected d-bus error
+ */
+int zb_get_cluster_list(zigbee_h handle, ieee_addr addr64, unsigned char ep,
+               unsigned char *in_cluster_count, unsigned short *in_cluster_list,
+               unsigned char *out_cluster_count, unsigned short *out_cluster_list);
+
+/**
  * @brief free all children device list information.
  * @details This function return end-point list and simple description per each end-point
  * at each device.
index 997ed67..0b8edcf 100644 (file)
@@ -3124,13 +3124,15 @@ int zbl_get_controller_mac_address(ieee_addr addr64)
        return result;
 }
 
-int zbl_get_cluster_list(ieee_addr eui64, unsigned char endpoint, unsigned short list[],
-               unsigned char *count)
+int zbl_get_cluster_list(ieee_addr eui64, unsigned char endpoint,
+               unsigned char *in_cluster_count, unsigned char *out_cluster_count,
+               unsigned short in_cluster_list[], unsigned short out_cluster_list[])
 {
        GVariant *variant = NULL;
        GVariantBuilder *mac_builder = NULL;
        GVariant *mac_variant = NULL;
-       GVariantIter *iter = NULL;
+       GVariantIter *in_cluster_iter = NULL;
+       GVariantIter *out_cluster_iter = NULL;
        GError *dbus_err = NULL;
        unsigned short cluster;
        int i = 0;
@@ -3152,28 +3154,42 @@ int zbl_get_cluster_list(ieee_addr eui64, unsigned char endpoint, unsigned short
        g_variant_builder_unref(mac_builder);
 
        variant = g_dbus_proxy_call_sync(service_gproxy, "get_cluster_list",
-                               g_variant_new("(@ayy)", mac_variant, endpoint), G_DBUS_CALL_FLAGS_NONE,
+                               g_variant_new("(@a(y)y)", mac_variant, endpoint), G_DBUS_CALL_FLAGS_NONE,
                                -1, NULL, &dbus_err);
 
        if (variant) {
-               g_variant_get(variant, "(iaq)", &result, &iter);
+               g_variant_get(variant, "(iaqaq)", &result, &in_cluster_iter, &out_cluster_iter);
                DBG("ret = [0x%x]", result);
 
-               while (g_variant_iter_loop(iter, "q", &cluster)) {
-                       DBG("Cluster 0x%04X", cluster);
-                       list[i++] = cluster;
+               /* In clusters */
+               while (g_variant_iter_loop(in_cluster_iter, "q", &cluster)) {
+                       DBG("In Cluster 0x%04X", cluster);
+                       in_cluster_list[i++] = cluster;
                }
-               *count = i;
+               *in_cluster_count = i;
                if (0 == i)
-                       ERR("No Clusters for Endpoint %0X", endpoint);
+                       ERR("No In Clusters for Endpoint %0X", endpoint);
 
-               if (NULL != iter)
-                       g_variant_iter_free(iter);
+               /* Out clusters */
+               i = 0;
+               while (g_variant_iter_loop(out_cluster_iter, "q", &cluster)) {
+                       DBG("Out Cluster 0x%04X", cluster);
+                       out_cluster_list[i++] = cluster;
+               }
+               *out_cluster_count = i;
+               if (0 == i)
+                       ERR("No Out Clusters for Endpoint %0X", endpoint);
+
+               if (NULL != in_cluster_iter)
+                       g_variant_iter_free(in_cluster_iter);
+               if (NULL != out_cluster_iter)
+                       g_variant_iter_free(out_cluster_iter);
                g_variant_unref(variant);
        } else {
-               ERR("No Clusters for Endpoint %0X [%s]", endpoint, dbus_err->message);
+               ERR("No In/Out Clusters for Endpoint %0X [%s]", endpoint, dbus_err->message);
                g_error_free(dbus_err);
-               *count = 0;
+               *in_cluster_count = 0;
+               *out_cluster_count = 0;
        }
 
        return ZIGBEE_ERROR_NONE;
index 0b8176c..44ba027 100644 (file)
@@ -34,6 +34,10 @@ int zbl_coex_stop(void);
 int zbl_get_network_info(ieee_addr addr64, nwk_addr *nodeid, nwk_addr *panid,
                unsigned char *channel, unsigned char *tx_power);
 int zbl_get_controller_mac_address(ieee_addr addr64);
+int zbl_get_cluster_list(ieee_addr eui64, unsigned char endpoint,
+               unsigned char *in_cluster_count, unsigned char *out_cluster_count,
+               unsigned short in_cluster_list[], unsigned short out_cluster_list[]);
+int zbl_get_endpoint_list(ieee_addr eui64, unsigned char list[], unsigned char *count);
 int zbl_get_all_device_info(zb_end_device_info_h **dev_list, unsigned char* num);
 int zbl_form_network(zigbee_h handle, zb_form_network_cb cb, void *user_data);
 int zbl_disable_network(zigbee_h handle, zb_disable_network_cb cb, void *user_data);
index bee6f2a..a58614b 100644 (file)
@@ -201,6 +201,43 @@ API int zb_get_all_device_list(zigbee_h handle, int *count, zb_end_device_info_h
        return ret;
 }
 
+API int zb_get_endpoint_list(zigbee_h handle, ieee_addr addr64, int *count,
+               unsigned char *ep_list)
+{
+       int ret;
+       unsigned char cnt = 0;
+
+       RETV_IF(NULL == addr64, ZIGBEE_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == count, ZIGBEE_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == ep_list, ZIGBEE_ERROR_INVALID_PARAMETER);
+
+       ret = zbl_get_endpoint_list(addr64, ep_list, &cnt);
+       *count = cnt;
+       return ret;
+}
+
+API int zb_get_cluster_list(zigbee_h handle, ieee_addr addr64, unsigned char ep,
+               unsigned char *in_cluster_count, unsigned short *in_cluster_list,
+               unsigned char *out_cluster_count, unsigned short *out_cluster_list)
+{
+       int ret;
+       unsigned char in_cnt = 0;
+       unsigned char out_cnt = 0;
+
+       RETV_IF(NULL == addr64, ZIGBEE_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == in_cluster_count, ZIGBEE_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == in_cluster_list, ZIGBEE_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == out_cluster_count, ZIGBEE_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == out_cluster_list, ZIGBEE_ERROR_INVALID_PARAMETER);
+
+       ret = zbl_get_cluster_list(addr64, ep, &in_cnt, in_cluster_list,
+                       &out_cnt, out_cluster_list);
+       *in_cluster_count = in_cnt;
+       *out_cluster_count = out_cnt;
+
+       return ret;
+}
+
 API int zb_devices_info_foreach_end_device(zb_end_device_info_h *list,
                zb_end_device_cb cb, void *user_data)
 {
index 7a73c61..7098a2b 100644 (file)
@@ -39,6 +39,7 @@ extern struct menu_data menu_zcl_cluster[];
 extern struct menu_data menu_custom[];
 
 static char data_remove_children[MENU_DATA_SIZE + 1] = "1";
+static char data_endpoint[MENU_DATA_SIZE + 1] = "0";
 static char data_rejoin[MENU_DATA_SIZE + 1] = "0";
 static char data_pj_timeout[MENU_DATA_SIZE + 1] = "90";
 static char data_choose_target[MENU_DATA_SIZE + 1] = "0";
@@ -651,6 +652,66 @@ static int run_get_end_device_list(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
+static int run_get_endpoint_list(MManager *mm, struct menu_data *menu)
+{
+       int ret = ZIGBEE_ERROR_NONE;
+       int i = 0;
+       unsigned char count = 0;
+       unsigned char ep_list[10];
+
+       ret = zb_get_endpoint_list(handle, dest_addr64, &count, ep_list);
+       if (ZIGBEE_ERROR_NONE != ret) {
+               msg("zb_get_endpoint_list(%d) - FAILED!!!", ret);
+               return RET_FAILURE;
+       }
+
+       msg(" - zb_get_endpoint_list() ret: [0x%X]", ret);
+       msgb("Endpoints count [%d] : ", count);
+       for(i = 0; i < count; i++) {
+               msgn("  %04d", ep_list[i]);
+       }
+       msg("\n");
+
+       return RET_SUCCESS;
+}
+
+static int run_get_cluster_list(MManager *mm, struct menu_data *menu)
+{
+       int ret = ZIGBEE_ERROR_NONE;
+       int i = 0;
+       unsigned char ep = 0;
+       unsigned char in_count = 0;
+       unsigned char out_count = 0;
+       unsigned short in_cluster_list[MAX_ENDPOINT_CLUSTERS];
+       unsigned short out_cluster_list[MAX_ENDPOINT_CLUSTERS];
+
+       if (strlen(data_endpoint) > 0) {
+               ep = (unsigned char)strtol(data_endpoint, NULL, 10);
+       }
+
+       ret = zb_get_cluster_list(handle, dest_addr64, ep,
+                               &in_count, in_cluster_list,
+                               &out_count, out_cluster_list);
+       if (ZIGBEE_ERROR_NONE != ret) {
+               msg("zb_get_cluster_list(%d) - FAILED!!!", ret);
+               return RET_FAILURE;
+       }
+
+       msg(" - zb_get_cluster_list() ret: [0x%X]", ret);
+       msgb("In Clusters count [%d] : ", in_count);
+       for(i = 0; i < in_count; i++) {
+               msgn("  %04d", in_cluster_list[i]);
+       }
+       msg("\n");
+       msgb("Out Clusters count [%d] : ", out_count);
+       for(i = 0; i < out_count; i++) {
+               msgn("  %04d", out_cluster_list[i]);
+       }
+       msg("\n");
+
+       return RET_SUCCESS;
+}
+
 static int run_choose_end_device_list(MManager *mm, struct menu_data *menu)
 {
        int ret = ZIGBEE_ERROR_NONE;
@@ -823,6 +884,12 @@ struct menu_data menu_sel_device[] = {
        { NULL, NULL, },
 };
 
+static struct menu_data _menu_get_cluster_list[] = {
+       { "1", "Endpoint", NULL, NULL, data_endpoint },
+       { "2", "Run", NULL, run_get_cluster_list, NULL },
+       { NULL, NULL, },
+};
+
 static struct menu_data menu_device[] = {
        { "1", "zb_create", NULL, run_create, NULL },
        { "2", "zb_destroy", NULL, run_destroy, NULL },
@@ -832,6 +899,8 @@ static struct menu_data menu_device[] = {
        { "6", "zb_coex_start", NULL, run_coex_start, NULL },
        { "7", "zb_coex_stop", NULL, run_coex_stop, NULL },
        { "8", "zb_get_all_device_list", NULL, run_get_end_device_list, NULL },
+       { "9", "zb_get_endpoint_list", NULL, run_get_endpoint_list, NULL },
+       { "10", "zb_get_cluster_list", _menu_get_cluster_list, NULL, NULL },
        { NULL, NULL, },
 };