Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adpt zephy le feature #20

Merged
merged 8 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions framework/include/bt_le_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,19 @@ enum {

typedef void bt_scanner_t;

#ifdef CONFIG_BLUETOOTH_STACK_LE_ZBLUE
#define BT_LE_SCAN_TYPE_PASSIVE BT_LE_SCAN_TYPE_PASSIVE_MODE
#define BT_LE_SCAN_TYPE_ACTIVE BT_LE_SCAN_TYPE_ACTIVE_MODE
typedef enum {
BT_LE_SCAN_TYPE_PASSIVE_MODE = 0,
BT_LE_SCAN_TYPE_ACTIVE_MODE
} ble_scan_type_t;
#else
typedef enum {
BT_LE_SCAN_TYPE_PASSIVE = 0,
BT_LE_SCAN_TYPE_ACTIVE
} ble_scan_type_t;
#endif

/**
* @brief Scan result structure
Expand Down
8 changes: 8 additions & 0 deletions framework/include/bt_uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@ typedef struct {
} val;
} bt_uuid_t;

#ifndef BT_UUID_DECLARE_16
#define BT_UUID_DECLARE_16(value) \
((bt_uuid_t) { .type = BT_UUID16_TYPE, .val.u16 = (value) })
#endif

#ifndef BT_UUID_DECLARE_32
#define BT_UUID_DECLARE_32(value) \
((bt_uuid_t) { .type = BT_UUID32_TYPE, .val.u32 = (value) })
#endif

#ifndef BT_UUID_DECLARE_128
#define BT_UUID_DECLARE_128(value...) \
((bt_uuid_t) { .type = BT_UUID128_TYPE, .val.u128 = { value } })
#endif

void bt_uuid_to_uuid128(const bt_uuid_t* src, bt_uuid_t* uuid128);
int bt_uuid_compare(const bt_uuid_t* uuid1, const bt_uuid_t* uuid2);
Expand Down
32 changes: 16 additions & 16 deletions service/profiles/gatt/gattc_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static void gattc_connection_delete(gattc_connection_t* connection)
return;

if (connection->state == PROFILE_STATE_CONNECTING || connection->state == PROFILE_STATE_CONNECTED)
bt_sal_gatt_client_disconnect(&connection->remote_addr);
bt_sal_gatt_client_disconnect(PRIMARY_ADAPTER, &connection->remote_addr);
index_free(g_gattc_manager.allocator, connection->conn_id);
bt_list_free(connection->services);
connection->services = NULL;
Expand Down Expand Up @@ -521,7 +521,7 @@ static bt_status_t if_gattc_delete_connect(void* conn_handle)
CHECK_CONNECTION_VALID(g_gattc_manager.connections, connection);

void** user_phandle = connection->user_phandle;
bt_sal_gatt_client_disconnect(&connection->remote_addr);
bt_sal_gatt_client_disconnect(PRIMARY_ADAPTER, &connection->remote_addr);
bt_list_free(connection->services);
connection->services = NULL;
pthread_mutex_lock(&g_gattc_manager.device_lock);
Expand All @@ -540,7 +540,7 @@ static bt_status_t if_gattc_connect(void* conn_handle, bt_address_t* addr, ble_a
CHECK_CONNECTION_VALID(g_gattc_manager.connections, connection);

BT_ADDR_LOG("GATTC-CONNECT-REQUEST addr:%s", addr);
bt_status_t status = bt_sal_gatt_client_connect(addr, addr_type);
bt_status_t status = bt_sal_gatt_client_connect(PRIMARY_ADAPTER, addr, addr_type);
if (status == BT_STATUS_SUCCESS) {
connection->state = PROFILE_STATE_CONNECTING;
memcpy(&connection->remote_addr, addr, sizeof(connection->remote_addr));
Expand All @@ -557,7 +557,7 @@ static bt_status_t if_gattc_disconnect(void* conn_handle)
CHECK_CONNECTION_VALID(g_gattc_manager.connections, connection);

BT_ADDR_LOG("GATTC-DISCONNECT-REQUEST addr:%s", &connection->remote_addr);
bt_status_t status = bt_sal_gatt_client_disconnect(&connection->remote_addr);
bt_status_t status = bt_sal_gatt_client_disconnect(PRIMARY_ADAPTER, &connection->remote_addr);
if (status == BT_STATUS_SUCCESS)
connection->state = PROFILE_STATE_DISCONNECTING;

Expand All @@ -573,9 +573,9 @@ static bt_status_t if_gattc_discover_service(void* conn_handle, bt_uuid_t* filte

bt_status_t status;
if (!filter_uuid || !filter_uuid->type) {
status = bt_sal_gatt_client_discover_all_services(&connection->remote_addr);
status = bt_sal_gatt_client_discover_all_services(PRIMARY_ADAPTER, &connection->remote_addr);
} else {
status = bt_sal_gatt_client_discover_service_by_uuid(&connection->remote_addr, filter_uuid);
status = bt_sal_gatt_client_discover_service_by_uuid(PRIMARY_ADAPTER, &connection->remote_addr, filter_uuid);
}

return status;
Expand Down Expand Up @@ -630,7 +630,7 @@ static bt_status_t if_gattc_read(void* conn_handle, uint16_t attr_handle)
CHECK_ENABLED();
CHECK_CONNECTION_VALID(g_gattc_manager.connections, connection);

return bt_sal_gatt_client_read_element(&connection->remote_addr, attr_handle);
return bt_sal_gatt_client_read_element(PRIMARY_ADAPTER, &connection->remote_addr, attr_handle);
}

static bt_status_t if_gattc_write(void* conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
Expand All @@ -640,7 +640,7 @@ static bt_status_t if_gattc_write(void* conn_handle, uint16_t attr_handle, uint8
CHECK_ENABLED();
CHECK_CONNECTION_VALID(g_gattc_manager.connections, connection);

return bt_sal_gatt_client_write_element(&connection->remote_addr, attr_handle,
return bt_sal_gatt_client_write_element(PRIMARY_ADAPTER, &connection->remote_addr, attr_handle,
value, length, GATT_WRITE_TYPE_RSP);
}

Expand All @@ -651,7 +651,7 @@ static bt_status_t if_gattc_write_without_response(void* conn_handle, uint16_t a
CHECK_ENABLED();
CHECK_CONNECTION_VALID(g_gattc_manager.connections, connection);

return bt_sal_gatt_client_write_element(&connection->remote_addr, attr_handle,
return bt_sal_gatt_client_write_element(PRIMARY_ADAPTER, &connection->remote_addr, attr_handle,
value, length, GATT_WRITE_TYPE_NO_RSP);
}

Expand Down Expand Up @@ -683,7 +683,7 @@ static bt_status_t if_gattc_subscribe(void* conn_handle, uint16_t attr_handle, u
return BT_STATUS_PARM_INVALID;
}

return bt_sal_gatt_client_register_notifications(&connection->remote_addr, attr_handle, properties, true);
return bt_sal_gatt_client_register_notifications(PRIMARY_ADAPTER, &connection->remote_addr, attr_handle, properties, true);
}

static bt_status_t if_gattc_unsubscribe(void* conn_handle, uint16_t attr_handle)
Expand All @@ -703,7 +703,7 @@ static bt_status_t if_gattc_unsubscribe(void* conn_handle, uint16_t attr_handle)
return BT_STATUS_NOT_SUPPORTED;
}

return bt_sal_gatt_client_register_notifications(&connection->remote_addr, attr_handle, element->properties, false);
return bt_sal_gatt_client_register_notifications(PRIMARY_ADAPTER, &connection->remote_addr, attr_handle, element->properties, false);
}

static bt_status_t if_gattc_exchange_mtu(void* conn_handle, uint32_t mtu)
Expand All @@ -717,7 +717,7 @@ static bt_status_t if_gattc_exchange_mtu(void* conn_handle, uint32_t mtu)
mtu = GATT_MAX_MTU_SIZE;
}

return bt_sal_gatt_client_send_mtu_req(&connection->remote_addr, mtu);
return bt_sal_gatt_client_send_mtu_req(PRIMARY_ADAPTER, &connection->remote_addr, mtu);
}

static bt_status_t if_gattc_update_connection_parameter(void* conn_handle, uint32_t min_interval, uint32_t max_interval, uint32_t latency,
Expand All @@ -728,7 +728,7 @@ static bt_status_t if_gattc_update_connection_parameter(void* conn_handle, uint3
CHECK_ENABLED();
CHECK_CONNECTION_VALID(g_gattc_manager.connections, connection);

return bt_sal_gatt_client_update_connection_parameter(&connection->remote_addr, min_interval, max_interval, latency,
return bt_sal_gatt_client_update_connection_parameter(PRIMARY_ADAPTER, &connection->remote_addr, min_interval, max_interval, latency,
timeout, min_connection_event_length, max_connection_event_length);
}

Expand All @@ -739,7 +739,7 @@ static bt_status_t if_gattc_read_phy(void* conn_handle)
CHECK_ENABLED();
CHECK_CONNECTION_VALID(g_gattc_manager.connections, connection);

return bt_sal_gatt_client_read_phy(&connection->remote_addr);
return bt_sal_gatt_client_read_phy(PRIMARY_ADAPTER, &connection->remote_addr);
}

static bt_status_t if_gattc_update_phy(void* conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy)
Expand All @@ -749,7 +749,7 @@ static bt_status_t if_gattc_update_phy(void* conn_handle, ble_phy_type_t tx_phy,
CHECK_ENABLED();
CHECK_CONNECTION_VALID(g_gattc_manager.connections, connection);

return bt_sal_gatt_client_set_phy(&connection->remote_addr, tx_phy, rx_phy);
return bt_sal_gatt_client_set_phy(PRIMARY_ADAPTER, &connection->remote_addr, tx_phy, rx_phy);
}

static bt_status_t if_gattc_read_rssi(void* conn_handle)
Expand All @@ -759,7 +759,7 @@ static bt_status_t if_gattc_read_rssi(void* conn_handle)
CHECK_ENABLED();
CHECK_CONNECTION_VALID(g_gattc_manager.connections, connection);

return bt_sal_gatt_client_read_remote_rssi(&connection->remote_addr);
return bt_sal_gatt_client_read_remote_rssi(PRIMARY_ADAPTER, &connection->remote_addr);
}

static const gattc_interface_t gattc_if = {
Expand Down
44 changes: 35 additions & 9 deletions service/profiles/gatt/gatts_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static void gatts_process_message(void* data)
break;

if (element->rsp_type == ATTR_AUTO_RSP) {
bt_sal_gatt_server_send_response(&msg->param.read.addr, msg->param.read.request_id, element->attr_data, element->attr_length);
bt_sal_gatt_server_send_response(PRIMARY_ADAPTER, &msg->param.read.addr, msg->param.read.request_id, element->attr_data, element->attr_length);
} else if (element->read_cb) {
element->read_cb(service, &msg->param.read.addr, msg->param.read.element_id ^ service->srv_id, msg->param.read.request_id);
}
Expand All @@ -298,7 +298,7 @@ static void gatts_process_message(void* data)
if (!element)
break;

bt_sal_gatt_server_send_response(&msg->param.write.addr, msg->param.write.request_id, NULL, 0);
bt_sal_gatt_server_send_response(PRIMARY_ADAPTER, &msg->param.write.addr, msg->param.write.request_id, NULL, 0);
if (element->rsp_type == ATTR_AUTO_RSP) {
if (element->attr_data) {
msg->param.write.length = MIN(element->attr_length, msg->param.write.length);
Expand Down Expand Up @@ -558,7 +558,7 @@ static bt_status_t if_gatts_connect(void* srv_handle, bt_address_t* addr, ble_ad
CHECK_SERVICE_VALID(g_gatts_manager.services, service);

BT_ADDR_LOG("GATTS-CONNECT-REQUEST addr:%s", addr);
return bt_sal_gatt_server_connect(addr, addr_type);
return bt_sal_gatt_server_connect(PRIMARY_ADAPTER, addr, addr_type);
}

static bt_status_t if_gatts_disconnect(void* srv_handle, bt_address_t* addr)
Expand All @@ -569,7 +569,7 @@ static bt_status_t if_gatts_disconnect(void* srv_handle, bt_address_t* addr)
CHECK_SERVICE_VALID(g_gatts_manager.services, service);

BT_ADDR_LOG("GATTS-DISCONNECT-REQUEST addr:%s", addr);
return bt_sal_gatt_server_cancel_connection(addr);
return bt_sal_gatt_server_cancel_connection(PRIMARY_ADAPTER, addr);
}

static bt_status_t if_gatts_add_attr_table(void* srv_handle, gatt_srv_db_t* srv_db)
Expand Down Expand Up @@ -688,31 +688,57 @@ static bt_status_t if_gatts_response(void* srv_handle, bt_address_t* addr, uint3
if (!value)
return BT_STATUS_PARM_INVALID;

return bt_sal_gatt_server_send_response(addr, req_handle, value, length);
return bt_sal_gatt_server_send_response(PRIMARY_ADAPTER, addr, req_handle, value, length);
}

static bt_status_t if_gatts_notify(void* srv_handle, bt_address_t* addr, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gatts_service_t* service = srv_handle;
#if defined(CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
gatt_element_t* element;
#endif

CHECK_ENABLED();
CHECK_SERVICE_VALID(g_gatts_manager.services, service);
if (!value)
return BT_STATUS_PARM_INVALID;

return bt_sal_gatt_server_send_notification(addr, attr_handle + service->srv_id, value, length);
#if defined(CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
element = find_service_element_by_id(service, attr_handle + service->srv_id);
if (!element) {
BT_LOGE("%s element null", __func__);
return BT_STATUS_PARM_INVALID;
}

return bt_sal_gatt_server_send_notification(PRIMARY_ADAPTER, addr, element->uuid, value, length);
#else
return bt_sal_gatt_server_send_notification(PRIMARY_ADAPTER, addr, attr_handle + service->srv_id, value, length);
#endif
}

static bt_status_t if_gatts_indicate(void* srv_handle, bt_address_t* addr, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gatts_service_t* service = srv_handle;
#if defined(CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
gatt_element_t* element;
#endif

CHECK_ENABLED();
CHECK_SERVICE_VALID(g_gatts_manager.services, service);
if (!value)
return BT_STATUS_PARM_INVALID;

return bt_sal_gatt_server_send_indication(addr, attr_handle + service->srv_id, value, length);
#if defined(CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
element = find_service_element_by_id(service, attr_handle + service->srv_id);
if (!element) {
BT_LOGE("%s element null", __func__);
return BT_STATUS_PARM_INVALID;
}

return bt_sal_gatt_server_send_indication(PRIMARY_ADAPTER, addr, element->uuid, value, length);
#else
return bt_sal_gatt_server_send_indication(PRIMARY_ADAPTER, addr, attr_handle + service->srv_id, value, length);
#endif
}

static bt_status_t if_gatts_read_phy(void* srv_handle, bt_address_t* addr)
Expand All @@ -722,7 +748,7 @@ static bt_status_t if_gatts_read_phy(void* srv_handle, bt_address_t* addr)
CHECK_ENABLED();
CHECK_SERVICE_VALID(g_gatts_manager.services, service);

bt_status_t status = bt_sal_gatt_server_read_phy(addr);
bt_status_t status = bt_sal_gatt_server_read_phy(PRIMARY_ADAPTER, addr);

if (status == BT_STATUS_SUCCESS && service->callbacks->on_phy_read) {
gatts_op_t* op = gatts_op_new(GATTS_REQ_READ_PHY);
Expand All @@ -741,7 +767,7 @@ static bt_status_t if_gatts_update_phy(void* srv_handle, bt_address_t* addr, ble
CHECK_ENABLED();
CHECK_SERVICE_VALID(g_gatts_manager.services, service);

bt_status_t status = bt_sal_gatt_server_set_phy(addr, tx_phy, rx_phy);
bt_status_t status = bt_sal_gatt_server_set_phy(PRIMARY_ADAPTER, addr, tx_phy, rx_phy);

if (status == BT_STATUS_SUCCESS && service->callbacks->on_phy_updated) {
gatts_op_t* op = gatts_op_new(GATTS_REQ_UPDATE_PHY);
Expand Down
Loading
Loading