Skip to content

Latest commit

 

History

History
178 lines (158 loc) · 6.66 KB

usb_moded-dyn-config.c

File metadata and controls

178 lines (158 loc) · 6.66 KB
 
May 10, 2011
May 10, 2011
1
2
3
4
/**
@file usb_moded-dyn-mode.c
Copyright (C) 2011 Nokia Corporation. All rights reserved.
Jun 11, 2014
Jun 11, 2014
5
Copyright (C) 2013 Jolla. All rights reserved.
May 10, 2011
May 10, 2011
6
7
@author: Philippe De Swert <philippe.de-swert@nokia.com>
Jun 11, 2014
Jun 11, 2014
8
@author: Philippe De Swert <philippe.deswert@jollamobile.com>
May 10, 2011
May 10, 2011
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
*/
#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"
static struct mode_list_elem *read_mode_file(const gchar *filename);
Oct 22, 2013
Oct 22, 2013
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
void list_item_free(mode_list_elem *list_item)
{
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->idProduct);
free(list_item);
}
void free_mode_list(GList *modelist)
{
if(modelist)
{
g_list_foreach(modelist, (GFunc) list_item_free, NULL);
g_list_free(modelist);
modelist = 0;
}
}
Mar 11, 2014
Mar 11, 2014
67
68
69
70
71
72
73
74
static gint compare_modes(gconstpointer a, gconstpointer b)
{
struct mode_list_elem *aa = (struct mode_list_elem *)a;
struct mode_list_elem *bb = (struct mode_list_elem *)b;
return g_strcmp0(aa->mode_name, bb->mode_name);
}
Sep 10, 2013
Sep 10, 2013
75
GList *read_mode_list(int diag)
May 10, 2011
May 10, 2011
76
77
78
79
80
{
GDir *confdir;
GList *modelist = NULL;
const gchar *dirname;
struct mode_list_elem *list_item;
Sep 12, 2013
Sep 12, 2013
81
gchar *full_filename = NULL;
May 10, 2011
May 10, 2011
82
Sep 10, 2013
Sep 10, 2013
83
84
85
86
if(diag)
confdir = g_dir_open(DIAG_DIR_PATH, 0, NULL);
else
confdir = g_dir_open(MODE_DIR_PATH, 0, NULL);
May 10, 2011
May 10, 2011
87
88
89
90
91
if(confdir)
{
while((dirname = g_dir_read_name(confdir)) != NULL)
{
log_debug("Read file %s\n", dirname);
Sep 12, 2013
Sep 12, 2013
92
93
94
95
96
97
98
if(diag)
full_filename = g_strconcat(DIAG_DIR_PATH, "/", dirname, NULL);
else
full_filename = g_strconcat(MODE_DIR_PATH, "/", dirname, NULL);
list_item = read_mode_file(full_filename);
/* free full_filename immediately as we do not use it anymore */
free(full_filename);
May 10, 2011
May 10, 2011
99
100
101
102
103
104
if(list_item)
modelist = g_list_append(modelist, list_item);
}
g_dir_close(confdir);
}
else
May 27, 2013
May 27, 2013
105
log_debug("Mode confdir open failed or file is incomplete/invalid.\n");
Mar 11, 2014
Mar 11, 2014
106
Mar 12, 2014
Mar 12, 2014
107
modelist = g_list_sort (modelist, compare_modes);
May 10, 2011
May 10, 2011
108
109
110
111
112
113
114
115
116
117
return(modelist);
}
static struct mode_list_elem *read_mode_file(const gchar *filename)
{
GKeyFile *settingsfile;
gboolean test = FALSE;
struct mode_list_elem *list_item = NULL;
settingsfile = g_key_file_new();
Sep 12, 2013
Sep 12, 2013
118
test = g_key_file_load_from_file(settingsfile, filename, G_KEY_FILE_NONE, NULL);
May 10, 2011
May 10, 2011
119
120
121
122
123
124
125
126
127
128
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);
Sep 18, 2013
Sep 18, 2013
129
list_item->mass_storage = g_key_file_get_integer(settingsfile, MODE_ENTRY, MODE_MASS_STORAGE, NULL);
May 10, 2011
May 10, 2011
130
131
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);
May 27, 2013
May 27, 2013
132
list_item->sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_PATH, NULL);
Jul 19, 2013
Jul 19, 2013
133
//log_debug("Dynamic mode sysfs path = %s\n", list_item->sysfs_path);
May 27, 2013
May 27, 2013
134
list_item->sysfs_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_VALUE, NULL);
Jul 19, 2013
Jul 19, 2013
135
//log_debug("Dynamic mode sysfs value = %s\n", list_item->sysfs_value);
May 29, 2013
May 29, 2013
136
list_item->sysfs_reset_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SYSFS_RESET_VALUE, NULL);
May 27, 2013
May 27, 2013
137
list_item->softconnect = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SOFTCONNECT, NULL);
May 29, 2013
May 29, 2013
138
list_item->softconnect_disconnect = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SOFTCONNECT_DISCONNECT, NULL);
May 27, 2013
May 27, 2013
139
list_item->softconnect_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_SOFTCONNECT_PATH, NULL);
Jul 19, 2013
Jul 19, 2013
140
list_item->android_extra_sysfs_path = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH, NULL);
Aug 21, 2013
Aug 21, 2013
141
142
list_item->android_extra_sysfs_path2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_PATH2, NULL);
//log_debug("Android extra mode sysfs path2 = %s\n", list_item->android_extra_sysfs_path2);
Jul 19, 2013
Jul 19, 2013
143
list_item->android_extra_sysfs_value = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE, NULL);
Aug 21, 2013
Aug 21, 2013
144
145
list_item->android_extra_sysfs_value2 = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_ANDROID_EXTRA_SYSFS_VALUE2, NULL);
//log_debug("Android extra value2 = %s\n", list_item->android_extra_sysfs_value2);
Aug 23, 2013
Aug 23, 2013
146
list_item->idProduct = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_IDPRODUCT, NULL);
Nov 30, 2013
Nov 30, 2013
147
list_item->nat = g_key_file_get_integer(settingsfile, MODE_OPTIONS_ENTRY, MODE_HAS_NAT, NULL);
Dec 10, 2013
Dec 10, 2013
148
list_item->dhcp_server = g_key_file_get_integer(settingsfile, MODE_OPTIONS_ENTRY, MODE_HAS_DHCP_SERVER, NULL);
Aug 23, 2013
Aug 23, 2013
149
May 10, 2011
May 10, 2011
150
151
152
153
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 */
Oct 22, 2013
Oct 22, 2013
154
list_item_free(list_item);
May 10, 2011
May 10, 2011
155
156
157
158
159
return NULL;
}
if(list_item->network && list_item->network_interface == NULL)
{
/* free list_item as it will not be used */
Oct 22, 2013
Oct 22, 2013
160
list_item_free(list_item);
May 10, 2011
May 10, 2011
161
162
return NULL;
}
May 27, 2013
May 27, 2013
163
164
165
if(list_item->sysfs_path && list_item->sysfs_value == NULL)
{
/* free list_item as it will not be used */
Oct 22, 2013
Oct 22, 2013
166
list_item_free(list_item);
May 27, 2013
May 27, 2013
167
168
169
170
171
return NULL;
}
if(list_item->softconnect && list_item->softconnect_path == NULL)
{
/* free list_item as it will not be used */
Oct 22, 2013
Oct 22, 2013
172
list_item_free(list_item);
May 27, 2013
May 27, 2013
173
174
return NULL;
}
May 10, 2011
May 10, 2011
175
176
177
else
return(list_item);
}