Skip to content
Open
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
18 changes: 15 additions & 3 deletions apps/btshell/src/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2267,6 +2267,7 @@ static const struct parse_arg_kv_pair cmd_keystore_entry_type[] = {
{ "msec", BLE_STORE_OBJ_TYPE_PEER_SEC },
{ "ssec", BLE_STORE_OBJ_TYPE_OUR_SEC },
{ "cccd", BLE_STORE_OBJ_TYPE_CCCD },
{ "csf", BLE_STORE_OBJ_TYPE_PEER_CL_SUP_FEAT },
{ NULL }
};

Expand Down Expand Up @@ -2388,6 +2389,9 @@ cmd_keystore_add(int argc, char **argv)
case BLE_STORE_OBJ_TYPE_CCCD:
rc = ble_store_write_cccd(&value.cccd);
break;
case BLE_STORE_OBJ_TYPE_PEER_CL_SUP_FEAT:
rc = ble_store_write_peer_cl_sup_feat(&value.feat);
break;
default:
rc = ble_store_write(obj_type, &value);
}
Expand All @@ -2396,7 +2400,7 @@ cmd_keystore_add(int argc, char **argv)

#if MYNEWT_VAL(SHELL_CMD_HELP)
static const struct shell_param keystore_add_params[] = {
{"type", "entry type, usage: =<msec|ssec|cccd>"},
{"type", "entry type, usage: =<msec|ssec|cccd|csf>"},
{"addr_type", "usage: =<public|random>"},
{"addr", "usage: =<XX:XX:XX:XX:XX:XX>"},
{"ediv", "usage: =<UINT16>"},
Expand Down Expand Up @@ -2441,7 +2445,7 @@ cmd_keystore_del(int argc, char **argv)

#if MYNEWT_VAL(SHELL_CMD_HELP)
static const struct shell_param keystore_del_params[] = {
{"type", "entry type, usage: =<msec|ssec|cccd>"},
{"type", "entry type, usage: =<msec|ssec|cccd|csf>"},
{"addr_type", "usage: =<public|random>"},
{"addr", "usage: =<XX:XX:XX:XX:XX:XX>"},
{"ediv", "usage: =<UINT16>"},
Expand Down Expand Up @@ -2504,6 +2508,14 @@ cmd_keystore_iterator(int obj_type,
console_printf(" flags: 0x%02x\n", val->cccd.flags);
console_printf(" changed: %d\n", val->cccd.value_changed);
break;
case BLE_STORE_OBJ_TYPE_PEER_CL_SUP_FEAT:

console_printf("Key: ");
console_printf("addr_type=%u ", val->feat.peer_addr.type);
print_addr(val->feat.peer_addr.val);
console_printf("\n");
console_printf("Enabled features: 0x%02x\n", val->feat.peer_cl_sup_feat[0]);
break;
}
return 0;
}
Expand Down Expand Up @@ -2531,7 +2543,7 @@ cmd_keystore_show(int argc, char **argv)

#if MYNEWT_VAL(SHELL_CMD_HELP)
static const struct shell_param keystore_show_params[] = {
{"type", "entry type, usage: =<msec|ssec|cccd>"},
{"type", "entry type, usage: =<msec|ssec|cccd|csf>"},
{NULL, NULL}
};

Expand Down
8 changes: 8 additions & 0 deletions nimble/host/include/host/ble_gatt.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ struct ble_hs_cfg;

/** @} */

/**
* @brief Size of the GATT Client Supported Features characteristic.
*
*/
#define BLE_GATT_CHR_CLI_SUP_FEAT_SZ 1

/** @} */

/*** @client. */
/** Represents a GATT error. */
struct ble_gatt_error {
Expand Down
113 changes: 110 additions & 3 deletions nimble/host/include/host/ble_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <inttypes.h>
#include "nimble/ble.h"
#include "host/ble_gatt.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -40,13 +41,16 @@ extern "C" {
* @{
*/
/** Object type: Our security material. */
#define BLE_STORE_OBJ_TYPE_OUR_SEC 1
#define BLE_STORE_OBJ_TYPE_OUR_SEC 1

/** Object type: Peer security material. */
#define BLE_STORE_OBJ_TYPE_PEER_SEC 2
#define BLE_STORE_OBJ_TYPE_PEER_SEC 2

/** Object type: Client Characteristic Configuration Descriptor. */
#define BLE_STORE_OBJ_TYPE_CCCD 3
#define BLE_STORE_OBJ_TYPE_CCCD 3

/** Object type: Peer Client Supported Features. */
#define BLE_STORE_OBJ_TYPE_PEER_CL_SUP_FEAT 4

/** @} */

Expand Down Expand Up @@ -154,6 +158,33 @@ struct ble_store_value_cccd {
unsigned value_changed:1;
};

/**
* Used as a key for lookups of stored client supported features of specific
* peer. This struct corresponds to the BLE_STORE_OBJ_TYPE_PEER_CL_SUP_FEAT
* store object type.
*/
struct ble_store_key_cl_sup_feat {
/**
* Key by peer identity address;
* peer_addr=BLE_ADDR_NONE means don't key off peer.
*/
ble_addr_t peer_addr;

/** Number of results to skip; 0 means retrieve the first match. */
uint8_t idx;
};

/**
* Represents a stored client supported features of specific peer. This struct
* corresponds to the BLE_STORE_OBJ_TYPE_PEER_CL_SUP_FEAT store object type.
*/
struct ble_store_value_cl_sup_feat {
/** The peer address associated with the stored supported features. */
ble_addr_t peer_addr;
/** Client supported features of a specific peer. */
uint8_t peer_cl_sup_feat[BLE_GATT_CHR_CLI_SUP_FEAT_SZ];
};

/**
* Used as a key for store lookups. This union must be accompanied by an
* object type code to indicate which field is valid.
Expand All @@ -163,6 +194,8 @@ union ble_store_key {
struct ble_store_key_sec sec;
/** Key for Client Characteristic Configuration Descriptor store lookups. */
struct ble_store_key_cccd cccd;
/** Key for Peer Client Supported Features store lookpus. */
struct ble_store_key_cl_sup_feat feat;
};

/**
Expand All @@ -174,6 +207,8 @@ union ble_store_value {
struct ble_store_value_sec sec;
/** Stored Client Characteristic Configuration Descriptor. */
struct ble_store_value_cccd cccd;
/** Stored Client Supported Features. */
struct ble_store_value_cl_sup_feat feat;
};

/** Represents an event associated with the BLE Store. */
Expand Down Expand Up @@ -556,6 +591,60 @@ int ble_store_write_cccd(const struct ble_store_value_cccd *value);
*/
int ble_store_delete_cccd(const struct ble_store_key_cccd *key);

/**
* @brief Reads Client Supported Features value from a storage
*
* This function reads client supported features value from a storage based
* on the provied key and stores the retrieved value in the specified output
* structure.
*
* @param key A pointer to a 'ble_store_key_cl_sup_feat'
* struct representing the key to identify
* Client Supported Features value to be read.
* @param out_value A pointer to a 'ble_store_value_cl_sup_feat'
* struct to store the Client Supported
* Features value read from a storage
*
* @return 0 if the Client Supported Features values was
* successfully read and stored in the
* 'out_value' structure;
* Non-zero on error
*/
int ble_store_read_peer_cl_sup_feat(const struct ble_store_key_cl_sup_feat *key,
struct ble_store_value_cl_sup_feat *out_value);

/**
* @brief Writes a Client Supported Features value to a storage.
*
* This function writes a Client Supported Features value to a storage based on
* the provided value
*
* @param value A pointer to a 'ble_store_value_cl_sup_feat'
* structure representing the Client Supported
* Features value to be written to a storage.
*
* @return 0 if the value was successfully written to
* a storage;
* Non-zero on error.
*/
int ble_store_write_peer_cl_sup_feat(const struct ble_store_value_cl_sup_feat *value);

/**
* @brief Deletes a Client Supported Features value from a storage.
*
* This function deletes a Client Supported Features value from a storage based
* on the provided key.
*
* @param key A pointer to a 'ble_store_key_cl_sup_feat'
* structure identifying the Client Supported
* Features value to be deleted from
* a storage.
*
* @return 0 if the Client Supported Features value was
* successfully written to a storage;
* Non-zero on error.
*/
int ble_store_delete_peer_cl_sup_feat(const struct ble_store_key_cl_sup_feat *key);

/**
* @brief Generates a storage key for a security material entry from its value.
Expand Down Expand Up @@ -587,6 +676,24 @@ void ble_store_key_from_value_sec(struct ble_store_key_sec *out_key,
void ble_store_key_from_value_cccd(struct ble_store_key_cccd *out_key,
const struct ble_store_value_cccd *value);

/**
* @brief Generates a storage key for a Client Supported Features entry from
* its value
*
* This function generates a storage key for a Client Supported Features value
* entry based on the provided value.
*
* @param out_key A pointer to a 'ble_store_key_cl_sup_feat'
* structure where the generated key will be
* stored.
* @param value A pointer to a 'ble_store_value_cl_sup_feat'
* structure containing the Client Supported
* Features value from which the key will be
* generated.
*/
void ble_store_key_from_value_peer_cl_sup_feat(
struct ble_store_key_cl_sup_feat *out_key,
const struct ble_store_value_cl_sup_feat *value);

/**
* @brief Generates a storage key from a value based on the object type.
Expand Down
1 change: 0 additions & 1 deletion nimble/host/src/ble_gatt_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ extern STATS_SECT_DECL(ble_gatts_stats) ble_gatts_stats;

#define BLE_GATT_CHR_DECL_SZ_16 5
#define BLE_GATT_CHR_DECL_SZ_128 19
#define BLE_GATT_CHR_CLI_SUP_FEAT_SZ 1
/**
* For now only 3 bits in first octet are defined
*
Expand Down
Loading
Loading