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"
22 #include "network-mptcp-intf.h"
25 static const char* __convert_mptcp_path_manager_enum_to_str(connection_mptcp_path_manager_e pm)
28 case CONNECTION_MPTCP_PM_UNKNOWN:
30 case CONNECTION_MPTCP_PM_DEFAULT:
32 case CONNECTION_MPTCP_PM_FULLMESH:
38 static connection_mptcp_path_manager_e __convert_mptcp_path_manager_str_to_enum(char* pm)
40 if (g_strcmp0(pm, "default") == 0)
41 return CONNECTION_MPTCP_PM_DEFAULT;
42 if (g_strcmp0(pm, "fullmesh") == 0)
43 return CONNECTION_MPTCP_PM_FULLMESH;
44 return CONNECTION_MPTCP_PM_UNKNOWN; //LCOV_EXCL_LINE
47 static const char* __convert_mptcp_scheduler_enum_to_str(connection_mptcp_scheduler_e scheduler)
50 case CONNECTION_MPTCP_SCHEDULER_UNKNOWN:
52 case CONNECTION_MPTCP_SCHEDULER_DEFAULT:
54 case CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN:
60 static connection_mptcp_scheduler_e __convert_mptcp_scheduler_str_to_enum(char *scheduler)
62 if (g_strcmp0(scheduler, "default") == 0)
63 return CONNECTION_MPTCP_SCHEDULER_DEFAULT;
64 if (g_strcmp0(scheduler, "roundrobin") == 0)
65 return CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN;
66 return CONNECTION_MPTCP_SCHEDULER_UNKNOWN; //LCOV_EXCL_LINE
69 gboolean _connection_libnet_mptcp_supported(connection_handle_s *conn_handle)
72 gboolean support = false;
74 rv = net_mptcp_supported(conn_handle->network_info_handle, &support);
75 if (rv == NET_ERR_ACCESS_DENIED) {
76 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
78 } else if (rv != NET_ERR_NONE) {
79 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable MPTCP [%d]", rv); //LCOV_EXCL_LINE
86 int _connection_libnet_mptcp_enable(connection_handle_s *conn_handle, connection_mptcp_enable_e enable)
90 rv = net_mptcp_set_enabled(conn_handle->network_info_handle, (int)enable);
91 if (rv == NET_ERR_ACCESS_DENIED) {
92 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
93 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
94 } else if (rv != NET_ERR_NONE) {
95 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable MPTCP [%d]", rv); //LCOV_EXCL_LINE
96 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
99 return CONNECTION_ERROR_NONE;
102 int _connection_libnet_mptcp_get_enabled(connection_handle_s *conn_handle, connection_mptcp_enable_e* enable)
107 rv = net_mptcp_get_enabled(conn_handle->network_info_handle, &result);
108 if (rv == NET_ERR_ACCESS_DENIED) {
109 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
110 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
111 } else if (rv != NET_ERR_NONE) {
112 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MPTCP enabled state [%d]", rv); //LCOV_EXCL_LINE
113 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
116 *enable = (connection_mptcp_enable_e)result;
117 return CONNECTION_ERROR_NONE;
121 int _connection_libnet_mptcp_set_path_manager(connection_handle_s *conn_handle, connection_mptcp_path_manager_e pm)
124 const char *str = __convert_mptcp_path_manager_enum_to_str(pm);
127 CONNECTION_LOG(CONNECTION_ERROR, "Invalid Parameter");
128 return CONNECTION_ERROR_INVALID_PARAMETER;
131 CONNECTION_LOG(CONNECTION_ERROR, "set path manager %s", str);
133 rv = net_mptcp_set_path_manager(conn_handle->network_info_handle, str);
134 if (rv == NET_ERR_ACCESS_DENIED) {
135 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
136 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
137 } else if (rv != NET_ERR_NONE) {
138 CONNECTION_LOG(CONNECTION_ERROR, "Failed to set MPTCP path manager [%d]", rv); //LCOV_EXCL_LINE
139 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
142 return CONNECTION_ERROR_NONE;
145 int _connection_libnet_mptcp_get_path_manager(connection_handle_s *conn_handle, connection_mptcp_path_manager_e* pm)
150 rv = net_mptcp_get_path_manager(conn_handle->network_info_handle, &result);
151 if (rv == NET_ERR_ACCESS_DENIED) {
152 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
153 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
154 } else if (rv != NET_ERR_NONE) {
155 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MPTCP path manager [%d]", rv); //LCOV_EXCL_LINE
156 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
159 CONNECTION_LOG(CONNECTION_ERROR, "get path manager %s", result);
160 *pm = __convert_mptcp_path_manager_str_to_enum(result);
162 return CONNECTION_ERROR_NONE;
166 int _connection_libnet_mptcp_set_scheduler(connection_handle_s *conn_handle, connection_mptcp_scheduler_e scheduler)
169 const char *str = __convert_mptcp_scheduler_enum_to_str(scheduler);
172 CONNECTION_LOG(CONNECTION_ERROR, "Invalid Parameter");
173 return CONNECTION_ERROR_INVALID_PARAMETER;
176 CONNECTION_LOG(CONNECTION_ERROR, "set scheduler %s", str);
178 rv = net_mptcp_set_scheduler(conn_handle->network_info_handle, str);
179 if (rv == NET_ERR_ACCESS_DENIED) {
180 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
181 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
182 } else if (rv != NET_ERR_NONE) {
183 CONNECTION_LOG(CONNECTION_ERROR, "Failed to set MPTCP scheduler [%d]", rv); //LCOV_EXCL_LINE
184 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
187 return CONNECTION_ERROR_NONE;
190 int _connection_libnet_mptcp_get_scheduler(connection_handle_s *conn_handle, connection_mptcp_scheduler_e* scheduler)
195 rv = net_mptcp_get_scheduler(conn_handle->network_info_handle, &result);
196 if (rv == NET_ERR_ACCESS_DENIED) {
197 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
198 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
199 } else if (rv != NET_ERR_NONE) {
200 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MPTCP scheduler [%d]", rv); //LCOV_EXCL_LINE
201 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
204 CONNECTION_LOG(CONNECTION_ERROR, "get scheduler %s", result);
205 *scheduler = __convert_mptcp_scheduler_str_to_enum(result);
207 return CONNECTION_ERROR_NONE;