@@ -4,6 +4,7 @@ action=$1
44config=$2
55slot_type=$3
66modem_support=$( cat /usr/share/qmodem/modem_support.json)
7+ modem_port_rule=$( cat /usr/share/qmodem/modem_port_rule.json)
78debug_subject=" modem_scan"
89source /lib/functions.sh
910source /usr/share/qmodem/modem_util.sh
@@ -183,7 +184,7 @@ scan_pcie_slot_interfaces()
183184 dun_devices=$( ls " $devices_path " | grep -E " wwan[0-9]at[0-9]" )
184185 fi
185186 fi
186- echo " net_devices: $net_devices dun_devices: $dun_devices "
187+ m_debug " net_devices: $net_devices dun_devices: $dun_devices "
187188 at_ports=" $dun_devices "
188189 [ -n " $net_devices " ] && get_associate_usb $slot
189190 if [ -n " $associated_usb " ] && [ -d " /sys/bus/usb/devices/$associated_usb " ]; then
@@ -225,6 +226,34 @@ scan_usb_slot_interfaces()
225226 net_devices=" "
226227 tty_devices=" "
227228 [ ! -d " $slot_path " ] && return
229+
230+ slot_vid=$( cat " $slot_path /idVendor" 2> /dev/null || echo " " )
231+ slot_pid=$( cat " $slot_path /idProduct" 2> /dev/null || echo " " )
232+
233+ # m_debug "($slot_vid:$slot_pid) $slot_path"
234+
235+ if [ -n " $slot_vid " ] && [ -n " $slot_pid " ]; then
236+ modem_port_config=$( echo $modem_port_rule | jq ' .modem_port_rule."' $slot_type ' "."' $slot_vid :$slot_pid ' "' )
237+ if [ " $modem_port_config " != " null" ] && [ -n " $modem_port_config " ]; then
238+ config_modem_name=$( echo $modem_port_config | jq -r ' .name' 2> /dev/null || echo " " )
239+ include_ports=$( echo $modem_port_config | jq -r ' .include[]' 2> /dev/null || echo " " )
240+ option_driver=$( echo $modem_port_config | jq -r ' .option_driver' 2> /dev/null || echo " 0" )
241+
242+ if [ -n " $include_ports " ]; then
243+ include_mode=1
244+ m_debug " using special config for $config_modem_name ($slot_vid :$slot_pid ) with ports: $include_ports "
245+ fi
246+ fi
247+ else
248+ m_debug " Unable to read VID/PID from device path: $slot_path "
249+ fi
250+
251+ if [ " $option_driver " = " 1" ] && [ -n " $slot_vid " ] && [ -n " $slot_pid " ]; then
252+ if ! echo " $slot_vid $slot_pid " > /sys/bus/usb-serial/drivers/option1/new_id 2> /dev/null; then
253+ m_debug " failed to set option driver"
254+ fi
255+ fi
256+
228257 local slot_interfaces=$( ls $slot_path | grep -E " $slot :[0-9]\.[0-9]+" )
229258 for interface in $slot_interfaces ; do
230259 unset device
@@ -234,6 +263,9 @@ scan_usb_slot_interfaces()
234263 [ ! -d " $interface_driver_path " ] && continue
235264 interface_driver=$( basename $( readlink $interface_driver_path ) )
236265 [ -z " $interface_driver " ] && continue
266+
267+ local if_port=$( echo " $interface " | grep -oE " [0-9]+\.[0-9]+$" || echo " " )
268+
237269 case $interface_driver in
238270 option|\
239271 cdc_acm|\
@@ -244,7 +276,22 @@ scan_usb_slot_interfaces()
244276 [ -z " $ttyUSB_device " ] && [ -z " $ttyACM_device " ] && continue
245277 [ -n " $ttyUSB_device " ] && device=" $ttyUSB_device "
246278 [ -n " $ttyACM_device " ] && device=" $ttyACM_device "
247- [ -z " $tty_devices " ] && tty_devices=" $device " || tty_devices=" $tty_devices $device "
279+
280+ local should_include=1
281+
282+ if [ $include_mode -eq 1 ]; then
283+ should_include=0
284+ for included_port in $include_ports ; do
285+ if [ -n " $if_port " ] && [ " $included_port " = " $if_port " ]; then
286+ should_include=1
287+ break
288+ fi
289+ done
290+ fi
291+
292+ if [ $should_include -eq 1 ]; then
293+ [ -z " $tty_devices " ] && tty_devices=" $device " || tty_devices=" $tty_devices $device "
294+ fi
248295 ;;
249296 qmi_wwan* |\
250297 cdc_mbim|\
@@ -258,7 +305,7 @@ scan_usb_slot_interfaces()
258305 ;;
259306 esac
260307 done
261- m_debug " net_devices: $net_devices tty_devices: $tty_devices "
308+ m_debug " net_devices: $net_devices tty_devices: $tty_devices device_id: ( $slot_vid : $slot_pid ) "
262309 at_ports=" $tty_devices "
263310 validate_at_port
264311}
0 commit comments