#!/bin/sh

# export DBGLVL=10; procd -h /etc/hotplug.json
RTLBT_PRODID="bda/8771/200"

if [ "${PRODUCT}" = "${RTLBT_PRODID}" ]; then
   if [ "${ACTION}" = "bind" ]; then
      slot=0
      bluetooth=""
      if [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.1/1-1.1:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.1/1-2.1:1.0" ]; then
         slot=1
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.2/1-1.2:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.2/1-2.2:1.0" ]; then
         slot=2
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.3/1-1.3:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.3/1-2.3:1.0" ]; then
         slot=3
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.4/1-1.4:1.0" ]; then
         slot=4
      fi
      if [ ${slot} -ne 0 ]; then
         logger -t Hotplug Device name of RTL BT is $DEVICE_NAME at slot $slot
         sh /lib/dyiot/bin/rtl_bt.sh add --slot $slot
      fi
   fi
fi

if [ "${PRODUCT}" = "${RTLBT_PRODID}" ]; then
   if [ "${ACTION}" = "unbind" ]; then
      slot=0
      if [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.1/1-1.1:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.1/1-2.1:1.0" ]; then
         slot=1
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.2/1-1.2:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.2/1-2.2:1.0" ]; then
         slot=2
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.3/1-1.3:1.0" -o "${DEVPATH}" = "/devices/platform/1e1c0000.xhci/usb1/1-2/1-2.3/1-2.3:1.0" ]; then
         slot=3
      elif [ "${DEVPATH}" = "/devices/platform/101c0000.ehci/usb1/1-1/1-1.4/1-1.4:1.0" ]; then
         slot=4
      fi
      if [ ${slot} -ne 0 ]; then
         logger -t Hotplug Device name of RTL BT is $DEVICE_NAME removed at slot $slot
         sh /lib/dyiot/bin/rtl_bt.sh remove --slot $slot
      fi
   fi
fi
