Ejemplo n.º 1
0
uint32_t ble_bas_init(ble_bas_t * p_bas, const ble_bas_init_t * p_bas_init)
{
    if (p_bas == NULL || p_bas_init == NULL)
    {
        return NRF_ERROR_NULL;
    }

    uint32_t   err_code;
    ble_uuid_t ble_uuid;

    // Initialize service structure
    p_bas->evt_handler               = p_bas_init->evt_handler;
    p_bas->conn_handle               = BLE_CONN_HANDLE_INVALID;
    p_bas->is_notification_supported = p_bas_init->support_notification;
    p_bas->battery_level_last        = INVALID_BATTERY_LEVEL;

    // Add service
    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_BATTERY_SERVICE);

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_bas->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    // Add battery level characteristic
    return battery_level_char_add(p_bas, p_bas_init);
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
uint32_t ble_qodome_init(void)
{
    uint32_t   err_code;
    ble_uuid_t ble_uuid;
    // Initialize service structure
    ble_qodome_t  * p_qodome = &m_qodome;

    p_qodome->conn_handle = BLE_CONN_HANDLE_INVALID;
    // Add service
    BLE_UUID_BLE_ASSIGN(ble_uuid, QODOME_PUBLIC_SERVICE);

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_qodome->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    // Add memory dump characteristic
    err_code = hts_qodome_char_add(p_qodome);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    return NRF_SUCCESS;
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
/*****************************************************************************
 * 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;
}
Ejemplo n.º 6
0
uint32_t ble_bps_init(ble_bps_t * p_bps, const ble_bps_init_t * p_bps_init)
{
    uint32_t   err_code;
    ble_uuid_t ble_uuid;

    // Initialize service structure
    p_bps->evt_handler = p_bps_init->evt_handler;
    p_bps->conn_handle = BLE_CONN_HANDLE_INVALID;
    p_bps->feature     = p_bps_init->feature;

    // Add service
    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_BLOOD_PRESSURE_SERVICE);

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_bps->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    // Add measurement characteristic
    err_code = bps_measurement_char_add(p_bps, p_bps_init);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    // Add feature characteristic
    err_code = bps_feature_char_add(p_bps, p_bps_init);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    return NRF_SUCCESS;
}
Ejemplo n.º 7
0
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;
}
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;
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 10
0
uint32_t conn_mw_ble_gatts_service_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);

    uint8_t      type;
    ble_uuid_t   uuid   = {0};
    ble_uuid_t * p_uuid = &uuid;
    uint16_t     handle;
    uint16_t *   p_handle = &handle;

    uint32_t err_code = NRF_SUCCESS;
    uint32_t sd_err_code;

    err_code = ble_gatts_service_add_req_dec(p_rx_buf, rx_buf_len, &type, &p_uuid, &p_handle);
    SER_ASSERT(err_code == NRF_SUCCESS, err_code);

    sd_err_code = sd_ble_gatts_service_add(type, p_uuid, p_handle);

    err_code = ble_gatts_service_add_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_handle);
    SER_ASSERT(err_code == NRF_SUCCESS, err_code);

    return err_code;
}
Ejemplo n.º 11
0
// Function for initializing the Light Control Service
uint32_t ble_lc_init(ble_lc_t * p_lc, const ble_lc_init_t * p_lc_init, ble_uuid_t * ble_uuid_service, ble_uuid_t * ble_uuid_char_status, ble_uuid_t * ble_uuid_char_cmd)
{
	uint32_t err_code;
	
	// Initialize service structure
	p_lc->conn_handle								= BLE_CONN_HANDLE_INVALID;
	p_lc->data_handler_cmd					= p_lc_init->data_handler_cmd;
	p_lc->data_handler_status				= p_lc_init->data_handler_status;
	p_lc->is_notification_enabled		= false;
	
	// Add the Light Control service
	err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
																			ble_uuid_service,
																			&p_lc->service_handle);
	if (err_code != NRF_SUCCESS)
  {
			return err_code;
  }
	
	// Add the Light Status characteristic
	err_code = light_status_char_add(p_lc, p_lc_init, ble_uuid_char_status);
	if (err_code != NRF_SUCCESS)
  {
			return err_code;
  }
	
	// Add the Light Command characteristic
	err_code = light_cmd_char_add(p_lc, p_lc_init, ble_uuid_char_cmd);
	if (err_code != NRF_SUCCESS)
  {
			return err_code;
  }
	
	return NRF_SUCCESS;	
}
Ejemplo n.º 12
0
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;
}
Ejemplo n.º 13
0
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;
}
Ejemplo n.º 14
0
uint32_t ble_ias_init(ble_ias_t * p_ias, const ble_ias_init_t * p_ias_init)
{
    uint32_t   err_code;
    ble_uuid_t ble_uuid;

    // Initialize service structure
    if (p_ias_init->evt_handler == NULL)
    {
        return NRF_ERROR_INVALID_PARAM;
    }
    p_ias->evt_handler = p_ias_init->evt_handler;

    // Add service
    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_IMMEDIATE_ALERT_SERVICE);

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                        &ble_uuid,
                                        &p_ias->service_handle);

    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    // Add alert level characteristic
    return alert_level_char_add(p_ias);
}
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);
}
Ejemplo n.º 16
0
uint32_t ble_cscs_init(ble_cscs_t * p_cscs, const ble_cscs_init_t * p_cscs_init)
{
    uint32_t   err_code;
    ble_uuid_t ble_uuid;
    ble_cs_ctrlpt_init_t sc_ctrlpt_init;

    // Initialize service structure
    p_cscs->evt_handler = p_cscs_init->evt_handler;
    p_cscs->conn_handle = BLE_CONN_HANDLE_INVALID;
    p_cscs->feature     = p_cscs_init->feature;

    // Add service
    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_CYCLING_SPEED_AND_CADENCE);

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                        &ble_uuid,
                                        &p_cscs->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    // Add cycling speed and cadence measurement characteristic
    err_code = csc_measurement_char_add(p_cscs, p_cscs_init);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    // Add cycling speed and cadence feature characteristic
    err_code = csc_feature_char_add(p_cscs, p_cscs_init);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    // Add Sensor Location characteristic (optional)
    if (p_cscs_init->sensor_location != NULL)
    {
        err_code = csc_sensor_loc_char_add(p_cscs, p_cscs_init);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    }


    //Add speed and cadence control point characteristic
    sc_ctrlpt_init.error_handler                 = p_cscs_init->error_handler;
    sc_ctrlpt_init.size_list_supported_locations = p_cscs_init->size_list_supported_locations;
    sc_ctrlpt_init.supported_functions           = p_cscs_init->ctrplt_supported_functions;
    sc_ctrlpt_init.evt_handler                   = p_cscs_init->ctrlpt_evt_handler;
    sc_ctrlpt_init.list_supported_locations      = p_cscs_init->list_supported_locations;
    sc_ctrlpt_init.sc_ctrlpt_attr_md             = p_cscs_init->csc_ctrlpt_attr_md;
    sc_ctrlpt_init.sensor_location_handle        = p_cscs->sensor_loc_handles.value_handle;
    sc_ctrlpt_init.service_handle                = p_cscs->service_handle;

    return ble_sc_ctrlpt_init(&p_cscs->ctrl_pt, &sc_ctrlpt_init);
}
Ejemplo n.º 17
0
ble_error_t nRF51GattServer::addService(GattService &service)
{
    /* ToDo: Make sure we don't overflow the array, etc. */
    /* ToDo: Make sure this service UUID doesn't already exist (?) */
    /* ToDo: Basic validation */

    /* Add the service to the nRF51 */
    ble_uuid_t nordicUUID;
    nordicUUID = custom_convert_to_nordic_uuid(service.getUUID());

    uint16_t serviceHandle;
    // ASSERT( ERROR_NONE ==      //_modify
            // sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                     // &nordicUUID,
                                     // &serviceHandle),
            // BLE_ERROR_PARAM_OUT_OF_RANGE );
    nrf_err_check(sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                     &nordicUUID,
                                     &serviceHandle) );        
            
    service.setHandle(serviceHandle);

    /* Add characteristics to the service */
    for (uint8_t i = 0; i < service.getCharacteristicCount(); i++) {
        GattCharacteristic *p_char = service.getCharacteristic(i);

        nordicUUID = custom_convert_to_nordic_uuid(p_char->getUUID());

        // ASSERT ( ERROR_NONE ==    //_modify
                 // custom_add_in_characteristic(service.getHandle(),
                                              // &nordicUUID,
                                              // p_char->getProperties(),
                                              // NULL,
                                              // p_char->getInitialLength(),
                                              // p_char->getMaxLength(),
                                              // &nrfCharacteristicHandles[characteristicCount]),
                 // BLE_ERROR_PARAM_OUT_OF_RANGE );
        nrf_err_check(custom_add_in_characteristic(service.getHandle(),
                                              &nordicUUID,
                                              p_char->getProperties(),
                                              NULL,
                                              p_char->getInitialLength(),
                                              p_char->getMaxLength(),
                                              &nrfCharacteristicHandles[characteristicCount]));
                 
        /* Update the characteristic handle */
        uint16_t charHandle = characteristicCount;
        p_characteristics[characteristicCount++] = p_char;

        p_char->setHandle(charHandle);
        if ((p_char->getValuePtr() != NULL) && (p_char->getInitialLength() > 0)) {
            updateValue(charHandle, p_char->getValuePtr(), p_char->getInitialLength(), false /* localOnly */);
        }
    }

    serviceCount++;

    return BLE_ERROR_NONE;
}
/**@brief Function for decoding a command packet with RPC_SD_BLE_GATTS_SERVICE_ADD opcode.
 *
 * This function will decode the command, call the BLE Stack API, and also send command response
 * to the peer through the the transport layer.
 *
 * @param[in] p_command         The encoded structure that needs to be decoded and passed on
 *                              to the BLE Stack API.
 * @param[in] command_len       The length of the encoded command read from transport layer.
 *
 * @retval NRF_SUCCESS               If the decoding of the command was successful, the SoftDevice
 *                                   API was called, and the command response was sent to peer,
 *                                   otherwise an error code.
 * @retval NRF_ERROR_INVALID_LENGTH  If the content length of the packet is not conforming to the
 *                                   codec specification.
 */
static uint32_t gatts_service_add_handle(const uint8_t * const p_command, uint32_t command_len)
{
    uint8_t      type;
    uint16_t *   p_handle;
    uint32_t     err_code;
    ble_uuid_t   uuid;
    ble_uuid_t * p_uuid;
    uint8_t      resp_data[sizeof(uint16_t)];

    uint32_t index  = 0;
    uint16_t handle = 0;

    type = p_command[index++];
    RPC_DECODER_LENGTH_CHECK(command_len, index, SD_BLE_GATTS_SERVICE_ADD);

    // Service UUID field is present.
    if (p_command[index++] == RPC_BLE_FIELD_PRESENT)
    {
        uuid.uuid = uint16_decode(&p_command[index]);
        index    += sizeof(uint16_t);
        uuid.type = p_command[index++];
        p_uuid    = &uuid;
        RPC_DECODER_LENGTH_CHECK(command_len, index, SD_BLE_GATTS_SERVICE_ADD);
    }
    else
    {
        RPC_DECODER_LENGTH_CHECK(command_len, index, SD_BLE_GATTS_SERVICE_ADD);
        p_uuid = NULL;
    }

    // Handle present.
    if (p_command[index++] == RPC_BLE_FIELD_PRESENT)
    {
        p_handle = &handle;
    }
    else
    {
        p_handle = NULL;
    }

    RPC_DECODER_LENGTH_CHECK(command_len, index, SD_BLE_GATTS_SERVICE_ADD);

    err_code = sd_ble_gatts_service_add(type, p_uuid, p_handle);

    if (err_code == NRF_SUCCESS)
    {
        UNUSED_VARIABLE(uint16_encode(handle, resp_data));
        return ble_rpc_cmd_resp_data_send(SD_BLE_GATTS_SERVICE_ADD,
                                          err_code,
                                          resp_data,
                                          sizeof(resp_data));
    }
    else
    {
        return ble_rpc_cmd_resp_send(SD_BLE_GATTS_SERVICE_ADD, err_code);
    }
}
Ejemplo n.º 19
0
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;
}
Ejemplo n.º 20
0
uint32_t add_vendor_service(VendorService* service){
    if(ble_device->vendor_service_count >= MAX_VENDOR_SERVICE_COUNT)
        return 1;
    create_uuid_for_vendor_service(&service->uuid, ble_device->vendor_service_count);
    uint32_t error_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &service->uuid, &service->handle);
    APP_ERROR_CHECK(error_code);
    ble_device->vendor_services[ble_device->vendor_service_count] = service;
    ble_device->vendor_service_count++;
    return 0;
}
Ejemplo n.º 21
0
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;

}
Ejemplo n.º 22
0
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;
}
Ejemplo n.º 23
0
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;
}
Ejemplo n.º 24
0
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;
}
Ejemplo n.º 25
0
void service_addService(const service_service_t* service, const service_characteristic_t characteristics[])
{
    uint32_t err_code;

    uint16_t service_handle;
    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &service->uuid, &service_handle);
    APP_ERROR_CHECK(err_code);

    for (unsigned i = 0; characteristics[i].name; i++)
    {
        if (service_state.mapfree >= HOMEKIT_CONFIG_SERVICE_MAX_CHARACTERISTICS)
        {
            APP_ERROR_CHECK(NRF_ERROR_INTERNAL);
        }

        ble_gatts_attr_md_t metadata =
        {
            .read_perm = { !!characteristics[i].read, !!characteristics[i].read },
            .write_perm = { !!characteristics[i].write, !!characteristics[i].write },
            .rd_auth = !!characteristics[i].read,
            .wr_auth = !!characteristics[i].write,
            .vlen = 1,
            .vloc = BLE_GATTS_VLOC_USER
        };
        const ble_gatts_attr_t attr =
        {
            .p_uuid = (ble_uuid_t*)&characteristics[i].uuid,
            .p_attr_md = &metadata,
            .max_len = SESSION_CIPHER_BUFFERLEN(characteristics[i].max_length ? characteristics[i].max_length : characteristics[i].length),
            .p_value = buffer_buffer
        };
        const ble_gatts_char_md_t character =
        {
            .char_props =
            {
                .read = !!characteristics[i].read,
                .write = !!characteristics[i].write,
                .notify = characteristics[i].notify
            },
            .p_char_user_desc = (uint8_t*)characteristics[i].name,
            .char_user_desc_max_size = strlen(characteristics[i].name),
            .char_user_desc_size = strlen(characteristics[i].name)
        };

        ble_gatts_char_handles_t newhandle;
        err_code = sd_ble_gatts_characteristic_add(service_handle, &character, &attr, &newhandle);
        APP_ERROR_CHECK(err_code);
        service_state.map[service_state.mapfree].handle = newhandle.value_handle;
        service_state.map[service_state.mapfree].characteristic = &characteristics[i];
        service_state.mapfree++;
    }
}
Ejemplo n.º 26
0
Archivo: main.c Proyecto: tkadom/TWBLE
/**@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);
}
Ejemplo n.º 27
0
uint32_t ble_tps_init(ble_tps_t * p_tps, const ble_tps_init_t * p_tps_init)
{
    uint32_t   err_code;
    ble_uuid_t ble_uuid;

    // Add service
    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_TX_POWER_SERVICE);

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_tps->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    
    // Add TX Power Level characteristic
    return tx_power_level_char_add(p_tps, p_tps_init);
}
Ejemplo n.º 28
0
uint32_t ble_iqo_init(ble_iqo_t * p_iqo)
{
    uint32_t   err_code;
    ble_uuid_t ble_uuid;

    iqo_ptr = p_iqo;

    // Initialize service structure
    p_iqo->conn_handle = BLE_CONN_HANDLE_INVALID;

    // Add service
    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_IQO_SERVICE);

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_iqo->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    // Add memory dump characteristic
    err_code = iqo_cmd_char_add(p_iqo);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    err_code = iqo_identify_char_add(p_iqo);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    err_code = iqo_wifi_status_char_add(p_iqo);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    err_code = iqo_peer_status_char_add(p_iqo);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    return NRF_SUCCESS;
}
Ejemplo n.º 29
0
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;
}
Ejemplo n.º 30
0
/*
 *  Function for initializing Temp's BLE usage.
 */
uint32_t ble_temp_init(ble_temp_t * p_temp)
{
    uint32_t   err_code;
    ble_uuid_t ble_uuid;

    // Initialize Temperature Measurement Interval timer
    err_code = app_timer_create(&m_temperature_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                temperature_timeout_handler);
    APP_ERROR_CHECK(err_code);

    // Convert default Interval value to ticks.
    m_interval_ticks = app_timer_ticks(m_interval * 1000 /* 1000 ms */);

    // Initialize service structure
    p_temp->conn_handle    = BLE_CONN_HANDLE_INVALID;
    p_temp->notify_enabled = false;

    // Add service
    ble_uuid128_t base_uuid = {TEMP_UUID_BASE};
    err_code = sd_ble_uuid_vs_add(&base_uuid, &p_temp->uuid_type);
    if (err_code != NRF_SUCCESS) {
        return err_code;
    }
    
    ble_uuid.type = p_temp->uuid_type;
    ble_uuid.uuid = TEMP_UUID_SERVICE;

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_temp->service_handle);
    if (err_code != NRF_SUCCESS) {
        return err_code;
    }

    err_code = temperature_char_add(p_temp);
    if (err_code != NRF_SUCCESS) {
        return err_code;
    }

    err_code = interval_char_add(p_temp);
    if (err_code != NRF_SUCCESS) {
        return err_code;
    }

    return NRF_SUCCESS;
}