#define MAX_PROP_LEN 95 /* SVACE WGID: 324403*/
#define MAX_PERM_LEN 80 //Fix for svace wgid:324402
-#define NUM_SERVER_INST 10 // Maximum slots supported by stack is set to 10
#define CHECK_OAL_GATT_ENABLED() \
do { \
if (gatt_api == NULL) { \
#define CHECK_SERVER_INSTANCE(instance_id) \
do { \
- if (instance_id < 1 || instance_id > NUM_SERVER_INST) { \
+ if (instance_id < 1) { \
BT_ERR("Invalid Instance"); \
return OAL_STATUS_INVALID_PARAM; \
} \
} while (0)
-#define CHECK_SERVER_REGISTRATION(instance_id) \
+#define CHECK_CORRECT_SERVER_ID(server_if, server_inst) \
do { \
- if (gatt_servers[instance_id - 1].server_id < 0) {\
- BT_INFO("GATT server registeration is not done for server Instance : %d", instance_id);\
- return OAL_STATUS_INTERNAL_ERROR;\
- } \
- } while (0)
-
-#define CHECK_CORRECT_SERVER_ID(instance_id, server_if, server_inst)\
- do { \
- for (instance_id = 1 ; instance_id <= NUM_SERVER_INST; instance_id++) { \
- if (gatt_servers[instance_id - 1].server_id == server_if) { \
- server_inst = instance_id; \
- goto sendevent;\
- } \
+ gatt_server_t *info; \
+ info = __gatts_find_server_instance(server_if); \
+ if (info) { \
+ server_inst = server_if; \
+ goto sendevent; \
} \
} while (0)
} gatt_data_state;
typedef struct {
- int server_id;
+ int instance_id;
oal_uuid_t uuid;
int state;
+ gboolean cur_adv_state;
} gatt_server_t;
const char *oal_device_type[] = {
} oal_pending_gattc_req_e;
static const btgatt_interface_t * gatt_api;
-static gboolean cur_adv_state[NUM_SERVER_INST];
-static gatt_server_t gatt_servers[NUM_SERVER_INST];
+static GSList *gatt_servers = NULL; /* List of gatt_server_t */
/* Forward declarations of GATT Server callbacks */
static void cb_gatts_register_app(int status, int server_if, bt_uuid_t *uuid);
{
const bt_interface_t * blued_api;
int ret;
- int i = 0;
-
- for (i = 0; i < NUM_SERVER_INST; i++) {
- gatt_servers[i].server_id = -1;
- gatt_servers[i].state = GATT_INS_DISABLED;
- memset(&gatt_servers[i].uuid, 0, sizeof(oal_uuid_t));
- cur_adv_state[i] = FALSE;
- }
/* Get stack interface */
blued_api = (const bt_interface_t *) adapter_get_stack_interface();
oal_status_t gatt_disable(void)
{
- int i;
if (gatt_api) {
gatt_api->cleanup();
gatt_api = NULL;
}
- for (i = 0; i < NUM_SERVER_INST; i++) {
- gatt_servers[i].server_id = -1;
- gatt_servers[i].state = GATT_INS_DISABLED;
- memset(&gatt_servers[i].uuid, 0, sizeof(oal_uuid_t));
- }
+ g_slist_free_full(gatt_servers, g_free);
+ gatt_servers = NULL;
return OAL_STATUS_SUCCESS;
}
+static gatt_server_t *__gatts_find_server_instance(int instance_id)
+{
+ gatt_server_t *info;
+ GSList *l;
+
+ for (l = gatt_servers; l; l = g_slist_next(l)) {
+ info = l->data;
+ if (!info)
+ continue;
+ if (info->instance_id == instance_id)
+ return info;
+ }
+
+ return NULL;
+}
+
/************************************GATT Server Functions*************************************/
/*Public */
oal_status_t gatts_register(oal_uuid_t* server_uuid)
{
char str[2*BT_UUID_STRING_MAX];
int ret = OAL_STATUS_SUCCESS;
- int i;
+ GSList *l;
CHECK_OAL_GATT_ENABLED();
uuid_to_stringname((service_uuid_t*)server_uuid->uuid, str);
API_TRACE("Register the server instance: UUID: [%s]", str);
- for (i = 0; i < NUM_SERVER_INST; i++) {
- if (memcmp(server_uuid->uuid, gatt_servers[i].uuid.uuid, sizeof(oal_uuid_t)) == 0) {
- if (gatt_servers[i].server_id != -1) {
- BT_ERR("This is resevered UUID for easy set up application i = %d \
- gatt_servers[i].server_id = %d", i, gatt_servers[i].server_id);
+ for (l = gatt_servers; l; l = g_slist_next(l)) {
+ gatt_server_t *info = l->data;
+ if (!info)
+ continue;
+ if (memcmp(server_uuid->uuid, info->uuid.uuid, sizeof(oal_uuid_t)) == 0) {
+ if (info->instance_id != -1) {
+ BT_ERR("This is resevered UUID for easy set up application \
+ instance_id = %d", info->instance_id);
return OAL_STATUS_ALREADY_DONE;
}
}
oal_status_t gatts_unregister(int instance_id)
{
int ret = OAL_STATUS_SUCCESS;
+ gatt_server_t *info;
API_TRACE("Unregister the registered server, instance_id: %d", instance_id);
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
- ret = gatt_api->server->unregister_server(gatt_servers[instance_id - 1].server_id);
+ info = __gatts_find_server_instance(instance_id);
+ if (!info)
+ return OAL_STATUS_INTERNAL_ERROR;
+ ret = gatt_api->server->unregister_server(instance_id);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT server unregistration failed: %d", instance_id);
return convert_to_oal_status(ret);
}
- gatt_servers[instance_id-1].server_id = -1;
- gatt_servers[instance_id-1].state = GATT_INS_DISABLED;
-
- if (instance_id != 1 && instance_id != 2)
- memset(&gatt_servers[instance_id-1].uuid, 0, sizeof(oal_uuid_t));
+ info->instance_id = -1;
+ info->state = GATT_INS_DISABLED;
+ info->cur_adv_state = FALSE;
+ if (instance_id != 1 && instance_id != 2) {
+ gatt_servers = g_slist_remove(gatt_servers, info);
+ BT_DBG("GATT Server Removed. count of gatt_servers: %d",
+ g_slist_length(gatt_servers));
+ }
return OAL_STATUS_SUCCESS;
}
oal_status_t gatts_start_listen(int instance_id, gboolean enable)
{
int ret = OAL_STATUS_SUCCESS;
- API_TRACE("server-id:%d enable: %d", gatt_servers[instance_id-1].server_id, enable);
+ gatt_server_t *info;
+ API_TRACE("instance_id: %d enable: %d", instance_id, enable);
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
-
- ret = gatt_api->server->listen(gatt_servers[instance_id-1].server_id, enable);
+ info = __gatts_find_server_instance(instance_id);
+ if (!info)
+ return OAL_STATUS_INTERNAL_ERROR;
+ ret = gatt_api->server->listen(instance_id, enable);
if (ret != BT_STATUS_SUCCESS) {
- BT_ERR("Error:Advertising start/stop on server-id:%d failed With Status: [%s]",
- gatt_servers[instance_id-1].server_id, status2string(ret));
+ BT_ERR("Error:Advertising %s on instance_id: %d failed \
+ with status: %s, cur_adv_state: %d",
+ enable ? "Start" : "Stop", instance_id,
+ status2string(ret), info->cur_adv_state);
return convert_to_oal_status(ret);
}
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
-
- ret = gatt_api->server->listen(gatt_servers[instance_id - 1].server_id, FALSE);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
+ ret = gatt_api->server->listen(instance_id, FALSE);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("Stop Advertising failed for server Instance:%d With Status: %s",
instance_id, status2string(ret));
return OAL_STATUS_SUCCESS;
}
-#if 0
-/* Below API's need to be removed as they are hardcoded API's.
- If at all, product specific API's are required to set specific data, then new naming should
- be adopted for these API's */
-oal_status_t gatts_set_advertising_params(int instance_id, float min_intv, float max_intv)
-{
- int ret = OAL_STATUS_SUCCESS;
-
- API_TRACE("Set advertising params min_int:%f, max_int:%f", min_intv, max_intv);
- CHECK_OAL_GATT_ENABLED();
- CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
-
- /* Historically used for Legacy Advertising */
- return OAL_STATUS_NOT_SUPPORT;
-}
-
-oal_status_t gatts_set_advertising_data(int instance_id, uint16_t manufac_len, char* manufac_data)
-{
- int ret = OAL_STATUS_SUCCESS;
-
- API_TRACE("Set advertising data");
- CHECK_OAL_GATT_ENABLED();
- CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
-
- /* Historically used for Legacy Advertising */
- return OAL_STATUS_NOT_SUPPORT;
-}
-
-oal_status_t gatts_set_scan_response(int instance_id, uint16_t manufac_len, char* manufac_data)
-{
- int ret = OAL_STATUS_SUCCESS;
-
- API_TRACE("Set Scan Response data");
- CHECK_OAL_GATT_ENABLED();
- CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
-
- /* Historically used for Legacy Advertising */
- return OAL_STATUS_NOT_SUPPORT;
-}
-#endif
-
oal_status_t gatts_multi_adv_enable(int instance_id)
{
int ret = OAL_STATUS_SUCCESS;
- API_TRACE("Start Multi advertising, srv_if: %d, instance_id: %d",
- gatt_servers[instance_id - 1].server_id, instance_id);
+ gatt_server_t *info;
+ API_TRACE("Start Multi advertising, instance_id: %d", instance_id);
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
+ info = __gatts_find_server_instance(instance_id);
+ if (!info)
+ return OAL_STATUS_INTERNAL_ERROR;
if (gatt_api->server->multi_adv_enable == NULL)
return OAL_STATUS_NOT_SUPPORT;
return OAL_STATUS_BUSY;
}
*/
- if (gatt_servers[instance_id - 1].state == GATT_INS_ENABLED) {
- BT_ERR("Not allowed, state: %d, instance_id: %d",
- gatt_servers[instance_id - 1].state, instance_id);
- return OAL_STATUS_ALREADY_DONE;
- }
- if (gatt_servers[instance_id - 1].state == GATT_INS_ENABLING) {
- BT_ERR("Not allowed, state: %d, instance_id: %d",
- gatt_servers[instance_id - 1].state, instance_id);
+ if (info->state == GATT_INS_ENABLED) {
+ BT_ERR("Not allowed, state: %d, instance_id: %d", info->state, instance_id);
+ return OAL_STATUS_ALREADY_DONE;
+ } else if (info->state == GATT_INS_ENABLING) {
+ BT_ERR("Not allowed, state: %d, instance_id: %d", info->state, instance_id);
return OAL_STATUS_BUSY;
}
+ info->state = GATT_INS_ENABLING;
- gatt_servers[instance_id - 1].state = GATT_INS_ENABLING;
-
- ret = gatt_api->server->multi_adv_enable(gatt_servers[instance_id - 1].server_id);
-
+ ret = gatt_api->server->multi_adv_enable(instance_id);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT enable multi advertising failed for server Instance: %d With Status: %s",
instance_id, status2string(ret));
oal_status_t gatts_multi_adv_disable(int instance_id)
{
int ret = OAL_STATUS_SUCCESS;
- API_TRACE("Stop Multi advertising, srv_if: %d, instance_id: %d",
- gatt_servers[instance_id - 1].server_id, instance_id);
+ gatt_server_t *info;
+ API_TRACE("Stop Multi advertising, instance_id: %d", instance_id);
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
+ info = __gatts_find_server_instance(instance_id);
+ if (!info)
+ return OAL_STATUS_INTERNAL_ERROR;
if (gatt_api->server->multi_adv_disable == NULL)
return OAL_STATUS_NOT_SUPPORT;
- if ((gatt_servers[instance_id - 1].state != GATT_INS_ENABLED)) {
- BT_ERR("Not Allowed, state: %d, instance_id: %d",
- gatt_servers[instance_id - 1].state, instance_id);
+ if (info->state != GATT_INS_ENABLED) {
+ BT_ERR("Not Allowed, state: %d, instance_id: %d", info->state, instance_id);
return OAL_STATUS_BUSY;
}
- ret = gatt_api->server->multi_adv_disable(gatt_servers[instance_id - 1].server_id);
-
+ ret = gatt_api->server->multi_adv_disable(instance_id);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT disable multi advertising failed for server Instance: %d With Status: %s",
instance_id, status2string(ret));
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
if (gatt_api->server->multi_adv_update == NULL)
return OAL_STATUS_NOT_SUPPORT;
- ret = gatt_api->server->multi_adv_update(gatt_servers[instance_id - 1].server_id,
+ ret = gatt_api->server->multi_adv_update(instance_id,
min_intv, max_intv,
adv_type, chnl_map,
tx_power, timeout_s);
-
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT update multi advertising failed for server Instance: %d With Status: %s",
instance_id, status2string(ret));
{
int ret = OAL_STATUS_SUCCESS;
btgatt_adv_param_setup_t adv_setup;
- API_TRACE("Set Multi advertising data, srv_if: %d, instance_id: %d",
- gatt_servers[instance_id - 1].server_id, instance_id);
+ gatt_server_t *info;
+ API_TRACE("Set Multi advertising data, instance_id: %d", instance_id);
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
+ info = __gatts_find_server_instance(instance_id);
+ if (!info)
+ return OAL_STATUS_INTERNAL_ERROR;
if (gatt_api->server->multi_adv_set_inst_data == NULL)
return OAL_STATUS_NOT_SUPPORT;
- if ((gatt_servers[instance_id - 1].state >= GATT_INS_DATA_SETTING) && (gatt_servers[instance_id - 1].state != GATT_INS_DATA_SET)) {
- BT_ERR("Not Allowed, state: %d, instance_id: %d", gatt_servers[instance_id - 1].state, instance_id);
+ if (info->state >= GATT_INS_DATA_SETTING && info->state != GATT_INS_DATA_SET) {
+ BT_ERR("Not Allowed, state: %d, instance_id: %d", info->state, instance_id);
return OAL_STATUS_BUSY;
}
-
- gatt_servers[instance_id - 1].state = GATT_INS_DATA_SETTING;
-
+ info->state = GATT_INS_DATA_SETTING;
adv_setup.set_scan_rsp = adv_param_setup->set_scan_rsp;
adv_setup.include_name = adv_param_setup->include_name;
adv_setup.include_txpower = adv_param_setup->include_txpower;
+#ifdef TIZEN_BT_HAL
+ adv_setup.include_appearance = adv_param_setup->include_appearance;
+#endif
adv_setup.appearance = adv_param_setup->appearance;
adv_setup.manufacturer_data = adv_param_setup->manufacturer_data;
adv_setup.manufacturer_data_len = adv_param_setup->manufacturer_data_len;
adv_setup.tx_power = adv_param_setup->tx_power;
adv_setup.timeout_s = adv_param_setup->timeout_s;
- adv_setup.server_if = gatt_servers[instance_id - 1].server_id;
+ adv_setup.server_if = instance_id;
ret = gatt_api->server->multi_adv_set_inst_data(adv_setup);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT Set Multi advertising data failed: %s", status2string(ret));
- gatt_servers[instance_id - 1].state = GATT_INS_DISABLED;
+ info->state = GATT_INS_DISABLED;
return convert_to_oal_status(ret);
}
return OAL_STATUS_SUCCESS;
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
API_TRACE("[%s]", bdt_bd2str(device_address, &bdstr));
- ret = gatt_api->server->disconnect(gatt_servers[instance_id - 1].server_id, (bt_bdaddr_t *) device_address, conn_id);
+ ret = gatt_api->server->disconnect(instance_id, (bt_bdaddr_t *) device_address, conn_id);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT Server disconnect failed: %s", status2string(ret));
return convert_to_oal_status(ret);
/*Server Callbacks*/
static void cb_gatts_register_app(int status, int server_if, bt_uuid_t *uuid)
{
- int i;
char str[2*BT_UUID_STRING_MAX];
uuid_to_stringname((service_uuid_t*)uuid, str);
event_gatts_register_t *event = g_malloc0(sizeof(event_gatts_register_t));
- BT_INFO("BTGATT SERVER REGISTER APP CB, status:%d, server_if:%d", status, server_if);
- BT_INFO("UUID: [%s]", str);
+ BT_INFO("BTGATT SERVER REGISTER APP CB, UUID:%s, status:%d, server_if:%d",
+ str, status, server_if);
- for (i = 0; i < NUM_SERVER_INST; i++) {
- if (gatt_servers[i].server_id == -1) {
- BT_INFO("Server Instance registered with stack [%d]", i+1);
- gatt_servers[i].server_id = server_if;
- event->server_inst = i+1;
- memcpy(gatt_servers[i].uuid.uuid, uuid->uu, sizeof(bt_uuid_t));
- memcpy(event->server_uuid.uuid, uuid->uu, sizeof(bt_uuid_t));
- break;
- }
- }
+ gatt_server_t *info = g_malloc0(sizeof(gatt_server_t));
+ info->instance_id = server_if;
+ memcpy(info->uuid.uuid, uuid->uu, sizeof(bt_uuid_t));
+ gatt_servers = g_slist_append(gatt_servers, info);
+ BT_DBG("GATT Server Added. count of gatt_servers: %d", g_slist_length(gatt_servers));
+
+ event->server_inst = server_if;
+ memcpy(event->server_uuid.uuid, uuid->uu, sizeof(bt_uuid_t));
send_event(OAL_EVENT_BLE_SERVER_INSTANCE_INITIALISED, event, sizeof(event_gatts_register_t));
}
static void cb_gatts_listen(int status, int server_if)
{
- gboolean prev_state[NUM_SERVER_INST];
- gboolean new_state;
+ gboolean prev_state;
+ gboolean new_state = FALSE;
event_ble_adv_status *event = g_malloc0(sizeof(event_ble_adv_status));
- int instance_id;
-
- for (instance_id = 1 ; instance_id <= NUM_SERVER_INST ; instance_id++) {
- if (gatt_servers[instance_id - 1].server_id == server_if) {
- event->server_inst = instance_id;
+ GSList *l;
+
+ for (l = gatt_servers; l; l = g_slist_next(l)) {
+ gatt_server_t *info = l->data;
+ if (!info)
+ continue;
+ if (info->instance_id == server_if) {
+ event->server_inst = server_if;
+ prev_state = info->cur_adv_state;
+ new_state = (status == BT_STATUS_SUCCESS) ? !prev_state : prev_state;
+ info->cur_adv_state = new_state;
break;
- } else {
- BT_WARN("Server ID:%d recevied server Id:%d\n", gatt_servers[instance_id - 1].server_id, server_if);
}
}
- if ((event->server_inst > 0) && (event->server_inst <= 10)) {
- prev_state[event->server_inst - 1] = cur_adv_state[event->server_inst - 1];
- new_state = (status == BT_STATUS_SUCCESS) ? !(prev_state[event->server_inst - 1]) : (prev_state[event->server_inst - 1]);
- cur_adv_state[event->server_inst - 1] = new_state;
- } else {
- BT_ERR("Invalid Callback...");
- g_free(event);
- return;
- }
- BT_INFO("Adv State of server instance %d :%d", instance_id, new_state);
+ BT_INFO("Adv State of server instance %d, new_state: %d", server_if, new_state);
if (TRUE == new_state)
send_event(OAL_EVENT_BLE_ADVERTISING_STARTED, event, sizeof(event_ble_adv_status));
BT_INFO("BTGATT SERVER MULTI ADV ENABLE CB, status:%d, srv_if: %d", status, server_if);
event_ble_multiadv_status *event = g_malloc0(sizeof(event_ble_multiadv_status));
- int instance_id;
+ GSList *l;
if (status != BT_STATUS_SUCCESS)
BT_ERR("MULTI ADV ENABLE failed, status:%d, srv_if: %d", status, server_if);
- for (instance_id = 1 ; instance_id <= NUM_SERVER_INST ; instance_id++) {
- if (gatt_servers[instance_id - 1].server_id == server_if) {
- event->server_inst = instance_id;
- gatt_servers[instance_id - 1].state = GATT_INS_ENABLED;
+ for (l = gatt_servers; l; l = g_slist_next(l)) {
+ gatt_server_t *info = l->data;
+ if (!info)
+ continue;
+ if (info->instance_id == server_if) {
+ event->server_inst = server_if;
+ info->state = GATT_INS_ENABLED;
goto sendevent;
}
}
- BT_ERR("Invalid Interface, srv_if: %d", server_if);
event->server_inst = -1;
sendevent:
event->status = convert_to_oal_status(status);
{
BT_INFO("BTGATT SERVER MULTI ADV DISABLE CB, status:%d, srv_if: %d", status, server_if);
event_ble_multiadv_status *event = g_malloc0(sizeof(event_ble_multiadv_status));
- int instance_id;
+ GSList *l;
if (status != BT_STATUS_SUCCESS)
BT_ERR("MULTI ADV DISABLE failed, status:%d, srv_if: %d", status, server_if);
- for (instance_id = 1 ; instance_id <= NUM_SERVER_INST; instance_id++) {
- if (gatt_servers[instance_id - 1].server_id == server_if) {
- event->server_inst = instance_id;
- gatt_servers[instance_id - 1].state = GATT_INS_DISABLED;
+ for (l = gatt_servers; l; l = g_slist_next(l)) {
+ gatt_server_t *info = l->data;
+ if (!info)
+ continue;
+ if (info->instance_id == server_if) {
+ event->server_inst = server_if;
+ info->state = GATT_INS_DISABLED;
goto sendevent;
}
}
- BT_ERR("Invalid Interface, srv_if: %d", server_if);
event->server_inst = -1;
sendevent:
event->status = convert_to_oal_status(status);
{
BT_INFO("BTGATT SERVER MULTI ADV UPDATE CB, status:%d, srv_if: %d", status, server_if);
event_ble_multiadv_status *event = g_malloc0(sizeof(event_ble_multiadv_status));
- int instance_id;
+ GSList *l;
if (status != BT_STATUS_SUCCESS)
BT_ERR("MULTI ADV UPDATE failed, status:%d, srv_if: %d", status, server_if);
- for (instance_id = 1 ; instance_id <= NUM_SERVER_INST ; instance_id++) {
- if (gatt_servers[instance_id - 1].server_id == server_if) {
- event->server_inst = instance_id;
+ for (l = gatt_servers; l; l = g_slist_next(l)) {
+ gatt_server_t *info = l->data;
+ if (!info)
+ continue;
+ if (info->instance_id == server_if) {
+ event->server_inst = server_if;
goto sendevent;
}
}
- BT_ERR("Invalid Interface, srv_if: %d", server_if);
event->server_inst = -1;
sendevent:
event->status = convert_to_oal_status(status);
{
BT_INFO("BTGATT SERVER MULTI ADV SET INST DATA CB, status:%d, srv_if: %d", status, server_if);
event_ble_multiadv_status *event = g_malloc0(sizeof(event_ble_multiadv_status));
- int instance_id;
+ GSList *l;
if (status != BT_STATUS_SUCCESS)
BT_ERR("MULTI ADV SET DATA failed, status:%d, srv_if: %d", status, server_if);
- for (instance_id = 1 ; instance_id <= NUM_SERVER_INST ; instance_id++) {
- if (gatt_servers[instance_id - 1].server_id == server_if) {
- event->server_inst = instance_id;
- gatt_servers[instance_id - 1].state = GATT_INS_DATA_SET;
+ for (l = gatt_servers; l; l = g_slist_next(l)) {
+ gatt_server_t *info = l->data;
+ if (!info)
+ continue;
+ if (info->instance_id == server_if) {
+ event->server_inst = server_if;
+ info->state = GATT_INS_DATA_SET;
goto sendevent;
}
}
- BT_ERR("Invalid Interface, srv_if: %d", server_if);
event->server_inst = -1;
sendevent:
event->status = convert_to_oal_status(status);
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
- CHECK_SERVER_REGISTRATION(instance_id);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
if (gatt_serv_id != NULL) {
uuid_to_stringname(&(gatt_serv_id->id.uuid), str);
return OAL_STATUS_INVALID_PARAM;
}
- ret = gatt_api->server->add_service(gatt_servers[instance_id - 1].server_id, &btgatt_srvc_id, num_handles);
-
+ ret = gatt_api->server->add_service(instance_id, &btgatt_srvc_id, num_handles);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT Server add service failed: %s", status2string(ret));
return convert_to_oal_status(ret);
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
- CHECK_SERVER_REGISTRATION(instance_id);
-
- ret = gatt_api->server->add_included_service(gatt_servers[instance_id - 1].server_id, serv_handle, incl_handle);
+ ret = gatt_api->server->add_included_service(instance_id, serv_handle, incl_handle);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT Server Add included Service failed: %s", status2string(ret));
return convert_to_oal_status(ret);
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
-
- CHECK_SERVER_REGISTRATION(instance_id);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
if (charc_uuid != NULL) {
uuid_to_stringname(charc_uuid, str);
API_TRACE("uuid: [%s]", str);
}
- ret = gatt_api->server->add_characteristic(gatt_servers[instance_id - 1].server_id,
+ ret = gatt_api->server->add_characteristic(instance_id,
serv_handle, (bt_uuid_t*)charc_uuid, propts, permsn);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT Server Add Characteristic failed: %s", status2string(ret));
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
-
- CHECK_SERVER_REGISTRATION(instance_id);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
if (desc_uuid != NULL) {
uuid_to_stringname(desc_uuid, str);
API_TRACE("uuid: [%s]", str);
}
- ret = gatt_api->server->add_descriptor(gatt_servers[instance_id - 1].server_id,
+ ret = gatt_api->server->add_descriptor(instance_id,
serv_handle, (bt_uuid_t*)desc_uuid, permsn);
-
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT Server Add Descriptor failed: %s", status2string(ret));
return convert_to_oal_status(ret);
CHECK_OAL_GATT_ENABLED();
CHECK_SERVER_INSTANCE(instance_id);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
- CHECK_SERVER_REGISTRATION(instance_id);
-
- ret = gatt_api->server->start_service(gatt_servers[instance_id - 1].server_id, svc_handle, transport);
-
+ ret = gatt_api->server->start_service(instance_id, svc_handle, transport);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT Server Start Service failed: %s", status2string(ret));
return convert_to_oal_status(ret);
return OAL_STATUS_SUCCESS;
}
-oal_status_t gatts_stop_service(int ins_id, int srv_hdl)
+oal_status_t gatts_stop_service(int instance_id, int srv_hdl)
{
int ret = OAL_STATUS_SUCCESS;
- API_TRACE("Server Stop Service : Ins_id = %d, srvHndl = %d, ", ins_id, srv_hdl);
+ API_TRACE("Server Stop Service : Ins_id = %d, srvHndl = %d, ", instance_id, srv_hdl);
CHECK_OAL_GATT_ENABLED();
- CHECK_SERVER_INSTANCE(ins_id);
- CHECK_SERVER_REGISTRATION(ins_id);
+ CHECK_SERVER_INSTANCE(instance_id);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
- ret = gatt_api->server->stop_service(gatt_servers[ins_id - 1].server_id, srv_hdl);
+ ret = gatt_api->server->stop_service(instance_id, srv_hdl);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT Server Stop Service failed: %s", status2string(ret));
return convert_to_oal_status(ret);
return OAL_STATUS_SUCCESS;
}
-oal_status_t gatts_delete_service(int ins_id, int srv_hdl)
+oal_status_t gatts_delete_service(int instance_id, int srv_hdl)
{
int ret = OAL_STATUS_SUCCESS;
- API_TRACE("Server Delete Service : Ins_id = %d, srvHndl = %d, ", ins_id, srv_hdl);
+ API_TRACE("Server Delete Service : Ins_id = %d, srvHndl = %d, ", instance_id, srv_hdl);
CHECK_OAL_GATT_ENABLED();
- CHECK_SERVER_INSTANCE(ins_id);
-
- CHECK_SERVER_REGISTRATION(ins_id);
+ CHECK_SERVER_INSTANCE(instance_id);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
- ret = gatt_api->server->delete_service(gatt_servers[ins_id - 1].server_id, srv_hdl);
+ ret = gatt_api->server->delete_service(instance_id, srv_hdl);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT Server Delete Service failed: %s", status2string(ret));
return convert_to_oal_status(ret);
return OAL_STATUS_SUCCESS;
}
-oal_status_t gatts_send_indication(int ins_id, int attr_hndl, int conn_id, int len, int confirm, char* value)
+oal_status_t gatts_send_indication(int instance_id, int attr_hndl, int conn_id, int len, int confirm, char* value)
{
int ret = OAL_STATUS_SUCCESS;
API_TRACE("Server Send Indication : Ins_id = %d, srvHndl = %d, [%s]",
- ins_id, attr_hndl, confirm == TRUE ? "INDICATION" : "NOTIFICATION");
+ instance_id, attr_hndl, confirm == TRUE ? "INDICATION" : "NOTIFICATION");
CHECK_OAL_GATT_ENABLED();
- CHECK_SERVER_INSTANCE(ins_id);
-
- CHECK_SERVER_REGISTRATION(ins_id);
+ CHECK_SERVER_INSTANCE(instance_id);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
if (value == NULL || len == 0) {
BT_ERR("GATT Server attribute value is empty");
return OAL_STATUS_INVALID_PARAM;
}
- ret = gatt_api->server->send_indication(gatt_servers[ins_id - 1].server_id,
+ ret = gatt_api->server->send_indication(instance_id,
attr_hndl, conn_id, len, confirm, value);
-
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT Server Send Indication failed: %s", status2string(ret));
return convert_to_oal_status(ret);
return OAL_STATUS_SUCCESS;
}
-oal_status_t gatts_update_att_value(int ins_id, oal_gatt_value_t *value)
+oal_status_t gatts_update_att_value(int instance_id, oal_gatt_value_t *value)
{
int ret = OAL_STATUS_SUCCESS;
CHECK_OAL_GATT_ENABLED();
- CHECK_SERVER_INSTANCE(ins_id);
-
- CHECK_SERVER_REGISTRATION(ins_id);
+ CHECK_SERVER_INSTANCE(instance_id);
+ if (__gatts_find_server_instance(instance_id) == NULL)
+ return OAL_STATUS_INTERNAL_ERROR;
if (value == NULL || value->len == 0) {
BT_ERR("GATT Server attribute value is empty");
}
API_TRACE("Server Update Value: Ins_id = [%d], att handle = [%d] data len [%d]",
- ins_id, value->handle, value->len);
+ instance_id, value->handle, value->len);
- ret = gatt_api->server->update_att_value(gatt_servers[ins_id - 1].server_id,
+ ret = gatt_api->server->update_att_value(instance_id,
(int)value->handle, (int)value->len, (char*)value->value);
-
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT Server Update Attribute Value failed: [%s]", status2string(ret));
return convert_to_oal_status(ret);
static void cb_gatts_service_added(int status, int server_if,
btgatt_srvc_id_t *psrvc_id, int srvc_handle)
{
- int instance_id;
-
BT_INFO("BTGATT SERVER SERVICE ADDED CB, status:%d, handle:%d", status, srvc_handle);
event_gatts_srvc_prm_t* event = g_new0(event_gatts_srvc_prm_t, 1);
- CHECK_CORRECT_SERVER_ID(instance_id, server_if, event->gatt_srvc_stat.server_inst);
+ CHECK_CORRECT_SERVER_ID(server_if, event->gatt_srvc_stat.server_inst);
BT_ERR("Invalid Interface, srv_if: %d", server_if);
event->gatt_srvc_stat.server_inst = -1;
int srvc_handle,
int incl_srvc_handle)
{
- int ins_id ;
BT_INFO("BTGATT SERVER INCLUDED SERVICE ADDED CB, status:%d, srvc handle:%d, incl handle:%d",
status, srvc_handle, incl_srvc_handle);
event_gatts_incld_srvc_t* event = g_new0(event_gatts_incld_srvc_t, 1);
- CHECK_CORRECT_SERVER_ID(ins_id, server_if, event->gatt_srvc_stat.server_inst);
+ CHECK_CORRECT_SERVER_ID(server_if, event->gatt_srvc_stat.server_inst);
BT_ERR("Invalid Interface, srv_if: %d", server_if);
event->gatt_srvc_stat.server_inst = -1;
static void cb_gatts_characteristic_added(int status, int server_if, bt_uuid_t *char_id,
int srvc_handle, int char_handle)
{
- int Ins_id ;
-
BT_INFO("BTGATT SERVER CHARACTERISTIC ADDED CB, status:%d, srvc handle:%d, char handle:%d",
status, srvc_handle, char_handle);
event_gatts_srvc_charctr_t* event = g_new0(event_gatts_srvc_charctr_t, 1);
- CHECK_CORRECT_SERVER_ID(Ins_id, server_if, event->gatt_srvc_stat.server_inst);
+ CHECK_CORRECT_SERVER_ID(server_if, event->gatt_srvc_stat.server_inst);
BT_ERR("Invalid Interface, srv_if: %d", server_if);
event->gatt_srvc_stat.server_inst = -1;
bt_uuid_t *descr_id, int srvc_handle,
int descr_handle)
{
- int Ins_id ;
BT_INFO("BTGATT SERVER DESCRIPTOR ADDED CB, status:%d, srvc handle:%d, desc handle:%d",
status, srvc_handle, descr_handle);
event_gatts_srvc_descr_t* event = g_new0(event_gatts_srvc_descr_t, 1);
- CHECK_CORRECT_SERVER_ID(Ins_id, server_if, event->gatt_srvc_stat.server_inst);
+ CHECK_CORRECT_SERVER_ID(server_if, event->gatt_srvc_stat.server_inst);
BT_ERR("Invalid Interface, srv_if: %d", server_if);
event->gatt_srvc_stat.server_inst = -1;
static void cb_gatts_service_started(int status, int server_if, int srvc_handle)
{
- int Ins_id ;
BT_INFO("BTGATT SERVER SERVICE STARTED CB, status:%d, srvc_handle:%d", status, srvc_handle);
event_gatts_srvc_t* event = g_new0(event_gatts_srvc_t, 1);
- CHECK_CORRECT_SERVER_ID(Ins_id, server_if, event->server_inst);
+ CHECK_CORRECT_SERVER_ID(server_if, event->server_inst);
BT_ERR("Invalid Interface, srv_if: %d", server_if);
event->server_inst = -1;
static void cb_gatts_service_stopped(int status, int server_if, int srvc_handle)
{
- int ins_id ;
BT_INFO("BTGATT SERVER SERVICE STOPPED CB, status:%d, srvc_handle:%d", status, srvc_handle);
event_gatts_srvc_t* event = g_new0(event_gatts_srvc_t, 1);
- CHECK_CORRECT_SERVER_ID(ins_id, server_if, event->server_inst);
+ CHECK_CORRECT_SERVER_ID(server_if, event->server_inst);
BT_ERR("Invalid Interface, srv_if: %d", server_if);
event->server_inst = -1;
static void cb_gatts_service_deleted(int status, int server_if, int srvc_handle)
{
- int ins_id;
BT_INFO("BTGATT SERVER SERVICE DELETED CB, status:%d, srvc_handle:%d", status, srvc_handle);
event_gatts_srvc_t* event = g_new0(event_gatts_srvc_t, 1);
- CHECK_CORRECT_SERVER_ID(ins_id, server_if, event->server_inst);
+ CHECK_CORRECT_SERVER_ID(server_if, event->server_inst);
BT_ERR("Invalid Interface, srv_if: %d", server_if);
event->server_inst = -1;
static void cb_gatts_connection(int conn_id, int server_if, int connected, bt_bdaddr_t *bda)
{
- int ins_id ;
+ GSList *l;
oal_event_t event_type;
BT_INFO("BTGATT SERVER CONNECTION connnected:%d, conn_id:%d server_if:%d", connected, conn_id, server_if);
event_gatts_conn_t *event = g_new0(event_gatts_conn_t, 1);
if (connected == TRUE) {
- for (ins_id = 1 ; ins_id <= NUM_SERVER_INST ; ins_id++) {
- if ((gatt_servers[ins_id - 1].server_id == server_if)) {
- event->server_inst = ins_id;
+ for (l = gatt_servers; l; l = g_slist_next(l)) {
+ gatt_server_t *info = l->data;
+ if (!info)
+ continue;
+ if (info->instance_id == server_if) {
+ event->server_inst = server_if;
break;
- } else {
- BT_INFO("Server ID:%d recevied server Id:%d\n", gatt_servers[ins_id - 1].server_id, server_if);
}
}
- if (ins_id == NUM_SERVER_INST+1) {
- BT_WARN("Incorrect Server Interface received: %d\n", server_if);
- g_free(event);
- return;
- }
} else {
/* server_inst is not required in disconnected case */
}
static void cb_gatts_request_read(int conn_id, int trans_id, bt_bdaddr_t *bda,
int attr_handle, int offset, bool is_long)
{
- BT_INFO("BTGATT SERVER REQUEST READ CB: conn_id:%d", conn_id);
+ BT_DBG("BTGATT SERVER REQUEST READ CB: conn_id:%d", conn_id);
event_gatts_srvc_read_attr_t* event = g_new0(event_gatts_srvc_read_attr_t, 1);
{
char uuid_str1[2*BT_UUID_STRING_MAX];
char uuid_str2[2*BT_UUID_STRING_MAX];
- BT_INFO("BTGATT Client Read Charcateristic Callback, conn_id:%d, read_status:%d", conn_id, status);
+ BT_DBG("BTGATT Client Read Charcateristic Callback, conn_id:%d, read_status:%d", conn_id, status);
event_gattc_read_data *event = g_new0(event_gattc_read_data, 1);
event->uuid_status.conn_status.conn_id = conn_id;
if (status == 0) {
uuid_to_stringname((oal_uuid_t *)&(p_data->srvc_id.id.uuid), uuid_str1);
uuid_to_stringname((oal_uuid_t *)&(p_data->char_id.uuid), uuid_str2);
- BT_INFO("Service=> [%s], Inst_id [%u], Type [%s]", uuid_str1,
+ BT_DBG("Service=> [%s], Inst_id [%u], Type [%s]", uuid_str1,
p_data->srvc_id.id.inst_id, p_data->srvc_id.is_primary ? "Primary" : "Secondary");
- BT_INFO("Charac => [%s], Inst_id [%u]", uuid_str2, p_data->char_id.inst_id);
+ BT_DBG("Charac => [%s], Inst_id [%u]", uuid_str2, p_data->char_id.inst_id);
BT_DBG("Len: %u, value_type: %u", p_data->value.len, p_data->value_type);
if (p_data->value.len > 0 && event->value_type == GATTC_READ_VALUE_TYPE_VALUE) {
event->data_len = p_data->value.len;
char uuid_str1[2*BT_UUID_STRING_MAX];
char uuid_str2[2*BT_UUID_STRING_MAX];
char uuid_str3[2*BT_UUID_STRING_MAX];
- BT_INFO("BTGATT Client Write Descriptor Callback, conn_id:%d, write_status:%d", conn_id, status);
+ BT_DBG("BTGATT Client Write Descriptor Callback, conn_id:%d, write_status:%d", conn_id, status);
event_gattc_write_data *event = g_new0(event_gattc_write_data, 1);
event->conn_status.conn_id = conn_id;
int ret = OAL_STATUS_SUCCESS;
- API_TRACE("Scan is stopped");
+ API_TRACE("BTGATT CLIENT SCAN STOP");
CHECK_OAL_GATT_ENABLED();
CHECK_CLIENT_REGISTRATION(client_id);
ret = gatt_api->client->scan(client_id, 0);
{
int ret;
- API_TRACE("Scan is stopped");
+ API_TRACE("GATT client set le scan param");
CHECK_OAL_GATT_ENABLED();
#ifdef TIZEN_BT_HAL
bdstr_t bdstr;
OAL_CHECK_PARAMETER(device_address, return);
- API_TRACE("Client Connect: [%s]", bdt_bd2str(device_address, &bdstr));
+ API_TRACE("Client Connect: [%s]", bdt_bd2str(device_address, &bdstr) + 12);
CHECK_OAL_GATT_ENABLED();
CHECK_CLIENT_REGISTRATION(client_id);
bdstr_t bdstr;
OAL_CHECK_PARAMETER(device_address, return);
- API_TRACE("Client Disconnect: [%s]", bdt_bd2str(device_address, &bdstr));
+ API_TRACE("Client Disconnect: [%s]", bdt_bd2str(device_address, &bdstr) + 12);
CHECK_OAL_GATT_ENABLED();
CHECK_CLIENT_REGISTRATION(client_id);
CHECK_CLIENT_CONNECTION(conn_id);
bdstr_t bdstr;
OAL_CHECK_PARAMETER(address, return);
- API_TRACE("Conn Param Update: [%s]", bdt_bd2str(address, &bdstr));
CHECK_OAL_GATT_ENABLED();
- BT_INFO("[%s] min[%d] max[%d] latency[%d] timeout[%d]", bdt_bd2str(address, &bdstr), min, max, latency, timeout);
+ BT_DBG("[%s] min[%d] max[%d] latency[%d] timeout[%d]", bdt_bd2str(address, &bdstr), min, max, latency, timeout);
ret = gatt_api->client->conn_parameter_update((bt_bdaddr_t *)address, min, max, latency, timeout);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("error: %s", status2string(ret));
return OAL_STATUS_SUCCESS;
}
+oal_status_t gattc_get_att_mtu(int conn_id, int *mtu)
+{
+ int ret = OAL_STATUS_SUCCESS;
+ API_TRACE("Get ATT MTU, conn_id: %d", conn_id);
+ CHECK_OAL_GATT_ENABLED();
+ CHECK_CLIENT_CONNECTION(conn_id);
+ OAL_CHECK_PARAMETER(mtu, return);
+
+ /* To prevent crash in case other libraries not support this api */
+ if (gatt_api->client->get_att_mtu == NULL) {
+ BT_WARN("get_att_mtu is NULL");
+ return OAL_STATUS_NOT_SUPPORT;
+ }
+
+ ret = gatt_api->client->get_att_mtu(conn_id, mtu);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("GATT MTU Size failed, status: %s", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+
+ BT_INFO("Current ATT MTU Size: %d", *mtu);
+ return OAL_STATUS_SUCCESS;
+}
+
oal_status_t gattc_configure_mtu(int conn_id, int mtu)
{
int ret;
BT_ERR("Gatt client configure_mtu error: %s", status2string(ret));
return convert_to_oal_status(ret);
}
+
+ return OAL_STATUS_SUCCESS;
+}
+
+oal_status_t gatt_get_data_batching_available_packets(
+ unsigned int *available_packets)
+{
+ int ret;
+
+ ret = gatt_api->client->get_data_batching_available_packets(available_packets);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("GATT data batching failed: %s", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+
+ return OAL_STATUS_SUCCESS;
+}
+
+oal_status_t gatt_enable_data_batching(bt_address_t * address,
+ int packet_threshold, int timeout)
+{
+ int ret;
+
+ ret = gatt_api->client->enable_data_batching((bt_bdaddr_t *)address, packet_threshold, timeout);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("GATT data batching failed: %s", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+
+ return OAL_STATUS_SUCCESS;
+}
+
+oal_status_t gatt_disable_data_batching(bt_address_t * address)
+{
+ int ret;
+
+ ret = gatt_api->client->disable_data_batching((bt_bdaddr_t *)address);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("GATT data batching failed: %s", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+
return OAL_STATUS_SUCCESS;
}
-oal_status_t gattc_add_connection_info(bt_address_t *device_address, int conn_id, int server_inst_id)
+oal_status_t gattc_add_connection_info(bt_address_t *device_address, int conn_id, int instance_id)
{
int ret = OAL_STATUS_SUCCESS;
bdstr_t bdstr;
OAL_CHECK_PARAMETER(device_address, return);
- API_TRACE("Add connection info: [%s]", bdt_bd2str(device_address, &bdstr));
+ API_TRACE("Add connection info: [%s]", bdt_bd2str(device_address, &bdstr) + 12);
CHECK_OAL_GATT_ENABLED();
- CHECK_SERVER_INSTANCE(server_inst_id);
- CHECK_SERVER_REGISTRATION(server_inst_id);
- ret = gatt_api->client->add_connection_info((bt_bdaddr_t *)device_address, conn_id, server_inst_id);
+ ret = gatt_api->client->add_connection_info((bt_bdaddr_t *)device_address, conn_id, instance_id);
if (ret != BT_STATUS_SUCCESS) {
BT_ERR("GATT connection info add failed: %s", status2string(ret));
return convert_to_oal_status(ret);