[maemo-commits] [maemo-commits] r16802 - in projects/haf/trunk/ke-recv: debian src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Fri Nov 28 16:50:50 EET 2008
Author: kihamala
Date: 2008-11-28 16:50:48 +0200 (Fri, 28 Nov 2008)
New Revision: 16802

Added:
   projects/haf/trunk/ke-recv/src/pcsuite-disable.sh
   projects/haf/trunk/ke-recv/src/pcsuite-enable.sh
Modified:
   projects/haf/trunk/ke-recv/debian/changelog
   projects/haf/trunk/ke-recv/debian/init.d
   projects/haf/trunk/ke-recv/src/events.c
   projects/haf/trunk/ke-recv/src/exec-func.c
   projects/haf/trunk/ke-recv/src/exec-func.h
   projects/haf/trunk/ke-recv/src/ke-recv.c
   projects/haf/trunk/ke-recv/src/ke-recv.h
   projects/haf/trunk/ke-recv/src/mmc-format.c
   projects/haf/trunk/ke-recv/src/osso-usb-mass-storage-enable.sh
Log:
first steps taken for pcsuite support


Modified: projects/haf/trunk/ke-recv/debian/changelog
===================================================================
--- projects/haf/trunk/ke-recv/debian/changelog	2008-11-28 12:15:27 UTC (rev 16801)
+++ projects/haf/trunk/ke-recv/debian/changelog	2008-11-28 14:50:48 UTC (rev 16802)
@@ -1,3 +1,12 @@
+ke-recv (3.3-1~unreleased) unstable; urgency=low
+
+  * Added support for PC Suite mode.
+  * Added D-Bus interfaces for enabling PC Suite or mass storage mode when in
+    the new S_PERIPHERAL_WAIT state.
+  * g_nokia is now the default kernel module.
+
+ -- Kimmo Hämäläinen <kimmo.hamalainen at nokia.com>  Fri, 28 Nov 2008 14:32:03 +0200
+
 ke-recv (3.2-1) unstable; urgency=low
 
   * Slot naming fix, e.g. "slot:internal" -> "internal". Fixes: NB#92323

Modified: projects/haf/trunk/ke-recv/debian/init.d
===================================================================
--- projects/haf/trunk/ke-recv/debian/init.d	2008-11-28 12:15:27 UTC (rev 16801)
+++ projects/haf/trunk/ke-recv/debian/init.d	2008-11-28 14:50:48 UTC (rev 16802)
@@ -46,7 +46,7 @@
 export MMC_MOUNTPOINT='/media/mmc1'
 export INTERNAL_MMC_MOUNTPOINT='/media/mmc2'
 
-/sbin/lsmod | grep "\(g_nokia\)\|\(g_ether\)" > /dev/null
+/sbin/lsmod | grep "\(g_ether\)" > /dev/null
 if [ $? = 0 ]; then
   echo "$DESC: USB networking enabled, ignoring USB cable"
   export OSSO_KE_RECV_IGNORE_CABLE=1
@@ -60,10 +60,8 @@
 	# Start daemons
 	echo -n "Starting $DESC: "
 
-        # g_file_storage is loaded unless g_ether is there
-        if [ "x$OSSO_KE_RECV_IGNORE_CABLE" = "x" ]; then
-                osso-usb-mass-storage-enable.sh
-        fi
+        # g_nokia is loaded as the default
+        modprobe g_nokia
 
         # check if this is the first boot
         if [ -e /home/user/first-boot-flag ]; then

Modified: projects/haf/trunk/ke-recv/src/events.c
===================================================================
--- projects/haf/trunk/ke-recv/src/events.c	2008-11-28 12:15:27 UTC (rev 16801)
+++ projects/haf/trunk/ke-recv/src/events.c	2008-11-28 14:50:48 UTC (rev 16802)
@@ -45,6 +45,7 @@
 static int mount_volumes(mmc_info_t *mmc);
 static int do_unmount(const char *mountpoint);
 static void open_dialog_helper(mmc_info_t *mmc);
+static volume_list_t *get_nth_volume(mmc_info_t *mmc, int n);
 
 #define CLOSE_DIALOG if (mmc->dialog_id == -1) { \
                              ULOG_WARN_F("%s dialog_id is invalid", \
@@ -523,18 +524,29 @@
 void unshare_usb_shared_card(mmc_info_t *mmc)
 {
         const char *args[] = {NULL, NULL}; 
+        char *dev;
 
-        ULOG_DEBUG_F("entered");
+        if (!mmc->control_partitions) {
+                volume_list_t *vol;
 
-        if (mmc->whole_device == NULL) {
-                ULOG_DEBUG_F("whole_device unknown for %s", mmc->name);
+                vol = get_nth_volume(mmc, mmc->preferred_volume);
+                if (vol == NULL) {
+                        ULOG_ERR_F("volume %d not found from %s",
+                                   mmc->preferred_volume, mmc->name);
+                        return;
+                }
+                dev = vol->dev_name;
+        } else
+                dev = mmc->whole_device;
+
+        if (dev == NULL) {
+                ULOG_DEBUG_F("dev unknown for %s", mmc->name);
                 return;
         }
 
-        args[0] = mmc->whole_device;
+        args[0] = dev;
         if (!unload_usb_driver(args)) {
-                ULOG_ERR_F("failed to unload the USB module for %s",
-                           mmc->whole_device);
+                ULOG_ERR_F("failed to unload the USB module for %s", dev);
                 /* there seems to be no way to recover from this... */
         } else {
                 inform_mmc_used_over_usb(FALSE, mmc);
@@ -544,9 +556,23 @@
 static void usb_share_card(mmc_info_t *mmc, gboolean show)
 {
         const char *args[] = {NULL, NULL};
+        char *dev;
 
-        if (mmc->whole_device == NULL) {
-                ULOG_DEBUG_F("whole_device unknown for %s", mmc->name);
+        if (!mmc->control_partitions) {
+                volume_list_t *vol;
+
+                vol = get_nth_volume(mmc, mmc->preferred_volume);
+                if (vol == NULL) {
+                        ULOG_ERR_F("volume %d not found from %s",
+                                   mmc->preferred_volume, mmc->name);
+                        return;
+                }
+                dev = vol->dev_name;
+        } else
+                dev = mmc->whole_device;
+
+        if (dev == NULL) {
+                ULOG_DEBUG_F("dev unknown for %s", mmc->name);
                 return;
         }
 
@@ -555,17 +581,16 @@
                 return;
         }
 
-        args[0] = mmc->whole_device;
+        args[0] = dev;
         if (load_usb_driver(args)) {
-                ULOG_INFO_F("USB mass storage module loaded for %s",
-                            mmc->whole_device);
+                ULOG_INFO_F("USB mass storage module loaded for %s", dev);
                 if (show) {
                         display_dialog(MSG_DEVICE_CONNECTED_VIA_USB);
                 }
                 inform_mmc_used_over_usb(TRUE, mmc);
         } else {
                 ULOG_ERR_F("failed to load USB mass storage module for %s",
-                           mmc->whole_device);
+                           dev);
         }
 }
 
@@ -623,25 +648,66 @@
         }
 }
 
+static volume_list_t *get_nth_volume(mmc_info_t *mmc, int n)
+{
+        volume_list_t *l, *ret = NULL;
+
+        for (l = &mmc->volumes; l != NULL; l = l->next) {
+                if (l->udi != NULL && l->volume_number == n) {
+                        ret = l;
+                        break;
+                }
+        }
+        return ret;
+}
+
 static void handle_e_format(mmc_info_t *mmc)
 {
         int ret;
-        const char* args[] = {MMC_FORMAT_PROG, NULL, NULL, NULL};
+        const char* args[] = {MMC_FORMAT_PROG, NULL, NULL, NULL, NULL};
+        volume_list_t *vol;
 
         ULOG_DEBUG_F("label for %s is '%s'", mmc->name, mmc->desired_label);
-        args[1] = mmc->whole_device;
-        args[2] = mmc->desired_label;
 
-        ret = unmount_volumes(&mmc->volumes);
+        vol = get_nth_volume(mmc, mmc->preferred_volume);
+
+        if (vol == NULL || vol->dev_name == NULL) {
+                ULOG_ERR_F("could not find partition number %d",
+                           mmc->preferred_volume);
+                return;
+        }
+
+        if (!mmc->control_partitions) {
+                args[1] = vol->dev_name;
+                args[2] = mmc->desired_label;
+
+                if (vol->mountpoint != NULL)
+                        ret = do_unmount(vol->mountpoint);
+                else {
+                        ULOG_DEBUG_F("no mountpoint, using dev_name");
+                        ret = do_unmount(vol->dev_name);
+                }
+        } else {
+                args[1] = mmc->whole_device;
+                args[2] = vol->dev_name;
+                args[3] = mmc->desired_label;
+
+                ret = unmount_volumes(&mmc->volumes);
+        }
         if (!ret) {
                 ULOG_INFO_F("memory card %s is in use", mmc->name);
                 display_system_note(dgettext("osso-filemanager",
                                     "sfil_ni_mmc_format_mmc_in_use"));
-                mount_volumes(mmc);
+                if (mmc->control_partitions)
+                        /* we could have unmounted some other volumes */
+                        mount_volumes(mmc);
                 return;
         }
 
-        clear_volume_list(&mmc->volumes); /* clear existing volume info */
+        if (mmc->control_partitions)
+                /* partition table will be cleared, clear volume info */
+                clear_volume_list(&mmc->volumes);
+
         ret = exec_prog(MMC_FORMAT_PROG, args);
         if (ret != 0) {
                 ULOG_INFO_F("format of %s failed, rc=%d", mmc->name, ret);
@@ -660,16 +726,12 @@
         volume_list_t *l;
         const char* args[] = {"/usr/sbin/mmc-check", NULL, NULL};
 
-        /* find out the device name of the first partition */
-        for (l = &mmc->volumes; l != NULL; l = l->next) {
-                if (l->udi != NULL && l->volume_number == 1) {
-                        part_device = l->dev_name;
-                        udi = l->udi;
-                        break;
-                }
-        }
+        l = get_nth_volume(mmc, mmc->preferred_volume);
+        part_device = l != NULL ? l->dev_name : NULL;
+        udi = l->udi;
+
         if (part_device == NULL) {
-                ULOG_ERR_F("device name for first partition not found");
+                ULOG_ERR_F("device name for the partition not found");
                 display_system_note(MSG_UNABLE_TO_REPAIR);
                 return;
         }
@@ -717,21 +779,20 @@
         const char *udi = NULL, *device = NULL;
         int ret, count = 0;
        
-        /* we currently only consider the partition number 1
-         * for mounting */
-        for (l = &mmc->volumes; l != NULL; l = l->next) {
-                ULOG_DEBUG_F("%s %d %s", mmc->name, l->volume_number, l->udi);
-                if (l->udi != NULL && l->volume_number == 1
-                    && !l->corrupt) {
-                        udi = l->udi;
-                        device = l->dev_name;
-                        break;
-                }
+        l = get_nth_volume(mmc, mmc->preferred_volume);
+        if (l && l->corrupt) {
+                ULOG_DEBUG_F("partition %d is corrupt",
+                             mmc->preferred_volume);
+                return 0;
         }
-        if (udi == NULL) {
-                ULOG_DEBUG_F("first partition not found or marked corrupt");
+
+        if (l == NULL || l->udi == NULL) {
+                ULOG_DEBUG_F("partition %d not found", mmc->preferred_volume);
                 return 0;
         }
+        udi = l->udi;
+        device = l->dev_name;
+
         if (device == NULL) {
                 ULOG_ERR_F("couldn't get device for %s", udi);
                 return 0;
@@ -847,7 +908,7 @@
                         ULOG_DEBUG_F("E_CLOSED for %s", mmc->name);
                         /* notify applications about closed cover */
                         inform_mmc_cover_open(FALSE, mmc);
-                        if (!ignore_cable && get_cable_peripheral()
+                        if (!ignore_cable && in_mass_storage_mode()
                             && !device_locked) {
                                 usb_share_card(mmc, TRUE);
                         } else {
@@ -1000,7 +1061,7 @@
                         /* notify applications about opened cover */
                         inform_mmc_cover_open(TRUE, mmc);
 
-                        if (!ignore_cable && get_cable_peripheral()) {
+                        if (!ignore_cable && in_mass_storage_mode()) {
                                 unshare_usb_shared_card(mmc);
                                 mmc->state = S_COVER_OPEN;
                                 break;
@@ -1015,7 +1076,7 @@
                         }
                         break;
                 case E_PLUGGED:
-                        if (!ignore_cable && get_cable_peripheral()
+                        if (!ignore_cable && in_mass_storage_mode()
                             && !device_locked) {
                                 possibly_turn_swap_off(NO_DIALOG, mmc);
                                 if (!unmount_volumes(&mmc->volumes)) {
@@ -1026,7 +1087,7 @@
                         }
                         break;
                 case E_DETACHED:
-                        if (!ignore_cable && get_cable_peripheral()) {
+                        if (!ignore_cable && in_mass_storage_mode()) {
                                 unshare_usb_shared_card(mmc);
                                 init_mmc_volumes(mmc);
                                 update_mmc_label(mmc);
@@ -1044,7 +1105,7 @@
                         break;
                 case E_VOLUME_ADDED:
                         ULOG_DEBUG_F("E_VOLUME_ADDED for %s", mmc->name);
-                        if (ignore_cable || !get_cable_peripheral()) {
+                        if (ignore_cable || !in_mass_storage_mode()) {
                                 update_mmc_label(mmc);
                                 if (mount_volumes(mmc)) {
                                         if (!mmc->skip_banner) {
@@ -1060,14 +1121,14 @@
                         break;
                 case E_VOLUME_REMOVED:
                         ULOG_DEBUG_F("E_VOLUME_REMOVED for %s", mmc->name);
-                        if (ignore_cable || !get_cable_peripheral()) {
+                        if (ignore_cable || !in_mass_storage_mode()) {
                                 discard_volume(mmc, arg);
                         }
                         break;
                 case E_DEVICE_ADDED:
                         ULOG_DEBUG_F("E_DEVICE_ADDED for %s", mmc->name);
                         inform_device_present(TRUE, mmc);
-                        if (!ignore_cable && get_cable_peripheral()
+                        if (!ignore_cable && in_mass_storage_mode()
                             && !device_locked) {
                                 usb_share_card(mmc, TRUE);
                         }
@@ -1075,7 +1136,7 @@
                 case E_DEVICE_REMOVED:
                         ULOG_DEBUG_F("E_DEVICE_REMOVED for %s", mmc->name);
                         inform_device_present(FALSE, mmc);
-                        if (!ignore_cable && get_cable_peripheral()) {
+                        if (!ignore_cable && in_mass_storage_mode()) {
                                 unshare_usb_shared_card(mmc);
                         } else {
                                 unmount_volumes(&mmc->volumes);
@@ -1095,7 +1156,7 @@
                         ULOG_DEBUG_F("E_INIT_CARD for %s", mmc->name);
                         if (mmc->whole_device != NULL) {
                                 inform_device_present(TRUE, mmc);
-                                if (!ignore_cable && get_cable_peripheral()
+                                if (!ignore_cable && in_mass_storage_mode()
                                     && !device_locked) {
                                         usb_share_card(mmc, FALSE);
                                 } else {
@@ -1122,7 +1183,7 @@
                         inform_mmc_cover_open(FALSE, mmc);
                         CLOSE_DIALOG
                         CLOSE_SWAP_DIALOG
-                        if (!ignore_cable && get_cable_peripheral()
+                        if (!ignore_cable && in_mass_storage_mode()
                             && !device_locked) {
                                 usb_share_card(mmc, TRUE);
                         } else {

Modified: projects/haf/trunk/ke-recv/src/exec-func.c
===================================================================
--- projects/haf/trunk/ke-recv/src/exec-func.c	2008-11-28 12:15:27 UTC (rev 16801)
+++ projects/haf/trunk/ke-recv/src/exec-func.c	2008-11-28 14:50:48 UTC (rev 16802)
@@ -181,6 +181,22 @@
         }
 }
 
+gboolean enable_pcsuite(void)
+{
+        static const char *args[] = {ENABLE_PCSUITE_COMMAND, NULL};
+        int ret;
+        ret = exec_prog(args[0], args);
+        return ret != 0 ? FALSE : TRUE;
+}
+
+gboolean disable_pcsuite(void)
+{
+        static const char *args[] = {DISABLE_PCSUITE_COMMAND, NULL};
+        int ret;
+        ret = exec_prog(args[0], args);
+        return ret != 0 ? FALSE : TRUE;
+}
+
 gboolean usb_driver_is_used(void)
 {
         static const char *args[] = {USB_DRIVER_IS_USED_COMMAND, NULL};

Modified: projects/haf/trunk/ke-recv/src/exec-func.h
===================================================================
--- projects/haf/trunk/ke-recv/src/exec-func.h	2008-11-28 12:15:27 UTC (rev 16801)
+++ projects/haf/trunk/ke-recv/src/exec-func.h	2008-11-28 14:50:48 UTC (rev 16802)
@@ -37,6 +37,8 @@
 #define LOAD_USB_DRIVER_COMMAND "/usr/sbin/osso-usb-mass-storage-enable.sh"
 #define UNLOAD_USB_DRIVER_COMMAND "/usr/sbin/osso-usb-mass-storage-disable.sh"
 #define USB_DRIVER_IS_USED_COMMAND "/usr/sbin/osso-usb-mass-storage-is-used.sh"
+#define ENABLE_PCSUITE_COMMAND "/usr/sbin/pcsuite-enable.sh"
+#define DISABLE_PCSUITE_COMMAND "/usr/sbin/pcsuite-disable.sh"
 
 int exec_prog(const char* cmd, const char* args[]);
 
@@ -79,6 +81,20 @@
 gboolean unload_usb_driver(const char **arg);
 
 /**
+  Enable PC Suite mode.
+  Logs errors in case of failure.
+  @return true on success.
+*/
+gboolean enable_pcsuite(void);
+
+/**
+  Disable PC Suite mode.
+  Logs errors in case of failure.
+  @return true on success.
+*/
+gboolean disable_pcsuite(void);
+
+/**
   @return true if USB driver is used, false otherwise.
 */
 gboolean usb_driver_is_used(void);

Modified: projects/haf/trunk/ke-recv/src/ke-recv.c
===================================================================
--- projects/haf/trunk/ke-recv/src/ke-recv.c	2008-11-28 12:15:27 UTC (rev 16801)
+++ projects/haf/trunk/ke-recv/src/ke-recv.c	2008-11-28 14:50:48 UTC (rev 16802)
@@ -41,6 +41,8 @@
         "/org/freedesktop/Hal/devices/usb_device_0_0_musb_hdrc"
 #define DESKTOP_SVC "com.nokia.hildon-desktop"
 
+#define FREMANTLE_MODE 1
+
 extern GConfClient* gconfclient;
 
 const char* camera_out_udi = NULL;
@@ -586,6 +588,34 @@
         return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+static DBusHandlerResult enable_pcsuite_handler(DBusConnection *c,
+                                                DBusMessage *m,
+                                                void *data)
+{
+        ULOG_DEBUG_F("entered");
+        the_connection = c;
+        the_message = m;
+        handle_usb_event(E_ENTER_PCSUITE_MODE);
+        /* invalidate */
+        the_connection = NULL;
+        the_message = NULL;
+        return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult enable_mass_storage_handler(DBusConnection *c,
+                                                     DBusMessage *m,
+                                                     void *data)
+{
+        ULOG_DEBUG_F("entered");
+        the_connection = c;
+        the_message = m;
+        handle_usb_event(E_ENTER_MASS_STORAGE_MODE);
+        /* invalidate */
+        the_connection = NULL;
+        the_message = NULL;
+        return DBUS_HANDLER_RESULT_HANDLED;
+}
+
 int check_install_file(const mmc_info_t *mmc)
 {
         char buf[100];
@@ -692,13 +722,16 @@
                         ULOG_DEBUG_F("device locked signal");
                         device_locked = TRUE;
 	        } else {
-                        usb_state_t state = get_usb_state();
                         ULOG_DEBUG_F("device unlocked signal");
                         device_locked = FALSE;
+#if 0   /* TODO: if dialog is still open, we don't need to do anything;
+           otherwise, we should use the user's decision (saved) */
+                        usb_state_t state = get_usb_state();
                         if (state == S_PERIPHERAL) {
                                 /* possibly USB-share cards */
                                 handle_usb_event(E_ENTER_PERIPHERAL_MODE);
                         }
+#endif
 	        }
         }
         handled = TRUE;
@@ -1497,6 +1530,14 @@
                 mmc->format_op = INTERNAL_FORMAT_OP;
                 mmc->swap_on_op = INTERNAL_MMC_SWAP_ON_OP;
                 mmc->swap_off_op = INTERNAL_MMC_SWAP_OFF_OP;
+
+#ifdef FREMANTLE_MODE
+                mmc->preferred_volume = 3;
+                mmc->control_partitions = 0;
+#else
+                mmc->preferred_volume = 1;
+                mmc->control_partitions = 1;
+#endif
         } else {
                 mmc->volume_label_file = VOLUME_LABEL_FILE;
                 mmc->presence_key = MMC_PRESENT_KEY;
@@ -1508,6 +1549,9 @@
                 mmc->format_op = FORMAT_OP;
                 mmc->swap_on_op = MMC_SWAP_ON_OP;
                 mmc->swap_off_op = MMC_SWAP_OFF_OP;
+
+                mmc->preferred_volume = 1;
+                mmc->control_partitions = 1;
         }
 
         if (get_storage(mmc->udi, &mmc->storage_parent_udi,
@@ -1560,7 +1604,7 @@
                 ret = S_INVALID_USB_STATE;
         } else if (strcmp(prop, "b_peripheral") == 0 ||
                    strcmp(prop, "a_peripheral") == 0) {
-                ret = S_PERIPHERAL;
+                ret = S_PERIPHERAL_WAIT;
         } else if (strcmp(prop, "a_host") == 0 ||
                    strcmp(prop, "b_host") == 0) {
                 ret = S_HOST;
@@ -1690,8 +1734,8 @@
         state = get_usb_state();
         if (state == S_HOST) {
                 handle_usb_event(E_ENTER_HOST_MODE);
-        } else if (state == S_PERIPHERAL) {
-                handle_usb_event(E_ENTER_PERIPHERAL_MODE);
+        } else if (state == S_PERIPHERAL_WAIT) {
+                handle_usb_event(E_ENTER_PERIPHERAL_WAIT_MODE);
         } else if (state == S_CABLE_DETACHED) {
                 handle_usb_event(E_CABLE_DETACHED);
         }
@@ -1722,9 +1766,9 @@
                 if (usb_state == S_HOST) {
                         mount_usb_volumes();
                         set_usb_mode_key("host");
-                } else if (usb_state == S_PERIPHERAL) {
+                } else if (usb_state == S_PERIPHERAL_WAIT) {
                         if (do_e_plugged) {
-                                e_plugged_helper();
+                                handle_usb_event(E_ENTER_PERIPHERAL_WAIT_MODE);
                         }
                         set_usb_mode_key("peripheral");
                 } else {
@@ -2702,9 +2746,9 @@
                                 ULOG_DEBUG_F("E_CABLE_DETACHED in S_HOST");
                                 dismantle_usb_mount_timeout();
                                 unmount_usb_volumes();
-                        } else if (usb_state == S_PERIPHERAL) {
+                        } else if (usb_state == S_MASS_STORAGE) {
                                 ULOG_DEBUG_F("E_CABLE_DETACHED in"
-                                             " S_PERIPHERAL");
+                                             " S_MASS_STORAGE");
                                 handle_event(E_DETACHED, &ext_mmc, NULL);
                                 if (int_mmc_enabled) {
                                         handle_event(E_DETACHED, &int_mmc,
@@ -2721,8 +2765,16 @@
                                 ULOG_INFO_F("E_CABLE_DETACHED in S_EJECTING");
                                 dismantle_usb_unmount_pending();
                                 unmount_usb_volumes();
+                        } else if (usb_state == S_PERIPHERAL_WAIT) {
+                                ULOG_INFO_F("E_CABLE_DETACHED in "
+                                            "S_PERIPHERAL_WAIT");
+                        } else if (usb_state == S_PCSUITE) {
+                                ULOG_INFO_F("E_CABLE_DETACHED in S_PCSUITE");
+                                if (!disable_pcsuite()) {
+                                        ULOG_ERR_F("disable_pcsuite() failed");
+                                }
                         } else {
-                                ULOG_WARN_F("E_CABLE_DETACHED in %d",
+                                ULOG_WARN_F("E_CABLE_DETACHED in %d!",
                                             usb_state);
                         }
                         usb_state = S_CABLE_DETACHED;
@@ -2776,11 +2828,11 @@
                                 setup_usb_mount_timeout(15);
                                 usb_state = S_HOST;
                         } else {
-                                ULOG_WARN_F("E_ENTER_HOST_MODE in %d",
+                                ULOG_WARN_F("E_ENTER_HOST_MODE in %d!",
                                             usb_state);
                         }
                         break;
-                case E_ENTER_PERIPHERAL_MODE:
+                case E_ENTER_PERIPHERAL_WAIT_MODE:
                         /* clear the name */
                         free(usb_device_name);
                         usb_device_name = NULL;
@@ -2788,20 +2840,39 @@
 
                         set_usb_mode_key("peripheral");
                         inform_usb_cable_attached(TRUE);
-                        if (usb_state == S_CABLE_DETACHED
-                            || usb_state == S_PERIPHERAL) {
-                                /* we could be in S_PERIPHERAL already
+                        if (usb_state == S_CABLE_DETACHED ||
+                            usb_state == S_PERIPHERAL_WAIT) {
+                                /* we could be in S_PERIPHERAL_WAIT already
                                  * because of the device lock */
-                                ULOG_DEBUG_F("E_ENTER_PERIPHERAL_MODE"
+                                ULOG_DEBUG_F("E_ENTER_PERIPHERAL_WAIT_MODE"
                                              " in S_CABLE_DETACHED or "
-                                             "S_PERIPHERAL");
-                                usb_state = S_PERIPHERAL;
+                                             "S_PERIPHERAL_WAIT");
+                                usb_state = S_PERIPHERAL_WAIT;
+                        } else {
+                                ULOG_WARN_F("E_ENTER_PERIPHERAL_WAIT_MODE"
+                                            " in %d!", usb_state);
+                        }
+                        break;
+                case E_ENTER_MASS_STORAGE_MODE:
+                        if (usb_state == S_PERIPHERAL_WAIT) {
+                                usb_state = S_MASS_STORAGE;
                                 e_plugged_helper();
                         } else {
-                                ULOG_WARN_F("E_ENTER_PERIPHERAL_MODE in %d",
+                                ULOG_WARN_F("E_ENTER_MASS_STORAGE_MODE in %d!",
                                             usb_state);
                         }
                         break;
+                case E_ENTER_PCSUITE_MODE:
+                        if (usb_state == S_PERIPHERAL_WAIT) {
+                                usb_state = S_PCSUITE;
+                                if (!enable_pcsuite()) {
+                                        ULOG_ERR_F("Couldn't enable PC Suite");
+                                }
+                        } else {
+                                ULOG_WARN_F("E_ENTER_PCSUITE_MODE in %d!",
+                                            usb_state);
+                        }
+                        break;
                 default:
                         ULOG_ERR_F("unknown event %d", e);
         }
@@ -2821,9 +2892,9 @@
         }
 }
 
-int get_cable_peripheral(void)
+int in_mass_storage_mode(void)
 {
-        return usb_state == S_PERIPHERAL;
+        return usb_state == S_MASS_STORAGE;
 }
 
 static void sigterm(int signo)
@@ -2999,6 +3070,14 @@
         register_op(sys_conn, &vtable,
                     "/com/nokia/ke_recv/usb_cancel_eject", NULL);
 
+        /* D-Bus interface for PC suite selection */
+        vtable.message_function = enable_pcsuite_handler;
+        register_op(sys_conn, &vtable, ENABLE_PCSUITE_OP, NULL);
+
+        /* D-Bus interface for USB mass storage mode selection */
+        vtable.message_function = enable_mass_storage_handler;
+        register_op(sys_conn, &vtable, ENABLE_MASS_STORAGE_OP, NULL);
+
         add_prop_watch(ext_mmc.cover_udi);
         add_prop_watch(int_mmc.cover_udi);
         add_prop_watch(camera_out_udi);

Modified: projects/haf/trunk/ke-recv/src/ke-recv.h
===================================================================
--- projects/haf/trunk/ke-recv/src/ke-recv.h	2008-11-28 12:15:27 UTC (rev 16801)
+++ projects/haf/trunk/ke-recv/src/ke-recv.h	2008-11-28 14:50:48 UTC (rev 16802)
@@ -147,15 +147,21 @@
 #define AK_BROADCAST_OP "/com/nokia/osso_app_killer"
 #define AK_BROADCAST_EXIT "exit"
 
+/* PC suite & mass storage */
+#define ENABLE_PCSUITE_OP "/com/nokia/ke_recv/enable_pcsuite"
+#define ENABLE_MASS_STORAGE_OP "/com/nokia/ke_recv/enable_mass_storage"
+
 #define INVALID_DIALOG_RESPONSE -666
 
 typedef enum {
         S_INVALID_USB_STATE = 0,
         S_CABLE_DETACHED,
-        S_PERIPHERAL,
+        S_PERIPHERAL_WAIT,
         S_HOST,
         S_EJECTING,
-        S_EJECTED
+        S_EJECTED,
+        S_MASS_STORAGE,
+        S_PCSUITE
 } usb_state_t;
 
 typedef enum {
@@ -163,7 +169,9 @@
         E_EJECT,
         E_EJECT_CANCELLED,
         E_ENTER_HOST_MODE,
-        E_ENTER_PERIPHERAL_MODE
+        E_ENTER_PERIPHERAL_WAIT_MODE,
+        E_ENTER_MASS_STORAGE_MODE,
+        E_ENTER_PCSUITE_MODE
 } usb_event_t;
 
 typedef enum {
@@ -203,6 +211,9 @@
         mmc_cover_t cover_state;
 
         volume_list_t volumes;
+        int preferred_volume;  /* volume (partition) to do operations on */
+        int control_partitions;  /* whether or not we control the whole
+                                    device, not just one partition */
 
         char desired_label[12];
         const char *mount_point;
@@ -288,7 +299,7 @@
 void rm_volume_from_list(volume_list_t *l, const char *udi);
 int init_mmc_volumes(mmc_info_t *mmc);
 void clear_volume_list(volume_list_t *l);
-int get_cable_peripheral(void);
+int in_mass_storage_mode(void);
 usb_state_t get_usb_state(void);
 int check_install_file(const mmc_info_t *mmc);
 

Modified: projects/haf/trunk/ke-recv/src/mmc-format.c
===================================================================
--- projects/haf/trunk/ke-recv/src/mmc-format.c	2008-11-28 12:15:27 UTC (rev 16801)
+++ projects/haf/trunk/ke-recv/src/mmc-format.c	2008-11-28 14:50:48 UTC (rev 16802)
@@ -41,6 +41,7 @@
 
 /* device file names for mounting, renaming, formatting */
 const char* mmc_dev_file_without_part = NULL;
+const char* mmc_dev_file_with_part = NULL;
 
 static pid_t child_pid = -1;
 static int pipe_fd = -1;
@@ -158,22 +159,20 @@
 static gboolean start_format()
 {
         int fd, blk_sz, ret;
-        char blk_sz_buf[10], mmc_dev_file_with_part[100];
+        char blk_sz_buf[10];
         const char* args[] = {MMC_FORMAT_COMMAND, NULL, "-n", NULL,
                               "-S", NULL, "-F", "32", "-R", "38", NULL};
 
         ULOG_DEBUG_F("entered");
 
-        /* prepare partition table */
-        if (!prepare_partition()) {
-                return FALSE;
+        if (mmc_dev_file_without_part != NULL) {
+                /* prepare partition table */
+                if (!prepare_partition()) {
+                        return FALSE;
+                }
+                ULOG_DEBUG_F("partition prepared");
         }
-        ULOG_DEBUG_F("partition prepared");
 
-        /* FIXME: should use HAL to get this... */
-        snprintf(mmc_dev_file_with_part, 100, "%sp1",
-                 mmc_dev_file_without_part);
-
         args[1] = mmc_dev_file_with_part;
         args[3] = mmc_volume_label;
 
@@ -258,8 +257,9 @@
         ULOG_OPEN(MMC_FORMAT_PROG_NAME);
         ULOG_DEBUG_L("entered");
 
-        if (argc != 3) {
-                ULOG_CRIT_L("Usage: %s <device> <volume label>", argv[0]);
+        if (argc != 3 && argc != 4) {
+                ULOG_CRIT_L("Usage: %s [<device>] <partition> <volume label>",
+                            argv[0]);
                 exit(1);
         }
         sa.sa_handler = sig_handler;
@@ -280,8 +280,14 @@
                 ULOG_ERR_L("textdomain() failed");
         }
 
-        mmc_dev_file_without_part = argv[1];
-        mmc_volume_label = argv[2];
+        if (argc == 4) {
+                mmc_dev_file_without_part = argv[1];
+                mmc_dev_file_with_part = argv[2];
+                mmc_volume_label = argv[3];
+        } else {
+                mmc_dev_file_with_part = argv[1];
+                mmc_volume_label = argv[2];
+        }
 
         if (!gtk_init_check(&argc, &argv)) {
                 ULOG_CRIT_L("gtk_init failed");

Modified: projects/haf/trunk/ke-recv/src/osso-usb-mass-storage-enable.sh
===================================================================
--- projects/haf/trunk/ke-recv/src/osso-usb-mass-storage-enable.sh	2008-11-28 12:15:27 UTC (rev 16801)
+++ projects/haf/trunk/ke-recv/src/osso-usb-mass-storage-enable.sh	2008-11-28 14:50:48 UTC (rev 16802)
@@ -21,6 +21,12 @@
 
 RC=0
 
+/sbin/lsmod | grep g_nokia > /dev/null
+if [ $? = 0 ]; then
+    echo "$0: removing g_nokia"
+    /sbin/rmmod g_nokia
+fi
+
 /sbin/lsmod | grep g_file_storage > /dev/null
 if [ $? != 0 ]; then
     /sbin/modprobe g_file_storage stall=0 luns=2 removable

Added: projects/haf/trunk/ke-recv/src/pcsuite-disable.sh
===================================================================
--- projects/haf/trunk/ke-recv/src/pcsuite-disable.sh	2008-11-28 12:15:27 UTC (rev 16801)
+++ projects/haf/trunk/ke-recv/src/pcsuite-disable.sh	2008-11-28 14:50:48 UTC (rev 16802)
@@ -0,0 +1,23 @@
+#!/bin/sh
+# This file is part of ke-recv
+#
+# Copyright (C) 2008 Nokia Corporation. All rights reserved.
+#
+# Contact: Kimmo Hämäläinen <kimmo.hamalainen at nokia.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the 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 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
+
+echo "$0: I ain't no doing nothing"
+exit 0


Property changes on: projects/haf/trunk/ke-recv/src/pcsuite-disable.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: projects/haf/trunk/ke-recv/src/pcsuite-enable.sh
===================================================================
--- projects/haf/trunk/ke-recv/src/pcsuite-enable.sh	2008-11-28 12:15:27 UTC (rev 16801)
+++ projects/haf/trunk/ke-recv/src/pcsuite-enable.sh	2008-11-28 14:50:48 UTC (rev 16802)
@@ -0,0 +1,59 @@
+#!/bin/sh
+# This file is part of ke-recv
+#
+# Copyright (C) 2008 Nokia Corporation. All rights reserved.
+#
+# Contact: Kimmo Hämäläinen <kimmo.hamalainen at nokia.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the 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 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
+
+/sbin/lsmod | grep g_file_storage > /dev/null
+if [ $? = 0 ]; then
+    echo "$0: removing g_file_storage"
+    /sbin/rmmod g_file_storage
+fi
+
+/sbin/lsmod | grep g_nokia > /dev/null
+if [ $? != 0 ]; then
+    /sbin/modprobe g_nokia
+    RC=$?
+fi
+
+if [ $RC != 0 ]; then
+    echo "$0: failed to install g_nokia"
+    exit 1
+else
+    # TODO: remove the sleep when the wait is in place
+    sleep 2
+fi
+
+# TODO: wait for the devices
+
+OBEXD_PID=`pidof obexd`
+if [ $? != 0 ]; then
+    echo "$0: failed to get obexd's PID"
+    exit 1
+fi
+
+SYNCD_PID=`pidof syncd`
+if [ $? != 0 ]; then
+    echo "$0: failed to get syncd's PID"
+    exit 1
+fi
+
+kill -USR1 $OBEXD_PID
+kill -USR1 $SYNCD_PID
+
+exit 0


Property changes on: projects/haf/trunk/ke-recv/src/pcsuite-enable.sh
___________________________________________________________________
Name: svn:executable
   + *


More information about the maemo-commits mailing list