Check if mptcp is supported first
[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 EXPORT_API int connection_mptcp_is_supported(connection_h connection, bool* supported)
27 {
28         if (!(_connection_check_handle_validity(connection))) {
29                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
30                 return CONNECTION_ERROR_INVALID_PARAMETER;
31         }
32
33         *supported = _connection_libnet_mptcp_supported();
34         return CONNECTION_ERROR_NONE;
35 }
36
37 EXPORT_API int connection_mptcp_enable(connection_h connection, connection_mptcp_enable_e enable)
38 {
39         // check MPTCP support
40         if (_connection_libnet_mptcp_supported() == FALSE) {
41                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");
42                 return CONNECTION_ERROR_NOT_SUPPORTED;
43         }
44
45         if (!(_connection_check_handle_validity(connection))) {
46                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
47                 return CONNECTION_ERROR_INVALID_PARAMETER;
48         }
49
50         if (enable == CONNECTION_MPTCP_DISABLE) {
51                 CONNECTION_LOG(CONNECTION_ERROR, "Use connection_mptcp_disable()");
52                 return CONNECTION_ERROR_INVALID_PARAMETER;
53         }
54
55         return _connection_libnet_mptcp_enable(enable);
56 }
57
58 EXPORT_API int connection_mptcp_disable(connection_h connection)
59 {
60         // check MPTCP support
61         if (_connection_libnet_mptcp_supported() == FALSE) {
62                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");
63                 return CONNECTION_ERROR_NOT_SUPPORTED;
64         }
65
66         if (!(_connection_check_handle_validity(connection))) {
67                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
68                 return CONNECTION_ERROR_INVALID_PARAMETER;
69         }
70
71         return _connection_libnet_mptcp_enable(CONNECTION_MPTCP_DISABLE);
72 }
73
74 EXPORT_API int connection_mptcp_get_enabled(connection_h connection, connection_mptcp_enable_e* enable)
75 {
76         // check MPTCP support
77         if (_connection_libnet_mptcp_supported() == FALSE) {
78                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");
79                 return CONNECTION_ERROR_NOT_SUPPORTED;
80         }
81
82         if (!(_connection_check_handle_validity(connection))) {
83                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
84                 return CONNECTION_ERROR_INVALID_PARAMETER;
85         }
86
87         if (enable == NULL) {
88                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
89                 return CONNECTION_ERROR_INVALID_PARAMETER;
90         }
91
92         return _connection_libnet_mptcp_get_enabled(enable);
93 }
94
95
96 EXPORT_API int connection_mptcp_set_path_manager(connection_h connection, connection_mptcp_path_manager_e pm)
97 {
98         // check MPTCP support
99         if (_connection_libnet_mptcp_supported() == FALSE) {
100                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");
101                 return CONNECTION_ERROR_NOT_SUPPORTED;
102         }
103
104         if (!(_connection_check_handle_validity(connection))) {
105                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
106                 return CONNECTION_ERROR_INVALID_PARAMETER;
107         }
108
109         return _connection_libnet_mptcp_set_path_manager(pm);
110 }
111
112 EXPORT_API int connection_mptcp_get_path_manager(connection_h connection, connection_mptcp_path_manager_e* pm)
113 {
114         // check MPTCP support
115         if (_connection_libnet_mptcp_supported() == FALSE) {
116                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");
117                 return CONNECTION_ERROR_NOT_SUPPORTED;
118         }
119
120         if (!(_connection_check_handle_validity(connection))) {
121                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
122                 return CONNECTION_ERROR_INVALID_PARAMETER;
123         }
124
125         if (pm == NULL) {
126                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
127                 return CONNECTION_ERROR_INVALID_PARAMETER;
128         }
129
130         return _connection_libnet_mptcp_get_path_manager(pm);
131 }
132
133
134 EXPORT_API int connection_mptcp_set_scheduler(connection_h connection, connection_mptcp_scheduler_e scheduler)
135 {
136         // check MPTCP support
137         if (_connection_libnet_mptcp_supported() == FALSE) {
138                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");
139                 return CONNECTION_ERROR_NOT_SUPPORTED;
140         }
141
142         if (!(_connection_check_handle_validity(connection))) {
143                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
144                 return CONNECTION_ERROR_INVALID_PARAMETER;
145         }
146
147         return _connection_libnet_mptcp_set_scheduler(scheduler);
148 }
149
150 EXPORT_API int connection_mptcp_get_scheduler(connection_h connection, connection_mptcp_scheduler_e* scheduler)
151 {
152         // check MPTCP support
153         if (_connection_libnet_mptcp_supported() == FALSE) {
154                 CONNECTION_LOG(CONNECTION_ERROR, "MPTCP is not supported");
155                 return CONNECTION_ERROR_NOT_SUPPORTED;
156         }
157
158         if (!(_connection_check_handle_validity(connection))) {
159                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
160                 return CONNECTION_ERROR_INVALID_PARAMETER;
161         }
162
163         if (scheduler == NULL) {
164                 CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
165                 return CONNECTION_ERROR_INVALID_PARAMETER;
166         }
167
168         return _connection_libnet_mptcp_get_scheduler(scheduler);
169 }
170
171