/* non-zero, Instance ID on success or a negative error code. */ static int LLSRegisterService(unsigned int BluetoothStackID, LLS_Event_Callback_t EventCallback, unsigned long CallbackParameter, unsigned int *ServiceID, GATT_Attribute_Handle_Group_t *ServiceHandleRange) { int ret_val; unsigned int InstanceID; LLSServerInstance_t *ServiceInstance; /* Make sure the parameters passed to us are semi-valid. */ if((BluetoothStackID) && (ServiceID)) { /* Verify that no instance is registered to this Bluetooth Stack. */ if(!InstanceRegisteredByStackID(BluetoothStackID)) { /* Acquire a free LLS Instance. */ InstanceID = 0; if((ServiceInstance = AcquireServiceInstance(BluetoothStackID, &InstanceID)) != NULL) { /* Call GATT to register the LLS service. */ ret_val = GATT_Register_Service(BluetoothStackID, LLS_SERVICE_FLAGS, LINK_LOSS_SERVICE_ATTRIBUTE_COUNT, (GATT_Service_Attribute_Entry_t *)Link_Loss_Service, ServiceHandleRange, GATT_ServerEventCallback, InstanceID); if(ret_val > 0) { /* Save the Instance information. */ ServiceInstance->BluetoothStackID = BluetoothStackID; ServiceInstance->ServiceID = (unsigned int)ret_val; ServiceInstance->EventCallback = EventCallback; ServiceInstance->CallbackParameter = CallbackParameter; *ServiceID = (unsigned int)ret_val; /* Intilize the Instance Data for this instance. */ BTPS_MemInitialize(&InstanceData[InstanceID-1], 0,LLS_INSTANCE_DATA_SIZE); ASSIGN_HOST_WORD_TO_LITTLE_ENDIAN_UNALIGNED_WORD(&(InstanceData[InstanceID-1].Alert_Level_Length), LLS_ALERT_LEVEL_LENGTH); /* Return the LLS Instance ID. */ ret_val = (int)InstanceID; } /* UnLock the previously locked Bluetooth Stack. */ BSC_UnLockBluetoothStack(BluetoothStackID); } else ret_val = LLS_ERROR_INSUFFICIENT_RESOURCES; } else ret_val = LLS_ERROR_SERVICE_ALREADY_REGISTERED; } else ret_val = LLS_ERROR_INVALID_PARAMETER; /* Finally return the result to the caller. */ return(ret_val); }
/* non-zero, Instance ID on success or a negative error code. */ static int IASRegisterService(unsigned int BluetoothStackID, IAS_Event_Callback_t EventCallback, unsigned long CallbackParameter, unsigned int *ServiceID, GATT_Attribute_Handle_Group_t *ServiceHandleRange) { int ret_val; unsigned int InstanceID; IASServerInstance_t *ServiceInstance; /* Make sure the parameters passed to us are semi-valid. */ if((BluetoothStackID) && (EventCallback) && (ServiceID)) { /* Verify that no instance is registered to this Bluetooth Stack. */ if(!InstanceRegisteredByStackID(BluetoothStackID)) { /* Acquire a free IAS Instance. */ InstanceID = 0; if((ServiceInstance = AcquireServiceInstance(BluetoothStackID, &InstanceID)) != NULL) { /* Call GATT to register the IAS service. */ ret_val = GATT_Register_Service(BluetoothStackID, IAS_SERVICE_FLAGS, IMMEDIATE_ALERT_SERVICE_ATTRIBUTE_COUNT, (GATT_Service_Attribute_Entry_t *)Immediate_Alert_Service, ServiceHandleRange, GATT_ServerEventCallback, InstanceID); if(ret_val > 0) { /* Save the Instance information. */ ServiceInstance->BluetoothStackID = BluetoothStackID; ServiceInstance->ServiceID = (unsigned int)ret_val; ServiceInstance->EventCallback = EventCallback; ServiceInstance->CallbackParameter = CallbackParameter; *ServiceID = (unsigned int)ret_val; /* Return the IAS Instance ID. */ ret_val = (int)InstanceID; } /* UnLock the previously locked Bluetooth Stack. */ BSC_UnLockBluetoothStack(BluetoothStackID); } else ret_val = IAS_ERROR_INSUFFICIENT_RESOURCES; } else ret_val = IAS_ERROR_SERVICE_ALREADY_REGISTERED; } else ret_val = IAS_ERROR_INVALID_PARAMETER; /* Finally return the result to the caller. */ return(ret_val); }