Пример #1
0
static uint16_t
ptp_ptpip_event (PTPParams* params, PTPContainer* event, int wait)
{
	fd_set		infds;
	struct timeval	timeout;
	int ret;
	unsigned char*	data = NULL;
	PTPIPHeader	hdr;
	int n;

	while (1) {
		FD_ZERO(&infds);
		FD_SET(params->evtfd, &infds);
		timeout.tv_sec = 0;
		if (wait == PTP_EVENT_CHECK_FAST)
			timeout.tv_usec = 1;
		else
			timeout.tv_usec = 1000; /* 1/1000 second  .. perhaps wait longer? */

		ret = select (params->evtfd+1, &infds, NULL, NULL, &timeout);
		if (1 != ret) {
			if (-1 == ret) {
				gp_log (GP_LOG_DEBUG,"ptpip/event", "select returned error, errno is %d", errno);
				return PTP_ERROR_IO;
			}
			return PTP_ERROR_TIMEOUT;
		}

		ret = ptp_ptpip_evt_read (params, &hdr, &data);
		if (ret != PTP_RC_OK)
			return ret;
		gp_log (GP_LOG_DEBUG,"ptpip/event", "hdr type %d, length %d", hdr.type, hdr.length);

		if (dtoh32(hdr.type) == PTPIP_EVENT) {
			break;
		}

		/* TODO: Handle cancel transaction and ping/pong
		 * If not PTPIP_EVENT, process it and wait for next PTPIP_EVENT
		 */
		gp_log (GP_LOG_ERROR, "ptpip/event", "unknown/unhandled event type %d", dtoh32(hdr.type));
	}

	event->Code		= dtoh16a(&data[ptpip_event_code]);
	event->Transaction_ID	= dtoh32a(&data[ptpip_event_transid]);
	n = (dtoh32(hdr.length) - sizeof(hdr) - ptpip_event_param1)/sizeof(uint32_t);
	switch (n) {
	case 3: event->Param3 = dtoh32a(&data[ptpip_event_param3]);
	case 2: event->Param2 = dtoh32a(&data[ptpip_event_param2]);
	case 1: event->Param1 = dtoh32a(&data[ptpip_event_param1]);
	case 0: break;
	default:
		gp_log( GP_LOG_ERROR, "ptpip/event", "response got %d parameters?", n);
		break;
	}
	free (data);
	return PTP_RC_OK;
}
Пример #2
0
static uint16_t
ptp_ptpip_init_event_ack (PTPParams* params)
{
	PTPIPHeader	hdr;
	unsigned char	*data = NULL;
	uint16_t	ret;

	ret = ptp_ptpip_evt_read (params, &hdr, &data);
	if (ret != PTP_RC_OK)
		return ret;
	free (data);
	if (hdr.type != dtoh32(PTPIP_INIT_EVENT_ACK)) {
		gp_log (GP_LOG_ERROR, "ptpip", "bad type returned %d\n", htod32(hdr.type));
		return PTP_RC_GeneralError;
	}
	return PTP_RC_OK;
}
Пример #3
0
static inline uint16_t
ptp_ptpip_event(PTPParams *params, PTPContainer *event, int wait)
{
    fd_set      infds;
    struct timeval  timeout;
    int ret;
    unsigned char  *data = NULL;
    PTPIPHeader hdr;
    int n;

    while (1)
    {
        if (wait == PTP_EVENT_CHECK_FAST)
        {
            FD_ZERO(&infds);
            FD_SET(params->evtfd, &infds);
            timeout.tv_sec = 0;
            timeout.tv_usec = 1;

            if (1 != select(params->evtfd+1, &infds, NULL, NULL, &timeout))
                return PTP_RC_OK;
        }

        ret = ptp_ptpip_evt_read(params, &hdr, &data);

        if (ret != PTP_RC_OK)
            return ret;

        VitaMTP_Log(VitaMTP_DEBUG,"ptpip/event: hdr type %d, length %d\n", hdr.type, hdr.length);

        if (dtoh32(hdr.type) == PTPIP_EVENT)
        {
            break;
        }

        // TODO: Handle cancel transaction and ping/pong
        VitaMTP_Log(VitaMTP_ERROR, "ptpip/event: unknown/unhandled event type %d\n", hdr.type);
    }

    event->Code     = dtoh16a(&data[ptpip_event_code]);
    event->Transaction_ID   = dtoh32a(&data[ptpip_event_transid]);
    n = (dtoh32(hdr.length) - sizeof(hdr) - ptpip_event_param1)/sizeof(uint32_t);

    switch (n)
    {
    case 3:
        event->Param3 = dtoh32a(&data[ptpip_event_param3]);

    case 2:
        event->Param2 = dtoh32a(&data[ptpip_event_param2]);

    case 1:
        event->Param1 = dtoh32a(&data[ptpip_event_param1]);

    case 0:
        break;

    default:
        VitaMTP_Log(VitaMTP_ERROR, "ptpip/event: response got %d parameters?\n", n);
        break;
    }

    free(data);
    return PTP_RC_OK;
}