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