0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[2021Sep] Linux で Bluetooth バージョンを確認する

Posted at

はじめに

Bluetooth LE デバイスを使おうかと思った時に、まずは手元の環境が対応しているか調べないとね、ということで、調べました。

調べられたのですけれど、世間の情報が錯綜している感じだったので、調査に使ったツールのソースコードを確認して、情報を確定させようと思った次第です。

結論

hciconfig で表示される LMP Version は Bluetooth コア仕様バージョンです。

サンプル

hciconfig を使うと下記のような出力が得られます。

$ hciconfig -a
hci0:   Type: Primary  Bus: USB
(中略)
        HCI Version: 5.1 (0xa)  Revision: 0x100
        LMP Version: 5.1 (0xa)  Subversion: 0x100
        Manufacturer: Intel Corp. (2)

この LMP Version: 5.15.1 は、Bluetooth 5.1 であることを示しています。そして (0xa) の方が LMP のバージョンが 10 であることを示しています。

コード

※以下のリンクやコードは bluez 5.61 のものです。

0xa を 5.1 に変換している関数が lmp_vertostr() です。

lib/hci.c
char *lmp_vertostr(unsigned int ver)
{
	return hci_uint2str(ver_map, ver);
}

static char *hci_uint2str(hci_map *m, unsigned int val)
{
	char *str = malloc(50);
	char *ptr = str;

	if (!str)
		return NULL;

	*ptr = 0;
	while (m->str) {
		if ((unsigned int) m->val == val) {
			ptr += sprintf(ptr, "%s", m->str);
			break;
		}
		m++;
	}
	return str;
}

この ver_map 変数に LMP バージョンと Bluetooth コア仕様バージョンの対応一覧が入っています。

lib/hci.c
/* Version mapping */
static hci_map ver_map[] = {
	{ "1.0b",	0x00 },
	{ "1.1",	0x01 },
	{ "1.2",	0x02 },
	{ "2.0",	0x03 },
	{ "2.1",	0x04 },
	{ "3.0",	0x05 },
	{ "4.0",	0x06 },
	{ "4.1",	0x07 },
	{ "4.2",	0x08 },
	{ "5.0",	0x09 },
	{ "5.1",	0x0a },
	{ "5.2",	0x0b },
	{ NULL }
};

おわりに

Bluetooth バージョン(やプロファイル)が不明瞭なまま販売されてる機器ってありますよね。書いてなかったり、矛盾することが書いてあったり。いろいろと複雑なので仕方ないかと思います。是正しようにも出来なさそう。

とりあえず母艦(PC本体やらドングルやら)のバージョンが大きければ何とかなる可能性が高いと思います。それを確認する方法が確立できて良かったです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?