Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimble/gatts: Modify client supported features READ #1661

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions nimble/host/include/host/ble_gatt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,25 @@ int ble_gatts_start(void);
int ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle,
struct os_mbuf *om);

/**
* Gets Client Supported Features for specified connection.
*
* @param conn_handle Connection handle identifying connection for
* which Client Supported Features should be saved
* @param out_supported_feat Client supported features to be returned.
*
* @return 0 on success;
* BLE_HS_ENOTCONN if no matching connection
* was found
* BLE_HS_EINVAL if supplied buffer is empty or
* if any Client Supported Feature was
* attempted to be disabled.
* A BLE host core return code on unexpected
* error.
*
*/
int ble_gatts_peer_cl_sup_feat_get(uint16_t conn_handle, uint8_t *out_supported_feat, uint8_t len);

#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 7 additions & 3 deletions nimble/host/services/gatt/src/ble_svc_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ static int
ble_svc_gatt_cl_sup_feat_access(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg)
{
uint8_t supported_feat;
int rc;

if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
uint8_t supported_feat =
(MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0) << 1 |
(MYNEWT_VAL(BLE_ATT_SVR_NOTIFY_MULTI) == 1) << 2;
rc = ble_gatts_peer_cl_sup_feat_get(conn_handle, &supported_feat, 1);
if (rc != 0) {
return BLE_ATT_ERR_UNLIKELY;
}
os_mbuf_append(ctxt->om, &supported_feat, sizeof(supported_feat));
return 0;
}
Expand Down
29 changes: 29 additions & 0 deletions nimble/host/src/ble_gatts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,35 @@ ble_gatts_chr_updated(uint16_t chr_val_handle)
}
}

int
ble_gatts_peer_cl_sup_feat_get(uint16_t conn_handle, uint8_t *out_supported_feat, uint8_t len)
{
struct ble_hs_conn *conn;
int rc = 0;

if (out_supported_feat == NULL) {
return BLE_HS_EINVAL;
}

ble_hs_lock();
conn = ble_hs_conn_find(conn_handle);
if (conn == NULL) {
rc = BLE_HS_ENOTCONN;
goto done;
}

if (BLE_GATT_CHR_CLI_SUP_FEAT_SZ < len) {
len = BLE_GATT_CHR_CLI_SUP_FEAT_SZ;
}

memcpy(out_supported_feat, conn->bhc_gatt_svr.peer_cl_sup_feat,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should copy no more than N bytes of mentioned length parameter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should copy no more than N bytes of mentioned length parameter

and maybe N should be checked as N < BLE_GATT_CHR_CLI_SUP_FEAT_SZ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with either, if buffer is smaller we can fill just up to its size and ignore rest, currently only 3 bits are defined so it will be 1 for some time anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

sizeof(uint8_t) * len);

done:
ble_hs_unlock();
return rc;
}

int
ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, struct os_mbuf *om)
{
Expand Down
Loading