static bt_mesh_node_h local_node = NULL;
static bt_mesh_node_h g_node;
static bt_mesh_network_h network;
-static char *device_uuid;
+static bt_mesh_element_h g_element;
+static bt_mesh_model_h g_model;
+static bt_mesh_model_h g_model_onoff_srv;
+static GSList *unprov_dev_list;
+static GSList *prov_dev_list;
+static GSList *srv_model_list;
+static char *g_device_uuid;
+static bool node_discovered = false;
+
+static bt_mesh_netkey_h g_netkey;
+static bt_mesh_appkey_h g_appkey;
+static bt_mesh_group_h g_group;
static char *token;
static bt_mesh_authentication_type_e request_type = BT_MESH_AUTH_ALPHANUMERIC_DISPLAY;
GMainLoop *main_loop = NULL;
+GMainLoop *mainloop = NULL;
+
+static void wait_for_async_over()
+{
+ if (mainloop)
+ g_main_loop_quit(mainloop);
+}
+static void wait_for_async()
+{
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+}
tc_table_t tc_control[] = {
{"Back"
{NULL , 0X0000},
};
+tc_table_t tc_scenario[] = {
+ {"Back"
+ , BT_MESH_UNIT_TEST_FUNCTION_BACK},
+ {"bt_mesh_scenario_network_create"
+ , BT_MESH_UNIT_TEST_SCENARIO_NETWORK_CREATE},
+ {"bt_mesh_scenario_unprovisioned_scan"
+ , BT_MESH_UNIT_TEST_SCENARIO_UNPROVISIONED_SCAN},
+ {"bt_mesh_scenario_provision_device"
+ , BT_MESH_UNIT_TEST_SCENARIO_PROVISION_DEVICE},
+ {"bt_mesh_scenario_node_reset"
+ , BT_MESH_UNIT_TEST_SCENARIO_NODE_RESET},
+ {"bt_mesh_scenario_node_configure_key"
+ , BT_MESH_UNIT_TEST_SCENARIO_NODE_CONFIGURE_KEY},
+ {"bt_mesh_scenario_model_generic_onoff_set_on"
+ , BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_ON},
+ {"bt_mesh_scenario_model_generic_onoff_set_off"
+ , BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_OFF},
+ {"bt_mesh_scenario_group_generic_onoff_set_on"
+ , BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_ON},
+ {"bt_mesh_scenario_group_generic_onoff_set_off"
+ , BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_OFF},
+ {"select this menu to set parameters and then select the function again"
+ , BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS},
+ {NULL , 0X0000},
+};
+
tc_table_t tc_main[] = {
{"bt_mesh_initialize"
, BT_MESH_UNIT_TEST_FUNCTION_INITIALIZE},
, BT_MESH_UNIT_TEST_TABLE_CONFIGURATION},
{"Control"
, BT_MESH_UNIT_TEST_TABLE_CONTROL},
+ {"Scenerio"
+ , BT_MESH_UNIT_TEST_TABLE_SCENARIO},
{"Finish"
, BT_MESH_UNIT_TEST_TABLE_FINISH},
{NULL , 0x0000},
case BT_MESH_UNIT_TEST_TABLE_CONTROL:
tc_table = tc_control;
break;
+ case BT_MESH_UNIT_TEST_TABLE_SCENARIO:
+ tc_table = tc_scenario;
+ break;
default:
tc_table = tc_main;
break;
void __bt_mesh_node_discover_status_cb(int result, bt_mesh_network_h network, bt_mesh_node_h node_param,
void *user_data)
{
- TC_PRT("bt_mesh_node_discover_status_cb");
- TC_PRT("result: %s", __bt_get_error_message(result));
+ TC_PRT("bt_mesh_node_discover_status_cb result: %s", __bt_get_error_message(result));
//print_network_handle(network);
print_node_handle(node_param);
- if (result == BT_ERROR_NONE)
+ if (result == BT_ERROR_NONE) {
g_node = node_param;
+ node_discovered = true;
+ }
+ wait_for_async_over();
+}
+
+static gint __compare_model_handle(gconstpointer data, gconstpointer user_data)
+{
+ if(NULL == data)
+ return -1;
+ if(NULL == user_data)
+ return -1;
+ if ((void*) data == (void*) user_data)
+ return 0;
+ else
+ return -1;
}
+
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)
{
- TC_PRT("__bt_mesh_elem_foreach_model_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
-
+ GSList *l;
if (result == BT_ERROR_NONE) {
TC_PRT("Total number of Models in the element [%d]", total);
print_element_handle(element);
print_model_handle(model);
TC_PRT("Model Comp ID [0x%2.2x] Model ID [0x%2.2x]",
model_id->company_id, model_id->model_id);
+ /* Update generic onoff server model list */
+ if (model_id->model_id == BT_MESH_MODEL_ID_GEN_ONOFF_SRV) {
+ g_model_onoff_srv = model;
+ l = g_slist_find_custom(srv_model_list, model, __compare_model_handle);
+ if(!l) {
+ srv_model_list = g_slist_append(srv_model_list, model);
+ }
+ }
+ g_model = model;
}
return true;
} else
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)
{
- TC_PRT("__bt_mesh_node_foreach_elem_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
if (result == BT_ERROR_NONE) {
print_element_handle(element);
TC_PRT("Element address [0x%2.2x]", element_addr);
TC_PRT("Element index [%d]", elem_index);
+ g_element = element;
}
return true;
} else
static void __bt_mesh_node_configure_netkey_cb(int result, bt_mesh_node_key_configuration_e op,
bt_mesh_node_h node, bt_mesh_netkey_h netkey, void *user_data)
{
- TC_PRT("__bt_mesh_node_configure_netkey_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
if (result == BT_ERROR_NONE) {
bt_mesh_node_h node, bt_mesh_netkey_h netkey,
bt_mesh_appkey_h appkey, void *user_data)
{
- TC_PRT("__bt_mesh_node_configure_netkey_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
-
if (result == BT_ERROR_NONE) {
- print_node_handle(node);
+ //print_node_handle(node);
if (op == BT_MESH_NODE_KEY_ADD)
TC_PRT("AppKey Added!");
else if (op == BT_MESH_NODE_KEY_UPDATE)
print_netkey_handle(netkey);
print_appkey_handle(appkey);
}
+ wait_for_async_over();
}
static void __bt_mesh_node_features_cb(int result, bt_mesh_node_h node,
bt_mesh_node_features_s *features, void *user_data)
{
- TC_PRT("__bt_mesh_node_features_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
if (result == BT_ERROR_NONE) {
bt_mesh_netkey_h netkey,
uint16_t netkey_index, void *user_data)
{
- TC_PRT("__bt_mesh_node_foreach_netkeys_cb");
- TC_PRT("result: %s", __bt_get_error_message(result));
-
if (result == BT_ERROR_NONE) {
TC_PRT("Total Netkeys in node [%d]", total);
- print_node_handle(node);
+ //print_node_handle(node);
print_netkey_handle(netkey);
+ g_netkey = netkey;
return true;
+ } else {
+ TC_PRT("__bt_mesh_node_foreach_netkeys_cb result: %s", __bt_get_error_message(result));
}
return false;
}
bt_mesh_netkey_h netkey, bt_mesh_appkey_h appkey,
uint16_t appkey_index, void *user_data)
{
- TC_PRT("__bt_mesh_node_foreach_appkeys_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
if (result == BT_ERROR_NONE) {
void __bt_mesh_node_ttl_cb(int result, bt_mesh_node_h node,
bt_mesh_node_ttl_operation_e ttl_op, uint8_t ttl, void *user_data)
{
- TC_PRT("bt_mesh_node_ttl_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
if (result == BT_ERROR_NONE) {
void __bt_mesh_model_bind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
void *user_data)
{
- TC_PRT("bt_mesh_model_bind_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
if (result == BT_ERROR_NONE) {
print_model_handle(model);
print_appkey_handle(appkey);
}
+ wait_for_async_over();
}
void __bt_mesh_model_msg_cb(int result, bt_mesh_element_h element, bt_mesh_appkey_h appkey,
bt_mesh_model_msg_params_s *msg, void *user_data)
{
- TC_PRT("bt_mesh_model_msg_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
if (result == BT_ERROR_NONE) {
TC_PRT("opcode: 0X%2.2X", msg->opcode);
void __bt_mesh_model_unbind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
void *user_data)
{
- TC_PRT("bt_mesh_model_unbind_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
if (result == BT_ERROR_NONE) {
print_model_handle(model);
void __bt_mesh_model_appkey_list_cb(int result, bt_mesh_model_h model, int total, const GSList *appkeylist,
void *user_data)
{
- TC_PRT("bt_mesh_model_appkey_list_cb");
const GSList *l;
-
TC_PRT("result: %s", __bt_get_error_message(result));
+
if (result == BT_ERROR_NONE) {
TC_PRT("Total number of AppKeys bound to the model [%d]", total);
print_model_handle(model);
void __bt_mesh_model_subscription_op_cb(int result, bt_mesh_model_subscription_op_e op,
bt_mesh_model_h model, bt_mesh_group_h group, void *user_data)
{
- TC_PRT("bt_mesh_model_subscription_op_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
-
if (result == BT_ERROR_NONE) {
switch(op) {
case 0:
void *user_data)
{
const GSList *l;
- TC_PRT("bt_mesh_model_subscription_list_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
if (result == BT_ERROR_NONE) {
TC_PRT("Total number of AppKeys bound to the model [%d]", total);
void __bt_mesh_model_publication_status_cb(int result, bt_mesh_model_h model, bt_mesh_group_h group,
bt_mesh_appkey_h appkey, void *user_data)
{
- TC_PRT("bt_mesh_model_publication_status_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
if (result == BT_ERROR_NONE) {
void __bt_mesh_network_create_cb(int result, bt_mesh_network_h network, const char *network_name, void *user_data)
{
- TC_PRT("bt_mesh_network_create_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
print_network_handle(network);
}
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)
{
- TC_PRT("bt_mesh_network_appkey_info_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
//print_network_handle(network);
//print_netkey_handle(netkey);
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)
{
- TC_PRT("bt_mesh_network_netkey_info_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
//print_network_handle(network);
- print_netkey_handle(netkey);
+ //print_netkey_handle(netkey);
TC_PRT("Total netkeys are [%d]",total);
if (result == BT_ERROR_NONE && netkey_index == 0) {
TC_PRT("Attempt to delete Primary Subnet");
return true;
}
+static gint __compare_dev_uuid(gconstpointer data, gconstpointer user_data)
+{
+ const char *uuid1 = data;
+ const char *uuid2 = user_data;
+
+ if(NULL == uuid1)
+ return -1;
+ if(NULL == uuid2)
+ return -1;
+
+ return g_strcmp0(uuid1, uuid2);
+}
+
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)
{
- TC_PRT("bt_mesh_network_scan_unprovisioned_device_result_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
if (state == BT_MESH_SCANNING_STARTED) {
TC_PRT("The scanning state is: STARTED");
print_network_handle(network);
}
else {
- TC_PRT("Scan Result found");
- TC_PRT("Device UUID is %s\n", scan_res->uuid);
- TC_PRT("RSSI values is %d\n", scan_res->rssi);
- TC_PRT("OOB Info 0x%x\n", scan_res->oob_info);
+ GSList *l;
+ char *duuid = g_strdup(scan_res->uuid);
+ l = g_slist_find_custom(unprov_dev_list, duuid, __compare_dev_uuid);
+ if(!l) {
+ unprov_dev_list = g_slist_append(unprov_dev_list, duuid);
+ TC_PRT("New unprov Dev UUID %s", duuid);
+ TC_PRT("RSSI values is %d", scan_res->rssi);
+ TC_PRT("OOB Info 0x%x", scan_res->oob_info);
+ } else {
+ g_free(duuid);
+ }
}
}
void __bt_mesh_network_device_provision_cb(int result, bt_mesh_network_h network,
const char* dev_uuid, void* user_data)
{
- TC_PRT("bt_mesh_network_device_provision_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
- print_network_handle(network);
if(dev_uuid == NULL)
- TC_PRT("dev_uuid is NULL");
+ TC_PRT("Provisioned dev_uuid is NULL");
else {
- TC_PRT("The device_uuid is [%s]", dev_uuid);
- device_uuid = g_strdup(dev_uuid);
+ GSList *l;
+ TC_PRT("Provisioned device_uuid [%s]", dev_uuid);
+ char *duuid = g_strdup(dev_uuid);
+ l = g_slist_find_custom(prov_dev_list, duuid, __compare_dev_uuid);
+ if(!l) {
+ prov_dev_list = g_slist_append(prov_dev_list, duuid);
+ }
}
+ wait_for_async_over();
}
void __bt_mesh_authentication_request_cb(int result, bt_mesh_authentication_type_e auth_type,
char *auth_value, void *user_data)
{
- TC_PRT("bt_mesh_authentication_request_cb");
TC_PRT("result: %s", __bt_get_error_message(result));
TC_PRT("auth_value is [%s]", auth_value);
TC_PRT("auth_type is [%d]", auth_type);
}
break;
}
+ case BT_MESH_UNIT_TEST_TABLE_SCENARIO: {
+ switch(test_id) {
+ case BT_MESH_UNIT_TEST_SCENARIO_PROVISION_DEVICE:
+ param_count = 1;
+ TC_PRT("Input param(%d) (device_uuid)\n",param_index+1);
+ break;
+ case BT_MESH_UNIT_TEST_SCENARIO_NODE_RESET:
+ param_count = 1;
+ TC_PRT("Input param(%d) (node handle)\n",param_index+1);
+ break;
+ case BT_MESH_UNIT_TEST_SCENARIO_NODE_CONFIGURE_KEY:
+ param_count = 1;
+ TC_PRT("Input param(%d) (node handle)\n",param_index+1);
+ break;
+ case BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_ON:
+ param_count = 1;
+ TC_PRT("Input param(%d) (model handle)\n",param_index+1);
+ break;
+ case BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_OFF:
+ param_count = 1;
+ TC_PRT("Input param(%d) (model handle)\n",param_index+1);
+ break;
+ case BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_ON:
+ param_count = 1;
+ TC_PRT("Input param(%d) (group handle)\n",param_index+1);
+ break;
+ case BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_OFF:
+ param_count = 1;
+ TC_PRT("Input param(%d) (group handle)\n",param_index+1);
+ break;
+ case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS:
+ need_to_set_params = true;
+ TC_PRT("\nSelect the function again\n");
+ break;
+ default:
+ TC_PRT("There is no parameter to set\n");
+ break;
+ }
+ break;
+ }
case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION: {
switch(test_id) {
case BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE:
break;
}
case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN: {
+ unprov_dev_list = NULL;
bt_mesh_scan_params_s scan_params;
memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s));
if(g_test_param.param_count != 1) {
__bt_free_test_param(&g_test_param);
break;
}
+ case BT_MESH_UNIT_TEST_TABLE_SCENARIO:{
+ switch (test_id) {
+ case BT_MESH_UNIT_TEST_SCENARIO_NETWORK_CREATE: {
+ bt_mesh_element_h element_sh;
+ bt_mesh_model_h model_sh1, model_sh2, model_sh3, model_sh4;
+ bt_mesh_model_id_s mod_id1, mod_id2, mod_id3, mod_id4;
+ bt_mesh_appkey_h appkey_h = 0;
+ bt_mesh_node_key_configuration_e config;
+ char* network_name = "[Scenerio] Mesh Test Network";
+ bt_mesh_node_features_s features;
+ features.features = BT_MESH_FEATURE_RELAY;
+ features.features |= BT_MESH_FEATURE_LOWPOWER;
+ uint16_t group_addr = 0xc001;
+ bt_mesh_group_h group_h;
+
+ /* create node */
+ ret = bt_mesh_node_create(&features, &local_node);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("bt_mesh_node_create return %s\n", __bt_get_error_message(ret));
+
+ /* create element */
+ ret = bt_mesh_node_create_element(local_node, &element_sh);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("bt_mesh_node_create_element return %s\n", __bt_get_error_message(ret));
+
+ /* create models */
+ /* Add configuration client and server */
+ memset(&mod_id1, 0x00, sizeof(bt_mesh_model_id_s));
+ mod_id1.model_id = BT_MESH_MODEL_ID_CFG_SRV;
+ mod_id1.company_id = 0xFFFF;
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("The model_id is [0x%2.2X]\n", mod_id1.model_id);
+ ret = bt_mesh_element_create_model(element_sh, &mod_id1, &model_sh1);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("bt_mesh_element_create_model return %s\n", __bt_get_error_message(ret));
+
+ memset(&mod_id2, 0x00, sizeof(bt_mesh_model_id_s));
+ mod_id2.model_id = BT_MESH_MODEL_ID_CFG_CLIENT;
+ mod_id2.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(element_sh, &mod_id2, &model_sh2);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("bt_mesh_element_create_model return %s\n", __bt_get_error_message(ret));
+
+ /* Add Generic on-off client and server */
+ memset(&mod_id3, 0x00, sizeof(bt_mesh_model_id_s));
+ mod_id3.model_id = BT_MESH_MODEL_ID_GEN_ONOFF_SRV;
+ mod_id3.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(element_sh, &mod_id3, &model_sh3);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("bt_mesh_element_create_model return %s\n", __bt_get_error_message(ret));
+
+ memset(&mod_id4, 0x00, sizeof(bt_mesh_model_id_s));
+ mod_id4.model_id = BT_MESH_MODEL_ID_GEN_ONOFF_CLIENT;
+ mod_id4.company_id = 0xFFFF;
+ ret = bt_mesh_element_create_model(element_sh, &mod_id4, &model_sh4);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("bt_mesh_element_create_model return %s\n", __bt_get_error_message(ret));
+
+ /* create network */
+ ret = bt_mesh_network_create(local_node, (const char*)network_name, &network, &token);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("bt_mesh_network_create return %s", __bt_get_error_message(ret));
+ if (ret != BT_ERROR_NONE) break;
+
+ /* Create Group */
+ ret = bt_mesh_network_create_group(network, group_addr, &group_h);
+ if (ret != BT_ERROR_NONE) {
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ } else {
+ print_group_handle(group_h);
+ g_group = group_h;
+ }
+
+ /* Get net keys */
+ ret = bt_mesh_node_foreach_netkeys(local_node, __bt_mesh_node_foreach_netkeys_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+
+ /* Add Appkey in netkey */
+ ret = bt_mesh_netkey_add_appkey(g_netkey, &appkey_h);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ g_appkey = appkey_h;
+
+ /* Add appkey in local node */
+ config = BT_MESH_NODE_KEY_ADD;
+ ret = bt_mesh_node_configure_appkey(local_node, config, appkey_h,
+ __bt_mesh_node_configure_appkey_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ wait_for_async();
+
+ /* Bind local models */
+ ret = bt_mesh_model_bind_appkey(model_sh1, appkey_h, __bt_mesh_model_bind_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ wait_for_async();
+ ret = bt_mesh_model_bind_appkey(model_sh2, appkey_h, __bt_mesh_model_bind_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ wait_for_async();
+ ret = bt_mesh_model_bind_appkey(model_sh3, appkey_h, __bt_mesh_model_bind_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ wait_for_async();
+ ret = bt_mesh_model_bind_appkey(model_sh4, appkey_h, __bt_mesh_model_bind_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+
+ break;
+ }
+ case BT_MESH_UNIT_TEST_SCENARIO_UNPROVISIONED_SCAN: {
+ unprov_dev_list = NULL;
+ bt_mesh_scan_params_s scan_params;
+ memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s));
+ scan_params.seconds = 20;
+
+ /* Stop any ongoing scan */
+ ret = bt_mesh_stop_unprovisioned_device_scan(network);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+
+ /* Start scan */
+ TC_PRT("The scan is set for [%u] seconds", scan_params.seconds);
+ ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params,
+ __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ break;
+ }
+ case BT_MESH_UNIT_TEST_SCENARIO_PROVISION_DEVICE: {
+ const char *dev_uuid = "c2a6ff31ed00427d27a53698cca89029";
+ if(g_test_param.param_count > 0) {
+ dev_uuid = g_test_param.params[0];
+ }
+ g_device_uuid = g_strdup(dev_uuid);
+ TC_PRT("The dev_uuid is [%s]\n",g_device_uuid);
+
+ /* Stop any ongoing scan */
+ ret = bt_mesh_stop_unprovisioned_device_scan(network);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+
+ /* Provision device */
+ ret = bt_mesh_network_provision_device(network, g_device_uuid,
+ __bt_mesh_network_device_provision_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ wait_for_async();
+
+ /* Try to discover provisioned device */
+ node_discovered = false;
+ int try = 0;
+ int max_try = 10;
+ if (ret == BT_ERROR_NONE) {
+ while (!node_discovered && try < max_try) {
+ try++;
+ ret = bt_mesh_network_discover_node(network, (const char*)g_device_uuid,
+ __bt_mesh_node_discover_status_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ wait_for_async();
+ }
+ }
+ break;
+ }
+ case BT_MESH_UNIT_TEST_SCENARIO_NODE_RESET: {
+ bt_mesh_node_h node_h = g_node;
+ if (g_test_param.param_count > 0) {
+ node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
+ }
+
+ ret = bt_mesh_node_reset(node_h);
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ break;
+ }
+ case BT_MESH_UNIT_TEST_SCENARIO_NODE_CONFIGURE_KEY: {
+ bt_mesh_node_h node_h = g_node;
+ bt_mesh_appkey_h appkey_h = g_appkey;
+ bt_mesh_element_h element_h = g_element;
+ bt_mesh_model_h model_h = g_model;
+ bt_mesh_group_h group_h = g_group;
+ bt_mesh_node_key_configuration_e config = BT_MESH_NODE_KEY_ADD;
+ bt_mesh_model_subscription_op_e op = BT_MESH_MODEL_SUBSCRIPTION_ADD;
+
+ if (g_test_param.param_count > 0) {
+ node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
+ }
+
+ /* Get remote node */
+ ret = bt_mesh_node_foreach_element(node_h, __bt_mesh_node_foreach_elem_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ element_h = g_element;
+ ret = bt_mesh_element_foreach_models(element_h, __bt_mesh_elem_foreach_model_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+
+ /* Add appkey in remote node*/
+ ret = bt_mesh_node_configure_appkey(node_h, config, appkey_h,
+ __bt_mesh_node_configure_appkey_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ wait_for_async();
+
+ /* Bind appkey in on-off server*/
+ model_h = g_model_onoff_srv;
+ ret = bt_mesh_model_bind_appkey(model_h, appkey_h, __bt_mesh_model_bind_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ wait_for_async();
+
+ group_h = g_group;
+ ret = bt_mesh_model_configure_group_subscription(op, model_h, group_h,
+ __bt_mesh_model_subscription_op_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+
+ break;
+ }
+ case BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_ON: {
+ bt_mesh_model_h model_h = g_model_onoff_srv;
+ bt_mesh_appkey_h appkey_h = g_appkey;
+ bt_mesh_model_msg_params_s msg_params;
+
+ if (g_test_param.param_count > 0) {
+ model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
+ }
+
+ const char *msg_s = "0101";
+ msg_params.opcode = 0x8202;
+ msg_params.data = g_strdup(msg_s);
+ ret = bt_mesh_model_send_msg(model_h, appkey_h, &msg_params,
+ __bt_mesh_model_msg_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ break;
+ }
+ case BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_OFF: {
+ bt_mesh_model_h model_h = g_model_onoff_srv;
+ bt_mesh_appkey_h appkey_h = g_appkey;
+ bt_mesh_model_msg_params_s msg_params;
+
+ if (g_test_param.param_count > 0) {
+ model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
+ }
+
+ const char *msg_s = "0001";
+ msg_params.opcode = 0x8202;
+ msg_params.data = g_strdup(msg_s);
+ ret = bt_mesh_model_send_msg(model_h, appkey_h, &msg_params,
+ __bt_mesh_model_msg_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ break;
+ }
+ case BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_ON: {
+ bt_mesh_model_h group_h = g_group;
+ bt_mesh_appkey_h appkey_h = g_appkey;
+ bt_mesh_model_msg_params_s msg_params;
+
+ if (g_test_param.param_count > 0) {
+ group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
+ }
+
+ const char *msg_s = "0101";
+ msg_params.opcode = 0x8202;
+ msg_params.data = g_strdup(msg_s);
+ ret = bt_mesh_group_send_msg(group_h, appkey_h, &msg_params,
+ __bt_mesh_model_msg_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ break;
+ }
+ case BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_OFF: {
+ bt_mesh_model_h group_h = g_group;
+ bt_mesh_appkey_h appkey_h = g_appkey;
+ bt_mesh_model_msg_params_s msg_params;
+
+ if (g_test_param.param_count > 0) {
+ group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
+ }
+
+ const char *msg_s = "0001";
+ msg_params.opcode = 0x8202;
+ msg_params.data = g_strdup(msg_s);
+ ret = bt_mesh_group_send_msg(group_h, appkey_h, &msg_params,
+ __bt_mesh_model_msg_cb, NULL);
+ if (ret != BT_ERROR_NONE)
+ TC_PRT("return %s\n", __bt_get_error_message(ret));
+ break;
+ }
+ case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
+ need_to_set_params = true;
+ TC_PRT("Select the function again");
+ break;
+ }
+ default:
+ break;
+ }
+ __bt_free_test_param(&g_test_param);
+ break;
+ }
default:
break;
}
if (test_id == 0)
current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
else if(test_id >= BT_MESH_UNIT_TEST_TABLE_NETWORK
- && test_id <= BT_MESH_UNIT_TEST_TABLE_CONTROL) {
+ && test_id <= BT_MESH_UNIT_TEST_TABLE_SCENARIO) {
current_tc_table = test_id;
} else if (test_id > BT_MESH_UNIT_TEST_TABLE_CONTROL
&& test_id < BT_MESH_UNIT_TEST_TABLE_FINISH) {