⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ptp.c

📁 Media transfer protocol implementation on POSIX. Have detailed readme on how to move to windows
💻 C
📖 第 1 页 / 共 5 页
字号:
	*size = 0;	PTP_CNT_INIT(ptp);	ptp.Code	= PTP_OC_CANON_GetCustomizeData;	ptp.Param1	= themenr;	ptp.Nparam	= 1;	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); }uint16_tptp_nikon_curve_download (PTPParams* params, unsigned char **data, unsigned int *size) {	PTPContainer ptp;	*data = NULL;	*size = 0;	PTP_CNT_INIT(ptp);	ptp.Code	= PTP_OC_NIKON_CurveDownload;	ptp.Nparam	= 0;	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); }uint16_tptp_nikon_getfileinfoinblock ( PTPParams* params,	uint32_t p1, uint32_t p2, uint32_t p3,	unsigned char **data, unsigned int *size) {	PTPContainer ptp;	*data = NULL;	*size = 0;	PTP_CNT_INIT(ptp);	ptp.Code	= PTP_OC_NIKON_GetFileInfoInBlock;	ptp.Nparam	= 3;	ptp.Param1	= p1;	ptp.Param2	= p2;	ptp.Param3	= p3;	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); }/** * ptp_nikon_setcontrolmode: * * This command can switch the camera to full PC control mode. *   * params:	PTPParams* *      uint32_t mode - mode * * Return values: Some PTP_RC_* code. * **/uint16_tptp_nikon_setcontrolmode (PTPParams* params, uint32_t mode){        PTPContainer ptp;                PTP_CNT_INIT(ptp);        ptp.Code=PTP_OC_NIKON_SetControlMode;        ptp.Param1=mode;        ptp.Nparam=1;        return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_nikon_capture: * * This command captures a picture on the Nikon. *   * params:	PTPParams* *      uint32_t x - unknown parameter. seen to be -1. * * Return values: Some PTP_RC_* code. * **/uint16_tptp_nikon_capture (PTPParams* params, uint32_t x){        PTPContainer ptp;                PTP_CNT_INIT(ptp);        ptp.Code=PTP_OC_NIKON_Capture;        ptp.Param1=x;        ptp.Nparam=1;        return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_nikon_check_event: * * This command checks the event queue on the Nikon. *   * params:	PTPParams* *      PTPUSBEventContainer **event - list of usb events. *	int *evtcnt - number of usb events in event structure. * * Return values: Some PTP_RC_* code. * **/uint16_tptp_nikon_check_event (PTPParams* params, PTPUSBEventContainer** event, int* evtcnt){        PTPContainer ptp;	uint16_t ret;	unsigned char *data = NULL;	unsigned int size = 0;	PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_NIKON_CheckEvent;	ptp.Nparam=0;	*evtcnt = 0;	ret = ptp_transaction (params, &ptp, PTP_DP_GETDATA, 0, &data, &size);	if (ret == PTP_RC_OK) {		ptp_unpack_Nikon_EC (params, data, size, event, evtcnt);		free (data);	}	return ret;}/** * ptp_nikon_device_ready: * * This command checks if the device is ready. Used after * a capture. *   * params:	PTPParams* * * Return values: Some PTP_RC_* code. * **/uint16_tptp_nikon_device_ready (PTPParams* params){        PTPContainer ptp;                PTP_CNT_INIT(ptp);        ptp.Code=PTP_OC_NIKON_DeviceReady;        ptp.Nparam=0;        return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_nikon_getptpipinfo: * * This command gets the ptpip info data. *   * params:	PTPParams* *	unsigned char *data	- data *	unsigned int size	- size of returned data * * Return values: Some PTP_RC_* code. * **/uint16_tptp_nikon_getptpipinfo (PTPParams* params, unsigned char **data, unsigned int *size){        PTPContainer ptp;                PTP_CNT_INIT(ptp);        ptp.Code=PTP_OC_NIKON_GetDevicePTPIPInfo;        ptp.Nparam=0;        return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);}/** * ptp_nikon_getwifiprofilelist: * * This command gets the wifi profile list. *   * params:	PTPParams* * * Return values: Some PTP_RC_* code. * **/uint16_tptp_nikon_getwifiprofilelist (PTPParams* params){        PTPContainer ptp;	unsigned char* data;	unsigned int size;	unsigned int pos;	unsigned int profn;	unsigned int n;	char* buffer;	uint8_t len;	        PTP_CNT_INIT(ptp);        ptp.Code=PTP_OC_NIKON_GetProfileAllData;        ptp.Nparam=0;	size = 0;	data = NULL;	CHECK_PTP_RC(ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size));	if (size < 2) return PTP_RC_Undefined; /* FIXME: Add more precise error code */	params->wifi_profiles_version = data[0];	params->wifi_profiles_number = data[1];	if (params->wifi_profiles)		free(params->wifi_profiles);		params->wifi_profiles = malloc(params->wifi_profiles_number*sizeof(PTPNIKONWifiProfile));	memset(params->wifi_profiles, 0, params->wifi_profiles_number*sizeof(PTPNIKONWifiProfile));	pos = 2;	profn = 0;	while (profn < params->wifi_profiles_number && pos < size) {		if (pos+6 >= size) return PTP_RC_Undefined;		params->wifi_profiles[profn].id = data[pos++];		params->wifi_profiles[profn].valid = data[pos++];		n = dtoh32a(&data[pos]);		pos += 4;		if (pos+n+4 >= size) return PTP_RC_Undefined;		strncpy(params->wifi_profiles[profn].profile_name, (char*)&data[pos], n);		params->wifi_profiles[profn].profile_name[16] = '\0';		pos += n;		params->wifi_profiles[profn].display_order = data[pos++];		params->wifi_profiles[profn].device_type = data[pos++];		params->wifi_profiles[profn].icon_type = data[pos++];		buffer = ptp_unpack_string(params, data, pos, &len);		strncpy(params->wifi_profiles[profn].creation_date, buffer, sizeof(params->wifi_profiles[profn].creation_date));		pos += (len*2+1);		if (pos+1 >= size) return PTP_RC_Undefined;		/* FIXME: check if it is really last usage date */		buffer = ptp_unpack_string(params, data, pos, &len);		strncpy(params->wifi_profiles[profn].lastusage_date, buffer, sizeof(params->wifi_profiles[profn].lastusage_date));		pos += (len*2+1);		if (pos+5 >= size) return PTP_RC_Undefined;				n = dtoh32a(&data[pos]);		pos += 4;		if (pos+n >= size) return PTP_RC_Undefined;		strncpy(params->wifi_profiles[profn].essid, (char*)&data[pos], n);		params->wifi_profiles[profn].essid[32] = '\0';		pos += n;		pos += 1;		profn++;	}#if 0	PTPNIKONWifiProfile test;	memset(&test, 0, sizeof(PTPNIKONWifiProfile));	strcpy(test.profile_name, "MyTest");	test.icon_type = 1;	strcpy(test.essid, "nikon");	test.ip_address = 10 + 11 << 16 + 11 << 24;	test.subnet_mask = 24;	test.access_mode = 1;	test.wifi_channel = 1;	test.key_nr = 1;	ptp_nikon_writewifiprofile(params, &test);#endif	return PTP_RC_OK;}/** * ptp_nikon_deletewifiprofile: * * This command deletes a wifi profile. *   * params:	PTPParams* *	unsigned int profilenr	- profile number * * Return values: Some PTP_RC_* code. * **/uint16_tptp_nikon_deletewifiprofile (PTPParams* params, uint32_t profilenr){	PTPContainer ptp;	PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_NIKON_DeleteProfile;	ptp.Nparam=1;	ptp.Param1=profilenr;	return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_nikon_writewifiprofile: * * This command gets the ptpip info data. *   * params:	PTPParams* *	unsigned int profilenr	- profile number *	unsigned char *data	- data *	unsigned int size	- size of returned data * * Return values: Some PTP_RC_* code. * **/uint16_tptp_nikon_writewifiprofile (PTPParams* params, PTPNIKONWifiProfile* profile){	unsigned char guid[16];		PTPContainer ptp;	unsigned char buffer[1024];	unsigned char* data = buffer;	int size = 0;	int i;	uint8_t len;	int profilenr = -1;		ptp_nikon_getptpipguid(guid);	if (!params->wifi_profiles)		CHECK_PTP_RC(ptp_nikon_getwifiprofilelist(params));		for (i = 0; i < params->wifi_profiles_number; i++) {		if (!params->wifi_profiles[i].valid) {			profilenr = params->wifi_profiles[i].id;			break;		}	}		if (profilenr == -1) {		/* No free profile! */		return PTP_RC_StoreFull;	}		memset(buffer, 0, 1024);		buffer[0x00] = 0x64; /* Version */		/* Profile name */	htod32a(&buffer[0x01], 17);	/* 16 as third parameter, so there will always be a null-byte in the end */	strncpy((char*)&buffer[0x05], profile->profile_name, 16);		buffer[0x16] = 0x00; /* Display order */	buffer[0x17] = profile->device_type;	buffer[0x18] = profile->icon_type;		/* FIXME: Creation date: put a real date here */	ptp_pack_string(params, "19990909T090909", data, 0x19, &len);		/* IP parameters */	*((unsigned int*)&buffer[0x3A]) = profile->ip_address; /* Do not reverse bytes */	buffer[0x3E] = profile->subnet_mask;	*((unsigned int*)&buffer[0x3F]) = profile->gateway_address; /* Do not reverse bytes */	buffer[0x43] = profile->address_mode;		/* Wifi parameters */	buffer[0x44] = profile->access_mode;	buffer[0x45] = profile->wifi_channel;		htod32a(&buffer[0x46], 33); /* essid */	 /* 32 as third parameter, so there will always be a null-byte in the end */	strncpy((char*)&buffer[0x4A], profile->essid, 32);		buffer[0x6B] = profile->authentification;	buffer[0x6C] = profile->encryption;	htod32a(&buffer[0x6D], 64);	for (i = 0; i < 64; i++) {		buffer[0x71+i] = profile->key[i];	}	buffer[0xB1] = profile->key_nr;	memcpy(&buffer[0xB2], guid, 16);		switch(profile->encryption) {	case 1: /* WEP 64bit */		htod16a(&buffer[0xC2], 5); /* (64-24)/8 = 5 */		break;	case 2: /* WEP 128bit */		htod16a(&buffer[0xC2], 13); /* (128-24)/8 = 13 */		break;	default:		htod16a(&buffer[0xC2], 0);	}	size = 0xC4;	       	PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_NIKON_SendProfileData;	ptp.Nparam=1;	ptp.Param1=profilenr;	return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL);}/** * ptp_mtp_getobjectpropssupported: * * This command gets the object properties possible from the device. *   * params:	PTPParams* *	uint ofc		- object format code *	unsigned int *propnum	- number of elements in returned array *	uint16_t *props		- array of supported properties * * Return values: Some PTP_RC_* code. * **/uint16_tptp_mtp_getobjectpropssupported (PTPParams* params, uint16_t ofc,		 uint32_t *propnum, uint16_t **props) {        PTPContainer ptp;	uint16_t ret;	unsigned char *data = NULL;	unsigned int size = 0;                PTP_CNT_INIT(ptp);        ptp.Code=PTP_OC_MTP_GetObjectPropsSupported;        ptp.Nparam = 1;        ptp.Param1 = ofc;        ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size);	if (ret == PTP_RC_OK)        	*propnum=ptp_unpack_uint16_t_array(params,data,0,props);	free(data);	return ret;}/** * ptp_mtp_getobjectpropdesc: * * This command gets the object property description. *   * params:	PTPParams* *	uint16_t opc	- object property code *	uint16_t ofc	- object format code * * Return values: Some PTP_RC_* code. * **/uint16_tptp_mtp_getobjectpropdesc (	PTPParams* params, uint16_t opc, uint16_t ofc, PTPObjectPropDesc *opd) {        PTPContainer ptp;	uint16_t ret;	unsigned char *data = NULL;	unsigned int size = 0;                PTP_CNT_INIT(ptp);        ptp.Code=PTP_OC_MTP_GetObjectPropDesc;        ptp.Nparam = 2;        ptp.Param1 = opc;        ptp.Param2 = ofc;        ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size);	if (ret == PTP_RC_OK)		ptp_unpack_OPD (params, data, opd, size);	free(data);	return ret;}/** * ptp_mtp_getobjectpropvalue: * * This command gets the object properties of an object handle. *   * params:	PTPParams* *	uint32_t objectid	- object format code *	uint16_t opc		- object prop code * * Return values: Some PTP_RC_* code. * **/uint16_tptp_mtp_getobjectpropvalue (	PTPParams* params, uint32_t oid, uint16_t opc,	PTPPropertyValue *value, uint16_t datatype) {        PTPContainer ptp;	uint16_t ret;	unsigned char *data = NULL;	unsigned int size = 0;	int offset = 0;                PTP_CNT_INIT(ptp);        ptp.Code=PTP_OC_MTP_GetObjectPropValue;        ptp.Nparam = 2;        ptp.Param1 = oid;        ptp.Param2 = opc;        ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size);	if (ret == PTP_RC_OK)		ptp_unpack_DPV(params, data, &offset, size, value, datatype);	free(data);	return ret;}/** * ptp_mtp_setobjectpropvalue: * * This command gets the object properties of an object handle. *   * params:	PTPParams* *	uint32_t objectid	- object format code *	uint16_t opc		- object prop code * * Return values: Some PTP_RC_* code. * **/uint16_tptp_mtp_setobjectpropvalue (	PTPParams* params, uint32_t oid, uint16_t opc,	PTPPropertyValue *value, uint16_t datatype) {        PTPContainer ptp;	uint16_t ret;	unsigned char *data = NULL;	unsigned int size ;                PTP_CNT_INIT(ptp);        ptp.Code=PTP_OC_MTP_SetObjectPropValue;        ptp.Nparam = 2;        ptp.Param1 = oid;        ptp.Param2 = opc;	size = ptp_pack_DPV(params, value, &data, datatype);        ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL);	free(data);	return ret;}uint16_tptp

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -