meta-google: google-usb-network: Allow picking device type

This makes it possible to choose something other than EEM.

Change-Id: Id3bd080efa63eddd1d413df19bc373eef96ac359
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meta-google/recipes-google/networking/google-usb-network/usb_network.service.m4 b/meta-google/recipes-google/networking/google-usb-network/usb_network.service.m4
index 7893ba4..c65b815 100644
--- a/meta-google/recipes-google/networking/google-usb-network/usb_network.service.m4
+++ b/meta-google/recipes-google/networking/google-usb-network/usb_network.service.m4
@@ -18,6 +18,7 @@
 ExecStart=M_SCRIPT_INSTALL_DIR/usb_network.sh \
     --product-id "M_BMC_USB_PRODUCT_ID" \
     --product-name "M_BMC_USB_PRODUCT_NAME" \
+    --dev-type "M_BMC_USB_TYPE" \
     HOST_MAC_ARG(M_BMC_USB_HOST_MAC) \
     DEV_MAC_ARG(M_BMC_USB_DEV_MAC) \
     --bind-device "M_BMC_USB_BIND_DEV"
diff --git a/meta-google/recipes-google/networking/google-usb-network/usb_network.sh b/meta-google/recipes-google/networking/google-usb-network/usb_network.sh
index ede4482..6f2c4d5 100755
--- a/meta-google/recipes-google/networking/google-usb-network/usb_network.sh
+++ b/meta-google/recipes-google/networking/google-usb-network/usb_network.sh
@@ -23,6 +23,7 @@
     "host-mac:"
     "bind-device:"
     "dev-mac:"
+    "dev-type:"
     "gadget-dir-name:"
     "iface-name:"
 )
@@ -35,6 +36,7 @@
         --product-name Product name string (en) for the gadget.
         --host-mac MAC address of the host part of the connection. Optional.
         --dev-mac MAC address of the device (gadget) part of the connection. Optional.
+        --dev-type Type of gadget to instantiate. Default: "eem"
         --bind-device Name of the device to bind, as listed in /sys/class/udc/
         --gadget-dir-name Optional base name for gadget directory. Default: "g1"
         --iface-name Optional name of the network interface. Default: "usb0"
@@ -71,9 +73,9 @@
     mkdir -p "${config_dir}"
     echo 100 > "${config_dir}/MaxPower"
     mkdir -p "${config_dir}/strings/0x409"
-    echo "EEM" > "${config_dir}/strings/0x409/configuration"
+    echo "${DEV_TYPE^^}" > "${config_dir}/strings/0x409/configuration"
 
-    local func_dir="${gadget_dir}/functions/eem.${IFACE_NAME}"
+    local func_dir="${gadget_dir}/functions/${DEV_TYPE}.${IFACE_NAME}"
     mkdir -p "${func_dir}"
 
     if [[ -n $HOST_MAC_ADDR ]]; then
@@ -91,11 +93,11 @@
 
 gadget_stop() {
     local gadget_dir="${CONFIGFS_HOME}/usb_gadget/${GADGET_DIR_NAME}"
-    rm -f ${gadget_dir}/configs/c.1/eem.${IFACE_NAME}
+    rm -f ${gadget_dir}/configs/c.1/${DEV_TYPE}.${IFACE_NAME}
     rm -rf ${gadget_dir}/configs/c.1/strings/0x409
     rm -rf ${gadget_dir}/configs/c.1
     rm -rf ${gadget_dir}/strings/0x409
-    rm -rf ${gadget_dir}/functions/eem.${IFACE_NAME}
+    rm -rf ${gadget_dir}/functions/${DEV_TYPE}.${IFACE_NAME}
     rm -rf ${gadget_dir}
 
     rm -f /run/systemd/network/+-bmc-"${IFACE_NAME}".network
@@ -117,6 +119,7 @@
 STR_EN_VENDOR="Google"
 STR_EN_PRODUCT=""
 DEV_MAC_ADDR=""
+DEV_TYPE="eem"
 HOST_MAC_ADDR=""
 BIND_DEVICE=""
 ACTION="start"
@@ -140,6 +143,10 @@
             DEV_MAC_ADDR=$2
             shift 2
             ;;
+        --dev-type)
+            DEV_TYPE=$2
+            shift 2
+            ;;
         --bind-device)
             BIND_DEVICE=$2
             shift 2
diff --git a/meta-google/recipes-google/networking/google-usb-network_git.bb b/meta-google/recipes-google/networking/google-usb-network_git.bb
index eb07959..882b755 100644
--- a/meta-google/recipes-google/networking/google-usb-network_git.bb
+++ b/meta-google/recipes-google/networking/google-usb-network_git.bb
@@ -25,6 +25,7 @@
 BMC_USB_ECM_BIND_DEV ??= ""
 BMC_USB_CONFIG_PRIORITY ??= ""
 BMC_USB_CONFIG_FILENAME ??= "${BMC_USB_CONFIG_PRIORITY}-bmc-usb0.network"
+BMC_USB_TYPE ??= "eem"
 
 SRC_URI += "file://00-bmc-usb0.network.m4"
 SRC_URI += "file://usb_network.service.m4"
@@ -44,6 +45,7 @@
     m4 \
         -DM_BMC_USB_PRODUCT_ID="${BMC_USB_ECM_PRODUCT_ID}" \
         -DM_BMC_USB_PRODUCT_NAME="${BMC_USB_ECM_PRODUCT_NAME}" \
+        -DM_BMC_USB_TYPE="${BMC_USB_TYPE}" \
         -DM_BMC_USB_HOST_MAC="${BMC_USB_ECM_HOST_MAC}" \
         -DM_BMC_USB_DEV_MAC="${BMC_USB_ECM_DEV_MAC}" \
         -DM_BMC_USB_BIND_DEV="${BMC_USB_ECM_BIND_DEV}" \