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"
24 static const char* __convert_mptcp_path_manager_enum_to_str(connection_mptcp_path_manager_e pm)
27 case CONNECTION_MPTCP_PM_UNKNOWN:
29 case CONNECTION_MPTCP_PM_DEFAULT:
31 case CONNECTION_MPTCP_PM_FULLMESH:
37 static connection_mptcp_path_manager_e __convert_mptcp_path_manager_str_to_enum(char* pm)
39 if (g_strcmp0(pm, "default") == 0)
40 return CONNECTION_MPTCP_PM_DEFAULT;
41 if (g_strcmp0(pm, "fullmesh") == 0)
42 return CONNECTION_MPTCP_PM_FULLMESH;
43 return CONNECTION_MPTCP_PM_UNKNOWN; //LCOV_EXCL_LINE
46 static const char* __convert_mptcp_scheduler_enum_to_str(connection_mptcp_scheduler_e scheduler)
49 case CONNECTION_MPTCP_SCHEDULER_UNKNOWN:
51 case CONNECTION_MPTCP_SCHEDULER_DEFAULT:
53 case CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN:
59 static connection_mptcp_scheduler_e __convert_mptcp_scheduler_str_to_enum(char *scheduler)
61 if (g_strcmp0(scheduler, "default") == 0)
62 return CONNECTION_MPTCP_SCHEDULER_DEFAULT;
63 if (g_strcmp0(scheduler, "roundrobin") == 0)
64 return CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN;
65 return CONNECTION_MPTCP_SCHEDULER_UNKNOWN; //LCOV_EXCL_LINE
68 gboolean _connection_libnet_mptcp_supported(connection_handle_s *conn_handle)
71 gboolean support = false;
73 rv = net_mptcp_supported(conn_handle->network_info_handle, &support);
74 if (rv == NET_ERR_ACCESS_DENIED) {
75 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
77 } else if (rv != NET_ERR_NONE) {
78 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable MPTCP [%d]", rv); //LCOV_EXCL_LINE
85 int _connection_libnet_mptcp_enable(connection_handle_s *conn_handle, connection_mptcp_enable_e enable)
89 rv = net_mptcp_set_enabled(conn_handle->network_info_handle, (int)enable);
90 if (rv == NET_ERR_ACCESS_DENIED) {
91 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
92 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
93 } else if (rv != NET_ERR_NONE) {
94 CONNECTION_LOG(CONNECTION_ERROR, "Failed to enable MPTCP [%d]", rv); //LCOV_EXCL_LINE
95 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
98 return CONNECTION_ERROR_NONE;
101 int _connection_libnet_mptcp_get_enabled(connection_handle_s *conn_handle, connection_mptcp_enable_e* enable)
106 rv = net_mptcp_get_enabled(conn_handle->network_info_handle, &result);
107 if (rv == NET_ERR_ACCESS_DENIED) {
108 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
109 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
110 } else if (rv != NET_ERR_NONE) {
111 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MPTCP enabled state [%d]", rv); //LCOV_EXCL_LINE
112 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
115 *enable = (connection_mptcp_enable_e)result;
116 return CONNECTION_ERROR_NONE;
120 int _connection_libnet_mptcp_set_path_manager(connection_handle_s *conn_handle, connection_mptcp_path_manager_e pm)
123 const char* str = __convert_mptcp_path_manager_enum_to_str(pm);
124 CONNECTION_LOG(CONNECTION_ERROR, "set path manager %s", str);
127 CONNECTION_LOG(CONNECTION_ERROR, "Invalid Parameter");
128 return CONNECTION_ERROR_INVALID_PARAMETER;
131 rv = net_mptcp_set_path_manager(conn_handle->network_info_handle, str);
132 if (rv == NET_ERR_ACCESS_DENIED) {
133 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
134 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
135 } else if (rv != NET_ERR_NONE) {
136 CONNECTION_LOG(CONNECTION_ERROR, "Failed to set MPTCP path manager [%d]", rv); //LCOV_EXCL_LINE
137 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
140 return CONNECTION_ERROR_NONE;
143 int _connection_libnet_mptcp_get_path_manager(connection_handle_s *conn_handle, connection_mptcp_path_manager_e* pm)
148 rv = net_mptcp_get_path_manager(conn_handle->network_info_handle, &result);
149 if (rv == NET_ERR_ACCESS_DENIED) {
150 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
151 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
152 } else if (rv != NET_ERR_NONE) {
153 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MPTCP path manager [%d]", rv); //LCOV_EXCL_LINE
154 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
157 CONNECTION_LOG(CONNECTION_ERROR, "get path manager %s", result);
158 *pm = __convert_mptcp_path_manager_str_to_enum(result);
160 return CONNECTION_ERROR_NONE;
164 int _connection_libnet_mptcp_set_scheduler(connection_handle_s *conn_handle, connection_mptcp_scheduler_e scheduler)
167 const char *str = __convert_mptcp_scheduler_enum_to_str(scheduler);
168 CONNECTION_LOG(CONNECTION_ERROR, "set scheduler %s", str);
171 CONNECTION_LOG(CONNECTION_ERROR, "Invalid Parameter");
172 return CONNECTION_ERROR_INVALID_PARAMETER;
175 rv = net_mptcp_set_scheduler(conn_handle->network_info_handle, str);
176 if (rv == NET_ERR_ACCESS_DENIED) {
177 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
178 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
179 } else if (rv != NET_ERR_NONE) {
180 CONNECTION_LOG(CONNECTION_ERROR, "Failed to set MPTCP scheduler [%d]", rv); //LCOV_EXCL_LINE
181 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
184 return CONNECTION_ERROR_NONE;
187 int _connection_libnet_mptcp_get_scheduler(connection_handle_s *conn_handle, connection_mptcp_scheduler_e* scheduler)
192 rv = net_mptcp_get_scheduler(conn_handle->network_info_handle, &result);
193 if (rv == NET_ERR_ACCESS_DENIED) {
194 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
195 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
196 } else if (rv != NET_ERR_NONE) {
197 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MPTCP scheduler [%d]", rv); //LCOV_EXCL_LINE
198 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
201 CONNECTION_LOG(CONNECTION_ERROR, "get scheduler %s", result);
202 *scheduler = __convert_mptcp_scheduler_str_to_enum(result);
204 return CONNECTION_ERROR_NONE;