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

framework sal adaptation for zblue #6

Merged
merged 3 commits into from
Dec 26, 2024
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
14 changes: 14 additions & 0 deletions framework/include/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ extern "C" {
#endif
#endif // End of else

#define PRIMARY_ADAPTER 0

typedef uint8_t bt_controller_id_t;

typedef enum {
BT_IO_CAPABILITY_DISPLAYONLY = 0,
BT_IO_CAPABILITY_DISPLAYYESNO,
Expand Down Expand Up @@ -182,6 +186,11 @@ typedef enum {
BT_LE_ADDR_TYPE_UNKNOWN = 0xFF
} ble_addr_type_t;

typedef enum {
BT_ADDR_TYPE_BREDR,
BT_ADDR_TYPE_UNKNOWN = 0xFF
} bt_addr_type_t;

/* * BLE PHY type */
typedef enum {
BT_LE_1M_PHY,
Expand All @@ -202,6 +211,11 @@ typedef enum {

typedef uint8_t bt_128key_t[16];

typedef struct {
uint8_t hash[16];
uint8_t rand[16];
} bt_oob_data_t;

#define COD_SERVICE_BITS(c) (c & 0xFFE000) /* The major service classes field */
#define COD_DEVICE_MAJOR_BITS(c) (c & 0x001F00) /* The major device classes field */
#define COD_DEVICE_CLASS_BITS(c) (c & 0x001FFC) /* The device classes field, including major and minor */
Expand Down
8 changes: 4 additions & 4 deletions service/profiles/a2dp/a2dp_state_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

#include "sal_a2dp_sink_interface.h"
#include "sal_a2dp_source_interface.h"
#include "sal_adapter_interface.h"
#include "sal_avrcp_control_interface.h"
#include "sal_avrcp_target_interface.h"
#include "sal_interface.h"

#include "a2dp_audio.h"
#include "a2dp_control.h"
Expand Down Expand Up @@ -362,7 +362,7 @@ static bt_status_t a2dp_offload_send_stop_cmd(a2dp_state_machine_t* a2dp_sm,
STREAM_TO_UINT16(ocf, payload);
flag_set(a2dp_sm, PENDING_OFFLOAD_STOP);

return bt_sal_send_hci_command(ogf, ocf, len, payload, bt_hci_event_callback, a2dp_sm);
return bt_sal_send_hci_command(PRIMARY_ADAPTER, ogf, ocf, len, payload, bt_hci_event_callback, a2dp_sm);
}

static bool flag_isset(a2dp_state_machine_t* a2dp_sm, pending_state_t flag)
Expand Down Expand Up @@ -745,7 +745,7 @@ static bool opened_process_event(state_machine_t* sm, uint32_t event, void* p_da
flag_set(a2dp_sm, PENDING_OFFLOAD_START);
a2dp_sm->offload_timer = service_loop_timer(A2DP_OFFLOAD_TIMEOUT, 0, a2dp_offload_config_timeout_callback, a2dp_sm);

bt_sal_send_hci_command(ogf, ocf, len, payload, bt_hci_event_callback,
bt_sal_send_hci_command(PRIMARY_ADAPTER, ogf, ocf, len, payload, bt_hci_event_callback,
a2dp_sm);
break;
}
Expand Down Expand Up @@ -834,7 +834,7 @@ static bt_status_t a2dp_send_active_link_cmd(a2dp_state_machine_t* a2dp_sm, bool
STREAM_TO_UINT16(ocf, payload);
size -= sizeof(ogf) + sizeof(ocf);

return bt_sal_send_hci_command(ogf, ocf, size, payload, NULL /* TODO: add callback */, a2dp_sm);
return bt_sal_send_hci_command(PRIMARY_ADAPTER, ogf, ocf, size, payload, NULL /* TODO: add callback */, a2dp_sm);
}

static void started_enter(state_machine_t* sm)
Expand Down
4 changes: 2 additions & 2 deletions service/profiles/a2dp/source/a2dp_source_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "bt_list.h"
#include "callbacks_list.h"
#include "sal_a2dp_source_interface.h"
#include "sal_adapter_interface.h"
#include "sal_interface.h"
#include "service_loop.h"
#include "service_manager.h"
#include "utils/log.h"
Expand Down Expand Up @@ -117,7 +117,7 @@ static void a2dp_service_prepare_handle(a2dp_state_machine_t* sm,
{
switch (event->event) {
case CONNECTED_EVT: {
set_active_peer(&event->event_data.bd_addr, bt_sal_get_acl_link_handle(&event->event_data.bd_addr, BT_TRANSPORT_BREDR));
set_active_peer(&event->event_data.bd_addr, bt_sal_get_acl_connection_handle(PRIMARY_ADAPTER, &event->event_data.bd_addr, BT_TRANSPORT_BREDR));
break;
}

Expand Down
6 changes: 3 additions & 3 deletions service/profiles/hfp_ag/hfp_ag_state_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
#include "hfp_ag_tele_service.h"
#include "media_system.h"
#include "power_manager.h"
#include "sal_adapter_interface.h"
#include "sal_hfp_ag_interface.h"
#include "sal_interface.h"
#include "utils/log.h"

#define HFP_AG_RETRY_MAX 1
Expand Down Expand Up @@ -880,7 +880,7 @@ static bt_status_t ag_offload_send_cmd(ag_state_machine_t* agsm, bool is_start)
STREAM_TO_UINT16(ocf, payload);
size -= sizeof(ogf) + sizeof(ocf);

return bt_sal_send_hci_command(ogf, ocf, size, payload, bt_hci_event_callback, agsm);
return bt_sal_send_hci_command(PRIMARY_ADAPTER, ogf, ocf, size, payload, bt_hci_event_callback, agsm);
}

static bool is_virtual_call_allowed(state_machine_t* sm)
Expand Down Expand Up @@ -940,7 +940,7 @@ static bool connected_process_event(state_machine_t* sm, uint32_t event, void* p
hsm_transition_to(sm, &audio_connecting_state);
break;
case AG_STACK_EVENT_AUDIO_REQ:
if (bt_sal_reply_sco_link_request(&agsm->addr, true) != BT_STATUS_SUCCESS) {
if (bt_sal_sco_connection_reply(PRIMARY_ADAPTER, &agsm->addr, true) != BT_STATUS_SUCCESS) {
BT_ADDR_LOG("Reply audio request fail:%s", &agsm->addr);
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions service/profiles/hfp_hf/hfp_hf_state_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#include "hfp_hf_state_machine.h"
#include "media_system.h"
#include "power_manager.h"
#include "sal_adapter_interface.h"
#include "sal_hfp_hf_interface.h"
#include "sal_interface.h"
#include "service_loop.h"
#include "utils/log.h"

Expand Down Expand Up @@ -428,7 +428,7 @@ static bt_status_t hf_offload_send_cmd(hf_state_machine_t* hfsm, bool is_start)
STREAM_TO_UINT16(ocf, payload);
size -= sizeof(ogf) + sizeof(ocf);

return bt_sal_send_hci_command(ogf, ocf, size, payload, bt_hci_event_callback, hfsm);
return bt_sal_send_hci_command(PRIMARY_ADAPTER, ogf, ocf, size, payload, bt_hci_event_callback, hfsm);
}

static bool check_hfp_allowed(hf_state_machine_t* hfsm)
Expand Down Expand Up @@ -1215,7 +1215,7 @@ static bool connected_process_event(state_machine_t* sm, uint32_t event, void* p
pending_action_create(hfsm, HFP_ATCMD_CODE_BLDN, NULL);
break;
case HF_STACK_EVENT_AUDIO_REQ:
status = bt_sal_reply_sco_link_request(&hfsm->addr, true);
status = bt_sal_sco_connection_reply(PRIMARY_ADAPTER, &hfsm->addr, true);
if (status != BT_STATUS_SUCCESS) {
BT_LOGE("Accept Sco request failed");
}
Expand Down
6 changes: 3 additions & 3 deletions service/profiles/leaudio/client/lea_client_state_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "lea_client_service.h"
#include "lea_client_state_machine.h"
#include "lea_codec.h"
#include "sal_adapter_interface.h"
#include "sal_interface.h"
#include "sal_lea_client_interface.h"
#include "sal_lea_common.h"
#include "service_loop.h"
Expand Down Expand Up @@ -477,7 +477,7 @@ static void lea_client_stop_offload_req(lea_client_state_machine_t* leas_sm, lea
STREAM_TO_UINT16(ocf, payload);
flag_set(leas_sm, PENDING_OFFLOAD_STOP);

bt_sal_send_hci_command(ogf, ocf, len, payload, bt_hci_event_callback,
bt_sal_send_hci_command(PRIMARY_ADAPTER, ogf, ocf, len, payload, bt_hci_event_callback,
leas_sm);
}

Expand Down Expand Up @@ -539,7 +539,7 @@ static bool started_process_event(state_machine_t* sm, uint32_t event, void* p_d
flag_set(leas_sm, PENDING_OFFLOAD_START);
leas_sm->offload_timer = service_loop_timer(LEA_SERVER_OFFLOAD_TIMEOUT, 0, lea_offload_config_timeout_callback, leas_sm);

bt_sal_send_hci_command(ogf, ocf, len, payload, bt_hci_event_callback,
bt_sal_send_hci_command(PRIMARY_ADAPTER, ogf, ocf, len, payload, bt_hci_event_callback,
leas_sm);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions service/profiles/leaudio/server/lea_server_state_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "lea_audio_source.h"
#include "lea_server_service.h"
#include "lea_server_state_machine.h"
#include "sal_adapter_interface.h"
#include "sal_interface.h"
#include "sal_lea_server_interface.h"
#include "service_loop.h"

Expand Down Expand Up @@ -410,7 +410,7 @@ static void lea_server_stop_offload_req(lea_server_state_machine_t* leas_sm, lea
STREAM_TO_UINT16(ocf, payload);
flag_set(leas_sm, PENDING_OFFLOAD_STOP);

bt_sal_send_hci_command(ogf, ocf, len, payload, bt_hci_event_callback,
bt_sal_send_hci_command(PRIMARY_ADAPTER, ogf, ocf, len, payload, bt_hci_event_callback,
leas_sm);
}

Expand Down Expand Up @@ -460,7 +460,7 @@ static bool opened_process_event(state_machine_t* sm, uint32_t event, void* p_da
flag_set(leas_sm, PENDING_OFFLOAD_START);
leas_sm->offload_timer = service_loop_timer(LEA_SERVER_OFFLOAD_TIMEOUT, 0, lea_offload_config_timeout_callback, leas_sm);

bt_sal_send_hci_command(ogf, ocf, len, payload, bt_hci_event_callback,
bt_sal_send_hci_command(PRIMARY_ADAPTER, ogf, ocf, len, payload, bt_hci_event_callback,
leas_sm);
break;
}
Expand Down
16 changes: 9 additions & 7 deletions service/src/adapter_internel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ enum {
typedef struct {
bt_address_t addr; // Remote BT address
ble_addr_type_t addr_type; // if link type is ble connection type
uint8_t link_type;
uint8_t transport;
bt_status_t status;
connection_state_t connection_state;
uint32_t hci_reason_code;
Expand Down Expand Up @@ -114,6 +114,7 @@ typedef struct {
bt_address_t addr;
uint8_t evt_id;
union {
uint32_t cod;
acl_state_param_t acl_params;
struct {
bool local_initiate;
Expand All @@ -128,17 +129,18 @@ typedef struct {
uint32_t cod;
bt_pair_type_t ssp_type;
uint32_t pass_key;
uint8_t link_type;
uint8_t transport;
char name[BT_REM_NAME_MAX_LEN + 1];
} ssp_req;
struct {
bond_state_t state;
uint8_t link_type;
uint8_t transport;
bt_status_t status;
bool is_ctkd;
} bond_state;
struct {
bool encrypted;
uint8_t link_type;
uint8_t transport;
} enc_state;
struct {
bt_128key_t key;
Expand Down Expand Up @@ -222,17 +224,17 @@ void adapter_on_device_found(bt_discovery_result_t* result);
void adapter_on_scan_mode_changed(bt_scan_mode_t mode);
void adapter_on_discovery_state_changed(bt_discovery_state_t state);
void adapter_on_remote_name_recieved(bt_address_t* addr, const char* name);
void adapter_on_connect_request(bt_address_t* addr);
void adapter_on_connect_request(bt_address_t* addr, uint32_t cod);
void adapter_on_connection_state_changed(acl_state_param_t* param);
void adapter_on_pairing_request(bt_address_t* addr, bool local_initiate, bool is_bondable);
void adapter_on_ssp_request(bt_address_t* addr, uint8_t transport,
uint32_t cod, bt_pair_type_t ssp_type,
uint32_t pass_key, const char* name);
void adapter_on_pin_request(bt_address_t* addr, uint32_t cod,
bool min_16_digit, const char* name);
void adapter_on_bond_state_changed(bt_address_t* addr, bond_state_t state, uint8_t link_type, bool is_ctkd);
void adapter_on_bond_state_changed(bt_address_t* addr, bond_state_t state, uint8_t transport, bt_status_t status, bool is_ctkd);
void adapter_on_service_search_done(bt_address_t* addr, bt_uuid_t* uuids, uint16_t size);
void adapter_on_encryption_state_changed(bt_address_t* addr, bool encrypted, uint8_t link_type);
void adapter_on_encryption_state_changed(bt_address_t* addr, bool encrypted, uint8_t transport);
void adapter_on_link_key_update(bt_address_t* addr, bt_128key_t link_key, bt_link_key_type_t type);
void adapter_on_link_key_removed(bt_address_t* addr, bt_status_t status);
void adapter_on_link_role_changed(bt_address_t* addr, bt_link_role_t role);
Expand Down
Loading
Loading