Modify to load configurations
[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                 } else {
306                         h->address_family = WIFI_ADDRESS_FAMILY_IPV4;
307                         h->is_saved = TRUE;
308                         rv = callback((wifi_config_h)h, user_data);
309                         g_free(h->name);
310                         g_free(h->proxy_address);
311                         if (h->eap_config) {
312                                 g_free(h->eap_config->ca_cert);
313                                 g_free(h->eap_config->client_cert);
314                                 g_free(h->eap_config->private_key);
315                                 g_free(h->eap_config->anonymous_identity);
316                                 g_free(h->eap_config->identity);
317                                 g_free(h->eap_config->subject_match);
318                                 g_free(h->eap_config);
319                         }
320                         g_free(h);
321                         h = NULL;
322
323                         if (rv == false)
324                                 break;
325                 }
326
327                 config_ids = config_ids->next;
328         }
329
330         config_ids = g_slist_nth(config_ids, 0);
331         g_slist_free_full(config_ids, g_free);
332
333         return WIFI_ERROR_NONE;
334 }
335
336 EXPORT_API int wifi_config_get_name(wifi_config_h config, char **name)
337 {
338         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_name");
339         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
340
341         struct _wifi_config *h = (struct _wifi_config *)config;
342
343         if (_wifi_is_init() == false) {
344                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
345                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
346         }
347
348         if (config == NULL || name == NULL) {
349                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
350                 return WIFI_ERROR_INVALID_PARAMETER;
351         }
352
353         if (h->name != NULL)
354                 *name = g_strdup(h->name);
355         else
356                 *name = NULL;
357
358         return WIFI_ERROR_NONE;
359 }
360
361 EXPORT_API int wifi_config_get_security_type(wifi_config_h config, wifi_security_type_e *security_type)
362 {
363         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_security_type");
364         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
365
366         struct _wifi_config *h = (struct _wifi_config *)config;
367
368         if (_wifi_is_init() == false) {
369                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
370                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
371         }
372
373         if (config == NULL || security_type == NULL) {
374                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
375                 return WIFI_ERROR_INVALID_PARAMETER;
376         }
377
378         *security_type = h->security_type;
379
380         return WIFI_ERROR_NONE;
381 }
382
383 /**
384  * wifi configuration set field
385  */
386 EXPORT_API int wifi_config_set_proxy_address(wifi_config_h config, wifi_address_family_e address_family, const char *proxy_address)
387 {
388         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_proxy_address");
389         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
390
391         struct _wifi_config *h = (struct _wifi_config *)config;
392         int ret = WIFI_ERROR_NONE;
393
394         if (_wifi_is_init() == false) {
395                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
396                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
397         }
398
399         if (config == NULL) {
400                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
401                 return WIFI_ERROR_INVALID_PARAMETER;
402         }
403         if ((address_family != WIFI_ADDRESS_FAMILY_IPV4 && address_family != WIFI_ADDRESS_FAMILY_IPV6)) {
404                 WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
405                 return WIFI_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
406         }
407
408         if (address_family == WIFI_ADDRESS_FAMILY_IPV6) {
409                 WIFI_LOG(WIFI_ERROR, "Not supported yet"); //LCOV_EXCL_LINE
410                 return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; //LCOV_EXCL_LINE
411         }
412
413         h->address_family = address_family;
414         h->proxy_address = g_strdup(proxy_address);
415
416         if (h->is_saved == TRUE) {
417                 //LCOV_EXCL_START
418                 wifi_dbus *dbus_h = NULL;
419                 gchar *config_id = NULL;
420
421                 dbus_h = _wifi_get_dbus_handle();
422                 if (dbus_h == NULL) {
423                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
424                         return WIFI_ERROR_INVALID_OPERATION;
425                 }
426
427                 config_id = wifi_config_get_config_id(h->name, h->security_type);
428
429                 ret = wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_PROXYADDRESS, proxy_address);
430                 if (ret != WIFI_ERROR_NONE)
431                         WIFI_LOG(WIFI_ERROR, "Fail to set proxy address [%d]", ret);
432
433                 g_free(config_id);
434                 //LCOV_EXCL_STOP
435         }
436
437         return ret;
438 }
439
440 EXPORT_API int wifi_config_get_proxy_address(wifi_config_h config, wifi_address_family_e *address_family, char **proxy_address)
441 {
442         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_proxy_address");
443         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
444
445         struct _wifi_config *h = (struct _wifi_config *)config;
446
447         if (_wifi_is_init() == false) {
448                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
449                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
450         }
451
452         if (config == NULL || address_family == NULL || proxy_address == NULL) {
453                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
454                 return WIFI_ERROR_INVALID_PARAMETER;
455         }
456
457         *address_family = h->address_family;
458         *proxy_address = g_strdup(h->proxy_address);
459
460         return WIFI_ERROR_NONE;
461 }
462
463 EXPORT_API int wifi_config_set_hidden_ap_property(wifi_config_h config, bool hidden)
464 {
465         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_hidden_ap_property");
466         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
467
468         struct _wifi_config *h = (struct _wifi_config *)config;
469         int ret = WIFI_ERROR_NONE;
470
471         if (_wifi_is_init() == false) {
472                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
473                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
474         }
475
476         if (config == NULL) {
477                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
478                 return WIFI_ERROR_INVALID_PARAMETER;
479         }
480
481         h->is_hidden = hidden;
482
483         if (h->is_saved == TRUE) {
484                 //LCOV_EXCL_START
485                 wifi_dbus *dbus_h = NULL;
486                 char *config_id = NULL;
487                 char *hidden = NULL;
488
489                 dbus_h = _wifi_get_dbus_handle();
490                 if (dbus_h == NULL) {
491                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
492                         return WIFI_ERROR_INVALID_OPERATION;
493                 }
494
495                 config_id = wifi_config_get_config_id(h->name, h->security_type);
496
497                 if (h->is_hidden == TRUE)
498                         hidden = g_strdup("TRUE");
499                 else
500                         hidden = g_strdup("FALSE");
501
502                 ret = wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_HIDDEN, hidden);
503                 if (ret != WIFI_ERROR_NONE)
504                         WIFI_LOG(WIFI_ERROR, "Fail to set hidden [%d]", ret);
505
506                 g_free(hidden);
507                 g_free(config_id);
508                 //LCOV_EXCL_STOP
509         }
510
511         return ret;
512 }
513
514 EXPORT_API int wifi_config_get_hidden_ap_property(wifi_config_h config, bool *hidden)
515 {
516         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_hidden_ap_property");
517         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
518
519         struct _wifi_config *h = (struct _wifi_config *)config;
520
521         if (_wifi_is_init() == false) {
522                 WIFI_LOG(WIFI_ERROR, "Not initialized"); //LCOV_EXCL_LINE
523                 return WIFI_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
524         }
525
526         if (config == NULL || hidden == NULL) {
527                 WIFI_LOG(WIFI_ERROR, "Invalid parameter");
528                 return WIFI_ERROR_INVALID_PARAMETER;
529         }
530
531         *hidden = h->is_hidden;
532
533         return WIFI_ERROR_NONE;
534 }
535
536 EXPORT_API int wifi_config_get_eap_anonymous_identity(wifi_config_h config, char** anonymous_identity)
537 {
538         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_anonymous_identity");
539         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
540
541         struct _wifi_config *h = (struct _wifi_config *)config;
542
543         if (config == NULL)
544                 return WIFI_ERROR_INVALID_PARAMETER;
545         if (h->eap_config == NULL)
546                 return WIFI_ERROR_INVALID_PARAMETER;
547         if (anonymous_identity == NULL)
548                 return WIFI_ERROR_INVALID_PARAMETER;
549
550         *anonymous_identity = g_strdup(h->eap_config->anonymous_identity);
551
552         return WIFI_ERROR_NONE;
553 }
554
555 EXPORT_API int wifi_config_set_eap_anonymous_identity(wifi_config_h config, const char* anonymous_identity)
556 {
557         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_anonymous_identity");
558         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
559
560         struct _wifi_config *h = (struct _wifi_config *)config;
561
562         if (config == NULL)
563                 return WIFI_ERROR_INVALID_PARAMETER;
564         if (h->eap_config == NULL)
565                 return WIFI_ERROR_INVALID_PARAMETER;
566
567         h->eap_config->anonymous_identity = g_strdup(anonymous_identity);
568
569         if (h->is_saved == TRUE) {
570                 //LCOV_EXCL_START
571                 wifi_dbus *dbus_h = NULL;
572                 gchar *config_id = NULL;
573
574                 dbus_h = _wifi_get_dbus_handle();
575                 if (dbus_h == NULL) {
576                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
577                         return WIFI_ERROR_INVALID_OPERATION;
578                 }
579
580                 config_id = wifi_config_get_config_id(h->name, h->security_type);
581
582                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY, anonymous_identity);
583
584                 g_free(config_id);
585                 //LCOV_EXCL_STOP
586         }
587
588         return WIFI_ERROR_NONE;
589 }
590
591 EXPORT_API int wifi_config_get_eap_ca_cert_file(wifi_config_h config, char** ca_cert)
592 {
593         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_ca_cert_file");
594         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
595
596         struct _wifi_config *h = (struct _wifi_config *)config;
597
598         if (config == NULL)
599                 return WIFI_ERROR_INVALID_PARAMETER;
600         if (h->eap_config == NULL)
601                 return WIFI_ERROR_INVALID_PARAMETER;
602         if (ca_cert == NULL)
603                 return WIFI_ERROR_INVALID_PARAMETER;
604
605         *ca_cert = g_strdup(h->eap_config->ca_cert);
606
607         return WIFI_ERROR_NONE;
608 }
609
610 EXPORT_API int wifi_config_set_eap_ca_cert_file(wifi_config_h config, const char* ca_cert)
611 {
612         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_ca_cert_file");
613         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
614
615         struct _wifi_config *h = (struct _wifi_config *)config;
616
617         if (config == NULL)
618                 return WIFI_ERROR_INVALID_PARAMETER;
619         if (h->eap_config == NULL)
620                 return WIFI_ERROR_INVALID_PARAMETER;
621
622         h->eap_config->ca_cert = g_strdup(ca_cert);
623
624         if (h->is_saved == TRUE) {
625                 //LCOV_EXCL_START
626                 wifi_dbus *dbus_h = NULL;
627                 gchar *config_id = NULL;
628
629                 dbus_h = _wifi_get_dbus_handle();
630                 if (dbus_h == NULL) {
631                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
632                         return WIFI_ERROR_INVALID_OPERATION;
633                 }
634
635                 config_id = wifi_config_get_config_id(h->name, h->security_type);
636
637                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_CACERT, ca_cert);
638
639                 g_free(config_id);
640                 //LCOV_EXCL_STOP
641         }
642
643         return WIFI_ERROR_NONE;
644 }
645
646 EXPORT_API int wifi_config_get_eap_client_cert_file(wifi_config_h config, char** client_cert)
647 {
648         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_client_cert_file");
649         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
650
651         struct _wifi_config *h = (struct _wifi_config *)config;
652
653         if (config == NULL)
654                 return WIFI_ERROR_INVALID_PARAMETER;
655         if (h->eap_config == NULL)
656                 return WIFI_ERROR_INVALID_PARAMETER;
657         if (client_cert == NULL)
658                 return WIFI_ERROR_INVALID_PARAMETER;
659
660         *client_cert = g_strdup(h->eap_config->client_cert);
661
662         return WIFI_ERROR_NONE;
663 }
664
665 EXPORT_API int wifi_config_set_eap_client_cert_file(wifi_config_h config, const char* private_key, const char* client_cert)
666 {
667         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_client_cert_file");
668         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
669
670         struct _wifi_config *h = (struct _wifi_config *)config;
671
672         if (config == NULL)
673                 return WIFI_ERROR_INVALID_PARAMETER;
674         if (h->eap_config == NULL)
675                 return WIFI_ERROR_INVALID_PARAMETER;
676
677         h->eap_config->private_key = g_strdup(private_key);
678         h->eap_config->client_cert = g_strdup(client_cert);
679
680         if (h->is_saved == TRUE) {
681                 //LCOV_EXCL_START
682                 wifi_dbus *dbus_h = NULL;
683                 gchar *config_id = NULL;
684
685                 dbus_h = _wifi_get_dbus_handle();
686                 if (dbus_h == NULL) {
687                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
688                         return WIFI_ERROR_INVALID_OPERATION;
689                 }
690
691                 config_id = wifi_config_get_config_id(h->name, h->security_type);
692
693                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_CLIENTCERT, client_cert);
694                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_PRIVATEKEY, private_key);
695
696                 g_free(config_id);
697                 //LCOV_EXCL_STOP
698         }
699
700         return WIFI_ERROR_NONE;
701 }
702
703 EXPORT_API int wifi_config_get_eap_identity(wifi_config_h config, char** identity)
704 {
705         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_identity");
706         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
707
708         struct _wifi_config *h = (struct _wifi_config *)config;
709
710         if (config == NULL)
711                 return WIFI_ERROR_INVALID_PARAMETER;
712         if (h->eap_config == NULL)
713                 return WIFI_ERROR_INVALID_PARAMETER;
714         if (identity == NULL)
715                 return WIFI_ERROR_INVALID_PARAMETER;
716
717         *identity = g_strdup(h->eap_config->identity);
718
719         return WIFI_ERROR_NONE;
720 }
721
722 EXPORT_API int wifi_config_set_eap_identity(wifi_config_h config, const char* identity)
723 {
724         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_identity");
725         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
726
727         struct _wifi_config *h = (struct _wifi_config *)config;
728
729         if (config == NULL)
730                 return WIFI_ERROR_INVALID_PARAMETER;
731         if (h->eap_config == NULL)
732                 return WIFI_ERROR_INVALID_PARAMETER;
733
734         h->eap_config->identity = g_strdup(identity);
735
736         if (h->is_saved == TRUE) {
737                 //LCOV_EXCL_START
738                 wifi_dbus *dbus_h = NULL;
739                 gchar *config_id = NULL;
740
741                 dbus_h = _wifi_get_dbus_handle();
742                 if (dbus_h == NULL) {
743                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
744                         return WIFI_ERROR_INVALID_OPERATION;
745                 }
746
747                 config_id = wifi_config_get_config_id(h->name, h->security_type);
748
749                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_IDENTITY, identity);
750
751                 g_free(config_id);
752                 //LCOV_EXCL_STOP
753         }
754
755         return WIFI_ERROR_NONE;
756 }
757
758 EXPORT_API int wifi_config_get_eap_type(wifi_config_h config, wifi_eap_type_e *eap_type)
759 {
760         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_type");
761         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
762
763         struct _wifi_config *h = (struct _wifi_config *)config;
764
765         if (config == NULL)
766                 return WIFI_ERROR_INVALID_PARAMETER;
767         if (h->eap_config == NULL)
768                 return WIFI_ERROR_INVALID_PARAMETER;
769         if (eap_type == NULL)
770                 return WIFI_ERROR_INVALID_PARAMETER;
771
772         *eap_type = h->eap_config->eap_type;
773
774         return WIFI_ERROR_NONE;
775 }
776
777 EXPORT_API int wifi_config_set_eap_type(wifi_config_h config, wifi_eap_type_e eap_type)
778 {
779         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_type");
780         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
781
782         struct _wifi_config *h = (struct _wifi_config *)config;
783
784         if (config == NULL)
785                 return WIFI_ERROR_INVALID_PARAMETER;
786         if (h->eap_config == NULL)
787                 return WIFI_ERROR_INVALID_PARAMETER;
788
789         h->eap_config->eap_type = eap_type;
790
791         if (h->is_saved == TRUE) {
792                 //LCOV_EXCL_START
793                 wifi_dbus *dbus_h = NULL;
794                 gchar *config_id = NULL;
795                 gchar *value = NULL;
796
797                 dbus_h = _wifi_get_dbus_handle();
798                 if (dbus_h == NULL) {
799                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
800                         return WIFI_ERROR_INVALID_OPERATION;
801                 }
802
803                 config_id = wifi_config_get_config_id(h->name, h->security_type);
804
805                 value = wifi_eap_type_to_string(eap_type);
806
807                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_TYPE, value);
808
809                 g_free(config_id);
810                 g_free(value);
811                 //LCOV_EXCL_STOP
812         }
813
814         return WIFI_ERROR_NONE;
815 }
816
817 EXPORT_API int wifi_config_get_eap_auth_type(wifi_config_h config, wifi_eap_auth_type_e* eap_auth_type)
818 {
819         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_auth_type");
820         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
821
822         struct _wifi_config *h = (struct _wifi_config *)config;
823
824         if (config == NULL)
825                 return WIFI_ERROR_INVALID_PARAMETER;
826         if (h->eap_config == NULL)
827                 return WIFI_ERROR_INVALID_PARAMETER;
828         if (eap_auth_type == NULL)
829                 return WIFI_ERROR_INVALID_PARAMETER;
830
831         *eap_auth_type = h->eap_config->eap_auth_type;
832
833         return WIFI_ERROR_NONE;
834 }
835
836 EXPORT_API int wifi_config_set_eap_auth_type(wifi_config_h config, wifi_eap_auth_type_e eap_auth_type)
837 {
838         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_auth_type");
839         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
840
841         struct _wifi_config *h = (struct _wifi_config *)config;
842
843         if (config == NULL)
844                 return WIFI_ERROR_INVALID_PARAMETER;
845         if (h->eap_config == NULL)
846                 return WIFI_ERROR_INVALID_PARAMETER;
847
848         h->eap_config->eap_auth_type = eap_auth_type;
849
850         if (h->is_saved == TRUE) {
851                 //LCOV_EXCL_START
852                 wifi_dbus *dbus_h = NULL;
853                 gchar *config_id = NULL;
854                 gchar *value = NULL;
855
856                 dbus_h = _wifi_get_dbus_handle();
857                 if (dbus_h == NULL) {
858                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
859                         return WIFI_ERROR_INVALID_OPERATION;
860                 }
861
862                 config_id = wifi_config_get_config_id(h->name, h->security_type);
863
864                 value = wifi_eap_auth_type_to_string(eap_auth_type);
865
866                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_AUTH_TYPE, value);
867
868                 g_free(config_id);
869                 g_free(value);
870                 //LCOV_EXCL_STOP
871         }
872
873         return WIFI_ERROR_NONE;
874 }
875
876 EXPORT_API int wifi_config_get_eap_subject_match(wifi_config_h config, char** subject_match)
877 {
878         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_get_eap_subject_match");
879         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
880
881         struct _wifi_config *h = (struct _wifi_config *)config;
882
883         if (config == NULL)
884                 return WIFI_ERROR_INVALID_PARAMETER;
885         if (h->eap_config == NULL)
886                 return WIFI_ERROR_INVALID_PARAMETER;
887         if (subject_match == NULL)
888                 return WIFI_ERROR_INVALID_PARAMETER;
889
890         *subject_match = g_strdup(h->eap_config->subject_match);
891
892         return WIFI_ERROR_NONE;
893 }
894
895 EXPORT_API int wifi_config_set_eap_subject_match(wifi_config_h config, const char* subject_match)
896 {
897         DEPRECATED_LOG(__FUNCTION__, "wifi_manager_config_set_eap_subject_match");
898         CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
899
900         struct _wifi_config *h = (struct _wifi_config *)config;
901
902         if (config == NULL)
903                 return WIFI_ERROR_INVALID_PARAMETER;
904         if (h->eap_config == NULL)
905                 return WIFI_ERROR_INVALID_PARAMETER;
906
907         h->eap_config->subject_match = g_strdup(subject_match);
908
909         if (h->is_saved == TRUE) {
910                 //LCOV_EXCL_START
911                 wifi_dbus *dbus_h = NULL;
912                 gchar *config_id = NULL;
913
914                 dbus_h = _wifi_get_dbus_handle();
915                 if (dbus_h == NULL) {
916                         WIFI_LOG(WIFI_ERROR, "Not initialized for wifi dbus connection");
917                         return WIFI_ERROR_INVALID_OPERATION;
918                 }
919
920                 config_id = wifi_config_get_config_id(h->name, h->security_type);
921
922                 wifi_configuration_set_field(dbus_h, config_id, WIFI_CONFIG_EAP_SUBJECT_MATCH, subject_match);
923
924                 g_free(config_id);
925                 //LCOV_EXCL_STOP
926         }
927
928         return WIFI_ERROR_NONE;
929 }