Lines Matching refs:gmap_cli
64 static void gmap_reset(struct bt_gmap_client *gmap_cli) in gmap_reset() argument
66 if (gmap_cli->conn != NULL) { in gmap_reset()
67 bt_conn_unref(gmap_cli->conn); in gmap_reset()
70 memset(gmap_cli, 0, sizeof(*gmap_cli)); in gmap_reset()
75 struct bt_gmap_client *gmap_cli = &gmap_insts[bt_conn_index(conn)]; in client_by_conn() local
77 if (gmap_cli->conn == conn) { in client_by_conn()
78 return gmap_cli; in client_by_conn()
86 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in disconnected() local
88 if (gmap_cli != NULL) { in disconnected()
89 bt_conn_unref(gmap_cli->conn); in disconnected()
90 gmap_cli->conn = NULL; in disconnected()
98 static void discover_complete(struct bt_gmap_client *gmap_cli) in discover_complete() argument
100 LOG_DBG("conn %p", (void *)gmap_cli->conn); in discover_complete()
102 atomic_clear_bit(gmap_cli->flags, GMAP_CLIENT_FLAG_BUSY); in discover_complete()
105 gmap_cb->discover(gmap_cli->conn, 0, gmap_cli->role, gmap_cli->feat); in discover_complete()
109 static void discover_failed(struct bt_gmap_client *gmap_cli, int err) in discover_failed() argument
111 struct bt_conn *conn = gmap_cli->conn; in discover_failed()
113 gmap_reset(gmap_cli); in discover_failed()
123 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in bgr_feat_read_cb() local
127 __ASSERT(gmap_cli, "no instance for conn %p", (void *)conn); in bgr_feat_read_cb()
137 discover_failed(gmap_cli, err); in bgr_feat_read_cb()
144 gmap_cli->feat.bgr_feat = net_buf_simple_pull_u8(&buf); in bgr_feat_read_cb()
145 LOG_DBG("bgr_feat 0x%02x", gmap_cli->feat.bgr_feat); in bgr_feat_read_cb()
147 discover_complete(gmap_cli); in bgr_feat_read_cb()
152 static int gmap_read_bgr_feat(struct bt_gmap_client *gmap_cli, uint16_t handle) in gmap_read_bgr_feat() argument
154 LOG_DBG("conn %p handle 0x%04x", (void *)gmap_cli->conn, handle); in gmap_read_bgr_feat()
156 memset(&gmap_cli->params.read, 0, sizeof(gmap_cli->params.read)); in gmap_read_bgr_feat()
158 gmap_cli->params.read.func = bgr_feat_read_cb; in gmap_read_bgr_feat()
159 gmap_cli->params.read.handle_count = 1u; in gmap_read_bgr_feat()
160 gmap_cli->params.read.single.handle = handle; in gmap_read_bgr_feat()
161 gmap_cli->params.read.single.offset = 0u; in gmap_read_bgr_feat()
163 return bt_gatt_read(gmap_cli->conn, &gmap_cli->params.read); in gmap_read_bgr_feat()
169 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in bgr_feat_discover_func() local
173 __ASSERT(gmap_cli != NULL, "no instance for conn %p", (void *)conn); in bgr_feat_discover_func()
178 discover_failed(gmap_cli, -ENOENT); in bgr_feat_discover_func()
186 err = gmap_read_bgr_feat(gmap_cli, chrc->value_handle); in bgr_feat_discover_func()
188 discover_failed(gmap_cli, err); in bgr_feat_discover_func()
194 static int gmap_discover_bgr_feat(struct bt_gmap_client *gmap_cli) in gmap_discover_bgr_feat() argument
196 LOG_DBG("conn %p", (void *)gmap_cli->conn); in gmap_discover_bgr_feat()
198 memset(&gmap_cli->params.discover, 0, sizeof(gmap_cli->params.discover)); in gmap_discover_bgr_feat()
200 gmap_cli->params.discover.func = bgr_feat_discover_func; in gmap_discover_bgr_feat()
201 gmap_cli->params.discover.uuid = gmap_bgr_feat_uuid; in gmap_discover_bgr_feat()
202 gmap_cli->params.discover.type = BT_GATT_DISCOVER_CHARACTERISTIC; in gmap_discover_bgr_feat()
203 gmap_cli->params.discover.start_handle = gmap_cli->svc_start_handle; in gmap_discover_bgr_feat()
204 gmap_cli->params.discover.end_handle = gmap_cli->svc_end_handle; in gmap_discover_bgr_feat()
206 return bt_gatt_discover(gmap_cli->conn, &gmap_cli->params.discover); in gmap_discover_bgr_feat()
212 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in bgs_feat_read_cb() local
216 __ASSERT(gmap_cli, "no instance for conn %p", (void *)conn); in bgs_feat_read_cb()
226 discover_failed(gmap_cli, err); in bgs_feat_read_cb()
233 gmap_cli->feat.bgs_feat = net_buf_simple_pull_u8(&buf); in bgs_feat_read_cb()
234 LOG_DBG("bgs_feat 0x%02x", gmap_cli->feat.bgs_feat); in bgs_feat_read_cb()
236 if ((gmap_cli->role & BT_GMAP_ROLE_BGR) != 0) { in bgs_feat_read_cb()
237 err = gmap_discover_bgr_feat(gmap_cli); in bgs_feat_read_cb()
239 discover_complete(gmap_cli); in bgs_feat_read_cb()
245 discover_failed(gmap_cli, err); in bgs_feat_read_cb()
251 static int gmap_read_bgs_feat(struct bt_gmap_client *gmap_cli, uint16_t handle) in gmap_read_bgs_feat() argument
253 LOG_DBG("conn %p handle 0x%04x", (void *)gmap_cli->conn, handle); in gmap_read_bgs_feat()
255 memset(&gmap_cli->params.read, 0, sizeof(gmap_cli->params.read)); in gmap_read_bgs_feat()
257 gmap_cli->params.read.func = bgs_feat_read_cb; in gmap_read_bgs_feat()
258 gmap_cli->params.read.handle_count = 1u; in gmap_read_bgs_feat()
259 gmap_cli->params.read.single.handle = handle; in gmap_read_bgs_feat()
260 gmap_cli->params.read.single.offset = 0u; in gmap_read_bgs_feat()
262 return bt_gatt_read(gmap_cli->conn, &gmap_cli->params.read); in gmap_read_bgs_feat()
268 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in bgs_feat_discover_func() local
272 __ASSERT(gmap_cli != NULL, "no instance for conn %p", (void *)conn); in bgs_feat_discover_func()
277 discover_failed(gmap_cli, -ENOENT); in bgs_feat_discover_func()
285 err = gmap_read_bgs_feat(gmap_cli, chrc->value_handle); in bgs_feat_discover_func()
287 discover_failed(gmap_cli, err); in bgs_feat_discover_func()
293 static int gmap_discover_bgs_feat(struct bt_gmap_client *gmap_cli) in gmap_discover_bgs_feat() argument
295 LOG_DBG("conn %p", (void *)gmap_cli->conn); in gmap_discover_bgs_feat()
297 memset(&gmap_cli->params.discover, 0, sizeof(gmap_cli->params.discover)); in gmap_discover_bgs_feat()
299 gmap_cli->params.discover.func = bgs_feat_discover_func; in gmap_discover_bgs_feat()
300 gmap_cli->params.discover.uuid = gmap_bgs_feat_uuid; in gmap_discover_bgs_feat()
301 gmap_cli->params.discover.type = BT_GATT_DISCOVER_CHARACTERISTIC; in gmap_discover_bgs_feat()
302 gmap_cli->params.discover.start_handle = gmap_cli->svc_start_handle; in gmap_discover_bgs_feat()
303 gmap_cli->params.discover.end_handle = gmap_cli->svc_end_handle; in gmap_discover_bgs_feat()
305 return bt_gatt_discover(gmap_cli->conn, &gmap_cli->params.discover); in gmap_discover_bgs_feat()
311 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in ugt_feat_read_cb() local
315 __ASSERT(gmap_cli, "no instance for conn %p", (void *)conn); in ugt_feat_read_cb()
325 discover_failed(gmap_cli, err); in ugt_feat_read_cb()
332 gmap_cli->feat.ugt_feat = net_buf_simple_pull_u8(&buf); in ugt_feat_read_cb()
333 LOG_DBG("ugt_feat 0x%02x", gmap_cli->feat.ugt_feat); in ugt_feat_read_cb()
335 if ((gmap_cli->role & BT_GMAP_ROLE_BGS) != 0) { in ugt_feat_read_cb()
336 err = gmap_discover_bgs_feat(gmap_cli); in ugt_feat_read_cb()
337 } else if ((gmap_cli->role & BT_GMAP_ROLE_BGR) != 0) { in ugt_feat_read_cb()
338 err = gmap_discover_bgr_feat(gmap_cli); in ugt_feat_read_cb()
340 discover_complete(gmap_cli); in ugt_feat_read_cb()
346 discover_failed(gmap_cli, err); in ugt_feat_read_cb()
352 static int gmap_read_ugt_feat(struct bt_gmap_client *gmap_cli, uint16_t handle) in gmap_read_ugt_feat() argument
354 LOG_DBG("conn %p handle 0x%04x", (void *)gmap_cli->conn, handle); in gmap_read_ugt_feat()
356 memset(&gmap_cli->params.read, 0, sizeof(gmap_cli->params.read)); in gmap_read_ugt_feat()
358 gmap_cli->params.read.func = ugt_feat_read_cb; in gmap_read_ugt_feat()
359 gmap_cli->params.read.handle_count = 1u; in gmap_read_ugt_feat()
360 gmap_cli->params.read.single.handle = handle; in gmap_read_ugt_feat()
361 gmap_cli->params.read.single.offset = 0u; in gmap_read_ugt_feat()
363 return bt_gatt_read(gmap_cli->conn, &gmap_cli->params.read); in gmap_read_ugt_feat()
369 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in ugt_feat_discover_func() local
373 __ASSERT(gmap_cli != NULL, "no instance for conn %p", (void *)conn); in ugt_feat_discover_func()
378 discover_failed(gmap_cli, -ENOENT); in ugt_feat_discover_func()
386 err = gmap_read_ugt_feat(gmap_cli, chrc->value_handle); in ugt_feat_discover_func()
388 discover_failed(gmap_cli, err); in ugt_feat_discover_func()
394 static int gmap_discover_ugt_feat(struct bt_gmap_client *gmap_cli) in gmap_discover_ugt_feat() argument
396 LOG_DBG("conn %p", (void *)gmap_cli->conn); in gmap_discover_ugt_feat()
398 memset(&gmap_cli->params.discover, 0, sizeof(gmap_cli->params.discover)); in gmap_discover_ugt_feat()
400 gmap_cli->params.discover.func = ugt_feat_discover_func; in gmap_discover_ugt_feat()
401 gmap_cli->params.discover.uuid = gmap_ugt_feat_uuid; in gmap_discover_ugt_feat()
402 gmap_cli->params.discover.type = BT_GATT_DISCOVER_CHARACTERISTIC; in gmap_discover_ugt_feat()
403 gmap_cli->params.discover.start_handle = gmap_cli->svc_start_handle; in gmap_discover_ugt_feat()
404 gmap_cli->params.discover.end_handle = gmap_cli->svc_end_handle; in gmap_discover_ugt_feat()
406 return bt_gatt_discover(gmap_cli->conn, &gmap_cli->params.discover); in gmap_discover_ugt_feat()
412 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in ugg_feat_read_cb() local
416 __ASSERT(gmap_cli, "no instance for conn %p", (void *)conn); in ugg_feat_read_cb()
426 discover_failed(gmap_cli, err); in ugg_feat_read_cb()
433 gmap_cli->feat.ugg_feat = net_buf_simple_pull_u8(&buf); in ugg_feat_read_cb()
434 LOG_DBG("ugg_feat 0x%02x", gmap_cli->feat.ugg_feat); in ugg_feat_read_cb()
436 if ((gmap_cli->role & BT_GMAP_ROLE_UGT) != 0) { in ugg_feat_read_cb()
437 err = gmap_discover_ugt_feat(gmap_cli); in ugg_feat_read_cb()
438 } else if ((gmap_cli->role & BT_GMAP_ROLE_BGS) != 0) { in ugg_feat_read_cb()
439 err = gmap_discover_bgs_feat(gmap_cli); in ugg_feat_read_cb()
440 } else if ((gmap_cli->role & BT_GMAP_ROLE_BGR) != 0) { in ugg_feat_read_cb()
441 err = gmap_discover_bgr_feat(gmap_cli); in ugg_feat_read_cb()
443 discover_complete(gmap_cli); in ugg_feat_read_cb()
449 discover_failed(gmap_cli, err); in ugg_feat_read_cb()
455 static int gmap_read_ugg_feat(struct bt_gmap_client *gmap_cli, uint16_t handle) in gmap_read_ugg_feat() argument
457 LOG_DBG("conn %p handle 0x%04x", (void *)gmap_cli->conn, handle); in gmap_read_ugg_feat()
459 memset(&gmap_cli->params.read, 0, sizeof(gmap_cli->params.read)); in gmap_read_ugg_feat()
461 gmap_cli->params.read.func = ugg_feat_read_cb; in gmap_read_ugg_feat()
462 gmap_cli->params.read.handle_count = 1u; in gmap_read_ugg_feat()
463 gmap_cli->params.read.single.handle = handle; in gmap_read_ugg_feat()
464 gmap_cli->params.read.single.offset = 0u; in gmap_read_ugg_feat()
466 return bt_gatt_read(gmap_cli->conn, &gmap_cli->params.read); in gmap_read_ugg_feat()
472 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in ugg_feat_discover_func() local
476 __ASSERT(gmap_cli != NULL, "no instance for conn %p", (void *)conn); in ugg_feat_discover_func()
481 discover_failed(gmap_cli, -ENOENT); in ugg_feat_discover_func()
489 err = gmap_read_ugg_feat(gmap_cli, chrc->value_handle); in ugg_feat_discover_func()
491 discover_failed(gmap_cli, err); in ugg_feat_discover_func()
497 static int gmap_discover_ugg_feat(struct bt_gmap_client *gmap_cli) in gmap_discover_ugg_feat() argument
499 LOG_DBG("conn %p", (void *)gmap_cli->conn); in gmap_discover_ugg_feat()
501 memset(&gmap_cli->params.discover, 0, sizeof(gmap_cli->params.discover)); in gmap_discover_ugg_feat()
503 gmap_cli->params.discover.func = ugg_feat_discover_func; in gmap_discover_ugg_feat()
504 gmap_cli->params.discover.uuid = gmap_ugg_feat_uuid; in gmap_discover_ugg_feat()
505 gmap_cli->params.discover.type = BT_GATT_DISCOVER_CHARACTERISTIC; in gmap_discover_ugg_feat()
506 gmap_cli->params.discover.start_handle = gmap_cli->svc_start_handle; in gmap_discover_ugg_feat()
507 gmap_cli->params.discover.end_handle = gmap_cli->svc_end_handle; in gmap_discover_ugg_feat()
509 return bt_gatt_discover(gmap_cli->conn, &gmap_cli->params.discover); in gmap_discover_ugg_feat()
515 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in role_read_cb() local
519 __ASSERT(gmap_cli, "no instance for conn %p", (void *)conn); in role_read_cb()
529 discover_failed(gmap_cli, err); in role_read_cb()
536 gmap_cli->role = net_buf_simple_pull_u8(&buf); in role_read_cb()
537 LOG_DBG("role 0x%02x", gmap_cli->role); in role_read_cb()
539 if ((gmap_cli->role & BT_GMAP_ROLE_UGG) != 0) { in role_read_cb()
540 err = gmap_discover_ugg_feat(gmap_cli); in role_read_cb()
541 } else if ((gmap_cli->role & BT_GMAP_ROLE_UGT) != 0) { in role_read_cb()
542 err = gmap_discover_ugt_feat(gmap_cli); in role_read_cb()
543 } else if ((gmap_cli->role & BT_GMAP_ROLE_BGS) != 0) { in role_read_cb()
544 err = gmap_discover_bgs_feat(gmap_cli); in role_read_cb()
545 } else if ((gmap_cli->role & BT_GMAP_ROLE_BGR) != 0) { in role_read_cb()
546 err = gmap_discover_bgr_feat(gmap_cli); in role_read_cb()
553 discover_failed(gmap_cli, err); in role_read_cb()
559 static int gmap_read_role(struct bt_gmap_client *gmap_cli, uint16_t handle) in gmap_read_role() argument
561 LOG_DBG("conn %p handle 0x%04x", (void *)gmap_cli->conn, handle); in gmap_read_role()
563 memset(&gmap_cli->params.read, 0, sizeof(gmap_cli->params.read)); in gmap_read_role()
565 gmap_cli->params.read.func = role_read_cb; in gmap_read_role()
566 gmap_cli->params.read.handle_count = 1u; in gmap_read_role()
567 gmap_cli->params.read.single.handle = handle; in gmap_read_role()
568 gmap_cli->params.read.single.offset = 0u; in gmap_read_role()
570 return bt_gatt_read(gmap_cli->conn, &gmap_cli->params.read); in gmap_read_role()
576 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in role_discover_func() local
580 __ASSERT(gmap_cli != NULL, "no instance for conn %p", (void *)conn); in role_discover_func()
585 discover_failed(gmap_cli, -ENOENT); in role_discover_func()
593 err = gmap_read_role(gmap_cli, chrc->value_handle); in role_discover_func()
595 discover_failed(gmap_cli, err); in role_discover_func()
601 static int gmap_discover_role(struct bt_gmap_client *gmap_cli) in gmap_discover_role() argument
603 LOG_DBG("conn %p", (void *)gmap_cli->conn); in gmap_discover_role()
605 memset(&gmap_cli->params.discover, 0, sizeof(gmap_cli->params.discover)); in gmap_discover_role()
607 gmap_cli->params.discover.func = role_discover_func; in gmap_discover_role()
608 gmap_cli->params.discover.uuid = gmap_role_uuid; in gmap_discover_role()
609 gmap_cli->params.discover.type = BT_GATT_DISCOVER_CHARACTERISTIC; in gmap_discover_role()
610 gmap_cli->params.discover.start_handle = gmap_cli->svc_start_handle; in gmap_discover_role()
611 gmap_cli->params.discover.end_handle = gmap_cli->svc_end_handle; in gmap_discover_role()
613 return bt_gatt_discover(gmap_cli->conn, &gmap_cli->params.discover); in gmap_discover_role()
619 struct bt_gmap_client *gmap_cli = client_by_conn(conn); in gmas_discover_func() local
623 __ASSERT(gmap_cli != NULL, "no instance for conn %p", (void *)conn); in gmas_discover_func()
628 discover_failed(gmap_cli, -ENOENT); in gmas_discover_func()
634 gmap_cli->svc_start_handle = attr->handle; in gmas_discover_func()
635 gmap_cli->svc_end_handle = svc->end_handle; in gmas_discover_func()
637 err = gmap_discover_role(gmap_cli); in gmas_discover_func()
639 discover_failed(gmap_cli, err); in gmas_discover_func()
647 struct bt_gmap_client *gmap_cli; in bt_gmap_discover() local
656 gmap_cli = &gmap_insts[bt_conn_index(conn)]; in bt_gmap_discover()
658 if (atomic_test_and_set_bit(gmap_cli->flags, GMAP_CLIENT_FLAG_BUSY)) { in bt_gmap_discover()
664 gmap_reset(gmap_cli); in bt_gmap_discover()
666 gmap_cli->params.discover.func = gmas_discover_func; in bt_gmap_discover()
667 gmap_cli->params.discover.uuid = gmas_uuid; in bt_gmap_discover()
668 gmap_cli->params.discover.type = BT_GATT_DISCOVER_PRIMARY; in bt_gmap_discover()
669 gmap_cli->params.discover.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; in bt_gmap_discover()
670 gmap_cli->params.discover.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; in bt_gmap_discover()
672 err = bt_gatt_discover(conn, &gmap_cli->params.discover); in bt_gmap_discover()
676 atomic_clear_bit(gmap_cli->flags, GMAP_CLIENT_FLAG_BUSY); in bt_gmap_discover()
681 gmap_cli->conn = bt_conn_ref(conn); in bt_gmap_discover()