From d6fd8a3effbb045309c462bd0d61244dbd32a149 Mon Sep 17 00:00:00 2001 From: Mariusz Woloszyn Date: Fri, 17 May 2002 13:56:34 +0000 Subject: [PATCH] Added support for testing deviceinfo information. library.c: addred workaround for devices not supporting getstorageids. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@4519 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/ptp/library.c | 31 +++++++++++++++++++++++++------ camlibs/ptp/ptp-pack.c | 31 ++++++++++++++++++++++--------- camlibs/ptp/ptp.c | 14 ++++++++++++++ camlibs/ptp/ptp.h | 6 +++++- 4 files changed, 66 insertions(+), 16 deletions(-) diff --git a/camlibs/ptp/library.c b/camlibs/ptp/library.c index 5ba16e07e..fa476a4b4 100644 --- a/camlibs/ptp/library.c +++ b/camlibs/ptp/library.c @@ -583,7 +583,8 @@ file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, for (i = 0; i < params->handles.n; i++) { if (params->objectinfo[i].ParentObject==parent) if (params->objectinfo[i].ObjectFormat != PTP_OFC_Association) - if (params->objectinfo[i].StorageID == storage) + if (!ptp_operation_issupported(params,PTP_OC_GetStorageIDs) + || (params->objectinfo[i].StorageID == storage)) CR (gp_list_append (list, params->objectinfo[i].Filename, NULL)); } @@ -602,14 +603,22 @@ folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, /* add storage pseudofolders in root folder */ if (!strcmp(folder, "/")) { PTPStorageIDs storageids; - CPR (context, ptp_getstorageids(params, - &storageids)); + + if (ptp_operation_issupported(params,PTP_OC_GetStorageIDs)) { + CPR (context, ptp_getstorageids(params, + &storageids)); + } else { + storageids.n = 1; + storageids.storage[0]=0xdeadbeef; + } for (i=0; ihandles.n; i++) { if (params->objectinfo[i].ParentObject==parent) - if (params->objectinfo[i].StorageID == storage) + if ((!ptp_operation_issupported(params,PTP_OC_GetStorageIDs)) || + (params->objectinfo[i].StorageID == storage)) if (params->objectinfo[i].ObjectFormat==PTP_OFC_Association && params->objectinfo[i].AssociationType==PTP_AT_GenericFolder) CR (gp_list_append (list, params->objectinfo[i].Filename, NULL)); @@ -926,6 +936,8 @@ init_ptp_fs (Camera *camera, GPContext *context) camera->pl->params.objectinfo = (PTPObjectInfo*)malloc(sizeof(PTPObjectInfo)* camera->pl->params.handles.n); + // XXX !!! + //memset (camera->pl->params.objectinfo,0,sizeof(PTPObjectInfo)); for (i = 0; i < camera->pl->params.handles.n; i++) { CPR (context, ptp_getobjectinfo(&camera->pl->params, camera->pl->params.handles.handler[i], @@ -1005,6 +1017,13 @@ camera_init (Camera *camera, GPContext *context) /* init internal ptp objectfiles (required for fs implementation) */ init_ptp_fs (camera, context); + CPR(context, ptp_getdeviceinfo(&camera->pl->params, + &camera->pl->params.deviceinfo)); + + GP_DEBUG ("Manufacturer: %s",camera->pl->params.deviceinfo.Manufacturer); + GP_DEBUG ("model: %s", camera->pl->params.deviceinfo.Model); + GP_DEBUG ("device version: %s", camera->pl->params.deviceinfo.DeviceVersion); + { PTPEvent event; // ptp_event_check (&camera->pl->params,event); diff --git a/camlibs/ptp/ptp-pack.c b/camlibs/ptp/ptp-pack.c index fbf545e23..439899b7c 100644 --- a/camlibs/ptp/ptp-pack.c +++ b/camlibs/ptp/ptp-pack.c @@ -110,12 +110,12 @@ ptp_unpack_uint32_t_array(PTPParams *params, PTPReq *req, uint16_t offset, uint3 static inline uint32_t ptp_unpack_uint16_t_array(PTPParams *params, PTPReq *req, uint16_t offset, uint16_t **array) { - uint32_t n, i=0; + uint32_t n, i=1; n=dtoh32a(&req->data[offset]); *array = malloc (n*sizeof(uint16_t)); - while (n>i) { - (*array)[i]=dtoh16a(&req->data[offset+(sizeof(uint16_t)*(i+1))]); + while (n>=i) { + (*array)[i-1]=dtoh16a(&req->data[offset+(sizeof(uint16_t)*i)]); i++; } return n; @@ -134,7 +134,7 @@ static inline void ptp_unpack_DI (PTPParams *params, PTPReq *req, PTPDeviceInfo *di) { uint8_t len, totallen; - + di->StaqndardVersion = dtoh16a(&req->data[PTP_di_StandardVersion]); di->VendorExtensionID = dtoh32a(&req->data[PTP_di_VendorExtensionID]); @@ -149,27 +149,40 @@ ptp_unpack_DI (PTPParams *params, PTPReq *req, PTPDeviceInfo *di) di->OperationsSupported_len = ptp_unpack_uint16_t_array(params, req, PTP_di_OperationsSupported+totallen, &di->OperationsSupported); - totallen=totallen+di->OperationsSupported_len+sizeof(uint32_t); + totallen=totallen+di->OperationsSupported_len*sizeof(uint16_t)+sizeof(uint32_t); di->EventsSupported_len = ptp_unpack_uint16_t_array(params, req, PTP_di_OperationsSupported+totallen, &di->EventsSupported); - totallen=totallen+di->EventsSupported_len+sizeof(uint32_t); + totallen=totallen+di->EventsSupported_len*sizeof(uint16_t)+sizeof(uint32_t); di->DevicePropertiesSupported_len = ptp_unpack_uint16_t_array(params, req, PTP_di_OperationsSupported+totallen, &di->DevicePropertiesSupported); - totallen=totallen+di->DevicePropertiesSupported_len+sizeof(uint32_t); + totallen=totallen+di->DevicePropertiesSupported_len*sizeof(uint16_t)+sizeof(uint32_t); di->CaptureFormats_len = ptp_unpack_uint16_t_array(params, req, PTP_di_OperationsSupported+totallen, &di->CaptureFormats); - totallen=totallen+di->CaptureFormats_len+sizeof(uint32_t); + totallen=totallen+di->CaptureFormats_len*sizeof(uint16_t)+sizeof(uint32_t); di->ImageFormats_len = ptp_unpack_uint16_t_array(params, req, PTP_di_OperationsSupported+totallen, &di->ImageFormats); - totallen=totallen+di->ImageFormats_len+sizeof(uint32_t); + totallen=totallen+di->ImageFormats_len*sizeof(uint16_t)+sizeof(uint32_t); di->Manufacturer = ptp_unpack_string(params, req, PTP_di_OperationsSupported+totallen, &len); + totallen+=len*2+1; + di->Model = ptp_unpack_string(params, req, + PTP_di_OperationsSupported+totallen, + &len); + totallen+=len*2+1; + di->DeviceVersion = ptp_unpack_string(params, req, + PTP_di_OperationsSupported+totallen, + &len); + totallen+=len*2+1; + di->SerialNumber = ptp_unpack_string(params, req, + PTP_di_OperationsSupported+totallen, + &len); + } // ObjectHandles array pack/unpack diff --git a/camlibs/ptp/ptp.c b/camlibs/ptp/ptp.c index 2721550ae..94b7fb709 100644 --- a/camlibs/ptp/ptp.c +++ b/camlibs/ptp/ptp.c @@ -581,3 +581,17 @@ ptp_ek_sendfileobject (PTPParams* params, PTPReq* object, uint32_t size) PTP_DP_SENDDATA | PTP_RQ_PARAM0, size, object); } + +/* devinfo testing functions */ + +int +ptp_operation_issupported(PTPParams* params, uint16_t operation) +{ + int i=0; + + for (;ideviceinfo.OperationsSupported_len;i++) { + if (params->deviceinfo.OperationsSupported[i]==operation) + return 1; + } + return 0; +} diff --git a/camlibs/ptp/ptp.h b/camlibs/ptp/ptp.h index d5d122ebb..5141f9f96 100644 --- a/camlibs/ptp/ptp.h +++ b/camlibs/ptp/ptp.h @@ -182,7 +182,7 @@ struct _PTPDeviceInfo { uint16_t *ImageFormats; char *Manufacturer; char *Model; - char *DeviceVersionl; + char *DeviceVersion; char *SerialNumber; }; typedef struct _PTPDeviceInfo PTPDeviceInfo; @@ -353,6 +353,7 @@ struct _PTPParams { /* internal structures used by ptp driver */ PTPObjectHandles handles; PTPObjectInfo * objectinfo; + PTPDeviceInfo deviceinfo; }; typedef struct _PTPParams PTPParams; @@ -395,4 +396,7 @@ uint16_t ptp_ek_sendfileobjectinfo (PTPParams* params, uint32_t* store, PTPObjectInfo* objectinfo); uint16_t ptp_ek_sendfileobject (PTPParams* params, PTPReq* object, uint32_t size); + +int ptp_operation_issupported (PTPParams* params, uint16_t operation); + #endif /* __PTP_H__ */