Mesh: Remove duplicate code
[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 *owner;
38         char *app_cred;
39         json_object *jcfg;
40         uint8_t token[8];
41         uint8_t uuid[16]; /* Network UUID */
42         struct timeval write_time;
43         GSList *groups;
44 } _bt_mesh_cdb_t;
45
46 /* Virtual Group */
47 typedef struct {
48         uint8_t label_uuid[16];
49         uint16_t grp_addr;
50 } _bt_mesh_group_t;
51
52
53 void _bt_mesh_conf_free(_bt_mesh_cdb_t *cfg);
54
55 bool _bt_mesh_conf_parse_data(void *cfg, int k);
56
57 bool _bt_mesh_conf_set_vendor_info(_bt_mesh_cdb_t *cfg, uint16_t unicast,
58                 uint16_t crpl, uint16_t cid, uint16_t vid, uint16_t pid,
59                                 int proxy, int relay, int lpn, int frnd);
60
61 bool _bt_mesh_conf_set_model_info(_bt_mesh_cdb_t *cfg,
62                 uint16_t unicast, GSList *models);
63
64 _bt_mesh_cdb_t * _bt_mesh_conf_database_create(const char *file_name,
65         const uint8_t uuid[16], const uint8_t token[8],
66                 const char *network_name,
67                         const char *sender, const char *app_cred);
68
69 bool _bt_mesh_conf_set_phase_network_key(_bt_mesh_cdb_t *cfg,
70         uint16_t net_idx, uint8_t phase);
71
72 _bt_mesh_cdb_t* _bt_mesh_conf_load(const char *file_name,
73                 const char *token);
74
75 bool _bt_mesh_conf_delete_application_key(_bt_mesh_cdb_t *cfg,
76                 uint16_t app_idx);
77
78 bool _bt_mesh_conf_load_all_nodes(_bt_mesh_cdb_t *cfg);
79
80 bool _bt_mesh_conf_insert_network_key(_bt_mesh_cdb_t *cfg,
81                 uint16_t idx, uint8_t key_refresh);
82
83 bool _bt_mesh_conf_delete_network_key(_bt_mesh_cdb_t *cfg,
84                 uint16_t net_idx);
85
86 bool _bt_mesh_conf_set_unicast_address_range(_bt_mesh_cdb_t *cfg,
87                 uint16_t low, uint16_t high);
88
89 bool _bt_mesh_conf_insert_node_object(_bt_mesh_cdb_t *cfg,
90                 uint8_t uuid[16], uint8_t num_els,
91                         uint16_t unicast, uint16_t net_idx);
92
93 bool _bt_mesh_conf_get_element_count(_bt_mesh_cdb_t *cfg,
94                 uint16_t *num_elems);
95
96 bool _bt_mesh_conf_load_all_keys(_bt_mesh_cdb_t* cfg);
97
98 bool _bt_mesh_conf_fetch_vendor_specific_info(
99                 _bt_mesh_cdb_t *cfg, uint16_t unicast,
100                         uint16_t *cid, uint16_t *vid, uint16_t *version,
101                                 uint16_t *crpl, int *relay, int *frnd,
102                                         int *proxy, int *lpn);
103
104 uint16_t** _bt_mesh_conf_get_all_model_info(_bt_mesh_cdb_t *cfg,
105                 int element_index, int *num_models);
106
107 bool _bt_mesh_conf_get_token_info(uint8_t token[8]);
108
109 bool _bt_mesh_conf_insert_application_key(_bt_mesh_cdb_t *cfg,
110                 uint16_t net_idx, uint16_t app_idx);
111
112 bool _bt_mesh_conf_get_unicast_address_range(uint16_t *low,
113         uint16_t *high);
114
115 bool _bt_mesh_conf_node_set_network_transmission(uint16_t unicast,
116                 uint8_t cnt, uint16_t interval);
117
118 bool _bt_mesh_conf_delete_node(_bt_mesh_cdb_t *cfg,
119                 uint16_t unicast);
120
121 bool _bt_mesh_conf_set_node_comp_data(_bt_mesh_cdb_t *cfg,
122                 uint16_t unicast, uint8_t *data, uint16_t len);
123
124 bool _bt_mesh_conf_node_insert_network_key(_bt_mesh_cdb_t *cfg,
125                 uint16_t unicast, uint16_t idx);
126
127 bool _bt_mesh_conf_node_delete_network_key(_bt_mesh_cdb_t *cfg,
128                 uint16_t unicast, uint16_t idx);
129
130 bool _bt_mesh_conf_node_insert_application_key(_bt_mesh_cdb_t *cfg,
131                 uint16_t unicast, uint16_t idx);
132
133 bool _bt_mesh_conf_node_delete_application_key(_bt_mesh_cdb_t *cfg,
134                 uint16_t unicast, uint16_t idx);
135
136 bool _bt_mesh_conf_node_set_timetolive_value(_bt_mesh_cdb_t *cfg,
137                 uint16_t unicast, uint8_t ttl);
138
139 bool _bt_mesh_conf_node_set_write_op_mode(uint16_t unicast,
140                 const char *keyword, int value);
141
142 bool _bt_mesh_conf_bind_model(uint16_t unicast,
143                 uint8_t ele, bool vendor,
144                         uint32_t mod_id, uint16_t app_idx);
145
146 bool _bt_mesh_conf_unbind_model(uint16_t unicast,
147                 uint8_t ele, bool vendor,
148                         uint32_t mod_id, uint16_t app_idx);
149
150 GSList *_bt_mesh_conf_load_group_info(_bt_mesh_cdb_t *cfg);
151
152 bool _bt_mesh_conf_insert_group_info(_bt_mesh_cdb_t *cfg,
153                 _bt_mesh_group_t *grp);
154
155 bool _bt_mesh_conf_delete_group_entry(_bt_mesh_cdb_t *cfg,
156                 uint16_t addr);
157
158 bool _bt_mesh_is_group_subscribed(_bt_mesh_cdb_t *cfg,
159                                         uint16_t addr);
160
161 bool _bt_mesh_conf_add_model_config_data(_bt_mesh_cdb_t *cfg, uint16_t unicast,
162                         int element_index, uint32_t model_id, uint16_t group_addr);
163
164 bool _bt_mesh_conf_delete_model_config_data(_bt_mesh_cdb_t *cfg, uint16_t unicast,
165                         int element_index, uint32_t model_id, uint16_t group_addr);
166
167 bool _bt_mesh_conf_delete_all_model_config_data(_bt_mesh_cdb_t *cfg, uint16_t unicast,
168                         int element_index, uint32_t model_id);
169
170 bool _bt_mesh_conf_overwrite_model_config_data(_bt_mesh_cdb_t *cfg, uint16_t unicast,
171                         int element_index, uint32_t model_id, uint16_t group_addr);
172
173 bool _bt_mesh_conf_set_network_friendly_name(_bt_mesh_cdb_t *cfg,
174                 const char *network_name);
175
176 const char * _bt_mesh_conf_get_network_friendly_name(_bt_mesh_cdb_t *cfg);
177
178 #ifdef __cplusplus
179 }
180 #endif /* __cplusplus */
181 #endif /* BT_SERVICE_MESH_CDB_H_ */