unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: "pelzflorian (Florian Pelz)" <pelzflorian@pelzflorian.de>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 35640@debbugs.gnu.org
Subject: bug#35640: Make USB modems just work on Guix
Date: Thu, 13 Jun 2019 20:05:52 +0200	[thread overview]
Message-ID: <20190613180552.ckiihg7p6imni5a3@pelzflorian.localdomain> (raw)
In-Reply-To: <20190613180452.yeytgript2vhnl5b@pelzflorian.localdomain>

[-- Attachment #1: Type: text/plain, Size: 205 bytes --]

On Thu, Jun 13, 2019 at 08:04:52PM +0200, pelzflorian (Florian Pelz) wrote:
> Find attached patches taking into account your suggestions.  (The
> second patch is unchanged.)
> 

Forgot attachment.  Sorry.

[-- Attachment #2: 0001-Add-usb-modeswitch-service-type.patch --]
[-- Type: text/plain, Size: 8368 bytes --]

From 27aff97683537407c178ea2b664069def0cf141a Mon Sep 17 00:00:00 2001
From: Florian Pelz <pelzflorian@pelzflorian.de>
Date: Thu, 13 Jun 2019 19:17:05 +0200
Subject: [PATCH 1/2] Add usb-modeswitch-service-type.

* gnu/services/networking.scm (usb-modeswitch-service-type): New variable.
(usb-modeswitch-configuration): New variable.
(usb-modeswitch-sh): New procedure.
(usb-modeswitch-configuration->udev-rules): New procedure.
* doc/guix.texi (Networking Services): Document it.
---
 doc/guix.texi               |  35 ++++++++++++
 gnu/services/networking.scm | 104 ++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index 9dc1d2a9ca..c407d6257f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -12668,6 +12668,41 @@ The ModemManager package to use.
 @end table
 @end deftp
 
+@cindex USB_ModeSwitch
+@cindex Modeswitching
+
+@defvr {Scheme Variable} usb-modeswitch-service-type
+This is the service type for the
+@uref{http://www.draisberghof.de/usb_modeswitch/, USB_ModeSwitch} service. The
+value for this service type is a @code{usb-modeswitch-configuration} record.
+
+When plugged in, some USB modems (and other USB devices) initially present
+themselves as a read-only storage medium and not as a modem.  They need to be
+@dfn{modeswitched} before they are usable.  The USB_ModeSwitch service type
+installs udev rules to automatically modeswitch these devices when they are
+plugged in.
+@end defvr
+
+@deftp {Data Type} usb-modeswitch-configuration
+Data type representing the configuration of USB_ModeSwitch.
+
+@table @asis
+@item @code{usb-modeswitch} (default: @code{usb-modeswitch})
+The USB_ModeSwitch package providing the binaries for modeswitching.
+
+@item @code{usb-modeswitch-data} (default: @code{usb-modeswitch-data})
+The package providing the device data and udev rules file used by
+USB_ModeSwitch.
+
+@item @code{config-file} (default: @code{#~(string-append #$usb-modeswitch:dispatcher "/etc/usb_modeswitch.conf")})
+Which config file to use for the USB_ModeSwitch dispatcher.  By default the
+config file shipped with USB_ModeSwitch is used which disables logging to
+@file{/var/log} among other default settings.  If set to @code{#f}, no config
+file is used.
+
+@end table
+@end deftp
+
 @cindex NetworkManager
 
 @defvr {Scheme Variable} network-manager-service-type
diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
index 082a85f63d..73acb3b17f 100644
--- a/gnu/services/networking.scm
+++ b/gnu/services/networking.scm
@@ -9,6 +9,7 @@
 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2018 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2019 Florian Pelz <pelzflorian@pelzflorian.de>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -33,10 +34,13 @@
   #:use-module (gnu system shadow)
   #:use-module (gnu system pam)
   #:use-module (gnu packages admin)
+  #:use-module (gnu packages base)
+  #:use-module (gnu packages bash)
   #:use-module (gnu packages connman)
   #:use-module (gnu packages freedesktop)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages tor)
+  #:use-module (gnu packages usb-modeswitch)
   #:use-module (gnu packages messaging)
   #:use-module (gnu packages networking)
   #:use-module (gnu packages ntp)
@@ -104,6 +108,12 @@
             modem-manager-configuration?
             modem-manager-service-type
 
+            usb-modeswitch-configuration
+            usb-modeswitch-configuration?
+            usb-modeswitch-configuration-usb-modeswitch
+            usb-modeswitch-configuration-usb-modeswitch-data
+            usb-modeswitch-service-type
+
             <wpa-supplicant-configuration>
             wpa-supplicant-configuration
             wpa-supplicant-configuration?
@@ -1042,6 +1052,100 @@ ModemManager}, a modem management daemon that aims to simplify dialup
 networking."))))
 
 \f
+;;;
+;;; USB_ModeSwitch
+;;;
+
+(define-record-type* <usb-modeswitch-configuration>
+  usb-modeswitch-configuration make-usb-modeswitch-configuration
+  usb-modeswitch-configuration?
+  (usb-modeswitch      usb-modeswitch-configuration-usb-modeswitch
+                       (default usb-modeswitch))
+  (usb-modeswitch-data usb-modeswitch-configuration-usb-modeswitch-data
+                       (default usb-modeswitch-data))
+  (config-file         usb-modeswitch-configuration-config-file
+                       (default #~(string-append #$usb-modeswitch:dispatcher
+                                                 "/etc/usb_modeswitch.conf"))))
+
+(define (usb-modeswitch-sh usb-modeswitch config-file)
+  "Build a copy of usb_modeswitch.sh located in package USB-MODESWITCH,
+modified to pass the CONFIG-FILE in its calls to usb_modeswitch_dispatcher,
+and wrap it to actually find the dispatcher in USB-MODESWITCH.  The script
+will be run by USB_ModeSwitch’s udev rules file when a modeswitchable USB
+device is detected."
+  (computed-file
+   "usb_modeswitch-sh"
+   (with-imported-modules '((guix build utils))
+     #~(begin
+         (use-modules (guix build utils))
+         (let ((cfg-param
+                #$(if config-file
+                      #~(string-append " --config-file=" #$config-file)
+                      "")))
+           (mkdir #$output)
+           (install-file (string-append #$usb-modeswitch:dispatcher
+                                        "/lib/udev/usb_modeswitch")
+                         #$output)
+
+           ;; insert CFG-PARAM into usb_modeswitch_dispatcher command-lines
+           (substitute* (string-append #$output "/usb_modeswitch")
+             (("(exec usb_modeswitch_dispatcher .*)( 2>>)" _ left right)
+              (string-append left cfg-param right))
+             (("(exec usb_modeswitch_dispatcher .*)( &)" _ left right)
+              (string-append left cfg-param right)))
+
+           ;; wrap-program needs bash in PATH:
+           (putenv (string-append "PATH=" #$bash "/bin"))
+           (wrap-program (string-append #$output "/usb_modeswitch")
+             `("PATH" ":" = (,(string-append #$coreutils "/bin")
+                             ,(string-append
+                               #$usb-modeswitch:dispatcher
+                               "/bin")))))))))
+
+(define (usb-modeswitch-configuration->udev-rules config)
+  "Build a rules file for extending udev-service-type from the rules in the
+usb-modeswitch package specified in CONFIG.  The rules file will invoke
+usb_modeswitch.sh from the usb-modeswitch package, modified to pass the right
+config file."
+  (match config
+    (($ <usb-modeswitch-configuration> usb-modeswitch data config-file)
+     (computed-file
+      "usb_modeswitch.rules"
+      (with-imported-modules '((guix build utils))
+        #~(begin
+            (use-modules (guix build utils))
+            (let ((in (string-append #$data "/udev/40-usb_modeswitch.rules"))
+                  (out (string-append #$output "/lib/udev/rules.d"))
+                  (script #$(usb-modeswitch-sh usb-modeswitch config-file)))
+              (mkdir-p out)
+              (chdir out)
+              (install-file in out)
+              (substitute* "40-usb_modeswitch.rules"
+                (("PROGRAM=\"usb_modeswitch")
+                 (string-append "PROGRAM=\"" script "/usb_modeswitch"))
+                (("RUN\\+=\"usb_modeswitch")
+                 (string-append "RUN+=\"" script "/usb_modeswitch"))))))))))
+
+(define usb-modeswitch-service-type
+  (service-type
+   (name 'usb-modeswitch)
+   (extensions
+    (list
+     (service-extension
+      udev-service-type
+      (lambda (config)
+        (let ((rules (usb-modeswitch-configuration->udev-rules config)))
+          (list rules))))))
+   (default-value (usb-modeswitch-configuration))
+   (description "Run @uref{http://www.draisberghof.de/usb_modeswitch/,
+USB_ModeSwitch}, a mode switching tool for controlling USB devices with
+multiple @dfn{modes}.  When plugged in for the first time many USB
+devices (primarily high-speed WAN modems) act like a flash storage containing
+installers for Windows drivers.  USB_ModeSwitch replays the sequence the
+Windows drivers would send to switch their mode from storage to modem (or
+whatever the thing is supposed to do).")))
+
+\f
 ;;;
 ;;; WPA supplicant
 ;;;
-- 
2.21.0


[-- Attachment #3: 0002-services-Include-USB_ModeSwitch-in-desktop-services.patch --]
[-- Type: text/plain, Size: 1540 bytes --]

From f4a5103b365f8bc5d2c514dad2e40f3c9981cfc2 Mon Sep 17 00:00:00 2001
From: Florian Pelz <pelzflorian@pelzflorian.de>
Date: Wed, 12 Jun 2019 11:16:57 +0200
Subject: [PATCH 2/2] services: Include USB_ModeSwitch in %desktop-services.

Fixes <https://bugs.gnu.org/35640>.

* gnu/services/desktop.scm (%desktop-services): Add usb-modeswitch-service-type.
* doc/guix.texi (Networking Services): Document it.
---
 doc/guix.texi            | 3 +++
 gnu/services/desktop.scm | 1 +
 2 files changed, 4 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index c407d6257f..8b07693445 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -12681,6 +12681,9 @@ themselves as a read-only storage medium and not as a modem.  They need to be
 @dfn{modeswitched} before they are usable.  The USB_ModeSwitch service type
 installs udev rules to automatically modeswitch these devices when they are
 plugged in.
+
+This service is part of @code{%desktop-services} (@pxref{Desktop
+Services}).
 @end defvr
 
 @deftp {Data Type} usb-modeswitch-configuration
diff --git a/gnu/services/desktop.scm b/gnu/services/desktop.scm
index 652f7b1b02..343d507c14 100644
--- a/gnu/services/desktop.scm
+++ b/gnu/services/desktop.scm
@@ -1067,6 +1067,7 @@ dispatches events from it.")))
                          profile-service-type
                          (list network-manager-applet))
          (service modem-manager-service-type)
+         (service usb-modeswitch-service-type)
 
          ;; The D-Bus clique.
          (service avahi-service-type)
-- 
2.21.0


  reply	other threads:[~2019-06-13 18:07 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-08 18:26 bug#35640: Make USB modems just work on Guix pelzflorian (Florian Pelz)
2019-05-09  5:31 ` pelzflorian (Florian Pelz)
2019-05-09 12:55   ` Danny Milosavljevic
2019-05-09 13:07     ` pelzflorian (Florian Pelz)
2019-05-09 13:43       ` pelzflorian (Florian Pelz)
2019-05-09 15:24 ` Ludovic Courtès
2019-05-13 20:57   ` pelzflorian (Florian Pelz)
2019-05-13 21:04     ` pelzflorian (Florian Pelz)
2019-05-14  7:22       ` pelzflorian (Florian Pelz)
2019-05-14  8:35       ` Danny Milosavljevic
2019-05-14 20:56         ` pelzflorian (Florian Pelz)
2019-05-15 13:01           ` Ludovic Courtès
2019-05-15 14:40             ` pelzflorian (Florian Pelz)
2019-05-22 16:29             ` pelzflorian (Florian Pelz)
2019-05-22 17:58               ` pelzflorian (Florian Pelz)
2019-05-24 15:37               ` Ludovic Courtès
2019-05-24 20:12                 ` pelzflorian (Florian Pelz)
2019-05-25 11:18                   ` pelzflorian (Florian Pelz)
2019-05-25 12:43                     ` pelzflorian (Florian Pelz)
2019-05-25 17:44                     ` Ludovic Courtès
2019-05-25 19:42                       ` pelzflorian (Florian Pelz)
2019-06-12 10:36                         ` pelzflorian (Florian Pelz)
2019-06-12 10:41                           ` pelzflorian (Florian Pelz)
2019-06-12 21:00                             ` Ludovic Courtès
2019-06-12 21:11                           ` Ludovic Courtès
2019-06-13 18:04                             ` pelzflorian (Florian Pelz)
2019-06-13 18:05                               ` pelzflorian (Florian Pelz) [this message]
2019-06-15 16:39                                 ` Ludovic Courtès
2019-06-12 12:13                       ` pelzflorian (Florian Pelz)
2019-06-12 12:21                         ` Ludovic Courtès
2019-06-12 19:51                           ` pelzflorian (Florian Pelz)
2019-06-12 20:42                             ` Ludovic Courtès
2019-06-12 20:58                         ` Ludovic Courtès
2019-05-14 20:48     ` Ludovic Courtès
2019-05-15 11:17     ` pelzflorian (Florian Pelz)
2019-05-15 12:51       ` Ludovic Courtès
2019-05-16  7:50   ` pelzflorian (Florian Pelz)
2019-05-16  8:34     ` pelzflorian (Florian Pelz)
2019-05-16 11:30     ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190613180552.ckiihg7p6imni5a3@pelzflorian.localdomain \
    --to=pelzflorian@pelzflorian.de \
    --cc=35640@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).