예제 #1
0
/** Initialize a new ddf driver instance of i8042 driver
 *
 * @param[in] device DDF instance of the device to initialize.
 *
 * @return Error code.
 *
 */
static int i8042_dev_add(ddf_dev_t *device)
{
	if (!device)
		return EINVAL;
	
	uintptr_t io_regs = 0;
	size_t io_size = 0;
	int kbd = 0;
	int mouse = 0;
	
	int ret = get_my_registers(device, &io_regs, &io_size, &kbd, &mouse);
	CHECK_RET_RETURN(ret, "Failed to get registers: %s.",
	    str_error(ret));
	ddf_msg(LVL_DEBUG, "I/O regs at %p (size %zuB), IRQ kbd %d, IRQ mouse %d.",
	    (void *) io_regs, io_size, kbd, mouse);
	
	i8042_t *i8042 = ddf_dev_data_alloc(device, sizeof(i8042_t));
	ret = (i8042 == NULL) ? ENOMEM : EOK;
	CHECK_RET_RETURN(ret, "Failed to allocate i8042 driver instance.");
	
	ret = i8042_init(i8042, (void *) io_regs, io_size, kbd, mouse, device);
	CHECK_RET_RETURN(ret, "Failed to initialize i8042 driver: %s.",
	    str_error(ret));
	
	ddf_msg(LVL_NOTE, "Controlling '%s' (%" PRIun ").",
	    ddf_dev_get_name(device), ddf_dev_get_handle(device));
	return EOK;
}
예제 #2
0
파일: drec.c 프로젝트: jvesely/helenos
/**
 * Start fragment based recording.
 * @param rec Recording helper structure.
 * @param f PCM format
 */
static void record_fragment(record_t *rec, pcm_format_t f)
{
	assert(rec);
	assert(rec->device);
	int ret = audio_pcm_register_event_callback(rec->device,
	    device_event_callback, rec);
	if (ret != EOK) {
		printf("Failed to register for events: %s.\n", str_error(ret));
		return;
	}
	rec->buffer.position = rec->buffer.base;
	printf("Recording: %dHz, %s, %d channel(s).\n", f.sampling_rate,
	    pcm_sample_format_str(f.sample_format), f.channels);
	const unsigned frames =
		pcm_format_size_to_frames(rec->buffer.size / BUFFER_PARTS, &f);
	ret = audio_pcm_start_capture_fragment(rec->device,
	    frames, f.channels, f.sampling_rate, f.sample_format);
	if (ret != EOK) {
		printf("Failed to start recording: %s.\n", str_error(ret));
		return;
	}

	getchar();
	printf("\n");
	audio_pcm_stop_capture(rec->device);
	/* XXX Control returns even before we can be sure callbacks finished */
	printf("Delay before playback termination\n");
	async_usleep(1000000);
	printf("Terminate playback\n");
}
예제 #3
0
파일: str.c 프로젝트: doug16rogers/dr
/* ------------------------------------------------------------------------- */
str_t str_append_string(str_t str, const char* s) {
    if (!str_error(str) && (NULL != s)) {
        /*
         * @todo(dr) Yeah, uh, this could be optimized.
         */
        for (; *s && !str_error(str); ++s) {
            str_append_char(str, *s);
        }
    }
    return str;
}   /* str_append_string() */
예제 #4
0
파일: mkfs.c 프로젝트: jvesely/helenos
static int cmd_runl(const char *path, ...)
{
	va_list ap;
	const char *arg;
	int cnt = 0;

	va_start(ap, path);
	do {
		arg = va_arg(ap, const char *);
		cnt++;
	} while (arg != NULL);
	va_end(ap);

	va_start(ap, path);
	task_id_t id;
	task_wait_t wait;
	int rc = task_spawn(&id, &wait, path, cnt, ap);
	va_end(ap);

	if (rc != EOK) {
		log_msg(LOG_DEFAULT, LVL_ERROR, "Error spawning %s (%s)",
		    path, str_error(rc));
		return rc;
	}

	if (!id) {
		log_msg(LOG_DEFAULT, LVL_ERROR, "Error spawning %s "
		    "(invalid task ID)", path);
		return EINVAL;
	}

	task_exit_t texit;
	int retval;
	rc = task_wait(&wait, &texit, &retval);
	if (rc != EOK) {
		log_msg(LOG_DEFAULT, LVL_ERROR, "Error waiting for %s (%s)",
		    path, str_error(rc));
		return rc;
	}

	if (texit != TASK_EXIT_NORMAL) {
		log_msg(LOG_DEFAULT, LVL_ERROR, "Command %s unexpectedly "
		    "terminated", path);
		return EINVAL;
	}

	if (retval != 0) {
		log_msg(LOG_DEFAULT, LVL_ERROR, "Command %s returned non-zero "
		    "exit code %d)", path, retval);
	}

	return retval;
}
예제 #5
0
/** Register child and inform user about it.
 *
 * @param parent Parent device.
 * @param message Message for the user.
 * @param name Device name.
 * @param match_id Device match id.
 * @param score Device match score.
 */
static int register_fun_verbose(ddf_dev_t *parent, const char *message,
    const char *name, const char *match_id, int match_score,
    int expected_rc, ddf_fun_t **pfun)
{
	ddf_fun_t *fun = NULL;
	int rc;

	ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);

	fun = ddf_fun_create(parent, fun_inner, name);
	if (fun == NULL) {
		ddf_msg(LVL_ERROR, "Failed creating function %s", name);
		rc = ENOMEM;
		goto leave;
	}

	rc = ddf_fun_add_match_id(fun, match_id, match_score);
	if (rc != EOK) {
		ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
		    name);
		goto leave;
	}

	rc = ddf_fun_bind(fun);
	if (rc != EOK) {
		ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
		    str_error(rc));
		goto leave;
	}

	ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
	rc = EOK;

leave:
	if (rc != expected_rc) {
		fprintf(stderr,
		    NAME ": Unexpected error registering function `%s'.\n" 
		    NAME ":     Expected \"%s\" but got \"%s\".\n",
		    name, str_error(expected_rc), str_error(rc));
	}

	if ((rc != EOK) && (fun != NULL)) {
		ddf_fun_destroy(fun);
	}

	if (pfun != NULL)
		*pfun = fun;

	return rc;
}
예제 #6
0
static int amdm37x_dispc_dev_add(ddf_dev_t *dev)
{
	assert(dev);
	/* Visualizer part */
	ddf_fun_t *fun = ddf_fun_create(dev, fun_exposed, "viz");
	if (!fun) {
		ddf_log_error("Failed to create visualizer function\n");
		return ENOMEM;
	}

	visualizer_t *vis = ddf_fun_data_alloc(fun, sizeof(visualizer_t));
	if (!vis) {
		ddf_log_error("Failed to allocate visualizer structure\n");
		ddf_fun_destroy(fun);
		return ENOMEM;
	}

	graph_init_visualizer(vis);
	vis->reg_svc_handle = ddf_fun_get_handle(fun);

	ddf_fun_set_ops(fun, &graph_fun_ops);
	/* Hw part */
	amdm37x_dispc_t *dispc =
	    ddf_dev_data_alloc(dev, sizeof(amdm37x_dispc_t));
	if (!dispc) {
		ddf_log_error("Failed to allocate dispc structure\n");
		ddf_fun_destroy(fun);
		return ENOMEM;
	}

	int ret = amdm37x_dispc_init(dispc, vis);
	if (ret != EOK) {
		ddf_log_error("Failed to init dispc: %s\n", str_error(ret));
		ddf_fun_destroy(fun);
		return ret;
	}

	/* Report to devman */
	ret = ddf_fun_bind(fun);
	if (ret != EOK) {
		ddf_log_error("Failed to bind function: %s\n", str_error(ret));
		amdm37x_dispc_fini(dispc);
		ddf_fun_destroy(fun);
		return ret;
	}
	ddf_fun_add_to_category(fun, "visualizer");

	ddf_log_note("Added device `%s'\n", ddf_dev_get_name(dev));
	return EOK;
}
예제 #7
0
int SetUpListener()
{
    unsigned int port;
    SOCKET sd;
    struct sockaddr_in sinInterface;

    port = GetConfigUInt(CFG_HTTP_PORT);
    if (port == 0) {
        port = GetConfigUInt(CFG_SERVER_PORT);
    }//if

    if (port == 0) {
        errorm("HTTP port not specified");
        return FALSE;
    }//if

    logf("Creating TCP server socket (port: %u).", port);

    //struct protoent *pp;
    //getprotobyname("tcp");
    sd = socket(AF_INET, SOCK_STREAM, 0);
    if (sd == INVALID_SOCKET) { 
        errorm("socket() for tcp failed: %s", str_error());   
        return FALSE;
    }
    // SO_REUSEADDR
    int one = 1;
    if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int)) != 0) {
        errorm("setsockopt(SO_REUSEADDR) for tcp failed: %s", str_error());
      }

    sinInterface.sin_family = AF_INET;
    sinInterface.sin_addr.s_addr = INADDR_ANY;
    sinInterface.sin_port = htons((u_short)port);
    if (bind(sd, (struct sockaddr *)&sinInterface, sizeof(sinInterface)) == INVALID_SOCKET) { 
        errorm("bind() for tcp failed: %s", str_error()); 
        return FALSE;
    }

    if (listen(sd, SOMAXCONN) == SOCKET_ERROR) { 
        errorm("listen() for tcp failed: %s", str_error()); 
        return FALSE;
    }

    ssd = sd;
   
    return TRUE;
}
예제 #8
0
/** Perform SCSI Request Sense command on USB mass storage device.
 *
 * @param mfun		Mass storage function
 * @param buf		Destination buffer
 * @param size		Size of @a buf
 *
 * @return		Error code.
 */
int usbmast_request_sense(usbmast_fun_t *mfun, void *buf, size_t size)
{
	scsi_cmd_t cmd;
	scsi_cdb_request_sense_t cdb;
	int rc;

	memset(&cdb, 0, sizeof(cdb));
	cdb.op_code = SCSI_CMD_REQUEST_SENSE;
	cdb.alloc_len = min(size, SCSI_SENSE_DATA_MAX_SIZE);

	memset(&cmd, 0, sizeof(cmd));
	cmd.cdb = &cdb;
	cmd.cdb_size = sizeof(cdb);
	cmd.data_in = buf;
	cmd.data_in_size = size;

	rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd);

        if (rc != EOK || cmd.status != CMDS_GOOD) {
		usb_log_error("Request Sense failed, device %s: %s.\n",
		   mfun->mdev->ddf_dev->name, str_error(rc));
		return rc;
	}

	if (cmd.rcvd_size < SCSI_SENSE_DATA_MIN_SIZE) {
		/* The missing bytes should be considered to be zeroes. */
		memset((uint8_t *)buf + cmd.rcvd_size, 0,
		    SCSI_SENSE_DATA_MIN_SIZE - cmd.rcvd_size);
	}

	return EOK;
}
예제 #9
0
static bool cmd_error(int srv, struct message *response)
{
  warnx("received error from server for command %d : %s",
        current_request, str_error(response->p_int.value));

  return true;
}
예제 #10
0
static void print_hc_devices(devman_handle_t hc_handle)
{
	int rc;
	usb_hc_connection_t conn;

	usb_hc_connection_initialize(&conn, hc_handle);
	rc = usb_hc_connection_open(&conn);
	if (rc != EOK) {
		printf(NAME ": failed to connect to HC: %s.\n",
		    str_error(rc));
		return;
	}
	usb_address_t addr;
	for (addr = 1; addr < MAX_USB_ADDRESS; addr++) {
		devman_handle_t dev_handle;
		rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);
		if (rc != EOK) {
			continue;
		}
		char path[MAX_PATH_LENGTH];
		rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH);
		if (rc != EOK) {
			continue;
		}
		print_found_dev(addr, path);
	}
	usb_hc_connection_close(&conn);
}
예제 #11
0
/** Perform SCSI Inquiry command on USB mass storage device.
 *
 * @param mfun		Mass storage function
 * @param inquiry_result Where to store parsed inquiry result
 * @return		Error code
 */
int usbmast_inquiry(usbmast_fun_t *mfun, usbmast_inquiry_data_t *inq_res)
{
	scsi_std_inquiry_data_t inq_data;
	scsi_cmd_t cmd;
	scsi_cdb_inquiry_t cdb;
	int rc;

	memset(&cdb, 0, sizeof(cdb));
	cdb.op_code = SCSI_CMD_INQUIRY;
	cdb.alloc_len = host2uint16_t_be(sizeof(inq_data));

	memset(&cmd, 0, sizeof(cmd));
	cmd.cdb = &cdb;
	cmd.cdb_size = sizeof(cdb);
	cmd.data_in = &inq_data;
	cmd.data_in_size = sizeof(inq_data);

	rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd);

	if (rc != EOK) {
		usb_log_error("Inquiry transport failed, device %s: %s.\n",
		   mfun->mdev->ddf_dev->name, str_error(rc));
		return rc;
	}

	if (cmd.status != CMDS_GOOD) {
		usb_log_error("Inquiry command failed, device %s.\n",
		   mfun->mdev->ddf_dev->name);
		return EIO;
	}

	if (cmd.rcvd_size < SCSI_STD_INQUIRY_DATA_MIN_SIZE) {
		usb_log_error("SCSI Inquiry response too short (%zu).\n",
		    cmd.rcvd_size);
		return EIO;
	}

	/*
	 * Parse inquiry data and fill in the result structure.
	 */

	bzero(inq_res, sizeof(*inq_res));

	inq_res->device_type = BIT_RANGE_EXTRACT(uint8_t,
	    inq_data.pqual_devtype, SCSI_PQDT_DEV_TYPE_h, SCSI_PQDT_DEV_TYPE_l);

	inq_res->removable = BIT_RANGE_EXTRACT(uint8_t,
	    inq_data.rmb, SCSI_RMB_RMB, SCSI_RMB_RMB);

	spascii_to_str(inq_res->vendor, SCSI_INQ_VENDOR_STR_BUFSIZE,
	    inq_data.vendor, sizeof(inq_data.vendor));

	spascii_to_str(inq_res->product, SCSI_INQ_PRODUCT_STR_BUFSIZE,
	    inq_data.product, sizeof(inq_data.product));

	spascii_to_str(inq_res->revision, SCSI_INQ_REVISION_STR_BUFSIZE,
	    inq_data.revision, sizeof(inq_data.revision));

	return EOK;
}
예제 #12
0
static task_id_t spawn(int argc, char *argv[])
{
	const char **args;
	task_id_t id = 0;
	int rc;

	args = (const char **) calloc(argc + 1, sizeof(char *));
	if (!args) {
		fprintf(stderr, "No memory available\n");
		return 0;
	}
	
	int i;
	for (i = 0; i < argc; i++)
		args[i] = argv[i];
	
	args[argc] = NULL;
	
	rc = task_spawnv(&id, argv[0], args);
	
	free(args);
	
	if (rc != EOK) {
		fprintf(stderr, "%s: Error spawning %s (%s)\n", NAME, argv[0],
		    str_error(rc));
		return 0;
	}
	
	return id;
}
예제 #13
0
//���������������������������������������������������������������������������
// InitBachCd
//���������������������������������������������������������������������������
BOOL InitBachCd()
{
    if (BachCd)
        return TRUE;

    BachCd = new BachCD;
    if (!BachCd)
    {
        MessageBox(hWndClient,"Bach Cd - Out of memory",
                   szAppName,MB_OK | MB_ICONEXCLAMATION);
        return FALSE;
    }

    bach_err_codes err = BachCd->init();
    if (err)
    {
        char buff[128];
        strcat(str_error(buff,err)," - Bach Cd Init");
        MessageBox(hWndClient,buff,
                   szAppName,MB_OK | MB_ICONEXCLAMATION);
        delete BachCd;
        BachCd =0;
        return FALSE;
    }

    return TRUE;
}
예제 #14
0
/**
 * Process hub over current change
 *
 * This means either to power off the hub or power it on.
 * @param hub_dev hub instance
 * @param status hub status bitmask
 * @return error code
 */
static void usb_hub_over_current(const usb_hub_dev_t *hub_dev,
    usb_hub_status_t status)
{
	if (status & USB_HUB_STATUS_OVER_CURRENT) {
		/* Hub should remove power from all ports if it detects OC */
		usb_log_warning("Detected hub over-current condition, "
		    "all ports should be powered off.");
		return;
	}

	/* Ports are always powered. */
	if (!hub_dev->power_switched)
		return;

	/* Over-current condition is gone, it is safe to turn the ports on. */
	for (size_t port = 0; port < hub_dev->port_count; ++port) {
		const int ret = usb_hub_port_set_feature(
		    &hub_dev->ports[port], USB_HUB_FEATURE_PORT_POWER);
		if (ret != EOK) {
			usb_log_warning("HUB OVER-CURRENT GONE: Cannot power on"
			    " port %zu: %s\n", hub_dev->ports[port].port_number,
			    str_error(ret));
		} else {
			if (!hub_dev->per_port_power)
				return;
		}
	}

}
예제 #15
0
/** Register child and inform user about it.
 *
 * @param parent Parent device.
 * @param message Message for the user.
 * @param name Device name.
 * @param match_id Device match id.
 * @param score Device match score.
 */
static int register_fun_verbose(ddf_dev_t *parent, const char *message,
    const char *name, const char *match_id, int match_score, ddf_fun_t **pfun)
{
	ddf_fun_t *fun;
	int rc;

	ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);

	fun = ddf_fun_create(parent, fun_inner, name);
	if (fun == NULL) {
		ddf_msg(LVL_ERROR, "Failed creating function %s", name);
		return ENOMEM;
	}

	rc = ddf_fun_add_match_id(fun, match_id, match_score);
	if (rc != EOK) {
		ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
		    name);
		ddf_fun_destroy(fun);
		return rc;
	}

	rc = ddf_fun_bind(fun);
	if (rc != EOK) {
		ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
		    str_error(rc));
		ddf_fun_destroy(fun);
		return rc;
	}

	*pfun = fun;

	ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
	return EOK;
}
예제 #16
0
int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data)
{
	if (hid_dev == NULL) {
		return EINVAL;
	}

	/* Create the exposed function. */
	usb_log_debug("Creating DDF function %s...\n", HID_GENERIC_FUN_NAME);
	ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 
	    HID_GENERIC_FUN_NAME);
	if (fun == NULL) {
		usb_log_error("Could not create DDF function node.\n");
		return ENOMEM;
	}

	/* This is nasty, both device and this function have the same
	 * driver data, thus destruction causes to double free */
	fun->driver_data = hid_dev;
	fun->ops = &usb_generic_hid_ops;

	int rc = ddf_fun_bind(fun);
	if (rc != EOK) {
		usb_log_error("Could not bind DDF function: %s.\n",
		    str_error(rc));
		fun->driver_data = NULL;
		ddf_fun_destroy(fun);
		return rc;
	}

	usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle);
	*data = fun;

	return EOK;
}
예제 #17
0
/** Initialize UHCI hc driver structure
 *
 * @param[in] instance Memory place to initialize.
 * @param[in] regs Address of I/O control registers.
 * @param[in] reg_size Size of I/O control registers.
 * @param[in] interrupts True if hw interrupts should be used.
 * @return Error code.
 * @note Should be called only once on any structure.
 *
 * Initializes memory structures, starts up hw, and launches debugger and
 * interrupt fibrils.
 */
int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interrupts)
{
	assert(reg_size >= sizeof(uhci_regs_t));
	int ret;

#define CHECK_RET_RETURN(ret, message...) \
	if (ret != EOK) { \
		usb_log_error(message); \
		return ret; \
	} else (void) 0

	instance->hw_interrupts = interrupts;
	instance->hw_failures = 0;

	/* allow access to hc control registers */
	uhci_regs_t *io;
	ret = pio_enable(regs, reg_size, (void **)&io);
	CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p: %s.\n",
	    io, str_error(ret));
	instance->registers = io;
	usb_log_debug(
	    "Device registers at %p (%zuB) accessible.\n", io, reg_size);

	ret = hc_init_mem_structures(instance);
	CHECK_RET_RETURN(ret,
	    "Failed to initialize UHCI memory structures: %s.\n",
	    str_error(ret));

#undef CHECK_RET_RETURN

	hcd_init(&instance->generic, USB_SPEED_FULL,
	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);

	instance->generic.private_data = instance;
	instance->generic.schedule = hc_schedule;
	instance->generic.ep_add_hook = NULL;

	hc_init_hw(instance);
	if (!interrupts) {
		instance->interrupt_emulator =
		    fibril_create(hc_interrupt_emulator, instance);
		fibril_add_ready(instance->interrupt_emulator);
	}
	(void)hc_debug_checker;

	return EOK;
}
예제 #18
0
/** Fibril for each accepted socket.
 *
 * @param arg Corresponding @c telnet_user_t structure.
 */
static int network_user_fibril(void *arg)
{
	telnet_user_t *user = arg;

	int rc = loc_service_register(user->service_name, &user->service_id);
	if (rc != EOK) {
		telnet_user_error(user, "Unable to register %s with loc: %s.",
		    user->service_name, str_error(rc));
		return EOK;
	}

	telnet_user_log(user, "Service %s registerd with id %" PRIun ".",
	    user->service_name, user->service_id);
	
	fid_t spawn_fibril = fibril_create(spawn_task_fibril, user);
	assert(spawn_fibril);
	fibril_add_ready(spawn_fibril);
	
	/* Wait for all clients to exit. */
	fibril_mutex_lock(&user->guard);
	while (!user_can_be_destroyed_no_lock(user)) {
		if (user->task_finished) {
			closesocket(user->socket);
			user->socket_closed = true;
			user->srvs.aborted = true;
			continue;
		} else if (user->socket_closed) {
			if (user->task_id != 0) {
				task_kill(user->task_id);
			}
		}
		fibril_condvar_wait_timeout(&user->refcount_cv, &user->guard, 1000);
	}
	fibril_mutex_unlock(&user->guard);
	
	rc = loc_service_unregister(user->service_id);
	if (rc != EOK) {
		telnet_user_error(user,
		    "Unable to unregister %s from loc: %s (ignored).",
		    user->service_name, str_error(rc));
	}

	telnet_user_log(user, "Destroying...");
	telnet_user_destroy(user);

	return EOK;
}
예제 #19
0
static const char *test_virtchar1_internal(const char *path)
{
	TPRINTF("Opening `%s'...\n", path);
	int fd = open(path, O_RDONLY);
	if (fd < 0) {
		TPRINTF("   ...error: %s\n", str_error(fd));
		if (fd == ENOENT) {
			TPRINTF("   (error was ENOENT: " \
			    "have you compiled test drivers?)\n");
		}
		return "Failed opening devman driver device for reading";
	}
	
	TPRINTF("   ...file handle %d\n", fd);
	
	TPRINTF(" Asking for session...\n");
	async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd);
	if (!sess) {
		close(fd);
		TPRINTF("   ...error: %s\n", str_error(errno));
		return "Failed to get session to device";
	}
	TPRINTF("   ...session is %p\n", sess);
	
	TPRINTF(" Will try to read...\n");
	size_t i;
	char buffer[BUFFER_SIZE];
	char_dev_read(sess, buffer, BUFFER_SIZE);
	TPRINTF(" ...verifying that we read zeroes only...\n");
	for (i = 0; i < BUFFER_SIZE; i++) {
		if (buffer[i] != 0) {
			return "Not all bytes are zeroes";
		}
	}
	TPRINTF("   ...data read okay\n");
	
	/* Clean-up. */
	TPRINTF(" Closing session and file descriptor\n");
	async_hangup(sess);
	close(fd);
	
	return NULL;
}
void DownloadThread::run()
{
	const char *error;
	if (!strcmp(data->vendor, "Uemis"))
		error = do_uemis_import(data->devname, data->force_download);
	else
		error = do_libdivecomputer_import(data);
	if (error)
		this->error =  str_error(error, data->devname, data->vendor, data->product);
}
예제 #21
0
static int register_fun_and_add_to_category(ddf_dev_t *parent,
    const char *base_name, size_t index, const char *class_name,
    ddf_fun_t **pfun)
{
	ddf_fun_t *fun = NULL;
	int rc;
	char *fun_name = NULL;
	
	rc = asprintf(&fun_name, "%s%zu", base_name, index);
	if (rc < 0) {
		ddf_msg(LVL_ERROR, "Failed to format string: %s", str_error(rc));
		goto leave;
	}
	
	fun = ddf_fun_create(parent, fun_exposed, fun_name);
	if (fun == NULL) {
		ddf_msg(LVL_ERROR, "Failed creating function %s", fun_name);
		rc = ENOMEM;
		goto leave;
	}

	rc = ddf_fun_bind(fun);
	if (rc != EOK) {
		ddf_msg(LVL_ERROR, "Failed binding function %s: %s", fun_name,
		    str_error(rc));
		goto leave;
	}
	
	ddf_fun_add_to_category(fun, class_name);

	ddf_msg(LVL_NOTE, "Registered exposed function `%s'.", fun_name);

leave:	
	free(fun_name);
	
	if ((rc != EOK) && (fun != NULL)) {
		ddf_fun_destroy(fun);
	}
	
	*pfun = fun;
	return rc;
}
예제 #22
0
/** Initialize a new ddf driver instance of UHCI root hub.
 *
 * @param[in] device DDF instance of the device to initialize.
 * @return Error code.
 */
static int uhci_rh_dev_add(ddf_dev_t *device)
{
	if (!device)
		return EINVAL;

	usb_log_debug2("uhci_rh_dev_add(handle=%" PRIun ")\n",
	    device->handle);

	uintptr_t io_regs = 0;
	size_t io_size = 0;
	uhci_root_hub_t *rh = NULL;
	int ret = EOK;

#define CHECK_RET_FREE_RH_RETURN(ret, message...) \
if (ret != EOK) { \
	usb_log_error(message); \
	if (rh) \
		free(rh); \
	return ret; \
} else (void)0

	ret = hc_get_my_registers(device, &io_regs, &io_size);
	CHECK_RET_FREE_RH_RETURN(ret,
	    "Failed to get registers from HC: %s.\n", str_error(ret));
	usb_log_debug("I/O regs at %p (size %zuB).\n",
	    (void *) io_regs, io_size);

	rh = malloc(sizeof(uhci_root_hub_t));
	ret = (rh == NULL) ? ENOMEM : EOK;
	CHECK_RET_FREE_RH_RETURN(ret,
	    "Failed to allocate rh driver instance.\n");

	ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
	CHECK_RET_FREE_RH_RETURN(ret,
	    "Failed(%d) to initialize rh driver instance: %s.\n",
	    ret, str_error(ret));

	device->driver_data = rh;
	usb_log_info("Controlling root hub '%s' (%" PRIun ").\n",
	    device->name, device->handle);
	return EOK;
}
예제 #23
0
void cec_worker_init(void)
{
  cec_set_own_address(/*DEVICE_TYPE_UNREG*/ 0x0F);

  dprintk(1, "*** CEC INIT ***\n");
  str_status(cec_get_status());
  str_error(cec_get_error());
  dprintk(1, "~~~ CEC INIT ~~~\n");

  sendPingWithAutoIncrement();
}
예제 #24
0
파일: listen.c 프로젝트: lmangani/libre
static void reinvite_handler(struct sipsess_sock *sock,
			     const struct sip_msg *msg)
{
	struct sip *sip = sock->sip;
	struct sipsess *sess;
	struct mbuf *desc;
	char m[256];
	int err;

	sess = sipsess_find(sock, msg);
	if (!sess || sess->terminated) {
		(void)sip_treply(NULL, sip, msg, 481, "Call Does Not Exist");
		return;
	}

	if (!sip_dialog_rseq_valid(sess->dlg, msg)) {
		(void)sip_treply(NULL, sip, msg, 500, "Server Internal Error");
		return;
	}

	if (sess->st || sess->awaiting_answer) {
		(void)sip_treplyf(NULL, NULL, sip, msg, false,
				  500, "Server Internal Error",
				  "Retry-After: 5\r\n"
				  "Content-Length: 0\r\n"
				  "\r\n");
		return;
	}

	if (sess->req) {
		(void)sip_treply(NULL, sip, msg, 491, "Request Pending");
		return;
	}

	err = sess->offerh(&desc, msg, sess->arg);
	if (err) {
		(void)sip_reply(sip, msg, 488, str_error(err, m, sizeof(m)));
		return;
	}

	(void)sip_dialog_update(sess->dlg, msg);
	(void)sipsess_reply_2xx(sess, msg, 200, "OK", desc,
				NULL, NULL);

	/* pending modifications considered outdated;
	   sdp may have changed in above exchange */
	sess->desc = mem_deref(sess->desc);
	sess->modify_pending = false;
	tmr_cancel(&sess->tmr);
	mem_deref(desc);
}
예제 #25
0
파일: str.c 프로젝트: doug16rogers/dr
/* ------------------------------------------------------------------------- */
str_t str_reverse(str_t str) {
    if (!str_error(str)) {
        const int kHalfLen = str->len / 2;
        char* data = str->data;
        char b;
        int i = 0;
        int k = 0;
        for (i = 0, k = str->len - 1; i < kHalfLen; ++i, --k) {
            b = data[i];
            data[i] = data[k];
            data[k] = b;
        }
    }
    return str;
}   /* str_reverse() */
예제 #26
0
/**
 * Send Get Idle request to the HID device.
 *
 * @param[in] hid_dev HID device to send the request to.
 * @param[out] duration Duration value (multiplicate by 4 to get real duration
 *                      in miliseconds).
 *
 * @retval EOK if successful.
 * @retval EINVAL if no HID device is given.
 * @return Other value inherited from one of functions 
 *         usb_pipe_start_session(), usb_pipe_end_session(),
 *         usb_control_request_set().
 */
int usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t *duration)
{
	if (ctrl_pipe == NULL) {
		usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
		return EINVAL;
	}
	
	if (iface_no < 0) {
		usb_log_warning("usbhid_req_set_report(): no interface given."
		    "\n");
		return EINVAL;
	}
	
	/*
	 * No need for checking other parameters, as they are checked in
	 * the called function (usb_control_request_set()).
	 */
	
	int rc;

	usb_log_debug("Sending Get Idle request to the device ("
	    "iface: %d).\n", iface_no);
	
	uint16_t value = 0;
	uint8_t buffer[1];
	size_t actual_size = 0;
	
	rc = usb_control_request_get(ctrl_pipe, 
	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
	    USB_HIDREQ_GET_IDLE, value, iface_no, buffer, 1, 
	    &actual_size);

	if (rc != EOK) {
		usb_log_warning("Error sending Get Idle request to the device: "
		    "%s.\n", str_error(rc));
		return rc;
	}
	
	if (actual_size != 1) {
		usb_log_warning("Wrong data size: %zu, expected: 1.\n",
			actual_size);
		return ELIMIT;
	}
	
	*duration = buffer[0];
	
	return EOK;
}
예제 #27
0
/** Initialize a new ddf driver instance for uhci hc and hub.
 *
 * @param[in] device DDF instance of the device to initialize.
 * @return Error code.
 */
int uhci_dev_add(ddf_dev_t *device)
{
	usb_log_debug2("uhci_dev_add() called\n");
	assert(device);

	const int ret = device_setup_uhci(device);
	if (ret != EOK) {
		usb_log_error("Failed to initialize UHCI driver: %s.\n",
		    str_error(ret));
	} else {
		usb_log_info("Controlling new UHCI device '%s'.\n",
		    ddf_dev_get_name(device));
	}

	return ret;
}
예제 #28
0
/** Perform SCSI Read command on USB mass storage device.
 *
 * @param mfun		Mass storage function
 * @param ba		Address of first block
 * @param nblocks	Number of blocks to read
 *
 * @return		Error code
 */
int usbmast_read(usbmast_fun_t *mfun, uint64_t ba, size_t nblocks, void *buf)
{
	scsi_cmd_t cmd;
	scsi_cdb_read_10_t cdb;
	int rc;

	if (ba > UINT32_MAX)
		return ELIMIT;

	if (nblocks > UINT16_MAX)
		return ELIMIT;

	memset(&cdb, 0, sizeof(cdb));
	cdb.op_code = SCSI_CMD_READ_10;
	cdb.lba = host2uint32_t_be(ba);
	cdb.xfer_len = host2uint16_t_be(nblocks);

	memset(&cmd, 0, sizeof(cmd));
	cmd.cdb = &cdb;
	cmd.cdb_size = sizeof(cdb);
	cmd.data_in = buf;
	cmd.data_in_size = nblocks * mfun->block_size;

	rc = usbmast_run_cmd(mfun, &cmd);

        if (rc != EOK) {
		usb_log_error("Read (10) transport failed, device %s: %s.\n",
		   mfun->mdev->ddf_dev->name, str_error(rc));
		return rc;
	}

	if (cmd.status != CMDS_GOOD) {
		usb_log_error("Read (10) command failed, device %s.\n",
		   mfun->mdev->ddf_dev->name);
		return EIO;
	}

	if (cmd.rcvd_size < nblocks * mfun->block_size) {
		usb_log_error("SCSI Read response too short (%zu).\n",
		    cmd.rcvd_size);
		return EIO;
	}

	return EOK;
}
예제 #29
0
static void fault_event(ipc_callid_t callid, ipc_call_t *call)
{
	const char *fname;
	char *s_taskid;
	int rc;

	task_id_t taskid;
	uintptr_t thread;

	taskid = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
	thread = IPC_GET_ARG3(*call);

	if (asprintf(&s_taskid, "%" PRIu64, taskid) < 0) {
		printf("Memory allocation failed.\n");
		return;
	}

	printf(NAME ": Task %" PRIu64 " fault in thread %p.\n", taskid,
	    (void *) thread);

	fname = "/app/taskdump";

#ifdef CONFIG_WRITE_CORE_FILES
	char *dump_fname;

	if (asprintf(&dump_fname, "/data/core%" PRIu64, taskid) < 0) {
		printf("Memory allocation failed.\n");
		return;
	}

	printf(NAME ": Executing %s -c %s -t %s\n", fname, dump_fname, s_taskid);
	rc = task_spawnl(NULL, fname, fname, "-c", dump_fname, "-t", s_taskid,
	    NULL);
#else
	printf(NAME ": Executing %s -t %s\n", fname, s_taskid);
	rc = task_spawnl(NULL, fname, fname, "-t", s_taskid, NULL);
#endif
	if (rc != EOK) {
		printf("%s: Error spawning %s (%s).\n", NAME, fname,
		    str_error(rc));
	}
}
예제 #30
0
/** Perform SCSI Read Capacity command on USB mass storage device.
 *
 * @param mfun		Mass storage function
 * @param nblocks	Output, number of blocks
 * @param block_size	Output, block size in bytes
 *
 * @return		Error code.
 */
int usbmast_read_capacity(usbmast_fun_t *mfun, uint32_t *nblocks,
    uint32_t *block_size)
{
	scsi_cmd_t cmd;
	scsi_cdb_read_capacity_10_t cdb;
	scsi_read_capacity_10_data_t data;
	int rc;

	memset(&cdb, 0, sizeof(cdb));
	cdb.op_code = SCSI_CMD_READ_CAPACITY_10;

	memset(&cmd, 0, sizeof(cmd));
	cmd.cdb = &cdb;
	cmd.cdb_size = sizeof(cdb);
	cmd.data_in = &data;
	cmd.data_in_size = sizeof(data);

	rc = usbmast_run_cmd(mfun, &cmd);

        if (rc != EOK) {
		usb_log_error("Read Capacity (10) transport failed, device %s: %s.\n",
		   mfun->mdev->ddf_dev->name, str_error(rc));
		return rc;
	}

	if (cmd.status != CMDS_GOOD) {
		usb_log_error("Read Capacity (10) command failed, device %s.\n",
		   mfun->mdev->ddf_dev->name);
		return EIO;
	}

	if (cmd.rcvd_size < sizeof(data)) {
		usb_log_error("SCSI Read Capacity response too short (%zu).\n",
		    cmd.rcvd_size);
		return EIO;
	}

	*nblocks = uint32_t_be2host(data.last_lba) + 1;
	*block_size = uint32_t_be2host(data.block_size);

	return EOK;
}