if (strlen(str) != 32)
continue;
BT_INFO("Mesh: Got one node with UUID [%s]", str);
+ BT_INFO("Mesh: Match with uuid [%s]", buf);
+
if (!g_strcmp0(buf, str))
return jentry;
}
json_object *jval;
const char *str;
- if (!json_object_object_get_ex(jobj, "token", &jval))
+ if (!json_object_object_get_ex(jobj, "Network_Token", &jval))
return false;
str = json_object_get_string(jval);
json_object *jval;
const char *str;
- if (!json_object_object_get_ex(jobj, "uuid", &jval))
+ if (!json_object_object_get_ex(jobj, "Config_Node_UUID", &jval))
return false;
str = json_object_get_string(jval);
return __mesh_delete_key(cfg, cfg->jcfg, "appKeys", app_idx);
}
+bool _bt_mesh_conf_set_model_info(_bt_mesh_cdb_t *cfg,
+ uint16_t unicast, GSList *models)
+{
+ int sz;
+ json_object *jnode, *jobj, *jelements;
+ GSList *l;
+
+ BT_INFO("Mesh: Set All model informations in the node [0x%2.2x]",
+ unicast);
+
+ if (!cfg || !cfg->jcfg)
+ return false;
+
+ jnode = __mesh_get_node_by_unicast(cfg, unicast);
+ if (!jnode)
+ return false;
+
+ jelements = json_object_object_get(jnode, "elements");
+ if (!jelements)
+ return false;
+
+ sz = json_object_array_length(jelements);
+ BT_INFO("Mesh: Total elements [%d]", sz);
+ BT_INFO("Mesh: Total Models in List [%d]",
+ g_slist_length(models));
+
+ for (l = models; l != NULL; l = g_slist_next(l)) {
+ json_object *jentry, *jmods;
+ bluetooth_mesh_model_t *mod = l->data;
+
+ BT_INFO("Mesh: Elem Idx [%u]", mod->elem_index);
+ BT_INFO("Mesh: Model ID [0x%4.4x]", mod->model_id);
+
+ jentry = json_object_array_get_idx(jelements, mod->elem_index);
+ if (!jentry)
+ return false;
+
+ /* Write Index for the eleement */
+ if (!__mesh_write_int(jentry, "index", (int)mod->elem_index))
+ return false;
+
+ /* Set Hardcoded location */
+ if (!__mesh_write_uint16_hex(jentry, "location", 0x0000))
+ return false;
+
+ jmods = json_object_object_get(jentry, "models");
+ if (!jmods) {
+ /* For backwards compatibility */
+ jmods = json_object_new_array();
+ json_object_object_add(jentry, "models", jmods);
+ }
+
+ /* TODO: Vendor Model Entry: Only BT SIG model entry is handled now */
+ jobj = __mesh_init_model((uint16_t)mod->model_id);
+ if (!jobj)
+ return false;
+
+ json_object_array_add(jmods, jobj);
+ }
+
+ /* Save */
+ return __bt_mesh_save_configruation_file(cfg);
+}
+
+bool _bt_mesh_conf_set_vendor_info(_bt_mesh_cdb_t *cfg,
+ uint16_t unicast, uint16_t crpl, uint16_t cid,
+ uint16_t vid, uint16_t pid,
+ int proxy, int relay,
+ int lpn, int frnd)
+{
+ json_object *jnode, *jobj;
+
+ BT_INFO("Mesh: Set Vednor Information in CDB for node [0x%2.2x]",
+ unicast);
+
+ if (!cfg || !cfg->jcfg)
+ return false;
+
+ jnode = __mesh_get_node_by_unicast(cfg, unicast);
+ if (!jnode) {
+ BT_INFO("Mesh: Node not found");
+ return false;
+ }
+
+ /* Company ID */
+ if (!__mesh_write_uint16_hex(jnode, "crpl", crpl)) {
+ BT_ERR("Mesh: Could not write CRPL");
+ return false;
+ }
+
+ /* Company ID */
+ if (!__mesh_write_uint16_hex(jnode, "cid", cid)) {
+ BT_ERR("Mesh: Could not write CID");
+ return false;
+ }
+
+ /* Vendor ID or Product ID */
+ if (!__mesh_write_uint16_hex(jnode, "pid", pid)) {
+ BT_INFO("Mesh: Could not write PID");
+ return false;
+ }
+
+ /* Version ID */
+ if (!__mesh_write_uint16_hex(jnode, "vid", vid)) {
+ BT_INFO("Mesh: Could not write VID");
+ return false;
+ }
+
+ jobj = json_object_object_get(jnode, "features");
+ if (!jobj) {
+ jobj = json_object_new_object();
+ json_object_object_add(jnode, "features", jobj);
+ }
+
+ BT_INFO("Mesh: Set features in CDB");
+
+ __mesh_write_int(jobj, "relay", relay ? 1 : 0);
+ __mesh_write_int(jobj, "friend", frnd ? 1 : 0);
+ __mesh_write_int(jobj, "proxy", proxy ? 1 : 0);
+ __mesh_write_int(jobj, "lowPower", lpn ? 1 : 0);
+
+ BT_INFO("Mesh: All vendor Info data set successfully");
+
+ return __bt_mesh_save_configruation_file(cfg);
+}
+
bool _bt_mesh_conf_set_unicast_address_range(_bt_mesh_cdb_t *cfg,
uint16_t low, uint16_t high)
{
json_object *jelement = NULL;
json_object *jmodelarray = NULL;
const char *str;
- uint16_t **models;
+ uint16_t **models = NULL;
if (!cfg)
return NULL;
return NULL;
jnode = __mesh_get_node_by_uuid(jcfg, cfg->uuid);
- if (!jnode)
+ if (!jnode) {
+ BT_ERR("Mesh: Node not found with UUID");
return NULL;
+ }
/* Get element array object */
json_object_object_get_ex(jnode, "elements", &jarray);
- if (!jarray || json_object_get_type(jarray) != json_type_array)
+ if (!jarray || json_object_get_type(jarray) != json_type_array) {
+ BT_ERR("Mesh:could not get element array");
return NULL;
+ }
/* Get specific element by index */
jelement = __mesh_get_key_object(jarray, element_index);
- if (!jelement)
+ if (!jelement) {
+ BT_ERR("Mesh: Could not find element");
return NULL;
-
+ }
/* Get Model array object inside the selected element */
json_object_object_get_ex(jelement, "models", &jmodelarray);
- if (!jmodelarray || json_object_get_type(jmodelarray) != json_type_array)
+ if (!jmodelarray || json_object_get_type(jmodelarray) != json_type_array) {
+ BT_ERR("Mesh: Could not get Model Array");
return NULL;
+ }
sz = json_object_array_length(jmodelarray);
+ BT_INFO("Mesh: Total number of Models in Element index [%d] is [%d]",
+ element_index, sz);
+
models = (uint16_t**) g_malloc0(sz * sizeof(uint16_t*));
for (i = 0; i < sz; ++i) {
- json_object *jentry;
+ json_object *jentry, *jval;
+ uint16_t mod_id;
+ BT_INFO("Mesh: Model [%d]", i);
jentry = json_object_array_get_idx(jmodelarray, i);
- str = json_object_get_string(jentry);
+
+ if (!json_object_object_get_ex(jentry, "modelId", &jval)) {
+ BT_ERR("Mesh: Failed to read Model in index [%d]", i);
+ for (int j = 0 ; j < sz; j++)
+ g_free(models[j]);
+ g_free(models);
+ return NULL;
+ }
+
+ str = json_object_get_string(jval);
+ BT_INFO("Mesh: Model ID String [%s]", str);
/* Only standard models are handled now */
- if (sscanf(str, "%04hx", models[i]) != 1) {
+ if (sscanf(str, "%04hx", &mod_id) != 1) {
+ BT_INFO("Mesh: Failed to read Model ID from Model entry [%s]", str);
for (int j = 0 ; j < sz; j++)
g_free(models[j]);
g_free(models);
return NULL;
}
+
+ BT_INFO("Mesh: Model string [%s] Model ID [0x%4.4x]", str, mod_id);
+ models[i] = g_malloc0(sizeof(uint16_t));
+ *models[i] = mod_id;
}
/* TODO: Need to handle vendor models */
+ BT_INFO("Mesh: Got all model info");
*num_models = sz;
return models;
}
return false;
jnode = __mesh_get_node_by_uuid(jcfg, cfg->uuid);
- if (!jnode)
+ if (!jnode) {
+ BT_ERR("Mesh: Node by UUID not found");
return false;
+ }
json_object_object_get_ex(jnode, "elements", &jarray);
- if (!jarray || json_object_get_type(jarray) != json_type_array)
+ if (!jarray || json_object_get_type(jarray) != json_type_array) {
+ BT_ERR("Mesh: Element array not found in Node");
return false;
+ }
sz = json_object_array_length(jarray);
- if (sz == 0)
+ if (sz == 0 ){
+ BT_ERR("Mesh: Element array length is 0");
return false;
+ }
*num_elems = sz;
return true;
return false;
jnode = __mesh_get_node_by_unicast(cfg, unicast);
- if (!jnode)
+ if (!jnode) {
+ BT_ERR("Mesh: Node not found by unicast [0x%2.2x]", unicast);
return false;
+ }
/* Get CRPL */
- if (!json_object_object_get_ex(jnode, "crpl", &jobj))
+ if (!json_object_object_get_ex(jnode, "crpl", &jobj)) {
+ BT_ERR("Mesh: CRPL info not found");
return false;
+ }
str = json_object_get_string(jobj);
if (!str)
_bt_mesh_cdb_t* _bt_mesh_conf_load(const char *file_name,
const char *token)
{
- char *token_str = NULL;
+ char token_str[17];
int fd;
char *str;
struct stat st;
_bt_mesh_cdb_t *cfg;
fd = open(file_name, O_RDONLY);
- if (fd < 0)
+ if (fd < 0) {
+ BT_ERR("Mesh: Could not open file [%s]",
+ file_name);
return NULL;
+ }
if (fstat(fd, &st) == -1) {
close(fd);
+ BT_ERR("Mesh: Could not stat file [%s]",
+ file_name);
return NULL;
}
str = (char *) g_malloc0(st.st_size + 1);
if (!str) {
close(fd);
+ BT_ERR("Mesh: Could not stat file [%s]",
+ file_name);
return NULL;
}
goto fail;
}
- token_str = _bt_service_convert_hex_to_string((unsigned char*)cfg->token, 8);
+ _bt_mesh_util_convert_hex_to_string(cfg->token, 8, token_str, 17);
/* Match CDB file tken with user's token */
if (g_strcmp0(token_str, token)) {
BT_INFO("Mesh: Token did not match! File token [%s] requested token [%s]",
- cfg->token, token);
+ token_str, token);
goto fail;
}
+
+ BT_INFO("Mesh: Token found");
/* TODO: Load keys and remotes */
return cfg;
fail:
MESH_PRIMARY_NET_IDX);
BT_INFO("Mesh: Added Local node's basic info in CDB");
+ _bt_mesh_conf_set_vendor_info(cdb_cfg, 0x0001, tmp->vendor_info.crpl,
+ tmp->vendor_info.companyid, tmp->vendor_info.versionid,
+ tmp->vendor_info.vendorid, tmp->vendor_info.proxy,
+ tmp->vendor_info.relay, tmp->vendor_info.lpn,
+ tmp->vendor_info.frnd);
+
+ BT_INFO("Mesh: Vendor Info set successfully");
+ _bt_mesh_conf_set_model_info(cdb_cfg, 0x0001, tmp->model_list);
+
cdb_list = g_slist_append(cdb_list, cdb_cfg);
BT_INFO("Mesh: CDB added to list");
char **network)
{
GSList *l;
- char *token_str;
+ char token_str[17];
_bt_mesh_cdb_t *cdb_cfg = NULL;
- token_str = _bt_service_convert_hex_to_string(token, 8);
+ _bt_mesh_util_convert_hex_to_string(token, 8,
+ token_str, 17);
/* Find CDB */
l = g_slist_find_custom(cdb_list, token_str,
if (!l)
return BLUETOOTH_ERROR_INTERNAL;
- g_free(token_str);
cdb_cfg = (_bt_mesh_cdb_t*)l->data;
if (result != BLUETOOTH_ERROR_NONE)
int ret = OAL_STATUS_SUCCESS;
GSList *l;
char *dir_path = NULL;
+ char *file_path = NULL;
_bt_mesh_cdb_t *cdb_cfg = NULL;
oal_mesh_node_t node;
GSList *models = NULL;
g_free(dir_path);
return BLUETOOTH_ERROR_INTERNAL;
}
- g_free(dir_path);
while ((filename = g_dir_read_name(dir)) != NULL) {
if ((g_file_test(filename, G_FILE_TEST_IS_SYMLINK) == TRUE) ||
(g_str_has_suffix(filename, ".json") == FALSE))
continue;
+ file_path = g_strdup_printf("%s%s",
+ dir_path, filename);
+ BT_INFO("Mesh: Token [%s]", token);
BT_INFO("Mesh: File name [%s]", filename);
- cdb_cfg = _bt_mesh_conf_load(filename, token);
+ BT_INFO("Mesh: File Absolute Path [%s]", file_path);
+
+ cdb_cfg = _bt_mesh_conf_load(file_path, token);
if (cdb_cfg)
break;
}
}
+ g_free(file_path);
+ g_free(dir_path);
+
if (!cdb_cfg) {
BT_ERR("Mesh: Could not find CDB for the token!! Possibly not authorized!!");
return BLUETOOTH_ERROR_ACCESS_DENIED;
_bt_mesh_conf_free(cdb_cfg);
return BLUETOOTH_ERROR_INTERNAL;
}
+ BT_INFO("Mesh: toatl number of elements [%d]", node.num_elements);
+ BT_INFO("Mesh:Fetch Vendor specific info");
if (!_bt_mesh_conf_fetch_vendor_specific_info(cdb_cfg, 0x0001 /* Local Node Unicast */,
&node.vendor_info.companyid, &node.vendor_info.vendorid,
&node.vendor_info.versionid, &node.vendor_info.crpl,
return BLUETOOTH_ERROR_INTERNAL;
}
+ BT_INFO("Mesh: Fill Model informations");
for (int i = 0; i < node.num_elements; i++) {
int num_models;
uint16_t **model_array = _bt_mesh_conf_get_all_model_info(
/* Free all model(s) */
for (int j = 0; j < num_models; j++)
g_free(model_array[j]);
+ g_free(model_array);
}
+ BT_INFO("Mesh: Node formation done:: Register it!");
/* Register Mesh Node */
ret = mesh_register_node((oal_mesh_node_t*)&node,
models, true);
/* Cleanup */
- g_slist_free_full(models, g_free);
+ //g_slist_free_full(models, g_free);
if (ret != OAL_STATUS_SUCCESS) {
BT_ERR("Mesh: Load Network Failed ret: %d", ret);
/* Save till Network attached */
cdb_list = g_slist_append(cdb_list, cdb_cfg);
- return ret;
+ return BLUETOOTH_ERROR_NONE;
}
bool _bt_mesh_network_get_label_uuid_from_sub_addr(