mesh-config.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* SPDX-License-Identifier: LGPL-2.1-or-later */
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2018-2019 Intel Corporation. All rights reserved.
  7. *
  8. *
  9. */
  10. #define MIN_COMP_SIZE 14
  11. struct mesh_config;
  12. struct mesh_config_sub {
  13. bool virt;
  14. union {
  15. uint16_t grp;
  16. uint8_t label[16];
  17. } addr;
  18. };
  19. struct mesh_config_pub {
  20. bool virt;
  21. uint32_t period;
  22. uint16_t addr;
  23. uint16_t idx;
  24. uint16_t interval;
  25. uint8_t ttl;
  26. uint8_t credential;
  27. uint8_t cnt;
  28. uint8_t virt_addr[16];
  29. };
  30. struct mesh_config_model {
  31. struct mesh_config_sub *subs;
  32. struct mesh_config_pub *pub;
  33. uint16_t *bindings;
  34. uint32_t id;
  35. bool vendor;
  36. bool sub_enabled;
  37. bool pub_enabled;
  38. uint32_t num_bindings;
  39. uint32_t num_subs;
  40. };
  41. struct mesh_config_element {
  42. struct l_queue *models;
  43. uint16_t location;
  44. uint8_t index;
  45. };
  46. struct mesh_config_modes {
  47. struct {
  48. uint16_t interval;
  49. uint8_t cnt;
  50. uint8_t state;
  51. } relay;
  52. uint8_t lpn;
  53. uint8_t friend;
  54. uint8_t proxy;
  55. uint8_t beacon;
  56. };
  57. struct mesh_config_netkey {
  58. uint16_t idx;
  59. uint8_t key[16];
  60. uint8_t new_key[16];
  61. uint8_t phase;
  62. };
  63. struct mesh_config_appkey {
  64. uint16_t net_idx;
  65. uint16_t app_idx;
  66. uint8_t key[16];
  67. uint8_t new_key[16];
  68. };
  69. struct mesh_config_transmit {
  70. uint16_t interval;
  71. uint8_t count;
  72. };
  73. struct mesh_config_comp_page {
  74. uint16_t len;
  75. uint8_t page_num;
  76. uint8_t data[];
  77. };
  78. struct mesh_config_node {
  79. struct l_queue *elements;
  80. struct l_queue *netkeys;
  81. struct l_queue *appkeys;
  82. struct l_queue *pages;
  83. uint32_t seq_number;
  84. uint32_t iv_index;
  85. bool iv_update;
  86. uint16_t cid;
  87. uint16_t pid;
  88. uint16_t vid;
  89. uint16_t crpl;
  90. uint16_t unicast;
  91. struct mesh_config_transmit *net_transmit;
  92. struct mesh_config_modes modes;
  93. uint8_t ttl;
  94. uint8_t dev_key[16];
  95. uint8_t token[8];
  96. };
  97. typedef void (*mesh_config_status_func_t)(void *user_data, bool result);
  98. typedef bool (*mesh_config_node_func_t)(struct mesh_config_node *node,
  99. const uint8_t uuid[16],
  100. struct mesh_config *cfg,
  101. void *user_data);
  102. bool mesh_config_load_nodes(const char *cfgdir_name, mesh_config_node_func_t cb,
  103. void *user_data);
  104. void mesh_config_release(struct mesh_config *cfg);
  105. void mesh_config_destroy_nvm(struct mesh_config *cfg);
  106. bool mesh_config_save(struct mesh_config *cfg, bool no_wait,
  107. mesh_config_status_func_t cb, void *user_data);
  108. struct mesh_config *mesh_config_create(const char *cfgdir_name,
  109. const uint8_t uuid[16],
  110. struct mesh_config_node *node);
  111. bool mesh_config_write_net_transmit(struct mesh_config *cfg, uint8_t cnt,
  112. uint16_t interval);
  113. bool mesh_config_write_device_key(struct mesh_config *cfg, uint8_t *key);
  114. bool mesh_config_write_token(struct mesh_config *cfg, uint8_t *token);
  115. bool mesh_config_write_network_key(struct mesh_config *cfg, uint16_t idx,
  116. uint8_t *key, uint8_t *new_key, int phase);
  117. bool mesh_config_write_app_key(struct mesh_config *cfg, uint16_t net_idx,
  118. uint16_t app_idx, uint8_t *key, uint8_t *new_key);
  119. bool mesh_config_write_seq_number(struct mesh_config *cfg, uint32_t seq,
  120. bool cache);
  121. bool mesh_config_write_unicast(struct mesh_config *cfg, uint16_t unicast);
  122. bool mesh_config_write_relay_mode(struct mesh_config *cfg, uint8_t mode,
  123. uint8_t count, uint16_t interval);
  124. bool mesh_config_write_ttl(struct mesh_config *cfg, uint8_t ttl);
  125. bool mesh_config_write_mode(struct mesh_config *cfg, const char *keyword,
  126. int value);
  127. bool mesh_config_comp_page_add(struct mesh_config *cfg, uint8_t page,
  128. uint8_t *data, uint16_t size);
  129. bool mesh_config_comp_page_mv(struct mesh_config *cfg, uint8_t old, uint8_t nw);
  130. bool mesh_config_model_binding_add(struct mesh_config *cfg, uint16_t ele_addr,
  131. uint32_t mod_id, bool vendor,
  132. uint16_t app_idx);
  133. bool mesh_config_model_binding_del(struct mesh_config *cfg, uint16_t ele_addr,
  134. uint32_t mod_id, bool vendor,
  135. uint16_t app_idx);
  136. bool mesh_config_model_pub_add(struct mesh_config *cfg, uint16_t ele_addr,
  137. uint32_t mod_id, bool vendor,
  138. struct mesh_config_pub *pub);
  139. bool mesh_config_model_pub_del(struct mesh_config *cfg, uint16_t ele_addr,
  140. uint32_t mod_id, bool vendor);
  141. bool mesh_config_model_sub_add(struct mesh_config *cfg, uint16_t ele_addr,
  142. uint32_t mod_id, bool vendor,
  143. struct mesh_config_sub *sub);
  144. bool mesh_config_model_sub_del(struct mesh_config *cfg, uint16_t ele_addr,
  145. uint32_t mod_id, bool vendor,
  146. struct mesh_config_sub *sub);
  147. bool mesh_config_model_sub_del_all(struct mesh_config *cfg, uint16_t ele_addr,
  148. uint32_t mod_id, bool vendor);
  149. bool mesh_config_model_pub_enable(struct mesh_config *cfg, uint16_t ele_addr,
  150. uint32_t mod_id, bool vendor,
  151. bool enable);
  152. bool mesh_config_model_sub_enable(struct mesh_config *cfg, uint16_t ele_addr,
  153. uint32_t mod_id, bool vendor,
  154. bool enable);
  155. bool mesh_config_app_key_add(struct mesh_config *cfg, uint16_t net_idx,
  156. uint16_t app_idx, const uint8_t key[16]);
  157. bool mesh_config_app_key_update(struct mesh_config *cfg, uint16_t app_idx,
  158. const uint8_t key[16]);
  159. bool mesh_config_app_key_del(struct mesh_config *cfg, uint16_t net_idx,
  160. uint16_t idx);
  161. bool mesh_config_net_key_add(struct mesh_config *cfg, uint16_t net_idx,
  162. const uint8_t key[16]);
  163. bool mesh_config_net_key_update(struct mesh_config *cfg, uint16_t idx,
  164. const uint8_t key[16]);
  165. bool mesh_config_net_key_del(struct mesh_config *cfg, uint16_t net_idx);
  166. bool mesh_config_net_key_set_phase(struct mesh_config *cfg, uint16_t idx,
  167. uint8_t phase);
  168. bool mesh_config_write_address(struct mesh_config *cfg, uint16_t address);
  169. bool mesh_config_write_iv_index(struct mesh_config *cfg, uint32_t idx,
  170. bool update);
  171. bool mesh_config_update_company_id(struct mesh_config *cfg, uint16_t cid);
  172. bool mesh_config_update_product_id(struct mesh_config *cfg, uint16_t pid);
  173. bool mesh_config_update_version_id(struct mesh_config *cfg, uint16_t vid);
  174. bool mesh_config_update_crpl(struct mesh_config *cfg, uint16_t crpl);