Fix 64bit build error
[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 } bluetooth_mesh_model_msg_t;
197
198 typedef struct {
199         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
200         bool is_virtual;
201         uint16_t group_addr;
202         char label_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH +1];
203 } bluetooth_mesh_network_group_info_t;
204
205 typedef struct {
206         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
207         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
208         uint16_t primary_unicast;
209         uint16_t netkey_idx;
210         uint16_t appkey_idx;
211         bool is_netkey;
212         bluetooth_mesh_node_key_conf_e op;
213 } bluetooth_mesh_key_configure_t;
214
215 typedef struct {
216         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
217         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
218 } bluetooth_mesh_provisioning_request_t;
219
220 typedef struct {
221         int result;
222         int reason;
223         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
224         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
225         uint16_t unicast;
226         uint8_t count;
227 } bluetooth_mesh_provisioning_result_t;
228
229 typedef struct {
230         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
231         int auth_type;
232         char auth_value[50];
233 } bluetooth_mesh_authentication_request_t;
234
235 typedef struct {
236         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
237         uint16_t primary_unicast;
238         uint16_t num_elements;
239         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
240 } bluetooth_mesh_node_info_t;
241
242 /**
243  * Mesh Event handler callback
244  */
245 typedef void (*mesh_cb_func_ptr)(int, mesh_event_param_t *, void *);
246
247 /**
248  * Mesh Init
249  */
250 int bluetooth_mesh_init(mesh_cb_func_ptr callback_ptr, void *user_data);
251
252 /**
253  * Mesh De-Init
254  */
255 int bluetooth_mesh_deinit(void);
256
257 /**
258  * Create Local Mesh Network
259  */
260 int bluetooth_mesh_network_create(const char *net_name,
261                 bluetooth_mesh_node_t *node, uint16_t total_models,
262                         bluetooth_mesh_model_t **models,
263                                 bluetooth_mesh_network_t *network);
264
265
266 /**
267  * Destroy Local Network Configuration
268  */
269 int bluetooth_mesh_network_destroy(bluetooth_mesh_network_t *network);
270
271 /**
272  * Unload Local network Configuration
273  */
274 int bluetooth_mesh_network_unload(bluetooth_mesh_network_t *network);
275
276 /**
277  * Reset a remote Node & remove it from network
278  */
279 int bluetooth_mesh_node_reset(bluetooth_mesh_node_info_t *node);
280
281 /**
282  * Load already created Network
283  */
284 int bluetooth_mesh_network_load(const char *token,
285                 bluetooth_mesh_network_t *network);
286
287 /**
288  * Scan for Unprovisioned Devices
289  */
290 int bluetooth_mesh_network_scan(bluetooth_mesh_network_t *network,
291                 bluetooth_mesh_scan_param_t *scan_param);
292
293 /**
294  * Cancel the ongoing Scan
295  */
296 int bluetooth_mesh_network_cancel_scan(bluetooth_mesh_network_t *network);
297
298 /**
299  * Set Local Network Provisioning Capabilities
300  */
301 int bluetooth_mesh_network_set_capabilities(
302                 bluetooth_mesh_network_t *network,
303                         bluetooth_mesh_provisioner_caps_t *caps);
304
305 /**
306  * Povision a Device
307 */
308 int bluetooth_mesh_network_provision_device(
309                 bluetooth_mesh_provisioning_request_t *req);
310
311 /**
312  * Reply to Authentication request
313  */
314 int bluetooth_mesh_authentication_reply(int auth_type,
315                 const char *auth_val, gboolean reply);
316
317 /**
318  * Set Local Mesh Network name
319  */
320 int bluetooth_mesh_network_set_name(bluetooth_mesh_network_t *network);
321
322 /**
323  * Add Subnet key in local Network
324  */
325 int bluetooth_mesh_network_add_netkey(bluetooth_mesh_network_t *network,
326                 uint16_t *netkey_idx);
327
328 /**
329  * Delete Subnet key in local Network
330  */
331 int bluetooth_mesh_network_delete_netkey(
332                 bluetooth_mesh_network_t *network, uint16_t netkey_idx);
333
334 /**
335  * Update Subnet key in local Network
336  */
337 int bluetooth_mesh_network_update_netkey(bluetooth_mesh_network_t *network,
338                 uint16_t netkey_idx);
339
340 /**
341  * Add Application Key in local Network
342  */
343 int bluetooth_mesh_network_add_appkey(bluetooth_mesh_network_t *network,
344                 uint16_t netkey_idx, uint16_t *appkey_index);
345
346 /**
347  * Update Application Key in local Network
348  */
349 int bluetooth_mesh_network_update_appkey(bluetooth_mesh_network_t *network,
350                 uint16_t netkey_index, uint16_t appkey_idx);
351
352 /**
353  * Delete Application Key in local Network
354  */
355 int bluetooth_mesh_network_delete_appkey(bluetooth_mesh_network_t *network,
356                 uint16_t netkey_index, uint16_t appkey_idx);
357
358 /**
359  * Get All Netkeys in Local Network
360  */
361 int bluetooth_mesh_network_get_all_netkey(bluetooth_mesh_network_t *network,
362                         GPtrArray **netkeys);
363
364 /**
365  * Get All Appkeys Bound to a Netkey in Local Network
366  * Mesh Init
367  */
368 int bluetooth_mesh_netkey_get_all_appkey(bluetooth_mesh_network_t *network,
369                 uint16_t netkey_idx,  GPtrArray **appkeys);
370
371 /**
372  * Get All nodes's basic information, that are added in the local Network
373  */
374 int bluetooth_mesh_network_get_all_nodes(bluetooth_mesh_network_t *network,
375                 GPtrArray **nodes);
376
377 /**
378  * Get all Model information
379  */
380 int bluetooth_mesh_element_get_all_models(bluetooth_mesh_network_t *network,
381                  uint16_t node_addr, int elem_idx, GPtrArray **models);
382
383
384 /**
385  * Get All Netkeys bound to a node
386  */
387 int bluetooth_mesh_node_get_all_netkeys(bluetooth_mesh_node_discover_t *req,
388                         GPtrArray **netkeys);
389
390 /**
391  * Get All Application Keys bound to a node
392  */
393 int bluetooth_mesh_node_get_all_appkeys(bluetooth_mesh_node_discover_t *req,
394                         GPtrArray **appkeys);
395
396 /**
397  * Discover remote node exported informations (E.g: Models)
398  */
399 int bluetooth_mesh_browse_remote_node(bluetooth_mesh_node_discover_t *req);
400
401 /**
402  * Configure Key to a node
403  */
404 int bluetooth_mesh_node_configure_key(bluetooth_mesh_key_configure_t *req);
405
406 /**
407  * Confiure Appplication key to a model of a node
408  */
409 int bluetooth_mesh_model_configure_appkey(
410                 bluetooth_mesh_model_configure_t *req);
411
412 /**
413  * Send message to a model of a node
414  */
415 int bluetooth_mesh_model_send_msg(
416                         bluetooth_mesh_model_msg_t *req);
417
418 /**
419  * Get all application keys added to a model of a node
420  */
421 int bluetooth_mesh_model_get_all_appkeys(
422                 bluetooth_mesh_model_configure_t *req);
423
424 /**
425  * Get full subscription list added to a Model in a node
426  */
427 int bluetooth_mesh_model_get_subscriptopn_list(
428                 bluetooth_mesh_model_configure_t *req);
429
430 /**
431  * Get/Set Time To Live value of a node
432  */
433 int bluetooth_mesh_node_ttl_execute(
434                 bluetooth_mesh_node_ttl_info_t *req);
435
436 /**
437  * Get all groups available in local Network
438  */
439 int bluetooth_mesh_network_get_all_groups(
440                 bluetooth_mesh_network_t *network,
441                 GPtrArray **groups);
442
443 /**
444  * Create a group in a network
445  */
446 int bluetooth_mesh_network_create_group(bluetooth_mesh_network_t *network,
447                 bool is_virtual, uint16_t grp_addr,
448                         bluetooth_mesh_network_group_info_t *info);
449
450 /**
451  * Remove a group in a network
452  */
453 int bluetooth_mesh_network_remove_group(bluetooth_mesh_network_t *network,
454                 bluetooth_mesh_network_group_info_t *req);
455
456 /**
457  * Configure a Mesh group to a Mesh odel
458  */
459 int bluetooth_mesh_model_configure_group_sub(
460         bluetooth_mesh_model_configure_t *req);
461
462 /**
463  * Confgure Virtual group to a Mesh Model
464  */
465 int bluetooth_mesh_model_configure_virtual_group_sub(
466                 bluetooth_mesh_model_configure_t *req);
467
468 /**
469  * Set Publication Information to a model of a node
470  */
471 int bluetooth_mesh_model_set_publication(bluetooth_mesh_model_configure_t *req);
472
473 /**
474  * Get Publication Information from a model of a node
475  */
476 int bluetooth_mesh_model_get_publication(bluetooth_mesh_model_configure_t *req);
477
478 /**
479  * Browse Vendor specific features from node
480  */
481 int bluetooth_mesh_node_browse_vendor_features(bluetooth_mesh_node_features_t *req);
482
483 #ifdef __cplusplus
484 }
485 #endif
486 #endif /* __BLUETOOTH_MESH_API_H */