Add new API to get the panid from operational network 04/272904/1
authorWootak Jung <wootak.jung@samsung.com>
Fri, 25 Mar 2022 02:18:46 +0000 (11:18 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 28 Mar 2022 01:57:51 +0000 (10:57 +0900)
Change-Id: I658dfd3d29753b0c24024b74b172398b8ac4e54a
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
include/thread.h
src/thread-network.c

index f430ea6..36fbb4e 100644 (file)
@@ -363,6 +363,27 @@ int thread_network_get_active_dataset_tlvs(thread_instance_h instance,
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_MODULE
+ * @brief Get the PanId from Operational Network
+ * @since_tizen 7.0
+ *
+ * @param[out] panid The PanId
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #THREAD_ERROR_NONE  Successful
+ * @retval #THREAD_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #THREAD_ERROR_OPERATION_FAILED  Operation failed
+ * @retval #THREAD_ERROR_NOT_SUPPORTED  Not supported
+ *
+ * @pre thread API must be initialized with thread_initialize().
+ * @pre Active Operational Dataset must be set using thread_set_active_dataset_tlvs().
+ *
+ * @see thread_network_create_operational_network()
+ * @see thread_set_active_dataset_tlvs()
+ */
+int thread_network_get_panid(thread_instance_h instance, uint16_t *panid);
+
+/**
+ * @ingroup CAPI_NETWORK_THREAD_MODULE
  * @brief Attach the OT hardware to the active Operational Network, which is pre-set
  * @since_tizen 7.0
  *
index 9ec8254..83bf963 100644 (file)
@@ -236,6 +236,30 @@ int thread_network_get_active_dataset_tlvs(thread_instance_h instance,
        return ret;
 }
 
+int thread_network_get_panid(thread_instance_h instance, uint16_t *panid)
+{
+       FUNC_ENTRY;
+       THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
+       THREAD_CHECK_INIT_STATUS();
+       THREAD_VALIDATE_INPUT_PARAMETER(instance);
+       THREAD_VALIDATE_INPUT_PARAMETER(panid);
+
+       int ret = THREAD_ERROR_NONE;
+       GVariant *out = NULL;
+
+       /* get "PanId" dbus property */
+       ret = _thread_dbus_get_property(
+               THREAD_DBUS_PROPERTY_PANID, &out);
+       retv_if(ret != THREAD_ERROR_NONE, ret);
+
+       g_variant_get(out, "q", panid);
+       THREAD_DBG("Thread PanId: %u", (size_t)*panid);
+       g_variant_unref(out);
+
+       FUNC_EXIT;
+       return THREAD_ERROR_NONE;
+}
+
 static int __thread_attach_active_network()
 {
        FUNC_ENTRY;