#!/bin/sh
#
# Prints out the full status of the USB Gadget interface
#
# Copyright (c) 2017 Valeo
#

INTERFACE=android0
STATUS=unknown

# Check that the USB Gadget interface support is enabled in the kernel
if [ \! -e /sys/class/android_usb/$INTERFACE/enable ]
then
    STATUS=disabled
    exit 0
fi

# Check the USB gadget interface current status is enabled.
ENABLED=`cat /sys/class/android_usb/$INTERFACE/enable`
if [ "$ENABLED" != 1 ]
then
    STATUS=disabled
    echo $STATUS
    exit 0
fi
STATUS=enabled

# Check if each USB Gadget function listed on the command line
# is enabled.
FUNCTIONS=`sed 's/,/ /g' /sys/class/android_usb/$INTERFACE/functions`
for enabled_function in $FUNCTIONS
do
    STATUS="$STATUS $enabled_function"
done

# If the script reached that point it means that all is enabled.
echo $STATUS
exit 0
