service: Add function to set the favorite flag
[framework/connectivity/connman.git] / src / config.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <errno.h>
27 #include <stdio.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <sys/vfs.h>
31 #include <sys/inotify.h>
32 #include <glib.h>
33
34 #include "connman.h"
35
36 struct connman_config_service {
37         char *ident;
38         char *name;
39         char *type;
40         void *ssid;
41         unsigned int ssid_len;
42         char *eap;
43         char *identity;
44         char *ca_cert_file;
45         char *client_cert_file;
46         char *private_key_file;
47         char *private_key_passphrase;
48         char *private_key_passphrase_type;
49         char *phase2;
50         char *passphrase;
51         GSList *service_identifiers;
52         char *config_ident; /* file prefix */
53         char *config_entry; /* entry name */
54 };
55
56 struct connman_config {
57         char *ident;
58         char *name;
59         char *description;
60         connman_bool_t protected;
61         GHashTable *service_table;
62 };
63
64 static GHashTable *config_table = NULL;
65 static GSList *protected_services = NULL;
66
67 static int inotify_wd = -1;
68
69 static GIOChannel *inotify_channel = NULL;
70 static uint inotify_watch = 0;
71
72 #define INTERNAL_CONFIG_PREFIX           "__internal"
73
74 /* Definition of possible strings in the .config files */
75 #define CONFIG_KEY_NAME                "Name"
76 #define CONFIG_KEY_DESC                "Description"
77 #define CONFIG_KEY_PROT                "Protected"
78
79 #define SERVICE_KEY_TYPE               "Type"
80 #define SERVICE_KEY_NAME               "Name"
81 #define SERVICE_KEY_SSID               "SSID"
82 #define SERVICE_KEY_EAP                "EAP"
83 #define SERVICE_KEY_CA_CERT            "CACertFile"
84 #define SERVICE_KEY_CL_CERT            "ClientCertFile"
85 #define SERVICE_KEY_PRV_KEY            "PrivateKeyFile"
86 #define SERVICE_KEY_PRV_KEY_PASS       "PrivateKeyPassphrase"
87 #define SERVICE_KEY_PRV_KEY_PASS_TYPE  "PrivateKeyPassphraseType"
88 #define SERVICE_KEY_IDENTITY           "Identity"
89 #define SERVICE_KEY_PHASE2             "Phase2"
90 #define SERVICE_KEY_PASSPHRASE         "Passphrase"
91
92 static const char *config_possible_keys[] = {
93         CONFIG_KEY_NAME,
94         CONFIG_KEY_DESC,
95         CONFIG_KEY_PROT,
96         NULL,
97 };
98
99 static const char *service_possible_keys[] = {
100         SERVICE_KEY_TYPE,
101         SERVICE_KEY_NAME,
102         SERVICE_KEY_SSID,
103         SERVICE_KEY_EAP,
104         SERVICE_KEY_CA_CERT,
105         SERVICE_KEY_CL_CERT,
106         SERVICE_KEY_PRV_KEY,
107         SERVICE_KEY_PRV_KEY_PASS,
108         SERVICE_KEY_PRV_KEY_PASS_TYPE,
109         SERVICE_KEY_IDENTITY,
110         SERVICE_KEY_PHASE2,
111         SERVICE_KEY_PASSPHRASE,
112         NULL,
113 };
114
115 static void unregister_config(gpointer data)
116 {
117         struct connman_config *config = data;
118
119         connman_info("Removing configuration %s", config->ident);
120
121         g_hash_table_destroy(config->service_table);
122
123         g_free(config->description);
124         g_free(config->name);
125         g_free(config->ident);
126         g_free(config);
127 }
128
129 static void unregister_service(gpointer data)
130 {
131         struct connman_config_service *config_service = data;
132         struct connman_service *service;
133         char *service_id;
134         GSList *list;
135
136         connman_info("Removing service configuration %s",
137                                                 config_service->ident);
138
139         protected_services = g_slist_remove(protected_services,
140                                                 config_service);
141
142         for (list = config_service->service_identifiers; list != NULL;
143                                                         list = list->next) {
144                 service_id = list->data;
145
146                 service = __connman_service_lookup_from_ident(service_id);
147                 if (service != NULL) {
148                         __connman_service_set_immutable(service, FALSE);
149                         __connman_service_remove(service);
150                 }
151
152                 if (__connman_storage_remove_service(service_id) == FALSE)
153                         DBG("Could not remove all files for service %s",
154                                                                 service_id);
155         }
156
157         g_free(config_service->ident);
158         g_free(config_service->type);
159         g_free(config_service->name);
160         g_free(config_service->ssid);
161         g_free(config_service->eap);
162         g_free(config_service->identity);
163         g_free(config_service->ca_cert_file);
164         g_free(config_service->client_cert_file);
165         g_free(config_service->private_key_file);
166         g_free(config_service->private_key_passphrase);
167         g_free(config_service->private_key_passphrase_type);
168         g_free(config_service->phase2);
169         g_free(config_service->passphrase);
170         g_slist_free_full(config_service->service_identifiers, g_free);
171         g_free(config_service->config_ident);
172         g_free(config_service->config_entry);
173         g_free(config_service);
174 }
175
176 static void check_keys(GKeyFile *keyfile, const char *group,
177                         const char **possible_keys)
178 {
179         char **avail_keys;
180         gsize nb_avail_keys, i, j;
181
182         avail_keys = g_key_file_get_keys(keyfile, group, &nb_avail_keys, NULL);
183         if (avail_keys == NULL)
184                 return;
185
186         /*
187          * For each key in the configuration file,
188          * verify it is understood by connman
189          */
190         for (i = 0 ; i < nb_avail_keys; i++) {
191                 for (j = 0; possible_keys[j] ; j++)
192                         if (g_strcmp0(avail_keys[i], possible_keys[j]) == 0)
193                                 break;
194
195                 if (possible_keys[j] == NULL)
196                         connman_warn("Unknown configuration key %s in [%s]",
197                                         avail_keys[i], group);
198         }
199
200         g_strfreev(avail_keys);
201 }
202
203 static connman_bool_t
204 is_protected_service(struct connman_config_service *service)
205 {
206         GSList *list;
207
208         DBG("ident %s", service->ident);
209
210         for (list = protected_services; list; list = list->next) {
211                 struct connman_config_service *s = list->data;
212
213                 if (g_strcmp0(s->type, service->type) != 0)
214                         continue;
215
216                 if (s->ssid == NULL || service->ssid == NULL)
217                         continue;
218
219                 if (s->ssid_len != service->ssid_len)
220                         continue;
221
222                 if (g_strcmp0(service->type, "wifi") == 0 &&
223                         strncmp(s->ssid, service->ssid, s->ssid_len) == 0) {
224                         return TRUE;
225                 }
226         }
227
228         return FALSE;
229 }
230
231 static int load_service(GKeyFile *keyfile, const char *group,
232                                                 struct connman_config *config)
233 {
234         struct connman_config_service *service;
235         const char *ident;
236         char *str, *hex_ssid;
237         gboolean service_created = FALSE;
238         int err;
239
240         /* Strip off "service_" prefix */
241         ident = group + 8;
242
243         if (strlen(ident) < 1)
244                 return -EINVAL;
245
246         /* Verify that provided keys are good */
247         check_keys(keyfile, group, service_possible_keys);
248
249         service = g_hash_table_lookup(config->service_table, ident);
250         if (service == NULL) {
251                 service = g_try_new0(struct connman_config_service, 1);
252                 if (service == NULL)
253                         return -ENOMEM;
254
255                 service->ident = g_strdup(ident);
256
257                 service_created = TRUE;
258         }
259
260         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_TYPE, NULL);
261         if (str != NULL) {
262                 g_free(service->type);
263                 service->type = str;
264         }
265
266         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_NAME, NULL);
267         if (str != NULL) {
268                 g_free(service->name);
269                 service->name = str;
270         }
271
272         hex_ssid = g_key_file_get_string(keyfile, group, SERVICE_KEY_SSID,
273                                          NULL);
274         if (hex_ssid != NULL) {
275                 char *ssid;
276                 unsigned int i, j = 0, hex;
277                 size_t hex_ssid_len = strlen(hex_ssid);
278
279                 ssid = g_try_malloc0(hex_ssid_len / 2);
280                 if (ssid == NULL) {
281                         err = -ENOMEM;
282                         g_free(hex_ssid);
283                         goto err;
284                 }
285
286                 for (i = 0; i < hex_ssid_len; i += 2) {
287                         if (sscanf(hex_ssid + i, "%02x", &hex) <= 0) {
288                                 connman_warn("Invalid SSID %s", hex_ssid);
289                                 g_free(ssid);
290                                 g_free(hex_ssid);
291                                 err = -EILSEQ;
292                                 goto err;
293                         }
294                         ssid[j++] = hex;
295                 }
296
297                 g_free(hex_ssid);
298
299                 g_free(service->ssid);
300                 service->ssid = ssid;
301                 service->ssid_len = hex_ssid_len / 2;
302         } else if (service->name != NULL) {
303                 char *ssid;
304                 unsigned int ssid_len;
305
306                 ssid_len = strlen(service->name);
307                 ssid = g_try_malloc0(ssid_len);
308                 if (ssid == NULL) {
309                         err = -ENOMEM;
310                         goto err;
311                 }
312
313                 memcpy(ssid, service->name, ssid_len);
314                 g_free(service->ssid);
315                 service->ssid = ssid;
316                 service->ssid_len = ssid_len;
317         }
318
319         if (is_protected_service(service) == TRUE) {
320                 connman_error("Trying to provision a protected service");
321                 err = -EACCES;
322                 goto err;
323         }
324
325         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_EAP, NULL);
326         if (str != NULL) {
327                 g_free(service->eap);
328                 service->eap = str;
329         }
330
331         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_CA_CERT, NULL);
332         if (str != NULL) {
333                 g_free(service->ca_cert_file);
334                 service->ca_cert_file = str;
335         }
336
337         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_CL_CERT, NULL);
338         if (str != NULL) {
339                 g_free(service->client_cert_file);
340                 service->client_cert_file = str;
341         }
342
343         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PRV_KEY, NULL);
344         if (str != NULL) {
345                 g_free(service->private_key_file);
346                 service->private_key_file = str;
347         }
348
349         str = g_key_file_get_string(keyfile, group,
350                                                 SERVICE_KEY_PRV_KEY_PASS, NULL);
351         if (str != NULL) {
352                 g_free(service->private_key_passphrase);
353                 service->private_key_passphrase = str;
354         }
355
356         str = g_key_file_get_string(keyfile, group,
357                                         SERVICE_KEY_PRV_KEY_PASS_TYPE, NULL);
358         if (str != NULL) {
359                 g_free(service->private_key_passphrase_type);
360                 service->private_key_passphrase_type = str;
361         }
362
363         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_IDENTITY, NULL);
364         if (str != NULL) {
365                 g_free(service->identity);
366                 service->identity = str;
367         }
368
369         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PHASE2, NULL);
370         if (str != NULL) {
371                 g_free(service->phase2);
372                 service->phase2 = str;
373         }
374
375         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PASSPHRASE,
376                                         NULL);
377         if (str != NULL) {
378                 g_free(service->passphrase);
379                 service->passphrase = str;
380         }
381
382         service->config_ident = g_strdup(config->ident);
383         service->config_entry = g_strdup_printf("service_%s", service->ident);
384
385         if (service_created)
386                 g_hash_table_insert(config->service_table, service->ident,
387                                         service);
388
389         if (config->protected == TRUE)
390                 protected_services =
391                         g_slist_append(protected_services, service);
392
393         connman_info("Adding service configuration %s", service->ident);
394
395         return 0;
396
397 err:
398         if (service_created == TRUE) {
399                 g_free(service->ident);
400                 g_free(service->type);
401                 g_free(service->name);
402                 g_free(service->ssid);
403                 g_free(service);
404         }
405
406         return err;
407 }
408
409 static int load_config(struct connman_config *config)
410 {
411         GKeyFile *keyfile;
412         GError *error = NULL;
413         gsize length;
414         char **groups;
415         char *str;
416         gboolean protected, found = FALSE;
417         int i;
418
419         DBG("config %p", config);
420
421         keyfile = __connman_storage_load_config(config->ident);
422         if (keyfile == NULL)
423                 return -EIO;
424
425         /* Verify keys validity of the global section */
426         check_keys(keyfile, "global", config_possible_keys);
427
428         str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_NAME, NULL);
429         if (str != NULL) {
430                 g_free(config->name);
431                 config->name = str;
432         }
433
434         str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_DESC, NULL);
435         if (str != NULL) {
436                 g_free(config->description);
437                 config->description = str;
438         }
439
440         protected = g_key_file_get_boolean(keyfile, "global",
441                                         CONFIG_KEY_PROT, &error);
442         if (error == NULL)
443                 config->protected = protected;
444         else
445                 config->protected = TRUE;
446
447         groups = g_key_file_get_groups(keyfile, &length);
448
449         for (i = 0; groups[i] != NULL; i++) {
450                 if (g_str_has_prefix(groups[i], "service_") == TRUE) {
451                         if (load_service(keyfile, groups[i], config) == 0)
452                                 found = TRUE;
453                 }
454         }
455
456         if (found == FALSE)
457                 connman_warn("Config file %s/%s.config does not contain any "
458                         "configuration that can be provisioned!",
459                         STORAGEDIR, config->ident);
460
461         g_strfreev(groups);
462
463         g_key_file_free(keyfile);
464
465         return 0;
466 }
467
468 static struct connman_config *create_config(const char *ident)
469 {
470         struct connman_config *config;
471
472         DBG("ident %s", ident);
473
474         if (g_hash_table_lookup(config_table, ident) != NULL)
475                 return NULL;
476
477         config = g_try_new0(struct connman_config, 1);
478         if (config == NULL)
479                 return NULL;
480
481         config->ident = g_strdup(ident);
482
483         config->service_table = g_hash_table_new_full(g_str_hash, g_str_equal,
484                                                 NULL, unregister_service);
485
486         g_hash_table_insert(config_table, config->ident, config);
487
488         connman_info("Adding configuration %s", config->ident);
489
490         return config;
491 }
492
493 static connman_bool_t validate_ident(const char *ident)
494 {
495         unsigned int i;
496
497         if (ident == NULL)
498                 return FALSE;
499
500         for (i = 0; i < strlen(ident); i++)
501                 if (g_ascii_isprint(ident[i]) == FALSE)
502                         return FALSE;
503
504         return TRUE;
505 }
506
507 static int read_configs(void)
508 {
509         GDir *dir;
510
511         DBG("");
512
513         dir = g_dir_open(STORAGEDIR, 0, NULL);
514         if (dir != NULL) {
515                 const gchar *file;
516
517                 while ((file = g_dir_read_name(dir)) != NULL) {
518                         GString *str;
519                         gchar *ident;
520
521                         if (g_str_has_suffix(file, ".config") == FALSE)
522                                 continue;
523
524                         ident = g_strrstr(file, ".config");
525                         if (ident == NULL)
526                                 continue;
527
528                         str = g_string_new_len(file, ident - file);
529                         if (str == NULL)
530                                 continue;
531
532                         ident = g_string_free(str, FALSE);
533
534                         if (validate_ident(ident) == TRUE) {
535                                 struct connman_config *config;
536
537                                 config = create_config(ident);
538                                 if (config != NULL)
539                                         load_config(config);
540                         } else {
541                                 connman_error("Invalid config ident %s", ident);
542                         }
543                         g_free(ident);
544                 }
545
546                 g_dir_close(dir);
547         }
548
549         return 0;
550 }
551
552 static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
553                                                         gpointer user_data)
554 {
555         char buffer[256];
556         char *next_event;
557         gsize bytes_read;
558         GIOStatus status;
559
560         if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
561                 inotify_watch = 0;
562                 return FALSE;
563         }
564
565         status = g_io_channel_read_chars(channel, buffer,
566                                         sizeof(buffer) -1, &bytes_read, NULL);
567
568         switch (status) {
569         case G_IO_STATUS_NORMAL:
570                 break;
571         case G_IO_STATUS_AGAIN:
572                 return TRUE;
573         default:
574                 connman_error("Reading from inotify channel failed");
575                 inotify_watch = 0;
576                 return FALSE;
577         }
578
579         next_event = buffer;
580
581         while (bytes_read > 0) {
582                 struct inotify_event *event;
583                 gchar *ext;
584                 gchar *ident;
585                 gsize len;
586
587                 event = (struct inotify_event *) next_event;
588                 if (event->len)
589                         ident = next_event + sizeof(struct inotify_event);
590                 else
591                         ident = NULL;
592
593                 len = sizeof(struct inotify_event) + event->len;
594
595                 /* check if inotify_event block fit */
596                 if (len > bytes_read)
597                         break;
598
599                 next_event += len;
600                 bytes_read -= len;
601
602                 if (ident == NULL)
603                         continue;
604
605                 if (g_str_has_suffix(ident, ".config") == FALSE)
606                         continue;
607
608                 ext = g_strrstr(ident, ".config");
609                 if (ext == NULL)
610                         continue;
611
612                 *ext = '\0';
613
614                 if (validate_ident(ident) == FALSE) {
615                         connman_error("Invalid config ident %s", ident);
616                         continue;
617                 }
618
619                 if (event->mask & IN_CREATE)
620                         create_config(ident);
621
622                 if (event->mask & IN_MODIFY) {
623                         struct connman_config *config;
624
625                         config = g_hash_table_lookup(config_table, ident);
626                         if (config != NULL) {
627                                 g_hash_table_remove_all(config->service_table);
628                                 load_config(config);
629                                 __connman_service_provision_changed(ident);
630                         }
631                 }
632
633                 if (event->mask & IN_DELETE)
634                         g_hash_table_remove(config_table, ident);
635         }
636
637         return TRUE;
638 }
639
640 static int create_watch(void)
641 {
642         int fd;
643
644         fd = inotify_init();
645         if (fd < 0)
646                 return -EIO;
647
648         inotify_wd = inotify_add_watch(fd, STORAGEDIR,
649                                         IN_MODIFY | IN_CREATE | IN_DELETE);
650         if (inotify_wd < 0) {
651                 connman_error("Creation of STORAGEDIR  watch failed");
652                 close(fd);
653                 return -EIO;
654         }
655
656         inotify_channel = g_io_channel_unix_new(fd);
657         if (inotify_channel == NULL) {
658                 connman_error("Creation of inotify channel failed");
659                 inotify_rm_watch(fd, inotify_wd);
660                 inotify_wd = 0;
661
662                 close(fd);
663                 return -EIO;
664         }
665
666         g_io_channel_set_close_on_unref(inotify_channel, TRUE);
667         g_io_channel_set_encoding(inotify_channel, NULL, NULL);
668         g_io_channel_set_buffered(inotify_channel, FALSE);
669
670         inotify_watch = g_io_add_watch(inotify_channel,
671                                 G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
672                                 inotify_data, NULL);
673
674         return 0;
675 }
676
677 static void remove_watch(void)
678 {
679         int fd;
680
681         if (inotify_channel == NULL)
682                 return;
683
684         if (inotify_watch > 0) {
685                 g_source_remove(inotify_watch);
686                 inotify_watch = 0;
687         }
688
689         fd = g_io_channel_unix_get_fd(inotify_channel);
690
691         if (inotify_wd >= 0) {
692                 inotify_rm_watch(fd, inotify_wd);
693                 inotify_wd = 0;
694         }
695
696         g_io_channel_unref(inotify_channel);
697 }
698
699 int __connman_config_init(void)
700 {
701         DBG("");
702
703         config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
704                                                 NULL, unregister_config);
705
706         create_watch();
707
708         return read_configs();
709 }
710
711 void __connman_config_cleanup(void)
712 {
713         DBG("");
714
715         remove_watch();
716
717         g_hash_table_destroy(config_table);
718         config_table = NULL;
719 }
720
721 static char *config_pem_fsid(const char *pem_file)
722 {
723         struct statfs buf;
724         unsigned *fsid = (unsigned *) &buf.f_fsid;
725         unsigned long long fsid64;
726
727         if (pem_file == NULL)
728                 return NULL;
729
730         if (statfs(pem_file, &buf) < 0) {
731                 connman_error("statfs error %s for %s",
732                                                 strerror(errno), pem_file);
733                 return NULL;
734         }
735
736         fsid64 = ((unsigned long long) fsid[0] << 32) | fsid[1];
737
738         return g_strdup_printf("%llx", fsid64);
739 }
740
741 static void provision_service(gpointer key, gpointer value, gpointer user_data)
742 {
743         struct connman_service *service = user_data;
744         struct connman_config_service *config = value;
745         struct connman_network *network;
746         const void *ssid, *service_id;
747         unsigned int ssid_len;
748
749         /* For now only WiFi service entries are supported */
750         if (g_strcmp0(config->type, "wifi") != 0)
751                 return;
752
753         network = __connman_service_get_network(service);
754         if (network == NULL) {
755                 connman_error("Service has no network set");
756                 return;
757         }
758
759         ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
760         if (ssid == NULL) {
761                 connman_error("Network SSID not set");
762                 return;
763         }
764
765         if (config->ssid == NULL || ssid_len != config->ssid_len)
766                 return;
767
768         if (memcmp(config->ssid, ssid, ssid_len) != 0)
769                 return;
770
771         service_id = __connman_service_get_ident(service);
772         config->service_identifiers =
773                 g_slist_prepend(config->service_identifiers,
774                                 g_strdup(service_id));
775
776         __connman_service_set_immutable(service, TRUE);
777
778         __connman_service_set_favorite_delayed(service, TRUE, TRUE);
779
780         __connman_service_set_config(service, config->config_ident,
781                                                 config->config_entry);
782
783         if (config->eap != NULL)
784                 __connman_service_set_string(service, "EAP", config->eap);
785
786         if (config->identity != NULL)
787                 __connman_service_set_string(service, "Identity",
788                                                         config->identity);
789
790         if (config->ca_cert_file != NULL)
791                 __connman_service_set_string(service, "CACertFile",
792                                                         config->ca_cert_file);
793
794         if (config->client_cert_file != NULL)
795                 __connman_service_set_string(service, "ClientCertFile",
796                                                 config->client_cert_file);
797
798         if (config->private_key_file != NULL)
799                 __connman_service_set_string(service, "PrivateKeyFile",
800                                                 config->private_key_file);
801
802         if (g_strcmp0(config->private_key_passphrase_type, "fsid") == 0 &&
803                                         config->private_key_file != NULL) {
804                 char *fsid;
805
806                 fsid = config_pem_fsid(config->private_key_file);
807                 if (fsid == NULL)
808                         return;
809
810                 g_free(config->private_key_passphrase);
811                 config->private_key_passphrase = fsid;
812         }
813
814         if (config->private_key_passphrase != NULL) {
815                 __connman_service_set_string(service, "PrivateKeyPassphrase",
816                                                 config->private_key_passphrase);
817                 /*
818                  * TODO: Support for PEAP with both identity and key passwd.
819                  * In that case, we should check if both of them are found
820                  * from the config file. If not, we should not set the
821                  * service passphrase in order for the UI to request for an
822                  * additional passphrase.
823                  */
824         }
825
826         if (config->phase2 != NULL)
827                 __connman_service_set_string(service, "Phase2", config->phase2);
828
829         if (config->passphrase != NULL)
830                 __connman_service_set_string(service, "Passphrase", config->passphrase);
831 }
832
833 int __connman_config_provision_service(struct connman_service *service)
834 {
835         enum connman_service_type type;
836         GHashTableIter iter;
837         gpointer value, key;
838
839         DBG("service %p", service);
840
841         /* For now only WiFi services are supported */
842         type = connman_service_get_type(service);
843         if (type != CONNMAN_SERVICE_TYPE_WIFI)
844                 return -ENOSYS;
845
846         g_hash_table_iter_init(&iter, config_table);
847
848         while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
849                 struct connman_config *config = value;
850
851                 g_hash_table_foreach(config->service_table,
852                                                 provision_service, service);
853         }
854
855         return 0;
856 }
857
858 int __connman_config_provision_service_ident(struct connman_service *service,
859                                                         const char *ident)
860 {
861         enum connman_service_type type;
862         struct connman_config *config;
863
864         DBG("service %p", service);
865
866         /* For now only WiFi services are supported */
867         type = connman_service_get_type(service);
868         if (type != CONNMAN_SERVICE_TYPE_WIFI)
869                 return -ENOSYS;
870
871         config = g_hash_table_lookup(config_table, ident);
872         if(config != NULL)
873                 g_hash_table_foreach(config->service_table,
874                                                 provision_service, service);
875
876         return 0;
877 }