/**@brief Function for initializing the services that will be used by the application. * * @details Initialize the Heart Rate, Battery and Device Information services. */ static void services_init(void) { ble_ams_c_init_t ams_init_obj; ble_uuid_t service_uuid; uint32_t err_code; err_code = sd_ble_uuid_vs_add(&ble_ams_base_uuid128, &m_ams_uuid_type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ams_rc_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ams_eu_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ams_ea_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); memset(&ams_init_obj, 0, sizeof(ams_init_obj)); memset(m_apple_message_buffer, 0, MESSAGE_BUFFER_SIZE); ams_init_obj.evt_handler = on_ams_c_evt; ams_init_obj.message_buffer_size = MESSAGE_BUFFER_SIZE; ams_init_obj.p_message_buffer = m_apple_message_buffer; ams_init_obj.error_handler = apple_notification_error_handler; err_code = ble_ams_c_init(&m_ams_c, &ams_init_obj); APP_ERROR_CHECK(err_code); err_code = ble_ams_c_service_load(&m_ams_c); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the Apple Notification Center Service. */ static void service_init(void) { ble_ancs_c_init_t ancs_init_obj; ble_uuid_t service_uuid; uint32_t err_code; err_code = sd_ble_uuid_vs_add(&ble_ancs_base_uuid128, &m_ancs_uuid_type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_cp_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_ns_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_ds_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); memset(&ancs_init_obj, 0, sizeof(ancs_init_obj)); err_code = ble_ancs_c_attr_add(BLE_ANCS_NOTIF_ATTR_ID_TITLE, m_attr_title, ATTR_DATA_SIZE); APP_ERROR_CHECK(err_code); err_code = ble_ancs_c_attr_add(BLE_ANCS_NOTIF_ATTR_ID_SUBTITLE, m_attr_subtitle, ATTR_DATA_SIZE); APP_ERROR_CHECK(err_code); err_code = ble_ancs_c_attr_add(BLE_ANCS_NOTIF_ATTR_ID_MESSAGE, m_attr_message, ATTR_DATA_SIZE); APP_ERROR_CHECK(err_code); err_code = ble_ancs_c_attr_add(BLE_ANCS_NOTIF_ATTR_ID_MESSAGE_SIZE, m_attr_message_size, ATTR_DATA_SIZE); APP_ERROR_CHECK(err_code); err_code = ble_ancs_c_attr_add(BLE_ANCS_NOTIF_ATTR_ID_DATE, m_attr_date, ATTR_DATA_SIZE); APP_ERROR_CHECK(err_code); err_code = ble_ancs_c_attr_add(BLE_ANCS_NOTIF_ATTR_ID_POSITIVE_ACTION_LABEL, m_attr_posaction, ATTR_DATA_SIZE); APP_ERROR_CHECK(err_code); err_code = ble_ancs_c_attr_add(BLE_ANCS_NOTIF_ATTR_ID_NEGATIVE_ACTION_LABEL, m_attr_negaction, ATTR_DATA_SIZE); APP_ERROR_CHECK(err_code); ancs_init_obj.evt_handler = on_ancs_c_evt; ancs_init_obj.error_handler = apple_notification_error_handler; err_code = ble_ancs_c_init(&m_ancs_c, &ancs_init_obj); APP_ERROR_CHECK(err_code); }
uint32_t ble_rcmon_init(ble_rcmon_t * p_rcmon, const ble_rcmon_init_t * p_rcmon_init) { app_trace_log("\r\nrcmon_init\r\n"); uint32_t err_code; ble_uuid_t ble_uuid; // Initialize service structure. p_rcmon->conn_handle = BLE_CONN_HANDLE_INVALID; // Add service. ble_uuid128_t base_uuid = {RCMON_UUID_BASE}; err_code = sd_ble_uuid_vs_add(&base_uuid, &p_rcmon->uuid_type); APP_ERROR_CHECK(err_code); ble_uuid.type = p_rcmon->uuid_type; ble_uuid.uuid = RCMON_UUID_SERVICE; err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_rcmon->service_handle); APP_ERROR_CHECK(err_code); p_rcmon_init->pdata->accelerometer[0] = 1000; p_rcmon_init->pdata->accelerometer[1] = 2000; p_rcmon_init->pdata->accelerometer[2] = 3000; // Add characteristics. err_code = data_char_add(p_rcmon, p_rcmon_init); APP_ERROR_CHECK(err_code); err_code = config_char_add(p_rcmon, p_rcmon_init); APP_ERROR_CHECK(err_code); app_trace_log("added chars\r\n"); return NRF_SUCCESS; }
/**@brief Function for initializing the services that will be used by the application. * * @details Initialize the Heart Rate, Battery and Device Information services. */ static void services_init(void) { uint32_t err_code; ble_dis_init_t dis_init; uint8_t bitcrazeUuidType; const ble_uuid128_t base_uuid128 = { { UUID_BITCRAZE_BASE } }; // Initialize Bitcraze services err_code = sd_ble_uuid_vs_add(&base_uuid128, &bitcrazeUuidType); APP_ERROR_CHECK(err_code); ble_crazyflies_init(bitcrazeUuidType); // Initialize Device Information Service memset(&dis_init, 0, sizeof(dis_init)); ble_srv_ascii_to_utf8(&dis_init.manufact_name_str, MANUFACTURER_NAME); BLE_GAP_CONN_SEC_MODE_SET_OPEN(&dis_init.dis_attr_md.read_perm); BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&dis_init.dis_attr_md.write_perm); err_code = ble_dis_init(&dis_init); APP_ERROR_CHECK(err_code); }
void cch_service_init(ble_cch_t * p_cch_service) { uint32_t err_code; // Variable to hold return codes from library and softdevice functions //Declare 16-bit service and 128-bit base UUIDs and add them to the BLE stack ble_uuid_t service_uuid; ble_uuid128_t base_uuid = BLE_UUID_CCH_BASE_UUID; service_uuid.uuid = BLE_UUID_CCH_SERVICE_UUID; err_code = sd_ble_uuid_vs_add(&base_uuid, &service_uuid.type); APP_ERROR_CHECK(err_code); // Set our service connection handle to default value. I.e. an invalid handle since we are not yet in a connection. p_cch_service->conn_handle = BLE_CONN_HANDLE_INVALID; // Add our service err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &service_uuid, &p_cch_service->service_handle); APP_ERROR_CHECK(err_code); // Call the function our_char_add() to add our new characteristic to the service. cch_char_add(p_cch_service); }
uint32_t ble_nus_c_init(ble_nus_c_t * p_ble_nus_c, ble_nus_c_init_t * p_ble_nus_c_init) { uint32_t err_code; ble_uuid_t uart_uuid; ble_uuid128_t nus_base_uuid = NUS_BASE_UUID; if ((p_ble_nus_c == NULL) || (p_ble_nus_c_init == NULL)) { return NRF_ERROR_NULL; } err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_ble_nus_c->uuid_type); if (err_code != NRF_SUCCESS) { return err_code; } uart_uuid.type = p_ble_nus_c->uuid_type; uart_uuid.uuid = BLE_UUID_NUS_SERVICE; // save the pointer to the ble_uart_c_t struct locally mp_ble_nus_c = p_ble_nus_c; p_ble_nus_c->conn_handle = BLE_CONN_HANDLE_INVALID; p_ble_nus_c->evt_handler = p_ble_nus_c_init->evt_handler; p_ble_nus_c->nus_rx_handle = BLE_GATT_HANDLE_INVALID; p_ble_nus_c->nus_tx_handle = BLE_GATT_HANDLE_INVALID; return ble_db_discovery_evt_register(&uart_uuid, db_discover_evt_handler); }
uint32_t ble_lbs_c_init(ble_lbs_c_t * p_ble_lbs_c, ble_lbs_c_init_t * p_ble_lbs_c_init) { uint32_t err_code; ble_uuid_t lbs_uuid; ble_uuid128_t lbs_base_uuid = {LBS_UUID_BASE}; VERIFY_PARAM_NOT_NULL(p_ble_lbs_c); VERIFY_PARAM_NOT_NULL(p_ble_lbs_c_init); VERIFY_PARAM_NOT_NULL(p_ble_lbs_c_init->evt_handler); p_ble_lbs_c->peer_lbs_db.button_cccd_handle = BLE_GATT_HANDLE_INVALID; p_ble_lbs_c->peer_lbs_db.button_handle = BLE_GATT_HANDLE_INVALID; p_ble_lbs_c->peer_lbs_db.led_handle = BLE_GATT_HANDLE_INVALID; p_ble_lbs_c->conn_handle = BLE_CONN_HANDLE_INVALID; p_ble_lbs_c->evt_handler = p_ble_lbs_c_init->evt_handler; err_code = sd_ble_uuid_vs_add(&lbs_base_uuid, &p_ble_lbs_c->uuid_type); if (err_code != NRF_SUCCESS) { return err_code; } VERIFY_SUCCESS(err_code); lbs_uuid.type = p_ble_lbs_c->uuid_type; lbs_uuid.uuid = LBS_UUID_SERVICE; return ble_db_discovery_evt_register(&lbs_uuid); }
uint32_t initBlePHYSEN(ble_pss_t * p_pss, const ble_pss_init_t * p_pss_init) { /// init BLE physical sensor service uint32_t err_code; ble_uuid_t ble_uuid; // initialize service structure p_pss->evt_handler = p_pss_init->evt_handler; p_pss->conn_handle = BLE_CONN_HANDLE_INVALID; p_pss->is_notification_supported = p_pss_init->support_notification; // add service ble_uuid128_t base_uuid= {PHY_SENSOR_UUID_BASE}; err_code = sd_ble_uuid_vs_add(&base_uuid, &p_pss->uuid_type); if (err_code != NRF_SUCCESS) { return err_code; } ble_uuid.type = p_pss->uuid_type; ble_uuid.uuid = BLE_UUID_PHY_SENSOR_SERVICE; err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_pss->service_handle); if (err_code != NRF_SUCCESS) { return err_code; } // Add physics sensor characteristic return addCharPHYSEN(p_pss, p_pss_init); }
uint32_t ble_nus_c_init(ble_nus_c_t * p_ble_nus_c, ble_nus_c_init_t * p_ble_nus_c_init) { uint32_t err_code; ble_uuid_t uart_uuid; ble_uuid128_t nus_base_uuid = NUS_BASE_UUID; VERIFY_PARAM_NOT_NULL(p_ble_nus_c); VERIFY_PARAM_NOT_NULL(p_ble_nus_c_init); err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_ble_nus_c->uuid_type); VERIFY_SUCCESS(err_code); uart_uuid.type = p_ble_nus_c->uuid_type; uart_uuid.uuid = BLE_UUID_NUS_SERVICE; // save the pointer to the ble_uart_c_t struct locally mp_ble_nus_c = p_ble_nus_c; p_ble_nus_c->conn_handle = BLE_CONN_HANDLE_INVALID; p_ble_nus_c->evt_handler = p_ble_nus_c_init->evt_handler; p_ble_nus_c->nus_rx_handle = BLE_GATT_HANDLE_INVALID; p_ble_nus_c->nus_tx_handle = BLE_GATT_HANDLE_INVALID; return ble_db_discovery_evt_register(&uart_uuid, db_discover_evt_handler); }
void service_doorlock_init(void) { uint32_t err_code; ble_uuid_t ble_uuid; ble_doorlock_t *p_doorlock = &m_doorlock; ble_doorlock_init_t *p_doorlock_init = &m_doorlock_init; m_doorlock_init.lock_control_handler = lock_control_handler; // Initialize service structure p_doorlock->conn_handle = BLE_CONN_HANDLE_INVALID; p_doorlock->lock_control_handler = p_doorlock_init->lock_control_handler; // Add service ble_uuid128_t base_uuid = {DOORLOCK_UUID_BASE}; err_code = sd_ble_uuid_vs_add(&base_uuid, &p_doorlock->uuid_type); APP_ERROR_CHECK(err_code); ble_uuid.type = p_doorlock->uuid_type; ble_uuid.uuid = DOORLOCK_UUID_SERVICE; err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_doorlock->service_handle); APP_ERROR_CHECK(err_code); err_code = lock_char_add(p_doorlock, p_doorlock_init); APP_ERROR_CHECK(err_code); }
uint32_t conn_mw_ble_uuid_vs_add(uint8_t const * const p_rx_buf, uint32_t rx_buf_len, uint8_t * const p_tx_buf, uint32_t * const p_tx_buf_len) { SER_ASSERT_NOT_NULL(p_rx_buf); SER_ASSERT_NOT_NULL(p_tx_buf); SER_ASSERT_NOT_NULL(p_tx_buf_len); ble_uuid128_t uuid; ble_uuid128_t * p_uuid = &uuid; uint8_t uuid_type; uint8_t * p_uuid_type = &uuid_type; uint32_t err_code = NRF_SUCCESS; uint32_t sd_err_code; err_code = ble_uuid_vs_add_req_dec(p_rx_buf, rx_buf_len, &p_uuid, &p_uuid_type); SER_ASSERT(err_code == NRF_SUCCESS, err_code); sd_err_code = sd_ble_uuid_vs_add(p_uuid, p_uuid_type); err_code = ble_uuid_vs_add_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_uuid_type); SER_ASSERT(err_code == NRF_SUCCESS, err_code); return err_code; }
uint32_t ble_acc_init(ble_acc_t * p_acc, const ble_acc_init_t * p_acc_init) { uint32_t err_code; ble_uuid_t ble_uuid; ble_uuid128_t acc_acce_uuid = {{0xAA, 0xCA, 0x55, 0xAC, 0xEE, 0xEF, 0xFE, 0xDE, 0xEE, 0xAF, 0xBE, 0xA0, 0x00, 0x00, 0xA0, 0xEF}}; //nb bytes 12 and 13 are ignored // Initialize service structure p_acc->evt_handler = p_acc_init->evt_handler; p_acc->conn_handle = BLE_CONN_HANDLE_INVALID; p_acc->is_notification_supported = p_acc_init->support_notification; p_acc->accel_level_last = INVALID_accel_LEVEL; // Add service // Add uuid to p_acc struct and add to sd stack err_code = sd_ble_uuid_vs_add(&acc_acce_uuid, &p_acc->uuid_type); if (err_code != NRF_SUCCESS) { return err_code; } ble_uuid.type = p_acc->uuid_type; ble_uuid.uuid = BLE_UUID_TYPE_VENDOR_BEGIN; err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_acc->service_handle); if (err_code != NRF_SUCCESS) { return err_code; } // Add accel level characteristic return accel_level_char_add(p_acc, p_acc_init); }
uint32_t ble_lbs_init(ble_lbs_t * p_lbs, const ble_lbs_init_t * p_lbs_init) { uint32_t err_code; ble_uuid_t ble_uuid; // Initialize service structure. p_lbs->conn_handle = BLE_CONN_HANDLE_INVALID; p_lbs->led_write_handler = p_lbs_init->led_write_handler; // Add service. ble_uuid128_t base_uuid = {LBS_UUID_BASE}; err_code = sd_ble_uuid_vs_add(&base_uuid, &p_lbs->uuid_type); VERIFY_SUCCESS(err_code); ble_uuid.type = p_lbs->uuid_type; ble_uuid.uuid = LBS_UUID_SERVICE; err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_lbs->service_handle); VERIFY_SUCCESS(err_code); // Add characteristics. err_code = button_char_add(p_lbs, p_lbs_init); VERIFY_SUCCESS(err_code); err_code = led_char_add(p_lbs, p_lbs_init); VERIFY_SUCCESS(err_code); return NRF_SUCCESS; }
/***************************************************************************** * Interface functions *****************************************************************************/ uint32_t mesh_gatt_init(uint32_t access_address, uint8_t channel, uint32_t interval_min_ms) { uint32_t error_code; mesh_metadata_char_t md_char; md_char.mesh_access_addr = access_address; md_char.mesh_interval_min_ms = interval_min_ms; md_char.mesh_channel = channel; ble_uuid_t ble_srv_uuid; ble_srv_uuid.type = BLE_UUID_TYPE_BLE; ble_srv_uuid.uuid = MESH_SRV_UUID; error_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_srv_uuid, &m_mesh_service.service_handle); if (error_code != NRF_SUCCESS) { return NRF_ERROR_INTERNAL; } error_code = sd_ble_uuid_vs_add(&m_mesh_base_uuid, &m_mesh_base_uuid_type); if (error_code != NRF_SUCCESS) { return error_code; } error_code = mesh_md_char_add(&md_char); if (error_code != NRF_SUCCESS) { return error_code; } error_code = mesh_value_char_add(); if (error_code != NRF_SUCCESS) { return error_code; } return NRF_SUCCESS; }
uint32_t ble_blinkys_init(ble_blinkys_t * p_blinkys, const ble_blinkys_init_t * p_blinkys_init) { uint32_t err_code; ble_uuid_t ble_uuid; // Initialize service structure p_blinkys->conn_handle = BLE_CONN_HANDLE_INVALID; p_blinkys->write_handler = p_blinkys_init->write_handler; // Add base UUID to softdevice's internal list. ble_uuid128_t base_uuid = {BLINKY_UUID_BASE}; err_code = sd_ble_uuid_vs_add(&base_uuid, &p_blinkys->uuid_type); if (err_code != NRF_SUCCESS) { return err_code; } ble_uuid.type = p_blinkys->uuid_type; ble_uuid.uuid = BLINKY_UUID_SERVICE; err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_blinkys->service_handle); if (err_code != NRF_SUCCESS) { return err_code; } err_code = blinky_char_add(p_blinkys, p_blinkys_init); if (err_code != NRF_SUCCESS) { return err_code; } return NRF_SUCCESS; }
/**@brief Function for initializing the client handling. */ void client_handling_init(void) { uint32_t err_code; uint32_t i; ble_uuid128_t base_uuid = MULTILINK_PERIPHERAL_BASE_UUID; err_code = sd_ble_uuid_vs_add(&base_uuid, &m_base_uuid_type); APP_ERROR_CHECK(err_code); for (i = 0; i < MAX_CLIENTS; i++) { m_client[i].state = IDLE; } m_client_count = 0; db_discovery_init(); // Register with discovery module for the discovery of the service. ble_uuid_t uuid; uuid.type = m_base_uuid_type; uuid.uuid = MULTILINK_PERIPHERAL_SERVICE_UUID; err_code = ble_db_discovery_evt_register(&uuid, db_discovery_evt_handler); APP_ERROR_CHECK(err_code); }
uint32_t ble_achs_init(ble_achs_t * p_achs, const ble_achs_init_t * p_achs_init) { VERIFY_NOT_NULL_PARAM(p_achs); VERIFY_NOT_NULL_PARAM(p_achs_init); uint32_t err_code; ble_uuid_t service_uuid; // Invalidate any previous existing connection handle. p_achs->conn_handle = BLE_CONN_HANDLE_INVALID; service_uuid.uuid = LOCAL_SERVICE_UUID; err_code = sd_ble_uuid_vs_add(&m_base_uuid128, &service_uuid.type); if (err_code != NRF_SUCCESS) { return err_code; } err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &service_uuid, &m_service_handle); if (err_code != NRF_SUCCESS) { return err_code; } err_code = ach_report_char_add(service_uuid.type); if (err_code == NRF_SUCCESS) { m_module_initialized = true; } return err_code; }
/**@brief Function for initializing the client handling. */ void client_handling_init(void) { uint32_t err_code; uint32_t i; //Add the Ms. Pacman base UUID ble_uuid128_t base_uuid = BLE_MS_PACMAN_BASE_UUID; err_code = sd_ble_uuid_vs_add(&base_uuid, &m_base_uuid_type_ms_pacman); APP_ERROR_CHECK(err_code); //Add the Nunchuck base UUID ble_uuid128_t base_uuid_1 = BLE_NUNCHUCK_BASE_UUID; err_code = sd_ble_uuid_vs_add(&base_uuid_1, &m_base_uuid_type_nunchuck); APP_ERROR_CHECK(err_code); for (i = 0; i < MAX_CLIENTS; i++) { m_client[i].state = IDLE; } m_client_count = 0; db_discovery_init(); // Register with discovery module for the discovery of the service. ble_uuid_t uuid; //Register the Ms. Pacman Service with the discover module uuid.type = m_base_uuid_type_ms_pacman; uuid.uuid = BLE_MS_PACMAN_SERVICE_UUID; err_code = ble_db_discovery_evt_register(&uuid, db_discovery_evt_handler); //Register the Nunchuck Service with the discover module uuid.type = m_base_uuid_type_nunchuck; uuid.uuid = BLE_NUNCHUCK_SERVICE_UUID; err_code = ble_db_discovery_evt_register(&uuid, db_discovery_evt_handler); APP_ERROR_CHECK(err_code); }
/**@brief Add version characteristic. * * @param[in] p_vns Version Number Service structure. * @param[in] p_vns_init Information needed to initialize the service. * * @return NRF_SUCCESS on success, otherwise an error code. */ uint32_t version_char_add(ble_vns_t * p_vns, const ble_vns_init_t * p_vns_init) { ble_gatts_char_md_t char_md; ble_gatts_attr_t attr_char_value; ble_uuid_t ble_version_char_uuid; ble_gatts_attr_md_t attr_md; /* The characteristic should be read-able only. This block of code * configures the characteristic's descriptors. */ memset(&char_md, 0, sizeof(char_md)); char_md.char_props.read = 1; char_md.p_char_user_desc = NULL; char_md.p_user_desc_md = NULL; char_md.p_char_pf = NULL; char_md.p_cccd_md = NULL; char_md.p_sccd_md = NULL; /* The attribute is the part of the characteristic that holds data. Here * we configure its metadata to allow open reads. We disallow writes. */ memset(&attr_md, 0, sizeof(attr_md)); BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm); BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm); attr_md.vloc = BLE_GATTS_VLOC_STACK; attr_md.vlen = 1; #if (0) /* Add a vendor specific 128-bit UUID to the BLE stack's table of UUIDs. * In particular, this UUID will be used to identify the acknowledged data * characteristic. An index identifying this new UUID will be stored in * p_vns->config_char_uuid_type. */ ble_uuid128_t base_uuid = VNS_UUID_VERSION_CHAR_BASE; err_code = sd_ble_uuid_vs_add(&base_uuid, &p_vns->version_char_uuid_type); if (err_code != NRF_SUCCESS) { return err_code; } #endif /* Create a more easily used 24-bit UUID from the new vendor-specific * acknowledged data characteristic UUID base and the two TimeLow bytes * that are specific to the acknowledged data characteristic. */ #if (0) ble_version_char_uuid.type = p_vns->version_char_uuid_type; #else ble_version_char_uuid.type = p_vns->service_uuid_type; #endif ble_version_char_uuid.uuid = VNS_UUID_VERSION_CHAR; memset(&attr_char_value, 0, sizeof(attr_char_value)); attr_char_value.p_uuid = &ble_version_char_uuid; attr_char_value.p_attr_md = &attr_md; attr_char_value.init_len = 2; attr_char_value.init_offs = 0; attr_char_value.max_len = 2; attr_char_value.p_value = (uint8_t *)(&p_vns_init->version); return sd_ble_gatts_characteristic_add(p_vns->service_handle, &char_md, &attr_char_value, &p_vns->version_char_handles); }
uint32_t ble_nus_init(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init) { uint32_t err_code; ble_uuid_t ble_uuid; ble_uuid128_t nus_base_uuid = {{0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E}}; if ((p_nus == NULL) || (p_nus_init == NULL)) { return NRF_ERROR_NULL; } // Initialize service structure. p_nus->conn_handle = BLE_CONN_HANDLE_INVALID; p_nus->data_handler = p_nus_init->data_handler; p_nus->is_notification_enabled = false; /**@snippet [Adding proprietary Service to S110 SoftDevice] */ // Add custom base UUID. err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_nus->uuid_type); if (err_code != NRF_SUCCESS) { return err_code; } ble_uuid.type = p_nus->uuid_type; ble_uuid.uuid = BLE_UUID_NUS_SERVICE; // Add service. err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_nus->service_handle); /**@snippet [Adding proprietary Service to S110 SoftDevice] */ if (err_code != NRF_SUCCESS) { return err_code; } // Add RX Characteristic. err_code = rx_char_add(p_nus, p_nus_init); if (err_code != NRF_SUCCESS) { return err_code; } // Add TX Characteristic. err_code = tx_char_add(p_nus, p_nus_init); if (err_code != NRF_SUCCESS) { return err_code; } return NRF_SUCCESS; }
static void service_add(void) { ble_ancs_c_init_t ancs_init_obj; ble_uuid_t service_uuid; uint32_t err_code; bool services_delete; err_code = sd_ble_uuid_vs_add(&ble_ancs_base_uuid128, &m_ancs_uuid_type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_cp_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_ns_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_ds_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); memset(&ancs_init_obj, 0, sizeof(ancs_init_obj)); memset(m_apple_message_buffer, 0, MESSAGE_BUFFER_SIZE); ancs_init_obj.evt_handler = on_ancs_c_evt; ancs_init_obj.message_buffer_size = MESSAGE_BUFFER_SIZE; ancs_init_obj.p_message_buffer = m_apple_message_buffer; ancs_init_obj.error_handler = apple_notification_error_handler; err_code = ble_ancs_c_init(&m_ancs_c, &ancs_init_obj); APP_ERROR_CHECK(err_code); // Clear all discovered and stored services if the "delete all bonds" button is pushed. err_code = bsp_button_is_pressed(BOND_DELETE_ALL_WAKEUP_BUTTON_ID,&(services_delete)); APP_ERROR_CHECK(err_code); if (services_delete) { err_code = ble_ans_c_service_delete(); APP_ERROR_CHECK(err_code); } err_code = ble_ans_c_service_load(&m_ancs_c); APP_ERROR_CHECK(err_code); }
uint32_t ble_ancs_c_init(ble_ancs_c_t * p_ancs, const ble_ancs_c_init_t * p_ancs_init) { uint32_t err_code; //Verify that the parameters needed for to initialize this instance of ANCS are not NULL. VERIFY_PARAM_NOT_NULL(p_ancs); VERIFY_PARAM_NOT_NULL(p_ancs_init); VERIFY_PARAM_NOT_NULL(p_ancs_init->evt_handler); p_ancs->parse_state = COMMAND_ID_AND_NOTIF_UID; p_ancs->p_data_dest = NULL; p_ancs->current_attr_index = 0; p_ancs->evt_handler = p_ancs_init->evt_handler; p_ancs->error_handler = p_ancs_init->error_handler; p_ancs->conn_handle = BLE_CONN_HANDLE_INVALID; p_ancs->service.data_source_cccd.uuid.uuid = BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG; p_ancs->service.notif_source_cccd.uuid.uuid = BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG; // Make sure instance of service is clear. GATT handles inside the service and characteristics are set to @ref BLE_GATT_HANDLE_INVALID. memset(&p_ancs->service, 0, sizeof(ble_ancs_c_service_t)); memset(m_tx_buffer, 0, TX_BUFFER_SIZE); // Assign UUID types. err_code = sd_ble_uuid_vs_add(&ble_ancs_base_uuid128, &p_ancs->service.service.uuid.type); VERIFY_SUCCESS(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_cp_base_uuid128, &p_ancs->service.control_point_char.uuid.type); VERIFY_SUCCESS(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_ns_base_uuid128, &p_ancs->service.notif_source_char.uuid.type); VERIFY_SUCCESS(err_code); err_code = sd_ble_uuid_vs_add(&ble_ancs_ds_base_uuid128, &p_ancs->service.data_source_char.uuid.type); VERIFY_SUCCESS(err_code); // Assign UUID to the service. p_ancs->service.service.uuid.uuid = ANCS_UUID_SERVICE; p_ancs->service.service.uuid.type = p_ancs->service.service.uuid.type; return ble_db_discovery_evt_register(&p_ancs->service.service.uuid); }
uint32_t new_server_nus_init(new_server_t * p_nus, const new_service_nus_init_t * p_nus_init) { uint32_t err_code; ble_uuid_t ble_uuid; ble_uuid128_t nus_base_uuid = NEW_SERVECE_NUS_BASE_UUID; if ((p_nus == NULL) || (p_nus_init == NULL)) { return NRF_ERROR_NULL; } // Initialize the service structure. p_nus->conn_handle = BLE_CONN_HANDLE_INVALID; p_nus->data_handler = p_nus_init->data_handler; p_nus->is_notification_enabled = false; /**@snippet [Adding proprietary Service to S110 SoftDevice] */ // Add a custom base UUID. err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_nus->uuid_type); if (err_code != NRF_SUCCESS) { return err_code; } ble_uuid.type = p_nus->uuid_type; ble_uuid.uuid = NEW_SERVECE_NUS_SERVICE; // Add the service. err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_nus->service_handle); //#if ((DEBUG_UART_EN) && (ENABLE_BLE_DEBUG)) // DbgPrintf("service2_handle=%x\r\n",p_nus->service_handle); //#endif /**@snippet [Adding proprietary Service to S110 SoftDevice] */ if (err_code != NRF_SUCCESS) { return err_code; } // Add the TX Characteristic. err_code = new_service_tx_char_add(p_nus, p_nus_init); if (err_code != NRF_SUCCESS) { return err_code; } // Add the RX Characteristic. err_code = new_service_rx_char_add(p_nus, p_nus_init); if (err_code != NRF_SUCCESS) { return err_code; } return NRF_SUCCESS; }
uint32_t ble_lss_init(ble_lss_t * p_lss, const ble_lss_init_t * p_lss_init) { uint32_t err_code; ble_uuid_t ble_uuid; ble_uuid128_t lss_base_uuid = LSS_BASE_UUID; if ((p_lss == NULL) || (p_lss_init == NULL)) { return NRF_ERROR_NULL; } // Initialize the service structure. p_lss->conn_handle = BLE_CONN_HANDLE_INVALID; p_lss->data_handler = p_lss_init->data_handler; p_lss->is_notification_enabled = false; /**@snippet [Adding proprietary Service to S110 SoftDevice] */ // Add a custom base UUID. err_code = sd_ble_uuid_vs_add(&lss_base_uuid, &p_lss->uuid_type); if (err_code != NRF_SUCCESS) { return err_code; } ble_uuid.type = p_lss->uuid_type; ble_uuid.uuid = BLE_UUID_LSS_SERVICE; // Add the service. err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_lss->service_handle); /**@snippet [Adding proprietary Service to S110 SoftDevice] */ if (err_code != NRF_SUCCESS) { return err_code; } // Add the RX Characteristic. err_code = rx_char_add(p_lss, p_lss_init); if (err_code != NRF_SUCCESS) { return err_code; } // Add the TX Characteristic. err_code = tx_char_add(p_lss, p_lss_init); if (err_code != NRF_SUCCESS) { return err_code; } return NRF_SUCCESS; }
uint32_t ble_dfu_init(ble_dfu_t * p_dfu, ble_dfu_init_t * p_dfu_init) { if ((p_dfu == NULL) || (p_dfu_init == NULL) || (p_dfu_init->evt_handler == NULL)) { return NRF_ERROR_NULL; } p_dfu->conn_handle = BLE_CONN_HANDLE_INVALID; ble_uuid_t service_uuid; uint32_t err_code; const ble_uuid128_t base_uuid128 = { { 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00 } }; service_uuid.uuid = BLE_DFU_SERVICE_UUID; err_code = sd_ble_uuid_vs_add(&base_uuid128, &(service_uuid.type)); VERIFY_SUCCESS(err_code); err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &service_uuid, &(p_dfu->service_handle)); VERIFY_SUCCESS(err_code); p_dfu->uuid_type = service_uuid.type; err_code = dfu_pkt_char_add(p_dfu); VERIFY_SUCCESS(err_code); err_code = dfu_ctrl_pt_add(p_dfu); VERIFY_SUCCESS(err_code); err_code = dfu_rev_char_add(p_dfu, p_dfu_init); VERIFY_SUCCESS(err_code); p_dfu->evt_handler = p_dfu_init->evt_handler; if (p_dfu_init->error_handler != NULL) { p_dfu->error_handler = p_dfu_init->error_handler; } m_is_dfu_service_initialized = true; return NRF_SUCCESS; }
uint32_t ble_led_init(ble_led_t * p_led) { ble_uuid_t service_uuid; uint32_t ret; // check if parameters are correctly set up if (p_led == NULL) { return NRF_ERROR_NULL; } p_led->conn_handle = BLE_CONN_HANDLE_INVALID; // create a custom base BLE uuid for our service (ble_led_service in ascii) const ble_uuid128_t base_uuid128 = { { 0x62, 0x6c, 0x65, 0x5f, 0x6c, 0x65, 0x64, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x00 } }; // setup LED service uuid service_uuid.uuid = BLE_LED_SERVICE_UUID; // add our custom services in BLE stack's table ret = sd_ble_uuid_vs_add(&base_uuid128, &(service_uuid.type)); if (ret != NRF_SUCCESS) { return ret; } // sd led service declaration to the local server ATT table ret = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &service_uuid, &(p_led->service_handle)); if (ret != NRF_SUCCESS) { return ret; } p_led->uuid_type = service_uuid.type; // add LED status Characteristics ret = ble_led_sta_char_add(p_led); if (ret != NRF_SUCCESS) { return ret; } return NRF_SUCCESS; }
uint8_t custom_add_uuid_base(uint8_t const *const p_uuid_base) { ble_uuid128_t base_uuid; uint8_t uuid_type = 0; for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) { base_uuid.uuid128[i] = p_uuid_base[i]; } ASSERT_INT( ERROR_NONE, sd_ble_uuid_vs_add( &base_uuid, &uuid_type ), 0); return uuid_type; }
uint8_t custom_add_uuid_base(uint8_t const * const p_uuid_base) { ble_uuid128_t base_uuid; uint8_t uuid_type = 0; /* Reverse the bytes since ble_uuid128_t is LSB */ for(uint8_t i=0; i<16; i++) { base_uuid.uuid128[i] = p_uuid_base[15-i]; } ASSERT_INT( ERROR_NONE, sd_ble_uuid_vs_add( &base_uuid, &uuid_type ), 0); return uuid_type; }
/**@brief Function for adding the Service. * * @details This function adds the service and the characteristic within it to the local db. * */ static void service_add(void) { ble_uuid_t service_uuid; uint32_t err_code; service_uuid.uuid = LOCAL_SERVICE_UUID; err_code = sd_ble_uuid_vs_add(&m_base_uuid128, &service_uuid.type); APP_ERROR_CHECK(err_code); err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &service_uuid, &m_service_handle); APP_ERROR_CHECK(err_code); // Add characteristics char_add(service_uuid.type); }
uint32_t ble_si7021_init(ble_si7021_t * p_si7021, const ble_si7021_init_t * p_si7021_init) { uint32_t err_code; ble_uuid_t ble_uuid; // Initialize service structure. p_si7021->conn_handle = BLE_CONN_HANDLE_INVALID; p_si7021->evt_handler = p_si7021_init->evt_handler; p_si7021->last_humraw = 0; p_si7021->last_tempraw = 0; p_si7021->running = 0; p_si7021->interval = 1000; // i.e. 1000ms // Add a Vendor Specific UUID 128-Bit ble_uuid128_t base_uuid = {BLE_si7021_UUID_BASE}; err_code = sd_ble_uuid_vs_add(&base_uuid, &p_si7021->uuid_type); if (err_code != NRF_SUCCESS) { return err_code; } ble_uuid.type = p_si7021->uuid_type; ble_uuid.uuid = BLE_si7021_UUID_SERVICE; // Add a service declaration to the Attribute Table err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_si7021->service_handle); if (err_code != NRF_SUCCESS) { return err_code; } NRF_LOG_DEBUG("sd_ble_gatts_service_add %x,%x\n\r",p_si7021->conn_handle,p_si7021->value_char_handles.value_handle); // err_code = ble_si7021_com_char_add(p_si7021, p_si7021_init); if (err_code != NRF_SUCCESS) { return err_code; } NRF_LOG_DEBUG("ble_si7021_com_char_add %x,%x\n\r",p_si7021->conn_handle,p_si7021->com_char_handles.value_handle); // err_code = ble_si7021_value_char_add(p_si7021, p_si7021_init); if (err_code != NRF_SUCCESS) { return err_code; } NRF_LOG_DEBUG("ble_si7021_value_char_add %x,%x\n\r",p_si7021->conn_handle,p_si7021->value_char_handles.value_handle); return NRF_SUCCESS; }