1. 21 Feb, 2019 2 commits
    • spiiroin's avatar
      [usb-moded] Normalize backend startup/cleanup functionality · 97107d13
      spiiroin authored
      Use backend_init() and backend_quit() functions for settings up and
      cleaning up all backends.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      97107d13
    • spiiroin's avatar
      [settings] Do not write dynamic data to /etc. Fixes JB#38241 · 0e9f72cb
      spiiroin authored
      While combining all configuration data into /etc/usb-moded/usb-moded.ini
      works as expected when new configuration files are installed to the device,
      it also means that 1) uninstalling / updating configuration files has no
      effect and 2) /etc can't reside on a read-only file-system.
      
      Maintain "delta to static configuration" and store it outside /etc - in
      /var/lib/usb-moded/usb-moded.ini, so that also changes in / removal of
      existing configuration files are handled in deterministic manner.
      
      If /etc/usb-moded/usb-moded.ini exists, migrate data from it and then remove
      the now unnecessary file.
      
      Streamline handling of non-existing configuration and remove functions made
      redundant in the process.
      
      Note: The "read from filesystem on each setting access" is retained for now
      to avoid regression is situations where such behavior might be expected.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      0e9f72cb
  2. 20 Feb, 2019 2 commits
  3. 07 Feb, 2019 1 commit
    • spiiroin's avatar
      [dbus] Add target mode signaling. JB#44479 · 87936ffc
      spiiroin authored
      Some transitions such as activating mtp mode can take so long that giving
      user feedback becomes necessary. However as usb-moded exposes only what
      has happened, there is no reliable source of information for what is
      going on.
      
      Also, the "sig_usb_state_ind" D-Bus signal is used for transmitting both
      mode change notifications and transient events - which is confusing and
      can cause problems if new signals are ever added as there is no backwards
      compatible ways to tell apart mode names from event names.
      
      Add dbus query / change notifications for target mode. The target mode
      is changed before starting mode transition, so that processes listening
      to signals from usb-moded know what kind of transition is happening when
      the current mode changes to "busy".
      
      Add separate dbus signals for mode changes and events. The legacy
      "sig_usb_state_ind" is retained as-is for the sake of backwards
      compatibility.
      
      Also synchronize the content of D-Bus Introspect xml data provided as
      a file in development package and made available at runtime via D-Bus
      method call.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      87936ffc
  4. 05 Sep, 2018 8 commits
  5. 24 Aug, 2018 14 commits
    • spiiroin's avatar
      [usb_moded] Reject mtp_mode if mtp daemon can't be started · a7af998e
      spiiroin authored
      Gadget is programmed according to mtp_mode requirements
      regardless of availability of mtp daemon - which leaves
      non-functional mtp_mode supposedly active.
      
      Switch to fallback mode if mtp daemon can't be started.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      a7af998e
    • spiiroin's avatar
      [usb_moded] Fix mode-switch failure handling · 439360bf
      spiiroin authored
      Using MODE_CHARGING_FALLBACK as mode switch failure fallback
      causes retriggering of "ask" mode. And overriding only higher
      level state data leads to subtle issues later on.
      
      Use MODE_CHARGING as failure fallback, and override both
      high and low level mode state info when requested mode can't
      be activated.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      439360bf
    • spiiroin's avatar
      [usb_moded] Expose mode switch as "busy" during transition · f8d0985c
      spiiroin authored
      Especially switch to mtp_mode can take a long time to finish.
      
      Use transitional "busy" mode as an enabler for ui showing a spinner when
      mode change takes long enough to cause confusion for users.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      f8d0985c
    • spiiroin's avatar
      [usb_moded] Explicitly start/stop mtp daemon. Fixes JB#41748 · 041d46de
      spiiroin authored
      The mtp functionality is started roughly as follows:
      
      1. usb-moded completes whole gadget configuration, and then
      2. signals mtp mode activation on D-Bus
      3. msyncd sees the mode change and loads mtp plugin
      4. mtp plugin writes endpoint configuration, and then
      5. scans storage ares to enumerate files exposed via mtp, but
      6. does not really respond to ptp/mtp requests until storages are ready
      
      The problems are:
      
      While the above sequence has worked with with android usb, it does cause
      timing issues for usb enumeration and longer than expected response times
      from pc side mtp initiator point of view.
      
      Additionally when configfs is used, the gadget configuration can't even
      be completed before mtp daemon gets a chance to write configuration data
      to the control endpoint.
      
      To remedy the situation the following changes are made:
      
      1. buteo-mtp-qt5-sync-plugin package is removed from the system -> mtp
         functionality is no longer handled by msyncd process
      
      2. mtp daemon is made to enumerate storage content before writing config
         data to control endpoint -> when usb enumeration is possible, mtp
         daemon is already ready to handle commands from initiator
      
      3. usb-moded explicitly starts/stops mtp daemon when it is about to
         activate/deactivate mtp_mode -> usb stays configured in charging
         mode until it is ready to handle mtp
      
      This patch handles step (3). Step (2) is in buteo-mtp-qt5 >= 0.5.0,
      and (1) needs to be fixed in device specific package configuration.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      041d46de
    • spiiroin's avatar
      [modesetting] Refactor mass-storage mode handling · e659901c
      spiiroin authored
      Code duplication and interleaving of kernel module vs android usb logic
      makes it difficult to add support for configfs based systems.
      
      Use helper functions for common tasks.
      
      Use explicit checks for what backend should be used.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      e659901c
    • spiiroin's avatar
      [usb_moded] Do not track pc / charger connect separately. JB#41748 · 8e469091
      spiiroin authored
      Handling "connected to pc" and "connected to charger" as separate boolean
      states just complicates things.
      
      Move cable_state_t enumeration values from udev module to usb_moded.h
      to make them generally available.
      
      Utilize cable_state_t also within usb_moded.c module.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      8e469091
    • spiiroin's avatar
      [usb_moded] Arrange a route for signaling mode switch failures. JB#41748 · 94978637
      spiiroin authored
      If gadget configuration / other mode selection related activites fail,
      usb-moded attempts to activate charging only configuration / does fallback
      to undefined mode. This situation is not propagated upwards and thus
      incorrect information is exposed over D-Bus.
      
      Add feedback function that lower level functionality can use to signal
      failures / successfully completed mode change, and delay broadcasting
      of D-Bus signals until completing the change.
      
      As the mode change actions can potentially block for extended periods of
      time and render usb-moded unresponsive, mark places where worker thread
      signaling could be utilized instead of function calls.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      94978637
    • spiiroin's avatar
      [usb_moded] Use common code for evaluating "can-export" state · 623c2ee1
      spiiroin authored
      When usb-moded is compiled with MEEGOLOCK feature enabled, only limited
      functionality is available while device is locked. However the scattered
      use of MEEGOLOCK compilation time conditionals makes the code
      unnecessarily difficult to read.
      
      Add a utility function to handle evaluation of the can-export state and
      remove the now unnecessary preprocessor conditionals.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      623c2ee1
    • spiiroin's avatar
      [usb_moded] Tweak mode selection dialog related D-Bus signaling · 046e1b71
      spiiroin authored
      The USB_CONNECTED_DIALOG_SHOW signal is sent just before the usb mode
      changes to MODE_ASK. Handling it as a part of activity on mode change
      instead of as precursor to mode change makes the logic more robust
      and a bit simpler.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      046e1b71
    • spiiroin's avatar
      [usb_moded] Move connect/disconnect signaling to udev · 39a3a90c
      spiiroin authored
      Cable connect/disconnect is detected at udev module - handling the
      related dbus signaling in the same place allows simplifying the usb
      mode related logic.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      39a3a90c
    • spiiroin's avatar
      [usb_moded] Refactor entering/leaving usb mode. JB#41748 · 64350689
      spiiroin authored
      Split mode switching to three layers: Tracking cable connection state,
      choosing target mode, and performing required actions to activate
      the chosen mode.
      
      Try to minimize places where layer borders are crossed - which should
      work also as an enabler for moving blocking actions to separate thread
      later on.
      
      Arrange logic in such manner that usb gadget is always configured as
      being able to serve some function - fallback being the dummy mass_storage
      function used for charging.
      
      Deprecate command line options that serve no useful purpose after the
      changes.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      64350689
    • spiiroin's avatar
      [usb_moded] Drop --android-bootup-function option. JB#41748 · 4f53cf48
      spiiroin authored
      The target is to always have android usb enabled with valid function, so
      this workaround is not relevant anymore.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      4f53cf48
    • spiiroin's avatar
      [usb_moded] Normalize multiline comments · 7a386e38
      spiiroin authored
      Just to make it easier for editor to handle automatic indentation, make
      all C comment continuation lines start with whitespace followed by '*'.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      7a386e38
    • spiiroin's avatar
      [usb_moded] Add configfs support. Fixes JB#42083 · 692c2cb3
      spiiroin authored
      Add custom Makefile for faster smoke-test rebuilds without spending time
      in configure, autotools, document generation and/or rolling rpm packages.
      
      Add multiple include protection to all header files.
      
      Move function prototypes away from header files that included in the
      development package.
      
      Mass rename functions to have a prefix giving context for the function.
      For the most part the prefix is derived from the name of the compilation
      module containing the function.
      
      Mass normalize indentation to four spaces in all source files.
      
      Augment author lists on each source file based on git committers.
      
      Remove "inline" attributes from not-really-inlineable functions.
      
      Remove .gitignore.
      
      Remove unused modules-android.c source file.
      
      Define _GNU_SOURCE for whole build rather than in individual files.
      
      Fix resource leaks here and there.
      
      Try to avoid hard-coding android usb paths.
      
      Add configfs backend for usb cadget configuration.
      
      Probe supported backends (configfs, android usb, or kmod) on usb-moded
      startup and make them mutually exclusive with each other.
      
      Allow configfs and android usb control structures some time to show up
      if usb-moded is started during device bootup.
      
      Refactor udev event listener to utilize a state machine. Simplifies
      book keeping and makes pc/charger detection heuristics easier to control.
      
      Refactor mode selection to utilize three interconnected mini state machines.
      Allows separating logically wanted mode from mode programmed to usb and
      mode exposed over D-Bus.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      692c2cb3
  6. 05 Jun, 2018 3 commits
  7. 28 Mar, 2018 5 commits
  8. 08 Mar, 2018 1 commit
    • spiiroin's avatar
      [android] Do not require android configuration block. Fixes JB#41303 · 7a2607c1
      spiiroin authored
      Usb-moded does android usb initialization only if there is a non-empty
      configuration block in the ini-files. This does not make sense anymore
      as the values defined in the config file are used as fallback solution
      if required data can't be obtained by other means.
      
      If android_usb specific sysfs controls are present on the device, try
      to initialize them regardless of whether ubs-moded configuration files
      contain relevant information or not.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      7a2607c1
  9. 17 Aug, 2017 1 commit
    • spiiroin's avatar
      [debug] Optionally include file/line/function info when logging to stderr · 3420f50a
      spiiroin authored
      When debugging usb-moded it is time consuming to find where the
      various debug messages originate from.
      
      When logging to stderr, prefix the messages with source code
      position info similar as gcc uses for reporting compilation
      issues. This allows browsing usb-moded code with jump to the
      next error functionality available in many text editors.
      
      Since the amount of information passed to logging functions
      is significantly increased, check whether the message would
      be emitted or not before evaluating formatting parameters etc.
      
      Also make variables relating to logging level, type, etc
      available only via accessor functions.
      Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
      3420f50a
  10. 11 Aug, 2017 1 commit
  11. 26 Apr, 2017 2 commits