Bluetooth Management API
*************************
Copyright (C) 2008-2009 Marcel Holtmann <[email protected]>
Overview
========
This document describes the format of data used for communicating with
the kernel using a so-called Bluetooth Management sockets. These sockets
are available starting with Linux kernel version 3.4
The following kernel versions introduced new commands, new events or
important fixes to the Bluetooth Management API:
Linux kernel v3.4 Version 1.0
Linux kernel v3.5 Version 1.1
Linux kernel v3.7 Version 1.2
Linux kernel v3.9 Version 1.3
Linux kernel v3.13 Version 1.4
Linux kernel v3.15 Version 1.5
Linux kernel v3.16 Version 1.6 (not yet released)
Version 1.1 introduces Set Device ID command.
Version 1.2 introduces Passkey Notify event.
Version 1.3 does not introduce any new command or event.
Version 1.4 introduces Set Advertising, Set BR/EDR, Set Static Address
and Set Scan Parameters commands.
Version 1.5 introduces Set Secure Connections, Set Debug Keys, Set Privacy
and Load Identity Resolving Keys commands. It also introduces New Identity
Resolving Key and New Signature Resolving Key events.
Version 1.6 introduces Get Connection Information command. It also updates
the Device Found event to combine advertising data and scan response data
into a single event.
Example
=======
The Bluetooth management sockets can be created by setting the hci_channel
member of struct sockaddr_hci to HCI_CHANNEL_CONTROL (3) when creating a
raw HCI socket. In C the needed code would look something like the following:
int mgmt_create(void)
{
struct sockaddr_hci addr;
int fd;
fd = socket(PF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK,
BTPROTO_HCI);
if (fd < 0)
return -errno;
memset(&addr, 0, sizeof(addr));
addr.hci_family = AF_BLUETOOTH;
addr.hci_dev = HCI_DEV_NONE;
addr.hci_channel = HCI_CHANNEL_CONTROL;
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
int err = -errno;
close(fd);
return err;
}
return fd;
}
The process creating the mgmt socket is required to have the
CAP_NET_ADMIN capability (e.g. root would have this).
Packet Structures
=================
Commands:
0 4 8 12 16 22 24 28 31 35 39 43 47
+-------------------+-------------------+-------------------+
| Command Code | Controller Index | Parameter Length |
+-------------------+-------------------+-------------------+
| |
Events:
0 4 8 12 16 22 24 28 31 35 39 43 47
+-------------------+-------------------+-------------------+
| Event Code | Controller Index | Parameter Length |
+-------------------+-------------------+-------------------+
| |
All fields are in little-endian byte order (least significant byte first).
Controller Index can have a special value <non-controller> to indicate that
command or event is not related to any controller. Possible values:
<controller id> 0x0000 to 0xFFFE
<non-controller> 0xFFFF
Error Codes
===========
The following values have been defined for use with the Command Status
and Command Complete events:
0x00 Success
0x01 Unknown Command
0x02 Not Connected
0x03 Failed
0x04 Connect Failed
0x05 Authentication Failed
0x06 Not Paired
0x07 No Resources
0x08 Timeout
0x09 Already Connected
0x0A Busy
0x0B Rejected
0x0C Not Supported
0x0D Invalid Parameters
0x0E Disconnected
0x0F Not Powered
0x10 Cancelled
0x11 Invalid Index
Read Management Version Information Command
===========================================
Command Code: 0x0001
Controller Index: <non-controller>
Command Parameters:
Return Parameters: Version (1 Octets)
Revision (2 Octets)
This command returns the Management version and revision.
Besides, being informational the information can be used to
determine whether certain behavior has changed or bugs fixed
when interacting with the kernel.
This command generates a Command Complete event on success or
a Command Status event on failure.
Read Management Supported Commands Command
==========================================
Command Code: 0x0002
Controller Index: <non-controller>
Command Parameters:
Return Parameters: Num_Of_Commands (2 Octets)
Num_Of_Events (2 Octets)
Command1 (2 Octets)
Command2 (2 Octets)
...
Event1 (2 Octets)
Event2 (2 Octets)
...
This command returns the list of supported Management commands
and events.
The commands Read Management Version Information and Read
management Supported Commands are not included in this list.
Both commands are always supported and mandatory.
The events Command Status and Command Complete are not included
in this list. Both are implicit and mandatory.
This command generates a Command Complete event on success or
a Command Status event on failure.
Read Controller Index List Command
==================================
Command Code: 0x0003
Controller Index: <non-controller>
Command Parameters:
Return Parameters: Num_Controllers (2 Octets)
Controller_Index[i] (2 Octets)
This command returns the list of currently known controllers.
Controllers added or removed after calling this command can be
monitored using the Index Added and Index Removed events.
This command generates a Command Complete event on success or
a Command Status event on failure.
Read Controller Information Command
===================================
Command Code: 0x0004
Controller Index: <controller id>
Command Parameters:
Return Parameters: Address (6 Octets)
Bluetooth_Version (1 Octet)
Manufacturer (2 Octets)
Supported_Settings (4 Octets)
Current_Settings (4 Octets)
Class_Of_Device (3 Octets)
Name (249 Octets)
Short_Name (11 Octets)
This command is used to retreive the current state and basic
information of a controller. It is typically used right after
getting the response to the Read Controller Index List command
or an Index Added event.
If not short name is set the Short_Name parameter will be empty
(begin with a nul byte).
Current_Settings & Supported_Settings is a bitmask with
currently the following available bits:
0 Powered
1 Connectable
2 Fast Connectable
3 Discoverable
4 Pairable
5 Link Level Security (Sec. mode 3)
6 Secure Simple Pairing
7 Basic Rate/Enhanced Data Rate
8 High Speed
9 Low Energy
10 Advertising
11 Secure Connections
12 Debug Keys
13 Privacy
This command generates a Command Complete event on success or
a Command Status event on failure.
Possible errors: Invalid Parameters
Invalid Index
Set Powered Command
===================
Command Code: 0x0005
Controller Index: <controller id>
Command Parameters: Powered (1 Octet)
Return Parameters: Current_Settings (4 Octets)
This command is used to power on or off a controller. The
allowed Powered command parameter values are 0x00 and 0x01. All
other values will return Invalid Parameters.
If discoverable setting is activated with a timeout, then
switching the controller off will expire this timeout and
disable discoverable.
This command generates a Command Complete event on success or
a Command Status event on failure.
Possible errors: Busy
Invalid Parameters
Invalid Index
Set Discoverable Command
========================
Command Code: 0x0006
Controller Index: <controller id>
Command Parameters: Discoverable (1 Octet)
Timeout (2 Octets)
Return Parameters: Current_Settings (4 Octets)
This command is used to set the discoverable property of a
controller. The allowed Discoverable command parameter values
are 0x00, 0x01 and 0x02. All other values will return Invalid
Parameters.
Timeout is the time in seconds and is only meaningful when
Discoverable is set to 0x01 or 0x02. Providing a timeout
with 0x00 return Invalid Parameters. For 0x02, the tim
没有合适的资源?快使用搜索试试~ 我知道了~
c语言写的蓝牙扫描配对发送文件的工具,供参考
共137个文件
c:45个
h:41个
txt:20个
需积分: 5 0 下载量 42 浏览量
2023-08-28
15:37:00
上传
评论
收藏 97KB 7Z 举报
温馨提示
c语言写的蓝牙扫描配对发送文件的工具,供参考
资源推荐
资源详情
资源评论
收起资源包目录
c语言写的蓝牙扫描配对发送文件的工具,供参考 (137个子文件)
bt-device.1 7KB
bt-adapter.1 7KB
bt-obex.1 6KB
bt-agent.1 6KB
bt-network.1 5KB
configure.ac 2KB
Makefile.am 3KB
Makefile.am 243B
AUTHORS 121B
bt-obex.c 38KB
bt-device.c 25KB
agent-helper.c 16KB
helpers.c 15KB
bt-adapter.c 14KB
device.c 13KB
media_player.c 13KB
adapter.c 12KB
obex_message.c 12KB
obex_agent.c 12KB
sdp.c 10KB
obex_transfer.c 9KB
properties.c 9KB
bt-network.c 9KB
manager.c 8KB
obex_file_transfer.c 8KB
media_control.c 8KB
obex_session.c 8KB
proximity_monitor.c 8KB
bt-agent.c 8KB
health_channel.c 8KB
health_device.c 7KB
network.c 7KB
proximity_reporter.c 7KB
obex_message_access.c 7KB
cycling_speed.c 7KB
obex_phonebook_access.c 7KB
obex_object_push.c 6KB
sim_access.c 6KB
thermometer.c 6KB
heart_rate.c 6KB
media.c 6KB
network_server.c 6KB
obex_synchronization.c 6KB
alert_agent.c 5KB
cycling_speed_manager.c 5KB
thermometer_manager.c 5KB
heart_rate_manager.c 5KB
agent_manager.c 5KB
health_manager.c 5KB
obex_agent_manager.c 5KB
profile_manager.c 5KB
obex_client.c 5KB
alert.c 5KB
dbus-common.c 1KB
ChangeLog 2KB
COPYING 18KB
git-version-gen 6KB
.gitignore 320B
sdp.h 10KB
media_player.h 4KB
device.h 4KB
obex_message.h 4KB
adapter.h 4KB
obex_transfer.h 3KB
obex_file_transfer.h 3KB
proximity_monitor.h 3KB
media_control.h 3KB
obex_agent.h 3KB
health_channel.h 3KB
obex_session.h 3KB
obex_message_access.h 3KB
proximity_reporter.h 3KB
obex_phonebook_access.h 3KB
health_device.h 3KB
obex_object_push.h 3KB
cycling_speed.h 3KB
obex_synchronization.h 3KB
obex_agent_manager.h 3KB
network.h 3KB
profile_manager.h 3KB
agent_manager.h 3KB
cycling_speed_manager.h 3KB
network_server.h 3KB
thermometer.h 2KB
sim_access.h 2KB
health_manager.h 2KB
thermometer_manager.h 2KB
heart_rate.h 2KB
heart_rate_manager.h 2KB
alert_agent.h 2KB
media.h 2KB
obex_client.h 2KB
alert.h 2KB
helpers.h 2KB
properties.h 2KB
manager.h 2KB
bluez-api.h 1KB
agent-helper.h 1KB
dbus-common.h 439B
INSTALL 15KB
共 137 条
- 1
- 2
资源评论
冰小忆
- 粉丝: 9
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功