Hello again,
I was trying to add a service/characteristic to the bleprph example, and
thought it would be as simple as:
* add a gatt_svr_chr_access_ function
* add the service definition in gatt_svr_svcs
* increase some configuration values (max_services, max_attrs)
to be safe
Once done, I'm not able to discover services anymore.
Did I miss something?
(Using gcc 4.9.2, and newt 0.9.0)
Thanks
--
Stephane D'Alu
diff -ru repos/apache-mynewt-core/apps/bleprph/src/gatt_svr.c apps/bleprph/src/gatt_svr.c
--- repos/apache-mynewt-core/apps/bleprph/src/gatt_svr.c 2016-05-31 22:33:11.469344349 +0200
+++ apps/bleprph/src/gatt_svr.c 2016-06-01 18:43:38.657289236 +0200
@@ -55,6 +55,9 @@
static uint8_t gatt_svr_nimble_test_write_val;
static int
+gatt_svr_chr_access_zog(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+ union ble_gatt_access_ctxt *ctxt, void *arg);
+static int
gatt_svr_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
union ble_gatt_access_ctxt *ctxt, void *arg);
static int
@@ -64,7 +67,6 @@
gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
uint8_t op, union ble_gatt_access_ctxt *ctxt,
void *arg);
-
static int
gatt_svr_chr_access_bleprph(uint16_t conn_handle, uint16_t attr_handle,
uint8_t op, union ble_gatt_access_ctxt *ctxt,
@@ -106,6 +108,20 @@
},
{
+ /*** Service: Zog. */
+ .type = BLE_GATT_SVC_TYPE_PRIMARY,
+ .uuid128 = BLE_UUID16(0x1111),
+ .characteristics = (struct ble_gatt_chr_def[]) { {
+ /*** Characteristic: Zog. */
+ .uuid128 = BLE_UUID16(0x1112),
+ .access_cb = gatt_svr_chr_access_zog,
+ .flags = BLE_GATT_CHR_F_READ,
+ }, {
+ 0, /* No more characteristics in this service. */
+ } },
+ },
+
+ {
/*** Service: GATT */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid128 = BLE_UUID16(BLE_GATT_SVC_UUID16),
@@ -188,6 +204,30 @@
}
return 0;
+}
+
+static int
+gatt_svr_chr_access_zog(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+ union ble_gatt_access_ctxt *ctxt, void *arg)
+{
+ uint16_t uuid16;
+ static char *zog_name = "ZOG";
+ uuid16 = ble_uuid_128_to_16(ctxt->chr_access.chr->uuid128);
+ assert(uuid16 != 0);
+
+ switch (uuid16) {
+ case 0x1112:
+ assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+ ctxt->chr_access.data = (void *)zog_name;
+ ctxt->chr_access.len = strlen(zog_name);
+ break;
+
+ default:
+ assert(0);
+ break;
+ }
+
+ return 0;
}
static int
diff -ru repos/apache-mynewt-core/apps/bleprph/src/main.c apps/bleprph/src/main.c
--- repos/apache-mynewt-core/apps/bleprph/src/main.c 2016-05-31 22:33:11.469344349 +0200
+++ apps/bleprph/src/main.c 2016-06-01 18:40:50.679768663 +0200
@@ -363,10 +363,10 @@
/* Initialize the BLE host. */
cfg = ble_hs_cfg_dflt;
- cfg.max_hci_bufs = 3;
+ cfg.max_hci_bufs = 5;
cfg.max_connections = 1;
- cfg.max_attrs = 42;
- cfg.max_services = 5;
+ cfg.max_attrs = 50;
+ cfg.max_services = 10;
cfg.max_client_configs = 6;
cfg.max_gattc_procs = 2;
cfg.max_l2cap_chans = 3;