d25e499807e6d6b15dd029a1aa515450531f1585
[platform/core/api/wifi.git] / src / net_wifi_config.c
1 /*
2  * Copyright (c) 2012-2013 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 "wifi.h"
18 #include "wifi_config_private.h"
19 #include "net_wifi_private.h"
20
21 /**
22  * wifi configuration
23  */
24 EXPORT_API int wifi_config_create(const char *name, const char *passphrase, wifi_security_type_e security_type, wifi_config_h *config)
25 {
26         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_create");
27         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
28
29         struct _wifi_config *h = NULL;
30
31         if (_wifi_is_init() == false) {
32                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
33                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
34         }
35
36         if (config == NULL || name == NULL) {
37                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
38                 return WIFI_ERROR_INVALID_PARAMETER;
39         }
40
41         h = g_new0(struct _wifi_config, 1);
42         if (h == NULL)
43                 return WIFI_ERROR_OUT_OF_MEMORY;
44
45         h->name = g_strdup(name);
46         h->passphrase = g_strdup(passphrase);
47         h->security_type = security_type;
48         h->is_saved = FALSE;
49         h->is_hidden = FALSE;
50         h->proxy_address = NULL;
51         h->address_family = WIFI_ADDRESS_FAMILY_IPV4;
52         h->eap_config = NULL;
53
54         if (security_type == WIFI_SECURITY_TYPE_EAP) {
55                 h->eap_config = g_new0(struct _wifi_eap_config, 1);
56                 if (h->eap_config == NULL) {
57                         g_free(h->name); //LCOV_EXCL_LINE
58                         g_free(h->passphrase); //LCOV_EXCL_LINE
59                         g_free(h); //LCOV_EXCL_LINE
60                         return WIFI_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
61                 }
62
63                 h->eap_config->ca_cert = NULL;
64                 h->eap_config->client_cert = NULL;
65                 h->eap_config->private_key = NULL;
66                 h->eap_config->anonymous_identity = NULL;
67                 h->eap_config->identity = NULL;
68                 h->eap_config->subject_match = NULL;
69                 h->eap_config->eap_type = -1;
70                 h->eap_config->eap_auth_type = WIFI_EAP_AUTH_TYPE_NONE;
71         }
72
73         *config = (wifi_config_h)h;
74
75         return WIFI_ERROR_NONE;
76 }
77
78 EXPORT_API int wifi_config_clone(wifi_config_h origin, wifi_config_h *cloned_config)
79 {
80         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_clone");
81         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
82
83         struct _wifi_config *h = NULL;
84         struct _wifi_config *config = NULL;
85
86         if (_wifi_is_init() == false) {
87                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
88                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
89         }
90
91         if (origin == NULL || cloned_config == NULL) {
92                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
93                 return WIFI_ERROR_INVALID_PARAMETER;
94         }
95
96         config = (struct _wifi_config *)origin;
97
98         h = g_new0(struct _wifi_config, 1);
99         if (h == NULL)
100                 return WIFI_ERROR_OUT_OF_MEMORY;
101
102         h->name = g_strdup(config->name);
103         h->passphrase = g_strdup(config->passphrase);
104         h->security_type = config->security_type;
105         h->is_saved = config->is_saved;
106         h->is_hidden = config->is_hidden;
107         h->proxy_address = g_strdup(config->proxy_address);
108         h->address_family = config->address_family;
109
110         if (config->eap_config) {
111                 h->eap_config = g_new0(struct _wifi_eap_config, 1);
112                 if (h->eap_config == NULL) {
113                         g_free(h->name); //LCOV_EXCL_LINE
114                         g_free(h->passphrase); //LCOV_EXCL_LINE
115                         g_free(h->proxy_address); //LCOV_EXCL_LINE
116                         g_free(h); //LCOV_EXCL_LINE
117                         return WIFI_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
118                 }
119
120                 h->eap_config->ca_cert = g_strdup(config->eap_config->ca_cert);
121                 h->eap_config->client_cert = g_strdup(config->eap_config->client_cert);
122                 h->eap_config->private_key = g_strdup(config->eap_config->private_key);
123                 h->eap_config->anonymous_identity = g_strdup(config->eap_config->anonymous_identity);
124                 h->eap_config->identity = g_strdup(config->eap_config->identity);
125                 h->eap_config->subject_match = g_strdup(config->eap_config->subject_match);
126                 h->eap_config->eap_type = config->eap_config->eap_type;
127                 h->eap_config->eap_auth_type = config->eap_config->eap_auth_type;
128         }
129
130         *cloned_config = (wifi_config_h)h;
131
132         return WIFI_ERROR_NONE;
133 }
134
135 EXPORT_API int wifi_config_destroy(wifi_config_h config)
136 {
137         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_destroy");
138         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
139
140         struct _wifi_config *h = (struct _wifi_config *)config;
141
142         if (_wifi_is_init() == false) {
143                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
144                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
145         }
146
147         if (config == NULL) {
148                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
149                 return WIFI_ERROR_INVALID_PARAMETER;
150         }
151
152         g_free(h->name);
153         g_free(h->passphrase);
154         g_free(h->proxy_address);
155         if (h->eap_config) {
156                 g_free(h->eap_config->ca_cert);
157                 g_free(h->eap_config->client_cert);
158                 g_free(h->eap_config->private_key);
159                 g_free(h->eap_config->anonymous_identity);
160                 g_free(h->eap_config->identity);
161                 g_free(h->eap_config->subject_match);
162                 g_free(h->eap_config);
163         }
164         g_free(h);
165
166         return WIFI_ERROR_NONE;
167 }
168
169 EXPORT_API int wifi_config_save_configuration(wifi_config_h config)
170 {
171         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_save");
172         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
173
174         int ret = WIFI_ERROR_NONE;
175         wifi_dbus *dbus_h = NULL;
176         struct _wifi_config *h = (struct _wifi_config *)config;
177
178         if (_wifi_is_init() == false) {
179                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
180                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
181         }
182
183         if (config == NULL || h->name == NULL) {
184                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
185                 return WIFI_ERROR_INVALID_PARAMETER;
186         }
187
188         dbus_h = _wifi_get_dbus_handle();
189         if (dbus_h == NULL) {
190                 WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection"); //LCOV_EXCL_LINE
191                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
192         }
193
194         if (h->security_type == WIFI_SECURITY_TYPE_EAP) {
195                 ret = wifi_save_eap_configurations(dbus_h, h->name, h->passphrase, h->security_type, h->proxy_address, h->eap_config, h->is_hidden);
196                 if (ret != WIFI_ERROR_NONE)
197                         WIFI_LOG(WIFI_ERROR, "Fail to wifi_save_eap_configurations"); //LCOV_EXCL_LINE
198         } else {
199                 ret = wifi_save_configurations(dbus_h, h->name, h->passphrase, h->security_type, h->proxy_address, h->is_hidden);
200                 if (ret != WIFI_ERROR_NONE)
201                         WIFI_LOG(WIFI_ERROR, "Fail to save configurations [%d]", ret); //LCOV_EXCL_LINE
202         }
203
204         h->is_saved = TRUE;
205
206         return ret;
207 }
208
209 EXPORT_API int wifi_config_remove(wifi_config_h config)
210 {
211         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_remove");
212         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
213         int ret = WIFI_ERROR_NONE;
214         struct _wifi_config *h = (struct _wifi_config *)config;
215
216         if (_wifi_is_init() == false) {
217                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
218                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
219         }
220
221         if (config == NULL || h->name == NULL) {
222                 WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
223                 return WIFI_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
224         }
225
226         if (h->is_saved == TRUE) {
227                 wifi_dbus *dbus_h = NULL;
228                 gchar *config_id = NULL;
229
230                 dbus_h = _wifi_get_dbus_handle();
231                 if (dbus_h == NULL) {
232                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
233                         return WIFI_ERROR_INVALID_OPERATION;
234                 }
235
236                 config_id = wifi_config_get_config_id(h->name, h->security_type);
237
238                 ret = wifi_remove_configurations(dbus_h, config_id);
239                 if (ret != WIFI_ERROR_NONE)
240                         WIFI_LOG(WIFI_ERROR, "Fail to remove configurations [%d]", ret);
241
242                 g_free(config_id);
243         }
244
245         return ret;
246 }
247
248 EXPORT_API int wifi_config_foreach_configuration(wifi_config_list_cb callback, void *user_data)
249 {
250         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_foreach_configuration");
251         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
252
253         int ret = WIFI_ERROR_NONE;
254         wifi_dbus *dbus_h = NULL;
255         GSList *config_ids = NULL;
256
257         if (_wifi_is_init() == false) {
258                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
259                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
260         }
261
262         if (callback == NULL) {
263                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
264                 return WIFI_ERROR_INVALID_PARAMETER;
265         }
266
267         dbus_h = _wifi_get_dbus_handle();
268         if (dbus_h == NULL) {
269                 WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection"); //LCOV_EXCL_LINE
270                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
271         }
272
273         config_ids = wifi_config_get_config_id_list(dbus_h);
274         if (config_ids == NULL) {
275                 WIFI_LOG(WIFI_ERROR, "Fail to wifi_get_config_id_list"); //LCOV_EXCL_LINE
276                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
277         }
278
279         while (config_ids) {
280                 bool rv = 0;
281                 struct _wifi_config *h;
282                 gchar *id = config_ids->data;
283
284                 h = g_new0(struct _wifi_config, 1);
285                 if (h == NULL) {
286                         ret = WIFI_ERROR_OUT_OF_MEMORY;
287                         break;
288                 }
289
290                 if (g_str_has_suffix(id, "ieee8021x") == TRUE) {
291                         h->eap_config = g_new0(struct _wifi_eap_config, 1);
292                         if (h->eap_config == NULL) {
293                                 ret = WIFI_ERROR_OUT_OF_MEMORY;
294                                 break;
295                         }
296                         ret = wifi_load_eap_configurations(dbus_h, id, &h->name,
297                                 &h->security_type, &h->proxy_address, &h->is_hidden, &h->eap_config, &h->last_error);
298                 } else {
299                         ret = wifi_load_configurations(dbus_h, id, &h->name,
300                                 &h->security_type, &h->proxy_address, &h->is_hidden, &h->last_error);
301                 }
302
303                 if (ret != WIFI_ERROR_NONE) {
304                         WIFI_LOG(WIFI_ERROR, "Fail to load configurations [%d]", ret); //LCOV_EXCL_LINE
305                         return ret; //LCOV_EXCL_LINE
306                 }
307
308                 h->address_family = WIFI_ADDRESS_FAMILY_IPV4;
309                 h->is_saved = TRUE;
310                 rv = callback((wifi_config_h)h, user_data);
311                 g_free(h->name);
312                 g_free(h->proxy_address);
313                 if (h->eap_config) {
314                         g_free(h->eap_config->ca_cert);
315                         g_free(h->eap_config->client_cert);
316                         g_free(h->eap_config->private_key);
317                         g_free(h->eap_config->anonymous_identity);
318                         g_free(h->eap_config->identity);
319                         g_free(h->eap_config->subject_match);
320                         g_free(h->eap_config);
321                 }
322                 g_free(h);
323                 h = NULL;
324
325                 if (rv == false)
326                         break;
327
328                 config_ids = config_ids->next;
329         }
330
331         config_ids = g_slist_nth(config_ids, 0);
332         g_slist_free_full(config_ids, g_free);
333
334         return ret;
335 }
336
337 EXPORT_API int wifi_config_get_name(wifi_config_h config, char **name)
338 {
339         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_name");
340         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
341
342         struct _wifi_config *h = (struct _wifi_config *)config;
343
344         if (_wifi_is_init() == false) {
345                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
346                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
347         }
348
349         if (config == NULL || name == NULL) {
350                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
351                 return WIFI_ERROR_INVALID_PARAMETER;
352         }
353
354         if (h->name != NULL)
355                 *name = g_strdup(h->name);
356         else
357                 *name = NULL;
358
359         return WIFI_ERROR_NONE;
360 }
361
362 EXPORT_API int wifi_config_get_security_type(wifi_config_h config, wifi_security_type_e *security_type)
363 {
364         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_security_type");
365         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
366
367         struct _wifi_config *h = (struct _wifi_config *)config;
368
369         if (_wifi_is_init() == false) {
370                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
371                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
372         }
373
374         if (config == NULL || security_type == NULL) {
375                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
376                 return WIFI_ERROR_INVALID_PARAMETER;
377         }
378
379         *security_type = h->security_type;
380
381         return WIFI_ERROR_NONE;
382 }
383
384 /**
385  * wifi configuration set field
386  */
387 EXPORT_API int wifi_config_set_proxy_address(wifi_config_h config, wifi_address_family_e address_family, const char *proxy_address)
388 {
389         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_proxy_address");
390         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
391
392         struct _wifi_config *h = (struct _wifi_config *)config;
393         int ret = WIFI_ERROR_NONE;
394
395         if (_wifi_is_init() == false) {
396                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
397                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
398         }
399
400         if (config == NULL) {
401                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
402                 return WIFI_ERROR_INVALID_PARAMETER;
403         }
404         if ((address_family != WIFI_ADDRESS_FAMILY_IPV4 && address_family != WIFI_ADDRESS_FAMILY_IPV6)) {
405                 WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
406                 return WIFI_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
407         }
408
409         if (address_family == WIFI_ADDRESS_FAMILY_IPV6) {
410                 WIFI_LOG(WIFI_ERROR, "Not supported yet"); //LCOV_EXCL_LINE
411                 return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; //LCOV_EXCL_LINE
412         }
413
414         h->address_family = address_family;
415         h->proxy_address = g_strdup(proxy_address);
416
417         if (h->is_saved == TRUE) {
418                 //LCOV_EXCL_START
419                 wifi_dbus *dbus_h = NULL;
420                 gchar *config_id = NULL;
421
422                 dbus_h = _wifi_get_dbus_handle();
423                 if (dbus_h == NULL) {
424                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
425                         return WIFI_ERROR_INVALID_OPERATION;
426                 }
427
428                 config_id = wifi_config_get_config_id(h->name, h->security_type);
429
430                 ret = wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_PROXYADDRESS, proxy_address);
431                 if (ret != WIFI_ERROR_NONE)
432                         WIFI_LOG(WIFI_ERROR, "Fail to set proxy address [%d]", ret);
433
434                 g_free(config_id);
435                 //LCOV_EXCL_STOP
436         }
437
438         return ret;
439 }
440
441 EXPORT_API int wifi_config_get_proxy_address(wifi_config_h config, wifi_address_family_e *address_family, char **proxy_address)
442 {
443         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_proxy_address");
444         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
445
446         struct _wifi_config *h = (struct _wifi_config *)config;
447
448         if (_wifi_is_init() == false) {
449                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
450                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
451         }
452
453         if (config == NULL || address_family == NULL || proxy_address == NULL) {
454                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
455                 return WIFI_ERROR_INVALID_PARAMETER;
456         }
457
458         *address_family = h->address_family;
459         *proxy_address = g_strdup(h->proxy_address);
460
461         return WIFI_ERROR_NONE;
462 }
463
464 EXPORT_API int wifi_config_set_hidden_ap_property(wifi_config_h config, bool hidden)
465 {
466         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_hidden_ap_property");
467         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
468
469         struct _wifi_config *h = (struct _wifi_config *)config;
470         int ret = WIFI_ERROR_NONE;
471
472         if (_wifi_is_init() == false) {
473                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
474                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
475         }
476
477         if (config == NULL) {
478                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
479                 return WIFI_ERROR_INVALID_PARAMETER;
480         }
481
482         h->is_hidden = hidden;
483
484         if (h->is_saved == TRUE) {
485                 //LCOV_EXCL_START
486                 wifi_dbus *dbus_h = NULL;
487                 char *config_id = NULL;
488                 char *hidden = NULL;
489
490                 dbus_h = _wifi_get_dbus_handle();
491                 if (dbus_h == NULL) {
492                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
493                         return WIFI_ERROR_INVALID_OPERATION;
494                 }
495
496                 config_id = wifi_config_get_config_id(h->name, h->security_type);
497
498                 if (h->is_hidden == TRUE)
499                         hidden = g_strdup("TRUE");
500                 else
501                         hidden = g_strdup("FALSE");
502
503                 ret = wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_HIDDEN, hidden);
504                 if (ret != WIFI_ERROR_NONE)
505                         WIFI_LOG(WIFI_ERROR, "Fail to set hidden [%d]", ret);
506
507                 g_free(hidden);
508                 g_free(config_id);
509                 //LCOV_EXCL_STOP
510         }
511
512         return ret;
513 }
514
515 EXPORT_API int wifi_config_get_hidden_ap_property(wifi_config_h config, bool *hidden)
516 {
517         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_hidden_ap_property");
518         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
519
520         struct _wifi_config *h = (struct _wifi_config *)config;
521
522         if (_wifi_is_init() == false) {
523                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
524                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
525         }
526
527         if (config == NULL || hidden == NULL) {
528                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
529                 return WIFI_ERROR_INVALID_PARAMETER;
530         }
531
532         *hidden = h->is_hidden;
533
534         return WIFI_ERROR_NONE;
535 }
536
537 EXPORT_API int wifi_config_get_eap_anonymous_identity(wifi_config_h config, char** anonymous_identity)
538 {
539         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_anonymous_identity");
540         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
541
542         struct _wifi_config *h = (struct _wifi_config *)config;
543
544         if (config == NULL)
545                 return WIFI_ERROR_INVALID_PARAMETER;
546         if (h->eap_config == NULL)
547                 return WIFI_ERROR_INVALID_PARAMETER;
548         if (anonymous_identity == NULL)
549                 return WIFI_ERROR_INVALID_PARAMETER;
550
551         *anonymous_identity = g_strdup(h->eap_config->anonymous_identity);
552
553         return WIFI_ERROR_NONE;
554 }
555
556 EXPORT_API int wifi_config_set_eap_anonymous_identity(wifi_config_h config, const char* anonymous_identity)
557 {
558         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_anonymous_identity");
559         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
560
561         struct _wifi_config *h = (struct _wifi_config *)config;
562
563         if (config == NULL)
564                 return WIFI_ERROR_INVALID_PARAMETER;
565         if (h->eap_config == NULL)
566                 return WIFI_ERROR_INVALID_PARAMETER;
567
568         h->eap_config->anonymous_identity = g_strdup(anonymous_identity);
569
570         if (h->is_saved == TRUE) {
571                 //LCOV_EXCL_START
572                 wifi_dbus *dbus_h = NULL;
573                 gchar *config_id = NULL;
574
575                 dbus_h = _wifi_get_dbus_handle();
576                 if (dbus_h == NULL) {
577                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
578                         return WIFI_ERROR_INVALID_OPERATION;
579                 }
580
581                 config_id = wifi_config_get_config_id(h->name, h->security_type);
582
583                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, anonymous_identity);
584
585                 g_free(config_id);
586                 //LCOV_EXCL_STOP
587         }
588
589         return WIFI_ERROR_NONE;
590 }
591
592 EXPORT_API int wifi_config_get_eap_ca_cert_file(wifi_config_h config, char** ca_cert)
593 {
594         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_ca_cert_file");
595         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
596
597         struct _wifi_config *h = (struct _wifi_config *)config;
598
599         if (config == NULL)
600                 return WIFI_ERROR_INVALID_PARAMETER;
601         if (h->eap_config == NULL)
602                 return WIFI_ERROR_INVALID_PARAMETER;
603         if (ca_cert == NULL)
604                 return WIFI_ERROR_INVALID_PARAMETER;
605
606         *ca_cert = g_strdup(h->eap_config->ca_cert);
607
608         return WIFI_ERROR_NONE;
609 }
610
611 EXPORT_API int wifi_config_set_eap_ca_cert_file(wifi_config_h config, const char* ca_cert)
612 {
613         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_ca_cert_file");
614         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
615
616         struct _wifi_config *h = (struct _wifi_config *)config;
617
618         if (config == NULL)
619                 return WIFI_ERROR_INVALID_PARAMETER;
620         if (h->eap_config == NULL)
621                 return WIFI_ERROR_INVALID_PARAMETER;
622
623         h->eap_config->ca_cert = g_strdup(ca_cert);
624
625         if (h->is_saved == TRUE) {
626                 //LCOV_EXCL_START
627                 wifi_dbus *dbus_h = NULL;
628                 gchar *config_id = NULL;
629
630                 dbus_h = _wifi_get_dbus_handle();
631                 if (dbus_h == NULL) {
632                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
633                         return WIFI_ERROR_INVALID_OPERATION;
634                 }
635
636                 config_id = wifi_config_get_config_id(h->name, h->security_type);
637
638                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_CACERT, ca_cert);
639
640                 g_free(config_id);
641                 //LCOV_EXCL_STOP
642         }
643
644         return WIFI_ERROR_NONE;
645 }
646
647 EXPORT_API int wifi_config_get_eap_client_cert_file(wifi_config_h config, char** client_cert)
648 {
649         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_client_cert_file");
650         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
651
652         struct _wifi_config *h = (struct _wifi_config *)config;
653
654         if (config == NULL)
655                 return WIFI_ERROR_INVALID_PARAMETER;
656         if (h->eap_config == NULL)
657                 return WIFI_ERROR_INVALID_PARAMETER;
658         if (client_cert == NULL)
659                 return WIFI_ERROR_INVALID_PARAMETER;
660
661         *client_cert = g_strdup(h->eap_config->client_cert);
662
663         return WIFI_ERROR_NONE;
664 }
665
666 EXPORT_API int wifi_config_set_eap_client_cert_file(wifi_config_h config, const char* private_key, const char* client_cert)
667 {
668         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_client_cert_file");
669         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
670
671         struct _wifi_config *h = (struct _wifi_config *)config;
672
673         if (config == NULL)
674                 return WIFI_ERROR_INVALID_PARAMETER;
675         if (h->eap_config == NULL)
676                 return WIFI_ERROR_INVALID_PARAMETER;
677
678         h->eap_config->private_key = g_strdup(private_key);
679         h->eap_config->client_cert = g_strdup(client_cert);
680
681         if (h->is_saved == TRUE) {
682                 //LCOV_EXCL_START
683                 wifi_dbus *dbus_h = NULL;
684                 gchar *config_id = NULL;
685
686                 dbus_h = _wifi_get_dbus_handle();
687                 if (dbus_h == NULL) {
688                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
689                         return WIFI_ERROR_INVALID_OPERATION;
690                 }
691
692                 config_id = wifi_config_get_config_id(h->name, h->security_type);
693
694                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_CLIENTCERT, client_cert);
695                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_PRIVATEKEY, private_key);
696
697                 g_free(config_id);
698                 //LCOV_EXCL_STOP
699         }
700
701         return WIFI_ERROR_NONE;
702 }
703
704 EXPORT_API int wifi_config_get_eap_identity(wifi_config_h config, char** identity)
705 {
706         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_identity");
707         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
708
709         struct _wifi_config *h = (struct _wifi_config *)config;
710
711         if (config == NULL)
712                 return WIFI_ERROR_INVALID_PARAMETER;
713         if (h->eap_config == NULL)
714                 return WIFI_ERROR_INVALID_PARAMETER;
715         if (identity == NULL)
716                 return WIFI_ERROR_INVALID_PARAMETER;
717
718         *identity = g_strdup(h->eap_config->identity);
719
720         return WIFI_ERROR_NONE;
721 }
722
723 EXPORT_API int wifi_config_set_eap_identity(wifi_config_h config, const char* identity)
724 {
725         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_identity");
726         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
727
728         struct _wifi_config *h = (struct _wifi_config *)config;
729
730         if (config == NULL)
731                 return WIFI_ERROR_INVALID_PARAMETER;
732         if (h->eap_config == NULL)
733                 return WIFI_ERROR_INVALID_PARAMETER;
734
735         h->eap_config->identity = g_strdup(identity);
736
737         if (h->is_saved == TRUE) {
738                 //LCOV_EXCL_START
739                 wifi_dbus *dbus_h = NULL;
740                 gchar *config_id = NULL;
741
742                 dbus_h = _wifi_get_dbus_handle();
743                 if (dbus_h == NULL) {
744                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
745                         return WIFI_ERROR_INVALID_OPERATION;
746                 }
747
748                 config_id = wifi_config_get_config_id(h->name, h->security_type);
749
750                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_IDENTITY, identity);
751
752                 g_free(config_id);
753                 //LCOV_EXCL_STOP
754         }
755
756         return WIFI_ERROR_NONE;
757 }
758
759 EXPORT_API int wifi_config_get_eap_type(wifi_config_h config, wifi_eap_type_e *eap_type)
760 {
761         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_type");
762         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
763
764         struct _wifi_config *h = (struct _wifi_config *)config;
765
766         if (config == NULL)
767                 return WIFI_ERROR_INVALID_PARAMETER;
768         if (h->eap_config == NULL)
769                 return WIFI_ERROR_INVALID_PARAMETER;
770         if (eap_type == NULL)
771                 return WIFI_ERROR_INVALID_PARAMETER;
772
773         *eap_type = h->eap_config->eap_type;
774
775         return WIFI_ERROR_NONE;
776 }
777
778 EXPORT_API int wifi_config_set_eap_type(wifi_config_h config, wifi_eap_type_e eap_type)
779 {
780         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_type");
781         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
782
783         struct _wifi_config *h = (struct _wifi_config *)config;
784
785         if (config == NULL)
786                 return WIFI_ERROR_INVALID_PARAMETER;
787         if (h->eap_config == NULL)
788                 return WIFI_ERROR_INVALID_PARAMETER;
789
790         h->eap_config->eap_type = eap_type;
791
792         if (h->is_saved == TRUE) {
793                 //LCOV_EXCL_START
794                 wifi_dbus *dbus_h = NULL;
795                 gchar *config_id = NULL;
796                 gchar *value = NULL;
797
798                 dbus_h = _wifi_get_dbus_handle();
799                 if (dbus_h == NULL) {
800                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
801                         return WIFI_ERROR_INVALID_OPERATION;
802                 }
803
804                 config_id = wifi_config_get_config_id(h->name, h->security_type);
805
806                 value = wifi_eap_type_to_string(eap_type);
807
808                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_TYPE, value);
809
810                 g_free(config_id);
811                 g_free(value);
812                 //LCOV_EXCL_STOP
813         }
814
815         return WIFI_ERROR_NONE;
816 }
817
818 EXPORT_API int wifi_config_get_eap_auth_type(wifi_config_h config, wifi_eap_auth_type_e* eap_auth_type)
819 {
820         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_auth_type");
821         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
822
823         struct _wifi_config *h = (struct _wifi_config *)config;
824
825         if (config == NULL)
826                 return WIFI_ERROR_INVALID_PARAMETER;
827         if (h->eap_config == NULL)
828                 return WIFI_ERROR_INVALID_PARAMETER;
829         if (eap_auth_type == NULL)
830                 return WIFI_ERROR_INVALID_PARAMETER;
831
832         *eap_auth_type = h->eap_config->eap_auth_type;
833
834         return WIFI_ERROR_NONE;
835 }
836
837 EXPORT_API int wifi_config_set_eap_auth_type(wifi_config_h config, wifi_eap_auth_type_e eap_auth_type)
838 {
839         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_auth_type");
840         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
841
842         struct _wifi_config *h = (struct _wifi_config *)config;
843
844         if (config == NULL)
845                 return WIFI_ERROR_INVALID_PARAMETER;
846         if (h->eap_config == NULL)
847                 return WIFI_ERROR_INVALID_PARAMETER;
848
849         h->eap_config->eap_auth_type = eap_auth_type;
850
851         if (h->is_saved == TRUE) {
852                 //LCOV_EXCL_START
853                 wifi_dbus *dbus_h = NULL;
854                 gchar *config_id = NULL;
855                 gchar *value = NULL;
856
857                 dbus_h = _wifi_get_dbus_handle();
858                 if (dbus_h == NULL) {
859                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
860                         return WIFI_ERROR_INVALID_OPERATION;
861                 }
862
863                 config_id = wifi_config_get_config_id(h->name, h->security_type);
864
865                 value = wifi_eap_auth_type_to_string(eap_auth_type);
866
867                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_AUTH_TYPE, value);
868
869                 g_free(config_id);
870                 g_free(value);
871                 //LCOV_EXCL_STOP
872         }
873
874         return WIFI_ERROR_NONE;
875 }
876
877 EXPORT_API int wifi_config_get_eap_subject_match(wifi_config_h config, char** subject_match)
878 {
879         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_subject_match");
880         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
881
882         struct _wifi_config *h = (struct _wifi_config *)config;
883
884         if (config == NULL)
885                 return WIFI_ERROR_INVALID_PARAMETER;
886         if (h->eap_config == NULL)
887                 return WIFI_ERROR_INVALID_PARAMETER;
888         if (subject_match == NULL)
889                 return WIFI_ERROR_INVALID_PARAMETER;
890
891         *subject_match = g_strdup(h->eap_config->subject_match);
892
893         return WIFI_ERROR_NONE;
894 }
895
896 EXPORT_API int wifi_config_set_eap_subject_match(wifi_config_h config, const char* subject_match)
897 {
898         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_subject_match");
899         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
900
901         struct _wifi_config *h = (struct _wifi_config *)config;
902
903         if (config == NULL)
904                 return WIFI_ERROR_INVALID_PARAMETER;
905         if (h->eap_config == NULL)
906                 return WIFI_ERROR_INVALID_PARAMETER;
907
908         h->eap_config->subject_match = g_strdup(subject_match);
909
910         if (h->is_saved == TRUE) {
911                 //LCOV_EXCL_START
912                 wifi_dbus *dbus_h = NULL;
913                 gchar *config_id = NULL;
914
915                 dbus_h = _wifi_get_dbus_handle();
916                 if (dbus_h == NULL) {
917                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
918                         return WIFI_ERROR_INVALID_OPERATION;
919                 }
920
921                 config_id = wifi_config_get_config_id(h->name, h->security_type);
922
923                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_SUBJECT_MATCH, subject_match);
924
925                 g_free(config_id);
926                 //LCOV_EXCL_STOP
927         }
928
929         return WIFI_ERROR_NONE;
930 }