コード例 #1
0
ファイル: mbm_manager.c プロジェクト: idaohang/mbm-gpsd-1
static char *find_device_file (int capability)
{
	struct udev *udev;
	struct udev_enumerate *enumerate;
	struct udev_list_entry *devices, *dev_list_entry;
	struct udev_device *dev;
	const char *path;
	char *device = NULL;

	udev = udev_new();
	if (!udev) return NULL;

	enumerate = udev_enumerate_new(udev);
	udev_enumerate_add_match_property(enumerate, "MBM_CAPABILITY",
									  gps_capabilities[capability]);
	udev_enumerate_scan_devices(enumerate);

	devices = udev_enumerate_get_list_entry(enumerate);
	udev_list_entry_foreach(dev_list_entry, devices) {
		path = udev_list_entry_get_name(dev_list_entry);
		dev = udev_device_new_from_syspath(udev, path);
		if (!udev_device_get_devnode(dev))
			continue;
		device = strdup(udev_device_get_devnode(dev));
		udev_device_unref (dev);
		if (mbm_options_debug ()) {
			g_debug ("found device %s for capability %s",
					 device, gps_capabilities[capability]);
		}
		/*
		 * the code returns the first matching device found
		 */
		break;
	}
コード例 #2
0
void joystick_linux::enumerate_joysticks(udev *p_udev) {

	udev_enumerate *enumerate;
	udev_list_entry *devices, *dev_list_entry;
	udev_device *dev;

	enumerate = udev_enumerate_new(p_udev);
	udev_enumerate_add_match_subsystem(enumerate,"input");
	udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYSTICK", "1");

	udev_enumerate_scan_devices(enumerate);
	devices = udev_enumerate_get_list_entry(enumerate);
	udev_list_entry_foreach(dev_list_entry, devices) {

		const char* path = udev_list_entry_get_name(dev_list_entry);
		dev = udev_device_new_from_syspath(p_udev, path);
		const char* devnode = udev_device_get_devnode(dev);

		if (devnode) {

			String devnode_str = devnode;
			if (devnode_str.find(ignore_str) == -1) {
				joy_mutex->lock();
				open_joystick(devnode);
				joy_mutex->unlock();
			}
		}
		udev_device_unref(dev);
	}
	udev_enumerate_unref(enumerate);
}
コード例 #3
0
ファイル: libudev.c プロジェクト: flyingoctopus/serialosc
int scan_connected_devices(detector_state_t *state) {
	struct udev_list_entry *cursor;
	struct udev_enumerate *ue;
	struct udev_device *ud;

	const char *devnode = NULL;

	if( !(ue = udev_enumerate_new(state->u)) )
		return 1;

	udev_enumerate_add_match_subsystem(ue, "tty");
	udev_enumerate_add_match_property(ue, "ID_BUS", "usb");
	udev_enumerate_scan_devices(ue);
	cursor = udev_enumerate_get_list_entry(ue);

	do {
		ud = udev_device_new_from_syspath(
			state->u, udev_list_entry_get_name(cursor));

		if( (devnode = udev_device_get_devnode(ud)) )
			spawn_server(state->exec_path, devnode);

		udev_device_unref(ud);
	} while( (cursor = udev_list_entry_get_next(cursor)) );

	udev_enumerate_unref(ue);
	return 0;
}
コード例 #4
0
ファイル: urf-utils.c プロジェクト: fishman/urfkill
/**
 * get_rfkill_device_by_index:
 **/
struct udev_device *
get_rfkill_device_by_index (struct udev *udev,
			    guint        index)
{
	struct udev_enumerate *enumerate;
	struct udev_list_entry *devices;
	struct udev_list_entry *dev_list_entry;
	struct udev_device *dev;

	enumerate = udev_enumerate_new(udev);
	udev_enumerate_add_match_subsystem(enumerate, "rfkill");
	udev_enumerate_scan_devices(enumerate);
	devices = udev_enumerate_get_list_entry(enumerate);

	udev_list_entry_foreach(dev_list_entry, devices) {
		const char *path, *index_c;
		path = udev_list_entry_get_name(dev_list_entry);
		dev = udev_device_new_from_syspath(udev, path);

		index_c = udev_device_get_sysattr_value (dev, "index");
		if (index_c && atoi(index_c) == index)
			break;

		udev_device_unref (dev);
		dev = NULL;
	}

	return dev;
}
コード例 #5
0
ファイル: test-network.c プロジェクト: AlexBaranosky/systemd
int main(void) {
        _cleanup_manager_free_ Manager *manager = NULL;
        struct udev *udev;
        struct udev_device *loopback;
        int r;

        test_deserialize_in_addr();
        test_deserialize_dhcp_routes();
        test_address_equality();

        assert_se(manager_new(&manager) >= 0);

        r = test_load_config(manager);
        if (r == -EPERM)
                return EXIT_TEST_SKIP;

        udev = udev_new();
        assert_se(udev);

        loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
        assert_se(loopback);
        assert_se(udev_device_get_ifindex(loopback) == 1);

        test_network_get(manager, loopback);

        assert_se(manager_rtnl_enumerate_links(manager) >= 0);

        udev_device_unref(loopback);
        udev_unref(udev);
}
コード例 #6
0
ファイル: usbeject.c プロジェクト: x2b/usbeject
static int usb_unmount_dev(const char *devname, struct udev *udev)
{
  struct udev_enumerate *enumerate;
  struct udev_list_entry *dev_list, *dev_list_entry;
  struct udev_device *device = NULL, *parent_device = NULL;
  int device_found = 0;
  int retval = 0;
  FILE *remfile = NULL;
  struct stat buf;


  enumerate = udev_enumerate_new(udev);
  udev_enumerate_add_match_subsystem(enumerate, "block");
  udev_enumerate_scan_devices(enumerate);
  dev_list = udev_enumerate_get_list_entry(enumerate);

  udev_list_entry_foreach(dev_list_entry, dev_list)
  {
    device = udev_device_new_from_syspath(udev,
                                          udev_list_entry_get_name(dev_list_entry));

    if(!strcmp(udev_device_get_devnode(device), devname))
    {
      device_found = 1;
      break;
    }
    else
    {
      udev_device_unref(device);
      device = NULL;
    }
  }
コード例 #7
0
ファイル: Gamepad.cpp プロジェクト: dakerfp/drowser
GamepadController::GamepadController()
    : m_gamepadDevices(Nix::Gamepads::itemsLengthCap)
{
    m_udev = udev_new();
    m_gamepadsMonitor = udev_monitor_new_from_netlink(m_udev, "udev");

    udev_monitor_enable_receiving(m_gamepadsMonitor);
    udev_monitor_filter_add_match_subsystem_devtype(m_gamepadsMonitor, "input", 0);

    GIOChannel *channel = g_io_channel_unix_new(udev_monitor_get_fd(m_gamepadsMonitor));
    g_io_add_watch(channel, GIOCondition(G_IO_IN), static_cast<GIOFunc>(&GamepadController::onGamepadChange), this);
    g_io_channel_unref(channel);

    struct udev_enumerate* enumerate = udev_enumerate_new(m_udev);
    udev_enumerate_add_match_subsystem(enumerate, "input");
    udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYSTICK", "1");
    udev_enumerate_scan_devices(enumerate);
    struct udev_list_entry* cur;
    struct udev_list_entry* devs = udev_enumerate_get_list_entry(enumerate);
    udev_list_entry_foreach(cur, devs)
    {
        const char* devname = udev_list_entry_get_name(cur);
        struct udev_device* device = udev_device_new_from_syspath(m_udev, devname);
        if (isGamepadDevice(device))
            registerDevice(udev_device_get_devnode(device));
        udev_device_unref(device);
    }
    udev_enumerate_unref(enumerate);
}
コード例 #8
0
int main(void) {
        _cleanup_manager_free_ Manager *manager = NULL;
        struct udev *udev;
        struct udev_device *loopback;

        assert_se(manager_new(&manager) >= 0);

        test_load_config(manager);

        udev = udev_new();
        assert_se(udev);

        loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
        assert_se(loopback);
        assert_se(udev_device_get_ifindex(loopback) == 1);

        test_network_get(manager, loopback);

        test_link(manager, loopback);

        assert_se(manager_udev_listen(manager) >= 0);
        assert_se(manager_udev_enumerate_links(manager) >= 0);
        assert_se(manager_rtnl_listen(manager) >= 0);

        udev_device_unref(loopback);
        udev_unref(udev);
}
コード例 #9
0
ファイル: usb.c プロジェクト: seec/TL866
int get_device_count()
{
    struct udev *udev = udev_new();
    if (!udev)
    {
        return -1;
    }

    struct udev_enumerate *enumerate;
    struct udev_list_entry *devices, *dev_list_entry;
    struct udev_device *dev;

    enumerate = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerate, "usb");
    udev_enumerate_scan_devices(enumerate);
    devices = udev_enumerate_get_list_entry(enumerate);
    const char *path;
    int count = 0;
    udev_list_entry_foreach(dev_list_entry, devices)
    {

        path = udev_list_entry_get_name(dev_list_entry);
        dev = udev_device_new_from_syspath(udev, path);
        if(!dev)
            return -1;

        const char * vid = udev_device_get_sysattr_value(dev,"idVendor");
        const char * pid = udev_device_get_sysattr_value(dev,"idProduct");
        if((vid && pid) && (!strcmp(vid, "04d8") && (!strcmp(pid, "e11c"))))
            count++;
        udev_device_unref(dev);
    }
コード例 #10
0
ファイル: wgbm_display.c プロジェクト: Sonicadvance1/waffle
int
wgbm_get_default_fd_for_pattern(const char *pattern)
{
    struct udev *ud;
    struct udev_enumerate *en;
    struct udev_list_entry *devices, *entry;
    const char *path, *filename;
    struct udev_device *device;
    int fd;

    ud = udev_new();
    en = udev_enumerate_new(ud);
    udev_enumerate_add_match_subsystem(en, "drm");
    udev_enumerate_add_match_sysname(en, pattern);
    udev_enumerate_scan_devices(en);
    devices = udev_enumerate_get_list_entry(en);

    udev_list_entry_foreach(entry, devices) {
        path = udev_list_entry_get_name(entry);
        device = udev_device_new_from_syspath(ud, path);
        filename = udev_device_get_devnode(device);
        fd = open(filename, O_RDWR | O_CLOEXEC);
        udev_device_unref(device);
        if (fd >= 0) {
            udev_enumerate_unref(en);
            udev_unref(ud);
            return fd;
        }
    }
コード例 #11
0
ファイル: renderer.cpp プロジェクト: jrjeojst/WinlabEEG
bool Renderer::connectEmotiv()
{
   /* Opens Emotiv if Emotiv is only HID Device attached */
  struct udev_device *dev;
  struct udev *udev;
  struct udev_list_entry *devices, *dev_list_entry;
  struct udev_enumerate *enumerate;
  udev = udev_new();
  enumerate = udev_enumerate_new(udev);
  udev_enumerate_add_match_subsystem(enumerate, "hidraw");
  udev_enumerate_scan_devices(enumerate);
  devices = udev_enumerate_get_list_entry(enumerate);
  udev_list_entry_foreach(dev_list_entry, devices) 
    {
      const char * path = udev_list_entry_get_name(dev_list_entry);
      dev = udev_device_new_from_syspath(udev,path);
    }
  emotiv_fd = open(udev_device_get_devnode(dev), O_RDONLY);
  if (emotiv_fd > 0) 
    {
      int res = read(emotiv_fd, emotivBuffer, 32);
      if(res < 0) {perror("read"); return false;}
      return true;
    }
  else 
    {
      perror("Unable to open device");
      return false;
    }
}
コード例 #12
0
ファイル: setbacklight.c プロジェクト: ChristophHaag/weston
int
main(int argc, char **argv)
{
	int blight, connector_id;
	const char *path;
	struct udev *udev;
	struct udev_enumerate *e;
	struct udev_list_entry *entry;
	struct udev_device *drm_device;

	if (argc < 3) {
		printf("Please add connector_id and brightness values from 0-255\n");
		return 1;
	}

	connector_id = atoi(argv[1]);
	blight = atoi(argv[2]);

	udev = udev_new();
	if (udev == NULL) {
		printf("failed to initialize udev context\n");
		return 1;
	}

	e = udev_enumerate_new(udev);
	udev_enumerate_add_match_subsystem(e, "drm");
	udev_enumerate_add_match_sysname(e, "card[0-9]*");

	udev_enumerate_scan_devices(e);
	drm_device = NULL;
	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
		path = udev_list_entry_get_name(entry);
		drm_device = udev_device_new_from_syspath(udev, path);
		break;
	}
コード例 #13
0
ファイル: udevadm-util.c プロジェクト: halfline/systemd
struct udev_device *find_device(const char *id,
                                const char *prefix) {

        assert(id);

        if (prefix && !startswith(id, prefix))
                id = strjoina(prefix, id);

        if (path_startswith(id, "/dev/")) {
                struct stat statbuf;
                char type;

                if (stat(id, &statbuf) < 0)
                        return NULL;

                if (S_ISBLK(statbuf.st_mode))
                        type = 'b';
                else if (S_ISCHR(statbuf.st_mode))
                        type = 'c';
                else
                        return NULL;

                return udev_device_new_from_devnum(NULL, type, statbuf.st_rdev);
        } else if (path_startswith(id, "/sys/"))
                return udev_device_new_from_syspath(NULL, id);
        else
                return NULL;
}
コード例 #14
0
ファイル: udev-seat.c プロジェクト: bpeel/weston
static int
udev_input_add_devices(struct udev_input *input, struct udev *udev)
{
	struct udev_enumerate *e;
	struct udev_list_entry *entry;
	struct udev_device *device;
	const char *path, *sysname;
	struct udev_seat *seat;
	int devices_found = 0;

	e = udev_enumerate_new(udev);
	udev_enumerate_add_match_subsystem(e, "input");
	udev_enumerate_scan_devices(e);
	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
		path = udev_list_entry_get_name(entry);
		device = udev_device_new_from_syspath(udev, path);

		sysname = udev_device_get_sysname(device);
		if (strncmp("event", sysname, 5) != 0) {
			udev_device_unref(device);
			continue;
		}

		if (device_added(device, input) < 0) {
			udev_device_unref(device);
			udev_enumerate_unref(e);
			return -1;
		}

		udev_device_unref(device);
	}
コード例 #15
0
eErrorCode GetAdapterBus(DeviceHandle& Handle, String SysDevicePath)
{
    struct udev *udevObject;
    struct udev_device *udevDevice;

    udevObject = udev_new();
    if (nullptr == udevObject)
    {
        return(eErrorCode::Memory);
    }
    udevDevice = udev_device_new_from_syspath(udevObject, SysDevicePath.c_str());

    if (true == IsAtaDeviceBus(udevDevice))
    {
        Handle.Bus = eBusType::Ata;
    }
    else if (true == IsScsiDeviceBus(udevDevice))
    {
        Handle.Bus = eBusType::Scsi;
    }
    else
    {
        //! Adapter Property is not Ata or Scsi
        return(eErrorCode::FormatNotSupported);
    }

    udev_device_unref(udevDevice);
    udev_unref(udevObject);

    return(eErrorCode::None);
}
コード例 #16
0
ファイル: udev-acl.c プロジェクト: SaschaMester/devuan-udev
/* add or remove a ACL for a given uid from all matching devices */
static void apply_acl_to_devices(uid_t uid, int add)
{
	struct udev *udev;
	struct udev_enumerate *enumerate;
	struct udev_list_entry *list_entry;

	/* iterate over all devices tagged with ACL_SET */
	udev = udev_new();
	enumerate = udev_enumerate_new(udev);
	udev_enumerate_add_match_tag(enumerate, "udev-acl");
	udev_enumerate_scan_devices(enumerate);
	udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
		struct udev_device *device;
		const char *node;

		device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
						      udev_list_entry_get_name(list_entry));
		if (device == NULL)
			continue;
		node = udev_device_get_devnode(device);
		if (node == NULL) {
			udev_device_unref(device);
			continue;
		}
		set_facl(node, uid, add);
		udev_device_unref(device);
	}
	udev_enumerate_unref(enumerate);
	udev_unref(udev);
}
コード例 #17
0
ファイル: udev_subsystem.cpp プロジェクト: brojudd/ubuntu
void
UdevSubsystem::enumerate_udev_devices()
{
  assert(m_process_match_cb);

  // Enumerate over all devices already connected to the computer
  struct udev_enumerate* enumerate = udev_enumerate_new(m_udev);
  assert(enumerate);

  udev_enumerate_add_match_subsystem(enumerate, "usb");
  // not available yet: udev_enumerate_add_match_is_initialized(enumerate);
  udev_enumerate_scan_devices(enumerate);

  struct udev_list_entry* devices;
  struct udev_list_entry* dev_list_entry;

  devices = udev_enumerate_get_list_entry(enumerate);
  udev_list_entry_foreach(dev_list_entry, devices)
  {
    // name is path, value is NULL
    const char* path = udev_list_entry_get_name(dev_list_entry);

    struct udev_device* device = udev_device_new_from_syspath(m_udev, path);

    // manually filter for devtype, as udev enumerate can't do it by itself
    const char* devtype = udev_device_get_devtype(device);
    if (devtype && strcmp(devtype, "usb_device") == 0)
    {
      m_process_match_cb(device);
    }
    udev_device_unref(device);
  }
  udev_enumerate_unref(enumerate);
}
コード例 #18
0
ファイル: usb_linux.c プロジェクト: TricksterGuy/ckb
void udevenum(){
    struct udev_enumerate* enumerator = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerator, "usb");
    udev_enumerate_add_match_sysattr(enumerator, "idVendor", V_CORSAIR_STR);
    udev_enumerate_scan_devices(enumerator);
    struct udev_list_entry* devices, *dev_list_entry;
    devices = udev_enumerate_get_list_entry(enumerator);

    udev_list_entry_foreach(dev_list_entry, devices){
        const char* path = udev_list_entry_get_name(dev_list_entry);
        struct udev_device* dev = udev_device_new_from_syspath(udev, path);
        // If the device matches a recognized device ID, open it
        const char* product = udev_device_get_sysattr_value(dev, "idProduct");
        if(!strcmp(product, P_K70_STR)){
            pthread_mutex_lock(&kblistmutex);
            openusb(dev, 70);
            pthread_mutex_unlock(&kblistmutex);
            continue;
        }
        if(!strcmp(product, P_K95_STR)){
            pthread_mutex_lock(&kblistmutex);
            openusb(dev, 95);
            pthread_mutex_unlock(&kblistmutex);
            continue;
        }
        // Free the device if it wasn't used
        udev_device_unref(dev);
    }
    udev_enumerate_unref(enumerator);
}
コード例 #19
0
ファイル: umount.c プロジェクト: nazgul77/systemd
static int loopback_list_get(MountPoint **head) {
        _cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL;
        struct udev_list_entry *item = NULL, *first = NULL;
        _cleanup_udev_unref_ struct udev *udev = NULL;
        int r;

        assert(head);

        udev = udev_new();
        if (!udev)
                return -ENOMEM;

        e = udev_enumerate_new(udev);
        if (!e)
                return -ENOMEM;

        r = udev_enumerate_add_match_subsystem(e, "block");
        if (r < 0)
                return r;

        r = udev_enumerate_add_match_sysname(e, "loop*");
        if (r < 0)
                return r;

        r = udev_enumerate_add_match_sysattr(e, "loop/backing_file", NULL);
        if (r < 0)
                return r;

        r = udev_enumerate_scan_devices(e);
        if (r < 0)
                return r;

        first = udev_enumerate_get_list_entry(e);
        udev_list_entry_foreach(item, first) {
                MountPoint *lb;
                _cleanup_udev_device_unref_ struct udev_device *d;
                char *loop;
                const char *dn;

                d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
                if (!d)
                        return -ENOMEM;

                dn = udev_device_get_devnode(d);
                if (!dn)
                        continue;

                loop = strdup(dn);
                if (!loop)
                        return -ENOMEM;

                lb = new0(MountPoint, 1);
                if (!lb) {
                        free(loop);
                        return -ENOMEM;
                }

                lb->path = loop;
                LIST_PREPEND(mount_point, *head, lb);
        }
コード例 #20
0
QStringList QDeviceDiscovery::scanConnectedDevices()
{
    QStringList devices;

    if (!m_udev)
        return devices;

    udev_enumerate *ue = udev_enumerate_new(m_udev);
    udev_enumerate_add_match_subsystem(ue, "input");
    udev_enumerate_add_match_subsystem(ue, "drm");

    if (m_types & Device_Mouse)
        udev_enumerate_add_match_property(ue, "ID_INPUT_MOUSE", "1");
    if (m_types & Device_Touchpad)
        udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHPAD", "1");
    if (m_types & Device_Touchscreen)
        udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHSCREEN", "1");
    if (m_types & Device_Keyboard) {
        udev_enumerate_add_match_property(ue, "ID_INPUT_KEYBOARD", "1");
        udev_enumerate_add_match_property(ue, "ID_INPUT_KEY", "1");
    }
    if (m_types & Device_Tablet)
        udev_enumerate_add_match_property(ue, "ID_INPUT_TABLET", "1");

    if (udev_enumerate_scan_devices(ue) != 0) {
#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG
        qWarning() << "UDeviceHelper scan connected devices for enumeration failed";
#endif
        return devices;
    }

    udev_list_entry *entry;
    udev_list_entry_foreach (entry, udev_enumerate_get_list_entry(ue)) {
        const char *syspath = udev_list_entry_get_name(entry);
        udev_device *udevice = udev_device_new_from_syspath(m_udev, syspath);
        QString candidate = QString::fromUtf8(udev_device_get_devnode(udevice));
        if ((m_types & Device_InputMask) && candidate.startsWith(QLatin1String(QT_EVDEV_DEVICE)))
            devices << candidate;
        if ((m_types & Device_VideoMask) && candidate.startsWith(QLatin1String(QT_DRM_DEVICE))) {
            if (m_types & Device_DRM_PrimaryGPU) {
                udev_device *pci = udev_device_get_parent_with_subsystem_devtype(udevice, "pci", 0);
                if (pci) {
                    if (qstrcmp(udev_device_get_sysattr_value(pci, "boot_vga"), "1") == 0)
                        devices << candidate;
                }
            } else
                devices << candidate;
        }

        udev_device_unref(udevice);
    }
    udev_enumerate_unref(ue);

#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG
    qWarning() << "UDeviceHelper found matching devices" << devices;
#endif

    return devices;
}
コード例 #21
0
ファイル: rwudev.c プロジェクト: RIFTIO/RIFT.ware
rw_status_t
rw_udev_register_cb(rw_udev_handle_t *handle,
                    void *userdata, rw_udev_cb_t cb)
{
  struct udev_enumerate *enumerate = NULL;
  struct udev_list_entry *devices, *dev_list_entry;
  int ret = -1;
  rw_status_t status = RW_STATUS_SUCCESS;
  rw_pci_address_t pci_addr;
  rw_pci_device_t *dev;
  struct udev_device *udevice;
  
  handle->cb = cb;
  handle->userdata = userdata;
  
  //walk throight he list and call the callback..
  enumerate = udev_enumerate_new(handle->udev);
  if (!enumerate){
    goto free_and_ret;
  }
  udev_enumerate_add_match_subsystem(enumerate, "net");
  udev_enumerate_scan_devices(enumerate);
  devices = udev_enumerate_get_list_entry(enumerate);
  udev_list_entry_foreach(dev_list_entry, devices) {
    const char *path;
    path = udev_list_entry_get_name(dev_list_entry);
    ret = rw_sys_populate_pci_from_path(path, &pci_addr);
    if (!ret){
      
    }else{
      udevice = udev_device_new_from_syspath(handle->udev, path);
      dev = rw_udev_insert_device(handle, &pci_addr);
      rw_udev_update_device(udevice, dev);
      if (dev){
        handle->cb(handle->userdata, dev, RW_UDEV_DEVICE_ADD);
      }
      udev_device_unref(udevice);
    }
  }
  
  handle->mon = udev_monitor_new_from_netlink(handle->udev, "udev");
  udev_monitor_filter_add_match_subsystem_devtype(handle->mon, "net", NULL);
  udev_monitor_enable_receiving(handle->mon);
  /* Get the file descriptor (fd) for the monitor.
     This fd will get passed to select() */
  handle->fd = udev_monitor_get_fd(handle->mon);

  
ret:
  return status;
  
free_and_ret:
  if (enumerate){
    udev_enumerate_unref(enumerate);
    enumerate = NULL;
  }
  status = RW_STATUS_FAILURE;
  goto ret;
}
コード例 #22
0
ファイル: QUdev_private.cpp プロジェクト: jpfeiffer/QUdev
QUdevDeviceList QUdevPrivate::getUDevDevicesForSubsystem(const QString &strSubSystem, const QString &strDeviceType, const QString &strParentSubSystem, const QString &strParentDeviceType)
{
    struct udev_enumerate *enumerate = udev_enumerate_new(m_pUdev);
    struct udev_list_entry *devices = 0;
    struct udev_list_entry *dev_list_entry = 0;
    struct udev_device *dev = 0;

    QList<QUdevDevice> lDevices;

    if(strSubSystem.isEmpty()) return lDevices;

    //get subsystem enumerator
    udev_enumerate_add_match_subsystem(enumerate, strSubSystem.toLatin1().constData());
    //perform sysfs scanning
    udev_enumerate_scan_devices(enumerate);
    devices = udev_enumerate_get_list_entry(enumerate);

    //iterate over all devices in the enumeration list
    udev_list_entry_foreach(dev_list_entry, devices)
    {
        QUdevDevice udDev;

        //create udev device for the sysfs path returned
        udDev.m_strSysfsPath = QString::fromLatin1(udev_list_entry_get_name(dev_list_entry));        
        dev = udev_device_new_from_syspath(m_pUdev, udDev.m_strSysfsPath.toLatin1().constData());

        //filter the correct device types, ignored if empty device type is specified
        if(strDeviceType.isEmpty() || (QString::fromLatin1(udev_device_get_devtype(dev)) == strDeviceType))
        {
            //get the path inside /dev
            udDev.m_strDevPath = QString::fromLatin1(udev_device_get_devnode(dev));
            udDev.m_strSubsystem = strSubSystem;
            udDev.m_strDeviceType = strDeviceType;

            //if the caller wants a specific parent subsystem/devtype query the sysfs tree here
            if(!strParentSubSystem.isEmpty() && !strParentDeviceType.isEmpty())
            {
                /*
                 * retrieve the parent device with the subsystem/devtype pair of m_strParentSubSystem/m_strParentDeviceType.
                 *
                 * udev_device_get_parent_with_subsystem_devtype() will walk up the complete tree if needed
                 */
                dev = udev_device_get_parent_with_subsystem_devtype(dev, strParentSubSystem.toLatin1().constData(), strParentDeviceType.toLatin1().constData());
            }

            if(dev)
            {
                //fill the device information
                udDev.m_strVendorID = QString::fromLatin1(udev_device_get_sysattr_value(dev,"idVendor"));
                udDev.m_strProductID = QString::fromLatin1(udev_device_get_sysattr_value(dev, "idProduct"));
                udDev.m_strManufacturer = QString::fromLatin1(udev_device_get_sysattr_value(dev,"manufacturer"));
                udDev.m_strProduct = QString::fromLatin1(udev_device_get_sysattr_value(dev,"product"));
                udDev.m_strSerial = QString::fromLatin1(udev_device_get_sysattr_value(dev, "serial"));
                lDevices.append(udDev);
            }

            udev_device_unref(dev);
        }
    }
コード例 #23
0
ファイル: interface_backend_udev.c プロジェクト: avdv/libvirt
static virInterfacePtr
udevInterfaceLookupByMACString(virConnectPtr conn, const char *macstr)
{
    struct udev_iface_driver *driverState = conn->interfacePrivateData;
    struct udev *udev = udev_ref(driverState->udev);
    struct udev_enumerate *enumerate = NULL;
    struct udev_list_entry *dev_entry;
    struct udev_device *dev;
    const char *name;
    virInterfacePtr ret = NULL;

    enumerate = udevGetDevices(udev, VIR_UDEV_IFACE_ALL);

    if (!enumerate) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("failed to lookup interface with MAC address '%s'"),
                       macstr);
        goto err;
    }

    /* Match on MAC */
    udev_enumerate_add_match_sysattr(enumerate, "address", macstr);

    /* Do the scan to load up the enumeration */
    udev_enumerate_scan_devices(enumerate);

    /* Get a list we can walk */
    dev_entry = udev_enumerate_get_list_entry(enumerate);

    /* Check that we got something back */
    if (!dev_entry) {
        virReportError(VIR_ERR_NO_INTERFACE,
                       _("couldn't find interface with MAC address '%s'"),
                       macstr);
        goto err;
    }

    /* Check that we didn't get multiple items back */
    if (udev_list_entry_get_next(dev_entry)) {
        virReportError(VIR_ERR_MULTIPLE_INTERFACES,
                       _("the MAC address '%s' matches multiple interfaces"),
                       macstr);
        goto err;
    }

    dev = udev_device_new_from_syspath(udev, udev_list_entry_get_name(dev_entry));
    name = udev_device_get_sysname(dev);
    ret = virGetInterface(conn, name, macstr);
    udev_device_unref(dev);

err:
    if (enumerate)
        udev_enumerate_unref(enumerate);
    udev_unref(udev);

    return ret;
}
コード例 #24
0
  /* 
     This implementation uses udev to retrieve capture devices.
     We support both udev and default v4l2 ways to retrieve 
     devices. Udev is not supported on all systems.

   */
  std::vector<V4L2_Device> v4l2_get_devices() {
    
    std::vector<V4L2_Device> result;
    struct udev* udev;
    struct udev_enumerate* enumerate;
    struct udev_list_entry* devices;
    struct udev_list_entry* dev_list_entry;
    struct udev_device* dev;
 
    udev = udev_new();
    if(!udev) {
      printf("Error: Cannot udev_new()\n");
      return result;
    }
 
    enumerate = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerate, "video4linux");
    udev_enumerate_scan_devices(enumerate);
    devices = udev_enumerate_get_list_entry(enumerate);

    udev_list_entry_foreach(dev_list_entry, devices) {

      /* Get the device by syspath. */
      const char* syspath = udev_list_entry_get_name(dev_list_entry);
      dev = udev_device_new_from_syspath(udev, syspath);

      if(!dev) {
        printf("Error: cannot get the device using the syspath: %s\n", syspath);
        continue;
      }

      V4L2_Device v4l2_device;
      v4l2_device.path = udev_device_get_devnode(dev);

      if(v4l2_device.path.size() == 0) {
        printf("Error: Cannot find devpath.\n");
        continue;
      }

      dev = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_device");

      if(!dev) {
        printf("Error:Cannot find related usb device.\n");
        continue;
      }

      v4l2_device.id_vendor = udev_device_get_sysattr_value(dev, "idVendor");
      v4l2_device.id_product = udev_device_get_sysattr_value(dev, "idProduct");

      result.push_back(v4l2_device);
    }

    udev_enumerate_unref(enumerate);
    udev_unref(udev);
    
    return result;
  }
コード例 #25
0
ファイル: input.c プロジェクト: vulcandth/moonlight-embedded
void input_init(char* mapfile) {
  #ifdef HAVE_LIBCEC
  init_cec();
  #endif

  udev = udev_new();
  if (!udev) {
    fprintf(stderr, "Can't create udev\n");
    exit(1);
  }

  autoadd = (numDevices == 0);
  if (autoadd) {
    struct udev_enumerate *enumerate = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerate, "input");
    udev_enumerate_scan_devices(enumerate);
    struct udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate);

    struct udev_list_entry *dev_list_entry;
    udev_list_entry_foreach(dev_list_entry, devices) {
      const char *path = udev_list_entry_get_name(dev_list_entry);
      struct udev_device *dev = udev_device_new_from_syspath(udev, path);
      const char *devnode = udev_device_get_devnode(dev);
      int id;
      if (devnode != NULL && sscanf(devnode, "/dev/input/event%d", &id) == 1) {
        input_create(devnode, mapfile);
      }
      udev_device_unref(dev);
    }

    udev_enumerate_unref(enumerate);
  }

  udev_mon = udev_monitor_new_from_netlink(udev, "udev");
  udev_monitor_filter_add_match_subsystem_devtype(udev_mon, "input", NULL);
  udev_monitor_enable_receiving(udev_mon);

  udev_fdindex = numFds++;
  sig_fdindex = numFds++;

  if (fds == NULL)
    fds = malloc(sizeof(struct pollfd)*numFds);
  else
    fds = realloc(fds, sizeof(struct pollfd)*numFds);

  if (fds == NULL) {
    fprintf(stderr, "Not enough memory\n");
    exit(EXIT_FAILURE);
  }

  defaultMapfile = mapfile;
  fds[udev_fdindex].fd = udev_monitor_get_fd(udev_mon);
  fds[udev_fdindex].events = POLLIN;

  main_thread_id = pthread_self();
}
コード例 #26
0
int get_usbinfo(int bus, int dev, usbinfo_t *ui)
{
  struct udev *udev;
  struct udev_enumerate *enumerate;
  struct udev_list_entry *devices, *dev_list_entry;
  struct udev_device *udev_dev;
  char bus_str[16], dev_str[16];
  int found = 0;

  memset(ui, 0, sizeof(usbinfo_t));

  /* construct xenstore dev id */
  if (dev > 0xFFF) {
    xd_log(LOG_ERR, "bad device id %d", dev);
    return -EINVAL;
  }

  ui->usb_virtid = bus << 12 | (dev & 0xFFF);
  ui->usb_bus = bus;
  ui->usb_device = dev;

  /* udev scan */
  udev = udev_new();
  if (!udev) {
    xd_log(LOG_ERR, "Can't create udev");
    return -ENOMEM;
  }
  enumerate = udev_enumerate_new(udev);
  if (!enumerate) {
    xd_log(LOG_ERR, "Can't create enumeration");
    return -ENOMEM;
  }

  snprintf(bus_str, sizeof(bus_str), "%d", bus);
  snprintf(dev_str, sizeof(dev_str), "%d", dev);

  udev_enumerate_add_match_subsystem(enumerate, "usb");
  udev_enumerate_add_match_sysattr(enumerate, "busnum", bus_str);
  udev_enumerate_add_match_sysattr(enumerate, "devnum", dev_str);
  udev_enumerate_scan_devices(enumerate);
  devices = udev_enumerate_get_list_entry(enumerate);
  udev_list_entry_foreach(dev_list_entry, devices) {
    const char *path;
    path = udev_list_entry_get_name(dev_list_entry);
    udev_dev = udev_device_new_from_syspath(udev, path);
    sscanf(udev_device_get_sysattr_value(udev_dev, "idVendor"), "%x", &ui->usb_vendor);
    sscanf(udev_device_get_sysattr_value(udev_dev, "idProduct"), "%x", &ui->usb_product);
    udev_device_unref(udev_dev);
    udev_enumerate_unref(enumerate);
    udev_unref(udev);
    return 0;
  }
  udev_enumerate_unref(enumerate);
  udev_unref(udev);
  return -ENOENT;
}
コード例 #27
0
ファイル: gamepad.c プロジェクト: PhoenixClub/gamepad
void GamepadInit(void) {
	struct udev_list_entry* devices;
	struct udev_list_entry* item;
	struct udev_enumerate* enu;
	int i;

	/* initialize connection state */
	for (i = 0; i != GAMEPAD_COUNT; ++i) {
		STATE[i].flags = 0;
		STATE[i].fd = STATE[i].effect = -1;
	}

	/* open the udev handle */
	UDEV = udev_new();
	if (UDEV == NULL) {
		/* FIXME: flag error? */
		return;
	}
	
	/* open monitoring device (safe to fail) */
	MON = udev_monitor_new_from_netlink(UDEV, "udev");
	/* FIXME: flag error if hot-plugging can't be supported? */
	if (MON != NULL) {
		udev_monitor_enable_receiving(MON);
		udev_monitor_filter_add_match_subsystem_devtype(MON, "input", NULL);
	}

	/* enumerate joypad devices */
	enu = udev_enumerate_new(UDEV);
	udev_enumerate_add_match_subsystem(enu, "input");
	udev_enumerate_scan_devices(enu);
	devices = udev_enumerate_get_list_entry(enu);

	udev_list_entry_foreach(item, devices) {
		const char* name;
		const char* sysPath;
		const char* devPath;
		struct udev_device* dev;

		name = udev_list_entry_get_name(item);
		dev = udev_device_new_from_syspath(UDEV, name);
		sysPath = udev_device_get_syspath(dev);
		devPath = udev_device_get_devnode(dev);

		if (sysPath != NULL && devPath != NULL && strstr(sysPath, "/js") != 0) {
			GamepadAddDevice(devPath);
		}

		udev_device_unref(dev);
	}

	/* cleanup */
	udev_enumerate_unref(enu);
}
コード例 #28
0
io_object_t io_device_iterator::next()
{
	if (!m_next)
		return nullptr;
	else
	{
		udev_device* dev = udev_device_new_from_syspath(m_udev, udev_list_entry_get_name(m_next));
		m_next = udev_list_entry_get_next(m_next);
		return new io_device(dev);
	}
}
コード例 #29
0
ファイル: loader.c プロジェクト: TechnoMancer/mesa
static char *
get_render_node_from_id_path_tag(struct udev *udev,
                                 char *id_path_tag,
                                 char another_tag)
{
   struct udev_device *device;
   struct udev_enumerate *e;
   struct udev_list_entry *entry;
   const char *path, *id_path_tag_tmp;
   char *path_res;
   char found = 0;
   UDEV_SYMBOL(struct udev_enumerate *, udev_enumerate_new,
               (struct udev *));
   UDEV_SYMBOL(int, udev_enumerate_add_match_subsystem,
               (struct udev_enumerate *, const char *));
   UDEV_SYMBOL(int, udev_enumerate_add_match_sysname,
               (struct udev_enumerate *, const char *));
   UDEV_SYMBOL(int, udev_enumerate_scan_devices,
               (struct udev_enumerate *));
   UDEV_SYMBOL(struct udev_list_entry *, udev_enumerate_get_list_entry,
               (struct udev_enumerate *));
   UDEV_SYMBOL(struct udev_list_entry *, udev_list_entry_get_next,
               (struct udev_list_entry *));
   UDEV_SYMBOL(const char *, udev_list_entry_get_name,
               (struct udev_list_entry *));
   UDEV_SYMBOL(struct udev_device *, udev_device_new_from_syspath,
               (struct udev *, const char *));
   UDEV_SYMBOL(const char *, udev_device_get_property_value,
               (struct udev_device *, const char *));
   UDEV_SYMBOL(const char *, udev_device_get_devnode,
               (struct udev_device *));
   UDEV_SYMBOL(struct udev_device *, udev_device_unref,
               (struct udev_device *));

   e = udev_enumerate_new(udev);
   udev_enumerate_add_match_subsystem(e, "drm");
   udev_enumerate_add_match_sysname(e, "render*");

   udev_enumerate_scan_devices(e);
   udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
      path = udev_list_entry_get_name(entry);
      device = udev_device_new_from_syspath(udev, path);
      if (!device)
         continue;
      id_path_tag_tmp = udev_device_get_property_value(device, "ID_PATH_TAG");
      if (id_path_tag_tmp) {
         if ((!another_tag && !strcmp(id_path_tag, id_path_tag_tmp)) ||
             (another_tag && strcmp(id_path_tag, id_path_tag_tmp))) {
            found = 1;
            break;
         }
      }
      udev_device_unref(device);
   }
コード例 #30
0
ファイル: LinuxInputDevices.cpp プロジェクト: intrcomp/xbmc
/*
 * this function is not powerful because it reinitializes a new udev search each
 * time it would be nicer to call this only one time + one time at each hotplug
 * but it is already very fast, so, let's keep it simple and non intrusive
 */
bool CLinuxInputDevices::IsUdevJoystick(const char *devpath)
{
#if defined(HAVE_LIBUDEV)
  struct udev *udev;
  struct udev_enumerate *enumerate;
  struct udev_list_entry *devices, *dev_list_entry;
  struct udev_device *dev;
  const char *path;
  const char *devfoundpath;

  udev = udev_new();
  if (!udev)
    return false; // can't create udev

  enumerate = udev_enumerate_new(udev);
  if (enumerate == NULL)
  {
    udev_unref(udev);
    return false;
  }

  if (udev_enumerate_add_match_subsystem(enumerate, "input") == 0)
  {
    if (udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYSTICK", "1") == 0)
    {
      if (udev_enumerate_scan_devices(enumerate) >= 0)
      {
        devices = udev_enumerate_get_list_entry(enumerate);

        udev_list_entry_foreach(dev_list_entry, devices)
        {
          path = udev_list_entry_get_name(dev_list_entry);
          dev = udev_device_new_from_syspath(udev, path);
          if (dev != NULL)
          {
            devfoundpath = udev_device_get_devnode(dev);
            if (devfoundpath != NULL)
            {
              // found (finally !)
              //printf("=> %s\n", devfoundpath);
              if (strcmp(devfoundpath, devpath) == 0)
              {
                udev_device_unref(dev);
                udev_enumerate_unref(enumerate);
                udev_unref(udev);
                return true;
              }
            }
            udev_device_unref(dev);
          }
        }
      }
    }