pax_global_header00006660000000000000000000000064140154236170014515gustar00rootroot0000000000000052 comment=7b93914ed023bf6dddd92c6cebb993715f75f2a1 wys-0.1.11/000077500000000000000000000000001401542361700124175ustar00rootroot00000000000000wys-0.1.11/.dir-locals.el000066400000000000000000000000451401542361700150470ustar00rootroot00000000000000((nil . ((indent-tabs-mode . nil)))) wys-0.1.11/.gitlab-ci.yml000066400000000000000000000017171401542361700150610ustar00rootroot00000000000000include: - 'https://source.puri.sm/Librem5/librem5-ci/raw/master/librem5-pipeline-definitions.yml' stages: - build - package - test-package variables: DEPS: build-essential before_script: - export DEBIAN_FRONTEND=noninteractive - apt-get -y update - apt-get -y update - apt-get -y build-dep . - apt-get -y install $DEPS .tags: &tags tags: - librem5 build:native: <<: *tags stage: build artifacts: paths: - _build script: - meson --werror . _build - ninja -C _build except: variables: - $PKG_ONLY == "1" package:deb-debian-buster: extends: .l5-build-debian-package package:deb-debian-buster:arm64: tags: - librem5:arm64 extends: .l5-build-debian-package autopkgtest-debian-buster-package: dependencies: - package:deb-debian-buster extends: .l5-autopkgtest-debian-package lintian-debian-buster-package: dependencies: - package:deb-debian-buster extends: .l5-lintian-debian-package wys-0.1.11/COPYING000066400000000000000000001045131401542361700134560ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 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, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . wys-0.1.11/README.md000066400000000000000000000035121401542361700136770ustar00rootroot00000000000000# Wys A daemon to bring up and take down PulseAudio loopbacks for phone call audio. Wys was written to manage call audio in the Librem 5 phone with a Gemalto PLS8. It may be useful for other systems. Wys is pronounced "weece" to rhyme with "fleece". ## License Wys is licensed under the GPLv3+. ## Dependencies sudo apt-get install libpulse-dev libglib2.0-dev ## Building We use the meson and thereby Ninja. The quickest way to get going is to do the following: meson ../wys-build ninja -C ../wys-build ninja -C ../wys-build install ## Running Wys is usually run as a systemd user service. To run it by hand, the program takes one option, --modem. It should specify the ALSA card name of the modem ALSA device. That is, the value of the "alsa.card_name" property of the device's PulseAudio sink or source. $ wys --modem "SIMCom SIM7100" You can also set the WYS_MODEM environment variable with the same information. $ export WYS_MODEM="SIMCom SIM7100" $ wys There is also a database of machine-specific configuration files in the machine-conf/ sub-directory. This database will be installed under the installation prefix, in $prefix/share/wys/machine-conf. The machine name is the device tree model field for that machine, given by /proc/device-tree/model. A number of locations will be checked for Wys machine configuration entries under a wys/machine-conf/ sub-directory in this order: $XDG_CONFIG_HOME (default: $HOME/.config) $XDG_CONFIG_DIRS (default: /etc/xdg) sysconfdir meson option (default: $prefix/etc) datadir meson option (default: $prefix/share) $XDG_DATA_DIRS (default: /usr/local/share/:/usr/share/) The precendence of the different configuration methods is as follows: (1) command line options (2) environment variables (3) machine configuration files. wys-0.1.11/debian/000077500000000000000000000000001401542361700136415ustar00rootroot00000000000000wys-0.1.11/debian/changelog000066400000000000000000000067121401542361700155210ustar00rootroot00000000000000wys (0.1.11) byzantium; urgency=medium [ Guido Günther ] * wys-audio: Detect modem by device.class. This keeps the card names, to the kernel and ucm. (Closes: #6) * Drop machine-conf for Librem 5. We don't use it there. But let's keep the logic in case it's of use to other platforms * wys-audio: Guard public methods. This makes sure we get the right type passed in and also don't crash when there's no modem. * d/gbp.conf: Automatically bump meson version [ Danct12 ] * meson.build: bump version to 0.1.10 -- Guido Günther Tue, 23 Feb 2021 13:14:41 +0100 wys (0.1.10) amber-phone; urgency=critical * machine-conf: Add config entry for Evergreen -- Sebastian Krzyszkowiak Mon, 16 Nov 2020 00:37:51 +0100 wys (0.1.9) amber-phone; urgency=medium [ Sebastian Krzyszkowiak ] * Get rid of codec handling * Request echo cancellation from PulseAudio on mic and speaker streams [ Guido Günther ] * gitlab-ci: Honor PKG_ONLY * audio: Actually set appliction props -- Martin Kepplinger Wed, 04 Nov 2020 16:31:55 +0100 wys (0.1.8) amber-phone; urgency=high [ Bob Ham ] * main: Clarify warning message for no codec or modem specification [ Guido Günther ] * debian: Switch to compat level 12 * Add machine-confs for Librem 5r2 and r3 meson fails at copying symlinked dirs so symlink the files only. * Add gitlab-ci * Add gbp.conf -- Guido Günther Tue, 21 Jul 2020 15:53:48 +0200 wys (0.1.7) amber-phone; urgency=medium * main: Fix interface name comparison check during interface removal * main: Stop running (via systemd restart) when not configured -- Bob Ham Fri, 24 Jan 2020 13:33:11 +0000 wys (0.1.6) amber-phone; urgency=medium * d/control: Add versioned dependecy on pulseaudio -- Bob Ham Sun, 08 Dec 2019 12:17:58 +0000 wys (0.1.5) amber-phone; urgency=medium [ Bob Ham ] * Instantiate mic loopback module only when call is active [ Angus Ainslie ] * src/wys-audio.c: set the max latency at 100 milli seconds -- Bob Ham Fri, 06 Dec 2019 15:00:35 +0000 wys (0.1.4) amber-phone; urgency=medium * libmachine-check: Add useful debugging output * libmachine-check: Fix setting of default pass value -- Bob Ham Fri, 29 Nov 2019 15:05:12 +0000 wys (0.1.3) amber-phone; urgency=medium [ Angus Ainslie ] * machine-conf/Purism Librem 5: add config files for the librem5 phone [ Bob Ham ] * debian: Make systemd unit WantedBy default.target instead of RequiredBy -- Bob Ham Tue, 26 Nov 2019 08:45:28 +0000 wys (0.1.2) amber-phone; urgency=medium * machine-check: Add blacklist with only devkit -- Bob Ham Thu, 21 Nov 2019 14:38:43 +0000 wys (0.1.1) amber-phone; urgency=medium * Read machine-specific configuration files * Add libmachine-check subproject * Check the machine name against a whitelist/blacklist -- Bob Ham Wed, 06 Nov 2019 09:41:16 +0000 wys (0.1.0) purple; urgency=medium * Instantiate/deinstantiate PulseAudio loopback modules * wys-audio: Remove extraneous debugging output * wys-audio: Swap ordering of module instantiation * Release Wys 0.1.0 -- Bob Ham Fri, 20 Sep 2019 13:24:54 +0100 wys (0.0.1) purple; urgency=low * Initial release. -- Bob Ham Thu, 04 Dec 2019 14:01:40 +0000 wys-0.1.11/debian/control000066400000000000000000000015351401542361700152500ustar00rootroot00000000000000Source: wys Section: comm Priority: optional Maintainer: Bob Ham Build-Depends: debhelper-compat (= 12), dh-exec, libglib2.0-dev, libmm-glib-dev, libpulse-dev, meson, Standards-Version: 4.1.3 Homepage: https://source.puri.sm/Librem5/wys Package: wys Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, pulseaudio (>= 12.2-4+deb10u1pureos+librem5.1), Recommends: modemmanager Description: A daemon to start/stop PulseAudio loopbacks for phone call audio During a phone call, audio must be streamed from one ALSA device to another ALSA device. This should only happen during the call, when the modem's audio interfaces will actually be active. To facilitate this, Wys will wait for ModemManager calls in the ringing or active state and enable appropriate PulseAudio loopback modules only during those states. wys-0.1.11/debian/copyright000066400000000000000000000016771401542361700156070ustar00rootroot00000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: wys Source: https://source.puri.sm/Librem5/wys Files: * Copyright: 2018, 2019 Purism SPC License: GPL-3+ This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. . This package 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, see . On Debian systems, the complete text of the GNU General Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". wys-0.1.11/debian/gbp.conf000066400000000000000000000003401401542361700152550ustar00rootroot00000000000000[DEFAULT] debian-branch = master debian-tag = v%(version)s debian-tag-msg = %(pkg)s v%(version)s [tag] sign-tags = true [dch] postedit = sed -i s"@^\( \+version\s\+: '\)[0-9.]\+\(',\)@\1$GBP_DEBIAN_VERSION\2@" meson.build wys-0.1.11/debian/rules000077500000000000000000000004121401542361700147160ustar00rootroot00000000000000#!/usr/bin/make -f export DEB_BUILD_MAINT_OPTIONS = hardening=+all %: dh $@ --builddirectory=_build override_dh_link: dh_link ifeq ($(DEB_HOST_ARCH_OS),linux) dh_link usr/lib/systemd/user/wys.service usr/lib/systemd/user/default.target.wants/wys.service endif wys-0.1.11/debian/source/000077500000000000000000000000001401542361700151415ustar00rootroot00000000000000wys-0.1.11/debian/source/format000066400000000000000000000000151401542361700163500ustar00rootroot000000000000003.0 (native) wys-0.1.11/debian/wys.install000077500000000000000000000001351401542361700160550ustar00rootroot00000000000000#!/usr/bin/dh-exec [linux-any] debian/wys.user-service => /usr/lib/systemd/user/wys.service wys-0.1.11/debian/wys.user-service000066400000000000000000000013501401542361700170200ustar00rootroot00000000000000[Unit] Description=Wys, a daemon for voice call audio # Don't stop restarting the program StartLimitIntervalSec=0 # We need PulseAudio Requires=pulseaudio.service [Service] # Execution will fail unless (1) the --modem command-line # option is given with appropriate ALSA card name, (2) the # WYS_MODEM environment variables is set, or (3) the # current machine is present in a machine-conf database under # /usr/share/wys, /etc/wys, $HOME/.config/wys, etc. # # Environment variable can be set elsewhere, for example adding a # wys.service.d/my-hardware.conf containing the following: # # [Service] # Environment=WYS_MODEM="SIMCom SIM7100" # ExecStart=/usr/bin/wys Restart=on-failure RestartSec=500ms [Install] WantedBy=default.target wys-0.1.11/meson.build000066400000000000000000000034511401542361700145640ustar00rootroot00000000000000# # Copyright (C) 2019 Purism SPC # # This file is part of Wys. # # Wys is free software: you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your # option) any later version. # # Wys 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 Wys. If not, see . # # SPDX-License-Identifier: GPL-3.0-or-later # project ( 'wys', 'c', version : '0.1.11', license : 'GPLv3+', meson_version : '>= 0.42.0', default_options : [ 'warning_level=1', 'buildtype=debugoptimized', 'c_std=gnu11' ], ) libmchk_proj = subproject('libmachine-check') libmchk_dep = libmchk_proj.get_variable('libmachine_check_dep') app_name = meson.project_name() prefix = get_option('prefix') datadir = get_option('datadir') sysconfdir = get_option('sysconfdir') if datadir.startswith('/') full_datadir = datadir else full_datadir = join_paths(prefix, datadir) endif if sysconfdir.startswith('/') full_sysconfdir = sysconfdir else full_sysconfdir = join_paths(prefix, sysconfdir) endif config_data = configuration_data() config_data.set_quoted('APP_DATA_NAME', app_name) config_data.set_quoted('DATADIR', full_datadir) config_data.set_quoted('SYSCONFDIR', full_sysconfdir) subdir('src') install_subdir ( 'machine-conf', install_dir : join_paths(datadir, app_name) ) install_subdir ( 'machine-check', install_dir : join_paths(datadir, 'machine-check', app_name), strip_directory : true ) wys-0.1.11/src/000077500000000000000000000000001401542361700132065ustar00rootroot00000000000000wys-0.1.11/src/main.c000066400000000000000000000352511401542361700143040ustar00rootroot00000000000000/* * Copyright (C) 2019 Purism SPC * * This file is part of Wys. * * Wys is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Wys 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 Wys. If not, see . * * Author: Bob Ham * * SPDX-License-Identifier: GPL-3.0-or-later * */ #include "wys-modem.h" #include "wys-audio.h" #include "util.h" #include "config.h" #include "mchk-machine-check.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #define TTY_CHUNK_SIZE 320 #define SAMPLE_LEN 2 static GMainLoop *main_loop = NULL; struct wys_data { /** PulseAudio interface */ WysAudio *audio; /** ID for the D-Bus watch */ guint watch_id; /** ModemManager object proxy */ MMManager *mm; /** Map of D-Bus object paths to WysModems */ GHashTable *modems; /** How many modems have audio, in each direction */ guint audio_count[2]; }; static void update_audio_count (struct wys_data *data, WysDirection direction, gint delta) { const guint old_count = data->audio_count[direction]; g_assert (delta >= 0 || data->audio_count[direction] > 0); data->audio_count[direction] += delta; if (data->audio_count[direction] > 0 && old_count == 0) { g_debug ("Audio %s now present", wys_direction_get_description (direction)); wys_audio_ensure_loopback (data->audio, direction); } else if (data->audio_count[direction] == 0 && old_count > 0) { g_debug ("Audio %s now absent", wys_direction_get_description (direction)); wys_audio_ensure_no_loopback (data->audio, direction); } } static void audio_present_cb (struct wys_data *data, WysDirection direction, WysModem *modem) { update_audio_count (data, direction, +1); } static void audio_absent_cb (struct wys_data *data, WysDirection direction, WysModem *modem) { update_audio_count (data, direction, -1); } static void add_modem (struct wys_data *data, GDBusObject *object) { const gchar *path; MMModemVoice *voice; WysModem *modem; path = g_dbus_object_get_object_path (object); if (g_hash_table_contains (data->modems, path)) { g_warning ("New voice interface on existing" " modem with path `%s'", path); return; } g_debug ("Adding new voice-capable modem `%s'", path); g_assert (MM_IS_OBJECT (object)); voice = mm_object_get_modem_voice (MM_OBJECT (object)); g_assert (voice != NULL); modem = wys_modem_new (voice); g_hash_table_insert (data->modems, strdup (path), modem); g_signal_connect_swapped (modem, "audio-present", G_CALLBACK (audio_present_cb), data); g_signal_connect_swapped (modem, "audio-absent", G_CALLBACK (audio_absent_cb), data); } static void interface_added_cb (struct wys_data *data, GDBusObject *object, GDBusInterface *interface) { GDBusInterfaceInfo *info; info = g_dbus_interface_get_info (interface); g_debug ("ModemManager interface `%s' found on object `%s'", info->name, g_dbus_object_get_object_path (object)); if (g_strcmp0 (info->name, MM_DBUS_INTERFACE_MODEM_VOICE) == 0) { add_modem (data, object); } } static void remove_modem_object (struct wys_data *data, const gchar *path, GDBusObject *object) { g_hash_table_remove (data->modems, path); } static void interface_removed_cb (struct wys_data *data, GDBusObject *object, GDBusInterface *interface) { const gchar *path; GDBusInterfaceInfo *info; path = g_dbus_object_get_object_path (object); info = g_dbus_interface_get_info (interface); g_debug ("ModemManager interface `%s' removed on object `%s'", info->name, path); if (g_strcmp0 (info->name, MM_DBUS_INTERFACE_MODEM_VOICE) == 0) { remove_modem_object (data, path, object); } } static void add_mm_object (struct wys_data *data, GDBusObject *object) { GList *ifaces, *node; ifaces = g_dbus_object_get_interfaces (object); for (node = ifaces; node; node = node->next) { interface_added_cb (data, object, G_DBUS_INTERFACE (node->data)); } g_list_free_full (ifaces, g_object_unref); } static void add_mm_objects (struct wys_data *data) { GList *objects, *node; objects = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (data->mm)); for (node = objects; node; node = node->next) { add_mm_object (data, G_DBUS_OBJECT (node->data)); } g_list_free_full (objects, g_object_unref); } void object_added_cb (struct wys_data *data, GDBusObject *object) { g_debug ("ModemManager object `%s' added", g_dbus_object_get_object_path (object)); add_mm_object (data, object); } void object_removed_cb (struct wys_data *data, GDBusObject *object) { const gchar *path; path = g_dbus_object_get_object_path (object); g_debug ("ModemManager object `%s' removed", path); remove_modem_object (data, path, object); } static void mm_manager_new_cb (GDBusConnection *connection, GAsyncResult *res, struct wys_data *data) { GError *error = NULL; data->mm = mm_manager_new_finish (res, &error); if (!data->mm) { wys_error ("Error creating ModemManager Manager: %s", error->message); } g_signal_connect_swapped (G_DBUS_OBJECT_MANAGER (data->mm), "interface-added", G_CALLBACK (interface_added_cb), data); g_signal_connect_swapped (G_DBUS_OBJECT_MANAGER (data->mm), "interface-removed", G_CALLBACK (interface_removed_cb), data); g_signal_connect_swapped (G_DBUS_OBJECT_MANAGER (data->mm), "object-added", G_CALLBACK (object_added_cb), data); g_signal_connect_swapped (G_DBUS_OBJECT_MANAGER (data->mm), "object-removed", G_CALLBACK (object_removed_cb), data); add_mm_objects (data); } static void mm_appeared_cb (GDBusConnection *connection, const gchar *name, const gchar *name_owner, struct wys_data *data) { g_debug ("ModemManager appeared on D-Bus"); mm_manager_new (connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, NULL, (GAsyncReadyCallback) mm_manager_new_cb, data); } static void clear_dbus (struct wys_data *data) { g_hash_table_remove_all (data->modems); g_clear_object (&data->mm); } void mm_vanished_cb (GDBusConnection *connection, const gchar *name, struct wys_data *data) { g_debug ("ModemManager vanished from D-Bus"); clear_dbus (data); } static void set_up (struct wys_data *data, const gchar *modem) { data->audio = wys_audio_new (modem); data->modems = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); data->watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM, MM_DBUS_SERVICE, G_BUS_NAME_WATCHER_FLAGS_AUTO_START, (GBusNameAppearedCallback)mm_appeared_cb, (GBusNameVanishedCallback)mm_vanished_cb, data, NULL); g_debug ("Watching for ModemManager"); } static void tear_down (struct wys_data *data) { clear_dbus (data); g_bus_unwatch_name (data->watch_id); g_hash_table_unref (data->modems); g_object_unref (G_OBJECT (data->audio)); } static void run (const gchar *modem) { struct wys_data data; memset (&data, 0, sizeof (struct wys_data)); set_up (&data, modem); main_loop = g_main_loop_new (NULL, FALSE); printf (APPLICATION_NAME " started with modem `%s'\n", modem ? modem : "(none)"); g_main_loop_run (main_loop); g_main_loop_unref (main_loop); main_loop = NULL; tear_down (&data); } static void check_machine (const gchar *machine) { gboolean ok, passed; GError *error = NULL; ok = mchk_check_machine (APP_DATA_NAME, machine, &passed, &error); if (!ok) { g_warning ("Error checking machine name against" " whitelist/blacklist, continuing anyway"); g_error_free (error); } else if (!passed) { g_message ("Machine name `%s' did not pass" " whitelist/blacklist check, exiting", machine); exit (EXIT_SUCCESS); } } static void terminate (int signal) { if (main_loop) { g_main_loop_quit (main_loop); } } /** Ignore signals which make systemd refrain from restarting us due * to "Restart=on-failure": SIGHUP, SIGINT, and SIGPIPE. */ static void setup_signals () { void (*ret)(int); #define try_setup(NUM,handler) \ ret = signal (SIG##NUM, handler); \ if (ret == SIG_ERR) \ { \ g_error ("Error setting signal handler: %s", \ g_strerror (errno)); \ } try_setup (HUP, SIG_IGN); try_setup (INT, SIG_IGN); try_setup (PIPE, SIG_IGN); try_setup (TERM, terminate); #undef try_setup } /** This function will close @fd */ static gchar * read_machine_conf_file (const gchar *filename, int fd) { GInputStream *unix_stream; GDataInputStream *data_stream; gboolean try_again; gchar *line; GError *error = NULL; g_debug ("Reading machine configuration file `%s'", filename); unix_stream = g_unix_input_stream_new (fd, TRUE); g_assert (unix_stream != NULL); data_stream = g_data_input_stream_new (unix_stream); g_assert (data_stream != NULL); g_object_unref (unix_stream); do { try_again = FALSE; line = g_data_input_stream_read_line_utf8 (data_stream, NULL, NULL, &error); if (error) { g_warning ("Error reading from machine" " configuration file `%s': %s", filename, error->message); g_error_free (error); } else if (line) { g_strstrip (line); // Skip comments and empty lines if (line[0] == '#' || line[0] == '\0') { g_free (line); try_again = TRUE; } } } while (try_again); g_object_unref (data_stream); return line; } static gchar * dir_machine_conf (const gchar *dir, const gchar *machine, const gchar *key) { gchar *filename; int fd; gchar *value = NULL; filename = g_build_filename (dir, APP_DATA_NAME, "machine-conf", machine, key, NULL); g_debug ("Trying machine configuration file `%s'", filename); fd = g_open (filename, O_RDONLY, 0); if (fd == -1) { if (errno != ENOENT) { // The error isn't that the file doesn't exist g_warning ("Error opening machine" " configuration file `%s': %s", filename, g_strerror (errno)); } } else { value = read_machine_conf_file (filename, fd); } g_free (filename); return value; } static gchar * machine_conf (const gchar *machine, const gchar *key) { gchar *value = NULL; const gchar * const *dirs, * const *dir; #define try_dir(d) \ value = dir_machine_conf (d, machine, key); \ if (value) \ { \ return value; \ } try_dir (g_get_user_config_dir ()); dirs = g_get_system_config_dirs (); for (dir = dirs; *dir; ++dir) { try_dir (*dir); } try_dir (SYSCONFDIR); try_dir (DATADIR); dirs = g_get_system_data_dirs (); for (dir = dirs; *dir; ++dir) { try_dir (*dir); } #undef try_dir return NULL; } static void ensure_alsa_card (const gchar *machine, const gchar *var, const gchar *key, gchar **name) { const gchar *env; if (*name) { return; } env = g_getenv (var); if (env) { *name = g_strdup (env); return; } if (machine) { *name = machine_conf (machine, key); if (*name) { return; } } g_debug ("No predefined modem found, detecting dynamically."); } int main (int argc, char **argv) { GError *error = NULL; GOptionContext *context; gboolean ok; g_autofree gchar *modem = NULL; g_autofree gchar *machine = NULL; GOptionEntry options[] = { { "modem", 'm', 0, G_OPTION_ARG_STRING, &modem, "Name of the modem's ALSA card", "NAME" }, { NULL } }; setlocale(LC_ALL, ""); machine = mchk_read_machine (NULL); if (machine) { check_machine (machine); } else { g_warning ("Could not read machine name, continuing without machine check"); } context = g_option_context_new ("- set up PulseAudio loopback for phone call audio"); g_option_context_add_main_entries (context, options, NULL); ok = g_option_context_parse (context, &argc, &argv, &error); if (!ok) { g_print ("Error parsing options: %s\n", error->message); } if (machine) { /* Convert any directory separator characters to "_" */ g_strdelimit (machine, G_DIR_SEPARATOR_S, '_'); } ensure_alsa_card (machine, "WYS_MODEM", "modem", &modem); setup_signals (); run (modem); return 0; } wys-0.1.11/src/meson.build000066400000000000000000000027551401542361700153610ustar00rootroot00000000000000# # Copyright (C) 2019 Purism SPC # # This file is part of Wys. # # Wys is free software: you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your # option) any later version. # # Wys 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 Wys. If not, see . # # SPDX-License-Identifier: GPL-3.0-or-later # gnome = import('gnome') wys_deps = [ libmchk_dep, dependency('gobject-2.0'), dependency('gio-unix-2.0'), dependency('ModemManager'), dependency('mm-glib'), dependency('libpulse'), dependency('libpulse-mainloop-glib'), ] config_h = configure_file ( output: 'config.h', configuration: config_data ) wys_enum_headers = files(['wys-direction.h']) wys_enum_sources = gnome.mkenums_simple('enum-types', sources : wys_enum_headers) executable ( 'wys', config_h, wys_enum_sources, [ 'main.c', 'util.h', 'util.c', 'wys-direction.h', 'wys-direction.c', 'wys-modem.h', 'wys-modem.c', 'wys-audio.h', 'wys-audio.c', ], dependencies : wys_deps, include_directories : include_directories('..'), install : true ) wys-0.1.11/src/util.c000066400000000000000000000017761401542361700143420ustar00rootroot00000000000000/* * Copyright (C) 2019 Purism SPC * * This file is part of Wys. * * Wys is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Wys 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 Wys. If not, see . * * Author: Bob Ham * * SPDX-License-Identifier: GPL-3.0-or-later * */ #include #include #include void wys_error (const gchar *format, ...) { va_list ap; va_start (ap, format); g_logv (NULL, G_LOG_LEVEL_CRITICAL, format, ap); va_end (ap); exit (EXIT_FAILURE); } wys-0.1.11/src/util.h000066400000000000000000000017711401542361700143420ustar00rootroot00000000000000/* * Copyright (C) 2019 Purism SPC * * This file is part of Wys. * * Wys is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Wys 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 Wys. If not, see . * * Author: Bob Ham * * SPDX-License-Identifier: GPL-3.0-or-later * */ #ifndef WYS_UTIL_H__ #define WYS_UTIL_H__ #include #define APPLICATION_NAME "Wys" #define APPLICATION_ID "sm.puri.Wys" G_BEGIN_DECLS void wys_error (const gchar *format, ...); G_END_DECLS #endif /* WYS_UTIL_H__ */ wys-0.1.11/src/wys-audio.c000066400000000000000000001137521401542361700153040ustar00rootroot00000000000000/* * copyright (C) 2018, 2019 Purism SPC * * This file is part of Wys. * * Wys is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Wys 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 Wys. If not, see . * * Author: Bob Ham * * SPDX-License-Identifier: GPL-3.0-or-later * */ #include "wys-audio.h" #include "util.h" #include #include #include #include struct _WysAudio { GObject parent_instance; gchar *modem; pa_glib_mainloop *loop; pa_context *ctx; gboolean ready; }; G_DEFINE_TYPE (WysAudio, wys_audio, G_TYPE_OBJECT); enum { PROP_0, PROP_MODEM, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; static void proplist_set (pa_proplist *props, const char *key, const char *value) { int err = pa_proplist_sets (props, key, value); if (err != 0) { wys_error ("Error setting PulseAudio property list" " property: %s", pa_strerror (err)); } } static void get_card_info_cb (pa_context *audio, const pa_card_info *info, int is_last, void *userdata) { WysAudio *self = WYS_AUDIO (userdata); const char *class, *alsa_card; if (is_last < 0) { g_warning ("Failed to get card information: %s", pa_strerror (pa_context_errno (self->ctx))); return; } if (is_last) return; class = pa_proplist_gets (info->proplist, "device.class"); if (g_strcmp0 (class, "modem")) return; alsa_card = pa_proplist_gets (info->proplist, "alsa.card_name"); if (!alsa_card) return; g_debug ("Found card '%s', alsa: '%s'", info->name, alsa_card); self->modem = g_strdup (alsa_card); } static void context_notify_cb (pa_context *audio, WysAudio *self) { pa_context_state_t audio_state; pa_operation *op; audio_state = pa_context_get_state (audio); switch (audio_state) { case PA_CONTEXT_UNCONNECTED: case PA_CONTEXT_CONNECTING: case PA_CONTEXT_AUTHORIZING: case PA_CONTEXT_SETTING_NAME: self->ready = FALSE; break; case PA_CONTEXT_FAILED: wys_error ("Error in PulseAudio context: %s", pa_strerror (pa_context_errno (audio))); break; case PA_CONTEXT_TERMINATED: case PA_CONTEXT_READY: self->ready = TRUE; /* Find modem if there's none already */ if (!self->modem) { op = pa_context_get_card_info_list(self->ctx, get_card_info_cb, self); if (op) pa_operation_unref(op); } break; } } static void set_up_audio_context (WysAudio *self) { pa_proplist *props; int err; /* Meta data */ props = pa_proplist_new (); g_assert (props != NULL); proplist_set (props, PA_PROP_APPLICATION_NAME, APPLICATION_NAME); proplist_set (props, PA_PROP_APPLICATION_ID, APPLICATION_ID); self->loop = pa_glib_mainloop_new (NULL); if (!self->loop) { wys_error ("Error creating PulseAudio main loop"); } self->ctx = pa_context_new_with_proplist (pa_glib_mainloop_get_api (self->loop), APPLICATION_NAME, props); if (!self->ctx) { wys_error ("Error creating PulseAudio context"); } pa_context_set_state_callback (self->ctx, (pa_context_notify_cb_t)context_notify_cb, self); err = pa_context_connect(self->ctx, NULL, PA_CONTEXT_NOFAIL, 0); if (err < 0) { wys_error ("Error connecting PulseAudio context: %s", pa_strerror (err)); } while (!self->ready) { g_main_context_iteration (NULL, TRUE); } pa_context_set_state_callback (self->ctx, NULL, NULL); pa_proplist_free (props); } static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { WysAudio *self = WYS_AUDIO (object); switch (property_id) { case PROP_MODEM: self->modem = g_value_dup_string (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void constructed (GObject *object) { GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT); WysAudio *self = WYS_AUDIO (object); set_up_audio_context (self); parent_class->constructed (object); } static void dispose (GObject *object) { GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT); WysAudio *self = WYS_AUDIO (object); if (self->ctx) { pa_context_disconnect (self->ctx); pa_context_unref (self->ctx); self->ctx = NULL; pa_glib_mainloop_free (self->loop); self->loop = NULL; } parent_class->dispose (object); } static void finalize (GObject *object) { GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT); WysAudio *self = WYS_AUDIO (object); g_free (self->modem); parent_class->finalize (object); } static void wys_audio_class_init (WysAudioClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = set_property; object_class->constructed = constructed; object_class->dispose = dispose; object_class->finalize = finalize; props[PROP_MODEM] = g_param_spec_string ("modem", _("Modem"), _("The ALSA card name for the modem"), NULL, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void wys_audio_init (WysAudio *self) { } WysAudio * wys_audio_new (const gchar *modem) { return g_object_new (WYS_TYPE_AUDIO, "modem", modem, NULL); } /**************** Get single info ****************/ struct callback_data { GCallback callback; gpointer userdata; }; #define GET_SINGLE_INFO_CALLBACK(SingleInfo, single_info) \ typedef void (*Get##SingleInfo##Callback) \ (pa_context *ctx, \ const pa_##single_info##_info *info, \ gpointer userdata); #define GET_SINGLE_INFO_CB(SingleInfo, single_info) \ static void \ get_##single_info##_cb (pa_context *ctx, \ const pa_##single_info##_info *info, \ int eol, \ void *userdata) \ { \ struct callback_data *data = userdata; \ Get##SingleInfo##Callback func; \ \ if (eol == -1) \ { \ wys_error ("Error getting PulseAudio " \ #single_info ": %s", \ pa_strerror (pa_context_errno (ctx))); \ } \ \ if (eol) \ { \ if (data->callback) \ { \ func = (Get##SingleInfo##Callback)data->callback; \ func (ctx, NULL, data->userdata); \ } \ \ g_free (data); \ return; \ } \ \ g_assert (info != NULL); \ \ /* We should only be called once with data */ \ g_assert (data->callback != NULL); \ \ func = (Get##SingleInfo##Callback)data->callback; \ func (ctx, info, data->userdata); \ \ data->callback = NULL; \ } #define GET_SINGLE_INFO(single_info, single_info_func) \ static void \ get_##single_info (pa_context *ctx, \ uint32_t index, \ GCallback callback, \ gpointer userdata) \ { \ pa_operation *op; \ struct callback_data *data; \ \ data = g_new (struct callback_data, 1); \ data->callback = callback; \ data->userdata = userdata; \ \ op = pa_context_get_##single_info_func \ (ctx, \ index, \ get_##single_info##_cb, \ data); \ \ pa_operation_unref (op); \ } #define DECLARE_GET_SINGLE_INFO(SingleInfo, single_info, single_info_func) \ GET_SINGLE_INFO_CALLBACK(SingleInfo, single_info) \ GET_SINGLE_INFO_CB(SingleInfo, single_info) \ GET_SINGLE_INFO(single_info, single_info_func) DECLARE_GET_SINGLE_INFO(Source, source, source_info_by_index); DECLARE_GET_SINGLE_INFO(Module, module, module_info); DECLARE_GET_SINGLE_INFO(Sink, sink, sink_info_by_index); /**************** PulseAudio properties ****************/ static gboolean prop_matches (pa_proplist *props, const gchar *key, const gchar *needle) { const char *value; value = pa_proplist_gets (props, key); if (!value) { return FALSE; } return strcmp (value, needle) == 0; } static gboolean props_name_alsa_card (pa_proplist *props, const gchar *alsa_card) { #define check(key,val) \ if (!prop_matches (props, key, val)) \ { \ return FALSE; \ } check ("device.class", "sound"); check ("device.api", "alsa"); check ("alsa.card_name", alsa_card); #undef check return TRUE; } /**************** Find loopback data ****************/ typedef void (*FindLoopbackCallback) (gchar *alsa_card, WysDirection direction, GList *modules, gpointer userdata); struct find_loopback_data { gchar *alsa_card; WysDirection direction; GCallback callback; gpointer userdata; GList *modules; }; static struct find_loopback_data * find_loopback_data_new (const gchar *alsa_card, WysDirection direction) { struct find_loopback_data *data; data = g_rc_box_new0 (struct find_loopback_data); data->alsa_card = g_strdup (alsa_card); data->direction = direction; return data; } static void find_loopback_data_clear (struct find_loopback_data *data) { FindLoopbackCallback func = (FindLoopbackCallback)data->callback; func (data->alsa_card, data->direction, data->modules, data->userdata); g_list_free (data->modules); g_free (data->alsa_card); } static inline void find_loopback_data_release (struct find_loopback_data *data) { g_rc_box_release_full (data, (GDestroyNotify)find_loopback_data_clear); } /**************** Loopback module data ****************/ struct loopback_module_data { struct find_loopback_data *loopback_data; uint32_t module_index; }; static struct loopback_module_data * loopback_module_data_new (struct find_loopback_data *loopback_data, uint32_t module_index) { struct loopback_module_data * module_data; module_data = g_rc_box_new0 (struct loopback_module_data); module_data->module_index = module_index; g_rc_box_acquire (loopback_data); module_data->loopback_data = loopback_data; return module_data; } static inline void loopback_module_data_clear (struct loopback_module_data *module_data) { find_loopback_data_release (module_data->loopback_data); } static inline void loopback_module_data_release (struct loopback_module_data *module_data) { g_rc_box_release_full (module_data, (GDestroyNotify)loopback_module_data_clear); } /**************** Module ****************/ static void find_loopback_get_module_cb (pa_context *ctx, const pa_module_info *info, struct loopback_module_data *module_data) { struct find_loopback_data *loopback_data = module_data->loopback_data; if (!info) { g_warning ("Could not get module %" PRIu32 " for ALSA card `%s' %s", module_data->module_index, loopback_data->alsa_card, loopback_data->direction == WYS_DIRECTION_FROM_NETWORK ? "source output" : "sink input"); loopback_module_data_release (module_data); return; } if (strcmp (info->name, "module-loopback") != 0) { g_debug ("Module %" PRIu32 " for ALSA card `%s` %s" " is not a loopback module", info->index, loopback_data->alsa_card, loopback_data->direction == WYS_DIRECTION_FROM_NETWORK ? "source output" : "sink input"); loopback_module_data_release (module_data); return; } g_debug ("Module %" PRIu32 " for ALSA card `%s' %s is a" " loopback module", info->index, loopback_data->alsa_card, loopback_data->direction == WYS_DIRECTION_FROM_NETWORK ? "source output" : "sink input"); loopback_data->modules = g_list_append (loopback_data->modules, GUINT_TO_POINTER (module_data->module_index)); loopback_module_data_release (module_data); } /**************** Sink ****************/ static void find_loopback_get_sink_cb (pa_context *ctx, const pa_sink_info *info, struct loopback_module_data *module_data) { struct find_loopback_data *loopback_data = module_data->loopback_data; if (!info) { g_warning ("Couldn't find sink for sink input" " while finding ALSA card `%s' sink", loopback_data->alsa_card); loopback_module_data_release (module_data); return; } if (!props_name_alsa_card (info->proplist, loopback_data->alsa_card)) { g_debug ("Sink %" PRIu32 " `%s' is not ALSA card `%s'", info->index, info->name, loopback_data->alsa_card); loopback_module_data_release (module_data); return; } g_debug ("Checking whether module %" PRIu32 " for ALSA card `%s' sink input" " is a loopback module", module_data->module_index, loopback_data->alsa_card); get_module (ctx, module_data->module_index, G_CALLBACK (find_loopback_get_module_cb), module_data); } /**************** Sink input list ****************/ static void find_loopback_sink_input_list_cb (pa_context *ctx, const pa_sink_input_info *info, int eol, void *userdata) { struct find_loopback_data *loopback_data = userdata; struct loopback_module_data *module_data; if (eol == -1) { wys_error ("Error listing PulseAudio source outputs: %s", pa_strerror (pa_context_errno (ctx))); } if (eol) { g_debug ("End of sink input list reached"); find_loopback_data_release (loopback_data); return; } if (info->owner_module == PA_INVALID_INDEX) { g_debug ("Sink input %" PRIu32 " `%s'" " is not owned by a module", info->index, info->name); return; } module_data = loopback_module_data_new (loopback_data, info->owner_module); g_debug ("Getting sink %" PRIu32 " of sink input %" PRIu32 " `%s'", info->sink, info->index, info->name); get_sink (ctx, info->sink, G_CALLBACK (find_loopback_get_sink_cb), module_data); } /**************** Source ****************/ static void find_loopback_get_source_cb (pa_context *ctx, const pa_source_info *info, struct loopback_module_data *module_data) { struct find_loopback_data *loopback_data = module_data->loopback_data; if (!info) { g_warning ("Couldn't find source for source output" " while finding ALSA card `%s' source", loopback_data->alsa_card); loopback_module_data_release (module_data); return; } if (!props_name_alsa_card (info->proplist, loopback_data->alsa_card)) { g_debug ("Source %" PRIu32 " `%s' is not ALSA card `%s'", info->index, info->name, loopback_data->alsa_card); loopback_module_data_release (module_data); return; } g_debug ("Checking whether module %" PRIu32 " for ALSA card `%s' source output" " is a loopback module", module_data->module_index, loopback_data->alsa_card); get_module (ctx, module_data->module_index, G_CALLBACK (find_loopback_get_module_cb), module_data); } /**************** Find loopback (source output list) ****************/ static void find_loopback_source_output_list_cb (pa_context *ctx, const pa_source_output_info *info, int eol, void *userdata) { struct find_loopback_data *loopback_data = userdata; struct loopback_module_data *module_data; if (eol == -1) { wys_error ("Error listing PulseAudio source outputs: %s", pa_strerror (pa_context_errno (ctx))); } if (eol) { g_debug ("End of source output list reached"); find_loopback_data_release (loopback_data); return; } if (info->owner_module == PA_INVALID_INDEX) { g_debug ("Source output %" PRIu32 " `%s'" " is not owned by a module", info->index, info->name); return; } module_data = loopback_module_data_new (loopback_data, info->owner_module); g_debug ("Getting source %" PRIu32 " of source output %" PRIu32 " `%s'", info->source, info->index, info->name); get_source (ctx, info->source, G_CALLBACK (find_loopback_get_source_cb), module_data); } /** Find any loopback module for the specified source or sink alsa card. 1. Loop through all source outputs / sink outputs. 1. Skip any source output / sink input that doesn't have the specified alsa card as its source. 2. Skip any source output / sink input that isn't a loopback module. 3. Found a loopback. */ static void find_loopback (pa_context *ctx, const gchar *alsa_card, WysDirection direction, GCallback callback, gpointer userdata) { struct find_loopback_data *data; pa_operation *op; data = find_loopback_data_new (alsa_card, direction); data->callback = callback; data->userdata = userdata; switch (direction) { case WYS_DIRECTION_FROM_NETWORK: g_debug ("Finding ALSA card `%s' source output", alsa_card); op = pa_context_get_source_output_info_list (ctx, find_loopback_source_output_list_cb, data); pa_operation_unref (op); break; case WYS_DIRECTION_TO_NETWORK: g_debug ("Finding ALSA card `%s' sink input", alsa_card); op = pa_context_get_sink_input_info_list (ctx, find_loopback_sink_input_list_cb, data); pa_operation_unref (op); break; default: break; } } /**************** Find ALSA card data ****************/ typedef void (*FindALSACardCallback) (const gchar *alsa_card_name, const gchar *pulse_object_name, gpointer userdata); struct find_alsa_card_data { gchar *alsa_card_name; GCallback callback; gpointer userdata; gchar *pulse_object_name; }; static struct find_alsa_card_data * find_alsa_card_data_new (const gchar *alsa_card_name) { struct find_alsa_card_data *data; data = g_rc_box_new0 (struct find_alsa_card_data); data->alsa_card_name = g_strdup (alsa_card_name); return data; } static void find_alsa_card_data_clear (struct find_alsa_card_data *data) { FindALSACardCallback func = (FindALSACardCallback)data->callback; func (data->alsa_card_name, data->pulse_object_name, data->userdata); g_free (data->pulse_object_name); g_free (data->alsa_card_name); } static inline void find_alsa_card_data_release (struct find_alsa_card_data *data) { g_rc_box_release_full (data, (GDestroyNotify)find_alsa_card_data_clear); } /**************** Find ALSA card ****************/ #define FIND_ALSA_CARD_LIST_CB(object_type) \ static void \ find_alsa_card_##object_type##list_cb \ (pa_context *ctx, \ const pa_##object_type##_info *info, \ int eol, \ void *userdata) \ { \ struct find_alsa_card_data *alsa_card_data = userdata; \ \ if (eol == -1) \ { \ wys_error ("Error listing PulseAudio " #object_type "s: %s", \ pa_strerror (pa_context_errno (ctx))); \ } \ \ if (eol) \ { \ g_debug ("End of " #object_type " list reached"); \ find_alsa_card_data_release (alsa_card_data); \ return; \ } \ \ if (alsa_card_data->pulse_object_name != NULL) \ { \ /* Already found our object */ \ g_debug ("Skipping " #object_type \ " %" PRIu32 " `%s'", \ info->index, info->name); \ return; \ } \ \ g_assert (info != NULL); \ \ if (!props_name_alsa_card (info->proplist, \ alsa_card_data->alsa_card_name)) \ { \ g_debug ("The " #object_type " %" PRIu32 \ " `%s' is not ALSA card `%s'", \ info->index, \ info->name, \ alsa_card_data->alsa_card_name); \ return; \ } \ \ g_debug ("The " #object_type " %" PRIu32 \ " `%s' is ALSA card `%s'", \ info->index, \ info->name, \ alsa_card_data->alsa_card_name); \ alsa_card_data->pulse_object_name = g_strdup (info->name); \ } #define FIND_ALSA_CARD(object_type) \ static void \ find_alsa_card_##object_type (pa_context *ctx, \ const gchar *alsa_card_name, \ GCallback callback, \ gpointer userdata) \ { \ pa_operation *op; \ struct find_alsa_card_data *data; \ \ data = find_alsa_card_data_new (alsa_card_name); \ data->callback = callback; \ data->userdata = userdata; \ \ op = pa_context_get_##object_type##_info_list \ (ctx, find_alsa_card_##object_type##list_cb, data); \ \ pa_operation_unref (op); \ } #define DECLARE_FIND_ALSA_CARD(object_type) \ FIND_ALSA_CARD_LIST_CB(object_type) \ FIND_ALSA_CARD(object_type) DECLARE_FIND_ALSA_CARD(source); DECLARE_FIND_ALSA_CARD(sink); /**************** Instantiate loopback data ****************/ typedef void (*InstantiateLoopbackCallback) (gchar *alsa_card, WysDirection direction, gchar *master, gpointer userdata); struct instantiate_loopback_data { pa_context *ctx; gchar *alsa_card; WysDirection direction; gchar *media_name; gchar *master; }; static struct instantiate_loopback_data * instantiate_loopback_data_new (pa_context *ctx, const gchar *alsa_card, WysDirection direction, const gchar *media_name) { struct instantiate_loopback_data *data; data = g_rc_box_new0 (struct instantiate_loopback_data); pa_context_ref (ctx); data->ctx = ctx; data->alsa_card = g_strdup (alsa_card); data->direction = direction; data->media_name = g_strdup (media_name); return data; } static void instantiate_loopback_data_clear (struct instantiate_loopback_data *data) { g_free (data->master); g_free (data->media_name); g_free (data->alsa_card); pa_context_unref (data->ctx); } static inline void instantiate_loopback_data_release (struct instantiate_loopback_data *data) { g_rc_box_release_full (data, (GDestroyNotify)instantiate_loopback_data_clear); } /**************** Instantiate loopback ****************/ static void instantiate_loopback_load_module_cb (pa_context *ctx, uint32_t index, void *userdata) { struct instantiate_loopback_data *data = userdata; if (index == PA_INVALID_INDEX) { g_warning ("Error instantiating loopback module with %s `%s'" " (ALSA card `%s'): %s", data->direction == WYS_DIRECTION_FROM_NETWORK ? "source" : "sink", data->master, data->alsa_card, pa_strerror (pa_context_errno (ctx))); } else { g_debug ("Instantiated loopback module %" PRIu32 " with %s `%s' (ALSA card `%s')", index, data->direction == WYS_DIRECTION_FROM_NETWORK ? "source" : "sink", data->master, data->alsa_card); } instantiate_loopback_data_release (data); } static void instantiate_loopback_load_module (struct instantiate_loopback_data *data) { pa_proplist *stream_props; gchar *stream_sink_props_str, *stream_source_props_str; gchar *arg; pa_operation *op; g_debug ("Instantiating loopback module with %s `%s'" " (ALSA card `%s')", data->direction == WYS_DIRECTION_FROM_NETWORK ? "source" : "sink", data->master, data->alsa_card); // sink properties stream_props = pa_proplist_new (); g_assert (stream_props != NULL); proplist_set (stream_props, "media.role", "phone"); proplist_set (stream_props, "media.icon_name", "phone"); proplist_set (stream_props, "media.name", data->media_name); if (data->direction == WYS_DIRECTION_FROM_NETWORK) { proplist_set (stream_props, "filter.want", "echo-cancel"); } stream_sink_props_str = pa_proplist_to_string (stream_props); pa_proplist_free (stream_props); // source properties stream_props = pa_proplist_new (); g_assert (stream_props != NULL); proplist_set (stream_props, "media.role", "phone"); proplist_set (stream_props, "media.icon_name", "phone"); proplist_set (stream_props, "media.name", data->media_name); if (data->direction == WYS_DIRECTION_TO_NETWORK) { proplist_set (stream_props, "filter.want", "echo-cancel"); } stream_source_props_str = pa_proplist_to_string (stream_props); pa_proplist_free (stream_props); arg = g_strdup_printf ("%s=%s" " %s_dont_move=true" " fast_adjust_threshold_msec=100" " max_latency_msec=25" " sink_input_properties='%s'" " source_output_properties='%s'", data->direction == WYS_DIRECTION_FROM_NETWORK ? "source" : "sink", data->master, data->direction == WYS_DIRECTION_FROM_NETWORK ? "source" : "sink", stream_sink_props_str, stream_source_props_str); pa_xfree (stream_sink_props_str); pa_xfree (stream_source_props_str); op = pa_context_load_module (data->ctx, "module-loopback", arg, instantiate_loopback_load_module_cb, data); pa_operation_unref (op); g_free (arg); } static void instantiate_loopback_master_cb (const gchar *alsa_card_name, const gchar *pulse_object_name, gpointer userdata) { struct instantiate_loopback_data *data = userdata; if (!pulse_object_name) { g_warning ("Could not find source/sink for ALSA card `%s'", alsa_card_name); instantiate_loopback_data_release (data); return; } data->master = g_strdup (pulse_object_name); instantiate_loopback_load_module (data); } static void instantiate_loopback (pa_context *ctx, const gchar *alsa_card, WysDirection direction, const gchar *media_name) { struct instantiate_loopback_data *loopback_data; loopback_data = instantiate_loopback_data_new (ctx, alsa_card, direction, media_name); switch (direction) { case WYS_DIRECTION_FROM_NETWORK: g_debug ("Finding source for ALSA card `%s'", alsa_card); find_alsa_card_source (ctx, alsa_card, G_CALLBACK (instantiate_loopback_master_cb), loopback_data); break; case WYS_DIRECTION_TO_NETWORK: g_debug ("Finding sink for ALSA card `%s'", alsa_card); find_alsa_card_sink (ctx, alsa_card, G_CALLBACK (instantiate_loopback_master_cb), loopback_data); break; default: break; } } /**************** Ensure loopback ****************/ struct ensure_loopback_data { pa_context *ctx; const gchar *media_name; }; static void ensure_loopback_find_loopback_cb (gchar *alsa_card, WysDirection direction, GList *modules, struct ensure_loopback_data *data) { if (modules != NULL) { g_warning ("%u loopback module(s) for ALSA card `%s' %s ->" " already exist", g_list_length (modules), alsa_card, direction == WYS_DIRECTION_FROM_NETWORK ? "source" : "sink"); } else { g_debug ("Instantiating loopback module for ALSA card `%s' %s", alsa_card, direction == WYS_DIRECTION_FROM_NETWORK ? "source" : "sink"); instantiate_loopback (data->ctx, alsa_card, direction, data->media_name); } g_free (data); } static void ensure_loopback (pa_context *ctx, const gchar *alsa_card, WysDirection direction, const gchar *media_name) { struct ensure_loopback_data *data; data = g_new (struct ensure_loopback_data, 1); data->ctx = ctx; // This is a static string so we don't need a copy data->media_name = media_name; find_loopback (ctx, alsa_card, direction, G_CALLBACK (ensure_loopback_find_loopback_cb), data); } void wys_audio_ensure_loopback (WysAudio *self, WysDirection direction) { g_return_if_fail (WYS_IS_AUDIO (self)); g_return_if_fail (self->modem); switch (direction) { case WYS_DIRECTION_FROM_NETWORK: ensure_loopback (self->ctx, self->modem, direction, "Voice call audio (to speaker)"); break; case WYS_DIRECTION_TO_NETWORK: ensure_loopback (self->ctx, self->modem, direction, "Voice call audio (from mic)"); break; default: break; } } /**************** Ensure no loopback ****************/ static void ensure_no_loopback_unload_module_cb (pa_context *ctx, int success, void *userdata) { const guint module_index = GPOINTER_TO_UINT (userdata); if (success) { g_debug ("Successfully deinstantiated loopback module %u", module_index); } else { g_warning ("Error deinstantiating loopback module %u: %s", module_index, pa_strerror (pa_context_errno (ctx))); } } static void ensure_no_loopback_modules_cb (gpointer data, pa_context *ctx) { const uint32_t module_index = GPOINTER_TO_UINT (data); pa_operation *op; g_debug ("Deinstantiating loopback module %" PRIu32, module_index); op = pa_context_unload_module (ctx, module_index, ensure_no_loopback_unload_module_cb, data); pa_operation_unref (op); } static void ensure_no_loopback_find_loopback_cb (gchar *alsa_card, WysDirection direction, GList *modules, pa_context *ctx) { if (modules == NULL) { g_warning ("No loopback module(s) for ALSA card `%s' %s", alsa_card, direction == WYS_DIRECTION_FROM_NETWORK ? "source" : "sink"); return; } g_debug ("Deinstantiating loopback modules for ALSA card `%s' %s", alsa_card, direction == WYS_DIRECTION_FROM_NETWORK ? "source" : "sink"); g_list_foreach (modules, (GFunc)ensure_no_loopback_modules_cb, ctx); } static void ensure_no_loopback (pa_context *ctx, const gchar *alsa_card, WysDirection direction) { find_loopback (ctx, alsa_card, direction, G_CALLBACK (ensure_no_loopback_find_loopback_cb), ctx); } void wys_audio_ensure_no_loopback (WysAudio *self, WysDirection direction) { g_return_if_fail (WYS_IS_AUDIO (self)); g_return_if_fail (self->modem); ensure_no_loopback (self->ctx, self->modem, direction); } wys-0.1.11/src/wys-audio.h000066400000000000000000000025371401542361700153070ustar00rootroot00000000000000/* * Copyright (C) 2018, 2019 Purism SPC * * This file is part of Wys. * * Wys is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Wys 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 Wys. If not, see . * * Author: Bob Ham * * SPDX-License-Identifier: GPL-3.0-or-later * */ #ifndef WYS_AUDIO_H__ #define WYS_AUDIO_H__ #include "wys-direction.h" #include G_BEGIN_DECLS #define WYS_TYPE_AUDIO (wys_audio_get_type ()) G_DECLARE_FINAL_TYPE (WysAudio, wys_audio, WYS, AUDIO, GObject); WysAudio *wys_audio_new (const gchar *modem); void wys_audio_ensure_loopback (WysAudio *self, WysDirection direction); void wys_audio_ensure_no_loopback (WysAudio *self, WysDirection direction); G_END_DECLS #endif /* WYS_AUDIO_H__ */ wys-0.1.11/src/wys-direction.c000066400000000000000000000020711401542361700161520ustar00rootroot00000000000000/* * Copyright (C) 2019 Purism SPC * * This file is part of Wys. * * Wys is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Wys 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 Wys. If not, see . * * Author: Bob Ham * * SPDX-License-Identifier: GPL-3.0-or-later * */ #include "wys-direction.h" const gchar * wys_direction_get_description (WysDirection direction) { switch (direction) { case WYS_DIRECTION_FROM_NETWORK: return "from network"; case WYS_DIRECTION_TO_NETWORK: return "to network"; default: return NULL; } } wys-0.1.11/src/wys-direction.h000066400000000000000000000020701401542361700161560ustar00rootroot00000000000000/* * Copyright (C) 2019 Purism SPC * * This file is part of Wys. * * Wys is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Wys 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 Wys. If not, see . * * Author: Bob Ham * * SPDX-License-Identifier: GPL-3.0-or-later * */ #ifndef WYS_DIRECTION_H__ #define WYS_DIRECTION_H__ #include G_BEGIN_DECLS typedef enum { WYS_DIRECTION_FROM_NETWORK = 0, WYS_DIRECTION_TO_NETWORK } WysDirection; const gchar *wys_direction_get_description (WysDirection direction); G_END_DECLS #endif /* WYS_DIRECTION_H__ */ wys-0.1.11/src/wys-modem.c000066400000000000000000000325531401542361700153030ustar00rootroot00000000000000/* * Copyright (C) 2018, 2019 Purism SPC * * This file is part of Wys. * * Wys is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Wys 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 Wys. If not, see . * * Author: Bob Ham * * SPDX-License-Identifier: GPL-3.0-or-later * */ #include "wys-modem.h" #include "wys-direction.h" #include "util.h" #include "enum-types.h" #include static const gchar * const WYS_MODEM_HAS_AUDIO[] = { [WYS_DIRECTION_FROM_NETWORK] = "wys-has-audio-from-network", [WYS_DIRECTION_TO_NETWORK] = "wys-has-audio-to-network" }; struct _WysModem { GObject parent_instance; /** ModemManager voice proxy */ MMModemVoice *voice; /** Map of D-Bus object paths to MMCall objects */ GHashTable *calls; /** How many calls have audio, in each direction */ guint audio_count[2]; }; G_DEFINE_TYPE(WysModem, wys_modem, G_TYPE_OBJECT) enum { PROP_0, PROP_VOICE, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; enum { SIGNAL_AUDIO_PRESENT, SIGNAL_AUDIO_ABSENT, SIGNAL_LAST_SIGNAL, }; static guint signals [SIGNAL_LAST_SIGNAL]; static gboolean call_state_has_audio (WysDirection direction, MMCallState state) { switch (state) { case MM_CALL_STATE_RINGING_OUT: return (direction == WYS_DIRECTION_FROM_NETWORK) ? TRUE : FALSE; case MM_CALL_STATE_ACTIVE: return TRUE; default: return FALSE; } } static void update_audio_count (WysModem *self, WysDirection direction, gint delta) { const guint old_count = self->audio_count[direction]; g_assert (delta >= 0 || self->audio_count[direction] > 0); self->audio_count[direction] += delta; if (self->audio_count[direction] > 0 && old_count == 0) { g_debug ("Modem `%s' audio %s now present", mm_modem_voice_get_path (self->voice), wys_direction_get_description (direction)); g_signal_emit_by_name (self, "audio-present", direction); } else if (self->audio_count[direction] == 0 && old_count > 0) { g_debug ("Modem `%s' audio now absent", mm_modem_voice_get_path (self->voice)); g_signal_emit_by_name (self, "audio-absent", direction); } } static gboolean get_call_has_audio (MMCall *mm_call, WysDirection direction) { gpointer data; data = g_object_get_data (G_OBJECT (mm_call), WYS_MODEM_HAS_AUDIO[direction]); return (gboolean)(GPOINTER_TO_UINT (data)); } static void set_call_has_audio (MMCall *mm_call, WysDirection direction, gboolean has_audio) { g_object_set_data (G_OBJECT (mm_call), WYS_MODEM_HAS_AUDIO[direction], GUINT_TO_POINTER ((guint)has_audio)); } static void update_direction_state (WysModem *self, MMCall *mm_call, const gchar *path, WysDirection direction, MMCallState old_state, MMCallState new_state) { gboolean had_audio = call_state_has_audio (direction, old_state); gboolean have_audio = call_state_has_audio (direction, new_state); if (!had_audio && have_audio) { g_debug ("Call `%s' gained audio %s", path, wys_direction_get_description (direction)); update_audio_count (self, direction, +1); } else if (had_audio && !have_audio) { g_debug ("Call `%s' lost audio %s", path, wys_direction_get_description (direction)); update_audio_count (self, direction, -1); } if (had_audio != have_audio) { set_call_has_audio (mm_call, direction, have_audio); } } static void call_state_changed_cb (MmGdbusCall *mm_gdbus_call, MMCallState old_state, MMCallState new_state, MMCallStateReason reason, WysModem *self) { MMCall *mm_call = MM_CALL (mm_gdbus_call); const gchar * path = mm_call_get_path (mm_call); g_debug ("Call `%s' state changed, new: %i, old: %i", path, (int)new_state, (int)old_state); // FIXME: deal with calls being put on hold (one call goes // non-audio, another call goes audio after) update_direction_state (self, mm_call, path, WYS_DIRECTION_FROM_NETWORK, old_state, new_state); update_direction_state (self, mm_call, path, WYS_DIRECTION_TO_NETWORK, old_state, new_state); } static void init_call_direction (WysModem *self, MMCall *mm_call, MMCallState state, WysDirection direction) { gboolean has_audio = call_state_has_audio (direction, state); set_call_has_audio (mm_call, direction, has_audio); if (has_audio) { update_audio_count (self, direction, +1); } } static void add_call (WysModem *self, MMCall *mm_call) { MmGdbusCall *mm_gdbus_call = MM_GDBUS_CALL (mm_call); gchar *path; MMCallState state; g_object_ref (mm_call); path = mm_call_dup_path (mm_call); g_hash_table_insert (self->calls, path, mm_call); g_signal_connect (mm_gdbus_call, "state-changed", G_CALLBACK (call_state_changed_cb), self); state = mm_call_get_state (mm_call); init_call_direction (self, mm_call, state, WYS_DIRECTION_FROM_NETWORK); init_call_direction (self, mm_call, state, WYS_DIRECTION_TO_NETWORK); g_debug ("Call `%s' added, state: %i", path, (int)state); } struct WysModemCallAddedData { WysModem *self; gchar *path; }; static void call_added_list_calls_cb (MMModemVoice *voice, GAsyncResult *res, struct WysModemCallAddedData *data) { GList *calls; GError *error = NULL; calls = mm_modem_voice_list_calls_finish (voice, res, &error); if (!calls) { if (error) { g_warning ("Error listing calls on MMModemVoice" " after call-added signal: %s", error->message); g_error_free (error); } else { g_warning ("No calls on MMModemVoice" " after call-added signal"); } } else { GList *node; MMCall *call; gboolean found = FALSE; for (node = calls; node; node = node->next) { call = MM_CALL (node->data); if (g_strcmp0 (mm_call_get_path (call), data->path) == 0) { add_call (data->self, call); found = TRUE; } } if (!found) { g_warning ("Could not find new call `%s' in call list" " on MMModemVoice after call-added signal", data->path); } g_list_free_full (calls, g_object_unref); } g_free (data->path); g_free (data); } static void call_added_cb (MMModemVoice *voice, gchar *path, WysModem *self) { struct WysModemCallAddedData *data; if (g_hash_table_contains (self->calls, path)) { g_warning ("Received call-added signal for" " existing call object path `%s'", path); return; } data = g_new0 (struct WysModemCallAddedData, 1); data->self = self; data->path = g_strdup (path); mm_modem_voice_list_calls (voice, NULL, (GAsyncReadyCallback) call_added_list_calls_cb, data); } static void clear_call_direction (WysModem *self, MMCall *mm_call, WysDirection direction) { gboolean has_audio = get_call_has_audio (mm_call, direction); if (has_audio) { update_audio_count (self, direction, -1); } } static void call_deleted_cb (MMModemVoice *voice, const gchar *path, WysModem *self) { MMCall *mm_call; g_debug ("Removing call `%s'", path); mm_call = g_hash_table_lookup (self->calls, path); if (!mm_call) { g_warning ("Could not find removed call `%s'", path); return; } clear_call_direction (self, mm_call, WYS_DIRECTION_FROM_NETWORK); clear_call_direction (self, mm_call, WYS_DIRECTION_TO_NETWORK); g_hash_table_remove (self->calls, path); g_debug ("Call `%s' removed", path); } static void list_calls_cb (MMModemVoice *voice, GAsyncResult *res, WysModem *self) { GList *calls, *node; GError *error = NULL; calls = mm_modem_voice_list_calls_finish (voice, res, &error); if (!calls) { if (error) { g_warning ("Error listing calls on MMModemVoice: %s", error->message); g_error_free (error); } return; } for (node = calls; node; node = node->next) { add_call (self, MM_CALL (node->data)); } g_list_free_full (calls, g_object_unref); } static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { WysModem *self = WYS_MODEM (object); switch (property_id) { case PROP_VOICE: g_set_object (&self->voice, g_value_get_object(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void constructed (GObject *object) { GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT); WysModem *self = WYS_MODEM (object); MmGdbusModemVoice *gdbus_voice; gdbus_voice = MM_GDBUS_MODEM_VOICE (self->voice); g_signal_connect (gdbus_voice, "call-added", G_CALLBACK (call_added_cb), self); g_signal_connect (gdbus_voice, "call-deleted", G_CALLBACK (call_deleted_cb), self); mm_modem_voice_list_calls (self->voice, NULL, (GAsyncReadyCallback) list_calls_cb, self); parent_class->constructed (object); } static void dispose (GObject *object) { GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT); WysModem *self = WYS_MODEM (object); if (g_hash_table_size (self->calls) > 0) { g_hash_table_remove_all (self->calls); if (self->audio_count[WYS_DIRECTION_FROM_NETWORK] > 0 || self->audio_count[WYS_DIRECTION_TO_NETWORK] > 0) { self->audio_count[WYS_DIRECTION_FROM_NETWORK] = self->audio_count[WYS_DIRECTION_TO_NETWORK] = 0; g_signal_emit_by_name (self, "audio-absent"); } } g_clear_object (&self->voice); parent_class->dispose (object); } static void finalize (GObject *object) { GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT); WysModem *self = WYS_MODEM (object); g_hash_table_unref (self->calls); parent_class->finalize (object); } static void wys_modem_class_init (WysModemClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = set_property; object_class->constructed = constructed; object_class->dispose = dispose; object_class->finalize = finalize; props[PROP_VOICE] = g_param_spec_object ("voice", _("Voice object"), _("A libmm-glib proxy object for the modem's voice interface"), MM_TYPE_MODEM_VOICE, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); /** * WysModem::audio-present: * @self: The #WysModem instance. * * This signal is emitted when a modem's call enters a state where * it has audio in a particular direction with respect to the phone * network. */ signals[SIGNAL_AUDIO_PRESENT] = g_signal_new ("audio-present", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, WYS_TYPE_DIRECTION); /** * WysModem::audio-absent: * @self: The #WysModem instance. * * This signal is emitted when none of the modem's calls are in a * state where they have audio. */ signals[SIGNAL_AUDIO_ABSENT] = g_signal_new ("audio-absent", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, WYS_TYPE_DIRECTION); } static void wys_modem_init (WysModem *self) { self->calls = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); } WysModem * wys_modem_new (MMModemVoice *voice) { return g_object_new (WYS_TYPE_MODEM, "voice", voice, NULL); } wys-0.1.11/src/wys-modem.h000066400000000000000000000020671401542361700153050ustar00rootroot00000000000000/* * Copyright (C) 2018, 2019 Purism SPC * * This file is part of Wys. * * Wys is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Wys 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 Wys. If not, see . * * Author: Bob Ham * * SPDX-License-Identifier: GPL-3.0-or-later * */ #ifndef WYS_MODEM_H__ #define WYS_MODEM_H__ #include G_BEGIN_DECLS #define WYS_TYPE_MODEM (wys_modem_get_type ()) G_DECLARE_FINAL_TYPE (WysModem, wys_modem, WYS, MODEM, GObject); WysModem *wys_modem_new (MMModemVoice *voice); G_END_DECLS #endif /* WYS_MODEM_H__ */ wys-0.1.11/subprojects/000077500000000000000000000000001401542361700147625ustar00rootroot00000000000000wys-0.1.11/subprojects/libmachine-check/000077500000000000000000000000001401542361700201305ustar00rootroot00000000000000wys-0.1.11/subprojects/libmachine-check/mchk-machine-check.c000066400000000000000000000175751401542361700237120ustar00rootroot00000000000000/* * Copyright (C) 2019 Purism SPC * * This file is part of libmachine-check. * * libmachine-check is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * libmachine-check 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 libmachine-check. If not, see * . * * Author: Bob Ham * * SPDX-License-Identifier: GPL-3.0-or-later * */ #include "mchk-machine-check.h" #include "config.h" #include #include #include #include #include #include /** * mchk_read_machine: * @error: (allow-none): return location for an error, or %NULL * * Read the machine name from /proc/device-tree/machine. If the * machine name could not be read, %NULL is returned and @error is * set. * * Returns: (nullable) (transfer full): The machine name or %NULL on * error. */ gchar * mchk_read_machine (GError **error_out) { static const gchar *MODEL_FILENAME = "/proc/device-tree/model"; gchar *machine; GError *error = NULL; g_return_val_if_fail (error_out == NULL || *error_out == NULL, NULL); g_file_get_contents (MODEL_FILENAME, &machine, NULL, &error); if (error) { g_warning ("Error reading machine name from `%s': %s", MODEL_FILENAME, error->message); g_propagate_error (error_out, error); } return machine; } static gboolean check_list_lines (const gchar *filename, int fd, const gchar *machine, gboolean *present, GError **error_out) { GInputStream *unix_stream; g_autoptr(GDataInputStream) data_stream = NULL; GError *error = NULL; g_debug ("Reading list file `%s'", filename); unix_stream = g_unix_input_stream_new (fd, TRUE); g_assert (unix_stream != NULL); data_stream = g_data_input_stream_new (unix_stream); g_assert (data_stream != NULL); g_object_unref (unix_stream); for (;;) { g_autofree gchar *line = g_data_input_stream_read_line_utf8 (data_stream, NULL, NULL, &error); if (error) { g_warning ("Error reading from check" " list file `%s': %s", filename, error->message); g_propagate_error (error_out, error); return FALSE; } if (line) { g_strstrip (line); // Skip comments and empty lines if (line[0] == '#' || line[0] == '\0') { continue; } // Check for the machine name if (strcmp (line, machine) == 0) { *present = TRUE; return TRUE; } } else // EOF { *present = FALSE; return TRUE; } } } static gboolean check_list (const gchar *dirname, const gchar *list, gboolean *list_exists, const gchar *machine, gboolean *present, GError **error) { g_autofree gchar *filename = NULL; int fd; filename = g_build_filename (dirname, list, NULL); fd = g_open (filename, O_RDONLY, 0); if (fd == -1) { if (errno == ENOENT) // The file doesn't exist { if (list_exists) { *list_exists = FALSE; } *present = FALSE; return TRUE; } g_warning ("Error opening check" " list file `%s': %s", filename, g_strerror (errno)); return FALSE; } if (list_exists) { *list_exists = TRUE; } return check_list_lines (filename, fd, machine, present, error); } static gboolean check_dir_machine (const gchar *dir, const gchar *param, const gchar *machine, gboolean *done, gboolean *passed, GError **error) { g_autofree gchar *check_dirname = NULL; gboolean list_exists, present, ok; check_dirname = g_build_filename (dir, "machine-check", param, NULL); // Check the blacklist ok = check_list (check_dirname, "blacklist", NULL, machine, &present, error); if (!ok) { return FALSE; } if (present) { g_debug ("Machine present in blacklist under `%s'", check_dirname); if (passed) { *passed = FALSE; } *done = TRUE; return TRUE; } // Check the whitelist ok = check_list (check_dirname, "whitelist", &list_exists, machine, &present, error); if (!ok) { return FALSE; } if (list_exists) { g_debug ("Machine whitelist exists under `%s'" ", machine %spresent", check_dirname, present ? "" : "not "); *done = TRUE; if (passed) { *passed = present; } } g_debug ("No machine whitelist or blacklist under `%s'", check_dirname); return TRUE; } /** * mchk_check_machine: * @param: the name of the machine-check sub-directory whose blacklist * and whitelist should be used * @machine: (allow-none): the machine name to check, or %NULL * @passed: (out) (allow-none): return location for the check result, * or %NULL * @error: (allow-none): return location for an error, or %NULL * * Check whether the machine name is not present in a blacklist and/or * present in a whitelist within a machine-check sub-directory * named @param. If @machine is %NULL then mchk_read_machine() will * be used to get the machine name. If an error is encountered, * @error will be set and %FALSE will be returned. * * Returns: %TRUE on success or %FALSE on error. */ gboolean mchk_check_machine (const gchar *param, const gchar *machine, gboolean *passed, GError **error) { g_autofree gchar *mach = NULL; const gchar * const *dirs, * const *dir; gboolean done = FALSE, ok; g_return_val_if_fail (param != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); // Get the machine name if (machine) { mach = g_strdup (machine); } else { mach = mchk_read_machine (error); if (!mach) { return FALSE; } } // Iterate over possible whitelist/blacklist locations #define try_dir(d) \ ok = check_dir_machine (d, param, mach, \ &done, passed, error); \ if (!ok || done) \ { \ return ok; \ } try_dir (g_get_user_config_dir ()); dirs = g_get_system_config_dirs (); for (dir = dirs; *dir; ++dir) { try_dir (*dir); } try_dir (SYSCONFDIR); try_dir (DATADIR); dirs = g_get_system_data_dirs (); for (dir = dirs; *dir; ++dir) { try_dir (*dir); } #undef try_dir g_debug ("Defaulting to pass"); if (passed) { *passed = TRUE; } return TRUE; } wys-0.1.11/subprojects/libmachine-check/mchk-machine-check.h000066400000000000000000000022051401542361700236770ustar00rootroot00000000000000/* * Copyright (C) 2019 Purism SPC * * This file is part of libmachine-check. * * libmachine-check is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * libmachine-check 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 libmachine-check. If not, see * . * * Author: Bob Ham * * SPDX-License-Identifier: GPL-3.0-or-later * */ #pragma once #include G_BEGIN_DECLS gchar * mchk_read_machine (GError **error); gboolean mchk_check_machine (const gchar *param, const gchar *machine, gboolean *passed, GError **error); G_END_DECLS wys-0.1.11/subprojects/libmachine-check/meson.build000066400000000000000000000037321401542361700222770ustar00rootroot00000000000000# # Copyright (C) 2019 Purism SPC # # This file is part of libmachine-check. # # libmachine-check is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # libmachine-check 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 libmachine-check. If not, see # . # # SPDX-License-Identifier: GPL-3.0-or-later # project ( 'libmachine-check', 'c', version: '0.1.0', license: 'GPLv3+', default_options: [ 'warning_level=1', 'buildtype=debugoptimized', 'c_std=gnu11' ], ) prefix = get_option('prefix') datadir = get_option('datadir') sysconfdir = get_option('sysconfdir') if datadir.startswith('/') full_datadir = datadir else full_datadir = join_paths(prefix, datadir) endif if sysconfdir.startswith('/') full_sysconfdir = sysconfdir else full_sysconfdir = join_paths(prefix, sysconfdir) endif config_data = configuration_data() config_data.set_quoted('DATADIR', full_datadir) config_data.set_quoted('SYSCONFDIR', full_sysconfdir) config_h = configure_file ( output: 'config.h', configuration: config_data ) libmachine_check_deps = [ dependency('gio-unix-2.0'), ] libmachine_check_inc = include_directories('.') libmachine_check = static_library ( 'machine-check', config_h, [ 'mchk-machine-check.h', 'mchk-machine-check.c', ], dependencies : libmachine_check_deps, include_directories : libmachine_check_inc, ) libmachine_check_dep = declare_dependency ( dependencies: libmachine_check_deps, link_with: libmachine_check, include_directories: libmachine_check_inc, ) wys-0.1.11/wys.doap000066400000000000000000000024041401542361700141060ustar00rootroot00000000000000 Wys Wys A daemon to bring up and take down PulseAudio loopbacks for phone call audio During a phone call, audio must be streamed from one ALSA device to another ALSA device. This should only happen during the call, when the modem's audio interfaces will actually be active. To facilitate this, Wys will wait for ModemManager calls in the ringing or active state and enable appropriate PulseAudio loopback modules only during those states. C Bob Ham