hack のためのネタ帳, etc,,,

×
INKBIRD IBS-TH2 Plus の Bluetooth GATT caracteristics を調べるたところ以下のような結果となった。
$ gatttool -b "$MAC" --characteristics
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 = 0x02, char value handle = 0x0007, uuid = 00002a04-0000-1000-8000-00805f9b34fb
handle = 0x0009, char properties = 0x20, char value handle = 0x000a, uuid = 00002a05-0000-1000-8000-00805f9b34fb
handle = 0x000d, char properties = 0x08, char value handle = 0x000e, uuid = 5833ff02-9b8b-5191-6142-22a4536ef123
handle = 0x000f, char properties = 0x10, char value handle = 0x0010, uuid = 5833ff03-9b8b-5191-6142-22a4536ef123
handle = 0x0013, char properties = 0x0a, char value handle = 0x0014, uuid = 0000fff1-0000-1000-8000-00805f9b34fb
handle = 0x0016, char properties = 0x02, char value handle = 0x0017, uuid = 0000fff2-0000-1000-8000-00805f9b34fb
handle = 0x0019, char properties = 0x0a, char value handle = 0x001a, uuid = 0000fff3-0000-1000-8000-00805f9b34fb
handle = 0x001c, char properties = 0x02, char value handle = 0x001d, uuid = 0000fff4-0000-1000-8000-00805f9b34fb
handle = 0x001f, char properties = 0x02, char value handle = 0x0020, uuid = 0000fff5-0000-1000-8000-00805f9b34fb
handle = 0x0022, char properties = 0x10, char value handle = 0x0023, uuid = 0000fff6-0000-1000-8000-00805f9b34fb
handle = 0x0026, char properties = 0x0a, char value handle = 0x0027, uuid = 0000fff7-0000-1000-8000-00805f9b34fb
handle = 0x0029, char properties = 0x0a, char value handle = 0x002a, uuid = 0000fff8-0000-1000-8000-00805f9b34fb
handle = 0x002c, char properties = 0x08, char value handle = 0x002d, uuid = 0000fff9-0000-1000-8000-00805f9b34fb
$ gatttool -b "$MAC" --char-desc
handle = 0x0001, uuid = 00002800-0000-1000-8000-00805f9b34fb
handle = 0x0002, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x0003, uuid = 00002a00-0000-1000-8000-00805f9b34fb
handle = 0x0004, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x0005, uuid = 00002a01-0000-1000-8000-00805f9b34fb
handle = 0x0006, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x0007, uuid = 00002a04-0000-1000-8000-00805f9b34fb
handle = 0x0008, uuid = 00002800-0000-1000-8000-00805f9b34fb
handle = 0x0009, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x000a, uuid = 00002a05-0000-1000-8000-00805f9b34fb
handle = 0x000b, uuid = 00002902-0000-1000-8000-00805f9b34fb
handle = 0x000c, uuid = 00002800-0000-1000-8000-00805f9b34fb
handle = 0x000d, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x000e, uuid = 5833ff02-9b8b-5191-6142-22a4536ef123
handle = 0x000f, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x0010, uuid = 5833ff03-9b8b-5191-6142-22a4536ef123
handle = 0x0011, uuid = 00002902-0000-1000-8000-00805f9b34fb
handle = 0x0012, uuid = 00002800-0000-1000-8000-00805f9b34fb
handle = 0x0013, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x0014, uuid = 0000fff1-0000-1000-8000-00805f9b34fb
handle = 0x0015, uuid = 00002901-0000-1000-8000-00805f9b34fb
handle = 0x0016, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x0017, uuid = 0000fff2-0000-1000-8000-00805f9b34fb
handle = 0x0018, uuid = 00002901-0000-1000-8000-00805f9b34fb
handle = 0x0019, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x001a, uuid = 0000fff3-0000-1000-8000-00805f9b34fb
handle = 0x001b, uuid = 00002901-0000-1000-8000-00805f9b34fb
handle = 0x001c, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x001d, uuid = 0000fff4-0000-1000-8000-00805f9b34fb
handle = 0x001e, uuid = 00002901-0000-1000-8000-00805f9b34fb
handle = 0x001f, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x0020, uuid = 0000fff5-0000-1000-8000-00805f9b34fb
handle = 0x0021, uuid = 00002901-0000-1000-8000-00805f9b34fb
handle = 0x0022, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x0023, uuid = 0000fff6-0000-1000-8000-00805f9b34fb
handle = 0x0024, uuid = 00002902-0000-1000-8000-00805f9b34fb
handle = 0x0025, uuid = 00002901-0000-1000-8000-00805f9b34fb
handle = 0x0026, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x0027, uuid = 0000fff7-0000-1000-8000-00805f9b34fb
handle = 0x0028, uuid = 00002901-0000-1000-8000-00805f9b34fb
handle = 0x0029, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x002a, uuid = 0000fff8-0000-1000-8000-00805f9b34fb
handle = 0x002b, uuid = 00002901-0000-1000-8000-00805f9b34fb
handle = 0x002c, uuid = 00002803-0000-1000-8000-00805f9b34fb
handle = 0x002d, uuid = 0000fff9-0000-1000-8000-00805f9b34fb
handle = 0x002e, uuid = 00002901-0000-1000-8000-00805f9b34fb
$ for i in {1..46}; do h="$(printf "0x%04x" $i)"; echo -n "$h : "; gatttool -b "$MAC" --char-read -a $h; done
0x0001 : Characteristic value/descriptor: 00 18
0x0002 : Characteristic value/descriptor: 02 03 00 00 2a
0x0003 : Characteristic value/descriptor: 73 70 73
0x0004 : Characteristic value/descriptor: 02 05 00 01 2a
0x0005 : Characteristic value/descriptor: 00 00
0x0006 : Characteristic value/descriptor: 02 07 00 04 2a
0x0007 : Characteristic value/descriptor: 0f 00 0f 00 00 00 e8 03
0x0008 : Characteristic value/descriptor: 01 18
0x0009 : Characteristic value/descriptor: 20 0a 00 05 2a
0x000a : Characteristic value/descriptor read failed: Attribute can't be read
0x000b : Characteristic value/descriptor: 00 00
0x000c : Characteristic value/descriptor: 23 f1 6e 53 a4 22 42 61 91 51 8b 9b 01 ff 33 58
0x000d : Characteristic value/descriptor: 08 0e 00 23 f1 6e 53 a4 22 42 61 91 51 8b 9b 02 ff 33 58
0x000e : Characteristic value/descriptor read failed: Attribute can't be read
0x000f : Characteristic value/descriptor: 10 10 00 23 f1 6e 53 a4 22 42 61 91 51 8b 9b 03 ff 33 58
0x0010 : Characteristic value/descriptor read failed: Attribute can't be read
0x0011 : Characteristic value/descriptor: 00 00
0x0012 : Characteristic value/descriptor: f0 ff
0x0013 : Characteristic value/descriptor: 0a 14 00 f1 ff
0x0014 : Characteristic value/descriptor: 00 00 00 00 00 00 00 78 00 00 00 32 2d 37 ae 4f 00 00 00 00
0x0015 : Characteristic value/descriptor: 63 66 67 20 64 61 74 61
0x0016 : Characteristic value/descriptor: 02 17 00 f2 ff
0x0017 : Characteristic value/descriptor: 07 0a 6a 10 00 bf c4
0x0018 : Characteristic value/descriptor: 52 65 61 6c 20 74 69 6d 65 20 64 61 74 61
0x0019 : Characteristic value/descriptor: 0a 1a 00 f3 ff
0x001a : Characteristic value/descriptor: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x001b : Characteristic value/descriptor: 63 66 67 20 64 61 74 61 32
0x001c : Characteristic value/descriptor: 02 1d 00 f4 ff
0x001d : Characteristic value/descriptor: 49 25 06 16 08 f1 64 8d 00 00 00 00 00 00 00 00 00 00 00 00
0x001e : Characteristic value/descriptor: 6d 65 61 73 75 72 65
0x001f : Characteristic value/descriptor: 02 20 00 f5 ff
0x0020 : Characteristic value/descriptor: 49 0e 00 00
0x0021 : Characteristic value/descriptor: 72 65 63 6f 64 65 72 20 66 72 61 6d 65
0x0022 : Characteristic value/descriptor: 10 23 00 f6 ff
0x0023 : Characteristic value/descriptor: 4e 3d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0024 : Characteristic value/descriptor: 01 00
0x0025 : Characteristic value/descriptor: 68 69 73 74 6f 72 79 20 64 61 74 61
0x0026 : Characteristic value/descriptor: 0a 27 00 f7 ff
0x0027 : Characteristic value/descriptor: 01 7e 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0028 : Characteristic value/descriptor: 72 75 6e 2f 73 74 6f 70 20 72 65 63 6f 64 65 72
0x0029 : Characteristic value/descriptor: 0a 2a 00 f8 ff
0x002a : Characteristic value/descriptor: 08
0x002b : Characteristic value/descriptor: 68 69 73 20 64 61 74 61 20 74 79 70 65
0x002c : Characteristic value/descriptor: 08 2d 00 f9 ff
0x002d : Characteristic value/descriptor read failed: No attribute found within the given range
0x002e : Characteristic value/descriptor: 72 65 73 65 74
$ gatttool -b "$MAC"--char-desc \
| grep 00002901 \
| sed -E 's/.*(0x[0-9a-f]+).*/\1/g' \
| while read i; do \
    echo -n "$i : "; gatttool -b "$MAC" --char-read -a "$i" \
|   sed -E 's/.*://g;s/ *$//g;s/ /\\x/g;s/.*/"\0"/g;s/^//g' \
|   xargs echo -e; \
done
0x0015 : cfg data
0x0018 : Real time data
0x001b : cfg data2
0x001e : measure
0x0021 : recoder frame
0x0025 : history data
0x0028 : run/stop recoder
0x002b : his data type
0x002e : reset

$ # It seems that describe previous handle usage.
$ read v < <(gatttool -b "$MAC" --char-read -a 0x0017); printf "%s\n" "$v"; \
readarray -t v < <(sed -E 's/.*: *//g;s/ +/\n/g' <<<"$v"); declare -p v; \
printf "%d\n" \
"0x${v[1]}${v[0]}" \
"0x${v[3]}${v[2]}" \
"0x${v[6]}${v[5]}${v[4]}" \
"0x${v[5]}${v[4]}" \
"0x${v[6]}${v[5]}" \
"0x${v[5]}" \
"0x${v[6]}"
Characteristic value/descriptor: 04 0a 64 10 00 9a 07
declare -a v=([0]="04" [1]="0a" [2]="64" [3]="10" [4]="00" [5]="9a" [6]="07")
2564
4196
498176
39424
1946
154
7

$ # It seems that:
$ # [1,0] bytes = temperature * 100 = 25.64℃ * 100
$ # [3,2] bytes = humidity    * 100 = 41.96%  * 100
$ # [4, 5, 6] bytes : unidentified usage values

human readable にするため以下のようなスクリプトをこさえた。

gatt_info.sh

#!/usr/bin/env bash

function explain_uuid () # <uuid>
{
  local uuid="$1"
  case "$uuid" in
  0000ff*) echo -n "Vnd Spec: " ;;
  000028*) echo -n "Std Decl: " ;;
  000029*) echo -n "Std Desc: " ;;
  00002a*) echo -n "Std Char: " ;;
  *)       echo -n "Unknown : " ;;
  esac
  case "$uuid" in
  00002800) echo "Primary Service" ;;
  00002801) echo "Secondary Service" ;;
  00002802) echo "Include" ;;
  00002803) echo "Characteristic" ;;
  00002900) echo "Char ext prop" ;;
  00002901) echo "Char usr desc" ;;
  00002902) echo "Client char config" ;;
  00002903) echo "Server char config" ;;
  00002a00) echo "Device Name" ;;
  00002a01) echo "Appearance" ;;
  00002a04) echo "Peripheral Preferred Connection Params" ;;
  00002a05) echo "Service Changed" ;;
  *)        echo ;;
  esac
}

function sep () # <char>
{
  local char="${1:--}"
  printf "%*s\n" "$(tput cols)" | tr " " "$char"
}

function presep () # <uuid>
{
  local uuid="$1"
  case "$uuid" in
  00002800) ;&
  00002801) sep = ;;
  00002803) sep ;;
  esac
}

function postsep () # <uuid>
{
  return
  local uuid="$1"
  case "$uuid" in
  00002901) sep ;;
  esac
}

function tostring () # <value>...
{
  local tmp
  printf -v tmp "\\\\x%s" "$@"
  echo -e "$tmp"
}


MAC="$1"

readarray -t char_descs < <(gatttool -b "$MAC" --char-desc)

for char_desc in "${char_descs[@]}"; do
  read uuid < <(sed -E 's/.*uuid * = *([0-9a-f]+).*/\1/g' <<< "$char_desc")
  read handle < <(sed -E 's/.*handle * = *([0-9a-fx]+).*/\1/g' <<< "$char_desc")
  read exp < <(explain_uuid "$uuid")
  presep "$uuid"
  echo "$char_desc : $exp"
  readarray -t values < <(gatttool -b "$MAC" --char-read -a "$handle" | sed -E 's/.*: *| *$//g;s/ +/\n/g')
  echo -n "${values[@]}"
  case "$uuid" in
  00002a00) ;&
  00002901)
    echo -n " : "
    tostring "${values[@]}"
    ;;
  *) echo ;;
  esac
  postsep "$uuid"
done
sep =

  • temperature : 27.07℃
  • humidity : 39.55%
  • battery : 69%
のタイミングでの結果
$ ./gatt_info.sh $MAC
========================================================================================================================
handle = 0x0001, uuid = 00002800-0000-1000-8000-00805f9b34fb : Std Decl: Primary Service
00 18
------------------------------------------------------------------------------------------------------------------------
handle = 0x0002, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
02 03 00 00 2a
handle = 0x0003, uuid = 00002a00-0000-1000-8000-00805f9b34fb : Std Char: Device Name
73 70 73 : sps
------------------------------------------------------------------------------------------------------------------------
handle = 0x0004, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
02 05 00 01 2a
handle = 0x0005, uuid = 00002a01-0000-1000-8000-00805f9b34fb : Std Char: Appearance
00 00
------------------------------------------------------------------------------------------------------------------------
handle = 0x0006, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
02 07 00 04 2a
handle = 0x0007, uuid = 00002a04-0000-1000-8000-00805f9b34fb : Std Char: Peripheral Preferred Connection Params
0f 00 0f 00 00 00 e8 03
========================================================================================================================
handle = 0x0008, uuid = 00002800-0000-1000-8000-00805f9b34fb : Std Decl: Primary Service
01 18
------------------------------------------------------------------------------------------------------------------------
handle = 0x0009, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
20 0a 00 05 2a
handle = 0x000a, uuid = 00002a05-0000-1000-8000-00805f9b34fb : Std Char: Service Changed
Characteristic value/descriptor read failed: Attribute can't be read

handle = 0x000b, uuid = 00002902-0000-1000-8000-00805f9b34fb : Std Desc: Client char config
00 00
========================================================================================================================
handle = 0x000c, uuid = 00002800-0000-1000-8000-00805f9b34fb : Std Decl: Primary Service
23 f1 6e 53 a4 22 42 61 91 51 8b 9b 01 ff 33 58
------------------------------------------------------------------------------------------------------------------------
handle = 0x000d, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
08 0e 00 23 f1 6e 53 a4 22 42 61 91 51 8b 9b 02 ff 33 58
handle = 0x000e, uuid = 5833ff02-9b8b-5191-6142-22a4536ef123 : Unknown :
Characteristic value/descriptor read failed: Attribute can't be read

------------------------------------------------------------------------------------------------------------------------
handle = 0x000f, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
10 10 00 23 f1 6e 53 a4 22 42 61 91 51 8b 9b 03 ff 33 58
handle = 0x0010, uuid = 5833ff03-9b8b-5191-6142-22a4536ef123 : Unknown :
Characteristic value/descriptor read failed: Attribute can't be read

handle = 0x0011, uuid = 00002902-0000-1000-8000-00805f9b34fb : Std Desc: Client char config
00 00
========================================================================================================================
handle = 0x0012, uuid = 00002800-0000-1000-8000-00805f9b34fb : Std Decl: Primary Service
f0 ff
------------------------------------------------------------------------------------------------------------------------
handle = 0x0013, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
0a 14 00 f1 ff
handle = 0x0014, uuid = 0000fff1-0000-1000-8000-00805f9b34fb : Vnd Spec:
00 00 00 00 00 00 00 78 00 00 00 32 2d 37 ae 4f 00 00 00 00
handle = 0x0015, uuid = 00002901-0000-1000-8000-00805f9b34fb : Std Desc: Char usr desc
63 66 67 20 64 61 74 61 : cfg data
------------------------------------------------------------------------------------------------------------------------
handle = 0x0016, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
02 17 00 f2 ff
handle = 0x0017, uuid = 0000fff2-0000-1000-8000-00805f9b34fb : Vnd Spec:
94 0a 72 0f 00 b3 ee
handle = 0x0018, uuid = 00002901-0000-1000-8000-00805f9b34fb : Std Desc: Char usr desc
52 65 61 6c 20 74 69 6d 65 20 64 61 74 61 : Real time data
------------------------------------------------------------------------------------------------------------------------
handle = 0x0019, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
0a 1a 00 f3 ff
handle = 0x001a, uuid = 0000fff3-0000-1000-8000-00805f9b34fb : Vnd Spec:
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
handle = 0x001b, uuid = 00002901-0000-1000-8000-00805f9b34fb : Std Desc: Char usr desc
63 66 67 20 64 61 74 61 32 : cfg data2
------------------------------------------------------------------------------------------------------------------------
handle = 0x001c, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
02 1d 00 f4 ff
handle = 0x001d, uuid = 0000fff4-0000-1000-8000-00805f9b34fb : Vnd Spec:
49 25 06 16 08 f1 64 8d 00 00 00 00 00 00 00 00 00 00 00 00
handle = 0x001e, uuid = 00002901-0000-1000-8000-00805f9b34fb : Std Desc: Char usr desc
6d 65 61 73 75 72 65 : measure
------------------------------------------------------------------------------------------------------------------------
handle = 0x001f, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
02 20 00 f5 ff
handle = 0x0020, uuid = 0000fff5-0000-1000-8000-00805f9b34fb : Vnd Spec:
bd 0e 00 00
handle = 0x0021, uuid = 00002901-0000-1000-8000-00805f9b34fb : Std Desc: Char usr desc
72 65 63 6f 64 65 72 20 66 72 61 6d 65 : recoder frame
------------------------------------------------------------------------------------------------------------------------
handle = 0x0022, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
10 23 00 f6 ff
handle = 0x0023, uuid = 0000fff6-0000-1000-8000-00805f9b34fb : Vnd Spec:
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
handle = 0x0024, uuid = 00002902-0000-1000-8000-00805f9b34fb : Std Desc: Client char config
00 00
handle = 0x0025, uuid = 00002901-0000-1000-8000-00805f9b34fb : Std Desc: Char usr desc
68 69 73 74 6f 72 79 20 64 61 74 61 : history data
------------------------------------------------------------------------------------------------------------------------
handle = 0x0026, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
0a 27 00 f7 ff
handle = 0x0027, uuid = 0000fff7-0000-1000-8000-00805f9b34fb : Vnd Spec:
01 7e 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
handle = 0x0028, uuid = 00002901-0000-1000-8000-00805f9b34fb : Std Desc: Char usr desc
72 75 6e 2f 73 74 6f 70 20 72 65 63 6f 64 65 72 : run/stop recoder
------------------------------------------------------------------------------------------------------------------------
handle = 0x0029, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
0a 2a 00 f8 ff
handle = 0x002a, uuid = 0000fff8-0000-1000-8000-00805f9b34fb : Vnd Spec:
00
handle = 0x002b, uuid = 00002901-0000-1000-8000-00805f9b34fb : Std Desc: Char usr desc
68 69 73 20 64 61 74 61 20 74 79 70 65 : his data type
------------------------------------------------------------------------------------------------------------------------
handle = 0x002c, uuid = 00002803-0000-1000-8000-00805f9b34fb : Std Decl: Characteristic
08 2d 00 f9 ff
handle = 0x002d, uuid = 0000fff9-0000-1000-8000-00805f9b34fb : Vnd Spec:
Characteristic value/descriptor read failed: No attribute found within the given range

handle = 0x002e, uuid = 00002901-0000-1000-8000-00805f9b34fb : Std Desc: Char usr desc
72 65 73 65 74 : reset
========================================================================================================================
$

UUID 0x2803 (Standard Decliptors: Characteristic) は
{
  int8     char_properties,
  int16le  char_value_handle,
  int16le   uuid,
}
または
{
  int8     char_properties,
  int16le  char_value_handle,
  int128le uuid,
}
のようだ。

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

フリーエリア

管理人/副管理人のみ編集できます

広告募集中