Exemple #1
0
__u16 ptp_closesession(struct ptpfs_sb_info *sb)
{
    struct ptp_container ptp;
    memset(&ptp,0,sizeof(ptp));

    ptp.code=PTP_OC_CloseSession;
    ptp.nparam=0;
    return ptp_transaction(sb, &ptp, PTP_DP_NODATA, 0, NULL);
}
Exemple #2
0
/**
 * Sends the PC client's status.
 * 
 * @param device a pointer to the device.
 * @param status the client's status
 * @return the PTP result code that the Vita returns.
 * @see VITA_HOST_STATUS
 */
uint16_t VitaMTP_SendHostStatus(LIBMTP_mtpdevice_t *device, uint32_t status){
    PTPParams *params = (PTPParams*)device->params;
    PTPContainer ptp;
    
    PTP_CNT_INIT(ptp);
    ptp.Code = PTP_OC_VITA_SendHostStatus;
    ptp.Nparam = 1;
    ptp.Param1 = status;
    return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, 0);
}
Exemple #3
0
__u16 ptp_deleteobject(struct ptpfs_sb_info *sb, __u32 handle, __u32 ofc)
{
    struct ptp_container ptp;
    memset(&ptp,0,sizeof(ptp));
    ptp.code=PTP_OC_DeleteObject;
    ptp.param1=handle;
    ptp.param2=ofc;
    ptp.nparam=2;
    return ptp_transaction(sb, &ptp, PTP_DP_NODATA, 0, NULL);
}
Exemple #4
0
__u16
ptp_getobject (struct ptpfs_sb_info *sb, __u32 handle, struct ptp_data_buffer *data)
{
    struct ptp_container ptp;
    memset(&ptp,0,sizeof(ptp));

    ptp.code=PTP_OC_GetObject;
    ptp.param1=handle;
    ptp.nparam=1;
    return ptp_transaction(sb, &ptp, PTP_DP_GETDATA, 0, data);
}
Exemple #5
0
/**
 * Tell the Vita that the current event is being processed and not 
 * to time out on us.
 * 
 * @param device a pointer to the device.
 * @param event_id the unique ID sent by the Vita with the event.
 */
uint16_t VitaMTP_KeepAlive(LIBMTP_mtpdevice_t *device, uint32_t event_id){
    PTPParams *params = (PTPParams*)device->params;
    PTPContainer ptp;
    
    PTP_CNT_INIT(ptp);
    ptp.Code = PTP_OC_VITA_KeepAlive;
    ptp.Nparam = 1;
    ptp.Param1 = event_id;
    
    return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, 0);
}
Exemple #6
0
/**
 * Sends the number of objects to list.
 * 
 * @param device a pointer to the device.
 * @param event_id the unique ID sent by the Vita with the event.
 * @param num the number of objects to list.
 * @return the PTP result code that the Vita returns.
 * @see VitaMTP_SendObjectMetadata()
 */
uint16_t VitaMTP_SendNumOfObject(LIBMTP_mtpdevice_t *device, uint32_t event_id, uint32_t num){
    PTPParams *params = (PTPParams*)device->params;
    PTPContainer ptp;
    
    PTP_CNT_INIT(ptp);
    ptp.Code = PTP_OC_VITA_SendNumOfObject;
    ptp.Nparam = 2;
    ptp.Param1 = event_id;
    ptp.Param2 = num;
    
    return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, 0);
}
Exemple #7
0
/**
 * Sends a command with a data send phase and a event id
 * 
 * The Vita uses the PC as a slave. It sends an event asking the PC to 
 * send a command, and it complies, sending the command with the event_id 
 * as its first parameter. Most commands only has this paramater, so this 
 * function it called internally to make our lives easier.
 * @param device a pointer to the device.
 * @param event_id the unique ID sent by the Vita with the event.
 * @param code the command to send.
 * @param data the array of data to send.
 * @param len the length of "data".
 * @return the PTP result code that the Vita returns.
 * @see VitaMTP_GetData()
 */
uint16_t VitaMTP_SendData(LIBMTP_mtpdevice_t *device, uint32_t event_id, uint32_t code, unsigned char* data, unsigned int len){
    PTPParams *params = (PTPParams*)device->params;
    PTPContainer ptp;
    
    PTP_CNT_INIT(ptp);
    ptp.Code = code;
    ptp.Nparam = 1;
    ptp.Param1 = event_id;
    
    uint16_t ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, len, &data, 0);
    return ret;
}
Exemple #8
0
/**
 * Same as VitaMTP_ReportResult(), but also sends another integer
 * as a parameter.
 * 
 * @param device a pointer to the device.
 * @param event_id the unique ID sent by the Vita with the event.
 * @param result a PTP result code to send
 * @param param a parameter to send
 * @return the PTP result code that the Vita returns.
 * @see VitaMTP_ReportResult()
 */
uint16_t VitaMTP_ReportResultWithParam(LIBMTP_mtpdevice_t *device, uint32_t event_id, uint16_t result, uint32_t param){
    PTPParams *params = (PTPParams*)device->params;
    PTPContainer ptp;
    
    PTP_CNT_INIT(ptp);
    ptp.Code = PTP_OC_VITA_ReportResult;
    ptp.Nparam = 3;
    ptp.Param1 = event_id;
    ptp.Param2 = result;
    ptp.Param3 = param;
    return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, 0);
}
Exemple #9
0
__u16 ptp_getstorageids(struct ptpfs_sb_info *sb, struct ptp_storage_ids* storageids)
{
    __u16 ret;
    struct ptp_container ptp;
    struct ptp_data_buffer data;

    memset(&ptp,0,sizeof(ptp));
    memset(&data,0,sizeof(data));
    ptp.code=PTP_OC_GetStorageIDs;
    ptp.nparam=0;
    ret=ptp_transaction(sb, &ptp, PTP_DP_GETDATA, 0, &data);
    if (ret == PTP_RC_OK) ptp_unpack_SIDs(sb, &data, storageids);
    ptp_free_data_buffer(&data);
    return ret;
}
Exemple #10
0
/**
 * Called during initialization to send information abouthe PC.
 * 
 * @param device a pointer to the device.
 * @param info a pointer to the initiator_info structure.
 *  You should get this with new_initiator_info()
 * @return the PTP result code that the Vita returns.
 * @see new_initiator_info()
 */
uint16_t VitaMTP_SendInitiatorInfo(LIBMTP_mtpdevice_t *device, initiator_info_t *info){
    char *data;
    int len = 0;
    if(initiator_info_to_xml(info, &data, &len) < 0)
        return PTP_RC_GeneralError;
    PTPParams *params = (PTPParams*)device->params;
    PTPContainer ptp;
    
    PTP_CNT_INIT(ptp);
    ptp.Code = PTP_OC_VITA_SendInitiatorInfo;
    ptp.Nparam = 0;
    uint16_t ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, len, (unsigned char**)&data, 0); // plus one for null terminator, which is required on the vita's side
    free(data);
    return ret;
}
Exemple #11
0
__u16 ptp_getdeviceinfo(struct ptpfs_sb_info *sb, struct ptp_device_info* deviceinfo)
{
    __u16 ret;
    struct ptp_container ptp;
    struct ptp_data_buffer data;

    memset(&ptp,0,sizeof(ptp));
    memset(&data,0,sizeof(data));

    ptp.code=PTP_OC_GetDeviceInfo;
    ptp.nparam=0;
    ret=ptp_transaction(sb, &ptp, PTP_DP_GETDATA, 0, &data);
    if (ret == PTP_RC_OK) ptp_unpack_DI(sb, &data, deviceinfo);
    ptp_free_data_buffer(&data);
    return ret;
}
Exemple #12
0
__u16 ptp_sendobject(struct ptpfs_sb_info *sb, struct ptp_data_buffer* object, __u32 size)
{
    struct ptp_container ptp;
    memset(&ptp,0,sizeof(ptp));

    if (ptp_operation_issupported(sb,PTP_OC_EK_SendFileObject))
    {
        ptp.code=PTP_OC_EK_SendFileObject;
    }
    else
    {
        ptp.code=PTP_OC_SendObject;
    }
    ptp.nparam=0;

    return ptp_transaction(sb, &ptp, PTP_DP_SENDDATA, size, object);
}
Exemple #13
0
__u16 ptp_getobjectinfo (struct ptpfs_sb_info *sb, __u32 handle,
                         struct ptp_object_info* objectinfo)
{
    __u16 ret;
    struct ptp_container ptp;
    struct ptp_data_buffer data;

    memset(&ptp,0,sizeof(ptp));
    memset(&data,0,sizeof(data));

    ptp.code=PTP_OC_GetObjectInfo;
    ptp.param1=handle;
    ptp.nparam=1;
    ret=ptp_transaction(sb, &ptp, PTP_DP_GETDATA, 0, &data);
    if (ret == PTP_RC_OK) ptp_unpack_OI(sb, &data, objectinfo);
    ptp_free_data_buffer(&data);
    return ret;
}
Exemple #14
0
__u16 ptp_opensession(struct ptpfs_sb_info *sb, __u32 session) 
{
    __u16 ret;
    struct ptp_container ptp;
    memset(&ptp,0,sizeof(ptp));

    /* SessonID field of the operation dataset should always be set to 0 for OpenSession request! */
    sb->session_id=0x00000000;
    /* TransactionID should be set to 0 also! */
    sb->transaction_id=0x0000000;

    ptp.code=PTP_OC_OpenSession;
    ptp.param1=session;
    ptp.nparam=1;

    ret=ptp_transaction(sb, &ptp, PTP_DP_NODATA, 0, NULL);
    /* now set the global session id to current session number */
    sb->session_id=session;
    return ret;
}
Exemple #15
0
/**
 * Called during initialization to get Vita information.
 * 
 * @param device a pointer to the device.
 * @param info a pointer to the vita_info struct to fill
 * @return the PTP result code that the Vita returns.
 */
uint16_t VitaMTP_GetVitaInfo(LIBMTP_mtpdevice_t *device, vita_info_t *info){
    PTPParams *params = (PTPParams*)device->params;
    PTPContainer ptp;
    int ret;
    unsigned char *data;
    unsigned int len;
    
    PTP_CNT_INIT(ptp);
    ptp.Code = PTP_OC_VITA_GetVitaInfo;
    ptp.Nparam = 0;
    ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len);
    if(ret != PTP_RC_OK || len == 0){
        return ret;
    }
    if(vita_info_from_xml(info, (char*)data+sizeof(uint32_t), len-sizeof(uint32_t)) != 0){ // strip header
        return PTP_RC_GeneralError;
    }
    free(data);
    return ret;
}
Exemple #16
0
__u16 ptp_getobjecthandles (struct ptpfs_sb_info *sb, __u32 storage,
                            __u32 objectformatcode, __u32 associationOH,
                            struct ptp_object_handles* objecthandles)
{
    __u16 ret;
    struct ptp_container ptp;
    struct ptp_data_buffer data;

    memset(&ptp,0,sizeof(ptp));
    memset(&data,0,sizeof(data));

    ptp.code=PTP_OC_GetObjectHandles;
    ptp.param1=storage;
    ptp.param2=objectformatcode;
    ptp.param3=associationOH;
    ptp.nparam=3;
    ret=ptp_transaction(sb, &ptp, PTP_DP_GETDATA, 0, &data);
    if (ret == PTP_RC_OK) ptp_unpack_OH(sb, &data, objecthandles);
    ptp_free_data_buffer(&data);
    return ret;
}
Exemple #17
0
/**
 * ptp_sendobjectinfo:
 * params:	PTPParams*
 *		__u32* store		- destination StorageID on Responder
 *		__u32* parenthandle 	- Parent ObjectHandle on responder
 * 		__u32* 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 : __u32* store	- Responder StorageID in which
 *					  object will be stored
 *		  __u32* parenthandle- Responder Parent ObjectHandle
 *					  in which the object will be stored
 *		  __u32* handle	- Responder's reserved ObjectHandle
 *					  for the incoming object
 **/
__u16
ptp_sendobjectinfo (struct ptpfs_sb_info *sb, __u32* store, 
                    __u32* parenthandle, __u32* handle,
                    struct ptp_object_info* objectinfo)
{
    __u16 ret;
    struct ptp_container ptp;
    struct ptp_data_buffer data;
    struct ptp_block block;

    memset(&ptp,0,sizeof(ptp));
    memset(&data,0,sizeof(data));

    if (ptp_operation_issupported(sb,PTP_OC_EK_SendFileObjectInfo))
    {
        ptp.code=PTP_OC_EK_SendFileObjectInfo;
    }
    else
    {
        ptp.code=PTP_OC_SendObjectInfo;
    }
    ptp.param1=*store;
    ptp.param2=*parenthandle;
    ptp.nparam=2;

    data.num_blocks = 1;
    data.blocks = &block;
    block.block_size = ptp_pack_OI(sb, objectinfo, &block.block);
    ret=ptp_transaction(sb, &ptp, PTP_DP_SENDDATA, block.block_size, &data); 
    kfree(block.block);

    *store=ptp.param1;
    *parenthandle=ptp.param2;
    *handle=ptp.param3; 

    return ret;
}
Exemple #18
0
/**
 * Gets a MTP properties list for an object
 * 
 * @param device a pointer to the device.
 * @param handle a object handle.
 * @param props a pointer to a MTPProperties array to be created.
 *  Dynamically allocated.
 * @param nrofprops number of elements in the props array.
 */
uint16_t VitaMTP_GetObjectPropList(LIBMTP_mtpdevice_t *device, uint32_t handle, MTPProperties** props, int* nrofprops){
    uint16_t ret;
    PTPParams *params = (PTPParams*)device->params;
    PTPContainer ptp;
    unsigned char* opldata = NULL;
    unsigned int oplsize;
    
    PTP_CNT_INIT(ptp);
    ptp.Code = PTP_OC_MTP_GetObjPropList;
    ptp.Param1 = handle;
    ptp.Param2 = 0x00000000;
    ptp.Param3 = 0x00000000;
    ptp.Param4 = 0x00000001;
    ptp.Param5 = 0x00000000;
    ptp.Nparam = 5;
    ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &opldata, &oplsize);  
    if(ret == PTP_RC_OK){
        *nrofprops = ptp_unpack_MTPProperties(params, opldata, props, oplsize);
    }
    if(opldata){
        free(opldata);
    }
    return ret;
}