pax_global_header00006660000000000000000000000064151745427370014531gustar00rootroot0000000000000052 comment=7c0cd9442d71b55260c9917c89ebc4bd20e283a8 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/000077500000000000000000000000001517454273700206035ustar00rootroot0000000000000081voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/81voltd.1000066400000000000000000000017201517454273700221660ustar00rootroot00000000000000.\" Hey, EMACS: -*- nroff -*- .\" (C) Copyright 2025 Alexandre Viard , .\" .TH 81VOLTD 1 "February 18 2025" "81voltd" "Server-side implementation of the QMI IMS Data service" .SH NAME 81voltd \- Server-side implementation of the QMI IMS Data service .SH SYNOPSIS .B 81voltd .SH DESCRIPTION .B 81voltd is a simple implementation of the IMS Data service on QMI/QRTR. It handles the known and important requests to start and stop a connection through the ModemManager D-Bus API, treating other requests as no operation. The IMS Data service is mandatory to support voice call on 4G/5G mobile network. .SH BUGS Stopping the implementation does not release or disconnect any bearers. This makes it hard to debug, requiring the modem be set to low-power, then back online. .PP ModemManager errors are not communicated to the modem. .SH COPYRIGHT Copyright (C) 2024 Richard Acayan 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/81voltd.initd.in000066400000000000000000000003241517454273700235410ustar00rootroot00000000000000#!/sbin/openrc-run name="81voltd" description="IMS Data service on QMI/QRTR" command="@bindir@/81voltd" command_args="" command_background=true pidfile="/run/${RC_SVCNAME}.pid" depend() { need modemmanager } 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/81voltd.service.in000066400000000000000000000002261517454273700240730ustar00rootroot00000000000000[Unit] Description=IMS Data service on QMI/QRTR After=ModemManager.target [Service] ExecStart=@bindir@/81voltd [Install] WantedBy=multi-user.target 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/LICENSE000066400000000000000000000432541517454273700216200ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) 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 this service 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 make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. 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. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), 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 distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the 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 a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE 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. 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 convey 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision 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, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This 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. 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/README.md000066400000000000000000000104231517454273700220620ustar00rootroot00000000000000This is a simple implementation of the IMS Data service on QMI/QRTR. It handles the known and important requests to start and stop a connection through the ModemManager D-Bus API, treating other requests as no operation. Some known issues remain: - Stopping the implementation does not release or disconnect any bearers. This makes it hard to debug, requiring the modem be set to low-power, then back online. - ModemManager errors are not communicated to the modem. # IMS Data Protocol The IMS Data service is served over the known QMI/QRTR protocols, with service number 770 and version number 1. Requests are sent by the modem (where firmware runs) and prompt responses from the Application Processor (where the FOSS drivers run). The AP can also send indications which are not directly requested. The critical QMI request is IMSD 0x20, by which the modem requests the AP to start a connection via WDS Start Network with the specified parameters. The rest of the IMSD requests can succeed through a simple response with the operation result (field 0x02) set to zero. Another important QMI request is IMSD 0x21, by which the modem requests to stop the connection. This must be properly implemented so the modem attempts to reconnect after being put in low power mode and brought back online. ## Request 0x20: Start Connection Field 0x01 is a sequence of: - a string containing the APN name with an 8-bit length prefix - a 32-bit number, valid from 0 to 5 inclusive - a 32-bit enumerable indicating which profile IDs to include in the WDS Start Network request - 0 = 3GPP2 profile ID only - 1 = 3GPP profile ID only - 2 = 3GPP and 3GPP2 profile IDs - a 32-bit enumerable representing the IP family - 0 = IPv4 - 1 = IPv6 - the 3GPP profile ID sign-extended to 16 bits - the 3GPP2 profile ID sign-extended to 16 bits Thanks to Dylan's research, field 0x13 is known to be a subscription ID. Binding a subscription is probably not required most of the time, but this number is used to track the connection. Field 0x10 is an ID for the connection. Example: APN "ims", IPv6, 3GPP profile 2, 3GPP2 profile 255, Connection 101, Subscription 1 Type Length Value (in hexadecimal) 01 1400 03 696d73 00000000 02000000 01000000 0200 ffff 10 0400 65000000 11 0400 00000000 12 0400 01000000 13 0400 01000000 ## Response 0x20 Field 0x11 is the connection ID from the request. Field 0x12 is the subscription ID from the request. Field 0x10 is an updated connection ID. If the connection ID and subscription ID are valid, the modem will refer to the connection with this new connection ID. Example: New ID 21, Connection 101, Subscription 1 Type Length Value 02 0400 0000 0000 10 0100 15 11 0400 65000000 12 0400 01000000 ## Request 0x21: Stop Connection If a valid indication 0x20 was emitted, field 0x01 is the connection ID from the indication. If the corresponding 0x20 request was given a valid response but an indication was not emitted, field 0x01 is the connection ID from the response. Otherwise, field 0x01 is the connection ID from the request. Example: Connection 21, Subscription 1 Type Length Value 01 0100 15 10 0400 01000000 ## Response 0x21 Field 0x11 is set to field 0x10 of the request. Field 0x10 is set to -6. Example: Type Length Value 02 0400 0000 0000 10 0100 fa 11 0400 01000000 ## Indication 0x20: Connection Changed Field 0x02 is the operation result. If the connection is up, the error status and code are zero. If the connection is down due to request 0x20, the error status is zero and the error code is 13. Field 0x01 is the new connection ID, and will be used to update the connection ID if it differs. Field 0x10 is the connection ID of the request. If the connection is up, field 0x11 is a sequence of: - a 32-bit integer, set to 1 for IPv6 addresses - a string containing the IP address obtained by the device with an 8-bit length prefix Field 0x12 is the subscription ID. Example: Connection 21, Old Connection ID 101, Subscription 1, IPv6 Address 2606:4700::1111 Type Length Value 02 0400 0000 0000 01 0100 15 10 0400 65000000 11 1400 01000000 0f 323630363a343730303a3a31313131 12 0400 01000000 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/imsd.qmi000066400000000000000000000023331517454273700222500ustar00rootroot00000000000000# SPDX-License-Identifier: GPL-2.0-or-later # # Copyright (c) 2024, Richard Acayan. All rights reserved. # package imsd; struct wds_spec { string apn; u32 unkfield_0_5; u32 profiles_select; u32 ip_family; u16 profile_idx_3gpp; u16 profile_idx_3gpp2; }; struct address { u32 family; string addr; }; struct op_res { u16 err_status; u16 err_code; }; request start_connection_req { required wds_spec conn_params = 0x1; required u32 connection = 0x10; required u32 subscription = 0x13; } = 0x20; response start_connection_resp { required op_res res = 0x2; required u8 connection = 0x10; required u32 orig_conn_id = 0x11; required u32 subscription = 0x12; } = 0x20; indication connection_changed_ind { required op_res res = 0x2; required u8 connection = 0x1; required u32 orig_conn_id = 0x10; optional address ip_addr = 0x11; required u32 subscription = 0x12; } = 0x20; request stop_connection_req { required u8 connection = 0x1; required u32 unkecho_01 = 0x10; } = 0x21; response stop_connection_resp { required op_res res = 0x2; required u8 unkfield_FA = 0x10; required u32 unkecho_01 = 0x11; } = 0x21; request no_op_req { optional u8 data[255] = 0x1; }; response no_op_resp { required op_res res = 0x2; }; 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/main.c000066400000000000000000000013631517454273700216760ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2024, Richard Acayan. All rights reserved. */ #include #include "qvd-modem.h" #include "qvd-server.h" int main(void) { GMainLoop *loop; GError *err = NULL; QVDModem *modem; QVDServer *server; g_info("81voltd starting\n"); modem = qvd_modem_new(&err); if (err != NULL) { g_printerr("Failed to create connection manager: %s\n", err->message); g_error_free(err); return 1; } server = qvd_server_new(modem, &err); if (err != NULL) { g_printerr("Failed to create IMSD server: %s\n", err->message); g_error_free(err); return 1; } loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(loop); g_object_unref(server); g_object_unref(modem); return 0; } 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/meson.build000066400000000000000000000024251517454273700227500ustar00rootroot00000000000000project('81voltd', 'c', version : '1.2.0') libmm = dependency('mm-glib') libqmi = dependency('qmi-glib') libqrtr = dependency('qrtr') qmic = find_program('qmic', required : false) wrapper = files('qmic_wrapper.sh') if qmic.found() qmi = custom_target('qmi_imsd', command : [wrapper, qmic, '@INPUT@', '@OUTDIR@'], input : 'imsd.qmi', output : ['qmi_imsd.c', 'qmi_imsd.h']) else qmi = custom_target('qmi_imsd', command : ['cp', '@INPUT@', '@OUTDIR@'], input : ['qmi_imsd.c', 'qmi_imsd.h'], output : ['qmi_imsd.c', 'qmi_imsd.h']) endif executable('81voltd', 'main.c', 'qvd-connection.c', 'qvd-message.c', 'qvd-modem.c', 'qvd-server.c', qmi, dependencies : [libmm, libqmi, libqrtr], install : true) install_man('81voltd.1') configure_file( input: '81voltd.service.in', output: '81voltd.service', configuration: { 'bindir': get_option('prefix') / get_option('bindir') }, install: true, install_dir: get_option('prefix') / 'lib' / 'systemd' / 'system' ) openrcinit = configure_file( input: '81voltd.initd.in', output: '81voltd.initd', configuration: { 'bindir': get_option('prefix') / get_option('bindir') }, ) install_data(openrcinit, install_dir: get_option('sysconfdir') / 'init.d', install_mode : 'rwxr-xr-x', rename: '81voltd' ) 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/qmi_imsd.c000066400000000000000000000135731517454273700225620ustar00rootroot00000000000000#include #include #include "qmi_imsd.h" struct qmi_elem_info imsd_wds_spec_ei[] = { { .data_type = QMI_STRING, .elem_len = 256, .elem_size = sizeof(char), .offset = offsetof(struct imsd_wds_spec, apn) }, { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .offset = offsetof(struct imsd_wds_spec, unkfield_0_5), }, { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .offset = offsetof(struct imsd_wds_spec, profiles_select), }, { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .offset = offsetof(struct imsd_wds_spec, ip_family), }, { .data_type = QMI_UNSIGNED_2_BYTE, .elem_len = 1, .elem_size = sizeof(uint16_t), .offset = offsetof(struct imsd_wds_spec, profile_idx_3gpp), }, { .data_type = QMI_UNSIGNED_2_BYTE, .elem_len = 1, .elem_size = sizeof(uint16_t), .offset = offsetof(struct imsd_wds_spec, profile_idx_3gpp2), }, {} }; struct qmi_elem_info imsd_address_ei[] = { { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .offset = offsetof(struct imsd_address, family), }, { .data_type = QMI_STRING, .elem_len = 256, .elem_size = sizeof(char), .offset = offsetof(struct imsd_address, addr) }, {} }; struct qmi_elem_info imsd_op_res_ei[] = { { .data_type = QMI_UNSIGNED_2_BYTE, .elem_len = 1, .elem_size = sizeof(uint16_t), .offset = offsetof(struct imsd_op_res, err_status), }, { .data_type = QMI_UNSIGNED_2_BYTE, .elem_len = 1, .elem_size = sizeof(uint16_t), .offset = offsetof(struct imsd_op_res, err_code), }, {} }; struct qmi_elem_info imsd_start_connection_req_ei[] = { { .data_type = QMI_STRUCT, .elem_len = 1, .elem_size = sizeof(struct imsd_wds_spec), .tlv_type = 1, .offset = offsetof(struct imsd_start_connection_req, conn_params), .ei_array = imsd_wds_spec_ei, }, { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .tlv_type = 16, .offset = offsetof(struct imsd_start_connection_req, connection), }, { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .tlv_type = 19, .offset = offsetof(struct imsd_start_connection_req, subscription), }, {} }; struct qmi_elem_info imsd_start_connection_resp_ei[] = { { .data_type = QMI_STRUCT, .elem_len = 1, .elem_size = sizeof(struct imsd_op_res), .tlv_type = 2, .offset = offsetof(struct imsd_start_connection_resp, res), .ei_array = imsd_op_res_ei, }, { .data_type = QMI_UNSIGNED_1_BYTE, .elem_len = 1, .elem_size = sizeof(uint8_t), .tlv_type = 16, .offset = offsetof(struct imsd_start_connection_resp, connection), }, { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .tlv_type = 17, .offset = offsetof(struct imsd_start_connection_resp, orig_conn_id), }, { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .tlv_type = 18, .offset = offsetof(struct imsd_start_connection_resp, subscription), }, {} }; struct qmi_elem_info imsd_connection_changed_ind_ei[] = { { .data_type = QMI_STRUCT, .elem_len = 1, .elem_size = sizeof(struct imsd_op_res), .tlv_type = 2, .offset = offsetof(struct imsd_connection_changed_ind, res), .ei_array = imsd_op_res_ei, }, { .data_type = QMI_UNSIGNED_1_BYTE, .elem_len = 1, .elem_size = sizeof(uint8_t), .tlv_type = 1, .offset = offsetof(struct imsd_connection_changed_ind, connection), }, { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .tlv_type = 16, .offset = offsetof(struct imsd_connection_changed_ind, orig_conn_id), }, { .data_type = QMI_OPT_FLAG, .elem_len = 1, .elem_size = sizeof(bool), .tlv_type = 17, .offset = offsetof(struct imsd_connection_changed_ind, ip_addr_valid), }, { .data_type = QMI_STRUCT, .elem_len = 1, .elem_size = sizeof(struct imsd_address), .tlv_type = 17, .offset = offsetof(struct imsd_connection_changed_ind, ip_addr), .ei_array = imsd_address_ei, }, { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .tlv_type = 18, .offset = offsetof(struct imsd_connection_changed_ind, subscription), }, {} }; struct qmi_elem_info imsd_stop_connection_req_ei[] = { { .data_type = QMI_UNSIGNED_1_BYTE, .elem_len = 1, .elem_size = sizeof(uint8_t), .tlv_type = 1, .offset = offsetof(struct imsd_stop_connection_req, connection), }, { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .tlv_type = 16, .offset = offsetof(struct imsd_stop_connection_req, unkecho_01), }, {} }; struct qmi_elem_info imsd_stop_connection_resp_ei[] = { { .data_type = QMI_STRUCT, .elem_len = 1, .elem_size = sizeof(struct imsd_op_res), .tlv_type = 2, .offset = offsetof(struct imsd_stop_connection_resp, res), .ei_array = imsd_op_res_ei, }, { .data_type = QMI_UNSIGNED_1_BYTE, .elem_len = 1, .elem_size = sizeof(uint8_t), .tlv_type = 16, .offset = offsetof(struct imsd_stop_connection_resp, unkfield_FA), }, { .data_type = QMI_UNSIGNED_4_BYTE, .elem_len = 1, .elem_size = sizeof(uint32_t), .tlv_type = 17, .offset = offsetof(struct imsd_stop_connection_resp, unkecho_01), }, {} }; struct qmi_elem_info imsd_no_op_req_ei[] = { { .data_type = QMI_OPT_FLAG, .elem_len = 1, .elem_size = sizeof(bool), .tlv_type = 1, .offset = offsetof(struct imsd_no_op_req, data_valid), }, { .data_type = QMI_UNSIGNED_1_BYTE, .elem_len = 255, .elem_size = sizeof(uint8_t), .array_type = STATIC_ARRAY, .tlv_type = 1, .offset = offsetof(struct imsd_no_op_req, data), }, {} }; struct qmi_elem_info imsd_no_op_resp_ei[] = { { .data_type = QMI_STRUCT, .elem_len = 1, .elem_size = sizeof(struct imsd_op_res), .tlv_type = 2, .offset = offsetof(struct imsd_no_op_resp, res), .ei_array = imsd_op_res_ei, }, {} }; 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/qmi_imsd.h000066400000000000000000000031341517454273700225570ustar00rootroot00000000000000#ifndef __QMI_IMSD_H__ #define __QMI_IMSD_H__ #include #include #include "libqrtr.h" struct imsd_wds_spec { uint32_t apn_len; char apn[256]; uint32_t unkfield_0_5; uint32_t profiles_select; uint32_t ip_family; uint16_t profile_idx_3gpp; uint16_t profile_idx_3gpp2; }; struct imsd_address { uint32_t family; uint32_t addr_len; char addr[256]; }; struct imsd_op_res { uint16_t err_status; uint16_t err_code; }; struct imsd_start_connection_req { struct imsd_wds_spec conn_params; uint32_t connection; uint32_t subscription; }; struct imsd_start_connection_resp { struct imsd_op_res res; uint8_t connection; uint32_t orig_conn_id; uint32_t subscription; }; struct imsd_connection_changed_ind { struct imsd_op_res res; uint8_t connection; uint32_t orig_conn_id; bool ip_addr_valid; struct imsd_address ip_addr; uint32_t subscription; }; struct imsd_stop_connection_req { uint8_t connection; uint32_t unkecho_01; }; struct imsd_stop_connection_resp { struct imsd_op_res res; uint8_t unkfield_FA; uint32_t unkecho_01; }; struct imsd_no_op_req { bool data_valid; uint32_t data_len; uint8_t data[255]; }; struct imsd_no_op_resp { struct imsd_op_res res; }; extern struct qmi_elem_info imsd_start_connection_req_ei[]; extern struct qmi_elem_info imsd_start_connection_resp_ei[]; extern struct qmi_elem_info imsd_connection_changed_ind_ei[]; extern struct qmi_elem_info imsd_stop_connection_req_ei[]; extern struct qmi_elem_info imsd_stop_connection_resp_ei[]; extern struct qmi_elem_info imsd_no_op_req_ei[]; extern struct qmi_elem_info imsd_no_op_resp_ei[]; #endif 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/qmic_wrapper.sh000077500000000000000000000011311517454273700236270ustar00rootroot00000000000000#!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later # # QMI interface compiler wrapper from sensh # # Copyright (C) 2023 Richard Acayan # qmic="$1" # # Usage: qmic_wrapper.sh QMIC INPUT OUTPUT_DIRECTORY # # Example: qmic_wrapper.sh /usr/bin/qmic ../qmi/sns_client.qmi qmi/ # # # We need to move into the output directory so QMIC puts the files in the # correct place, but the path to the input might be relative to the directory # we are already in. Open the file now and pipe it to stdin so the pathname # gets processed relative to the correct directory. # exec < "$2" cd "$3" exec "$qmic" -k 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/qvd-connection.c000066400000000000000000000117611517454273700237040ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2024, Richard Acayan. All rights reserved. */ #include #include #include "qvd-connection.h" enum { ADDR_CHANGED, CONNECT_ERR, DISCONNECT_ERR, N_SIGNALS, }; struct _QVDConnection { GObject parent_instance; MMBearer *bearer; MMBearerIpFamily ip_type; gchar *addr; gboolean requested; guint32 sub_id, conn_id; guint8 local_id; }; G_DEFINE_TYPE(QVDConnection, qvd_connection, G_TYPE_OBJECT) static guint conn_signals[N_SIGNALS]; static void qvd_connection_dispose(GObject *obj); static void qvd_connection_class_init(QVDConnectionClass *c) { GObjectClass *obj_class = G_OBJECT_CLASS(c); obj_class->dispose = qvd_connection_dispose; conn_signals[ADDR_CHANGED] = g_signal_new("qvd-address-changed", QVD_TYPE_CONNECTION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING); conn_signals[CONNECT_ERR] = g_signal_new("qvd-connect-error", QVD_TYPE_CONNECTION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_ERROR); conn_signals[DISCONNECT_ERR] = g_signal_new("qvd-disconnect-error", QVD_TYPE_CONNECTION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_ERROR); } static void qvd_connection_init(QVDConnection *conn) { } static void qvd_connection_dispose(GObject *obj) { QVDConnection *conn = QVD_CONNECTION(obj); if (conn->addr != NULL) g_free(g_steal_pointer(&conn->addr)); g_clear_object(&conn->bearer); } QVDConnection *qvd_connection_new(MMBearerIpFamily ip_type) { QVDConnection *conn; conn = QVD_CONNECTION(g_object_new(QVD_TYPE_CONNECTION, NULL)); conn->ip_type = ip_type; return conn; } const gchar *qvd_connection_get_path(QVDConnection *conn) { if (conn->bearer == NULL) return NULL; return g_dbus_proxy_get_object_path(G_DBUS_PROXY(conn->bearer)); } void qvd_connection_get_handles(const QVDConnection *conn, guint32 *sub_id, guint32 *conn_id, guint8 *local_id) { g_assert(conn != NULL); if (sub_id != NULL) *sub_id = conn->sub_id; if (conn_id != NULL) *conn_id = conn->conn_id; if (local_id != NULL) *local_id = conn->local_id; } static void try_notify_address(QVDConnection *conn, GVariant *changed, MMBearerIpFamily ip_type, const gchar *conf_name) { GVariant *ip_conf; gchar *addr = NULL; ip_conf = g_variant_lookup_value(changed, conf_name, G_VARIANT_TYPE_DICTIONARY); if (ip_conf == NULL) return; g_variant_lookup(ip_conf, "address", "s", &addr); if (g_strcmp0(addr, conn->addr)) { g_signal_emit(conn, conn_signals[ADDR_CHANGED], 0, ip_type, addr); conn->addr = addr; } else { g_free(addr); } } void qvd_connection_set_handles(QVDConnection *conn, guint32 sub_id, guint32 conn_id, guint8 local_id) { g_assert(conn != NULL); conn->sub_id = sub_id; conn->conn_id = conn_id; conn->local_id = local_id; } static void on_connect(GObject *obj, GAsyncResult *res, gpointer data) { QVDConnection *conn = QVD_CONNECTION(data); GError *err = NULL; mm_bearer_connect_finish(MM_BEARER(obj), res, &err); if (err != NULL) { g_printerr("Failed to connect: %s\n", err->message); g_signal_emit(conn, conn_signals[CONNECT_ERR], 0, err); g_clear_error(&err); } g_object_unref(conn); } void qvd_connection_connect(QVDConnection *conn) { g_assert(conn != NULL); conn->requested = TRUE; if (conn->bearer != NULL) mm_bearer_connect(conn->bearer, NULL, on_connect, g_object_ref(conn)); } static void on_disconnect(GObject *obj, GAsyncResult *res, gpointer data) { QVDConnection *conn = QVD_CONNECTION(data); GError *err = NULL; mm_bearer_disconnect_finish(MM_BEARER(obj), res, &err); if (err != NULL) { g_printerr("Failed to disconnect: %s\n", err->message); g_signal_emit(conn, conn_signals[DISCONNECT_ERR], 0, err); g_clear_error(&err); } g_object_unref(conn); } void qvd_connection_disconnect(QVDConnection *conn) { g_assert(conn != NULL); g_assert(conn->bearer != NULL); conn->requested = FALSE; if (conn->bearer != NULL) mm_bearer_disconnect(conn->bearer, NULL, on_disconnect, g_object_ref(conn)); } static void on_bearer_properties_changed(GDBusProxy* bearer, GVariant* changed, char** invalidated, gpointer data) { QVDConnection *conn = QVD_CONNECTION(data); g_assert(conn->ip_type == MM_BEARER_IP_FAMILY_IPV4 || conn->ip_type == MM_BEARER_IP_FAMILY_IPV6); if (conn->ip_type == MM_BEARER_IP_FAMILY_IPV4) try_notify_address(conn, changed, MM_BEARER_IP_FAMILY_IPV4, "Ip4Config"); else try_notify_address(conn, changed, MM_BEARER_IP_FAMILY_IPV6, "Ip6Config"); } void qvd_connection_set_bearer(QVDConnection *conn, MMBearer *bearer) { g_assert(conn != NULL); g_assert(conn->bearer == NULL); conn->bearer = g_object_ref(bearer); g_signal_connect(bearer, "g-properties-changed", G_CALLBACK(on_bearer_properties_changed), conn); if (conn->requested) mm_bearer_connect(conn->bearer, NULL, on_connect, conn); } 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/qvd-connection.h000066400000000000000000000016711517454273700237100ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (c) 2024, Richard Acayan. All rights reserved. */ #ifndef QVD_CONNECTION_H #define QVD_CONNECTION_H #include #include #include G_BEGIN_DECLS #define QVD_TYPE_CONNECTION qvd_connection_get_type() G_DECLARE_FINAL_TYPE(QVDConnection, qvd_connection, QVD, CONNECTION, GObject) QVDConnection *qvd_connection_new(MMBearerIpFamily ip_type); const gchar *qvd_connection_get_path(QVDConnection *conn); void qvd_connection_get_handles(const QVDConnection *conn, guint32 *sub_id, guint32 *conn_id, guint8 *local_id); void qvd_connection_set_handles(QVDConnection *conn, guint32 sub_id, guint32 conn_id, guint8 local_id); void qvd_connection_connect(QVDConnection *conn); void qvd_connection_disconnect(QVDConnection *conn); void qvd_connection_set_bearer(QVDConnection *conn, MMBearer *bearer); G_END_DECLS #endif /* QVD_CONNECTION_H */ 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/qvd-message.c000066400000000000000000000114001517454273700231570ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2025, Richard Acayan. All rights reserved. */ #include #include #include #include #include #include #include "qvd-message.h" enum { PROP_REQ = 1, PROP_SOCK, PROP_NODE, PROP_PORT, N_PROPS, }; struct _QVDMessage { GObject parent_instance; gboolean txn_valid; unsigned int txn; GSocket *sock; struct qrtr_packet *req; guint32 node; guint32 port; }; G_DEFINE_TYPE(QVDMessage, qvd_message, G_TYPE_OBJECT) static GParamSpec *props[N_PROPS] = { NULL, }; static void qvd_message_dispose(GObject *obj); void qvd_message_get_property(GObject *obj, guint prop, GValue *val, GParamSpec *spec) { QVDMessage *ctx = QVD_MESSAGE(obj); switch (prop) { case PROP_REQ: g_value_set_pointer(val, ctx->req); break; case PROP_SOCK: g_value_set_object(val, G_OBJECT(ctx->sock)); break; case PROP_NODE: g_value_set_uint(val, ctx->node); break; case PROP_PORT: g_value_set_uint(val, ctx->port); break; default: break; } } void qvd_message_set_property(GObject *obj, guint prop, const GValue *val, GParamSpec *spec) { QVDMessage *ctx = QVD_MESSAGE(obj); switch (prop) { case PROP_REQ: ctx->req = g_value_get_pointer(val); break; case PROP_SOCK: ctx->sock = G_SOCKET(g_value_get_object(val)); break; case PROP_NODE: ctx->node = g_value_get_uint(val); break; case PROP_PORT: ctx->port = g_value_get_uint(val); break; default: break; } } static void qvd_message_class_init(QVDMessageClass *c) { GObjectClass *obj_class = G_OBJECT_CLASS(c); obj_class->get_property = qvd_message_get_property; obj_class->set_property = qvd_message_set_property; obj_class->dispose = qvd_message_dispose; props[PROP_REQ] = g_param_spec_pointer("request", "Request", "QMI request from the modem", G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); props[PROP_SOCK] = g_param_spec_object("socket", "Socket", "Socket for request and response", G_TYPE_SOCKET, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); props[PROP_NODE] = g_param_spec_uint("peer-node", "Peer Node", "QRTR Node of client", 0, UINT32_MAX, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); props[PROP_PORT] = g_param_spec_uint("peer-port", "Peer Port", "QRTR Port of client", 0, UINT32_MAX, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); g_object_class_install_properties(obj_class, N_PROPS, props); } static void qvd_message_init(QVDMessage *ctx) { } static void qvd_message_dispose(GObject *obj) { QVDMessage *ctx = QVD_MESSAGE(obj); g_clear_object(&ctx->sock); g_free(ctx->req->data); g_free(ctx->req); } QVDMessage *qvd_message_new(GSocket *sock, const struct qrtr_packet *req, guint32 node, guint32 port) { return QVD_MESSAGE(g_object_new(QVD_TYPE_MESSAGE, "socket", sock, "request", req, "peer-node", node, "peer-port", port, NULL)); } guint qvd_message_get_msg_id(QVDMessage *ctx) { unsigned int msg_id; qmi_decode_header(ctx->req, &msg_id); return msg_id; } void qvd_message_decode(QVDMessage *ctx, void *c_struct, struct qmi_elem_info *ei, GError **out_err) { GError *err; guint msg_id; int ret; msg_id = qvd_message_get_msg_id(ctx); ret = qmi_decode_message(c_struct, &ctx->txn, ctx->req, QMI_REQUEST, msg_id, ei); if (ret < 0) { err = g_error_new(QMI_CORE_ERROR, QMI_CORE_ERROR_INVALID_MESSAGE, "failed to decode request: %s", strerror(-ret)); g_propagate_error(out_err, err); return; } ctx->txn_valid = true; } void qvd_message_respond(QVDMessage *ctx, const void *c_struct, struct qmi_elem_info *ei, GError **out_err) { GError *err; struct qrtr_packet outpkt; guint msg_id; ssize_t ret; int fd; if (!ctx->txn_valid) { err = g_error_new(QMI_CORE_ERROR, QMI_CORE_ERROR_WRONG_STATE, "request must be decoded before issuing a response"); g_propagate_error(out_err, err); return; } fd = g_socket_get_fd(ctx->sock); msg_id = qvd_message_get_msg_id(ctx); outpkt.data_len = 65536; outpkt.data = g_malloc(outpkt.data_len); ret = qmi_encode_message(&outpkt, QMI_RESPONSE, msg_id, ctx->txn, c_struct, ei); if (ret < 0) { err = g_error_new(QMI_CORE_ERROR, QMI_CORE_ERROR_INVALID_MESSAGE, "failed to encode response: %s", strerror(-ret)); g_propagate_error(out_err, err); goto err; } ret = qrtr_sendto(fd, ctx->node, ctx->port, outpkt.data, outpkt.data_len); if (ret < 0) { err = g_error_new(QMI_CORE_ERROR, QMI_CORE_ERROR_INVALID_MESSAGE, "failed to send response: %s", strerror(-ret)); g_propagate_error(out_err, err); } err: g_free(outpkt.data); } 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/qvd-message.h000066400000000000000000000014211517454273700231660ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (c) 2025, Richard Acayan. All rights reserved. */ #ifndef QVD_MESSAGE_H #define QVD_MESSAGE_H #include #include #include G_BEGIN_DECLS #define QVD_TYPE_MESSAGE qvd_message_get_type() G_DECLARE_FINAL_TYPE(QVDMessage, qvd_message, QVD, MESSAGE, GObject) QVDMessage *qvd_message_new(GSocket *sock, const struct qrtr_packet *req, guint32 node, guint32 port); guint qvd_message_get_msg_id(QVDMessage *ctx); void qvd_message_decode(QVDMessage *ctx, void *c_struct, struct qmi_elem_info *ei, GError **err); void qvd_message_respond(QVDMessage *ctx, const void *c_struct, struct qmi_elem_info *ei, GError **err); G_END_DECLS #endif /* QVD_MESSAGE_H */ 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/qvd-modem.c000066400000000000000000000262751517454273700226540ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2024, Richard Acayan. All rights reserved. */ #include #include #include #include #include #include "qvd-connection.h" #include "qvd-modem.h" enum { ADDR_CHANGED, CONNECT_ERR, DISCONNECT_ERR, N_SIGNALS, }; struct _QVDModem { GObject parent_instance; GDBusConnection *dbus; MMManager *manager; MMModem *modem; GHashTable *bearers; GPtrArray *pending_bearers; }; struct qvd_pending_bearer { MMBearerProperties *props; GTask *task; }; struct qvd_bearer_config { MMBearerIpFamily ip_type; gchar apn[256]; }; static void qvd_modem_initable_iface_init(GInitableIface *iface); G_DEFINE_TYPE_WITH_CODE(QVDModem, qvd_modem, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE, qvd_modem_initable_iface_init)) static gboolean qvd_modem_initable_init(GInitable *initable, GCancellable *cancellable, GError **out_err); static void qvd_modem_dispose(GObject *obj); static guint modem_signals[N_SIGNALS]; static void qvd_modem_class_init(QVDModemClass *c) { GObjectClass *obj_class = G_OBJECT_CLASS(c); obj_class->dispose = qvd_modem_dispose; modem_signals[ADDR_CHANGED] = g_signal_new("qvd-connection-address-changed", QVD_TYPE_MODEM, G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 3, QVD_TYPE_CONNECTION, G_TYPE_INT, G_TYPE_STRING); modem_signals[CONNECT_ERR] = g_signal_new("qvd-connection-connect-error", QVD_TYPE_MODEM, G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 2, QVD_TYPE_CONNECTION, G_TYPE_ERROR); modem_signals[DISCONNECT_ERR] = g_signal_new("qvd-connection-disconnect-error", QVD_TYPE_MODEM, G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 2, QVD_TYPE_CONNECTION, G_TYPE_ERROR); } static void qvd_modem_initable_iface_init(GInitableIface *iface) { iface->init = qvd_modem_initable_init; } static void qvd_modem_init(QVDModem *self) { } static void create_bearer_ready(GObject *obj, GAsyncResult *res, gpointer data) { GTask *task = G_TASK(data); QVDConnection *conn; GError *err = NULL; MMBearer *bearer; bearer = mm_modem_create_bearer_finish(MM_MODEM(obj), res, &err); if (err != NULL) { g_printerr("Failed to create bearer: %s\n", err->message); g_task_return_error(task, err); goto err; } conn = QVD_CONNECTION(g_task_get_task_data(task)); qvd_connection_set_bearer(conn, bearer); g_task_return_boolean(task, TRUE); err: g_object_unref(task); } static gboolean is_bearer_listed(QVDConnection *conn, GVariant *bearers) { GVariantIter *iter; gchar *path; const gchar *conn_path; gboolean matched = FALSE; conn_path = qvd_connection_get_path(conn); if (conn_path == NULL) return TRUE; g_variant_get(bearers, "ao", &iter); while (g_variant_iter_loop(iter, "o", &path)) { if (!strcmp(path, conn_path)) { matched = TRUE; g_free(path); break; } } g_variant_iter_free(iter); return matched; } static void on_modem_props_changed(GDBusProxy *modem, GVariant *changed, char **invalidated, gpointer data) { struct qvd_bearer_config *config; QVDModem *ctx = QVD_MODEM(data); QVDConnection *conn; GHashTableIter tracked_bearers; GVariantIter *props; gpointer k, v; GVariant *prop; gchar *name; g_variant_get(changed, "a{sv}", &props); while (g_variant_iter_loop(props, "{sv}", &name, &prop)) { if (!strcmp(name, "Bearers")) break; } g_variant_iter_free(props); if (name == NULL || prop == NULL) return; g_free(name); g_hash_table_iter_init(&tracked_bearers, ctx->bearers); while (g_hash_table_iter_next(&tracked_bearers, &k, &v)) { config = k; conn = QVD_CONNECTION(v); if (!is_bearer_listed(conn, prop)) { g_signal_emit(ctx, modem_signals[ADDR_CHANGED], 0, QVD_CONNECTION(v), config->ip_type, NULL); g_hash_table_iter_remove(&tracked_bearers); g_warning("Bearer removed remotely"); } } g_variant_unref(prop); } static void on_object_added(QVDConnection *conn, GDBusObject *object, gpointer data) { MMModem *modem; const MMModemPortInfo *ports; struct qvd_pending_bearer *pending; guint n_ports = 0, i; gboolean is_qrtr = FALSE; QVDModem *ctx = QVD_MODEM(data); modem = mm_object_get_modem(MM_OBJECT(object)); if (modem == NULL) return; mm_modem_peek_ports(modem, &ports, &n_ports); for (i = 0; i < n_ports; i++) { if (ports[i].type == MM_MODEM_PORT_TYPE_QMI && !strcmp(ports[i].name, "qrtr0")) { is_qrtr = TRUE; break; } } if (is_qrtr) { g_info("New ModemManager QRTR modem detected: path: %s\n", mm_modem_get_path(modem)); ctx->modem = g_object_ref(modem); g_signal_connect(modem, "g-properties-changed", G_CALLBACK(on_modem_props_changed), ctx); for (i = 0; i < ctx->pending_bearers->len; i++) { pending = ctx->pending_bearers->pdata[i]; mm_modem_create_bearer(ctx->modem, pending->props, NULL, create_bearer_ready, pending->task); g_object_unref(pending->props); } g_ptr_array_unref(g_steal_pointer(&ctx->pending_bearers)); ctx->pending_bearers = g_ptr_array_new_full(0, g_free); } else { g_info("Ignoring new modem: path %s, not a qrtr modem.\n", mm_modem_get_path(modem)); } } static void send_bearer_disconnected(gpointer k, gpointer v, gpointer data) { struct qvd_bearer_config *config = k; QVDModem *ctx = QVD_MODEM(data); QVDConnection *conn = QVD_CONNECTION(v); g_signal_emit(ctx, modem_signals[ADDR_CHANGED], 0, conn, config->ip_type, NULL); } static void on_object_removed(QVDConnection *conn, GDBusObject *object, gpointer data) { QVDModem *ctx = QVD_MODEM(data); const gchar *removed_path, *path; removed_path = mm_object_get_path(MM_OBJECT(object)); path = mm_modem_get_path(ctx->modem); g_info("ModemManager removed object: path: %s\n", removed_path); if (strcmp(path, removed_path)) return; g_warning("ModemManager QRTR modem removed: path: %s\n", path); g_hash_table_foreach(ctx->bearers, send_bearer_disconnected, ctx); g_hash_table_remove_all(ctx->bearers); g_clear_object(&ctx->modem); } static void find_modem(gpointer memb, gpointer data) { MMModem **out = data; MMModem *modem; const MMModemPortInfo *ports; guint n_ports = 0, i; gboolean is_qrtr = FALSE; modem = mm_object_get_modem(memb); if (modem == NULL) return; mm_modem_peek_ports(modem, &ports, &n_ports); for (i = 0; i < n_ports; i++) { if (ports[i].type == MM_MODEM_PORT_TYPE_QMI && !strcmp(ports[i].name, "qrtr0")) { is_qrtr = TRUE; break; } } if (is_qrtr) *out = g_object_ref(modem); } static guint qvd_bearer_config_hash(gconstpointer key) { const struct qvd_bearer_config *conf = key; return g_int_hash(&conf->ip_type) ^ g_str_hash(conf->apn); } static gboolean qvd_bearer_config_equal(gconstpointer va, gconstpointer vb) { const struct qvd_bearer_config *a = va; const struct qvd_bearer_config *b = vb; return g_int_equal(&a->ip_type, &b->ip_type) && g_str_equal(a->apn, b->apn); } static gboolean qvd_modem_initable_init(GInitable *initable, GCancellable *cancellable, GError **out_err) { QVDModem *ctx = QVD_MODEM(initable); GError *err = NULL; GList *objs; ctx->dbus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, cancellable, &err); if (err != NULL) { g_propagate_error(out_err, err); return FALSE; } ctx->manager = mm_manager_new_sync(ctx->dbus, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, NULL, &err); if (err != NULL) { g_propagate_error(out_err, err); return FALSE; } objs = g_dbus_object_manager_get_objects(G_DBUS_OBJECT_MANAGER(ctx->manager)); g_list_foreach(objs, find_modem, &ctx->modem); g_list_free_full(objs, g_object_unref); if (ctx->modem != NULL) g_signal_connect(ctx->modem, "g-properties-changed", G_CALLBACK(on_modem_props_changed), ctx); else g_warning("ModemManager QRTR modem not detected on startup\n"); g_signal_connect(ctx->manager, "object-added", G_CALLBACK(on_object_added), ctx); g_signal_connect(ctx->manager, "object-removed", G_CALLBACK(on_object_removed), ctx); ctx->bearers = g_hash_table_new_full(qvd_bearer_config_hash, qvd_bearer_config_equal, g_free, g_object_unref); ctx->pending_bearers = g_ptr_array_new_full(0, g_free); return TRUE; } static void qvd_modem_dispose(GObject *obj) { QVDModem *ctx = QVD_MODEM(obj); if (ctx->bearers != NULL) g_hash_table_destroy(g_steal_pointer(&ctx->bearers)); if (ctx->pending_bearers != NULL) g_ptr_array_unref(g_steal_pointer(&ctx->pending_bearers)); g_clear_object(&ctx->manager); g_clear_object(&ctx->dbus); } QVDModem *qvd_modem_new(GError **err) { return g_initable_new(QVD_TYPE_MODEM, NULL, err, NULL); } static void on_address_changed(QVDConnection *conn, MMBearerIpFamily ip_type, const gchar *addr, gpointer data) { QVDModem *ctx = QVD_MODEM(data); g_signal_emit(ctx, modem_signals[ADDR_CHANGED], 0, conn, ip_type, addr); } static void on_connect_error(QVDConnection *conn, const GError *err, gpointer data) { QVDModem *ctx = QVD_MODEM(data); g_signal_emit(ctx, modem_signals[CONNECT_ERR], 0, conn, err); } static void on_disconnect_error(QVDConnection *conn, const GError *err, gpointer data) { QVDModem *ctx = QVD_MODEM(data); g_signal_emit(ctx, modem_signals[DISCONNECT_ERR], 0, conn, err); } gboolean qvd_modem_get_connection_finish(QVDModem *ctx, GAsyncResult *res, GError **err) { return g_task_propagate_boolean(G_TASK(res), err); } QVDConnection *qvd_modem_get_connection(QVDModem *ctx, const gchar *apn, MMBearerIpFamily ip_family, guint16 profile_idx_3gpp, GCancellable *cancellable, GAsyncReadyCallback cb, gpointer data) { struct qvd_bearer_config *conf; struct qvd_pending_bearer *pending; GTask *task; QVDConnection *conn; MMBearerProperties *props; g_assert(ctx != NULL); task = g_task_new(ctx, cancellable, cb, data); conf = g_malloc(sizeof(struct qvd_bearer_config)); conf->ip_type = ip_family; strncpy(conf->apn, apn, 255); conf->apn[255] = '\0'; if (!g_hash_table_contains(ctx->bearers, conf)) { conn = qvd_connection_new(ip_family); g_signal_connect(conn, "qvd-address-changed", G_CALLBACK(on_address_changed), ctx); g_signal_connect(conn, "qvd-connect-error", G_CALLBACK(on_connect_error), ctx); g_signal_connect(conn, "qvd-disconnect-error", G_CALLBACK(on_disconnect_error), ctx); g_hash_table_insert(ctx->bearers, conf, conn); props = mm_bearer_properties_new(); mm_bearer_properties_set_apn(props, apn); mm_bearer_properties_set_ip_type(props, ip_family); if (profile_idx_3gpp != 0xffff) mm_bearer_properties_set_profile_id(props, profile_idx_3gpp); g_task_set_task_data(task, conn, NULL); if (ctx->modem == NULL) { g_warning("Deferring connection until ModemManager QRTR modem can be detected\n"); pending = g_malloc(sizeof(*pending)); pending->props = props; pending->task = task; g_ptr_array_add(ctx->pending_bearers, pending); } else { mm_modem_create_bearer(ctx->modem, props, NULL, create_bearer_ready, task); g_object_unref(props); } } else { conn = g_hash_table_lookup(ctx->bearers, conf); g_task_return_boolean(task, true); g_free(conf); } return g_object_ref(conn); } 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/qvd-modem.h000066400000000000000000000014001517454273700226400ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (c) 2024, Richard Acayan. All rights reserved. */ #ifndef QVD_MODEM_H #define QVD_MODEM_H #include #include #include #include "qvd-connection.h" G_BEGIN_DECLS #define QVD_TYPE_MODEM qvd_modem_get_type() G_DECLARE_FINAL_TYPE(QVDModem, qvd_modem, QVD, MODEM, GObject) QVDModem *qvd_modem_new(GError **err); QVDConnection *qvd_modem_get_connection(QVDModem *ctx, const gchar *apn, MMBearerIpFamily ip_family, guint16 profile_idx_3gpp, GCancellable *cancellable, GAsyncReadyCallback cb, gpointer data); gboolean qvd_modem_get_connection_finish(QVDModem *ctx, GAsyncResult *res, GError **err); G_END_DECLS #endif /* QVD_MODEM_H */ 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/qvd-server.c000066400000000000000000000324431517454273700230530ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2024, Richard Acayan. All rights reserved. */ #include #include #include #include #include #include #include #include "qmi_imsd.h" #include "qvd-message.h" #include "qvd-modem.h" #include "qvd-server.h" #define IMSD_START_CONNECTION 0x20 #define IMSD_STOP_CONNECTION 0x21 #define IMSD_CONNECTION_CHANGED 0x20 enum imsd_address_family { IMSD_AF_IPV4 = 0, IMSD_AF_IPV6 = 1, }; enum imsd_profiles { IMSD_PROFILES_3GPP2 = 0, IMSD_PROFILES_3GPP = 1, IMSD_PROFILES_3GPP_3GPP2 = 2, }; struct qvd_connect_data { QVDServer *server; QVDConnection *conn; QVDMessage *msg; guint32 connection_id; guint32 subscription_id; }; struct _QVDServer { GObject parent_instance; GSocket *sock; GSource *source; GHashTable *clients; GPtrArray *conns; QVDModem *modem; gulong modem_sig; struct qrtr_packet outpkt; char *outbuf; guint16 ind_txn; }; static void qvd_server_initable_iface_init(GInitableIface *iface); static gboolean qvd_server_initable_init(GInitable *initable, GCancellable *cancellable, GError **out_err); static void qvd_server_dispose(GObject *obj); static gboolean receive_message(GSocket *sock, GIOCondition cond, gpointer data); static void connection_address_changed(QVDModem *modem, QVDConnection *conn, MMBearerIpFamily ip_type, const gchar *addr, gpointer data); G_DEFINE_TYPE_WITH_CODE(QVDServer, qvd_server, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE, qvd_server_initable_iface_init)) static void qvd_server_class_init(QVDServerClass *c) { GObjectClass *obj_class = G_OBJECT_CLASS(c); obj_class->dispose = qvd_server_dispose; } static void qvd_server_initable_iface_init(GInitableIface *iface) { iface->init = qvd_server_initable_init; } static void qvd_server_init(QVDServer *self) { } static gboolean qvd_server_initable_init(GInitable *initable, GCancellable *cancellable, GError **out_err) { QVDServer *server = QVD_SERVER(initable); GError *err = NULL; int fd, ret; server->ind_txn = 1; server->outbuf = g_malloc(65536); fd = qrtr_open(0); if (fd == -1) { g_set_error(out_err, G_FILE_ERROR, G_FILE_ERROR_FAILED, "QRTR open failed"); return FALSE; } server->sock = g_socket_new_from_fd(fd, &err); if (server->sock == NULL) { g_propagate_error(out_err, err); qrtr_close(fd); return FALSE; } server->source = g_socket_create_source(server->sock, G_IO_IN, cancellable); g_source_set_callback(server->source, G_SOURCE_FUNC(receive_message), server, NULL); g_source_attach(server->source, NULL); server->conns = g_ptr_array_new_full(0, g_object_unref); server->clients = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL); ret = qrtr_new_server(fd, 770, 1, 0); if (ret) { // NOPUSH g_set_error(out_err, G_FILE_ERROR, G_FILE_ERROR_FAILED, "QRTR server publish failed"); return FALSE; } return TRUE; } static void qvd_server_dispose(GObject *obj) { QVDServer *server = QVD_SERVER(obj); GSource *src; if (server->clients != NULL) g_hash_table_destroy(g_steal_pointer(&server->clients)); if (server->conns != NULL) g_ptr_array_unref(g_steal_pointer(&server->conns)); if (server->source != NULL) { src = g_steal_pointer(&server->source); g_source_destroy(src); g_source_unref(src); } if (server->outbuf != NULL) g_free(g_steal_pointer(&server->outbuf)); // Close the socket and decrease the modem reference counter. g_clear_object(&server->sock); g_clear_object(&server->modem); } QVDServer *qvd_server_new(QVDModem *modem, GError **out_err) { QVDServer *server; GError *err = NULL; g_assert(modem != NULL); server = g_initable_new(QVD_TYPE_SERVER, NULL, &err, NULL); if (err != NULL) { g_propagate_error(out_err, err); return NULL; } server->modem = g_object_ref(modem); server->modem_sig = g_signal_connect(server->modem, "qvd-connection-address-changed", G_CALLBACK(connection_address_changed), server); return server; } static void encode_error(QVDMessage *msg, guint16 code) { struct imsd_no_op_resp resp; GError *err = NULL; resp.res.err_status = 1; resp.res.err_code = code; g_info("Resp: with error: err_status: %d, err_code: %d\n", resp.res.err_status, resp.res.err_code); qvd_message_respond(msg, &resp, imsd_no_op_resp_ei, &err); if (err != NULL) g_printerr("IMSD Error: failed to send error response: %s\n", err->message); } static void process_no_op(unsigned int msg_id, QVDMessage *msg) { struct imsd_no_op_req req; struct imsd_no_op_resp resp = { .res = { .err_status = 0, .err_code = 0, }, }; GError *err = NULL; g_info("Fallback handler for unknown message %d\n", msg_id); qvd_message_decode(msg, &req, imsd_no_op_req_ei, &err); if (err != NULL) { g_printerr("IMSD No Operation: failed to decode request: %s\n", err->message); } qvd_message_respond(msg, &resp, imsd_no_op_resp_ei, &err); if (err != NULL) g_printerr("IMSD No Operation: failed to send response: %s\n", err->message); g_object_unref(msg); } static void register_connection(QVDServer *server, QVDConnection *conn, guint32 connection, guint32 subscription) { guint i; for (i = 0; i < server->conns->len; i++) { if (server->conns->pdata[i] == NULL) { server->conns->pdata[i] = conn; break; } } if (i == server->conns->len) g_ptr_array_add(server->conns, conn); qvd_connection_set_handles(conn, connection, subscription, i); } static void on_connection_opened(GObject *obj, GAsyncResult *res, gpointer data) { GError *err = NULL; struct qvd_connect_data *connect_data = data; struct imsd_start_connection_resp resp; guint8 local_id; gboolean success; success = qvd_modem_get_connection_finish(QVD_MODEM(obj), res, &err); if (!success) { g_printerr("IMSD Start Connection: failed to create bearer: %s\n", err->message); encode_error(connect_data->msg, 1); goto err; } qvd_connection_connect(connect_data->conn); register_connection(connect_data->server, connect_data->conn, connect_data->connection_id, connect_data->subscription_id); qvd_connection_get_handles(connect_data->conn, NULL, NULL, &local_id); resp.res.err_status = 0; resp.res.err_code = 0; resp.connection = local_id; resp.orig_conn_id = connect_data->connection_id; resp.subscription = connect_data->subscription_id; g_info("Resp: Start Connection, local_id %d, ims conn %d, subscription %d\n", resp.connection, resp.connection, resp.subscription); qvd_message_respond(connect_data->msg, &resp, imsd_start_connection_resp_ei, &err); if (err != NULL) { g_printerr("IMSD Start Connection: failed to send response: %s\n", err->message); g_clear_error(&err); } err: g_object_unref(connect_data->server); g_object_unref(connect_data->msg); g_free(connect_data); } static void process_start_connection(QVDServer *server, QVDMessage *msg) { MMBearerIpFamily ip_family; QVDConnection *conn; GError *err = NULL; struct imsd_start_connection_req req; struct qvd_connect_data *connect_data; gint *client; guint node, port; g_info("Req: Start Connection received\n"); qvd_message_decode(msg, &req, imsd_start_connection_req_ei, &err); if (err != NULL) { g_printerr("IMSD Start Connection: failed to decode request: %s\n", err->message); g_clear_error(&err); encode_error(msg, 1); return; } if (req.conn_params.ip_family == IMSD_AF_IPV4) { g_info("Req: Start connection, conn %d, sub %d, type: IPv4, apn: %s\n", req.connection, req.subscription, req.conn_params.apn); ip_family = MM_BEARER_IP_FAMILY_IPV4; } else if (req.conn_params.ip_family == IMSD_AF_IPV6) { g_info("Req: Start connection, conn %d, sub %d, type: IPv6, apn: %s\n", req.connection, req.subscription, req.conn_params.apn); ip_family = MM_BEARER_IP_FAMILY_IPV6; } else { g_printerr("IMSD Start Connection: unknown IP family: %u\n", req.conn_params.ip_family); g_clear_error(&err); encode_error(msg, 1); return; } // Register the client for indications. g_object_get(msg, "peer-node", &node, "peer-port", &port, NULL); client = g_malloc(sizeof(gint)); *client = (node << 16) | port; g_hash_table_add(server->clients, client); connect_data = g_malloc(sizeof(*connect_data)); connect_data->msg = msg; connect_data->server = g_object_ref(server); conn = qvd_modem_get_connection(server->modem, req.conn_params.apn, ip_family, req.conn_params.profile_idx_3gpp, NULL, on_connection_opened, connect_data); if (conn == NULL) { g_printerr("IMSD Start Connection: modem not present\n"); g_clear_error(&err); encode_error(msg, 1); g_free(connect_data); return; } connect_data->conn = conn; connect_data->connection_id = req.connection; connect_data->subscription_id = req.subscription; } static void process_stop_connection(QVDServer *server, QVDMessage *msg) { QVDConnection *conn; GError *err = NULL; struct imsd_stop_connection_req req; struct imsd_stop_connection_resp resp; gint *client; guint node, port; qvd_message_decode(msg, &req, imsd_stop_connection_req_ei, &err); g_info("Req: Stop connection, conn %d, unknown field %d\n", req.connection, req.unkecho_01); if (err != NULL) { g_printerr("IMSD Stop Connection: failed to decode request: %s\n", err->message); g_clear_error(&err); encode_error(msg, 1); goto err; } if (req.connection >= server->conns->len || server->conns->pdata[req.connection] == NULL) { g_printerr("IMSD Stop Connection: unknown connection ID %u\n", req.connection); encode_error(msg, 9); goto err; } // Register the client for indications. g_object_get(msg, "peer-node", &node, "peer-port", &port, NULL); client = g_malloc(sizeof(gint)); *client = (node << 16) | port; g_hash_table_add(server->clients, client); conn = g_steal_pointer(&server->conns->pdata[req.connection]); qvd_connection_disconnect(conn); g_object_unref(conn); resp.res.err_status = 0; resp.res.err_code = 0; resp.unkfield_FA = 0xFA; resp.unkecho_01 = req.unkecho_01; qvd_message_respond(msg, &resp, imsd_stop_connection_resp_ei, &err); if (err != NULL) { g_printerr("IMSD Stop Connection: failed to send response: %s\n", err->message); g_clear_error(&err); } err: g_object_unref(msg); } static void process_message(QVDServer *server, QVDMessage *msg) { guint msg_id; msg_id = qvd_message_get_msg_id(msg); g_info("Processing QMI message %d\n", msg_id); if (msg_id == IMSD_START_CONNECTION) process_start_connection(server, msg); else if (msg_id == IMSD_STOP_CONNECTION) process_stop_connection(server, msg); else process_no_op(msg_id, msg); } static gboolean receive_message(GSocket *sock, GIOCondition cond, gpointer data) { QVDServer *server = QVD_SERVER(data); QVDMessage *msg; struct sockaddr_qrtr peer = { .sq_family = AF_QIPCRTR, }; struct qrtr_packet *req; gint *client; int fd, inlen; fd = g_socket_get_fd(sock); req = g_malloc(sizeof(*req)); req->data_len = 65536; req->data = g_malloc(req->data_len); inlen = qrtr_recvfrom(fd, req->data, 65536, &peer.sq_node, &peer.sq_port); if (inlen < 0) return TRUE; qrtr_decode(req, req->data, inlen, &peer); g_debug("Received QRTR message %d length %d\n", req->type, inlen); if (req->type == QRTR_TYPE_DATA) { msg = qvd_message_new(g_object_ref(server->sock), req, peer.sq_node, peer.sq_port); process_message(server, msg); } else if (req->type == QRTR_TYPE_DEL_CLIENT) { client = g_malloc(sizeof(gint)); *client = (req->node << 16) | req->port; g_hash_table_remove(server->clients, client); g_free(client); g_free(req->data); g_free(req); } return TRUE; } static void send_staged_message(gpointer k, gpointer v, gpointer data) { QVDServer *server = QVD_SERVER(data); guint *addr = k; uint16_t node = *addr >> 16; uint16_t port = *addr & 0xFFFF; int fd; // The MSG_NOSIGNAL flag is not supported by the QRTR kernel driver. fd = g_socket_get_fd(server->sock); qrtr_sendto(fd, node, port, server->outpkt.data, server->outpkt.data_len); } static void connection_address_changed(QVDModem *modem, QVDConnection *conn, MMBearerIpFamily ip_type, const gchar *addr, gpointer data) { QVDServer *server = QVD_SERVER(data); struct imsd_connection_changed_ind ind; guint32 conn_id, sub_id; guint8 local_id; g_assert(ip_type == MM_BEARER_IP_FAMILY_IPV4 || ip_type == MM_BEARER_IP_FAMILY_IPV6); qvd_connection_get_handles(conn, &conn_id, &sub_id, &local_id); server->outpkt.data = server->outbuf; server->outpkt.data_len = 65536; g_info("QMI Connection Address Changed: local_id: %d, conn_id: %d, sub: %d, type: %d, addr: %s\n", local_id, conn_id, sub_id, ip_type, addr); ind.res.err_status = 0; ind.connection = local_id; ind.orig_conn_id = conn_id; ind.subscription = sub_id; if (addr != NULL) { ind.res.err_code = 0; ind.ip_addr_valid = true; strncpy(ind.ip_addr.addr, addr, 255); ind.ip_addr.addr[255] = '\0'; if (ip_type == MM_BEARER_IP_FAMILY_IPV4) ind.ip_addr.family = IMSD_AF_IPV4; else if (ip_type == MM_BEARER_IP_FAMILY_IPV6) ind.ip_addr.family = IMSD_AF_IPV6; } else { ind.res.err_code = 13; ind.ip_addr_valid = false; } qmi_encode_message(&server->outpkt, QMI_INDICATION, IMSD_CONNECTION_CHANGED, server->ind_txn, &ind, imsd_connection_changed_ind_ei); server->ind_txn++; g_hash_table_foreach(server->clients, send_staged_message, server); } 81voltd-v1.2.0-7c0cd9442d71b55260c9917c89ebc4bd20e283a8/qvd-server.h000066400000000000000000000010071517454273700230500ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (c) 2024, Richard Acayan. All rights reserved. */ #ifndef QVD_SERVER_H #define QVD_SERVER_H #include #include #include "qvd-modem.h" G_BEGIN_DECLS #define QVD_TYPE_SERVER qvd_server_get_type() G_DECLARE_FINAL_TYPE(QVDServer, qvd_server, QVD, SERVER, GObject) QVDServer *qvd_server_new(QVDModem *modem, GError **err); void qvd_server_set_modem(QVDServer *server, QVDModem *modem); G_END_DECLS #endif /* QVD_SERVER_H */