gatttool的使用
1、使能hci接口
# hciconfig hci0 up
2、使用hcitool搜索BLE设备
# hcitool lescan
LE Scan ...
D0:39:72:BE:D2:26 (unknown)
D0:39:72:BE:D2:26 HMDongle
D0:39:72:BE:D2:26 (unknown)
搜索到设备后按CTRL+C停止搜索,设备名称为HMDongle,是一个蓝牙串口设备,MAC地址为D0:39:72:BE:D2:26
3、使用gatttool连接设备
先查看gatttool的help
# gattool -h
Usage:
gatttool [OPTION...]
Help Options:
-h, --help Show help options
--help-all Show all help options
--help-gatt Show all GATT commands
--help-params Show all Primary Services/Characteristics arguments
--help-char-read-write Show all Characteristics Value/Descriptor Read/Write arguments
Application Options:
-i, --adapter=hciX Specify local adapter interface
-b, --device=MAC Specify remote Bluetooth address
-t, --addr-type=[public | random] Set LE address type. Default: public
-m, --mtu=MTU Specify the MTU size
-p, --psm=PSM Specify the PSM for GATT/ATT over BR/EDR
-l, --sec-level=[low | medium | high] Set security level. Default: low
-I, --interactive Use interactive mode
使用interactive方式连接设备
# gatttool -b D0:39:72:BE:D2:26 -I
[ ][D0:39:72:BE:D2:26][LE]>
查看help
[ ][D0:39:72:BE:D2:26][LE]> help
help Show this help
exit Exit interactive mode
quit Exit interactive mode
connect [address [address type]] Connect to a remote device
disconnect Disconnect from a remote device
primary [UUID] Primary Service Discovery
characteristics [start hnd [end hnd [UUID]]] Characteristics Discovery
char-desc [start hnd] [end hnd] Characteristics Descriptor Discovery
char-read-hnd <handle> [offset] Characteristics Value/Descriptor Read by handle
char-read-uuid <UUID> [start hnd] [end hnd] Characteristics Value/Descriptor Read by UUID
char-write-req <handle> <new value> Characteristic Value Write (Write Request)
char-write-cmd <handle> <new value> Characteristic Value Write (No response)
sec-level [low | medium | high] Set security level. Default: low
mtu <value> Exchange MTU for GATT/ATT
[ ][D0:39:72:BE:D2:26][LE]>
连接设备
[ ][D0:39:72:BE:D2:26][LE]> connect
[CON][D0:39:72:BE:D2:26][LE]>
连接成功之后命令行前面会有[CON]标识
查看设备提供的服务
[CON][D0:39:72:BE:D2:26][LE]> primary
[CON][D0:39:72:BE:D2:26][LE]>
attr handle: 0x0001, end grp handle: 0x000b uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x000c, end grp handle: 0x000f uuid: 00001801-0000-1000-8000-00805f9b34fb
attr handle: 0x0010, end grp handle: 0xffff uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
查看特性
[CON][D0:39:72:BE:D2:26][LE]> characteristics
[CON][D0:39:72:BE:D2:26][LE]>
handle: 0x0002, char properties: 0x02, char value handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0004, char properties: 0x02, char value handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
handle: 0x0006, char properties: 0x0a, char value handle: 0x0007, uuid: 00002a02-0000-1000-8000-00805f9b34fb
handle: 0x0008, char properties: 0x0a, char value handle: 0x0009, uuid: 00002a03-0000-1000-8000-00805f9b34fb
handle: 0x000a, char properties: 0x02, char value handle: 0x000b, uuid: 00002a04-0000-1000-8000-00805f9b34fb
handle: 0x000d, char properties: 0x20, char value handle: 0x000e, uuid: 00002a05-0000-1000-8000-00805f9b34fb
handle: 0x0011, char properties: 0x16, char value handle: 0x0012, uuid: 0000ffe1-0000-1000-8000-00805f9b34fb
其中handle是特性的句柄,char properties是特性的属性值,char value handle是特性值的句柄,uuid是特性的标识;
我想,可以把特性当作是设备特供的寄存器,寄存器会有属性,如只读、只写或可读可写,在蓝牙协议里面,还有notify的属性,当然,这个通知属性当作是寄存器的中断服务也是说得过去的;那么,第一个handle可以理解为寄存器的编号,第二个handle理解为寄存器的地址,properties即是寄存器属性,如果是可读可写,那么直接读写操作寄存器的地址即可。
上面列出了好多个特性,其中只有一个才是读写蓝牙串口的特性,很容易看得出来,它的uuid为ffe1,属性值为0x16,可读可写(without response)可通知。在这里,从蓝牙串口读取数据并不是直接去读取0x0012这个handle,而是通过notify获取数据,首先要使能notify功能,怎么使能呢,就是把特性值handle加1即0x0013,往这个0x0013handle写入0x0100,如:
[CON][D0:39:72:BE:D2:26][LE]> char-write-req 0x0013 0100
[CON][D0:39:72:BE:D2:26][LE]> Characteristic value was written successfully
往handle写入十六进制值时不要带0x,不然会出错
[CON][D0:39:72:BE:D2:26][LE]> char-write-req 0x0013 0x0100
[CON][D0:39:72:BE:D2:26][LE]> Characteristic Write Request failed: Attribute value length is invalid
如果要向设备发送串口数据就直接往0x0012写入数据即可
[CON][D0:39:72:BE:D2:26][LE]> char-write-cmd 0x0012 48
在这里我碰到了问题,始终获取不到蓝牙串口发送过来的数据,根本无法收到notify,即使加了--listen参数也不行,郁闷啊!首先设备是没问题的,使用lightblue工具都可以正常收发串口数据。
gatttool的使用的更多相关文章
- 【蓝牙】蓝牙,调试 hcitool与gatttool实例
Bluez协议栈在安装完以后,会提供两个命令行调试工具,hcitool与gattool,我们可以根据提供的工具来轻松的调试我们的蓝牙设备,调试BLE设备时,需要获取root权限. 蓝牙设备的开启与关闭 ...
- 物联网安全拔“牙”实战——低功耗蓝牙(BLE)初探
物联网安全拔“牙”实战——低功耗蓝牙(BLE)初探 唐朝实验室 · 2015/10/30 10:22 Author: FengGou 0x00 目录 0x00 目录 0x01 前言 0x02 BLE概 ...
- BLE Hacking:使用Ubertooth one扫描嗅探低功耗蓝牙
0×00 前言 低功耗蓝牙(Low Energy; LE),又视为Bluetooth Smart或蓝牙核心规格4.0版本.其特点具备节能.便于采用,是蓝牙技术专为物联网(Internet of Thi ...
- [BlueZ] 2、使用bluetoothctl搜索、连接、配对、读写、使能notify蓝牙低功耗设备
星期三, 05. 九月 2018 02:03上午 - beautifulzzzz 1.前言 上一篇讲了如何编译安装BlueZ-5,本篇主要在于玩BlueZ,用命令行去操作BLE设备: [BlueZ] ...
- 玩转BLE(3)_使用微信蓝牙精简协议伪造记步数据
1. 前言 在物联网时代,有一个问题肯定会让人头疼(现在已经初露端倪了): 物联网中的IOT设备有两个主要特点: 1)简单小巧(不具备复杂的人机交互接口,需要手机等终端设备辅助完成配置.控制等功能). ...
- 玩转BLE(1)_Eddystone beacon
1. 前言 你相信两条命令就可以把自己的破手机变成一个Beacon节点吗?不相信的话就接着往下看吧. 通过前几篇“蓝牙协议分析”相关的文章,特别是“蓝牙协议分析(3)_蓝牙低功耗(BLE)协议栈介绍” ...
- ubuntu GCC 版本切换
(1) 查看gcc以及g++的版本 gcc -v g++ -v star@ai:~ $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_L ...
- 蓝牙学习 (8)配对raspberryPi和SensorTag CC2650
在上一篇中,用raspberryPi能够扫描到Ti SensorTag. 但是没有获得更多的数据,并且发现sensor Tag并没有回复scan request. https://blog.csdn. ...
- 树莓派 - 蓝牙 (1) 试试Beacon
首先先了解一下bluez, 以及常用的tools. - hcitool.bluetoothctl等工具,可以进行BLE设备的扫描.连接.配对.广播等操作: - hcitool可以发送HCI comma ...
随机推荐
- JFreeChart的简单使用
实例1:简单的饼图 public class Test { public static void main(String[] args) { //建立默认的饼图 DefaultPieDataset d ...
- 51nod 算法马拉松4 B递归(YY)
递归 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 函数f(n,m) { 若n=1或m=1返回a[n][m]; 返回f(n-1,m)异或f(n,m-1); } 读入2<= ...
- Packer 基本试用
安装 使用mac 系统 https://www.packer.io/downloads.html 配置环境变量 可选 sudo nano ~/.bash_profile export PATH=$PA ...
- wchar_t char string wstring 之间的转换
wchar_t char string wstring 之间的转换 转:http://blog.csdn.net/lbd2008/article/details/8333583 在处理中文时有时需要进 ...
- Float IP设置
浮动IP: 在做双机的时候,设定的一个IP,通过访问这个IP,具体到后台哪台机器,由系统指定. 浮动IP是随资源一起走的. 就是由软件根据具体情况把该IP设置在某一台机器上,对外提供服务 为了避免因为 ...
- C++ - 容器概述
一 迭代器iterator 5种类别 常用的迭代器 常用的迭代器 二 分配算符Allocators 三 容器简介 STL标准容器类简介 标准容器类 说明 顺序性容器 关联容器 容器适配器 所有标准库共 ...
- python打造文件包含漏洞检测工具
0x00前言: 做Hack the box的题.感觉那个平台得开个VIp 不然得凉.一天只能重置一次...mmp 做的那题毒药是文件包含漏洞的题,涉及到了某个工具 看的不错就开发了一个. 0x01代码 ...
- Oracle 查询历史数据(转帖)
回复误删除数据信息. 1.执行 alter table table_name enable row movement; 2.执行 FlashBack table table_name to times ...
- HTTP代理器Fiddler(三)
HTTP代理神器Fiddler Fiddler是一款强大Web调试工具,它能记录所有客户端和服务器的HTTP请求. Fiddler启动的时候,默认IE的代理设为了127.0.0.1:8888,而其他浏 ...
- socket和udp简介
socket简介 1.本地的进程间通信(IPC)有很多种方式,例如 队列 同步(互斥锁.条件变量等) 以上通信方式都是在一台机器上不同进程之间的通信方式,那么问题来了 网络中进程之间如何通信? 2. ...