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);
125 CONNECTION_LOG(CONNECTION_ERROR, "set path manager %s", str);
128 CONNECTION_LOG(CONNECTION_ERROR, "Invalid Parameter");
129 return CONNECTION_ERROR_INVALID_PARAMETER;
132 rv = net_mptcp_set_path_manager(conn_handle->network_info_handle, str);
133 if (rv == NET_ERR_ACCESS_DENIED) {
134 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
135 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
136 } else if (rv != NET_ERR_NONE) {
137 CONNECTION_LOG(CONNECTION_ERROR, "Failed to set MPTCP path manager [%d]", rv); //LCOV_EXCL_LINE
138 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
141 return CONNECTION_ERROR_NONE;
144 int _connection_libnet_mptcp_get_path_manager(connection_handle_s *conn_handle, connection_mptcp_path_manager_e* pm)
149 rv = net_mptcp_get_path_manager(conn_handle->network_info_handle, &result);
150 if (rv == NET_ERR_ACCESS_DENIED) {
151 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
152 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
153 } else if (rv != NET_ERR_NONE) {
154 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MPTCP path manager [%d]", rv); //LCOV_EXCL_LINE
155 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
158 CONNECTION_LOG(CONNECTION_ERROR, "get path manager %s", result);
159 *pm = __convert_mptcp_path_manager_str_to_enum(result);
161 return CONNECTION_ERROR_NONE;
165 int _connection_libnet_mptcp_set_scheduler(connection_handle_s *conn_handle, connection_mptcp_scheduler_e scheduler)
168 const char *str = __convert_mptcp_scheduler_enum_to_str(scheduler);
169 CONNECTION_LOG(CONNECTION_ERROR, "set scheduler %s", str);
172 CONNECTION_LOG(CONNECTION_ERROR, "Invalid Parameter");
173 return CONNECTION_ERROR_INVALID_PARAMETER;
176 rv = net_mptcp_set_scheduler(conn_handle->network_info_handle, str);
177 if (rv == NET_ERR_ACCESS_DENIED) {
178 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
179 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
180 } else if (rv != NET_ERR_NONE) {
181 CONNECTION_LOG(CONNECTION_ERROR, "Failed to set MPTCP scheduler [%d]", rv); //LCOV_EXCL_LINE
182 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
185 return CONNECTION_ERROR_NONE;
188 int _connection_libnet_mptcp_get_scheduler(connection_handle_s *conn_handle, connection_mptcp_scheduler_e* scheduler)
193 rv = net_mptcp_get_scheduler(conn_handle->network_info_handle, &result);
194 if (rv == NET_ERR_ACCESS_DENIED) {
195 CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
196 return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
197 } else if (rv != NET_ERR_NONE) {
198 CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MPTCP scheduler [%d]", rv); //LCOV_EXCL_LINE
199 return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
202 CONNECTION_LOG(CONNECTION_ERROR, "get scheduler %s", result);
203 *scheduler = __convert_mptcp_scheduler_str_to_enum(result);
205 return CONNECTION_ERROR_NONE;