Solved Automating 'dhclient ue0' when tethering USB

what about a devd.conf

Code:
/usr/local/etc/devd.conf

this is what i use for my keyboard

i guess you could do the same thing to run dhclient ue0


Code:
#=========================================================================#
# devd.conf
#=========================================================================#

#=========================================================================#
# ducky one 2 mini
#=========================================================================#

attach 100 {
        device-name "uhid[0-9]+";                                                           
        match "vendor"  "0x0416"; # (1)
        match "product" "0x0123"; # (2)

    #
    # Do not add -d flag ! if you do it devd will never detach to background
    # because usbhidaction will run in foreground !
    #
    # Remember you can add arguments after /etc/usbhidaction.conf like
    # action "/usr/bin/usbhidaction -f $device-name -c /etc/usbhidaction.conf /dev/mixer1 2"
    #
        action "/usr/bin/usbhidaction -f $device-name -c /usr/local/etc/usbhidaction.conf";
};
 
To summarize:

Create this file and populate it.
/usr/local/etc/devd/usb_tethering.conf
Code:
notify 20 {
    match    "system"    "ETHERNET";
    match    "type"        "IFATTACH";
    match    "subsystem"    "ue[0-9]+";
    action    "/sbin/dhclient $subsystem";
};
Then service devd restart.

Running devd with the -d flag will show it in action.
service devd stop && devd -d
If you have any errors it will tell on startup what file and line numbers that have issues.

No other settings are needed. Create a devd rule configuration file in the proper location and restart devd.
 
Last edited:
To summarize:

Create this file and populate it.
/usr/local/etc/devd/usb_tethering.conf
Code:
notify 20 {
    match    "system"    "ETHERNET";
    match    "type"        "IFATTACH";
    match    "subsystem"    "ue[0-9]+";
    action    "/sbin/dhclient $subsystem";
};
Then service devd restart.

Running devd with the -d flag will show it in action.
service devd stop && devd -d
If you have any errors it will tell on startup what file and line numbers that have issues.

No other settings are needed. Create a devd rule configuration file in the proper location and restart devd.
I just tried this but something doesn't work.

Where should I look?

cat usb_tethering.conf:-
Code:
notify 20 {
        match "system"          "ETHERNET";
        match "type"            "IFATTACH";
        match "subsystem"       "ue[0-9}+";
        action "/sbin/dhclient $subsystem";
};
 
Do you see parsing usb_tethering.conf ?

# service devd stop && devd -d
Code:
Stopping devd.
Waiting for PIDS: 64207.
Parsing /etc/devd.conf
setting wifi-driver-regex=(ath|ath[0-9]+k|bwi|bwn|ipw|iwlwifi|iwi|iwm|iwn|malo|mwl|mt79|mtw|otus|ral|rsu|rtw|rtwn|rum|run|uath|upgt|ural|urtw|wpi|wtap|zyd)[0-9]+
Parsing files in /etc/devd
Parsing /etc/devd/syscons.conf
Parsing /etc/devd/uath.conf
Parsing /etc/devd/power_profile.conf
Parsing /etc/devd/zfs.conf
Parsing /etc/devd/snd.conf
Parsing /etc/devd/devmatch.conf
Parsing /etc/devd/dhclient.conf
Parsing /etc/devd/iwmbtfw.conf
Parsing /etc/devd/asus.conf
Parsing /etc/devd/nvmf.conf
Parsing /etc/devd/moused.conf
Parsing /etc/devd/autofs.conf
Parsing /etc/devd/hyperv.conf
Parsing /etc/devd/rtlbtfw.conf
Parsing /etc/devd/ulpt.conf
Parsing /etc/devd/bluetooth.conf
Parsing files in /usr/local/etc/devd
Parsing /usr/local/etc/devd/automount_devd.conf
Parsing /usr/local/etc/devd/cups.conf
Parsing /usr/local/etc/devd/usb_tethering.conf

Am I correct in thinking that after inserting a USB cable into my smartphone and selecting Tethering USB, this should automatically run dhclient ue0 ?

Can I output a message as part of the 'action' line ?
 
Am I correct in thinking that after inserting a USB cable into my smartphone and selecting Tethering USB, this should automatically run dhclient ue0 ?
Yes I would assume so. This is how it works on my USB Ethernet device:
Code:
Processing event '+axge0 at bus=0 hubaddr=1 port=18 devaddr=4 interface=0 ugen=ugen0.4 vendor=0x0b95 product=0x1790 devclass=0x00 devsubclass=0x00 devproto=0x00 sernum="00C70A20" release=0x0200 mode=host intclass=0xff intsubclass=0xff intprotocol=0x00 on uhub0'
Pushing table
setting *=+axge0 at bus=0 hubaddr=1 port=18 devaddr=4 interface=0 ugen=ugen0.4 vendor=0x0b95 product=0x1790 devclass=0x00 devsubclass=0x00 devproto=0x00 sernum="00C70A20" release=0x0200 mode=host intclass=0xff intsubclass=0xff intprotocol=0x00 on uhub0
setting _=axge0 at bus=0 hubaddr=1 port=18 devaddr=4 interface=0 ugen=ugen0.4 vendor=0x0b95 product=0x1790 devclass=0x00 devsubclass=0x00 devproto=0x00 sernum="00C70A20" release=0x0200 mode=host intclass=0xff intsubclass=0xff intprotocol=0x00 on uhub0
setting timestamp=1782256833.683211
setting vm_guest=none
setting device-name=axge0
setting bus=0
setting hubaddr=1
setting port=18
setting devaddr=4
setting interface=0
setting ugen=ugen0.4
setting vendor=0x0b95
setting product=0x1790
setting devclass=0x00
setting devsubclass=0x00
setting devproto=0x00
setting sernum=00C70A20
setting release=0x0200
setting mode=host
setting intclass=0xff
setting intsubclass=0xff
setting intprotocol=0x00
setting bus=uhub0
Processing attach event
Testing device-name=axge0 against ^ed50$, invert=0
Testing device-name=axge0 against ^ukbd0$, invert=0
Testing device-name=axge0 against ^ubt[0-9]+$, invert=0
Testing device-name=axge0 against ^(ath|ath[0-9]+k|bwi|bwn|ipw|iwlwifi|iwi|iwm|iwn|malo|mwl|mt79|otus|ral|rsu|rtw|rtwn|rum|run|uath|upgt|ural|urtw|wpi|wtap|zyd)[0-9]+$, invert=0
Popping table
 
what about a devd.conf

Code:
/usr/local/etc/devd.conf

this is what i use for my keyboard

i guess you could do the same thing to run dhclient ue0


Code:
#=========================================================================#
# devd.conf
#=========================================================================#

#=========================================================================#
# ducky one 2 mini
#=========================================================================#

attach 100 {
        device-name "uhid[0-9]+";                                                          
        match "vendor"  "0x0416"; # (1)
        match "product" "0x0123"; # (2)

    #
    # Do not add -d flag ! if you do it devd will never detach to background
    # because usbhidaction will run in foreground !
    #
    # Remember you can add arguments after /etc/usbhidaction.conf like
    # action "/usr/bin/usbhidaction -f $device-name -c /etc/usbhidaction.conf /dev/mixer1 2"
    #
        action "/usr/bin/usbhidaction -f $device-name -c /usr/local/etc/usbhidaction.conf";
};

Enabling Tethering USB on my smartphone results in this addition in usbconfig:-

ugen0.2: <Mi/Redmi series (RNDIS) Xiaomi Inc.> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (500mA)

in lsusb:-

Bus /dev/usb Device /dev/ugen0.2: ID 2717:ff80 Xiaomi Inc. Mi/Redmi series (RNDIS)

so the action I want to achieve would be

/usr/bin/dhclient ue0

What are the other required parameters?

And should the block start with

attach 100 {

?
 
yes the block should start with attach 100 {
thats the priority for the rule

here how i match my mic and set the volume

Code:
attach 100 {
    match "device-name" "pcm3";
    action "mixer -f /dev/mixer3 mic.volume=1.0";
};
 
Not sure what the device name should be, but once I work it out, should this work?

Code:
attach 100 {

    match "device-name" ????????";

    action "/sbin/dhclient ue0";

};
 
I'm almost there with this:

Code:
attach 100 {

    match "device-name" "urndis0";

    action "/sbin/dhclient ue0";

};

Initially when inserting the cable into the phone the new device is ugen0.2. urndis0 gets added when I enable Tehering USB. I don't know if there is something like a devd configuration for Android so I doubt whether is an option for enabling it automaticlly.

The only thing that I'm unclear about is when to stop/start/restart devd.
Do I need something like a devd_enable=YES in rc.conf?
 
hi mate

you dont need devd_enable=YES in rc.conf
its enabled by default

Code:
attach 100 {

    match "device-name" "urndis0";

    action "/sbin/dhclient ue0";

};

you seem to have to different device names
urndis0 and ue0

i maybe wrong
but i would have thought you should do something like this

Code:
attach 100 {
    match "device-name" "ue0";
    action "/sbin/dhclient ue0";
};
 
i dont see why not

i suppose you would have to do the same thing
using whatever the ifconfig interface name is created from the pc

then just use the interface name like you did with the previous code
and you can add it to the same file
 
Back
Top