From mboxrd@z Thu Jan 1 00:00:00 1970 From: "pelzflorian (Florian Pelz)" Subject: bug#35640: Make USB modems just work on Guix Date: Thu, 13 Jun 2019 20:05:52 +0200 Message-ID: <20190613180552.ckiihg7p6imni5a3@pelzflorian.localdomain> References: <87ef4zvpm7.fsf@gnu.org> <20190522162909.tds5wz7lj6npkgy4@pelzflorian.localdomain> <87ef4nx3s2.fsf@gnu.org> <20190524201210.bzeyua7lv2mamf52@pelzflorian.localdomain> <20190525111856.jfu5ly2p6ynn3rdk@pelzflorian.localdomain> <87lfyupgxm.fsf@gnu.org> <20190525194215.egiyrax3f3k7nojp@pelzflorian.localdomain> <20190612103646.yem2wtmw6w2vw7an@pelzflorian.localdomain> <87zhmmqzkb.fsf@gnu.org> <20190613180452.yeytgript2vhnl5b@pelzflorian.localdomain> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="4ztiyylwfo3eovbp" Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:51004) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbU85-0004jf-6c for bug-guix@gnu.org; Thu, 13 Jun 2019 14:07:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbU7q-0003iD-N2 for bug-guix@gnu.org; Thu, 13 Jun 2019 14:07:09 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:50757) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hbU7p-0003gc-VS for bug-guix@gnu.org; Thu, 13 Jun 2019 14:07:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hbU7p-00034i-OG for bug-guix@gnu.org; Thu, 13 Jun 2019 14:07:01 -0400 Sender: "Debbugs-submit" Resent-Message-ID: Content-Disposition: inline In-Reply-To: <20190613180452.yeytgript2vhnl5b@pelzflorian.localdomain> List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 35640@debbugs.gnu.org --4ztiyylwfo3eovbp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. --4ztiyylwfo3eovbp Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="0001-Add-usb-modeswitch-service-type.patch" Content-Transfer-Encoding: 8bit >From 27aff97683537407c178ea2b664069def0cf141a Mon Sep 17 00:00:00 2001 From: Florian Pelz 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 ;;; Copyright © 2018 Chris Marusich ;;; Copyright © 2018 Arun Isaac +;;; Copyright © 2019 Florian Pelz ;;; ;;; 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? @@ -1042,6 +1052,100 @@ ModemManager}, a modem management daemon that aims to simplify dialup networking.")))) +;;; +;;; USB_ModeSwitch +;;; + +(define-record-type* + 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 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)."))) + + ;;; ;;; WPA supplicant ;;; -- 2.21.0 --4ztiyylwfo3eovbp Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0002-services-Include-USB_ModeSwitch-in-desktop-services.patch" >From f4a5103b365f8bc5d2c514dad2e40f3c9981cfc2 Mon Sep 17 00:00:00 2001 From: Florian Pelz Date: Wed, 12 Jun 2019 11:16:57 +0200 Subject: [PATCH 2/2] services: Include USB_ModeSwitch in %desktop-services. Fixes . * 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 --4ztiyylwfo3eovbp--