bt_gatt_srv_register_service()

Register a local service with the Generic Attribute (GATT) server.

Synopsis:

#include <btapi/btgattsrv.h>
 
int bt_gatt_srv_register_service(bt_gatt_srv_attrvalue_t *service, bt_gatt_srv_service_cb *cb, void *userData)

Since:

BlackBerry 10.2.0

Arguments:

service
An array of bt_gatt_srv_attrvalue_t objects representing the GATT services to register. For example, you may want to define a service with a private UUID that mimics an Immediate Alert Service. In this case, by setting the cnt attribute of the first array element to a value of 3, you tell this function that there are three instances of bt_gatt_srv_attrvalue_t in the registration, one for the primary service and one for each attribute. The following code sample illustrates this example:
 bt_gatt_srv_attrvalue_t _myService[3];
 strlcpy(_myService[0].service,
     "0x3759E92B-4E2C-4EFD-97B5-BEDF474A1C56", sizeof(_myService[0].service));
 _myService[0].handle = 0;
 _myService[0].attrType = BT_GATT_SRV_ATT_SERVICE;
 _myService[0].dcl.service.cnt = 3;
 _myService[0].dcl.service.startHandle = 0;
 _myService[0].dcl.service.numHandles = 4;
 _myService[0].dcl.service.type = BT_GATT_SRV_ATT_PRIMARY_SERVICE;
 _myService[0].dcl.service.useSDP = 1;
 _myService[0].valueType = BT_GATT_SRV_ATT_VALUE_STATIC;
 _myService[0].value.sta.valueLen = 19;
 _myService[0].value.sta.value = (uint8_t *)"My Immediate Alert";

 strlcpy(_myService[1].service, "0x2A06", sizeof(_myService[0].service));
 _myService[1].handle = 1;
 _myService[1].attrType = BT_GATT_SRV_ATT_CHARACTERISTICS;
 _myService[1].dcl.characteristic.properties = BT_GATT_SRV_ATT_PROPERTY_WRITE_NORESP;
 _myService[1].dcl.characteristic.permission = BT_GATT_SRV_ATT_PERMISSION_WRITEABLE;
 _myService[1].dcl.characteristic.encryptKeySize = 0;
 _myService[1].dcl.characteristic.valueHandle = 2;
 _myService[1].valueType = BT_GATT_SRV_ATT_VALUE_DYNAMIC;
 _myService[1].value.dyn.valueLen = 1;
 _myService[1].value.dyn.maxValueLen = 1;

 strlcpy(_myService[2].service, "0x2901", sizeof(_myService[0].service));
 _myService[2].handle = 3;
 _myService[2].attrType = BT_GATT_SRV_ATT_DESCRIPTOR;
 _myService[2].dcl.descriptor.permission = BT_GATT_SRV_ATT_PERMISSION_READABLE;
 _myService[2].dcl.descriptor.encryptKeySize = 0;
 _myService[2].valueType = BT_GATT_SRV_ATT_VALUE_STATIC;
 _myService[2].value.sta.valueLen = 12;
 _myService[2].value.sta.value = (uint8_t *)"Alert Level";
                     
cb

The callbacks to call when read/write operations are performed on this service.

userData

(Optional) Pointer to user data that will be passed back during event callbacks.

Library:

libbtapi

Description:

Returns:

The instance representing the service, -1 with the errno set otherwise. The error codes that can be returned are as follows:
  • EBUSY: The stack was busy performing another operation. You can try again later.
  • EDEADLK: A potential deadlock has been avoided.
  • EINVAL: The arguments passed are invalid.
  • ENOMEM: Insufficient memory was available to perform the request.
  • ESRVRFAULT: An internal error has occurred.