DA: Skip initializing failed_bssids list when eapol failure case
[platform/upstream/connman.git] / plugins / hh2serial-gps.c
1 /*
2  *
3  *  hh2serial GPS
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 <stdio.h>
27 #include <errno.h>
28
29 #define CONNMAN_API_SUBJECT_TO_CHANGE
30 #include <connman/plugin.h>
31 #include <connman/device.h>
32 #include <connman/log.h>
33
34 static struct connman_device *hh2serial_device;
35
36 static int set_reg(char *key, char *value)
37 {
38         FILE *reg_file;
39
40         reg_file = fopen(key, "w");
41         if (!reg_file)
42                 return -errno;
43
44         fprintf(reg_file, "%s", value);
45         fclose(reg_file);
46         return 0;
47 }
48
49 static int hh2serial_probe(struct connman_device *device)
50 {
51         return 0;
52 }
53
54 static void hh2serial_remove(struct connman_device *device)
55 {
56 }
57
58 static int hh2serial_enable(struct connman_device *device)
59 {
60         DBG("");
61
62         set_reg("/sys/class/gpio/expo_rt", "85");
63         set_reg("/sys/class/gpio/gpio85/direction", "out");
64         set_reg("/sys/class/gpio/gpio85/value", "1");
65
66         return 0;
67 }
68
69 static int hh2serial_disable(struct connman_device *device)
70 {
71         DBG("");
72
73         set_reg("/sys/class/gpio/expo_rt", "85");
74         set_reg("/sys/class/gpio/gpio85/direction", "out");
75         set_reg("/sys/class/gpio/gpio85/value", "0");
76
77         return 0;
78 }
79
80 static struct connman_device_driver hh2serial_device_driver = {
81         .name           = "hh2serial GPS",
82         .type           = CONNMAN_DEVICE_TYPE_GPS,
83         .enable         = hh2serial_enable,
84         .disable        = hh2serial_disable,
85         .probe          = hh2serial_probe,
86         .remove         = hh2serial_remove,
87 };
88
89 static int hh2serial_init(void)
90 {
91         int err;
92
93         err = connman_device_driver_register(&hh2serial_device_driver);
94         if (err < 0)
95                 return err;
96
97         hh2serial_device = connman_device_create("hh2serial_gps",
98                                                 CONNMAN_DEVICE_TYPE_GPS);
99         if (!hh2serial_device) {
100                 connman_device_driver_unregister(&hh2serial_device_driver);
101                 return -ENODEV;
102         }
103
104         err = connman_device_register(hh2serial_device);
105         if (err < 0) {
106                 connman_device_unref(hh2serial_device);
107                 return err;
108         }
109
110         return 0;
111 }
112
113 static void hh2serial_exit(void)
114 {
115         if (hh2serial_device) {
116                 connman_device_unregister(hh2serial_device);
117                 connman_device_unref(hh2serial_device);
118         }
119
120         connman_device_driver_unregister(&hh2serial_device_driver);
121 }
122
123 CONNMAN_PLUGIN_DEFINE(hh2serial_gps, "hh2serial GPS", VERSION,
124                 CONNMAN_PLUGIN_PRIORITY_LOW, hh2serial_init, hh2serial_exit)