You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/07/11 23:50:08 UTC
[18/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Comments
for GATT server structs.
BLE Host - Comments for GATT server structs.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2997fff8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2997fff8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2997fff8
Branch: refs/heads/ble_hs_api
Commit: 2997fff8aaea5f18482506a609b9d28491fb1d1e
Parents: 81b89f6
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jun 27 18:02:16 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:32 2016 -0700
----------------------------------------------------------------------
net/nimble/host/include/host/ble_gatt.h | 215 +++++++++++++++++++--------
net/nimble/host/src/ble_gatts.c | 4 +
2 files changed, 160 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2997fff8/net/nimble/host/include/host/ble_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gatt.h b/net/nimble/host/include/host/ble_gatt.h
index 76d61cf..d805590 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -25,9 +25,47 @@
struct ble_hs_conn;
struct ble_att_error_rsp;
+#define BLE_GATT_REGISTER_OP_SVC 1
+#define BLE_GATT_REGISTER_OP_CHR 2
+#define BLE_GATT_REGISTER_OP_DSC 3
+
#define BLE_GATT_SVC_UUID16 0x1801
#define BLE_GATT_CHR_SERVICE_CHANGED_UUID16 0x2a05
+#define BLE_GATT_CHR_PROP_BROADCAST 0x01
+#define BLE_GATT_CHR_PROP_READ 0x02
+#define BLE_GATT_CHR_PROP_WRITE_NO_RSP 0x04
+#define BLE_GATT_CHR_PROP_WRITE 0x08
+#define BLE_GATT_CHR_PROP_NOTIFY 0x10
+#define BLE_GATT_CHR_PROP_INDICATE 0x20
+#define BLE_GATT_CHR_PROP_AUTH_SIGN_WRITE 0x40
+#define BLE_GATT_CHR_PROP_EXTENDED 0x80
+
+#define BLE_GATT_ACCESS_OP_READ_CHR 0
+#define BLE_GATT_ACCESS_OP_WRITE_CHR 1
+#define BLE_GATT_ACCESS_OP_READ_DSC 2
+#define BLE_GATT_ACCESS_OP_WRITE_DSC 3
+
+#define BLE_GATT_CHR_F_BROADCAST 0x0001
+#define BLE_GATT_CHR_F_READ 0x0002
+#define BLE_GATT_CHR_F_WRITE_NO_RSP 0x0004
+#define BLE_GATT_CHR_F_WRITE 0x0008
+#define BLE_GATT_CHR_F_NOTIFY 0x0010
+#define BLE_GATT_CHR_F_INDICATE 0x0020
+#define BLE_GATT_CHR_F_AUTH_SIGN_WRITE 0x0040
+#define BLE_GATT_CHR_F_RELIABLE_WRITE 0x0080
+#define BLE_GATT_CHR_F_AUX_WRITE 0x0100
+#define BLE_GATT_CHR_F_READ_ENC 0x0200
+#define BLE_GATT_CHR_F_READ_AUTHEN 0x0400
+#define BLE_GATT_CHR_F_READ_AUTHOR 0x0800
+#define BLE_GATT_CHR_F_WRITE_ENC 0x1000
+#define BLE_GATT_CHR_F_WRITE_AUTHEN 0x2000
+#define BLE_GATT_CHR_F_WRITE_AUTHOR 0x4000
+
+#define BLE_GATT_SVC_TYPE_END 0
+#define BLE_GATT_SVC_TYPE_PRIMARY 1
+#define BLE_GATT_SVC_TYPE_SECONDARY 2
+
/*** @client. */
struct ble_gatt_error {
uint16_t status;
@@ -143,20 +181,6 @@ int ble_gattc_init(void);
/*** @server. */
-#define BLE_GATT_CHR_PROP_BROADCAST 0x01
-#define BLE_GATT_CHR_PROP_READ 0x02
-#define BLE_GATT_CHR_PROP_WRITE_NO_RSP 0x04
-#define BLE_GATT_CHR_PROP_WRITE 0x08
-#define BLE_GATT_CHR_PROP_NOTIFY 0x10
-#define BLE_GATT_CHR_PROP_INDICATE 0x20
-#define BLE_GATT_CHR_PROP_AUTH_SIGN_WRITE 0x40
-#define BLE_GATT_CHR_PROP_EXTENDED 0x80
-
-#define BLE_GATT_ACCESS_OP_READ_CHR 0
-#define BLE_GATT_ACCESS_OP_WRITE_CHR 1
-#define BLE_GATT_ACCESS_OP_READ_DSC 2
-#define BLE_GATT_ACCESS_OP_WRITE_DSC 3
-
struct ble_gatt_access_ctxt;
typedef int ble_gatt_access_fn(uint16_t conn_handle, uint16_t attr_handle,
uint8_t op, struct ble_gatt_access_ctxt *ctxt,
@@ -164,53 +188,79 @@ typedef int ble_gatt_access_fn(uint16_t conn_handle, uint16_t attr_handle,
typedef uint16_t ble_gatt_chr_flags;
-#define BLE_GATT_CHR_F_BROADCAST 0x0001
-#define BLE_GATT_CHR_F_READ 0x0002
-#define BLE_GATT_CHR_F_WRITE_NO_RSP 0x0004
-#define BLE_GATT_CHR_F_WRITE 0x0008
-#define BLE_GATT_CHR_F_NOTIFY 0x0010
-#define BLE_GATT_CHR_F_INDICATE 0x0020
-#define BLE_GATT_CHR_F_AUTH_SIGN_WRITE 0x0040
-#define BLE_GATT_CHR_F_RELIABLE_WRITE 0x0080
-#define BLE_GATT_CHR_F_AUX_WRITE 0x0100
-#define BLE_GATT_CHR_F_READ_ENC 0x0200
-#define BLE_GATT_CHR_F_READ_AUTHEN 0x0400
-#define BLE_GATT_CHR_F_READ_AUTHOR 0x0800
-#define BLE_GATT_CHR_F_WRITE_ENC 0x1000
-#define BLE_GATT_CHR_F_WRITE_AUTHEN 0x2000
-#define BLE_GATT_CHR_F_WRITE_AUTHOR 0x4000
-
struct ble_gatt_chr_def {
- const uint8_t *uuid128; /* NULL if no more characteristics. */
+ /**
+ * Pointer to first element in a uint8_t[16]; use the BLE_UUID16 macro for
+ * 16-bit UUIDs; NULL if there are no more characteristics in the service.
+ */
+ const uint8_t *uuid128;
+
+ /**
+ * Callback that gets executed when this characteristic is read or
+ * written.
+ */
ble_gatt_access_fn *access_cb;
+
+ /** Optional argument for callback. */
void *arg;
+
+ /**
+ * Array of this characteristic's descriptors. NULL if no descriptors.
+ * Do not include CCCD; it gets added automatically if this
+ * characteristic's notify or indicate flag is set.
+ */
struct ble_gatt_dsc_def *descriptors;
+
+ /** Specifies the set of permitted operations for this characteristic. */
ble_gatt_chr_flags flags;
-};
-#define BLE_GATT_SVC_TYPE_END 0
-#define BLE_GATT_SVC_TYPE_PRIMARY 1
-#define BLE_GATT_SVC_TYPE_SECONDARY 2
+ /**
+ * At registration time, this is filled in with the characteristic's value
+ * attribute handle.
+ */
+ uint16_t * const val_handle;
+};
struct ble_gatt_svc_def {
+ /**
+ * One of the following:
+ * o BLE_GATT_SVC_TYPE_PRIMARY - primary service
+ * o BLE_GATT_SVC_TYPE_SECONDARY - secondary service
+ * o 0 - No more services in this array.
+ */
uint8_t type;
+
+ /**
+ * Pointer to first element in a uint8_t[16]; use the BLE_UUID16 macro for
+ * 16-bit UUIDs.
+ */
const uint8_t *uuid128;
- const struct ble_gatt_svc_def **includes; /* Terminated with null. */
+
+ /**
+ * Array of pointers to other service definitions. These services are
+ * reported as "included services" during service discovery. Terminate the
+ * array with NULL.
+ */
+ const struct ble_gatt_svc_def **includes;
+
+ /**
+ * Array of characteristic definitions corresponding to characteristics
+ * belonging to this service.
+ */
const struct ble_gatt_chr_def *characteristics;
};
struct ble_gatt_access_ctxt {
union {
/**
- * Points to the characteristic defintion corresponding to the
- * characteristic being accessed. This is what the app registered at
- * startup.
+ * The characteristic definition corresponding to the characteristic
+ * being accessed. This is what the app registered at startup.
*/
const struct ble_gatt_chr_def *chr;
/**
- * Points to the descriptor defintion corresponding to the descriptor
- * being accessed. This is what the app registered at startup.
+ * The descriptor definition corresponding to the descriptor being
+ * accessed. This is what the app registered at startup.
*/
const struct ble_gatt_dsc_def *dsc;
};
@@ -219,46 +269,93 @@ struct ble_gatt_access_ctxt {
};
struct ble_gatt_dsc_def {
+ /**
+ * The first element in a uint8_t[16]; use the BLE_UUID16 macro for 16-bit
+ * UUIDs; NULL if there are no more descriptors in the characteristic.
+ */
uint8_t *uuid128;
+
+ /** Specifies the set of permitted operations for this descriptor. */
uint8_t att_flags;
+
+ /** Callback that gets executed when the descriptor is read or written. */
ble_gatt_access_fn *access_cb;
+
+ /** Optional argument for callback. */
void *arg;
};
-#define BLE_GATT_REGISTER_OP_SVC 1
-#define BLE_GATT_REGISTER_OP_CHR 2
-#define BLE_GATT_REGISTER_OP_DSC 3
-
-union ble_gatt_register_ctxt;
-typedef void ble_gatt_register_fn(uint8_t op,
- union ble_gatt_register_ctxt *ctxt,
- void *arg);
-
-int ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
- ble_gatt_register_fn *register_cb,
- void *cb_arg);
-void ble_gatts_chr_updated(uint16_t chr_def_handle);
-
+/**
+ * Context passed to the registration callback; represents the GATT service,
+ * characteristic, or descriptor being registered.
+ */
union ble_gatt_register_ctxt {
+ /** Service; valid if op == BLE_GATT_REGISTER_OP_SVC. */
struct {
+ /** The ATT handle of the service definition attribute. */
uint16_t handle;
+
+ /**
+ * The service definition representing the service being
+ * registered.
+ */
const struct ble_gatt_svc_def *svc_def;
} svc;
+ /** Characteristic; valid if op == BLE_GATT_REGISTER_OP_CHR. */
struct {
+ /** The ATT handle of the characteristic definition attribute. */
uint16_t def_handle;
+
+ /** The ATT handle of the characteristic value attribute. */
uint16_t val_handle;
- const struct ble_gatt_svc_def *svc_def;
+
+ /**
+ * The characteristic definition representing the characteristic being
+ * registered.
+ */
const struct ble_gatt_chr_def *chr_def;
+
+ /**
+ * The service definition corresponding to the characteristic's parent
+ * service.
+ */
+ const struct ble_gatt_svc_def *svc_def;
} chr;
+ /** Descriptor; valid if op == BLE_GATT_REGISTER_OP_DSC. */
struct {
- uint16_t dsc_handle;
+ /** The ATT handle of the descriptor definition attribute. */
+ uint16_t handle;
+
+ /**
+ * The descriptor definition corresponding to the descriptor being
+ * registered.
+ */
const struct ble_gatt_dsc_def *dsc_def;
- uint16_t chr_def_handle;
- uint16_t chr_val_handle;
+
+ /**
+ * The characteristic definition corresponding to the descriptor's
+ * parent characteristic.
+ */
const struct ble_gatt_chr_def *chr_def;
+
+ /**
+ * The service definition corresponding to the descriptor's grandparent
+ * service
+ */
+ const struct ble_gatt_svc_def *svc_def;
} dsc;
};
+union ble_gatt_register_ctxt;
+typedef void ble_gatt_register_fn(uint8_t op,
+ union ble_gatt_register_ctxt *ctxt,
+ void *arg);
+
+int ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
+ ble_gatt_register_fn *register_cb,
+ void *cb_arg);
+void ble_gatts_chr_updated(uint16_t chr_def_handle);
+
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2997fff8/net/nimble/host/src/ble_gatts.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatts.c b/net/nimble/host/src/ble_gatts.c
index 320ee65..0665758 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -716,6 +716,10 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
}
BLE_HS_DBG_ASSERT(val_handle == def_handle + 1);
+ if (chr->val_handle != NULL) {
+ *chr->val_handle = val_handle;
+ }
+
if (register_cb != NULL) {
register_ctxt.chr.def_handle = def_handle;
register_ctxt.chr.val_handle = val_handle;