예제 #1
0
/* send / receive functions */
uint16_t
ptp_ptpip_sendreq(PTPParams *params, PTPContainer *req)
{
    ssize_t         ret;
    uint32_t        len = 18+req->Nparam*4;
    unsigned char       *request = malloc(len);

    //ptp_ptpip_check_event (params);

    htod32a(&request[ptpip_type],PTPIP_CMD_REQUEST);
    htod32a(&request[ptpip_len],len);
    htod32a(&request[ptpip_cmd_dataphase],1);   /* FIXME: dataphase handling */
    htod16a(&request[ptpip_cmd_code],req->Code);
    htod32a(&request[ptpip_cmd_transid],req->Transaction_ID);

    switch (req->Nparam)
    {
    case 5:
        htod32a(&request[ptpip_cmd_param5],req->Param5);

    case 4:
        htod32a(&request[ptpip_cmd_param4],req->Param4);

    case 3:
        htod32a(&request[ptpip_cmd_param3],req->Param3);

    case 2:
        htod32a(&request[ptpip_cmd_param2],req->Param2);

    case 1:
        htod32a(&request[ptpip_cmd_param1],req->Param1);

    case 0:
    default:
        break;
    }

    VitaMTP_Log(VitaMTP_DEBUG, "ptpip/oprequest\n");

    if (MASK_SET(g_VitaMTP_logmask, VitaMTP_DEBUG))
    {
        VitaMTP_hex_dump(request, len, 16);
    }

    ret = write(params->cmdfd, request, len);
    free(request);

    if (ret == -1)
        perror("sendreq/write to cmdfd");

    if (ret != len)
    {
        VitaMTP_Log(VitaMTP_ERROR, "ptpip: ptp_ptpip_sendreq() len =%d but ret=%zd\n", len, ret);
        return PTP_RC_OK;
    }

    return PTP_RC_OK;
}
예제 #2
0
파일: ptpip.c 프로젝트: FooFeeK/libgphoto2
static uint16_t
ptp_ptpip_init_command_request (PTPParams* params)
{
	char		hostname[100];
	unsigned char*	cmdrequest;
	unsigned int	i;
	int 		len, ret;
	unsigned char	guid[16];
	
	ptp_nikon_getptpipguid(guid);
	if (gethostname (hostname, sizeof(hostname)))
		return PTP_RC_GeneralError;
	len = ptpip_initcmd_name + (strlen(hostname)+1)*2 + 4;

	cmdrequest = malloc(len);
	htod32a(&cmdrequest[ptpip_type],PTPIP_INIT_COMMAND_REQUEST);
	htod32a(&cmdrequest[ptpip_len],len);

	memcpy(&cmdrequest[ptpip_initcmd_guid], guid, 16);
	for (i=0;i<strlen(hostname)+1;i++) {
		/* -> ucs-2 in little endian */
		cmdrequest[ptpip_initcmd_name+i*2] = hostname[i];
		cmdrequest[ptpip_initcmd_name+i*2+1] = 0;
	}
	htod16a(&cmdrequest[ptpip_initcmd_name+(strlen(hostname)+1)*2],PTPIP_VERSION_MINOR);
	htod16a(&cmdrequest[ptpip_initcmd_name+(strlen(hostname)+1)*2+2],PTPIP_VERSION_MAJOR);

	gp_log_data ( "ptpip/init_cmd", (char*)cmdrequest, len);
	ret = write (params->cmdfd, cmdrequest, len);
	free (cmdrequest);
	if (ret == -1) {
		perror("write init cmd request");
		return PTP_RC_GeneralError;
	}
	gp_log (GP_LOG_ERROR,"ptpip/init_cmd", "return %d / len %d", ret, len);
	if (ret != len) {
		gp_log (GP_LOG_ERROR, "ptpip", "return %d vs len %d", ret, len);
		return PTP_RC_GeneralError;
	}
	return PTP_RC_OK;
}
예제 #3
0
uint16_t
ptp_usb_control_cancel_request (PTPParams *params, uint32_t transactionid) {
	Camera	*camera = ((PTPData *)params->data)->camera;
	int	ret;
	unsigned char	buffer[6];

	htod16a(&buffer[0],PTP_EC_CancelTransaction);
	htod32a(&buffer[2],transactionid);
	ret = gp_port_usb_msg_class_write (camera->port, 0x64, 0x0000, 0x0000, (char*)buffer, sizeof (buffer));
	if (ret < GP_OK)
		return PTP_ERROR_IO;
	return PTP_RC_OK;
}
예제 #4
0
파일: ptpip.c 프로젝트: FooFeeK/libgphoto2
/* send / receive functions */
uint16_t
ptp_ptpip_sendreq (PTPParams* params, PTPContainer* req)
{
	int		ret;
	int		len = 18+req->Nparam*4;
	unsigned char 	*request = malloc(len);

	ptp_ptpip_check_event (params);

	htod32a(&request[ptpip_type],PTPIP_CMD_REQUEST);
	htod32a(&request[ptpip_len],len);
	htod32a(&request[ptpip_cmd_dataphase],1);	/* FIXME: dataphase handling */
	htod16a(&request[ptpip_cmd_code],req->Code);
	htod32a(&request[ptpip_cmd_transid],req->Transaction_ID);

	switch (req->Nparam) {
	case 5: htod32a(&request[ptpip_cmd_param5],req->Param5);
	case 4: htod32a(&request[ptpip_cmd_param4],req->Param4);
	case 3: htod32a(&request[ptpip_cmd_param3],req->Param3);
	case 2: htod32a(&request[ptpip_cmd_param2],req->Param2);
	case 1: htod32a(&request[ptpip_cmd_param1],req->Param1);
	case 0:
	default:
		break;
	}
	gp_log_data ( "ptpip/oprequest", (char*)request, len);
	ret = write (params->cmdfd, request, len);
	free (request);
	if (ret == -1)
		perror ("sendreq/write to cmdfd");
	if (ret != len) {
		gp_log (GP_LOG_ERROR, "ptpip","ptp_ptpip_sendreq() len =%d but ret=%d", len, ret);
		return PTP_RC_OK;
	}
	return PTP_RC_OK;
}