pull in new policy updates
[profile/ivi/smartdevicelink.git] / src / components / policy / src / policy / include / policy / policy_types.h
1 /*
2  Copyright (c) 2013, Ford Motor Company
3  All rights reserved.
4
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7
8  Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10
11  Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following
13  disclaimer in the documentation and/or other materials provided with the
14  distribution.
15
16  Neither the name of the Ford Motor Company nor the names of its contributors
17  may be used to endorse or promote products derived from this software
18  without specific prior written permission.
19
20  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_TYPES_H_
34 #define SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_TYPES_H_
35
36 #include <string>
37 #include <vector>
38 #include <map>
39 #include <set>
40 #include "utils/shared_ptr.h"
41
42 namespace policy {
43
44 // TODO(PV): specify errors
45 enum PolicyErrorEnum {
46 };
47
48 const std::string kDefaultDeviceMacAddress = "00:00:00:00:00:00";
49 const std::string kDefaultDeviceName = "MyDevice";
50
51 /**
52  * @brief Constants for special ids in application policies section of
53  * policy table
54  */
55 const std::string kPreDataConsentId = "pre_DataConsent";
56 const std::string kDefaultId = "default";
57 const std::string kDeviceId = "device";
58
59 /*
60  *@brief Policy Services specifies Users of Updates
61  * received from cloud through mobile device
62  */
63 enum PolicyServiceTypes {
64     SERVICE_NONE = 0,
65     IVSU = 0x04,
66     POLICY = 0x07
67 };
68
69 /*
70  * @brief Status of policy table update
71  */
72 enum PolicyTableStatus {
73     StatusUpToDate = 0,
74     StatusUpdatePending,
75     StatusUpdateRequired,
76     StatusUnknown
77 };
78
79 // Code generator uses String class name, so this typedef was renamed to PTSring
80 typedef std::string PTString;
81 typedef std::vector<uint8_t> BinaryMessage;
82 typedef utils::SharedPtr<BinaryMessage> BinaryMessageSptr;
83
84 typedef std::string HMILevel;
85 typedef std::string Parameter;
86 typedef std::string RpcName;
87
88 typedef std::map<std::string, std::set<policy::HMILevel> > HMIPermissions;
89 typedef std::map<std::string, std::set<policy::Parameter> > ParameterPermissions;
90
91 struct RpcPermissions {
92     HMIPermissions hmi_permissions;
93     ParameterPermissions parameter_permissions;
94 };
95
96 typedef std::map<RpcName, RpcPermissions> Permissions;
97
98 /**
99  * @brief Typedef for use with AllowApp request/notification
100  */
101 typedef std::vector<std::string> PermissionsList;
102
103 /**
104  * @brief Typedef for getting initial application data, e.g. nickname list
105  */
106 typedef std::vector<std::string> StringArray;
107
108 enum PermitResult {
109     kRpcAllowed = 0,
110     kRpcDisallowed,
111     kRpcUserDisallowed
112 };
113
114 /**
115   * @struct Stores result of check:
116   * if HMI Level was allowed for RPC to work in
117   * and list of parameters allowed for RPC if specified in PT.
118   */
119 struct CheckPermissionResult {
120     CheckPermissionResult()
121         : hmi_level_permitted(kRpcDisallowed) {
122     }
123
124     PermitResult hmi_level_permitted;
125     utils::SharedPtr<std::vector<PTString> > list_of_allowed_params;
126 };
127
128 /**
129   @struct Holds Url string and optional policy app id.
130   */
131 struct EndpointData {
132     explicit EndpointData(const std::string& url_string = "")
133         : url(url_string)
134         , app_id("default") {}
135     std::string url;
136     std::string app_id;
137 };
138
139 typedef std::vector<EndpointData> EndpointUrls;
140
141 /**
142  * @brief Struct contains device data to be used for dialogs, generation of IDs
143  */
144 struct DeviceParams {
145     DeviceParams()
146         : device_name(kDefaultDeviceName),
147           device_mac_address(kDefaultDeviceMacAddress),
148           device_handle(0) {
149     }
150
151     std::string device_name;
152     std::string device_mac_address;
153     uint32_t device_handle;
154 };
155
156 /**
157  * @brief Stores data to be sent to HMI on application permissions change
158  */
159 struct AppPermissions {
160
161     AppPermissions(const std::string& app_id)
162         : application_id(app_id),
163           isAppPermissionsRevoked(false),
164           appRevoked(false),
165           appPermissionsConsentNeeded(false),
166           appUnauthorized(false) {
167     }
168
169     std::string application_id;
170     bool isAppPermissionsRevoked;
171     // TODO(AOleynik):  Change type according to HMI_API spec
172     std::vector<std::string> appRevokedPermissions;
173     bool appRevoked;
174     bool appPermissionsConsentNeeded;
175     bool appUnauthorized;
176     bool isSDLAllowed;
177     std::string priority;
178     DeviceParams deviceInfo;
179 };
180
181 /**
182  * @brief User consent for device data usage
183  */
184 enum DeviceConsent {
185     kDeviceAllowed = 0,
186     kDeviceDisallowed,
187     kDeviceHasNoConsent
188 };
189
190 /**
191  * @brief Struct contains parameters, which can be received during application
192  * registration and should be stored in policy table
193  */
194 struct DeviceInfo {
195     DeviceInfo()
196         : max_number_rfcom_ports(0) {
197     }
198
199     std::string hardware;
200     std::string firmware_rev;
201     std::string os;
202     std::string os_ver;
203     std::string carrier;
204     uint32_t max_number_rfcom_ports;
205 };
206
207 /**
208  * @brief User consent for functional group
209  */
210 enum GroupConsent {
211     kGroupAllowed = 0,
212     kGroupDisallowed,
213     kGroupUndefined
214 };
215
216 /**
217  * @brief Contains user permission for RPC functional group with specific name
218  * and id from DB
219  */
220 struct FunctionalGroupPermission {
221     FunctionalGroupPermission()
222         : group_id(0),
223           state(kGroupUndefined) {
224     }
225
226     std::string group_alias;
227     std::string group_name;
228     uint32_t group_id;
229     GroupConsent state;
230 };
231
232 /**
233  * @brief Contains parameters for user-defined consent for appication
234  * functional groups on given device
235  */
236 struct PermissionConsent {
237     std::string device_id;
238     std::string policy_app_id;
239     std::vector<FunctionalGroupPermission> group_permissions;
240     std::string consent_source;
241 };
242
243 /**
244  * @brief Contain data for GetUserFriendyMessage response
245  */
246 struct UserFriendlyMessage {
247     std::string message_code;
248     std::string tts;
249     std::string label;
250     std::string line1;
251     std::string line2;
252     std::string text_body;
253 };
254
255 /**
256  * @brief Types of functional groups in policy table
257  */
258 enum GroupType {
259     kTypeDefault = 0,
260     kTypeAllowed,
261     kTypeDisallowed,
262     kTypePreconsented,
263     kTypeGeneral, // means, all types above
264     kTypePreDataConsented,
265     kTypeDevice
266 };
267
268 /**
269  * @brief Array of functional group id from DB
270  */
271 typedef std::vector<uint32_t> FunctionalGroupIDs;
272
273 /**
274  * @brief Array of functional group ids sorted by types
275  */
276 typedef std::map<GroupType, FunctionalGroupIDs> FunctionalIdType;
277
278 /**
279  * @brief Array of functional group ids binded to group name (e.g.
280  * VehicleData-4) and user_consent_prompt (e.g. VehicleData)
281  */
282 typedef std::map<uint32_t, std::pair<std::string, std::string> > FunctionalGroupNames;
283
284 /**
285  * @brief Array of device ids, which are an identifiers in policy table
286  */
287 typedef std::vector<std::string> DeviceIds;
288
289 }  //  namespace policy
290
291 #endif  //  SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_TYPES_H_