#!/bin/sh
# Dell wwan DW5932e and DW5934e of FCC unlock operation
#!/bin/sh

# SPDX-License-Identifier: CC0-1.0
#

# require program name and at least 2 arguments
[ $# -lt 2 ] && exit 1

# first argument is DBus path, not needed here
shift

# second and next arguments are control port names
for PORT in "$@"; do
  # match port type in Linux 5.14 and newer
  grep -q MBIM "/sys/class/wwan/$PORT/type" 2>/dev/null && {
    MBIM_PORT=$PORT
    break
  }
  # match port name in Linux 5.13
  echo "$PORT" | grep -q MBIM && {
    MBIM_PORT=$PORT
    break
  }
done

# fail if no MBIM port exposed
[ -n "$MBIM_PORT" ] || exit 2

UNLOCK_RESULT=1
FoxFlss

UNLOCK_RESULT=$?
if [ $UNLOCK_RESULT -ne 0 ]; then
  echo "Device FCC unlock FAILED" >&2
fi

exit $UNLOCK_RESULT

