Fix the svace issue (DEREF_OF_NULL)
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / services / include / bt-service-mesh-cdb.h
1 /*
2  * Bluetooth-frwk
3  *
4  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
5  *
6  * @author: Anupam Roy <anupam.r@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *              http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef BT_SERVICE_MESH_CDB_H_
23 #define BT_SERVICE_MESH_CDB_H_
24
25 #include <glib.h>
26 #include <sys/types.h>
27 #include "bluetooth-api.h"
28 #include "bluetooth-mesh-api.h"
29 #include <json-c/json.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 typedef struct {
36         char *cfg_fname;
37         char *app_cred;
38         json_object *jcfg;
39         uint8_t token[8];
40         uint8_t uuid[16]; /* Network UUID */
41         struct timeval write_time;
42         GSList *groups;
43 } _bt_mesh_cdb_t;
44
45 /* Virtual Group */
46 typedef struct {
47         uint8_t label_uuid[16];
48         uint16_t grp_addr;
49 } _bt_mesh_group_t;
50
51
52 void _bt_mesh_conf_free(_bt_mesh_cdb_t *cfg);
53
54 bool _bt_mesh_conf_parse_data(void *cfg, int k);
55
56 _bt_mesh_cdb_t * _bt_mesh_conf_database_create(const char *file_name,
57         const uint8_t uuid[16], const uint8_t token[8],
58                 const char *network_name,
59                         const char *app_cred);
60
61 bool _bt_mesh_conf_set_phase_network_key(_bt_mesh_cdb_t *cfg,
62         uint16_t net_idx, uint8_t phase);
63
64 _bt_mesh_cdb_t* _bt_mesh_conf_load(const char *file_name,
65                 const char *token);
66
67 bool _bt_mesh_conf_delete_application_key(_bt_mesh_cdb_t *cfg,
68                 uint16_t app_idx);
69
70 bool _bt_mesh_conf_load_all_nodes(_bt_mesh_cdb_t *cfg);
71
72 bool _bt_mesh_conf_insert_network_key(_bt_mesh_cdb_t *cfg,
73                 uint16_t idx, uint8_t key_refresh);
74
75 bool _bt_mesh_conf_delete_network_key(_bt_mesh_cdb_t *cfg,
76                 uint16_t net_idx);
77
78 bool _bt_mesh_conf_set_unicast_address_range(_bt_mesh_cdb_t *cfg,
79                 uint16_t low, uint16_t high);
80
81 bool _bt_mesh_conf_insert_node_object(_bt_mesh_cdb_t *cfg,
82                 uint8_t uuid[16], uint8_t num_els,
83                         uint16_t unicast, uint16_t net_idx);
84
85 bool _bt_mesh_conf_get_element_count(_bt_mesh_cdb_t *cfg,
86                 uint16_t *num_elems);
87
88 bool _bt_mesh_conf_load_all_keys(_bt_mesh_cdb_t* cfg);
89
90 bool _bt_mesh_conf_fetch_vendor_specific_info(
91                 _bt_mesh_cdb_t *cfg, uint16_t unicast,
92                         uint16_t *cid, uint16_t *vid, uint16_t *version,
93                                 uint16_t *crpl, int *relay, int *frnd,
94                                         int *proxy, int *lpn);
95
96 uint16_t** _bt_mesh_conf_get_all_model_info(_bt_mesh_cdb_t *cfg,
97                 int element_index, int *num_models);
98
99 bool _bt_mesh_conf_get_token_info(uint8_t token[8]);
100
101 bool _bt_mesh_conf_insert_application_key(_bt_mesh_cdb_t *cfg,
102                 uint16_t net_idx, uint16_t app_idx);
103
104 bool _bt_mesh_conf_get_unicast_address_range(uint16_t *low,
105         uint16_t *high);
106
107 bool _bt_mesh_conf_node_set_network_transmission(uint16_t unicast,
108                 uint8_t cnt, uint16_t interval);
109
110 bool _bt_mesh_conf_delete_node(_bt_mesh_cdb_t *cfg,
111                 uint16_t unicast);
112
113 bool _bt_mesh_conf_set_node_comp_data(_bt_mesh_cdb_t *cfg,
114                 uint16_t unicast, uint8_t *data, uint16_t len);
115
116 bool _bt_mesh_conf_node_insert_network_key(_bt_mesh_cdb_t *cfg,
117                 uint16_t unicast, uint16_t idx);
118
119 bool _bt_mesh_conf_node_delete_network_key(_bt_mesh_cdb_t *cfg,
120                 uint16_t unicast, uint16_t idx);
121
122 bool _bt_mesh_conf_node_insert_application_key(_bt_mesh_cdb_t *cfg,
123                 uint16_t unicast, uint16_t idx);
124
125 bool _bt_mesh_conf_node_delete_application_key(_bt_mesh_cdb_t *cfg,
126                 uint16_t unicast, uint16_t idx);
127
128 bool _bt_mesh_conf_node_set_timetolive_value(_bt_mesh_cdb_t *cfg,
129                 uint16_t unicast, uint8_t ttl);
130
131 bool _bt_mesh_conf_node_set_write_op_mode(uint16_t unicast,
132                 const char *keyword, int value);
133
134 bool _bt_mesh_conf_bind_model(uint16_t unicast,
135                 uint8_t ele, bool vendor,
136                         uint32_t mod_id, uint16_t app_idx);
137
138 bool _bt_mesh_conf_unbind_model(uint16_t unicast,
139                 uint8_t ele, bool vendor,
140                         uint32_t mod_id, uint16_t app_idx);
141
142 GSList *_bt_mesh_conf_load_group_info(_bt_mesh_cdb_t *cfg);
143
144 bool _bt_mesh_conf_insert_group_info(_bt_mesh_cdb_t *cfg,
145                 _bt_mesh_group_t *grp);
146
147 bool _bt_mesh_conf_delete_group_entry(_bt_mesh_cdb_t *cfg,
148                 uint16_t addr);
149
150 bool _bt_mesh_conf_set_network_friendly_name(_bt_mesh_cdb_t *cfg,
151                 const char *network_name);
152
153 const char * _bt_mesh_conf_get_network_friendly_name(_bt_mesh_cdb_t *cfg);
154
155 #ifdef __cplusplus
156 }
157 #endif /* __cplusplus */
158 #endif /* BT_SERVICE_MESH_CDB_H_ */