Lines Matching +full:pre +full:- +full:declared

1 /* gatt.c - Bluetooth GATT Server Tester */
4 * Copyright (c) 2015-2016 Intel Corporation
6 * SPDX-License-Identifier: Apache-2.0
60 /* bt_gatt_attr_next cannot be used on non-registered services */
62 #define LAST_DB_ATTR (server_db + (attr_count - 1))
78 * gatt_buf - cache used by a gatt client (to cache data read/discovered)
103 if ((ccc_values[i].attr != NULL) && (handle == ccc_values[i].attr->handle)) { in ccc_find_by_attr()
108 return -ENOENT; in ccc_find_by_attr()
119 return -ENOENT; in ccc_find_by_ccc()
163 const union uuid *u = CONTAINER_OF(pattern->uuid, union uuid, uuid); in gatt_db_add()
164 size_t uuid_size = u->uuid.type == BT_UUID_TYPE_16 ? sizeof(u->u16) : in gatt_db_add()
165 sizeof(u->u128); in gatt_db_add()
168 if (attr == &server_db[SERVER_MAX_ATTRIBUTES - 1]) { in gatt_db_add()
180 attr->uuid = server_buf_push(uuid_size); in gatt_db_add()
181 memcpy((void *) attr->uuid, &u->uuid, uuid_size); in gatt_db_add()
185 attr->user_data = server_buf_push(user_data_len); in gatt_db_add()
186 memcpy(attr->user_data, pattern->user_data, user_data_len); in gatt_db_add()
189 LOG_DBG("handle 0x%04x", attr->handle); in gatt_db_add()
205 bt_uuid->type = BT_UUID_TYPE_16; in btp2bt_uuid()
207 BT_UUID_16(bt_uuid)->val = sys_le16_to_cpu(le16); in btp2bt_uuid()
210 bt_uuid->type = BT_UUID_TYPE_128; in btp2bt_uuid()
211 memcpy(BT_UUID_128(bt_uuid)->val, uuid, 16); in btp2bt_uuid()
226 tester_set_bit(rp->data, BTP_GATT_READ_SUPPORTED_COMMANDS); in supported_commands()
227 tester_set_bit(rp->data, BTP_GATT_ADD_SERVICE); in supported_commands()
228 tester_set_bit(rp->data, BTP_GATT_ADD_CHARACTERISTIC); in supported_commands()
229 tester_set_bit(rp->data, BTP_GATT_ADD_DESCRIPTOR); in supported_commands()
230 tester_set_bit(rp->data, BTP_GATT_ADD_INCLUDED_SERVICE); in supported_commands()
231 tester_set_bit(rp->data, BTP_GATT_SET_VALUE); in supported_commands()
232 tester_set_bit(rp->data, BTP_GATT_START_SERVER); in supported_commands()
235 tester_set_bit(rp->data, BTP_GATT_SET_ENC_KEY_SIZE); in supported_commands()
236 tester_set_bit(rp->data, BTP_GATT_EXCHANGE_MTU); in supported_commands()
237 tester_set_bit(rp->data, BTP_GATT_DISC_ALL_PRIM); in supported_commands()
238 tester_set_bit(rp->data, BTP_GATT_DISC_PRIM_UUID); in supported_commands()
239 tester_set_bit(rp->data, BTP_GATT_FIND_INCLUDED); in supported_commands()
240 tester_set_bit(rp->data, BTP_GATT_DISC_ALL_CHRC); in supported_commands()
241 tester_set_bit(rp->data, BTP_GATT_DISC_CHRC_UUID); in supported_commands()
244 tester_set_bit(rp->data, BTP_GATT_DISC_ALL_DESC); in supported_commands()
245 tester_set_bit(rp->data, BTP_GATT_READ); in supported_commands()
246 tester_set_bit(rp->data, BTP_GATT_READ_LONG); in supported_commands()
247 tester_set_bit(rp->data, BTP_GATT_READ_MULTIPLE); in supported_commands()
248 tester_set_bit(rp->data, BTP_GATT_WRITE_WITHOUT_RSP); in supported_commands()
249 tester_set_bit(rp->data, BTP_GATT_SIGNED_WRITE_WITHOUT_RSP); in supported_commands()
250 tester_set_bit(rp->data, BTP_GATT_WRITE); in supported_commands()
253 tester_set_bit(rp->data, BTP_GATT_WRITE_LONG); in supported_commands()
254 tester_set_bit(rp->data, BTP_GATT_CFG_NOTIFY); in supported_commands()
255 tester_set_bit(rp->data, BTP_GATT_CFG_INDICATE); in supported_commands()
256 tester_set_bit(rp->data, BTP_GATT_GET_ATTRIBUTES); in supported_commands()
257 tester_set_bit(rp->data, BTP_GATT_GET_ATTRIBUTE_VALUE); in supported_commands()
258 tester_set_bit(rp->data, BTP_GATT_CHANGE_DB); in supported_commands()
259 tester_set_bit(rp->data, BTP_GATT_EATT_CONNECT); in supported_commands()
262 tester_set_bit(rp->data, BTP_GATT_READ_MULTIPLE_VAR); in supported_commands()
263 tester_set_bit(rp->data, BTP_GATT_NOTIFY_MULTIPLE); in supported_commands()
276 (attr_count - svc_attr_count); in register_service()
298 (cmd_len != sizeof(*cp) + cp->uuid_length)) { in add_service()
302 if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { in add_service()
318 switch (cp->type) { in add_service()
332 svc_count--; in add_service()
336 rp->svc_id = sys_cpu_to_le16(attr_svc->handle); in add_service()
358 const struct gatt_value *value = attr->user_data; in read_value()
360 if (tester_test_bit(value->flags, GATT_VALUE_READ_AUTHOR_FLAG)) { in read_value()
364 if ((attr->perm & GATT_PERM_ENC_READ_MASK) && (conn != NULL) && in read_value()
365 (value->enc_key_size > bt_conn_enc_key_size(conn))) { in read_value()
369 return bt_gatt_attr_read(conn, attr, buf, len, offset, value->data, in read_value()
370 value->len); in read_value()
378 ev->handle = sys_cpu_to_le16(handle); in attr_value_changed_ev()
379 ev->data_length = sys_cpu_to_le16(len); in attr_value_changed_ev()
380 memcpy(ev->data, value, len); in attr_value_changed_ev()
390 struct gatt_value *value = attr->user_data; in write_value()
392 if (tester_test_bit(value->flags, GATT_VALUE_WRITE_AUTHOR_FLAG)) { in write_value()
396 if ((attr->perm & GATT_PERM_ENC_WRITE_MASK) && in write_value()
397 (value->enc_key_size > bt_conn_enc_key_size(conn))) { in write_value()
406 if (offset > value->len) { in write_value()
410 if (offset + len > value->len) { in write_value()
414 memcpy(value->data + offset, buf, len); in write_value()
415 value->len = len; in write_value()
418 __ASSERT_NO_MSG(value->len <= 512); in write_value()
420 attr_value_changed_ev(attr->handle, value->data, value->len); in write_value()
446 return -EINVAL; in alloc_characteristic()
451 if (ch->permissions & GATT_PERM_READ_AUTHORIZATION) { in alloc_characteristic()
455 if (!(ch->permissions & GATT_PERM_ENC_READ_MASK)) { in alloc_characteristic()
456 ch->permissions |= BT_GATT_PERM_READ; in alloc_characteristic()
460 if (ch->permissions & GATT_PERM_WRITE_AUTHORIZATION) { in alloc_characteristic()
464 if (!(ch->permissions & GATT_PERM_ENC_WRITE_MASK)) { in alloc_characteristic()
465 ch->permissions |= BT_GATT_PERM_WRITE; in alloc_characteristic()
470 ch->permissions |= BT_GATT_PERM_PREPARE_WRITE; in alloc_characteristic()
474 BT_GATT_ATTRIBUTE(ch->uuid, in alloc_characteristic()
475 ch->permissions & GATT_PERM_MASK, in alloc_characteristic()
482 return -EINVAL; in alloc_characteristic()
485 chrc_data = attr_chrc->user_data; in alloc_characteristic()
486 chrc_data->properties = ch->properties; in alloc_characteristic()
487 chrc_data->uuid = attr_value->uuid; in alloc_characteristic()
489 ch->char_id = attr_chrc->handle; in alloc_characteristic()
502 (cmd_len != sizeof(*cp) + cp->uuid_length)) { in add_characteristic()
506 /* Pre-set char_id */ in add_characteristic()
508 cmd_data.permissions = cp->permissions; in add_characteristic()
509 cmd_data.properties = cp->properties; in add_characteristic()
512 if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { in add_characteristic()
517 if (cp->svc_id) { in add_characteristic()
527 rp->char_id = sys_cpu_to_le16(cmd_data.char_id); in add_characteristic()
549 struct bt_gatt_chrc *chrc = attr->user_data; in add_ccc()
550 struct gatt_value *value = NEXT_DB_ATTR(attr)->user_data; in add_ccc()
559 if (!(chrc->properties & in add_ccc()
577 tester_set_bit(value->flags, GATT_VALUE_CCC_FLAG); in add_ccc()
585 struct bt_gatt_chrc *chrc = attr_chrc->user_data; in add_cep()
589 if (!(chrc->properties & BT_GATT_CHRC_EXT_PROP)) { in add_cep()
612 if (!bt_uuid_cmp(d->uuid, BT_UUID_GATT_CEP)) { in alloc_descriptor()
614 } else if (!bt_uuid_cmp(d->uuid, BT_UUID_GATT_CCC)) { in alloc_descriptor()
619 if (d->permissions & GATT_PERM_READ_AUTHORIZATION) { in alloc_descriptor()
627 if (!(d->permissions & GATT_PERM_ENC_READ_MASK)) { in alloc_descriptor()
628 d->permissions |= BT_GATT_PERM_READ; in alloc_descriptor()
632 if (d->permissions & GATT_PERM_WRITE_AUTHORIZATION) { in alloc_descriptor()
640 if (!(d->permissions & GATT_PERM_ENC_WRITE_MASK)) { in alloc_descriptor()
641 d->permissions |= BT_GATT_PERM_WRITE; in alloc_descriptor()
646 d->permissions |= BT_GATT_PERM_PREPARE_WRITE; in alloc_descriptor()
649 BT_GATT_DESCRIPTOR(d->uuid, in alloc_descriptor()
650 d->permissions & GATT_PERM_MASK, in alloc_descriptor()
656 return -EINVAL; in alloc_descriptor()
659 d->desc_id = attr_desc->handle; in alloc_descriptor()
667 for (tmp = attr; tmp > server_db; tmp--) { in get_base_chrc()
669 if (!bt_uuid_cmp(tmp->uuid, BT_UUID_GATT_PRIMARY) || in get_base_chrc()
670 !bt_uuid_cmp(tmp->uuid, BT_UUID_GATT_SECONDARY)) { in get_base_chrc()
674 if (!bt_uuid_cmp(tmp->uuid, BT_UUID_GATT_CHRC)) { in get_base_chrc()
692 (cmd_len != sizeof(*cp) + cp->uuid_length)) { in add_descriptor()
696 /* Must be declared first svc or at least 3 attrs (svc+char+char val) */ in add_descriptor()
701 /* Pre-set desc_id */ in add_descriptor()
703 cmd_data.permissions = cp->permissions; in add_descriptor()
706 if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { in add_descriptor()
711 if (cp->char_id) { in add_descriptor()
725 rp->desc_id = sys_cpu_to_le16(cmd_data.desc_id); in add_descriptor()
744 return -EINVAL; in alloc_included()
747 attr_incl->user_data = attr; in alloc_included()
749 *included_service_id = attr_incl->handle; in alloc_included()
766 svc_id = sys_le16_to_cpu(cp->svc_id); in add_included()
772 svc = &server_db[svc_id - 1]; in add_included()
775 if (bt_uuid_cmp(svc->uuid, BT_UUID_GATT_PRIMARY) && in add_included()
776 bt_uuid_cmp(svc->uuid, BT_UUID_GATT_SECONDARY)) { in add_included()
784 rp->included_service_id = sys_cpu_to_le16(included_service_id); in add_included()
793 struct bt_gatt_cep *cep_value = attr->user_data; in set_cep_value()
801 cep_value->properties = sys_le16_to_cpu(properties); in set_cep_value()
830 if (!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_CCC)) { in alloc_value()
835 if (!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_CEP)) { in alloc_value()
836 return set_cep_value(attr, data->value, data->len); in alloc_value()
839 value = attr->user_data; in alloc_value()
842 if (!value->len) { in alloc_value()
843 value->data = server_buf_push(data->len); in alloc_value()
844 value->len = data->len; in alloc_value()
848 if (value->len != data->len) { in alloc_value()
852 memcpy(value->data, data->value, value->len); in alloc_value()
855 i = ccc_find_by_attr(attr->handle - 1); in alloc_value()
863 if (tester_test_bit(value->flags, GATT_VALUE_CCC_FLAG) && ccc_value) { in alloc_value()
865 bt_gatt_notify(NULL, attr, value->data, value->len); in alloc_value()
868 indicate_params.data = value->data; in alloc_value()
869 indicate_params.len = value->len; in alloc_value()
890 (cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->len))) { in set_value()
894 attr_id = sys_le16_to_cpu(cp->attr_id); in set_value()
899 /* Pre-set btp_status */ in set_value()
900 cmd_data.value = cp->value; in set_value()
901 cmd_data.len = sys_le16_to_cpu(cp->len); in set_value()
906 /* set value of local attr, corrected by pre set attr handles */ in set_value()
907 status = alloc_value(&server_db[attr_id - server_db[0].handle], in set_value()
926 rp->db_attr_off = sys_cpu_to_le16(0); /* TODO*/ in start_server()
927 rp->db_attr_cnt = svc_attr_count; in start_server()
939 if (!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_PRIMARY) || in set_attr_enc_key_size()
940 !bt_uuid_cmp(attr->uuid, BT_UUID_GATT_SECONDARY) || in set_attr_enc_key_size()
941 !bt_uuid_cmp(attr->uuid, BT_UUID_GATT_INCLUDE)) { in set_attr_enc_key_size()
942 return -EINVAL; in set_attr_enc_key_size()
946 if (!(attr->perm & (GATT_PERM_ENC_READ_MASK | in set_attr_enc_key_size()
948 return -EINVAL; in set_attr_enc_key_size()
951 value = attr->user_data; in set_attr_enc_key_size()
952 value->enc_key_size = key_size; in set_attr_enc_key_size()
965 if (cp->key_size < 0x07 || cp->key_size > 0x0f) { in set_enc_key_size()
969 attr_id = sys_le16_to_cpu(cp->attr_id); in set_enc_key_size()
972 ret = set_attr_enc_key_size(LAST_DB_ATTR, cp->key_size); in set_enc_key_size()
974 /* set value of local attr, corrected by pre set attr handles */ in set_enc_key_size()
975 ret = set_attr_enc_key_size(&server_db[attr_id - in set_enc_key_size()
976 server_db[0].handle], cp->key_size); in set_enc_key_size()
1004 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in exchange_mtu()
1050 data = attr->user_data; in disc_prim_cb()
1052 uuid_length = data->uuid->type == BT_UUID_TYPE_16 ? 2 : 16; in disc_prim_cb()
1061 service->start_handle = sys_cpu_to_le16(attr->handle); in disc_prim_cb()
1062 service->end_handle = sys_cpu_to_le16(data->end_handle); in disc_prim_cb()
1063 service->uuid_length = uuid_length; in disc_prim_cb()
1065 if (data->uuid->type == BT_UUID_TYPE_16) { in disc_prim_cb()
1066 uint16_t u16 = sys_cpu_to_le16(BT_UUID_16(data->uuid)->val); in disc_prim_cb()
1068 memcpy(service->uuid, &u16, uuid_length); in disc_prim_cb()
1070 memcpy(service->uuid, BT_UUID_128(data->uuid)->val, in disc_prim_cb()
1074 rp->services_count++; in disc_prim_cb()
1085 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in disc_all_prim()
1122 (cmd_len != sizeof(*cp) + cp->uuid_length)) { in disc_prim_uuid()
1126 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in disc_prim_uuid()
1131 if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { in disc_prim_uuid()
1177 data = attr->user_data; in find_included_cb()
1179 uuid_length = data->uuid->type == BT_UUID_TYPE_16 ? 2 : 16; in find_included_cb()
1188 included->included_handle = attr->handle; in find_included_cb()
1189 included->service.start_handle = sys_cpu_to_le16(data->start_handle); in find_included_cb()
1190 included->service.end_handle = sys_cpu_to_le16(data->end_handle); in find_included_cb()
1191 included->service.uuid_length = uuid_length; in find_included_cb()
1193 if (data->uuid->type == BT_UUID_TYPE_16) { in find_included_cb()
1194 uint16_t u16 = sys_cpu_to_le16(BT_UUID_16(data->uuid)->val); in find_included_cb()
1196 memcpy(included->service.uuid, &u16, uuid_length); in find_included_cb()
1198 memcpy(included->service.uuid, BT_UUID_128(data->uuid)->val, in find_included_cb()
1202 rp->services_count++; in find_included_cb()
1213 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in find_included()
1223 discover_params.start_handle = sys_le16_to_cpu(cp->start_handle); in find_included()
1224 discover_params.end_handle = sys_le16_to_cpu(cp->end_handle); in find_included()
1256 data = attr->user_data; in disc_chrc_cb()
1258 uuid_length = data->uuid->type == BT_UUID_TYPE_16 ? 2 : 16; in disc_chrc_cb()
1267 chrc->characteristic_handle = sys_cpu_to_le16(attr->handle); in disc_chrc_cb()
1268 chrc->properties = data->properties; in disc_chrc_cb()
1269 chrc->value_handle = sys_cpu_to_le16(attr->handle + 1); in disc_chrc_cb()
1270 chrc->uuid_length = uuid_length; in disc_chrc_cb()
1272 if (data->uuid->type == BT_UUID_TYPE_16) { in disc_chrc_cb()
1273 uint16_t u16 = sys_cpu_to_le16(BT_UUID_16(data->uuid)->val); in disc_chrc_cb()
1275 memcpy(chrc->uuid, &u16, uuid_length); in disc_chrc_cb()
1277 memcpy(chrc->uuid, BT_UUID_128(data->uuid)->val, uuid_length); in disc_chrc_cb()
1280 rp->characteristics_count++; in disc_chrc_cb()
1291 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in disc_all_chrc()
1301 discover_params.start_handle = sys_le16_to_cpu(cp->start_handle); in disc_all_chrc()
1302 discover_params.end_handle = sys_le16_to_cpu(cp->end_handle); in disc_all_chrc()
1328 (cmd_len != sizeof(*cp) + cp->uuid_length)) { in disc_chrc_uuid()
1332 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in disc_chrc_uuid()
1337 if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { in disc_chrc_uuid()
1348 discover_params.start_handle = sys_le16_to_cpu(cp->start_handle); in disc_chrc_uuid()
1349 discover_params.end_handle = sys_le16_to_cpu(cp->end_handle); in disc_chrc_uuid()
1383 uuid_length = attr->uuid->type == BT_UUID_TYPE_16 ? 2 : 16; in disc_all_desc_cb()
1392 descriptor->descriptor_handle = sys_cpu_to_le16(attr->handle); in disc_all_desc_cb()
1393 descriptor->uuid_length = uuid_length; in disc_all_desc_cb()
1395 if (attr->uuid->type == BT_UUID_TYPE_16) { in disc_all_desc_cb()
1396 uint16_t u16 = sys_cpu_to_le16(BT_UUID_16(attr->uuid)->val); in disc_all_desc_cb()
1398 memcpy(descriptor->uuid, &u16, uuid_length); in disc_all_desc_cb()
1400 memcpy(descriptor->uuid, BT_UUID_128(attr->uuid)->val, in disc_all_desc_cb()
1404 rp->descriptors_count++; in disc_all_desc_cb()
1415 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in disc_all_desc()
1425 discover_params.start_handle = sys_le16_to_cpu(cp->start_handle); in disc_all_desc()
1426 discover_params.end_handle = sys_le16_to_cpu(cp->end_handle); in disc_all_desc()
1458 rp->att_response = err; in read_cb()
1475 rp->data_length += length; in read_cb()
1489 rp->att_response = err; in read_uuid_cb()
1501 value.handle = params->by_uuid.start_handle; in read_uuid_cb()
1518 rp->values_count++; in read_uuid_cb()
1529 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in read_data()
1540 read_params.single.handle = sys_le16_to_cpu(cp->handle); in read_data()
1566 (cmd_len != sizeof(*cp) + cp->uuid_length)) { in read_uuid()
1570 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in read_uuid()
1575 if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { in read_uuid()
1587 read_params.by_uuid.start_handle = sys_le16_to_cpu(cp->start_handle); in read_uuid()
1588 read_params.by_uuid.end_handle = sys_le16_to_cpu(cp->end_handle); in read_uuid()
1611 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in read_long()
1622 read_params.single.handle = sys_le16_to_cpu(cp->handle); in read_long()
1623 read_params.single.offset = sys_le16_to_cpu(cp->offset); in read_long()
1650 (cmd_len != sizeof(*cp) + (cp->handles_count * sizeof(cp->handles[0])))) { in read_multiple()
1654 if (cp->handles_count == 0 || cp->handles_count > ARRAY_SIZE(handles)) { in read_multiple()
1658 for (i = 0; i < cp->handles_count; i++) { in read_multiple()
1659 handles[i] = sys_le16_to_cpu(cp->handles[i]); in read_multiple()
1662 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in read_multiple()
1673 read_params.handle_count = cp->handles_count; in read_multiple()
1701 (cmd_len != sizeof(*cp) + (cp->handles_count * sizeof(cp->handles[0])))) { in read_multiple_var()
1705 if (cp->handles_count > ARRAY_SIZE(handles)) { in read_multiple_var()
1710 handles[i] = sys_le16_to_cpu(cp->handles[i]); in read_multiple_var()
1713 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in read_multiple_var()
1750 cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { in write_without_rsp()
1754 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in write_without_rsp()
1759 if (bt_gatt_write_without_response(conn, sys_le16_to_cpu(cp->handle), in write_without_rsp()
1760 cp->data, in write_without_rsp()
1761 sys_le16_to_cpu(cp->data_length), in write_without_rsp()
1778 cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { in write_signed_without_rsp()
1782 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in write_signed_without_rsp()
1787 if (bt_gatt_write_without_response(conn, sys_le16_to_cpu(cp->handle), in write_signed_without_rsp()
1788 cp->data, in write_signed_without_rsp()
1789 sys_le16_to_cpu(cp->data_length), in write_signed_without_rsp()
1814 cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { in write_data()
1818 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in write_data()
1823 write_params.handle = sys_le16_to_cpu(cp->handle); in write_data()
1826 write_params.data = cp->data; in write_data()
1827 write_params.length = sys_le16_to_cpu(cp->data_length); in write_data()
1852 cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { in write_long()
1856 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in write_long()
1861 write_params.handle = sys_le16_to_cpu(cp->handle); in write_long()
1863 write_params.offset = sys_le16_to_cpu(cp->offset); in write_long()
1864 write_params.data = cp->data; in write_long()
1865 write_params.length = sys_le16_to_cpu(cp->data_length); in write_long()
1891 #define MAX_NOTIF_DATA (MIN(BT_L2CAP_RX_MTU, BT_L2CAP_TX_MTU) - 3)
1906 ev->type = (uint8_t)params->value; in notify_func()
1907 ev->handle = sys_cpu_to_le16(params->value_handle); in notify_func()
1911 ev->data_length = sys_cpu_to_le16(length); in notify_func()
1912 memcpy(ev->data, data, length); in notify_func()
1913 bt_addr_le_copy(&ev->address, bt_conn_get_dst(conn)); in notify_func()
1931 if (!subscription->value_handle) { in discover_complete()
1936 subscription->chan_opt = BT_ATT_CHAN_OPT_NONE; in discover_complete()
1944 op = subscription->value == BT_GATT_CCC_NOTIFY ? BTP_GATT_CFG_NOTIFY : in discover_complete()
1971 subscription->value_handle = attr->handle + 1; in discover_func()
1988 return -ENOMEM; in enable_subscription()
1993 return -EBUSY; in enable_subscription()
2003 subscription->ccc_handle = ccc_handle; in enable_subscription()
2004 subscription->value = value; in enable_subscription()
2005 subscription->notify = notify_func; in enable_subscription()
2008 subscription->min_security = bt_conn_get_security(conn); in enable_subscription()
2021 return -EINVAL; in disable_subscription()
2025 return -EBUSY; in disable_subscription()
2038 uint16_t ccc_handle = sys_le16_to_cpu(cp->ccc_handle); in config_subscription_notif()
2041 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in config_subscription_notif()
2046 if (cp->enable) { in config_subscription_notif()
2073 uint16_t ccc_handle = sys_le16_to_cpu(cp->ccc_handle); in config_subscription_ind()
2076 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in config_subscription_ind()
2081 if (cp->enable) { in config_subscription_ind()
2121 (cmd_len != sizeof(*cp) + (cp->cnt * sizeof(cp->attr_id[0])))) { in notify_mult()
2125 if (!IN_RANGE(cp->cnt, min_cnt, max_cnt)) { in notify_mult()
2127 cp->cnt, min_cnt, max_cnt); in notify_mult()
2132 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in notify_mult()
2139 for (uint16_t i = 0U; i < cp->cnt; i++) { in notify_mult()
2140 struct bt_gatt_attr attr = server_db[cp->attr_id[i] - in notify_mult()
2152 err = bt_gatt_notify_multiple(conn, cp->cnt, params); in notify_mult()
2159 LOG_DBG("Send %u notifications", cp->cnt); in notify_mult()
2177 if (foreach->uuid && bt_uuid_cmp(foreach->uuid, attr->uuid)) { in get_attrs_rp()
2182 gatt_attr = net_buf_simple_add(foreach->buf, sizeof(*gatt_attr)); in get_attrs_rp()
2183 gatt_attr->handle = sys_cpu_to_le16(handle); in get_attrs_rp()
2184 gatt_attr->permission = attr->perm; in get_attrs_rp()
2186 if (attr->uuid->type == BT_UUID_TYPE_16) { in get_attrs_rp()
2187 gatt_attr->type_length = 2U; in get_attrs_rp()
2188 net_buf_simple_add_le16(foreach->buf, in get_attrs_rp()
2189 BT_UUID_16(attr->uuid)->val); in get_attrs_rp()
2191 gatt_attr->type_length = 16U; in get_attrs_rp()
2192 net_buf_simple_add_mem(foreach->buf, in get_attrs_rp()
2193 BT_UUID_128(attr->uuid)->val, in get_attrs_rp()
2194 gatt_attr->type_length); in get_attrs_rp()
2197 foreach->count++; in get_attrs_rp()
2207 struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE - sizeof(*rp)); in get_attrs()
2213 (cmd_len != sizeof(*cp) + cp->type_length)) { in get_attrs()
2217 start_handle = sys_le16_to_cpu(cp->start_handle); in get_attrs()
2218 end_handle = sys_le16_to_cpu(cp->end_handle); in get_attrs()
2220 if (cp->type_length) { in get_attrs()
2223 if (btp2bt_uuid(cp->type, cp->type_length, &search_uuid.uuid)) { in get_attrs()
2245 (void)memcpy(rp->attrs, buf->data, buf->len); in get_attrs()
2246 rp->attrs_count = foreach.count; in get_attrs()
2248 *rsp_len = sizeof(*rp) + buf->len; in get_attrs()
2255 if (err < 0 && err >= -0xff) { in err_to_att()
2256 return -err; in err_to_att()
2266 struct net_buf_simple *buf = u_data->buf; in get_attr_val_rp()
2267 struct bt_conn *conn = u_data->conn; in get_attr_val_rp()
2272 rp->value_length = 0x0000; in get_attr_val_rp()
2273 rp->att_response = BT_ATT_ERR_SUCCESS; in get_attr_val_rp()
2278 if (!attr->read) { in get_attr_val_rp()
2279 rp->att_response = BT_ATT_ERR_READ_NOT_PERMITTED; in get_attr_val_rp()
2283 read = attr->read(conn, attr, buf->data + buf->len, to_read, in get_attr_val_rp()
2284 rp->value_length); in get_attr_val_rp()
2286 rp->att_response = err_to_att(read); in get_attr_val_rp()
2290 rp->value_length += read; in get_attr_val_rp()
2297 const struct gatt_value *value = attr->user_data; in get_attr_val_rp()
2299 if ((rp->att_response == BT_ATT_ERR_SUCCESS) && (value->enc_key_size > 0)) { in get_attr_val_rp()
2301 * If attribute has enc_key_size set to non-zero value in get_attr_val_rp()
2309 * set to <16, but is can be of any 7-16 value) in get_attr_val_rp()
2319 if (value->enc_key_size > bt_conn_enc_key_size(conn)) { in get_attr_val_rp()
2320 rp->att_response = BT_ATT_ERR_ENCRYPTION_KEY_SIZE; in get_attr_val_rp()
2323 rp->att_response = BT_ATT_ERR_ENCRYPTION_KEY_SIZE; in get_attr_val_rp()
2336 uint16_t handle = sys_le16_to_cpu(cp->handle); in get_attr_val()
2339 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in get_attr_val()
2347 if (buf->len) { in get_attr_val()
2348 (void)memcpy(rsp, buf->data, buf->len); in get_attr_val()
2349 *rsp_len = buf->len; in get_attr_val()
2374 if (cp->start_handle > 0 || cp->end_handle > 0) { in change_database()
2378 switch (cp->operation) { in change_database()
2420 conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); in eatt_connect()
2425 err = bt_eatt_connect(conn, cp->num_channels); in eatt_connect()