This commit is contained in:
lmx
2025-10-29 13:10:02 +08:00
commit 49a07fa419
2284 changed files with 642060 additions and 0 deletions

View File

@ -0,0 +1,220 @@
#ifndef LMP_API_H
#define LMP_API_H
int lmp_private_is_clearing_a2dp_packet(void *_conn);
int lmp_private_a2dp_channel_exist(void *_conn);
int lmp_private_get_sbc_remain_time(void *_conn, u8 include_tws);
void *lmp_private_open_sbc_channel(u8 *addr, u16 channel, u8 codec_type);
void lmp_private_free_sbc_packet(void *_conn, void *packet);
int lmp_private_get_sbc_data_len(void *_conn);
int lmp_private_get_rx_buffer_size();
void lmp_private_set_max_rx_buf_persent(u8 *addr, int persent);
void *lmp_private_fetch_sbc_packet(void *_conn, int *len, void *_prev, int);
int lmp_private_get_sbc_packet_num(void *_conn);
void lmp_private_close_sbc_channel(void *_conn);
int lmp_private_get_sbc_packet(void *_conn, u8 **frame, int block);
u8 *lmp_private_get_tx_packet_buffer(int size);
int lmp_private_clear_a2dp_packet(void *_conn, u16 seqn_number);
int lmp_private_send_esco_packet(void *priv, u8 *packet, int len);
u8 *lmp_private_remote_addr_for_handler(int handle);
u16 lmp_private_handler_for_remote_addr(u8 *addr, int link_type);
int lmp_private_get_rx_buffer_total_size(void *_conn);
int lmp_private_get_rx_buffer_remain_size(void *_conn);
void lmp_hci_private_hold_acl_packet(u8 *packet);
void lmp_hci_private_free_acl_packet(u8 *packet);
void lmp_hci_private_try_free_acl_packet(u8 *packet);
int lmp_hci_send_packet(u8 *packet, int len);
int lmp_hci_send_packet_standard(const u8 *packet, int len);
int lmp_hci_reset();
int lmp_hci_write_scan_enable(u8 enable);
void lmp_hci_write_class_of_device(int dev_class);
void lmp_hci_write_local_name(const char *name);
void lmp_hci_write_local_priv_version(const char *ic_verson, const char *priv_version, u8 *tws_local_addr);
void lmp_hci_write_local_address(const u8 *addr);
void lmp_hci_write_simple_pairing_mode(u8 enable);
void lmp_hci_write_super_timeout(u16 timeout);
void lmp_hci_write_page_timeout(u16 timeout);
void lmp_hci_write_tws_internal_addr(u8 *internal_addr_local, u8 *internal_addr_remote);
void lmp_hci_write_link_supervision_timeout(u16 handle, int);
int lmp_hci_write_le_host_support(int features);
int lmp_hci_read_pin_type();
void lmp_hci_set_pin_code(const char *code, u8 len);
void lmp_hci_pin_code_request_reply(u8 *addr, u8 len, u8 *pin_code);
void lmp_hci_pin_code_request_negative_reply(u8 *addr);
int lmp_hci_write_pin_type(u8 type);
int lmp_hci_set_connection_encryption(u16 handle, int enable);
void lmp_hci_io_capability_request_reply(u8 *addr, u8 io_cap, u8 oob_data, u8 auth_req);
void lmp_hci_user_confirmation_request_reply(u8 *address);
void lmp_hci_user_confirmation_request_negative_reply(u8 *addr);
int lmp_hci_disconnect(u16 handle, u8 reason);
int lmp_hci_test_key_cmd(u8 cmd, u16 handle);
int lmp_hci_send_user_info_cmd(u32 info, u16 handle);
void lmp_hci_accept_connection_request(u8 *addr, u8 role);
void lmp_hci_accept_sco_connection_request(u8 *addr, u32 tx_bandwidth,
u32 rx_bandwidth, u16 max_latency, u16 content_format,
u8 retransmission, u16 packey_type);
void lmp_hci_reject_connection_request(u8 *addr, u8 reason);
void lmp_hci_switch_role_command(u8 *addr, u8 role);
void lmp_hci_authentication_requested(u16 handler);
void lmp_hci_link_key_request_reply(u8 *addr, u8 *link_key);
void lmp_hci_link_key_request_negative_reply(u8 *addr);
void lmp_hci_write_default_link_policy_settings(u16 setting);
void lmp_hci_release_packet(u8 *packet);
void lmp_hci_create_connection(const u8 *addr, u16 packet_type,
u8 repetition_mode, u8 reserved,
u16 clk_offset, u8 allow_role_switch);
void lmp_hci_connection_cancel(u8 *addr);;
void lmp_hci_cancel_page();
void lmp_hci_inquiry(int lap, u8 length, u8 num);
void lmp_hci_cancel_inquiry();
void lmp_hci_sniff_mode_command(u16 handle, u16 max_interval, u16 min_interval, u16 attempt, u16 timeout);
void lmp_hci_exit_sniff_mode_command(u16 handle);
void lmp_hci_host_num_of_completed_packets(u16 handle, u16 num_of_completed_packet);
int lmp_hci_read_remote_version_information(u16 handle);
void lmp_hci_read_remote_supported_features(u16 handle);
void lmp_hci_read_remote_extended_features(u16 handle);
void lmp_hci_role_discovery(u16 handle);
void lmp_hci_read_clock_offset(u16 handle);
void lmp_hci_read_link_policy_settings(u16 handle);
void lmp_hci_write_link_policy_settings(u16 handle, u16 policy);
void lmp_hci_remote_name_request(u8 *addr, u8 page_scan_repetition_mode, u16 clk_offset);
void lmp_set_sniff_establish_by_remote(u8 enable);
void lmp_set_sniff_disable(void);
u8 lmp_hci_read_local_supported_features(int octet);
void lmp_hci_write_local_supported_features(u8 features, int octet);
u8 lmp_standard_connect_check(void);
void lmp_hci_send_keypress_notification(u8 *addr, u8 key);
void lmp_hci_user_keypress_request_reply(u8 *addr, u32 key);
void lmp_hci_user_keypress_request_negative_reply(u8 *addr, u8 key);
void lmp_hci_set_role_switch_supported(bool enable);
void lmp_hci_tx_channel_chassification(u8 *map);
u8 *get_tws_internal_addr(int channel);
extern int lmp_private_esco_suspend_resume(int flag);;
void user_set_tws_box_mode(u8 mode);
void bt_set_tx_power(u8 txpower);
void bredr_bulk_change(u8 mode);
extern u8 get_bredr_link_state();
extern u32 get_bt_slot_time(u8 type, u32 time, int *ret_time, int (*local_us_time)(void));
extern u32 get_sync_rec_instant_us_time();
extern u8 tws_remote_state_check(void);
extern void tws_remote_state_clear(void);
extern void user_set_tws_box_mode(u8 mode);
extern void bredr_fcc_init(u8 mode, u8 fre);
extern void bredr_set_dut_enble(u8 en, u8 phone);
extern int a2dp_media_clear_packet_before_seqn(u16 seqn_number);
struct link_fix_rx_result {
u32 rx_err_b; //接收到err bit
u32 rx_sum_b; //接收到正确bit
u32 rx_perr_p; //接收到crc 错误 包数
u32 rx_herr_p; //接收到crc 以外其他错误包数
u32 rx_invail_p; //接收到crc错误bit太多的包数丢弃不统计到err bit中
};
#define DH1_1 0
#define DH3_1 1
#define DH5_1 2
#define DH1_2 3
#define DH3_2 4
#define DH5_2 5
int link_fix_tx_enable(u8 *remote_addr, u8 fre, u8 packet_type, u16 payload);
int link_fix_rx_enable(u8 *remote_addr, u8 fre, u8 packet_type, u16 payload);
void link_fix_txrx_disable();
void link_fix_rx_update_result(struct link_fix_rx_result *result);
void link_fix_rx_dump_result();
#endif

View File

@ -0,0 +1,18 @@
/*********************************************************************************************
* Filename : lmp_config.h
* Description : Lto 优化Macro 定义
* Author : Bingquan
* Email : bingquan_cai@zh-jieli.com
* Last modifiled : 2018-12-19 16:38
* Copyright:(c)JIELI 2011-2017 @ , All Rights Reserved.
*********************************************************************************************/
#ifndef _LMP_CONFIG_H_
#define _LMP_CONFIG_H_
#endif

View File

@ -0,0 +1,243 @@
#ifndef TWS_API_H
#define TWS_API_H
#include "typedef.h"
#include "classic/tws_event.h"
#include "classic/tws_local_media_sync.h"
#include "classic/tws_data_trans.h"
#define TWS_ROLE_MASTER 0
#define TWS_ROLE_SLAVE 1
/*
* tws 状态
*/
#define TWS_STA_SIBLING_DISCONNECTED 0x00000001 //tws未连接
#define TWS_STA_SIBLING_CONNECTED 0x00000002 //tws已连接
#define TWS_STA_PHONE_DISCONNECTED 0x00000004 //手机未连接
#define TWS_STA_PHONE_CONNECTED 0x00000008 //手机已连接
#define TWS_STA_ESCO_OPEN 0x00000010 //正在打电话
#define TWS_STA_SBC_OPEN 0x00000020 //正在播歌
#define TWS_STA_MONITOR_START 0x00000040 //tws从机开始监听手机链路
#define TWS_STA_LOCAL_TWS_OPEN 0x00000080 //开启local_tws
#define TWS_STA_ESCO_OPEN_LINK 0x00000100 //正在打电话create link
#define TWS_STA_MONITOR_ING 0x00000200 //tws主从收到监听信息
#define TWS_SYNC_CALL_TX 1
#define TWS_SYNC_CALL_RX 2
struct tws_sync_call {
int uuid;
void (*func)(int priv, int err);
const char *task_name;
};
extern const struct tws_sync_call tws_sync_call_begin[];
extern const struct tws_sync_call tws_sync_call_end[];
#define list_for_each_tws_sync_call(p) \
for (p = tws_sync_call_begin; p < tws_sync_call_end; p++)
#define TWS_SYNC_CALL_REGISTER(sync_call) \
static const struct tws_sync_call __tws_##sync_call sec(.tws_sync_call)
#define TWS_FUNC_ID(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
typedef void (*tws_func_t)(void *data, u16 len, bool rx);
struct tws_func_stub {
u32 func_id;
tws_func_t func; //call from irq
};
#define REGISTER_TWS_FUNC_STUB(stub) \
static const struct tws_func_stub stub sec(.tws_func_stub)
extern const struct tws_func_stub tws_func_stub_begin[];
extern const struct tws_func_stub tws_func_stub_end[];
static inline tws_func_t tws_function_get_by_id(u32 id)
{
const struct tws_func_stub *p;
for (p = tws_func_stub_begin; p < tws_func_stub_end; p++) {
if (p->func_id == id) {
return p->func;
}
}
return NULL;
}
static inline void tws_function_call_by_id(u32 id, void *data, u16 len, bool rx)
{
const struct tws_func_stub *p;
for (p = tws_func_stub_begin; p < tws_func_stub_end; p++) {
if (p->func_id == id) {
p->func(data, len, rx);
break;
}
}
}
/*
* 通过搜索码搜索tws设备
*/
int tws_api_search_sibling_by_code(u16 code, int timeout_ms);
/*
*打开可发现, 可连接可被手机和tws搜索到
*/
int tws_api_wait_pair_by_code(u16 code, const char *name, int timeout_ms);
int tws_api_wait_pair_by_ble(u16 code, const char *name, int timeout_ms);
int tws_api_wait_tws_pair(int code, const char *name);
int tws_api_wait_phone_pair(int code, const char *name);
int tws_wait_tws_pair(u16 code, const char *name);
int tws_wait_phone_pair(u16 code, const char *name);
/*
*取消可发现, 可连接可被tws搜索到
*/
int tws_api_cancle_wait_pair();
/*
* 搜索并连接已经配对过的tws
* timeout: 单位ms 0 表示不超时
* 返回值: 0: 函数调用成功
*/
int tws_api_create_connection(int timeout);
/*
* 取消搜索已配对的tws
*/
int tws_api_cancle_create_connection();
/*
* 打开可发现,可连接, 可以被手机和已配对过的tws连接
*/
int tws_api_wait_connection();
/*
* 断开tws直接的连接
* reason: 断开原因
*/
int tws_api_detach(enum tws_detach_reason reason);
/*
* 获取主从, 播歌和打电话状态下结果不可靠,请勿调用
*/
int tws_api_get_role();
/*
* 获取tws 连接的状态
* 返回值: 详见顶部TWS_STA_**
*/
int tws_api_get_tws_state();
/*
* 设置tws对方地址
*/
int tws_api_set_sibling_addr(u8 *addr);
/*
* 获取tws对方地址
*/
int tws_api_get_sibling_addr(u8 *addr);
/*
* 获取tws本地地址
*/
int tws_api_get_local_addr(u8 *addr);
/*
*发送解除配对命令给对方, 成功后会收到TWS_EVENT_REMOVE_PAIRS事件
*/
int tws_api_remove_pairs();
/*
* 设置本地声道
* 'L': 左声道
* 'R': 右声道
* 'U': 双声道合并
*/
void tws_api_set_local_channel(char channel);
/*
* 获取本地声道
*/
char tws_api_get_local_channel();
/*
* 通过uuid主从同步调用相同函数
*/
int tws_api_sync_call_by_uuid(int uuid, int priv, int delay_ms);
/*
* tws 数据发送函数, 要求 len <= 512
*/
int tws_api_send_data_to_sibling(void *data, u16 len, u32 func_id);
int tws_api_send_data_to_slave(void *data, int len, u32 func_id);
int tws_profile_init();
int tws_profile_exit();
int tws_api_connect_in_esco();
int tws_api_cancle_connect_in_esco();
int tws_disconnect();
/*
* 使能对耳自动主从切换
*/
void tws_api_auto_role_switch_enable();
/*
* 关闭对耳自动主从切换
*/
void tws_api_auto_role_switch_disable();
int tws_api_get_low_latency_state();
int tws_api_low_latency_enable(bool enable);
void tws_api_set_quick_connect_addr(u8 *addr);
u8 *tws_api_get_quick_connect_addr();
void tws_api_common_addr_en(u8 en);
void tws_api_pair_all_way(u8 en);
int tws_api_power_saving_mode_enable();
int tws_api_power_saving_mode_disable();
int tws_api_enter_pure_monitor_mode();
void tws_try_connect_disable(void);
void tws_conn_switch_role();
void tws_api_role_switch();
#endif

View File

@ -0,0 +1,47 @@
#ifndef TWS_DATA_TRANS_H
#define TWS_DATA_TRANS_H
#include "generic/typedef.h"
enum {
TWS_DATA_TRANS_SOURCE,
TWS_DATA_TRANS_SINK,
};
enum tws_data_trans_attr {
TWS_DTC_LOCAL_MEDIA,
TWS_DTC_MIC_REC,
};
u8 tws_api_data_trans_open(u8 channel, enum tws_data_trans_attr attr, u16 buf_size);
int tws_api_data_trans_start(u8 channel, u8 *arg, u8 len);
int tws_api_data_trans_stop(u8 channel);
int tws_api_data_trans_close(u8 channel);
void tws_api_data_trans_auto_drop(u8 channel, int enable);
int tws_api_data_trans_send(u8 channel, u8 *buf, int len);
void *tws_api_data_trans_buf_alloc(u8 channel, int len);
int tws_api_data_trans_push(u8 channel, void *_frame, int len);
void *tws_api_data_trans_pop(u8 channel, int *len);
void tws_api_data_trans_free(u8 channel, void *_frame);
void *tws_api_data_trans_fetch(u8 channel, void *_prev, int *len);
void tws_api_data_trans_clear(u8 channel);
int tws_api_data_trans_check(u8 channel, u16 *ready_len, u16 *total_len);
#endif

View File

@ -0,0 +1,95 @@
#ifndef TWS_EVENT_H
#define TWS_EVENT_H
#define KEY_EVENT_FROM_TWS (('T' << 24) | ('W' << 16) | ('S' << 8) | '\0')
#define SYS_BT_EVENT_FROM_TWS (('T' << 24) | ('W' << 16) | ('S' << 8) | '\0')
enum {
TWS_STA_WAIT_SIBLING_PAIR = 1,
TWS_STA_SEARCH_SIBLING,
TWS_STA_CREATE_CONNECTION_BREDR,
TWS_STA_CREATE_CONNECTION_BLE,
TWS_STA_WAIT_CONNECTION_BREDR,
TWS_STA_WAIT_CONNECTION_BLE,
TWS_STA_DISCONNECTION,
TWS_STA_CONNECTION,
TWS_STA_START_MONITOR,
TWS_STA_MONITOR,
TWS_STA_WAIT_PHONE_PAIR,
TWS_STA_WAIT_PAIR,
};
enum {
LOCAL_REMOTE_ADDR = 0,
TWS_PAIR_REMOTE_ADDR_STATE_OK,
TWS_PAIR_REMOTE_ADDR_STATE_NOT,
};
enum tws_detach_reason {
TWS_DETACH_BY_SUPER_TIMEOUT = 8,
TWS_DETACH_BY_LOCAL,
TWS_DETACH_BY_REMOTE,
TWS_DETACH_BY_POWEROFF,
TWS_DETACH_BY_REMOVE_PAIRS,
TWS_DETACH_BY_TESTBOX_CON,
TWS_DETACH_BY_REMOVE_NO_RECONN,
};
#define TWS_CONN_CHANNEL 0
#define TWS_LINK_SYNC_CHANNEL 1
#define TWS_LMP_SYNC_CHANNEL 2
#define TWS_AFH_SYNC_CHANNEL 3
#define TWS_TX_SYNC_CHANNEL 4
#define TWS_LOW_LATENCY_CHANNEL 5
#define TWS_DATA_SYNC_CHANNEL 6
#define TWS_SBC_SYNC_CHANNEL 7
#define TWS_EVENT_SYNC_CHANNEL 8
#define TWS_SYNC_CALL_CHANNEL 9
#define TWS_POWER_BALANCE_CHANNEL 10
#define TWS_CI_DATA_SYNC_CHANNEL 11
#define TWS_LOCAL_MEIDA_SYNC_CHANNEL 12
#define TWS_LMP_SLOT_CHANNEL 13
#define TWS_DATA_TRANS_CHANNEL 14
enum {
TWS_EVENT_SEARCH_TIMEOUT = 1,
TWS_EVENT_CONNECTED,
TWS_EVENT_CONNECTION_TIMEOUT,
TWS_EVENT_CONNECTION_DETACH,
TWS_EVENT_REMOVE_PAIRS,
TWS_EVENT_PHONE_LINK_DETACH,
TWS_EVENT_SYNC_FUN_CMD,
TWS_EVENT_SYNC_FUN_TRANID,
TWS_EVENT_CONNECT_TEST,
TWS_EVENT_ROLE_SWITCH,
TWS_EVENT_LOCAL_MEDIA_START,
TWS_EVENT_LOCAL_MEDIA_STOP,
TWS_EVENT_ESCO_ADD_CONNECT,
TWS_EVENT_SETUP_MONITOR_LINK,
TWS_EVENT_MONITOR_START,
TWS_EVENT_DATA_TRANS_OPEN,
TWS_EVENT_DATA_TRANS_START,
TWS_EVENT_DATA_TRANS_STOP,
TWS_EVENT_DATA_TRANS_CLOSE,
TWS_EVENT_MODE_CHANGE, //sniff without phone
TWS_EVENT_ROLE_SWITCH_START,
TWS_EVENT_TONE_TEST = 0xff,
};
#endif

View File

@ -0,0 +1,48 @@
#ifndef TWS_LOCAL_MEDIA_SYNC_H
#define TWS_LOCAL_MEDIA_SYNC_H
#include "generic/list.h"
#include "generic/typedef.h"
void tws_api_local_media_trans_start();
void tws_api_local_media_trans_set_buf(void *buf, int size);
void *tws_api_local_media_trans_alloc(int len);
void tws_api_local_media_trans_free(void *frame);
void tws_api_local_media_trans_push(void *frame, int len);
void *tws_api_local_media_trans_pop(int *len);
void *tws_api_local_media_trans_fetch(void *prev, int *len);
void tws_api_local_media_trans_stop();
void tws_api_local_media_trans_packet_del(void *_frame);
int tws_api_local_media_trans_check_total(u8 head);
int tws_api_local_media_trans_check_ready_total(void);
void tws_api_local_media_trans_clear(void);
int tws_api_local_media_packet_cnt(u8 *rx_packet_cnt, u8 *wait_send_pcaket_cnt);
// 填数超过了一定值才可以发送
void tws_api_local_media_set_limit_size(int size);
int tws_api_local_media_trans_bulk_push(u8 *buf, int len);
int tws_api_local_media_push_with_sequence(u8 *buf, int len, u16 seqn);
int tws_api_local_media_push_with_timestamp(u8 *buf, int len, u32 timestamp);
int tws_api_local_media_trans_open(u16 buf_size);
int tws_api_local_media_dec_start(u8 *arg, u8 len);
int tws_api_local_media_dec_stop();
void tws_api_auto_drop_frame_enable(int enable);
#endif