├── .gitattributes ├── .gitignore ├── Dockerfile ├── HBlink.png ├── HBlink.svg ├── LICENSE.txt ├── README.md ├── bridge.py ├── bridge_all.py ├── config.py ├── const.py ├── docker-compose.yml ├── entrypoint ├── hblink-SAMPLE.cfg ├── hblink.py ├── log.py ├── mk_voice.py ├── play_ambe.py ├── playback.py ├── reporting_const.py ├── requirements.txt ├── rules_SAMPLE.py └── voice_lib.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | 91 | .DS_Store 92 | hblink.cfg 93 | *.config 94 | *.bak 95 | rules.py 96 | subscriber_ids.* 97 | local_subscriber_ids.* 98 | peer_ids.* 99 | local_peer_ids.* 100 | talkgroup_ids.* 101 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.9-alpine 2 | 3 | COPY entrypoint /entrypoint 4 | 5 | RUN adduser -D -u 54000 radio && \ 6 | apk update && \ 7 | apk add git gcc musl-dev && \ 8 | cd /opt && \ 9 | git clone https://github.com/ShaYmez/hblink3 && \ 10 | cd /opt/hblink3 && \ 11 | pip install --no-cache-dir -r requirements.txt && \ 12 | apk del git gcc musl-dev && \ 13 | chown -R radio: /opt/hblink3 14 | 15 | USER radio 16 | 17 | ENTRYPOINT [ "/entrypoint" ] 18 | -------------------------------------------------------------------------------- /HBlink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HBLink-org/hblink3/f68fbdd26a04d511d49016c80082ba22e14f31cb/HBlink.png -------------------------------------------------------------------------------- /HBlink.svg: -------------------------------------------------------------------------------- 1 | 2 | 17 | 44 | 46 | 75 | 76 | 78 | 79 | 80 | 109 | 110 | 112 | 113 | 114 | 115 | Produced by OmniGraffle 7.12.1 117 | 2018-03-14 13:37:44 +0000 118 | 119 | 121 | image/svg+xml 122 | 124 | 125 | 126 | 127 | 128 | 136 | Canvas 2 138 | 140 | Layer 1 142 | 144 | 146 | path6007 148 | 156 | 157 | 159 | 164 | 169 | 174 | 175 | 176 | 178 | 183 | 188 | 193 | 198 | 203 | 204 | 205 | 207 | 212 | 213 | 215 | path6381 217 | 225 | 226 | 228 | 233 | 234 | 236 | 241 | 242 | 243 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 3, 29 June 2007 4 | 5 | Copyright © 2007 Free Software Foundation, Inc. 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 12 | 13 | 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. 14 | 15 | 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. 16 | 17 | 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. 18 | 19 | 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. 20 | 21 | 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. 22 | 23 | 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. 24 | 25 | 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. 26 | 27 | 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. 28 | 29 | The precise terms and conditions for copying, distribution and modification follow. 30 | 31 | TERMS AND CONDITIONS 32 | 33 | 0. Definitions. 34 | 35 | “This License” refers to version 3 of the GNU General Public License. 36 | 37 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 38 | 39 | “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. 40 | 41 | 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. 42 | 43 | A “covered work” means either the unmodified Program or a work based on the Program. 44 | 45 | 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. 46 | 47 | 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. 48 | 49 | 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. 50 | 51 | 1. Source Code. 52 | 53 | 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. 54 | 55 | 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. 56 | 57 | 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. 58 | 59 | 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. 60 | 61 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 62 | 63 | The Corresponding Source for a work in source code form is that same work. 64 | 65 | 2. Basic Permissions. 66 | 67 | 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. 68 | 69 | 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. 70 | 71 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 72 | 73 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 74 | 75 | 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. 76 | 77 | 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. 78 | 79 | 4. Conveying Verbatim Copies. 80 | 81 | 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. 82 | 83 | 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. 84 | 85 | 5. Conveying Modified Source Versions. 86 | 87 | 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: 88 | 89 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 90 | 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”. 91 | 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. 92 | 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. 93 | 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. 94 | 95 | 6. Conveying Non-Source Forms. 96 | 97 | 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: 98 | 99 | 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. 100 | 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. 101 | 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. 102 | 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. 103 | 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. 104 | 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. 105 | 106 | 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. 107 | 108 | “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. 109 | 110 | 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). 111 | 112 | 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. 113 | 114 | 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. 115 | 116 | 7. Additional Terms. 117 | 118 | “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. 119 | 120 | 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. 121 | 122 | 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: 123 | 124 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 125 | 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 126 | 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 127 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or 128 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 129 | 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. 130 | 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. 131 | 132 | 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. 133 | 134 | 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. 135 | 136 | 8. Termination. 137 | 138 | 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). 139 | 140 | 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. 141 | 142 | 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. 143 | 144 | 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. 145 | 146 | 9. Acceptance Not Required for Having Copies. 147 | 148 | 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. 149 | 150 | 10. Automatic Licensing of Downstream Recipients. 151 | 152 | 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. 153 | 154 | 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. 155 | 156 | 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. 157 | 158 | 11. Patents. 159 | 160 | 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”. 161 | 162 | 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. 163 | 164 | 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. 165 | 166 | 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. 167 | 168 | 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. 169 | 170 | 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. 171 | 172 | 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. 173 | 174 | 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. 175 | 176 | 12. No Surrender of Others' Freedom. 177 | 178 | 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. 179 | 180 | 13. Use with the GNU Affero General Public License. 181 | 182 | 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. 183 | 184 | 14. Revised Versions of this License. 185 | 186 | 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. 187 | 188 | 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. 189 | 190 | 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. 191 | 192 | 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. 193 | 194 | 15. Disclaimer of Warranty. 195 | 196 | 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. 197 | 198 | 16. Limitation of Liability. 199 | 200 | 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. 201 | 202 | 17. Interpretation of Sections 15 and 16. 203 | 204 | 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. 205 | 206 | END OF TERMS AND CONDITIONS 207 | 208 | How to Apply These Terms to Your New Programs 209 | 210 | 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. 211 | 212 | 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. 213 | 214 | 215 | Copyright (C) 216 | 217 | This program is free software: you can redistribute it and/or modify 218 | it under the terms of the GNU General Public License as published by 219 | the Free Software Foundation, either version 3 of the License, or 220 | (at your option) any later version. 221 | 222 | This program is distributed in the hope that it will be useful, 223 | but WITHOUT ANY WARRANTY; without even the implied warranty of 224 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 225 | GNU General Public License for more details. 226 | 227 | You should have received a copy of the GNU General Public License 228 | along with this program. If not, see . 229 | Also add information on how to contact you by electronic and paper mail. 230 | 231 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: 232 | 233 | Copyright (C) 234 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 235 | This is free software, and you are welcome to redistribute it 236 | under certain conditions; type `show c' for details. 237 | 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”. 238 | 239 | 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 . 240 | 241 | 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 . 242 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | --- 2 | ### FOR SUPPORT, DISCUSSION, GETTING INVOLVED ### 3 | 4 | Please join the DVSwitch group at groups.io for online forum support, discussion, and to become part of the development team. 5 | 6 | DVSwitch@groups.io 7 | 8 | A voluntary registrty for HBlink systems with public access has been created at http://hblink-register.com.es Please consider listing your system if you allow open access. 9 | 10 | --- 11 | 12 | ## PROJECT: Open Source HomeBrew Repeater Protocol Client/Master. ## 13 | 14 | **UPDATES:** 15 | 16 | **PURPOSE:** Thanks to the work of Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT we have an open protocol for internetworking DMR repeaters. Unfortunately, there's no generic client and/or master stacks. This project is to build an open-source, python-based implementation. You are free to use this software however you want, however we ask that you provide attribution in some public venue (such as project, club, organization web site). This helps us see where the software is in use and track how it is used. 17 | 18 | For those who will ask: This is a piece of software that implements an open-source, amateur radio networking protocol. It is not a network. It is not intended to be a network. It is not intended to replace or circumvent a network. People do those things, code doesn't. 19 | 20 | **PROPERTY:** 21 | This work represents the author's interpretation of the HomeBrew Repeater Protocol, based on the 2015-07-26 documents from DMRplus, "IPSC Protocol Specs for homebrew DMR repeater" as written by Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT, also licenced under Creative Commons BY-NC-SA license. 22 | 23 | **WARRANTY** 24 | None. The owners of this work make absolutely no warranty, express or implied. Use this software at your own risk. 25 | 26 | **PRE-REQUISITE KNOWLEDGE:** 27 | This document assumes the reader is familiar with Linux/UNIX, the Python programming language and DMR. 28 | 29 | **Using docker version** 30 | 31 | Docker file included for own image build 32 | To work with provided docker setup you will need: 33 | * A private repository with your configuration files (all .cfg files in repo will be copyed to the application root directory on start up) 34 | * A service user able to read your private repository (or be brave and publish your configuration, or be really brave and give your username and password to the docker) 35 | * A server with docker installed 36 | * Follow this simple steps: 37 | 38 | Build your own image from source 39 | 40 | ```bash 41 | 42 | docker build . -t hblink3/hblink3:latest 43 | 44 | ``` 45 | 46 | Or user a prebuilt one in docker hub: shaymez/hblink3:latest 47 | This image is multi-arch 48 | 49 | Wake up your container 50 | 51 | ```bash 52 | touch /var/log/hblink.log 53 | chown 54000 -R /var/log/hblink.log 54 | run -v /var/log/hblink/hblink.log:/var/log/hblink/hblink.log -e GIT_USER=$USER -e GIT_PASSWORD=$PASSWORD -e GIT_REPO=$URL_TO_REPO_WITHOUT_HTTPS:// -p 54000:54000 shaymez/hblink3:latest 55 | ``` 56 | 57 | **MORE DOCUMENTATION TO COME** 58 | 59 | ***0x49 DE N0MJS*** 60 | 61 | Copyright (C) 2016-2020 Cortney T. Buffington, N0MJS n0mjs@me.com 62 | 63 | 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. 64 | 65 | 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. 66 | 67 | 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 68 | -------------------------------------------------------------------------------- /bridge_all.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | ############################################################################### 4 | # Copyright (C) 2016-2019 Cortney T. Buffington, N0MJS 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software Foundation, 18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | ############################################################################### 20 | 21 | ''' 22 | This is a very simple call/packet router for Homebrew Repeater Protocol. It 23 | will forward traffic from any system to all other systems configured in the 24 | hblink.py configuration file. It does not check for call contentions or 25 | filter TS/TGID combinations. It should really only be used as a proxy to 26 | hide multiple Homebrew repater protocol systems behind what appears as a single 27 | repeater, hotspot, etc. 28 | 29 | As is, this program only works with group voice packets. It could work for all 30 | of them by removing a few things. 31 | 32 | IT ONLY WORKS FOR HBP SYSTEMS!!! Using it with OpenBridge or XLX wouldn't make 33 | a lot of sense, and has the potential to do bad things. 34 | ''' 35 | 36 | # Python modules we need 37 | import sys 38 | from bitarray import bitarray 39 | from time import time 40 | from importlib import import_module 41 | from types import ModuleType 42 | 43 | # Twisted is pretty important, so I keep it separate 44 | from twisted.internet.protocol import Factory, Protocol 45 | from twisted.protocols.basic import NetstringReceiver 46 | from twisted.internet import reactor, task 47 | 48 | # Things we import from the main hblink module 49 | from hblink import HBSYSTEM, OPENBRIDGE, systems, hblink_handler, reportFactory, REPORT_OPCODES, config_reports, mk_aliases, acl_check 50 | from dmr_utils3.utils import bytes_3, int_id, get_alias 51 | from dmr_utils3 import decode, bptc, const 52 | import config 53 | import log 54 | import const 55 | 56 | # The module needs logging logging, but handlers, etc. are controlled by the parent 57 | import logging 58 | logger = logging.getLogger(__name__) 59 | 60 | 61 | # Does anybody read this stuff? There's a PEP somewhere that says I should do this. 62 | __author__ = 'Cortney T. Buffington, N0MJS' 63 | __copyright__ = 'Copyright (c) 2016-2018 Cortney T. Buffington, N0MJS and the K0USY Group' 64 | __credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT' 65 | __license__ = 'GNU GPLv3' 66 | __maintainer__ = 'Cort Buffington, N0MJS' 67 | __email__ = 'n0mjs@me.com' 68 | __status__ = 'pre-alpha' 69 | 70 | # Module gobal varaibles 71 | 72 | 73 | class bridgeallSYSTEM(HBSYSTEM): 74 | 75 | def __init__(self, _name, _config, _report): 76 | HBSYSTEM.__init__(self, _name, _config, _report) 77 | self._laststrid = '' 78 | 79 | # Status information for the system, TS1 & TS2 80 | # 1 & 2 are "timeslot" 81 | self.STATUS = { 82 | 1: { 83 | 'RX_START': time(), 84 | 'RX_LOSS': 0, 85 | 'RX_SEQ': 0, 86 | 'RX_RFS': b'\x00', 87 | 'TX_RFS': b'\x00', 88 | 'RX_STREAM_ID': b'\x00', 89 | 'TX_STREAM_ID': b'\x00', 90 | 'RX_TGID': b'\x00\x00\x00', 91 | 'TX_TGID': b'\x00\x00\x00', 92 | 'RX_TIME': time(), 93 | 'TX_TIME': time(), 94 | 'RX_TYPE': const.HBPF_SLT_VTERM, 95 | }, 96 | 2: { 97 | 'RX_START': time(), 98 | 'RX:LOSS': 0, 99 | 'RX_SEQ': 0, 100 | 'RX_RFS': b'\x00', 101 | 'TX_RFS': b'\x00', 102 | 'RX_STREAM_ID': b'\x00', 103 | 'TX_STREAM_ID': b'\x00', 104 | 'RX_TGID': b'\x00\x00\x00', 105 | 'TX_TGID': b'\x00\x00\x00', 106 | 'RX_TIME': time(), 107 | 'TX_TIME': time(), 108 | 'RX_TYPE': const.HBPF_SLT_VTERM, 109 | } 110 | } 111 | 112 | def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): 113 | pkt_time = time() 114 | dmrpkt = _data[20:53] 115 | _bits = _data[15] 116 | 117 | if _call_type == 'group': 118 | 119 | # Is this is a new call stream? 120 | new_stream = (_stream_id != self.STATUS[_slot]['RX_STREAM_ID']) 121 | 122 | if new_stream: 123 | self.STATUS[_slot]['RX_START'] = pkt_time 124 | self.STATUS[_slot]['RX_LOSS'] = 0 125 | self.STATUS[_slot]['RX_SEQ'] = _seq 126 | logger.info('(%s) *CALL START* STREAM ID: %s SUB: %s (%s) PEER: %s (%s) TGID %s (%s), TS %s', \ 127 | self._system, int_id(_stream_id), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot) 128 | else: 129 | # This could be much better, it will have errors during roll-over 130 | if _seq > (self.STATUS[_slot]['RX_SEQ'] + 1): 131 | #print(_seq, self.STATUS[_slot]['RX_SEQ']) 132 | self.STATUS[_slot]['RX_LOSS'] += _seq - (self.STATUS[_slot]['RX_SEQ'] + 1) 133 | 134 | # Final actions - Is this a voice terminator? 135 | if (_frame_type == const.HBPF_DATA_SYNC) and (_dtype_vseq == const.HBPF_SLT_VTERM) and (self.STATUS[_slot]['RX_TYPE'] != const.HBPF_SLT_VTERM): 136 | call_duration = pkt_time - self.STATUS[_slot]['RX_START'] 137 | logger.info('(%s) *CALL END* STREAM ID: %s SUB: %s (%s) PEER: %s (%s) TGID %s (%s), TS %s, Loss: %s, Duration: %s', \ 138 | self._system, int_id(_stream_id), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot, self.STATUS[_slot]['RX_LOSS'], call_duration) 139 | 140 | 141 | for _target in self._CONFIG['SYSTEMS']: 142 | if _target != self._system: 143 | 144 | _target_status = systems[_target].STATUS 145 | _target_system = self._CONFIG['SYSTEMS'][_target] 146 | 147 | # BEGIN STANDARD CONTENTION HANDLING 148 | # 149 | # The rules for each of the 4 "ifs" below are listed here for readability. The Frame To Send is: 150 | # From a different group than last RX from this HBSystem, but it has been less than Group Hangtime 151 | # From a different group than last TX to this HBSystem, but it has been less than Group Hangtime 152 | # From the same group as the last RX from this HBSystem, but from a different subscriber, and it has been less than stream timeout 153 | # From the same group as the last TX to this HBSystem, but from a different subscriber, and it has been less than stream timeout 154 | # The "continue" at the end of each means the next iteration of the for loop that tests for matching rules 155 | # 156 | if ((_dst_id != _target_status[_slot]['RX_TGID']) and ((pkt_time - _target_status[_slot]['RX_TIME']) < _target_system['GROUP_HANGTIME'])): 157 | if _frame_type == const.HBPF_DATA_SYNC and _dtype_vseq == const.HBPF_SLT_VHEAD and self.STATUS[_slot]['RX_STREAM_ID'] != _stream_id: 158 | logger.info('(%s) Call not routed to TGID %s, target active or in group hangtime: HBSystem: %s, TS: %s, TGID: %s', self._system, int_id(_dst_id), _target, _slot, int_id(_target_status[_slot]['RX_TGID'])) 159 | continue 160 | if ((_dst_id != _target_status[_slot]['TX_TGID']) and ((pkt_time - _target_status[_slot]['TX_TIME']) < _target_system['GROUP_HANGTIME'])): 161 | if _frame_type == const.HBPF_DATA_SYNC and _dtype_vseq == const.HBPF_SLT_VHEAD and self.STATUS[_slot]['RX_STREAM_ID'] != _stream_id: 162 | logger.info('(%s) Call not routed to TGID%s, target in group hangtime: HBSystem: %s, TS: %s, TGID: %s', self._system, int_id(_dst_id), _target, _slot, int_id(_target_status[_slot]['TX_TGID'])) 163 | continue 164 | if (_dst_id == _target_status[_slot]['RX_TGID']) and ((pkt_time - _target_status[_slot]['RX_TIME']) < const.STREAM_TO): 165 | if _frame_type == const.HBPF_DATA_SYNC and _dtype_vseq == const.HBPF_SLT_VHEAD and self.STATUS[_slot]['RX_STREAM_ID'] != _stream_id: 166 | logger.info('(%s) Call not routed to TGID%s, matching call already active on target: HBSystem: %s, TS: %s, TGID: %s', self._system, int_id(_dst_id), _target, _slot, int_id(_target_status[_slot]['RX_TGID'])) 167 | continue 168 | if (_dst_id == _target_status[_slot]['TX_TGID']) and (_rf_src != _target_status[_slot]['TX_RFS']) and ((pkt_time - _target_status[_slot]['TX_TIME']) < const.STREAM_TO): 169 | if _frame_type == const.HBPF_DATA_SYNC and _dtype_vseq == const.HBPF_SLT_VHEAD and self.STATUS[_slot]['RX_STREAM_ID'] != _stream_id: 170 | logger.info('(%s) Call not routed for subscriber %s, call route in progress on target: HBSystem: %s, TS: %s, TGID: %s, SUB: %s', self._system, int_id(_rf_src), _target, _slot, int_id(_target_status[_slot]['TX_TGID']), int_id(_target_status[_slot]['TX_RFS'])) 171 | continue 172 | 173 | 174 | # ACL Processing 175 | if self._CONFIG['GLOBAL']['USE_ACL']: 176 | if not acl_check(_rf_src, self._CONFIG['GLOBAL']['SUB_ACL']): 177 | if _stream_id != _target_status[_slot]['TX_STREAM_ID']: 178 | logger.info('(%s) CALL DROPPED ON EGRESS WITH STREAM ID %s FROM SUBSCRIBER %s BY GLOBAL ACL', _target, int_id(_stream_id), int_id(_rf_src)) 179 | _target_status[_slot]['TX_STREAM_ID'] = _stream_id 180 | continue 181 | if _slot == 1 and not acl_check(_dst_id, self._CONFIG['GLOBAL']['TG1_ACL']): 182 | if _stream_id != _target_status[_slot]['TX_STREAM_ID']: 183 | logger.info('(%s) CALL DROPPED ON EGRESS WITH STREAM ID %s ON TGID %s BY GLOBAL TS1 ACL', _target, int_id(_stream_id), int_id(_dst_id)) 184 | _target_status[_slot]['TX_STREAM_ID'] = _stream_id 185 | continue 186 | if _slot == 2 and not acl_check(_dst_id, self._CONFIG['GLOBAL']['TG2_ACL']): 187 | if _stream_id != _target_status[_slot]['TX_STREAM_ID']: 188 | logger.info('(%s) CALL DROPPED ON EGRESS WITH STREAM ID %s ON TGID %s BY GLOBAL TS2 ACL', _target, int_id(_stream_id), int_id(_dst_id)) 189 | _target_status[_slot]['TX_STREAM_ID'] = _stream_id 190 | continue 191 | if _target_system['USE_ACL']: 192 | if not acl_check(_rf_src, _target_system['SUB_ACL']): 193 | if _stream_id != _target_status[_slot]['TX_STREAM_ID']: 194 | logger.info('(%s) CALL DROPPED ON EGRESS WITH STREAM ID %s FROM SUBSCRIBER %s BY SYSTEM ACL', _target, int_id(_stream_id), int_id(_rf_src)) 195 | _target_status[_slot]['TX_STREAM_ID'] = _stream_id 196 | continue 197 | if _slot == 1 and not acl_check(_dst_id, _target_system['TG1_ACL']): 198 | if _stream_id != _target_status[_slot]['TX_STREAM_ID']: 199 | logger.info('(%s) CALL DROPPED ON EGRESS WITH STREAM ID %s ON TGID %s BY SYSTEM TS1 ACL', _target, int_id(_stream_id), int_id(_dst_id)) 200 | _target_status[_slot]['TX_STREAM_ID'] = _stream_id 201 | continue 202 | if _slot == 2 and not acl_check(_dst_id, _target_system['TG2_ACL']): 203 | if _stream_id != _target_status[_slot]['TX_STREAM_ID']: 204 | logger.info('(%s) CALL DROPPED ON EGRESS WITH STREAM ID %s ON TGID %s BY SYSTEM TS2 ACL', _target, int_id(_stream_id), int_id(_dst_id)) 205 | _target_status[_slot]['TX_STREAM_ID'] = _stream_id 206 | continue 207 | 208 | # Record this stuff for later 209 | # Is this a new call stream? 210 | if new_stream: 211 | # Record the DST TGID and Stream ID 212 | _target_status[_slot]['TX_START'] = pkt_time 213 | _target_status[_slot]['TX_TGID'] = _dst_id 214 | _target_status[_slot]['TX_RFS'] = _rf_src 215 | _target_status[_slot]['TX_PEER'] = _peer_id 216 | _target_status[_slot]['TX_STREAM_ID'] = _stream_id 217 | 218 | _target_status[_slot]['TX_TIME'] = pkt_time 219 | 220 | systems[_target].send_system(_data) 221 | #logger.debug('(%s) Packet routed to system: %s', self._system, _target) 222 | 223 | # Mark status variables for use later 224 | self.STATUS[_slot]['RX_RFS'] = _rf_src 225 | self.STATUS[_slot]['RX_SEQ'] = _seq 226 | self.STATUS[_slot]['RX_TYPE'] = _dtype_vseq 227 | self.STATUS[_slot]['RX_TGID'] = _dst_id 228 | self.STATUS[_slot]['RX_TIME'] = pkt_time 229 | self.STATUS[_slot]['RX_STREAM_ID'] = _stream_id 230 | 231 | 232 | #************************************************ 233 | # MAIN PROGRAM LOOP STARTS HERE 234 | #************************************************ 235 | 236 | if __name__ == '__main__': 237 | import argparse 238 | import sys 239 | import os 240 | import signal 241 | from dmr_utils3.utils import try_download, mk_id_dict 242 | 243 | # Change the current directory to the location of the application 244 | os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) 245 | 246 | # CLI argument parser - handles picking up the config file from the command line, and sending a "help" message 247 | parser = argparse.ArgumentParser() 248 | parser.add_argument('-c', '--config', action='store', dest='CONFIG_FILE', help='/full/path/to/config.file (usually hblink.cfg)') 249 | parser.add_argument('-l', '--logging', action='store', dest='LOG_LEVEL', help='Override config file logging level.') 250 | cli_args = parser.parse_args() 251 | 252 | # Ensure we have a path for the config file, if one wasn't specified, then use the default (top of file) 253 | if not cli_args.CONFIG_FILE: 254 | cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg' 255 | 256 | # Call the external routine to build the configuration dictionary 257 | CONFIG = config.build_config(cli_args.CONFIG_FILE) 258 | 259 | # Start the system logger 260 | if cli_args.LOG_LEVEL: 261 | CONFIG['LOGGER']['LOG_LEVEL'] = cli_args.LOG_LEVEL 262 | logger = log.config_logging(CONFIG['LOGGER']) 263 | logger.info('\n\nCopyright (c) 2013, 2014, 2015, 2016, 2018, 2019\n\tThe Regents of the K0USY Group. All rights reserved.\n') 264 | logger.debug('Logging system started, anything from here on gets logged') 265 | 266 | # Set up the signal handler 267 | def sig_handler(_signal, _frame): 268 | logger.info('SHUTDOWN: BRIDGE_ALL IS TERMINATING WITH SIGNAL %s', str(_signal)) 269 | hblink_handler(_signal, _frame) 270 | logger.info('SHUTDOWN: ALL SYSTEM HANDLERS EXECUTED - STOPPING REACTOR') 271 | reactor.stop() 272 | 273 | # Set signal handers so that we can gracefully exit if need be 274 | for sig in [signal.SIGTERM, signal.SIGINT]: 275 | signal.signal(sig, sig_handler) 276 | 277 | # Create the name-number mapping dictionaries 278 | peer_ids, subscriber_ids, talkgroup_ids = mk_aliases(CONFIG) 279 | 280 | # INITIALIZE THE REPORTING LOOP 281 | report_server = config_reports(CONFIG, reportFactory) 282 | 283 | # HBlink instance creation 284 | logger.info('HBlink \'bridge_all.py\' -- SYSTEM STARTING...') 285 | for system in CONFIG['SYSTEMS']: 286 | if CONFIG['SYSTEMS'][system]['ENABLED']: 287 | if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE': 288 | logger.critical('%s FATAL: Instance is mode \'OPENBRIDGE\', \n\t\t...Which would be tragic for Bridge All, since it carries multiple call\n\t\tstreams simultaneously. bridge_all.py onlyl works with MMDVM-based systems', system) 289 | sys.exit('bridge_all.py cannot function with systems that are not MMDVM devices. System {} is configured as an OPENBRIDGE'.format(system)) 290 | else: 291 | systems[system] = bridgeallSYSTEM(system, CONFIG, report_server) 292 | reactor.listenUDP(CONFIG['SYSTEMS'][system]['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['IP']) 293 | logger.debug('%s instance created: %s, %s', CONFIG['SYSTEMS'][system]['MODE'], system, systems[system]) 294 | 295 | reactor.run() 296 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | ############################################################################### 4 | # Copyright (C) 2016-2018 Cortney T. Buffington, N0MJS 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software Foundation, 18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | ############################################################################### 20 | 21 | ''' 22 | This module generates the configuration data structure for hblink.py and 23 | assoicated programs that use it. It has been seaparated into a different 24 | module so as to keep hblink.py easeier to navigate. This file only needs 25 | updated if the items in the main configuraiton file (usually hblink.cfg) 26 | change. 27 | ''' 28 | 29 | import configparser 30 | import sys 31 | import const 32 | 33 | from socket import gethostbyname 34 | 35 | # Does anybody read this stuff? There's a PEP somewhere that says I should do this. 36 | __author__ = 'Cortney T. Buffington, N0MJS' 37 | __copyright__ = 'Copyright (c) 2016-2018 Cortney T. Buffington, N0MJS and the K0USY Group' 38 | __credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT' 39 | __license__ = 'GNU GPLv3' 40 | __maintainer__ = 'Cort Buffington, N0MJS' 41 | __email__ = 'n0mjs@me.com' 42 | 43 | # Processing of ALS goes here. It's separated from the acl_build function because this 44 | # code is hblink config-file format specific, and acl_build is abstracted 45 | def process_acls(_config): 46 | # Global registration ACL 47 | _config['GLOBAL']['REG_ACL'] = acl_build(_config['GLOBAL']['REG_ACL'], const.PEER_MAX) 48 | 49 | # Global subscriber and TGID ACLs 50 | for acl in ['SUB_ACL', 'TG1_ACL', 'TG2_ACL']: 51 | _config['GLOBAL'][acl] = acl_build(_config['GLOBAL'][acl], const.ID_MAX) 52 | 53 | # System level ACLs 54 | for system in _config['SYSTEMS']: 55 | # Registration ACLs (which make no sense for peer systems) 56 | if _config['SYSTEMS'][system]['MODE'] == 'MASTER': 57 | _config['SYSTEMS'][system]['REG_ACL'] = acl_build(_config['SYSTEMS'][system]['REG_ACL'], const.PEER_MAX) 58 | 59 | # Subscriber and TGID ACLs (valid for all system types) 60 | for acl in ['SUB_ACL', 'TG1_ACL', 'TG2_ACL']: 61 | _config['SYSTEMS'][system][acl] = acl_build(_config['SYSTEMS'][system][acl], const.ID_MAX) 62 | 63 | # Create an access control list that is programatically useable from human readable: 64 | # ORIGINAL: 'DENY:1-5,3120101,3120124' 65 | # PROCESSED: (False, set([(1, 5), (3120124, 3120124), (3120101, 3120101)])) 66 | def acl_build(_acl, _max): 67 | if not _acl: 68 | return(True, set((const.ID_MIN, _max))) 69 | 70 | acl = [] #set() 71 | sections = _acl.split(':') 72 | 73 | if sections[0] == 'PERMIT': 74 | action = True 75 | else: 76 | action = False 77 | 78 | for entry in sections[1].split(','): 79 | if entry == 'ALL': 80 | acl.append((const.ID_MIN, _max)) 81 | break 82 | 83 | elif '-' in entry: 84 | start,end = entry.split('-') 85 | start,end = int(start), int(end) 86 | if (const.ID_MIN <= start <= _max) or (const.ID_MIN <= end <= _max): 87 | acl.append((start, end)) 88 | else: 89 | sys.exit('ACL CREATION ERROR, VALUE OUT OF RANGE ({} - {})IN RANGE-BASED ENTRY: {}'.format(const.ID_MIN, _max, entry)) 90 | else: 91 | id = int(entry) 92 | if (const.ID_MIN <= id <= _max): 93 | acl.append((id, id)) 94 | else: 95 | sys.exit('ACL CREATION ERROR, VALUE OUT OF RANGE ({} - {}) IN SINGLE ID ENTRY: {}'.format(const.ID_MIN, _max, entry)) 96 | 97 | return (action, acl) 98 | 99 | def build_config(_config_file): 100 | config = configparser.ConfigParser() 101 | 102 | if not config.read(_config_file): 103 | sys.exit('Configuration file \''+_config_file+'\' is not a valid configuration file! Exiting...') 104 | 105 | CONFIG = {} 106 | CONFIG['GLOBAL'] = {} 107 | CONFIG['REPORTS'] = {} 108 | CONFIG['LOGGER'] = {} 109 | CONFIG['ALIASES'] = {} 110 | CONFIG['SYSTEMS'] = {} 111 | 112 | try: 113 | for section in config.sections(): 114 | if section == 'GLOBAL': 115 | CONFIG['GLOBAL'].update({ 116 | 'PATH': config.get(section, 'PATH'), 117 | 'PING_TIME': config.getint(section, 'PING_TIME'), 118 | 'MAX_MISSED': config.getint(section, 'MAX_MISSED'), 119 | 'USE_ACL': config.get(section, 'USE_ACL'), 120 | 'REG_ACL': config.get(section, 'REG_ACL'), 121 | 'SUB_ACL': config.get(section, 'SUB_ACL'), 122 | 'TG1_ACL': config.get(section, 'TGID_TS1_ACL'), 123 | 'TG2_ACL': config.get(section, 'TGID_TS2_ACL') 124 | }) 125 | 126 | elif section == 'REPORTS': 127 | CONFIG['REPORTS'].update({ 128 | 'REPORT': config.getboolean(section, 'REPORT'), 129 | 'REPORT_INTERVAL': config.getint(section, 'REPORT_INTERVAL'), 130 | 'REPORT_PORT': config.getint(section, 'REPORT_PORT'), 131 | 'REPORT_CLIENTS': config.get(section, 'REPORT_CLIENTS').split(',') 132 | }) 133 | 134 | elif section == 'LOGGER': 135 | CONFIG['LOGGER'].update({ 136 | 'LOG_FILE': config.get(section, 'LOG_FILE'), 137 | 'LOG_HANDLERS': config.get(section, 'LOG_HANDLERS'), 138 | 'LOG_LEVEL': config.get(section, 'LOG_LEVEL'), 139 | 'LOG_NAME': config.get(section, 'LOG_NAME') 140 | }) 141 | if not CONFIG['LOGGER']['LOG_FILE']: 142 | CONFIG['LOGGER']['LOG_FILE'] = '/dev/null' 143 | 144 | elif section == 'ALIASES': 145 | CONFIG['ALIASES'].update({ 146 | 'TRY_DOWNLOAD': config.getboolean(section, 'TRY_DOWNLOAD'), 147 | 'PATH': config.get(section, 'PATH'), 148 | 'PEER_FILE': config.get(section, 'PEER_FILE'), 149 | 'SUBSCRIBER_FILE': config.get(section, 'SUBSCRIBER_FILE'), 150 | 'TGID_FILE': config.get(section, 'TGID_FILE'), 151 | 'PEER_URL': config.get(section, 'PEER_URL'), 152 | 'SUBSCRIBER_URL': config.get(section, 'SUBSCRIBER_URL'), 153 | 'STALE_TIME': config.getint(section, 'STALE_DAYS') * 86400, 154 | }) 155 | 156 | elif config.getboolean(section, 'ENABLED'): 157 | if config.get(section, 'MODE') == 'PEER': 158 | CONFIG['SYSTEMS'].update({section: { 159 | 'MODE': config.get(section, 'MODE'), 160 | 'ENABLED': config.getboolean(section, 'ENABLED'), 161 | 'LOOSE': config.getboolean(section, 'LOOSE'), 162 | 'SOCK_ADDR': (gethostbyname(config.get(section, 'IP')), config.getint(section, 'PORT')), 163 | 'IP': gethostbyname(config.get(section, 'IP')), 164 | 'PORT': config.getint(section, 'PORT'), 165 | 'MASTER_SOCKADDR': (gethostbyname(config.get(section, 'MASTER_IP')), config.getint(section, 'MASTER_PORT')), 166 | 'MASTER_IP': gethostbyname(config.get(section, 'MASTER_IP')), 167 | 'MASTER_PORT': config.getint(section, 'MASTER_PORT'), 168 | 'PASSPHRASE': bytes(config.get(section, 'PASSPHRASE'), 'utf-8'), 169 | 'CALLSIGN': bytes(config.get(section, 'CALLSIGN').ljust(8)[:8], 'utf-8'), 170 | 'RADIO_ID': config.getint(section, 'RADIO_ID').to_bytes(4, 'big'), 171 | 'RX_FREQ': bytes(config.get(section, 'RX_FREQ').ljust(9)[:9], 'utf-8'), 172 | 'TX_FREQ': bytes(config.get(section, 'TX_FREQ').ljust(9)[:9], 'utf-8'), 173 | 'TX_POWER': bytes(config.get(section, 'TX_POWER').rjust(2,'0'), 'utf-8'), 174 | 'COLORCODE': bytes(config.get(section, 'COLORCODE').rjust(2,'0'), 'utf-8'), 175 | 'LATITUDE': bytes(config.get(section, 'LATITUDE').ljust(8)[:8], 'utf-8'), 176 | 'LONGITUDE': bytes(config.get(section, 'LONGITUDE').ljust(9)[:9], 'utf-8'), 177 | 'HEIGHT': bytes(config.get(section, 'HEIGHT').rjust(3,'0'), 'utf-8'), 178 | 'LOCATION': bytes(config.get(section, 'LOCATION').ljust(20)[:20], 'utf-8'), 179 | 'DESCRIPTION': bytes(config.get(section, 'DESCRIPTION').ljust(19)[:19], 'utf-8'), 180 | 'SLOTS': bytes(config.get(section, 'SLOTS'), 'utf-8'), 181 | 'URL': bytes(config.get(section, 'URL').ljust(124)[:124], 'utf-8'), 182 | 'SOFTWARE_ID': bytes(config.get(section, 'SOFTWARE_ID').ljust(40)[:40], 'utf-8'), 183 | 'PACKAGE_ID': bytes(config.get(section, 'PACKAGE_ID').ljust(40)[:40], 'utf-8'), 184 | 'GROUP_HANGTIME': config.getint(section, 'GROUP_HANGTIME'), 185 | 'OPTIONS': b''.join([b'Type=HBlink;', bytes(config.get(section, 'OPTIONS'), 'utf-8')]), 186 | 'USE_ACL': config.getboolean(section, 'USE_ACL'), 187 | 'SUB_ACL': config.get(section, 'SUB_ACL'), 188 | 'TG1_ACL': config.get(section, 'TGID_TS1_ACL'), 189 | 'TG2_ACL': config.get(section, 'TGID_TS2_ACL') 190 | }}) 191 | CONFIG['SYSTEMS'][section].update({'STATS': { 192 | 'CONNECTION': 'NO', # NO, RTPL_SENT, AUTHENTICATED, CONFIG-SENT, YES 193 | 'CONNECTED': None, 194 | 'PINGS_SENT': 0, 195 | 'PINGS_ACKD': 0, 196 | 'NUM_OUTSTANDING': 0, 197 | 'PING_OUTSTANDING': False, 198 | 'LAST_PING_TX_TIME': 0, 199 | 'LAST_PING_ACK_TIME': 0, 200 | }}) 201 | 202 | if config.get(section, 'MODE') == 'XLXPEER': 203 | CONFIG['SYSTEMS'].update({section: { 204 | 'MODE': config.get(section, 'MODE'), 205 | 'ENABLED': config.getboolean(section, 'ENABLED'), 206 | 'LOOSE': config.getboolean(section, 'LOOSE'), 207 | 'SOCK_ADDR': (gethostbyname(config.get(section, 'IP')), config.getint(section, 'PORT')), 208 | 'IP': gethostbyname(config.get(section, 'IP')), 209 | 'PORT': config.getint(section, 'PORT'), 210 | 'MASTER_SOCKADDR': (gethostbyname(config.get(section, 'MASTER_IP')), config.getint(section, 'MASTER_PORT')), 211 | 'MASTER_IP': gethostbyname(config.get(section, 'MASTER_IP')), 212 | 'MASTER_PORT': config.getint(section, 'MASTER_PORT'), 213 | 'PASSPHRASE': bytes(config.get(section, 'PASSPHRASE'), 'utf-8'), 214 | 'CALLSIGN': bytes(config.get(section, 'CALLSIGN').ljust(8)[:8], 'utf-8'), 215 | 'RADIO_ID': config.getint(section, 'RADIO_ID').to_bytes(4, 'big'), 216 | 'RX_FREQ': bytes(config.get(section, 'RX_FREQ').ljust(9)[:9], 'utf-8'), 217 | 'TX_FREQ': bytes(config.get(section, 'TX_FREQ').ljust(9)[:9], 'utf-8'), 218 | 'TX_POWER': bytes(config.get(section, 'TX_POWER').rjust(2,'0'), 'utf-8'), 219 | 'COLORCODE': bytes(config.get(section, 'COLORCODE').rjust(2,'0'), 'utf-8'), 220 | 'LATITUDE': bytes(config.get(section, 'LATITUDE').ljust(8)[:8], 'utf-8'), 221 | 'LONGITUDE': bytes(config.get(section, 'LONGITUDE').ljust(9)[:9], 'utf-8'), 222 | 'HEIGHT': bytes(config.get(section, 'HEIGHT').rjust(3,'0'), 'utf-8'), 223 | 'LOCATION': bytes(config.get(section, 'LOCATION').ljust(20)[:20], 'utf-8'), 224 | 'DESCRIPTION': bytes(config.get(section, 'DESCRIPTION').ljust(19)[:19], 'utf-8'), 225 | 'SLOTS': bytes(config.get(section, 'SLOTS'), 'utf-8'), 226 | 'URL': bytes(config.get(section, 'URL').ljust(124)[:124], 'utf-8'), 227 | 'SOFTWARE_ID': bytes(config.get(section, 'SOFTWARE_ID').ljust(40)[:40], 'utf-8'), 228 | 'PACKAGE_ID': bytes(config.get(section, 'PACKAGE_ID').ljust(40)[:40], 'utf-8'), 229 | 'GROUP_HANGTIME': config.getint(section, 'GROUP_HANGTIME'), 230 | 'XLXMODULE': config.getint(section, 'XLXMODULE'), 231 | 'OPTIONS': '', 232 | 'USE_ACL': config.getboolean(section, 'USE_ACL'), 233 | 'SUB_ACL': config.get(section, 'SUB_ACL'), 234 | 'TG1_ACL': config.get(section, 'TGID_TS1_ACL'), 235 | 'TG2_ACL': config.get(section, 'TGID_TS2_ACL') 236 | }}) 237 | CONFIG['SYSTEMS'][section].update({'XLXSTATS': { 238 | 'CONNECTION': 'NO', # NO, RTPL_SENT, AUTHENTICATED, CONFIG-SENT, YES 239 | 'CONNECTED': None, 240 | 'PINGS_SENT': 0, 241 | 'PINGS_ACKD': 0, 242 | 'NUM_OUTSTANDING': 0, 243 | 'PING_OUTSTANDING': False, 244 | 'LAST_PING_TX_TIME': 0, 245 | 'LAST_PING_ACK_TIME': 0, 246 | }}) 247 | 248 | elif config.get(section, 'MODE') == 'MASTER': 249 | CONFIG['SYSTEMS'].update({section: { 250 | 'MODE': config.get(section, 'MODE'), 251 | 'ENABLED': config.getboolean(section, 'ENABLED'), 252 | 'REPEAT': config.getboolean(section, 'REPEAT'), 253 | 'MAX_PEERS': config.getint(section, 'MAX_PEERS'), 254 | 'IP': gethostbyname(config.get(section, 'IP')), 255 | 'PORT': config.getint(section, 'PORT'), 256 | 'PASSPHRASE': bytes(config.get(section, 'PASSPHRASE'), 'utf-8'), 257 | 'GROUP_HANGTIME': config.getint(section, 'GROUP_HANGTIME'), 258 | 'USE_ACL': config.getboolean(section, 'USE_ACL'), 259 | 'REG_ACL': config.get(section, 'REG_ACL'), 260 | 'SUB_ACL': config.get(section, 'SUB_ACL'), 261 | 'TG1_ACL': config.get(section, 'TGID_TS1_ACL'), 262 | 'TG2_ACL': config.get(section, 'TGID_TS2_ACL') 263 | }}) 264 | CONFIG['SYSTEMS'][section].update({'PEERS': {}}) 265 | 266 | elif config.get(section, 'MODE') == 'OPENBRIDGE': 267 | CONFIG['SYSTEMS'].update({section: { 268 | 'MODE': config.get(section, 'MODE'), 269 | 'ENABLED': config.getboolean(section, 'ENABLED'), 270 | 'NETWORK_ID': config.getint(section, 'NETWORK_ID').to_bytes(4, 'big'), 271 | 'IP': gethostbyname(config.get(section, 'IP')), 272 | 'PORT': config.getint(section, 'PORT'), 273 | 'PASSPHRASE': bytes(config.get(section, 'PASSPHRASE').ljust(20,'\x00')[:20], 'utf-8'), 274 | 'TARGET_SOCK': (gethostbyname(config.get(section, 'TARGET_IP')), config.getint(section, 'TARGET_PORT')), 275 | 'TARGET_IP': gethostbyname(config.get(section, 'TARGET_IP')), 276 | 'TARGET_PORT': config.getint(section, 'TARGET_PORT'), 277 | 'BOTH_SLOTS': config.getboolean(section, 'BOTH_SLOTS'), 278 | 'USE_ACL': config.getboolean(section, 'USE_ACL'), 279 | 'SUB_ACL': config.get(section, 'SUB_ACL'), 280 | 'TG1_ACL': config.get(section, 'TGID_ACL'), 281 | 'TG2_ACL': 'PERMIT:ALL' 282 | }}) 283 | 284 | 285 | except configparser.Error as err: 286 | sys.exit('Error processing configuration file -- {}'.format(err)) 287 | 288 | process_acls(CONFIG) 289 | 290 | return CONFIG 291 | 292 | # Used to run this file direclty and print the config, 293 | # which might be useful for debugging 294 | if __name__ == '__main__': 295 | import sys 296 | import os 297 | import argparse 298 | from pprint import pprint 299 | from dmr_utils3.utils import int_id 300 | 301 | # Change the current directory to the location of the application 302 | os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) 303 | 304 | # CLI argument parser - handles picking up the config file from the command line, and sending a "help" message 305 | parser = argparse.ArgumentParser() 306 | parser.add_argument('-c', '--config', action='store', dest='CONFIG_FILE', help='/full/path/to/config.file (usually hblink.cfg)') 307 | cli_args = parser.parse_args() 308 | 309 | 310 | # Ensure we have a path for the config file, if one wasn't specified, then use the execution directory 311 | if not cli_args.CONFIG_FILE: 312 | cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg' 313 | 314 | CONFIG = build_config(cli_args.CONFIG_FILE) 315 | pprint(CONFIG) 316 | 317 | def acl_check(_id, _acl): 318 | id = int_id(_id) 319 | for entry in _acl[1]: 320 | if entry[0] <= id <= entry[1]: 321 | return _acl[0] 322 | return not _acl[0] 323 | 324 | print(acl_check(b'\x00\x01\x37', CONFIG['GLOBAL']['TG1_ACL'])) 325 | -------------------------------------------------------------------------------- /const.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | ############################################################################### 4 | # Copyright (C) 2016-2018 Cortney T. Buffington, N0MJS 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software Foundation, 18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | ############################################################################### 20 | 21 | ''' 22 | These are contants used by HBlink. Rather than stuff them into the main program 23 | file, any new constants should be placed here. It makes them easier to keep track 24 | of and keeps hblink.py shorter. 25 | ''' 26 | 27 | __author__ = 'Cortney T. Buffington, N0MJS' 28 | __copyright__ = 'Copyright (c) 2016 Cortney T. Buffington, N0MJS and the K0USY Group' 29 | __credits__ = '' 30 | __license__ = 'GNU GPLv3' 31 | __maintainer__ = 'Cort Buffington, N0MJS' 32 | __email__ = 'n0mjs@me.com' 33 | 34 | 35 | # DMR Related constants 36 | ID_MIN = 1 37 | ID_MAX = 16776415 38 | 39 | # Timers 40 | STREAM_TO = .360 41 | 42 | # Options from the LC - used for late entry 43 | LC_OPT = b'\x00\x00\x20' 44 | 45 | # HomeBrew Protocol Frame Types 46 | HBPF_VOICE = 0x0 47 | HBPF_VOICE_SYNC = 0x1 48 | HBPF_DATA_SYNC = 0x2 49 | HBPF_SLT_VHEAD = 0x1 50 | HBPF_SLT_VTERM = 0x2 51 | 52 | # HomeBrew Protocol Commands 53 | DMRA = b'DMRA' 54 | DMRD = b'DMRD' 55 | MSTCL = b'MSTCL' 56 | MSTNAK = b'MSTNAK' 57 | MSTPONG = b'MSTPONG' 58 | MSTN = b'MSTN' 59 | MSTP = b'MSTP' 60 | MSTC = b'MSTC' 61 | RPTL = b'RPTL' 62 | RPTPING = b'RPTPING' 63 | RPTCL = b'RPTCL' 64 | RPTL = b'RPTL' 65 | RPTACK = b'RPTACK' 66 | RPTK = b'RPTK' 67 | RPTC = b'RPTC' 68 | RPTP = b'RPTP' 69 | RPTA = b'RPTA' 70 | RPTO = b'RPTO' 71 | RPTS = b'RPTS' 72 | RPTSBKN = b'RPTSBKN' 73 | 74 | 75 | # Higheset peer ID permitted by HBP 76 | PEER_MAX = 4294967295 77 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2.4' 2 | services: 3 | hblink3: 4 | container_name: hblink 5 | volumes: 6 | - '/etc/hblink3/hblink.cfg:/opt/hblink3/hblink.cfg' 7 | - '/var/log/hblink/hblink.log:/opt/hblink3/hblink.log' 8 | - '/etc/hblink3/rules.py:/opt/hblink3/rules.py' 9 | ports: 10 | - '62030:62030/udp' 11 | - '62031-62051:62031-62051/udp' 12 | - '4321:4321/tcp' 13 | image: 'shaymez/hblink3:latest' 14 | restart: "unless-stopped" 15 | -------------------------------------------------------------------------------- /entrypoint: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd /opt/hblink3 4 | python /opt/hblink3/bridge.py -c hblink.cfg -r rules.py 5 | -------------------------------------------------------------------------------- /hblink-SAMPLE.cfg: -------------------------------------------------------------------------------- 1 | # PROGRAM-WIDE PARAMETERS GO HERE 2 | # PATH - working path for files, leave it alone unless you NEED to change it 3 | # PING_TIME - the interval that peers will ping the master, and re-try registraion 4 | # - how often the Master maintenance loop runs 5 | # MAX_MISSED - how many pings are missed before we give up and re-register 6 | # - number of times the master maintenance loop runs before de-registering a peer 7 | # 8 | # ACLs: 9 | # 10 | # Access Control Lists are a very powerful tool for administering your system. 11 | # But they consume packet processing time. Disable them if you are not using them. 12 | # But be aware that, as of now, the configuration stanzas still need the ACL 13 | # sections configured even if you're not using them. 14 | # 15 | # REGISTRATION ACLS ARE ALWAYS USED, ONLY SUBSCRIBER AND TGID MAY BE DISABLED!!! 16 | # 17 | # The 'action' May be PERMIT|DENY 18 | # Each entry may be a single radio id, or a hypenated range (e.g. 1-2999) 19 | # Format: 20 | # ACL = 'action:id|start-end|,id|start-end,....' 21 | # --for example-- 22 | # SUB_ACL: DENY:1,1000-2000,4500-60000,17 23 | # 24 | # ACL Types: 25 | # REG_ACL: peer radio IDs for registration (only used on HBP master systems) 26 | # SUB_ACL: subscriber IDs for end-users 27 | # TGID_TS1_ACL: destination talkgroup IDs on Timeslot 1 28 | # TGID_TS2_ACL: destination talkgroup IDs on Timeslot 2 29 | # 30 | # ACLs may be repeated for individual systems if needed for granularity 31 | # Global ACLs will be processed BEFORE the system level ACLs 32 | # Packets will be matched against all ACLs, GLOBAL first. If a packet 'passes' 33 | # All elements, processing continues. Packets are discarded at the first 34 | # negative match, or 'reject' from an ACL element. 35 | # 36 | # If you do not wish to use ACLs, set them to 'PERMIT:ALL' 37 | # TGID_TS1_ACL in the global stanza is used for OPENBRIDGE systems, since all 38 | # traffic is passed as TS 1 between OpenBridges 39 | [GLOBAL] 40 | PATH: ./ 41 | PING_TIME: 5 42 | MAX_MISSED: 3 43 | USE_ACL: True 44 | REG_ACL: PERMIT:ALL 45 | SUB_ACL: DENY:1 46 | TGID_TS1_ACL: PERMIT:ALL 47 | TGID_TS2_ACL: PERMIT:ALL 48 | 49 | 50 | # NOT YET WORKING: NETWORK REPORTING CONFIGURATION 51 | # Enabling "REPORT" will configure a socket-based reporting 52 | # system that will send the configuration and other items 53 | # to a another process (local or remote) that may process 54 | # the information for some useful purpose, like a web dashboard. 55 | # 56 | # REPORT - True to enable, False to disable 57 | # REPORT_INTERVAL - Seconds between reports 58 | # REPORT_PORT - TCP port to listen on if "REPORT_NETWORKS" = NETWORK 59 | # REPORT_CLIENTS - comma separated list of IPs you will allow clients 60 | # to connect on. Entering a * will allow all. 61 | # 62 | # ****FOR NOW MUST BE TRUE - USE THE LOOPBACK IF YOU DON'T USE THIS!!!**** 63 | [REPORTS] 64 | REPORT: True 65 | REPORT_INTERVAL: 60 66 | REPORT_PORT: 4321 67 | REPORT_CLIENTS: 127.0.0.1 68 | 69 | 70 | # SYSTEM LOGGER CONFIGURAITON 71 | # This allows the logger to be configured without chaning the individual 72 | # python logger stuff. LOG_FILE should be a complete path/filename for *your* 73 | # system -- use /dev/null for non-file handlers. 74 | # LOG_HANDLERS may be any of the following, please, no spaces in the 75 | # list if you use several: 76 | # null 77 | # console 78 | # console-timed 79 | # file 80 | # file-timed 81 | # syslog 82 | # LOG_LEVEL may be any of the standard syslog logging levels, though 83 | # as of now, DEBUG, INFO, WARNING and CRITICAL are the only ones 84 | # used. 85 | # 86 | [LOGGER] 87 | LOG_FILE: /tmp/hblink.log 88 | LOG_HANDLERS: console-timed 89 | LOG_LEVEL: DEBUG 90 | LOG_NAME: HBlink 91 | 92 | # DOWNLOAD AND IMPORT SUBSCRIBER, PEER and TGID ALIASES 93 | # Ok, not the TGID, there's no master list I know of to download 94 | # This is intended as a facility for other applcations built on top of 95 | # HBlink to use, and will NOT be used in HBlink directly. 96 | # STALE_DAYS is the number of days since the last download before we 97 | # download again. Don't be an ass and change this to less than a few days. 98 | [ALIASES] 99 | TRY_DOWNLOAD: True 100 | PATH: ./ 101 | PEER_FILE: peer_ids.json 102 | SUBSCRIBER_FILE: subscriber_ids.json 103 | TGID_FILE: talkgroup_ids.json 104 | PEER_URL: https://www.radioid.net/static/rptrs.json 105 | SUBSCRIBER_URL: https://www.radioid.net/static/users.json 106 | STALE_DAYS: 7 107 | 108 | # OPENBRIDGE INSTANCES - DUPLICATE SECTION FOR MULTIPLE CONNECTIONS 109 | # OpenBridge is a protocol originall created by DMR+ for connection between an 110 | # IPSC2 server and Brandmeister. It has been implemented here at the suggestion 111 | # of the Brandmeister team as a way to legitimately connect HBlink to the 112 | # Brandemiester network. 113 | # It is recommended to name the system the ID of the Brandmeister server that 114 | # it connects to, but is not necessary. TARGET_IP and TARGET_PORT are of the 115 | # Brandmeister or IPSC2 server you are connecting to. PASSPHRASE is the password 116 | # that must be agreed upon between you and the operator of the server you are 117 | # connecting to. NETWORK_ID is a number in the format of a DMR Radio ID that 118 | # will be sent to the other server to identify this connection. 119 | # other parameters follow the other system types. 120 | # 121 | # ACLs: 122 | # OpenBridge does not 'register', so registration ACL is meaningless. 123 | # Proper OpenBridge passes all traffic on TS1. 124 | # HBlink can extend OPB to use both slots for unit calls only. 125 | # Setting "BOTH_SLOTS" True ONLY affects unit traffic! 126 | # Otherwise ACLs work as described in the global stanza 127 | [OBP-1] 128 | MODE: OPENBRIDGE 129 | ENABLED: True 130 | IP: 131 | PORT: 62035 132 | NETWORK_ID: 3129100 133 | PASSPHRASE: password 134 | TARGET_IP: 1.2.3.4 135 | TARGET_PORT: 62035 136 | BOTH_SLOTS: True 137 | USE_ACL: True 138 | SUB_ACL: DENY:1 139 | TGID_ACL: PERMIT:ALL 140 | 141 | # MASTER INSTANCES - DUPLICATE SECTION FOR MULTIPLE MASTERS 142 | # HomeBrew Protocol Master instances go here. 143 | # IP may be left blank if there's one interface on your system. 144 | # Port should be the port you want this master to listen on. It must be unique 145 | # and unused by anything else. 146 | # Repeat - if True, the master repeats traffic to peers, False, it does nothing. 147 | # 148 | # MAX_PEERS -- maximun number of peers that may be connect to this master 149 | # at any given time. This is very handy if you're allowing hotspots to 150 | # connect, or using a limited computer like a Raspberry Pi. 151 | # 152 | # ACLs: 153 | # See comments in the GLOBAL stanza 154 | [MASTER-1] 155 | MODE: MASTER 156 | ENABLED: True 157 | REPEAT: True 158 | MAX_PEERS: 10 159 | EXPORT_AMBE: False 160 | IP: 161 | PORT: 54000 162 | PASSPHRASE: s3cr37w0rd 163 | GROUP_HANGTIME: 5 164 | USE_ACL: True 165 | REG_ACL: DENY:1 166 | SUB_ACL: DENY:1 167 | TGID_TS1_ACL: PERMIT:ALL 168 | TGID_TS2_ACL: PERMIT:ALL 169 | 170 | # PEER INSTANCES - DUPLICATE SECTION FOR MULTIPLE PEERS 171 | # There are a LOT of errors in the HB Protocol specifications on this one! 172 | # MOST of these items are just strings and will be properly dealt with by the program 173 | # The TX & RX Frequencies are 9-digit numbers, and are the frequency in Hz. 174 | # Latitude is an 8-digit unsigned floating point number. 175 | # Longitude is a 9-digit signed floating point number. 176 | # Height is in meters 177 | # Setting Loose to True relaxes the validation on packets received from the master. 178 | # This will allow HBlink to connect to a non-compliant system such as XLXD, DMR+ etc. 179 | # 180 | # ACLs: 181 | # See comments in the GLOBAL stanza 182 | [REPEATER-1] 183 | MODE: PEER 184 | ENABLED: True 185 | LOOSE: False 186 | EXPORT_AMBE: False 187 | IP: 188 | PORT: 54001 189 | MASTER_IP: 172.16.1.1 190 | MASTER_PORT: 54000 191 | PASSPHRASE: homebrew 192 | CALLSIGN: W1ABC 193 | RADIO_ID: 312000 194 | RX_FREQ: 449000000 195 | TX_FREQ: 444000000 196 | TX_POWER: 25 197 | COLORCODE: 1 198 | SLOTS: 1 199 | LATITUDE: 38.0000 200 | LONGITUDE: -095.0000 201 | HEIGHT: 75 202 | LOCATION: Anywhere, USA 203 | DESCRIPTION: This is a cool repeater 204 | URL: www.w1abc.org 205 | SOFTWARE_ID: 20170620 206 | PACKAGE_ID: MMDVM_HBlink 207 | GROUP_HANGTIME: 5 208 | OPTIONS: 209 | USE_ACL: True 210 | SUB_ACL: DENY:1 211 | TGID_TS1_ACL: PERMIT:ALL 212 | TGID_TS2_ACL: PERMIT:ALL 213 | 214 | [XLX-1] 215 | MODE: XLXPEER 216 | ENABLED: True 217 | LOOSE: True 218 | EXPORT_AMBE: False 219 | IP: 220 | PORT: 54002 221 | MASTER_IP: 172.16.1.1 222 | MASTER_PORT: 62030 223 | PASSPHRASE: passw0rd 224 | CALLSIGN: W1ABC 225 | RADIO_ID: 312000 226 | RX_FREQ: 449000000 227 | TX_FREQ: 444000000 228 | TX_POWER: 25 229 | COLORCODE: 1 230 | SLOTS: 1 231 | LATITUDE: 38.0000 232 | LONGITUDE: -095.0000 233 | HEIGHT: 75 234 | LOCATION: Anywhere, USA 235 | DESCRIPTION: This is a cool repeater 236 | URL: www.w1abc.org 237 | SOFTWARE_ID: 20170620 238 | PACKAGE_ID: MMDVM_HBlink 239 | GROUP_HANGTIME: 5 240 | XLXMODULE: 4004 241 | USE_ACL: True 242 | SUB_ACL: DENY:1 243 | TGID_TS1_ACL: PERMIT:ALL 244 | TGID_TS2_ACL: PERMIT:ALL 245 | -------------------------------------------------------------------------------- /hblink.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | ############################################################################### 4 | # Copyright (C) 2016-2019 Cortney T. Buffington, N0MJS 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software Foundation, 18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | ############################################################################### 20 | 21 | ''' 22 | This program does very little on its own. It is intended to be used as a module 23 | to build applications on top of the HomeBrew Repeater Protocol. By itself, it 24 | will only act as a peer or master for the systems specified in its configuration 25 | file (usually hblink.cfg). It is ALWAYS best practice to ensure that this program 26 | works stand-alone before troubleshooting any applications that use it. It has 27 | sufficient logging to be used standalone as a troubleshooting application. 28 | ''' 29 | 30 | # Specifig functions from modules we need 31 | from binascii import b2a_hex as ahex 32 | from binascii import a2b_hex as bhex 33 | from random import randint 34 | from hashlib import sha256, sha1 35 | from hmac import new as hmac_new, compare_digest 36 | from time import time 37 | from collections import deque 38 | 39 | # Twisted is pretty important, so I keep it separate 40 | from twisted.internet.protocol import DatagramProtocol, Factory, Protocol 41 | from twisted.protocols.basic import NetstringReceiver 42 | from twisted.internet import reactor, task 43 | 44 | # Other files we pull from -- this is mostly for readability and segmentation 45 | import log 46 | import config 47 | from const import * 48 | from dmr_utils3.utils import int_id, bytes_4, try_download, mk_id_dict 49 | 50 | # Imports for the reporting server 51 | import pickle 52 | from reporting_const import * 53 | 54 | # The module needs logging logging, but handlers, etc. are controlled by the parent 55 | import logging 56 | logger = logging.getLogger(__name__) 57 | 58 | # Does anybody read this stuff? There's a PEP somewhere that says I should do this. 59 | __author__ = 'Cortney T. Buffington, N0MJS' 60 | __copyright__ = 'Copyright (c) 2016-2019 Cortney T. Buffington, N0MJS and the K0USY Group' 61 | __credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT' 62 | __license__ = 'GNU GPLv3' 63 | __maintainer__ = 'Cort Buffington, N0MJS' 64 | __email__ = 'n0mjs@me.com' 65 | 66 | # Global variables used whether we are a module or __main__ 67 | systems = {} 68 | 69 | # Timed loop used for reporting HBP status 70 | def config_reports(_config, _factory): 71 | def reporting_loop(_logger, _server): 72 | _logger.debug('(GLOBAL) Periodic reporting loop started') 73 | _server.send_config() 74 | 75 | logger.info('(GLOBAL) HBlink TCP reporting server configured') 76 | 77 | report_server = _factory(_config) 78 | report_server.clients = [] 79 | reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server) 80 | 81 | reporting = task.LoopingCall(reporting_loop, logger, report_server) 82 | reporting.start(_config['REPORTS']['REPORT_INTERVAL']) 83 | 84 | return report_server 85 | 86 | 87 | # Shut ourselves down gracefully by disconnecting from the masters and peers. 88 | def hblink_handler(_signal, _frame): 89 | for system in systems: 90 | logger.info('(GLOBAL) SHUTDOWN: DE-REGISTER SYSTEM: %s', system) 91 | systems[system].dereg() 92 | 93 | # Check a supplied ID against the ACL provided. Returns action (True|False) based 94 | # on matching and the action specified. 95 | def acl_check(_id, _acl): 96 | id = int_id(_id) 97 | for entry in _acl[1]: 98 | if entry[0] <= id <= entry[1]: 99 | return _acl[0] 100 | return not _acl[0] 101 | 102 | 103 | #************************************************ 104 | # OPENBRIDGE CLASS 105 | #************************************************ 106 | 107 | class OPENBRIDGE(DatagramProtocol): 108 | def __init__(self, _name, _config, _report): 109 | # Define a few shortcuts to make the rest of the class more readable 110 | self._CONFIG = _config 111 | self._system = _name 112 | self._report = _report 113 | self._config = self._CONFIG['SYSTEMS'][self._system] 114 | self._laststrid = deque([], 20) 115 | 116 | def dereg(self): 117 | logger.info('(%s) is mode OPENBRIDGE. No De-Registration required, continuing shutdown', self._system) 118 | 119 | def send_system(self, _packet): 120 | if _packet[:4] == DMRD: 121 | #_packet = _packet[:11] + self._config['NETWORK_ID'] + _packet[15:] 122 | _packet = b''.join([_packet[:11], self._config['NETWORK_ID'], _packet[15:]]) 123 | #_packet += hmac_new(self._config['PASSPHRASE'],_packet,sha1).digest() 124 | _packet = b''.join([_packet, (hmac_new(self._config['PASSPHRASE'],_packet,sha1).digest())]) 125 | self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT'])) 126 | # KEEP THE FOLLOWING COMMENTED OUT UNLESS YOU'RE DEBUGGING DEEPLY!!!! 127 | # logger.debug('(%s) TX Packet to OpenBridge %s:%s -- %s', self._system, self._config['TARGET_IP'], self._config['TARGET_PORT'], ahex(_packet)) 128 | else: 129 | logger.error('(%s) OpenBridge system was asked to send non DMRD packet: %s', self._system, _packet) 130 | 131 | def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): 132 | pass 133 | #print(int_id(_peer_id), int_id(_rf_src), int_id(_dst_id), int_id(_seq), _slot, _call_type, _frame_type, repr(_dtype_vseq), int_id(_stream_id)) 134 | 135 | def datagramReceived(self, _packet, _sockaddr): 136 | # Keep This Line Commented Unless HEAVILY Debugging! 137 | #logger.debug('(%s) RX packet from %s -- %s', self._system, _sockaddr, ahex(_packet)) 138 | 139 | if _packet[:4] == DMRD: # DMRData -- encapsulated DMR data frame 140 | _data = _packet[:53] 141 | _hash = _packet[53:] 142 | _ckhs = hmac_new(self._config['PASSPHRASE'],_data,sha1).digest() 143 | 144 | if compare_digest(_hash, _ckhs) and _sockaddr == self._config['TARGET_SOCK']: 145 | _peer_id = _data[11:15] 146 | _seq = _data[4] 147 | _rf_src = _data[5:8] 148 | _dst_id = _data[8:11] 149 | _bits = _data[15] 150 | _slot = 2 if (_bits & 0x80) else 1 151 | #_call_type = 'unit' if (_bits & 0x40) else 'group' 152 | if _bits & 0x40: 153 | _call_type = 'unit' 154 | elif (_bits & 0x23) == 0x23: 155 | _call_type = 'vcsbk' 156 | else: 157 | _call_type = 'group' 158 | _frame_type = (_bits & 0x30) >> 4 159 | _dtype_vseq = (_bits & 0xF) # data, 1=voice header, 2=voice terminator; voice, 0=burst A ... 5=burst F 160 | _stream_id = _data[16:20] 161 | #logger.debug('(%s) DMRD - Seqence: %s, RF Source: %s, Destination ID: %s', self._system, int_id(_seq), int_id(_rf_src), int_id(_dst_id)) 162 | 163 | # Sanity check for OpenBridge -- all calls must be on Slot 1 for Brandmeister or DMR+. Other HBlinks can process timeslot on OPB if the flag is set 164 | if _slot != 1 and not self._config['BOTH_SLOTS'] and not _call_type == 'unit': 165 | logger.error('(%s) OpenBridge packet discarded because it was not received on slot 1. SID: %s, TGID %s', self._system, int_id(_rf_src), int_id(_dst_id)) 166 | return 167 | 168 | # ACL Processing 169 | if self._CONFIG['GLOBAL']['USE_ACL']: 170 | if not acl_check(_rf_src, self._CONFIG['GLOBAL']['SUB_ACL']): 171 | if _stream_id not in self._laststrid: 172 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s FROM SUBSCRIBER %s BY GLOBAL ACL', self._system, int_id(_stream_id), int_id(_rf_src)) 173 | self._laststrid.append(_stream_id) 174 | return 175 | if _slot == 1 and not acl_check(_dst_id, self._CONFIG['GLOBAL']['TG1_ACL']): 176 | if _stream_id not in self._laststrid: 177 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY GLOBAL TS1 ACL', self._system, int_id(_stream_id), int_id(_dst_id)) 178 | self._laststrid.append(_stream_id) 179 | return 180 | if self._config['USE_ACL']: 181 | if not acl_check(_rf_src, self._config['SUB_ACL']): 182 | if _stream_id not in self._laststrid: 183 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s FROM SUBSCRIBER %s BY SYSTEM ACL', self._system, int_id(_stream_id), int_id(_rf_src)) 184 | self._laststrid.append(_stream_id) 185 | return 186 | if not acl_check(_dst_id, self._config['TG1_ACL']): 187 | if _stream_id not in self._laststrid: 188 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY SYSTEM ACL', self._system, int_id(_stream_id), int_id(_dst_id)) 189 | self._laststrid.append(_stream_id) 190 | return 191 | 192 | # Userland actions -- typically this is the function you subclass for an application 193 | self.dmrd_received(_peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data) 194 | else: 195 | logger.info('(%s) OpenBridge HMAC failed, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s', self._system, _packet[:4], repr(_packet[:53]), len(_packet[53:]), repr(_packet[53:])) 196 | 197 | 198 | #************************************************ 199 | # HB MASTER CLASS 200 | #************************************************ 201 | 202 | class HBSYSTEM(DatagramProtocol): 203 | def __init__(self, _name, _config, _report): 204 | # Define a few shortcuts to make the rest of the class more readable 205 | self._CONFIG = _config 206 | self._system = _name 207 | self._report = _report 208 | self._config = self._CONFIG['SYSTEMS'][self._system] 209 | self._laststrid = {1: b'', 2: b''} 210 | 211 | # Define shortcuts and generic function names based on the type of system we are 212 | if self._config['MODE'] == 'MASTER': 213 | self._peers = self._CONFIG['SYSTEMS'][self._system]['PEERS'] 214 | self.send_system = self.send_peers 215 | self.maintenance_loop = self.master_maintenance_loop 216 | self.datagramReceived = self.master_datagramReceived 217 | self.dereg = self.master_dereg 218 | 219 | elif self._config['MODE'] == 'PEER': 220 | self._stats = self._config['STATS'] 221 | self.send_system = self.send_master 222 | self.maintenance_loop = self.peer_maintenance_loop 223 | self.datagramReceived = self.peer_datagramReceived 224 | self.dereg = self.peer_dereg 225 | 226 | elif self._config['MODE'] == 'XLXPEER': 227 | self._stats = self._config['XLXSTATS'] 228 | self.send_system = self.send_master 229 | self.maintenance_loop = self.peer_maintenance_loop 230 | self.datagramReceived = self.peer_datagramReceived 231 | self.dereg = self.peer_dereg 232 | 233 | def startProtocol(self): 234 | # Set up periodic loop for tracking pings from peers. Run every 'PING_TIME' seconds 235 | self._system_maintenance = task.LoopingCall(self.maintenance_loop) 236 | self._system_maintenance_loop = self._system_maintenance.start(self._CONFIG['GLOBAL']['PING_TIME']) 237 | 238 | # Aliased in __init__ to maintenance_loop if system is a master 239 | def master_maintenance_loop(self): 240 | logger.debug('(%s) Master maintenance loop started', self._system) 241 | remove_list = [] 242 | for peer in self._peers: 243 | _this_peer = self._peers[peer] 244 | # Check to see if any of the peers have been quiet (no ping) longer than allowed 245 | if _this_peer['LAST_PING']+(self._CONFIG['GLOBAL']['PING_TIME']*self._CONFIG['GLOBAL']['MAX_MISSED']) < time(): 246 | remove_list.append(peer) 247 | for peer in remove_list: 248 | logger.info('(%s) Peer %s (%s) has timed out and is being removed', self._system, self._peers[peer]['CALLSIGN'], self._peers[peer]['RADIO_ID']) 249 | # Remove any timed out peers from the configuration 250 | del self._CONFIG['SYSTEMS'][self._system]['PEERS'][peer] 251 | 252 | # Aliased in __init__ to maintenance_loop if system is a peer 253 | def peer_maintenance_loop(self): 254 | logger.debug('(%s) Peer maintenance loop started', self._system) 255 | if self._stats['PING_OUTSTANDING']: 256 | self._stats['NUM_OUTSTANDING'] += 1 257 | # If we're not connected, zero out the stats and send a login request RPTL 258 | if self._stats['CONNECTION'] != 'YES' or self._stats['NUM_OUTSTANDING'] >= self._CONFIG['GLOBAL']['MAX_MISSED']: 259 | self._stats['PINGS_SENT'] = 0 260 | self._stats['PINGS_ACKD'] = 0 261 | self._stats['NUM_OUTSTANDING'] = 0 262 | self._stats['PING_OUTSTANDING'] = False 263 | self._stats['CONNECTION'] = 'RPTL_SENT' 264 | self.send_master(b''.join([RPTL, self._config['RADIO_ID']])) 265 | logger.info('(%s) Sending login request to master %s:%s', self._system, self._config['MASTER_IP'], self._config['MASTER_PORT']) 266 | # If we are connected, sent a ping to the master and increment the counter 267 | if self._stats['CONNECTION'] == 'YES': 268 | self.send_master(b''.join([RPTPING, self._config['RADIO_ID']])) 269 | logger.debug('(%s) RPTPING Sent to Master. Total Sent: %s, Total Missed: %s, Currently Outstanding: %s', self._system, self._stats['PINGS_SENT'], self._stats['PINGS_SENT'] - self._stats['PINGS_ACKD'], self._stats['NUM_OUTSTANDING']) 270 | self._stats['PINGS_SENT'] += 1 271 | self._stats['PING_OUTSTANDING'] = True 272 | 273 | def send_peers(self, _packet): 274 | for _peer in self._peers: 275 | self.send_peer(_peer, _packet) 276 | #logger.debug('(%s) Packet sent to peer %s', self._system, self._peers[_peer]['RADIO_ID']) 277 | 278 | def send_peer(self, _peer, _packet): 279 | if _packet[:4] == DMRD: 280 | _packet = b''.join([_packet[:11], _peer, _packet[15:]]) 281 | self.transport.write(_packet, self._peers[_peer]['SOCKADDR']) 282 | # KEEP THE FOLLOWING COMMENTED OUT UNLESS YOU'RE DEBUGGING DEEPLY!!!! 283 | #logger.debug('(%s) TX Packet to %s on port %s: %s', self._peers[_peer]['RADIO_ID'], self._peers[_peer]['IP'], self._peers[_peer]['PORT'], ahex(_packet)) 284 | 285 | def send_master(self, _packet): 286 | if _packet[:4] == DMRD: 287 | _packet = b''.join([_packet[:11], self._config['RADIO_ID'], _packet[15:]]) 288 | self.transport.write(_packet, self._config['MASTER_SOCKADDR']) 289 | # KEEP THE FOLLOWING COMMENTED OUT UNLESS YOU'RE DEBUGGING DEEPLY!!!! 290 | # logger.debug('(%s) TX Packet to %s:%s -- %s', self._system, self._config['MASTER_IP'], self._config['MASTER_PORT'], ahex(_packet)) 291 | 292 | def send_xlxmaster(self, radio, xlx, mastersock): 293 | radio3 = int.from_bytes(radio, 'big').to_bytes(3, 'big') 294 | radio4 = int.from_bytes(radio, 'big').to_bytes(4, 'big') 295 | xlx3 = xlx.to_bytes(3, 'big') 296 | streamid = randint(0,255).to_bytes(1, 'big')+randint(0,255).to_bytes(1, 'big')+randint(0,255).to_bytes(1, 'big')+randint(0,255).to_bytes(1, 'big') 297 | # Wait for .5 secs for the XLX to log us in 298 | for packetnr in range(5): 299 | if packetnr < 3: 300 | # First 3 packets, voice start, stream type e1 301 | strmtype = 225 302 | payload = bytearray.fromhex('4f2e00b501ae3a001c40a0c1cc7dff57d75df5d5065026f82880bd616f13f185890000') 303 | else: 304 | # Last 2 packets, voice end, stream type e2 305 | strmtype = 226 306 | payload = bytearray.fromhex('4f410061011e3a781c30a061ccbdff57d75df5d2534425c02fe0b1216713e885ba0000') 307 | packetnr1 = packetnr.to_bytes(1, 'big') 308 | strmtype1 = strmtype.to_bytes(1, 'big') 309 | _packet = b''.join([DMRD, packetnr1, radio3, xlx3, radio4, strmtype1, streamid, payload]) 310 | self.transport.write(_packet, mastersock) 311 | # KEEP THE FOLLOWING COMMENTED OUT UNLESS YOU'RE DEBUGGING DEEPLY!!!! 312 | #logger.debug('(%s) XLX Module Change Packet: %s', self._system, ahex(_packet)) 313 | return 314 | 315 | def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): 316 | pass 317 | 318 | def master_dereg(self): 319 | for _peer in self._peers: 320 | self.send_peer(_peer, MSTCL + _peer) 321 | logger.info('(%s) De-Registration sent to Peer: %s (%s)', self._system, self._peers[_peer]['CALLSIGN'], self._peers[_peer]['RADIO_ID']) 322 | 323 | def peer_dereg(self): 324 | self.send_master(RPTCL + self._config['RADIO_ID']) 325 | logger.info('(%s) De-Registration sent to Master: %s:%s', self._system, self._config['MASTER_SOCKADDR'][0], self._config['MASTER_SOCKADDR'][1]) 326 | 327 | # Aliased in __init__ to datagramReceived if system is a master 328 | def master_datagramReceived(self, _data, _sockaddr): 329 | # Keep This Line Commented Unless HEAVILY Debugging! 330 | # logger.debug('(%s) RX packet from %s -- %s', self._system, _sockaddr, ahex(_data)) 331 | 332 | # Extract the command, which is various length, all but one 4 significant characters -- RPTCL 333 | _command = _data[:4] 334 | 335 | if _command == DMRD: # DMRData -- encapsulated DMR data frame 336 | _peer_id = _data[11:15] 337 | if _peer_id in self._peers \ 338 | and self._peers[_peer_id]['CONNECTION'] == 'YES' \ 339 | and self._peers[_peer_id]['SOCKADDR'] == _sockaddr: 340 | _seq = _data[4] 341 | _rf_src = _data[5:8] 342 | _dst_id = _data[8:11] 343 | _bits = _data[15] 344 | _slot = 2 if (_bits & 0x80) else 1 345 | #_call_type = 'unit' if (_bits & 0x40) else 'group' 346 | if _bits & 0x40: 347 | _call_type = 'unit' 348 | elif (_bits & 0x23) == 0x23: 349 | _call_type = 'vcsbk' 350 | else: 351 | _call_type = 'group' 352 | _frame_type = (_bits & 0x30) >> 4 353 | _dtype_vseq = (_bits & 0xF) # data, 1=voice header, 2=voice terminator; voice, 0=burst A ... 5=burst F 354 | _stream_id = _data[16:20] 355 | #logger.debug('(%s) DMRD - Seqence: %s, RF Source: %s, Destination ID: %s', self._system, _seq, int_id(_rf_src), int_id(_dst_id)) 356 | # ACL Processing 357 | if self._CONFIG['GLOBAL']['USE_ACL']: 358 | if not acl_check(_rf_src, self._CONFIG['GLOBAL']['SUB_ACL']): 359 | if self._laststrid[_slot] != _stream_id: 360 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s FROM SUBSCRIBER %s BY GLOBAL ACL', self._system, int_id(_stream_id), int_id(_rf_src)) 361 | self._laststrid[_slot] = _stream_id 362 | return 363 | if _slot == 1 and not acl_check(_dst_id, self._CONFIG['GLOBAL']['TG1_ACL']): 364 | if self._laststrid[_slot] != _stream_id: 365 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY GLOBAL TS1 ACL', self._system, int_id(_stream_id), int_id(_dst_id)) 366 | self._laststrid[_slot] = _stream_id 367 | return 368 | if _slot == 2 and not acl_check(_dst_id, self._CONFIG['GLOBAL']['TG2_ACL']): 369 | if self._laststrid[_slot] != _stream_id: 370 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY GLOBAL TS2 ACL', self._system, int_id(_stream_id), int_id(_dst_id)) 371 | self._laststrid[_slot] = _stream_id 372 | return 373 | if self._config['USE_ACL']: 374 | if not acl_check(_rf_src, self._config['SUB_ACL']): 375 | if self._laststrid[_slot] != _stream_id: 376 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s FROM SUBSCRIBER %s BY SYSTEM ACL', self._system, int_id(_stream_id), int_id(_rf_src)) 377 | self._laststrid[_slot] = _stream_id 378 | return 379 | if _slot == 1 and not acl_check(_dst_id, self._config['TG1_ACL']): 380 | if self._laststrid[_slot] != _stream_id: 381 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY SYSTEM TS1 ACL', self._system, int_id(_stream_id), int_id(_dst_id)) 382 | self._laststrid[_slot] = _stream_id 383 | return 384 | if _slot == 2 and not acl_check(_dst_id, self._config['TG2_ACL']): 385 | if self._laststrid[_slot]!= _stream_id: 386 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY SYSTEM TS2 ACL', self._system, int_id(_stream_id), int_id(_dst_id)) 387 | self._laststrid[_slot] = _stream_id 388 | return 389 | 390 | # The basic purpose of a master is to repeat to the peers 391 | if self._config['REPEAT'] == True: 392 | pkt = [_data[:11], '', _data[15:]] 393 | for _peer in self._peers: 394 | if _peer != _peer_id: 395 | pkt[1] = _peer 396 | self.transport.write(b''.join(pkt), self._peers[_peer]['SOCKADDR']) 397 | #logger.debug('(%s) Packet on TS%s from %s (%s) for destination ID %s repeated to peer: %s (%s) [Stream ID: %s]', self._system, _slot, self._peers[_peer_id]['CALLSIGN'], int_id(_peer_id), int_id(_dst_id), self._peers[_peer]['CALLSIGN'], int_id(_peer), int_id(_stream_id)) 398 | 399 | 400 | # Userland actions -- typically this is the function you subclass for an application 401 | self.dmrd_received(_peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data) 402 | 403 | elif _command == RPTL: # RPTLogin -- a repeater wants to login 404 | _peer_id = _data[4:8] 405 | # Check to see if we've reached the maximum number of allowed peers 406 | if len(self._peers) < self._config['MAX_PEERS']: 407 | # Check for valid Radio ID 408 | if acl_check(_peer_id, self._CONFIG['GLOBAL']['REG_ACL']) and acl_check(_peer_id, self._config['REG_ACL']): 409 | # Build the configuration data strcuture for the peer 410 | self._peers.update({_peer_id: { 411 | 'CONNECTION': 'RPTL-RECEIVED', 412 | 'CONNECTED': time(), 413 | 'PINGS_RECEIVED': 0, 414 | 'LAST_PING': time(), 415 | 'SOCKADDR': _sockaddr, 416 | 'IP': _sockaddr[0], 417 | 'PORT': _sockaddr[1], 418 | 'SALT': randint(0,0xFFFFFFFF), 419 | 'RADIO_ID': str(int(ahex(_peer_id), 16)), 420 | 'CALLSIGN': '', 421 | 'RX_FREQ': '', 422 | 'TX_FREQ': '', 423 | 'TX_POWER': '', 424 | 'COLORCODE': '', 425 | 'LATITUDE': '', 426 | 'LONGITUDE': '', 427 | 'HEIGHT': '', 428 | 'LOCATION': '', 429 | 'DESCRIPTION': '', 430 | 'SLOTS': '', 431 | 'URL': '', 432 | 'SOFTWARE_ID': '', 433 | 'PACKAGE_ID': '', 434 | }}) 435 | logger.info('(%s) Repeater Logging in with Radio ID: %s, %s:%s', self._system, int_id(_peer_id), _sockaddr[0], _sockaddr[1]) 436 | _salt_str = bytes_4(self._peers[_peer_id]['SALT']) 437 | self.send_peer(_peer_id, b''.join([RPTACK, _salt_str])) 438 | self._peers[_peer_id]['CONNECTION'] = 'CHALLENGE_SENT' 439 | logger.info('(%s) Sent Challenge Response to %s for login: %s', self._system, int_id(_peer_id), self._peers[_peer_id]['SALT']) 440 | else: 441 | self.transport.write(b''.join([MSTNAK, _peer_id]), _sockaddr) 442 | logger.warning('(%s) Invalid Login from %s Radio ID: %s Denied by Registation ACL', self._system, _sockaddr[0], int_id(_peer_id)) 443 | else: 444 | self.transport.write(b''.join([MSTNAK, _peer_id]), _sockaddr) 445 | logger.warning('(%s) Registration denied from Radio ID: %s Maximum number of peers exceeded', self._system, int_id(_peer_id)) 446 | 447 | elif _command == RPTK: # Repeater has answered our login challenge 448 | _peer_id = _data[4:8] 449 | if _peer_id in self._peers \ 450 | and self._peers[_peer_id]['CONNECTION'] == 'CHALLENGE_SENT' \ 451 | and self._peers[_peer_id]['SOCKADDR'] == _sockaddr: 452 | _this_peer = self._peers[_peer_id] 453 | _this_peer['LAST_PING'] = time() 454 | _sent_hash = _data[8:] 455 | _salt_str = bytes_4(_this_peer['SALT']) 456 | _calc_hash = bhex(sha256(_salt_str+self._config['PASSPHRASE']).hexdigest()) 457 | if _sent_hash == _calc_hash: 458 | _this_peer['CONNECTION'] = 'WAITING_CONFIG' 459 | self.send_peer(_peer_id, b''.join([RPTACK, _peer_id])) 460 | logger.info('(%s) Peer %s has completed the login exchange successfully', self._system, _this_peer['RADIO_ID']) 461 | else: 462 | logger.info('(%s) Peer %s has FAILED the login exchange successfully', self._system, _this_peer['RADIO_ID']) 463 | self.transport.write(b''.join([MSTNAK, _peer_id]), _sockaddr) 464 | del self._peers[_peer_id] 465 | else: 466 | self.transport.write(b''.join([MSTNAK, _peer_id]), _sockaddr) 467 | logger.warning('(%s) Login challenge from Radio ID that has not logged in: %s', self._system, int_id(_peer_id)) 468 | 469 | elif _command == RPTC: # Repeater is sending it's configuraiton OR disconnecting 470 | if _data[:5] == RPTCL: # Disconnect command 471 | _peer_id = _data[5:9] 472 | if _peer_id in self._peers \ 473 | and self._peers[_peer_id]['CONNECTION'] == 'YES' \ 474 | and self._peers[_peer_id]['SOCKADDR'] == _sockaddr: 475 | logger.info('(%s) Peer is closing down: %s (%s)', self._system, self._peers[_peer_id]['CALLSIGN'], int_id(_peer_id)) 476 | self.transport.write(b''.join([MSTNAK, _peer_id]), _sockaddr) 477 | del self._peers[_peer_id] 478 | 479 | else: 480 | _peer_id = _data[4:8] # Configure Command 481 | if _peer_id in self._peers \ 482 | and self._peers[_peer_id]['CONNECTION'] == 'WAITING_CONFIG' \ 483 | and self._peers[_peer_id]['SOCKADDR'] == _sockaddr: 484 | _this_peer = self._peers[_peer_id] 485 | _this_peer['CONNECTION'] = 'YES' 486 | _this_peer['CONNECTED'] = time() 487 | _this_peer['LAST_PING'] = time() 488 | _this_peer['CALLSIGN'] = _data[8:16] 489 | _this_peer['RX_FREQ'] = _data[16:25] 490 | _this_peer['TX_FREQ'] = _data[25:34] 491 | _this_peer['TX_POWER'] = _data[34:36] 492 | _this_peer['COLORCODE'] = _data[36:38] 493 | _this_peer['LATITUDE'] = _data[38:46] 494 | _this_peer['LONGITUDE'] = _data[46:55] 495 | _this_peer['HEIGHT'] = _data[55:58] 496 | _this_peer['LOCATION'] = _data[58:78] 497 | _this_peer['DESCRIPTION'] = _data[78:97] 498 | _this_peer['SLOTS'] = _data[97:98] 499 | _this_peer['URL'] = _data[98:222] 500 | _this_peer['SOFTWARE_ID'] = _data[222:262] 501 | _this_peer['PACKAGE_ID'] = _data[262:302] 502 | 503 | self.send_peer(_peer_id, b''.join([RPTACK, _peer_id])) 504 | logger.info('(%s) Peer %s (%s) has sent repeater configuration', self._system, _this_peer['CALLSIGN'], _this_peer['RADIO_ID']) 505 | else: 506 | self.transport.write(b''.join([MSTNAK, _peer_id]), _sockaddr) 507 | logger.warning('(%s) Peer info from Radio ID that has not logged in: %s', self._system, int_id(_peer_id)) 508 | 509 | elif _command == RPTP: # RPTPing -- peer is pinging us 510 | _peer_id = _data[7:11] 511 | if _peer_id in self._peers \ 512 | and self._peers[_peer_id]['CONNECTION'] == "YES" \ 513 | and self._peers[_peer_id]['SOCKADDR'] == _sockaddr: 514 | self._peers[_peer_id]['PINGS_RECEIVED'] += 1 515 | self._peers[_peer_id]['LAST_PING'] = time() 516 | self.send_peer(_peer_id, b''.join([MSTPONG, _peer_id])) 517 | logger.debug('(%s) Received and answered RPTPING from peer %s (%s)', self._system, self._peers[_peer_id]['CALLSIGN'], int_id(_peer_id)) 518 | else: 519 | self.transport.write(b''.join([MSTNAK, _peer_id]), _sockaddr) 520 | logger.warning('(%s) Ping from Radio ID that is not logged in: %s', self._system, int_id(_peer_id)) 521 | 522 | elif _command == RPTO: 523 | _peer_id = _data[4:8] 524 | if _peer_id in self._peers \ 525 | and self._peers[_peer_id]['CONNECTION'] == 'YES' \ 526 | and self._peers[_peer_id]['SOCKADDR'] == _sockaddr: 527 | logger.info('(%s) Peer %s (%s) has send options: %s', self._system, self._peers[_peer_id]['CALLSIGN'], int_id(_peer_id), _data[8:]) 528 | self.transport.write(b''.join([RPTACK, _peer_id]), _sockaddr) 529 | 530 | elif _command == DMRA: 531 | _peer_id = _data[4:8] 532 | logger.info('(%s) Recieved DMR Talker Alias from peer %s, subscriber %s', self._system, self._peers[_peer_id]['CALLSIGN'], int_id(_rf_src)) 533 | 534 | else: 535 | logger.error('(%s) Unrecognized command. Raw HBP PDU: %s', self._system, ahex(_data)) 536 | 537 | # Aliased in __init__ to datagramReceived if system is a peer 538 | def peer_datagramReceived(self, _data, _sockaddr): 539 | # Keep This Line Commented Unless HEAVILY Debugging! 540 | # logger.debug('(%s) RX packet from %s -- %s', self._system, _sockaddr, ahex(_data)) 541 | 542 | # Validate that we receveived this packet from the master - security check! 543 | if self._config['MASTER_SOCKADDR'] == _sockaddr: 544 | # Extract the command, which is various length, but only 4 significant characters 545 | _command = _data[:4] 546 | if _command == DMRD: # DMRData -- encapsulated DMR data frame 547 | 548 | _peer_id = _data[11:15] 549 | if self._config['LOOSE'] or _peer_id == self._config['RADIO_ID']: # Validate the Radio_ID unless using loose validation 550 | _seq = _data[4:5] 551 | _rf_src = _data[5:8] 552 | _dst_id = _data[8:11] 553 | _bits = _data[15] 554 | _slot = 2 if (_bits & 0x80) else 1 555 | #_call_type = 'unit' if (_bits & 0x40) else 'group' 556 | if _bits & 0x40: 557 | _call_type = 'unit' 558 | elif (_bits & 0x23) == 0x23: 559 | _call_type = 'vcsbk' 560 | else: 561 | _call_type = 'group' 562 | _frame_type = (_bits & 0x30) >> 4 563 | _dtype_vseq = (_bits & 0xF) # data, 1=voice header, 2=voice terminator; voice, 0=burst A ... 5=burst F 564 | _stream_id = _data[16:20] 565 | #logger.debug('(%s) DMRD - Sequence: %s, RF Source: %s, Destination ID: %s', self._system, int_id(_seq), int_id(_rf_src), int_id(_dst_id)) 566 | 567 | # ACL Processing 568 | if self._CONFIG['GLOBAL']['USE_ACL']: 569 | if not acl_check(_rf_src, self._CONFIG['GLOBAL']['SUB_ACL']): 570 | if self._laststrid[_slot] != _stream_id: 571 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s FROM SUBSCRIBER %s BY GLOBAL ACL', self._system, int_id(_stream_id), int_id(_rf_src)) 572 | self._laststrid[_slot] = _stream_id 573 | return 574 | if _slot == 1 and not acl_check(_dst_id, self._CONFIG['GLOBAL']['TG1_ACL']): 575 | if self._laststrid[_slot] != _stream_id: 576 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY GLOBAL TS1 ACL', self._system, int_id(_stream_id), int_id(_dst_id)) 577 | self._laststrid[_slot] = _stream_id 578 | return 579 | if _slot == 2 and not acl_check(_dst_id, self._CONFIG['GLOBAL']['TG2_ACL']): 580 | if self._laststrid[_slot] != _stream_id: 581 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY GLOBAL TS2 ACL', self._system, int_id(_stream_id), int_id(_dst_id)) 582 | self._laststrid[_slot] = _stream_id 583 | return 584 | if self._config['USE_ACL']: 585 | if not acl_check(_rf_src, self._config['SUB_ACL']): 586 | if self._laststrid[_slot] != _stream_id: 587 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s FROM SUBSCRIBER %s BY SYSTEM ACL', self._system, int_id(_stream_id), int_id(_rf_src)) 588 | self._laststrid[_slot] = _stream_id 589 | return 590 | if _slot == 1 and not acl_check(_dst_id, self._config['TG1_ACL']): 591 | if self._laststrid[_slot] != _stream_id: 592 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY SYSTEM TS1 ACL', self._system, int_id(_stream_id), int_id(_dst_id)) 593 | self._laststrid[_slot] = _stream_id 594 | return 595 | if _slot == 2 and not acl_check(_dst_id, self._config['TG2_ACL']): 596 | if self._laststrid[_slot] != _stream_id: 597 | logger.info('(%s) CALL DROPPED WITH STREAM ID %s ON TGID %s BY SYSTEM TS2 ACL', self._system, int_id(_stream_id), int_id(_dst_id)) 598 | self._laststrid[_slot] = _stream_id 599 | return 600 | 601 | 602 | # Userland actions -- typically this is the function you subclass for an application 603 | self.dmrd_received(_peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data) 604 | 605 | elif _command == MSTN: # Actually MSTNAK -- a NACK from the master 606 | _peer_id = _data[6:10] 607 | if self._config['LOOSE'] or _peer_id == self._config['RADIO_ID']: # Validate the Radio_ID unless using loose validation 608 | logger.warning('(%s) MSTNAK Received. Resetting connection to the Master.', self._system) 609 | self._stats['CONNECTION'] = 'NO' # Disconnect ourselves and re-register 610 | self._stats['CONNECTED'] = time() 611 | 612 | elif _command == RPTA: # Actually RPTACK -- an ACK from the master 613 | # Depending on the state, an RPTACK means different things, in each clause, we check and/or set the state 614 | if self._stats['CONNECTION'] == 'RPTL_SENT': # If we've sent a login request... 615 | _login_int32 = _data[6:10] 616 | logger.info('(%s) Repeater Login ACK Received with 32bit ID: %s', self._system, int_id(_login_int32)) 617 | _pass_hash = sha256(b''.join([_login_int32, self._config['PASSPHRASE']])).hexdigest() 618 | _pass_hash = bhex(_pass_hash) 619 | self.send_master(b''.join([RPTK, self._config['RADIO_ID'], _pass_hash])) 620 | self._stats['CONNECTION'] = 'AUTHENTICATED' 621 | 622 | elif self._stats['CONNECTION'] == 'AUTHENTICATED': # If we've sent the login challenge... 623 | _peer_id = _data[6:10] 624 | if self._config['LOOSE'] or _peer_id == self._config['RADIO_ID']: # Validate the Radio_ID unless using loose validation 625 | logger.info('(%s) Repeater Authentication Accepted', self._system) 626 | _config_packet = b''.join([\ 627 | self._config['RADIO_ID'],\ 628 | self._config['CALLSIGN'],\ 629 | self._config['RX_FREQ'],\ 630 | self._config['TX_FREQ'],\ 631 | self._config['TX_POWER'],\ 632 | self._config['COLORCODE'],\ 633 | self._config['LATITUDE'],\ 634 | self._config['LONGITUDE'],\ 635 | self._config['HEIGHT'],\ 636 | self._config['LOCATION'],\ 637 | self._config['DESCRIPTION'],\ 638 | self._config['SLOTS'],\ 639 | self._config['URL'],\ 640 | self._config['SOFTWARE_ID'],\ 641 | self._config['PACKAGE_ID']\ 642 | ]) 643 | 644 | self.send_master(b''.join([RPTC, _config_packet])) 645 | self._stats['CONNECTION'] = 'CONFIG-SENT' 646 | logger.info('(%s) Repeater Configuration Sent', self._system) 647 | else: 648 | self._stats['CONNECTION'] = 'NO' 649 | logger.error('(%s) Master ACK Contained wrong ID - Connection Reset', self._system) 650 | 651 | elif self._stats['CONNECTION'] == 'CONFIG-SENT': # If we've sent out configuration to the master 652 | _peer_id = _data[6:10] 653 | if self._config['LOOSE'] or _peer_id == self._config['RADIO_ID']: # Validate the Radio_ID unless using loose validation 654 | logger.info('(%s) Repeater Configuration Accepted', self._system) 655 | if self._config['OPTIONS']: 656 | self.send_master(b''.join([RPTO, self._config['RADIO_ID'], self._config['OPTIONS']])) 657 | self._stats['CONNECTION'] = 'OPTIONS-SENT' 658 | logger.info('(%s) Sent options: (%s)', self._system, self._config['OPTIONS']) 659 | else: 660 | self._stats['CONNECTION'] = 'YES' 661 | self._stats['CONNECTED'] = time() 662 | logger.info('(%s) Connection to Master Completed', self._system) 663 | 664 | # If we are an XLX, send the XLX module request here. 665 | if self._config['MODE'] == 'XLXPEER': 666 | self.send_xlxmaster(self._config['RADIO_ID'], int(4000), self._config['MASTER_SOCKADDR']) 667 | self.send_xlxmaster(self._config['RADIO_ID'], self._config['XLXMODULE'], self._config['MASTER_SOCKADDR']) 668 | logger.info('(%s) Sending XLX Module request', self._system) 669 | else: 670 | self._stats['CONNECTION'] = 'NO' 671 | logger.error('(%s) Master ACK Contained wrong ID - Connection Reset', self._system) 672 | 673 | elif self._stats['CONNECTION'] == 'OPTIONS-SENT': # If we've sent out options to the master 674 | _peer_id = _data[6:10] 675 | if self._config['LOOSE'] or _peer_id == self._config['RADIO_ID']: # Validate the Radio_ID unless using loose validation 676 | logger.info('(%s) Repeater Options Accepted', self._system) 677 | self._stats['CONNECTION'] = 'YES' 678 | self._stats['CONNECTED'] = time() 679 | logger.info('(%s) Connection to Master Completed with options', self._system) 680 | else: 681 | self._stats['CONNECTION'] = 'NO' 682 | logger.error('(%s) Master ACK Contained wrong ID - Connection Reset', self._system) 683 | 684 | elif _command == MSTP: # Actually MSTPONG -- a reply to RPTPING (send by peer) 685 | _peer_id = _data[7:11] 686 | if self._config['LOOSE'] or _peer_id == self._config['RADIO_ID']: # Validate the Radio_ID unless using loose validation 687 | self._stats['PING_OUTSTANDING'] = False 688 | self._stats['NUM_OUTSTANDING'] = 0 689 | self._stats['PINGS_ACKD'] += 1 690 | logger.debug('(%s) MSTPONG Received. Pongs Since Connected: %s', self._system, self._stats['PINGS_ACKD']) 691 | 692 | elif _command == MSTC: # Actually MSTCL -- notify us the master is closing down 693 | _peer_id = _data[5:9] 694 | if self._config['LOOSE'] or _peer_id == self._config['RADIO_ID']: # Validate the Radio_ID unless using loose validation 695 | self._stats['CONNECTION'] = 'NO' 696 | logger.info('(%s) MSTCL Recieved', self._system) 697 | 698 | elif _command == RPTS: 699 | if _data[:7] == RPTSBKN: 700 | logger.info('(%s) Received Site Beacon with Repeater ID: %s', self._system, int_id(_data[7:])) 701 | 702 | else: 703 | logger.error('(%s) Received an invalid command in packet: %s', self._system, ahex(_data)) 704 | 705 | # 706 | # Socket-based reporting section 707 | # 708 | class report(NetstringReceiver): 709 | def __init__(self, factory): 710 | self._factory = factory 711 | 712 | def connectionMade(self): 713 | self._factory.clients.append(self) 714 | logger.info('(REPORT) HBlink reporting client connected: %s', self.transport.getPeer()) 715 | 716 | def connectionLost(self, reason): 717 | logger.info('(REPORT) HBlink reporting client disconnected: %s', self.transport.getPeer()) 718 | self._factory.clients.remove(self) 719 | 720 | def stringReceived(self, data): 721 | self.process_message(data) 722 | 723 | def process_message(self, _message): 724 | opcode = _message[:1] 725 | if opcode == REPORT_OPCODES['CONFIG_REQ']: 726 | logger.info('(REPORT) HBlink reporting client sent \'CONFIG_REQ\': %s', self.transport.getPeer()) 727 | self.send_config() 728 | else: 729 | logger.error('(REPORT) got unknown opcode') 730 | 731 | class reportFactory(Factory): 732 | def __init__(self, config): 733 | self._config = config 734 | 735 | def buildProtocol(self, addr): 736 | if (addr.host) in self._config['REPORTS']['REPORT_CLIENTS'] or '*' in self._config['REPORTS']['REPORT_CLIENTS']: 737 | logger.debug('(REPORT) Permitting report server connection attempt from: %s:%s', addr.host, addr.port) 738 | return report(self) 739 | else: 740 | logger.error('(REPORT) Invalid report server connection attempt from: %s:%s', addr.host, addr.port) 741 | return None 742 | 743 | def send_clients(self, _message): 744 | for client in self.clients: 745 | client.sendString(_message) 746 | 747 | def send_config(self): 748 | serialized = pickle.dumps(self._config['SYSTEMS'], protocol=2) #.decode('utf-8', errors='ignore') #pickle.HIGHEST_PROTOCOL) 749 | self.send_clients(b''.join([REPORT_OPCODES['CONFIG_SND'], serialized])) 750 | 751 | 752 | # ID ALIAS CREATION 753 | # Download 754 | def mk_aliases(_config): 755 | if _config['ALIASES']['TRY_DOWNLOAD'] == True: 756 | # Try updating peer aliases file 757 | result = try_download(_config['ALIASES']['PATH'], _config['ALIASES']['PEER_FILE'], _config['ALIASES']['PEER_URL'], _config['ALIASES']['STALE_TIME']) 758 | logger.info('(GLOBAL) %s', result) 759 | # Try updating subscriber aliases file 760 | result = try_download(_config['ALIASES']['PATH'], _config['ALIASES']['SUBSCRIBER_FILE'], _config['ALIASES']['SUBSCRIBER_URL'], _config['ALIASES']['STALE_TIME']) 761 | logger.info('(GLOBAL) %s', result) 762 | 763 | # Make Dictionaries 764 | peer_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['PEER_FILE']) 765 | if peer_ids: 766 | logger.info('(GLOBAL) ID ALIAS MAPPER: peer_ids dictionary is available') 767 | 768 | subscriber_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['SUBSCRIBER_FILE']) 769 | if subscriber_ids: 770 | logger.info('(GLOBAL) ID ALIAS MAPPER: subscriber_ids dictionary is available') 771 | 772 | talkgroup_ids = mk_id_dict(_config['ALIASES']['PATH'], _config['ALIASES']['TGID_FILE']) 773 | if talkgroup_ids: 774 | logger.info('(GLOBAL) ID ALIAS MAPPER: talkgroup_ids dictionary is available') 775 | 776 | return peer_ids, subscriber_ids, talkgroup_ids 777 | 778 | #************************************************ 779 | # MAIN PROGRAM LOOP STARTS HERE 780 | #************************************************ 781 | 782 | if __name__ == '__main__': 783 | # Python modules we need 784 | import argparse 785 | import sys 786 | import os 787 | import signal 788 | 789 | # Change the current directory to the location of the application 790 | os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) 791 | 792 | # CLI argument parser - handles picking up the config file from the command line, and sending a "help" message 793 | parser = argparse.ArgumentParser() 794 | parser.add_argument('-c', '--config', action='store', dest='CONFIG_FILE', help='/full/path/to/config.file (usually hblink.cfg)') 795 | parser.add_argument('-l', '--logging', action='store', dest='LOG_LEVEL', help='Override config file logging level.') 796 | cli_args = parser.parse_args() 797 | 798 | # Ensure we have a path for the config file, if one wasn't specified, then use the execution directory 799 | if not cli_args.CONFIG_FILE: 800 | cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg' 801 | 802 | # Call the external routine to build the configuration dictionary 803 | CONFIG = config.build_config(cli_args.CONFIG_FILE) 804 | 805 | # Call the external routing to start the system logger 806 | if cli_args.LOG_LEVEL: 807 | CONFIG['LOGGER']['LOG_LEVEL'] = cli_args.LOG_LEVEL 808 | logger = log.config_logging(CONFIG['LOGGER']) 809 | logger.info('\n\nCopyright (c) 2013, 2014, 2015, 2016, 2018, 2019, 2020\n\tThe Regents of the K0USY Group. All rights reserved.\n') 810 | logger.debug('(GLOBAL) Logging system started, anything from here on gets logged') 811 | 812 | # Set up the signal handler 813 | def sig_handler(_signal, _frame): 814 | logger.info('(GLOBAL) SHUTDOWN: HBLINK IS TERMINATING WITH SIGNAL %s', str(_signal)) 815 | hblink_handler(_signal, _frame) 816 | logger.info('(GLOBAL) SHUTDOWN: ALL SYSTEM HANDLERS EXECUTED - STOPPING REACTOR') 817 | reactor.stop() 818 | 819 | # Set signal handers so that we can gracefully exit if need be 820 | for sig in [signal.SIGTERM, signal.SIGINT]: 821 | signal.signal(sig, sig_handler) 822 | 823 | peer_ids, subscriber_ids, talkgroup_ids = mk_aliases(CONFIG) 824 | 825 | # INITIALIZE THE REPORTING LOOP 826 | if CONFIG['REPORTS']['REPORT']: 827 | report_server = config_reports(CONFIG, reportFactory) 828 | else: 829 | report_server = None 830 | logger.info('(REPORT) TCP Socket reporting not configured') 831 | 832 | # HBlink instance creation 833 | logger.info('(GLOBAL) HBlink \'HBlink.py\' -- SYSTEM STARTING...') 834 | for system in CONFIG['SYSTEMS']: 835 | if CONFIG['SYSTEMS'][system]['ENABLED']: 836 | if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE': 837 | systems[system] = OPENBRIDGE(system, CONFIG, report_server) 838 | else: 839 | systems[system] = HBSYSTEM(system, CONFIG, report_server) 840 | reactor.listenUDP(CONFIG['SYSTEMS'][system]['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['IP']) 841 | logger.debug('(GLOBAL) %s instance created: %s, %s', CONFIG['SYSTEMS'][system]['MODE'], system, systems[system]) 842 | 843 | reactor.run() 844 | -------------------------------------------------------------------------------- /log.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | ############################################################################### 4 | # Copyright (C) 2016-2018 Cortney T. Buffington, N0MJS 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software Foundation, 18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | ############################################################################### 20 | 21 | ''' 22 | This is the logging configuration for hblink.py. It changes very infrequently, 23 | so keeping in a separate module keeps hblink.py more concise. this file is 24 | likely to never change. 25 | ''' 26 | 27 | import logging 28 | from logging.config import dictConfig 29 | 30 | # Does anybody read this stuff? There's a PEP somewhere that says I should do this. 31 | __author__ = 'Cortney T. Buffington, N0MJS' 32 | __copyright__ = 'Copyright (c) 2016-2018 Cortney T. Buffington, N0MJS and the K0USY Group' 33 | __credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT' 34 | __license__ = 'GNU GPLv3' 35 | __maintainer__ = 'Cort Buffington, N0MJS' 36 | __email__ = 'n0mjs@me.com' 37 | 38 | 39 | def config_logging(_logger): 40 | dictConfig({ 41 | 'version': 1, 42 | 'disable_existing_loggers': False, 43 | 'filters': { 44 | }, 45 | 'formatters': { 46 | 'verbose': { 47 | 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' 48 | }, 49 | 'timed': { 50 | 'format': '%(levelname)s %(asctime)s %(message)s' 51 | }, 52 | 'simple': { 53 | 'format': '%(levelname)s %(message)s' 54 | }, 55 | 'syslog': { 56 | 'format': '%(name)s (%(process)d): %(levelname)s %(message)s' 57 | } 58 | }, 59 | 'handlers': { 60 | 'null': { 61 | 'class': 'logging.NullHandler' 62 | }, 63 | 'console': { 64 | 'class': 'logging.StreamHandler', 65 | 'formatter': 'simple' 66 | }, 67 | 'console-timed': { 68 | 'class': 'logging.StreamHandler', 69 | 'formatter': 'timed' 70 | }, 71 | 'file': { 72 | 'class': 'logging.FileHandler', 73 | 'formatter': 'simple', 74 | 'filename': _logger['LOG_FILE'], 75 | }, 76 | 'file-timed': { 77 | 'class': 'logging.FileHandler', 78 | 'formatter': 'timed', 79 | 'filename': _logger['LOG_FILE'], 80 | }, 81 | 'syslog': { 82 | 'class': 'logging.handlers.SysLogHandler', 83 | 'formatter': 'syslog', 84 | } 85 | }, 86 | 'root': { 87 | 'handlers': _logger['LOG_HANDLERS'].split(','), 88 | 'level': _logger['LOG_LEVEL'], 89 | 'propagate': True, 90 | }, 91 | }) 92 | 93 | return logging.getLogger(_logger['LOG_NAME']) 94 | -------------------------------------------------------------------------------- /mk_voice.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | ############################################################################### 4 | # Copyright (C) 2016-2019 Cortney T. Buffington, N0MJS 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software Foundation, 18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | ############################################################################### 20 | 21 | from bitarray import bitarray 22 | from dmr_utils3 import bptc, golay, qr 23 | from dmr_utils3.utils import bytes_3, bytes_4 24 | from dmr_utils3.const import EMB, SLOT_TYPE, BS_VOICE_SYNC, BS_DATA_SYNC, LC_OPT 25 | from random import randint 26 | from voice_lib import words 27 | 28 | # Precalculated "dmrbits" (DMRD packet byte 15) -- just (slot << 7 | this value) and you're good to go! 29 | HEADBITS = 0b00100001 30 | BURSTBITS = [0b00010000,0b00000001,0b00000010,0b00000011,0b00000100,0b00000101] 31 | TERMBITS = 0b00100010 32 | 33 | # Need a bitstring of 4-bytes of zero for burst F 34 | NULL_EMB_LC = bitarray(endian='big') 35 | NULL_EMB_LC.frombytes(b'\x00\x00\x00\x00') 36 | 37 | # This is where HBP encodes RSSI, it will need to be null 38 | TAIL = b'\x00\x00' 39 | 40 | # WARNING this funciton uses yeild to return a generator that will pass the next HBP packet for a phrase 41 | # each time that it is called. Do NOT try to use it like a normal function. 42 | def pkt_gen(_rf_src, _dst_id, _peer, _slot, _phrase): 43 | 44 | # Calculate all of the static components up-front 45 | STREAM_ID = bytes_4(randint(0x00, 0xFFFFFFFF)) 46 | SDP = _rf_src + _dst_id + _peer 47 | LC = LC_OPT + _dst_id + _rf_src 48 | 49 | HEAD_LC = bptc.encode_header_lc(LC) 50 | HEAD_LC = [HEAD_LC[:98], HEAD_LC[-98:]] 51 | 52 | TERM_LC = bptc.encode_terminator_lc(LC) 53 | TERM_LC = [TERM_LC[:98], TERM_LC[-98:]] 54 | 55 | EMB_LC = bptc.encode_emblc(LC) 56 | 57 | EMBED = [] 58 | EMBED.append( BS_VOICE_SYNC ) 59 | EMBED.append(EMB['BURST_B'][:8] + EMB_LC[1] + EMB['BURST_B'][-8:]) 60 | EMBED.append(EMB['BURST_C'][:8] + EMB_LC[2] + EMB['BURST_C'][-8:]) 61 | EMBED.append(EMB['BURST_D'][:8] + EMB_LC[3] + EMB['BURST_D'][-8:]) 62 | EMBED.append(EMB['BURST_E'][:8] + EMB_LC[4] + EMB['BURST_E'][-8:]) 63 | EMBED.append(EMB['BURST_F'][:8] + NULL_EMB_LC + EMB['BURST_F'][-8:]) 64 | 65 | 66 | #initialize the HBP calls stream sequence to 0 67 | SEQ = 0 68 | 69 | # Send the Call Stream 70 | 71 | # Send 3 Voice Header Frames 72 | for i in range(3): 73 | pkt = b'DMRD' + bytes([SEQ]) + SDP + bytes([_slot << 7 | HEADBITS]) + STREAM_ID + (HEAD_LC[0] + SLOT_TYPE['VOICE_LC_HEAD'][:10] + BS_DATA_SYNC + SLOT_TYPE['VOICE_LC_HEAD'][-10:] + HEAD_LC[1]).tobytes() + TAIL 74 | SEQ = (SEQ + 1) % 0x100 75 | yield pkt 76 | 77 | # Send each burst, six bursts per Superframe rotating through with the proper EMBED value per burst A-F 78 | for word in _phrase: 79 | for burst in range(0, len(word)): 80 | print(burst) 81 | pkt = b'DMRD' + bytes([SEQ]) + SDP + bytes([_slot << 7 | BURSTBITS[burst % 6]]) + STREAM_ID + (word[burst + 0][0] + EMBED[burst % 6] + word[burst + 0][1]).tobytes() + TAIL 82 | SEQ = (SEQ + 1) % 0x100 83 | yield pkt 84 | 85 | # Send a single Voice Terminator Frame 86 | pkt = b'DMRD' + bytes([SEQ]) + SDP + bytes([_slot << 7 | TERMBITS]) + STREAM_ID + (TERM_LC[0] + SLOT_TYPE['VOICE_LC_TERM'][:10] + BS_DATA_SYNC + SLOT_TYPE['VOICE_LC_TERM'][-10:] + TERM_LC[1]).tobytes() + TAIL 87 | SEQ = (SEQ + 1) % 0x100 88 | yield pkt 89 | 90 | # Return False to indicate we're done. 91 | return False 92 | 93 | 94 | if __name__ == '__main__': 95 | from time import time 96 | 97 | speech = pkt_gen(bytes_3(3120101), bytes_3(3120), bytes_4(312000), 0, [words['all_circuits'], words['all_circuits']]) 98 | 99 | 100 | while True: 101 | try: 102 | pkt = next(speech) 103 | except StopIteration: 104 | break 105 | print(len(pkt), pkt[4], pkt) 106 | -------------------------------------------------------------------------------- /play_ambe.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | ############################################################################### 4 | # Copyright (C) 2016-2019 Cortney T. Buffington, N0MJS 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software Foundation, 18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | ############################################################################### 20 | 21 | # Python modules we need 22 | import sys 23 | from bitarray import bitarray 24 | from time import time, sleep 25 | from importlib import import_module 26 | from binascii import b2a_hex as bhex 27 | 28 | # Twisted is pretty important, so I keep it separate 29 | from twisted.internet.protocol import Factory, Protocol 30 | from twisted.protocols.basic import NetstringReceiver 31 | from twisted.internet import reactor, task 32 | 33 | # Things we import from the main hblink module 34 | from hblink import HBSYSTEM, OPENBRIDGE, systems, hblink_handler, reportFactory, REPORT_OPCODES, mk_aliases 35 | from dmr_utils3.utils import bytes_3, bytes_4, int_id, get_alias 36 | from dmr_utils3 import decode, bptc, const 37 | import config 38 | import log 39 | from const import * 40 | from mk_voice import pkt_gen 41 | from voice_lib import words 42 | 43 | # Stuff for socket reporting 44 | import pickle 45 | # REMOVE LATER from datetime import datetime 46 | # The module needs logging, but handlers, etc. are controlled by the parent 47 | import logging 48 | logger = logging.getLogger(__name__) 49 | 50 | 51 | # Does anybody read this stuff? There's a PEP somewhere that says I should do this. 52 | __author__ = 'Cortney T. Buffington, N0MJS' 53 | __copyright__ = 'Copyright (c) 2016-2019 Cortney T. Buffington, N0MJS and the K0USY Group' 54 | __credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT' 55 | __license__ = 'GNU GPLv3' 56 | __maintainer__ = 'Cort Buffington, N0MJS' 57 | __email__ = 'n0mjs@me.com' 58 | 59 | # Module gobal varaibles 60 | 61 | 62 | class OBP(OPENBRIDGE): 63 | 64 | def __init__(self, _name, _config, _report): 65 | OPENBRIDGE.__init__(self, _name, _config, _report) 66 | 67 | 68 | def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): 69 | pass 70 | 71 | 72 | class HBP(HBSYSTEM): 73 | 74 | def __init__(self, _name, _config, _report): 75 | HBSYSTEM.__init__(self, _name, _config, _report) 76 | self.last_stream = b'\x00' 77 | 78 | def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): 79 | if (_frame_type == HBPF_DATA_SYNC) and (_dtype_vseq == HBPF_SLT_VTERM) and (_stream_id != self.last_stream): 80 | print(int_id(_stream_id), int_id(self.last_stream)) 81 | self.last_stream = _stream_id 82 | print('start speech') 83 | speech = pkt_gen(bytes_3(3120101), bytes_3(2), bytes_4(3120119), 0, [words['all_circuits'],words['all_circuits']]) 84 | 85 | sleep(1) 86 | while True: 87 | try: 88 | pkt = next(speech) 89 | except StopIteration: 90 | break 91 | sleep(.058) 92 | self.send_system(pkt) 93 | print(bhex(pkt)) 94 | print('end speech') 95 | 96 | 97 | 98 | #************************************************ 99 | # MAIN PROGRAM LOOP STARTS HERE 100 | #************************************************ 101 | 102 | if __name__ == '__main__': 103 | 104 | import argparse 105 | import sys 106 | import os 107 | import signal 108 | 109 | # Change the current directory to the location of the application 110 | os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) 111 | 112 | # CLI argument parser - handles picking up the config file from the command line, and sending a "help" message 113 | parser = argparse.ArgumentParser() 114 | parser.add_argument('-c', '--config', action='store', dest='CONFIG_FILE', help='/full/path/to/config.file (usually hblink.cfg)') 115 | parser.add_argument('-l', '--logging', action='store', dest='LOG_LEVEL', help='Override config file logging level.') 116 | cli_args = parser.parse_args() 117 | 118 | # Ensure we have a path for the config file, if one wasn't specified, then use the default (top of file) 119 | if not cli_args.CONFIG_FILE: 120 | cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg' 121 | 122 | # Call the external routine to build the configuration dictionary 123 | CONFIG = config.build_config(cli_args.CONFIG_FILE) 124 | 125 | # Start the system logger 126 | if cli_args.LOG_LEVEL: 127 | CONFIG['LOGGER']['LOG_LEVEL'] = cli_args.LOG_LEVEL 128 | logger = log.config_logging(CONFIG['LOGGER']) 129 | logger.info('\n\nCopyright (c) 2013, 2014, 2015, 2016, 2018, 2019\n\tThe Regents of the K0USY Group. All rights reserved.\n') 130 | logger.debug('(GLOBAL) Logging system started, anything from here on gets logged') 131 | 132 | # Set up the signal handler 133 | def sig_handler(_signal, _frame): 134 | logger.info('(GLOBAL) SHUTDOWN: CONFBRIDGE IS TERMINATING WITH SIGNAL %s', str(_signal)) 135 | hblink_handler(_signal, _frame) 136 | logger.info('(GLOBAL) SHUTDOWN: ALL SYSTEM HANDLERS EXECUTED - STOPPING REACTOR') 137 | reactor.stop() 138 | 139 | # Set signal handers so that we can gracefully exit if need be 140 | for sig in [signal.SIGINT, signal.SIGTERM]: 141 | signal.signal(sig, sig_handler) 142 | 143 | # Create the name-number mapping dictionaries 144 | peer_ids, subscriber_ids, talkgroup_ids = mk_aliases(CONFIG) 145 | 146 | # INITIALIZE THE REPORTING LOOP 147 | if CONFIG['REPORTS']['REPORT']: 148 | report_server = config_reports(CONFIG, bridgeReportFactory) 149 | else: 150 | report_server = None 151 | logger.info('(REPORT) TCP Socket reporting not configured') 152 | 153 | # HBlink instance creation 154 | logger.info('(GLOBAL) HBlink \'bridge.py\' -- SYSTEM STARTING...') 155 | for system in CONFIG['SYSTEMS']: 156 | if CONFIG['SYSTEMS'][system]['ENABLED']: 157 | if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE': 158 | systems[system] = OBP(system, CONFIG, report_server) 159 | else: 160 | systems[system] = HBP(system, CONFIG, report_server) 161 | reactor.listenUDP(CONFIG['SYSTEMS'][system]['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['IP']) 162 | logger.debug('(GLOBAL) %s instance created: %s, %s', CONFIG['SYSTEMS'][system]['MODE'], system, systems[system]) 163 | 164 | def loopingErrHandle(failure): 165 | logger.error('(GLOBAL) STOPPING REACTOR TO AVOID MEMORY LEAK: Unhandled error in timed loop.\n %s', failure) 166 | reactor.stop() 167 | 168 | 169 | reactor.run() 170 | -------------------------------------------------------------------------------- /playback.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | ############################################################################### 4 | # Copyright (C) 2016-2019 Cortney T. Buffington, N0MJS (and Mike Zingman N4IRR) 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software Foundation, 18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | ############################################################################### 20 | 21 | 22 | # Python modules we need 23 | import sys 24 | from bitarray import bitarray 25 | from time import time, sleep 26 | from importlib import import_module 27 | 28 | # Twisted is pretty important, so I keep it separate 29 | from twisted.internet.protocol import Factory, Protocol 30 | from twisted.protocols.basic import NetstringReceiver 31 | from twisted.internet import reactor, task 32 | 33 | # Things we import from the main hblink module 34 | from hblink import HBSYSTEM, systems, hblink_handler, reportFactory, REPORT_OPCODES, config_reports, mk_aliases 35 | from dmr_utils3.utils import bytes_3, int_id, get_alias 36 | from dmr_utils3 import decode, bptc, const 37 | import config 38 | import log 39 | import const 40 | 41 | # The module needs logging logging, but handlers, etc. are controlled by the parent 42 | import logging 43 | logger = logging.getLogger(__name__) 44 | 45 | 46 | # Does anybody read this stuff? There's a PEP somewhere that says I should do this. 47 | __author__ = 'Cortney T. Buffington, N0MJS and Mike Zingman, N4IRR' 48 | __copyright__ = 'Copyright (c) 2016-2019 Cortney T. Buffington, N0MJS and the K0USY Group' 49 | __license__ = 'GNU GPLv3' 50 | __maintainer__ = 'Cort Buffington, N0MJS' 51 | __email__ = 'n0mjs@me.com' 52 | __status__ = 'pre-alpha' 53 | 54 | # Module gobal varaibles 55 | 56 | class playback(HBSYSTEM): 57 | 58 | def __init__(self, _name, _config, _report): 59 | HBSYSTEM.__init__(self, _name, _config, _report) 60 | 61 | # Status information for the system, TS1 & TS2 62 | # 1 & 2 are "timeslot" 63 | # In TX_EMB_LC, 2-5 are burst B-E 64 | self.STATUS = { 65 | 1: { 66 | 'RX_START': time(), 67 | 'RX_SEQ': '\x00', 68 | 'RX_RFS': '\x00', 69 | 'TX_RFS': '\x00', 70 | 'RX_STREAM_ID': '\x00', 71 | 'TX_STREAM_ID': '\x00', 72 | 'RX_TGID': '\x00\x00\x00', 73 | 'TX_TGID': '\x00\x00\x00', 74 | 'RX_TIME': time(), 75 | 'TX_TIME': time(), 76 | 'RX_TYPE': const.HBPF_SLT_VTERM, 77 | 'RX_LC': '\x00', 78 | 'TX_H_LC': '\x00', 79 | 'TX_T_LC': '\x00', 80 | 'TX_EMB_LC': { 81 | 1: '\x00', 82 | 2: '\x00', 83 | 3: '\x00', 84 | 4: '\x00', 85 | } 86 | }, 87 | 2: { 88 | 'RX_START': time(), 89 | 'RX_SEQ': '\x00', 90 | 'RX_RFS': '\x00', 91 | 'TX_RFS': '\x00', 92 | 'RX_STREAM_ID': '\x00', 93 | 'TX_STREAM_ID': '\x00', 94 | 'RX_TGID': '\x00\x00\x00', 95 | 'TX_TGID': '\x00\x00\x00', 96 | 'RX_TIME': time(), 97 | 'TX_TIME': time(), 98 | 'RX_TYPE': const.HBPF_SLT_VTERM, 99 | 'RX_LC': '\x00', 100 | 'TX_H_LC': '\x00', 101 | 'TX_T_LC': '\x00', 102 | 'TX_EMB_LC': { 103 | 1: '\x00', 104 | 2: '\x00', 105 | 3: '\x00', 106 | 4: '\x00', 107 | } 108 | } 109 | } 110 | self.CALL_DATA = [] 111 | 112 | def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): 113 | pkt_time = time() 114 | dmrpkt = _data[20:53] 115 | _bits = _data[15] 116 | if _call_type == 'group': 117 | 118 | # Is this is a new call stream? 119 | if (_stream_id != self.STATUS[_slot]['RX_STREAM_ID']): 120 | self.STATUS['RX_START'] = pkt_time 121 | logger.info('(%s) *START RECORDING* STREAM ID: %s SUB: %s (%s) REPEATER: %s (%s) TGID %s (%s), TS %s', \ 122 | self._system, int_id(_stream_id), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot) 123 | self.CALL_DATA.append(_data) 124 | self.STATUS[_slot]['RX_STREAM_ID'] = _stream_id 125 | return 126 | 127 | # Final actions - Is this a voice terminator? 128 | if (_frame_type == const.HBPF_DATA_SYNC) and (_dtype_vseq == const.HBPF_SLT_VTERM) and (self.STATUS[_slot]['RX_TYPE'] != const.HBPF_SLT_VTERM) and (self.CALL_DATA): 129 | call_duration = pkt_time - self.STATUS['RX_START'] 130 | self.CALL_DATA.append(_data) 131 | logger.info('(%s) *END RECORDING* STREAM ID: %s', self._system, int_id(_stream_id)) 132 | sleep(2) 133 | logger.info('(%s) *START PLAYBACK* STREAM ID: %s SUB: %s (%s) REPEATER: %s (%s) TGID %s (%s), TS %s, Duration: %s', \ 134 | self._system, int_id(_stream_id), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot, call_duration) 135 | for i in self.CALL_DATA: 136 | self.send_system(i) 137 | #print(i) 138 | sleep(0.06) 139 | self.CALL_DATA = [] 140 | logger.info('(%s) *END PLAYBACK* STREAM ID: %s', self._system, int_id(_stream_id)) 141 | 142 | else: 143 | if self.CALL_DATA: 144 | self.CALL_DATA.append(_data) 145 | 146 | 147 | # Mark status variables for use later 148 | self.STATUS[_slot]['RX_RFS'] = _rf_src 149 | self.STATUS[_slot]['RX_TYPE'] = _dtype_vseq 150 | self.STATUS[_slot]['RX_TGID'] = _dst_id 151 | self.STATUS[_slot]['RX_TIME'] = pkt_time 152 | self.STATUS[_slot]['RX_STREAM_ID'] = _stream_id 153 | 154 | 155 | #************************************************ 156 | # MAIN PROGRAM LOOP STARTS HERE 157 | #************************************************ 158 | 159 | if __name__ == '__main__': 160 | 161 | import argparse 162 | import sys 163 | import os 164 | import signal 165 | from dmr_utils3.utils import try_download, mk_id_dict 166 | 167 | # Change the current directory to the location of the application 168 | os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) 169 | 170 | # CLI argument parser - handles picking up the config file from the command line, and sending a "help" message 171 | parser = argparse.ArgumentParser() 172 | parser.add_argument('-c', '--config', action='store', dest='CONFIG_FILE', help='/full/path/to/config.file (usually hblink.cfg)') 173 | parser.add_argument('-l', '--logging', action='store', dest='LOG_LEVEL', help='Override config file logging level.') 174 | cli_args = parser.parse_args() 175 | 176 | # Ensure we have a path for the config file, if one wasn't specified, then use the default (top of file) 177 | if not cli_args.CONFIG_FILE: 178 | cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg' 179 | 180 | # Call the external routine to build the configuration dictionary 181 | CONFIG = config.build_config(cli_args.CONFIG_FILE) 182 | 183 | # Start the system logger 184 | if cli_args.LOG_LEVEL: 185 | CONFIG['LOGGER']['LOG_LEVEL'] = cli_args.LOG_LEVEL 186 | logger = log.config_logging(CONFIG['LOGGER']) 187 | logger.info('\n\nCopyright (c) 2013, 2014, 2015, 2016, 2018, 2019\n\tThe Founding Members of the K0USY Group. All rights reserved.\n') 188 | logger.debug('Logging system started, anything from here on gets logged') 189 | 190 | # Set up the signal handler 191 | def sig_handler(_signal, _frame): 192 | logger.info('SHUTDOWN: HBROUTER IS TERMINATING WITH SIGNAL %s', str(_signal)) 193 | hblink_handler(_signal, _frame) 194 | logger.info('SHUTDOWN: ALL SYSTEM HANDLERS EXECUTED - STOPPING REACTOR') 195 | reactor.stop() 196 | 197 | # Set signal handers so that we can gracefully exit if need be 198 | for sig in [signal.SIGTERM, signal.SIGINT]: 199 | signal.signal(sig, sig_handler) 200 | 201 | # ID ALIAS CREATION 202 | # Download 203 | if CONFIG['ALIASES']['TRY_DOWNLOAD'] == True: 204 | # Try updating peer aliases file 205 | result = try_download(CONFIG['ALIASES']['PATH'], CONFIG['ALIASES']['PEER_FILE'], CONFIG['ALIASES']['PEER_URL'], CONFIG['ALIASES']['STALE_TIME']) 206 | logger.info(result) 207 | # Try updating subscriber aliases file 208 | result = try_download(CONFIG['ALIASES']['PATH'], CONFIG['ALIASES']['SUBSCRIBER_FILE'], CONFIG['ALIASES']['SUBSCRIBER_URL'], CONFIG['ALIASES']['STALE_TIME']) 209 | logger.info(result) 210 | 211 | # Create the name-number mapping dictionaries 212 | peer_ids, subscriber_ids, talkgroup_ids = mk_aliases(CONFIG) 213 | 214 | # INITIALIZE THE REPORTING LOOP 215 | report_server = config_reports(CONFIG, reportFactory) 216 | 217 | # HBlink instance creation 218 | logger.info('HBlink \'playback.py\' (c) 2017-2019 Cort Buffington, N0MJS & Mike Zingman, N4IRR -- SYSTEM STARTING...') 219 | for system in CONFIG['SYSTEMS']: 220 | if CONFIG['SYSTEMS'][system]['ENABLED']: 221 | if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE': 222 | logger.critical('%s FATAL: Instance is mode \'OPENBRIDGE\', \n\t\t...Which would be tragic for playback, since it carries multiple call\n\t\tstreams simultaneously. playback.py onlyl works with MMDVM-based systems', system) 223 | sys.exit('playback.py cannot function with systems that are not MMDVM devices. System {} is configured as an OPENBRIDGE'.format(system)) 224 | else: 225 | systems[system] = playback(system, CONFIG, report_server) 226 | reactor.listenUDP(CONFIG['SYSTEMS'][system]['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['IP']) 227 | logger.debug('%s instance created: %s, %s', CONFIG['SYSTEMS'][system]['MODE'], system, systems[system]) 228 | 229 | reactor.run() 230 | -------------------------------------------------------------------------------- /reporting_const.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018 Cortney T. Buffington, N0MJS 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software Foundation, 16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | ############################################################################### 18 | 19 | # Opcodes for the network-based reporting protocol 20 | 21 | REPORT_OPCODES = { 22 | 'CONFIG_REQ': b'\x00', 23 | 'CONFIG_SND': b'\x01', 24 | 'BRIDGE_REQ': b'\x02', 25 | 'BRIDGE_SND': b'\x03', 26 | 'CONFIG_UPD': b'\x04', 27 | 'BRIDGE_UPD': b'\x05', 28 | 'LINK_EVENT': b'\x06', 29 | 'BRDG_EVENT': b'\x07', 30 | } 31 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | bitstring>=3.1.9 2 | bitarray>=2.3.5 3 | Twisted>=21.7.0 4 | dmr_utils3>=0.1.29 5 | configparser>=5.2.0 6 | -------------------------------------------------------------------------------- /rules_SAMPLE.py: -------------------------------------------------------------------------------- 1 | ''' 2 | THIS EXAMPLE WILL NOT WORK AS IT IS - YOU MUST SPECIFY YOUR OWN VALUES!!! 3 | 4 | This file is organized around the "Conference Bridges" that you wish to use. If you're a c-Bridge 5 | person, think of these as "bridge groups". You might also liken them to a "reflector". If a particular 6 | system is "ACTIVE" on a particular conference bridge, any traffid from that system will be sent 7 | to any other system that is active on the bridge as well. This is not an "end to end" method, because 8 | each system must independently be activated on the bridge. 9 | 10 | The first level (e.g. "WORLDWIDE" or "STATEWIDE" in the examples) is the name of the conference 11 | bridge. This is any arbitrary ASCII text string you want to use. Under each conference bridge 12 | definition are the following items -- one line for each HBSystem as defined in the main HBlink 13 | configuration file. 14 | 15 | * SYSTEM - The name of the sytem as listed in the main hblink configuration file (e.g. hblink.cfg) 16 | This MUST be the exact same name as in the main config file!!! 17 | * TS - Timeslot used for matching traffic to this confernce bridge 18 | XLX connections should *ALWAYS* use TS 2 only. 19 | * TGID - Talkgroup ID used for matching traffic to this conference bridge 20 | XLX connections should *ALWAYS* use TG 9 only. 21 | * ON and OFF are LISTS of Talkgroup IDs used to trigger this system off and on. Even if you 22 | only want one (as shown in the ON example), it has to be in list format. None can be 23 | handled with an empty list, such as " 'ON': [] ". 24 | * TO_TYPE is timeout type. If you want to use timers, ON means when it's turned on, it will 25 | turn off afer the timout period and OFF means it will turn back on after the timout 26 | period. If you don't want to use timers, set it to anything else, but 'NONE' might be 27 | a good value for documentation! 28 | * TIMOUT is a value in minutes for the timout timer. No, I won't make it 'seconds', so don't 29 | ask. Timers are performance "expense". 30 | * RESET is a list of Talkgroup IDs that, in addition to the ON and OFF lists will cause a running 31 | timer to be reset. This is useful if you are using different TGIDs for voice traffic than 32 | triggering. If you are not, there is NO NEED to use this feature. 33 | ''' 34 | 35 | BRIDGES = { 36 | 'WORLDWIDE': [ 37 | {'SYSTEM': 'MASTER-1', 'TS': 1, 'TGID': 1, 'ACTIVE': True, 'TIMEOUT': 2, 'TO_TYPE': 'ON', 'ON': [2,], 'OFF': [9,10], 'RESET': []}, 38 | {'SYSTEM': 'CLIENT-1', 'TS': 1, 'TGID': 3100, 'ACTIVE': True, 'TIMEOUT': 2, 'TO_TYPE': 'ON', 'ON': [2,], 'OFF': [9,10], 'RESET': []}, 39 | ], 40 | 'ENGLISH': [ 41 | {'SYSTEM': 'MASTER-1', 'TS': 1, 'TGID': 13, 'ACTIVE': True, 'TIMEOUT': 2, 'TO_TYPE': 'NONE', 'ON': [3,], 'OFF': [8,10], 'RESET': []}, 42 | {'SYSTEM': 'CLIENT-2', 'TS': 1, 'TGID': 13, 'ACTIVE': True, 'TIMEOUT': 2, 'TO_TYPE': 'NONE', 'ON': [3,], 'OFF': [8,10], 'RESET': []}, 43 | ], 44 | 'STATEWIDE': [ 45 | {'SYSTEM': 'MASTER-1', 'TS': 2, 'TGID': 3129, 'ACTIVE': True, 'TIMEOUT': 2, 'TO_TYPE': 'NONE', 'ON': [4,], 'OFF': [7,10], 'RESET': []}, 46 | {'SYSTEM': 'CLIENT-2', 'TS': 2, 'TGID': 3129, 'ACTIVE': True, 'TIMEOUT': 2, 'TO_TYPE': 'NONE', 'ON': [4,], 'OFF': [7,10], 'RESET': []}, 47 | ] 48 | } 49 | 50 | ''' 51 | list the names of each system that should bridge unit to unit (individual) calls. 52 | ''' 53 | 54 | UNIT = ['ONE', 'TWO'] 55 | 56 | ''' 57 | This is for testing the syntax of the file. It won't eliminate all errors, but running this file 58 | like it were a Python program itself will tell you if the syntax is correct! 59 | ''' 60 | 61 | if __name__ == '__main__': 62 | from pprint import pprint 63 | pprint(BRIDGES) 64 | print(UNIT) 65 | -------------------------------------------------------------------------------- /voice_lib.py: -------------------------------------------------------------------------------- 1 | from bitarray import bitarray 2 | 3 | words = { 4 | 'all_circuits': [ 5 | [bitarray('001011000001010000100010001001011111101010110000110001100010011001011000001010010000000100000111010000111101'), bitarray('100101001000101100110100111010010101011010110100001001100010000001111001101000010010000101110010111000101011')], 6 | [bitarray('000010010000010101100110000100000010111101001010001111000010001100111011001111010110010000100100110101000111'), bitarray('001000001000100101100010010100100010001111010110011111000110001100100111000110100100110111100011001010011000')], 7 | [bitarray('111111110010101010101001111000111010110110011010011000001001110011011101001110000011001101111010100001111111'), bitarray('010101101001110001010011011000111111000011000011011100000011011001011011100111110010111001100001000000111111')], 8 | [bitarray('001010110011001000100111010100101001100101101010101000100101110110000001010111110001111001000110000000101110'), bitarray('000010110010010111110111111100101110001010100010101101000101000010100111000101001101111000001011010000000011')], 9 | [bitarray('010011010001100000101011110101010011011001101000011100101010001100110110000010100111111001101000101000000010'), bitarray('011011111110101000011001100000000111000011101001010110101000010101111000101110101010001101100001100111010000')], 10 | [bitarray('011111010010011100111010111110010110101001101100100010110000011000101011000111000100001001011000000100111111'), bitarray('000010010011100011001101101101101111000110000101101001000110001000111000111010101111001011111111111000000000')], 11 | [bitarray('010111101111010000000011000001101100111111000101011011001011101001100010001010111010000100000001011100111010'), bitarray('011110001000001110000010111101001111000011111100110100100110011001111100110100101100011100110001101000111111')], 12 | [bitarray('010010011010101100000110011100101011010100000111001101001110100001110101001111001111101000100101001101110110'), bitarray('000110000010000010011011111011101001111100110000000100000000000001000110011110101011100011010001110111100111')], 13 | [bitarray('111001100001010000001010100000000101001011011111000111111111011110001001010110111100000101111001101101001001'), bitarray('011000101100011110011101100100110111000011110001101001111001001001111100111110101010101100101111001011000000')], 14 | [bitarray('011011010000111000010110001000101100101001101011111110111110010000100111010010110110000101100011001100101001'), bitarray('111001100010011101110111100100111110000010000001001100000111001001011001101001001011101100010011111111000001')], 15 | [bitarray('011110110101001101000000010100001011101000010001001101010010101100111010010110010111100001000101101001000111'), bitarray('111011000111011011010010010011001110010110110000111001101010000111110011101001100010011010000010101110101101')], 16 | [bitarray('011010011101000101101000101001111000000101101010010111011001110001010001000010110101100000011011100101111011'), bitarray('000110111010011111001001010111001011011010100010101100001000011110111111110100000111101100010101010100100111')], 17 | [bitarray('001110101010000100000001000000011111011110111011011111000111100100011011010110101101001001000111001101011101'), bitarray('001110000011100011000100110111000111011111001001110100000010010001001010010010101111010101111000011011111011')], 18 | [bitarray('001011101111111001000100011000001101000111100010110101001110000101000110011011101001101101100001011000010100'), bitarray('010010001111110111101001101101110110000010011110110001100010010000010000110011100010101011000011110000011000')], 19 | [bitarray('010110011011111100001101010011000111110001001011000101011011011001011000000010111111010101001000011101111101'), bitarray('111111111011010100001110001101011000010011001101011100110011011101011101100010110000001111001100100000000010')], 20 | [bitarray('001010011100101100100000000001001111101011100110010101000111010010100011011011111001110001000011001001011111'), bitarray('110000100100101001000101111111100011010011001010110001000011011101101100100101100111110000000110101110010001')], 21 | [bitarray('010011111111100001100111110101011100111100100111110010011111101100011100110100100111000101100100100001001010'), bitarray('011011111010000010001011010111000100110001000001000001101111001010101011000011110111000011001011001100101111')], 22 | [bitarray('111101100010001101101100011010011111011010000110000110011011010101011000111100110010010001101000000111011100'), bitarray('010000001110011111011101111010010111100001100000110001101100101000000110100111011100101000011100111011101111')], 23 | [bitarray('101001000000100001101110111000101111000001110100110011000011100101011010110101100101111000001010111001110010'), bitarray('110110000100001101011000100000100100101001000111101101010100111000110000111101100000001010011000101010110111')], 24 | [bitarray('111100100010111001101111111011110110000010101100010000011000011100100100110000100011110001101111110111010100'), bitarray('001010001110010000011011011101000100110100110000111101001110111111010110001010001110010000011010001100010111')], 25 | [bitarray('101000100110111100101001110110110110010010000110110001011101000111011001101100010100111100001000110111110110'), bitarray('011011100101111000011101000111011001101101110110100100101100111111110001010001001111110100011000100100100011')], 26 | [bitarray('100001110100101011110100010100010001011000110100100000010100001100010111101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')] 27 | ], 28 | '0': [ 29 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 30 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 31 | [bitarray('000110011010000101000001001001011010110001000001101010011000001000010110001010101000001000100011000100111011'), bitarray('000010011011001111010000100100001011010111001000110100100001010000011101011010001110001001011101001111101010')], 32 | [bitarray('000011001010101101111101010101011010011001001101010111001010011100011011000011101100110101001101001111111111'), bitarray('010101110001100010000111110110011010100100100101001100001110011010110110100110001110100000100011110010001110')], 33 | [bitarray('101000100011010100101101011100100010101111100100000000001110010101001001110101010110000001001110001101110000'), bitarray('111101110100110000001110100000001101110100110110101000001010010010100000101101000110110011101011110110110111')], 34 | [bitarray('111001100111111001000000101011000111000011001100111011011001100111110001111001100000100001100010101001110001'), bitarray('000111100111011011010101001100100001111101110010100001000010111101000100001111000000010111000001000101100100')], 35 | [bitarray('111000100001110101010101111100000101010000001000010010010101100110101111111001000100111101101001110100100010'), bitarray('000100111000110101000000000100011011100001100010111000001101100001110100011101110000010000010100011110010111')], 36 | [bitarray('101101110100101111110100001001000110010100000110100101110000010001110110111111111010110011100000010100100010'), bitarray('010010010101110100110110011100001101101011001010101001000000001000000000000001000100010000001000000010000000')] 37 | ], 38 | '1': [ 39 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 40 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 41 | [bitarray('001111101011000100000101011101000110111010111110010100001011011000100110000111001000110000000110000010100001'), bitarray('011011001111100111000111001101011000000011101000111000100011111101100100001011000110000100010011101101000011')], 42 | [bitarray('011011001010100100100011010101110111110001000000011110010101010101011011111100010001000000100000000001100011'), bitarray('001010101101100011110000111010000001111000100010001100100001001001010100011010101000101011010001101010110111')], 43 | [bitarray('111000100001001001100011001001010100111001010001010010001111000011001101101100010110000101100010100111000111'), bitarray('000011011000111100000100011100000101101101010010111000000111101011100010011010100101011011001010101001101011')], 44 | [bitarray('100100000000100100100001100011010011010001001110001110011000001010110111110001100100110001100000100110100001'), bitarray('001111101001110110001100100110000101100101000101101100101101111110110111011001101000100001011110111001110011')], 45 | [bitarray('111100010001110001101110110111110110000011001100010000001100010001000110110100111101010001101011100010000000'), bitarray('000001100000100000001001111000010111010011001100111110100110011100110101011101010011110110010000110001110000')], 46 | [bitarray('110011101011111011100000011100000000011010100111111100010110011101001101110010001001100011000101011101100010'), bitarray('011000111100100101100010101111000101110010011000100011000100011101100010011000111100100101100010101011000101')], 47 | [bitarray('110010011000100011000100011101100010011000111100100101100010101011000101101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')] 48 | ], 49 | '2': [ 50 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 51 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 52 | [bitarray('110000000100010000000111110101100001000011101100110101111000111100111111100000100000100000001000101001000000'), bitarray('001110101010000000010101110101101110100100100011100101101010111000010010101101010010100100111111010001100101')], 53 | [bitarray('110000100001111001001101100111000110000110111110010100011100000001010011100000100110110000001010101110110110'), bitarray('011111010100110100001000001011011110101100011000010000001101110010100110010000111110010000011101111110001111')], 54 | [bitarray('101000100010011101001000110110000111000000000011000110010000001001011011111100010101010111010101011101000100'), bitarray('011100010001100010011011100010110010110110011000100011000100011101100010011000111101101001000010101011110100')], 55 | [bitarray('111110011010100011100100011101000010010000011100100001100010111011110100110110011000100011000100011101100010'), bitarray('011000101101100001100010100011110110101011001010101001000000001000000000000001000100010000001000000010000000')] 56 | ], 57 | '3': [ 58 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 59 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 60 | [bitarray('010010100001100001000010001101011011001000111110001111000001000111100011010011101110011001000010011100101110'), bitarray('000101101010111011000011011101101111000111011100111101100110011000001100001010100110101000011000000101110010')], 61 | [bitarray('010010101010100100100101011001111111011100100101010000101101101100100110010010101000100000100110010101011100'), bitarray('010100110111010000111110111100110011101101010100011100100010000001000101101110000101101011011010111111111010')], 62 | [bitarray('101000100000010100000000111100100100110101001101101100010100011110101010101000000011011100000010111100010101'), bitarray('110101001100101100000001000110011010100101100101101100100111111000000101001011011011110011100110011110101010')], 63 | [bitarray('100000000110111000111111010001110111001011011001011010011001100110000111111100000001110101011001010001010110'), bitarray('001010100001110010011110110000011110100000100111111100011100011001000101001011001011010010011100101111100110')], 64 | [bitarray('111100010010111101001001000101110110000110000111100011011000100100001110100100101001010000101110111011110000'), bitarray('000001101111010100011100110111011010111001010010101001001010101011110110011000100110000000011101111110011110')], 65 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')] 66 | ], 67 | '4': [ 68 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 69 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 70 | [bitarray('001111001110110001100001110011011110000111111111011111011001101000001110010011001010111000000110111111111100'), bitarray('011110010000100110001110101111010010100000010010001000001101000001101001001100001010000111000111001110101111')], 71 | [bitarray('111000110110000101001001011001111001010001000000101010000100001100000011101100100110010100101101001111001101'), bitarray('011000000100110010001011101001011001110000010010000001001010010111110111110010100100001000000101110000000110')], 72 | [bitarray('101001110011100101001010011010001100011000001110000001000110011100000011100001010000110001101000000011000101'), bitarray('101011100010001110011001011010110000111101110110111000001110011011100000111110101100110011011001001000101001')], 73 | [bitarray('101000110011100101101111010011000000101000101110001011011100110000011011100100110000101101101110010011000010'), bitarray('101000001100010011111010111000011011101100010100110001101110000000000011110100100000100111000101010010011100')], 74 | [bitarray('111100100101101001101111110100000110010010000011100000010000101011100010101001010011110000001101101000110010'), bitarray('010101110011000001010101011011000000101011001010101001000000001000000000000001000100010000001000000010000000')] 75 | ], 76 | '5': [ 77 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 78 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 79 | [bitarray('000110011110101101100001011101001101000100011001100100001011111010011010001011101000100101101110000101011111'), bitarray('010101111111000011111000001100011000100100000011001100101100001000001101011101111011010011110101010011001011')], 80 | [bitarray('101000000000000000101101000000011100010000011101001111000110001110101011100001110001010000000111111100101000'), bitarray('010100111111101111011011110110000111111001000111011101000001111100001001011001110101011011001111100100011010')], 81 | [bitarray('111100110111010001011000011101010010101010111010100101111001000010000110100000010100110101111111010000000000'), bitarray('101001110101111011000101000011111001100100000000101001101011100000000101110000010111100100011001010001000111')], 82 | [bitarray('101000110000101100001011100000010110001111101010010000010000110001001011101100000100110001101011111011110011'), bitarray('111000011100000100010011111010110100101100110100101101101000111110101011011010100110011011111000101100000011')], 83 | [bitarray('110101110010110111100011001100001111011000101101110010110101101000110100110100111010110110100011011000100101'), bitarray('100001000101110011010100100111001000011100010011101111110000011110000111000001001000100011011000101010001110')], 84 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')] 85 | ], 86 | '6': [ 87 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 88 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 89 | [bitarray('111000010110100001101000010011100011000111101011011111110101000111001110110000110101010111100111010100010101'), bitarray('001101100101110011011110111111110110101100010000010001111011111110100010000101000000001110110010010000011100')], 90 | [bitarray('100101110110100000101101111011100100001101001000100101111010101100110100111111001000011010100100110100111101'), bitarray('111110101111011111111011001110110100001011110011100110001010101101111110101001100010111010001111011001101111')], 91 | [bitarray('110101011001100010000111000100110000101011101100100011000110010000100110100111111000010010100101001101010001'), bitarray('101110100000010110100100100000001101100010110001001110000111001101010100000011111110101001010001001101111000')], 92 | [bitarray('111101001010101010100100010100100111100010101100110111110010011000110110100100011110111111000111001101000011'), bitarray('110100101111011010000001110101110010111011110011111010100101010000110001011011001011101011101001100111101011')], 93 | [bitarray('101110110111100111000101001001010111010000001000010110111010011010011010111110010011101110100000000000110011'), bitarray('001000100101110010111111011100110100111010101010101011100111011101100110000100111100110101010000101010010000')], 94 | [bitarray('110001010011010011011001011000100101010001000110000101011010000000010000001100010101011011101000111000100100'), bitarray('000001100010101001010100001010100100110011001000111111000010011101000100010111110001110000100100011000001001')], 95 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')] 96 | ], 97 | '7': [ 98 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 99 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 100 | [bitarray('010010110001100100000010000100111111101010100000111011011001111010001000010110111100000100000100001101101100'), bitarray('101100001111000010001011011111001101011111011000111101100000010001101111111001010111100000000110111110100010')], 101 | [bitarray('000110011010110001011000011101001101011110100101000110111000101111000000100101010011000101111001011001000001'), bitarray('000111000111100101010110011110101011111101010101000000011101001001110011000010001100001100000000010001000011')], 102 | [bitarray('110100000000001100100000001101000000000010011111100011010011110011000011100000110101000101100101001101100111'), bitarray('001111100111011010010000100000011011111000100001001000000011000101010000010110001011111011010011110111000011')], 103 | [bitarray('110001010101111001100010101010000000001011011101111110001110101010110010100101000010110000000100100010100011'), bitarray('000010100110010111101011101001101111110101010110110101100000101011010010001011011001111010011101100110100111')], 104 | [bitarray('101101010010111100100111100111000110001110110100001010011100101101111011100100110011101000100000100110000110'), bitarray('011000101110010110011000011011110011100001010111100000001110111010110101010100101100110001001100101000010100')], 105 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')] 106 | ], 107 | '8': [ 108 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 109 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 110 | [bitarray('110000011010100110100000001001001110000010011000100100001000110100111111101000110100101011101100101101101001'), bitarray('111111001100011110100011111011001101101011100011001111000010011001101110011100010000010011010101010101011010')], 111 | [bitarray('110011110101011110000101000101100101100011010100100000101111001101110111110010010101000111100010011101000101'), bitarray('000110010110010101000011001111000101101111010011011110000010011101000010001100010001100001110011100011000111')], 112 | [bitarray('111110101011100011100100010101000100010000101101100101010000100010100001101110101101101010000011010100100110'), bitarray('001001000101010100010101100000001101101011001010101001000000001000000000000001000100010000001000000010000000')] 113 | ], 114 | '9': [ 115 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 116 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 117 | [bitarray('010010001110100101111111001101110010011110111100001000011101000110010111010110111100100001001110011101010101'), bitarray('000010101110010000011010001111000101110000100001001000100011000000100100010010001100101011000000101111110001')], 118 | [bitarray('111100110010001100000010000000000101011110111101101111010000111111100011110000100011001000000011000001100001'), bitarray('001011101100100011000110110111000110110100110000001101000011011001110110111001100101000010001001010111011011')], 119 | [bitarray('110100010010000000000011001001110011000011101100100011000000110111000011100100110100000101100101001101100110'), bitarray('001011100110010010010010100000001011100001000111011000101000010111110110111001010000101100010110001000100011')], 120 | [bitarray('100101110101010100001101100100010101110001101010011111010011101000101110101000110001000100001001100110011001'), bitarray('000001010101110000010011110010010010111000110000111101001101111011000111001011001001000001001001011001000100')], 121 | [bitarray('110001010001100001101001100011110100000100010110010100001101101110011111111000110101010011100111010100100111'), bitarray('000100000100100010011000100110010101110110001000100111000100011101000100010000111101101000110101100010110011')], 122 | [bitarray('111110101010101111000110011101000110011001011101110001100111100011010001101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')] 123 | ], 124 | 'disabled': [ 125 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 126 | [bitarray('101011001010101001000000001000000000000001000100010000001000000010000000101011001010101001000000001000000000'), bitarray('000001000100010000001000000010000000101011001010101001000000001000000000000001000100010000001000000010000000')], 127 | [bitarray('001111000111111001000001001101111110111101100010011111001010011011101111000011110110111101100001000101011010'), bitarray('111100000010010011101000011111011100001111110101111100000011000101011100011011011100101010000011111110110011')], 128 | [bitarray('000000100100010011111110010011100100011100001001001011100101101011101000010110111111101101011011100010110100'), bitarray('011111100001110010001110111011011110000011101001010000011011110001001101011011011110110010001111000000100101')], 129 | [bitarray('010110111100001000111110010011101111100010001100001000100101111000110101000010101010000000010111111010011011'), bitarray('000110000101101001000001001100100001000111011010010100100100011100001101011101100000001010010111001111110101')], 130 | [bitarray('010010001000101100000100010001001000011001100110001100011001101100010101000011101100100101100100011001010101'), bitarray('100100111111111011010101011110110001001111111000100101100010101101111110000010100111110010100010001111111111')], 131 | [bitarray('100000100000011100000011111000000000110100001101100001100000001111111111110100110100011101000101111001110100'), bitarray('111001100110000000100111011101010001100001000001001000100110110001110001100010100111110001010111101100000001')], 132 | [bitarray('110000100111011101100100110101100010110001000100000000000010011101010001111100110110010101100101111101000001'), bitarray('111101100110000100100011011100110001101001100101011001001011001110110101001111011000000100101101110100001011')], 133 | [bitarray('100100110100000100101001111100010111111111010011001011110010010111000001110100110000110001001111101010010010'), bitarray('000010111010000101011100001101000001100101100111100111110101010001010111000001100000101000010101011101110110')], 134 | [bitarray('101001110110101010000100000000110001100110001110000001111001110101011100100101100000011010111010101100011001'), bitarray('100010100000110101101001011111110010100110111001001011000000001100010111001011110000110110111100110010011111')], 135 | [bitarray('110111111101011110100011010001010001000001110000001011101001000010001101110110101010101011100110011101000010'), bitarray('001101101001110101010001101111000001101011001010101001000000001000000000000001000100010000001000000010000000')] 136 | ], 137 | 'enabled': [ 138 | [bitarray('010011101100010000101011000011111110110001110110001001110101000111111001011010001100000001100011101111001101'), bitarray('001111101111000000110100010110011101010111011000111001100000000001001010110001100110110000100001110110100010')], 139 | [bitarray('011010101011101100000111011001011010010101000101001000001101111001110101010010001000101000000111011101101001'), bitarray('011000010100001000001001110101000100110001000111001101000110001011100100100010000000111010000001001111010001')], 140 | [bitarray('100000000010010100100000110000010011111001001100101000000101011111011101100101110100010100000011001101000011'), bitarray('101111010101101110001001100111111111111101010110001101000000101101110110101010011000011100000101101111111101')], 141 | [bitarray('100001100111101100000111111000100000000010001011101011000111010110111111110000100000101100000100111001101101'), bitarray('010001001010111000000111001101110111101001000111100100000100110000000011000111111000101010000001011110011101')], 142 | [bitarray('110100110000111000100101101001100100101010010010111011011001010110110011111100110100100101101000011011100000'), bitarray('001010011110000010110001000111011100110101100111110001001111011011100100000000000100011011010111110000100010')], 143 | [bitarray('100000110100001001101101011110010011010000100010011100111111011010100011110101010110001111000011011100010111'), bitarray('011011101100111011011011010101011011000001001100101011101100001101111010111011111100010101100111001001110110')], 144 | [bitarray('110101101110001110100111011001110010011011000000110100010011101010001000101101011011001100101001110010110010'), bitarray('010010000000010001111001001001100010101011001010101001000000001000000000000001000100010000001000000010000000')] 145 | ] 146 | } 147 | --------------------------------------------------------------------------------