Merge "Add busy return logic when connecting timer is existing" into tizen
[platform/core/connectivity/bluetooth-frwk.git] / include / bluetooth-mesh-api.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 __BLUETOOTH_MESH_API_H
23 #define __BLUETOOTH_MESH_API_H
24
25 #include <stdint.h>
26 #include <glib.h>
27 #include <dlog.h>
28
29 #include <bluetooth-api.h>
30
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #define BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX  100
37 #define BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH       32
38 #define BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH      16
39 #define BLUETOOTH_MESH_APP_UNIQUE_CRED_STRING_LENGTH    50
40 #define BLUETOOTH_MESH_AUTH_VALUE_LENGTH_MAX    50
41 #define BLUETOOTH_MESH_MODEL_MSG_LENGTH_MAX     32
42
43 typedef enum {
44         BLUETOOTH_MESH_NODE_KEY_ADD,
45         BLUETOOTH_MESH_NODE_KEY_UPDATE,
46         BLUETOOTH_MESH_NODE_KEY_DELETE,
47 } bluetooth_mesh_node_key_conf_e;
48
49 typedef enum {
50         BLUETOOTH_MESH_MODEL_SUB_ADD,
51         BLUETOOTH_MESH_MODEL_SUB_DELETE,
52         BLUETOOTH_MESH_MODEL_SUB_DELETE_ALL,
53         BLUETOOTH_MESH_MODEL_SUB_OVERWRITE,
54 } bluetooth_mesh_model_sub_op_e;
55
56 typedef struct {
57         int event;
58         int result;
59         void *param_data;
60         void *user_data;
61 } mesh_event_param_t;
62
63 typedef struct {
64         uint16_t elem_index;
65         uint32_t model_id;
66 } bluetooth_mesh_model_t;
67
68 typedef struct {
69         uint16_t index;
70         uint16_t num_models;
71 } bluetooth_mesh_element_t;
72
73 typedef struct {
74         uint16_t companyid;
75         uint16_t vendorid;
76         uint16_t versionid;
77         uint16_t crpl;
78 } bluetooth_mesh_vendor_info_t;
79
80 typedef struct {
81         int relay;
82         int proxy;
83         int frnd;
84         int lpn;
85 } bluetooth_mesh_features_t;
86
87 typedef struct {
88         bluetooth_mesh_vendor_info_t vendor_info;
89         uint16_t num_elements;
90         uint16_t primary_unicast;
91         uint8_t uuid[16];
92         union {
93                 uint8_t u8[8];
94                 uint64_t u64;
95         } token;
96 } bluetooth_mesh_node_t;
97
98
99 typedef struct {
100         char token[BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH +1];
101 } bluetooth_mesh_token_t;
102
103 typedef struct {
104         char name[BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX +1];
105 } bluetooth_mesh_network_name_t;
106
107 typedef struct {
108         bluetooth_mesh_network_name_t name;
109         bluetooth_mesh_token_t token;
110         char uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
111         char app_cred[BLUETOOTH_MESH_APP_UNIQUE_CRED_STRING_LENGTH + 1];
112 } bluetooth_mesh_network_t;
113
114 typedef struct {
115         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
116         int rssi;
117         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
118         uint8_t oob_info[2];
119         uint8_t uri_hash[4];
120 } bluetooth_mesh_scan_result_t;
121
122 typedef struct {
123         uint16_t scan_time;
124 } bluetooth_mesh_scan_param_t;
125
126
127 typedef struct {
128         bool public_oob;
129         bool static_oob;
130         uint16_t out_oob;
131         uint16_t  in_oob;
132 } bluetooth_mesh_provisioner_caps_t;
133
134 typedef struct {
135         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
136         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
137         uint16_t unicast;
138         int count;
139         int netkey_idx;
140 } bluetooth_mesh_node_discover_t;
141
142 typedef struct {
143         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
144         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
145         uint16_t unicast;
146         int elem_count;
147         bluetooth_mesh_vendor_info_t vendor_info;
148         bluetooth_mesh_features_t features;
149 } bluetooth_mesh_node_features_t;
150
151 typedef struct {
152         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
153         uint16_t unicast;
154         uint8_t ttl;
155         bool is_set;
156 } bluetooth_mesh_node_ttl_info_t;
157
158 typedef struct {
159         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
160         uint16_t primary_unicast;
161         int elem_index;
162         uint32_t model;
163         uint16_t netkey_idx;
164         uint16_t appkey_idx;
165         uint16_t **appkey_list;
166         int appkeylist_count;
167         bool is_bind;
168
169         /* For Subscription Configuration */
170         bluetooth_mesh_model_sub_op_e op;
171         bool is_virtual_sub;
172         uint16_t sub_addr;
173         uint16_t **sub_list;
174         int sublist_count;
175
176         /* For Publication Configuration */
177         uint16_t pub_addr;
178         uint8_t ttl;
179         uint8_t period;
180         uint8_t retransmit;
181 } bluetooth_mesh_model_configure_t;
182
183 typedef struct {
184         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
185         uint16_t primary_unicast;
186         int elem_index;
187         uint16_t model;
188         uint16_t appkey_idx;
189         uint16_t opcode;
190         uint16_t msg_len;
191         char msg[BLUETOOTH_MESH_MODEL_MSG_LENGTH_MAX + 1];
192 } bluetooth_mesh_model_msg_t;
193
194 typedef struct {
195         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
196         bool is_virtual;
197         uint16_t group_addr;
198         char label_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH +1];
199 } bluetooth_mesh_network_group_info_t;
200
201 typedef struct {
202         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
203         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
204         uint16_t primary_unicast;
205         uint16_t netkey_idx;
206         uint16_t appkey_idx;
207         bool is_netkey;
208         bluetooth_mesh_node_key_conf_e op;
209 } bluetooth_mesh_key_configure_t;
210
211 typedef struct {
212         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
213         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
214 } bluetooth_mesh_provisioning_request_t;
215
216 typedef struct {
217         int result;
218         int reason;
219         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
220         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
221         uint16_t unicast;
222         uint8_t count;
223 } bluetooth_mesh_provisioning_result_t;
224
225 typedef struct {
226         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
227         int auth_type;
228         char auth_value[50];
229 } bluetooth_mesh_authentication_request_t;
230
231 typedef struct {
232         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
233         uint16_t primary_unicast;
234         uint16_t num_elements;
235         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
236 } bluetooth_mesh_node_info_t;
237
238 /**
239  * Mesh Event handler callback
240  */
241 typedef void (*mesh_cb_func_ptr)(int, mesh_event_param_t *, void *);
242
243 /**
244  * Mesh Init
245  */
246 int bluetooth_mesh_init(mesh_cb_func_ptr callback_ptr, void *user_data);
247
248 /**
249  * Mesh De-Init
250  */
251 int bluetooth_mesh_deinit(void);
252
253 /**
254  * Create Local Mesh Network
255  */
256 int bluetooth_mesh_network_create(const char *net_name,
257                 bluetooth_mesh_node_t *node, uint16_t total_models,
258                         bluetooth_mesh_model_t **models,
259                                 bluetooth_mesh_network_t *network);
260
261 int bluetooth_mesh_network_destroy(bluetooth_mesh_network_t *network);
262
263 /**
264  * Reset a remote Node & remove it from network
265  */
266 int bluetooth_mesh_node_reset(bluetooth_mesh_node_info_t *node);
267
268 /**
269  * Load already created Network
270  */
271 int bluetooth_mesh_network_load(const char *token,
272                 bluetooth_mesh_network_t *network);
273
274 /**
275  * Scan for Unprovisioned Devices
276  */
277 int bluetooth_mesh_network_scan(bluetooth_mesh_network_t *network,
278                 bluetooth_mesh_scan_param_t *scan_param);
279
280 /**
281  * Cancel the ongoing Scan
282  */
283 int bluetooth_mesh_network_cancel_scan(bluetooth_mesh_network_t *network);
284
285 /**
286  * Set Local Network Provisioning Capabilities
287  */
288 int bluetooth_mesh_network_set_capabilities(
289                 bluetooth_mesh_network_t *network,
290                         bluetooth_mesh_provisioner_caps_t *caps);
291
292 /**
293  * Povision a Device
294 */
295 int bluetooth_mesh_network_provision_device(
296                 bluetooth_mesh_provisioning_request_t *req);
297
298 /**
299  * Reply to Authentication request
300  */
301 int bluetooth_mesh_authentication_reply(int auth_type,
302                 const char *auth_val, gboolean reply);
303
304 /**
305  * Set Local Mesh Network name
306  */
307 int bluetooth_mesh_network_set_name(bluetooth_mesh_network_t *network);
308
309 /**
310  * Add Subnet key in local Network
311  */
312 int bluetooth_mesh_network_add_netkey(bluetooth_mesh_network_t *network,
313                 uint16_t *netkey_idx);
314
315 /**
316  * Delete Subnet key in local Network
317  */
318 int bluetooth_mesh_network_delete_netkey(
319                 bluetooth_mesh_network_t *network, uint16_t netkey_idx);
320
321 /**
322  * Update Subnet key in local Network
323  */
324 int bluetooth_mesh_network_update_netkey(bluetooth_mesh_network_t *network,
325                 uint16_t netkey_idx);
326
327 /**
328  * Add Application Key in local Network
329  */
330 int bluetooth_mesh_network_add_appkey(bluetooth_mesh_network_t *network,
331                 uint16_t netkey_idx, uint16_t *appkey_index);
332
333 /**
334  * Update Application Key in local Network
335  */
336 int bluetooth_mesh_network_update_appkey(bluetooth_mesh_network_t *network,
337                 uint16_t netkey_index, uint16_t appkey_idx);
338
339 /**
340  * Delete Application Key in local Network
341  */
342 int bluetooth_mesh_network_delete_appkey(bluetooth_mesh_network_t *network,
343                 uint16_t netkey_index, uint16_t appkey_idx);
344
345 /**
346  * Get All Netkeys in Local Network
347  */
348 int bluetooth_mesh_network_get_all_netkey(bluetooth_mesh_network_t *network,
349                         GPtrArray **netkeys);
350
351 /**
352  * Get All Appkeys Bound to a Netkey in Local Network
353  * Mesh Init
354  */
355 int bluetooth_mesh_netkey_get_all_appkey(bluetooth_mesh_network_t *network,
356                 uint16_t netkey_idx,  GPtrArray **appkeys);
357
358 /**
359  * Get All nodes's basic information, that are added in the local Network
360  */
361 int bluetooth_mesh_network_get_all_nodes(bluetooth_mesh_network_t *network,
362                 GPtrArray **nodes);
363
364 /**
365  * Get all Model information
366  */
367 int bluetooth_mesh_element_get_all_models(bluetooth_mesh_network_t *network,
368                  uint16_t node_addr, int elem_idx, GPtrArray **models);
369
370
371 /**
372  * Get All Netkeys bound to a node
373  */
374 int bluetooth_mesh_node_get_all_netkeys(bluetooth_mesh_node_discover_t *req,
375                         GPtrArray **netkeys);
376
377 /**
378  * Get All Application Keys bound to a node
379  */
380 int bluetooth_mesh_node_get_all_appkeys(bluetooth_mesh_node_discover_t *req,
381                         GPtrArray **appkeys);
382
383 /**
384  * Discover remote node exported informations (E.g: Models)
385  */
386 int bluetooth_mesh_browse_remote_node(bluetooth_mesh_node_discover_t *req);
387
388 /**
389  * Configure Key to a node
390  */
391 int bluetooth_mesh_node_configure_key(bluetooth_mesh_key_configure_t *req);
392
393 /**
394  * Confiure Appplication key to a model of a node
395  */
396 int bluetooth_mesh_model_configure_appkey(
397                 bluetooth_mesh_model_configure_t *req);
398
399 /**
400  * Send message to a model of a node
401  */
402 int bluetooth_mesh_model_send_msg(
403                         bluetooth_mesh_model_msg_t *req);
404
405 /**
406  * Get all application keys added to a model of a node
407  */
408 int bluetooth_mesh_model_get_all_appkeys(
409                 bluetooth_mesh_model_configure_t *req);
410
411 /**
412  * Get full subscription list added to a Model in a node
413  */
414 int bluetooth_mesh_model_get_subscriptopn_list(
415                 bluetooth_mesh_model_configure_t *req);
416
417 /**
418  * Get/Set Time To Live value of a node
419  */
420 int bluetooth_mesh_node_ttl_execute(
421                 bluetooth_mesh_node_ttl_info_t *req);
422
423 /**
424  * Get all groups available in local Network
425  */
426 int bluetooth_mesh_network_get_all_groups(
427                 bluetooth_mesh_network_t *network,
428                 GPtrArray **groups);
429
430 /**
431  * Create a group in a network
432  */
433 int bluetooth_mesh_network_create_group(bluetooth_mesh_network_t *network,
434                 bool is_virtual, uint16_t grp_addr,
435                         bluetooth_mesh_network_group_info_t *info);
436
437 /**
438  * Remove a group in a network
439  */
440 int bluetooth_mesh_network_remove_group(bluetooth_mesh_network_t *network,
441                 bluetooth_mesh_network_group_info_t *req);
442
443 /**
444  * Configure a Mesh group to a Mesh odel
445  */
446 int bluetooth_mesh_model_configure_group_sub(
447         bluetooth_mesh_model_configure_t *req);
448
449 /**
450  * Confgure Virtual group to a Mesh Model
451  */
452 int bluetooth_mesh_model_configure_virtual_group_sub(
453                 bluetooth_mesh_model_configure_t *req);
454
455 /**
456  * Set Publication Information to a model of a node
457  */
458 int bluetooth_mesh_model_set_publication(bluetooth_mesh_model_configure_t *req);
459
460 /**
461  * Get Publication Information from a model of a node
462  */
463 int bluetooth_mesh_model_get_publication(bluetooth_mesh_model_configure_t *req);
464
465 /**
466  * Browse Vendor specific features from node
467  */
468 int bluetooth_mesh_node_browse_vendor_features(bluetooth_mesh_node_features_t *req);
469
470 #ifdef __cplusplus
471 }
472 #endif
473 #endif /* __BLUETOOTH_MESH_API_H */