prov.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* SPDX-License-Identifier: LGPL-2.1-or-later */
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2018 Intel Corporation. All rights reserved.
  7. *
  8. *
  9. */
  10. #ifndef __packed
  11. #define __packed __attribute__((packed))
  12. #endif
  13. struct mesh_net;
  14. struct mesh_dev;
  15. enum mesh_trans {
  16. MESH_TRANS_IDLE,
  17. MESH_TRANS_TX,
  18. MESH_TRANS_RX,
  19. };
  20. enum mesh_bearer {
  21. MESH_BEARER_IDLE,
  22. MESH_BEARER_ADV,
  23. };
  24. enum mesh_prov_mode {
  25. MESH_PROV_MODE_NONE,
  26. MESH_PROV_MODE_INITIATOR,
  27. MESH_PROV_MODE_GATT_ACCEPTOR,
  28. MESH_PROV_MODE_ADV_ACCEPTOR,
  29. MESH_PROV_MODE_GATT_CLIENT,
  30. MESH_PROV_MODE_MESH_SERVER,
  31. MESH_PROV_MODE_MESH_CLIENT,
  32. MESH_PROV_MODE_MESH_GATT_CLIENT,
  33. };
  34. struct mesh_prov;
  35. typedef void (*prov_trans_tx_t)(void *trans_data, void *data, uint16_t len);
  36. typedef void (*mesh_prov_open_func_t)(void *user_data, prov_trans_tx_t trans_tx,
  37. void *trans_data, uint8_t trans_type);
  38. typedef void (*mesh_prov_close_func_t)(void *user_data, uint8_t reason);
  39. typedef void (*mesh_prov_send_func_t)(bool success, struct mesh_prov *prov);
  40. typedef void (*mesh_prov_ack_func_t)(void *user_data, uint8_t msg_num);
  41. typedef void (*mesh_prov_receive_func_t)(void *user_data, const uint8_t *data,
  42. uint16_t size);
  43. struct prov_invite {
  44. uint8_t attention;
  45. } __packed;
  46. struct prov_invite_msg {
  47. uint8_t opcode;
  48. struct prov_invite invite;
  49. } __packed;
  50. struct prov_start {
  51. uint8_t algorithm;
  52. uint8_t pub_key;
  53. uint8_t auth_method;
  54. uint8_t auth_action;
  55. uint8_t auth_size;
  56. } __packed;
  57. struct prov_caps_msg {
  58. uint8_t opcode;
  59. struct mesh_net_prov_caps caps;
  60. } __packed;
  61. struct prov_start_msg {
  62. uint8_t opcode;
  63. struct prov_start start;
  64. } __packed;
  65. struct prov_pub_key_msg {
  66. uint8_t opcode;
  67. uint8_t pub_key[64];
  68. } __packed;
  69. struct prov_conf_msg {
  70. uint8_t opcode;
  71. uint8_t conf[16];
  72. } __packed;
  73. struct prov_rand_msg {
  74. uint8_t opcode;
  75. uint8_t rand[16];
  76. } __packed;
  77. struct prov_data {
  78. uint8_t net_key[16];
  79. uint16_t net_idx;
  80. uint8_t flags;
  81. uint32_t iv_index;
  82. uint16_t primary;
  83. } __packed;
  84. struct prov_data_msg {
  85. uint8_t opcode;
  86. struct prov_data data;
  87. uint64_t mic;
  88. } __packed;
  89. struct prov_fail_msg {
  90. uint8_t opcode;
  91. uint8_t reason;
  92. } __packed;
  93. struct conf_input {
  94. struct prov_invite invite;
  95. struct mesh_net_prov_caps caps;
  96. struct prov_start start;
  97. uint8_t prv_pub_key[64];
  98. uint8_t dev_pub_key[64];
  99. } __packed;
  100. struct mesh_prov {
  101. int ref_count;
  102. struct mesh_dev *dev;
  103. struct mesh_net *net;
  104. enum mesh_prov_mode mode;
  105. enum mesh_trans trans;
  106. enum mesh_bearer bearer;
  107. uint8_t uuid[16];
  108. uint8_t caps[12];
  109. uint32_t conn_id;
  110. uint16_t net_idx;
  111. uint16_t remote;
  112. uint16_t addr;
  113. uint16_t expected_len;
  114. uint16_t packet_len;
  115. uint8_t local_msg_num;
  116. uint8_t peer_msg_num;
  117. uint8_t last_peer_msg_num;
  118. uint8_t got_segs;
  119. uint8_t expected_segs;
  120. uint8_t expected_fcs;
  121. uint8_t packet_buf[80];
  122. uint8_t peer_buf[80];
  123. struct timeval tx_start;
  124. struct l_timeout *tx_timeout;
  125. /* Provisioning credentials and crypto material */
  126. struct conf_input conf_inputs;
  127. uint8_t dev_key[16];
  128. uint8_t conf_salt[16];
  129. uint8_t s_key[16];
  130. uint8_t s_nonce[13];
  131. uint8_t conf_key[16];
  132. uint8_t conf[16];
  133. uint8_t r_conf[16];
  134. uint8_t rand_auth[32];
  135. uint8_t prov_salt[16];
  136. uint8_t secret[32];
  137. uint8_t r_public[64];
  138. uint8_t l_public[64];
  139. /* End Provisioning credentials and crypto material */
  140. mesh_prov_open_func_t open_callback;
  141. mesh_prov_close_func_t close_callback;
  142. mesh_prov_receive_func_t receive_callback;
  143. void *receive_data;
  144. mesh_prov_send_func_t send_callback;
  145. void *send_data;
  146. };
  147. struct mesh_prov *mesh_prov_new(struct mesh_net *net, uint16_t remote);
  148. struct mesh_prov *mesh_prov_ref(struct mesh_prov *prov);
  149. void mesh_prov_unref(struct mesh_prov *prov);
  150. bool mesh_prov_gatt_client(struct mesh_prov *prov, struct mesh_dev *dev,
  151. uint8_t uuid[16],
  152. mesh_prov_open_func_t open_callback,
  153. mesh_prov_close_func_t close_callback,
  154. mesh_prov_receive_func_t recv_callback,
  155. void *user_data);
  156. bool mesh_prov_listen(struct mesh_net *net, uint8_t uuid[16], uint8_t caps[12],
  157. mesh_prov_open_func_t open_callback,
  158. mesh_prov_close_func_t close_callback,
  159. mesh_prov_receive_func_t recv_callback,
  160. void *user_data);
  161. bool mesh_prov_connect(struct mesh_prov *prov, struct mesh_dev *dev,
  162. uint16_t net_idx, uint8_t uuid[16],
  163. mesh_prov_open_func_t open_callback,
  164. mesh_prov_close_func_t close_callback,
  165. mesh_prov_receive_func_t recv_callback,
  166. void *user_data);
  167. unsigned int mesh_prov_send(struct mesh_prov *prov,
  168. const void *data, uint16_t size,
  169. mesh_prov_send_func_t send_callback,
  170. void *user_data);
  171. bool mesh_prov_cancel(struct mesh_prov *prov, unsigned int id);
  172. bool mesh_prov_close(struct mesh_prov *prov, uint8_t reason);
  173. void mesh_prov_set_addr(struct mesh_prov *prov, uint16_t addr);
  174. uint16_t mesh_prov_get_addr(struct mesh_prov *prov);
  175. void mesh_prov_set_idx(struct mesh_prov *prov, uint16_t net_idx);
  176. uint16_t mesh_prov_get_idx(struct mesh_prov *prov);