2 * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "net_connection_private.h"
20 #include "connection_extension.h"
21 #include "net_connection_mptcp_private.h"
23 static const char* __convert_mptcp_path_manager_enum_to_str(connection_mptcp_path_manager_e pm)
26 case CONNECTION_MPTCP_PM_UNKNOWN:
28 case CONNECTION_MPTCP_PM_DEFAULT:
30 case CONNECTION_MPTCP_PM_FULLMESH:
36 static connection_mptcp_path_manager_e __convert_mptcp_path_manager_str_to_enum(char* pm)
38 if (g_strcmp0(pm, "default") == 0)
39 return CONNECTION_MPTCP_PM_DEFAULT;
40 if (g_strcmp0(pm, "fullmesh") == 0)
41 return CONNECTION_MPTCP_PM_FULLMESH;
42 return CONNECTION_MPTCP_PM_UNKNOWN;
45 static const char* __convert_mptcp_scheduler_enum_to_str(connection_mptcp_scheduler_e scheduler)
48 case CONNECTION_MPTCP_SCHEDULER_UNKNOWN:
50 case CONNECTION_MPTCP_SCHEDULER_DEFAULT:
52 case CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN:
58 static connection_mptcp_scheduler_e __convert_mptcp_scheduler_str_to_enum(char *scheduler)
60 if (g_strcmp0(scheduler, "default") == 0)
61 return CONNECTION_MPTCP_SCHEDULER_DEFAULT;
62 if (g_strcmp0(scheduler, "roundrobin") == 0)
63 return CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN;
64 return CONNECTION_MPTCP_SCHEDULER_UNKNOWN;
67 gboolean _connection_libnet_mptcp_supported()
70 gboolean support = false;
72 rv = net_mptcp_supported(&support);
73 if (rv == NET_ERR_ACCESS_DENIED) {
74 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
76 } else if (rv != NET_ERR_NONE) {
77 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable MPTCP [%d]", rv);
84 int _connection_libnet_mptcp_enable(connection_mptcp_enable_e enable)
88 rv = net_mptcp_set_enable((int)enable);
89 if (rv == NET_ERR_ACCESS_DENIED) {
90 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
91 return CONNECTION_ERROR_PERMISSION_DENIED;
92 } else if (rv != NET_ERR_NONE) {
93 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable MPTCP [%d]", rv);
94 return CONNECTION_ERROR_OPERATION_FAILED;
97 return CONNECTION_ERROR_NONE;
100 int _connection_libnet_mptcp_get_enabled(connection_mptcp_enable_e* enable)
105 rv = net_mptcp_get_enabled(&result);
106 if (rv == NET_ERR_ACCESS_DENIED) {
107 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
108 return CONNECTION_ERROR_PERMISSION_DENIED;
109 } else if (rv != NET_ERR_NONE) {
110 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MPTCP enabled state [%d]", rv);
111 return CONNECTION_ERROR_OPERATION_FAILED;
114 *enable = (connection_mptcp_enable_e)result;
115 return CONNECTION_ERROR_NONE;
119 int _connection_libnet_mptcp_set_path_manager(connection_mptcp_path_manager_e pm)
122 const char* str = __convert_mptcp_path_manager_enum_to_str(pm);
123 CONNECTION_LOG(CONNECTION_ERROR, "set path manager %s", str);
126 CONNECTION_LOG(CONNECTION_ERROR, "Invalid Parameter");
127 return CONNECTION_ERROR_INVALID_PARAMETER;
130 rv = net_mptcp_set_path_manager(str);
131 if (rv == NET_ERR_ACCESS_DENIED) {
132 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
133 return CONNECTION_ERROR_PERMISSION_DENIED;
134 } else if (rv != NET_ERR_NONE) {
135 CONNECTION_LOG(CONNECTION_ERROR, "Failed to set MPTCP path manager [%d]", rv);
136 return CONNECTION_ERROR_OPERATION_FAILED;
139 return CONNECTION_ERROR_NONE;
142 int _connection_libnet_mptcp_get_path_manager(connection_mptcp_path_manager_e* pm)
147 rv = net_mptcp_get_path_manager(&result);
148 if (rv == NET_ERR_ACCESS_DENIED) {
149 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
150 return CONNECTION_ERROR_PERMISSION_DENIED;
151 } else if (rv != NET_ERR_NONE) {
152 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MPTCP path manager [%d]", rv);
153 return CONNECTION_ERROR_OPERATION_FAILED;
156 CONNECTION_LOG(CONNECTION_ERROR, "get path manager %s", result);
157 *pm = __convert_mptcp_path_manager_str_to_enum(result);
159 return CONNECTION_ERROR_NONE;
163 int _connection_libnet_mptcp_set_scheduler(connection_mptcp_scheduler_e scheduler)
166 const char *str = __convert_mptcp_scheduler_enum_to_str(scheduler);
167 CONNECTION_LOG(CONNECTION_ERROR, "set scheduler %s", str);
170 CONNECTION_LOG(CONNECTION_ERROR, "Invalid Parameter");
171 return CONNECTION_ERROR_INVALID_PARAMETER;
174 rv = net_mptcp_set_scheduler(str);
175 if (rv == NET_ERR_ACCESS_DENIED) {
176 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
177 return CONNECTION_ERROR_PERMISSION_DENIED;
178 } else if (rv != NET_ERR_NONE) {
179 CONNECTION_LOG(CONNECTION_ERROR, "Failed to set MPTCP scheduler [%d]", rv);
180 return CONNECTION_ERROR_OPERATION_FAILED;
183 return CONNECTION_ERROR_NONE;
186 int _connection_libnet_mptcp_get_scheduler(connection_mptcp_scheduler_e* scheduler)
191 rv = net_mptcp_get_scheduler(&result);
192 if (rv == NET_ERR_ACCESS_DENIED) {
193 CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
194 return CONNECTION_ERROR_PERMISSION_DENIED;
195 } else if (rv != NET_ERR_NONE) {
196 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MPTCP scheduler [%d]", rv);
197 return CONNECTION_ERROR_OPERATION_FAILED;
200 CONNECTION_LOG(CONNECTION_ERROR, "get scheduler %s", result);
201 *scheduler = __convert_mptcp_scheduler_str_to_enum(result);
203 return CONNECTION_ERROR_NONE;