Sync code with Tizen 3.0 branch
[platform/core/connectivity/mtp-responder.git] / include / mtp_cmd_handler.h
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef _MTP_CMD_HANDLER_H_
18 #define _MTP_CMD_HANDLER_H_
19
20 #include "mtp_object.h"
21 #include "mtp_device.h"
22 #include "ptp_container.h"
23 #include "mtp_event_handler.h"
24
25 #ifdef MTP_SUPPORT_PRINT_COMMAND
26 #define MTP_MAX_CMD_LENGTH 40
27 #endif /* MTP_SUPPORT_PRINT_COMMAND */
28
29 /*
30  * A structure for containing the object infomation. It is used for saving
31  * information in between paired operations like send_obj_info
32  * and send_object.
33  * @see obj_info
34  */
35 typedef struct {
36         mtp_uint32 store_id;    /* The storage ID. */
37         mtp_uint32 h_parent;    /* Handle of the parent object */
38         /* Reserved Handle for the incoming object. */
39         mtp_uint32 obj_handle;
40         /* Indicates if the ObjectInfo dataset is valid. */
41         mtp_bool is_valid;
42         mtp_bool is_data_sent;  /* Indicates whether data was actually sent */
43         mtp_uint64 file_size;
44         mtp_obj_t *obj;         /* Object containing info for SendObject */
45 } data_4send_object_t;
46
47 /*
48  * A structure for handling the operations of the MTP protocol.
49  * It is the main driving structure behind the MTP protocol handling. The
50  * MTP device contains device information and other data buffers.
51  *
52  * @see mtp_device
53  * @see cmd_blk_t
54  * @see data4_send_obj
55  */
56 typedef struct {
57         cmd_container_t usb_cmd;        /* A USB command container block. */
58         /* Data saved during paired operations: SendObjectInfo/SendObject. */
59         data_4send_object_t data4_send_obj;
60         mtp_uint32 session_id;          /* Current session ID. */
61         mtp_uint32 last_opcode;         /* Current transaction ID. */
62         mtp_uint16 last_fmt_code;       /* Last Format Code */
63 } mtp_handler_t;
64
65 typedef struct {
66         mtp_uint32 recent_tid;
67         mtp_uint32 cur_index;
68         mtp_uint32 mod;
69 } wmp_meta_info_t;
70
71 /*
72  * This structure specifies the buffer of Mtp.
73  */
74 typedef struct {
75         mtp_char cmd_buf[MTP_MAX_CMD_BLOCK_SIZE];
76         mtp_char header_buf[MTP_USB_HEADER_LENGTH];
77         mtp_uint32 cmd_size;
78         mtp_uint32 data_size;
79         mtp_uint32 data_count;
80         FILE* fhandle;  /* for temporary mtp file */
81         mtp_char *filepath;
82         mtp_uint32 file_size;
83         mtp_uint32 size_remaining;
84         /* PC-> Device file transfer user space buffering till 512K*/
85         mtp_char *temp_buff;
86 } temp_file_struct_t;
87
88 typedef struct {
89         temp_file_struct_t ftemp_st;
90         mtp_handler_t hdlr;
91         wmp_meta_info_t meta_info;
92 } mtp_mgr_t;
93
94 void _cmd_hdlr_reset_cmd(mtp_handler_t *hdlr);
95 mtp_bool _cmd_hdlr_send_response(mtp_handler_t *hdlr, mtp_uint16 resp,
96                 mtp_uint32 num_param, mtp_uint32 *params);
97 mtp_bool _cmd_hdlr_send_response_code(mtp_handler_t *hdlr, mtp_uint16 resp);
98 void _receive_mq_data_cb(mtp_char *buffer, mtp_int32 buf_len);
99
100 #endif /* _MTP_CMD_HANDLER_H_ */