blob: 91360766677d555acb12716346f4570fb79a0a0d [file] [log] [blame]
#!/bin/sh
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This script prints the hardware class (e.g., the hardware
# qualification ID) of this device, or "unknown" if it can't determine
# the hardware class.
# TODO(petkov): If the hardware qualification ID is not available on
# the systems, the script uses alternative ways to identify different
# system classes (e.g., the WiFi adapter PCI vendor and device
# IDs). Switch the script to use only real hardware qualification ID
# when that becomes available on all systems.
HARDWARE_CLASS=
readonly HWID_PATH=/sys/bus/platform/devices/chromeos_acpi/HWID
# Appends a new component ID to the hardware class. Separates IDs with
# dashes.
append_class() {
[ -n "$1" ] || return
[ -n "$HARDWARE_CLASS" ] && HARDWARE_CLASS="${HARDWARE_CLASS}-"
HARDWARE_CLASS="${HARDWARE_CLASS}$1"
}
hwid() {
[ -r "$HWID_PATH" ] || return
local acpihwid
acpihwid=$(cat "$HWID_PATH")
[ -n "$acpihwid" ] || return
append_class "$acpihwid"
}
# Adds the CPU family, model and stepping info, if available, to the
# class.
cpu() {
[ -r /proc/cpuinfo ] || return
local family
family=$(grep -m1 '^cpu family' /proc/cpuinfo \
| sed 's/cpu family\s\+:\s\+\([0-9]\+\)$/\1/')
local model
model=$(grep -m1 '^model' /proc/cpuinfo \
| sed 's/model\s\+:\s\+\([0-9]\+\)$/\1/')
local stepping
stepping=$(grep -m1 '^stepping' /proc/cpuinfo \
| sed 's/stepping\s\+:\s\+\([0-9]\+\)$/\1/')
if [ -n "$family" ] && [ -n "$model" ] && [ -n "$stepping" ]; then
append_class "cpu/$family:$model:$stepping"
fi
}
# Adds the wlan0 PCI vendor and device ID, if available, to the class.
wlan() {
local dev=/sys/class/net/wlan0/device
if [ -r $dev/vendor ] && [ -r $dev/device ]; then
local id
id=$(paste -d ':' $dev/vendor $dev/device | sed s/0x//g)
append_class "wlan0/$id"
fi
}
main() {
hwid
# If the HWID is not available, use system component IDs.
if [ -z "$HARDWARE_CLASS" ]; then
cpu
wlan
[ -z "$HARDWARE_CLASS" ] && HARDWARE_CLASS=unknown
fi
echo $HARDWARE_CLASS
}
main $@