android 初始化流程,Android Bluetooth初始化流程

=========================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 initialize BTS402x )

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android设备上,要初始化蓝牙功能需要进行一些步骤。首先,需要在AndroidManifest.xml文件中添加蓝牙权限声明,以便应用程序可以使用蓝牙功能。然后,需要在应用程序代码中获取BluetoothAdapter对象,这是所有蓝牙操作的入口点。可以通过调用getSystemService方法并传入Context.BLUETOOTH_SERVICE参数来获取BluetoothManager,再调用getAdapter方法获取BluetoothAdapter对象。 接下来,需要检查设备是否支持蓝牙功能。通过调用BluetoothAdapter的isEnabled方法,可以判断蓝牙功能是否开启。如果蓝牙功能关闭,可以请求用户打开蓝牙,代码如下: ```java Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); ``` 当用户选择启用蓝牙后,可以在onActivityResult方法中获取结果,并进行相应处理。 如果蓝牙已开启,可以开始搜索其他蓝牙设备。通过调用BluetoothAdapter的startDiscovery方法,可以开始搜索周围的蓝牙设备并将它们显示在列表中。 最后,要记得在应用程序不需要使用蓝牙功能时,调用BluetoothAdapter的disable方法来关闭蓝牙功能,以节省设备的电量。 总之,初始化Android蓝牙功能需要在AndroidManifest.xml中声明权限,获取BluetoothAdapter对象,检查蓝牙是否开启,并进行搜索其他蓝牙设备的操作。同时,在应用程序不需要使用蓝牙时要记得关闭蓝牙功能,以提高设备的电量利用率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值