http://blog.chinaunix.net/uid-22415790-id-1774118.html
1 read local name:
hcitool cmd 0x03 0x0014
2 write local name:
for example, set to name to "kreed", we need use the below command, please note: the length of name should be 248 octets.
hcitool cmd 0x03 0x0013 0x6b 0x72 0x65 0x65 0x64 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
3. enable iscan and disable pscan:
hcitool cmd 0x03 0x001A 0x01
4. enable both iscan and pscan:
hcitool cmd 0x03 0x001A 0x03
5. inquiry and get inquiry result
5.1 firstly use hcidump -V to get dump information.
5.2 send command to inquiry.
/tmp # hcitool cmd 0x01 0x0001 0x33 0x8B 0x9E 0x08 0x00
< HCI Command: ogf 0x01, ocf 0x0001, plen 5
33 8B 9E 08 00
> HCI Event: 0x0f plen 4
00 01 01 04
/tmp # hcitool cmd 0x01 0x0019 0xB0 0xBD 0xD4 0xE5 0x4C 0x90 0x00 0x00 0x00 0x00
< HCI Command: ogf 0x01, ocf 0x0019, plen 10
B0 BD D4 E5 4C 90 00 00 00 00
> HCI Event: 0x0f plen 4
00 01 19 04
0xB0 0xBD 0xD4 0xE5 0x4C 0x90 means BT address 90:4C:E5:D4:BD:B0, which is obtained from hcidump log.
5.3 as we said, we have already launch hcidump while we execute hcitool command. the below is dump log.
hcidump -V
I sniffer - Bluetooth packet analyzer ver 1.42
device: hci0 snap_len: 1028 filter: 0xffffffff
< HCI Command: Inquiry (0x01|0x0001) plen 5
lap 0x9e8b33 len 8 num 0
> HCI Event: Command Status (0x0f) plen 4
Inquiry (0x01|0x0001) status 0x00 ncmd 1
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 00:24:23:18:58:B3 mode 1 clkoffset 0x3f02 class 0x58020c
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 50:63:13:96:33:FD mode 1 clkoffset 0x290f class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 90:4C:E5:D4:BD:B0 mode 1 clkoffset 0x4763 class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 50:63:13:90:54:AE mode 1 clkoffset 0x58fe class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 50:63:13:90:54:AE mode 1 clkoffset 0x58ff class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 50:63:13:90:54:AE mode 1 clkoffset 0x58ff class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr F4:FC:32:47:B1:39 mode 1 clkoffset 0x16a1 class 0x58020c
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr F4:FC:32:47:B1:39 mode 1 clkoffset 0x16a1 class 0x58020c
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 90:4C:E5:D4:BD:B0 mode 1 clkoffset 0x4762 class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 90:4C:E5:D4:BD:B0 mode 1 clkoffset 0x4763 class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 90:4C:E5:D4:BD:B0 mode 1 clkoffset 0x4762 class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 90:4C:E5:D4:BD:B0 mode 1 clkoffset 0x4763 class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 00:24:23:18:58:B3 mode 1 clkoffset 0x3f02 class 0x58020c
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 90:4C:E5:D4:BD:B0 mode 1 clkoffset 0x4762 class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 90:4C:E5:D4:BD:B0 mode 1 clkoffset 0x4763 class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr F4:FC:32:47:B1:39 mode 1 clkoffset 0x16a1 class 0x58020c
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 70:F1:A1:00:27:B8 mode 1 clkoffset 0x5645 class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr 50:63:13:90:54:AE mode 1 clkoffset 0x58ff class 0x000000
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr F4:FC:32:47:B1:39 mode 1 clkoffset 0x16a1 class 0x58020c
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr F4:FC:32:47:B1:39 mode 1 clkoffset 0x16a1 class 0x58020c
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr F4:FC:32:47:B1:39 mode 1 clkoffset 0x16a1 class 0x58020c
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr F4:FC:32:47:B1:39 mode 1 clkoffset 0x16a1 class 0x58020c
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr F4:FC:32:47:B1:39 mode 1 clkoffset 0x16a1 class 0x58020c
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr F4:FC:32:47:B1:39 mode 1 clkoffset 0x16a1 class 0x58020c
> HCI Event: Inquiry Result (0x02) plen 15
bdaddr F4:FC:32:47:B1:39 mode 1 clkoffset 0x16a1 class 0x58020c
> HCI Event: Inquiry Complete (0x01) plen 1
status 0x00
< HCI Command: Remote Name Request (0x01|0x0019) plen 10
bdaddr 90:4C:E5:D4:BD:B0 mode 0 clkoffset 0x0000
> HCI Event: Command Status (0x0f) plen 4
Remote Name Request (0x01|0x0019) status 0x00 ncmd 1
> HCI Event: Remote Name Req Complete (0x07) plen 255
status 0x00 bdaddr 90:4C:E5:D4:BD:B0 name 'Dell Wireless 370 Bluetooth Mini-card'
5.4 from the above dump log, we can get detailed information about remote device:
status 0x00 bdaddr 90:4C:E5:D4:BD:B0 name 'Dell Wireless 370 Bluetooth Mini-card'
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
http://blog.csdn.net/sunrock/article/details/6573237
create connection to bt device
1. HCI UART driver initialization, Attach the tty device
hciattach /dev/ttyS1 any 38400 flow
2. Open and initialize HCI device
hciconfig hci0 up
3. Get/Set local name
hciconfig hci0 name [name]
hciconfig hci0 name TEST --- set the name as "TEST"
4. Display local devices
hcitool dev
5. Scan for remote devices
hcitool scan
6. Create connection to remote device
hcitool cc
create connection to bt spp
1. browse the spp sevice
# sdptool browse bdaddr
2. bind to a rfcomm device
# rfcomm bind /dev/rfcomm0 bdaddr
3. create a connection
# hcitool cc bdaddr
4. open minicom
Serial Device : /dev/rfcomm0
Bps/Par/Bits : 115200 8N1
Hardware Flow Control : No
Software Flow Control : No
# minicom -s rfc0
hcitool
Usage:
hcitool [options] [command parameters]
Options:
--help Display help
-i dev HCI device
Commands:
dev Display local devices
inq Inquire remote devices
scan Scan for remote devices
name Get name from remote device
info Get information from remote device
spinq Start periodic inquiry
epinq Exit periodic inquiry
cmd Submit arbitrary HCI commands
con Display active connections
cc Create connection to remote device
dc Disconnect from remote device
sr Switch master/slave role
cpt Change connection packet type
rssi Display connection RSSI
lq Display link quality
tpl Display transmit power level
afh Display AFH channel map
lp Set/display link policy settings
lst Set/display link supervision timeout
auth Request authentication
enc Set connection encryption
key Change connection link key
clkoff Read clock offset
clock Read local or remote clock
sdptool
sdptool - SDP tool v4.60
Usage:
sdptool [options] [command parameters]
Options:
-h Display help
-i Specify source interface
Commands:
search Search for a service
browse Browse all available services
records Request all records
add Add local service
del Delete local service
get Get local service
setattr Set/Add attribute to a SDP record
setseq Set/Add attribute sequence to a SDP record
Services:
DID SP DUN LAN FAX OPUSH FTP PRINT HS HSAG HF HFAG SAP PBAP NAP
GN PANU HCRP HID KEYB WIIMOTE CIP CTP A2SRC A2SNK AVRCT AVRTG
UDIUE UDITE SEMCHLA SR1 SYNCML SYNCMLSERV ACTIVESYNC HOTSYNC
PALMOS NOKID PCSUITE NFTP NSYNCML NGAGE APPLE ISYNC
rfcomm
RFCOMM configuration utility ver 4.60
Usage:
rfcomm [options]
Options:
-i [hciX|bdaddr] Local HCI device or BD Address
-h, --help Display help
-r, --raw Switch TTY into raw mode
-A, --auth Enable authentication
-E, --encrypt Enable encryption
-S, --secure Secure connection
-M, --master Become the master of a piconet
-f, --config [file] Specify alternate config file
-a Show all devices (default)
Commands:
bind [channel] Bind device
release Release device
show Show device
connect [channel] Connect device
listen [channel [cmd]] Listen
watch [channel [cmd]] Watch