现在的位置: 首页 > 移动开发 > 正文

android启动蓝牙的过程 (高通方案)

2018年04月16日 移动开发 ⁄ 共 4834字 ⁄ 字号 评论关闭

=========================Kernel Space=========================
1. Board power init
MACHINE_START 
init_machine = comet_init
bt_power_init
bluetooth_power
2. HCI device/connection manager, socket init
bt_init()
bt_sysfs_init
sock_register
hci_sock_init
3. HCI UART init( UART LINE DISCIPLINE)
hci_uart_init(open/close/read/write/ioctl,poll...)
h4_init
hci_uart_register_proto
4. Bluetooth Sleep Module,/proc/bluetooth
bluesleep_init()
platform_driver_register(&bluesleep_driver)
5. BT Power switch, RF kill
bluetooth_power_init()
bt_power_probe
6. L2CAP init
l2cap_init()
proto_register(&l2cap_proto, 0)
bt_sock_register(BTPROTO_L2CAP , &l2cap_sock_family_ops)
hci_register_proto(&l2cap_hci_proto)
class_create_file(bt_class, &class_attr_l2cap)
7. SCO init
sco_init()
proto_register(&sco_proto, 0)
bt_sock_register(BTPROTO_SCO , &sco_sock_family_ops)
hci_register_proto(&sco_hci_proto)
class_create_file(bt_class, &class_attr_sco)
8. RFCOMM Init
rfcomm_init()
hci_register_cb(&rfcomm_cb)
kthread_run(rfcomm_run, NULL, "krfcommd")
class_create_file(bt_class, &class_attr_rfcomm_dlc)
rfcomm_init_sockets
rfcomm_init_ttys()
9. BNEP Init
bnep_init()
bnep_sock_init()
10. thread running
rfcomm_run
rfcomm_l2sock_create
l2cap_sock_create: sock 
l2cap_sock_init: sk 
l2cap_sock_bind: sk 
l2cap_sock_listen: sk 
rfcomm_session_add: session
=========================命令行方式启动BT============================== 
1.echo 1 > /sys/class/rfkill/rfkill0/state
*Bluetooth power switch: 1[bluetooth_power(), board_qsc8x50.c]
2. hci_qcomm_init -vvv -e
*hci_qcomm_init-d /dev/ttyHS0 -s 3200000 -i 115200 -r 19200000 (open HSUART COM port and initializeBTS402x )
3. hciattach /dev/ttyHS0 qualcomm 3000000 (HCI LINE DISCIPLINE)
hciattach/dev/ttyHS0 any 200 flow (attach serial device via UART HCI to BlueZstack )
=============user space===================
main()
init_uart()
ioctl(fd, HCIUARTSETPROTO, u->proto) 
==============kernel space=================
hci_uart_tty_ioctl()
hci_uart_set_proto()
open()[h4_open()]
hci_uart_register_dev()
hci_register_dev()
hci_register_sysfs()
4. hciconfig hci0 up(open and initialize HCI device) [hdev->name == hci0]
==========user space====================
ctl=socket(AF_BLUETOOTH , SOCK_RAW , BTPROTO_HCI ))
ioctl(ctl, HCIGETDEVINFO, (void *) &di)
hci_open_dev(di.dev_id)->bind(dd, (struct sockaddr *) &a, sizeof(a))
cmd_up
ioctl(ctl, HCIDEVUP, hdev)
==========kernel space================
hci_sock_ioctl
hci_dev_open
hci_dev_get
hdev->open [ hci_uart_open(hci_ldisc) ]
_hci_request(hdev, hci_init_req, 0,msecs_to_jiffies(HCI_INIT_TIMEOUT ))
hci_init_req
hci_send_cmd(hdev, HCI_OP_READ_LOCAL_FEATURES , 0, NULL);
......................
===========CMD Flow============================
hci_cmd_task: hci0 cmd 1
hci_send_frame: hci0 type 1 len 3
hci_sock_dev_event: hdev hci0 event 7
hci_send_to_sock: hdev (null) len 8
hci_uart_send_frame: hci0: type 1 len 3
h4_enqueue: hu c658f6c0 skb c662d340
hci_uart_tx_wakeup:
hci_uart_tty_wakeup:
hci_uart_tx_wakeup:
===========Event Flow===========================
h4_recv: hu c658f6c0 count 15 rx_state 0 rx_count 0
h4_recv: Event packet
h4_recv: Event header: evt 0x0e plen 12
h4_check_data_len: len 12 room 1046
h4_recv: Complete data
hci_rx_task: hci0
hci_cc_read_local_features: hci0 status 0x0
hci_cc_read_local_features: hci0 features 0xfffe8ffe9bff598
========================================BT TOOLS=======================================
hciattatch
hciconfig
hciconfig - HCI device configuration utility
Usage:
hciconfig
hciconfig [-a] hciX [command]
Commands:
up Open and initialize HCI device
down Close HCI device
reset Reset HCI device
rstat Reset statistic counters
auth Enable Authentication
noauth Disable Authentication
encrypt Enable Encryption
noencrypt Disable Encryption
piscan Enable Page and Inquiry scan
noscan Disable scan
iscan Enable Inquiry scan
pscan Enable Page scan
ptype [type] Get/Set default packet type
lm [mode] Get/Set default link mode
lp [policy] Get/Set default link policy
name [name] Get/Set local name
class [class] Get/Set class of device
voice [voice] Get/Set voice setting
iac [iac] Get/Set inquiry access code
inqtpl [level] Get/Set inquiry transmit power level
inqmode [mode] Get/Set inquiry mode
inqdata [data] Get/Set inquiry data
inqtype [type] Get/Set inquiry scan type
inqparms [win:int] Get/Set inquiry scan window and interval
pageparms [win:int] Get/Set page scan window and interval
pageto [to] Get/Set page timeout
afhmode [mode] Get/Set AFH mode
sspmode [mode] Get/Set Simple Pairing Mode
aclmtu Set ACL MTU and number of packets
scomtu Set SCO MTU and number of packets
putkey Store link key on the device
delkey Delete link key from the device
oobdata Display local OOB data
commands Display supported commands
features Display device features
version Display version information
revision Display revision information
bttest
hcitool cmd
hcitool scan
hcidump
hcidump -B -w /data/test.cfa [Log HCI packets as FTS btsnoopformat]
hcidump -XVt [Print HCI packets that can be readable with timestamps and payloads]
sdptool
sdptool add -channel=10 HFAG (add HFAG service records to be supported)
sdptool del [record_handle] (remove service from local SDP)
sdptool browse local [Browse all local service records]
l2ping [Run L2CAPping-to-peer device]
========================================android 脚本执行过程===============================
2. init.rc
3. init.qcom.rc
4. init.qcom.bt.sh

 

抱歉!评论已关闭.