Merge "Removed code for resetting MAC address" into tizen
[platform/core/api/tethering.git] / src / tethering_client.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <stdlib.h>
18 #include <string.h>
19 #include "tethering_private.h"
20
21 API int tethering_client_clone(tethering_client_h *dest, tethering_client_h origin)
22 {
23         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
24
25         _retvm_if(dest == NULL, TETHERING_ERROR_INVALID_PARAMETER,
26                         "Parameter(dest) is NULL\n");
27
28         __tethering_client_h *si = NULL;
29         __tethering_client_h *source = NULL;
30
31         source = (__tethering_client_h *)origin;
32
33         si = malloc(sizeof(__tethering_client_h));
34         if (si == NULL) {
35                 ERR("malloc is failed\n");
36                 return TETHERING_ERROR_OUT_OF_MEMORY;
37         }
38
39         memcpy(si, source, sizeof(__tethering_client_h));
40         si->hostname = g_strdup(source->hostname);
41         if (si->hostname == NULL) {
42                 ERR("malloc is failed\n");
43                 free(si);
44                 return TETHERING_ERROR_OUT_OF_MEMORY;
45         }
46
47         *dest = (tethering_client_h)si;
48
49         return TETHERING_ERROR_NONE;
50 }
51
52 API int tethering_client_destroy(tethering_client_h client)
53 {
54         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
55
56         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
57                         "Parameter(client) is NULL\n");
58
59         __tethering_client_h *si = NULL;
60
61         si = (__tethering_client_h *)client;
62
63         g_free(si->hostname);
64
65         free(client);
66
67         return TETHERING_ERROR_NONE;
68 }
69
70 API int tethering_client_get_tethering_type(tethering_client_h client, tethering_type_e *type)
71 {
72         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
73
74         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
75                         "Parameter(client) is NULL\n");
76         _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
77                         "Parameter(type) is NULL\n");
78
79         __tethering_client_h *si = (__tethering_client_h *)client;
80
81         *type = si->interface;
82
83         return TETHERING_ERROR_NONE;
84 }
85
86 API int tethering_client_get_name(tethering_client_h client, char **name)
87 {
88         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
89
90         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
91                         "Parameter(client) is NULL\n");
92         _retvm_if(name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
93                         "Parameter(name) is NULL\n");
94
95         __tethering_client_h *si = (__tethering_client_h *)client;
96
97         *name = strdup(si->hostname);
98         if (*name == NULL) {
99                 ERR("strdup is failed\n");
100                 return TETHERING_ERROR_OUT_OF_MEMORY;
101         }
102
103         return TETHERING_ERROR_NONE;
104 }
105
106 API int tethering_client_get_ip_address(tethering_client_h client, tethering_address_family_e address_family, char **ip_address)
107 {
108         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
109
110         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
111                         "Parameter(client) is NULL\n");
112         _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
113                         "Parameter(ip_address) is NULL\n");
114
115         __tethering_client_h *si = (__tethering_client_h *)client;
116
117         *ip_address = strdup(si->ip);
118         if (*ip_address == NULL) {
119                 ERR("strdup is failed\n");
120                 return TETHERING_ERROR_OUT_OF_MEMORY;
121         }
122
123         return TETHERING_ERROR_NONE;
124 }
125
126 API int tethering_client_get_mac_address(tethering_client_h client, char **mac_address)
127 {
128         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
129
130         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
131                         "Parameter(client) is NULL\n");
132         _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
133                         "Parameter(mac_address) is NULL\n");
134
135         __tethering_client_h *si = (__tethering_client_h *)client;
136
137         *mac_address = strdup(si->mac);
138         if (*mac_address == NULL) {
139                 ERR("strdup is failed\n");
140                 return TETHERING_ERROR_OUT_OF_MEMORY;
141         }
142
143         return TETHERING_ERROR_NONE;
144 }
145
146 API int tethering_client_get_time(tethering_client_h client, time_t *timestamp)
147 {
148         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
149
150         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
151                         "Parameter(client) is NULL\n");
152
153         __tethering_client_h *si = (__tethering_client_h *)client;
154
155         *timestamp = si->tm;
156
157         return TETHERING_ERROR_NONE;
158 }
159