Code Sync up from tizen_2.4
[platform/core/connectivity/mtp-responder.git] / include / ptp_container.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 _PTP_CONTAINER_H_
18 #define _PTP_CONTAINER_H_
19
20 #include "mtp_datatype.h"
21
22 #define MAX_MTP_PARAMS                  5
23 #define MTP_USB_HEADER_LENGTH           12
24
25 typedef enum {
26         CONTAINER_UNDEFINED = 0x00,
27         CONTAINER_CMD_BLK,
28         CONTAINER_DATA_BLK,
29         CONTAINER_RESP_BLK,
30         CONTAINER_EVENT_BLK
31 } container_type_t;
32
33 /*
34  * A generic USB container header.
35  */
36 typedef struct {
37         mtp_uint32 len;         /* the valid container size in BYTES */
38         mtp_uint16 type;        /* Container type */
39         mtp_uint16 code;        /* Operation, response or Event code */
40         mtp_uint32 tid;         /* host generated transaction id */
41 } header_container_t;
42
43 /*
44  * A generic USB container.
45  */
46 typedef struct {
47         mtp_uint32 len;         /* the valid container size in BYTES */
48         mtp_uint16 type;        /* Container type */
49         mtp_uint16 code;        /* Operation, response or Event code */
50         mtp_uint32 tid;         /* host generated transaction id */
51         mtp_uint32 params[MAX_MTP_PARAMS];
52         mtp_uint32 no_param;
53 } cmd_container_t;
54
55 /*
56  * A USB container for sending data.
57  */
58 typedef struct {
59         mtp_uint32 len;         /* the valid container size in BYTES */
60         mtp_uint16 type;        /* Container type */
61         mtp_uint16 code;        /* Operation, response or Event code */
62         mtp_uint32 tid;         /* host generated transaction id */
63         mtp_uint32 params[MAX_MTP_PARAMS];
64         mtp_uint32 no_param;
65         mtp_uchar *data;
66 } data_container_t;
67
68 typedef cmd_container_t cmd_blk_t;
69 typedef cmd_container_t resp_blk_t;
70 typedef data_container_t data_blk_t;
71
72 void _hdlr_init_cmd_container(cmd_container_t *cntr);
73 mtp_uint32 _hdlr_get_param_cmd_container(cmd_container_t *cntr,
74                 mtp_uint32 index);
75 void _hdlr_copy_cmd_container_unknown_params(cmd_container_t *src,
76                 cmd_container_t *dst);
77 void _hdlr_copy_cmd_container(cmd_container_t *src, cmd_container_t *dst);
78 mtp_bool _hdlr_add_param_resp_container(resp_blk_t *dst, mtp_uint32 num,
79                 mtp_uint32 *params);
80 mtp_bool _hdlr_validate_cmd_container(mtp_uchar *blk, mtp_uint32 size);
81 void _hdlr_init_data_container(data_container_t *dst, mtp_uint16 code,
82                 mtp_uint32 trans_id);
83 mtp_uchar *_hdlr_alloc_buf_data_container(data_container_t *dst,
84                 mtp_uint32 bufsz, mtp_uint64 pkt_size);
85 mtp_bool _hdlr_send_data_container(data_container_t *dst);
86 mtp_bool _hdlr_send_bulk_data(mtp_uchar *dst, mtp_uint32 len);
87 mtp_bool _hdlr_rcv_data_container(data_container_t *dst, mtp_uint32 size);
88 mtp_bool _hdlr_rcv_file_in_data_container(data_container_t *dst,
89                 mtp_char *filepath, mtp_uint32 path_len);
90 mtp_uint32 _hdlr_get_payload_size(data_container_t *dst);
91 mtp_uchar *_hdlr_get_payload_data(data_container_t *dst);
92 void _hdlr_resp_container_init(cmd_container_t *dst, mtp_uint16 resp_code,
93                 mtp_uint32 tid);
94 mtp_bool _hdlr_send_resp_container(cmd_container_t *dst);
95 void _hdlr_init_event_container(cmd_container_t *dst, mtp_uint16 code,
96                 mtp_uint32 tid, mtp_uint32 param1, mtp_uint32 param2);
97 void _hdlr_init_event_container_with_param(cmd_container_t *dst,
98                 mtp_uint16 code, mtp_uint32 tid, mtp_uint32 param1, mtp_uint32 param2);
99 mtp_bool _hdlr_send_event_container(cmd_container_t *dst);
100 void _hdlr_conv_cmd_container_byte_order(cmd_container_t *dst);
101 void _hdlr_conv_data_container_byte_order(data_container_t *dst);
102
103 #endif  /* _PTP_CONTAINER_H_ */