summaryrefslogtreecommitdiff
path: root/tools/update_compids.sh
blob: 606d6cf9c485446a9bb5175828e0bcfb4f08ab3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Download the list of company IDs from bluetooth.org and generate a diff which
# can be applied to source tree to update bt_compidtostr(). Usage:
#
# 1) ./tools/update_compids.sh | git apply -p0
# 2) Inspect changes to make sure they are sane
# 3) git commit -m "lib: Update list of company identifiers" lib/bluetooth.c
#
# Requires html2text: http://www.mbayer.de/html2text/
#
set -e -u

tmpdir=$(mktemp -d)
trap "rm -rf $tmpdir" EXIT

scriptdir=$(pwd)

mkdir $tmpdir/lib
cp lib/bluetooth.c $tmpdir/lib/bluetooth.c.orig
cp lib/bluetooth.c $tmpdir/lib/bluetooth.c

cd $tmpdir

echo -e 'const char *bt_compidtostr(int compid)\n{\n\tswitch (compid) {' > new.c

path=specifications/assigned-numbers/company-identifiers/
# Use "iconv -c" to strip unwanted unicode characters
curl --insecure https://www.bluetooth.com/$path | \
    $scriptdir/tools/parse_companies.pl >> new.c

if ! grep -q "return \"" new.c; then
    echo "ERROR: could not parse company IDs from bluetooth.org" >&2
    exit 1
fi
echo -e '\tcase 65535:\n\t\treturn "internal use";' >> new.c
echo -e '\tdefault:\n\t\treturn "not assigned";\n\t}\n}' >> new.c

sed -n '/^const char \*bt_compidtostr(int compid)/,/^}/p' \
    lib/bluetooth.c > old.c

diff -Naur old.c new.c | patch -sp0 lib/bluetooth.c
diff -Naur lib/bluetooth.c.orig lib/bluetooth.c