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