Tuesday, August 11, 2009

CM19a USB Permissions

A typical user in Linux does not have sufficient privileges to read/write to the CM19a USB device without the appropriate driver installed with the correct permissions. Since I am writing a User Space driver in Python I need a way to read/write to the device without having to run the script/programme as thee root user.

The following notes show how I have set up udev rules to automatically set the correct permissions on system start or hot pluggin the CM19a.

1. Create the udev rules file:

gksudo gedit /etc/udev/rules.d/40-cm19a.rules

Note:
  • This uses gedit text editor in Ubuntu. You can create the text file any way you like.
  • The '''40''' is the priority/order for the rule relative to other rules found in /etc/udev/rules.d (user rules) and /lib/udev/rules.d (system/package rules etc)

2. Add the rules
These rules says that for a device with the specific vendor and product id, enable read/write access to any user who is a member of the '''cm19a-users''' groups


# Sets user permissions for the CM19a X10 US Wireless Transceiver
# Users who are members of the cm19a-users group have read and write access to this device
# Note that the vendor and product IDs are hexadecimal values
# Vendor id = 3015 (decimal), 0bc7(hex), X10 Wireless Technology Inc
# Product id = 2 (decimal), 0002 (hex), USB Transceiver

# Skip these rules if a usb device is not being added
SUBSYSTEM!="usb_device", ACTION!="add", GOTO="end_of_cm19a_rules"

SYSFS{idVendor}=="0bc7", SYSFS{idProduct}=="0002", MODE:="0660", GROUP:="cm19a-users"

LABEL="end_of_cm19a_rules"


3. Restart the server/pc to ensure to permissions take hold.
(Just re-plugging the device does not seem to work correctly)

4. Check that the CM19a has been detected

lsusb

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 002: ID 046d:c517 Logitech, Inc. LX710 Cordless Desktop Laser
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 003: ID 0bc7:0002 X10 Wireless Technology, Inc. Firecracker Interface (ACPI-compliant)
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 045e:00f5 Microsoft Corp. LifeCam VX-3000.
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub


5. Check the group ownership

ls -la /dev/bus/usb/004/

total 0
drwxr-xr-x 2 root root 80 2009-08-11 11:22 .
drwxr-xr-x 7 root root 140 2009-08-11 18:20 ..
crw-rw-r-- 1 root root 189, 384 2009-08-11 18:20 001
crw-rw---- 1 root cm19a-users 189, 387 2009-08-11 11:22 003


Notes:
* 004 in the ls command is the bus number where lsusb found the device
* The ls command lists the devices found on that bus
* The Cm19a is device number 003 on bus 004
* Owner is root with permissions: create, read, write
* Group is cm19a-users with permissions: read, write
* The World has no permissions at all

6. Add any users who need to access the CM19a to the cm19a-users group.

7. Now your users have read/write access to the device

0 comments:

Post a Comment

Recent Comments