# how to set "usbconfig set_config 1" at boot?



## da1 (Jan 15, 2019)

12.0-RELEASE and I'm struggling to find a way to do `usbconfig set_config 1` at boot. Besides having a script that runs every time the servers comes up, what's the proper way of doing this?


----------



## SirDice (Jan 15, 2019)

Why exactly do you need it?

Usually /etc/rc.local works for situations like this. But there might be better solutions (devd(8) for example) depending on what the command is for.


----------



## da1 (Jan 15, 2019)

I have this:


```
ugen1.4: <TP-LINK USB 10/100 LAN> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (100mA)

  bLength = 0x0012 
  bDescriptorType = 0x0001 
  bcdUSB = 0x0210 
  bDeviceClass = 0x0000  <Probed by interface class>
  bDeviceSubClass = 0x0000 
  bDeviceProtocol = 0x0000 
  bMaxPacketSize0 = 0x0040 
  idVendor = 0x2357 
  idProduct = 0x0602 
  bcdDevice = 0x2000 
  iManufacturer = 0x0001  <TP-LINK>
  iProduct = 0x0002  <USB 10/100 LAN>
  iSerialNumber = 0x0003  <503EAAACB692>
  bNumConfigurations = 0x0002
```

that needs `set_config 1`.

I tried devd with:

```
notify 100 {
        match "system"          "USB";
        match "subsystem"       "DEVICE";
        match "type"            "ATTACH";
        match "vendor"          "0x2357";
        match "product"          "0x0602";
        action "usbconfig -d $cdev set_config 1";
};
```
but it only works when attaching, not when the device is already attached and I reboot the server.

I guess I can stick with /etc/rc.local but I just wanted to know if there's a proper way of handling this situation


----------



## SirDice (Jan 15, 2019)

da1 said:


> but it only works when attaching, not when the device is already attached and I reboot the server.


The attaching is done during boot, and the setting is fairly specific to this USB device, so that should be the best place for it.

The issue with rc.local is that it's only executed during boot. If you later on remove and reinsert the device rc.local will not get executed.


----------



## lambert (Sep 6, 2019)

In my setup the following devd config works:


```
#action for Lenovo Thinkpad USB LAN adapter
notify 100 {
    match "system"        "USB";
    match "subsystem"    "DEVICE";
    match "type"        "ATTACH";
        match "vendor"          "0x17ef";
        match "product"         "0x7205";
        action "/usr/sbin/usbconfig -d $ugen set_config 1";
};
```

I found out that the action command should use $ugen instead of $cdev.


----------

