static int gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg); static int gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg); static const struct ble_gatt_svc_def gatt_svr_svcs[] = { { /*** Alert Notification Service. */ .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid128 = BLE_UUID16(GATT_SVR_SVC_ALERT_UUID), .characteristics = (struct ble_gatt_chr_def[]) { { .uuid128 = BLE_UUID16(GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID), .access_cb = gatt_svr_chr_access_alert, .flags = BLE_GATT_CHR_F_READ, }, { .uuid128 = BLE_UUID16(GATT_SVR_CHR_NEW_ALERT), .access_cb = gatt_svr_chr_access_alert, .flags = BLE_GATT_CHR_F_NOTIFY, }, { .uuid128 = BLE_UUID16(GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID), .access_cb = gatt_svr_chr_access_alert, .flags = BLE_GATT_CHR_F_READ, }, { .uuid128 = BLE_UUID16(GATT_SVR_CHR_UNR_ALERT_STAT_UUID), .access_cb = gatt_svr_chr_access_alert,
static char ble_svc_gap_name[BLE_SVC_GAP_NAME_MAX_LEN + 1] = "nimble"; static uint16_t ble_svc_gap_appearance; static uint8_t ble_svc_gap_privacy_flag; static uint8_t ble_svc_gap_reconnect_addr[6]; static uint8_t ble_svc_gap_pref_conn_params[8]; static int ble_svc_gap_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg); static const struct ble_gatt_svc_def ble_svc_gap_defs[] = { { /*** Service: GAP. */ .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid128 = BLE_UUID16(BLE_SVC_GAP_UUID16), .characteristics = (struct ble_gatt_chr_def[]) { { /*** Characteristic: Device Name. */ .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME), .access_cb = ble_svc_gap_access, .flags = BLE_GATT_CHR_F_READ, }, { /*** Characteristic: Appearance. */ .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_APPEARANCE), .access_cb = ble_svc_gap_access, .flags = BLE_GATT_CHR_F_READ, }, { /*** Characteristic: Peripheral Privacy Flag. */ .uuid128 = BLE_UUID16(BLE_SVC_GAP_CHR_UUID16_PERIPH_PRIV_FLAG), .access_cb = ble_svc_gap_access, .flags = BLE_GATT_CHR_F_READ,
TEST_ASSERT(rc == BLE_HS_EINVAL); /*** Missing UUID. */ struct ble_gatt_svc_def svcs_no_uuid[] = { { .type = BLE_GATT_SVC_TYPE_PRIMARY, }, { .type = BLE_GATT_SVC_TYPE_END, } }; rc = ble_gatts_register_svcs(svcs_no_uuid, NULL, NULL); TEST_ASSERT(rc == BLE_HS_EINVAL); /*** Circular dependency. */ struct ble_gatt_svc_def svcs_circ[] = { { .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid128 = BLE_UUID16(0x1234), .includes = (struct ble_gatt_svc_def*[]) { svcs_circ + 1, NULL }, }, { .type = BLE_GATT_SVC_TYPE_SECONDARY, .uuid128 = BLE_UUID16(0x1234), .includes = (struct ble_gatt_svc_def*[]) { svcs_circ + 0, NULL }, }, { .type = BLE_GATT_SVC_TYPE_END, } }; rc = ble_gatts_register_svcs(svcs_circ, NULL, NULL); TEST_ASSERT(rc == BLE_HS_EINVAL); /*** Success. */ struct ble_gatt_svc_def svcs_good[] = { { .type = BLE_GATT_SVC_TYPE_PRIMARY,
* power. */ #include "../src/ble_hs_hci_priv.h" int8_t ble_svc_tps_tx_power_level; /* Access function */ static int ble_svc_tps_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg); static const struct ble_gatt_svc_def ble_svc_tps_defs[] = { { /*** Service: Tx Power Service. */ .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = BLE_UUID16(BLE_SVC_TPS_UUID16), .characteristics = (struct ble_gatt_chr_def[]) { { /*** Characteristic: Tx Power Level. */ .uuid = BLE_UUID16(BLE_SVC_TPS_CHR_UUID16_TX_POWER_LEVEL), .access_cb = ble_svc_tps_access, .flags = BLE_GATT_CHR_F_READ, }, { 0, /* No more characteristics in this service. */ } }, }, { 0, /* No more services. */ }, };
#include <assert.h> #include "sysinit/sysinit.h" #include "host/ble_hs.h" #include "services/gatt/ble_svc_gatt.h" static int ble_svc_gatt_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg); static const struct ble_gatt_svc_def ble_svc_gatt_defs[] = { { /*** Service: GATT */ .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid128 = BLE_UUID16(BLE_GATT_SVC_UUID16), .characteristics = (struct ble_gatt_chr_def[]) { { .uuid128 = BLE_UUID16(BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16), .access_cb = ble_svc_gatt_access, .flags = BLE_GATT_CHR_F_INDICATE, }, { 0, /* No more characteristics in this service. */ } }, }, { 0, /* No more services. */ }, }; static int
bletest_inc_adv_pkt_num(void) { } static int prphtest_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op, union ble_gatt_access_ctxt *ctxt, void *arg); #define PRPHTEST_SVC1_UUID 0x1234 #define PRPHTEST_SVC2_UUID 0x5678 #define PRPHTEST_CHR1_UUID 0x1111 #define PRPHTEST_CHR2_UUID 0x1112 #define PRPHTEST_CHR3_UUID 0x5555 static const struct ble_gatt_svc_def prphtest_svcs[] = { { /*** Service 0x1234. */ .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid128 = BLE_UUID16(PRPHTEST_SVC1_UUID), .characteristics = (struct ble_gatt_chr_def[]) { { /*** Characteristic 0x1111. */ .uuid128 = BLE_UUID16(PRPHTEST_CHR1_UUID), .access_cb = prphtest_gatt_cb, .flags = 0, }, { /*** Characteristic 0x1112. */ .uuid128 = BLE_UUID16(PRPHTEST_CHR2_UUID), .access_cb = prphtest_gatt_cb, .flags = 0, }, { .uuid128 = NULL, /* No more characteristics in this service. */ } },