+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#include "assert_local.h"
+#include <bluetooth.h>
+#include "bluetooth_internal.h"
+#include <stdlib.h>
+#include <stdbool.h>
+#include <glib.h>
+#include <string.h>
+#include <system_info.h>
+#include "bluetooth_private.h"
+
+static int startup_flag = BT_ERROR_NONE;
+static GMainLoop *mainloop = NULL;
+static int ret = BT_ERROR_NONE;
+static bool bt_supported = false;
+static bool mesh_supported = false;
+
+static bool __bt_mesh_elem_foreach_model_cb(int result, bt_mesh_element_h element, int total,
+ bt_mesh_model_h model, bt_mesh_model_id_s *model_id, void *user_data)
+{
+ return true;
+}
+
+static bool __bt_mesh_node_foreach_elem_cb(int result, bt_mesh_node_h node, int total,
+ bt_mesh_element_h element, int elem_index, uint16_t element_addr, void *user_data)
+{
+ return true;
+}
+
+static bool __bt_mesh_network_netkey_info_cb(int result, bt_mesh_network_h network, int total,
+ bt_mesh_netkey_h netkey, uint16_t netkey_index, void *user_data)
+{
+ return true;
+}
+
+static bool __bt_mesh_appkey_info_cb(int result, bt_mesh_network_h network, int total, bt_mesh_netkey_h netkey,
+ bt_mesh_appkey_h appkey, uint16_t appkey_index, void *user_data)
+{
+ return true;
+}
+
+static bool __bt_mesh_network_device_info_cb(int result, bt_mesh_network_h network, int total,
+ const char *dev_uuid, uint16_t primary_unicast, void *user_data)
+{
+ return true;
+}
+
+static bool __bt_mesh_network_group_info_cb(int result, bt_mesh_network_h network, int total,
+ bt_mesh_group_h group, void *user_data)
+{
+ return true;
+}
+
+static void __bt_mesh_network_scan_unprovisioned_device_result_cb(int result, bt_mesh_network_h network,
+ bt_mesh_scanning_state_e state, bt_mesh_scan_result_s *scan_res, void *user_data)
+{
+ if (mainloop)
+ g_main_loop_quit(mainloop);
+}
+
+static void __bt_mesh_network_device_provision_cb(int result, bt_mesh_network_h network,
+ const char* dev_uuid, void* user_data)
+{
+ if (mainloop)
+ g_main_loop_quit(mainloop);
+}
+
+static void __bt_mesh_authentication_request_cb(int result, bt_mesh_authentication_type_e auth_type,
+ char *auth_value, void *user_data)
+{
+ if (mainloop)
+ g_main_loop_quit(mainloop);
+}
+
+static void wait_for_async()
+{
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+}
+
+void utc_bluetooth_mesh_network_positive_startup(void)
+{
+ bt_supported = false;
+ system_info_get_platform_bool("http://tizen.org/feature/network.bluetooth", &bt_supported);
+
+ if (bt_supported) {
+ startup_flag = BT_ERROR_NONE;
+ mesh_supported = false;
+ _bt_check_supported_feature(BT_FEATURE_MESH, &mesh_supported);
+
+ if (mesh_supported) {
+ ret = bt_mesh_initialize();
+ if (BT_ERROR_NONE != ret) {
+ fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__);
+ fprintf(stderr, "bt_mesh_initialize failed (code: %d)\n", ret);
+ startup_flag = ret;
+ return;
+ }
+ }
+ }
+}
+
+void utc_bluetooth_mesh_network_positive_cleanup(void)
+{
+ if (mesh_supported)
+ bt_mesh_deinitialize();
+
+
+ if (bt_supported)
+ bt_deinitialize();
+}
+
+int utc_bluetooth_bt_mesh_initialize_p(void)
+{
+ int ret = BT_ERROR_NONE;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ ret = bt_mesh_deinitialize();
+
+ ret = bt_mesh_initialize();
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_initialize();
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_deinitialize_p(void)
+{
+ int ret = BT_ERROR_NONE;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ ret = bt_mesh_deinitialize();
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_deinitialize();
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_create_node_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h local_node = NULL;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &local_node);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_node_create(&features, &local_node);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_node_destroy_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h local_node = NULL;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &local_node);
+
+ ret = bt_mesh_node_destroy(local_node);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_node_destroy(local_node);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_node_create_element_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_node_get_network_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_network_h net_h = NULL;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ ret = bt_mesh_node_get_network(node_h, &net_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_node_get_network(node_h, &net_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_element_create_model_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_model_get_id_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+
+ memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s));
+
+ ret = bt_mesh_model_get_id(model_h, &mod_id);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_model_get_id(model_h, &mod_id);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_model_destroy_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+
+ ret = bt_mesh_model_destroy(model_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_model_destroy(model_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_model_get_element_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+
+ elem_h = NULL;
+ ret = bt_mesh_model_get_element(model_h, &elem_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_model_get_element(model_h, &elem_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_element_destroy_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+
+ ret = bt_mesh_element_destroy(elem_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_element_destroy(elem_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_element_get_node_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ ret = bt_mesh_element_get_node(elem_h, &node_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_element_get_node(elem_h, &node_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_node_foreach_element_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ ret = bt_mesh_node_foreach_element(node_h, __bt_mesh_node_foreach_elem_cb, NULL);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_node_foreach_element(node_h, __bt_mesh_node_foreach_elem_cb, NULL);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_element_foreach_models_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h element_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &element_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(element_h, &mod_id, &model_h);
+
+ ret = bt_mesh_element_foreach_models(element_h, __bt_mesh_elem_foreach_model_cb, NULL);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_element_foreach_models(element_h, __bt_mesh_elem_foreach_model_cb, NULL);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_network_create_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_network_load_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+
+ ret = bt_mesh_network_load(token, &network);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_load(token, &network);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_network_set_name_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+
+ ret = bt_mesh_network_set_name(network, network_name);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_set_name(network, network_name);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_network_get_name_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+
+ ret = bt_mesh_network_get_name(network, &network_name);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_get_name(network, &network_name);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_network_add_netkey_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h n_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+
+ ret = bt_mesh_network_add_netkey(network, &n_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_add_netkey(network, &n_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_network_foreach_netkeys_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h n_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &n_h);
+
+ ret = bt_mesh_network_foreach_netkeys(network, __bt_mesh_network_netkey_info_cb, NULL);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_foreach_netkeys(network, __bt_mesh_network_netkey_info_cb, NULL);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_netkey_get_index_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ uint16_t indx = 0xFFFF;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+
+ ret = bt_mesh_netkey_get_index(netkey_h, &indx);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_netkey_get_index(netkey_h, &indx);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_netkey_update_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+
+ ret = bt_mesh_netkey_update(netkey_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_netkey_update(netkey_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_netkey_delete_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+
+ ret = bt_mesh_netkey_delete(netkey_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_netkey_delete(netkey_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_netkey_add_appkey_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_netkey_foreach_appkeys_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+
+ ret = bt_mesh_netkey_foreach_appkeys(netkey_h, __bt_mesh_appkey_info_cb, NULL);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_netkey_foreach_appkeys(netkey_h, __bt_mesh_appkey_info_cb, NULL);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+int utc_bluetooth_bt_mesh_appkey_get_index_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ uint16_t index = 0xFFFF;
+ bt_mesh_appkey_h appkey_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+
+ ret = bt_mesh_appkey_get_index(appkey_h, &index);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_appkey_get_index(appkey_h, &index);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_appkey_update_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+
+ ret = bt_mesh_appkey_update(appkey_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_appkey_update(appkey_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_appkey_delete_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+
+ ret = bt_mesh_appkey_delete(appkey_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_appkey_delete(appkey_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_network_foreach_devices_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+
+ ret = bt_mesh_network_foreach_devices(network, __bt_mesh_network_device_info_cb, NULL);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_foreach_devices(network, __bt_mesh_network_device_info_cb, NULL);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_network_create_group_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+ uint16_t group_addr = 0xc001;
+ bt_mesh_group_h group_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+
+ ret = bt_mesh_network_create_group(network, group_addr, &group_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_create_group(network, group_addr, &group_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_network_create_virtual_group_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+ bt_mesh_group_h group_h;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+
+ ret = bt_mesh_network_create_virtual_group(network, &group_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_create_virtual_group(network, &group_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_network_remove_group_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+ bt_mesh_group_h group_h;
+ uint16_t group_addr = 0xc001;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+ ret = bt_mesh_network_create_group(network, group_addr, &group_h);
+
+ ret = bt_mesh_network_remove_group(group_h);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_remove_group(group_h);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_network_foreach_groups_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+ bt_mesh_group_h group_h;
+ uint16_t group_addr = 0xc001;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+ ret = bt_mesh_network_create_group(network, group_addr, &group_h);
+
+ ret = bt_mesh_network_foreach_groups(network, __bt_mesh_network_group_info_cb, NULL);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_foreach_groups(network, __bt_mesh_network_group_info_cb, NULL);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_network_unprovisioned_device_scan_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+ bt_mesh_group_h group_h;
+ uint16_t group_addr = 0xc001;
+ bt_mesh_scan_params_s scan_params;
+
+ memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s));
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+ ret = bt_mesh_network_create_group(network, group_addr, &group_h);
+
+ ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params,
+ __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL);
+ assert_eq(ret, BT_ERROR_NONE);
+ wait_for_async();
+
+ } else {
+ ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params,
+ __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_stop_unprovisioned_device_scan_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+ bt_mesh_group_h group_h;
+ uint16_t group_addr = 0xc001;
+ bt_mesh_scan_params_s scan_params;
+
+ memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s));
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+ ret = bt_mesh_network_create_group(network, group_addr, &group_h);
+
+ ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params,
+ __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL);
+ wait_for_async();
+
+ ret = bt_mesh_stop_unprovisioned_device_scan(network);
+ assert_eq(ret, BT_ERROR_NONE);
+
+ } else {
+ ret = bt_mesh_stop_unprovisioned_device_scan(network);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_network_provision_device_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+ bt_mesh_group_h group_h;
+ uint16_t group_addr = 0xc001;
+ char *dev_uuid = "abababababababababababababababab";
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+ ret = bt_mesh_network_create_group(network, group_addr, &group_h);
+
+ ret = bt_mesh_network_provision_device(network, dev_uuid,
+ __bt_mesh_network_device_provision_cb, NULL);
+ assert_eq(ret, BT_ERROR_NONE);
+
+ wait_for_async();
+
+ } else {
+ ret = bt_mesh_network_provision_device(network, dev_uuid,
+ __bt_mesh_network_device_provision_cb, NULL);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_authentication_set_request_cb_p(void)
+{
+ int ret = BT_ERROR_NONE;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ ret = bt_mesh_authentication_set_request_cb(__bt_mesh_authentication_request_cb, NULL);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_authentication_set_request_cb(__bt_mesh_authentication_request_cb, NULL);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_authentication_reply_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+ bt_mesh_group_h group_h;
+ uint16_t group_addr = 0xc001;
+ char *dev_uuid = "abababababababababababababababab";
+ static bt_mesh_authentication_type_e request_type = BT_MESH_AUTH_ALPHANUMERIC_DISPLAY;
+ char* value = "authentication_reply";
+ bool auth_reply = TRUE;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+ ret = bt_mesh_network_create_group(network, group_addr, &group_h);
+ ret = bt_mesh_network_provision_device(network, dev_uuid,
+ __bt_mesh_network_device_provision_cb, NULL);
+ wait_for_async();
+
+ ret = bt_mesh_authentication_reply(request_type, (const char*)value, auth_reply);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_authentication_reply(request_type, (const char*)value, auth_reply);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+
+
+int utc_bluetooth_bt_mesh_network_set_provisioning_capabilities_p(void)
+{
+ int ret = BT_ERROR_NONE;
+ bt_mesh_node_features_s features;
+ bt_mesh_node_h node_h = NULL;
+ bt_mesh_element_h elem_h = NULL;
+ bt_mesh_model_h model_h = NULL;
+ bt_mesh_model_id_s mod_id;
+ char *network_name = "test-mesh";
+ char *token;
+ bt_mesh_network_h network;
+ bt_mesh_netkey_h netkey_h;
+ bt_mesh_appkey_h appkey_h;
+ bt_mesh_group_h group_h;
+ uint16_t group_addr = 0xc001;
+ bt_mesh_provisioner_capabilities_s capabilities;
+
+ if (mesh_supported) {
+ assert_eq(startup_flag, BT_ERROR_NONE);
+
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ ret = bt_mesh_node_create(&features, &node_h);
+ ret = bt_mesh_node_create_element(node_h, &elem_h);
+
+ mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV;
+ mod_id.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+ ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
+ ret = bt_mesh_network_add_netkey(network, &netkey_h);
+ ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
+ ret = bt_mesh_network_create_group(network, group_addr, &group_h);
+
+ capabilities.public_oob = FALSE;
+ capabilities.static_oob = FALSE;
+ capabilities.out_oob = BT_MESH_OUT_OOB_METHOD_BLINK;
+ capabilities.in_oob = BT_MESH_IN_OOB_METHOD_PUSH;
+
+ ret = bt_mesh_network_set_provisioning_capabilities(network, &capabilities);
+ assert_eq(ret, BT_ERROR_NONE);
+ } else {
+ ret = bt_mesh_network_set_provisioning_capabilities(network, &capabilities);
+ assert_eq(ret, BT_ERROR_NOT_SUPPORTED);
+ }
+
+ return 0;
+}
+