Solved [Solved] create unique /dev name for specific device

Dear all,

I am trying to configure devd(8) or devfs(8) rules to always create a specific /dev name for a couple of devices (gamepads/game controllers). I would like for them to always have the same /dev name that way one is not picked up instead of the other if I have them both plugged in. Is this possible? The order seems to vary depending on which order I plug then in as. They are either ugen0.2 or ugen0.3. The names don't matter to me, but it would be very nice to have them setup in a way that I can use them both in the same program by switching between them, as some tasks are easier done with one vs the other. Or perhaps be able to have it set up so that 2 people can use them in the same program as two different controllers, like in a game. However, currently with them switching between the two /dev names/links I have to remove them or be very careful in which order they get plugged in as.

I have hit Google, and even found a few forum threads that I thought would be helpful including:
http://forums.freebsd.org/viewtopic.php?f=39&t=18454
https://forums.freebsd.org/viewtopic.php?t=31551

But seeing as I do not have xf86-input-joystick installed and everything seems to work perfectly, except for the naming, I would like to find an alternative since some of the programs I run that I would like to use them with without worrying about the order use only SDL and other libraries and run from the console (without requiring xorg to run).

I have tried creating configurations for devd(8) but it never seems to work quite right.

The output of lsusb tells me that one of the devices have vendor ID of 0x0079 and product ID of 0x0006. I was unable to find the serial number.

Any help on this would be very appreciated.
Sincerely,
pauline123
 
Re: create unique /dev name for specific device

Okay, I just tried this in /usr/local/etc/devd/controllers.conf:

Code:
#0079:0006
# WB
# link Epson R200 printer to /dev/ulpt-r200 and unlpt-r200
attach 20 {
#        device-name "ulpt[0-9]";
        match "vendor" "0x0079";
        match "product" "0x0006";
        action "ln -sf /dev/$device-name /dev/controller1";
#        action "ln -sf /dev/`echo $device-name \
#                | sed -e 's/ulpt/unlpt/'` /dev/unlpt-r200";
#        action "chmod g+w /dev/ulpt-r200 /dev/unlpt-r200";
};

# WB
detach 20 {
        device-name "ugen[0-9].[0-9]";
        match "vendor" "0x0079";
        match "product" "0x0006";
        action "rm -f /dev/controller1";
};

Maybe I commented too much out, but how I understood it was that just using sed and creating a second link (which I don't need) I just need the one, right? And the chmod portion was because it was a printer, so I commented it out too.

Is that wrong?

However when I reboot to make sure that it goes into effect it does indeed create the two links (one for each controller) but the two controllers/gamepads will still swap places if plugged in in the wrong order, at least in my test program: snes9x-gtk. If plugged in in the correct order it does seem to work 100% of the time. Is this the best that can be achieved?
 
Re: create unique /dev name for specific device

If both the devices have the same vendor and product IDs, that rule will detect either. Ideally, there would be a difference between the two. Maybe a built-in serial number? Use usbconfig -d 0.4 dump_device_desc on each, replacing the 0.4 appropriately. If they are identical, the only thing that comes to mind is leaving one unplugged, so the one that's always connected will always be found first.
 
Re: create unique /dev name for specific device

They are two totally different vendor IDs and product IDs and if I use usbconfig -d 0.4 dump_device_desc on each both report a blank string as the serial number 0x0000. Either way, I guess this is a mute point since I have just now found out that one of them is broken and will need to be replaced or I will just manage with the one that I have. Thanks for reading and helping.
 
Re: create unique /dev name for specific device

When the vendor or product IDs are different, create two entries in the config file.
 
Re: create unique /dev name for specific device

I think I had tried that... but with one of them being broken, I am down to just the one. That being so I am either stuck as is for now or trying it with a broken gamepad (which seems a bit silly). Thank you for your help. Should I mark this as solved?
 
Re: create unique /dev name for specific device

As long as the devices are both detected, that part should be testable. I would not mark the thread solved unless the solution has been tested.
 
Re: create unique /dev name for specific device

Serials are both empty. I do not know what else I can put in the config file, to make it work. However, if there is anything else that could be of assistance let me know and I will try it out. At least, until I get tired of having the broken one around and get rid of it. Testing it might be of some value to someone, possibly even myself later.
 
Re: create unique /dev name for specific device

You already said the vendor and product IDs were different. Create one rule for the first vendor/product ID pair, and another for the second.
 
Re: create unique /dev name for specific device

I have two files in /usr/local/etc/devd/.
In one file I have:
Code:
#0079:0006
attach 20 {
        match "vendor" "0x0079";
        match "product" "0x0006";
        action "ln -sf /dev/$device-name /dev/controller1";
};

detach 20 {
        device-name "ugen[0-9].[0-9]";
        match "vendor" "0x0079";
        match "product" "0x0006";
        action "rm -rf /dev/controller1";
};
And in the second file I have:
Code:
#124b:4d01
attach 20 {
        match "vendor" "0x124b";
        match "product" "0x4d01";
        action "ln -sf /dev/$device-name /dev/controller2";
};


detach 20 {
        device-name "ugen[0-9].[0-9]";
        match "vendor" "0x124b";
        match "product" "0x4d01";
        action "rm -rf /dev/controller2";
};
But they continue to swap back and forth between each other. If it is any help I am running 10.0-RELEASE on an amd64 machine.
 
Re: create unique /dev name for specific device

They don't need to be in two different files. With the devices have different IDs, I don't see how devd(8) could assign the wrong names. It may be useful to run it in the foreground with devd -d to see what happens when the devices are connected.
 
Re: create unique /dev name for specific device

When I try to run devd -d it always says that the device is busy and stops before I get to plug the controllers in. I have also tried various versions of devd stop and it always refuses to stop with the same message that the device is busy. I have rebooted my computer and logged in as the root account, tried it while using su in an x-session and at the console without an x-session running.
 
Re: create unique /dev name for specific device

Kill the running version before trying to start it with debugging: service devd stop && devd -d
 
Re: create unique /dev name for specific device

Okay, well now I feel dumb. It works correctly with devd. I don't know if I was mistaken and/or misunderstanding what was going on or if the little edit I made to the configuration files made a difference. Either way, devd works correctly, but the applications still switches between them. I am so confused on how to fix that, but the problem that resulted in this thread is solved. Now if I can just determine the issue with the applications, but that would be application specific and have nothing to do with devd, correct?
 
Re: create unique /dev name for specific device

pauline123 said:
Now if I can just determine the issue with the applications, but that would be application specific and have nothing to do with devd, correct?

Correct.
 
Back
Top