Lines Matching full:ctx
42 struct bt_testlib_att_read_closure *ctx = in att_read_cb() local
45 k_mutex_lock(&ctx->lock, K_FOREVER); in att_read_cb()
47 ctx->att_err = att_err; in att_read_cb()
49 if (!att_err && ctx->result_handle) { in att_read_cb()
51 *ctx->result_handle = params->by_uuid.start_handle; in att_read_cb()
54 if (!att_err && ctx->result_size) { in att_read_cb()
56 *ctx->result_size += read_len; in att_read_cb()
57 if (*ctx->result_size > BT_ATT_MAX_ATTRIBUTE_LEN) { in att_read_cb()
62 if (read_data && ctx->result_data) { in att_read_cb()
64 MIN(read_len, net_buf_simple_tailroom(ctx->result_data)); in att_read_cb()
66 net_buf_simple_add_mem(ctx->result_data, read_data, result_data_size); in att_read_cb()
69 if (!att_err && ctx->att_mtu) { in att_read_cb()
70 *ctx->att_mtu = params->_att_mtu; in att_read_cb()
73 if (ctx->long_read && read_data) { in att_read_cb()
74 /* Don't signal `&ctx->done` */ in att_read_cb()
75 k_mutex_unlock(&ctx->lock); in att_read_cb()
79 k_condvar_signal(&ctx->done); in att_read_cb()
80 k_mutex_unlock(&ctx->lock); in att_read_cb()
84 static int bt_testlib_sync_bt_gatt_read(struct bt_testlib_att_read_closure *ctx) in bt_testlib_sync_bt_gatt_read() argument
92 if (ctx->result_size) { in bt_testlib_sync_bt_gatt_read()
93 *ctx->result_size = 0; in bt_testlib_sync_bt_gatt_read()
96 /* `att_read_cb` is smart and does the right thing based on `ctx`. */ in bt_testlib_sync_bt_gatt_read()
97 ctx->params.func = att_read_cb; in bt_testlib_sync_bt_gatt_read()
100 k_mutex_init(&ctx->lock); in bt_testlib_sync_bt_gatt_read()
101 k_condvar_init(&ctx->done); in bt_testlib_sync_bt_gatt_read()
103 k_mutex_lock(&ctx->lock, K_FOREVER); in bt_testlib_sync_bt_gatt_read()
105 api_err = bt_gatt_read(ctx->conn, &ctx->params); in bt_testlib_sync_bt_gatt_read()
108 k_condvar_wait(&ctx->done, &ctx->lock, K_FOREVER); in bt_testlib_sync_bt_gatt_read()
111 k_mutex_unlock(&ctx->lock); in bt_testlib_sync_bt_gatt_read()
118 __ASSERT_NO_MSG(ctx->att_err >= 0); in bt_testlib_sync_bt_gatt_read()
119 return ctx->att_err; in bt_testlib_sync_bt_gatt_read()
128 struct bt_testlib_att_read_closure ctx = {.result_handle = result_handle, in bt_testlib_att_read_by_type_sync() local
139 IF_ENABLED(CONFIG_BT_EATT, ({ ctx.params.chan_opt = bearer; })) in bt_testlib_att_read_by_type_sync()
145 return bt_testlib_sync_bt_gatt_read(&ctx); in bt_testlib_att_read_by_type_sync()
153 struct bt_testlib_att_read_closure ctx = {}; in bt_testlib_att_read_by_handle_sync() local
155 ctx.att_mtu = result_att_mtu; in bt_testlib_att_read_by_handle_sync()
156 ctx.conn = conn; in bt_testlib_att_read_by_handle_sync()
157 ctx.params.handle_count = 1; in bt_testlib_att_read_by_handle_sync()
158 ctx.params.single.handle = handle; in bt_testlib_att_read_by_handle_sync()
159 ctx.params.single.offset = offset; in bt_testlib_att_read_by_handle_sync()
160 ctx.result_data = result_data; in bt_testlib_att_read_by_handle_sync()
161 ctx.result_size = result_size; in bt_testlib_att_read_by_handle_sync()
162 IF_ENABLED(CONFIG_BT_EATT, (ctx.params.chan_opt = bearer)); in bt_testlib_att_read_by_handle_sync()
168 return bt_testlib_sync_bt_gatt_read(&ctx); in bt_testlib_att_read_by_handle_sync()
177 struct bt_testlib_att_read_closure ctx = {}; in bt_testlib_gatt_long_read() local
179 ctx.att_mtu = result_att_mtu; in bt_testlib_gatt_long_read()
180 ctx.conn = conn; in bt_testlib_gatt_long_read()
181 ctx.long_read = true, ctx.params.handle_count = 1; in bt_testlib_gatt_long_read()
182 ctx.params.single.handle = handle; in bt_testlib_gatt_long_read()
183 ctx.params.single.offset = offset; in bt_testlib_gatt_long_read()
184 ctx.result_data = result_data; in bt_testlib_gatt_long_read()
185 ctx.result_size = &_result_data_size; in bt_testlib_gatt_long_read()
186 IF_ENABLED(CONFIG_BT_EATT, (ctx.params.chan_opt = bearer)); in bt_testlib_gatt_long_read()
192 err = bt_testlib_sync_bt_gatt_read(&ctx); in bt_testlib_gatt_long_read()
213 struct bt_testlib_gatt_discover_service_closure *ctx = in gatt_discover_service_cb() local
216 k_mutex_lock(&ctx->lock, K_FOREVER); in gatt_discover_service_cb()
218 ctx->att_err = attr ? BT_ATT_ERR_SUCCESS : BT_ATT_ERR_ATTRIBUTE_NOT_FOUND; in gatt_discover_service_cb()
220 if (!ctx->att_err) { in gatt_discover_service_cb()
221 if (ctx->result_handle) { in gatt_discover_service_cb()
222 *ctx->result_handle = attr->handle; in gatt_discover_service_cb()
225 if (ctx->result_end_handle) { in gatt_discover_service_cb()
226 *ctx->result_end_handle = 0; in gatt_discover_service_cb()
230 *ctx->result_end_handle = in gatt_discover_service_cb()
236 k_condvar_signal(&ctx->done); in gatt_discover_service_cb()
237 k_mutex_unlock(&ctx->lock); in gatt_discover_service_cb()
259 struct bt_testlib_gatt_discover_service_closure *const ctx = &ctx_val; in bt_testlib_gatt_discover_primary() local
261 k_mutex_init(&ctx->lock); in bt_testlib_gatt_discover_primary()
262 k_condvar_init(&ctx->done); in bt_testlib_gatt_discover_primary()
270 k_mutex_lock(&ctx->lock, K_FOREVER); in bt_testlib_gatt_discover_primary()
272 api_err = bt_gatt_discover(conn, &ctx->params); in bt_testlib_gatt_discover_primary()
275 k_condvar_wait(&ctx->done, &ctx->lock, K_FOREVER); in bt_testlib_gatt_discover_primary()
278 k_mutex_unlock(&ctx->lock); in bt_testlib_gatt_discover_primary()
284 __ASSERT_NO_MSG(ctx->att_err >= 0); in bt_testlib_gatt_discover_primary()
285 return ctx->att_err; in bt_testlib_gatt_discover_primary()
302 struct bt_testlib_gatt_discover_char_closure *ctx = in gatt_discover_char_cb() local
306 k_mutex_lock(&ctx->lock, K_FOREVER); in gatt_discover_char_cb()
308 if (ctx->att_err == BT_ATT_ERR_ATTRIBUTE_NOT_FOUND) { in gatt_discover_char_cb()
313 ctx->att_err = BT_ATT_ERR_SUCCESS; in gatt_discover_char_cb()
314 if (ctx->result_def_handle) { in gatt_discover_char_cb()
315 *ctx->result_def_handle = attr->handle; in gatt_discover_char_cb()
317 if (ctx->result_value_handle) { in gatt_discover_char_cb()
318 *ctx->result_value_handle = in gatt_discover_char_cb()
321 if (ctx->result_end_handle) { in gatt_discover_char_cb()
329 __ASSERT_NO_MSG(ctx->result_end_handle); in gatt_discover_char_cb()
330 *ctx->result_end_handle = (attr->handle - 1); in gatt_discover_char_cb()
335 k_condvar_signal(&ctx->done); in gatt_discover_char_cb()
337 k_mutex_unlock(&ctx->lock); in gatt_discover_char_cb()
366 struct bt_testlib_gatt_discover_char_closure *const ctx = &ctx_val; in bt_testlib_gatt_discover_characteristic() local
368 k_mutex_init(&ctx->lock); in bt_testlib_gatt_discover_characteristic()
369 k_condvar_init(&ctx->done); in bt_testlib_gatt_discover_characteristic()
377 k_mutex_lock(&ctx->lock, K_FOREVER); in bt_testlib_gatt_discover_characteristic()
379 api_err = bt_gatt_discover(conn, &ctx->params); in bt_testlib_gatt_discover_characteristic()
382 k_condvar_wait(&ctx->done, &ctx->lock, K_FOREVER); in bt_testlib_gatt_discover_characteristic()
385 k_mutex_unlock(&ctx->lock); in bt_testlib_gatt_discover_characteristic()
391 __ASSERT_NO_MSG(ctx->att_err >= 0); in bt_testlib_gatt_discover_characteristic()
392 return ctx->att_err; in bt_testlib_gatt_discover_characteristic()