NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
prov.h
1/* Bluetooth Mesh */
2
3/*
4 * Copyright (c) 2017 Intel Corporation
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9#ifndef __PROV_H__
10#define __PROV_H__
11
12#include "prov_bearer.h"
13#include "nimble/porting/nimble/include/os/os_mbuf.h"
14#include "../include/mesh/mesh.h"
15#include "nimble/nimble/host/src/ble_hs_conn_priv.h"
16
17#define PROV_ERR_NONE 0x00
18#define PROV_ERR_NVAL_PDU 0x01
19#define PROV_ERR_NVAL_FMT 0x02
20#define PROV_ERR_UNEXP_PDU 0x03
21#define PROV_ERR_CFM_FAILED 0x04
22#define PROV_ERR_RESOURCES 0x05
23#define PROV_ERR_DECRYPT 0x06
24#define PROV_ERR_UNEXP_ERR 0x07
25#define PROV_ERR_ADDR 0x08
26
27#define AUTH_METHOD_NO_OOB 0x00
28#define AUTH_METHOD_STATIC 0x01
29#define AUTH_METHOD_OUTPUT 0x02
30#define AUTH_METHOD_INPUT 0x03
31
32#define OUTPUT_OOB_BLINK 0x00
33#define OUTPUT_OOB_BEEP 0x01
34#define OUTPUT_OOB_VIBRATE 0x02
35#define OUTPUT_OOB_NUMBER 0x03
36#define OUTPUT_OOB_STRING 0x04
37
38#define INPUT_OOB_PUSH 0x00
39#define INPUT_OOB_TWIST 0x01
40#define INPUT_OOB_NUMBER 0x02
41#define INPUT_OOB_STRING 0x03
42
43#define PUB_KEY_NO_OOB 0x00
44#define PUB_KEY_OOB 0x01
45
46#define PROV_INVITE 0x00
47#define PROV_CAPABILITIES 0x01
48#define PROV_START 0x02
49#define PROV_PUB_KEY 0x03
50#define PROV_INPUT_COMPLETE 0x04
51#define PROV_CONFIRM 0x05
52#define PROV_RANDOM 0x06
53#define PROV_DATA 0x07
54#define PROV_COMPLETE 0x08
55#define PROV_FAILED 0x09
56
57#define PROV_NO_PDU 0xff
58
59#define PDU_LEN_INVITE 1
60#define PDU_LEN_CAPABILITIES 11
61#define PDU_LEN_START 5
62#define PDU_LEN_PUB_KEY 64
63#define PDU_LEN_INPUT_COMPLETE 0
64#define PDU_LEN_CONFIRM 16
65#define PDU_LEN_RANDOM 16
66#define PDU_LEN_DATA 33
67#define PDU_LEN_COMPLETE 0
68#define PDU_LEN_FAILED 1
69
70#define PDU_OP_LEN 1
71
72#define PROV_ALG_P256 0x00
73
74#define PROV_IO_OOB_SIZE_MAX 8 /* in bytes */
75
76#define PROV_BUF(len) \
77 NET_BUF_SIMPLE(PROV_BEARER_BUF_HEADROOM + PDU_OP_LEN + len)
78
79enum {
80 WAIT_PUB_KEY, /* Waiting for local PubKey to be generated */
81 LINK_ACTIVE, /* Link has been opened */
82 WAIT_NUMBER, /* Waiting for number input from user */
83 WAIT_STRING, /* Waiting for string input from user */
84 NOTIFY_INPUT_COMPLETE, /* Notify that input has been completed. */
85 PROVISIONER, /* The link was opened as provisioner */
86 OOB_PUB_KEY, /* OOB Public key used */
87 PUB_KEY_SENT, /* Public key has been sent */
88 REMOTE_PUB_KEY, /* Remote key has been received */
89 INPUT_COMPLETE, /* Device input completed */
90 WAIT_CONFIRM, /* Wait for send confirm */
91 WAIT_AUTH, /* Wait for auth response */
92 OOB_STATIC_KEY, /* OOB Static Authentication */
93 WAIT_DH_KEY, /* Wait for DH Key */
94
95 NUM_FLAGS,
96};
97
100 void (*link_opened)(void);
101
102 void (*link_closed)(void);
103
104 void (*error)(uint8_t reason);
105
106 void (*input_complete)(void);
107
108 void (*op[10])(const uint8_t *data);
109};
110
111struct bt_mesh_prov_link {
112 ATOMIC_DEFINE(flags, NUM_FLAGS);
113
114 const struct prov_bearer *bearer;
115 const struct bt_mesh_prov_role *role;
116
117 uint8_t oob_method; /* Authen method */
118 uint8_t oob_action; /* Authen action */
119 uint8_t oob_size; /* Authen size */
120 uint8_t auth[16]; /* Authen value */
121
122 uint8_t dhkey[BT_DH_KEY_LEN]; /* Calculated DHKey */
123 uint8_t expect; /* Next expected PDU */
124 uint8_t conf[16]; /* Local/Remote Confirmation */
125 uint8_t rand[16]; /* Local Random */
126
127 uint8_t conf_salt[16]; /* ConfirmationSalt */
128 uint8_t conf_key[16]; /* ConfirmationKey */
129 /* ConfirmationInput fields: */
130 struct {
131 uint8_t invite[PDU_LEN_INVITE];
132 uint8_t capabilities[PDU_LEN_CAPABILITIES];
133 uint8_t start[PDU_LEN_START];
134 uint8_t pub_key_provisioner[PDU_LEN_PUB_KEY]; /* big-endian */
135 uint8_t pub_key_device[PDU_LEN_PUB_KEY]; /* big-endian */
136 } conf_inputs;
137 uint8_t prov_salt[16]; /* Provisioning Salt */
138};
139
140extern struct bt_mesh_prov_link bt_mesh_prov_link;
141extern const struct bt_mesh_prov *bt_mesh_prov;
142
143static inline int bt_mesh_prov_send(struct os_mbuf *buf,
144 prov_bearer_send_complete_t cb)
145{
146 return bt_mesh_prov_link.bearer->send(buf, cb, NULL);
147}
148
149static inline void bt_mesh_prov_buf_init(struct os_mbuf *buf, uint8_t type)
150{
151 net_buf_reserve(buf, PROV_BEARER_BUF_HEADROOM);
152 net_buf_simple_add_u8(buf, type);
153}
154
155int bt_mesh_prov_reset_state(void (*func)(const uint8_t key[BT_PUB_KEY_LEN]));
156
157bool bt_mesh_prov_active(void);
158
159int bt_mesh_prov_auth(bool is_provisioner, uint8_t method, uint8_t action, uint8_t size);
160
161int bt_mesh_pb_gatt_open(uint16_t conn_handle);
162int bt_mesh_pb_gatt_close(uint16_t conn_handle);
163int bt_mesh_pb_gatt_recv(uint16_t conn_handle, struct os_mbuf *buf);
164
165const struct bt_mesh_prov *bt_mesh_prov_get(void);
166
167void bt_mesh_prov_reset_link(void);
168
169void bt_mesh_prov_complete(uint16_t net_idx, uint16_t addr);
170void bt_mesh_prov_reset(void);
171
172const struct prov_bearer_cb *bt_mesh_prov_bearer_cb_get(void);
173
174void bt_mesh_pb_adv_recv(struct os_mbuf *buf);
175
176int bt_mesh_prov_init(const struct bt_mesh_prov *prov);
177#endif
#define ATOMIC_DEFINE(name, num_bits)
Define an array of atomic variables.
Definition atomic.h:274
Definition prov.h:99
Definition main.h:90
Definition os_mbuf.h:86
Definition prov_bearer.h:30
Definition prov_bearer.h:47