Skip to content

Latest commit

 

History

History
210 lines (193 loc) · 9.18 KB

usb_moded-dyn-config.c

File metadata and controls

210 lines (193 loc) · 9.18 KB
 
May 10, 2011
May 10, 2011
1
/**
Jul 6, 2018
Jul 6, 2018
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
* @file usb_moded-dyn-mode.c
*
* Copyright (C) 2011 Nokia Corporation. All rights reserved.
* Copyright (C) 2013-2018 Jolla. All rights reserved.
*
* @author: Philippe De Swert <philippe.de-swert@nokia.com>
* @author: Philippe De Swert <philippedeswert@gmail.com>
* @author: Philippe De Swert <philippe.deswert@jollamobile.com>
* @author: Thomas Perl <thomas.perl@jolla.com>
* @author: Slava Monich <slava.monich@jolla.com>
* @author: Simo Piiroinen <simo.piiroinen@jollamobile.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Lesser GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
May 10, 2011
May 10, 2011
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "usb_moded-dyn-config.h"
#include "usb_moded-log.h"
Jul 6, 2018
Jul 6, 2018
40
41
42
/* ========================================================================= *
* Prototypes
* ========================================================================= */
May 10, 2011
May 10, 2011
43
Jul 6, 2018
Jul 6, 2018
44
45
46
47
48
49
50
51
52
53
54
55
56
/* -- dynconfig -- */
void dynconfig_free_list_item(mode_list_elem *list_item);
void dynconfig_free_mode_list(GList *modelist);
static gint dynconfig_compare_modes (gconstpointer a, gconstpointer b);
GList *dynconfig_read_mode_list(int diag);
static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename);
/* ========================================================================= *
* Functions
* ========================================================================= */
void dynconfig_free_list_item(mode_list_elem *list_item)
Oct 22, 2013
Oct 22, 2013
57
{
Jul 6, 2018
Jul 6, 2018
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
free(list_item->mode_name);
free(list_item->mode_module);
free(list_item->network_interface);
free(list_item->sysfs_path);
free(list_item->sysfs_value);
free(list_item->sysfs_reset_value);
free(list_item->softconnect);
free(list_item->softconnect_disconnect);
free(list_item->softconnect_path);
free(list_item->android_extra_sysfs_path);
free(list_item->android_extra_sysfs_value);
free(list_item->android_extra_sysfs_path2);
free(list_item->android_extra_sysfs_value2);
free(list_item->android_extra_sysfs_path3);
free(list_item->android_extra_sysfs_value3);
free(list_item->android_extra_sysfs_path4);
free(list_item->android_extra_sysfs_value4);
free(list_item->idProduct);
free(list_item->idVendorOverride);
Apr 15, 2015
Apr 15, 2015
77
#ifdef CONNMAN
Jul 6, 2018
Jul 6, 2018
78
free(list_item->connman_tethering);
Apr 15, 2015
Apr 15, 2015
79
#endif
Jul 6, 2018
Jul 6, 2018
80
free(list_item);
Oct 22, 2013
Oct 22, 2013
81
82
}
Jul 6, 2018
Jul 6, 2018
83
void dynconfig_free_mode_list(GList *modelist)
Oct 22, 2013
Oct 22, 2013
84
{
Jul 6, 2018
Jul 6, 2018
85
86
87
88
89
90
if(modelist)
{
g_list_foreach(modelist, (GFunc) dynconfig_free_list_item, NULL);
g_list_free(modelist);
modelist = 0;
}
Oct 22, 2013
Oct 22, 2013
91
92
}
Jul 6, 2018
Jul 6, 2018
93
static gint dynconfig_compare_modes(gconstpointer a, gconstpointer b)
Mar 11, 2014
Mar 11, 2014
94
{
Jul 6, 2018
Jul 6, 2018
95
96
struct mode_list_elem *aa = (struct mode_list_elem *)a;
struct mode_list_elem *bb = (struct mode_list_elem *)b;
Mar 11, 2014
Mar 11, 2014
97
Jul 6, 2018
Jul 6, 2018
98
return g_strcmp0(aa->mode_name, bb->mode_name);
Mar 11, 2014
Mar 11, 2014
99
100
}
Jul 6, 2018
Jul 6, 2018
101
GList *dynconfig_read_mode_list(int diag)
May 10, 2011
May 10, 2011
102
{
Jul 6, 2018
Jul 6, 2018
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
GDir *confdir;
GList *modelist = NULL;
const gchar *dirname;
struct mode_list_elem *list_item;
gchar *full_filename = NULL;
if(diag)
confdir = g_dir_open(DIAG_DIR_PATH, 0, NULL);
else
confdir = g_dir_open(MODE_DIR_PATH, 0, NULL);
if(confdir)
{
while((dirname = g_dir_read_name(confdir)) != NULL)
{
log_debug("Read file %s\n", dirname);
if(diag)
full_filename = g_strconcat(DIAG_DIR_PATH, "/", dirname, NULL);
else
full_filename = g_strconcat(MODE_DIR_PATH, "/", dirname, NULL);
list_item = dynconfig_read_mode_file(full_filename);
/* free full_filename immediately as we do not use it anymore */
free(full_filename);
if(list_item)
modelist = g_list_append(modelist, list_item);
}
g_dir_close(confdir);
}
else
log_debug("Mode confdir open failed or file is incomplete/invalid.\n");
modelist = g_list_sort (modelist, dynconfig_compare_modes);
return(modelist);
May 10, 2011
May 10, 2011
135
136
}
Jul 6, 2018
Jul 6, 2018
137
static struct mode_list_elem *dynconfig_read_mode_file(const gchar *filename)
May 10, 2011
May 10, 2011
138
{
Jul 6, 2018
Jul 6, 2018
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
GKeyFile *settingsfile;
gboolean test = FALSE;
struct mode_list_elem *list_item = NULL;
settingsfile = g_key_file_new();
test = g_key_file_load_from_file(settingsfile, filename, G_KEY_FILE_NONE, NULL);
if(!test)
{
return(NULL);
}
list_item = malloc(sizeof(struct mode_list_elem));
list_item->mode_name = g_key_file_get_string(settingsfile, MODE_ENTRY, MODE_NAME_KEY, NULL);
log_debug("Dynamic mode name = %s\n", list_item->mode_name);
list_item->mode_module = g_key_file_get_string(settingsfile, MODE_ENTRY, MODE_MODULE_KEY, NULL);
log_debug("Dynamic mode module = %s\n", list_item->mode_module);
list_item->appsync = g_key_file_get_integer(settingsfile, MODE_ENTRY, MODE_NEEDS_APPSYNC_KEY, NULL);
list_item->mass_storage = g_key_file_get_integer(settingsfile, MODE_ENTRY, MODE_MASS_STORAGE, NULL);
list_item->network = g_key_file_get_integer(settingsfile, MODE_ENTRY, MODE_NETWORK_KEY, NULL);
list_item->network_interface = g_key_file_get_string(settingsfile, MODE_ENTRY, MODE_NETWORK_INTERFACE_KEY, NULL);
list_item->sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_PATH, NULL);
//log_debug("Dynamic mode sysfs path = %s\n", list_item->sysfs_path);
list_item->sysfs_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_VALUE, NULL);
//log_debug("Dynamic mode sysfs value = %s\n", list_item->sysfs_value);
list_item->sysfs_reset_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_RESET_VALUE, NULL);
list_item->softconnect = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SOFTCONNECT, NULL);
list_item->softconnect_disconnect = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SOFTCONNECT_DISCONNECT, NULL);
list_item->softconnect_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SOFTCONNECT_PATH, NULL);
list_item->android_extra_sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH, NULL);
list_item->android_extra_sysfs_path2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH2, NULL);
list_item->android_extra_sysfs_path3 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH3, NULL);
list_item->android_extra_sysfs_path4 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH4, NULL);
//log_debug("Android extra mode sysfs path2 = %s\n", list_item->android_extra_sysfs_path2);
list_item->android_extra_sysfs_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE, NULL);
list_item->android_extra_sysfs_value2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE2, NULL);
list_item->android_extra_sysfs_value3 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE3, NULL);
list_item->android_extra_sysfs_value4 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE4, NULL);
//log_debug("Android extra value2 = %s\n", list_item->android_extra_sysfs_value2);
list_item->idProduct = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_IDPRODUCT, NULL);
list_item->idVendorOverride = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_IDVENDOROVERRIDE, NULL);
list_item->nat = g_key_file_get_integer(settingsfile, MODE_OPTIONS_ENTRY, MODE_HAS_NAT, NULL);
list_item->dhcp_server = g_key_file_get_integer(settingsfile, MODE_OPTIONS_ENTRY, MODE_HAS_DHCP_SERVER, NULL);
Apr 15, 2015
Apr 15, 2015
180
#ifdef CONNMAN
Jul 6, 2018
Jul 6, 2018
181
list_item->connman_tethering = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_CONNMAN_TETHERING, NULL);
Apr 15, 2015
Apr 15, 2015
182
#endif
Aug 23, 2013
Aug 23, 2013
183
Jul 6, 2018
Jul 6, 2018
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
g_key_file_free(settingsfile);
if(list_item->mode_name == NULL || list_item->mode_module == NULL)
{
/* free list_item as it will not be used */
dynconfig_free_list_item(list_item);
return NULL;
}
if(list_item->network && list_item->network_interface == NULL)
{
/* free list_item as it will not be used */
dynconfig_free_list_item(list_item);
return NULL;
}
if(list_item->sysfs_path && list_item->sysfs_value == NULL)
{
/* free list_item as it will not be used */
dynconfig_free_list_item(list_item);
return NULL;
}
if(list_item->softconnect && list_item->softconnect_path == NULL)
{
/* free list_item as it will not be used */
dynconfig_free_list_item(list_item);
return NULL;
}
return(list_item);
May 10, 2011
May 10, 2011
210
}