9479965e0f32bdb030b27e418decec1088505480
[platform/core/api/connection.git] / src / connection_mptcp.c
1 /*
2  * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5 {
6 }
7
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <glib.h>
21
22 #include "connection_extension.h"
23 #include "net_connection_private.h"
24 #include "net_connection_mptcp_private.h"
25
26 //LCOV_EXCL_START
27 EXPORT_API int connection_mptcp_is_supported(connection_h connection, bool* supported)
28 {
29         if (!(_connection_check_handle_validity(connection))) {
30                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
31                 return CONNECTION_ERROR_INVALID_PARAMETER;
32         }
33
34         *supported = _connection_libnet_mptcp_supported(connection);
35         return CONNECTION_ERROR_NONE;
36 }
37
38 EXPORT_API int connection_mptcp_enable(connection_h connection, connection_mptcp_enable_e enable)
39 {
40         // check MPTCP support
41         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
42                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
43                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
44         }
45
46         if (!(_connection_check_handle_validity(connection))) {
47                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
48                 return CONNECTION_ERROR_INVALID_PARAMETER;
49         }
50
51         if (enable <= CONNECTION_MPTCP_DISABLE
52                         || enable > CONNECTION_MPTCP_ENABLE_SOCKOPT) {
53                 CONNECTION_LOG(CONNECTION_ERROR, "Use connection_mptcp_disable()");     //LCOV_EXCL_LINE
54                 return CONNECTION_ERROR_INVALID_PARAMETER;      //LCOV_EXCL_LINE
55         }
56
57         return _connection_libnet_mptcp_enable(connection, enable);
58 }
59
60 EXPORT_API int connection_mptcp_disable(connection_h connection)
61 {
62         // check MPTCP support
63         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
64                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
65                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
66         }
67
68         if (!(_connection_check_handle_validity(connection))) {
69                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
70                 return CONNECTION_ERROR_INVALID_PARAMETER;
71         }
72
73         return _connection_libnet_mptcp_enable(connection, CONNECTION_MPTCP_DISABLE);
74 }
75
76 EXPORT_API int connection_mptcp_get_enabled(connection_h connection, connection_mptcp_enable_e* enable)
77 {
78         // check MPTCP support
79         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
80                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
81                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
82         }
83
84         if (!(_connection_check_handle_validity(connection))) {
85                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
86                 return CONNECTION_ERROR_INVALID_PARAMETER;
87         }
88
89         if (enable == NULL) {
90                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");  //LCOV_EXCL_LINE
91                 return CONNECTION_ERROR_INVALID_PARAMETER;      //LCOV_EXCL_LINE
92         }
93
94         return _connection_libnet_mptcp_get_enabled(connection, enable);
95 }
96
97
98 EXPORT_API int connection_mptcp_set_path_manager(connection_h connection, connection_mptcp_path_manager_e pm)
99 {
100         // check MPTCP support
101         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
102                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
103                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
104         }
105
106         if (!(_connection_check_handle_validity(connection))) {
107                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
108                 return CONNECTION_ERROR_INVALID_PARAMETER;
109         }
110
111         return _connection_libnet_mptcp_set_path_manager(connection, pm);
112 }
113
114 EXPORT_API int connection_mptcp_get_path_manager(connection_h connection, connection_mptcp_path_manager_e* pm)
115 {
116         // check MPTCP support
117         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
118                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
119                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
120         }
121
122         if (!(_connection_check_handle_validity(connection))) {
123                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
124                 return CONNECTION_ERROR_INVALID_PARAMETER;
125         }
126
127         if (pm == NULL) {
128                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
129                 return CONNECTION_ERROR_INVALID_PARAMETER;
130         }
131
132         return _connection_libnet_mptcp_get_path_manager(connection, pm);
133 }
134
135
136 EXPORT_API int connection_mptcp_set_scheduler(connection_h connection, connection_mptcp_scheduler_e scheduler)
137 {
138         // check MPTCP support
139         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
140                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
141                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
142         }
143
144         if (!(_connection_check_handle_validity(connection))) {
145                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
146                 return CONNECTION_ERROR_INVALID_PARAMETER;
147         }
148
149         return _connection_libnet_mptcp_set_scheduler(connection, scheduler);
150 }
151
152 EXPORT_API int connection_mptcp_get_scheduler(connection_h connection, connection_mptcp_scheduler_e* scheduler)
153 {
154         // check MPTCP support
155         if (_connection_libnet_mptcp_supported(connection) == FALSE) {
156                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");     //LCOV_EXCL_LINE
157                 return CONNECTION_ERROR_NOT_SUPPORTED;  //LCOV_EXCL_LINE
158         }
159
160         if (!(_connection_check_handle_validity(connection))) {
161                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
162                 return CONNECTION_ERROR_INVALID_PARAMETER;
163         }
164
165         if (scheduler == NULL) {
166                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
167                 return CONNECTION_ERROR_INVALID_PARAMETER;
168         }
169
170         return _connection_libnet_mptcp_get_scheduler(connection, scheduler);
171 }
172 //LCOV_EXCL_STOP