Compare commits

...

393 Commits
trunk ... dev

Author SHA1 Message Date
wupengfei3 6425e8be56 bluetooth/scan: handle uuid16_some/uuid_all eir data
bug: v/22580

Signed-off-by: wupengfei3 <wupengfei3@xiaomi.com>
2026-05-11 20:09:15 +08:00
liuxiang18 676d098658 bluetooth/scan: add uuid_some & uuid_all macro
bug: v/22580

The watch now supports power meters. In addition to the existing SVC_DATA_16 filter, new UUID_SOME and UUID_ALL filters must be added.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-05-11 20:09:15 +08:00
huangyulong3 0cf1898d83 bluetooth: fix compilation errors
Fix various compilation errors across bluetooth framework, service,
and stack layers including:
- Add missing function declarations and header includes
- Fix type mismatches and implicit function declarations
- Add missing macro definitions in dfx headers
- Add stub implementation for hid device interface
- Fix list utility inline function issues

Signed-off-by: openvela <openvela@xiaomi.com>
2026-05-08 09:52:38 +08:00
Lu Jia eeadab36e1 a2dp: Fix use-after-free on ACP disconnect during CONFIGURED state
bug: v/88938

When acting as A2DP ACP, if the remote side disconnects ACL right after
Set Configuration (before media channel is established), a2dp_info->stream
is freed in a2dp_info_destroy() while zblue's ep->stream still references
the same memory. The subsequent avdtp_release_work() then accesses freed
memory (use-after-free).

Fix by deferring a2dp_info cleanup in zblue_on_disconnected() when stream
is still alive. The cleanup is completed later in zblue_on_stream_released()
after zblue finishes its release work.

Also guard DISCONNECTED_EVT in zblue_on_stream_released() to only fire
when media channel was actually established, avoiding duplicate events
with zblue_on_disconnected().

Add debug logging to a2dp_info_destroy, zblue_on_stream_configured,
zblue_on_stream_released, and zblue_on_disconnected for easier diagnosis.

Signed-off-by: Lu Jia <jialu@xiaomi.com>
2026-04-27 23:14:56 +08:00
liyuheng 9e14509c31 sal_hfp_hf: add mutex lock for connection list
bug: v/87935

Rootcause: The global connection list g_sal_hf_conn_list in
sal_hfp_hf_interface.c is accessed by multiple threads (zblue
callback thread, service work thread, upper layer API thread)
without any synchronization, which may cause data race, list
corruption, use-after-free or crash.

Add a pthread recursive mutex (g_sal_hf_conn_lock) with wrapper
functions conn_list_lock()/conn_list_unlock() to protect all
accesses to g_sal_hf_conn_list and calls sub-lists. The mutex
is initialized in bt_sal_hfp_hf_init() and destroyed in
bt_sal_hfp_hf_cleanup(). NULL checks for the list pointer are
moved inside the lock scope to avoid TOCTOU races.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:56 +08:00
liyuheng f3f6b7f8f9 sal_hfp_ag: add mutex lock for connection list
bug: v/87935

Rootcause: The global connection list g_sal_ag_conn_list in
sal_hfp_ag_interface.c is accessed by multiple threads (zblue
callback thread, service work thread, upper layer API thread)
without any synchronization, which may cause data race, list
corruption, use-after-free or crash.

Add a pthread recursive mutex (g_sal_ag_conn_lock) with wrapper
functions conn_list_lock()/conn_list_unlock() to protect all
accesses to g_sal_ag_conn_list and calls sub-lists. The mutex
is initialized in bt_sal_hfp_ag_init() and destroyed in
bt_sal_hfp_ag_cleanup(). NULL checks for the list pointer are
moved inside the lock scope to avoid TOCTOU races.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:56 +08:00
liyuheng c7750b15d5 sal/hfp_hf: move remaining interfaces to service loop work
bug: v/87673

Rootcause: Multiple bt_sal_hfp_hf_* functions directly call zblue
Z_API() in the caller's context, which can cause concurrent access
issues. Move all remaining HF interfaces (answer_call, reject_call,
hold_call, hangup_call, dial_number, dial_memory, call_control,
get_current_calls, voice_recognition, send_battery_level, send_at_cmd,
send_dtmf, get_subscriber_number) into service_loop_work to serialize
execution in the service loop.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:56 +08:00
liyuheng bad412afbc sal/hfp_ag: move remaining interfaces to service loop work
bug: v/87673

Rootcause: Multiple bt_sal_hfp_ag_* functions directly call zblue
Z_API() in the caller's context, which can cause concurrent access
issues similar to the set_volume deadlock. Move all remaining AG
interfaces (voice_recognition, cind_response, dial_response,
cops_response, notify_device_status_changed, set_inband_ring_enable,
send_at_cmd, error_response) into service_loop_work to serialize
execution in the service loop.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:56 +08:00
liyuheng e832f79c93 sal/hfp: move set_volume to service loop work
bug: v/87673

Rootcause: bt_sal_hfp_hf_set_volume and bt_sal_hfp_ag_set_volume
directly call zblue API (bt_hfp_hf_vgm/vgs, bt_hfp_ag_vgm/vgs) in
the caller's context. During volume adjustment stress testing on iOS
calls, rapid consecutive invocations can cause deadlock. Move the
actual zblue API calls into service_loop_work to serialize execution
in the service loop, preventing concurrent access issues.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:56 +08:00
v-yichenxi e6cb78e55a bluetooth: hid: move blocking zblue API calls to worker thread
bug: v/87939

Move all synchronous zblue HID API calls from service_loop/sysworkq
context to worker thread via service_loop_work() to avoid blocking.

The affected functions are:
- bt_sal_hid_device_send_report (bt_hid_device_send_intr_data)
- bt_sal_hid_device_get_report_response (bt_hid_device_send_ctrl_data)
- bt_sal_hid_device_report_error (bt_hid_device_report_error)
- bt_sal_hid_device_virtual_unplug (bt_hid_device_virtual_unplug)
- hid_get_protocol_callback (bt_hid_device_send_ctrl_data)

These calls internally invoke bt_conn_create_pdu_timeout which may
block, causing service_loop stalls.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2026-04-27 23:14:56 +08:00
Kai Cheng 50c45b2fa0 bluetooth: serialize ACL connect requests to avoid controller disallow
bug: v/88196

Rootcause: Concurrent bt_sal_connect calls send multiple HCI Create
Connection commands before the first completes, causing controller to
reject with Command Disallowed. Add a pending queue to serialize ACL
connect requests, dispatching the next via sal_send_req only after
zblue_on_connected callback fires.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:56 +08:00
Lu Jia 166492cf4c a2dp: Refine SBC sink codec IE preference order
bug: v/88931

Narrow each SBC codec IE entry to a single channel mode and
sampling frequency combination, ordered by preference:
44.1kHz Joint Stereo > 48kHz Joint Stereo > 44.1kHz Stereo >
48kHz Stereo > 44.1kHz Dual > 48kHz Dual > 44.1kHz Mono >
48kHz Mono. Fix block length and allocation method comments.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:56 +08:00
zhangyuan20 c7f1136d36 hfp_hf: fix set_volume_cnt race causing AT+VGS not sent back to phone
bug: v/88680

Rootcause: hfp_hf_voice_volume_change_callback runs in media policy thread
while set_volume_cnt is read/written in hf_stm service loop thread, causing
a race condition. Move set_volume_cnt check and media_volume update from
the callback into a new HF_MEDIA_VOLUME_CHANGED event handler in the
service loop, so all accesses run in the same thread without needing a lock.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 ba33b35581 Notify BR/EDR CONNECTING state on outgoing ACL
after bt_conn_create_br succeeds (conn enters BT_CONN_INITIATING internally,
which maps to BT_CONN_STATE_CONNECTING publicly), send CONNECTION_STATE_CONNECTING
event to upper layers via adapter_on_connection_state_changed.

Previously only incoming connections (zblue_on_connect_req) notified
CONNECTING state; outgoing connections jumped directly from
DISCONNECTED to CONNECTED, causing upper layers to miss the
intermediate state.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 ad8d3c3e1c Trigger profile handlers on ACL failure
bug: v/87679

When ACL connection fails (e.g., Page Timeout), profile handlers were
not triggered, causing upper layer to wait for timeout instead of
receiving immediate disconnection notification.

This patch:
1. Triggers pending profile handlers when ACL disconnects, allowing
   them to detect failure via bt_conn_lookup_addr_br() returning NULL
2. Ensures all profile connect handlers have complete error callbacks
   in their failure paths

Affected profiles: HFP HF/AG, A2DP Source/Sink, AVRCP, GATTS BR

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 7a7bec624e avoid removing bond on generic security failures
bug: v/88179

Restrict BR/LE security_changed bond cleanup to authentication failure
and missing-key cases only. Preserve existing bond information for other
security errors, and move BR bond removal plus ACL disconnect handling
to the service work queue to match the async LE flow.

- rootcause: BR/LE security_changed treated generic security failures as
  stale key failures, so delayed teardown or non-key-related errors could
  incorrectly delete the stored bond and break the next reconnect.
- include connection state in security_changed logs to improve failure
  diagnosis.
- route BR remove_bond and disconnect through the internal async SAL
  path instead of operating directly in the callback.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 5c129c4322 a2dp: Override SBC max bitpool to 53 in PTS mode
bug: v/88496

When PTS mode is enabled, set the SBC max bitpool to 53 for all
source and sink codec IEs on A2DP connected. This ensures PTS
test compliance with the standard SBC max bitpool value.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 559d730ee2 gatts: Dispatch notify/indicate/response to service worker
bug: v/88088

bt_att_create_pdu uses BT_ATT_TIMEOUT (K_SECONDS(30)) for ATT_RESPONSE
and ATT_NOTIFICATION ops, which can block the calling thread up to 30s
when the buf pool is exhausted.

Refactor bt_sal_gatt_server_send_notification,
bt_sal_gatt_server_send_indication and bt_sal_gatt_server_send_response
to copy the payload into a heap-allocated request struct and dispatch
via service_loop_work, so the framework thread returns immediately and
the blocking stack call runs in the service worker thread.

- rootcause: bt_gatt_notify_cb/bt_gatt_indicate/bt_gatt_send_read_rsp
  all call bt_att_create_pdu which may block K_SECONDS(30) on buf pool
  exhaustion, stalling the framework thread
- Add sal_gatts_notify_req_t and sal_gatts_rsp_req_t with flexible array
  member to carry the value copy inline
- First four fields of both structs mirror sal_adapter_req_t so
  sal_invoke_async can cast and dispatch safely

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
Zihao Gao f35a3353d8 HFP: Keep ACL link active during SCO connection
bug: v/87639

Keep the ACL link in active mode during SCO connection to reduce
control latency for HFP commands such as call termination.

Also fix audio_on_exit to call bt_pm_idle instead of bt_pm_busy,
ensuring consistent idle state when SCO is not established.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:55 +08:00
liuxiang18 fa468a7dfd bluetooth: fix CM_RECONNECT_TIMES mismatch with reconnect interval
bug: v/5823

CM_RECONNECT_INTERVAL was changed from 8s to 12s for power optimization,
but CM_RECONNECT_TIMES was not updated accordingly, resulting in a 45-minute
reconnect window instead of the designed 30 minutes.

Fix by deriving CM_RECONNECT_TIMES from CM_RECONNECT_INTERVAL directly,
so future interval changes are automatically reflected.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng 53af42b246 bluetooth/sal: refactor HFP AG connection flow to match HF pattern
bug: v/87902

Refactor the HFP AG SAL connection establishment to align with the
HFP HF implementation:

- Remove global g_conn_params that serialized all connections through
  a single slot, preventing parallel outgoing connections.
- Split do_ag_connect into do_ag_sdp_discover (SDP phase) and
  do_ag_slc_connect (SLC phase), matching HF's do_hf_sdp_discover
  and do_hf_slc_connect.
- Create sal_conn early at SDP discover time so the connection is
  tracked from the start, enabling proper cleanup on SDP failure.
- Use service_loop_work to dispatch do_ag_slc_connect from
  zblue_on_sdp_done, instead of direct synchronous call.
- Add find_connection_by_context to look up sal_conn by bt_conn*.
- Fix zblue_on_ag_disconnected to use sal_conn->addr directly and
  call bt_list_remove after callbacks.
- Fix zblue_on_ag_connected to handle incoming connections and
  simultaneous connection collision consistently with HF.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng b785295a2d bluetooth/sal: remove intermediate pointer variable in zblue_hf_disconnected
bug: v/87902

Use sal_conn->addr directly instead of an intermediate bt_address_t*
pointer variable. The sal_conn object remains valid until bt_list_remove
at the end of the function, so direct access is safe and cleaner.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng 2f97944915 bluetooth: hfp_ag: handle SDP disconnection during discovery
bug: v/87902

Rootcause: When ACL disconnects during SDP discovery, the SDP client
only invokes the disconnected callback, not the func callback. HFP AG
SAL did not register a disconnected callback, so the upper layer never
received a PROFILE_STATE_DISCONNECTED notification and could get stuck.
Add the disconnected callback to notify the upper layer of the
disconnection.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng 1bf95d3005 bluetooth: hfp_hf: handle SDP disconnection during discovery
bug: v/87902

Rootcause: When ACL disconnects during SDP discovery, the SDP client
only invokes the disconnected callback, not the func callback. HFP HF
SAL did not register a disconnected callback, causing sal_conn to be
orphaned in g_sal_hf_conn_list and the upper layer state machine to
get stuck. Add the disconnected callback to clean up sal_conn and
notify the upper layer of the disconnection.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
chejinxian1 6c4dc95334 bluetooth/tools: fix bttool cleanup failure on BT disable
bug: v/85832

Fix defects causing bttool resource leak during BT enable/disable
stress test:

1. Store bttool_t pointer in g_bttool_loop->data so TURNING_OFF callback
   can access the async queue (previously always 0, cleanup was skipped)
2. Replace do_in_thread_loop with bttool_uninit() in TURNING_OFF callback
   to send _uninit command via uv_async_queue_send, ensuring bt_tool_uninit
   runs on g_bttool_loop thread (mirrors bttool_quit pattern). Guard with
   CONFIG_LIBUV_EXTENSION only.
3. Add re-entry guard in bt_tool_uninit to prevent double cleanup on
   repeated BT disable cycles

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia fb03f0bbc5 Fix A2DP crash issue
bug: v/87941

bt_sal_a2dp_source_send_data calls net_buf_add_mem(media_packet_buf, &buf[AVDTP_RTP_HEADER_LEN], nbytes) without validating whether nbytes exceeds the available space in media_packet_buf. The buffer is allocated from bt_a2dp_tx_pool with a data size of CONFIG_ZBLUE_A2DP_SOURCE_BUF_SIZE (default 660 bytes). After bt_a2dp_stream_create_pdu reserves protocol headers (STREAM_DATA_RESERVED, i.e. AVDTP_RTP_HEADER_LEN = 12 bytes), the actual usable payload space is CONFIG_ZBLUE_A2DP_SOURCE_BUF_SIZE - STREAM_DATA_RESERVED (648 bytes). Zephyr's net_buf_add_mem only has an __ASSERT_NO_MSG check which is stripped in release builds. If nbytes exceeds the tailroom, a buffer overflow occurs, corrupting adjacent memory and potentially causing hard faults or data corruption.

Fix: Add a length check before buffer allocation using CONFIG_ZBLUE_A2DP_SOURCE_BUF_SIZE - STREAM_DATA_RESERVED as the maximum payload limit. When nbytes exceeds this limit, log an error and return BT_STATUS_PARM_INVALID, avoiding unnecessary buffer allocation and out-of-bounds writes.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia bf3e459d0b cmake: add CONFIG_BLUETOOTH_LE_CS build support
bug: v/88558

Add conditional compilation for Bluetooth LE Channel Sounding (CS)
feature across framework API, socket IPC, Zephyr SAL, CS profiles,
and le_cs tool.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 5845d97591 cs: Fix the issue where RAS data is transmitted incompletely (only half sent).
bug: v/87852

This commit performs an architecture-level refactoring of cs_ras.c and cs_ras.h. The core change replaces the shared global buffer and static arrays used for Real-time and On-demand mode data storage with independent dynamically-allocated linked list queues, resolving memory safety issues and concurrent processing defects in the original architecture.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 6757503ea8 a2dp: Fix sink-initiated connection failure.
bug: v/88151

In zblue_on_connected, when the device acts as ACP (acceptor), it only creates the a2dp_info and waits passively. It never initiates bt_a2dp_discover, so if the remote side also does not initiate the discover/set_config flow, the A2DP connection stalls -- signaling channel is up but no stream is ever configured.

Additionally, in bt_a2dp_discover_endpoint_cb, the a2dp_info->role remains SEP_INVALID for ACP connections because the role was only assigned during the connect initiation path. The SNK set_config branch also had an unnecessary int_acp == A2DP_INT guard, which blocked ACP-initiated discover from completing the configuration.

Fix:

Added a 2-second service_loop_timer in the ACP path of zblue_on_connected. If the remote does not send set_config within 2s, the local side proactively initiates bt_a2dp_discover.
The timer is cancelled in zblue_on_config_req (remote drove the flow first) and in a2dp_info_destroy (cleanup on disconnect).
In bt_a2dp_discover_endpoint_cb, the local role is now derived from the remote's sep_info->tsep: BT_AVDTP_SOURCE -> local SEP_SNK, BT_AVDTP_SINK -> local SEP_SRC.
Removed the int_acp == A2DP_INT restriction on the SEP_SNK set_config branch so ACP-triggered discover can also complete codec negotiation.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng 1a471d24a0 hfp_ag: avoid recv blocking crash in call ops
bug: v/82380

The previous call operation path could block receiving and eventually lead to a
crash.
Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
Kai Cheng b378e460b7 bluetooth: fix bt disable failing to reconnect.
bug: v/84601

rootcause:
1: The old interface forcibly disconnects ACLs, causing profile
connection compatibility issues.
2: The old interface port forcibly releases and cleans up local
resources before disconnecting, especially in sniffing scenarios,
ending before entering active mode, causing a 30-second
timeout on the phone.

in turn, increases the connection disconnection time by 300 milliseconds.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhangyuan20 435a4f37b6 bluetooth: close sniff when set volume
bug: v/-88168

Rootcause: Adjusting the volume in sniff mode is relatively slow; need to exit sniff before adjusting the volume.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 055fbbb9ea Map unknown address type to public for legacy compatibility
bug: v/87917

Map BT_LE_ADDR_TYPE_UNKNOWN to BT_ADDR_LE_PUBLIC instead of
BT_ADDR_LE_RANDOM to maintain compatibility with legacy stack
behavior where the default address type was public.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
chejinxian1 88cab691fd bluetooth/spp: implement bt_sal_spp_connect_with_option for SPP client connect
bug: v/88096

Fix SPP client connection by implementing bt_sal_spp_connect_with_option.
Previously this function returned BT_STATUS_UNSUPPORTED directly, causing
SPP client connect to fail.

Now for non-insecure mode, it calls bt_sal_spp_connect to establish
connection. Insecure mode is not yet supported and still returns
BT_STATUS_UNSUPPORTED.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:55 +08:00
Zihao Gao 406593e3ac gattc: refactor to use debug module and add build config
Bug: v/87379

Refactor gattc_service.c to use the new debug module:
- Include gattc_internal.h and gattc_debug.h
- Remove local struct definitions (moved to gattc_internal.h)
- Replace inline logging with debug module functions
- Remove dump_services() (moved to gattc_debug.c)

Add CONFIG_BLUETOOTH_GATT_CLIENT_DEBUG Kconfig option:
- Default enabled (y) for backward compatibility
- When disabled, debug functions become empty macros
- Reduces code size by removing log strings

Update Makefile and CMakeLists.txt to conditionally compile
gattc_debug.c based on the config option.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:55 +08:00
Zihao Gao 554f74f7b3 gattc: add debug module with conditional compilation
Bug: v/87379

Add GATT client debug module for conditional compilation of logging:

- gattc_internal.h: shared type definitions (gattc_service_t,
  gattc_connection_t) extracted from gattc_service.c
- gattc_debug.h: function declarations with empty macro fallbacks
  when CONFIG_BLUETOOTH_GATT_CLIENT_DEBUG is disabled
- gattc_debug.c: logging implementations using explicit bt_addr_ba2str()
  + BT_LOGI() to avoid BT_ADDR_LOG parameter order confusion

Functions provided:
- gattc_log(): log address with message
- gattc_log_state(): log connection state changes
- gattc_log_status(): log operation status
- gattc_dump_services(): dump discovered services

Also fix gattc_event.h enum typo: GATTC_EVENT_DICCOVER_CMPL ->
GATTC_EVENT_DISCOVER_CMPL

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:55 +08:00
Zihao Gao ea27e37547 bt_uuid: define BT_UUID_STR_LENGTH macro and update usages
Bug: v/87379

Define BT_UUID_STR_LENGTH macro (40) in bt_uuid.h to replace hardcoded
magic numbers for UUID string buffer size. Use LENGTH suffix to avoid
conflict with Zephyr's BT_UUID_STR_LEN definition.

Update all usages across the codebase to use the new macro.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:55 +08:00
chejinxian1 8769dc695a spp: fix pipe read stall after tx pool full recovery
bug: v/87572

When bt_sal_spp_write returns BT_STATUS_NOMEM, the complete packet
(size == mfs) is cached via spp_cache_fragement, setting
cache_buf.length = mfs. On recovery, spp_on_outgoing_complete directly
calls euv_pipe_read_start, causing euv_alloc_buffer to compute
len = mfs - mfs = 0. libuv gets a zero-length buffer, pipe read
stalls, and the connection eventually drops.

Fix by incrementing remaining_quota before the recovery check to
prevent uint8_t underflow (0 - 1 = 0xFF), then branching on
cache_buf.length: flush cached data via do_spp_write if present,
otherwise restart pipe read with mfs.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia e321fa7f5c cs: Fix CS functionality abnormal issue.
bug: v/87852

This change fixes multiple issues in the Bluetooth CS (Channel Sounding) RAS (Ranging Service) data conversion and transmission:

Filter type overflow: Changed ras_filter from uint32_t to uint16_t to match the RAS spec (16-bit filter mask per mode), and updated the initial value from 0xFFFFFFFF to 0xFFFF.

Filter enum start value: All mode filter bit enums (MODE_0/1/2/3) now start at 2 instead of 0, aligning with the actual bit definitions in the RAS specification.

MODE 1 role condition inverted: In CS_RAS_SUBEVENT_STEP_MODE_1, the Initiator and Reflector role branches were swapped (Reflector was incorrectly executing the Initiator path).

Missing antenna_paths semantic conversion: HCI reports num_antenna_paths as a count (1-4), but RAS requires a bitmask. Added count-to-bitmask conversion (e.g., count=4 → 0x0F).

MODE 2/3 Tone data parsing: Changed Tone_PCT and Tone_Quality_Indicator from bulk copy using (num_antenna_paths+1) to per-tone iteration via while(remaining > 0), matching the RAS spec's per-tone filtering semantics.

Real-time data trigger condition: Changed the condition in cs_ras_subevent_result_cb from procedure_done_status to subevent_done_status, since real-time mode should trigger on each subevent completion, not the entire procedure.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 f1c0794060 Fix BLE SMP Bus Fault crash on pairing rejection
bug: v/87862

Rootcause: zblue_on_security_changed and zblue_on_pairing_failed
callbacks run inside smp_pairing_complete. They called bt_unpair /
bt_conn_disconnect synchronously, which freed bt_conn before
smp_pairing_complete finished. smp_reset then accessed freed memory.

Fix: use async bt_sal_le_remove_bond / bt_sal_le_disconnect instead,
so bt_conn stays alive until the entire callback chain returns.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 83d3c9933c cs : Add cs_set_config command to set RAS supported configuration and fix compilation warnings.
bug: v/87425

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia df46a78b4e a2dp: Fix the issue of no sound from earbuds after repeated reconnection.
bug: v/87645

After sending STREAM_SUSPEND_REQ without receiving a response, STREAM_START_REQ is received and enters open state, then DISCONNECTED_EVT is received, causing pending to remain in stop state, which
prevents music from playing normally after reconnection.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng c052138352 hfp_hf: move callbacks lifecycle to init/cleanup
bug: v/83395

Rootcause: Upper-layer app does not unregister callbacks on BT off.

Callbacks list was freed in hf_shutdown, losing registrations across BT on/off cycles. As a compatibility change, move callbacks to init/cleanup so registrations persist across BT enable/disable.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng 24f3458801 hfp_ag: add debug logs for phone state change
bug: v/86209

Add logging in bt_sal_hfp_ag_phone_state_change to trace incoming
call state parameters, new call creation, and existing call state
transitions for easier debugging.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng a757639402 hfp_ag: fix last call terminate not sending hangup to HF
bug: v/86209

When only one call remains in the call list and it is terminated,
the AG should send a hangup indication rather than CHLD=1 to the
HF device, so the HF side can correctly update its call state.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng 54aca2b7d4 hfp_ag: move callbacks lifecycle to init/cleanup
bug: v/83395

Rootcause: Upper-layer app does not unregister callbacks on BT off.
Callbacks list was freed in ag_shutdown, losing registrations across
BT on/off cycles. As a compatibility change, move callbacks to
init/cleanup so registrations persist across BT enable/disable.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng caf260a82f hfp_ag: fix duplicate call state transitions in SAL callbacks
bug: v/86209

Rootcause: When zblue triggers call state callbacks (accept/held/retrieve/
reject/terminate), the SAL layer notifies the upper service layer, which
then calls phone_state_change to update the same state. This causes
duplicate Z_API calls back into zblue, leading to stack errors.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng 738422724c hfp_ag: fix call_sync entry cleanup in SAL layer
bug: v/87527

Rootcause: In update_sal_call, when a call entry has unknown state
or direction, find_call_by_context was used to locate the owner
connection. However for call_sync entries the context may be NULL,
causing the lookup to fail and the stale entry to remain in the
list. Also, phone_state_change did not remove call entries on
terminal states.

Use the conn parameter directly instead of find_call_by_context,
and remove call entries when state becomes unknown after
phone_state_change.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng 7450ea80b6 hfp_ag: sync actual codec on negotiation success
bug: v/87527

Rootcause: When HFP connection is established during an active call,
AT+BAC sets preferred_codec to mSBC, but bt_hfp_ag_codec_select may
auto-select CVSD. The codec_negotiate callback on success path did
not sync the actual codec back to preferred_codec, so upper layer
used mSBC sample rate (16000Hz) for CVSD data, causing audio
distortion (noise).

Update zblue_on_ag_codec_negotiation to accept the actual codec_id
from the callback. On success, compare with preferred_codec and
notify upper layer via hfp_ag_on_codec_changed if they differ.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng 962f40c78c hfp_ag: fix can not disconnect connecting connect.
bug: v/87566

can not disconnect connecting connect.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng b2356d6bda hfp_ag: add AG_STACK_EVENT_CALL_SYNC CASE_RETURN_STR
bug: v/87550

Rootcause: CASE_RETURN_STR missing
Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 71d247e024 add conn param/phy callbacks to gatt role-based dispatch
bug: v/87762

Replace HCI role checks (BT_HCI_ROLE_CENTRAL/PERIPHERAL) with slot->role
bitmask dispatch (GATT_ROLE_SERVER/CLIENT) in zblue_on_param_updated and
zblue_on_phy_updated, consistent with zblue_on_connected pattern.

- Use get_le_addr_from_conn() instead of manual bt_conn_get_info +
  address resolution blocks
- zblue_on_param_updated: dispatch to gatts/gattc based on slot->role
- zblue_on_phy_updated: call adapter_on_le_phy_update, then dispatch to
  gatts/gattc based on slot->role

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
chejinxian1 ebefa1d6d4 bluetooth/tools: fix Coverity defects in l2cap tool
bug: v/87430

- Replace strncpy with memcpy for non-string delimiter field
  to avoid non-null terminated buffer warning
- Remove dead comparison msg->id < 0 on unsigned type and
  change msg->len <= 0 to msg->len == 0 to fix
  unsigned compared against 0 warning

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 c612690595 Add NULL guards for global connection lists
bug: v/83789

Add defensive NULL checks before bt_list_find/bt_list_head calls
to prevent crashes when global connection lists are not initialized.

Files modified:
- sal_avrcp_interface.c: check bt_avrcp_conn
- sal_connection_manager.c: check bt_sal_connecting_list
- sal_hfp_hf_interface.c: check g_sal_hf_conn_list
- sal_spp_interface.c: check connections/servers lists

- rootcause: bt_list_find() contains assert(list) which crashes when
  the list parameter is NULL. This can happen if callbacks are invoked
  before the module is fully initialized or after cleanup.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 e12d033afb zblue le scan sal support scan filter with whitelist
bug: v/82734

Support BT_LE_SCAN_POLICY_ONLY_WHITE_LIST in bt_sal_le_set_scan_parameters
by setting BT_LE_SCAN_OPT_FILTER_ACCEPT_LIST option, now zblue only
support BT_LE_SCAN_OPT_FILTER_ACCEPT_LIST

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 a559753d1d bluetooth: fix the heap use after free bug in scan_manager.
bug: v/55272

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 9e3c953bcf bluetooth:Support scan filter policy feature in bluetooth framework/service.
bug: v/55749

API user can pass scan policy refs in ble_scan_filter_type_t.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia ca9dec36f2 cs: clang-format.
bug: v/87425

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 0c4d32d4d4 cs: Fix the issue of LE address and conn mismatch.
bug: v/87425

After successful binding, the address obtained from zblue using bt_conn_get_dst is different from the address stored by the framework after ACL connection success, causing the conn retrieved by address
to potentially be null.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 832a9608be cs: Fix the issue of incomplete RAS data notify transmission.
bug: v/87425

In ras_notify_cb, only RAS_RTT_DATA_INDICATE is handled, RAS_RTT_DATA_NOTIFY is not handled.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 bc366f3585 Fix bt_sal_le_smp_reply to use service worker
bug: v/87570

Switch bt_sal_le_smp_reply to async execution via service worker
to avoid HCI command timeout when user rejects pairing.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia eb2f3910fd cs: Add default configuration.
bug: v/87425

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 5eb5c62f05 cs: Fix the crash issue.
bug: v/87425

In zblue_on_cs_subevent, even if step_data_buf is NULL, the system still reports it to the service, which leads to a NULL pointer dereference in ras_subevent_data_conversion and causes a system crash.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 1dfea5724b cs: Move the HCI command into the worker.
bug: v/87425

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia d44b35611f cs: Fix the issue where On-Demand Mode can only handle the first Producer.
bug: v/87350

After sending data for one Producer, the subsequent Producers are not processed because ras_notify_cb lacks handling for RAS_CONTROL_POINT_CHAR_SEND_CB. Additionally, sending the next Producer requires the condition on_demand_state == IDLE to be satisfied.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 9ec5776fd1 cs: Fix the data transmission issue in On-Demand mode notifications.
bug: v/87350

In ras_ondemand_send_ranging_data, after sending notification data, the on_demand_curr_node pointer does not advance to the next element, causing cs_ras_on_demand_notify_finished to process data that has already been sent.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia d6690aeb93 cs: Fix the parameter mismatch in cs_ras_on_demand_send_cmp_ranging_data_rsp.
bug: v/87350

When sending CS data in On-Demand mode completes, the cs_ras_on_demand_send_cmp_ranging_data_rsp should be called with the current Producer Index, but the code does not record this index.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia a913c6a857 cs: Fix RAS not receiving notification/indication callbacks.
bug: v/87350

CCC configuration not being propagated through ras_attr_db and cfg_cb, and ensure cs_ras_notify_complete_cb handles the correct ATTR_ID.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 5ee890cc21 cs: Fix compilation errors.
bug: v/87350

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 215e4f1e11 cs: Modify the composition of the first 16 bits in the Ranging Header.
bug: v/87350

anging Counter is lower 12-bits of CS Procedure_Counter,Configuration ID is configuration identifier.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia d39fc0f95e cs: Fix Data Transmission Failure in RTT Mode.
bug: v/87350

In range_rtt_dt_ccc_cfg_changed, rt_dt_ccc_cfg is not assigned a value, but cs_ras_split_real_time_segment uses rt_dt_ccc_cfg to determine whether to call BT_GATT_NOTIFY or BT_GATT_INDICATE, causing CS data transmission failures .

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 2fc72d34b7 cs: Enhance Compatibility
bug: v/87350

Introduce Controller ID Parameter in bt_sal_cs_procedure_enable.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
Lu Jia 3222cb0948 cs: Update ras_send_feature_read_rsp.
bug: v/87349

Adapt to the new CS framework .

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 7d5503bc92 Fix AMS volume control failure after BLE reconnection
bug: v/85877

rootcause:
Disconnect event order was incorrect: LE ACL reported before profile (GATT),
causing stale handle to be selected after reconnection.
Fix by reporting profile (GATT) disconnect before LE ACL disconnect.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 24f2be16ee auto-accept BLE smp CONSENT pairing directly at SAL layer
bug: v/87350

rootcause: bt_device_set_pairing_confirmation() only supports PASSKEY_CONFIRM
  type pairing. When zblue_on_auth_pairing_confirm() is triggered for CONSENT
  type pairing, the previous code called adapter_on_ssp_request(PAIR_TYPE_CONSENT)
  to route through the app-layer callback chain, but the app layer has no way to
  reply via the existing API since set_pairing_confirmation does not handle
  CONSENT. To properly support CONSENT auto-accept without modifying the public
  API, call bt_conn_auth_pairing_confirm() directly at the SAL layer instead.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
YuhengLi a1ed5e657f hfp_hf: adapt vendor_specific callback to split cmd and value
bug: v/86014

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 e27c2a1cd5 Fix subscription persistence issue after bt_disable/enable
bug: v/85867

Problem:
After calling bt_disable_mc(), acl disconnected or bt_enable_mc(), bt_gatt_subscribe()
returns -EALREADY error when trying to resubscribe to the same CCCD.

Root Cause:
Zephyr Bluetooth stack implements subscription persistence for bonded
devices. When a device is bonded and the subscription does not have
BT_GATT_SUBSCRIBE_FLAG_VOLATILE set, the subscription parameters are
retained in memory after disconnection. Upon reconnection, when the
application attempts to subscribe again using the same params pointer,
the stack detects a duplicate subscription and returns -EALREADY.

Solution:
Set BT_GATT_SUBSCRIBE_FLAG_VOLATILE flag for all GATT client
subscriptions. This flag indicates that the subscription is temporary
and should be automatically removed upon disconnection.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng f02f33bafa hfp_ag: cache indicator values to avoid duplicate updates
bug: v/86045

Rootcause: bt_sal_hfp_ag_notify_device_status_changed unconditionally
calls all four indicator APIs on every invocation. The zblue stack
rejects duplicate values with -EINVAL, and SAL_CHECK_RET aborts the
remaining indicator updates.

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
liyuheng d12f79ab8c hfp_ag: handle AG_STACK_EVENT_CALL_SYNC in connecting state
bug: v/87271

Add AG_STACK_EVENT_CALL_SYNC handling in connecting_process_event to
avoid dropping the event when a call sync arrives before the HFP
connection is fully established.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhangyuan20 d9e407836e CS: add cs config and makefile.
bug: v/80281

Rootcause: Add CS configuration and makefile to manage CS compilation.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhangyuan20 90020e899a CS: add bttool to test cs.
bug: v/80281

Rootcause: Add bttool to test CS functionality

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhangyuan20 a8fa3ba64d CS: add cs socket server and client.
bug: v/80281

Rootcause: Add a socket server and client to enable communication between the user and Bluetooth.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhangyuan20 c0eb262b37 CS: add cs_ras_common.h
bug: v/80281

Rootcuase: this file used for ras server.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhangyuan20 1787ea002f CS: add cs service.
bug: v/80281

Rootcause: Add a CS service to manage CS.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhangyuan20 2c19cbfb56 CS: Add cs state machine.
bug: v/80281

Rootcuase: add cs state machine to manager cs procedure.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhangyuan20 388154f714 CS: Add sal_le_cs_interface.c
bug: v/80281

Rootcause: Add control interfaces such as CS config to the SAL layer.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhangyuan20 ac8d14a313 CS: Add CS callback in sal.
bug: v/80281

Rootcause: CS needs to report config, subevent, and other callbacks.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:55 +08:00
huangyulong3 9d9ab69e5d CS: Add the cs util header file.
bug: v/83722

rootcause: The CS util module provides functions and operations such as
linked list management for Channel Sounding.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
2026-04-27 23:14:55 +08:00
huangyulong3 8eac5afb0f CS: The CS util module provides functions for Channel Sounding.
bug: v/83721

roocause: The CS util module provides functions and operations such as
linked list management for Channel Sounding.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
2026-04-27 23:14:55 +08:00
huangyulong3 48293bb53b CS: Add the RAS test header file.
bug: v/83718

rootcause: Test modules can add various test cases to RAS, ensuring
that no additional bugs are introduced during code modifications.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
2026-04-27 23:14:55 +08:00
huangyulong3 9c75d61ad0 CS: Add the Channel Sounding RAS test file.
bug: v/83717

rootcause: Test modules can add various test cases to RAS,
ensuring that no additional bugs are introduced during code modifications.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
2026-04-27 23:14:55 +08:00
huangyulong3 ee66b60638 CS: Add the CS RAS header file.
bug: v/83716

rootcause: Add the Channel Sounding Ranging Service Header file.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
2026-04-27 23:14:55 +08:00
huangyulong3 9ae7450c1f CS: Add RAS moudle
bug: v/83713

rootcause: RAS is the Ranging Service required during the Channel Sounding
ranging process to return ranging data.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
2026-04-27 23:14:55 +08:00
huangyulong3 25897a5b40 CS: Add the CS GATTS header file.
bug: v/83698

rootcause: The GATTS module is essential for Channel Sounding during
the ranging process, involving GATT service creation, GATT message
transmission, and GATT management.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
2026-04-27 23:14:55 +08:00
huangyulong3 a3eac431b9 CS: Add the CS RAS GATTS module.
bug: v/83693

rootcause: The GATTS module is essential for Channel Sounding during
the ranging process, involving GATT service creation, GATT message
transmission, and GATT management.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 f43a1bf044 Implement CTKD support for cross-transport key derivation
bug: v/85866

Implemented Cross-Transport Key Derivation (CTKD) functionality to enable
secure key derivation between BR/EDR and BLE transports.

Changes:
- service/stacks/zephyr/sal_adapter_le_interface.c:
  * Added ctkd_mode field to sal_adapter_args_t union
  * Implemented enable_key_derivation() function
  * Completed bt_sal_le_enable_key_derivation() implementation with support
    for bidirectional key derivation (BR->LE and LE->BR)
  * Added proper CONFIG_BT_CLASSIC conditional compilation

- tools/bt_tools.c:
  * Added set_ctkd_mode_cmd() function for CLI control
  * Registered 'setctkd' and 'set ctkd' commands in command tables
  * Provides user-friendly interface to enable/disable CTKD modes

This feature allows devices to derive encryption keys across different
Bluetooth transports, improving security and user experience during
dual-mode connections.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 fa7f730f7e bluetooth: fix safe disable state checks and bonded restore ordering
bug: v/85716

The safe-disable path treated DISCONNECTING as DISCONNECTED, which can fire the "all ACL disconnected" event too early. That enables disable cleanup to run while links are still tearing down, leaving stale entries in the device list.

Those stale entries then break bonded restore: bonded_device_loaded used br_device_create unconditionally, so a new BR/EDR device (with a valid link key) was appended behind a zombie node. zblue link key loading copies from the service list by address, which can then feed an all-zero key into the stack.

Fixes:

- gate "all disconnected" on explicit DISCONNECTED state

- reuse existing device entries during bonded restore

- avoid removing devices that are still connecting/disconnecting

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
Kai Cheng b39cadca8e spp: prevent service loop deadlock on rfcomm_tx_pool exhaustion
bug: v/85736

Replace K_FOREVER blocking net_buf alloc in bt_sal_spp_write with
K_NO_WAIT non-blocking alloc. When rfcomm_tx_pool is exhausted,
return BT_STATUS_NOMEM instead of blocking the service loop thread
indefinitely.

In do_spp_write, handle BT_STATUS_NOMEM by caching unsent data via
spp_cache_fragement and stopping euv_pipe reads, rather than dropping
the data. Recovery occurs naturally when in-flight buffers complete
and spp_on_outgoing_complete restores remaining_quota.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 5c526deff8 fix null pointer access crash
bug: v/83903

when bt off, bt_sal_hid_device_cleanup() is called, hid_mgr->connections
will be removed, but there has hid_disconnect_handler in defered service
worker. Call hid_find_connection_by_address again, 'bt_list_head(hid_mgr->connections)' with null input.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 7133dbf0f4 drop stack api access in defered service worker when bt adapter is offline.
bug: v/83903

rootcause:
During shutdown, the stack disable is executed synchronously, while some API execute asynchronously. This can cause asynchronous handler func access 'hdev' resources that have already been memset to zero, resulting in null pointer exceptions. Therefore, service_work is not allowed to make stack interface calls during the bt_disable phase.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
zhongzhijie1 a50d87978f add miss bt_conn_unref
bug: v/83903

need bt_conn_unref after bt_conn_lookup_addr_br.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:55 +08:00
liuxiang18 a510c37783 gatts: modify gatts service sdp registration.
bug: v/85730

Previously, only the corresponding value in `bt_sdp_data_elem` was replaced, while other parts were still copied from `gatt_attrs_template`. This caused all modifications to reuse a single address, resulting in later-registered services overwriting earlier service records. Consequently, during SDP queries after BREDR connection, multiple identical `ATT sdp service attribute` entries appeared.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:55 +08:00
v-yichenxi 9ac5a39952 adapter: skip RNR for CTKD-derived link key to avoid paging conflict
bug: v/952

Rootcause: When BLE pairing completes and CTKD derives a BREDR link key,
process_link_key_update_evt triggers a Remote_Name_Request (paging) on the
BREDR address. This conflicts with the ongoing BLE SSP flow which may also
be paging, and more critically blocks the MFI SPP Create_Connection issued
~500ms later, causing it to fail with HCI 0x0C COMMAND_DISALLOWED.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2026-04-27 23:14:55 +08:00
Zihao Gao 2cad6e44d1 RSSI: add log when disconnected with 0x08 or 0x3e
bug: v/86588

This patch is used to monitor if connection timeout occurs when the remote device is in a reasonable range.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:55 +08:00
Zihao Gao 0e72579851 RSSI: add log mechanism at connection manager.
bug: v/86588

Connection manager, as a manager, should be responsible for monitoring the link quality of each connection.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:55 +08:00
Zihao Gao 4ddf4c0ef8 RSSI: update adapter services to update rssi.
bug: v/86588

Rootcase: the rssi is never changed after BR/EDR inquiry scan, and is never assigned a value for LE.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:54 +08:00
Zihao Gao 2f7c5b8421 RSSI: SAL interfaces for HCI Read RSSI command
bug: v/86588

This patch add sal interface to send a HCI Read RSSI command for a specific link. Note that bt_conn_le_read_rssi is renamed as bt_conn_read_rssi since this command serves for both BR/EDR and LE.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:54 +08:00
YuhengLi a446d6ecd0 zblue: hfp: replace magic numbers with named constants
bug: v/83723

Replace hardcoded sample rate and bit width values in HFP AG/HF codec

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:54 +08:00
YuhengLi 21d4eadaaa zblue: hfp: ag: fix connection not found when no codec negotiation
bug: v/86458

When HF does not support codec negotiation (no AT+BAC sent), the
sal_conn is not created before AT+CIND? is processed during SLC
establishment. zblue_on_ag_get_ongoing_call is called at this point
and fails with 'connection not found' because sal_conn only gets
created later in zblue_on_ag_connected.

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:54 +08:00
YuhengLi 7ecb00b734 zblue: hfp: ag: support codec neg
bug: v/83723

support codec neg

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 17f572ca9a fix build waring when CONFIG_BLUETOOTH_BLE_SUPPORT not enable
bug: v/84604

if ble not support, return 0.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 84b7960406 L2CAP: Fix log format mismatch in `handle_packet_received()`
bug: v/85464

Remove extraneous parameter in `BT_LOGE` call where format string has no corresponding placeholder for `packet->len_received`.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 95dd38bafb L2CAP: Add MPS validation for received segments
bug: v/85177

Add validation check to ensure received segment length does not exceed the negotiated MPS before processing. Abort channel if validation fails to maintain protocol integrity.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
Lu Jia 8aa53e32d4 bluetooth: Fix the issue where disabling does not disconnect the AVRCP target (tg) connection.
bug: v/85747

Fix connection manager disconnection logic: Only AVRCP Controller (CT) instances register explicit disconnect callbacks with the connection manager, while AVRCP Target (TG) connections are not proactively terminated during disable operations, leading to stale connection states and potential resource leaks.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 30f781f87f pm: add bt_cm_enable/disable_enhanced_mode for BR/EDR low-latency sniff
bug: v/67000

Add bt_cm_enable_enhanced_mode() and bt_cm_disable_enhanced_mode().
Support EM_BR_SNIFF_LOW_LATENCY and EM_BR_SNIFF_ULTRA_LOW_LATENCY.
They switch to lower sniff intervals for short-term low latency needs.
Disable API restores the default sniff parameters.

Note: idle timeout is not changed in current design. It may be extended in the future.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
YuhengLi 55d8088676 zblue: spp: unregister rfcomm server when sdp register fails
bug: v/86062

Rootcause: not unregister rfcomm server when sdp register fails causing memory access after free
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 9c4b086364 implement get addrtype api
bug: v/84604

original return 0 default, now use adapter_get_le_remote_address_type

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 a504715438 Fix GATTC discovery filter UUID handling
bug: v/83024

Restore the type==0 check so a non-NULL filter_uuid with type 0 is treated

as "discover all services," matching bt_gattc_discover_service behavior.

Add an inline comment to document the NULL-to-type=0 contract and avoid

invalid UUID discovery calls that can break subscription flow.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 daf31822d8 Supports user confirm in BLE Just Work pairing mode
bug: v/85869

1. Configure the correct `passkey_confirm` interface.

2. Follow the legacy stack; `le` iocap and `bt_iocap` are consistent.

3. No input/output iocap also supports `passkey confirm cb`.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 3adeaad48a gatts: fix address retrieval for att_over_br
bug: v/85531

When `conn.type = BT_CONN_TYPE_BR`, the original `get_le_addr_from_conn` function fails to locate the corresponding address, resulting in an address exception. The new `bt_sal_get_remote_address` function now incorporates logic to retrieve the LE address, making it a universal address retrieval interface for both BREDR and BLE.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 e1d922be22 gatts: add judge about conn_info is NULL.
bug: v/84474

When the SAL layer does not store the BREDR connection information, it returns info as NULL. At this point, attempting an erroneous address offset on info->conn will result in a null pointer return.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 d34e8575aa gatts: add `bt_conn_info_t` when att_over_br connected callbacks report.
bug: v/84474

When the peer initiates a connection, the connection callback reporting logic lacks the `bt_conn_add` entry. This prevents the subsequent SAL layer from retrieving the corresponding `bt_conn_info_t` object for the address, leading to subsequent data transmission process failures.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 4762d1271d gatts: fix an issue where `bt_conn_unref` was not called after using `bt_conn_lookup_addr_br`.
bug: v/84474

1. Add a call to bt_conn_unref(conn)
2. Use the locally stored conn in the sal layer to avoid executing `bt_conn_unref`

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 c92cb9a9ee gatts: fix logical exceptions when the registration service exceeds its limit
bug: v/84473

When the number of registered services exceeds the limit, records not captured by `gatt_sdp_records` will be returned. Subsequent attempts to locate pointer indices for release will fail.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 e1caf81f4a add ATTR_AUTO_RSP_CCC_READ to keep legacy GATT_H_CCCD behavior
bug: v/86395

rootcause:
Previously, CCC descriptors (defined by `GATT_H_CCCD`) would automatically respond to *read requests* within the stack, while forwarding all *write operations* (including write requests and write commands) to the application. This allowed the app to detect when a characteristic's notify/indicate status changed, without needing to implement `on_read_cb`.

During the Android BTIF porting, CCC read requests started being passed up to the application. This introduced compatibility issues for existing services that used `GATT_H_CCCD` without registering an `on_read_cb`, resulting in unhandled read responses.

To preserve backward compatibility, a new `rsp_type` value — `ATTR_AUTO_RSP_CCC_READ` — is introduced for `GATT_H_CCCD`. It restores the original behavior:

* Automatically respond to CCC descriptor read requests inside the stack
* Still forward write requests and write commands to the application via `on_write_cb`

This allows legacy services to continue functioning without modification.
Apps that require full control over both read and write (e.g. Android BTIF layer) should use `GATT_H_CCCD_USER_RSP`.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 10190d8dcb support user response for descriptor read requests
bug: v/86395

Provides a hook for business logic to observe and track read requests
without changing existing ATT/CCCD behavior.

Application sees the request but its response data is ignored; stack
still uses internal values for protocol correctness.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
Kai Cheng e2927efd8d SPP: add rx credits mode control
bug: v/85788

rootcause: enable spp rx credits mode control, in order to
fix  HFP/AG not auto credits

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:54 +08:00
Kai Cheng 8b92f2d7c7 SPP: add credits control for recv data
bug: v/85608

rootcause: Adding SPP process handling to the bluetooth
service resolves the issue of non-flow control data
piling up in the protocol stack.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:54 +08:00
Kai Cheng 82c0b955c1 spp: correct SDP UUID endianness and isolate RFCOMM params
bug: v/85645

rootcause: SPP SDP records used the wrong UUID byte order
and reused template data, so later registrations overwrote
previous RFCOMM channel/UUID and triggered false duplicates.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:54 +08:00
Kai Cheng ab4b02cdb8 spp: fix SDP proto list handling for RFCOMM channel
bug: v/85645

rootcause:The SDP PROTO_DESC list was modified in place
without copying, so the RFCOMM channel element pointer
could become invalid or corrupt, leading to incorrect
SDP records.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 e044c99d57 bluetooth: fix adv data parsing for zero-length AD structures
bug: v/85714

The previous implementation did not handle zero-length AD items (len == 0)
and lacked sufficient boundary checks. As a result, padding bytes could be
misinterpreted as valid AD elements, leading to construction of invalid
bt_data entries with oversized data_len values.

This could further cause out-of-bounds memory access during advertising data
processing in the host stack.

This change adds proper handling for zero-length AD items, validates item
length and buffer boundaries, and enforces segment count limits to prevent
invalid bt_data construction.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 3cca36d333 commit LE bond settings after load
bug: v/85615

After adding LTK/IRK, the stack must trigger the settings commit path so the controller resolving list and related RPA advertise/scan behavior are updated. Previously there was no key-level commit hook for zblue settings, so the commit handler was not invoked for these updates.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 d0c5c186c5 gattc: add CCC handle query for Zephyr stack
bug: v/83024

Zephyr stack needs CCC handle to do CCCD.
Old stack only needs value handle.

So gattc_service.c adds a query helper.
It uses the full service DB to map value_handle to ccc_handle.
sal can use this function to find the correct CCC handle.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 4417269939 gattc: restore single service DB and fix discover result loss
bug: v/83024

Some apps call bt_sal_gatt_client_discover_service_by_uuid() many times.
But current sal_gatt_client resets element index on every discover call.
So the discover result cannot be accumulated.

After discover finished, the service DB is incomplete.
Read / write by handle, especially CCCD, may fail.

This change copies service data by malloc and passes it to gattc_service.c.
gattc_service.c owns and frees this memory.
So the GATT service DB becomes complete and stable.
CCCD and other operations can work correctly.

Future plan:
Keep only one service DB, maintained by gattc_service.c.
sal_gatt_client_interface will use a dynamic list or array only during discovery.
After discovery, sal will not keep any service memory.
The service DB will be owned only by gattc_service.c.
This part is still TBD.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 11d442c427 bluetooth: serialize gattc discovery for stack compatibility
bug: v/83024

Some stacks (e.g. zblue) do not support parallel GATT discovery requests.
To improve compatibility, make if_gattc_discover_service transactional and
serialize discovery per connection in the common service layer.

When a discovery is in progress, queue additional discover requests and
start them one by one after receiving DISCOVER_CMPL. Clear pending discovers
on disconnect. Save filter_uuid in the queued gattc_op_t so each queued
request can be executed with its original parameters.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 172157bb6f Fix whitelist API typo, use the correct addr type rules.
bug: v/85615

See adapter_service.c. When adding/removing from the whitelist, the unknown type is treated as public, and the random type is passed directly.
The stack also needs a patch to convert random type addresses into identity addresses.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 9131229035 fix address translation issue and improved subscribe API return value handling.
bug: v/83024

rootcause:
This will result in the upper layer not receiving the GATTC notify.
The `get_le_addr_from_conn` interface correctly retrieves the RPA address for the callback,
not the identity address.

The EALREADY return value indicates that ccc has already been subscribed to, so it is not an error.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chengkai 1309b694c3 bluetooth: add spp insecure feature
bug: v/13885

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:54 +08:00
YuhengLi 983df76378 zblue: hfp: hf: avoid call hci_send_sync in bluetoothd
bug: v/84390

Rootcause: should not call hci_send_sync in bluetoothd
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 301df447c1 Bluetooth Adapter: add log for scan mode and bondable state
bug: v/85755

Add `BT_LOGI` log to print scan mode and bondable state in `adapter_set_scan_mode` function for better debugging and monitoring of adapter scan mode changes.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
Zihao Gao 8e1229fcc7 Adapter: disable safe for both BR/EDR and BLE
bug: v/84965

rootcause: safe disable for BR/EDR does not automatically triger safe disable in BLE.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:54 +08:00
v-yichenxi 87d95cab3f bluetooth: add libbluetooth dependency on zblue when ZBLUE stack is enabled.
bug: v/85506

When either ZBLUE stack option is enabled, add a dependency on zblue for libbluetooth via nuttx_add_dependencies, so zblue’s include dirs are applied only to libbluetooth and not globally.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2026-04-27 23:14:54 +08:00
v-yuechen1 00b3834856 spp: increase max connections from 2 to 9
bug: v/85292

spp: increase max connections from 2 to 9
- Modify BLUETOOTH_SPP_MAX_CONNECTIONS constant in kconfig

Signed-off-by: v-yuechen1 <v-yuechen1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 e7c3ecd6f8 restore svc_attr_count even if att br SDP record registration fails
bug: v/85532

rootcause:
Because of the introduction of ATT over BR, `register_service` needs to complete both BLE service registration and SDP record registration. The original design uniformly cleaned up the intermediate `attr_db svc_attr_count = 0` upon function exit to allow for the registration of the next service.

However, when `gatt_sdp_create_record` fails to add a record, the function returns directly, failing to reach `svc_attr_count = 0`, causing anomalies in the subsequent GATT service registration process.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
YuhengLi dd23ac80a0 zblue: a2dpsrc: fix: a2dp connect failure
bug: v/84293

Rootcause: config->delay_report was unexpectedly set to 1 because a2dp_info->config was not initialized.

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:54 +08:00
openvela-robot 73ae55888b update workflow files 2026-04-27 23:14:54 +08:00
zhongzhijie1 14a279fffb add conn null check after bt_conn_lookup_addr_br.
bug: v/85073

rootcause:
For example, an ACL connection might suddenly drop, due to issues such as controller problems or remote device problems.
Therefore, we might get an empty `conn`. We must perform a null check here to avoid operations like `conn->hdev` when calling the API.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 a73a956ad7 gatt: remove unused service register logic
bug: v/84936

The process sequence:
bt_sal_gatt_server_add_elements->add_service->add_characteristic->
add_descriptor, last register_service, so

if (svc_attr_count) {
    register_service();
}

this part of the code cannot be called, remove it.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 4bb23325a9 gatt: avoid memmove on server_svcs, use free slots for service allocation
bug: v/84936

rootcause:
server_svcs[CONFIG_GATT_SERVER_MAX_SERVICES] is registered into
zblue gatt->ctx->db->slist via bt_gatt_service_register().

Each struct bt_gatt_service contains an slist node:
    struct bt_gatt_service {
        struct bt_gatt_attr *attrs;
        size_t attr_count;
        sys_snode_t node;
    };

So the stack keeps a pointer to &server_svcs[i] in the slist.

When a service is removed, doing memmove on server_svcs will move the
struct bt_gatt_service object in memory.
But the stack still holds the old pointer (&server_svcs[i]) in the slist.
After memmove, that pointer refers to stale or wrong content.
This can break the service list and cause use-after-free / memory corruption.

Fix:
Do not compact server_svcs with memmove.
Keep the bt_gatt_service node address stable after registration.
Only keep server_db[CONFIG_GATT_SERVER_MAX_ATTRIBUTES] linear for attributes,
and allocate new services by finding free slots in server_svcs.
This allows server_svcs storage to be non-linear, while the stack slist still
manages a linear sequence of service attributes via the attrs pointer.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
Lu Jia 35cfc2567f Fix CMake compilation errors.
bug: v/85482

In the /service/ipc/socket/src/ directory, the scan-related source file is named bt_socket_scan.c, not bt_socket_le_scan.c.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 0531683e09 sal: bugfix for build error.
bug: v/84474

1. ../../frameworks/connectivity/bluetooth/service/stacks/zephyr/include/sal_zblue.h:36:30: error: unknown type name 'bt_transport_t'
2. ../../frameworks/connectivity/bluetooth/service/stacks/zephyr/sal_zblue.error: 'GATT_ROLE_SERVER' undeclared

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 3f3c1b4508 bluetooth: improve LE connection event reporting with profile tracking
bug: v/64642

Root cause:
The original mechanism could not accurately identify which profile (e.g., GATTC, GATTS) initiated the connection. The connection callback relied only on link role, which led to edge cases and incorrect profile dispatch.

Changes:

Extend g_acl (now g_le_conn_info) array to include connection role flags.

Use addr-based slot matching to associate connection events with the correct profile after le_create_connect() calls.

Add helper APIs to manage and access g_le_conn_info:

le_conn_find() to locate connection info by address

le_conn_add() to allocate a new entry

le_conn_remove() to free an entry

le_conn_set_role() to set role flags and trigger profile callbacks

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 ac4a0d5539 bluetooth: adapter ZEPHYR 4.0 SAL.
bug: v/60917

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 870b84e37a support legacy advertising when ext adv is not supported
bug: v/82053

Root cause:
- The code assumed extended advertising is always supported.
- On some controllers, advertising start/stop could fail.
What changed:
- If ext adv is not supported, use `bt_le_adv_start()` (legacy path).
- If app asks for ext adv but controller does not support it, return `BT_STATUS_UNSUPPORTED`.
- If ext not support, also try `bt_le_adv_stop()` to stop legacy advertising.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 1dda88727b Extract AD/ScanRsp data parsing code
bug: v/84426

AD/ScanRsp parsing code was duplicated, Move parsing to a shared helper `parse_bt_adv_data()`.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhongzhijie1 ad6a003495 support filter_policy for LE advertising
bug: v/82052

`filter_policy` was ignored, so whitelist filtering did not work as expected.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 97d8fb5725 gatts: add gatts over br notification & indication
bug: v/84886

Added notification and indication handling for the gatt_over_br event in the sal layer

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 b6a731a7a9 gatts:Implement the bt_sal_gatt_server_connect_bear interface
bug: v/84474

add att_over_br connected and disconnected callback, and replace le_conn_xx as bt_conn_xx

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 164d3217db sal: Change le_conn_info to bt_conn_info to make it compatible with both BREDR and BLE.
bug: v/84474

The modifications include the following:
1. rename le_conn_xx as bt_conn_xx
2. move interface from sal_adapter_le_interface.c to sal_zblue.c
3. add new formal parameters: transport

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 28b761df29 gatts: Implementation of GATT Service Registration
bug: v/84473

When a user defines a service using GATT_H_PRIMARY_SERVICE_OVER_BREDR, the corresponding start_hdl, end_hdl, and service UUID are registered in the SDP attribute.and service UUID are registered to the SDP.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 36ec7b30dd gatts:Implement the `bt_sal_gatt_server_connect_bear` interface
bug: v/84474

Implement the bt_sal_gatt_server_connect_bear interface and connect att_over_br to the profile direct connection.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
Lu Jia 6bba45387b avrcp: Fix the issue where the AVRCP CT cannot control the TG to switch songs.
bug: v/83779

When handling the handle_avrcp_passthrough_cmd function, the AVRCP Target (TG) does not report the PASSTHROUGH_CMD_ID_FORWARD and PASSTHROUGH_CMD_ID_BACKWARD events to the service. Instead, it directly responds to the peer device with BT_AVRCP_RSP_NOT_IMPLEMENTED, causing the peer device’s track switching control to fail.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 cb5b0435cd L2CAP: add configuration parameter validation
bug: v/84214

- Add `l2cap_config_param` to validate MTU, MPS and credits
- Validate MTU does not exceed maximum buffer size
- Validate MPS is non-zero and MTU >= MPS for BLE transport
- Auto-adjust `init_credits` to valid range [min_credits, max_credits]
- Apply validation in both listen and connect operations
- Add rx_buf_size clamping to L2CAP_MAX_RX_BUF_SIZE in handle_channel_conneted() and l2cap_send_sdu_to_app_cb()

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 a61eb2c3d9 L2CAP: fix memory leak in `free_l2cap_channel`
bug: v/84457

Add missing cleanup for `rx_sdu` to prevent memory leak when freeing L2CAP channel. The `rx_sdu` buffer should be freed before the channel structure is released.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 cdd6946ebe bttool: L2CAP: add configurable mtu/mps/credits parameters
bug: v/84420

Add support for configurable MTU, MPS, and credits parameters in L2CAP connect and listen commands with proper validation.

Changes:
- Add optional [mtu] [mps] [credits] parameters to connect/listen commands
- Use default values when parameters are not specified
- Add validate_l2cap_params() function for parameter validation
- Validate MTU >= 23, MPS range 23-65533, credits >= 1, and MPS <= MTU
- Provide clear error messages with specific validation failures
- Update command help text to reflect new optional parameters

Usage:
  connect <address> <psm> [mtu] [mps] [credits]
  listen <psm> [mtu] [mps] [credits]

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 5a3c6dfbfe bttool: L2CAP: add flow control commands for testing
bug: v/84215

Add stoprecv/startrecv commands to manually control data reception on L2CAP channels for flow control testing purposes.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 2bf1af3792 L2CAP: implement incoming credits refill mechanism
bug: v/84210

- Calculate additional credits based on available rx buffer space
- Call `bt_sal_l2cap_give_incoming_credits` to refill credits
- Update channel incoming credits after successful refill
- Initialize `rx_buf_size` based on initial credits and MPS
- Add `rx_buf_size` to connection log for debugging

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 d2c8360dbf L2CAP: add incoming credits validation and auto-refill mechanism
bug: v/84210

- Add credits validation before processing received packets
- Abort channel when receiving data without available credits
- Implement auto-refill mechanism when credits drop below `L2CAP_LE_CREDITS_LOW_WATERMARK`
- Ensure flow control compliance to prevent buffer overflow

This change enhances L2CAP flow control by validating incoming credits before accepting packets and automatically refilling credits when they fall below the low watermark threshold, preventing potential data loss and ensuring proper credit-based flow control operation.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 a31abe3104 L2CAP: improve error handling with unified channel abort
bug: v/84383

- Add `local_cid` validation in `handle_channel_conneted()` before disconnect
- Add `l2cap_abort_channel()` calls in error paths for consistent cleanup
- Call `l2cap_abort_channel()` in `l2cap_send_sdu_to_app()` on pipe write failure
- Call `l2cap_abort_channel()` in `handle_packet_received()` on MTU validation failure and SDU append overflow
- Ensure proper cleanup of pipe and L2CAP connection in all error conditions

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 b7326a8755 L2CAP: Add SDU delivery and buffer management
bug: v/84209

- Add `rx_list` and `rx_buf_size` fields to `l2cap_channel_t` for SDU tracking
- Define `L2CAP_MAX_RX_BUF_SIZE` macro for maximum receive buffer size
- Initialize `rx_list` in `alloc_free_channel()`
- Initialize `rx_buf_size` in `handle_channel_conneted()` with overflow protection
- Clean up `rx_list` in `free_l2cap_channel()` to prevent memory leaks
- Implement `l2cap_send_sdu_to_app()` to deliver reassembled SDUs to app
- Add `l2cap_send_sdu_to_app_cb()` stub for write completion handling
- Track buffer usage with `rx_buf_size` (decremented on segment recieved)
- Queue delivered SDUs in `rx_list` for lifecycle management
- Handle pipe write failures with proper SDU cleanup

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 6c35b08788 L2CAP: add SDU reassembly support for segmented packets
bug: v/84190

- Add `rx_sdu` field to `l2cap_channel_t` for receiving SDU segments
- Implement SDU reassembly logic in `handle_packet_received()`
- Add validation for SDU length against MTU
- Handle single-segment and multi-segment SDU scenarios
- Decrease incoming credits for BLE transport
- Add `l2cap_send_sdu_to_app()` stub for future implementation

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 b5d58b7ea2 L2CAP: rename `init_credits` to `credits` for dynamic tracking
bug: v/84211

Change field name from `init_credits` to `credits` in `l2cap_endpoint_param_t` to better reflect its purpose of tracking credit changes dynamically, rather than just storing the initial credit value.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 599dae9ef7 L2CAP: Add segmented SDU reception support with unified packet structure
bug: v/84189

This commit implements segmented SDU (Service Data Unit) reception handling for L2CAP channels, introducing a unified packet structure to manage both complete packets and segmented data reception.

Key changes:
- Define `L2CAP_CID_DYNAMIC_MIN` macro to specify the minimum dynamic CID value per Bluetooth Core Spec
- Define `l2cap_pkt_t` structure to unify packet data handling for both complete and segmented reception with length tracking
- Fix event name typo: `PACKET_RECEVIED_EVT` to `PACKET_RECEIVED_EVT`
- Implement `l2cap_on_segment_received()` function to handle segmented SDU reception with parameter validation and memory management

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
v-yichenxi 6ca0e6c7ca bluetooth: check remote address retrieval in HFP AG
bug: v/83166

Check bt_sal_get_remote_address() return value when creating HFP AG connection to avoid using an uninitialized address on failure.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2026-04-27 23:14:54 +08:00
v-yichenxi fe10ebb341 bluetooth: check remote address retrieval
bug: v/83166

Check bt_sal_get_remote_address() return value in HID accept callback to avoid using an uninitialized address on failure.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2026-04-27 23:14:54 +08:00
v-chenghuijin 5e83175f35 fix: prevent crash by ensuring non-null string for sched_note_printf
bug: v/84212

Rootcase: The lightweight sched_note_printf function in the NuttX backend does not
perform NULL safety checks for the %s format specifier. Passing a NULL pointer from
hsm_get_state_name leads to a NULL pointer dereference, triggering a data abort
exception on systems with memory protection (MMU/MPU) and causing a system crash.

Solution: This commit addresses the issue by modifying the HSM_SAFE_NAME macro to
use the ternary operator. It now explicitly returns the "None" string literal when
hsm_get_state_name returns NULL, guaranteeing that a valid, non-null C-string is always
passed to the logging function.

Signed-off-by: v-chenghuijin <v-chenghuijin@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhangyuan20 3e90658fc9 MultiConnect: add log for volume changed.
bug: v/84794

Rootcause: The current avrcp ct cannot quickly determine whether the media has set the volume to Bluetooth; logging is needed.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 ffd449d59e Bluetooth: Fixed an issue where resources could not be released after closing uv_pipe in euv_pipe.
bug: v/83955

Rootcause: euv_pipe_close records the address of the euv_pipe in the data field of each uv_pipe instance to be closed, which is used to release the euv_pipe instance after the close operation completes.

A scenario exists where calling euv_pipe_close followed by euv_pipe_read_stop or euv_pipe_read_start causes the client pipe's data field to be reset to NULL or the reader's address. This prevents the euv_pipe instance from being released after close completes.

This occurs because euv_pipe_read_stop does not check the uv_pipe's state before directly freeing cli_pipe.data, while euv_pipe_read_start only verifies whether cli_pipe is active. Both functions lack a check for the closing state.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhangyuan20 a79cd61c07 bluetooth: add dfx in android.
bug: v/84700

Rootcause: dfx should be added in android, or it will cause compilation problems.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:54 +08:00
v-chenghuijin 498bbed959 SPP: Fix race condition crash by unifying thread context for resource cleanup
bug: v/80850

Rootcause: uv_loop_close() marks internal data structures as invalid, but
pending callbacks in the queue still reference these invalidated
structures. When uv_run() is called later, it processes the queue using
corrupted pointers, leading to segmentation faults and crashes.

Solution:To address the issues described above, the solution removes
uv_loop_t from the bttool_t struct and changes it to dynamic allocation,
introducing a global pointer g_bttool_loop to centrally manage its
lifecycle. Specific modifications include: dynamically allocating and
initializing the uv_loop_t instance within the bttool_thread function and
assigning it to the global pointer; modifying the bttool_command_uvloop_run
function to operate using the global g_bttool_loop pointer; and adjusting
the asynchronous API initialization logic in async/gap.c to ensure it
uses the global pointer instead of a local pointer. Furthermore, the
solution enhances error handling, ensuring proper resource cleanup if
memory allocation fails, and optimizes the bt_tool_uninit_cb function to
prevent premature clearing of the global pointer, which could lead to
access exceptions.

Signed-off-by: v-chenghuijin <v-chenghuijin@xiaomi.com>
2026-04-27 23:14:54 +08:00
YuhengLi 3c0bad6980 zblue: hfp: ag: fix mem leak
bug: v/82382

Rootcause: mem not free in some case.
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:54 +08:00
Lu Jia 73db978918 Fix the issue where disable does not disconnect le ACL.
bug: v/84222

The safe disable method should disconnect the ACL connection.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:54 +08:00
Lu Jia ed0d7cb859 Fix the issue where disabling fails when only BLE is enabled.
bug: v/84222

The bttool calls the disable API. While the SYS_TURN_OFF_SAFE event is received in ble_on_state, the ble_on_process_event handler fails to process this event, causing the disable operation to fail. Add handling for the SYS_TURN_OFF_SAFE event in ble_on_process_event and transition to the ble_turning_off_state.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 2244e388f7 aync adv/scan: fix build error
bug: v/83666

The callback macro `CALLBACK_REMOTE` currently used in gatts/gattc employs the member variable `callbacks`. For enhanced versatility, the callback member variables in adv and scan have been modified from `callback` to `callbacks`.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 ca68358f90 scan: fix coding error
bug: v/84177

The on_scan_start_status callback was incorrectly used in BT_LE_ON_SCAN_STOPPED. It has now been reverted to on_scan_stopped.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 257b1d3593 socket: fix nullptr access when callback->member is NULL.
bug: v/84177

When a member variable is NULL within the scan_callback or adv_callback of the client call interface, the bt_socket_scan/adv fails to check for nullptr, resulting in a null address access.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 9f1317ecb0 adv/scan: rename member variables callback as callbacks
bug: v/83666

The callback macro `CALLBACK_REMOTE` currently used in gatts/gattc employs the member variable `callbacks`. For enhanced versatility, the callback member variables in adv and scan have been modified from `callback` to `callbacks`.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
liuxiang18 4d524866b1 socket: Move the generic macro to the public header file.
bug: v/83666

In the current bt_socket_profile file, all client-side callbacks use the generic macro interface
BREDR & common: CALLBACK_FOREACH
BLE: CALLBACK_REMOTE

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:54 +08:00
zhangyuan20 a8e63f3c35 Android-Vela: Fix AirPods silent issue.
bug: v/84346

Rootcause: Some older AirPods have a default volume of 0, resulting in no sound during calls and music playback. Therefore, should manually set the current volume when the device is connected.
Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 304d0656c3 Fix build warning in zblue board.
bug: v/51103

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
chengkai d7a276c5a7 bluetooth: add gatts_connect_bear api [1/2]
bug: v/51103

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 aaa760ea87 Ensure that the app specifies a UUID instead of forcibly converting it to 128-bit.
bug: v/83302

rootcause:
The original design would directly convert all bt_uuid parameters to 128 bits. However, when adding a service using GATT, we need to consider the uuid_type. If a 16-bit UUID is registered as a 128-bit UUID, some GATT clients that only use discover by UUID with 16 bits might not be able to find the registered service.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
Lu Jia 04c18ed137 gatts: Fix the issue of GATTs sending two write responses.
bug: v/83303

When the stack receives an att_write_req, it calls attr->write(). If the return value from SAL is -EINPROGRESS, the stack does not send a response, as the response will be handled by the service. Otherwise, the stack sends a response. In the SAL layer, bt_sal_on_ccc_written notifies the service, which then calls bt_sal_gatt_server_send_response. Since the return value from SAL is not -EINPROGRESS, the stack also sends a response, causing a conflict.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 ff6ce1b422 Add persistent storage of the GATT server database hash using KVDB.
bug: v/65135

KVDB backend had no key and no save/load path for GATT server database hash.
The system could not restore the hash after reboot and cache validation failed.
Add BT_KVDB_BLEGATTDBHASH and helpers to save/load remote_device_gatt_properties_t entries.
Count and delete old hash properties before saving new data.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 c9ec25e045 implement storage logic for GATT database hash.
bug: v/65131

There was no persistent storage for the server GATT database hash.
The system could not compare hashes after reboot and peers could keep a stale GATT cache.
Add remote_device_gatt_properties_t with 16-byte hash field.
Add save/load APIs for GATT hash cache using the uv_db backend (BT_KEY_BLEGATTHASH).

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 123ade9b66 update code ownwers of frameworks/bluetooth
Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 04d1af18ce zblue: hfp: hf: add check when get remote address
bug: v/82928

Rootcause: bt_sal_get_remote_address may fail

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi fea685e8d6 zblue: hfp: hf: remove the redundant stack variable
bug: v/82928

Remove the redundant stack variable bd_addr, which already exists in sal_conn.

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 2e7c5c3fda Android-Vela:add cind interface for android
bug: v/59050

Rootcause:When reconnect to the headset during a call, the headset will obtain the call status through the cind command. Since Vela does not have modem, the status will be error. So, get cind from Android.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 e3da0a99f5 Supports user confirmation during Just Work pairing in the app.
bug: v/81924

By default, just working (no I/O) should automatically accept user confirmation, but for compatibility with the watch app, app confirmation is required.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 5d4b187141 resolve gatts sal DB attribute quantity limit insufficient miwear total
bug: v/82104

The number of gatts sal DB attributes was insufficient for miwear's needs, so it was increased to a margin of 60. Future memory optimization projects will no longer maintain static arrays.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 303c98578c Remove the zephyr header file from the Bluetooth global header directory
bug: v/82081

`bt_le_scan.h` is a globally exposed header file. Then, Zephyr's `#include <zephyr/bluetooth/bluetooth.h>` is declared as a private inclusion of Zephyr in CMake. However, the problem is that when third-party apps use my global `bt_le_scan.h`, the CMake system doesn't know where `zephyr/bluetooth/bluetooth.h` is and throws an error. One solution is for the third-party app to also declare a private inclusion of Zephyr in CMake, but this doesn't conform to design principles. The app only needs to be concerned with my framework layer. If the app also needs to include Zephyr's header files, then the framework layer is not properly configured. Therefore, `zephyr/bluetooth/bluetooth.h` must not be explicitly included in `bt_le_scan`.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 e2a23e44c7 gatt: workaround BR/EDR service force to ble service.
bug: v/81958

Some services are marked with GATT_PROP_EXPOSED_OVER_BREDR, but current
not implement gatt over bredr. As a temporary workaround, clear
this flag when calling add_service() so the service is exposed over BLE.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 b4222022ac support generic descriptors in alloc_descriptor()
bug: v/81925

Add a generic descriptor allocation path, matching alloc_characteristic() style.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 f42d03e00f fix: resolve SPP connection lookup failure
bug: v/82095

The spp_connect_handler was attempting to look up the SPP connection
by rfcomm_dlc before it was added to the connection list, causing
"SPP connection not found for rfcomm_dlc" error.

Root Cause:
The connection object wasn't in the global connection list at the
time of lookup, making spp_find_connection_by_dlc() always fail.

Fix:
Pass the spp_conn pointer directly as user_data to avoid the lookup,
and add it to the connection list after successful initialization.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 c6f31b57a0 fix build warning when close avrcp control
bug: v/74709

only open CONFIG_BLUETOOTH_AVRCP_CONTROL or CONFIG_BLUETOOTH_AVRCP_ABSOLUTE_VOLUME can build in bt_avrcp_control_notification_cb.

error: 'bt_avrcp_info_find_by_ct' undeclared (first use in this function); did you mean 'bt_avrcp_info_find_by_tg'?
 1501 |     avrcp_info = bt_list_find(bt_avrcp_conn, bt_avrcp_info_find_by_ct, ct);
      |                                              ^~~~~~~~~~~~~~~~~~~~~~~~
      |                                              bt_avrcp_info_find_by_tg

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
chejinxian1 2dd9ac98b6 SPP: Enhance SPP device cleanup and connection handling with new close callback
bug: v/80808

Rootcause: In high-throughput reception scenarios, situations may arise where the `write_cb` for SPP data transmission to the application has not yet completed, yet the SPP device is released due to an abrupt disconnection, thereby preventing notification to the protocol stack that data reception has concluded.

To circumvent this issue, it is imperative to ensure all write operations are finalised before releasing the SPP device. Consequently, an `euv_pipe` close callback implementation has been introduced to guarantee that all `write_cb` operations execute successfully prior to severing the data pathway.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:53 +08:00
chejinxian1 ffe9428e8f Bluetooth: Add close callback support to `euv_pipe` structure and close functions
bug: v/80811

Rootcause: In certain scenarios, users of `euv_pipe` must ensure all UV requests have completed execution before releasing resources. Consequently, it is necessary to notify users that `euv_pipe` has been fully released after its close operation is completed, thereby permitting subsequent operational procedures to proceed. Support for the close callback has therefore been added.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 7ace20ddc8 zblue: hfp: ag: fix cannot connect ag after disconnect ag.
bug: v/81968

Rootcause: disconnected_callback not called caused connect info not cleared in connection manager module

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi ba5b1c1352 zblue: hfp: ag: fix crash when connect sco
bug: v/81752

Rootcause: audio_connect should not be called in bluetoothd task
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 159eff88a4 zblue: hfp: ag: fix crash in some cases
bug: v/80258

Rootcause: attributes in bt_sdp_discover_params may be modified by ZBlue SDP. Using const could cause a crash in some cases
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 3b3ba992a1 zblue: hfp: ag: fix crash when enable bluetooth after disable
bug: v/80268

Rootcause: Not unregister callbacks when cleanup.
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi c50da340d1 zblue: hfp: ag: using BT_HFP_AG_CALL_STATUS_UNKNOWN instead of -1
bug: v/81504
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 52b2cb501e zblue: hfp: ag: remove global var g_sal_ag_sync_conn
bug: v/81589

remove global var g_sal_ag_sync_conn and sync  call by addr

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi e081bbe098 zblue: hfp: remove unused functions
bug: v/81567

remove unused functions

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi de09e4746d zblue: hfp: ag: use real dial result
bug: v/81504

return -EINPROGRESS dial callback and send OK after dial response

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi e6f54d41ff zblue: hfp: ag: add logs to print call number when sync
bug: v/80269

Rootcause: add logs to print call number when sync
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 6af7d7d3d9 zblue: hfp: ag: fix connect fail
bug: v/80268

Rootcause: should not call unref at this time
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi eefd90a60e zblue: hfp: ag: adapt new profile direct connect api
bug: v/80268

Rootcause: profile direct connect api has changed
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi dade9fde52 zblue: hfp: ag: fix ARRAY_SIZE redefine warning.
bug: v/80258

Rootcause: ARRAY_SIZE redefined
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi a477d6fded zblue: hfp: ag: profile direct connect
bug: v/80268

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi ad2a07f91a zblue: hfp: ag: fix: CIND value send fail when connect
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 28330f9382 zblue: hfp: ag: fix: unexpected disconnect when connect.
bug: v/80268

Rootcause: unref conn before use
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 95ff44b12e zblue: hfp: ag: disconnect profile when remote does not support HFP HF.
bug: v/80268

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 47c1ca9843 zblue: hfp: implement bt_sal_hfp_ag_send_at_cmd API and callback
bug: v/80270

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 1621b8217c zblue: hfp: ag: implement transmit_dtmf_code callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi b27697c417 zblue: hfp: ag: implement voice_recognition callback
bug: v/80279

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 095d21ddab zblue: hfp: ag: implement vgm/vgs callback
bug: v/80279

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 056ab86475 zblue: hfp: ag: implement terminate callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi c53c14c11f zblue: hfp: implement reject callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi cc07bcc9c3 zblue: hfp: ag: implement retieve callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi ccff2e2c35 zblue: hfp: ag: implement held callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi cbe2678d88 zblue: hfp: implement answer callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 108f885a0a zblue: hfp: implement incoming_held callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 5b6e5033b7 zblue: hfp: ag: implement incoming callback
bug: v/80269

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 86754d17f1 zblue: hfp: ag: implement outgoing callback
bug: v/81504

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 02afee005d zblue: hfp: ag: implement bt_sal_hfp_ag_set_volume
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 93c50cc7a5 zblue: hfp: implement bt_sal_hfp_ag_set_inband_ring_enable
bug: v/81567

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 0b006b78d9 zblue: hfp: ag: implement bt_sal_hfp_ag_notify_device_status_changed
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 3a7363adc6 zblue: hfp: ag: implement bt_sal_hfp_ag_cops_response
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 81de22d52d zblue: hfp: ag: implement bt_sal_hfp_ag_dial_response
bug: v/81504

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi edd9d7e1fb zblue: hfp: ag: implement bt_sal_hfp_ag_clcc_response
bug: v/81604

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi fd0296b569 zblue: hfp: ag: implement bt_sal_hfp_ag_phone_state_change API
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi c41b6e15b1 zblue: hfp: implement vr start/stop API
bug: v/80279

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi fa39a980aa zblue: hfp: ag: implement number_call callback
bug: v/81504

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 581948c330 zblue: hfp: ag: implement bt_sal_hfp_ag_cind_response API
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi f43330c59e zblue: hfp: ag: implement audio disconnect API and callback
bug: v/80279

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 57140e2137 zblue: hfp: ag: implement audio connect API and callback
bug: v/80279

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi eecfd090fe zblue: hfp: ag: implement ag disconnect API and callback
bug: v/80268

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
YuhengLi 4c5e7c5760 zblue: hfp: ag: implement ag connect API and callback
bug: v/80268

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
wuxiaodong6 524df6bb31 delete spp_lock in spps
bug: v/80501

rootcause: in spps, all locks are called by a single thread called bluetoothd, and there are no race conditions, so locks can be optimized.

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2026-04-27 23:14:53 +08:00
liuxiang18 438c0032b7 storage: fix build error - add config dependency
bug: v/73508

During build ap_test, BLUETOOTH_SERVICE was not enabled, resulting in `service_loop.c` used by the storage module not being compiled. This caused an LD error.

/home/work/data/miui_codes/build_home_rom/out/bes_o62_ap_performance_test/../../frameworks/connectivity/bluetooth/service/common/storage_property.c:72:(.text.bt_storage_save_le_remote_device.constprop.0+0x78): undefined reference to `service_loop_work'

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:53 +08:00
liuxiang18 c56f5b4f4b storage update: enable storage update module.
bug: v/80712

change BLUETOOTH_STORAGE_UPDATE default value to 'y'.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:53 +08:00
liuxiang18 27cc4374e5 stroage: change default storage to BLUETOOTH_STORAGE_PROPERTY_SUPPORT.
bug: v/80711

Migrate storage from Unqlite to KVDB.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:53 +08:00
liuxiang18 842e267a37 storage_update: fix build error.
bug: v/73508

ARRAY_SIZE() is defined at "bt_utils.h"

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:53 +08:00
liuxiang18 781c999c91 storage: add "irk" notify and load callback implement.
bug: v/79393

Implement the SAL layer callback function for settings storage.
include:
BLE: zblue_on_irk_notify
     zblue_on_irk_load

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:53 +08:00
liuxiang18 8018850f6e bluetooth: add zblue settings save & load implement - BREDR linkkey.
bug: v/79394

Implement the SAL layer callback function for settings storage.
include:
1. SAL zblue_on_linkkey_notify & zblue_on_linkkey_load
2. add adapter_get_link_key API
3. add adapter_get_link_key_type API

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:53 +08:00
liuxiang18 7baa3e9add bluetooth: add zblue settings save & load implement - BLE keys.
bug: v/79394

Implement the SAL layer callback function for settings storage.
include:
1. SAL zblue_on_ltk_notify & zblue_on_ltk_load
2. add adapter_get_smp_data API
3. add adapter_get_local_csrk API

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:53 +08:00
Yuheng Li f7d0f931c4 zblue: hfp: hf: fix ARRAY_SIZE redefine warning.
bug: v/80258

Rootcause: ARRAY_SIZE redefined

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
liyuheng 5a97fc75c1 zblue: hfp: add empty HFP AG implementation
bug: v/77997

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:53 +08:00
Kai Cheng c6ba6fab4f blueototh: fix audio build break in le only mode
bug: v/76636

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:53 +08:00
Kai Cheng 699fcfa34e bluetooth: fix gatt moudle ci break
bug: v/76636

fix gatt moudle ci break with condition config

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:53 +08:00
Kai Cheng bd50fdb0ae bluetooth: fix connectionmgr ci break
bug: v/76636

fix connectionmgr ci break with CONFIG_BLUETOOTH_CONNECTION_MANAGER

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:53 +08:00
Kai Cheng 3b18b7cb8a bluetooth: fix hci hal build break
bug: v/76636

CC:  string/lib_bsdstrchr.c service/stacks/bluelet/sal_adapter_interface.c: In function ‘transport_write_packet_callback’:
service/stacks/bluelet/sal_adapter_interface.c:357:5: warning: implicit declaration of function ‘bt_sal_hci_send_packet’ [-Wimplicit-function-declaration]
  357 |     bt_sal_hci_send_packet(hci_packet, length);
      |     ^~~~~~~~~~~~~~~~~~~~~~
service/stacks/bluelet/sal_adapter_interface.c: In function ‘hci_poll_recv’:
service/stacks/bluelet/sal_adapter_interface.c:666:9: warning: implicit declaration of function ‘bt_sal_hci_transport_recv’; did you mean ‘bt_sal_hci_transport_init’? [-Wimplicit-function-declaration]
  666 |         bt_sal_hci_transport_recv();
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~
      |         bt_sal_hci_transport_init

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:53 +08:00
Kai Cheng 43b6f0e791 bluetooth: fix bt_socket_server build break
bug: v/76636

rootcasue: fix ci break
./frameworks/connectivity/bluetooth/service/ipc/socket/src/bt_socket_server.c:171:96: error: code should be clang-formatted [-Wclang-format-violations]
      if (BT_IPC_CODE_CHECK_RANGE(packet->code, BT_MANAGER_MESSAGE_START, BT_MANAGER_MESSAGE_END)
./frameworks/connectivity/bluetooth/service/ipc/socket/src/bt_socket_server.c:174:103: error: code should be clang-formatted [-Wclang-format-violations]
      } else if (BT_IPC_CODE_CHECK_RANGE(packet->code, BT_ADAPTER_MESSAGE_START, BT_ADAPTER_MESSAGE_END)
./frameworks/connectivity/bluetooth/service/ipc/socket/src/bt_socket_server.c:177:78: error: code should be clang-formatted [-Wclang-format-violations]
      } else if (BT_IPC_CODE_CHECK_RANGE(packet->code, BT_DEVICE_MESSAGE_START,BT_DEVICE_MESSAGE_END)

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:53 +08:00
liuxiang18 c7d042e371 bluetooth: add bttool-storage
bug: v/70895

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:53 +08:00
liuxiang18 7684233bf1 bluetooth: add KVDB properties remove function.
bug: v/71117

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:53 +08:00
liuxiang18 76e949e897 bluetooth: Expose a subset of the universal interfaces for usage in storage updates.
bug: v/71112

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:53 +08:00
liuxiang18 415be99036 bluetooth: adapt storage update module Makefile & CMakeLists
bug: v/71113

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:53 +08:00
zhongzhijie1 2d71371901 Remove redundant gatt server local read/write implement.
bug: v/78372

cause of open-vela/external_zblue/pull/107, now use async way for gatts
read/write response, so no need local way.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:53 +08:00
Kai Cheng 0aa1d74548 bluetooth: remove invalid BLUETOOTH_SPP depend
bug: v/73970

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:52 +08:00
Lu Jia e0699b4797 bluetooth: Before releasing the IPC pending_queue, invoke the asynchronous callbacks for all messages contained within it.
bug: v/77564

When deleting the Bluetooth asynchronous instance, the IPC cached messages are directly released, and their asynchronous callbacks will not be invoked. This could lead to memory leaks if resources are released within the callbacks.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:52 +08:00
Zhijie Zhong de8ef06fc8 Add bluetooth code owners configuration
Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:52 +08:00
wuxiaodong6 158d5f8e10 fix sal_(gattc & le_adv & le_scan) _interface memory leaks
bug: v/76702

Rootcause: the memory may not be released.

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2026-04-27 23:14:52 +08:00
liyuheng 199fdff9d6 Fix overflow before widen
bug: v/76743

Rootcause: 2 * stream->interval_ms * 1000 will use 32-bit integer when calculate on a 32-bit platform.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:52 +08:00
Kai Cheng d6bd202002 bluetooth: add ipc and service module for cmake
bug: v/76636

disable unused ipc and service module in small
memory case.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:52 +08:00
Kai Cheng 3e328ff2f5 bluetooth: merged bt driver thread to btservice loop thread
bug: v/76633

remove bt driver thread, and merger it to service loop thread

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:52 +08:00
wuxiaodong6 616c09ec15 Move the internal header files out to include common
bug: v/73268

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2026-04-27 23:14:52 +08:00
gaoyuan28 7414987dde use jidl-rust tool to add bluetooth features
bug: v/53049

Signed-off-by: gaoyuan28 <gaoyuan28@xiaomi.com>
2026-04-27 23:14:52 +08:00
gaoyuan28 e18cc309fd use enhanced uttx_add_jidl to add bluetooth features
bug: v/58982

Signed-off-by: gaoyuan28 <gaoyuan28@xiaomi.com>
2026-04-27 23:14:52 +08:00
Lu Jia 5ee1c6944a bluetooth: Remove the macro control for bluetooth_ble_impl.c in Makefile and CMakeLists.
bug: v/67404

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:52 +08:00
Lu Jia 1aa0a59c97 ipc: trace async api
bug: v/62087

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:52 +08:00
zhongzhijie1 e52b434172 gattc/feature: add high-level GATT client, local DB, and async ops
bug: v/62106

Add feature-layer GATT client (gatt_client_t) wrapping low-level GATTC callbacks.
Build a local services DB from discovery (service/characteristic/descriptor).
Provide stable UUID handle lookups and helpers (service/char/desc finders).
Implement async read/write for characteristics and descriptors, notify subscribe/unsubscribe, and MTU exchange.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:52 +08:00
Lu Jia 6ab8107575 ipc: gattc async api
bug: v/62106

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:52 +08:00
Lu Jia 8a49db6e78 bluetooth: Increase the dependencies for the bluetooth feature.
bug: v/69934

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:52 +08:00
Lu Jia b8c7fb4e23 bluetooth: Rename the macro for modifying A2DP SBC parameters.
bug: v/60871

Root cause: The macro names A2DP_SBC_SUBBAND_MSK and A2DP_SBC_SUBBAND_4 conflict with the macros defined in zblue, causing warnings to appear. The names of the macros in the framework were prefixed with BT to resolve the conflict, and the macro names for A2DP SBC defined in the framework were also uniformly prefixed with BT to maintain consistency in style.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:52 +08:00
Zihao Gao e499823b31 A2DP: Add timeout detection for source stream timer.
bug: v/72047

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:52 +08:00
yuzihan1025 ded2d655b1 A2DP frame structure detection
bug: v/71791

Signed-off-by:Zihan Yu <167994520@qq.com>
2026-04-27 23:14:52 +08:00
v-yichenxi a737850e1f bluetooth: fix visibility not disabled before bt_disable
bug: v/64223

rootcause: device remained visible after bt_disable

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2026-04-27 23:14:52 +08:00
liuxiang18 54f9f99502 PTS: add pts property for dynamic control disconnect or not when pair failed.
bug: v/71321

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:52 +08:00
chengkai 7d2627e6f6 bleutooth: clean cached devices when discovery start stop
bug: v/57740

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:52 +08:00
liuxiang18 35619721a7 bluetooth: implement bt_device_set_bondable_le API to change bond mode.
bug: v/67335

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:52 +08:00
liuxiang18 9d7ddc49be bluetooth: implement bt_device_set_security_level API to change bond security level.
bug: v/67009

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:52 +08:00
Kai Cheng 89d1a7df7a bluetooth: add gatt client and server config
bug: v/51584

add gatt client and server config

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:52 +08:00
Kai Cheng cb99b4546c blueototh: add ipc and service config
bug: v/51584

add ipc and service profile config

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:52 +08:00
Kai Cheng adc08df0a4 blueotooth: add log config
bug: v/51584

add CONFIG_BLUETOOTH_LOG config

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-27 23:14:52 +08:00
duqunbo cd756e4cee HFP HF:Modify compilation warning.
bug: v/46476

rootcause:voip_call_number is used only when HFP_HF_WEBCHAT_BLOCKER is enabled.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2026-04-27 23:14:52 +08:00
liyuheng 16abe9046b Update Bluetooth Kconfig with new structure.
bug:v/68430

modified:   Kconfig

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2026-04-27 23:14:52 +08:00
v-yichenxi a3cc0bd160 bluetooth: fix visibility not disabled before bt_disable
bug: v/64223

rootcause: device remained visible after bt_disable

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2026-04-27 23:14:52 +08:00
liuxiang18 dd8a0ef9f1 bluetooth: fix bond fail after peer device deletes the bond information.
bug: v/66770

The local bond information remains when peer removes bond information. Then peer initiates the SMP Pairing request, will callback zblue_on_security_changed with err(BT_SMP_ERR_AUTH_REQUIREMENTS). So add the remove bond information logic on zblue_on_security_changed. When security_changed with an error, remove bond information.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:52 +08:00
zhongzhijie1 21458c91ca fix CCC callback crash due to early instance cleanup on disconnect
bug: v/66753

Calling `bt_conn_disconnect()` previously led to an immediate `memset` of
GATT instance resources, including CCC callback information.

However, during Zephyr's internal disconnect process, the CCC callbacks are
still invoked. Because the instance had already been cleared, this caused
null pointer dereference issues.

This patch defers instance cleanup until `zblue_on_disconnected()` is called,
ensuring CCC callbacks remain valid throughout the disconnection sequence.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:52 +08:00
zhongzhijie1 a99ae73163 bluetooth: improve LE connection event reporting with profile tracking
bug: v/64642

Root cause:
The original mechanism could not accurately identify which profile (e.g., GATTC, GATTS) initiated the connection. The connection callback relied only on link role, which led to edge cases and incorrect profile dispatch.

Changes:

Extend g_acl (now g_le_conn_info) array to include connection role flags.

Use addr-based slot matching to associate connection events with the correct profile after le_create_connect() calls.

Add helper APIs to manage and access g_le_conn_info:

le_conn_find() to locate connection info by address

le_conn_add() to allocate a new entry

le_conn_remove() to free an entry

le_conn_set_role() to set role flags and trigger profile callbacks

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:52 +08:00
v-hanjing3 e1f34acea6 64-bit: Fix type mismatch issues.
bug: v/59352

Rootcause: On 64-bit platforms, some Log statements have format strings that do not match the variable types.

Signed-off-by: v-hanjing3 <v-hanjing3@xiaomi.com>
2026-04-27 23:14:52 +08:00
zhongzhijie1 43429d82f2 bluetooth: open bluetooth dfx
bug: v/65804

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:52 +08:00
Lu Jia ac28491a2d bluetooth: Increase BLE gap data analytics with dfx.
bug: v/65489

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:52 +08:00
Lu Jia bb96c36bb5 bluetooth: Increase BR gap data analytics with dfx.
bug: v/65489

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:52 +08:00
Lu Jia 79655b85f6 bluetooth: Add kconfig and makefile for the asynchronous API feature.
bug: v/63431

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:51 +08:00
liuxiang18 2bec299b07 bluetooth: fix le disconnected_cb error called when bredr disconnected.
bug: v/67560

zblue's connection callback uses broadcast, and the connection callback is sent to all registered conn_cbs in a round-robin manner. This causes bredr to incorrectly execute the ble disconnection logic when it disconnects.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:51 +08:00
openvela-robot c94519872b update .github 2026-04-27 23:14:51 +08:00
openvela-robot 66ec689200 update .github 2026-04-27 23:14:51 +08:00
chengkai 05e1bfef50 bluetooth: fix multi-contoller ble enable fail
bug: v/57425

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:51 +08:00
chengkai 8d456a5218 bluetooth:fix zblue multi-controller build break
bug: v/57425

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:51 +08:00
liuxiang18 ace0535474 bluetooth: fix the problem of unsynchronized callback of connection address and bond address.
bug: v/62114

The current callback uses the info.le.dst as the callback address, but the dst addr is the random address of the peer when it is unbound. After bonded, the dst addr is updated to the public address after parsing. The result is that after bonded, the connected/disconnect callback is public address, which will result in first connected random address cannot to be removed.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:51 +08:00
zhongzhijie1 748ea54904 bttool: Update gattc gatts command, the last parameter is the address type.
bug: v/60490

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:51 +08:00
zhongzhijie1 578e895451 zblue: Fixed the issue that when BR and BLE coexist, framework BREDR monitors and responds to the BLE connection success event callback.
bug: v/60489

rootcause:
The ble connection event will invoke trigger the classic bluetooth connection event.
So we only need to determine whether conn belongs to bredr and then return.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:51 +08:00
chejinxian1 26a70f7af7 Bluetooth: add the stack size configuration option for the Bluetooth task.
bug: v/61147

Rootcause:The stack size parameter of the Bluetooth task should be set through configuration options to allow adaptation on different platforms.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:51 +08:00
zhongzhijie1 d79629bfa4 Rename helper func get_os_timestamp_xx to bt_get_os_timestamp_xx avoid
naming confict.

bug: v/59638

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:51 +08:00
Zihao Gao 9d6193def5 Bluetooth: defer LE scan results if IPC blocked.
bug: v/57341

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:51 +08:00
zhongzhijie1 fba5f48fab Fix build warning: -Werror=int-to-pointer-cast.
bug: v/58186

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:51 +08:00
zhongzhijie1 6cbbcb8ad1 Reduce MAX_SCAN_RESULTS_PER_PACKET from 15 to 13 for compatible with bt_message_packet_t union size.
bug: v/58186

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:51 +08:00
zhongzhijie1 12124f78a0 Redefine new ipc callback code BT_LE_ON_BATCH_SCAN_RESULT.
bug: v/52485

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:51 +08:00
zhongzhijie1 7bfcb74aa8 Support batch scan result report.
bug: v/58186

Detail:
- Implemented batch reporting for BLE scan results via 1024-byte pipe buffer.
  Supports up to 15 scan packets per batch.
- Added 150ms flush timeout to ensure timely reporting in low-traffic environments.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:51 +08:00
zhangyuan20 914526bf60 zephyr-pts: add send passthrough cmd for avrcp ct
bug: v/58789

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:51 +08:00
Lu Jia e781787517 bluetooth: When removing the bond, first disconnect the profile and then disconnect the ACL.
bug: v/59903

Root cause: When removing the bond, zblue only disconnects the ACL, not the profile. As a result, the A2DP connection fails when reconnecting next time.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:51 +08:00
liuxiang18 7fcbecc5cd IPC: fix build error conversion from 'int' to 'bt_message_type_t'.
bug: v/52485

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:51 +08:00
Haishen Zhang beebf57a97 Redefine IPC message/callback code
bug: v/52485

1. Add extended IPC message/callback code
2. Update bt_socket_client_callback_process()
3. Update bt_socket_server_receive()

Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2026-04-27 23:14:51 +08:00
liuxiang18 c4b13fe7b2 Makegile: fix adapter sal API undefined error when close bredr
bug: v/61048

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:51 +08:00
Haishen Zhang b6d9041078 BTS: Add Bond Tool
bug: v/57723

1. Add Bond Tool
2026-04-27 23:14:51 +08:00
Haishen Zhang 9dd20370bb BTS: Add Bluetooth Socket test tool
bug: v/57368

1. Add test tool of SPP
2. Add test tool of L2CAP over BREDR
3. Add test tool of L2CAP over BLE
4. Add Watch UI
2026-04-27 23:14:51 +08:00
Haishen Zhang 4aa506e324 BTS: Add layout for watch devices
bug: v/57133

1. Add layout for watch devices: ScrollView + ConstraintLayout
2026-04-27 23:14:51 +08:00
Haishen Zhang ae12a3458a BTS: Adjust the layout of MainActivity
bug: v/57133

1. Change LinearLayout to ConstraintLayout + ScrollView to make it more responsive
2. Add OnOffActivity.java and activity_on_off.xml to do Bluetooth On/Off operations
3. Add permissions in AndroidManifest.xml and request them during runtime
4. Add more debug logs
5. Remove Bluetooth On/Off operations from MainActivity.java
2026-04-27 23:14:51 +08:00
Haishen Zhang d78e6be873 BTS: remove "android:screenOrientation"
bug: v/57133

The <activity> element should not be locked to any orientation so that users can take advantage of the multi-window environments and larger screens available on Android.
2026-04-27 23:14:51 +08:00
Haishen Zhang 860e6357d9 Update Gradle and AGP
bug: v/57133

Upgrade AGP dependency from 8.7.2 to 8.9.0
Upgrade Gradle version to 8.11.1
2026-04-27 23:14:51 +08:00
chengkai 5b807f088c bluetooth: fix not report br/edr disconnect reason
bug: v/59936

rootcause: add disconnect reason report

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:51 +08:00
chengkai 540d46499d bluetooth: fix not update remote name
bug: v/59741

rootcause: it would not request remote when local has bonded info, then add
remote name request when acl connected.

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:51 +08:00
zhangyuan20 92594c2d26 Android-Vela: add clcc interface and callback
bug: v/60610

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:51 +08:00
Zihao Gao d91362fd92 Adapter: allow to check local support profiles via uuid.
bug: v/59759

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:51 +08:00
openvela-robot da1fa9aea1 workflows add stale.yml 2026-04-27 23:14:51 +08:00
chengkai af0bdfa8ac bluetooth: add bt trace tool
bug: v/59594

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:51 +08:00
chengkai d9cecb6987 bluetooth: add bt memory debug tool.
bug: v/59567

rootcause: add bt memory debug, support memory out-of-bounds check,
peak memory printing, and memory leak check
2026-04-27 23:14:51 +08:00
chejinxian1 981570db50 API: Add a new callback interface to obtain bond states.
bug: v/54141

Rootcause: The new interface will inform the upper-layer application of the previous bond state, thus distinguishing the different scenarios that may occur during the bonding process.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:51 +08:00
jialu 11c269d7d0 Bluetooth: Introducing the AVRCP function.
bug: v/46573

Rootcause: Add comments to the AVRCP .h file and improve function documentation.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:51 +08:00
fangzhenwei d61b5cf1be ipc: socket ipc support async call
bug: v/46316

1.add api bt_socket_client_send_with_reply

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2026-04-27 23:14:51 +08:00
liuxiang18 f376350309 Android-Vela: Adapter SPP in Android 14
bug: v/53727

open flag CONFIG_RPMSG_UART if defined(Android14)

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:51 +08:00
duqunbo 62216a72f8 A2DP sink: Switch stream.ready to false when A2DP sink is disconnected.
bug: v/53677

rootcause:When the A2DP sink disconnects, it does not send the A2DP_CTRL_CMD_STOP command. As a result, the bluetoothd daemon does not receive the STOP action, and the stream.ready flag is not reset. If stream.ready remains unreset, during the next connection, audio data may start being sent to the media layer before the media component issues the A2DP_CTRL_CMD_START command. This could lead to unintended audio streaming behavior.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2026-04-27 23:14:51 +08:00
liuxiang18 3401f08950 Android-vela: bt_client-add bt_socket disconnect handling
bug: v/53721

Fix lost BT connection between android and vela as vela/Android reboot.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:51 +08:00
duqunbo aea5f40624 Revert "HFP: Adds a function to delete list node resources"
bug: v/53473

This reverts commit 34efc6ea903f48edaac7d39dc4d2a3f269ae16b5.

Reason for revert: The release function causes repeated releases

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2026-04-27 23:14:51 +08:00
Zihao Gao 76014539ec HFP: hold +CIEV responses until current call list is updated.
bug: v/52252

Rootcause: Android behavior requires AT+CLCC command only after +CIEV received, and shall not be updated when not requested.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:51 +08:00
duqunbo 8e80c727a1 BTsnoop: Fixed cherry-pick conflicts.
bug: v/42717

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2026-04-27 23:14:51 +08:00
duqunbo d3b95f21f1 BTsnoop: add btsnoop API
bug: v/42717

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2026-04-27 23:14:51 +08:00
shenyangsi 75f0368648 test_suite: add BluetoothTest APP based on AndroidStudio
bug: v/52280

Signed-off-by: shenyangsi <shenyangsi@xiaomi.com>
2026-04-27 23:14:51 +08:00
chejinxian1 0d5604befa API Comments: Add comments to the API related to SPP.
bug: v/49544

Rootcause:To better assist the use of Bluetooth services for Bluetooth applications, this submission will add commentary descriptions for certain APIs in order to provide instructions for application reference

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:51 +08:00
chengkai 0f09cd64e9 bluetooth: adapt spp socket api
bug: v/47179

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:51 +08:00
chejinxian1 3345c269cc Log: Reduce redundant log information.
bug: v/53336

Rootcause: The log of PM will output information about the mode switching between sniff and active.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:51 +08:00
duqunbo 29e21f884e HFP: Adds a function to delete list node resources
bug: v/53343

rootcause: The memory allocated when the node is deleted is not freed because there is no delete function.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2026-04-27 23:14:51 +08:00
chejinxian1 8fbb699c66 API Comments: Add comments to the API related to HFP.
bug: v/46611

Rootcause:To better assist the use of Bluetooth services for Bluetooth applications, this submission will add commentary descriptions for certain APIs in order to provide instructions for application reference.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:51 +08:00
zhangyuan20 eb4d0a3ce3 Vela-Android: save bredr remote uuids
bug: v/45250

Rootcause: vela does not save remote uuids, causing android UI to display errors

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:51 +08:00
jialu 1838bc72e8 HFP: Adding vendor specific AT command process for AG
bug: v/17775

In order to implement the PTT function of headphone control, it is necessary to add the process of AG send and receive vendor specific AT commands.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:51 +08:00
fangzhenwei 3d0232691d sal: update zephyr 4.0 SAL
bug: v/49964

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2026-04-27 23:14:50 +08:00
fangzhenwei 44a24c0a70 addr: fix bt_addr_str multiple define
bug: v/49964

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2026-04-27 23:14:50 +08:00
openvela-robot a04c9f1196 Update the ci trigger from pull_request to pull_request_target 2026-04-27 23:14:50 +08:00
Zihao Gao 3b5e43eee4 zephyr: fix compiling issues.
bug: v/45540

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:50 +08:00
zhangyuan20 60072ab342 framework/avrcp: add metadata support for avrcp control in BT Service
bug: v/42362

Rootcause: Avrcp control lacks metadata interface, add get metadata interface and callback for avrcp control

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:50 +08:00
chejinxian1 5c99058bde OS-Upgrade: Add a BT storage transformation tool.
bug: v/47945

Rootcause: Due to the differences in the storage format of Bluetooth information in different system versions, in order to ensure that saved information can continue to be used after system upgrades, the storage transformation tool has been added.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:50 +08:00
chengkai 762c46bf83 bluetooth: add sal le scan interface
bug: v/42616

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:50 +08:00
chengkai b235c0ca05 bluetooth: add sal gatt server
bug: v/42619

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:50 +08:00
chengkai 34cd324193 bluetooth: fix le only mode build error
bug: v/43327

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:50 +08:00
chengkai 81057dee1c bluetooth: fix BT_UUID_DECLARE_XX build warning
bug: v/43328

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-27 23:14:50 +08:00
openvela-robot 4e284fe9d2 update CODEOWNERS, delete xiaoxiang781216 GUIDINGLI 2026-04-27 23:14:50 +08:00
Haishen Zhang 3b0e6f4ac7 Fix: compiling warning
bug: v/51418

1. Fix compiling warning. Print uint32_t as "%lu".

Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2026-04-27 23:14:50 +08:00
openvela-robot ff11a44813 update workflows ci.yml, delete pull_request_review trigger 2026-04-27 23:14:50 +08:00
openvela-robot b89fa88010 add .github/CODEOWNERS PULL_REQUEST_TEMPLATE.md 2026-04-27 23:14:50 +08:00
jialu b05d6fe309 AVRCP: add avrcp metadata feature
bug:v/42364

Adding AVRCP metadata feature

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-27 23:14:50 +08:00
zhongzhijie1 f49afa51e0 Bluetooth: framework/include/bt_hid_device.h, comments.
bug: v/45986

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:50 +08:00
zhongzhijie1 9e5bffd7b3 Bluetooth: framework/include/bt_device.h, comments.
bug: V/45984

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:50 +08:00
zhongzhijie1 8f6491a581 Bluetooth: framework/include/bt_addr.h, comments.
bug: V/45984

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:50 +08:00
zhongzhijie1 f7c8884982 Bluetooth: framework/include/bt_adapter.h, comments.
bug: V/45984

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:50 +08:00
zhongzhijie1 fe21f0767d [feat] Implement easy insertion of timeval measurements.
bug: V/43595

Changes:
1. Enabled Kconfig option BLUETOOTH_DEBUG_TIMEVAL, choice BLUETOOTH_DEBUG_TIME_UNIT_US enable or not.
2. Included 'bt_debug.h' in Bluetooth service or Bluetooth stack (bluelet).
3. Usage instructions:
   - In any function, first define the timeval structure by calling BT_DEBUG_MKTIMEVAL_S(name_s); at the global scope of the .c file.
   - Then, within the function, call BT_DEBUG_ENTER_TIME_SECTION(name_s); to record the entry time.
   - Finally, call BT_DEBUG_EXIT_TIME_SECTION(name_s); to record the exit time.

Example:

BT_DEBUG_MKTIMEVAL_S(hci_poll_recv);  // Suggest using the function name; since '__func__' cannot be used in precompile state, you need to input it manually.

static void hci_poll_recv(service_poll_t* poll, int revent, void* userdata)
{
    (void)poll;
    (void)userdata;

    if (revent & (POLL_ERROR | POLL_DISCONNECT))
        hci_remove_recv(NULL);

    if (revent & POLL_READABLE) {
        BT_DEBUG_ENTER_TIME_SECTION(hci_poll_recv); // Record entry time.
        bt_sal_hci_transport_recv();
        BT_DEBUG_EXIT_TIME_SECTION(hci_poll_recv);  // Record exit time.
    }
}

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:50 +08:00
fangzhenwei fa87d5daf5 adapter: service adapte to new sal2.0 api
bug: v/42144

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2026-04-27 23:14:50 +08:00
Zihao Gao 5f6acaf3f5 CMake: correct cmake dependencies.
bug: v/46045

Rootcause: Incorrect dependencies.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-27 23:14:50 +08:00
shenyangsi 805e59c285 ipc: fix the truncation issue of socket receiving or sending.
bug: v/45789

Rootcause: Missing return value handling for send() & recv() of socket

Signed-off-by: shenyangsi <shenyangsi@xiaomi.com>
2026-04-27 23:14:50 +08:00
liuxiang18 699424e0f6 storage:patch for KVDB storage feature
bug: v/42051

rootcause: implement the KVDB storage feature

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-04-27 23:14:50 +08:00
openvela-robot 9a1a00a441 update ci pull_request types to [opened, reopened, synchronize] 2026-04-27 23:14:50 +08:00
chejinxian1 636900a3ae Bluetooth: Add the Connection Manager(CM) module to manage performance enhancement features on different ACLs.
bug: v/43848

Rootcause: Some ACL need to add some enhanced features to provide a better Bluetooth communication experience. This submission is a part of the project and is intended for building a management framework.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:50 +08:00
zhongzhijie1 4a10c15312 [bugfix] Add global mutex to prevent multiple processors from modifying shared resources at the same time.
bug: v/50507

All processes can operate instance resources through the global pointer 'g_instances'. In order to avoid errors caused by common modifications, add mutex protection.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-27 23:14:50 +08:00
liujinye 314c68e58c workflows add ci.yaml 2026-04-27 23:14:50 +08:00
openvela-robot 56dcc1df6d workflows add checkpatch.yaml 2026-04-27 23:14:50 +08:00
openvela-robot 4f9a03d009 update issue template 2026-04-27 23:14:50 +08:00
openvela-robot c22ed32a0a update workflows ci 2026-04-27 23:14:50 +08:00
openvela-robot dc040bcd2b add issue template 2026-04-27 23:14:50 +08:00
Haishen Zhang e5ef25c8d5 Doc: Remove QuickAPP API details
Remove QuickAPP API details, for they've not been published yet.

Change-Id: Ie25d6c5088b118fadf681ba076ea984de7c15297
Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2026-04-27 23:14:50 +08:00
openvela-robot a6ab66c905 add ci.yml
Change-Id: Ica3c29801931a43fa5fb0bc327ece0f609e56cd3
2026-04-27 23:14:50 +08:00
openvela-robot 9d0c825cbb Merge commit
Change-Id: If26995eebd18a82ac4cd827e6801458e57a6ead3
2026-04-27 23:14:50 +08:00
387 changed files with 27930 additions and 8490 deletions

View File

@ -0,0 +1,40 @@
name: 缺陷反馈 | Bug
description: 当您发现了一个缺陷,需要向社区反馈时,请使用此模板。
title: "[BUG] <标题>"
labels: [👀 needs triage, "Type: Bug"]
body:
- type: markdown
attributes:
value: |
感谢您对 openvela 社区的支持与关注,欢迎反馈缺陷。
- type: textarea
attributes:
label: "重现问题的步骤"
description: "简洁地描述错误是什么,为什么您认为它是一个错误,以及如何重现它的步骤"
placeholder: |
重现问题的步骤,可能包括日志和截图。
1. 步骤 1
2. 步骤 2
validations:
required: true
- type: dropdown
id: architecture
attributes:
label: Issue Architecture
multiple: true
options:
- "Arch: arm"
- "Arch: arm64"
- "Arch: x86_64"
validations:
required: true
- type: markdown
attributes:
value: |
提交前请确认您已遵循以下步骤:
- 确认问题在 [**dev**](../) 上可重现。
- 遇到构建问题时运行 `make distclean`。
- 搜索 [现有问题](./)

View File

@ -0,0 +1,34 @@
name: 新需求 | Feature
description: 当您需要反馈或实现一个新需求时,使用此模板。
title: "[FEATURE] <标题>"
body:
- type: markdown
attributes:
value: |
感谢您对 openvela 社区的支持与关注。
- type: textarea
id: question-description
attributes:
label: 您的需求是否和问题相关?
description: 请简单描述问题并提供issue链接。
validations:
required: true
- type: textarea
id: solution
attributes:
label: 请描述您想要的解决方案
validations:
required: true
- type: textarea
id: 替代方案
attributes:
label: 请描述您考虑过的替代解决方案
- type: markdown
attributes:
value: |
提交前请搜索 [现有功能需求](./)

View File

@ -0,0 +1,22 @@
name: 问题咨询
title: "[问题咨询]"
body:
- type: markdown
attributes:
value: |
感谢您对 openvela 社区的支持与关注。
- type: textarea
id: question-description
attributes:
label: 描述
description: 请解释您的问题的背景或上下文,这有助于其他人更好地理解您的问题或疑问。
validations:
required: true
- type: markdown
attributes:
value: |
提交前请确认您已遵循以下步骤:
- 我已搜索 [openvela 文档](../),但未找到问题的答案。
- 已搜索 [现有问题](./)

View File

@ -0,0 +1 @@
blank_issues_enabled: false

View File

@ -0,0 +1,11 @@
## 概要
*在此部分更新信息,说明更改的必要性、具体做了什么以及如何实现的,如果有新功能出现,请提供参考资料(依赖关系、类似问题和解决方案等)。*
## 影响
*在此部分更新信息(如适用),说明更改如何影响用户、构建过程、硬件、文档、安全性、兼容性等。*
## 测试
*在此部分更新信息详细说明如何验证更改使用什么主机进行构建操作系统、CPU、编译器等使用什么目标进行验证架构、板子配置等。提供更改前后的构建和运行日志将非常有帮助。*

1
.github/CODEOWNERS vendored Normal file
View File

@ -0,0 +1 @@
* @hyson710 @gzh-terry @chengkai15 @huangyulong3 @zhongzhijie1 @zhangyuan376

View File

@ -0,0 +1,60 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Bug report
description: Report a bug to improve openvela stability
title: "[BUG] <title>"
labels: [👀 needs triage, "Type: Bug"]
body:
- type: markdown
attributes:
value: |
Hello openvela Community member! Please keep things tidy by putting your post in the proper place:
Reporting a bug: use this form.
Asking a question or getting help: use the [General Help](./new?assignees=&labels=Community%3A+Question&projects=&template=003_help.yml&title=%5BHELP%5D+%3Ctitle%3E) form.
Requesting a new feature: use the [Feature request](./new?assignees=&labels=Type%3A+Enhancement&projects=&template=002_feature_request.yml&title=%5BFEATURE%5D+%3Ctitle%3E) form.
- type: textarea
attributes:
label: "Description / Steps to reproduce the issue"
description: "A clear and concise description of what the bug is, and why you consider it to be a bug, and steps for how to reproduce it"
placeholder: |
A description with steps to reproduce the issue.
May include logs, images, or videos.
1. Step 1
2. Step 2
validations:
required: true
- type: dropdown
id: architecture
attributes:
label: Issue Architecture
description: What architecture(s) are you seeing the problem on?
multiple: true
options:
- "[Arch: arm]"
- "[Arch: arm64]"
- "[Arch: x86_64]"
validations:
required: true
- type: markdown
attributes:
value: |
### Before You Submit
Please verify that you've followed these steps:
- Confirm the problem is reproducible on [**dev**](../).
- Run `make distclean` when encountering build issues.
- Search [existing issues](./) (including [closed](./?q=is%3Aissue+is%3Aclosed))

View File

@ -0,0 +1,55 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Feature request
description: Request an enhancement for openvela
title: "[FEATURE] <title>"
labels: ["Type: Enhancement"]
body:
- type: markdown
attributes:
value: |
Hello openvela Community member! Please keep things tidy by putting your post in the proper place:
Requesting a new feature: use this form.
Asking a question or getting help: use the [General Help](./new?assignees=&labels=Community%3A+Question&projects=&template=003_help.yml&title=%5BHELP%5D+%3Ctitle%3E) form.
Reporting a bug: use the [Bug report](./new?assignees=&labels=%F0%9F%91%80+needs+triage%2CType%3A+Bug&projects=&template=001_bug_report.yml&title=%5BBUG%5D+%3Ctitle%3E) form.
- type: textarea
id: question-description
attributes:
label: Is your feature request related to a problem? Please describe.
description: Please provide a clear and concise description of what the problem is. Add relevant issue link.
validations:
required: true
- type: textarea
id: solution
attributes:
label: Describe the solution you'd like
description: Please provide a clear and concise description of what you want to happen.
validations:
required: true
- type: textarea
id: alternatives
attributes:
label: Describe alternatives you've considered
description: Please provide a clear and concise description of any alternative solutions or features you've considered.
- type: markdown
attributes:
value: |
### Before You Submit
Please verify that you've followed these steps:
- Search [existing feature requests](./) (including [closed](./?q=is%3Aissue+is%3Aclosed))

47
.github/ISSUE_TEMPLATE/003_help.yml vendored Normal file
View File

@ -0,0 +1,47 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: General Help
description: Get general support regarding openvela
title: "[HELP] <title>"
labels: ["Community: Question"]
body:
- type: markdown
attributes:
value: |
Hello openvela Community member! Please keep things tidy by putting your post in the proper place:
Asking a question or getting help: use this form.
Reporting a bug: use the [Bug report](./new?assignees=&labels=%F0%9F%91%80+needs+triage%2CType%3A+Bug&projects=&template=001_bug_report.yml&title=%5BBUG%5D+%3Ctitle%3E) form.
Requesting a new feature: use the [Feature request](./new?assignees=&labels=Type%3A+Enhancement&projects=&template=002_feature_request.yml&title=%5BFEATURE%5D+%3Ctitle%3E) form
- type: markdown
attributes:
value: |
### Whether you're a beginner or an experienced developer, openvela Help is here to assist you with all your openvela questions and concerns.
- type: textarea
id: question-description
attributes:
label: Description
description: Explain the background or context of your question. This helps others understand your problem or inquiry better.
validations:
required: true
- type: markdown
attributes:
value: |
### Before You Submit
Please verify that you've followed these steps:
- I have searched [openvela Documentation](../) and didn't find an answer to my question.
- Search [existing issues](./) (including [closed](./?q=is%3Aissue+is%3Aclosed))

1
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@ -0,0 +1 @@
blank_issues_enabled: false

20
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,20 @@
*Note: Please adhere to [Contributing Guidelines](https://github.com/open-vela/docs/blob/dev/CONTRIBUTING.md).*
## Summary
*Update this section with information on why change is necessary,
what it exactly does and how, if new feature shows up, provide
references (dependencies, similar problems and solutions), etc.*
## Impact
*Update this section, where applicable, on how change affects users,
build process, hardware, documentation, security, compatibility, etc.*
## Testing
*Update this section with details on how did you verify the change,
what Host was used for build (OS, CPU, compiler, ..), what Target was
used for verification (arch, board:config, ..), etc. Providing build
and runtime logs from before and after change is highly appreciated.*

14
.github/workflows/checkpatch.yml vendored Normal file
View File

@ -0,0 +1,14 @@
# This is a basic workflow to help you get started with Actions
name: checkpatch
# Controls when the workflow will run
on:
pull_request:
types: [opened, reopened, synchronize]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
checkpatch:
uses: open-vela/public-actions/.github/workflows/checkpatch.yml@dev
secrets: inherit

16
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,16 @@
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
pull_request_target:
types: [opened, reopened, synchronize]
issue_comment:
types: [created]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
ci:
uses: open-vela/public-actions/.github/workflows/ci.yml@dev
secrets: inherit

13
.github/workflows/clang-format.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# This is a basic workflow to help you get started with Actions
name: clang-format
# Controls when the workflow will run
on:
pull_request:
types: [opened, reopened, synchronize]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
clang-format:
uses: open-vela/public-actions/.github/workflows/clang-format.yml@dev

11
.github/workflows/stale.yml vendored Normal file
View File

@ -0,0 +1,11 @@
name: 'Close stale issues and PR'
on:
schedule:
- cron: '30 1 * * *'
workflow_dispatch: # 允许手动触发
jobs:
stale:
uses: open-vela/public-actions/.github/workflows/stale.yml@dev
secrets: inherit

View File

@ -7,7 +7,6 @@ bootstrap_go_package {
],
srcs: [
"frameworkBluetooth.go",
"frameworkBluetoothBin.go",
],
pluginFor: ["soong_build"],
}
@ -23,7 +22,6 @@ frameworkBluetooth_cc_library {
"service/ipc/socket/src/bt_socket_client.c",
"service/ipc/socket/src/bt_socket_adapter.c",
"service/ipc/socket/src/bt_socket_advertiser.c",
"service/ipc/socket/src/bt_socket_avrcp_control.c",
"service/ipc/socket/src/bt_socket_scan.c",
"service/ipc/socket/src/bt_socket_gattc.c",
"service/ipc/socket/src/bt_socket_gatts.c",
@ -33,7 +31,6 @@ frameworkBluetooth_cc_library {
"service/ipc/socket/src/bt_socket_hfp_ag.c",
"service/ipc/socket/src/bt_socket_hfp_hf.c",
"service/ipc/socket/src/bt_socket_hid_device.c",
"service/ipc/socket/src/bt_socket_l2cap.c",
"service/ipc/socket/src/bt_socket_spp.c",
"service/src/manager_service.c",
],
@ -76,13 +73,9 @@ frameworkBluetooth_cc_library {
"//apex_available:platform",
"com.android.btservices",
],
header_libs: [
"kernel_modules_headers_apex",
],
}
frameworkBluetooth_cc_binary {
cc_binary {
name : "bttool",
srcs : [
@ -96,7 +89,6 @@ frameworkBluetooth_cc_binary {
"tools/hfp_ag.c",
"tools/hfp_hf.c",
"tools/hid_device.c",
"tools/l2cap.c",
"tools/spp.c",
"tools/log.c",
"tools/utils.c",
@ -110,7 +102,6 @@ frameworkBluetooth_cc_binary {
local_include_dirs : [
"framework/include",
"service",
"service/common",
"service/utils",
],

View File

@ -35,6 +35,10 @@ if(CONFIG_BLUETOOTH)
${BLUETOOTH_DIR}/framework/api/bt_adapter.c
${BLUETOOTH_DIR}/framework/api/bt_device.c)
if(CONFIG_BLUETOOTH_LE_CS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_cs.c)
endif()
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_a2dp_sink.c)
endif()
@ -190,6 +194,11 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_log.c)
endif()
if(CONFIG_BLUETOOTH_LE_CS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_cs.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_cs.c)
endif()
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/ipc/socket/include)
if (CONFIG_BLUETOOTH_FRAMEWORK_ASYNC)
@ -211,7 +220,7 @@ if(CONFIG_BLUETOOTH)
if(CONFIG_BLUETOOTH_STORAGE_PROPERTY_SUPPORT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/common/storage_property.c)
else()
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/common/bt_storage.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/common/storage.c)
endif()
if(CONFIG_BLUETOOTH_STORAGE_UPDATE)
@ -281,10 +290,6 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_adapter_interface.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_connection_manager.c)
if(CONFIG_BLUETOOTH_SPP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_spp_interface.c)
endif()
if(CONFIG_BLUETOOTH_A2DP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_a2dp_interface.c)
endif()
@ -293,10 +298,6 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_avrcp_interface.c)
endif()
if(CONFIG_BLUETOOTH_HID_DEVICE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_hid_device_interface.c)
endif()
if(CONFIG_BLUETOOTH_HFP_HF)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_hfp_hf_interface.c)
endif()
@ -305,6 +306,14 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_hfp_ag_interface.c)
endif()
if(CONFIG_BLUETOOTH_SPP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_spp_interface.c)
endif()
if(CONFIG_BLUETOOTH_HID_DEVICE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_hid_device_stub.c)
endif()
endif()
if(CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
@ -325,6 +334,10 @@ if(CONFIG_BLUETOOTH)
if(CONFIG_BLUETOOTH_GATT_SERVER)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_gatt_server_interface.c)
endif()
if(CONFIG_BLUETOOTH_LE_CS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_le_cs_interface.c)
endif()
endif()
if(NOT CONFIG_BLUETOOTH_BLE_AUDIO)
@ -351,16 +364,17 @@ if(CONFIG_BLUETOOTH)
list(REMOVE_ITEM CSRCS
${BLUETOOTH_DIR}/service/profiles/system/media_system.c)
else()
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/audio_interface/audio_control.c)
if(CONFIG_AUDIOUTILS_TINYCOMPRESS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/audio_interface/audio_transport.c)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/profiles/audio_interface/include)
endif()
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/audio_interface/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_GATT_CLIENT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/gatt/gattc_event.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/gatt/gattc_service.c)
if(CONFIG_BLUETOOTH_GATT_CLIENT_DEBUG)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/gatt/gattc_debug.c)
endif()
endif()
if(CONFIG_BLUETOOTH_GATT_SERVER)
@ -415,12 +429,6 @@ if(CONFIG_BLUETOOTH)
if(CONFIG_BLUETOOTH_HFP_AG)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/hfp_ag/*.c)
if(CONFIG_PHONE_SERVICE)
list(REMOVE_ITEM APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/system/telephony_interface.c)
list(REMOVE_ITEM APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/hfp_ag/hfp_ag_tele_service.c)
else()
list(REMOVE_ITEM APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/hfp_ag/hfp_ag_tele_phone_service.c)
endif()
list(APPEND CSRCS ${APPEND_FILES})
endif()
@ -503,6 +511,12 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/utils/btsnoop_filter.c)
endif()
if(CONFIG_BLUETOOTH_LE_CS)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/cs/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/profiles/cs)
endif()
if(CONFIG_BLUETOOTH_HCI_FILTER)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/vhal/bt_hci_filter.c)
endif()
@ -519,23 +533,23 @@ if(CONFIG_BLUETOOTH)
if(CONFIG_APP_BT_SAMPLE_CODE)
if(CONFIG_APP_BT_SAMPLE_CODE_BASIC)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/basic/app_bt_gap.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/basic/*.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_ENABLE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/enable/app_bt_gap.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/enable/*.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_DISCOVERY)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/discovery/app_bt_gap.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/discovery/*.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_CREATEBOND)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/createbond/app_bt_gap.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/createbond/*.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_ACCEPTBOND)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/acceptbond/app_bt_gap.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/acceptbond/*.c)
endif()
endif()
@ -567,10 +581,6 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/scan.c)
endif()
if(CONFIG_BLUETOOTH_L2CAP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/l2cap.c)
endif()
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/a2dp_sink.c)
endif()
@ -601,10 +611,7 @@ if(CONFIG_BLUETOOTH)
if(CONFIG_BLUETOOTH_LOG)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/log.c)
endif()
if(CONFIG_BLUETOOTH_DEBUG_TRACE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/debug/bt_trace.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/debug/bt_trace.c)
endif()
if(CONFIG_BLUETOOTH_SPP)
@ -654,9 +661,14 @@ if(CONFIG_BLUETOOTH)
if(CONFIG_BLUETOOTH_STORAGE_UPDATE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/storage_update/storage_tool.c)
endif()
if(CONFIG_BLUETOOTH_LE_CS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/le_cs.c)
endif()
endif()
list(APPEND INCDIR ${BLUETOOTH_DIR}/framework/include)
list(APPEND INCDIR ${BLUETOOTH_DIR}/framework/common)
if(CONFIG_LIB_DBUS_RPMSG_SERVER_CPUNAME OR CONFIG_OFONO)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/dbus/dbus)
@ -703,10 +715,7 @@ if(CONFIG_BLUETOOTH)
endif()
if(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE OR CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/zblue/zblue/port/include/)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/zblue/zblue/subsys/settings/include/settings)
list(APPEND INCDIR
${NUTTX_APPS_DIR}/external/zblue/zblue/port/include/kernel/include)
nuttx_add_dependencies(TARGET libbluetooth DEPENDS zblue)
endif()
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/ipc)
@ -798,7 +807,7 @@ if(CONFIG_BLUETOOTH)
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
4096
8192
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
@ -896,6 +905,24 @@ if(CONFIG_BLUETOOTH)
libbluetooth)
endif()
if(CONFIG_BLUETOOTH_UPGRADE)
nuttx_add_application(
NAME
bt_upgrade
SRCS
${BLUETOOTH_DIR}/tools/storage_transform.c
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
libbluetooth)
endif()
if(CONFIG_BLUETOOTH_STORAGE_UPDATE)
nuttx_add_application(
NAME
@ -922,23 +949,21 @@ if(CONFIG_BLUETOOTH)
target_include_directories(libbluetooth PRIVATE ${CMAKE_CURRENT_LIST_DIR}/feature/include)
set(JIDL_PATHS ${BLUETOOTH_DIR}/feature/jidl/bluetooth.jidl
${BLUETOOTH_DIR}/feature/jidl/bluetooth_bt.jidl)
set(JIDL_OUT_NAMES system_bluetooth system_bluetooth_bt)
set(JIDL_PATHS ${BLUETOOTH_DIR}/feature/jdil/bluetooth.jidl
${BLUETOOTH_DIR}/feature/jdil/bluetooth_bt.jidl)
set(FEATURE_NAMES system_bluetooth system_bluetooth_bt)
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND FEATURE_SRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt_a2dpsink_impl.c)
list(APPEND JIDL_PATHS ${BLUETOOTH_DIR}/feature/jidl/bluetooth_bt_a2dpsink.jidl)
list(APPEND FEATURE_NAMES system_bluetooth_bt_a2dpsink)
list(APPEND JIDL_OUT_NAMES system_bluetooth_bt_a2dpsink)
list(APPEND FEATURE_SRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_a2dpsink_impl.c)
list(APPEND JIDL_PATHS ${BLUETOOTH_DIR}/feature/jdil/bluetooth_a2dpsink.jidl)
list(APPEND FEATURE_NAMES system_bluetooth_a2dpsink)
endif()
if(CONFIG_BLUETOOTH_AVRCP_CONTROL)
list(APPEND FEATURE_SRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt_avrcpcontrol_impl.c)
list(APPEND JIDL_PATHS ${BLUETOOTH_DIR}/feature/jidl/bluetooth_bt_avrcpcontrol.jidl)
list(APPEND FEATURE_NAMES system_bluetooth_bt_avrcpcontrol)
list(APPEND JIDL_OUT_NAMES system_bluetooth_bt_avrcpcontrol)
list(APPEND FEATURE_SRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_avrcpcontrol_impl.c)
list(APPEND JIDL_PATHS ${BLUETOOTH_DIR}/feature/jdil/bluetooth_avrcpcontrol.jidl)
list(APPEND FEATURE_NAMES system_bluetooth_avrcpcontrol)
endif()
nuttx_add_jidl(
@ -950,51 +975,31 @@ if(CONFIG_BLUETOOTH)
${JIDL_PATHS}
FEATURE_NAMES
${FEATURE_NAMES}
JIDL_OUT_NAMES
${JIDL_OUT_NAMES}
OUT_SRC_EXT
c)
elseif(CONFIG_BLUETOOTH_FEATURE_ASYNC)
set(ASYNC_FEATURE_SRCS ${BLUETOOTH_DIR}/feature/feature_async/src/bluetooth_impl.c
${BLUETOOTH_DIR}/feature/feature_async/src/feature_bluetooth_util.c
${BLUETOOTH_DIR}/feature/feature_async/src/bluetooth_ble_impl.c)
target_include_directories(libbluetooth PRIVATE ${CMAKE_CURRENT_LIST_DIR}/feature/feature_async/include)
set(ASYNC_FEATURE_NAMES system_bluetooth system_bluetooth_ble)
include(nuttx_add_jidl)
set(PY_SCRIPT ${FEATURE_TOP}/tools/jidl/jsongensource.py)
set(BINARY_EXT_MODULES_DIR ${CMAKE_BINARY_DIR}/feature/modules/)
set(JIDL_PATHS ${BLUETOOTH_DIR}/feature/feature_async/jidl/bluetooth.jidl)
list(APPEND JIDL_PATHS
${BLUETOOTH_DIR}/feature/feature_async/jidl/bluetooth_ble.jidl)
if(CONFIG_BLUETOOTH_GATT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/btwrap/async/bt_gatt_feature.c)
endif()
nuttx_add_jidl(
TARGET
libbluetooth
FEATURE_SRCS
${ASYNC_FEATURE_SRCS}
JIDL_SCRIPT
${PY_SCRIPT}
JIDL_OUT_DIR
${BINARY_EXT_MODULES_DIR}
JIDLS
${JIDL_PATHS}
FEATURE_NAMES
${ASYNC_FEATURE_NAMES}
OUT_SRC_EXT
c)
else()
endif()
if(CONFIG_BLUETOOTH_DFX)
set(XML_PATHS ${BLUETOOTH_DIR}/dfx/event_bt.xml)
nuttx_add_dfx_event(
TARGET
dfx_bt
XML_PATHS
${XML_PATHS})
endif()
# Add Dependson
nuttx_add_dependencies(TARGET libbluetooth DEPENDS libuv)
@ -1006,9 +1011,6 @@ if(CONFIG_BLUETOOTH)
${BLUETOOTH_DIR}/framework/include)
# Library Configuration
if(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE OR CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
target_link_libraries(libbluetooth PRIVATE zblue_headers)
endif()
target_compile_options(libbluetooth PRIVATE ${CFLAGS})
target_sources(libbluetooth PRIVATE ${CSRCS})
target_include_directories(libbluetooth PRIVATE ${INCDIR})

107
Kconfig
View File

@ -66,15 +66,15 @@ config BLUETOOTH_FRAMEWORK_ASYNC
Enable Bluetooth Framework async API
choice
prompt "select feature api"
prompt "Select feature API"
default BLUETOOTH_FEATURE_NONE
config BLUETOOTH_FEATURE_NONE
bool "not supporting Bluetooth feature API."
bool "Not supporting Bluetooth feature API."
config BLUETOOTH_FEATURE
bool "support Bluetooth synchronization API."
bool "Support Bluetooth synchronization API."
depends on FEATURE_FRAMEWORK
config BLUETOOTH_FEATURE_ASYNC
bool "support Bluetooth asynchronous API."
bool "Support Bluetooth asynchronous API."
depends on FEATURE_FRAMEWORK
depends on BLUETOOTH_FRAMEWORK_ASYNC
endchoice
@ -103,12 +103,6 @@ config BLUETOOTH_BLE_SCAN_FILTER
default n
depends on BLUETOOTH_BLE_SCAN
config BLUETOOTH_HCI_FILTER
bool "Enable Bluetooth HCI filter"
default y
help
Enable Bluetooth HCI filter
config BLUETOOTH_L2CAP
bool "L2CAP dynamic channel support"
default n
@ -163,7 +157,7 @@ config BLUETOOTH_MAX_SAVED_REMOTE_UUIDS_LEN
config BLUETOOTH_MAX_REGISTER_NUM
int "Max register callback nums"
default 6
default 4
endmenu #Core
@ -233,6 +227,11 @@ choice
bool "Not support BLE Stack"
endchoice
config BLUETOOTH_LE_CS
bool "Bluetooth LE Channel Sounding supported"
depends on BLUETOOTH_STACK_LE_ZBLUE
default n
config BLUETOOTH_LE_SCANNER_MAX_NUM
int "LE Scanner max register number"
default 2
@ -245,20 +244,15 @@ config BLUETOOTH_LE_ADVERTISER_MAX_NUM
help
LE Advertiser max register number
config BLUETOOTH_CONNECTION_MANAGER
bool "Bluetooth connection manager support"
default y
config LE_DLF_SUPPORT
bool "Enable LE DLF support"
depends on BLUETOOTH_CONNECTION_MANAGER
default n
endmenu #Bluetooth LE Config
endif #BLUETOOTH_BLE_SUPPORT
choice
prompt "select Bluetooth Storage Method(Unqlite, KVDB)"
prompt "Select Bluetooth Storage Method(Unqlite, KVDB)"
default BLUETOOTH_STORAGE_PROPERTY_SUPPORT
config BLUETOOTH_STORAGE_PROPERTY_SUPPORT
bool "Bluetooth Storage KVDB Property support"
@ -301,13 +295,6 @@ config BLUETOOTH_A2DP_SOURCE
default n
select BLUETOOTH_AVRCP_TARGET
config ZBLUE_A2DP_SBC_MAX_BIT_POOL
int "A2DP sbc codec max bit pool"
default 32
depends on BLUETOOTH_STACK_BREDR_ZBLUE
help
A2DP sbc codec max bit pool 1~53
if BLUETOOTH_A2DP_SOURCE
config BLUETOOTH_A2DP_PEER_PARTIAL_RECONN
bool "Bluetooth A2DP peer partial reconnect support"
@ -315,13 +302,6 @@ config BLUETOOTH_A2DP_PEER_PARTIAL_RECONN
help
Bluetooth A2DP peer partial reconnect support
config ZBLUE_A2DP_SOURCE_BUF_SIZE
int "A2DP source buffer size"
default 660
depends on BLUETOOTH_STACK_BREDR_ZBLUE
help
Buffer size is related to L2CAP TX MTU
endif #BLUETOOTH_A2DP_SOURCE
config BLUETOOTH_A2DP_SINK
@ -385,15 +365,6 @@ config BLUETOOTH_HFP_AG_PRIMARY_SLOT
int "HFP select primary modem slot"
default 0
config BLUETOOTH_HFP_AG_LOCAL_TELEPHONY
bool "Handle telephony AT commands locally instead of notifying upper layer"
default y
help
If enabled, the HFP AG service handles telephony-related AT commands
(AT+CIND, AT+CLCC, AT+COPS, ATA, AT+CHUP, ATD, AT+CHLD) locally by
calling telephony service directly. If disabled, these requests are
forwarded to the upper layer (e.g. AP core) via callback.
endif # BLUETOOTH_HFP_AG
config BLUETOOTH_SCO_CTRL_PATH
@ -650,16 +621,6 @@ config BLUETOOTH_AUDIO_TRANS_ID_HFP_CTRL
int "Bluetooth Audio Transport SCO Ctrl Channel ID"
default 4
config BLUETOOTH_A2DP_SINK_DEVICE
string "Bluetooth A2DP Audio Transport Sink Device"
default "/dev/audio/a2dpsnkp" if MEDIA_SERVER
default "/dev/audio/a2dpsnk"
config BLUETOOTH_A2DP_SOURCE_DEVICE
string "Bluetooth A2DP Audio Transport Source Device"
default "/dev/audio/a2dpsrcc" if MEDIA_SERVER
default "/dev/audio/a2dpsrc"
config BLUETOOTH_LEA_SINK_CTRL_PATH
string "Bluetooth LE Audio Transport Sink Ctrl Path"
default "lea_sink_ctrl"
@ -676,9 +637,25 @@ config BLUETOOTH_LEA_SOURCE_DATA_PATH
string "Bluetooth LE Audio Transport Source Data Path"
default "lea_source_data"
config BLUETOOTH_A2DP_SINK_CTRL_PATH
string "Bluetooth A2DP Audio Transport Sink Ctrl Path"
default "a2dp_sink_ctrl"
config BLUETOOTH_A2DP_SINK_DATA_PATH
string "Bluetooth A2DP Audio Transport Sink Data Path"
default "a2dp_sink_data"
config BLUETOOTH_A2DP_SOURCE_CTRL_PATH
string "Bluetooth A2DP Audio Transport Source Ctrl Path"
default "a2dp_source_ctrl"
config BLUETOOTH_A2DP_SOURCE_DATA_PATH
string "Bluetooth A2DP Audio Transport Source Data Path"
default "a2dp_source_data"
endmenu #Bluetooth Audio Transport config
menuconfig BLUETOOTH_GATT
config BLUETOOTH_GATT
bool "Generic ATT Profile Support(deprecated)"
default y
@ -716,6 +693,14 @@ config GATT_CLIENT_CHAR_PER_SERVICE_MAX
help
The maximum number of characteristics that can be discovered and stored
under a single GATT service when using the ZBLUE stack.
config BLUETOOTH_GATT_CLIENT_DEBUG
bool "Enable GATT Client debug"
default y
help
Enable debug logging for GATT Client service discovery and dump.
Disabling this option reduces code size by removing log strings.
endif # BLUETOOTH_GATT_CLIENT
menuconfig BLUETOOTH_GATT_SERVER
@ -731,32 +716,26 @@ config BLUETOOTH_GATTS_MAX_CONNECTIONS
config BLUETOOTH_GATTS_MAX_ATTRIBUTE_NUM
int "GATT Server max number of attributes contained in a table"
default 10
config BLUETOOTH_GATTS_CACHE_SUPPORT
bool "Enable GATT Server Cache Support"
default y
depends on BLUETOOTH_BLE_SUPPORT
help
Enable internal GATT attribute table hash comparison.
On reconnect, trusted devices may receive Service Changed indications
if attribute changes are detected.
endif # BLUETOOTH_GATT_SERVER
menuconfig BLUETOOTH_SPP
bool "Serial Port Profile (SPP)"
default n
depends on SERIAL_TERMIOS
depends on PSEUDOTERM
if BLUETOOTH_SPP
config BLUETOOTH_SPP_MAX_CONNECTIONS
int "SPP max connections"
default 1
default 8
config BLUETOOTH_SPP_SERVER_MAX_CONNECTIONS
int "SPP Server max connections"
default 8
config BLUETOOTH_SPP_RPMSG_NET
bool "SPP RPMsg net support"
default n
depends on NET_RPMSG
endif #BLUETOOTH_SPP
config BLUETOOTH_HID_DEVICE
@ -821,7 +800,7 @@ config BLUETOOTH_DUMPBUFFER
config BLUETOOTH_DFX
bool "Enable Bluetooth DFX"
default y
depends on DFX
depends on DFX_EVENT
help
Enable Bluetooth DFX

10
LICENSE Normal file
View File

@ -0,0 +1,10 @@
Copyright (C) 2024 Xiaomi Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -17,7 +17,7 @@
ifeq ($(CONFIG_BLUETOOTH), y)
CONFIGURED_APPS += $(APPDIR)/frameworks/connectivity/bluetooth
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/framework/include
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/framework/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/include
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/include
endif

View File

@ -22,7 +22,9 @@ CSRCS += framework/common/*.c
CSRCS += framework/api/bluetooth.c
CSRCS += framework/api/bt_adapter.c
CSRCS += framework/api/bt_device.c
ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += framework/api/bt_cs.c
endif #CONFIG_BLUETOOTH_LE_CS
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += framework/api/bt_a2dp_sink.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
@ -160,6 +162,11 @@ CSRCS += framework/socket/bt_trace.c
CSRCS += service/ipc/socket/src/bt_socket_log.c
endif #CONFIG_BLUETOOTH_BLE_AUDIO
ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += framework/socket/bt_cs.c
CSRCS += service/ipc/socket/src/bt_socket_cs.c
endif #CONFIG_BLUETOOTH_LE_CS
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/ipc/socket/include
ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK_ASYNC), y)
CSRCS += framework/socket/async/*.c
@ -177,7 +184,7 @@ endif #CONFIG_BLUETOOTH_CONNECTION_MANAGER
ifeq ($(CONFIG_BLUETOOTH_STORAGE_PROPERTY_SUPPORT), y)
CSRCS += service/common/storage_property.c
else
CSRCS += service/common/bt_storage.c
CSRCS += service/common/storage.c
endif
ifeq ($(CONFIG_BLUETOOTH_STORAGE_UPDATE), y)
@ -189,7 +196,7 @@ ifeq ($(CONFIG_BLUETOOTH_DEBUG_MEMORY),y)
CSRCS += debug/bt_memory.c
endif
ifeq ($(CONFIG_BLUETOOTH_DEBUG_TRACE), y)
ifeq ($(CONFIG_BLUETOOTH_LOG), y)
CSRCS += service/debug/bt_trace.c
endif
@ -230,9 +237,6 @@ ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE)$(CONFIG_BLUETOOTH_STACK_LE_ZBLUE),)
ifeq ($(CONFIG_BLUETOOTH_CONNECTION_MANAGER), y)
CSRCS += service/stacks/zephyr/sal_connection_manager.c
endif
ifeq ($(CONFIG_BLUETOOTH_SPP), y)
CSRCS += service/stacks/zephyr/sal_spp_interface.c
endif #CONFIG_BLUETOOTH_SPP
ifeq ($(CONFIG_BLUETOOTH_A2DP), y)
CSRCS += service/stacks/zephyr/sal_a2dp_interface.c
endif #CONFIG_BLUETOOTH_A2DP
@ -240,17 +244,6 @@ ifneq ($(CONFIG_BLUETOOTH_AVRCP_CONTROL)$(CONFIG_BLUETOOTH_AVRCP_TARGET),)
CSRCS += service/stacks/zephyr/sal_avrcp_interface.c
endif #CONFIG_BLUETOOTH_AVRCP_CONTROL/CONFIG_BLUETOOTH_AVRCP_TARGET
ifeq ($(CONFIG_BLUETOOTH_HFP_HF), y)
CSRCS += service/stacks/zephyr/sal_hfp_hf_interface.c
endif #CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_BLUETOOTH_HFP_AG), y)
CSRCS += service/stacks/zephyr/sal_hfp_ag_interface.c
endif #CONFIG_BLUETOOTH_HFP_AG
ifeq ($(CONFIG_BLUETOOTH_HID_DEVICE), y)
CSRCS += service/stacks/zephyr/sal_hid_device_interface.c
endif #CONFIG_BLUETOOTH_HID_DEVICE
ifeq ($(CONFIG_BLUETOOTH_STACK_LE_ZBLUE), y)
CSRCS += service/stacks/zephyr/sal_adapter_le_interface.c
ifeq ($(CONFIG_BLUETOOTH_BLE_ADV), y)
@ -265,6 +258,9 @@ endif #CONFIG_BLUETOOTH_GATT_CLIENT
ifeq ($(CONFIG_BLUETOOTH_GATT_SERVER), y)
CSRCS += service/stacks/zephyr/sal_gatt_server_interface.c
endif #CONFIG_BLUETOOTH_GATT_SERVER
ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += service/stacks/zephyr/sal_le_cs_interface.c
endif #CONFIG_BLUETOOTH_LE_CS
endif #CONFIG_BLUETOOTH_STACK_LE_ZBLUE
endif
@ -279,11 +275,7 @@ endif #CONFIG_BLUETOOTH_A2DP
ifeq ($(findstring y, $(CONFIG_BLUETOOTH_A2DP)_$(CONFIG_BLUETOOTH_HFP_AG)_$(CONFIG_BLUETOOTH_HFP_HF)_$(CONFIG_BLUETOOTH_BLE_AUDIO)), )
CSRCS := $(filter-out $(wildcard service/profiles/system/media_system.c),$(wildcard $(CSRCS)))
else
CSRCS += service/profiles/audio_interface/audio_control.c
ifeq ($(CONFIG_AUDIOUTILS_TINYCOMPRESS), y)
CSRCS += service/profiles/audio_interface/audio_transport.c
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/service/profiles/audio_interface/include
endif #CONFIG_AUDIOUTILS_TINYCOMPRESS
CSRCS += service/profiles/audio_interface/*.c
endif #CONFIG_BLUETOOTH_A2DP/CONFIG_BLUETOOTH_HFP_AG/CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_MICO_MEDIA_MAIN_PLAYER),y)
CFLAGS += ${INCDIR_PREFIX}${TOPDIR}/../vendor/xiaomi/miai/mediaplayer/include
@ -291,6 +283,9 @@ endif #CONFIG_MICO_MEDIA_MAIN_PLAYER
ifeq ($(CONFIG_BLUETOOTH_GATT_CLIENT), y)
CSRCS += service/profiles/gatt/gattc_event.c
CSRCS += service/profiles/gatt/gattc_service.c
ifeq ($(CONFIG_BLUETOOTH_GATT_CLIENT_DEBUG), y)
CSRCS += service/profiles/gatt/gattc_debug.c
endif
endif #CONFIG_BLUETOOTH_GATT_CLIENT
ifeq ($(CONFIG_BLUETOOTH_GATT_SERVER), y)
CSRCS += service/profiles/gatt/gatts_event.c
@ -328,11 +323,6 @@ endif #CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_BLUETOOTH_HFP_AG), y)
CSRCS += service/profiles/hfp_ag/*.c
ifeq ($(CONFIG_PHONE_SERVICE), y)
CSRCS := $(filter-out $(wildcard service/profiles/system/telephony_interface.c) $(wildcard service/profiles/hfp_ag/hfp_ag_tele_service.c), $(wildcard $(CSRCS)))
else
CSRCS := $(filter-out $(wildcard service/profiles/hfp_ag/hfp_ag_tele_phone_service.c),$(wildcard $(CSRCS)))
endif
endif #CONFIG_BLUETOOTH_HFP_AG
ifeq ($(CONFIG_BLUETOOTH_SPP), y)
@ -392,6 +382,11 @@ CSRCS += service/utils/btsnoop_writer.c
CSRCS += service/utils/btsnoop_filter.c
endif #CONFIG_BLUETOOTH_LOG
ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += service/profiles/cs/*.c
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/cs
endif #CONFIG_BLUETOOTH_LE_CS
ifeq ($(CONFIG_BLUETOOTH_HCI_FILTER), y)
CSRCS += service/vhal/bt_hci_filter.c
endif
@ -444,9 +439,6 @@ endif
ifeq ($(CONFIG_BLUETOOTH_BLE_SCAN), y)
CSRCS += tools/scan.c
endif
ifeq ($(CONFIG_BLUETOOTH_L2CAP), y)
CSRCS += tools/l2cap.c
endif #CONFIG_BLUETOOTH_L2CAP
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += tools/a2dp_sink.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
@ -517,10 +509,15 @@ ifeq ($(CONFIG_BLUETOOTH_STORAGE_UPDATE), y)
CSRCS += tools/storage_update/storage_tool.c
endif #CONFIG_BLUETOOTH_STORAGE_UPDATE
ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += tools/le_cs.c
endif
endif
# framework/service/stack/tools dependence
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/framework/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/framework/common
ifneq ($(CONFIG_LIB_DBUS_RPMSG_SERVER_CPUNAME)$(CONFIG_OFONO),)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/dbus/dbus
@ -552,6 +549,7 @@ ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE)$(CONFIG_BLUETOOTH_STACK_LE_ZBLUE),)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/port/include/
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/subsys/bluetooth/host
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/subsys/settings/include/settings
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/subsys/bluetooth
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/port/include/kernel/include
endif
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/ipc
@ -656,7 +654,6 @@ NOEXPORTSRCS = $(ASRCS)$(CSRCS)$(CXXSRCS)$(MAINSRC)
ifeq ($(CONFIG_BLUETOOTH_FEATURE),y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/feature/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/runtimes/feature/include
CSRCS += feature/src/system_bluetooth.c
CSRCS += feature/src/system_bluetooth_impl.c
@ -674,13 +671,6 @@ CSRCS += feature/src/system_bluetooth_bt_avrcpcontrol.c
CSRCS += feature/src/system_bluetooth_bt_avrcpcontrol_impl.c
endif
ifneq ($(CONFIG_BLUETOOTH_DFX),)
DFX_XML=$(APPDIR)/frameworks/system/dfx/src/onetrack/xml
BLUETOOTH_XML=$(APPDIR)/frameworks/connectivity/bluetooth/dfx/event_bt.xml
context::
@cp $(BLUETOOTH_XML) $(DFX_XML)
endif
depend::
$(APPDIR)/../prebuilts/tools/rust/bin/jidl/jidl_gen_cpp \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth.jidl --out-dir \
@ -694,9 +684,9 @@ ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
$(APPDIR)/frameworks/connectivity/bluetooth/feature/src --header system_bluetooth_bt_a2dpsink.h --source system_bluetooth_bt_a2dpsink.c
endif
ifeq ($(CONFIG_BLUETOOTH_AVRCP_CONTROL), y)
$(APPDIR)/../prebuilts/tools/rust/bin/jidl/jidl_gen_cpp \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth_bt_avrcpcontrol.jidl --out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/src --header system_bluetooth_bt_avrcpcontrol.h --source system_bluetooth_bt_avrcpcontrol.c
@python3 $(APPDIR)/frameworks/runtimes/feature/tools/jidl/jsongensource.py \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth_bt_avrcpcontrol.jidl -out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/src -header system_bluetooth_bt_avrcpcontrol.h -source system_bluetooth_bt_avrcpcontrol.c
endif
else ifeq ($(CONFIG_BLUETOOTH_FEATURE_ASYNC), y)
include $(APPDIR)/frameworks/runtimes/feature/Make.defs

View File

@ -15,6 +15,7 @@
***************************************************************************/
#include "bt_sched_trace.h"
#include <inttypes.h>
#include <stdatomic.h>
#include <stdio.h>
#include <string.h>
@ -23,6 +24,9 @@
#include "utils/log.h"
#ifndef CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE
#define CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE 64
#endif
#define DUMP_THRESHOLD 256
typedef struct {
@ -64,7 +68,7 @@ void bt_note_stop(void)
bt_latency_record_t* p = &trace_manager->buffer[trace_manager->tail % CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE];
written += snprintf(log_buf + written, sizeof(log_buf) - written,
"[TAG=%s][TS=%lu][LAT=%uus]\n",
"[TAG=%s][TS=%" PRIu64 "][LAT=%" PRIu32 "us]\n",
p->tag, p->timestamp, p->latency_us);
trace_manager->tail = (trace_manager->tail + 1) % CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE;
written = written % DUMP_THRESHOLD;

View File

@ -96,181 +96,75 @@
"%s:%s", "blePairError", reason); \
} while (0)
// spp
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_SPP)
#define BT_DFX_SEND_SPP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_SPP_EVENT(...)
#endif
#define BT_DFX_SPP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btSppConnectError: %s", reason); \
BT_DFX_SEND_SPP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_RFCOMM, BT_DFXC_SPP_CONN), \
"%s:%s", "btSppConnectError", reason); \
} while (0)
#define BT_DFX_SPP_DISCONN_ERROR(reason, scn, port, role) \
do { \
BT_LOGE("BT_DFX: btSppDisconnected: %s, scn: %d, port: %d, role: %d", \
reason, scn, port, role); \
BT_DFX_SEND_SPP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_RFCOMM, BT_DFXC_SPP_DISCONN), \
"%s:%s,%s:%d,%s:%d,%s:%s", "btSppDisconnected", reason, "scn", scn, \
"port", port, "role", role); \
} while (0)
// a2dp
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_A2DP)
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_BREDR_SUPPORT)
#define BT_DFX_SEND_A2DP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_A2DP_EVENT(...)
#endif
#define BT_DFX_A2DP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btA2dpConnectError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_CONN), \
"%s:%s", "btA2dpConnectError", reason); \
} while (0)
#define BT_DFX_A2DP_MEDIA_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btA2dpMediaError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_MEDIA), \
"%s:%s", "btA2dpMediaError", reason); \
} while (0)
#define BT_DFX_A2DP_OFFLOAD_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btA2dpOffloadError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_OFFLOAD), \
"%s:%s", "btA2dpOffloadError", reason); \
} while (0)
// avrcp
#if defined(CONFIG_BLUETOOTH_DFX) && (defined(CONFIG_BLUETOOTH_AVRCP_CONTROL) || defined(CONFIG_BLUETOOTH_AVRCP_TARGET))
#define BT_DFX_SEND_AVRCP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_AVRCP_EVENT(...)
#endif
#define BT_DFX_AVRCP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btAvrcpConnectError: %s", reason); \
BT_DFX_SEND_AVRCP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_AVRCP, BT_DFXC_AVRCP_CONN), \
"%s:%s", "btAvrcpConnectError", reason); \
} while (0)
#define BT_DFX_AVRCP_CTRL_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btAvrcpCtrlError: %s", reason); \
BT_DFX_SEND_AVRCP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_AVRCP, BT_DFXC_AVRCP_CTRL), \
"%s:%s", "btAvrcpCtrlError", reason); \
} while (0)
#define BT_DFX_AVRCP_VOL_ERROR(reason) \
#define BT_DFX_A2DP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btAvrcpVolError: %s", reason); \
BT_DFX_SEND_AVRCP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_AVRCP, BT_DFXC_AVRCP_VOL), \
"%s:%s", "btAvrcpVolError", reason); \
BT_LOGE("BT_DFX: a2dpConnError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_CONN), \
"%s:%s", "a2dpConnError", reason); \
} while (0)
#define BT_DFX_A2DP_OFFLOAD_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: a2dpOffloadError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_OFFLOAD), \
"%s:%s", "a2dpOffloadError", reason); \
} while (0)
// hfp
#if defined(CONFIG_BLUETOOTH_DFX) && (defined(CONFIG_BLUETOOTH_HFP_HF) || defined(CONFIG_BLUETOOTH_HFP_AG))
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_BREDR_SUPPORT)
#define BT_DFX_SEND_HFP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_HFP_EVENT(...)
#endif
#define BT_DFX_HFP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpConnectError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_CONN), \
"%s:%s", "btHfpConnectError", reason); \
} while (0)
#define BT_DFX_HFP_SCO_CONN_ERROR(reason) \
#define BT_DFX_HFP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpScoConnectError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_SCO_CONN), \
"%s:%s", "btHfpScoConnectError", reason); \
BT_LOGE("BT_DFX: hfpConnError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_CONN), \
"%s:%s", "hfpConnError", reason); \
} while (0)
#define BT_DFX_HFP_VOL_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpVolError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_VOL), \
"%s:%s", "btHfpVolError", reason); \
#define BT_DFX_HFP_OFFLOAD_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: hfpOffloadError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_OFFLOAD), \
"%s:%s", "hfpOffloadError", reason); \
} while (0)
#define BT_DFX_HFP_MEDIA_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpMediaError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_MEDIA), \
"%s:%s", "btHfpMediaError", reason); \
} while (0)
#define BT_DFX_HFP_OFFLOAD_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpOffloadError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_OFFLOAD), \
"%s:%s", "btHfpOffloadError", reason); \
} while (0)
// hid
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_HID_DEVICE)
#define BT_DFX_SEND_HID_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_HID_EVENT(...)
#endif
#define BT_DFX_HID_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHidConnectError: %s", reason); \
BT_DFX_SEND_HID_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HID, BT_DFXC_HID_CONN), \
"%s:%s", "btHidConnectError", reason); \
} while (0)
// others
// open (enable)
#if defined(CONFIG_BLUETOOTH_DFX)
#define BT_DFX_SEND_OTHERS_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_OTHERS_EVENT(...)
#endif
#define BT_DFX_SOCKET_ERROR(reason, port) \
do { \
BT_LOGE("BT_DFX: btSocketError: %s, port: %d", reason, port); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_SOCKET), \
"%s:%s,%s:%d", "btSocketError", reason, "port", port); \
#define BT_DFX_OPEN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: openError: %s", reason); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_OPEN), \
"%s:%s", "openError", reason); \
} while (0)
#define BT_DFX_IPC_CONN_ERROR(type, reason) \
do { \
BT_LOGE("BT_DFX: btIpcConnectError: %s, reason: %s", type, reason); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_IPC_CONN), \
"%s:%s,%s:%s", "btIpcConnectError", type, "reason", reason); \
// spp / ipc
#define BT_DFX_SPP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: sppConnError: %s", reason); \
BT_DFX_SEND_BR_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_RFCOMM, 0), \
"%s:%s", "sppConnError", reason); \
} while (0)
#define BT_DFX_IPC_ALLOC_ERROR(reason, packet_code) \
do { \
BT_LOGE("BT_DFX: btIpcAllocError: %s, packetCode: %" PRIu32, reason, packet_code); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_IPC_ALLOC), \
"%s:%s,%s:%" PRIu32 "", "btIpcAllocError", reason, "packetCode", packet_code); \
#define BT_DFX_IPC_CONN_ERROR(reason, extra) \
do { \
BT_LOGE("BT_DFX: ipcConnError: %s %s", reason, extra); \
BT_DFX_SEND_BR_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_RFCOMM, 0), \
"%s:%s:%s", "ipcConnError", reason, extra); \
} while (0)
#define BT_DFX_DRIVER_ERROR(type, name, reason) \
do { \
BT_LOGE("BT_DFX: btDriverError: %s, name: %s, reason: %s", type, name, reason); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_DRIVER), \
"%s:%s,%s:%s,%s:%s", "btDriverError", type, "name", name, "reason", reason); \
} while (0)
#define BT_DFX_OPEN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btOpenError: %s", reason); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_OPEN), \
"%s:%s", "btOpenError", reason); \
} while (0)
#endif /* _BT_DFX_H_ */
#endif /* _BT_DFX_H_ */

View File

@ -17,7 +17,7 @@
#define _BT_DFX_EVENT_H_
// vela bluetooth event id
#define BT_DFX_BASE_VELA_BLUETOOTH (961020000)
#define BT_DFX_BASE_VELA_BLUETOOTH (923020000)
// event group
#define BT_DFXG_BR_GAP (0)
@ -47,40 +47,16 @@
#define BT_DFXC_LE_GAP_DISCONN (110)
#define BT_DFXC_LE_GAP_PAIR (200)
// group: BT_DFXG_RFCOMM
#define BT_DFXC_SPP_CONN (0)
#define BT_DFXC_SPP_DISCONN (10)
// group: BT_DFXG_A2DP
#define BT_DFXC_A2DP_CONN (0)
#define BT_DFXC_A2DP_MEDIA (10)
#define BT_DFXC_A2DP_OFFLOAD (20)
// group: BT_DFXG_AVRCP
#define BT_DFXC_AVRCP_CONN (0)
#define BT_DFXC_AVRCP_CTRL (10)
#define BT_DFXC_AVRCP_VOL (20)
#define BT_DFXC_A2DP_OFFLOAD (100)
// group: BT_DFXG_HFP
#define BT_DFXC_HFP_CONN (0)
#define BT_DFXC_HFP_SCO_CONN (10)
#define BT_DFXC_HFP_VOL (20)
#define BT_DFXC_HFP_MEDIA (30)
#define BT_DFXC_HFP_OFFLOAD (40)
// group: BT_DFXG_HID
#define BT_DFXC_HID_CONN (0)
// group: BT_DFXG_MESH
// group: BT_DFXG_CHANNEL_SOUNDING
#define BT_DFXC_HFP_OFFLOAD (100)
// group: BT_DFXG_OTHERS
#define BT_DFXC_SOCKET (0)
#define BT_DFXC_IPC_CONN (10)
#define BT_DFXC_IPC_ALLOC (20)
#define BT_DFXC_DRIVER (100)
#define BT_DFXC_OPEN (200)
#define BT_DFXC_OPEN (0)
#define BT_DFX_BUILD_CODE(group, subcode) ((BT_DFX_BASE_VELA_BLUETOOTH) + (group) + (subcode))

View File

@ -24,53 +24,16 @@
#define BT_DFXE_CONN_FAILED_TO_BE_ESTABLISHED "btConnFailedToBeEstablished"
#define BT_DFXE_SCANNER_EXCEED_MAX_NUM "btScannerExceedMaxNum"
#define BT_DFXE_LE_ENABLE_FAIL "btLeEnableFail"
#define BT_DFXE_BR_ENABLE_FAIL "btBrEnableFail"
#define BT_DFXE_A2DP_CONN_TIMEOUT "btA2dpConnTimeout"
#define BT_DFXE_OFFLOAD_START_TIMEOUT "btOffloadStartTimeout"
#define BT_DFXE_OFFLOAD_HCI_UNSPECIFIED_ERROR "btOffloadHciUnspecifiedError"
#define BT_DFXE_HFP_HF_CONN_TIMEOUT "btHfpHfConnTimeout"
#define BT_DFXE_HFP_HF_CONN_RETRY_FAIL "btHfpHfConnRetryFail"
#define BT_DFXE_SPP_CONN_FAIL "btSppConnFail"
#define BT_DFXE_SPP_NOT_STARTUP "btSppNotStartup"
#define BT_DFXE_SPP_SCN_ALLOC_FAIL "btSppScnAllocFail"
#define BT_DFXE_SPP_NO_RESOURCES "btSppNoResources"
#define BT_DFXE_A2DP_CONN_TIMEOUT "btA2dpConnTimeout"
#define BT_DFXE_SET_A2DP_AVAILABLE_FAIL "btSetA2dpAvailableFail"
#define BT_DFXE_GET_A2DP_AVAILABLE_FAIL "btGetA2dpAvailableFail"
#define BT_DFXE_OFFLOAD_START_TIMEOUT "btOffloadStartTimeout"
#define BT_DFXE_OFFLOAD_HCI_UNSPECIFIED_ERROR "btOffloadHciUnspecifiedError"
#define BT_DFXE_GET_MEDIA_VOLUME_RANGE_FAIL "btGetMediaVolumeRangeFail"
#define BT_DFXE_SET_MEDIA_VOLUME_FAIL "btSetMediaVolumeFail"
#define BT_DFXE_SET_UI_VOLUME_FAIL "btSetUiVolumeFail"
#define BT_DFXE_MEDIA_PLAYER_CREATE_FAIL "btMediaPlayerCreateFail"
#define BT_DFXE_GET_STREAM_VOLUME_FAIL "btGetStreamVolumeFail"
#define BT_DFXE_MEDIA_SESSION_OPEN_FAIL "btMediaSessionOpenFail"
#define BT_DFXE_MEDIA_SESSION_SET_EVENT_CB_FAIL "btMediaSessionSetEventCbFail"
#define BT_DFXE_MEDIA_SESSION_START_FAIL "btMediaSessionStartFail"
#define BT_DFXE_MEDIA_SESSION_STOP_FAIL "btMediaSessionStopFail"
#define BT_DFXE_MEDIA_SESSION_PAUSE_FAIL "btMediaSessionPauseFail"
#define BT_DFXE_MEDIA_SESSION_NEXT_SONG_FAIL "btMediaSessionNextSongFail"
#define BT_DFXE_MEDIA_SESSION_PREV_SONG_FAIL "btMediaSessionPrevSongFail"
#define BT_DFXE_HFP_AG_CONN_TIMEOUT "btHfpAgConnTimeout"
#define BT_DFXE_HFP_AG_CONN_RETRY_FAIL "btHfpAgConnRetryFail"
#define BT_DFXE_HFP_HF_CONN_TIMEOUT "btHfpHfConnTimeout"
#define BT_DFXE_HFP_HF_CONN_RETRY_FAIL "btHfpHfConnRetryFail"
#define BT_DFXE_SET_VOICE_CALL_VOLUME_FAIL "btSetVoiceCallVolumeFail"
#define BT_DFXE_GET_VOICE_CALL_VOLUME_FAIL "btGetVoiceCallVolumeFail"
#define BT_DFXE_MEDIA_POLICY_SUBSCRIBE_FAIL "btMediaPolicySubscribeFail"
#define BT_DFXE_SET_HFP_SAMPLERATE_FAIL "btSetHfpSamplerateFail"
#define BT_DFXE_SET_SCO_AVAILABLE_FAIL "btSetScoAvailableFail"
#define BT_DFXE_SET_SCO_UNAVAILABLE_FAIL "btSetScoUnavailableFail"
#define BT_DFXE_SET_ANC_ENABLE_FAIL "btSetAncEnableFail"
#define BT_DFXE_HID_CONNECT_BUSY "btHidConnectBusy"
#define BT_DFXE_CLIENT_CONNECT_FAIL "btClientConnectFail"
#define BT_DFXE_ASYNC_CLIENT_CONN_FAIL "btAsyncClientConnectFail"
#define BT_DFXE_FILE_DESCRIPTOR_ERROR "btFileDescriptorError"
#define BT_DFXE_SPP_CONN_FAIL "btSppConnFail"
#define BT_DFXE_CLIENT_MSG_ALLOC_FAIL "btClientMsgAllocFail"
#define BT_DFXE_SERVER_CACHE_ALLOC_FAIL "btServerCacheAllocFail"
#define BT_DFXE_OPEN_HCI_UART_FAIL "btOpenHciUartFail"
#define BT_DFXE_LE_ENABLE_FAIL "btLeEnableFail"
#define BT_DFXE_BR_ENABLE_FAIL "btBrEnableFail"
#endif /* _BT_DFX_REASON_H_ */

View File

@ -191,8 +191,8 @@ bt_status_t get_valid_uuid128(uint8_t uuid128[16], const char* in)
char* bt_uuid_to_feature_string(const bt_uuid_t* bt_uuid)
{
char uuid[40] = { 0 };
bt_uuid_to_string(bt_uuid, uuid, 40);
char uuid[BT_UUID_STR_LENGTH] = { 0 };
bt_uuid_to_string(bt_uuid, uuid, BT_UUID_STR_LENGTH);
return StringToFtString(uuid);
}
#endif

View File

@ -424,7 +424,7 @@ FtString system_bluetooth_bt_wrap_getDeviceName(FeatureInstanceHandle feature, A
return StringToFtString(name);
}
FtUint32 system_bluetooth_bt_wrap_getDeviceClass(FeatureInstanceHandle feature, AppendData append_data, FtString deviceId)
unsigned int system_bluetooth_bt_wrap_getDeviceClass(FeatureInstanceHandle feature, AppendData append_data, FtString deviceId)
{
bt_address_t addr;
if (bt_addr_str2ba(deviceId, &addr) < 0) {

View File

@ -85,7 +85,7 @@ void system_bluetooth_wrap_openAdapter(FeatureInstanceHandle feature, AppendData
void system_bluetooth_wrap_closeAdapter(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_CloseAdapterParams* params)
{
bt_status_t status = bt_adapter_disable_safe(feature_bluetooth_get_bt_ins(feature));
bt_status_t status = bt_adapter_disable(feature_bluetooth_get_bt_ins(feature));
if (status == BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke success closeAdapter callback failed!");

View File

@ -44,7 +44,7 @@ bt_status_t BTSYMBOLS(bt_adapter_disable)(bt_instance_t* ins)
bt_status_t BTSYMBOLS(bt_adapter_disable_safe)(bt_instance_t* ins)
{
return adapter_disable_safe(SYS_SET_BT_ALL);
return adapter_disable(SYS_SET_BT_ALL);
}
bt_status_t BTSYMBOLS(bt_adapter_enable_le)(bt_instance_t* ins)
@ -82,7 +82,7 @@ bt_status_t BTSYMBOLS(bt_adapter_start_limited_discovery)(bt_instance_t* ins, ui
return adapter_start_discovery(timeout, true);
}
bt_status_t BTSYMBOLS(bt_adapter_set_debug_mode)(bt_instance_t* ins, bt_debug_mode_t mode, uint8_t operation)
bt_status_t BTSYMBOLS(bt_adapter_set_debug_mode)(bt_instance_t* ins, uint8_t mode, uint8_t operation)
{
return adapter_set_debug_mode(mode, operation);
}
@ -208,12 +208,7 @@ bt_status_t BTSYMBOLS(bt_adapter_le_enable_key_derivation)(bt_instance_t* ins,
bt_status_t BTSYMBOLS(bt_adapter_le_add_whitelist)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_add_whitelist_with_type(addr, BT_LE_ADDR_TYPE_UNKNOWN);
}
bt_status_t BTSYMBOLS(bt_adapter_le_add_whitelist_with_type)(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t type)
{
return adapter_le_add_whitelist_with_type(addr, type);
return adapter_le_add_whitelist(addr);
}
bt_status_t BTSYMBOLS(bt_adapter_le_remove_whitelist)(bt_instance_t* ins, bt_address_t* addr)

View File

@ -75,12 +75,12 @@ bt_status_t BTSYMBOLS(bt_avrcp_control_get_playback_state)(bt_instance_t* ins, b
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->avrcp_control_get_playback_state(addr);
return profile->get_playback_state(addr);
}
bt_status_t BTSYMBOLS(bt_avrcp_control_register_notification)(bt_instance_t* ins, bt_address_t* addr, uint8_t event, uint32_t interval)
bt_status_t BTSYMBOLS(bt_avrcp_control_register_notification)(bt_instance_t* ins, bt_address_t* addr, avrcp_notification_event_t event, uint32_t interval)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->avrcp_control_register_notification(addr, event, interval);
}
}

75
framework/api/bt_cs.c Normal file
View File

@ -0,0 +1,75 @@
/****************************************************************************
* Copyright (C) 2025 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include "bt_cs.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "cs_service.h"
#include "service_manager.h"
#include "utils/log.h"
#ifdef CONFIG_BLUETOOTH_LE_CS
static bt_cs_interface_t* get_profile_service(void)
{
return (bt_cs_interface_t*)service_manager_get_profile(PROFILE_CS);
}
void* BTSYMBOLS(bt_cs_register_callbacks)(bt_instance_t* ins, const cs_callbacks_t* callbacks)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_cs_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_cs_start_distance_measurement)(bt_instance_t* ins, bt_distance_measurement_params_t* params)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->start_distance_measurement(params);
}
bt_status_t BTSYMBOLS(bt_cs_stop_distance_measurement)(bt_instance_t* ins, bt_address_t* addr, uint8_t method, bool timeout)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->stop_distance_measurement(addr, method, timeout);
}
bt_status_t BTSYMBOLS(bt_cs_set_config)(bt_instance_t* ins, bt_address_t* addr, const bt_cs_set_params_t* params)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->set_config(addr, params);
}
#ifdef CONFIG_BT_CS_RAS_TEST
bt_status_t BTSYMBOLS(bt_cs_test)(bt_instance_t* ins, void* data, uint16_t len)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->cs_test(data, len);
}
#endif /* CONFIG_BT_CS_RAS_TEST */
#endif /* CONFIG_BLUETOOTH_LE_CS */

View File

@ -21,7 +21,6 @@
#include "bt_addr.h"
#include "bt_device.h"
#include "bt_internal.h"
#include "connection_manager.h"
#include "device.h"
bt_status_t BTSYMBOLS(bt_device_get_identity_address)(bt_instance_t* ins, bt_address_t* bd_addr, bt_address_t* id_addr)
@ -31,7 +30,11 @@ bt_status_t BTSYMBOLS(bt_device_get_identity_address)(bt_instance_t* ins, bt_add
ble_addr_type_t BTSYMBOLS(bt_device_get_address_type)(bt_instance_t* ins, bt_address_t* addr)
{
#ifdef CONFIG_BLUETOOTH_BLE_SUPPORT
return adapter_get_le_remote_address_type(addr);
#else
return 0;
#endif
}
bt_device_type_t BTSYMBOLS(bt_device_get_device_type)(bt_instance_t* ins, bt_address_t* addr)
@ -109,24 +112,6 @@ bt_status_t BTSYMBOLS(bt_device_disconnect)(bt_instance_t* ins, bt_address_t* ad
return adapter_disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_device_background_connect)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_device_connect(addr, transport);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}
bt_status_t BTSYMBOLS(bt_device_background_disconnect)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_device_disconnect(addr, transport);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}
bt_status_t BTSYMBOLS(bt_device_connect_le)(bt_instance_t* ins,
bt_address_t* addr,
ble_addr_type_t type,
@ -219,22 +204,4 @@ bt_status_t BTSYMBOLS(bt_device_set_le_sc_remote_oob_data)(bt_instance_t* ins, b
bt_status_t BTSYMBOLS(bt_device_get_le_sc_local_oob_data)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_get_local_oob_data(addr);
}
bt_status_t BTSYMBOLS(bt_device_enable_enhanced_mode)(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_enable_enhanced_mode(addr, mode);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}
bt_status_t BTSYMBOLS(bt_device_disable_enhanced_mode)(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_disable_enhanced_mode(addr, mode);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}

View File

@ -98,13 +98,6 @@ bt_status_t BTSYMBOLS(bt_gattc_write_without_response)(gattc_handle_t conn_handl
return profile->write_without_response(conn_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gattc_write_with_signed)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gattc_interface_t* profile = get_profile_service();
return profile->write_signed(conn_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gattc_subscribe)(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value)
{
gattc_interface_t* profile = get_profile_service();

View File

@ -152,6 +152,13 @@ bt_status_t BTSYMBOLS(bt_hfp_ag_send_at_command)(bt_instance_t* ins, bt_address_
return profile->send_at_command(addr, at_command);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_send_vendor_specific_at_command)(bt_instance_t* ins, bt_address_t* addr, const char* command, const char* value)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->send_vendor_specific_at_command(addr, command, value);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_send_clcc_response)(bt_instance_t* ins, bt_address_t* addr,
uint32_t index, hfp_call_direction_t dir, hfp_ag_call_state_t call, hfp_call_mode_t mode,
hfp_call_mpty_type_t mpty, hfp_call_addrtype_t type, const char* number)
@ -161,13 +168,6 @@ bt_status_t BTSYMBOLS(bt_hfp_ag_send_clcc_response)(bt_instance_t* ins, bt_addre
return profile->send_clcc_response(addr, index, dir, call, mode, mpty, type, number);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_send_vendor_specific_at_command)(bt_instance_t* ins, bt_address_t* addr, const char* command, const char* value)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->send_vendor_specific_at_command(addr, command, value);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_send_cind_response)(bt_instance_t* ins, bt_address_t* addr,
hfp_network_state_t network, hfp_call_t call, hfp_callheld_t call_held, hfp_callsetup_t call_setup,
uint8_t signal, hfp_roaming_state_t roam, uint8_t battery)
@ -175,4 +175,4 @@ bt_status_t BTSYMBOLS(bt_hfp_ag_send_cind_response)(bt_instance_t* ins, bt_addre
hfp_ag_interface_t* profile = get_profile_service();
return profile->send_cind_response(addr, network, call, call_held, call_setup, signal, roam, battery);
}
}

View File

@ -24,35 +24,25 @@
void* BTSYMBOLS(bt_l2cap_register_callbacks)(bt_instance_t* ins, const l2cap_callbacks_t* callbacks)
{
return l2cap_register_callbacks(ins, callbacks);
return l2cap_register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_l2cap_unregister_callbacks)(bt_instance_t* ins, void* handle)
bool BTSYMBOLS(bt_l2cap_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
return l2cap_unregister_callbacks(NULL, handle);
return l2cap_unregister_callbacks(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_l2cap_listen)(bt_instance_t* ins, void* handle, l2cap_config_option_t* option)
bt_status_t BTSYMBOLS(bt_l2cap_listen)(bt_instance_t* ins, l2cap_config_option_t* option)
{
return l2cap_listen_channel(handle, option);
return l2cap_listen_channel(option);
}
bt_status_t BTSYMBOLS(bt_l2cap_connect)(bt_instance_t* ins, void* handel, bt_address_t* addr, l2cap_config_option_t* option)
bt_status_t BTSYMBOLS(bt_l2cap_connect)(bt_instance_t* ins, bt_address_t* addr, l2cap_config_option_t* option)
{
return l2cap_connect_channel(handel, addr, option);
return l2cap_connect_channel(addr, option);
}
bt_status_t BTSYMBOLS(bt_l2cap_disconnect)(bt_instance_t* ins, void* handle, uint16_t id)
bt_status_t BTSYMBOLS(bt_l2cap_disconnect)(bt_instance_t* ins, uint16_t cid)
{
return l2cap_disconnect_channel(handle, id);
return l2cap_disconnect_channel(cid);
}
bt_status_t BTSYMBOLS(bt_l2cap_stop_listen)(bt_instance_t* ins, void* handle, uint16_t psm)
{
return l2cap_stop_listen_channel(handle, BT_TRANSPORT_BLE, psm);
}
bt_status_t BTSYMBOLS(bt_l2cap_stop_listen_with_transport)(bt_instance_t* ins, void* handle, bt_transport_t transport, uint16_t psm)
{
return l2cap_stop_listen_channel(handle, transport, psm);
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "scan"
#define LOG_TAG "adv"
#include <stdlib.h>

View File

@ -186,9 +186,9 @@ bt_status_t bt_adapter_set_le_address(bt_instance_t* ins, bt_address_t* addr)
return BpBtAdapter_setLeAddress((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t* addr, bool is_public)
bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t* addr, bool public)
{
return BpBtAdapter_setLeIdentityAddress((BpBtAdapter*)ins->adapter_proxy, addr, is_public);
return BpBtAdapter_setLeIdentityAddress((BpBtAdapter*)ins->adapter_proxy, addr, public);
}
bt_status_t bt_adapter_set_le_appearance(bt_instance_t* ins, uint16_t appearance)

View File

@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
@ -54,6 +53,7 @@ typedef struct {
struct gatt_client {
gattc_handle_t conn;
bt_address_t addr;
bt_gattc_feature_callbacks_t callbacks;
bool connected;
bool services_discovering;
@ -158,6 +158,25 @@ void discovery_database_destroy(gatt_client_t* client)
}
}
static bool match_client_by_addr(void* element, void* context)
{
bt_address_t* target_addr;
gatt_client_t* client;
target_addr = (bt_address_t*)context;
client = (gatt_client_t*)element;
return memcmp(&client->addr, target_addr, sizeof(bt_address_t)) == 0;
}
static gatt_client_t* find_client_by_addr(bt_address_t* addr)
{
if (!g_gatt_client_list || !addr)
return NULL;
return (gatt_client_t*)bt_list_find(g_gatt_client_list, match_client_by_addr, (void*)addr);
}
static gatt_client_t* find_client_by_conn(gattc_handle_t conn)
{
bt_list_node_t* node;
@ -308,18 +327,6 @@ static gatt_descriptor_t* find_desc_by_attr_handle(gatt_client_t* client, uint16
return NULL;
}
static void gatt_service_list_to_array(bt_list_t* list,
const gatt_service_t* out_array[])
{
bt_list_node_t* node;
size_t i = 0;
for (node = bt_list_head(list); node != NULL;
node = bt_list_next(list, node)) {
out_array[i++] = (gatt_service_t*)bt_list_node(node);
}
}
static gatt_service_t* build_service_from_attr_list(bt_list_t* attr_list)
{
gatt_service_t* service;
@ -432,10 +439,11 @@ static void feature_on_connected(void* conn_handle, bt_address_t* addr)
return;
client->connected = true;
memcpy(&client->addr, addr, sizeof(bt_address_t));
BT_FEATURE_LOG("connected: conn=%p", conn_handle);
BT_GATTC_FEATURE_INVOKE_CB(client, on_connected, client->ins, GATT_STATUS_SUCCESS, client->conn);
BT_GATTC_FEATURE_INVOKE_CB(client, on_connected, client->ins, BT_STATUS_SUCCESS, client->conn);
}
static void feature_on_disconnected(void* conn_handle, bt_address_t* addr)
@ -455,7 +463,7 @@ static void feature_on_disconnected(void* conn_handle, bt_address_t* addr)
client->services_discovering = false;
discovery_database_clear(client);
BT_GATTC_FEATURE_INVOKE_CB(client, on_disconnected, client->ins, GATT_STATUS_SUCCESS,
BT_GATTC_FEATURE_INVOKE_CB(client, on_disconnected, client->ins, BT_STATUS_SUCCESS,
client->conn);
}
@ -466,8 +474,6 @@ static void feature_get_attribute_cb(bt_instance_t* ins, bt_status_t status,
gatt_client_t* client;
gatt_attr_desc_t* attr_node;
gatt_service_t* service;
size_t service_count;
const gatt_service_t** service_array;
(void)ins;
@ -498,23 +504,10 @@ static void feature_get_attribute_cb(bt_instance_t* ins, bt_status_t status,
free(user_data);
client->services_discovering = false;
service_count = bt_list_length(client->services_db);
service_array = calloc(service_count, sizeof(gatt_service_t*));
if (!service_array) {
BT_GATTC_FEATURE_INVOKE_CB(client, on_discovered,
client->ins, GATT_STATUS_FAILURE,
client->conn, NULL, 0);
return;
}
gatt_service_list_to_array(client->services_db, service_array);
BT_GATTC_FEATURE_INVOKE_CB(client, on_discovered,
client->ins, GATT_STATUS_SUCCESS,
client->conn, service_array, service_count);
client->conn, NULL);
free(service_array);
return;
}
@ -537,6 +530,9 @@ static void feature_get_attribute_cb(bt_instance_t* ins, bt_status_t status,
if (service) {
bt_list_add_tail(client->services_db, service);
}
BT_GATTC_FEATURE_INVOKE_CB(client, on_discovered, client->ins, BT_STATUS_SUCCESS,
client->conn, service);
}
free(user_data);
@ -557,7 +553,7 @@ static void feature_on_discovered(void* conn_handle, gatt_status_t status,
if (status != GATT_STATUS_SUCCESS) {
client->services_discovering = false;
BT_GATTC_FEATURE_INVOKE_CB(client, on_discovered, client->ins, status,
client->conn, NULL, 0);
client->conn, NULL);
return;
}
@ -588,7 +584,7 @@ static void feature_on_discovered(void* conn_handle, gatt_status_t status,
client->services_discovering = false;
BT_GATTC_FEATURE_INVOKE_CB(client, on_discovered,
client->ins, GATT_STATUS_FAILURE,
client->conn, NULL, 0);
client->conn, NULL);
return;
}
@ -791,6 +787,7 @@ bt_status_t bt_gattc_feature_create_client_async(bt_instance_t* ins, bt_address_
goto fail;
}
memcpy(&client->addr, addr, sizeof(bt_address_t));
client->ins = ins;
memcpy(&client->callbacks, callbacks, callbacks->size);
@ -841,7 +838,7 @@ static void delete_client_cb(bt_instance_t* ins, bt_status_t status, void* userd
user_ud = client->delete_client_ctx.delete_userdata;
conn_handle = client->conn;
if (g_gatt_client_list) {
if (status == BT_STATUS_SUCCESS && g_gatt_client_list) {
bt_list_remove(g_gatt_client_list, client);
if (!bt_list_length(g_gatt_client_list)) {
@ -854,15 +851,15 @@ static void delete_client_cb(bt_instance_t* ins, bt_status_t status, void* userd
user_cb(ins, status, conn_handle, user_ud);
}
bt_status_t bt_gattc_feature_delete_client_async(bt_instance_t* ins, gattc_handle_t conn_handle,
bt_status_t bt_gattc_feature_delete_client_async(bt_instance_t* ins, bt_address_t* addr,
bt_gattc_feature_delete_client_cb_t cb, void* userdata)
{
gatt_client_t* client;
if (!ins || !conn_handle)
if (!ins || !addr || !cb)
return BT_STATUS_PARM_INVALID;
client = find_client_by_conn(conn_handle);
client = find_client_by_addr(addr);
if (!client)
return BT_STATUS_PARM_INVALID;

View File

@ -223,7 +223,6 @@ bool advertiser_data_add_service_data(advertiser_data_t* ad,
}
memcpy(p, data, len);
sdata->len += len;
bt_list_add_tail(ad->data, sdata);
return true;

View File

@ -88,13 +88,12 @@ static const char* show_ad_type_desc(uint8_t type)
static void advertiser_data_info(adv_data_t* ad)
{
if (!ad || ad->len < 1) {
syslog(LOG_ERR, "Invalid params, ad(%p)", ad);
if (ad->len < 1) {
return;
}
syslog(4, "AdvType:(%s)\n", show_ad_type_desc(ad->type));
BT_DUMPBUFFER("AdvData:", ad->data, ad->len - 1);
lib_dumpbuffer("AdvData:", ad->data, ad->len - 1);
switch (ad->type) {
case BT_AD_FLAGS:

View File

@ -138,6 +138,10 @@ static void euv_close_callback(uv_handle_t* hdl)
#endif
if (handle->status == EUV_ALL_PIPE_CLOSED) {
if (handle->close_cb) {
handle->close_cb(handle);
}
// all pipe closed, free handle
BT_LOGD("%s, free handle 0x%p", __func__, handle);
free(handle);
@ -199,6 +203,16 @@ int euv_pipe_read_start(euv_pipe_t* handle, uint16_t read_size, euv_read_cb read
euv_read_t* reader;
int ret;
if (!handle) {
BT_LOGE("%s, handle null", __func__);
return -EINVAL;
}
if (uv_is_closing((uv_handle_t*)&handle->cli_pipe)) {
BT_LOGE("%s, handle %p is closing", __func__, handle);
return -EPERM;
}
if (uv_is_active((uv_handle_t*)&handle->cli_pipe)) {
BT_LOGE("%s, client is active", __func__);
return 0;
@ -232,6 +246,12 @@ int euv_pipe_read_stop(euv_pipe_t* handle)
return -EINVAL;
}
if (uv_is_closing((uv_handle_t*)&handle->cli_pipe)) {
/* uv_pipe is closing; cli_pipe.data has been set to handle for cleanup, so don't free it here */
BT_LOGE("%s, handle %p is closing", __func__, handle);
return -EPERM;
}
if (handle->cli_pipe.data) {
free(handle->cli_pipe.data);
handle->cli_pipe.data = NULL;
@ -242,11 +262,6 @@ int euv_pipe_read_stop(euv_pipe_t* handle)
return 0;
}
if (uv_is_closing((uv_handle_t*)&handle->cli_pipe)) {
BT_LOGE("%s, uv_is_closing", __func__);
return 0;
}
return uv_read_stop((uv_stream_t*)&handle->cli_pipe);
}
@ -480,13 +495,14 @@ errout_with_handle:
return NULL;
}
void euv_pipe_close(euv_pipe_t* handle)
void euv_pipe_close_with_cb(euv_pipe_t* handle, euv_close_cb cb)
{
if (!handle) {
BT_LOGE("%s, invalid arg", __func__);
return;
}
handle->close_cb = cb;
if (handle->mode == EUV_PIPE_TYPE_UNKNOWN) {
BT_LOGE("%s, unkown mode", __func__);
handle->srv_pipe[EUV_PIPE_TYPE_SERVER_LOCAL].data = handle;
@ -509,6 +525,11 @@ void euv_pipe_close(euv_pipe_t* handle)
uv_close((uv_handle_t*)&handle->srv_pipe[handle->mode], euv_close_callback);
}
void euv_pipe_close(euv_pipe_t* handle)
{
euv_pipe_close_with_cb(handle, NULL);
}
void euv_pipe_disconnect(euv_pipe_t* handle)
{
if (!handle) {

View File

@ -63,8 +63,8 @@ const state_t* hsm_get_previous_state(state_machine_t* sm)
const char* hsm_get_current_state_name(state_machine_t* sm)
{
if (!sm) {
return NULL;
if (!sm || !sm->current_state) {
return HSM_NONE_STR;
}
return sm->current_state->state_name;
@ -73,7 +73,7 @@ const char* hsm_get_current_state_name(state_machine_t* sm)
const char* hsm_get_state_name(const state_t* state)
{
if (!state) {
return NULL;
return HSM_NONE_STR;
}
return state->state_name;

View File

@ -56,11 +56,6 @@ typedef struct {
uv_sem_t signal;
} signal_msg_t;
typedef struct {
thread_loop_work_t work;
uv_sem_t signal;
} signal_work_t;
#if defined(ANDROID)
#define LOOP_THREAD_STACK_SIZE 40960
#else
@ -184,7 +179,7 @@ int thread_loop_run(uv_loop_t* loop, bool start_thread, const char* name)
uv_thread_options_t options = {
UV_THREAD_HAS_STACK_SIZE | UV_THREAD_HAS_PRIORITY,
LOOP_THREAD_STACK_SIZE,
CONFIG_BLUETOOTH_SERVICE_LOOP_THREAD_PRIORITY + 1
CONFIG_BLUETOOTH_SERVICE_LOOP_THREAD_PRIORITY
};
ret = uv_thread_create_ex(&priv->thread, &options, thread_schedule_loop, (void*)loop);
if (ret != 0) {
@ -223,10 +218,8 @@ void thread_loop_exit(uv_loop_t* loop)
uv_sem_wait(&priv->exited);
uv_sem_destroy(&priv->exited);
} else {
if (!uv_loop_is_close(loop)) {
uv_run(loop, UV_RUN_ONCE);
(void)uv_loop_close(loop);
}
uv_run(loop, UV_RUN_ONCE);
(void)uv_loop_close(loop);
}
uv_mutex_lock(&priv->msg_lock);
@ -342,48 +335,3 @@ void do_in_thread_loop_sync(uv_loop_t* loop, thread_func_t func, void* data)
uv_sem_wait(&msg.signal);
uv_sem_destroy(&msg.signal);
}
static void work_sync_cb(uv_work_t* req)
{
signal_work_t* work = req->data;
assert(work);
if (work->work.work_cb)
work->work.work_cb(&work->work, work->work.userdata);
}
static void after_work_sync_cb(uv_work_t* req, int status)
{
signal_work_t* work = req->data;
assert(status == 0);
assert(work);
if (work->work.after_work_cb)
work->work.after_work_cb(&work->work, work->work.userdata);
uv_sem_post(&work->signal);
}
void thread_loop_work_sync(uv_loop_t* loop, void* user_data, thread_work_cb_t work_cb,
thread_after_work_cb_t after_work_cb)
{
signal_work_t* work = (signal_work_t*)calloc(1, sizeof(signal_work_t));
if (work == NULL)
return;
work->work.userdata = user_data;
work->work.work_cb = work_cb;
work->work.after_work_cb = after_work_cb;
work->work.work.data = work;
uv_sem_init(&work->signal, 0);
if (uv_queue_work(loop, &work->work.work, work_sync_cb, after_work_sync_cb) != 0) {
syslog(LOG_DEBUG, "%s uv_queue_work failed", __func__);
goto exit;
}
uv_sem_wait(&work->signal);
exit:
uv_sem_destroy(&work->signal);
free(work);
}

View File

@ -82,248 +82,29 @@ extern "C" {
#define BT_AD_FLAG_BREDR_NOT_SUPPORT 4
#define BT_AD_FLAG_DUAL_MODE 8
/**
* @cond
*/
typedef struct adv_data {
uint8_t len;
uint8_t type;
uint8_t data[0];
} adv_data_t;
/**
* @endcond
*/
typedef struct advertiser_data_ advertiser_data_t;
/**
* @brief Advertising data dump callback function.
*
* Function prototype for dumping advertising data in string format.
*
* @param str - Null-terminated string to dump.
*/
typedef void (*ad_dump_cb_t)(const char* str);
/**
* @brief Dump advertising data.
*
* Parses the advertising data and outputs it using the provided dump callback.
*
* @param data - Pointer to the advertising data buffer.
* @param len - Length of the advertising data buffer.
* @param dump - Callback function to output the parsed data.
* @return true - Parsing and dumping was successful.
* @return false - Parsing failed.
*
* **Example:**
* @code
static void on_scan_result_cb(bt_scanner_t* scanner, ble_scan_result_t* result)
{
PRINT_ADDR("ScanResult ------[%s]------", &result->addr);
PRINT("AddrType:%d", result->addr_type);
PRINT("Rssi:%d", result->rssi);
PRINT("Type:%d", result->adv_type);
advertiser_data_dump((uint8_t*)result->adv_data, result->length, NULL);
PRINT("\n");
}
* @endcode
*/
bool advertiser_data_dump(uint8_t* data, uint16_t len, ad_dump_cb_t dump);
/**
* @brief Create a new advertiser data object.
*
* Allocates and initializes a new advertiser data object.
*
* @return advertiser_data_t* - Pointer to the new advertiser data object; NULL on failure.
*
* **Example:**
* @code
advertiser_data_t* ad = advertiser_data_new();
if (ad == NULL) {
// Handle allocation failure
}
* @endcode
*/
advertiser_data_t* advertiser_data_new(void);
/**
* @brief Free an advertiser data object.
*
* Frees the memory associated with an advertiser data object.
*
* @param ad - Pointer to the advertiser data object to free.
*
* **Example:**
* @code
advertiser_data_free(ad);
* @endcode
*/
void advertiser_data_free(advertiser_data_t* ad);
/**
* @brief Build the advertising data buffer.
*
* Constructs the advertising data buffer from the advertiser data object.
*
* @param ad - Pointer to the advertiser data object.
* @param[out] len - Pointer to store the length of the advertising data buffer.
* @return uint8_t* - Pointer to the advertising data buffer; NULL on failure.
*
* **Note:** The returned buffer should be freed by the caller when no longer needed.
*
* **Example:**
* @code
uint16_t len;
uint8_t* data = advertiser_data_build(ad, &len);
if (data != NULL) {
// Use the advertising data buffer
free(data);
}
* @endcode
*/
uint8_t* advertiser_data_build(advertiser_data_t* ad, uint16_t* len);
/**
* @brief Set the device name in advertising data.
*
* Sets the local device name to be included in the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param name - Null-terminated string containing the device name.
*
* **Example:**
* @code
advertiser_data_set_name(ad, "My Device");
* @endcode
*/
void advertiser_data_set_name(advertiser_data_t* ad, const char* name);
/**
* @brief Set the advertising flags.
*
* Sets the advertising flags to be included in the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param flags - Advertising flags, see BT_AD_FLAG_* definitions.
*
* **Example:**
* @code
advertiser_data_set_flags(ad, BT_AD_FLAG_GENERAL_DISCOVERABLE | BT_AD_FLAG_BREDR_NOT_SUPPORT);
* @endcode
*/
void advertiser_data_set_flags(advertiser_data_t* ad, uint8_t flags);
/**
* @brief Set the GAP appearance.
*
* Sets the GAP appearance value to be included in the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param appearance - Appearance value, see GAP Appearance Values.
*
* **Example:**
* @code
advertiser_data_set_appearance(ad, 0x03C0); // HID Generic
* @endcode
*/
void advertiser_data_set_appearance(advertiser_data_t* ad, uint16_t appearance);
/**
* @brief Add custom data to advertising data.
*
* Adds a custom AD structure to the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param type - AD type, see BT_AD_* definitions.
* @param data - Pointer to the data payload.
* @param len - Length of the data payload.
*
* **Example:**
* @code
uint8_t custom_data[] = {0x01, 0x02, 0x03};
advertiser_data_add_data(ad, BT_AD_MANUFACTURER_DATA, custom_data, sizeof(custom_data));
* @endcode
*/
void advertiser_data_add_data(advertiser_data_t* ad, uint8_t type, uint8_t* data, uint8_t len);
/**
* @brief Remove custom data from advertising data.
*
* Removes a custom AD structure from the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param type - AD type, see BT_AD_* definitions.
* @param data - Pointer to the data payload.
* @param len - Length of the data payload.
*
* **Example:**
* @code
advertiser_data_remove_data(ad, BT_AD_MANUFACTURER_DATA, custom_data, sizeof(custom_data));
* @endcode
*/
void advertiser_data_remove_data(advertiser_data_t* ad, uint8_t type, uint8_t* data, uint8_t len);
/**
* @brief Add manufacturer-specific data to advertising data.
*
* Adds manufacturer-specific data to the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param manufacture_id - Manufacturer ID assigned by the Bluetooth SIG.
* @param data - Pointer to the manufacturer-specific data.
* @param length - Length of the manufacturer-specific data.
*
* **Example:**
* @code
uint8_t manuf_data[] = {0x12, 0x34, 0x56};
advertiser_data_add_manufacture_data(ad, 0x038F, manuf_data, sizeof(manuf_data)); // 0x038F is Xiaomi Inc.
* @endcode
*/
void advertiser_data_add_manufacture_data(advertiser_data_t* ad,
uint16_t manufacture_id,
uint8_t* data, uint8_t length);
/**
* @brief Add a service UUID to advertising data.
*
* Adds a service UUID to the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param uuid - Pointer to the UUID to add, see @ref bt_uuid_t.
* @return true - UUID added successfully.
* @return false - Failed to add UUID.
*
* **Example:**
* @code
bt_uuid_t service_uuid;
bt_uuid_from_string("0000180D-0000-1000-8000-00805F9B34FB", &service_uuid); // Heart Rate Service
advertiser_data_add_service_uuid(ad, &service_uuid);
* @endcode
*/
bool advertiser_data_add_service_uuid(advertiser_data_t* ad, const bt_uuid_t* uuid);
/**
* @brief Add service data to advertising data.
*
* Adds service-specific data associated with a service UUID to the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param uuid - Pointer to the UUID of the service, see @ref bt_uuid_t.
* @param data - Pointer to the service data payload.
* @param len - Length of the service data payload.
* @return true - Service data added successfully.
* @return false - Failed to add service data.
*
* **Example:**
* @code
bt_uuid_t service_uuid;
bt_uuid_from_string("0000180F-0000-1000-8000-00805F9B34FB", &service_uuid); // Battery Service
uint8_t battery_level = 85; // 85%
advertiser_data_add_service_data(ad, &service_uuid, &battery_level, 1);
* @endcode
*/
bool advertiser_data_add_service_data(advertiser_data_t* ad,
const bt_uuid_t* uuid,
uint8_t* data, uint8_t len);

View File

@ -32,10 +32,6 @@ extern "C" {
#include "callbacks_list.h"
#include "uv_thread_loop.h"
/**
* @cond
*/
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
@ -60,6 +56,17 @@ extern "C" {
#endif
#endif // End of else
#define CALLBACK_FOREACH(_list, _struct, _cback, ...) \
BT_CALLBACK_FOREACH(_list, _struct, _cback, ##__VA_ARGS__)
#define CALLBACK_REMOTE(_remote, _type, _cback, ...) \
do { \
_type* _cbs = (_type*)_remote->callbacks; \
if (_cbs && _cbs->_cback) { \
_cbs->_cback(_remote, ##__VA_ARGS__); \
} \
} while (0)
#define PRIMARY_ADAPTER 0
typedef uint8_t bt_controller_id_t;
@ -226,10 +233,16 @@ typedef enum {
typedef enum {
BT_DEBUG_MODE_PTS,
BT_DEBUG_MODE_RSSI,
} bt_debug_mode_t;
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 */
@ -428,6 +441,10 @@ enum {
typedef struct bt_instance bt_instance_t;
typedef bool (*bt_allocator_t)(void** data, uint32_t size);
typedef void (*bt_hci_event_callback_t)(bt_hci_event_t* hci_event, void* context);
typedef void (*bt_ipc_connected_cb_t)(bt_instance_t* ins, void* user_data);
typedef void (*bt_ipc_disconnected_cb_t)(bt_instance_t* ins, void* user_data, int status);
@ -470,11 +487,13 @@ typedef struct bt_instance {
callbacks_list_t* a2dp_source_callbacks;
callbacks_list_t* avrcp_target_callbacks;
callbacks_list_t* avrcp_control_callbacks;
callbacks_list_t* cs_callbacks;
void* adapter_cookie;
void* a2dp_sink_cookie;
void* a2dp_source_cookie;
void* avrcp_target_cookie;
void* avrcp_control_cookie;
void* cs_cookie;
callbacks_list_t* hfp_ag_callbacks;
callbacks_list_t* hfp_hf_callbacks;
@ -496,224 +515,60 @@ typedef struct bt_instance {
} bt_instance_t;
/**
* @endcond
*/
/**
* @brief Allocate memory
*
* This function pointer allocates a size of memory and is pointed to the allocated memory by *data
*
* @param data - pointer of the pointer to the allocated memory
* @param size - size of the memory to be allocated
* @return bool.
*
* **Example:**
* @code
static bool bt_socket_allocator(void** data, uint32_t size)
{
*data = zalloc(size);
if (!(*data))
return false;
return true;
}
* @endcode
*/
typedef bool (*bt_allocator_t)(void** data, uint32_t size);
/**
* @brief hci event callback.
*
* This function pointer is triggered when hci event is received.
*
* @param hci_event - pointer of hci event(specified by vendor).
* @param context - user context.
* @return void.
*
* **Example:**
* @code
static void bt_hci_event_callback(bt_hci_event_t* hci_event, void* context)
{
BT_LOGD("%s, evt_code:0x%x, len:%d", __func__, hci_event->evt_code,
hci_event->length);
// Handle Context.
}
* @endcode
*/
typedef void (*bt_hci_event_callback_t)(bt_hci_event_t* hci_event, void* context);
/**
* @brief Create bluetooth instance
* @brief Create bluetooth client instance
*
* @return bt_instance_t* - ins on success, NULL on failure.
*
* **Example:**
* @code
bt_instance_t* bluetooth_get_instance(void)
{
bt_instance_t* bluetooth_ins = bluetooth_find_instance(getpid());
if (bluetooth_ins == NULL)
return bluetooth_create_instance();
else
return bluetooth_ins;
}
* @endcode
*/
bt_instance_t* BTSYMBOLS(bluetooth_create_instance)(void);
/**
* @brief Get bluetooth instance, If it does not exist, an instance is created
* @brief Get bluetooth client instance, If it does not exist, an instance is created
*
* @return bt_instance_t* - ins if exist or create success, NULL, if create fail.
*
* **Example:**
* @code
bt_instance_t* bluetooth_get_instance(void)
{
bt_instance_t* bluetooth_ins = bluetooth_find_instance(getpid());
if (bluetooth_ins == NULL)
return bluetooth_create_instance();
else
return bluetooth_ins;
}
* @endcode
*/
bt_instance_t* BTSYMBOLS(bluetooth_get_instance)(void);
/**
* @brief Find bluetooth instance
* @brief Find bluetooth client instance
*
* @return bt_instance_t* - ins if exist, NULL otherwise.
*
* **Example:**
* @code
bt_instance_t* bluetooth_get_instance(void)
{
bt_instance_t* bluetooth_ins = bluetooth_find_instance(getpid());
if (bluetooth_ins == NULL)
return bluetooth_create_instance();
else
return bluetooth_ins;
}
* @endcode
*/
bt_instance_t* BTSYMBOLS(bluetooth_find_instance)(pid_t pid);
/**
* @brief Get profile proxy
*
* @param ins - bluetooth instance.
* @param ins - bluetooth client instance.
* @param id - profile ID.
* @return void* - profile proxy.
*
* **Example:**
* @code
static bool bt_socket_allocator(void** data, uint32_t size)
{
*data = zalloc(size);
if (!(*data))
return false;
return true;
}
* @endcode
*/
void* BTSYMBOLS(bluetooth_get_proxy)(bt_instance_t* ins, enum profile_id id);
/**
* @brief Delete client instance
*
* @param ins - bluetooth instance.
*
* **Example:**
* @code
int main(int argc, char** argv) {
g_app_ins = bluetooth_create_instance();
while(1) {
// Handle events
}
bluetooth_delete_instance(g_app_ins);
}
* @endcode
* @param ins - bluetooth client instance.
*/
void BTSYMBOLS(bluetooth_delete_instance)(bt_instance_t* ins);
/**
* @brief Start profile service
*
* @param ins - bluetooth instance.
* @param ins - bluetooth client instance.
* @param id - profile ID.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
int leac_command_init(void* handle)
{
bt_status_t ret;
ret = bluetooth_start_service(handle, PROFILE_LEAUDIO_CLIENT);
if (ret != BT_STATUS_SUCCESS) {
PRINT("%s, failed ret:%d", __func__, ret);
return ret;
}
lea_client_callbacks = bt_lea_client_register_callbacks(handle, &lea_client_cbs);
return 0;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bluetooth_start_service)(bt_instance_t* ins, enum profile_id id);
/**
* @brief Stop profile service
*
* @param ins - bluetooth instance.
* @param id - profile ID.
* @param ins - bluetooth client instance.
* @param id -profile ID.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
void leac_command_uninit(void* handle)
{
bt_status_t ret;
bt_lea_client_unregister_callbacks(handle, lea_client_callbacks);
ret = bluetooth_stop_service(handle, PROFILE_LEAUDIO_CLIENT);
if (ret != BT_STATUS_SUCCESS) {
PRINT("%s, failed ret:%d", __func__, ret);
}
}
* @endcode
*/
bt_status_t BTSYMBOLS(bluetooth_stop_service)(bt_instance_t* ins, enum profile_id id);
/**
* @brief Set external uv loop
*
* This function drops external UV_loop into bluetooth instance.
*
* @param ins - bluetooth instance.
* @param ext_loop - external uv loop.
* @return bool - true on success, false on failure.
*
* **Example:**
* @code
bool bluetooth_set_external_uv(bt_instance_t* ins, uv_loop_t* ext_loop)
{
BT_SOCKET_INS_VALID(ins, false);
ins->external_loop = ext_loop;
return true;
}
* @endcode
*/
bool BTSYMBOLS(bluetooth_set_external_uv)(bt_instance_t* ins, uv_loop_t* ext_loop);
/*
@ -737,23 +592,6 @@ bt_instance_t* bluetooth_create_async_instance(uv_loop_t* loop, bt_ipc_connected
*/
void bluetooth_delete_async_instance(bt_instance_t* ins);
/**
* @brief get bluetooth async client instance
*
* @param loop uv_loop_t
* @param connected client instance connected callback
* @param disconnected client instance disconnected callback
* @return bt_instance_t* - ins on success, NULL on failure.
*/
bt_instance_t* bluetooth_get_async_instance(uv_loop_t* loop, bt_ipc_connected_cb_t connected, bt_ipc_disconnected_cb_t disconnected, void* user_data);
/**
* @brief Find bluetooth instance
*
* @return bt_instance_t* - ins if exist, NULL otherwise.
*/
bt_instance_t* BTSYMBOLS(bluetooth_find_async_instance)(pid_t pid);
#ifdef __cplusplus
}
#endif

View File

@ -21,9 +21,6 @@
#include "bt_addr.h"
#include "bt_device.h"
/**
* @cond
*/
/**
* @brief A2DP audio state
*/
@ -32,63 +29,23 @@ typedef enum {
A2DP_AUDIO_STATE_STOPPED,
A2DP_AUDIO_STATE_STARTED,
} a2dp_audio_state_t;
/**
* @endcond
*/
/**
* @brief Callback for A2DP connection state changed.
* @brief A2DP connection state changed callback
*
* There are four states for A2DP connection, namely DISCONNECTED, CONNECTING,
* CONNECTED, and DISCONNECTING. During the initialization phase of the A2DP,
* it is necessary to register callback functions. This callback is triggered
* when there is a change in the state of the A2DP connection.
*
* Stable States:
* DISCONNECTED: The initial state.
* CONNECTED: The A2DP connection is established.
* Transient states:
* CONNECTING: The A2DP connection is being established.
* DISCONNECTING: The A2DP connection is being terminated.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
* @param state - A2DP profile connection state.
*
* **Example:**
* @code
static void on_connection_state_changed_cb(void* cookie, bt_address_t* addr, profile_connection_state_t state)
{
printf("A2DP connection state is: %d", state);
}
* @endcode
* @param cookie - callback cookie.
* @param addr - address of peer A2DP device.
* @param state - connection state.
*/
typedef void (*a2dp_connection_state_callback)(void* cookie, bt_address_t* addr,
profile_connection_state_t state);
/**
* @brief Callback for A2DP audio state changed.
* @brief A2DP audio connection state changed callback
*
* There are three states for A2DP audio, namely SUSPEND, STOPPED,
* and STARTED. It is important to note that a callback function
* is triggered whenever a change occurs in the audio state.
*
* Stable States:
* SUSPEND: The stream is suspended.
* STOPPED: The stream is stopped.
* STARTED: The stream is started.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
* @param state - A2DP audio connection state.
*
* **Example:**
* @code
static void on_audio_state_changed_cb(void* cookie, bt_address_t* addr, a2dp_audio_state_t state)
{
printf("A2DP audio state is: %d", state);
}
* @endcode
* @param cookie - callback cookie.
* @param addr - address of peer A2DP device.
* @param state - audio connection state.
*/
typedef void (*a2dp_audio_state_callback)(void* cookie, bt_address_t* addr,
a2dp_audio_state_t state);

View File

@ -25,30 +25,15 @@ extern "C" {
#endif
/**
* @brief Callback for A2DP audio configuration.
* @brief A2DP audio sink config changed callback
*
* During the initialization process of the A2DP, callback functions are registered.
* This callbacks is triggered whenever a change occurs in the audio configuration
* of an A2DP connection.
*
* @param cookie - Callbacks cookie.
* @param addr - The Bluetooth address of the peer device.
*
* **Example:**
* @code
static void on_audio_config_changed_cb(void* cookie, bt_address_t* addr)
{
printf("A2DP audio sink configuration is changed");
}
* @endcode
* @param cookie - callback cookie.
* @param addr - address of peer A2DP source device.
*/
typedef void (*a2dp_audio_sink_config_callback)(void* cookie, bt_address_t* addr);
/**
* @cond
*/
/**
* @brief A2DP Sink callback structure
* @brief A2DP sink callback structure
*
*/
typedef struct {
@ -58,209 +43,79 @@ typedef struct {
a2dp_audio_state_callback audio_state_cb;
a2dp_audio_sink_config_callback audio_sink_config_cb;
} a2dp_sink_callbacks_t;
/**
* @endcond
*/
/**
* @brief Register callback functions to A2DP Sink service.
* @brief Register callback functions to A2DP sink service
*
* When initializing the A2DP Sink, an application should register callback functions
* to the A2DP Sink service, which includes a connection state callback function, an
* audio state callback function, and an audio sink configuration callback function.
* Subsequently, the A2DP Sink service will notify the application of any state
* changes via the registered callback functions.
*
* @param ins - Buetooth client instance.
* @param callbacks - A2DP Sink callback functions.
* @return void* - Callbacks cookie, if the callback is registered successfuly. NULL
* if the callback is already registered or registration fails.
* To obtain more information, refer to bt_remote_callbacks_register().
*
* **Example:**
* @code
static const a2dp_sink_callbacks_t a2dp_sink_cbs = {
sizeof(a2dp_sink_cbs),
a2dp_sink_connection_state_cb,
a2dp_sink_audio_state_cb,
a2dp_sink_audio_config_cb,
};
void a2dp_sink_init(void* ins)
{
static void* sink_cbks_cookie;
sink_cbks_cookie = bt_a2dp_sink_register_callbacks(ins, &a2dp_sink_cbs);
}
* @endcode
* @param ins - bluetooth client instance.
* @param id - A2DP sink callback functions.
* @return void* - callbacks cookie.
*/
void* BTSYMBOLS(bt_a2dp_sink_register_callbacks)(bt_instance_t* ins, const a2dp_sink_callbacks_t* callbacks);
/**
* @brief Unregister callback functions from A2DP Sink service.
* @brief Unregister callback functions to a2dp sink service
*
* An application may use this interface to stop listening on the A2DP Sink
* callbacks and to release the associated resources.
*
* @param ins - Buetooth client instance.
* @param cookie - Callbacks cookie.
* @return true - Callback unregistration successful.
* @return false - Callback cookie not found or callback unregistration failed.
*
* **Example:**
* @code
static void* sink_cbks_cookie = bt_a2dp_sink_register_callbacks(ins, &a2dp_sink_cbs);
void a2dp_sink_uninit(void* ins)
{
bt_a2dp_sink_unregister_callbacks(ins, sink_cbks_cookie);
}
* @endcode
* @param ins - bluetooth client instance.
* @param id - callbacks cookie.
* @return true - on callback unregister success
* @return false - on callback cookie not found
*/
bool BTSYMBOLS(bt_a2dp_sink_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Check if A2DP is already connected.
* @brief Check A2DP sink is connected
*
* This function serves the purpose of verifying the connection status of A2DP.
* It is important to note that the A2DP profile is deemed connected solely when
* the A2DP Sink is either in the Opened or Started state.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return true - A2DP Sink connected.
* @return false - A2DP Sink not connected.
*
* **Example:**
* @code
void a2dp_sink_connected(void* ins, bt_address_t* addr)
{
bool ret = bt_a2dp_sink_is_connected(ins, addr);
printf("A2DP sink is %s", ret? "connected" : "not connected");
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return true - connected.
* @return false - not connected.
*/
bool BTSYMBOLS(bt_a2dp_sink_is_connected)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Check if the stream is being transmitted.
* @brief Check A2DP sink is playing
*
* This function is used to verify the streaming status of the A2DP Sink.
* The A2DP Sink can only be deemed as playing when it is in the Started
* state and the audio is also in the Started state.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return true - Stream is being transmitted .
* @return false - No stream transmission.
*
* **Example**
* @code
void a2dp_sink_playing(void* ins, bt_address_t* addr)
{
bool ret = bt_a2dp_sink_is_playing(ins, addr);
printf("A2DP sink is %s", ret? "playing" : "not playing");
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return true - playing.
* @return false - not playing.
*/
bool BTSYMBOLS(bt_a2dp_sink_is_playing)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Obtain A2DP Sink connection state.
* @brief get A2DP sink connection state
*
* There are four states for A2DP connection, namely DISCONNECTED, CONNECTING,
* CONNECTED, and DIACONNECTED. This function is used by the application of
* the A2DP Sink to obtain the current state of the A2DP profile connection.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return profile_connection_state_t - A2DP profile connection state.
*
* **Example**
* @code
int get_state_cmd(void* ins, bt_address_t* addr)
{
int state = bt_a2dp_sink_get_connection_state(ins, addr);
printf("A2DP sink connection state is: %d", state);
return state;
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return profile_connection_state_t - connection state.
*/
profile_connection_state_t BTSYMBOLS(bt_a2dp_sink_get_connection_state)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Establish connection with peer A2DP device.
* @brief Establish connection with peer A2DP device
*
* This function is used to establish an A2DP profile connection with a designated
* peer device. Following the successful creation of the A2DP connection, the A2DP
* Sink transitions to an Opened state and subsequently notifies the application of
* its CONNECTED state. Upon reception of audio data from the A2DP Source device,
* the A2DP Sink then proceeds to forward the audio data to the Media.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example**
* @code
int a2dp_sink_connect(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_sink_connect(ins, addr);
printf("A2DP sink connect %s", ret ? "failed" : "success");
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_sink_connect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect from peer A2DP device.
* @brief Disconnect from peer A2DP device
*
* This function is utilized for the purpose of disconnecting an A2DP profile connection
* with a designated peer device. Upon successful disconnection of the A2DP connection,
* the A2DP Sink transitions into an Idle state and subsequently notifies the application
* of the DISCONNECTED state.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example**
* @code
int a2dp_sink_disconnect(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_sink_disconnect(ins, addr);
printf("A2DP sink disconnect %s", ret ? "failed" : "success");
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_sink_disconnect)(bt_instance_t* ins, bt_address_t* addr);
/*
* @brief Set a peer A2DP Source device as active device.
/**
* @brief set a peer A2DP source device as active device
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example**
* @code
int enable_source_device(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_sink_set_active_device(ins, addr);
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_sink_set_active_device)(bt_instance_t* ins, bt_address_t* addr);

View File

@ -26,28 +26,13 @@ extern "C" {
#endif
/**
* @brief Callback for A2DP audio configuration.
* @brief A2DP audio source config changed callback
*
* During the initialization process of the A2DP, callback functions are registered.
* This callbacks is triggered whenever a change occurs in the audio configuration
* of an A2DP connection.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
*
* **Example:**
* @code
static void on_audio_config_changed_cb(void* cookie, bt_address_t* addr)
{
printf("A2DP audio source configuration is changed");
}
* @endcode
* @param cookie - callback cookie.
* @param addr - address of peer A2DP sink device.
*/
typedef void (*a2dp_audio_source_config_callback)(void* cookie, bt_address_t* addr);
/**
* @cond
*/
/**
* @brief A2DP source callback structure
*
@ -59,227 +44,87 @@ typedef struct {
a2dp_audio_state_callback audio_state_cb;
a2dp_audio_source_config_callback audio_source_config_cb;
} a2dp_source_callbacks_t;
/**
* @endcond
*/
/**
* @brief Register callback functions to A2DP Source service.
* @brief Register callback functions to A2DP source service
*
* When the A2DP Source is initialized, an application registers various callback
* functions to the A2DP Source service, such as the connection state callback function,
* audio state callback function, and audio source configuration callback function.
* The A2DP Source service will notify the application of any state changes via the
* registered callback functions.
*
* @param ins - Bluetooth client instance.
* @param callbacks - A2DP Source callback functions.
* @return void* - Callbacks cookie, if the callback is registered successfuly.
* NULL if the callback is already registered or registration fails.
*
* **Example:**
* @code
static const a2dp_source_callbacks_t a2dp_src_cbs = {
sizeof(a2dp_src_cbs),
a2dp_src_connection_state_cb,
a2dp_src_audio_state_cb,
a2dp_src_audio_source_config_cb,
};
void a2dp_source_uninit(void* ins)
{
static void* src_cbks_cookie;
src_cbks_cookie = bt_a2dp_source_register_callbacks(ins, &a2dp_src_cbs);
}
* @endcode
* @param ins - bluetooth client instance.
* @param id - A2DP source callback functions.
* @return void* - callbacks cookie.
*/
void* BTSYMBOLS(bt_a2dp_source_register_callbacks)(bt_instance_t* ins, const a2dp_source_callbacks_t* callbacks);
/**
* @brief Unregister callback functions to A2DP Source service.
* @brief Unregister callback functions to A2DP source service
*
* An application may use this interface to stop listening on the A2DP Source
* callbacks and to release the associated resources.
*
* @param ins - Bluetooth client instance.
* @param cookie - Callbacks cookie.
* @return true - Callback unregistration successful.
* @return false - Callback cookie not found or callback unregistration failed.
*
* **Example:**
* @code
static void* src_cbks_cookie = bt_a2dp_source_register_callbacks(ins, &a2dp_src_cbs);
void a2dp_source_uninit(void* ins)
{
bt_a2dp_source_unregister_callbacks(ins, src_cbks_cookie);
}
* @endcode
* @param ins - bluetooth client instance.
* @param id - callbacks cookie.
* @return true - on callback unregister success.
* @return false - on callback cookie not found.
*/
bool BTSYMBOLS(bt_a2dp_source_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Check if A2DP is already connected.
* @brief Check A2DP source is connected
*
* This function serves the purpose of verifying the connection status of A2DP.
* It is important to note that the A2DP profile is deemed connected solely when
* the A2DP Source is either in the Opened or Started state.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return true - A2DP Source connected.
* @return false - A2DP Source not connected.
*
* **Example:**
* @code
void a2dp_source_connected(void* ins, bt_address_t* addr)
{
bool ret = bt_a2dp_source_is_connected(ins, addr);
printf("A2DP source is %s", ret? "connected" : "not connected");
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return true - connected.
* @return false - not connected.
*/
bool BTSYMBOLS(bt_a2dp_source_is_connected)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Check if the stream is being transmitted.
* @brief Check A2DP source is playing
*
* This function is used to verify the streaming status of the A2DP Source.
* The A2DP Source can only be deemed as playing when it is in the Started
* state and the audio is also in the Started state.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return true - Stream is being transmitted.
* @return false - No stream transmission.
*
* **Example**
* @code
void a2dp_source_playing(void* ins, bt_address_t* addr)
{
bool ret = bt_a2dp_source_is_playing(ins, addr);
printf("A2DP source is %s", ret? "playing" : "not playing");
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return true - playing.
* @return false - not playing.
*/
bool BTSYMBOLS(bt_a2dp_source_is_playing)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Obtain A2DP Source connection state.
* @brief get A2DP source connection state
*
* There are four states for A2DP connection, namely DISCONNECTED, CONNECTING,
* CONNECTED, and DIACONNECTED. This function is used by the application of
* the A2DP Source to obtain the current state of the A2DP profile connection.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return profile_connection_state_t - A2DP profile connection state.
*
* **Example**
* @code
int get_state_cmd(void* ins, bt_address_t* addr)
{
int state = bt_a2dp_source_get_connection_state(ins, addr);
printf("A2DP source connection state is: %d", state);
return state;
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return profile_connection_state_t - connection state.
*/
profile_connection_state_t BTSYMBOLS(bt_a2dp_source_get_connection_state)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Establish connection with peer A2DP device.
* @brief Establish connection with peer A2DP device
*
* This function is used to establish an A2DP profile connection with a designated
* peer device. Upon successful establishment of the A2DP connection, the A2DP Source
* transitions to an Opened state and notifies the application of its CONNECTED status.
* Upon receipt of audio data from the media, the A2DP Source subsequently relays the
* audio data to the A2DP Sink.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example**
* @code
int a2dp_source_connect(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_source_connect(ins, &addr);
printf("A2DP source connect %s", ret ? "failed" : "success");
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_source_connect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect from peer A2DP device.
* @brief Disconnect from peer A2DP device
*
* This function is used to remove an A2DP profile connection with a specific peer device. Once
* the A2DP connection is removed, the A2DP Source turns into the Idle state and reports the
* DISCONNECTED state to the application.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example**
* @code
int a2dp_source_disconnect(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_source_disconnect(ins, addr);
printf("A2DP source disconnect %s", ret ? "failed" : "success");
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_source_disconnect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Set a peer A2DP Sink device as silence device.
* @brief set a peer A2DP sink device as silence device
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param silence - True, switch to silence mode to keep this device inactive.
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example**
* @code
int disable_sink_device(void* ins, bt_address_t* addr, bool silence)
{
int ret = bt_a2dp_source_set_silence_device(ins, addr, silence);
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_source_set_silence_device)(bt_instance_t* ins, bt_address_t* addr, bool silence);
/**
* @brief Set a peer A2DP Sink device as active device.
* @brief set a peer A2DP sink device as active device
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example**
* @code
int enable_sink_device(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_source_set_active_device(ins, addr);
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_source_set_active_device)(bt_instance_t* ins, bt_address_t* addr);

View File

@ -598,12 +598,6 @@ if (bt_adapter_disable(ins) == BT_STATUS_SUCCESS) {
*/
bt_status_t BTSYMBOLS(bt_adapter_disable)(bt_instance_t* ins);
/**
* @brief Disable bluetooth adapter safely
*
* @param ins - bluetooth client instance.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_disable_safe)(bt_instance_t* ins);
/**
@ -656,17 +650,6 @@ bt_device_type_t BTSYMBOLS(bt_adapter_get_type)(bt_instance_t* ins);
*/
bt_status_t BTSYMBOLS(bt_adapter_set_discovery_filter)(bt_instance_t* ins);
/**
* @brief Start device limited discovery.
*
* Initiates the device limited discovery process to find nearby Bluetooth devices.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param timeout - Maximum amount of time to perform discovery (Time = N * 1.28s, Range: 1.28s to 61.44s).
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_start_limited_discovery)(bt_instance_t* ins, uint32_t timeout);
/**
* @brief Start device discovery.
*
@ -687,6 +670,8 @@ if (bt_adapter_start_discovery(ins, 10) == BT_STATUS_SUCCESS) {
*/
bt_status_t BTSYMBOLS(bt_adapter_start_discovery)(bt_instance_t* ins, uint32_t timeout);
bt_status_t BTSYMBOLS(bt_adapter_start_limited_discovery)(bt_instance_t* ins, uint32_t timeout);
/**
* @brief Cancel device discovery.
*
@ -1150,19 +1135,6 @@ bt_status_t BTSYMBOLS(bt_adapter_le_enable_key_derivation)(bt_instance_t* ins,
*/
bt_status_t BTSYMBOLS(bt_adapter_le_add_whitelist)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Add a device to the BLE whitelist with specified address type.
*
* Adds a device address to the BLE whitelist, allowing the caller to specify the address type
* (e.g., public or random address).
*
* @param ins Bluetooth client instance, see @ref bt_instance_t.
* @param addr Address of the device to add, see @ref bt_address_t.
* @param type Address type of the device, see @ref ble_addr_type_t.
* @return bt_status_t BT_STATUS_SUCCESS on success; a negative error code on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_le_add_whitelist_with_type)(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t type);
/**
* @brief Remove a device from the BLE whitelist.
*
@ -1199,71 +1171,8 @@ bt_status_t BTSYMBOLS(bt_adapter_set_afh_channel_classification)(bt_instance_t*
*/
bt_status_t BTSYMBOLS(bt_adapter_set_auto_sniff)(bt_instance_t* ins, bt_auto_sniff_params_t* params);
// async
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#include "bt_async.h"
typedef void (*bt_register_callback_cb_t)(bt_instance_t* ins, bt_status_t status, void* cookie, void* userdata);
typedef void (*bt_adapter_get_state_cb_t)(bt_instance_t* ins, bt_status_t status, bt_adapter_state_t state, void* userdata);
typedef void (*bt_adapter_get_device_type_cb_t)(bt_instance_t* ins, bt_status_t status, bt_device_type_t type, void* userdata);
typedef void (*bt_adapter_get_address_cb_t)(bt_instance_t* ins, bt_status_t status, bt_address_t* addr, void* userdata);
typedef void (*bt_adapter_get_io_capability_cb_t)(bt_instance_t* ins, bt_status_t status, bt_io_capability_t cap, void* userdata);
typedef void (*bt_adapter_get_scan_mode_cb_t)(bt_instance_t* ins, bt_status_t status, bt_scan_mode_t mode, void* userdata);
typedef void (*bt_adapter_get_devices_cb_t)(bt_instance_t* ins, bt_status_t status, bt_address_t* addr, int num, void* userdata);
typedef void (*bt_adapter_get_uuids_cb_t)(bt_instance_t* ins, bt_status_t status, bt_uuid_t* uuids, uint16_t size, void* userdata);
typedef void (*bt_adapter_get_le_address_cb_t)(bt_instance_t* ins, bt_status_t status, bt_address_t* addr, ble_addr_type_t type, void* userdata);
bt_status_t bt_adapter_register_callback_async(bt_instance_t* ins,
const adapter_callbacks_t* adapter_cbs, bt_register_callback_cb_t cb, void* userdata);
bt_status_t bt_adapter_unregister_callback_async(bt_instance_t* ins, void* cookie, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_adapter_enable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_disable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_enable_le_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_disable_le_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_state_async(bt_instance_t* ins, bt_adapter_get_state_cb_t get_state_cb, void* userdata);
bt_status_t bt_adapter_is_le_enabled_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_type_async(bt_instance_t* ins, bt_device_type_cb_t get_dtype_cb, void* userdata);
bt_status_t bt_adapter_set_discovery_filter_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_start_discovery_async(bt_instance_t* ins, uint32_t timeout, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_cancel_discovery_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_is_discovering_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_address_async(bt_instance_t* ins, bt_address_cb_t cb, void* userdata);
bt_status_t bt_adapter_set_name_async(bt_instance_t* ins, const char* name, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_name_async(bt_instance_t* ins, bt_string_cb_t get_name_cb, void* userdata);
bt_status_t bt_adapter_get_uuids_async(bt_instance_t* ins, bt_uuids_cb_t get_uuids_cb, void* userdata);
bt_status_t bt_adapter_set_scan_mode_async(bt_instance_t* ins, bt_scan_mode_t mode, bool bondable, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_scan_mode_async(bt_instance_t* ins, bt_adapter_get_scan_mode_cb_t get_scan_mode_cb, void* userdata);
bt_status_t bt_adapter_set_device_class_async(bt_instance_t* ins, uint32_t cod, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_device_class_async(bt_instance_t* ins, bt_u32_cb_t get_cod_cb, void* userdata);
bt_status_t bt_adapter_set_io_capability_async(bt_instance_t* ins, bt_io_capability_t cap, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_io_capability_async(bt_instance_t* ins, bt_adapter_get_io_capability_cb_t get_ioc_cb, void* userdata);
bt_status_t bt_adapter_set_inquiry_scan_parameters_async(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_set_page_scan_parameters_async(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_set_le_io_capability_async(bt_instance_t* ins, uint32_t le_io_cap, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_le_io_capability_async(bt_instance_t* ins, bt_u32_cb_t get_le_ioc_cb, void* userdata);
bt_status_t bt_adapter_get_le_address_async(bt_instance_t* ins, bt_adapter_get_le_address_cb_t cb, void* userdata);
bt_status_t bt_adapter_set_le_address_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_set_le_identity_address_async(bt_instance_t* ins, bt_address_t* addr, bool is_public, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_set_le_appearance_async(bt_instance_t* ins, uint16_t appearance, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_le_appearance_async(bt_instance_t* ins, bt_u16_cb_t cb, void* userdata);
bt_status_t bt_adapter_le_enable_key_derivation_async(bt_instance_t* ins,
bool brkey_to_lekey, bool lekey_to_brkey, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_le_add_whitelist_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_le_remove_whitelist_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_bonded_devices_async(bt_instance_t* ins, bt_transport_t transport, bt_adapter_get_devices_cb_t get_bonded_cb, void* userdata);
bt_status_t bt_adapter_get_connected_devices_async(bt_instance_t* ins, bt_transport_t transport, bt_adapter_get_devices_cb_t get_connected_cb, void* userdata);
bt_status_t bt_adapter_set_afh_channel_classification_async(bt_instance_t* ins, uint16_t central_frequency,
uint16_t band_width, uint16_t number, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_set_auto_sniff_async(bt_instance_t* ins, bt_auto_sniff_params_t* params, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_disconnect_all_devices_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_is_support_bredr_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_adapter_is_support_le_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_adapter_is_support_leaudio_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
#endif /* CONFIG_BLUETOOTH_FRAMEWORK_ASYNC */
#ifdef __cplusplus
}
#endif
#endif /* __BT_ADAPTER_H__ */

View File

@ -69,6 +69,7 @@ typedef struct bt_le_addr {
*/
bool bt_addr_is_empty(const bt_address_t* addr);
/**
* @brief Set a Bluetooth address to empty.
*
@ -84,6 +85,7 @@ bool bt_addr_is_empty(const bt_address_t* addr);
*/
void bt_addr_set_empty(bt_address_t* addr);
/**
* @brief Compare two Bluetooth addresses.
*
@ -104,6 +106,7 @@ void bt_addr_set_empty(bt_address_t* addr);
*/
int bt_addr_compare(const bt_address_t* a, const bt_address_t* b);
/**
* @brief Convert a Bluetooth address to a string.
*
@ -125,6 +128,7 @@ int bt_addr_compare(const bt_address_t* a, const bt_address_t* b);
*/
int bt_addr_ba2str(const bt_address_t* addr, char* str);
/**
* @brief Convert a string to a Bluetooth address.
*
@ -145,6 +149,7 @@ int bt_addr_ba2str(const bt_address_t* addr, char* str);
*/
int bt_addr_str2ba(const char* str, bt_address_t* addr);
/**
* @brief Get the string representation of a Bluetooth address.
*
@ -185,6 +190,7 @@ char* bt_addr_bastr(const bt_address_t* addr);
*/
void bt_addr_set(bt_address_t* addr, const uint8_t* bd);
/**
* @brief Swap byte order of a Bluetooth address.
*

View File

@ -21,6 +21,9 @@
#include "bt_addr.h"
#include "bt_device.h"
/**
* @cond
*/
#define AVRCP_MAX_ATTR_COUNT 9
#define AVRCP_ATTR_MAX_TIELE_LEN 64
#define AVRCP_ATTR_MAX_ARTIST_LEN 64
@ -31,9 +34,6 @@
#define AVRCP_ATTR_MAX_PLAYING_TIMES_LEN 0
#define AVRCP_ATTR_MAX_COVER_ART_HANDLE_LEN 0
/**
* @cond
*/
typedef enum {
PASSTHROUGH_CMD_ID_SELECT,
PASSTHROUGH_CMD_ID_UP,
@ -111,10 +111,10 @@ typedef enum {
PLAY_STATUS_ERROR,
} avrcp_play_status_t;
typedef enum {
enum {
AVRCP_CAPABILITY_ID_COMPANY_ID = 2,
AVRCP_CAPABILITY_ID_EVENTS_SUPPORTED,
} avrcp_capability_id_t;
};
typedef enum {
NOTIFICATION_EVT_PALY_STATUS_CHANGED = 0x01,
@ -156,7 +156,6 @@ typedef enum {
AVRCP_ATTR_PLAYING_TIME_MS,
AVRCP_ATTR_COVER_ART_HANDLE
} avrcp_media_attr_type_t;
/**
* @endcond
*/

View File

@ -21,7 +21,6 @@
/**
* @cond
*/
typedef struct {
uint32_t attr_id;
uint16_t chr_set;
@ -45,7 +44,6 @@ typedef struct {
avrcp_connection_state_callback connection_state_cb;
avrcp_get_element_attribute_cb get_element_attribute_cb;
} avrcp_control_callbacks_t;
/**
* @endcond
*/
@ -107,15 +105,24 @@ void avrcp_control_uninit(void* ins)
bool BTSYMBOLS(bt_avrcp_control_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Get element attribute from peer device.
* @brief Get element attributes from AVRCP Target.
*
* This function is used when an application wants to obtain song information
* from an AVRCP Target device, including title, artist name, album name, track
* number, total number of tracks, genre, playing time.
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @param addr - The Bluetooth address of the peer device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
bt_status_t start_get_element_attributes(bt_instance_t* ins, bt_address_t* addr)
{
bt_status_t ret = bt_avrcp_control_get_element_attributes(ins, addr);
return ret;
}
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_get_element_attributes)(bt_instance_t* ins, bt_address_t* addr);
@ -130,41 +137,12 @@ bt_status_t BTSYMBOLS(bt_avrcp_control_get_element_attributes)(bt_instance_t* in
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_send_passthrough_cmd)(bt_instance_t* ins, bt_address_t* addr, uint8_t cmd, uint8_t state);
/**
* @brief Get unit info from peer device.
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_get_unit_info)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get subunit info from peer device.
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_get_subunit_info)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get playback state from peer device.
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_get_playback_state)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Register notification to peer device, this interface is used for pts.
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @param event - Notification event.
* @param interval - Notification interval.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_register_notification)(bt_instance_t* ins, bt_address_t* addr, uint8_t event, uint32_t interval);
bt_status_t BTSYMBOLS(bt_avrcp_control_register_notification)(bt_instance_t* ins, bt_address_t* addr, avrcp_notification_event_t event, uint32_t interval);
#endif /* __BT_AVRCP_CONTROL_H__ */

View File

@ -1,6 +1,13 @@
#ifndef __INCLUDE_BT_CONFIG_H
#define __INCLUDE_BT_CONFIG_H
// Platform: 32-bit or 64-bit
#if defined(CONFIG_ARCH_ARM64) || defined(ARCH_X86_64) || defined(ANDROID) || (!defined(CONFIG_SIM_M32) && defined(CONFIG_ARCH_SIM))
#define CONFIG_CPU_BIT64 1
#elif defined(ARCH_ARM) || defined(ARCH_X86) || defined(__NuttX__)
#define CONFIG_CPU_BIT32 1
#endif
// Configuration of Bluetooth Framework/Service/Stack
#if defined(__NuttX__)
@ -55,7 +62,7 @@
#define CONFIG_BLUETOOTH_LEA_SOURCE_DATA_PATH "lea_source_data"
#define CONFIG_BLUETOOTH_MAX_SAVED_REMOTE_UUIDS_LEN 80
#define CONFIG_BLUETOOTH_SCO_CTRL_PATH "sco_ctrl"
#define CONFIG_BLUETOOTH_L2CAP 1
// #define CONFIG_BLUETOOTH_L2CAP 1
#define CONFIG_BLUETOOTH_L2CAP_OUTGOING_MTU 2048
#define CONFIG_BLUETOOTH_GATTC_MAX_CONNECTIONS 8
#define CONFIG_BLUETOOTH_GATTS_MAX_ATTRIBUTE_NUM 10
@ -72,14 +79,14 @@
#define CONFIG_BLUETOOTH_SPP_SERVER_MAX_CONNECTIONS 8
#define CONFIG_BLUETOOTH_MAX_REGISTER_NUM 4
#define CONFIG_BLUETOOTH_FRAMEWORK 1
//#define CONFIG_BLUETOOTH_FRAMEWORK_LOCAL 1
// #define CONFIG_BLUETOOTH_FRAMEWORK_LOCAL 1
#define CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC 1
#define CONFIG_BLUETOOTH_SOCKET_PORT 6001
#define CONFIG_BLUETOOTH_SERVICE 1
//#define CONFIG_BLUETOOTH_SERVER 1
// #define CONFIG_BLUETOOTH_SERVER 1
#define CONFIG_BLUETOOTH_SERVER_NAME "bluetoothd"
#define CONFIG_BLUETOOTH_IPC_JOIN_LOOP 1
//#define CONFIG_BLUETOOTH_SERVICE_LOG_LEVEL 7
// #define CONFIG_BLUETOOTH_SERVICE_LOG_LEVEL 7
#define CONFIG_BLUETOOTH_SERVICE_HCI_UART_NAME "/dev/ttyHCI0"
#define CONFIG_BLUETOOTH_STACK_BREDR_BLUELET 1
#define CONFIG_BLUETOOTH_STACK_LE_BLUELET 1
@ -92,14 +99,17 @@
#define CONFIG_NET_RPMSG 1
// Socket: via IPv4
//#define CONFIG_NET_IPv4 1
//#define CONFIG_BLUETOOTH_NET_IPv4 1
// #define CONFIG_NET_IPv4 1
// #define CONFIG_BLUETOOTH_NET_IPv4 1
#define CONFIG_INADDR_LOOPBACK 0x0A000202
// SPP
#define CONFIG_RPMSG_UART 1
// SPP via RPMsg UART "/dev/ttyDROID"
//#define CONFIG_RPMSG_UART 1
// #define CONFIG_RPMSG_UART 1
// SPP via RPMsg socket/pipe
#define CONFIG_BLUETOOTH_SPP_RPMSG_NET 1
/********************* O95 Project Only *********************/
#if defined(ANDROID_12)
@ -107,7 +117,7 @@
#define CONFIG_BLUETOOTH_RPMSG_CPUNAME "ap"
/********************* O61 Project Only *********************/
#elif defined(ANDROID_14) || defined(ANDROID_15)
#elif defined(ANDROID_14)
// Socket: RPMsg
#define CONFIG_BLUETOOTH_RPMSG_CPUNAME "cp"
// A2DP
@ -121,14 +131,7 @@
#endif
// Platform: 32-bit or 64-bit
#if defined(CONFIG_ARCH_ARM64) || defined(ARCH_X86_64) || defined(ANDROID) || (!defined(CONFIG_SIM_M32) && defined(CONFIG_ARCH_SIM)) || defined(CONFIG_ARCH_X86_64)
#define CONFIG_CPU_BIT64 1
#elif defined(ARCH_ARM) || defined(ARCH_X86)
#define CONFIG_CPU_BIT32 1
#endif
//############################################################################
// ############################################################################
#define CONFIG_y 1
#define CONFIG_m 2

203
framework/include/bt_cs.h Normal file
View File

@ -0,0 +1,203 @@
/****************************************************************************
* Copyright (C) 2025 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_CS_H__
#define __BT_CS_H__
#include <stdbool.h>
#include <stddef.h>
#include "bluetooth.h"
#include "bt_addr.h"
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
#define MAX_TEST_DATA 128
typedef struct {
uint8_t centimeter;
uint8_t error_centimeter;
uint8_t azimuth_angle;
uint8_t error_azimuthAngle;
uint8_t altitude_angle;
uint8_t error_altitudeAngle;
long elapsed_realtime_nanos;
uint8_t confidence_level;
double delay_spread_meters;
uint8_t detected_attack_level;
double velocity_meters_persecond;
uint8_t method;
} bt_distance_measurement_result_t;
typedef void (*cs_distance_measure_started_cb)(void* cookie, bt_address_t* addr, uint8_t method);
typedef void (*cs_distance_measure_stopped_cb)(void* cookie, bt_address_t* addr, uint8_t reason, uint8_t method);
typedef void (*cs_distance_measure_result_cb)(void* cookie, bt_address_t* addr, bt_distance_measurement_result_t* result);
/**
* @cond
*/
typedef struct {
bt_address_t addr;
uint8_t method;
uint8_t role;
uint16_t interval_ms;
uint16_t duration_ms;
uint8_t submode;
uint8_t max_steps;
uint8_t mode0_steps;
uint8_t rtt_type;
uint8_t sync_phy;
uint8_t channel_map;
uint8_t antenna_paths_mask;
uint8_t vendor_specific;
uint8_t debug_flags;
} bt_distance_measurement_params_t;
typedef struct {
size_t size;
cs_distance_measure_started_cb cs_distance_measure_started_cb;
cs_distance_measure_stopped_cb cs_distance_measure_stopped_cb;
cs_distance_measure_result_cb cs_distance_measure_result_cb;
} cs_callbacks_t;
typedef enum {
METHOD_AUTO,
METHOD_RSSI,
METHOD_CS,
} cs_method_t;
/**
* @endcond
*/
/**
* @brief register cs event callback
*
* register cs event callback.
*
* @param ins bt instance.
* @param callbacks cs event callback function.
* @return cookie of cs event callback.
*/
void* BTSYMBOLS(bt_cs_register_callbacks)(bt_instance_t* ins, const cs_callbacks_t* callbacks);
/**
* @brief unregister cs event callback
*
* unregister cs event callback.
*
* @param ins bt instance.
* @param cookie cookie of cs event callback.
* @return true if success, false otherwise.
*/
bool BTSYMBOLS(bt_cs_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief start distance measurement
*
* start distance measurement.
*
* @param ins bt instance.
* @param params distance measurement parameters.
* @return bt_status_t.
*/
bt_status_t BTSYMBOLS(bt_cs_start_distance_measurement)(bt_instance_t* ins, const bt_distance_measurement_params_t* params);
/**
* @brief stop distance measurement
*
* stop distance measurement.
*
* @param ins bt instance.
* @param addr remote device address.
* @param method method of distance measurement.
* @param timeout timeout flag.
* @return bt_status_t.
*/
bt_status_t BTSYMBOLS(bt_cs_stop_distance_measurement)(bt_instance_t* ins, bt_address_t* addr, uint8_t method, bool timeout);
/**
* @brief get max supported security level
*
* get max supported security level of remote device.
*
* @param ins bt instance.
* @param addr remote device address.
* @return bt_status_t.
*/
bt_status_t BTSYMBOLS(bt_get_cs_max_supported_security_level)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief RAS feature bits for ras_feature field
*/
#define BT_CS_RAS_REAL_TIME_RANGING_DATA 0x01 /**< Bit 0: Real-time Ranging Data */
#define BT_CS_RAS_RETRIEVE_LOST_DATA_SEGMENTS 0x02 /**< Bit 1: Retrieve Lost Ranging Data Segments */
#define BT_CS_RAS_ABORT_OPERATION 0x04 /**< Bit 2: Abort Operation */
#define BT_CS_RAS_FILTER_RANGING_DATA 0x08 /**< Bit 3: Filter Ranging Data */
/**
* @brief CS_SYNC antenna selection values
*/
#define BT_CS_ANTENNA_SEL_1 0x01 /**< Use antenna identifier 1 */
#define BT_CS_ANTENNA_SEL_2 0x02 /**< Use antenna identifier 2 */
#define BT_CS_ANTENNA_SEL_3 0x03 /**< Use antenna identifier 3 */
#define BT_CS_ANTENNA_SEL_4 0x04 /**< Use antenna identifier 4 */
#define BT_CS_ANTENNA_SEL_SINGLE_REPEATE 0xFD /**< Antenna identifiers in repetitive order (0x01, 0x01, ..., Num_Antennae_Supported, Num_Antennae_Supported) */
#define BT_CS_ANTENNA_SEL_DOUBLE_REPEATE 0xFE /**< Antenna identifiers in repetitive order from 0x01 to Num_Antennae_Supported */
#define BT_CS_ANTENNA_SEL_NO_RECOMMEND 0xFF /**< Host does not have a recommendation */
/**
* @brief CS configuration parameters for set command
*/
typedef struct {
uint32_t ras_feature; /**< RAS feature bits: Bit 0 (0x01): Real-time Ranging Data,
Bit 1 (0x02): Retrieve Lost Ranging Data Segments,
Bit 2 (0x04): Abort Operation,
Bit 3 (0x08): Filter Ranging Data */
uint8_t role; /**< CS role bits: Bit 0 (0x01): initiator, Bit 1 (0x02): reflector */
uint8_t cs_sync_antenna_selection; /**< Antenna selection for CS_SYNC packets, see BT_CS_ANTENNA_SEL_* macros */
int8_t max_tx_power; /**< Maximum TX power in dBm (-127 to 20) */
} bt_cs_set_params_t;
/**
* @brief set CS configuration
*
* set CS configuration including RAS feature and default settings.
*
* @param ins bt instance.
* @param addr remote device address.
* @param params CS configuration parameters, see @ref bt_cs_set_params_t.
* @return bt_status_t.
*/
bt_status_t BTSYMBOLS(bt_cs_set_config)(bt_instance_t* ins, bt_address_t* addr, const bt_cs_set_params_t* params);
#ifdef CONFIG_BT_CS_RAS_TEST
/**
* @brief test function
*
* test function.
*
* @param ins bt instance.
* @param data test subevent result data.
* @param len length of test data.
* @return bt_status_t.
* @note only for test.
*/
bt_status_t BTSYMBOLS(bt_cs_test)(bt_instance_t* ins, const void* data, uint16_t len);
#endif /* CONFIG_BT_CS_RAS_TEST */
#endif /* __BT_CS_H__ */

View File

@ -755,25 +755,6 @@ if (bt_device_connect(ins, &addr) == BT_STATUS_SUCCESS) {
*/
bt_status_t BTSYMBOLS(bt_device_connect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Connect to peer device with specific Profiles. And open reconnect method.
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.if addr is NULL, connect last device in bonded list.
* @param transport - transport type (0:BLE, 1:BREDR).
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
if (bt_device_background_connect(ins, &addr, BT_TRANSPORT_BREDR) == BT_STATUS_SUCCESS) {
// connection initiated successfully
} else {
// Handle error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_device_background_connect)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Disconnect from a remote device.
*
@ -794,25 +775,6 @@ if (bt_device_disconnect(ins, &addr) == BT_STATUS_SUCCESS) {
*/
bt_status_t BTSYMBOLS(bt_device_disconnect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect specific prfoiles.
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param transport - transport type (0:BLE, 1:BREDR).
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
if (bt_device_background_disconnect(ins, &addr, BT_TRANSPORT_BREDR) == BT_STATUS_SUCCESS) {
// Disconnection initiated successfully
} else {
// Handle error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_device_background_disconnect)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Connect to a remote LE device.
*
@ -885,65 +847,29 @@ void BTSYMBOLS(bt_device_connect_all_profile)(bt_instance_t* ins, bt_address_t*
void BTSYMBOLS(bt_device_disconnect_all_profile)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Enable connection enhanced mode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param mode - enhanced mode.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
* @brief Enable enhanced mode for a connection.
*
* Enables an enhanced mode (e.g., eSCO, sniff mode) for a connection with a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param mode - Enhanced mode to enable, see @ref bt_enhanced_mode_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*/
bt_status_t BTSYMBOLS(bt_device_enable_enhanced_mode)(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode);
/**
* @brief Disable connection enhanced mode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param mode - enhanced mode.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
* @brief Disable enhanced mode for a connection.
*
* Disables an enhanced mode (e.g., eSCO, sniff mode) for a connection with a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param mode - Enhanced mode to disable, see @ref bt_enhanced_mode_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*/
bt_status_t BTSYMBOLS(bt_device_disable_enhanced_mode)(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode);
// async
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#include "bt_async.h"
typedef void (*bt_device_get_bond_state_cb_t)(bt_instance_t* ins, bt_status_t status, bond_state_t bstate, void* userdata);
typedef void (*bt_device_get_address_type_cb_t)(bt_instance_t* ins, bt_status_t status, ble_addr_type_t atype, void* userdata);
bt_status_t bt_device_get_identity_address_async(bt_instance_t* ins, bt_address_t* bd_addr, bt_address_cb_t cb, void* userdata);
bt_status_t bt_device_get_address_type_async(bt_instance_t* ins, bt_address_t* addr, bt_device_get_address_type_cb_t cb, void* userdata);
bt_status_t bt_device_get_device_type_async(bt_instance_t* ins, bt_address_t* addr, bt_device_type_cb_t cb, void* userdata);
bt_status_t bt_device_get_name_async(bt_instance_t* ins, bt_address_t* addr, bt_string_cb_t cb, void* userdata);
bt_status_t bt_device_get_device_class_async(bt_instance_t* ins, bt_address_t* addr, bt_u32_cb_t cb, void* userdata);
bt_status_t bt_device_get_uuids_async(bt_instance_t* ins, bt_address_t* addr, bt_uuids_cb_t cb, void* userdata);
bt_status_t bt_device_get_appearance_async(bt_instance_t* ins, bt_address_t* addr, bt_u16_cb_t cb, void* userdata);
bt_status_t bt_device_get_rssi_async(bt_instance_t* ins, bt_address_t* addr, bt_s8_cb_t cb, void* userdata);
bt_status_t bt_device_get_alias_async(bt_instance_t* ins, bt_address_t* addr, bt_string_cb_t cb, void* userdata);
bt_status_t bt_device_set_alias_async(bt_instance_t* ins, bt_address_t* addr, const char* alias, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_is_connected_async(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_device_is_encrypted_async(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_device_is_bond_initiate_local_async(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_device_get_bond_state_async(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport, bt_device_get_bond_state_cb_t cb, void* userdata);
bt_status_t bt_device_is_bonded_async(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_device_connect_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_disconnect_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_connect_le_async(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t type, ble_connect_params_t* param, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_disconnect_le_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_connect_request_reply_async(bt_instance_t* ins, bt_address_t* addr, bool accept, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_connect_all_profile_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_disconnect_all_profile_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_set_le_phy_async(bt_instance_t* ins, bt_address_t* addr, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_create_bond_async(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_remove_bond_async(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_cancel_bond_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_pair_request_reply_async(bt_instance_t* ins, bt_address_t* addr, bool accept, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_set_pairing_confirmation_async(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_set_pin_code_async(bt_instance_t* ins, bt_address_t* addr, bool accept, char* pincode, int len, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_set_pass_key_async(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept, uint32_t passkey, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_set_le_legacy_tk_async(bt_instance_t* ins, bt_address_t* addr, bt_128key_t tk_val, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_set_le_sc_remote_oob_data_async(bt_instance_t* ins, bt_address_t* addr, bt_128key_t c_val, bt_128key_t r_val, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_get_le_sc_local_oob_data_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -23,6 +23,8 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
#include "bt_uuid.h"
/**
* @cond
*/
@ -145,23 +147,22 @@ typedef enum {
/* GATT_H_DESCRIPTOR */
#define GATT_H_CEPD(_value, _length, _handle) \
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(0x2900), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(BT_UUID_GATT_CEPD), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
/* GATT_H_DESCRIPTOR */
#define GATT_H_CUDD(_value, _length, _handle) \
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(0x2901), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(BT_UUID_GATT_CUDD), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
/* GATT_H_DESCRIPTOR */
#define GATT_H_CCCD(_perm, _change, _handle) \
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(0x2902), _perm, ATTR_AUTO_RSP_CCC_READ, NULL, _change, NULL, 0, _handle)
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(BT_UUID_GATT_CCCD), _perm, ATTR_AUTO_RSP_CCC_READ, NULL, _change, NULL, 0, _handle)
/* GATT_H_DESCRIPTOR for CCCD with user response (APP handles read/write) */
#define GATT_H_CCCD_USER_RSP(_perm, _read, _write, _handle) \
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(0x2902), _perm, ATTR_RSP_BY_APP, _read, _write, NULL, 0, _handle)
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(BT_UUID_GATT_CCCD), _perm, ATTR_RSP_BY_APP, _read, _write, NULL, 0, _handle)
/* GATT_H_DESCRIPTOR */
#define GATT_H_CPFD(_value, _length, _handle) \
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(0x2904), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(BT_UUID_GATT_CPFD), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
/**
* @endcond

View File

@ -133,11 +133,10 @@ typedef void (*bt_gattc_feature_delete_client_cb_t)(bt_instance_t* ins, gatt_sta
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
* @param services Array of discovered services (pointer array).
* @param count Number of services in the array.
* @param service Retrieved service (single entry).
*/
typedef void (*bt_gattc_feature_get_service_cb_t)(bt_instance_t* ins, gatt_status_t status, gattc_handle_t conn_handle,
const gatt_service_t* services[], size_t count);
const gatt_service_t* service);
/**
* @brief Read characteristic callback.
@ -233,13 +232,13 @@ bt_status_t bt_gattc_feature_create_client_async(bt_instance_t* ins, bt_address_
/**
* @brief Delete GATT client.
* @param ins Bluetooth instance.
* @param conn_handle Connection handle (from create).
* @param cb Async call status callback.
* @param userdata User context.
* @param ins Bluetooth instance.
* @param addr Remote device address.
* @param cb Delete completion callback.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_delete_client_async(bt_instance_t* ins, gattc_handle_t conn_handle,
bt_status_t bt_gattc_feature_delete_client_async(bt_instance_t* ins, bt_address_t* addr,
bt_gattc_feature_delete_client_cb_t cb, void* userdata);
/**

View File

@ -28,10 +28,6 @@ extern "C" {
#include "bt_uuid.h"
#include <stddef.h>
/**
* @cond
*/
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
@ -47,300 +43,20 @@ typedef struct {
} gatt_attr_desc_t;
/**
* @endcond
*/
/**
* @brief callback for connected as GATT client.
*
* This callback is triggered when gattc connected. BT Service use this callback to notify the application calling
* bt_gattc_connect that gattc connection has been established.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param addr - remote device address.
* @return void.
*
* **Example:**
* @code
static void connect_callback(void* conn_handle, bt_address_t* addr)
{
gattc_device_t* device = find_gattc_device(conn_handle);
assert(device);
memcpy(&device->remote_address, addr, sizeof(bt_address_t));
device->conn_state = CONNECTION_STATE_CONNECTED;
PRINT_ADDR("gattc_connect_callback, addr:%s", addr);
}
* @endcode
*/
typedef void (*gattc_connected_cb_t)(gattc_handle_t conn_handle, bt_address_t* addr);
/**
* @brief callback for disconnected as GATT client.
*
* This callback is triggered when gattc disconnected. BT Service use this callback to notify the application that
* the gattc connection is destroyed.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param addr - remote device address.
* @return void.
*
* **Example:**
* @code
static void disconnect_callback(void* conn_handle, bt_address_t* addr)
{
gattc_device_t* device = find_gattc_device(conn_handle);
assert(device);
device->conn_state = CONNECTION_STATE_DISCONNECTED;
PRINT_ADDR("gattc_disconnect_callback, addr:%s", addr);
}
* @endcode
*/
typedef void (*gattc_disconnected_cb_t)(gattc_handle_t conn_handle, bt_address_t* addr);
/**
* @brief callback for GATT client execute Services discover operation.
*
* This callback is triggered when application initiating service discovery procedure to peer GATT server.
* BT Service use this callback to report the result of attributes.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param uuid - uuid of the attribute. uuid == NULL or uuid->type == 0 means discovery procedure completed.
* @param start_handle - start handle of Primary services(Secondary services).
* @param end_handle - end handle of Primary services(Secondary services).
* @return void.
*
* **Example:**
* @code
static void discover_callback(void* conn_handle, gatt_status_t status, bt_uuid_t* uuid, uint16_t start_handle, uint16_t end_handle)
{
PRINT("gattc_discover_callback result, attr_handle: 0x%04x - 0x%04x", start_handle, end_handle);
}
* @endcode
*/
typedef void (*gattc_discover_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, bt_uuid_t* uuid, uint16_t start_handle, uint16_t end_handle);
/**
* @brief callback for GATT client excute Exchange MTU operation.
*
* This callback is triggered when application initiating Exchange MTU procedure to peer GATT server.
* BT Service use this callback to Report the results of MTU negotiation.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param mtu - negotiated MTU.
* @return void.
*
* **Example:**
* @code
static void mtu_updated_callback(void* conn_handle, gatt_status_t status, uint32_t mtu)
{
gattc_device_t* device = find_gattc_device(conn_handle);
assert(device);
if (status == GATT_STATUS_SUCCESS) {
device->gatt_mtu = mtu;
}
PRINT("gattc_mtu_updated_callback, status:%d, mtu:%" PRIu32, status, mtu);
}
* @endcode
*/
typedef void (*gattc_mtu_updated_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint32_t mtu);
/**
* @brief callback for GATT client excute attribute read operation.
*
* This callback is triggered when application initiating read procedure to peer GATT server.
* BT Service use this callback to Report the attribute value of corresponding attribute.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param attr_handle - attribute handle.
* @param value - attribute value.
* @param length - attribute value length.
* @return void.
*
* **Example:**
* @code
static void read_complete_callback(void* conn_handle, gatt_status_t status, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
PRINT("gattc connection read complete, handle 0x%" PRIx16 ", status:%d", attr_handle, status);
}
* @endcode
*/
typedef void (*gattc_read_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint16_t attr_handle, uint8_t* value, uint16_t length);
/**
* @brief callback for GATT client excute attribute read operation.
*
* This callback is triggered when application initiating write procedure to peer GATT server.
* BT Service use this callback to Report the status of write procedure to corresponding attribute.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param attr_handle - attribute handle.
* @return void.
*
* **Example:**
* @code
static void write_complete_callback(void* conn_handle, gatt_status_t status, uint16_t attr_handle)
{
if (status != GATT_STATUS_SUCCESS) {
PRINT("gattc connection write failed, handle 0x%" PRIx16 ", status:%d", attr_handle, status);
return;
}
if (throughtput_cursor) {
throughtput_cursor--;
} else {
PRINT("gattc connection write complete, handle 0x%" PRIx16 ", status:%d", attr_handle, status);
}
}
* @endcode
*/
typedef void (*gattc_write_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint16_t attr_handle);
/**
* @brief callback for GATT client excute enable/disable cccd operation.
*
* This callback is triggered when application initiating enable/disable to corresponding cccd.
* BT Service use this callback to Report the value of corresponding cccd.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param attr_handle - attribute handle.
* @param enable - enable/disable flag.
* @return void.
*
* **Example:**
* @code
static void subscribe_complete_callback(void* conn_handle, gatt_status_t status, uint16_t attr_handle, bool enable)
{
PRINT("gattc connection subscribe complete, handle 0x%" PRIx16 ", status:%d, enable:%d", attr_handle, status, enable);
}
* @endcode
*/
typedef void (*gattc_subscribe_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint16_t attr_handle, bool enable);
/**
* @brief callback for GATT client recv notification/indication from peer GATT server.
*
* This callback is triggered when Peer GATT Server initiating notify/indicate procedure. BT Service use this callback
* to Report the notify/indicate value received.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param attr_handle - attribute handle.
* @param value - notify/indicate value.
* @param length - notify/indicate value length.
* @return void.
*
* **Example:**
* @code
static void notify_received_callback(void* conn_handle, uint16_t attr_handle,
uint8_t* value, uint16_t length)
{
PRINT("gattc connection receive notify, handle 0x%" PRIx16, attr_handle);
}
* @endcode
*/
typedef void (*gattc_notify_cb_t)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
/**
* @brief callback for GATT client execute read PHY.
*
* This callback is triggered when application initiating read PHY procedure. BT Service use this callback to Report
* the Tx PHY & Rx PHY.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param tx_phy - current Tx PHY.
* @param rx_phy - current Rx PHY.
* @return void.
*
* **Example:**
* @code
static void phy_read_callback(void* conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy)
{
PRINT("gattc read phy complete, tx:%d, rx:%d", tx_phy, rx_phy);
}
* @endcode
*/
typedef void (*gattc_phy_read_cb_t)(gattc_handle_t conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
/**
* @brief callback for GATT client execute update PHY operation.
*
* This callback is triggered when application initiating update PHY procedure. BT Service use this callback to Report
* the result of update Tx PHY & Rx PHY.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param tx_phy - Tx PHY after update. If update operation failed, keep original value.
* @param rx_phy - Rx PHY after update. If update operation failed, keep original value.
* @return void.
*
* **Example:**
* @code
static void phy_updated_callback(void* conn_handle, gatt_status_t status, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy)
{
PRINT("gattc_phy_updated_callback, status:%d, tx:%d, rx:%d", status, tx_phy, rx_phy);
}
* @endcode
*/
typedef void (*gattc_phy_updated_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
/**
* @brief callback for GATT client execute read RSSI of remote device.
*
* This callback is triggered when application initiating read remote RSSI procedure. BT Service use this callback to
* Report the RSSI of remote device.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param RSSI - value of remote RSSI.
* @return void.
*
* **Example:**
* @code
static void rssi_read_callback(void* conn_handle, gatt_status_t status, int32_t rssi)
{
PRINT("gattc read rssi complete, status:%d, rssi:%" PRIi32, status, rssi);
}
* @endcode
*/
typedef void (*gattc_rssi_read_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, int32_t rssi);
/**
* @brief callback for GATT client execute connnection parameter update operation.
*
* This callback is triggered when application initiating connnection parameter update procedure. BT Service use this
* callback to Report the connection parameter.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param connection_interval - connection interval(n * 1.25ms).
* @param peripheral_latency - peripheral latency.
* @param supervision_timeout - supervision timeout(n * 10ms).
* @return void.
*
* **Example:**
* @code
static void conn_param_updated_callback(void* conn_handle, bt_status_t status, uint16_t connection_interval,
uint16_t peripheral_latency, uint16_t supervision_timeout)
{
PRINT("gattc connection paramter updated, status:%d, interval:%" PRIu16 ", latency:%" PRIu16 ", timeout:%" PRIu16,
status, connection_interval, peripheral_latency, supervision_timeout);
}
* @endcode
*/
typedef void (*gattc_connection_parameter_updated_cb_t)(gattc_handle_t conn_handle, bt_status_t status, uint16_t connection_interval,
uint16_t peripheral_latency, uint16_t supervision_timeout);
/**
* @cond
*/
typedef struct {
uint32_t size;
gattc_connected_cb_t on_connected;
@ -357,368 +73,24 @@ typedef struct {
gattc_connection_parameter_updated_cb_t on_conn_param_updated;
} gattc_callbacks_t;
/**
* @endcond
*/
/**
* @brief create a gatt client.
*
* This function is used to create a gatt client.
*
* @param ins - Bluetooth client instance.
* @param phandle - pointer of gattc connection handle(void*).
* @param callbacks - gattc callback table.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_create_connect(handle, &g_gattc_devies[conn_id].handle, &gattc_cbs) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_create_connect)(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks);
/**
* @brief delete a gatt client.
*
* This function is used to delete a gatt client.
*
* @param conn_handle - gattc connection handle(void*).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_delete_connect(g_gattc_devies[conn_id].handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_delete_connect)(gattc_handle_t conn_handle);
/**
* @brief create a ATT bearer with peer device.
*
* This function is used to establish a ATT bearer.
*
* @param conn_handle - gattc connection handle(void*).
* @param addr - peer bluetooth device address.
* @param addr_type - peer address type(ble_addr_type_t).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_connect(g_gattc_devies[conn_id].handle, &addr, BT_LE_ADDR_TYPE_UNKNOWN) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_connect)(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type);
/**
* @brief dicconnect ATT bearer.
*
* This function is used to initiate a disconnection.
*
* @param conn_handle - gattc connection handle(void*).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_disconnect(g_gattc_devies[conn_id].handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_disconnect)(gattc_handle_t conn_handle);
/**
* @brief discover all GATT services or service with specific UUIDs on peer GATT Server.
*
* This function is used to discover GATT services. If filter_uuid is NULL, all services will be discovered.
*
* @param conn_handle - gattc connection handle(void*).
* @param filter_uuid - UUID of service to be discovered. filter_uuid is NULL for discover all service of peer device
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_discover_service(g_gattc_devies[conn_id].handle, NULL) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_discover_service)(gattc_handle_t conn_handle, bt_uuid_t* filter_uuid);
/**
* @brief get attribute by specific Attribute handle.
*
* This function is used to get attribute by specific Attribute handle, which is stored after Discover Services procedure.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle being found.
* @param attr_desc - attribute structure(Type, handle, UUID, property). The desired result is stored in this pointer.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_get_attribute_by_handle(conn_handle, attr_handle, &attr_desc) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_get_attribute_by_handle)(gattc_handle_t conn_handle, uint16_t attr_handle, gatt_attr_desc_t* attr_desc);
/**
* @brief get attribute by specific UUID.
*
* This function is used to get attribute by specific handle, which is stored after Discover Services procedure.
*
* @param conn_handle - gattc connection handle(void*).
* @param start_handle - start of the Attribute handle range being found.
* @param end_handle - end of the Attribute handle range being found.
* @param attr_uuid - attribute UUID being found.
* @param attr_desc - attribute structure(Type, handle, UUID, property). The desired result is stored in this pointer.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_get_attribute_by_handle(conn_handle, start_handle, end_handle &attr_desc.uuid, &attr_desc) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_get_attribute_by_uuid)(gattc_handle_t conn_handle, uint16_t start_handle, uint16_t end_handle, bt_uuid_t* attr_uuid, gatt_attr_desc_t* attr_desc);
/**
* @brief read attribute value by specific handle.If This Attribute's permissions is readable
*
* This function is used to read a attribute value by specific handle. This function will initiate a ATT Read Request procedure.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle being read.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_read(g_gattc_devies[conn_id].handle, attr_handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_read)(gattc_handle_t conn_handle, uint16_t attr_handle);
/**
* @brief write data to a specific attribute. If This Attribute's permissions is Writable
*
* This function is used to write data to a specific attribute. This function will initiate a ATT write Request procedure.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle being written.
* @param value - data to be written.
* @param length - the length of value.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_write_without_response(g_gattc_devies[conn_id].handle, attr_handle, value, len) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_write)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
/**
* @brief write data to a specific attribute. If Write Without Response flag of This Attribute's property is set to 1
*
* This function is used to write data to a specific attribute. This function will initiate a ATT write command procedure.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle being written.
* @param value - data to be written.
* @param length - the length of value.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_write_without_response(g_gattc_devies[conn_id].handle, attr_handle, value, len) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_write_without_response)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
/**
* @brief Write data to a specific attribute (Signed Write Without Response).
*
* This function writes data to a specific attribute handle using the
* ATT "Signed Write Command" procedure. It should be used when the
* attribute's properties include the `GATT_PROPERTY_SIGNED_WRITE` flag.
*
* Unlike a normal Write Without Response, this procedure includes a
* signature to provide authentication of the write operation.
*
* @param conn_handle GATT client connection handle (void*).
* @param attr_handle Attribute handle being written.
* @param value Pointer to the buffer containing the data to write.
* @param length Length of the data buffer.
*
* @return bt_status_t
* - BT_STATUS_SUCCESS on success,
* - Other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_write_with_signed(g_gattc_devices[conn_id].handle,
attr_handle, value, len) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_write_with_signed)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
/**
* @brief enable a centain CCCD(Client Characteristic Configuration Description).
*
* This function is used to enable CCCD. Once enabled, it can receive Indication and Notification
* from the Server successfully.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle of the characteristic you want to enable CCCD.
* @param ccc_value - bit 0 is used to enable Notification, bit 1 is used to enable Indication.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_subscribe(g_gattc_devies[conn_id].handle, attr_handle, ccc_value) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_subscribe)(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value);
/**
* @brief disable a centain CCCD(Client Characteristic Configuration Description).
*
* This function is used to disable CCCD. Once disable, it cannot receive Indication and Notification
* from the Server.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle of the characteristic you want to disable CCCD.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_unsubscribe(g_gattc_devies[conn_id].handle, attr_handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_unsubscribe)(gattc_handle_t conn_handle, uint16_t attr_handle);
/**
* @brief exchange ATT_MTU.
*
* This function is used to initiate an ATT_MTU negotiation, which will initiate a Exchcange MTU procedure.
* In Bluetooth Core Spec, this procedure can be initiated once per connection. If it is initiated more than
* once, BT_STATUS_FAIL will be returned.
*
* @param conn_handle - gattc connection handle(void*).
* @param mtu - MTU size.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_exchange_mtu(g_gattc_devies[conn_id].handle, mtu) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_exchange_mtu)(gattc_handle_t conn_handle, uint32_t mtu);
/**
* @brief Modify BLE connection parameters.
*
* This function is used to modify BLE connection parameters.
* Note: The following conditions must be met:
* min_interval <= max_interval.
* min_connection_event_length <= max_connection_event_length.
* timeout > (1 + latency) * max_interval * 2
*
* @param conn_handle - gattc connection handle(void*).
* @param min_interval - min connection interval(n * 1.25ms).
* @param max_interval - max connection interval(n * 1.25ms).
* @param latency - peripheral latency.
* @param timeout - supervision timeout(n * 10ms).
* @param min_connection_event_length - min connection event length(n * 0.625ms).
* @param max_connection_event_length - max connection event length(n * 0.625ms).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_update_connection_parameter(g_gattc_devies[conn_id].handle, min_interval, max_interval, latency,
timeout, min_connection_event_length, max_connection_event_length)
!= BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_update_connection_parameter)(gattc_handle_t conn_handle, uint32_t min_interval, uint32_t max_interval,
uint32_t latency, uint32_t timeout, uint32_t min_connection_event_length,
uint32_t max_connection_event_length);
/**
* @brief read Tx & Rx PHY.
*
* This function is used to read PHY.(1M, 2M, Coded)
*
* @param conn_handle - gattc connection handle(void*).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_read_phy(g_gattc_devies[conn_id].handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_read_phy)(gattc_handle_t conn_handle);
/**
* @brief update PHY.
*
* This function is used to update PHY type(1M, 2M, Coded).
*
* @param conn_handle - gattc connection handle(void*).
* @param tx_phy - Tx PHY type wants to update.
* @param rx_phy - Rx PHY type wants to update.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_update_phy(g_gattc_devies[conn_id].handle, tx, rx) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_update_phy)(gattc_handle_t conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
/**
* @brief read RSSI.
*
* This function is used to read RSSI value.
*
* @param conn_handle - gattc connection handle(void*).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_read_rssi(g_gattc_devies[conn_id].handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_read_rssi)(gattc_handle_t conn_handle);
// async

View File

@ -120,6 +120,11 @@ typedef enum {
HFP_ROAM_STATE_ROAMING,
} hfp_roaming_state_t;
typedef enum {
HFP_HF_SERVICE_VOICE = 4,
HFP_HF_SERVICE_FAX = 5,
} hfp_subscriber_number_service_t;
/**
* @endcond
*/

View File

@ -284,6 +284,29 @@ void hfp_ag_at_cmd_received_cb(void* cookie, bt_address_t* addr, const char* at_
*/
typedef void (*hfp_ag_at_cmd_received_callback)(void* cookie, bt_address_t* addr, const char* at_command);
/**
* @brief Callback for HFP AG received vendor specific AT command.
*
* This callback is used to notify the application of the vendor specific AT command. During
* HFP AG initialization, callback functions will be registered. This callback will be triggered
* when AG receives a vendor specific AT command.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
* @param command - The prefix of the AT command.
* @param company_id - Bluetooth company ID.
* @param value - AT command value.
*
* **Example:**
* @code
void hfp_ag_vend_spec_at_cmd_received_cb(void* cookie, bt_address_t* addr, const char* command, uint16_t company_id, const char* value)
{
printf("hfp_ag_vend_spec_at_cmd_received_cb, command: %s, company_id: %d, value: %s\n", command, company_id, value);
}
* @endcode
*/
typedef void (*hfp_ag_vend_spec_at_cmd_received_callback)(void* cookie, bt_address_t* addr, const char* command, uint16_t company_id, const char* value);
/**
* @brief HFP CLCC command received callback
*
@ -320,17 +343,6 @@ typedef void (*hfp_ag_cind_cmd_received_callback)(void* cookie, bt_address_t* ad
* @cond
*/
/**
* @brief HFP vendor specific AT command received callback
*
* @param cookie - callback cookie.
* @param command - The prefix of the AT command.
* @param company_id - Bluetooth company ID.
* @param value - AT command value.
* @param addr - address of peer HF device.
*/
typedef void (*hfp_ag_vend_spec_at_cmd_received_callback)(void* cookie, bt_address_t* addr, const char* command, uint16_t company_id, const char* value);
/**
* @brief HFP AG callback structure
*
@ -395,7 +407,7 @@ void app_init_hfp_ag(bt_instance_t* ins)
else
printf("register callbacks success\n");
}
* @endcode
* @endcode
*/
void* BTSYMBOLS(bt_hfp_ag_register_callbacks)(bt_instance_t* ins, const hfp_ag_callbacks_t* callbacks);
@ -834,7 +846,7 @@ int app_send_specific_volume_control(bt_instance_t* ins, bt_address_t* addr);
bt_status_t BTSYMBOLS(bt_hfp_ag_volume_control)(bt_instance_t* ins, bt_address_t* addr, hfp_volume_type_t type, uint8_t volume);
/**
* @brief Send an AT Command to HF device [Deprecated].
* @brief Send an AT Command to HF device.
*
* This function is used to send specific AT commands to the specified HF device. The
* address parameter is used to specify the peer HF device.
@ -864,6 +876,36 @@ int app_send_specific_at_command(bt_instance_t* ins, bt_address_t* addr);
*/
bt_status_t BTSYMBOLS(bt_hfp_ag_send_at_command)(bt_instance_t* ins, bt_address_t* addr, const char* at_command);
/**
* @brief Send a vendor specific AT Command
*
* This function is used to send specific vendor AT commands to the specified HF device. The
* address parameter is used to specify the peer HF device.
*
* @param ins - The Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param command - The prefix of the AT command to be send.
* @param value - The value of the AT command to be send.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
int app_send_specific_at_command(bt_instance_t* ins, bt_address_t* addr);
{
bt_status_t status;
char at_command[] = "+XIAOMI";
char value[] = "123456";
status = bt_hfp_ag_send_at_command(ins, addr, at_command, value);
if (status != BT_STATUS_SUCCESS)
printf("send AT command failed\n");
return status;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_hfp_ag_send_vendor_specific_at_command)(bt_instance_t* ins, bt_address_t* addr, const char* command, const char* value);
/**
* @brief Send CLCC Response
*
@ -908,17 +950,6 @@ bt_status_t BTSYMBOLS(bt_hfp_ag_send_clcc_response)(bt_instance_t* ins, bt_addre
uint32_t index, hfp_call_direction_t dir, hfp_ag_call_state_t state, hfp_call_mode_t mode,
hfp_call_mpty_type_t mpty, hfp_call_addrtype_t type, const char* number);
/**
* @brief Send vendor specific AT Command
*
* @param ins - bluetooth client instance.
* @param addr - address of peer HF device.
* @param command - the prefix of the AT command to be send.
* @param value - the value of the AT command to be send.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_hfp_ag_send_vendor_specific_at_command)(bt_instance_t* ins, bt_address_t* addr, const char* command, const char* value);
/**
* @brief Send CIND Response
*

View File

@ -69,15 +69,6 @@ typedef struct {
char name[HFP_NAME_DIGITS_MAX];
} hfp_current_call_t;
/**
* @brief HFP subscriber number service
*/
typedef enum {
HFP_HF_SERVICE_UNKNOWN = 0,
HFP_HF_SERVICE_VOICE,
HFP_HF_SERVICE_FAX,
} hfp_subscriber_number_service_t;
/**
* @endcond
*/
@ -396,35 +387,8 @@ void hfp_hf_callheld_cb(void* cookie, bt_address_t* addr, hfp_callheld_t callhel
* @endcode
*/
typedef void (*hfp_hf_callheld_callback)(void* cookie, bt_address_t* addr, hfp_callheld_t callheld);
/**
* @brief HFP HF get subscriber number callback.
*
* @param cookie - callback cookie.
* @param addr - address of peer AG device.
* @param number - phone number.
* @param service - indicates which service this phone number relates to.
*/
typedef void (*hfp_hf_subscriber_number_callback)(void* cookie, bt_address_t* addr, const char* number, hfp_subscriber_number_service_t service);
/**
* @brief HFP HF +clip callback.
*
* @param cookie - callback cookie.
* @param addr - address of peer AG device.
* @param number - the number of call.
* @param name - the name of call.
*/
typedef void (*hfp_hf_clip_callback)(void* cookie, bt_address_t* addr, const char* number, const char* name);
/**
* @brief HFP HF query current calls callback.
*
* @param cookie - callback cookie.
* @param addr - address of peer AG device.
* @param num - number of current calls.
* @param calls - list of current calls.
*/
typedef void (*hfp_hf_subscriber_number_callback)(void* cookie, bt_address_t* addr, const char* number, hfp_subscriber_number_service_t service);
typedef void (*hfp_hf_query_current_calls_callback)(void* cookie, bt_address_t* addr, uint8_t num, hfp_current_call_t* calls);
/**
@ -1189,21 +1153,8 @@ int app_send_dtmf(bt_instance_t* ins, bt_address_t* addr, char dtmf);
*/
bt_status_t BTSYMBOLS(bt_hfp_hf_send_dtmf)(bt_instance_t* ins, bt_address_t* addr, char dtmf);
/**
* @brief Get Subscriber Number
*
* @param ins - bluetooth client instance.
* @param addr - address of peer AG device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_hfp_hf_get_subscriber_number)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Query Current Calls With Callback
*
* @param ins - bluetooth client instance.
* @param addr - address of peer AG device.
*/
bt_status_t BTSYMBOLS(bt_hfp_hf_query_current_calls_with_callback)(bt_instance_t* ins, bt_address_t* addr);
#ifdef __cplusplus

View File

@ -124,14 +124,15 @@ typedef enum {
* @endcond
*/
/**
* @brief HID device application state callback.
*
* Callback function invoked when the HID application state changes. This callback
* is used to notify the HID device about the state transition in interaction
* is used to notify the HID device about the state transition in interaction
* with the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param state - New HID application state, see @ref hid_app_state_t.
*
@ -149,10 +150,10 @@ typedef void (*hidd_app_state_callback)(void* cookie, hid_app_state_t state);
* @brief HID device connection state callback.
*
* Callback function invoked when the HID connection state changes. This callback
* is used to notify the HID device about connection state changes with the remote
* is used to notify the HID device about connection state changes with the remote
* HID host.
*
* @param cookie - `remote_callback_t*`.
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @param le_hid - TRUE if the connection is over LE; FALSE if over BR/EDR.
@ -174,7 +175,7 @@ typedef void (*hidd_connection_state_callback)(void* cookie, bt_address_t* addr,
*
* Callback function invoked when a GET_REPORT request is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @param rpt_type - Report type, see @ref hid_report_type_t.
@ -198,7 +199,7 @@ typedef void (*hidd_get_report_callback)(void* cookie, bt_address_t* addr, uint8
*
* Callback function invoked when a SET_REPORT request is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @param rpt_type - Report type, see @ref hid_report_type_t.
@ -222,7 +223,7 @@ typedef void (*hidd_set_report_callback)(void* cookie, bt_address_t* addr, uint8
*
* Callback function invoked when an INPUT report is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @param rpt_type - Report type, see @ref hid_report_type_t.
@ -246,7 +247,7 @@ typedef void (*hidd_receive_report_callback)(void* cookie, bt_address_t* addr, u
*
* Callback function invoked when a virtual cable unplug request is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param addr - Address of the peer device, see @ref bt_address_t.
*

View File

@ -26,8 +26,6 @@ extern "C" {
#define BTSYMBOLS(s) s
#endif
#define INVALID_L2CAP_LISTEN_ID 0xFFFF
enum {
LE_PSM_DYNAMIC_MIN = 0x0080,
LE_PSM_DYNAMIC_MAX = 0x00FF,
@ -52,21 +50,16 @@ typedef struct {
uint16_t mtu; /* Maximum Transmission Unit */
uint16_t le_mps; /* Maximum PDU payload Size for LE */
uint16_t init_credits; /* initial credits for LE */
uint16_t id; /* L2CAP Service socket id */
char proxy_name[16]; /* Proxy name */
} l2cap_config_option_t;
typedef struct {
bt_address_t addr;
bt_transport_t transport;
uint16_t cid; /* Local channel id. */
uint16_t cid; /* Channel id. */
uint16_t psm; /* Dynamic Service PSM */
uint16_t incoming_mtu; /* Incoming transmit MTU. */
uint16_t outgoing_mtu; /* Outgoing transmit MTU */
uint16_t id; /* Connected L2CAP Channel socket id */
// for L2CAP listen only.
uint16_t listen_id; /* New L2CAP Listen socket id, INVALID_L2CAP_LISTEN_ID indicates invalid */
char proxy_name[16]; /* Proxy name for server */
uint16_t outgoing_mtu; /* outgoing transmit MTU */
const char* pty_name; /* pty device name, like "/dev/pts/0" */
} l2cap_connect_params_t;
/**
@ -82,10 +75,10 @@ typedef void (*l2cap_connected_callback_t)(void* cookie, l2cap_connect_params_t*
*
* @param cookie - callbacks cookie, the return value of bt_l2cap_register_callbacks.
* @param addr - remote addr.
* @param id - L2CAP service socket id, used to identify L2CAP service channel resource.
* @param cid - channel id.
* @param reason - disconnect reason.
*/
typedef void (*l2cap_disconnected_callback_t)(void* cookie, bt_address_t* addr, uint16_t id, uint32_t reason);
typedef void (*l2cap_disconnected_callback_t)(void* cookie, bt_address_t* addr, uint16_t cid, uint32_t reason);
/**
* @brief L2CAP event callback structure
@ -102,7 +95,7 @@ typedef struct {
*
* @param ins - bluetooth client instance.
* @param callbacks - L2CAP callback functions.
* @return void* - L2CAP APP handle, NULL on failure.
* @return void* - callbacks cookie, NULL on failure.
*/
void* BTSYMBOLS(bt_l2cap_register_callbacks)(bt_instance_t* ins, const l2cap_callbacks_t* callbacks);
@ -110,68 +103,36 @@ void* BTSYMBOLS(bt_l2cap_register_callbacks)(bt_instance_t* ins, const l2cap_cal
* @brief Unregister L2CAP callback functions.
*
* @param ins - bluetooth client instance.
* @param handle - L2CAP APP handle.
* @param cookie - callbacks cookie.
* @return true - on callback unregister success
* @return false - on callback cookie not found
*/
bool BTSYMBOLS(bt_l2cap_unregister_callbacks)(bt_instance_t* ins, void* handle);
bool BTSYMBOLS(bt_l2cap_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Listen for a L2CAP connection request
* @param ins - bluetooth client instance.
* @param handle - L2CAP APP handle.
* @param option - L2CAP config option.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_l2cap_listen)(bt_instance_t* ins, void* handle, l2cap_config_option_t* option);
bt_status_t BTSYMBOLS(bt_l2cap_listen)(bt_instance_t* ins, l2cap_config_option_t* option);
/**
* @brief Request L2CAP connection to remote device
* @param ins - bluetooth client instance.
* @param handle - L2CAP APP handle.
* @param addr - remote addr.
* @param option - L2CAP config option.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_l2cap_connect)(bt_instance_t* ins, void* handle, bt_address_t* addr, l2cap_config_option_t* option);
bt_status_t BTSYMBOLS(bt_l2cap_connect)(bt_instance_t* ins, bt_address_t* addr, l2cap_config_option_t* option);
/**
* @brief Reqeust to disconnect a L2CAP channel
* @param ins - bluetooth client instance.
* @param handle - L2CAP APP handle.
* @param id - Connected L2CAP Channel socket id.
* @param cid - channel id.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_l2cap_disconnect)(bt_instance_t* ins, void* handle, uint16_t id);
/**
* @brief Stop L2CAP listen
*
* This function used to stop L2CAP listen rather than disconnect all conected
* L2CAP channels for a specific PSM.
*
* @param ins - bluetooth client instance.
* @param handle - L2CAP APP handle.
* @param psm - LE PSM used for listen.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* @note This function is only used for LE transport scenario.
*/
bt_status_t BTSYMBOLS(bt_l2cap_stop_listen)(bt_instance_t* ins, void* handle, uint16_t psm);
/**
* @brief Stop L2CAP listen with transport
*
* This function used to stop L2CAP listen rather than disconnect all conected
* L2CAP channels for a specific PSM.
*
* @param ins - bluetooth client instance.
* @param handle - L2CAP APP handle.
* @param transport - bt_transport_t, LE or BR/EDR.
* @param psm - PSM used for listen.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_l2cap_stop_listen_with_transport)(bt_instance_t* ins, void* handle, bt_transport_t transport, uint16_t psm);
bt_status_t BTSYMBOLS(bt_l2cap_disconnect)(bt_instance_t* ins, uint16_t cid);
#ifdef __cplusplus
}

View File

@ -25,10 +25,6 @@ extern "C" {
#define BTSYMBOLS(s) s
#endif
/**
* @cond
*/
/**
* @brief Advertising type
*
@ -92,57 +88,23 @@ enum {
typedef void bt_advertiser_t;
/**
* @endcond
*/
/**
* @brief Callback for advertising started notification.
* @brief Advertising start status callback, invoke on adverting start success or failure
*
* This callback is used to notify the application of the adverter handle, ID, and
* start status of the advertiser. It will be triggered in the following cases:
* 1. Advertiser ID allocates failed or the return value of the function "bt_sal_le_start_adv"
* is not "BT_STATUS_SUCCESS" within the advertiser starting event.
* 2. 1 second after the successful notification of the start of LE advertising to the
* Bluetooth protocol stack.
* @param adv - advertiser handle.
* @param adv_id - advertiser ID.
* @param status - advertiser start status, BT_ADV_STATUS_SUCCESS on success.
*
* @param adv - Notifies the allocated Advertiser handle.
* @param adv_id - Notifies the allocated Advertiser ID.
* @param status - Notifies the starting status of the advertiser. BT_ADV_STATUS_SUCCESS
* indicates that the advertiser has started successfully.
*
* **Example:**
* @code
void on_advertising_start(bt_advertiser_t* adv, uint8_t adv_id, uint8_t status)
{
printf("on_advertising_start, adv_id: %d, status: %d\n", adv_id, status);
}
* @endcode
*/
typedef void (*on_advertising_start_cb_t)(bt_advertiser_t* adv, uint8_t adv_id, uint8_t status);
/**
* @brief Callback for advertising stopped notification.
* @brief Advertising stopped notification
*
* This callback is used to notify the application of the handle and ID corresponding to
* the stopped advertising.
*
* @param adv - Advertiser handle.
* @param adv_id - Advertiser ID.
*
* **Example:**
* @code
void on_advertising_stopped(bt_advertiser_t* adv, uint8_t adv_id)
{
printf("on_advertising_stopped, adv_id: %d\n", adv_id);
}
* @endcode
* @param adv - advertiser handle
* @param adv_id - advertiser ID.
*/
typedef void (*on_advertising_stopped_cb_t)(bt_advertiser_t* adv, uint8_t adv_id);
/**
* @cond
*/
/**
* @brief Advertising callback functions structure
*
@ -168,58 +130,16 @@ typedef struct {
} ble_adv_params_t;
/**
* @endcond
*/
/**
* @brief Initate LE advertising.
* @brief Start LE advertising
*
* Before using this function to initiate LE advertising, the Bluetooth application
* should set appropriate LE advertising parameters, prepare advertising data and scan
* response data, and an advertising callback function. When using this function, the
* above content is passed as parameters, and an advertiser handle is returned to indicate
* the initiated advertising. With this handle, the Bluetooth application can disable the
* corresponding advertising at an appropriate time.
*
* @param ins - Bluetooth client instance.
* @param params - Advertising parameter.
* @param adv_data - Advertisement data.
* @param adv_len - Length of advertisement data.
* @param scan_rsp_data - Scan response data.
* @param scan_rsp_len - Length of scan response data.
* @param cbs - Advertiser callback functions.
* @return bt_advertiser_t* - Advertiser handle.
*
* **Example:**
* @code
bt_advertiser_t* adver;
void app_start_advertising(bt_instance_t* ins)
{
ble_adv_params_t params;
uint8_t adv_data[10];
uint8_t scan_rsp_data[10];
advertiser_callback_t cbs;
params.adv_type = BT_LE_ADV_IND;
params.own_addr_type = BT_LE_ADDR_TYPE_PUBLIC;
params.tx_power = -20;
params.interval = 100;
params.duration = 0;
params.channel_map = 7;
params.filter_policy = BT_LE_ADV_FILTER_WHITE_LIST_FOR_ALL;
memset(adv_data, 0, sizeof(adv_data));
memset(scan_rsp_data, 0, sizeof(scan_rsp_data));
cbs.size = sizeof(advertiser_callback_t);
cbs.on_advertising_start = on_advertising_start;
cbs.on_advertising_stopped = on_advertising_stopped;
adver = bt_le_start_advertising(ins, &params, adv_data, sizeof(adv_data), scan_rsp_data, sizeof(scan_rsp_data), &cbs);
}
* @endcode
* @param ins - bluetooth client instance.
* @param params - advertising parameter.
* @param adv_data - advertisement data.
* @param adv_len - length of advertisement data.
* @param scan_rsp_data - scan response data.
* @param scan_rsp_len - length of scan response data.
* @param cbs - advertiser callback functions.
* @return bt_advertiser_t* - advertiser handle.
*/
bt_advertiser_t* BTSYMBOLS(bt_le_start_advertising)(bt_instance_t* ins,
ble_adv_params_t* params,
@ -230,87 +150,30 @@ bt_advertiser_t* BTSYMBOLS(bt_le_start_advertising)(bt_instance_t* ins,
advertiser_callback_t* cbs);
/**
* @brief Stop LE advertising by advertiser handle.
* @brief Stop LE advertising by advertiser handle
*
* This function is used to stop the LE advertising indicated by the specified advertiser
* handle. Therefore, before using this function, the Bluetooth application should know
* the handle corresponding to the initiated advertising. When a Bluetooth application
* initiates an advertising, it will be informed of the advertiser handle.
*
* @param ins - Bluetooth client instance.
* @param adver - Advertiser handle.
*
* **Example:**
* @code
void app_stop_advertising(bt_instance_t* ins)
{
if(!adver)
return;
bt_le_stop_advertising(ins, adver);
}
* @endcode
* @param ins - bluetooth client instance.
* @param adver - advertiser handle.
*/
void BTSYMBOLS(bt_le_stop_advertising)(bt_instance_t* ins, bt_advertiser_t* adver);
/**
* @brief Stop LE advertising by advertiser ID.
* @brief Stop LE advertising by adver id
*
* This function is used to stop the LE advertising indicated by the specified advertiser ID.
* Therefore, before using this function, the Bluetooth application should know the ID
* corresponding to the initiated advertising. When a Bluetooth application successfully initiates
* an advertising, the advertiser ID will be informed through the "on_advertising_start_cb_t"
* callback function provided when the advertising is initiated by the application.
*
* @param ins - Bluetooth client instance.
* @param adv_id - Advertiser ID.
*
* **Example:**
* @code
void app_stop_advertising(bt_instance_t* ins, uint8_t adv_id)
{
bt_le_stop_advertising_id(ins, adv_id);
}
* @endcode
* @param ins - bluetooth client instance.
* @param adv_id - advertiser ID.
*/
void BTSYMBOLS(bt_le_stop_advertising_id)(bt_instance_t* ins, uint8_t adv_id);
/**
* @brief Check if LE advertising is supported.
* @brief Check is advertising supported
*
* This function is used to check if the Bluetooth protocol stack supports LE advertising for
* Bluetooth applications.
*
* @param ins - Bluetooth client instance.
* @return bool - true represents support for LE advertising, while false represents non-support.
*
* **Example:**
* @code
void app_check_advertising_support(bt_instance_t* ins)
{
if(bt_le_advertising_is_supported(ins))
printf("advertising is supported\n");
else
printf("advertising is not supported\n");
}
* @endcode
* @param ins - bluetooth client instance.
* @return true - support.
* @return false - not support.
*/
bool BTSYMBOLS(bt_le_advertising_is_supported)(bt_instance_t* ins);
// async
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#include "bt_async.h"
typedef void (*bt_le_start_adv_callback_cb_t)(bt_instance_t* ins, bt_status_t status, void* adv, void* userdata);
bt_status_t bt_le_start_advertising_async(bt_instance_t* ins, ble_adv_params_t* params, uint8_t* adv_data,
uint16_t adv_len, uint8_t* scan_rsp_data, uint16_t scan_rsp_len,
advertiser_callback_t* adv_cbs, bt_le_start_adv_callback_cb_t cb, void* userdata);
bt_status_t bt_le_stop_advertising_async(bt_instance_t* ins, bt_advertiser_t* adver, bt_status_cb_t cb, void* userdata);
bt_status_t bt_le_stop_advertising_id_async(bt_instance_t* ins, uint8_t adv_id, bt_status_cb_t cb, void* userdata);
bt_status_t bt_le_advertising_is_supported_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
#endif // CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#ifdef __cplusplus
}
#endif

View File

@ -22,10 +22,6 @@ extern "C" {
#include <stdint.h>
#ifdef CONFIG_BLUETOOTH_STACK_LE_ZBLUE
#include <zephyr/bluetooth/bluetooth.h>
#endif
#include "bluetooth.h"
#include "bt_le_advertiser.h"
#ifndef BTSYMBOLS
@ -34,10 +30,6 @@ extern "C" {
#define BLE_SCAN_FILTER_UUID_MAX_NUM 2
/**
* @cond
*/
/**
* @brief Scan start status code
*
@ -49,8 +41,7 @@ enum {
BT_SCAN_STATUS_SCANNER_REG_NOMEM,
BT_SCAN_STATUS_SCANNER_EXISTED,
BT_SCAN_STATUS_SCANNER_NOT_FOUND,
BT_SCAN_STATUS_SCANNER_REMOVED,
BT_SCAN_STATUS_INVALID_PARAMETER = 0xFF
BT_SCAN_STATUS_SCANNER_REMOVED
};
/**
@ -63,28 +54,19 @@ enum {
BT_SCAN_MODE_LOW_LATENCY,
};
#define SCAN_MODE_LOW_POWER_INTERVAL 0x3C0
#define SCAN_MODE_LOW_POWER_WINDOW 0x18
#define SCAN_MODE_BALANCED_INTERVAL 0x80
#define SCAN_MODE_BALANCED_WINDOW 0x20
#define SCAN_MODE_LOW_POWER_INTERVAL 0x1000
#define SCAN_MODE_LOW_POWER_WINDOW 0x100
#define SCAN_MODE_BALANCED_INTERVAL 0x500
#define SCAN_MODE_BALANCED_WINDOW 0x140
#define SCAN_MODE_LOW_LATENCY_INTERVAL 0xA0
#define SCAN_MODE_LOW_LATENCY_WINDOW 0xA0
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 filter policy
@ -151,76 +133,30 @@ typedef struct {
uint8_t active;
uint8_t duplicated;
} ble_scan_filter_t;
/**
* @endcond
*/
/**
* @brief Scan result callback function.
* @brief scan result callback
*
* Callback function called when a scan result is available.
*
* @param scanner - Scanner handle.
* @param result - Pointer to the scan result, see @ref ble_scan_result_t.
*
* **Example:**
* @code
void le_scan_result_callback(bt_scanner_t* scanner, ble_scan_result_t* result)
{
// Process scan result
}
static scanner_callbacks_t lescan_cbs = {
.size = sizeof(lescan_cbs),
.on_scan_result = le_scan_result_callback,
};
* @endcode
* @param scanner - scanner handle.
* @param result - scan result.
*/
typedef void (*on_scan_result_cb_t)(bt_scanner_t* scanner, ble_scan_result_t* result);
/**
* @brief Scan start status callback function.
* @brief Scan start status callback
*
* Callback function called when the scan starts or fails to start.
*
* @param scanner - Scanner handle.
* @param status - Scan start status code, see scan status codes.
*
* **Example:**
* @code
void on_scan_status(bt_scanner_t* scanner, uint8_t status)
{
if (status == BT_SCAN_STATUS_SUCCESS) {
// Scan started successfully
} else {
// Handle scan start failure
}
}
* @endcode
* @param scanner - scanner handle.
* @param result - scan start status, BT_SCAN_STATUS_SUCCESS on success.
*/
typedef void (*on_scan_status_cb_t)(bt_scanner_t* scanner, uint8_t status);
/**
* @brief Scan stopped callback function.
* @brief Scan stopped callback
*
* Callback function called when the scan is stopped.
*
* @param scanner - Scanner handle.
*
* **Example:**
* @code
void on_scan_stopped(bt_scanner_t* scanner)
{
// Handle scan stopped event
}
* @endcode
* @param scanner - scanner handle.
*/
typedef void (*on_scan_stopped_cb_t)(bt_scanner_t* scanner);
/**
* @cond
*/
/**
* @brief Scanner callback structure
*
@ -231,79 +167,37 @@ typedef struct {
on_scan_status_cb_t on_scan_start_status;
on_scan_stopped_cb_t on_scan_stopped;
} scanner_callbacks_t;
/**
* @endcond
*/
/**
* @brief Start BLE scan.
* @brief Start LE scan
*
* Initiates a BLE scan with default settings.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @return bt_scanner_t* - Scanner handle generated by the scan manager.
*
* **Example:**
* @code
bt_scanner_t* scanner = bt_le_start_scan(ins, &my_scanner_callbacks);
if (scanner == NULL) {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param cbs - scan callback function.
* @return bt_scanner_t* - scanner handle generated by scan manager.
*/
bt_scanner_t* BTSYMBOLS(bt_le_start_scan)(bt_instance_t* ins, const scanner_callbacks_t* cbs);
/**
* @brief Start BLE scan with specific settings.
* @brief Start LE scan with scan settings
*
* Initiates a BLE scan with provided scan settings.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param settings - Pointer to scan settings, see @ref ble_scan_settings_t.
* @param cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @return bt_scanner_t* - Scanner handle generated by the scan manager.
*
* **Example:**
* @code
ble_scan_settings_t settings = {
.scan_mode = BT_SCAN_MODE_LOW_LATENCY,
.scan_type = BT_LE_SCAN_TYPE_ACTIVE,
// Additional settings...
};
bt_scanner_t* scanner = bt_le_start_scan_settings(ins, &settings, &my_scanner_callbacks);
if (scanner == NULL) {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param settings - scan settings with scan mode and scan phy.
* @param cbs - scan callback function.
* @return bt_scanner_t* - scanner handle generated by scan manager.
*/
bt_scanner_t* BTSYMBOLS(bt_le_start_scan_settings)(bt_instance_t* ins,
ble_scan_settings_t* settings,
const scanner_callbacks_t* cbs);
/**
* @brief Start BLE scan with filters.
* @brief Start LE scan with scan filters
*
* Initiates a BLE scan with specific settings and filters.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param settings - Pointer to scan settings, see @ref ble_scan_settings_t.
* @param filter_data - Pointer to filter data, see @ref ble_scan_filter_t.
* @param cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @return bt_scanner_t* - Scanner handle generated by the scan manager.
*
* **Example:**
* @code
ble_scan_filter_t filter = {
.uuids = {0x180D, 0x180F}, // Heart Rate and Battery Service UUIDs
.active = 1,
// Additional filter settings...
};
bt_scanner_t* scanner = bt_le_start_scan_with_filters(ins, &settings, &filter, &my_scanner_callbacks);
if (scanner == NULL) {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param settings - scan settings with scan mode and scan phy.
* @param filter_data - filter data.
* @param filter_length - filter data length.
* @param cbs - scan callback function.
* @return bt_scanner_t* - scanner handle generated by scan manager.
*/
bt_scanner_t* BTSYMBOLS(bt_le_start_scan_with_filters)(bt_instance_t* ins,
ble_scan_settings_t* settings,
@ -311,136 +205,24 @@ bt_scanner_t* BTSYMBOLS(bt_le_start_scan_with_filters)(bt_instance_t* ins,
const scanner_callbacks_t* cbs);
/**
* @brief Stop BLE scan.
* @brief Stop LE scan
*
* Stops an ongoing BLE scan.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param scanner - Scanner handle generated by the scan manager.
*
* **Example:**
* @code
bt_le_stop_scan(ins, scanner);
* @endcode
* @param ins - bluetooth client instance.
* @param scanner - scanner handle generated by scan manager.
*/
void BTSYMBOLS(bt_le_stop_scan)(bt_instance_t* ins, bt_scanner_t* scanner);
/**
* @brief Check if BLE scanning is supported.
* @brief Check LE scan is support
*
* Determines whether BLE scanning is supported by the adapter.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @return true - Scanning is supported.
* @return false - Scanning is not supported.
*
* **Example:**
* @code
if (bt_le_scan_is_supported(ins)) {
// Scanning is supported
} else {
// Scanning is not supported
}
* @endcode
* @param ins - bluetooth client instance.
* @return true - support.
* @return false - not support.
*/
bool BTSYMBOLS(bt_le_scan_is_supported)(bt_instance_t* ins);
// async
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#include "bt_async.h"
/**
* @brief The asynchronous callback for start BLE scan registered by the caller.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param status - Status of the operation.
* @param scan - Scanner handle generated by the scan manager. The caller needs
* to save the handle to use when stopping the scan.
* @param userdata - User context.
*/
typedef void (*bt_le_start_scan_cb_t)(bt_instance_t* ins, bt_status_t status, void* scan, void* userdata);
/**
* @brief The asynchronous callback for stop BLE scan registered by the caller.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param userdata - User context.
*/
typedef void (*bt_le_stop_scan_cb_t)(bt_instance_t* ins, void* userdata);
/**
* @brief Start BLE scan.
*
* Initiates a BLE scan with default settings.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param scan_cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @param cb - Callback function for asynchronous call.
* @param userdata - User context.
* @return bt_status_t - Only return IPC status.
*/
bt_status_t bt_le_start_scan_async(bt_instance_t* ins, const scanner_callbacks_t* scan_cbs,
bt_le_start_scan_cb_t cb, void* userdata);
/**
* @brief Start BLE scan with specific settings.
*
* Initiates a BLE scan with provided scan settings.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param settings - Pointer to scan settings, see @ref ble_scan_settings_t.
* @param scan_cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @param cb - Callback function for asynchronous call.
* @param userdata - User context.
* @return bt_status_t - Only return IPC status.
*/
bt_status_t bt_le_start_scan_settings_async(bt_instance_t* ins, ble_scan_settings_t* settings,
const scanner_callbacks_t* scan_cbs, bt_le_start_scan_cb_t cb, void* userdata);
/**
* @brief Start BLE scan with filters.
*
* Initiates a BLE scan with specific settings and filters.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param settings - Pointer to scan settings, see @ref ble_scan_settings_t.
* @param filter_data - Pointer to filter data, see @ref ble_scan_filter_t.
* @param scan_cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @param cb - Callback function for asynchronous call.
* @param userdata - User context.
* @return bt_status_t - Only return IPC status.
*/
bt_status_t bt_le_start_scan_with_filters_async(bt_instance_t* ins, ble_scan_settings_t* settings,
ble_scan_filter_t* filter, const scanner_callbacks_t* scan_cbs, bt_le_start_scan_cb_t cb, void* userdata);
/**
* @brief Stop BLE scan.
*
* Stops an ongoing BLE scan.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param scanner - Scanner handle generated by the scan manager.
* @param cb - Callback function for asynchronous call.
* @param userdata - User context.
* @return bt_status_t - Only return IPC status.
*/
bt_status_t bt_le_stop_scan_async(bt_instance_t* ins, bt_scanner_t* scanner, bt_le_stop_scan_cb_t cb, void* userdata);
/**
* @brief Check if BLE scanning is supported.
*
* Determines whether BLE scanning is supported by the adapter.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param cb - Callback function for asynchronous call.
* @param userdata - User context.
* @return bt_status_t - Only return IPC status.
*/
bt_status_t bt_le_scan_is_supported_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
#endif // CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#ifdef __cplusplus
}
#endif
#endif /* __BT_LE_SCAN_H_ */
#endif /* __BT_LE_SCAN_H_ */

View File

@ -23,7 +23,7 @@ extern "C" {
#include "bt_addr.h"
#include "bt_device.h"
#include "bt_lea_common.h"
#include "lea_audio_common.h"
#include <stddef.h>
/**

View File

@ -23,7 +23,7 @@ extern "C" {
#include "bt_addr.h"
#include "bt_device.h"
#include "bt_lea_common.h"
#include "lea_audio_common.h"
#include <stddef.h>
#define OBJ_ID_SIZE 6

View File

@ -23,7 +23,7 @@ extern "C" {
#include "bt_addr.h"
#include "bt_device.h"
#include "bt_lea_common.h"
#include "lea_audio_common.h"
#include <stddef.h>
typedef void (*lea_tbs_test_callback)(void* cookie, uint8_t value, bool added);

View File

@ -23,7 +23,7 @@ extern "C" {
#include <stdbool.h>
#include <stddef.h>
#include "bt_list_internal.h"
#include "list.h"
typedef void (*bt_list_free_cb_t)(void* data);
typedef struct _bt_list bt_list_t;

View File

@ -139,6 +139,15 @@
list_initialize(item); \
} while (0)
#define list_merge(list_dst, list_src) \
do { \
(list_dst)->prev->next = (list_src)->next; \
(list_src)->next->prev = (list_dst)->prev; \
(list_src)->prev->next = (list_dst); \
(list_dst)->prev = (list_src)->prev; \
list_initialize(list_src); \
} while (0)
#define list_remove_head_type(list, type, member) \
({ \
FAR struct list_node* __node = list_remove_head(list); \

View File

@ -26,11 +26,7 @@
#endif
/**
* @cond
*/
/**
* @brief PAN role type define.
* @brief Pan role type define.
*
*/
typedef enum {
@ -54,68 +50,29 @@ typedef enum {
} pan_netif_state_t;
/**
* @endcond
*/
/**
* @brief Callback for PAN connection state change.
* @brief Pan connection state change callback.
*
* When the PAN connection state changes, this callback will be triggered to
* notify the cookie corresponding to the callback, the latest PAN connection
* state, the Bluetooth address of the peer device, and the roles of both
* devices in the PAN.
*
* @param cookie - Callbacks cookie, the return value of bt_pan_register_callbacks.
* @param state - PAN connection state
* @param bd_addr - The Bluetooth address of the peer device.
* @param local_role - Local device PAN role, reference type pan_role_t.
* @param remote_role - Remote device PAN role, reference type pan_role_t.
*
* **Example:**
* @code
void pan_connection_state_cb(void* cookie, profile_connection_state_t state,
bt_address_t* bd_addr, uint8_t local_role,
uint8_t remote_role)
{
printf("pan_connection_state_cb, state: %d, bd_addr: %s, local_role: %d, remote_role: %d\n",
state, bd_addr->address, local_role, remote_role);
}
* @endcode
* @param cookie - callbacks cookie, the return value of bt_pan_register_callbacks.
* @param state - pan connection state
* @param bd_addr - address of peer device.
* @param local_role - local device pan role, reference type pan_role_t.
* @param remote_role - remote device pan role, reference type pan_role_t.
*/
typedef void (*pan_connection_state_callback)(void* cookie, profile_connection_state_t state,
bt_address_t* bd_addr, uint8_t local_role,
uint8_t remote_role);
/**
* @brief Callback for PAN net interface (down/up) state change.
* @brief Pan net interface (down/up)state change callback.
*
* When the PAN interface becomes up or down, this callback will be triggered
* to notify the Cookie corresponding to the callback, the latest status of
* the interface, the role of the local device in the PAN, and the interface
* name.
*
* @param cookie - Callbacks cookie, the return value of bt_pan_register_callbacks.
* @param state - Net interface state.
* @param local_role - Local device PAN role.
* @param ifname - Net interface name, default "bt-pan".
*
* **Example:**
* @code
void pan_netif_state_cb(void* cookie, pan_netif_state_t state,
int local_role, const char* ifname)
{
printf("pan_netif_state_cb, state: %d, local_role: %d, ifname: %s\n",
state, local_role, ifname);
}
* @endcode
* @param cookie - callbacks cookie, the return value of bt_pan_register_callbacks.
* @param state - net interface state.
* @param local_role - local device pan role
* @param ifname - net interface name, default "bt-pan".
*/
typedef void (*pan_netif_state_callback)(void* cookie, pan_netif_state_t state,
int local_role, const char* ifname);
/**
* @cond
*/
/**
* @brief PAN event callbacks structure
*
@ -127,133 +84,41 @@ typedef struct {
} pan_callbacks_t;
/**
* @endcond
*/
/**
* @brief Register callback functions to PAN service.
* @brief Register callback functions to pan service
*
* This function is used to register the callback for notifying PAN connection
* states and the callback for notifying PAN interface states to the PAN service.
* When the PAN service detects the corresponding event, it will notify the
* application through the registered callback function. After this function is
* called, it returns the cookie corresponding to the callback.
*
* @param ins - Bluetooth client instance.
* @param callbacks - PAN callback functions.
* @return void* - Callback cookie, NULL represents fail.
*
* **Example:**
* @code
void* pan_cookie;
const static pan_callbacks_t callbacks = {
.size = sizeof(pan_callbacks_t),
.netif_state_cb = pan_netif_state_cb,
.connection_state_cb = pan_connection_state_cb,
};
void app_init_pan(bt_instance_t* ins)
{
pan_cookie = bt_pan_register_callbacks(ins, &callbacks);
if (!pan_cookie)
printf("register pan callbacks failed\n");
else
printf("register pan callbacks success\n");
}
* @endcode
* @param ins - bluetooth client instance.
* @param callbacks - pan callback functions.
* @return void* - callback cookie, NULL on failure.
*/
void* BTSYMBOLS(bt_pan_register_callbacks)(bt_instance_t* ins, const pan_callbacks_t* callbacks);
/**
* @brief Unregister PAN callback functions.
* @brief Unregister pan callback function
*
* This function is used to unregister callbacks from the PAN service. The caller
* needs to provide the cookie corresponding to callbacks.
*
* @param ins - Bluetooth client instance.
* @param cookie - Callbacks cookie.
* @param ins - bluetooth client instance.
* @param cookie - callbacks cookie.
* @return true - on callback unregister success
* @return false - on callback cookie not found
*
* **Example:**
* @code
void app_deinit_pan(bt_instance_t* ins)
{
bt_status_t status;
if (!pan_cookie)
return;
status = bt_pan_unregister_callbacks(ins, pan_cookie);
if (status != BT_STATUS_SUCCESS)
printf("unregister pan callbacks failed\n");
else
printf("unregister pan callbacks success\n");
}
* @endcode
*/
bool BTSYMBOLS(bt_pan_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Connect to PAN device.
* @brief Connect to pan device
*
* This function is used to connect to a PAN device. The caller needs to provide
* the address of the peer device, the role of the local device, and the role of
* the peer device.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param dst_role - Destination PAN role, reference type pan_role_t.
* Only support PANU connect to NAP server, dst_role must be PAN_ROLE_NAP.
* @param src_role - Source PAN role, reference type pan_role_t.
* Only support PANU connect to NAP server, src_role must be PAN_ROLE_PANU.
* @param ins - bluetooth client instance.
* @param addr - address of peer device.
* @param dst_role - dest pan role, reference type pan_role_t.
* @param src_role - src pan role, reference type pan_role_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
void app_connect_pan_device(bt_instance_t* ins)
{
bt_status_t status;
bt_address_t addr = {
.addr = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
};
status = bt_pan_connect(ins, &addr, PAN_ROLE_NAP, PAN_ROLE_PANU);
if(status != BT_STATUS_SUCCESS)
printf("connect pan device failed\n");
else
printf("connect pan device success\n");
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_pan_connect)(bt_instance_t* ins, bt_address_t* addr, uint8_t dst_role, uint8_t src_role);
/**
* @brief Disconnect from PAN connection.
* @brief Disconnect from pan connection
*
* This function is used to disconnect from a PAN device. The caller needs to
* provide the address of the peer device.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param ins - bluetooth client instance.
* @param addr - address of peer device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
void app_disconnect_pan_device(bt_instance_t* ins)
{
bt_status_t status;
bt_address_t addr = {
.addr = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
};
status = bt_pan_disconnect(ins, &addr);
if(status != BT_STATUS_SUCCESS)
printf("disconnect pan device failed\n");
else
printf("disconnect pan device success\n");
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_pan_disconnect)(bt_instance_t* ins, bt_address_t* addr);

View File

@ -20,14 +20,11 @@
extern "C" {
#endif
/**
* @cond
*/
#define PROFILE_A2DP_NAME "A2DP-Src"
#define PROFILE_A2DP_SINK_NAME "A2DP-Sink"
#define PROFILE_AVRCP_CT_NAME "AVRCP-CT"
#define PROFILE_AVRCP_TG_NAME "AVRCP-TG"
#define PROFILE_CS_NAME "CS"
#define PROFILE_HFP_HF_NAME "HFP-HF"
#define PROFILE_HFP_AG_NAME "HFP-AG"
#define PROFILE_SPP_NAME "SPP"
@ -64,14 +61,11 @@ enum profile_id {
PROFILE_LEAUDIO_MCS,
PROFILE_LEAUDIO_TBS,
PROFILE_LEAUDIO_VMICP,
PROFILE_CS, // TODO: remove this profile
PROFILE_UNKOWN,
PROFILE_MAX
};
/**
* @endcond
*/
#ifdef __cplusplus
}
#endif

View File

@ -46,6 +46,8 @@ extern "C" {
*/
#define BT_UUID_SERVCLASS_SERIAL_PORT 0x1101
#define SPP_PORT_TYPE_TTY 1
/**
* @brief Spp proxy state
*
@ -57,10 +59,6 @@ typedef enum {
SPP_PROXY_STATE_CLOSING,
} spp_proxy_state_t;
/**
* @endcond
*/
/**
* @brief Callback used to notify SPP connection states.
*
@ -147,12 +145,9 @@ void spp_proxy_state_cb(void* handle, bt_address_t* addr, spp_proxy_state_t stat
*/
typedef void (*spp_proxy_state_callback)(void* handle, bt_address_t* addr, spp_proxy_state_t state, uint16_t scn, uint16_t port, char* name);
/**
* @cond
*/
/**
* @brief SPP event callbacks structure
*
*/
typedef struct {
size_t size;
@ -331,8 +326,8 @@ bt_status_t BTSYMBOLS(bt_spp_unregister_app)(bt_instance_t* ins, void* handle);
* on other devices.
*
* @param ins - Bluetooth client instance.
* @param handle - SPP APP handle.
* @param scn - Server channel number, range in <1-28>.
* @param handle - SPP application handle.
* @param scn - Server channel number, range in 1-28.
* @param uuid - Server uuid, default:0x1101.
* @param max_connection - Maximum of client connections.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
@ -369,8 +364,8 @@ bt_status_t BTSYMBOLS(bt_spp_server_start)(bt_instance_t* ins, void* handle, uin
* will have stopped the SPP server.
*
* @param ins - Bluetooth client instance.
* @param handle - SPP APP handle.
* @param scn - Server channel number, range in <1-28>.
* @param handle - SPP application handle.
* @param scn - Server channel number, range in 1-28.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
@ -401,9 +396,9 @@ bt_status_t BTSYMBOLS(bt_spp_server_stop)(bt_instance_t* ins, void* handle, uint
* an SPP connection will be established with the remote device.
*
* @param[in] ins - Bluetooth client instance.
* @param[in] handle - SPP APP handle.
* @param[in] addr - address of peer device.
* @param[in] scn - Server channel number, range in <1-28>.
* @param[in] handle - SPP application handle.
* @param[in] addr - The Bluetooth address of the peer device.
* @param[in] scn - Server channel number, range in 1-28.
* - UNKNOWN_SERVER_CHANNEL_NUM: Not specify scn.
* @param[in] uuid - Server uuid, default:0x1101.
* @param[out] port - The unique port of connection.

View File

@ -23,14 +23,30 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
/**
* @cond
*/
#define BT_UUID_A2DP_SRC 0x110A
#define BT_UUID_A2DP_SNK 0x110B
#define BT_UUID_HFP 0x111E
#define BT_UUID_HFP_AG 0x111F
/**
* @cond
*/
/* GATT Descriptor UUIDs (16-bit) */
#define BT_UUID_GATT_CEPD 0x2900
#define BT_UUID_GATT_CUDD 0x2901
#define BT_UUID_GATT_CCCD 0x2902
#define BT_UUID_GATT_CPFD 0x2904
#define BT_UUID_RANGING_VAL 0x185B
#define BT_UUID_RANGE_FEAT_VAL 0x2C14
#define BT_UUID_RANGE_RTT_DT_VAL 0x2C15
#define BT_UUID_RANGE_ON_DEM_DT_VAL 0x2C16
#define BT_UUID_RANGE_RAS_CTR_POINT_VAL 0x2C17
#define BT_UUID_RANGE_DT_RD_VAL 0x2C18
#define BT_UUID_RANGE_DT_OV_WR_VAL 0x2C19
#define BT_UUID_STR_LENGTH 40
typedef enum {
BT_UUID16_TYPE = 2,
@ -70,172 +86,13 @@ typedef struct {
((bt_uuid_t) { .type = BT_UUID128_TYPE, .val.u128 = { value } })
#endif
/**
* @endcond
*/
/**
* @brief Converting UUID to a 128-bits UUID.
*
* @param src - src UUID(16-bits, 32-bits, 128-bits).
* @param uuid128 - Converted 128-bits UUID.
* @return void.
*
* **Example:**
* @code
int bt_uuid_compare(const bt_uuid_t* uuid1, const bt_uuid_t* uuid2)
{
bt_uuid_t u1 = { 0 };
bt_uuid_t u2 = { 0 };
bt_uuid_to_uuid128(uuid1, &u1);
bt_uuid_to_uuid128(uuid2, &u2);
return bt_uuid128_cmp(&u1, &u2);
}
* @endcode
*/
void bt_uuid_to_uuid128(const bt_uuid_t* src, bt_uuid_t* uuid128);
void bt_uuid_to_uuid16(const bt_uuid_t* src, bt_uuid_t* uuid16);
/**
* @brief compare two UUIDs.
*
* @param uuid1 - UUID1.
* @param uuid2 - UUID2.
* @return int. If uuid1 is equal to uuid2, return 0.
*
* **Example:**
* @code
if (!bt_uuid_compare(&element->uuid, attr_uuid)) {
BT_LOGE("uuid match");
// Handle continue
} else {
BT_LOGE("uuid not match");
// Handle error
}
* @endcode
*/
int bt_uuid_compare(const bt_uuid_t* uuid1, const bt_uuid_t* uuid2);
/**
* @brief create a 16-bits UUID.
*
* @param uuid16 - pointer of the generated UUID16.
* @param value - UUID value.
* @return int.
*
* **Example:**
* @code
bool bt_uuid_create_common(bt_uuid_t* uuid, const uint8_t* data, uint8_t type)
{
switch (type) {
case BT_UUID16_TYPE: {
uint16_t val16;
STREAM_TO_UINT32(val16, data);
bt_uuid16_create(uuid, val16);
break;
}
default:
return false;
}
return true;
}
* @endcode
*/
int bt_uuid16_create(bt_uuid_t* uuid16, uint16_t value);
/**
* @brief create a 32-bits UUID.
*
* @param uuid16 - pointer of the generated UUID32.
* @param value - UUID value.
* @return int.
*
* **Example:**
* @code
bool bt_uuid_create_common(bt_uuid_t* uuid, const uint8_t* data, uint8_t type)
{
switch (type) {
case BT_UUID32_TYPE: {
uint32_t val32;
STREAM_TO_UINT32(val32, data);
bt_uuid32_create(uuid, val32);
break;
}
default:
return false;
}
return true;
}
* @endcode
*/
int bt_uuid32_create(bt_uuid_t* uuid32, uint32_t value);
/**
* @brief create a 128-bits UUID.
*
* @param uuid16 - pointer of the generated UUID128.
* @param value - UUID value.
* @return int.
*
* **Example:**
* @code
bool bt_uuid_create_common(bt_uuid_t* uuid, const uint8_t* data, uint8_t type)
{
switch (type) {
case BT_UUID128_TYPE:
bt_uuid128_create(uuid, data);
break;
default:
return false;
}
return true;
}
* @endcode
*/
int bt_uuid128_create(bt_uuid_t* uuid128, const uint8_t* value);
/**
* @brief Wrapper of UUID create.
*
* @param uuid - pointer of the generated UUID(16-bits, 32-bits, 128-bits).
* @param data - UUID value.
* @param type - UUID type(16-bits, 32-bits, 128-bits).
* @return bool. If type belongs to UUID16, UUID32, UUID128return true, else return false.
*
* **Example:**
* @code
bt_uuid_create_common(&uuid, data, BT_UUID128_TYPE)
* @endcode
*/
bool bt_uuid_create_common(bt_uuid_t* uuid, const uint8_t* data, uint8_t type);
/**
* @brief Converting UUID to string.
*
* @param uuid - pointer of the generated UUID.
* @param str - UUID string.
* @param len - string length.
* @return int.
*
* **Example:**
* @code
bt_device_get_uuids(handle, addr, &uuids, &uuid_cnt, bttool_allocator);
if (uuid_cnt) {
PRINT("\tUUIDs:[%d]", uuid_cnt);
for (int i = 0; i < uuid_cnt; i++) {
bt_uuid_to_string(uuids + i, uuid_str, 40);
PRINT("\t\tuuid[%-2d]: %s", i, uuid_str);
}
}
free(uuids);
* @endcode
*/
int bt_uuid_to_string(const bt_uuid_t* uuid, char* str, uint32_t len);
#ifdef __cplusplus

View File

@ -33,20 +33,25 @@ typedef enum {
EUV_RPMSG_SERVER_PIPE_OPENED = 1 << 2,
} euv_pipe_status_t;
typedef struct euv_pipe {
uv_pipe_t cli_pipe;
uv_pipe_t srv_pipe[2];
euv_pipe_mode_t mode;
euv_pipe_status_t status;
void* data;
} euv_pipe_t;
typedef struct euv_pipe euv_pipe_t;
typedef void (*euv_read_cb)(euv_pipe_t* handle, const uint8_t* buf, ssize_t size);
typedef void (*euv_write_cb)(euv_pipe_t* handle, uint8_t* buf, int status);
typedef void (*euv_alloc_cb)(euv_pipe_t* handle, uint8_t** buf, size_t* len);
typedef void (*euv_connect_cb)(euv_pipe_t* handle, int status, void* user_data);
typedef void (*euv_close_cb)(euv_pipe_t* handle);
struct euv_pipe {
uv_pipe_t cli_pipe;
uv_pipe_t srv_pipe[2];
euv_pipe_mode_t mode;
euv_pipe_status_t status;
void* data;
euv_close_cb close_cb;
};
euv_pipe_t* euv_pipe_open(uv_loop_t* loop, const char* path, euv_connect_cb cb, void* user_data);
void euv_pipe_close_with_cb(euv_pipe_t* handle, euv_close_cb cb);
void euv_pipe_close(euv_pipe_t* handle);
euv_pipe_t* euv_pipe_connect(uv_loop_t* loop, const char* path, euv_connect_cb cb, void* user_data);
#ifdef CONFIG_NET_RPMSG

327
framework/include/list.h Normal file
View File

@ -0,0 +1,327 @@
/****************************************************************************
* include/nuttx/list.h
*
* Extracted from logic originally written by Travis Geiselbrecht and
* released under a public domain license. Re-released here under the 3-
* clause BSD license by Pinecone, Inc.
*
* Copyright (C) 2008 Travis Geiselbrecht. All rights reserved.
* Author: Travis Geiselbrecht <geist@foobox.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_LIST_H
#define __INCLUDE_NUTTX_LIST_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdbool.h>
#include <stddef.h>
#define FAR
#define NEAR
#define DSEG
#define CODE
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define LIST_INITIAL_VALUE(list) \
{ \
&(list), &(list) \
}
#define LIST_INITIAL_CLEARED_VALUE \
{ \
NULL, NULL \
}
#define list_in_list(item) ((item)->prev != NULL)
#define list_is_empty(list) ((list)->next == list)
#define list_is_clear(list) ((list)->next == NULL)
#define list_is_singular(list) ((list)->next == (list)->prev)
#define list_initialize(list) \
do { \
FAR struct list_node* __list = (list); \
__list->prev = __list->next = __list; \
} while (0)
#define list_clear_node(item) \
do { \
FAR struct list_node* __item = (item); \
__item->prev = __item->next = NULL; \
} while (0)
#define list_peek_head(list) ((list)->next != (list) ? (list)->next : NULL)
#define list_peek_tail(list) ((list)->prev != (list) ? (list)->prev : NULL)
#define list_prev(list, item) ((item)->prev != (list) ? (item)->prev : NULL)
#define list_prev_wrap(list, item) \
((item)->prev != (list) ? (item)->prev : (item)->prev->prev != (list) ? (item)->prev->prev \
: NULL)
#define list_next(list, item) ((item)->next != (list) ? (item)->next : NULL)
#define list_next_wrap(list, item) \
((item)->next != (list) ? (item)->next : (item)->next->next != (list) ? (item)->next->next \
: NULL)
#define list_entry(ptr, type, member) container_of(ptr, type, member)
#define list_first_entry(list, type, member) container_of((list)->next, type, member)
#define list_last_entry(list, type, member) container_of((list)->prev, type, member)
#define list_next_entry(list, type, member) container_of((list)->member.next, type, member)
#define list_prev_entry(list, type, member) container_of((list)->member.prev, type, member)
#define list_add_after(entry, new_entry) list_add_head(entry, new_entry)
#define list_add_head(list, item) \
do { \
FAR struct list_node* __list = (list); \
FAR struct list_node* __item = (item); \
__item->next = __list->next; \
__item->prev = __list; \
__list->next->prev = __item; \
__list->next = __item; \
} while (0)
#define list_add_before(entry, new_entry) list_add_tail(entry, new_entry)
#define list_add_tail(list, item) \
do { \
FAR struct list_node* __list = (list); \
FAR struct list_node* __item = (item); \
__item->prev = __list->prev; \
__item->next = __list; \
__list->prev->next = __item; \
__list->prev = __item; \
} while (0)
#define list_delete(item) \
do { \
FAR struct list_node* __item = (item); \
__item->next->prev = __item->prev; \
__item->prev->next = __item->next; \
__item->prev = __item->next = NULL; \
} while (0)
#define list_delete_init(item) \
do { \
list_delete(item); \
list_initialize(item); \
} while (0)
#define list_merge(list_dst, list_src) \
do { \
(list_dst)->prev->next = (list_src)->next; \
(list_src)->next->prev = (list_dst)->prev; \
(list_src)->prev->next = (list_dst); \
(list_dst)->prev = (list_src)->prev; \
list_initialize(list_src); \
} while (0)
#define list_remove_head_type(list, type, member) \
({ \
FAR struct list_node* __node = list_remove_head(list); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_remove_tail_type(list, type, member) \
({ \
FAR struct list_node* __node = list_remove_tail(list); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_peek_head_type(list, type, member) \
({ \
FAR struct list_node* __node = list_peek_head(list); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_peek_tail_type(list, type, member) \
({ \
FAR struct list_node* __node = list_peek_tail(list); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_prev_type(list, item, type, member) \
({ \
FAR struct list_node* __node = list_prev(list, item); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_prev_wrap_type(list, item, type, member) \
({ \
FAR struct list_node* __node = list_prev_wrap(list, item); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_next_type(list, item, type, member) \
({ \
FAR struct list_node* __node = list_next(list, item); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_next_wrap_type(list, item, type, member) \
({ \
FAR struct list_node* __node = list_next_wrap(list, item); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
/* iterates over the list, node should be struct list_node* */
#define list_for_every(list, node) \
for (node = (list)->next; node != (list); node = node->next)
/* iterates over the list in a safe way for deletion of current node
* node and temp_node should be struct list_node*
*/
#define list_for_every_safe(list, node, temp) \
for (node = (list)->next, temp = node->next; \
node != (list); node = temp, temp = node->next)
/* iterates over the list, entry should be the container structure type */
#define list_for_every_entry(list, entry, type, member) \
for (entry = container_of((list)->next, type, member); \
&entry->member != (list); \
entry = container_of(entry->member.next, type, member))
/* iterates over the list in a safe way for deletion of current node
* entry and temp_entry should be the container structure type *
*/
#define list_for_every_entry_safe(list, entry, temp, type, member) \
for (entry = container_of((list)->next, type, member), \
temp = container_of(entry->member.next, type, member); \
&entry->member != (list); entry = temp, \
temp = container_of(temp->member.next, type, member))
/* Iterate from a given entry node in a safe way */
#define list_for_every_entry_safe_from(list, cur, temp, type, member) \
for ((temp) = list_next_entry(cur, type, member); \
&(cur)->member != (list); \
(cur) = (temp), (temp) = list_next_entry(temp, type, member))
#define list_for_every_entry_continue(list, head, type, member) \
for ((list) = list_next_entry(list, type, member); \
&(list)->member != (head); \
(list) = list_next_entry(list, type, member))
/* iterates over the list in reverse order, entry should be the container
* structure type
*/
#define list_for_every_entry_reverse(list, entry, type, member) \
for (entry = container_of((list)->prev, type, member); \
&entry->member != (list); \
entry = container_of(entry->member.prev, type, member))
/****************************************************************************
* Public Type Definitions
****************************************************************************/
#include <nuttx/list_type.h>
/****************************************************************************
* Inline Functions
****************************************************************************/
static inline FAR struct list_node*
list_remove_head(FAR struct list_node* list)
{
if (list->next != list) {
FAR struct list_node* item = list->next;
list_delete(item);
return item;
} else {
return NULL;
}
}
static inline FAR struct list_node*
list_remove_tail(FAR struct list_node* list)
{
if (list->prev != list) {
FAR struct list_node* item = list->prev;
list_delete(item);
return item;
} else {
return NULL;
}
}
static inline size_t list_length(FAR struct list_node* list)
{
FAR struct list_node* node = list;
size_t cnt = 0;
list_for_every(list, node)
{
cnt++;
}
return cnt;
}
#endif /* __INCLUDE_NUTTX_LIST_H */

View File

@ -24,6 +24,9 @@ extern "C" {
#include <stdint.h>
#include <stdlib.h>
/* Default string returned when state name is NULL */
#define HSM_NONE_STR "None"
typedef struct _state_machine state_machine_t;
typedef struct _state {

View File

@ -22,17 +22,6 @@
typedef void (*thread_func_t)(void* data);
typedef struct thread_loop_work thread_loop_work_t;
typedef void (*thread_work_cb_t)(thread_loop_work_t* work, void* userdata);
typedef void (*thread_after_work_cb_t)(thread_loop_work_t* work, void* userdata);
typedef struct thread_loop_work {
uv_work_t work;
thread_work_cb_t work_cb;
thread_after_work_cb_t after_work_cb;
void* userdata;
} thread_loop_work_t;
int thread_loop_init(uv_loop_t* loop);
int thread_loop_run(uv_loop_t* loop, bool start_thread, const char* name);
void thread_loop_exit(uv_loop_t* loop);
@ -44,7 +33,5 @@ uv_timer_t* thread_loop_timer_no_repeating(uv_loop_t* loop, uint64_t timeout, uv
void thread_loop_cancel_timer(uv_timer_t* timer);
void do_in_thread_loop(uv_loop_t* loop, thread_func_t func, void* data);
void do_in_thread_loop_sync(uv_loop_t* loop, thread_func_t func, void* data);
void thread_loop_work_sync(uv_loop_t* loop, void* user_data, thread_work_cb_t work_cb,
thread_after_work_cb_t after_work_cb);
#endif /* _UV_THREAD_LOOP_H__ */

View File

@ -30,7 +30,15 @@ static void adapter_status_reply(bt_instance_t* ins, bt_message_packet_t* packet
{
bt_status_cb_t ret_cb = (bt_status_cb_t)cb;
HANDLE_BT_ASTNC_CALLBACK(ret_cb, ins, packet, adpt_r, userdata);
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, userdata);
}
static void adapter_bool_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
@ -249,7 +257,7 @@ bt_status_t bt_adapter_register_callback_async(bt_instance_t* ins,
{
bt_register_callback_data_t* data;
bt_socket_async_client_t* priv;
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
bt_status_t status;
void* handle;
@ -302,7 +310,7 @@ send_message:
bt_status_t bt_adapter_unregister_callback_async(bt_instance_t* ins, void* cookie, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
bt_socket_async_client_t* priv;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -324,7 +332,7 @@ bt_status_t bt_adapter_unregister_callback_async(bt_instance_t* ins, void* cooki
bt_status_t bt_adapter_enable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -333,7 +341,7 @@ bt_status_t bt_adapter_enable_async(bt_instance_t* ins, bt_status_cb_t cb, void*
bt_status_t bt_adapter_disable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -342,7 +350,7 @@ bt_status_t bt_adapter_disable_async(bt_instance_t* ins, bt_status_cb_t cb, void
bt_status_t bt_adapter_enable_le_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -351,7 +359,7 @@ bt_status_t bt_adapter_enable_le_async(bt_instance_t* ins, bt_status_cb_t cb, vo
bt_status_t bt_adapter_disable_le_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -360,7 +368,7 @@ bt_status_t bt_adapter_disable_le_async(bt_instance_t* ins, bt_status_cb_t cb, v
bt_status_t bt_adapter_get_state_async(bt_instance_t* ins, bt_adapter_get_state_cb_t get_state_cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -369,7 +377,7 @@ bt_status_t bt_adapter_get_state_async(bt_instance_t* ins, bt_adapter_get_state_
bt_status_t bt_adapter_is_le_enabled_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -378,7 +386,7 @@ bt_status_t bt_adapter_is_le_enabled_async(bt_instance_t* ins, bt_bool_cb_t cb,
bt_status_t bt_adapter_get_type_async(bt_instance_t* ins, bt_device_type_cb_t get_dtype_cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -392,7 +400,7 @@ bt_status_t bt_adapter_set_discovery_filter_async(bt_instance_t* ins, bt_status_
bt_status_t bt_adapter_start_discovery_async(bt_instance_t* ins, uint32_t timeout, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -403,7 +411,7 @@ bt_status_t bt_adapter_start_discovery_async(bt_instance_t* ins, uint32_t timeou
bt_status_t bt_adapter_cancel_discovery_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -412,7 +420,7 @@ bt_status_t bt_adapter_cancel_discovery_async(bt_instance_t* ins, bt_status_cb_t
bt_status_t bt_adapter_is_discovering_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -421,7 +429,7 @@ bt_status_t bt_adapter_is_discovering_async(bt_instance_t* ins, bt_bool_cb_t cb,
bt_status_t bt_adapter_get_address_async(bt_instance_t* ins, bt_address_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -430,7 +438,7 @@ bt_status_t bt_adapter_get_address_async(bt_instance_t* ins, bt_address_cb_t cb,
bt_status_t bt_adapter_set_name_async(bt_instance_t* ins, const char* name, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -445,7 +453,7 @@ bt_status_t bt_adapter_set_name_async(bt_instance_t* ins, const char* name, bt_s
bt_status_t bt_adapter_get_name_async(bt_instance_t* ins, bt_string_cb_t get_name_cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -454,7 +462,7 @@ bt_status_t bt_adapter_get_name_async(bt_instance_t* ins, bt_string_cb_t get_nam
bt_status_t bt_adapter_get_uuids_async(bt_instance_t* ins, bt_uuids_cb_t get_uuids_cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -463,7 +471,7 @@ bt_status_t bt_adapter_get_uuids_async(bt_instance_t* ins, bt_uuids_cb_t get_uui
bt_status_t bt_adapter_set_scan_mode_async(bt_instance_t* ins, bt_scan_mode_t mode, bool bondable, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -475,7 +483,7 @@ bt_status_t bt_adapter_set_scan_mode_async(bt_instance_t* ins, bt_scan_mode_t mo
bt_status_t bt_adapter_get_scan_mode_async(bt_instance_t* ins, bt_adapter_get_scan_mode_cb_t get_scan_mode_cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -484,7 +492,7 @@ bt_status_t bt_adapter_get_scan_mode_async(bt_instance_t* ins, bt_adapter_get_sc
bt_status_t bt_adapter_set_device_class_async(bt_instance_t* ins, uint32_t cod, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -495,7 +503,7 @@ bt_status_t bt_adapter_set_device_class_async(bt_instance_t* ins, uint32_t cod,
bt_status_t bt_adapter_get_device_class_async(bt_instance_t* ins, bt_u32_cb_t get_cod_cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -504,7 +512,7 @@ bt_status_t bt_adapter_get_device_class_async(bt_instance_t* ins, bt_u32_cb_t ge
bt_status_t bt_adapter_set_io_capability_async(bt_instance_t* ins, bt_io_capability_t cap, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -515,7 +523,7 @@ bt_status_t bt_adapter_set_io_capability_async(bt_instance_t* ins, bt_io_capabil
bt_status_t bt_adapter_get_io_capability_async(bt_instance_t* ins, bt_adapter_get_io_capability_cb_t get_ioc_cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -525,7 +533,7 @@ bt_status_t bt_adapter_get_io_capability_async(bt_instance_t* ins, bt_adapter_ge
bt_status_t bt_adapter_set_inquiry_scan_parameters_async(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -539,7 +547,7 @@ bt_status_t bt_adapter_set_inquiry_scan_parameters_async(bt_instance_t* ins, bt_
bt_status_t bt_adapter_set_page_scan_parameters_async(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -552,7 +560,7 @@ bt_status_t bt_adapter_set_page_scan_parameters_async(bt_instance_t* ins, bt_sca
bt_status_t bt_adapter_set_le_io_capability_async(bt_instance_t* ins, uint32_t le_io_cap, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -563,7 +571,7 @@ bt_status_t bt_adapter_set_le_io_capability_async(bt_instance_t* ins, uint32_t l
bt_status_t bt_adapter_get_le_io_capability_async(bt_instance_t* ins, bt_u32_cb_t get_le_ioc_cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -572,7 +580,7 @@ bt_status_t bt_adapter_get_le_io_capability_async(bt_instance_t* ins, bt_u32_cb_
bt_status_t bt_adapter_get_le_address_async(bt_instance_t* ins, bt_adapter_get_le_address_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -581,7 +589,7 @@ bt_status_t bt_adapter_get_le_address_async(bt_instance_t* ins, bt_adapter_get_l
bt_status_t bt_adapter_set_le_address_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -592,7 +600,7 @@ bt_status_t bt_adapter_set_le_address_async(bt_instance_t* ins, bt_address_t* ad
bt_status_t bt_adapter_set_le_identity_address_async(bt_instance_t* ins, bt_address_t* addr, bool is_public, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -604,7 +612,7 @@ bt_status_t bt_adapter_set_le_identity_address_async(bt_instance_t* ins, bt_addr
bt_status_t bt_adapter_set_le_appearance_async(bt_instance_t* ins, uint16_t appearance, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -615,7 +623,7 @@ bt_status_t bt_adapter_set_le_appearance_async(bt_instance_t* ins, uint16_t appe
bt_status_t bt_adapter_get_le_appearance_async(bt_instance_t* ins, bt_u16_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -625,7 +633,7 @@ bt_status_t bt_adapter_get_le_appearance_async(bt_instance_t* ins, bt_u16_cb_t c
bt_status_t bt_adapter_le_enable_key_derivation_async(bt_instance_t* ins,
bool brkey_to_lekey, bool lekey_to_brkey, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -637,7 +645,7 @@ bt_status_t bt_adapter_le_enable_key_derivation_async(bt_instance_t* ins,
bt_status_t bt_adapter_le_add_whitelist_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -648,7 +656,7 @@ bt_status_t bt_adapter_le_add_whitelist_async(bt_instance_t* ins, bt_address_t*
bt_status_t bt_adapter_le_remove_whitelist_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -659,7 +667,7 @@ bt_status_t bt_adapter_le_remove_whitelist_async(bt_instance_t* ins, bt_address_
bt_status_t bt_adapter_get_bonded_devices_async(bt_instance_t* ins, bt_transport_t transport, bt_adapter_get_devices_cb_t get_bonded_cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -670,7 +678,7 @@ bt_status_t bt_adapter_get_bonded_devices_async(bt_instance_t* ins, bt_transport
bt_status_t bt_adapter_get_connected_devices_async(bt_instance_t* ins, bt_transport_t transport, bt_adapter_get_devices_cb_t get_connected_cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -682,7 +690,7 @@ bt_status_t bt_adapter_get_connected_devices_async(bt_instance_t* ins, bt_transp
bt_status_t bt_adapter_set_afh_channel_classification_async(bt_instance_t* ins, uint16_t central_frequency,
uint16_t band_width, uint16_t number, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -700,7 +708,7 @@ bt_status_t bt_adapter_set_auto_sniff_async(bt_instance_t* ins, bt_auto_sniff_pa
bt_status_t bt_adapter_disconnect_all_devices_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -709,7 +717,7 @@ bt_status_t bt_adapter_disconnect_all_devices_async(bt_instance_t* ins, bt_statu
bt_status_t bt_adapter_is_support_bredr_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -718,7 +726,7 @@ bt_status_t bt_adapter_is_support_bredr_async(bt_instance_t* ins, bt_bool_cb_t c
bt_status_t bt_adapter_is_support_le_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -727,7 +735,7 @@ bt_status_t bt_adapter_is_support_le_async(bt_instance_t* ins, bt_bool_cb_t cb,
bt_status_t bt_adapter_is_support_leaudio_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);

View File

@ -43,7 +43,15 @@ static void device_status_reply(bt_instance_t* ins, bt_message_packet_t* packet,
{
bt_status_cb_t ret_cb = (bt_status_cb_t)cb;
HANDLE_BT_ASTNC_CALLBACK(ret_cb, ins, packet, devs_r, userdata);
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, userdata);
}
static void device_bool_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
@ -206,7 +214,7 @@ static int bt_device_send_async(bt_instance_t* ins, bt_address_t* addr,
bt_status_t bt_device_get_identity_address_async(bt_instance_t* ins, bt_address_t* bd_addr, bt_address_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -215,7 +223,7 @@ bt_status_t bt_device_get_identity_address_async(bt_instance_t* ins, bt_address_
bt_status_t bt_device_get_address_type_async(bt_instance_t* ins, bt_address_t* addr, bt_device_get_address_type_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -224,7 +232,7 @@ bt_status_t bt_device_get_address_type_async(bt_instance_t* ins, bt_address_t* a
bt_status_t bt_device_get_device_type_async(bt_instance_t* ins, bt_address_t* addr, bt_device_type_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -244,7 +252,7 @@ bt_status_t bt_device_get_name_async(bt_instance_t* ins, bt_address_t* addr, bt_
bt_status_t bt_device_get_device_class_async(bt_instance_t* ins, bt_address_t* addr, bt_u32_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -264,7 +272,7 @@ bt_status_t bt_device_get_uuids_async(bt_instance_t* ins, bt_address_t* addr, bt
bt_status_t bt_device_get_appearance_async(bt_instance_t* ins, bt_address_t* addr, bt_u16_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -273,7 +281,7 @@ bt_status_t bt_device_get_appearance_async(bt_instance_t* ins, bt_address_t* add
bt_status_t bt_device_get_rssi_async(bt_instance_t* ins, bt_address_t* addr, bt_s8_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -308,7 +316,7 @@ bt_status_t bt_device_set_alias_async(bt_instance_t* ins, bt_address_t* addr,
bt_status_t bt_device_is_connected_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -320,7 +328,7 @@ bt_status_t bt_device_is_connected_async(bt_instance_t* ins, bt_address_t* addr,
bt_status_t bt_device_is_encrypted_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -332,7 +340,7 @@ bt_status_t bt_device_is_encrypted_async(bt_instance_t* ins, bt_address_t* addr,
bt_status_t bt_device_is_bond_initiate_local_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -344,7 +352,7 @@ bt_status_t bt_device_is_bond_initiate_local_async(bt_instance_t* ins, bt_addres
bt_status_t bt_device_get_bond_state_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_device_get_bond_state_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -356,7 +364,7 @@ bt_status_t bt_device_get_bond_state_async(bt_instance_t* ins, bt_address_t* add
bt_status_t bt_device_is_bonded_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -367,7 +375,7 @@ bt_status_t bt_device_is_bonded_async(bt_instance_t* ins, bt_address_t* addr,
bt_status_t bt_device_connect_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -376,7 +384,7 @@ bt_status_t bt_device_connect_async(bt_instance_t* ins, bt_address_t* addr, bt_s
bt_status_t bt_device_disconnect_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -388,7 +396,7 @@ bt_status_t bt_device_connect_le_async(bt_instance_t* ins,
ble_addr_type_t type,
ble_connect_params_t* param, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -401,7 +409,7 @@ bt_status_t bt_device_connect_le_async(bt_instance_t* ins,
bt_status_t bt_device_disconnect_le_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -411,7 +419,7 @@ bt_status_t bt_device_disconnect_le_async(bt_instance_t* ins, bt_address_t* addr
bt_status_t bt_device_connect_request_reply_async(bt_instance_t* ins, bt_address_t* addr,
bool accept, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -423,7 +431,7 @@ bt_status_t bt_device_connect_request_reply_async(bt_instance_t* ins, bt_address
bt_status_t bt_device_connect_all_profile_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -432,7 +440,7 @@ bt_status_t bt_device_connect_all_profile_async(bt_instance_t* ins, bt_address_t
bt_status_t bt_device_disconnect_all_profile_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -444,7 +452,7 @@ bt_status_t bt_device_set_le_phy_async(bt_instance_t* ins,
ble_phy_type_t tx_phy,
ble_phy_type_t rx_phy, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -458,7 +466,7 @@ bt_status_t bt_device_set_le_phy_async(bt_instance_t* ins,
bt_status_t bt_device_create_bond_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -470,7 +478,7 @@ bt_status_t bt_device_create_bond_async(bt_instance_t* ins, bt_address_t* addr,
bt_status_t bt_device_remove_bond_async(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -482,7 +490,7 @@ bt_status_t bt_device_remove_bond_async(bt_instance_t* ins, bt_address_t* addr,
bt_status_t bt_device_cancel_bond_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -493,7 +501,7 @@ bt_status_t bt_device_cancel_bond_async(bt_instance_t* ins, bt_address_t* addr,
bt_status_t bt_device_pair_request_reply_async(bt_instance_t* ins, bt_address_t* addr, bool accept, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -506,7 +514,7 @@ bt_status_t bt_device_pair_request_reply_async(bt_instance_t* ins, bt_address_t*
bt_status_t bt_device_set_pairing_confirmation_async(bt_instance_t* ins, bt_address_t* addr,
uint8_t transport, bool accept, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -520,7 +528,7 @@ bt_status_t bt_device_set_pairing_confirmation_async(bt_instance_t* ins, bt_addr
bt_status_t bt_device_set_pin_code_async(bt_instance_t* ins, bt_address_t* addr, bool accept,
char* pincode, int len, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
if (len > sizeof(packet.devs_pl._bt_device_set_pin_code.pincode))
@ -537,7 +545,7 @@ bt_status_t bt_device_set_pin_code_async(bt_instance_t* ins, bt_address_t* addr,
bt_status_t bt_device_set_pass_key_async(bt_instance_t* ins, bt_address_t* addr,
uint8_t transport, bool accept, uint32_t passkey, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -552,7 +560,7 @@ bt_status_t bt_device_set_pass_key_async(bt_instance_t* ins, bt_address_t* addr,
bt_status_t bt_device_set_le_legacy_tk_async(bt_instance_t* ins, bt_address_t* addr,
bt_128key_t tk_val, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -565,7 +573,7 @@ bt_status_t bt_device_set_le_legacy_tk_async(bt_instance_t* ins, bt_address_t* a
bt_status_t bt_device_set_le_sc_remote_oob_data_async(bt_instance_t* ins, bt_address_t* addr,
bt_128key_t c_val, bt_128key_t r_val, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -578,7 +586,7 @@ bt_status_t bt_device_set_le_sc_remote_oob_data_async(bt_instance_t* ins, bt_add
bt_status_t bt_device_get_le_sc_local_oob_data_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);

View File

@ -38,16 +38,19 @@ typedef struct {
gattc_handle_t* user_phandle;
} bt_gattc_create_connect_data_t;
typedef struct {
void* userdata;
void* gattc_remote;
} bt_gattc_delete_connect_data_t;
static void gattc_status_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_status_cb_t ret_cb = (bt_status_cb_t)cb;
HANDLE_BT_ASTNC_CALLBACK(ret_cb, ins, packet, gattc_r, userdata);
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, userdata);
return;
}
ret_cb(ins, packet->gattc_r.status, userdata);
}
static void gattc_get_attribute_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
@ -75,7 +78,7 @@ static void gattc_create_connect_reply(bt_instance_t* ins, bt_message_packet_t*
if (!packet || packet->gattc_r.status != BT_STATUS_SUCCESS)
goto error;
gattc_remote->cookie = PTR2INT(uint64_t) packet->gattc_r.handle;
gattc_remote->cookie = INT2PTR(void*) packet->gattc_r.handle;
gattc_remote->user_phandle = data->user_phandle;
bt_list_add_tail(priv->gattc_remote_list, gattc_remote);
*(data->user_phandle) = gattc_remote;
@ -106,40 +109,32 @@ error:
static void gattc_delete_connect_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_gattc_delete_connect_data_t* data = userdata;
bt_socket_async_client_t* priv = ins->priv;
bt_gattc_delete_connect_cb_t ret_cb = (bt_gattc_delete_connect_cb_t)cb;
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)data->gattc_remote;
void** user_phandle = gattc_remote->user_phandle;
bt_list_remove(priv->gattc_remote_list, gattc_remote);
*user_phandle = NULL;
if (!bt_list_length(priv->gattc_remote_list)) {
bt_list_free(priv->gattc_remote_list);
priv->gattc_remote_list = NULL;
}
if (!ret_cb) {
free(userdata);
if (!ret_cb)
return;
}
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, data->userdata);
free(userdata);
ret_cb(ins, BT_STATUS_UNHANDLED, userdata);
return;
}
ret_cb(ins, packet->gattc_r.status, data->userdata);
free(userdata);
ret_cb(ins, packet->gattc_r.status, userdata);
}
static void gattc_write_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_gattc_write_cb_t ret_cb = (bt_gattc_write_cb_t)cb;
HANDLE_BT_ASTNC_CALLBACK(ret_cb, ins, packet, gattc_r, userdata);
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, userdata);
return;
}
ret_cb(ins, packet->gattc_r.status, userdata);
}
bt_status_t bt_gattc_create_connect_async(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks,
@ -206,10 +201,11 @@ fail:
bt_status_t bt_gattc_delete_connect_async(gattc_handle_t conn_handle, bt_gattc_delete_connect_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_delete_connect_data_t* data;
bt_socket_async_client_t* priv;
bt_status_t status;
bt_instance_t* ins;
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
void** user_phandle;
CHECK_NULL_PTR(gattc_remote);
@ -220,11 +216,18 @@ bt_status_t bt_gattc_delete_connect_async(gattc_handle_t conn_handle, bt_gattc_d
ins = gattc_remote->ins;
packet.gattc_pl._bt_gattc_delete.handle = PTR2INT(uint64_t) gattc_remote->cookie;
data = calloc(1, sizeof(bt_gattc_delete_connect_data_t));
data->userdata = userdata;
data->gattc_remote = (void*)gattc_remote;
status = bt_socket_client_send_with_reply(ins, &packet, BT_GATT_CLIENT_DELETE_CONNECT, gattc_delete_connect_reply, (void*)cb, userdata);
return bt_socket_client_send_with_reply(ins, &packet, BT_GATT_CLIENT_DELETE_CONNECT, gattc_delete_connect_reply, (void*)cb, data);
user_phandle = gattc_remote->user_phandle;
bt_list_remove(priv->gattc_remote_list, gattc_remote);
*user_phandle = NULL;
if (!bt_list_length(priv->gattc_remote_list)) {
bt_list_free(priv->gattc_remote_list);
priv->gattc_remote_list = NULL;
}
return status;
}
bt_status_t bt_gattc_connect_async(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type, bt_status_cb_t cb, void* userdata)

View File

@ -34,7 +34,15 @@ static void le_advertiser_status_reply(bt_instance_t* ins, bt_message_packet_t*
{
bt_status_cb_t ret_cb = (bt_status_cb_t)cb;
HANDLE_BT_ASTNC_CALLBACK(ret_cb, ins, packet, adv_r, context);
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, context);
return;
}
ret_cb(ins, packet->adv_r.status, context);
}
static void le_advertiser_bool_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
@ -101,7 +109,7 @@ bt_status_t bt_le_start_advertising_async(bt_instance_t* ins, ble_adv_params_t*
return BT_STATUS_NOMEM;
adv->ins = ins;
adv->callback = adv_cbs;
adv->callbacks = adv_cbs;
packet.adv_pl._bt_le_start_advertising.adver = PTR2INT(uint64_t) adv;
memcpy(&packet.adv_pl._bt_le_start_advertising.params, params, sizeof(*params));
if ((adv_len && (adv_len > sizeof(packet.adv_pl._bt_le_start_advertising.adv_data)))

View File

@ -102,7 +102,7 @@ bt_status_t bt_le_start_scan_async(bt_instance_t* ins, const scanner_callbacks_t
return BT_STATUS_FAIL;
scan->ins = ins;
scan->callback = (scanner_callbacks_t*)scan_cbs;
scan->callbacks = (scanner_callbacks_t*)scan_cbs;
packet.scan_pl._bt_le_start_scan.remote = PTR2INT(uint64_t) scan;
data = calloc(1, sizeof(bt_le_start_scan_data_t));
@ -135,7 +135,7 @@ bt_status_t bt_le_start_scan_settings_async(bt_instance_t* ins, ble_scan_setting
return BT_STATUS_FAIL;
scan->ins = ins;
scan->callback = (scanner_callbacks_t*)scan_cbs;
scan->callbacks = (scanner_callbacks_t*)scan_cbs;
packet.scan_pl._bt_le_start_scan_settings.remote = PTR2INT(uint64_t) scan;
if (settings)
memcpy(&packet.scan_pl._bt_le_start_scan_settings.settings, settings, sizeof(*settings));
@ -170,7 +170,7 @@ bt_status_t bt_le_start_scan_with_filters_async(bt_instance_t* ins, ble_scan_set
return BT_STATUS_FAIL;
scan->ins = ins;
scan->callback = (scanner_callbacks_t*)scan_cbs;
scan->callbacks = (scanner_callbacks_t*)scan_cbs;
packet.scan_pl._bt_le_start_scan_with_filters.remote = PTR2INT(uint64_t) scan;
if (settings)
memcpy(&packet.scan_pl._bt_le_start_scan_with_filters.settings, settings, sizeof(*settings));

View File

@ -23,10 +23,6 @@
#include "manager_service.h"
#include "service_loop.h"
#ifdef CONFIG_NET_RPMSG
#include <netpacket/rpmsg.h>
#endif
bt_instance_t* bluetooth_create_instance(void)
{
bt_status_t status;
@ -111,8 +107,8 @@ bt_instance_t* bluetooth_create_async_instance(uv_loop_t* loop, bt_ipc_connected
return NULL;
}
status = manager_create_async_instance(PTR2INT(uint64_t) ins, BLUETOOTH_SYSTEM,
"local", getpid(), (uid_t)pthread_self(), &ins->app_id);
status = manager_create_instance(PTR2INT(uint64_t) ins, BLUETOOTH_SYSTEM,
"local", getpid(), 0, &ins->app_id);
if (status != BT_STATUS_SUCCESS) {
bt_socket_client_deinit(ins);
free(ins);
@ -133,18 +129,6 @@ bt_instance_t* bluetooth_find_instance(pid_t pid)
return INT2PTR(bt_instance_t*) handle;
}
bt_instance_t* bluetooth_find_async_instance(pid_t pid)
{
bt_status_t status;
uint64_t handle;
status = manager_get_async_instance("local", pid, &handle);
if (status != BT_STATUS_SUCCESS) {
return NULL;
}
return INT2PTR(bt_instance_t*) handle;
}
bt_instance_t* bluetooth_get_instance(void)
{
bt_instance_t* bluetooth_ins = bluetooth_find_instance(getpid());
@ -155,16 +139,6 @@ bt_instance_t* bluetooth_get_instance(void)
return bluetooth_ins;
}
bt_instance_t* bluetooth_get_async_instance(uv_loop_t* loop, bt_ipc_connected_cb_t connected, bt_ipc_disconnected_cb_t disconnected, void* user_data)
{
bt_instance_t* bluetooth_ins = bluetooth_find_async_instance(getpid());
if (bluetooth_ins == NULL)
return bluetooth_create_async_instance(loop, connected, disconnected, user_data);
else
return bluetooth_ins;
}
void* bluetooth_get_proxy(bt_instance_t* ins, enum profile_id id)
{
return NULL;

View File

@ -117,21 +117,6 @@ bt_status_t bt_adapter_disable(bt_instance_t* ins)
return packet.adpt_r.status;
}
bt_status_t bt_adapter_disable_safe(bt_instance_t* ins)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
status = bt_socket_client_sendrecv(ins, &packet, BT_ADAPTER_DISABLE_SAFE);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.adpt_r.status;
}
bt_status_t bt_adapter_enable_le(bt_instance_t* ins)
{
bt_message_packet_t packet;
@ -238,22 +223,6 @@ bt_status_t bt_adapter_start_discovery(bt_instance_t* ins, uint32_t timeout)
return packet.adpt_r.status;
}
bt_status_t bt_adapter_start_limited_discovery(bt_instance_t* ins, uint32_t timeout)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_start_limited_discovery.v32 = timeout;
status = bt_socket_client_sendrecv(ins, &packet, BT_ADAPTER_START_LIMITED_DISCOVERY);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.adpt_r.status;
}
bt_status_t bt_adapter_cancel_discovery(bt_instance_t* ins)
{
bt_message_packet_t packet;
@ -575,7 +544,7 @@ bt_status_t bt_adapter_set_le_address(bt_instance_t* ins, bt_address_t* addr)
return packet.adpt_r.status;
}
bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t* addr, bool is_public)
bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t* addr, bool public)
{
bt_message_packet_t packet;
bt_status_t status;
@ -583,7 +552,7 @@ bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t*
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.adpt_pl._bt_adapter_set_le_identity_address.addr, addr, sizeof(*addr));
packet.adpt_pl._bt_adapter_set_le_identity_address.pub = is_public;
packet.adpt_pl._bt_adapter_set_le_identity_address.pub = public;
status = bt_socket_client_sendrecv(ins, &packet, BT_ADAPTER_SET_LE_IDENTITY_ADDRESS);
if (status != BT_STATUS_SUCCESS) {
return status;
@ -643,11 +612,6 @@ bt_status_t bt_adapter_le_enable_key_derivation(bt_instance_t* ins,
}
bt_status_t bt_adapter_le_add_whitelist(bt_instance_t* ins, bt_address_t* addr)
{
return bt_adapter_le_add_whitelist_with_type(ins, addr, BT_LE_ADDR_TYPE_UNKNOWN);
}
bt_status_t bt_adapter_le_add_whitelist_with_type(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t type)
{
bt_message_packet_t packet;
bt_status_t status;
@ -655,7 +619,6 @@ bt_status_t bt_adapter_le_add_whitelist_with_type(bt_instance_t* ins, bt_address
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.adpt_pl._bt_adapter_le_add_whitelist.addr, addr, sizeof(*addr));
packet.adpt_pl._bt_adapter_le_add_whitelist.type = (uint8_t)type;
status = bt_socket_client_sendrecv(ins, &packet, BT_ADAPTER_LE_ADD_WHITELIST);
if (status != BT_STATUS_SUCCESS) {
return status;
@ -808,3 +771,24 @@ bool bt_adapter_is_support_leaudio(bt_instance_t* ins)
return packet.adpt_r.bbool;
}
bt_status_t bt_adapter_start_limited_discovery(bt_instance_t* ins, uint32_t timeout)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_start_limited_discovery.v32 = timeout;
status = bt_socket_client_sendrecv(ins, &packet, BT_ADAPTER_START_LIMITED_DISCOVERY);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.adpt_r.status;
}
bt_status_t bt_adapter_disable_safe(bt_instance_t* ins)
{
return bt_adapter_disable(ins);
}

View File

@ -116,71 +116,5 @@ bt_status_t bt_avrcp_control_send_passthrough_cmd(bt_instance_t* ins, bt_address
return status;
}
return packet.avrcp_control_r.status;
}
bt_status_t bt_avrcp_control_get_unit_info(bt_instance_t* ins, bt_address_t* addr)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.avrcp_control_pl._bt_avrcp_control_get_unit_info.addr, addr, sizeof(packet.avrcp_control_pl._bt_avrcp_control_get_unit_info.addr));
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CT_GET_UNIT_INFO_CMD);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.avrcp_control_r.status;
}
bt_status_t bt_avrcp_control_get_subunit_info(bt_instance_t* ins, bt_address_t* addr)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.avrcp_control_pl._bt_avrcp_control_get_subunit_info.addr, addr, sizeof(packet.avrcp_control_pl._bt_avrcp_control_get_subunit_info.addr));
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CT_GET_SUBUNIT_INFO_CMD);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.avrcp_control_r.status;
}
bt_status_t bt_avrcp_control_get_playback_state(bt_instance_t* ins, bt_address_t* addr)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.avrcp_control_pl._bt_avrcp_control_get_playback_state.addr, addr, sizeof(packet.avrcp_control_pl._bt_avrcp_control_get_playback_state.addr));
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CT_GET_PLAYBACK_STATE_CMD);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.avrcp_control_r.status;
}
bt_status_t bt_avrcp_control_register_notification(bt_instance_t* ins, bt_address_t* addr, uint8_t event, uint32_t interval)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.avrcp_control_pl._bt_avrcp_control_register_notification.addr, addr, sizeof(packet.avrcp_control_pl._bt_avrcp_control_register_notification.addr));
packet.avrcp_control_pl._bt_avrcp_control_register_notification.event = event;
packet.avrcp_control_pl._bt_avrcp_control_register_notification.interval = interval;
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CT_REGISTER_NOTIFICATION_CMD);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.avrcp_control_r.status;
}

146
framework/socket/bt_cs.c Normal file
View File

@ -0,0 +1,146 @@
/****************************************************************************
* Copyright (C) 2025 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_cs.h"
#include "bt_message.h"
#include "bt_socket.h"
#include <stdint.h>
void* bt_cs_register_callbacks(bt_instance_t* ins, const cs_callbacks_t* callbacks)
{
bt_message_packet_t packet;
bt_status_t status;
void* cookie;
BT_SOCKET_INS_VALID(ins, NULL);
if (ins->cs_callbacks != NULL) {
cookie = bt_remote_callbacks_register(ins->cs_callbacks, NULL, (void*)callbacks);
return cookie;
}
ins->cs_callbacks = bt_callbacks_list_new(CONFIG_BLUETOOTH_MAX_REGISTER_NUM);
cookie = bt_remote_callbacks_register(ins->cs_callbacks, NULL, (void*)callbacks);
if (cookie == NULL) {
bt_callbacks_list_free(ins->cs_callbacks);
ins->cs_callbacks = NULL;
return cookie;
}
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_REGISTER_CALLBACKS);
if (status != BT_STATUS_SUCCESS || packet.cs_r.status != BT_STATUS_SUCCESS) {
bt_callbacks_list_free(ins->cs_callbacks);
ins->cs_callbacks = NULL;
return NULL;
}
return cookie;
}
bool bt_cs_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, false);
if (!ins->cs_callbacks)
return false;
bt_remote_callbacks_unregister(ins->cs_callbacks, NULL, cookie);
if (bt_callbacks_list_count(ins->cs_callbacks) > 0) {
return true;
}
bt_callbacks_list_free(ins->cs_callbacks);
ins->cs_callbacks = NULL;
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_UNREGISTER_CALLBACKS);
if (status != BT_STATUS_SUCCESS || packet.cs_r.status != BT_STATUS_SUCCESS) {
return false;
}
return true;
}
bt_status_t bt_cs_start_distance_measurement(bt_instance_t* ins, const bt_distance_measurement_params_t* params)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.cs_pl._bt_cs_start_distance_measurement.params, params, sizeof(bt_distance_measurement_params_t));
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_START_DISTANCE_MEASUREMENT);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.cs_r.status;
}
bt_status_t bt_cs_stop_distance_measurement(bt_instance_t* ins, bt_address_t* addr, uint8_t method, bool timeout)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.cs_pl._bt_cs_stop_distance_measurement.addr, addr, sizeof(packet.cs_pl._bt_cs_stop_distance_measurement.addr));
packet.cs_pl._bt_cs_stop_distance_measurement.method = method;
packet.cs_pl._bt_cs_stop_distance_measurement.timeout_bool = timeout;
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_STOP_DISTANCE_MEASUREMENT);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.cs_r.status;
}
bt_status_t bt_cs_set_config(bt_instance_t* ins, bt_address_t* addr, const bt_cs_set_params_t* params)
{
bt_message_packet_t packet = { 0 };
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
if (addr)
memcpy(&packet.cs_pl._bt_cs_set_config.addr, addr, sizeof(bt_address_t));
memcpy(&packet.cs_pl._bt_cs_set_config.params, params, sizeof(bt_cs_set_params_t));
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_SET_CONFIG);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.cs_r.status;
}
#ifdef CONFIG_BT_CS_RAS_TEST
bt_status_t bt_cs_test(bt_instance_t* ins, const void* data, uint16_t len)
{
bt_message_packet_t packet = { 0 };
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
if (data) {
memcpy(&packet.cs_pl._bt_cs_test.data, data, len);
}
packet.cs_pl._bt_cs_test.len = len;
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_TEST);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.cs_r.status;
}
#endif /* CONFIG_BT_CS_RAS_TEST */

View File

@ -177,7 +177,7 @@ bool bt_device_get_alias(bt_instance_t* ins, bt_address_t* addr, char* alias, ui
}
strlcpy(alias, packet.devs_pl._bt_device_get_alias.alias,
MIN(length, sizeof(packet.devs_pl._bt_device_get_alias.alias)));
MIN(length, sizeof(packet.devs_pl._bt_device_get_alias.alias) - 1));
return packet.devs_r.status;
}
@ -288,40 +288,6 @@ bt_status_t bt_device_connect(bt_instance_t* ins, bt_address_t* addr)
return packet.devs_r.status;
}
bt_status_t bt_device_background_connect(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
bt_message_packet_t packet;
bt_status_t status;
if (addr)
memcpy(&packet.devs_pl._bt_device_background_connect, addr, sizeof(*addr));
else
bt_addr_set_empty(&packet.devs_pl._bt_device_background_connect.addr);
packet.devs_pl._bt_device_background_connect.transport = transport;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_BACKGROUND_CONNECT);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.devs_r.status;
}
bt_status_t bt_device_background_disconnect(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_background_disconnect, addr, sizeof(*addr));
packet.devs_pl._bt_device_background_disconnect.transport = transport;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_BACKGROUND_DISCONNECT);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.devs_r.status;
}
bt_status_t bt_device_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
bt_message_packet_t packet;
@ -548,7 +514,6 @@ bt_status_t bt_device_set_pin_code(bt_instance_t* ins, bt_address_t* addr, bool
memcpy(&packet.devs_pl._bt_device_set_pin_code.addr, addr, sizeof(*addr));
memcpy(&packet.devs_pl._bt_device_set_pin_code.pincode, pincode, len);
packet.devs_pl._bt_device_set_pin_code.len = len;
packet.devs_pl._bt_device_set_pin_code.accept = accept;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_SET_PIN_CODE);
if (status != BT_STATUS_SUCCESS) {
return status;
@ -575,7 +540,7 @@ bt_status_t bt_device_set_pass_key(bt_instance_t* ins, bt_address_t* addr, uint8
return packet.devs_r.status;
}
bt_status_t BTSYMBOLS(bt_device_set_le_legacy_tk)(bt_instance_t* ins, bt_address_t* addr, bt_128key_t tk_val)
bt_status_t bt_device_set_le_legacy_tk(bt_instance_t* ins, bt_address_t* addr, bt_128key_t tk_val)
{
bt_message_packet_t packet;
bt_status_t status;
@ -626,34 +591,10 @@ bt_status_t bt_device_get_le_sc_local_oob_data(bt_instance_t* ins, bt_address_t*
bt_status_t bt_device_enable_enhanced_mode(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_enable_enhanced_mode.addr, addr, sizeof(packet.devs_pl._bt_device_enable_enhanced_mode.addr));
packet.devs_pl._bt_device_enable_enhanced_mode.mode = mode;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_ENABLE_ENHANCED_MODE);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.devs_r.status;
return BT_STATUS_NOT_SUPPORTED;
}
bt_status_t bt_device_disable_enhanced_mode(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_disable_enhanced_mode.addr, addr, sizeof(packet.devs_pl._bt_device_disable_enhanced_mode.addr));
packet.devs_pl._bt_device_disable_enhanced_mode.mode = mode;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_DISABLE_ENHANCED_MODE);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.devs_r.status;
return BT_STATUS_NOT_SUPPORTED;
}

View File

@ -66,7 +66,7 @@ bt_status_t bt_gattc_create_connect(bt_instance_t* ins, gattc_handle_t* phandle,
goto fail;
}
gattc_remote->cookie = packet.gattc_r.handle;
gattc_remote->cookie = INT2PTR(void*) packet.gattc_r.handle;
gattc_remote->user_phandle = phandle;
bt_list_add_tail(ins->gattc_remote_list, gattc_remote);
@ -267,27 +267,6 @@ bt_status_t bt_gattc_write_without_response(gattc_handle_t conn_handle, uint16_t
return packet.gattc_r.status;
}
bt_status_t bt_gattc_write_with_signed(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
bt_message_packet_t packet;
bt_status_t status;
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
if (length > sizeof(packet.gattc_pl._bt_gattc_write.value))
return BT_STATUS_PARM_INVALID;
packet.gattc_pl._bt_gattc_write.handle = gattc_remote->cookie;
packet.gattc_pl._bt_gattc_write.attr_handle = attr_handle;
packet.gattc_pl._bt_gattc_write.length = length;
memcpy(packet.gattc_pl._bt_gattc_write.value, value, length);
status = bt_socket_client_sendrecv(gattc_remote->ins, &packet, BT_GATT_CLIENT_WRITE_WITH_SIGNED);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.gattc_r.status;
}
bt_status_t bt_gattc_subscribe(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value)
{
bt_message_packet_t packet;

View File

@ -45,7 +45,7 @@ static bt_gatts_remote_t* gatts_remote_new(bt_instance_t* ins, gatts_callbacks_t
remote->ins = ins;
remote->callbacks = callbacks;
remote->cookie = 0;
remote->cookie = NULL;
return remote;
}
@ -91,7 +91,7 @@ bt_status_t bt_gatts_register_service(bt_instance_t* ins, gatts_handle_t* phandl
goto fail;
}
gatts_remote->cookie = packet.gatts_r.handle;
gatts_remote->cookie = INT2PTR(void*) packet.gatts_r.handle;
gatts_remote->user_phandle = phandle;
bt_list_add_tail(ins->gatts_remote_list, gatts_remote);
@ -199,50 +199,42 @@ bt_status_t bt_gatts_add_attr_table(gatts_handle_t srv_handle, gatt_srv_db_t* sr
{
bt_message_packet_t packet;
bt_status_t status;
int32_t attr_offset = 0;
int num_max;
bt_gatts_remote_t* gatts_remote = (bt_gatts_remote_t*)srv_handle;
uint8_t* raw_data;
uint8_t* raw_data = (uint8_t*)packet.gatts_pl._bt_gatts_add_attr_table.attr_db;
uint32_t data_length = sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db[0]) * srv_db->attr_num;
gatt_attr_db_t* attr_inst = srv_db->attr_db;
CHECK_NULL_PTR(gatts_remote);
if (data_length > sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db))
return BT_STATUS_PARM_INVALID;
while (attr_offset < srv_db->attr_num) {
num_max = (srv_db->attr_num - attr_offset)
> GATTS_MAX_ATTRIBUTE_NUM
? GATTS_MAX_ATTRIBUTE_NUM
: (srv_db->attr_num - attr_offset);
raw_data += data_length;
for (int i = 0; i < srv_db->attr_num; i++, attr_inst++) {
memcpy(&packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].uuid, &attr_inst->uuid,
sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].uuid));
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].handle = attr_inst->handle;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].type = attr_inst->type;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].rsp_type = attr_inst->rsp_type;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].properties = attr_inst->properties;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].permissions = attr_inst->permissions;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].attr_length = attr_inst->attr_length;
raw_data = (uint8_t*)packet.gatts_pl._bt_gatts_add_attr_table.attr_db
+ sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db[0]) * num_max;
attr_inst = srv_db->attr_db + attr_offset;
if (attr_inst->rsp_type == ATTR_AUTO_RSP && attr_inst->attr_length) {
data_length += attr_inst->attr_length;
if (data_length > sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db))
return BT_STATUS_PARM_INVALID;
for (int i = 0; i < num_max; i++, attr_inst++) {
memcpy(&packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].uuid, &attr_inst->uuid,
sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].uuid));
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].handle = attr_inst->handle;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].type = attr_inst->type;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].rsp_type = attr_inst->rsp_type;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].properties = attr_inst->properties;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].permissions = attr_inst->permissions;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].attr_length = attr_inst->attr_length;
if (attr_inst->rsp_type == ATTR_AUTO_RSP && attr_inst->attr_length) {
memcpy(raw_data, attr_inst->attr_value, attr_inst->attr_length);
raw_data += attr_inst->attr_length;
}
memcpy(raw_data, attr_inst->attr_value, attr_inst->attr_length);
raw_data += attr_inst->attr_length;
}
packet.gatts_pl._bt_gatts_add_attr_table.handle = PTR2INT(uint64_t) gatts_remote->cookie;
packet.gatts_pl._bt_gatts_add_attr_table.attr_num = srv_db->attr_num;
packet.gatts_pl._bt_gatts_add_attr_table.attr_num_offset = attr_offset;
status = bt_socket_client_sendrecv(gatts_remote->ins, &packet, BT_GATT_SERVER_ADD_ATTR_TABLE);
if (status != BT_STATUS_SUCCESS)
return status;
attr_offset += num_max;
}
packet.gatts_pl._bt_gatts_add_attr_table.handle = PTR2INT(uint64_t) gatts_remote->cookie;
packet.gatts_pl._bt_gatts_add_attr_table.attr_num = srv_db->attr_num;
status = bt_socket_client_sendrecv(gatts_remote->ins, &packet, BT_GATT_SERVER_ADD_ATTR_TABLE);
if (status != BT_STATUS_SUCCESS)
return status;
if (packet.gatts_r.status == BT_STATUS_SUCCESS) {
bt_list_add_tail(gatts_remote->db_list, srv_db);
}

View File

@ -327,6 +327,23 @@ bt_status_t bt_hfp_ag_send_at_command(bt_instance_t* ins, bt_address_t* addr, co
return packet.hfp_ag_r.status;
}
bt_status_t bt_hfp_ag_send_vendor_specific_at_command(bt_instance_t* ins, bt_address_t* addr, const char* command, const char* value)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.addr, addr, sizeof(bt_address_t));
strlcpy(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.cmd, command, sizeof(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.cmd));
strlcpy(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.value, value, sizeof(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.value));
status = bt_socket_client_sendrecv(ins, &packet, BT_HFP_AG_SEND_VENDOR_SPECIFIC_AT_COMMAND);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.hfp_ag_r.status;
}
bt_status_t bt_hfp_ag_send_clcc_response(bt_instance_t* ins, bt_address_t* addr, uint32_t index,
hfp_call_direction_t dir, hfp_ag_call_state_t state, hfp_call_mode_t mode,
hfp_call_mpty_type_t mpty, hfp_call_addrtype_t type, const char* number)
@ -355,24 +372,6 @@ bt_status_t bt_hfp_ag_send_clcc_response(bt_instance_t* ins, bt_address_t* addr,
return packet.hfp_ag_r.status;
}
bt_status_t bt_hfp_ag_send_vendor_specific_at_command(bt_instance_t* ins, bt_address_t* addr, const char* command, const char* value)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.addr, addr, sizeof(bt_address_t));
strlcpy(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.cmd, command, sizeof(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.cmd));
strlcpy(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.value, value, sizeof(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.value));
status = bt_socket_client_sendrecv(ins, &packet, BT_HFP_AG_SEND_VENDOR_SPECIFIC_AT_COMMAND);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.hfp_ag_r.status;
}
bt_status_t bt_hfp_ag_send_cind_response(bt_instance_t* ins, bt_address_t* addr,
hfp_network_state_t network, hfp_call_t call, hfp_callheld_t call_held, hfp_callsetup_t call_setup,
uint8_t signal, hfp_roaming_state_t roam, uint8_t battery)

View File

@ -454,34 +454,3 @@ bt_status_t bt_hfp_hf_send_dtmf(bt_instance_t* ins, bt_address_t* addr, char dtm
return packet.hfp_hf_r.status;
}
bt_status_t bt_hfp_hf_get_subscriber_number(bt_instance_t* ins, bt_address_t* addr)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.hfp_hf_pl._bt_hfp_hf_get_subscriber_number.addr, addr, sizeof(bt_address_t));
status = bt_socket_client_sendrecv(ins, &packet, BT_HFP_HF_GET_SUBSCRIBER_NUMBER);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.hfp_hf_r.status;
}
bt_status_t bt_hfp_hf_query_current_calls_with_callback(bt_instance_t* ins, bt_address_t* addr)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.hfp_hf_pl._bt_hfp_hf_query_current_calls_with_callback.addr, addr, sizeof(bt_address_t));
status = bt_socket_client_sendrecv(ins, &packet, BT_HFP_HF_QUERY_CURRENT_CALLS_WITH_CALLBACK);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.hfp_hf_r.status;
}

View File

@ -26,7 +26,7 @@ void* bt_l2cap_register_callbacks(bt_instance_t* ins, const l2cap_callbacks_t* c
{
bt_message_packet_t packet;
bt_status_t status;
void* handle;
void* cookie;
BT_SOCKET_INS_VALID(ins, NULL);
@ -39,8 +39,8 @@ void* bt_l2cap_register_callbacks(bt_instance_t* ins, const l2cap_callbacks_t* c
return NULL;
}
handle = bt_remote_callbacks_register(ins->l2cap_callbacks, NULL, (void*)callbacks);
if (handle == NULL) {
cookie = bt_remote_callbacks_register(ins->l2cap_callbacks, NULL, (void*)callbacks);
if (cookie == NULL) {
bt_callbacks_list_free(ins->l2cap_callbacks);
ins->l2cap_callbacks = NULL;
return NULL;
@ -53,10 +53,10 @@ void* bt_l2cap_register_callbacks(bt_instance_t* ins, const l2cap_callbacks_t* c
return NULL;
}
return handle;
return cookie;
}
bool bt_l2cap_unregister_callbacks(bt_instance_t* ins, void* handle)
bool bt_l2cap_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
bt_message_packet_t packet;
bt_status_t status;
@ -68,7 +68,7 @@ bool bt_l2cap_unregister_callbacks(bt_instance_t* ins, void* handle)
return false;
}
bt_remote_callbacks_unregister(ins->l2cap_callbacks, NULL, handle);
bt_remote_callbacks_unregister(ins->l2cap_callbacks, NULL, cookie);
cbsl = ins->l2cap_callbacks;
ins->l2cap_callbacks = NULL;
@ -82,7 +82,7 @@ bool bt_l2cap_unregister_callbacks(bt_instance_t* ins, void* handle)
return true;
}
bt_status_t bt_l2cap_listen(bt_instance_t* ins, void* handle, l2cap_config_option_t* option)
bt_status_t bt_l2cap_listen(bt_instance_t* ins, l2cap_config_option_t* option)
{
bt_message_packet_t packet;
bt_status_t status;
@ -94,14 +94,10 @@ bt_status_t bt_l2cap_listen(bt_instance_t* ins, void* handle, l2cap_config_optio
if (status != BT_STATUS_SUCCESS)
return status;
option->psm = packet.l2cap_pl._bt_l2cap_listen.option.psm;
option->id = packet.l2cap_pl._bt_l2cap_listen.option.id;
strlcpy(option->proxy_name, packet.l2cap_pl._bt_l2cap_listen.option.proxy_name, sizeof(option->proxy_name));
return packet.l2cap_r.status;
}
bt_status_t bt_l2cap_connect(bt_instance_t* ins, void* handle, bt_address_t* addr, l2cap_config_option_t* option)
bt_status_t bt_l2cap_connect(bt_instance_t* ins, bt_address_t* addr, l2cap_config_option_t* option)
{
bt_message_packet_t packet;
bt_status_t status;
@ -114,55 +110,20 @@ bt_status_t bt_l2cap_connect(bt_instance_t* ins, void* handle, bt_address_t* add
if (status != BT_STATUS_SUCCESS)
return status;
option->id = packet.l2cap_pl._bt_l2cap_connect.option.id;
strlcpy(option->proxy_name, packet.l2cap_pl._bt_l2cap_connect.option.proxy_name, sizeof(option->proxy_name));
return packet.l2cap_r.status;
}
bt_status_t bt_l2cap_disconnect(bt_instance_t* ins, void* handle, uint16_t id)
bt_status_t bt_l2cap_disconnect(bt_instance_t* ins, uint16_t cid)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.l2cap_pl._bt_l2cap_disconnect.id = id;
packet.l2cap_pl._bt_l2cap_disconnect.cid = cid;
status = bt_socket_client_sendrecv(ins, &packet, BT_L2CAP_DISCONNECT);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.l2cap_r.status;
}
bt_status_t bt_l2cap_stop_listen(bt_instance_t* ins, void* handle, uint16_t psm)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.l2cap_pl._bt_l2cap_stop_listen.transport = BT_TRANSPORT_BLE;
packet.l2cap_pl._bt_l2cap_stop_listen.psm = psm;
status = bt_socket_client_sendrecv(ins, &packet, BT_L2CAP_STOP_LISTEN);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.l2cap_r.status;
}
bt_status_t bt_l2cap_stop_listen_with_transport(bt_instance_t* ins, void* handle, bt_transport_t transport, uint16_t psm)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.l2cap_pl._bt_l2cap_stop_listen.transport = transport;
packet.l2cap_pl._bt_l2cap_stop_listen.psm = psm;
status = bt_socket_client_sendrecv(ins, &packet, BT_L2CAP_STOP_LISTEN);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.l2cap_r.status;
}

View File

@ -42,7 +42,7 @@ bt_advertiser_t* bt_le_start_advertising(bt_instance_t* ins,
if (adv == NULL)
return NULL;
adv->callback = cbs;
adv->callbacks = cbs;
packet.adv_pl._bt_le_start_advertising.adver = PTR2INT(uint64_t) adv;
memcpy(&packet.adv_pl._bt_le_start_advertising.params, params, sizeof(*params));
if ((adv_len && (adv_len > sizeof(packet.adv_pl._bt_le_start_advertising.adv_data)))

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "scan"
#define LOG_TAG "adv"
#include <stdlib.h>
@ -36,7 +36,7 @@ bt_scanner_t* bt_le_start_scan(bt_instance_t* ins, const scanner_callbacks_t* cb
if (scan == NULL)
return NULL;
scan->callback = (scanner_callbacks_t*)cbs;
scan->callbacks = (scanner_callbacks_t*)cbs;
packet.scan_pl._bt_le_start_scan.remote = PTR2INT(uint64_t) scan;
status = bt_socket_client_sendrecv(ins, &packet, BT_LE_SCAN_START);
@ -62,7 +62,7 @@ bt_scanner_t* bt_le_start_scan_settings(bt_instance_t* ins,
if (scan == NULL)
return NULL;
scan->callback = (scanner_callbacks_t*)cbs;
scan->callbacks = (scanner_callbacks_t*)cbs;
packet.scan_pl._bt_le_start_scan_settings.remote = PTR2INT(uint64_t) scan;
if (settings)
memcpy(&packet.scan_pl._bt_le_start_scan_settings.settings, settings, sizeof(*settings));
@ -91,7 +91,7 @@ bt_scanner_t* bt_le_start_scan_with_filters(bt_instance_t* ins,
if (scan == NULL)
return NULL;
scan->callback = (scanner_callbacks_t*)cbs;
scan->callbacks = (scanner_callbacks_t*)cbs;
packet.scan_pl._bt_le_start_scan_with_filters.remote = PTR2INT(uint64_t) scan;
if (settings)
memcpy(&packet.scan_pl._bt_le_start_scan_with_filters.settings, settings, sizeof(*settings));

View File

@ -33,8 +33,6 @@ func frameworkBluetoothHook(ctx android.LoadHookContext) {
p.Cflags = append(p.Cflags, "-DANDROID_12")
} else if (Version == "14") {
p.Cflags = append(p.Cflags, "-DANDROID_14")
} else if (Version == "15") {
p.Cflags = append(p.Cflags, "-DANDROID_15")
}
ctx.AppendProperties(p)

38
service/common/bt_time.c Normal file
View File

@ -0,0 +1,38 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <time.h>
#include "bt_time.h"
uint64_t get_os_timestamp_us(void)
{
struct timespec ts;
clock_gettime(CLOCK_BOOTTIME, &ts);
return (uint64_t)(((uint64_t)ts.tv_sec * 1000000L) + ((uint64_t)ts.tv_nsec / 1000));
}
uint32_t get_os_timestamp_ms(void)
{
struct timespec ts;
clock_gettime(CLOCK_BOOTTIME, &ts);
return (uint32_t)((ts.tv_sec * 1000) + (ts.tv_nsec / 1000000UL));
}

Some files were not shown because too many files have changed in this diff Show More