4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * @file restriction-helper.c
22 * @desc Helper restriction functions
26 #include "data_usage.h"
29 #include "transmission.h"
31 resourced_iface_type get_store_iftype(const u_int32_t app_classid,
32 const resourced_iface_type iftype)
34 /* We need to put RESOURCED_IFACE_ALL type into the database,
35 in case of the "tethering" because it with no iftype */
36 return (app_classid == RESOURCED_TETHERING_APP_CLASSID) ?
37 RESOURCED_IFACE_ALL : iftype;
40 resourced_restriction_state convert_to_restriction_state(
41 const enum traffic_restriction_type rst_type)
45 return RESOURCED_RESTRICTION_ACTIVATED;
47 return RESOURCED_RESTRICTION_REMOVED;
49 return RESOURCED_RESTRICTION_EXCLUDED;
51 return RESOURCED_RESTRICTION_UNKNOWN;
55 enum traffic_restriction_type convert_to_restriction_type(
56 const resourced_restriction_state rst_state)
59 case RESOURCED_RESTRICTION_ACTIVATED:
61 case RESOURCED_RESTRICTION_REMOVED:
63 case RESOURCED_RESTRICTION_EXCLUDED:
66 return RST_UNDEFINDED;
70 int check_restriction_arguments(const char *appid,
71 const resourced_net_restrictions *rst,
72 const enum traffic_restriction_type rst_type)
74 ret_value_secure_msg_if(!appid, RESOURCED_ERROR_INVALID_PARAMETER,
75 "appid is required argument\n");
77 rst_type <= RST_UNDEFINDED || rst_type >= RST_MAX_VALUE,
78 RESOURCED_ERROR_INVALID_PARAMETER,
79 "Invalid restriction_type %d\n", rst_type);
80 ret_value_msg_if(!rst, RESOURCED_ERROR_INVALID_PARAMETER,
81 "Restriction should be set\n");
82 ret_value_msg_if(rst->iftype <= RESOURCED_IFACE_UNKNOWN ||
83 rst->iftype >= RESOURCED_IFACE_LAST_ELEM,
84 RESOURCED_ERROR_INVALID_PARAMETER,
85 "Invalid restriction network interface type %d\n",
87 if (rst_type == RST_SET) {
88 ret_value_msg_if(rst->send_limit < 0,
89 RESOURCED_ERROR_INVALID_PARAMETER,
90 "Invalid send_limit %d\n", rst->send_limit);
91 ret_value_msg_if(rst->rcv_limit < 0,
92 RESOURCED_ERROR_INVALID_PARAMETER,
93 "Invalid rcv_limit %d\n", rst->rcv_limit);
94 ret_value_msg_if(rst->snd_warning_limit < 0,
95 RESOURCED_ERROR_INVALID_PARAMETER,
96 "Invalid snd_warning_limit %d\n",
97 rst->snd_warning_limit);
98 ret_value_msg_if(rst->rcv_warning_limit < 0,
99 RESOURCED_ERROR_INVALID_PARAMETER,
100 "Invalid rcv_warning_limit %d\n",
101 rst->rcv_warning_limit);
105 ret_value_msg_if(rst->roaming >= RESOURCED_ROAMING_LAST_ELEM,
106 RESOURCED_ERROR_INVALID_PARAMETER,
107 "roaming is not valid %d", rst->roaming);
108 return RESOURCED_ERROR_NONE;