Example #1
0
static void
client_thread (void *args, zctx_t *ctx, void *pipe)
{
    client_t *self = client_new (ctx, pipe);
    while (!self->stopped) {
        //  Build structure each time since self->dealer can change
        zmq_pollitem_t items [] = {
            { self->pipe, 0, ZMQ_POLLIN, 0 },
            { self->dealer, 0, ZMQ_POLLIN, 0 }
        };
        int poll_size = self->dealer? 2: 1;
        if (zmq_poll (items, poll_size, self->heartbeat * ZMQ_POLL_MSEC) == -1)
            break;              //  Context has been shut down

        //  Process incoming messages; either of these can
        //  throw events into the state machine
        if (items [0].revents & ZMQ_POLLIN)
            control_message (self);

        if (items [1].revents & ZMQ_POLLIN)
            server_message (self);

        //  Check whether server seems dead
        if (self->expires_at && zclock_time () >= self->expires_at)
            client_restart (self, NULL);
    }
    client_destroy (&self);
}
Example #2
0
void packet_control(struct timeval *tv, uint16_t index, uint16_t opcode,
					const void *data, uint16_t size)
{
	print_channel_header(tv, index, HCI_CHANNEL_CONTROL);

	control_message(opcode, data, size);
}
Example #3
0
static int read_temper1(struct usb_dev_handle *handle, char *data, int datalen)
{
	int r = control_message(handle, CTRL_REQ_TYPE, CTRL_REQ, CTRL_VALUE, 
			1, cq_temperature, sizeof(cq_temperature));
	if (r >= 0) r = 
		interrupt_read(handle, READ_ENDPOINT, data, datalen);
	
	return r;
}
Example #4
0
static int usb_switch_csr(int fd, enum mode mode)
{
	int err;

	err = control_message(fd, USB_ENDPOINT_OUT | USB_TYPE_VENDOR  |
							USB_RECIP_DEVICE,
						0, mode, 0, NULL, 0, 10000);
	if (err == 0) {
		err = -1;
		errno = EALREADY;
	} else if (errno == ETIMEDOUT)
		err = 0;

	return err;
}
Example #5
0
static int usb_switch_dell(int fd, enum mode mode)
{
	char report[] = { 0x7f, 0x00, 0x00, 0x00 };
	struct usbfs_disconnect disconnect;
	int err;

	switch (mode) {
	case HCI:
		report[1] = 0x13;
		break;
	case HID:
		report[1] = 0x14;
		break;
	}

	disconnect.interface = 0;
	disconnect.flags = USBFS_DISCONNECT_EXCEPT_DRIVER;
	strcpy(disconnect.driver, "usbfs");

	if (ioctl(fd, USBFS_IOCTL_DISCONNECT, &disconnect) < 0) {
		fprintf(stderr, "Can't claim interface: %s (%d)\n",
						strerror(errno), errno);
		return -1;
	}

	err = control_message(fd, USB_ENDPOINT_OUT | USB_TYPE_CLASS |
							USB_RECIP_INTERFACE,
				USB_REQ_SET_CONFIGURATION,
				0x7f | (0x03 << 8), 0,
				report, sizeof(report), 5000);
	if (err == 0) {
		err = -1;
		errno = EALREADY;
	} else {
		if (errno == ETIMEDOUT)
			err = 0;
	}

	return err;
}
Example #6
0
/** HPI_6000()
 * Entry point from HPIMAN
 * All calls to the HPI start here
 */
void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
{
	struct hpi_adapter_obj *pao = NULL;

	if (phm->object != HPI_OBJ_SUBSYSTEM) {
		pao = hpi_find_adapter(phm->adapter_index);
		if (!pao) {
			hpi_init_response(phr, phm->object, phm->function,
				HPI_ERROR_BAD_ADAPTER_NUMBER);
			HPI_DEBUG_LOG(DEBUG, "invalid adapter index: %d \n",
				phm->adapter_index);
			return;
		}

		/* Don't even try to communicate with crashed DSP */
		if (pao->dsp_crashed >= 10) {
			hpi_init_response(phr, phm->object, phm->function,
				HPI_ERROR_DSP_HARDWARE);
			HPI_DEBUG_LOG(DEBUG, "adapter %d dsp crashed\n",
				phm->adapter_index);
			return;
		}
	}
	/* Init default response including the size field */
	if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
		hpi_init_response(phr, phm->object, phm->function,
			HPI_ERROR_PROCESSING_MESSAGE);

	switch (phm->type) {
	case HPI_TYPE_REQUEST:
		switch (phm->object) {
		case HPI_OBJ_SUBSYSTEM:
			subsys_message(phm, phr);
			break;

		case HPI_OBJ_ADAPTER:
			phr->size =
				sizeof(struct hpi_response_header) +
				sizeof(struct hpi_adapter_res);
			adapter_message(pao, phm, phr);
			break;

		case HPI_OBJ_CONTROL:
			control_message(pao, phm, phr);
			break;

		case HPI_OBJ_OSTREAM:
			outstream_message(pao, phm, phr);
			break;

		case HPI_OBJ_ISTREAM:
			instream_message(pao, phm, phr);
			break;

		default:
			hw_message(pao, phm, phr);
			break;
		}
		break;

	default:
		phr->error = HPI_ERROR_INVALID_TYPE;
		break;
	}
}
Example #7
0
/** HPI_6000()
 * Entry point from HPIMAN
 * All calls to the HPI start here
 */
void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
{
	struct hpi_adapter_obj *pao = NULL;

	/* subsytem messages get executed by every HPI. */
	/* All other messages are ignored unless the adapter index matches */
	/* an adapter in the HPI */
	/*HPI_DEBUG_LOG(DEBUG, "O %d,F %x\n", phm->wObject, phm->wFunction); */

	/* if Dsp has crashed then do not communicate with it any more */
	if (phm->object != HPI_OBJ_SUBSYSTEM) {
		pao = hpi_find_adapter(phm->adapter_index);
		if (!pao) {
			HPI_DEBUG_LOG(DEBUG,
				" %d,%d refused, for another HPI?\n",
				phm->object, phm->function);
			return;
		}

		if (pao->dsp_crashed >= 10) {
			hpi_init_response(phr, phm->object, phm->function,
				HPI_ERROR_DSP_HARDWARE);
			HPI_DEBUG_LOG(DEBUG, " %d,%d dsp crashed.\n",
				phm->object, phm->function);
			return;
		}
	}
	/* Init default response including the size field */
	if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
		hpi_init_response(phr, phm->object, phm->function,
			HPI_ERROR_PROCESSING_MESSAGE);

	switch (phm->type) {
	case HPI_TYPE_MESSAGE:
		switch (phm->object) {
		case HPI_OBJ_SUBSYSTEM:
			subsys_message(phm, phr);
			break;

		case HPI_OBJ_ADAPTER:
			phr->size =
				sizeof(struct hpi_response_header) +
				sizeof(struct hpi_adapter_res);
			adapter_message(pao, phm, phr);
			break;

		case HPI_OBJ_CONTROL:
			control_message(pao, phm, phr);
			break;

		case HPI_OBJ_OSTREAM:
			outstream_message(pao, phm, phr);
			break;

		case HPI_OBJ_ISTREAM:
			instream_message(pao, phm, phr);
			break;

		default:
			hw_message(pao, phm, phr);
			break;
		}
		break;

	default:
		phr->error = HPI_ERROR_INVALID_TYPE;
		break;
	}
}