+
+oal_status_t gattc_unregister_scan_filter(int slot_id)
+{
+ int ret;
+ int client_if = 0;
+
+ API_TRACE("");
+ CHECK_OAL_GATT_ENABLED();
+
+ BT_INFO("Remove Scan filter Slot ID is: [%d]", slot_id);
+
+ ret = gatt_api->client->scan_filter_clear(client_if, slot_id);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("error: %s", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+ return OAL_STATUS_SUCCESS;
+}
+
+oal_status_t gattc_enable_scan_filter(int client_if)
+{
+ int ret;
+
+ API_TRACE("");
+ CHECK_OAL_GATT_ENABLED();
+
+ BT_INFO("Enable Scan filter. Client If: %d", client_if);
+
+ ret = gatt_api->client->scan_filter_enable(client_if, TRUE);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("error: %s", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+ return OAL_STATUS_SUCCESS;
+}
+
+oal_status_t gattc_disable_scan_filter(int client_if)
+{
+ int ret;
+
+ API_TRACE("");
+ CHECK_OAL_GATT_ENABLED();
+
+ BT_INFO("Disable Scan filter. Client If: %d", client_if);
+
+ ret = gatt_api->client->scan_filter_enable(client_if, FALSE);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("error: %s", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+ return OAL_STATUS_SUCCESS;
+}
+
+oal_status_t gattc_register_scan_filter(oal_ble_scan_filter_t* filter_data)
+{
+ int ret;
+ int client_info = 0;
+ int action = 0;
+ int company_id = 0;
+ int company_id_mask = 0;
+ int address_type = 0;
+ int feature_selection = 0;
+
+ oal_ble_scan_filter_param_setup_t scan_filter_setup = {.list_logic_type = 0,
+ .filt_logic_type = 1,
+ .rssi_high_thres = -127,
+ .rssi_low_thres = -127,
+ .dely_mode = 0,
+ .found_timeout = 0,
+ .lost_timeout = 0,
+ .found_timeout_cnt = 0
+ };
+
+ OAL_CHECK_PARAMETER(filter_data, return);
+ API_TRACE();
+ CHECK_OAL_GATT_ENABLED();
+
+ if (filter_data->added_features & OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS){
+ bdstr_t bdstr;
+ BT_INFO("OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS is being added");
+ BT_INFO("BT remote Device address is %s", bdt_bd2str(filter_data->device_address, &bdstr));
+ ret = gatt_api->client->scan_filter_add_remove(client_info,
+ action,
+ OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS,
+ filter_data->slot_id,
+ company_id,
+ company_id_mask,
+ NULL,
+ NULL,
+ (bt_bdaddr_t*)filter_data->device_address,
+ address_type,
+ 0,
+ NULL,
+ 0,
+ NULL
+ );
+ if (ret != BT_STATUS_SUCCESS){
+ BT_ERR("error: %s", status2string(ret));
+ BT_INFO("unregistering already set filter features.");
+ gatt_api->client->scan_filter_clear(client_info, filter_data->slot_id);
+ return convert_to_oal_status(ret);
+ }
+
+ feature_selection |= OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS;
+ }
+ if (filter_data->added_features & OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_NAME){
+ ret = gatt_api->client->scan_filter_add_remove(client_info,
+ action,
+ OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_NAME,
+ filter_data->slot_id,
+ company_id,
+ company_id_mask,
+ NULL,
+ NULL,
+ NULL,
+ address_type,
+ 0,
+ filter_data->device_name, // device_name as p_data in HAL
+ 0,
+ NULL
+ );
+ if (ret != BT_STATUS_SUCCESS){
+ BT_ERR("error: %s", status2string(ret));
+ BT_INFO("unregistering already set filter features.");
+ gatt_api->client->scan_filter_clear(client_info, filter_data->slot_id);
+ return convert_to_oal_status(ret);
+ }
+
+ feature_selection |= OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_NAME;
+ }
+ if (filter_data->added_features & OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_UUID){
+ BT_INFO("OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_UUID is being added");
+ char uuid_str1[2*BT_UUID_STRING_MAX];
+ char uuid_str2[2*BT_UUID_STRING_MAX];
+
+ uuid_to_stringname((service_uuid_t*)filter_data->service_uuid, uuid_str1);
+ uuid_to_stringname((service_uuid_t*)filter_data->service_uuid_mask, uuid_str2);
+
+ BT_INFO("Service UUID is [%s] and Service UUID mask is [%s]", uuid_str1, uuid_str2);
+ ret = gatt_api->client->scan_filter_add_remove(client_info,
+ action,
+ OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_UUID,
+ filter_data->slot_id,
+ company_id,
+ company_id_mask,
+ (bt_uuid_t*)filter_data->service_uuid,
+ (bt_uuid_t*)filter_data->service_uuid_mask,
+ NULL,
+ address_type,
+ filter_data->service_uuid_len, // service_uuid_len as data_len in HAL
+ NULL,
+ filter_data->service_uuid_mask_len,
+ NULL
+ );
+ if (ret != BT_STATUS_SUCCESS){
+ BT_ERR("error: %s", status2string(ret));
+ BT_INFO("unregistering already set filter features.");
+ gatt_api->client->scan_filter_clear(client_info, filter_data->slot_id);
+ return convert_to_oal_status(ret);
+ }
+
+ feature_selection |= OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_UUID;
+ }
+ if (filter_data->added_features & OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID){
+ BT_INFO("OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID is being added");
+ char uuid_str1[2*BT_UUID_STRING_MAX];
+ char uuid_str2[2*BT_UUID_STRING_MAX];
+ uuid_to_stringname((service_uuid_t*)filter_data->service_solicitation_uuid, uuid_str1);
+ uuid_to_stringname((service_uuid_t*)filter_data->service_solicitation_uuid_mask, uuid_str2);
+ BT_INFO("Service Solicitation UUID is [%s] and Service Solicitation UUID mask is [%s]", uuid_str1, uuid_str2);
+ ret = gatt_api->client->scan_filter_add_remove(client_info,
+ action,
+ OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID,
+ filter_data->slot_id,
+ company_id,
+ company_id_mask,
+ (bt_uuid_t*)filter_data->service_solicitation_uuid,
+ (bt_uuid_t*)filter_data->service_solicitation_uuid_mask,
+ NULL,
+ address_type,
+ filter_data->service_solicitation_uuid_len, // service_solicitation_uuid_len as data_len in HAL
+ NULL,
+ filter_data->service_solicitation_uuid_mask_len,
+ NULL
+ );
+ if (ret != BT_STATUS_SUCCESS){
+ BT_ERR("error: %s", status2string(ret));
+ BT_INFO("unregistering already set filter features.");
+ gatt_api->client->scan_filter_clear(client_info, filter_data->slot_id);
+ return convert_to_oal_status(ret);
+ }
+
+ feature_selection |= OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID;
+ }
+ if (filter_data->added_features & OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_DATA){
+ ret = gatt_api->client->scan_filter_add_remove(client_info,
+ action,
+ OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_DATA,
+ filter_data->slot_id,
+ company_id,
+ company_id_mask,
+ NULL,
+ NULL,
+ NULL,
+ address_type,
+ filter_data->service_data_len, //service_data_len as data_len in HAL
+ (char*)filter_data->service_data,
+ filter_data->service_data_mask_len,
+ (char*)filter_data->service_data_mask
+ );
+ if (ret != BT_STATUS_SUCCESS){
+ BT_ERR("error: %s", status2string(ret));
+ BT_INFO("unregistering already set filter features.");
+ gatt_api->client->scan_filter_clear(client_info, filter_data->slot_id);
+ return convert_to_oal_status(ret);
+ }
+
+ feature_selection |= OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_DATA;
+ }
+ if (filter_data->added_features & OAL_BLE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA){
+ ret = gatt_api->client->scan_filter_add_remove(client_info,
+ action,
+ OAL_BLE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA,
+ filter_data->slot_id,
+ filter_data->manufacturer_id,
+ company_id_mask,
+ NULL,
+ NULL,
+ NULL,
+ address_type,
+ filter_data->manufacturer_data_len, //manufacturer_data_len as data_len in HAL
+ (char*)filter_data->manufacturer_data,
+ filter_data->manufacturer_data_mask_len,
+ (char*)filter_data->manufacturer_data_mask
+ );
+ feature_selection |= OAL_BLE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA;
+ if (ret != BT_STATUS_SUCCESS){
+ BT_ERR("error: %s", status2string(ret));
+ BT_INFO("unregistering already set filter features.");
+ gatt_api->client->scan_filter_clear(client_info, filter_data->slot_id);
+ return convert_to_oal_status(ret);
+ }
+
+ feature_selection |= OAL_BLE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA;
+ }
+
+ BT_DBG("Filter selection 0x%.2x", feature_selection);
+
+ ret = gatt_api->client->scan_filter_param_setup(client_info, action, filter_data->slot_id, feature_selection,
+ scan_filter_setup.list_logic_type, scan_filter_setup.filt_logic_type,
+ scan_filter_setup.rssi_high_thres, scan_filter_setup.rssi_low_thres,
+ scan_filter_setup.dely_mode, scan_filter_setup.found_timeout,
+ scan_filter_setup.lost_timeout, scan_filter_setup.found_timeout_cnt);
+ if (ret != BT_STATUS_SUCCESS){
+ BT_ERR("error: %s", status2string(ret));
+ return convert_to_oal_status(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;
+
+ API_TRACE("Configure MTU Size: [%d]", mtu);
+ CHECK_OAL_GATT_ENABLED();
+ CHECK_CLIENT_CONNECTION(conn_id);
+
+ /* To prevent crash in case other libraries not support this api */
+ if (gatt_api->client->configure_mtu == NULL) {
+ BT_WARN("configure_mtu is NULL");
+ return OAL_STATUS_NOT_SUPPORT;
+ }
+
+ ret = gatt_api->client->configure_mtu(conn_id, mtu);
+ if (ret != BT_STATUS_SUCCESS) {
+ 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 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) + 12);
+ CHECK_OAL_GATT_ENABLED();
+
+ 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);
+ }
+ return OAL_STATUS_SUCCESS;
+}
+