Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Android gadget manufacturer and vendor id support
Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Aug 2, 2013
1 parent af3a30b commit 26febfc
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Makefile.am
Expand Up @@ -32,7 +32,9 @@ usb_moded_SOURCES = \
usb_moded-mac.h \
usb_moded-dyn-config.c \
usb_moded-dyn-config.h \
usb_moded-modules.c
usb_moded-modules.c \
usb_moded-android.h \
usb_moded-android.c

if GCONF
usb_moded_SOURCES += \
Expand Down
64 changes: 64 additions & 0 deletions src/usb_moded-android.c
@@ -0,0 +1,64 @@
/**
@file usb_moded-android.c
Copyright (C) 2013 Jolla. All rights reserved.
@author: Philippe De Swert <philippe.deswert@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
*/

#include <stdio.h>
#include <glib.h>

#include "usb_moded-android.h"
#include "usb_moded-log.h"
#include "usb_moded-modesetting.h"
#include "usb_moded-config.h"

/** check if android settings are set
*
* @return 1 if settings are available, 0 if not
*
*/
int android_settings(void)
{
int ret = 0;

ret = check_android_section();

return ret;
}

/** initialize the basic android values
*/
void android_init_values(void)
{
const char *text;

text = get_android_manufacturer();
if(text)
{
write_to_file("/sys/class/android_usb/android0/iManufacturer", text);
g_free((char *)text);
}
text = get_android_vendor();
if(text)
{
write_to_file("/sys/class/android_usb/android0/idVendor", text);
g_free((char *)text);
}

}
24 changes: 24 additions & 0 deletions src/usb_moded-android.h
@@ -0,0 +1,24 @@
/**
@file usb_moded-android.h
Copyright (C) 2013 Jolla. All rights reserved.
@author: Philippe De Swert <philippe.deswert@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
*/

int android_settings(void);
void android_init_values(void);
37 changes: 34 additions & 3 deletions src/usb_moded-config.c
Expand Up @@ -196,6 +196,7 @@ static int get_conf_int(const gchar *entry, const gchar *key)
}
keys++;
}
g_strfreev(keys);
g_key_file_free(settingsfile);
return(ret);

Expand Down Expand Up @@ -229,6 +230,7 @@ static const char * get_conf_string(const gchar *entry, const gchar *key)
}
keys++;
}
g_strfreev(keys);
g_key_file_free(settingsfile);
return(g_strdup(tmp_char));

Expand Down Expand Up @@ -304,7 +306,6 @@ static const char * get_kcmdline_string(const char *entry)
return(ret);
}

#ifndef GCONF
const char * get_mode_setting(void)
{
const char * mode = get_kcmdline_string(MODE_SETTING_KEY);
Expand Down Expand Up @@ -380,8 +381,6 @@ int set_network_setting(const char *config, const char *setting)
return(!ret);
}

#endif

int conf_file_merge(void)
{
GDir *confdir;
Expand Down Expand Up @@ -493,3 +492,35 @@ int conf_file_merge(void)
g_dir_close(confdir);
return(ret);
}

const char * get_android_manufacturer(void)
{
return(get_conf_string(ANDROID_ENTRY, ANDROID_MANUFACTURER_KEY));
}
const char * get_android_vendor(void)
{
return(get_conf_string(ANDROID_ENTRY, ANDROID_VENDOR_KEY));
}

int check_android_section(void)
{
GKeyFile *settingsfile;
gboolean test = FALSE;
gchar **keys;

settingsfile = g_key_file_new();
test = g_key_file_load_from_file(settingsfile, FS_MOUNT_CONFIG_FILE, G_KEY_FILE_NONE, NULL);
if(!test)
return 0;
keys = g_key_file_get_keys (settingsfile, ANDROID_ENTRY, NULL, NULL);
if(keys == NULL)
{
g_key_file_free(settingsfile);
return 0;
}

g_strfreev(keys);
g_key_file_free(settingsfile);
return 1;
}

8 changes: 8 additions & 0 deletions src/usb_moded-config.h
Expand Up @@ -50,6 +50,9 @@
#define NETWORK_GATEWAY_KEY "gateway"
#define SOFT_CONNECT_ENTRY "soft_connect"
#define SOFT_CONNECT_PATH_KEY "soft_connect_path"
#define ANDROID_ENTRY "android"
#define ANDROID_MANUFACTURER_KEY "manufacturer"
#define ANDROID_VENDOR_KEY "vendor"

const char * find_mounts(void);
int find_sync(void);
Expand Down Expand Up @@ -78,5 +81,10 @@ const char * get_network_interface(void);
const char * get_network_gateway(void);
const char * get_soft_connect_path(void);

const char * get_android_manufacturer(void);
const char * get_android_vendor(void);

int check_android_section(void);

int conf_file_merge(void);
int set_config_setting(const char *entry, const char *key, const char *value);
4 changes: 4 additions & 0 deletions src/usb_moded.c
Expand Up @@ -51,6 +51,7 @@
#include "usb_moded-config-private.h"
#include "usb_moded-network.h"
#include "usb_moded-mac.h"
#include "usb_moded-android.h"

/* global definitions */

Expand Down Expand Up @@ -469,6 +470,9 @@ static void usb_moded_init(void)
ctx = kmod_new(NULL, NULL);
kmod_load_resources(ctx);

/* Android specific stuff */
if(android_settings())
android_init_values();
/* TODO: add more start-up clean-up and init here if needed */
}

Expand Down

0 comments on commit 26febfc

Please sign in to comment.