static gboolean cur_adv_state[NUM_SERVER_INST];
static gatt_server_t gatt_servers[NUM_SERVER_INST];
-static int default_client_id = -1;
-static int pending_gattc_req = OAL_REQ_NONE;
-
/* Forward declarations of GATT Server callbacks */
static void cb_gatts_register_app(int status, int server_if, bt_uuid_t *uuid);
static void cb_gatts_multi_adv_enable(int server_if, int status);
static void cb_gattc_read_descriptor(int conn_id, int status, btgatt_read_params_t *p_data);
static void cb_gattc_write_characteristic(int conn_id, int status, btgatt_write_params_t *p_data);
static void cb_gattc_write_descriptor(int conn_id, int status, btgatt_write_params_t *p_data);
+static void cb_gattc_register_for_notification(int conn_id, int registered, int status,
+ btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id);
/*TODO GATT CLient callbacks will be implemented in subsequent patches */
static const btgatt_client_callbacks_t btgatt_client_callbacks = {
cb_gattc_get_characteristics, /*cb_gattc_get_characteristics*/
cb_gattc_get_descriptor, /*cb_gattc_get_descriptor*/
NULL, /*cb_gattc_get_included_service*/
- NULL, /*cb_gattc_register_for_notification*/
+ cb_gattc_register_for_notification, /*cb_gattc_register_for_notification*/
NULL, /*cb_gattc_notify*/
cb_gattc_read_characteristic, /*cb_gattc_read_characteristic*/
cb_gattc_write_characteristic, /*cb_gattc_write_characteristic*/
adv_setup.server_if = gatt_servers[instance_id - 1].server_id;
if (adv_setup.manufacturer_data_len > 0 && adv_setup.manufacturer_data != NULL) {
BT_INFO("Manufacture data.....\n");
- PRINT_ADV_DATA(adv_setup.manufacturer_data_len, adv_setup.manufacturer_data, adv_setup.set_scan_rsp);
+ PRINT_ADV_DATA(adv_setup.manufacturer_data_len, (unsigned char *)adv_setup.manufacturer_data, adv_setup.set_scan_rsp);
}
if (adv_setup.service_uuid_len > 0 && adv_setup.service_uuid != NULL) {
BT_INFO("Service uuid.....\n");
- PRINT_ADV_DATA(adv_setup.service_uuid_len, adv_setup.service_uuid, FALSE);
+ PRINT_ADV_DATA(adv_setup.service_uuid_len, (unsigned char*)adv_setup.service_uuid, FALSE);
}
cur_adv_state[event->server_inst - 1] = new_state;
} else {
BT_ERR("Invalid Callback...");
+ g_free(event);
return;
}
send_event(OAL_EVENT_GATTC_DESC_SERACH_RESULT, event, sizeof(*event));
}
+static void cb_gattc_register_for_notification(int client_if, int registered, int status, btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id)
+{
+ char uuid_str1[2*BT_UUID_STRING_MAX];
+ char uuid_str2[2*BT_UUID_STRING_MAX];
+ BT_INFO("BTGATT Client Register For Notification Callback, client_if:%d, status:%d, registered: %s",
+ client_if, status, registered == 1 ? "REGISTERED" : "DEREGISTERED");
+ uuid_to_stringname((oal_uuid_t *)&(srvc_id->id.uuid), uuid_str1);
+ uuid_to_stringname((oal_uuid_t *)&(char_id->uuid), uuid_str2);
+ BT_INFO("Service=> UUID: [%s], Inst_id: [%u], Type: [%s]", uuid_str1, srvc_id->id.inst_id, srvc_id->is_primary ? "Primary" : "Secondary");
+ BT_INFO("Charac=> UUID: [%s], Inst_id: [%u]", uuid_str2, char_id->inst_id);
+
+ event_gattc_regdereg_notify_t *event = g_new0(event_gattc_regdereg_notify_t, 1);
+ oal_event_t event_type = (registered == 1 ? OAL_EVENT_GATTC_NOTIFICATION_REGISTERED : OAL_EVENT_GATTC_NOTIFICATION_DEREGISTERED);
+ event->client_if = client_if;
+ event->status = convert_to_oal_status(status);
+ memcpy(&(event->srvc_id), srvc_id, sizeof(oal_gatt_srvc_id_t));
+ memcpy(&(event->char_id), char_id, sizeof(oal_gatt_id_t));
+
+ send_event(event_type, event, sizeof(*event));
+}
+
+
static void cb_gattc_read_characteristic(int conn_id, int status, btgatt_read_params_t *p_data)
{
char uuid_str1[2*BT_UUID_STRING_MAX];
send_event(OAL_EVENT_GATTC_READ_DESCR, event, sizeof(*event));
}
-
-/* Register default gatt client to be used in LE scan etc. */
-static oal_status_t __register_default_gatt_client(void)
-{
- bt_uuid_t uuid;
- int ret;
-
- API_TRACE("GATT client register");
- CHECK_OAL_GATT_ENABLED();
-
- if (default_client_id >= 0) {
- BT_ERR("Client Already registered");
- return OAL_STATUS_ALREADY_DONE;
- }
-
- string_to_uuid(DEFAULT_GATT_CLIENT_UUID, (service_uuid_t *)&uuid);
- ret = gatt_api->client->register_client(&uuid);
- if (ret != BT_STATUS_SUCCESS) {
- BT_ERR("GATT client register failed: %s", status2string(ret));
- return convert_to_oal_status(ret);
- }
-
- return OAL_STATUS_SUCCESS;
-}
-
oal_status_t gattc_start_le_discovery(int client_id)
{
return OAL_STATUS_SUCCESS;
}
+oal_status_t gattc_register_for_notification(int client_id, bt_address_t * address,
+ oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id) {
+ int ret = OAL_STATUS_SUCCESS;
+ char uuid_str1[2*BT_UUID_STRING_MAX];
+ char uuid_str2[2*BT_UUID_STRING_MAX];
+ bdstr_t bdstr;
+
+ OAL_CHECK_PARAMETER(address, return);
+ OAL_CHECK_PARAMETER(srvc_id, return);
+ OAL_CHECK_PARAMETER(char_id, return);
+ uuid_to_stringname(&(srvc_id->id.uuid), uuid_str1);
+ uuid_to_stringname(&(char_id->uuid), uuid_str2);
+ API_TRACE("Client Register Notification: [%s], Service_uuid: [%s], Char_uuid: [%s]", bdt_bd2str(address, &bdstr), uuid_str1, uuid_str2);
+ CHECK_OAL_GATT_ENABLED();
+ CHECK_CLIENT_REGISTRATION(client_id);
+
+ ret = gatt_api->client->register_for_notification(client_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("GATT client register notification failed: %s", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+
+ return OAL_STATUS_SUCCESS;
+}
+
+oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * address,
+ oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id) {
+ int ret = OAL_STATUS_SUCCESS;
+ char uuid_str1[2*BT_UUID_STRING_MAX];
+ char uuid_str2[2*BT_UUID_STRING_MAX];
+ bdstr_t bdstr;
+
+ OAL_CHECK_PARAMETER(address, return);
+ OAL_CHECK_PARAMETER(srvc_id, return);
+ OAL_CHECK_PARAMETER(char_id, return);
+ uuid_to_stringname(&(srvc_id->id.uuid), uuid_str1);
+ uuid_to_stringname(&(char_id->uuid), uuid_str2);
+ API_TRACE("Client Deregister Notification: [%s], Service_uuid: [%s], Char_uuid: [%s]", bdt_bd2str(address, &bdstr), uuid_str1, uuid_str2);
+ CHECK_OAL_GATT_ENABLED();
+ CHECK_CLIENT_REGISTRATION(client_id);
+
+ ret = gatt_api->client->deregister_for_notification(client_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("GATT client deregister notification failed: %s", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+
+ return OAL_STATUS_SUCCESS;
+}
+
+
oal_status_t gattc_read_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id,
oal_gatt_id_t *char_id, oal_gatt_auth_req_t auth_req)
{