Skip to content

Commit 3b705c2

Browse files
PavelVPVrlubos
authored andcommitted
[nrf fromtree] tests: bluetooth: tester: Add Upload OOB support for mesh tester
This allow to run the following PTS test: - DFU/SR/FD/BV-06-C - DFU/SR/FD/BV-13-C - DFU/SR/FD/BV-14-C - DFU/SR/FD/BV-15-C - DFU/SR/FD/BV-16-C - DFU/SR/FD/BV-17-C - DFU/SR/FD/BV-18-C - DFU/SR/FD/BV-22-C Signed-off-by: Pavel Vasilyev <[email protected]> (cherry picked from commit 1c1c5e2)
1 parent 2ab6521 commit 3b705c2

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

tests/bluetooth/tester/src/btp_mesh.c

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,132 @@ static int dfd_srv_send(struct bt_mesh_dfd_srv *srv,
162162
return 0;
163163
}
164164

165+
#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD
166+
static struct {
167+
uint8_t uri[CONFIG_BT_MESH_DFU_URI_MAXLEN];
168+
uint8_t uri_len;
169+
uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN];
170+
uint8_t fwid_len;
171+
const struct bt_mesh_dfu_slot *slot;
172+
uint8_t progress;
173+
bool started;
174+
} dfd_srv_oob_ctx;
175+
176+
static void oob_check_handler(struct k_work *work);
177+
static K_WORK_DEFINE(oob_check, oob_check_handler);
178+
static void oob_store_handler(struct k_work *work);
179+
static K_WORK_DEFINE(oob_store, oob_store_handler);
180+
181+
static int dfd_srv_start_oob_upload(struct bt_mesh_dfd_srv *srv,
182+
const struct bt_mesh_dfu_slot *slot,
183+
const char *uri, uint8_t uri_len,
184+
const uint8_t *fwid, uint16_t fwid_len)
185+
{
186+
LOG_DBG("Start OOB Upload");
187+
188+
memcpy(dfd_srv_oob_ctx.uri, uri, uri_len);
189+
dfd_srv_oob_ctx.uri_len = uri_len;
190+
memcpy(dfd_srv_oob_ctx.fwid, fwid, fwid_len);
191+
dfd_srv_oob_ctx.fwid_len = fwid_len;
192+
dfd_srv_oob_ctx.slot = slot;
193+
dfd_srv_oob_ctx.progress = 0;
194+
dfd_srv_oob_ctx.started = true;
195+
196+
k_work_submit(&oob_check);
197+
198+
return BT_MESH_DFD_SUCCESS;
199+
}
200+
201+
static void dfd_srv_cancel_oob_upload(struct bt_mesh_dfd_srv *srv,
202+
const struct bt_mesh_dfu_slot *slot)
203+
{
204+
LOG_DBG("Cancel OOB Upload");
205+
206+
dfd_srv_oob_ctx.started = false;
207+
}
208+
209+
static uint8_t dfd_srv_oob_progress_get(struct bt_mesh_dfd_srv *srv,
210+
const struct bt_mesh_dfu_slot *slot)
211+
{
212+
uint8_t progress;
213+
214+
if (dfd_srv_oob_ctx.started) {
215+
progress = dfd_srv_oob_ctx.progress;
216+
217+
dfd_srv_oob_ctx.progress = MIN(dfd_srv_oob_ctx.progress + 25, 99);
218+
219+
if (dfd_srv_oob_ctx.progress == 99) {
220+
k_work_submit(&oob_store);
221+
}
222+
} else {
223+
progress = 0;
224+
}
225+
226+
LOG_DBG("OOB Progress Get (%sstarted: %d %%)", dfd_srv_oob_ctx.started ? "" : "not ",
227+
progress);
228+
return progress;
229+
}
230+
#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */
231+
165232
static struct bt_mesh_dfd_srv_cb dfd_srv_cb = {
166233
.recv = dfd_srv_recv,
167234
.del = dfd_srv_del,
168235
.send = dfd_srv_send,
236+
#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD
237+
.start_oob_upload = dfd_srv_start_oob_upload,
238+
.cancel_oob_upload = dfd_srv_cancel_oob_upload,
239+
.oob_progress_get = dfd_srv_oob_progress_get,
240+
#endif
169241
};
170242

171243
static struct bt_mesh_dfd_srv dfd_srv = BT_MESH_DFD_SRV_INIT(&dfd_srv_cb);
244+
245+
#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD
246+
#define SUPPORTED_SCHEME "http"
247+
248+
static void oob_check_handler(struct k_work *work)
249+
{
250+
uint8_t scheme[10];
251+
int i;
252+
int status;
253+
int err;
254+
255+
for (i = 0; i < MIN(dfd_srv_oob_ctx.uri_len, sizeof(scheme)); i++) {
256+
if (IN_RANGE(dfd_srv_oob_ctx.uri[i], 48, 57) || /* DIGIT */
257+
IN_RANGE(dfd_srv_oob_ctx.uri[i], 65, 90) || /* ALPHA UPPER CASE */
258+
IN_RANGE(dfd_srv_oob_ctx.uri[i], 97, 122) || /* ALPHA LOWER CASE */
259+
dfd_srv_oob_ctx.uri[i] == '.' ||
260+
dfd_srv_oob_ctx.uri[i] == '+' ||
261+
dfd_srv_oob_ctx.uri[i] == '-') {
262+
scheme[i] = dfd_srv_oob_ctx.uri[i];
263+
} else {
264+
break;
265+
}
266+
}
267+
268+
if (i == dfd_srv_oob_ctx.uri_len || dfd_srv_oob_ctx.uri[i] != ':') {
269+
status = BT_MESH_DFD_ERR_URI_MALFORMED;
270+
} else if (i != strlen(SUPPORTED_SCHEME) ||
271+
memcmp(scheme, SUPPORTED_SCHEME, strlen(SUPPORTED_SCHEME))) {
272+
status = BT_MESH_DFD_ERR_URI_NOT_SUPPORTED;
273+
} else {
274+
status = BT_MESH_DFD_SUCCESS;
275+
}
276+
277+
err = bt_mesh_dfd_srv_oob_check_complete(&dfd_srv, dfd_srv_oob_ctx.slot, status,
278+
dfd_srv_oob_ctx.fwid, dfd_srv_oob_ctx.fwid_len);
279+
LOG_DBG("OOB check completed (err %d)", err);
280+
}
281+
282+
static void oob_store_handler(struct k_work *work)
283+
{
284+
int err;
285+
286+
err = bt_mesh_dfd_srv_oob_store_complete(&dfd_srv, dfd_srv_oob_ctx.slot, true,
287+
10000, "metadata", 8);
288+
LOG_DBG("OOB store completed (err %d)", err);
289+
}
290+
#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */
172291
#endif
173292

174293
#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV)

0 commit comments

Comments
 (0)