Apply implementation for /opt/usr lazy mount
[platform/core/connectivity/mtp-responder.git] / include / util / mtp_util.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_UTIL_H_
18 #define _MTP_UTIL_H_
19
20 #include <errno.h>
21 #include "mtp_config.h"
22 #include "mtp_datatype.h"
23
24 #ifndef LOG_TAG
25 #define LOG_TAG "MTP-RESPONDER"
26 #endif /* LOG_TAG */
27 #include <dlog.h>
28
29 #define FIND_CMD_LEN                            300
30 #define FIND_CMD        "/usr/bin/find %s \\( -iname '*.jpg' -o -iname '*.gif' " \
31         "-o -iname '*.exif' -o -iname '*.png' " \
32         "-o -iname '*.mpeg' -o -iname '*.asf' " \
33         "-o -iname '*.wmv' -o -iname '*.avi' -o -iname '*.wma' " \
34         "-o -iname '*.mp3' \\) -mmin -%d >> %s"
35
36 #define DBG(format, args...) SLOGD(format, ##args)
37 #define ERR(format, args...) SLOGE(format, ##args)
38 #define DBG_SECURE(format, args...) SECURE_SLOGD(format, ##args)
39 #define ERR_SECURE(format, args...) SECURE_SLOGE(format, ##args)
40
41 #define ret_if(expr) \
42         do { \
43                 if (expr) { \
44                         ERR("(%s)", #expr); \
45                         return; \
46                 } \
47         } while (0)
48
49 #define retv_if(expr, val) \
50         do { \
51                 if (expr) { \
52                         ERR("(%s)", #expr); \
53                         return (val); \
54                 } \
55         } while (0)
56
57 #define retm_if(expr, fmt, arg...) \
58         do { \
59                 if (expr) { \
60                         ERR(fmt, ##arg); \
61                         return; \
62                 } \
63         } while (0)
64
65 #define retvm_if(expr, val, fmt, arg...) \
66         do { \
67                 if (expr) { \
68                         ERR(fmt, ##arg); \
69                         return (val); \
70                 } \
71         } while (0)
72
73 typedef enum {
74         MTP_PHONE_USB_CONNECTED = 0,
75         MTP_PHONE_USB_DISCONNECTED,
76         MTP_PHONE_MMC_INSERTED,
77         MTP_PHONE_MMC_NONE,
78         MTP_PHONE_USB_MODE_OTHER,
79         MTP_PHONE_LOCK_ON,
80         MTP_PHONE_LOCK_OFF,
81 } phone_status_t;
82
83 typedef struct {
84         phone_status_t mmc_state;
85         phone_status_t usb_state;
86         phone_status_t usb_mode_state;
87         phone_status_t lock_state;
88 } phone_state_t;
89
90 typedef enum {
91         MTP_DATA_PACKET = 1,
92         MTP_BULK_PACKET,
93         MTP_EVENT_PACKET,
94         MTP_ZLP_PACKET,
95         MTP_UNDEFINED_PACKET
96 } msg_type_t;
97
98 typedef enum {
99         MTP_STATE_STOPPED = 0,          /* stopped working */
100         MTP_STATE_INITIALIZING,         /* initializing device or enumerating*/
101         MTP_STATE_READY_SERVICE,        /* ready to handle commands */
102         MTP_STATE_ONSERVICE,            /* handling a command */
103         MTP_STATE_DATA_TRANSFER_DL,     /* file downloading */
104         MTP_STATE_DATA_PROCESSING       /* data processing */
105 } mtp_state_t;
106
107 /*
108  * PTP Cancellation Request
109  * mtp_uint16 io_code : Identifier for cancellation.
110  *      This must equal USB_PTPCANCELIO_ID.
111  * mtp_uint32 tid : Transaction to cancel.
112  */
113 typedef struct {
114         mtp_uint16 io_code;
115         mtp_uint32 tid;
116 } cancel_req_t;
117
118 /*
119  * PTP Status Request
120  * mtp_uint16 len : Total length of the status data.
121  * mtp_uint16 code : Response code
122  * mtp_uint32 params : Params depends on the status code.
123  */
124 typedef struct {
125         mtp_uint16 len;
126         mtp_uint16 code;
127         mtp_uint32 params[1];
128 } usb_status_req_t;
129
130 void _util_print_error();
131 mtp_int32 _util_get_battery_level(void);
132 mtp_bool _util_get_serial(mtp_char *serial, mtp_uint32 len);
133 void _util_get_model_name(mtp_char *model_name, mtp_uint32 len);
134 void _util_get_vendor_ext_desc(mtp_char *vendor_ext_desc, mtp_uint32 len);
135 void _util_get_device_version(mtp_char *device_version, mtp_uint32 len);
136 void _util_gen_alt_serial(mtp_char *serial, mtp_uint32 len);
137 void _util_get_usb_status(phone_status_t *val);
138 phone_status_t _util_get_local_usb_status(void);
139 void _util_set_local_usb_status(const phone_status_t val);
140 void _util_get_mmc_status(phone_status_t *val);
141 phone_status_t _util_get_local_mmc_status(void);
142 void _util_set_local_mmc_status(const phone_status_t val);
143 void _util_get_usbmode_status(phone_status_t *val);
144 phone_status_t _util_get_local_usbmode_status(void);
145 void _util_set_local_usbmode_status(const phone_status_t val);
146 void _util_get_lock_status(phone_status_t *val);
147 phone_status_t _util_get_local_lock_status(void);
148 void _util_set_local_lock_status(const phone_status_t val);
149 void _util_get_external_path(char *external_path);
150 void _util_get_internal_path(char *internal_path);
151 #endif /* _MTP_UTIL_H_ */