Commit 77679b78 authored by Philippe De Swert's avatar Philippe De Swert

* small memory usage fixes, split out meego devlock, Switch to g_mass_storage...

* small memory usage fixes, split out meego devlock, Switch to g_mass_storage for more recent kernels, Go to undefined if no matching mode is found, so non-existing modes are not set silently
parent 10347e8c
AC_INIT([usb_moded], [0.47])
AC_INIT([usb_moded], [0.49])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AM_CONFIG_HEADER([config.h])
......@@ -51,6 +51,14 @@ AC_ARG_ENABLE([nokia], AS_HELP_STRING([--enable-nokia], [Enable Nokia extra's @<
esac],[nokia=false])
AM_CONDITIONAL([NOKIA], [test x$nokia = xtrue])
AC_ARG_ENABLE([meegodevlock], AS_HELP_STRING([--enable-meegodevlock], [Enable Meego devicelock @<:@default=false@:>@]),
[case "${enableval}" in
yes) meegodevlock=true ; CFLAGS="-DMLOCK $CFLAGS" ;;
no) meegodevlock=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-meegodevlock]) ;;
esac],[meegodevlock=false])
AM_CONDITIONAL([MLOCK], [test x$meegodevlock = xtrue])
AC_ARG_ENABLE([n900], AS_HELP_STRING([--enable-n900], [Enable N900 extra's @<:@default=false@:>@]),
[case "${enableval}" in
yes) n900=true ; CFLAGS="-DN900 $CFLAGS" ;;
......@@ -59,7 +67,6 @@ AC_ARG_ENABLE([n900], AS_HELP_STRING([--enable-n900], [Enable N900 extra's @<:@d
esac],[n900=false])
AM_CONDITIONAL([N900], [test x$n900 = xtrue])
AC_ARG_ENABLE([bme], AS_HELP_STRING([--enable-bme], [Enable Nokia bme cable connection interface @<:@default=false@:>@]),
[case "${enableval}" in
yes) bme=true ; CFLAGS="-DBME $CFLAGS" ;;
......
usb-moded (0.49) unstable; urgency=low
* small memory usage fixes
* split out meego devlock
-- Philippe De Swert <philippe.de-swert@nokia.com> Fri, 13 Jan 2012 16:45:52 +0200
usb-moded (0.48) unstable; urgency=low
* Switch to g_mass_storage for more recent kernels
* Set network through convience functions
* Go to undefined if no matching mode is found, so non-existing modes are not set silently
-- Philippe De Swert <philippe.de-swert@nokia.com> Fri, 28 Oct 2011 12:21:22 +0300
usb-moded (0.47) unstable; urgency=low
* Make it possible to use the ini file for the mode setting also. This removes
......
......@@ -24,6 +24,8 @@ usb_moded_SOURCES = \
usb_moded-log.c \
usb_moded-config.c \
usb_moded-config.h \
usb_moded-network.c \
usb_moded-network.h \
usb_moded-modesetting.c \
usb_moded-modesetting.h
......@@ -49,7 +51,7 @@ usb_moded_SOURCES += \
usb_moded-trigger.c
endif
if NOKIA
if MLOCK
usb_moded_SOURCES += \
usb_moded-devicelock.h \
usb_moded-devicelock.c
......
......@@ -66,6 +66,11 @@ const char * find_udev_path(void)
{
return(get_conf_string(UDEV_PATH_ENTRY, UDEV_PATH_KEY));
}
const char * find_udev_subsystem(void)
{
return(get_conf_string(UDEV_PATH_ENTRY, UDEV_SUBSYSTEM_KEY));
}
#endif /* UDEV */
#ifdef NOKIA
......
......@@ -33,6 +33,7 @@
#define ALT_MOUNT_KEY "mount"
#define UDEV_PATH_ENTRY "udev"
#define UDEV_PATH_KEY "path"
#define UDEV_SUBSYSTEM_KEY "subsystem"
#define CDROM_ENTRY "cdrom"
#define CDROM_PATH_KEY "path"
#define CDROM_TIMEOUT_KEY "timeout"
......@@ -49,6 +50,7 @@ const char * find_alt_mount(void);
#ifdef UDEV
const char * find_udev_path(void);
const char * find_udev_subsystem(void);
#endif
#ifdef NOKIA
......
......@@ -142,7 +142,7 @@ void log_debugf(const char *fmt, ...)
*
* @return The current log level
*/
int log_get_level(void)
inline int log_get_level(void)
{
return log_level;
}
......@@ -151,7 +151,7 @@ int log_get_level(void)
*
* @param The wanted log level
*/
void log_set_level(int lev)
inline void log_set_level(int lev)
{
log_level = lev;
}
......
......@@ -37,6 +37,7 @@
#include "usb_moded-appsync.h"
#include "usb_moded-config.h"
#include "usb_moded-modesetting.h"
#include "usb_moded-network.h"
static void report_mass_storage_blocker(const char *mountpoint, int try);
......@@ -141,6 +142,7 @@ umount: command = g_strconcat("mount | grep ", mounts[i], NULL);
g_free(command);
if(!ret)
{
/* no check for / needed as that will fail to umount anyway */
command = g_strconcat("umount ", mounts[i], NULL);
log_debug("unmount command = %s\n", command);
ret = system(command);
......@@ -185,6 +187,7 @@ umount: command = g_strconcat("mount | grep ", mounts[i], NULL);
write_to_file(command2, mounts[i]);
}
g_strfreev(mounts);
g_free((gpointer *)mount);
}
/* only send data in use signal in case we actually succeed */
......@@ -245,7 +248,8 @@ int set_ovi_suite_mode(void)
write_to_file("/sys/devices/platform/musb_hdrc/gadget/softconnect", "1");
#endif /* APP_SYNC */
/* bring network interface up in case no other network is up */
system("ifdown usb0 ; ifup usb0");
/* system("ifdown usb0 ; ifup usb0"); */
usb_network_up();
#ifdef NOKIA
/* timeout for exporting CDROM image */
......@@ -291,6 +295,7 @@ gboolean export_cdrom(gpointer data)
}
else
log_debug("Cdrom image file does not exist => no export.\n");
g_free((gpointer *)path);
return(FALSE);
}
......@@ -333,6 +338,7 @@ int usb_moded_mode_cleanup(const char *module)
{
log_err("Mounting %s failed\n", mount);
usb_moded_send_error_signal(RE_MOUNT_FAILED);
g_free((gpointer *)mount);
mount = find_alt_mount();
if(mount)
{
......@@ -358,6 +364,7 @@ int usb_moded_mode_cleanup(const char *module)
system(command2);
}
g_strfreev(mounts);
g_free((gpointer *)mount);
}
}
......@@ -367,8 +374,9 @@ int usb_moded_mode_cleanup(const char *module)
/* preventive sync in case of bad quality mtp clients */
sync();
/* bring network down immediately */
system("ifdown usb0");
/*system("ifdown usb0"); */
/* do soft disconnect */
usb_network_down();
write_to_file("/sys/devices/platform/musb_hdrc/gadget/softconnect", "0");
/* DIRTY WORKAROUND: acm/phonet does not work as it should, remove when it does */
system("killall -SIGTERM acm");
......
......@@ -179,6 +179,7 @@ kill:
system("for i in `lsof -t /dev/ttyGS*`; do kill -s SIGTERM $i ; done");
system("for i in `lsof -t /dev/gc*`; do kill -s SIGTERM $i ; done");
system("for i in `lsof -t /dev/mtp*`; do kill -s SIGTERM $i ; done");
system("kill -s SIGTERM $(lsof -t /dev/usbacm");
// SP: three passes and for loops in sh?
// SP: system("kill -s SIGTERM $(lsof -t /dev/ttyGS* /dev/gc* /dev/mtp*") ?
// SP: or popen + kill loop?
......
......@@ -25,8 +25,8 @@
#else
#define MODULE_NETWORK_MTP "g_nokia"
#endif /* NOKIA */
#define MODULE_MASS_STORAGE "g_file_storage"
#define MODULE_CHARGING "g_file_storage luns=1 stall=0 removable=1"
#define MODULE_MASS_STORAGE "g_mass_storage"
#define MODULE_CHARGING "g_mass_storage luns=1 stall=0 removable=1"
#define MODULE_NONE "none"
#define MODULE_WINDOWS_NET "g_ether"
......
/*
@file usb-moded_network.c : (De)activates network depending on the network setting system.
Copyright (C) 2011 Nokia Corporation. All rights reserved.
Author: Philippe De Swert <philippe.de-swert@nokia.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 <stdlib.h>
#include "usb_moded-network.h"
#if CONNMAN
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#endif
/**
* Activate the network interface
*
*/
int usb_network_up(void)
{
#if CONNMAN
DBusConnection *dbus_conn_connman = NULL;
DBusMessage *msg = NULL, *reply = NULL;
DBusError error;
dbus_error_init(&error);
if( (dbus_conn_connman = dbus_bus_get(DBUS_BUS_SYSTEM, &error)) == 0 )
{
log_err("Could not connect to dbus for connman\n");
}
if ((msg = dbus_message_new_method_call("net.connman", "/", "net.connman.Service", connect)) != NULL)
{
if ((reply = dbus_connection_send_with_reply_and_block(dbus_conn_connman, msg, -1, NULL)) != NULL)
{
dbus_message_get_args(reply, NULL, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
dbus_message_unref(reply);
}
dbus_message_unref(msg);
}
dbus_connection_unref(dbus_conn_connman);
log_debug("connman state = %d\n", ret);
return(ret);
#else
system("ifdown usb0 && ifup usb0");
return(0);
#endif /* CONNMAN */
}
/**
* Deactivate the network interface
*
*/
int usb_network_down(void)
{
#if CONNMAN
#else
system("ifdown usb0 down");
return(0);
#endif /* CONNMAN */
}
/*
Copyright (C) 2011 Nokia Corporation. All rights reserved.
Author: Philippe De Swert <philippe.de-swert@nokia.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
usb-moded_network : (De)activates network depending on the network setting system.
*/
/*============================================================================= */
int usb_network_up(void);
int usb_network_down(void);
......@@ -38,9 +38,9 @@
#include "usb_moded-hw-ab.h"
#include "usb_moded-modesetting.h"
#include "usb_moded-trigger.h"
#ifdef NOKIA
#ifdef MLOCK
#include "usb_moded-devicelock.h"
#endif /* NOKIA */
#endif /* MLOCK */
/* global variables */
static struct udev *udev;
......@@ -186,9 +186,9 @@ static void udev_parse(struct udev_device *dev)
{
if(!strcmp(tmp, get_trigger_value()))
{
#ifdef NOKIA
#ifdef MLOCK
if(!usb_moded_get_export_permission())
#endif /* NOKIA */
#endif /* MLOCK */
if(strcmp(get_trigger_mode(), get_usb_mode()) != 0)
{
usb_moded_mode_cleanup(get_usb_module());
......@@ -201,9 +201,9 @@ static void udev_parse(struct udev_device *dev)
else
/* for triggers without trigger value */
{
#ifdef NOKIA
#ifdef MLOCK
if(!usb_moded_get_export_permission())
#endif /* NOKIA */
#endif /* MLOCK */
if(strcmp(get_trigger_mode(), get_usb_mode()) != 0)
{
usb_moded_mode_cleanup(get_usb_module());
......
......@@ -59,7 +59,7 @@ static void notify_issue (gpointer data)
gboolean hwal_init(void)
{
const gchar *udev_path = NULL;
const gchar *udev_path = NULL, *udev_subsystem = NULL;
struct udev_device *dev;
int ret = 0;
......@@ -73,7 +73,10 @@ gboolean hwal_init(void)
udev_path = find_udev_path();
if(udev_path)
{
dev = udev_device_new_from_syspath(udev, udev_path);
g_free((gpointer *)udev_path);
}
else
dev = udev_device_new_from_syspath(udev, "/sys/class/power_supply/usb");
if (!dev)
......@@ -94,7 +97,14 @@ gboolean hwal_init(void)
/* communicate failure, mainloop will exit and call appropriate clean-up */
return FALSE;
}
ret = udev_monitor_filter_add_match_subsystem_devtype(mon, "power_supply", NULL);
udev_subsystem = find_udev_subsystem();
if(udev_subsystem)
{
ret = udev_monitor_filter_add_match_subsystem_devtype(mon, udev_subsystem, NULL);
g_free((gpointer *)udev_subsystem);
}
else
ret = udev_monitor_filter_add_match_subsystem_devtype(mon, "power_supply", NULL);
if(ret != 0)
{
log_err("Udev match failed.\n");
......@@ -166,11 +176,13 @@ static void udev_parse(struct udev_device *dev)
if(!tmp)
{
tmp = udev_device_get_property_value(dev, "POWER_SUPPLY_PRESENT");
/* log_warning("Using present property\n"); */
log_warning("Using present property\n");
}
if(!tmp)
{
log_err("No usable power supply indicator\n");
/* TRY AGAIN?
return; */
exit(1);
}
if(!strcmp(tmp, "1"))
......@@ -182,7 +194,7 @@ static void udev_parse(struct udev_device *dev)
{
/* power supply type might not exist also :( Send connected event but this will not be able
to discriminate between charger/cable */
log_warning("Fallback since cable detection cannot be accurate. Will connect on any voltage on usb.\n");
log_warning("Fallback since cable detection might not be accurate. Will connect on any voltage on usb.\n");
cable = 1;
set_usb_connected(TRUE);
return;
......
......@@ -44,6 +44,7 @@
#include "usb_moded-trigger.h"
#include "usb_moded-config.h"
#include "usb_moded-config-private.h"
#include "usb_moded-network.h"
/* global definitions */
......@@ -153,15 +154,15 @@ void set_usb_connected_state(void)
{
const char *mode_to_set;
#ifdef NOKIA
#ifdef MLOCK
int export = 0, act_dead = 0;
#endif /* NOKIA */
#endif /* MLOCK */
/* signal usb connected */
log_debug("usb connected\n");
usb_moded_send_signal(USB_CONNECTED);
mode_to_set = get_mode_setting();
#ifdef NOKIA
#ifdef MLOCK
/* check if we are allowed to export system contents 0 is unlocked */
export = usb_moded_get_export_permission();
/* check if we are in acting dead or not, /tmp/USER will not exist in acting dead */
......@@ -169,7 +170,7 @@ void set_usb_connected_state(void)
if(mode_to_set && !export && !act_dead)
#else
if(mode_to_set)
#endif /* NOKIA */
#endif /* MLOCK */
{
#ifdef NOKIA
/* If we switch to another mode than the one that is still set before the
......@@ -211,7 +212,8 @@ void set_usb_connected_state(void)
*/
void set_usb_mode(const char *mode)
{
int ret=0, net=0;
/* set return to 1 to be sure to error out if no matching mode is found either */
int ret=1, net=0;
if(!strcmp(mode, MODE_MASS_STORAGE))
{
......@@ -242,6 +244,7 @@ void set_usb_mode(const char *mode)
ret = usb_moded_load_module(MODULE_NETWORK_MTP);
if(!ret)
ret = set_ovi_suite_mode();
goto end;
}
#endif /* N900 */
......@@ -250,7 +253,8 @@ void set_usb_mode(const char *mode)
check_module_state(MODULE_WINDOWS_NET);
set_usb_module(MODULE_WINDOWS_NET);
ret = usb_moded_load_module(MODULE_WINDOWS_NET);
net = system("ifdown usb0 ; ifup usb0");
net = usb_network_up();
goto end;
}
#ifdef APP_SYNC
......@@ -321,7 +325,7 @@ int valid_mode(const char *mode)
* @return the currently set mode
*
*/
const char * get_usb_mode(void)
inline const char * get_usb_mode(void)
{
return(current_mode.mode);
}
......@@ -331,7 +335,7 @@ const char * get_usb_mode(void)
* @param module The module name for the requested mode
*
*/
void set_usb_module(const char *module)
inline void set_usb_module(const char *module)
{
free(current_mode.module);
current_mode.module = strdup(module);
......@@ -342,7 +346,7 @@ void set_usb_module(const char *module)
* @return The name of the loaded module
*
*/
const char * get_usb_module(void)
inline const char * get_usb_module(void)
{
return(current_mode.module);
}
......@@ -352,7 +356,7 @@ const char * get_usb_module(void)
* @ return A boolean value for connected (TRUE) or not (FALSE)
*
*/
gboolean get_usb_connection_state(void)
inline gboolean get_usb_connection_state(void)
{
return current_mode.connected;
}
......@@ -362,7 +366,7 @@ gboolean get_usb_connection_state(void)
* @param state The connection status that needs to be set. Connected (TRUE)
*
*/
void set_usb_connection_state(gboolean state)
inline void set_usb_connection_state(gboolean state)
{
current_mode.connected = state;
}
......@@ -372,17 +376,17 @@ void set_usb_connection_state(gboolean state)
/* set default values for usb_moded */
static void usb_moded_init(void)
{
#ifdef NOKIA
#ifdef NOKIA_NSU
char readbuf[MAX_READ_BUF];
FILE *proc_fd;
#endif /* NOKIA */
#endif /* NOKIA_NSU */
current_mode.connected = FALSE;
current_mode.mounted = FALSE;
current_mode.mode = strdup(MODE_UNDEFINED);
current_mode.module = g_strdup(MODULE_NONE);
current_mode.module = strdup(MODULE_NONE);
#ifdef NOKIA
#ifdef NOKIA_NSU
proc_fd = fopen("/proc/cmdline", "r");
if(proc_fd)
{
......@@ -394,7 +398,7 @@ static void usb_moded_init(void)
fclose(proc_fd);
}
#endif /* NOKIA */
#endif /* NOKIA_NSU */
#ifdef APP_SYNC
readlist();
modelist = read_mode_list();
......@@ -654,11 +658,11 @@ int main(int argc, char* argv[])
log_crit("hwal init failed\n");
goto EXIT;
}
#ifdef NOKIA
#ifdef MLOCK
start_devicelock_listener();
if(!runlevel_ignore)
usb_moded_dsme_listener();
#endif /* NOKIA */
#endif /* MLOCK */
/* init succesful, run main loop */
result = EXIT_SUCCESS;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment