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