Module Name: src Committed By: thorpej Date: Sat Mar 30 16:47:55 UTC 2024
Modified Files: src/distrib/sets/lists/base: mi src/share/examples/devpubd/hooks: Makefile Added Files: src/share/examples/devpubd/hooks: 99-ugen-perms-minipro Log Message: Add an example devpubd hook that looks for Minipro-compatible EEPROM programmers and sets the access permissions to 0660. To generate a diff of this commit: cvs rdiff -u -r1.1337 -r1.1338 src/distrib/sets/lists/base/mi cvs rdiff -u -r0 -r1.1 src/share/examples/devpubd/hooks/99-ugen-perms-minipro cvs rdiff -u -r1.2 -r1.3 src/share/examples/devpubd/hooks/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/base/mi diff -u src/distrib/sets/lists/base/mi:1.1337 src/distrib/sets/lists/base/mi:1.1338 --- src/distrib/sets/lists/base/mi:1.1337 Sat Mar 30 06:42:10 2024 +++ src/distrib/sets/lists/base/mi Sat Mar 30 16:47:55 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1337 2024/03/30 06:42:10 thorpej Exp $ +# $NetBSD: mi,v 1.1338 2024/03/30 16:47:55 thorpej Exp $ # # Note: Don't delete entries from here - mark them as "obsolete" instead, # unless otherwise stated below. @@ -2488,6 +2488,7 @@ ./usr/share/examples/devpubd base-sys-examples ./usr/share/examples/devpubd/hooks base-sys-examples ./usr/share/examples/devpubd/hooks/99-ucom-symlinks base-sys-examples +./usr/share/examples/devpubd/hooks/99-ugen-perms-minipro base-sys-examples ./usr/share/examples/devpubd/hooks/99-ugen-perms-tigard base-sys-examples ./usr/share/examples/dhcp base-dhcpd-examples ./usr/share/examples/dhcpcd base-dhcpcd-examples Index: src/share/examples/devpubd/hooks/Makefile diff -u src/share/examples/devpubd/hooks/Makefile:1.2 src/share/examples/devpubd/hooks/Makefile:1.3 --- src/share/examples/devpubd/hooks/Makefile:1.2 Sat Mar 30 06:42:10 2024 +++ src/share/examples/devpubd/hooks/Makefile Sat Mar 30 16:47:55 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.2 2024/03/30 06:42:10 thorpej Exp $ +# $NetBSD: Makefile,v 1.3 2024/03/30 16:47:55 thorpej Exp $ NOOBJ= # defined @@ -6,6 +6,7 @@ NOOBJ= # defined .if ${MKSHARE} != "no" FILES= 99-ucom-symlinks +FILES+= 99-ugen-perms-minipro FILES+= 99-ugen-perms-tigard FILESDIR=/usr/share/examples/devpubd/hooks .endif Added files: Index: src/share/examples/devpubd/hooks/99-ugen-perms-minipro diff -u /dev/null src/share/examples/devpubd/hooks/99-ugen-perms-minipro:1.1 --- /dev/null Sat Mar 30 16:47:55 2024 +++ src/share/examples/devpubd/hooks/99-ugen-perms-minipro Sat Mar 30 16:47:55 2024 @@ -0,0 +1,144 @@ +#!/bin/sh -x +# +# $NetBSD: 99-ugen-perms-minipro,v 1.1 2024/03/30 16:47:55 thorpej Exp $ +# +# Look for a "Minipro" (https://gitlab.com/DavidGriffith/minipro) compatible +# EEPROM programmer and change change the permissions to 0660. +# +# Written by Jason R. Thorpe, March 2024. Public domain. +# + +export LC_ALL=C + +event="$1" +shift +devices=$@ + +orig_perms=0600 +new_perms=0660 + +orig_group=wheel +new_group=wheel + +device_name=minipro + +is_target_device() +{ + local vendor_string + local product_string + local vendor_id + local product_id + + # + # TL866A/TL866CS programmers have: + # + # VID = 0x04d8 (1240) # Microchip + # PID = 0xe11c (57628) # probably some PIC microcontroller + # + # XXX It's probably better to match on vendor-string / product-string + # in this case because of the use of the generic Microchip VID. + # + # The XGecu-branded TL866II+ devices have: + # + # vendor-string="Xingong Electronicg Co.." + # product-string="Xingong XGecu USB Prog.. Device" + # + # ...but they also have seemingly unique VID/PID (not the + # generic Microchip VID the older TL866A/CS programmers have): + # + # VID = 0xa466 (42086) + # PID = 0x0a53 (2643) + # + # XXX Add the XGecu T48 programmer info here. + # + + vendor_string="$(drvctl -p $1 vendor-string)" + product_string="$(drvctl -p $1 product-string)" + vendor_id="$(drvctl -p $1 vendor-id)" + product_id="$(drvctl -p $1 product-id)" + + # + # TL866A / TL866CS + # + if [ x"$vendor_id" = x"1240" -a \ + x"$product_id" = x"57628" ]; then + echo "yes" + return; + fi + + # + # TL866II+ + # + if [ x"$vendor_id" = x"42086" -a \ + x"$product_id" = x"2643" ]; then + echo "yes" + return + fi + + echo "no" +} + +set_permissions() +{ + if [ x$(is_target_device $1) = xyes ]; then + chgrp $new_group /dev/"${2}".* + chmod $new_perms /dev/"${2}".* + # + # We need to create a symlink here to remember + # the ugen device node that was used, since we + # can't recover it from the device name that + # comes from the kernel later because we get the + # event *after* the device is gone, and thus + # cannot query any properties. + # + rm -f /dev/${1}-${device_name} + ln -sf ${2} /dev/${1}-${device_name} + fi +} + +restore_permissions() +{ + if [ -h "/dev/${1}-${device_name}" ]; then + devnode=$(readlink "/dev/${1}-${device_name}") + if [ x"$devnode" != x ]; then + chmod $orig_perms /dev/"${devnode}".* + chgrp $orig_group /dev/"${devnode}".* + fi + rm -f "/dev/${1}-${device_name}" + fi +} + +get_ugen_devnode() +{ + # Because "ugen" and "ugenif" share the same /dev/ugenN.* + # namespace, we have to query an additional property to + # determine which one it is. + local ugen_unit + + ugen_unit=$(drvctl -p $1 ugen-unit) + case "$ugen_unit" in + [0-9]*) + echo "ugen$ugen_unit" + ;; + esac +} + +for device in $devices; do + case $device in + ugensa*) + # Ignore ugensa(4). + ;; + ugen*) + case $event in + device-attach) + devnode=$(get_ugen_devnode $1) + if [ x"$devnode" != x ]; then + set_permissions $device $devnode + fi + ;; + device-detach) + restore_permissions $device + ;; + esac + esac +done