📄 ptp.c
字号:
ptp_debug(params,"PTP: Obtaining DeviceInfo"); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_GetDeviceInfo; ptp.Nparam=0; ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &di); if (ret == PTP_RC_OK) ptp_unpack_DI(params, di, deviceinfo); free(di); return ret;}/** * ptp_opensession: * params: PTPParams* * session - session number * * Establishes a new session. * * Return values: Some PTP_RC_* code. **/uint16_tptp_opensession (PTPParams* params, uint32_t session){ uint16_t ret; PTPContainer ptp; ptp_debug(params,"PTP: Opening session 0x%08x", session); /* SessonID field of the operation dataset should always be set to 0 for OpenSession request! */ params->session_id=0x00000000; /* TransactionID should be set to 0 also! */ params->transaction_id=0x0000000; PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_OpenSession; ptp.Param1=session; ptp.Nparam=1; ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL); /* now set the global session id to current session number */ params->session_id=session; return ret;}/** * ptp_closesession: * params: PTPParams* * * Closes session. * * Return values: Some PTP_RC_* code. **/uint16_tptp_closesession (PTPParams* params){ PTPContainer ptp; ptp_debug(params,"PTP: Closing session"); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_CloseSession; ptp.Nparam=0; return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL);}/** * ptp_getststorageids: * params: PTPParams* * * Gets array of StorageiDs and fills the storageids structure. * * Return values: Some PTP_RC_* code. **/uint16_tptp_getstorageids (PTPParams* params, PTPStorageIDs* storageids){ uint16_t ret; PTPContainer ptp; char* sids=NULL; ptp_debug(params,"PTP: Obtaining StorageIDs"); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_GetStorageIDs; ptp.Nparam=0; ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &sids); if (ret == PTP_RC_OK) ptp_unpack_SIDs(params, sids, storageids); free(sids); return ret;}/** * ptp_getststorageinfo: * params: PTPParams* * storageid - StorageID * * Gets StorageInfo dataset of desired storage and fills storageinfo * structure. * * Return values: Some PTP_RC_* code. **/uint16_tptp_getstorageinfo (PTPParams* params, uint32_t storageid, PTPStorageInfo* storageinfo){ uint16_t ret; PTPContainer ptp; char* si=NULL; ptp_debug(params,"PTP: Obtaining StorageInfo for storage 0x%08x", storageid); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_GetStorageInfo; ptp.Param1=storageid; ptp.Nparam=1; ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &si); if (ret == PTP_RC_OK) ptp_unpack_SI(params, si, storageinfo); free(si); return ret;}/** * ptp_getobjecthandles: * params: PTPParams* * storage - StorageID * objectformatcode - ObjectFormatCode (optional) * associationOH - ObjectHandle of Association for * wich a list of children is desired * (optional) * objecthandles - pointer to structute * * Fills objecthandles with structure returned by device. * * Return values: Some PTP_RC_* code. **/uint16_tptp_getobjecthandles (PTPParams* params, uint32_t storage, uint32_t objectformatcode, uint32_t associationOH, PTPObjectHandles* objecthandles){ uint16_t ret; PTPContainer ptp; char* oh=NULL; ptp_debug(params,"PTP: Obtaining ObjectHandles"); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_GetObjectHandles; ptp.Param1=storage; ptp.Param2=objectformatcode; ptp.Param3=associationOH; ptp.Nparam=3; ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &oh); if (ret == PTP_RC_OK) ptp_unpack_OH(params, oh, objecthandles); free(oh); return ret;}/** * ptp_ptp_getobjectinfo: * params: PTPParams* * handle - object Handler * objectinfo - pointer to PTPObjectInfo structure * * Fills objectinfo structure with appropriate data of object given by * hander. * * Return values: Some PTP_RC_* code. **/uint16_tptp_getobjectinfo (PTPParams* params, uint32_t handle, PTPObjectInfo* objectinfo){ uint16_t ret; PTPContainer ptp; char* oi=NULL; ptp_debug(params,"PTP: Obtaining ObjectInfo for object 0x%08x", handle); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_GetObjectInfo; ptp.Param1=handle; ptp.Nparam=1; ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &oi); if (ret == PTP_RC_OK) ptp_unpack_OI(params, oi, objectinfo); free(oi); return ret;}uint16_tptp_getobject (PTPParams* params, uint32_t handle, char** object){ PTPContainer ptp; ptp_debug(params,"PTP: Downloading Object 0x%08x", handle); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_GetObject; ptp.Param1=handle; ptp.Nparam=1; return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object);}uint16_tptp_getthumb (PTPParams* params, uint32_t handle, char** object){ PTPContainer ptp; ptp_debug(params,"PTP: Downloading Thumbnail from object 0x%08x", handle); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_GetThumb; ptp.Param1=handle; ptp.Nparam=1; return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object);}/** * ptp_deleteobject: * params: PTPParams* * handle - object handle * ofc - object format code (optional) * * Deletes desired objects. * * Return values: Some PTP_RC_* code. **/uint16_tptp_deleteobject (PTPParams* params, uint32_t handle, uint32_t ofc){ PTPContainer ptp; ptp_debug(params,"PTP: Deleting Object 0x%08x", handle); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_DeleteObject; ptp.Param1=handle; ptp.Param2=ofc; ptp.Nparam=2; return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL);}/** * ptp_sendobjectinfo: * params: PTPParams* * uint32_t* store - destination StorageID on Responder * uint32_t* parenthandle - Parent ObjectHandle on responder * uint32_t* handle - see Return values * PTPObjectInfo* objectinfo- ObjectInfo that is to be sent * * Sends ObjectInfo of file that is to be sent via SendFileObject. * * Return values: Some PTP_RC_* code. * Upon success : uint32_t* store - Responder StorageID in which * object will be stored * uint32_t* parenthandle- Responder Parent ObjectHandle * in which the object will be stored * uint32_t* handle - Responder's reserved ObjectHandle * for the incoming object **/uint16_tptp_sendobjectinfo (PTPParams* params, uint32_t* store, uint32_t* parenthandle, uint32_t* handle, PTPObjectInfo* objectinfo){ uint16_t ret; PTPContainer ptp; char* oidata=NULL; uint32_t size; ptp_debug(params,"PTP: Sending ObjectInfo; parent object 0x%08x", *parenthandle); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_SendObjectInfo; ptp.Param1=*store; ptp.Param2=*parenthandle; ptp.Nparam=2; size=ptp_pack_OI(params, objectinfo, &oidata); ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &oidata); free(oidata); *store=ptp.Param1; *parenthandle=ptp.Param2; *handle=ptp.Param3; return ret;}/** * ptp_sendobject: * params: PTPParams* * char* object - contains the object that is to be sent * uint32_t size - object size * * Sends object to Responder. * * Return values: Some PTP_RC_* code. * */uint16_tptp_sendobject (PTPParams* params, char* object, uint32_t size){ PTPContainer ptp; ptp_debug(params,"PTP: Sending Object of size %u", size); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_SendObject; ptp.Nparam=0; return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &object);}/** * ptp_initiatecapture: * params: PTPParams* * storageid - destination StorageID on Responder * ofc - object format code * * Causes device to initiate the capture of one or more new data objects * according to its current device properties, storing the data into store * indicated by storageid. If storageid is 0x00000000, the object(s) will * be stored in a store that is determined by the capturing device. * The capturing of new data objects is an asynchronous operation. * * Return values: Some PTP_RC_* code. **/uint16_tptp_initiatecapture (PTPParams* params, uint32_t storageid, uint32_t ofc){ PTPContainer ptp; ptp_debug(params,"PTP: Initiating Capture"); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_InitiateCapture; ptp.Param1=storageid; ptp.Param2=ofc; ptp.Nparam=2; return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL);}uint16_tptp_getdevicepropdesc (PTPParams* params, uint16_t propcode, PTPDevicePropDesc* devicepropertydesc){ PTPContainer ptp; uint16_t ret; char* dpd=NULL; ptp_debug(params, "PTP: Obtaining Device Property Description for property 0x%04x", propcode); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_GetDevicePropDesc; ptp.Param1=propcode; ptp.Nparam=1; ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpd); if (ret == PTP_RC_OK) ptp_unpack_DPD(params, dpd, devicepropertydesc); free(dpd); return ret;}uint16_tptp_getdevicepropvalue (PTPParams* params, uint16_t propcode, void** value, uint16_t datatype){ PTPContainer ptp; uint16_t ret; char* dpv=NULL; ptp_debug(params, "PTP: Obtaining Device Property Value for property 0x%04x", propcode); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_GetDevicePropValue; ptp.Param1=propcode; ptp.Nparam=1; ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpv); if (ret == PTP_RC_OK) ptp_unpack_DPV(params, dpv, value, datatype); free(dpv); return ret;}uint16_tptp_setdevicepropvalue (PTPParams* params, uint16_t propcode, void* value, uint16_t datatype){ PTPContainer ptp; uint16_t ret; uint32_t size; char* dpv=NULL; ptp_debug(params, "PTP: Setting Device Property Value for property 0x%04x", propcode); PTP_CNT_INIT(ptp); ptp.Code=PTP_OC_SetDevicePropValue; ptp.Param1=propcode; ptp.Nparam=1; size=ptp_pack_DPV(params, value, &dpv, datatype); ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &dpv); free(dpv); return ret;}/** * ptp_ek_sendfileobjectinfo: * params: PTPParams* * uint32_t* store - destination StorageID on Responder * uint32_t* parenthandle - Parent ObjectHandle on responder * uint32_t* handle - see Return values * PTPObjectInfo* objectinfo- ObjectInfo that is to be sent * * Sends ObjectInfo of file that is to be sent via SendFileObject. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -