Ejemplo n.º 1
0
int wait_sdio_uevent(int *id, const char *keyword)
{
    static int fd = 0;
    pthread_t uevent_tid;
    struct uevent *event = NULL;
    int ret = 0;
    if(fd <= 0){
        fd = open_uevent_socket();
        if (fd < 0) {
            printf("error!\n");
            return -1;
        }
    }
    
    while(1){
        ret = pthread_create(&uevent_tid, NULL, handle_device_fd, &fd);
        if(ret<0) { 
            printf("Thread Creation Failed\n");
            return 1; 
        }
        pthread_join(uevent_tid, (void **)&event);
        if(strncmp(event->what, keyword, strlen(keyword))==0){
            printf("test_event { %s, %d, %s }\n", event->subsystem, event->host_id, event->what);
            *id = event->host_id;
            free(event->subsystem);
            free(event->what);
            free(event);
            break;
        }
    }

    return 0;
}
int ev_init(void)
{
    int fd;

	int i;
	for (i=0;;i++) {
		char fname[32];
		sprintf(fname, "/dev/input/event%d", i);
		fd = open(fname, O_RDONLY);
		if (fd < 0)
			break;
		ev_type[ev_count] = EV_TYPE_KEYBOARD;
		ev_fds[ev_count].fd = fd;
		ev_fds[ev_count].events = POLLIN;
		ev_count++;
	}

	fd = open_uevent_socket();
	if (fd >= 0) {
		fcntl(fd, F_SETFD, FD_CLOEXEC);
		fcntl(fd, F_SETFL, O_NONBLOCK);
		ev_type[ev_count] = EV_TYPE_UEVENT;
		ev_fds[ev_count].fd = fd;
		ev_fds[ev_count].events = POLLIN;
		uev_count = ev_count;
		ev_count++;
	}

    return 0;
}
Ejemplo n.º 3
0
/* Usbd main */
int main(int argc, char **argv)
{
  char buf[513];
  int len;


  LOGD("main(): Start usbd - version " USBD_VER "\n");

  /* init uevent */
  LOGD("main(): Initializing uevent_socket \n");
  if (open_uevent_socket())
    return -1;
  
  /* open device mode */
  LOGD("main(): Initializing usb_device_mode \n");
  usb_mode_fd = open("/dev/usb_device_mode", O_RDWR);

  get_phone_mode();
//  ev_init();


  if (usb_mode_fd < 0)
  {
    LOGE("main(): Unable to open usb_device_mode '%s'\n", strerror(errno));
    return -errno;
  }

  /* init usdb socket */
  if (init_usbd_socket() < 0)
  {
    LOGE("main(): failed to create socket server '%s'\n", strerror(errno));
    return -errno;
  }
  
  /* init cable status */
  if (usbd_get_cable_status() < 0)
  {
    LOGE("main(): failed to get cable status\n");
    return -1;
  }

 while(1) {
	ns = accept(socket_ev, 0, 0);
	if(ns != -1) {
		usbd_send_adb_status(1);
		usbd_get_cable_status();
		while(len = recv(ns, &buf, 512, 0)) {
			buf[len] = '\0';
			LOGI("receiving shit");
			LOGI("%s", buf);
		}
		close(ns);
	}

}

return 0;
}
Ejemplo n.º 4
0
int main(void)
{
	int fd = 0;

	fd = open_uevent_socket();
	if (fd < 0) {
		printf("error!\n");
		return -1;
	}

	handle_device_fd(fd);
}
Ejemplo n.º 5
0
int do_devwait(int nargs, char **args) {

    int dev_fd, uevent_fd, rc, timeout = DEVWAIT_TIMEOUT;
    struct pollfd ufds[1];

    uevent_fd = open_uevent_socket();

    ufds[0].fd = uevent_fd;
    ufds[0].events = POLLIN;

    for(;;) {

        dev_fd = open(args[1], O_RDONLY);
        if (dev_fd < 0) {
            if (errno != ENOENT) {
                ERROR("%s: open failed with error %d\n", __func__, errno);
                rc = -errno;
                break;
            }
        } else {
            return 0;
        }

        ufds[0].revents = 0;

        rc = poll(ufds, 1, DEVWAIT_POLL_TIME);

        if (rc == 0) {
            if (timeout > 0)
                timeout -= DEVWAIT_POLL_TIME;
            else {
                ERROR("%s: timed out waiting on file: %s\n", __func__, args[1]);
                rc = -ETIME;
                break;
            }
            continue;
        } else if (rc < 0) {
            ERROR("%s: poll request failed for file: %s\n", __func__, args[1]);
            break;
        }

        if (ufds[0].revents == POLLIN)
            handle_device_fd(uevent_fd);
    }

    return rc;
}
Ejemplo n.º 6
0
int ev_init(void)
{
	int fd;

	char fname[32];
	sprintf(fname, "/dev/socket/usbd");
	fd = open(fname, O_RDWR);
	if (fd < 0)
		return -1;
	fd = open_uevent_socket();
	if (fd >= 0) {
		fcntl(fd, F_SETFD, FD_CLOEXEC);
		fcntl(fd, F_SETFL, O_NONBLOCK);
		LOGI("ev_init function");
		}
    return fd;
    }