├── .gitignore
├── .travis.yml
├── .vscode
└── extensions.json
├── LICENSE
├── include
└── README
├── lib
└── README
├── logitech-unifying-device.code-workspace
├── notes.md
├── platformio.ini
├── readme.md
├── src
├── aes.cpp
├── aes.h
├── ludevice.cpp
├── ludevice.h
└── main.cpp
└── test
└── README
/.gitignore:
--------------------------------------------------------------------------------
1 | .pio
2 | .vscode/.browse.c_cpp.db*
3 | .vscode/c_cpp_properties.json
4 | .vscode/launch.json
5 | .vscode/ipch
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # Continuous Integration (CI) is the practice, in software
2 | # engineering, of merging all developer working copies with a shared mainline
3 | # several times a day < https://docs.platformio.org/page/ci/index.html >
4 | #
5 | # Documentation:
6 | #
7 | # * Travis CI Embedded Builds with PlatformIO
8 | # < https://docs.travis-ci.com/user/integration/platformio/ >
9 | #
10 | # * PlatformIO integration with Travis CI
11 | # < https://docs.platformio.org/page/ci/travis.html >
12 | #
13 | # * User Guide for `platformio ci` command
14 | # < https://docs.platformio.org/page/userguide/cmd_ci.html >
15 | #
16 | #
17 | # Please choose one of the following templates (proposed below) and uncomment
18 | # it (remove "# " before each line) or use own configuration according to the
19 | # Travis CI documentation (see above).
20 | #
21 |
22 |
23 | #
24 | # Template #1: General project. Test it using existing `platformio.ini`.
25 | #
26 |
27 | # language: python
28 | # python:
29 | # - "2.7"
30 | #
31 | # sudo: false
32 | # cache:
33 | # directories:
34 | # - "~/.platformio"
35 | #
36 | # install:
37 | # - pip install -U platformio
38 | # - platformio update
39 | #
40 | # script:
41 | # - platformio run
42 |
43 |
44 | #
45 | # Template #2: The project is intended to be used as a library with examples.
46 | #
47 |
48 | # language: python
49 | # python:
50 | # - "2.7"
51 | #
52 | # sudo: false
53 | # cache:
54 | # directories:
55 | # - "~/.platformio"
56 | #
57 | # env:
58 | # - PLATFORMIO_CI_SRC=path/to/test/file.c
59 | # - PLATFORMIO_CI_SRC=examples/file.ino
60 | # - PLATFORMIO_CI_SRC=path/to/test/directory
61 | #
62 | # install:
63 | # - pip install -U platformio
64 | # - platformio update
65 | #
66 | # script:
67 | # - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
68 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | // See http://go.microsoft.com/fwlink/?LinkId=827846
3 | // for the documentation about the extensions.json format
4 | "recommendations": [
5 | "platformio.platformio-ide"
6 | ]
7 | }
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/include/README:
--------------------------------------------------------------------------------
1 |
2 | This directory is intended for project header files.
3 |
4 | A header file is a file containing C declarations and macro definitions
5 | to be shared between several project source files. You request the use of a
6 | header file in your project source file (C, C++, etc) located in `src` folder
7 | by including it, with the C preprocessing directive `#include'.
8 |
9 | ```src/main.c
10 |
11 | #include "header.h"
12 |
13 | int main (void)
14 | {
15 | ...
16 | }
17 | ```
18 |
19 | Including a header file produces the same results as copying the header file
20 | into each source file that needs it. Such copying would be time-consuming
21 | and error-prone. With a header file, the related declarations appear
22 | in only one place. If they need to be changed, they can be changed in one
23 | place, and programs that include the header file will automatically use the
24 | new version when next recompiled. The header file eliminates the labor of
25 | finding and changing all the copies as well as the risk that a failure to
26 | find one copy will result in inconsistencies within a program.
27 |
28 | In C, the usual convention is to give header files names that end with `.h'.
29 | It is most portable to use only letters, digits, dashes, and underscores in
30 | header file names, and at most one dot.
31 |
32 | Read more about using header files in official GCC documentation:
33 |
34 | * Include Syntax
35 | * Include Operation
36 | * Once-Only Headers
37 | * Computed Includes
38 |
39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
40 |
--------------------------------------------------------------------------------
/lib/README:
--------------------------------------------------------------------------------
1 |
2 | This directory is intended for project specific (private) libraries.
3 | PlatformIO will compile them to static libraries and link into executable file.
4 |
5 | The source code of each library should be placed in a an own separate directory
6 | ("lib/your_library_name/[here are source files]").
7 |
8 | For example, see a structure of the following two libraries `Foo` and `Bar`:
9 |
10 | |--lib
11 | | |
12 | | |--Bar
13 | | | |--docs
14 | | | |--examples
15 | | | |--src
16 | | | |- Bar.c
17 | | | |- Bar.h
18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19 | | |
20 | | |--Foo
21 | | | |- Foo.c
22 | | | |- Foo.h
23 | | |
24 | | |- README --> THIS FILE
25 | |
26 | |- platformio.ini
27 | |--src
28 | |- main.c
29 |
30 | and a contents of `src/main.c`:
31 | ```
32 | #include
33 | #include
34 |
35 | int main (void)
36 | {
37 | ...
38 | }
39 |
40 | ```
41 |
42 | PlatformIO Library Dependency Finder will find automatically dependent
43 | libraries scanning project source files.
44 |
45 | More information about PlatformIO Library Dependency Finder
46 | - https://docs.platformio.org/page/librarymanager/ldf.html
47 |
--------------------------------------------------------------------------------
/logitech-unifying-device.code-workspace:
--------------------------------------------------------------------------------
1 | {
2 | "folders": [
3 | {
4 | "path": "."
5 | }
6 | ],
7 | "settings": {}
8 | }
--------------------------------------------------------------------------------
/notes.md:
--------------------------------------------------------------------------------
1 | Mouse
2 | [IN ][CH: 5] 6F:B8:96:D6:CD 00 10 CD 02 02 52 00 51 F0 8C (10 bytes)
3 | [OUT][CH: 5] 6F:B8:96:D6:CD 00 51 CD 02 12 00 52 51 4D 62 00 00 13 00 40 51 00 00 00 00 00 D8 (22 bytes)
4 |
5 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
6 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 51 D1 02 12 00 52 51 4D 62 00 00 13 00 40 51 00 00 00 00 00 D4 (22 bytes)
7 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
8 |
9 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
10 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 51 D1 02 02 01 F9 2B 7F F0 00 04 40 51 00 00 00 00 00 00 00 B1 (22 bytes) - Logitech (plain)
11 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
12 |
13 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 C2 00 00 03 80 FF 00 00 BC (10 bytes) - Logitech (plain)
14 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
15 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 51 D1 02 12 00 52 51 4D 62 00 00 13 00 40 51 00 00 00 00 00 D4 (22 bytes)
16 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
17 |
18 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 4F 00 00 6E 00 00 00 00 43 (10 bytes) - Logitech (plain)
19 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
20 | [IN ][CH: 5] 6F:B8:96:D6:D1 00 10 D1 02 02 52 00 51 00 78 (10 bytes)
21 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 51 D1 02 02 01 F9 2B 7F F0 00 04 40 51 00 00 00 00 00 00 00 B1 (22 bytes)
22 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
23 |
24 | K800 Keyboard
25 | [OUT][CH: 5] BB:0A:DC:A5:75 E0 DF 01 6F B8 96 D6 D2 14 20 10 04 00 01 07 00 00 00 00 00 00 8B (22 bytes)
26 | [OUT][CH: 5] BB:0A:DC:A5:75 E0 DF 01 6F B8 96 D6 D2 14 20 10 04 00 01 07 00 00 00 00 00 00 8B (22 bytes)
27 |
28 | [IN ][CH: 5] 6F:B8:96:D6:D2 00 10 D2 81 F1 01 00 00 A6 05 (10 bytes)
29 |
30 | [OUT][CH: 5] 6F:B8:96:D6:D2 00 50 D2 81 F1 01 22 00 00 49 (10 bytes)
31 | [OUT][CH: 5] 6F:B8:96:D6:D2 00 50 D2 81 F1 02 00 17 00 53 (10 bytes)
32 |
33 | [OUT][CH: 5] 6F:B8:96:D6:D2 00 50 D2 81 F1 01 22 00 00 49 (10 bytes)
34 | [OUT][CH: 5] 6F:B8:96:D6:D2 00 50 D2 81 F1 02 00 17 00 53 (10 bytes)
35 | [OUT][CH: 5] 6F:B8:96:D6:D2 00 50 D2 81 F1 04 02 01 00 65 (10 bytes)
36 |
37 |
38 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 40 00 14 AC (5 bytes) - Logitech (plain)
39 | [IN ][CH: 5] 6F:B8:96:D6:D6 00 10 D6 81 F1 01 00 00 A6 01 (10 bytes) - Logitech (plain)
40 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 40 00 14 AC (5 bytes) - Logitech (plain)
41 |
42 | [OUT][CH: 5] 6F:B8:96:D6:00 D6 50 D6 4B 01 00 00 00 00 B8 (10 bytes)
43 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 50 D6 8F 00 12 01 00 00 38 (10 bytes)
44 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 50 D6 81 F1 01 22 00 00 45 (10 bytes)
45 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 50 D6 81 F1 03 00 07 00 5E (10 bytes)
46 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 40 00 14 AC (5 bytes) - Logitech (plain)
47 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 50 D6 81 F1 02 00 17 00 4F (10 bytes)
48 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 40 00 14 AC (5 bytes) - Logitech (plain)
49 |
50 | [OUT][CH: 44] 6F:B8:96:D6:D7 00 40 00 14 AC (5 bytes) - Logitech (plain)
51 | [OUT][CH: 44] 6F:B8:96:D6:D7 00 50 D7 81 F1 02 00 17 00 4E (10 bytes)
52 | [OUT][CH: 44] 6F:B8:96:D6:D7 00 40 00 14 AC (5 bytes) - Logitech (plain)
53 |
54 | # K270
55 | [CH: 5] 49:16:90:09:F2 00 51 F2 04 00 5A 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 19 (22 bytes)
56 | [CH: 17] BB:0A:DC:A5:75 05 5F 01 49 16 90 09 F2 14 40 03 04 00 01 0D 00 00 00 00 00 2A 1E (22 bytes)
57 |
58 | [CH: 5] 49:16:90:09:F2 00, 0x51, 0xF2, 0x04, 0x00, 0x5A, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19
59 | [CH: 17] BB:0A:DC:A5:75 05 5F 01 49 16 90 09 F2 14 40 03 04 00 01 0D 00 00 00 00 00 2A 1E (22 bytes)
60 |
61 | [CH: 14] 49:16:90:09:18 00 51 18 04 00 46 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 39 (22 bytes)
62 | [CH: 14] 49:16:90:09:18 18 4F 07 00 00 00 00 00 00 92 (10 bytes)
63 | [CH: 8] 49:16:90:09:23 00 4F 00 01 16 00 00 00 00 9A (10 bytes) - Logitech (plain)
64 |
65 | IN [10]: 65 E3 0F 06 02 03 C6 AD DE AD 05
66 | IN [10]: 14 00 0F 05 01 27 D4 02 FA CE 26
67 | IN [10]: 44 00 0F 05 01 27 D4 00 FA CE 28
68 |
69 |
70 | **Mouse
71 | [IN ][CH: 5] 6F:B8:96:D6:CD 00 10 CD 02 02 52 00 51 F0 8C (10 bytes)
72 | [OUT][CH: 5] 6F:B8:96:D6:CD 00 51 CD 02 12 00 52 51 4D 62 00 00 13 00 40 51 00 00 00 00 00 D8 (22 bytes)
73 |
74 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
75 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 51 D1 02 12 00 52 51 4D 62 00 00 13 00 40 51 00 00 00 00 00 D4 (22 bytes)
76 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
77 |
78 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
79 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 51 D1 02 02 01 F9 2B 7F F0 00 04 40 51 00 00 00 00 00 00 00 B1 (22 bytes) - Logitech (plain)
80 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
81 |
82 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 C2 00 00 03 80 FF 00 00 BC (10 bytes) - Logitech (plain)
83 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
84 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 51 D1 02 12 00 52 51 4D 62 00 00 13 00 40 51 00 00 00 00 00 D4 (22 bytes)
85 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
86 |
87 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 4F 00 00 6E 00 00 00 00 43 (10 bytes) - Logitech (plain)
88 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
89 | [IN ][CH: 5] 6F:B8:96:D6:D1 00 10 D1 02 02 52 00 51 00 78 (10 bytes)
90 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 51 D1 02 02 01 F9 2B 7F F0 00 04 40 51 00 00 00 00 00 00 00 B1 (22 bytes)
91 | [OUT][CH: 5] 6F:B8:96:D6:D1 00 40 00 6E 52 (5 bytes) - Logitech (plain)
92 |
93 | K800 Keyboard
94 | [OUT][CH: 5] BB:0A:DC:A5:75 E0 DF 01 6F B8 96 D6 D2 14 20 10 04 00 01 07 00 00 00 00 00 00 8B (22 bytes)
95 | [OUT][CH: 5] BB:0A:DC:A5:75 E0 DF 01 6F B8 96 D6 D2 14 20 10 04 00 01 07 00 00 00 00 00 00 8B (22 bytes)
96 |
97 | [IN ][CH: 5] 6F:B8:96:D6:D2 00 10 D2 81 F1 01 00 00 A6 05 (10 bytes)
98 |
99 | [OUT][CH: 5] 6F:B8:96:D6:D2 00 50 D2 81 F1 01 22 00 00 49 (10 bytes)
100 | [OUT][CH: 5] 6F:B8:96:D6:D2 00 50 D2 81 F1 02 00 17 00 53 (10 bytes)
101 |
102 | [OUT][CH: 5] 6F:B8:96:D6:D2 00 50 D2 81 F1 01 22 00 00 49 (10 bytes)
103 | [OUT][CH: 5] 6F:B8:96:D6:D2 00 50 D2 81 F1 02 00 17 00 53 (10 bytes)
104 | [OUT][CH: 5] 6F:B8:96:D6:D2 00 50 D2 81 F1 04 02 01 00 65 (10 bytes)
105 |
106 |
107 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 40 00 14 AC (5 bytes) - Logitech (plain)
108 | [IN ][CH: 5] 6F:B8:96:D6:D6 00 10 D6 81 F1 01 00 00 A6 01 (10 bytes) - Logitech (plain)
109 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 40 00 14 AC (5 bytes) - Logitech (plain)
110 |
111 | [OUT][CH: 5] 6F:B8:96:D6:00 D6 50 D6 4B 01 00 00 00 00 B8 (10 bytes)
112 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 50 D6 8F 00 12 01 00 00 38 (10 bytes)
113 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 50 D6 81 F1 01 22 00 00 45 (10 bytes)
114 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 50 D6 81 F1 03 00 07 00 5E (10 bytes)
115 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 40 00 14 AC (5 bytes) - Logitech (plain)
116 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 50 D6 81 F1 02 00 17 00 4F (10 bytes)
117 | [OUT][CH: 5] 6F:B8:96:D6:D6 00 40 00 14 AC (5 bytes) - Logitech (plain)
118 |
119 | [OUT][CH: 44] 6F:B8:96:D6:D7 00 40 00 14 AC (5 bytes) - Logitech (plain)
120 | [OUT][CH: 44] 6F:B8:96:D6:D7 00 50 D7 81 F1 02 00 17 00 4E (10 bytes)
121 | [OUT][CH: 44] 6F:B8:96:D6:D7 00 40 00 14 AC (5 bytes) - Logitech (plain)
122 |
123 | # K270
124 | [CH: 5] 49:16:90:09:F2 00 51 F2 04 00 5A 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 19 (22 bytes)
125 | [CH: 17] BB:0A:DC:A5:75 05 5F 01 49 16 90 09 F2 14 40 03 04 00 01 0D 00 00 00 00 00 2A 1E (22 bytes)
126 |
127 | [CH: 5] 49:16:90:09:F2 00, 0x51, 0xF2, 0x04, 0x00, 0x5A, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19
128 | [CH: 17] BB:0A:DC:A5:75 05 5F 01 49 16 90 09 F2 14 40 03 04 00 01 0D 00 00 00 00 00 2A 1E (22 bytes)
129 |
130 |
131 |
132 | IN [10]: 65 E3 0F 06 02 03 C6 AD DE AD 05
133 | IN [10]: 14 00 0F 05 01 27 D4 02 FA CE 26
134 | IN [10]: 44 00 0F 05 01 27 D4 00 FA CE 28
135 | IN [10]: 44 00 0F 05 02 36 E4 02 FA CE 06
136 | IN [10]: 71 00 0F 05 02 36 E4 00 AC ED 37
--------------------------------------------------------------------------------
/platformio.ini:
--------------------------------------------------------------------------------
1 | ; PlatformIO Project Configuration File
2 | ;
3 | ; Build options: build flags, source filter
4 | ; Upload options: custom upload port, speed and extra flags
5 | ; Library options: dependencies, extra library storages
6 | ; Advanced options: extra scripting
7 | ;
8 | ; Please visit documentation for the other options and examples
9 | ; https://docs.platformio.org/page/projectconf.html
10 |
11 | [env:esp12e]
12 | platform = espressif8266
13 | board = esp12e
14 | framework = arduino
15 | monitor_speed = 921600
16 | upload_speed = 921600
17 |
18 | lib_deps =
19 | 1002 ;elapsedMillis
20 | 433 ;RF24
21 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Library to build Logitech Unifying compatible devices
2 | I have always wanted an 84 key standard layout, wireless, mechanical keyboard with RGB backlight and rotary knobs plus media control buttons near the spacebar. Anyway, it did not take long for me to realize that bluetooth keyboards are notoriously unreliable, intermittently disconnecting every so often. However, Unifying ones are much better.
3 |
4 | I never planned to publish this code, thus it is not the cleanest. ~~But since I'm stuck, I thought someone might put it to good use and maybe figure out the problem. If you can make a more secured Unifying compatible protocol, all the better.~~
5 |
6 | ### C-U0007 mitigation effort from firmware `012.010.00032` onwards
7 | In an effort to prevent keys injection, the receiver's firmware will reject packets that start with a full buffer of 6 keystrokes, so start by filling the buffer slowly (like a human). If you know exactly how the receiver rejects these packets, feel free to PR a write up.
8 |
9 |
10 | ### Many thanks to:
11 | - Ronan Gaillard https://github.com/ronangaillard/logitech-mouse/issues/5
12 | - RoganDawes and Marcus Meng https://github.com/RoganDawes/LOGITacker/issues/55
13 | - Code to perform AES ECB mode, will gladly attribute it if someone knows its origin
14 |
15 | ## Hardware
16 | - Logitech ```C-U0007``` dongle
17 | - ESP8266, NRF24L01+ and a 5v power board for the NRF24L01+ module, connect them as follows:
18 | - WEMOS D1 mini D3 <-> power board CS
19 | - WEMOS D1 mini D4 <-> power board CE
20 | - WEMOS D1 mini D5 <-> power board SCK
21 | - WEMOS D1 mini D6 <-> power board MISO
22 | - WEMOS D1 mini D7 <-> power board MOSI
23 | - WEMOS D1 mini 5V <-> power board VCC
24 | - WEMOS D1 mini GND <-> power board GND
25 |
26 | ## Software
27 | - Open ```logitech-unifying-device.code-workspace``` in VSCode with PlatformIO installed
28 | - Press ```ctrl + alt + u``` to compile
29 | - If it is your first time using PlatformIO, **wait** until the icon appears on the activity bar at the left of VSCode before compiling, it should just work
30 |
--------------------------------------------------------------------------------
/src/aes.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | This is an implementation of the AES algorithm, specifically ECB, CTR and CBC mode.
4 | Block size can be chosen in aes.h - available choices are AES128, AES192, AES256.
5 |
6 | The implementation is verified against the test vectors in:
7 | National Institute of Standards and Technology Special Publication 800-38A 2001 ED
8 |
9 | ECB-AES128
10 | ----------
11 |
12 | plain-text:
13 | 6bc1bee22e409f96e93d7e117393172a
14 | ae2d8a571e03ac9c9eb76fac45af8e51
15 | 30c81c46a35ce411e5fbc1191a0a52ef
16 | f69f2445df4f9b17ad2b417be66c3710
17 |
18 | key:
19 | 2b7e151628aed2a6abf7158809cf4f3c
20 |
21 | resulting cipher
22 | 3ad77bb40d7a3660a89ecaf32466ef97
23 | f5d3d58503b9699de785895a96fdbaaf
24 | 43b1cd7f598ece23881b00e3ed030688
25 | 7b0c785e27e8ad3f8223207104725dd4
26 |
27 |
28 | NOTE: String length must be evenly divisible by 16byte (str_len % 16 == 0)
29 | You should pad the end of the string with zeros if this is not the case.
30 | For AES192/256 the key size is proportionally larger.
31 |
32 | */
33 |
34 |
35 | /*****************************************************************************/
36 | /* Includes: */
37 | /*****************************************************************************/
38 | #include // CBC mode, for memset
39 | #include "aes.h"
40 |
41 | /*****************************************************************************/
42 | /* Defines: */
43 | /*****************************************************************************/
44 | // The number of columns comprising a state in AES. This is a constant in AES. Value=4
45 | #define Nb 4
46 |
47 | #if defined(AES256) && (AES256 == 1)
48 | #define Nk 8
49 | #define Nr 14
50 | #elif defined(AES192) && (AES192 == 1)
51 | #define Nk 6
52 | #define Nr 12
53 | #else
54 | #define Nk 4 // The number of 32 bit words in a key.
55 | #define Nr 10 // The number of rounds in AES Cipher.
56 | #endif
57 |
58 | // jcallan@github points out that declaring Multiply as a function
59 | // reduces code size considerably with the Keil ARM compiler.
60 | // See this link for more information: https://github.com/kokke/tiny-AES-C/pull/3
61 | #ifndef MULTIPLY_AS_A_FUNCTION
62 | #define MULTIPLY_AS_A_FUNCTION 0
63 | #endif
64 |
65 |
66 |
67 |
68 | /*****************************************************************************/
69 | /* Private variables: */
70 | /*****************************************************************************/
71 | // state - array holding the intermediate results during decryption.
72 | typedef uint8_t state_t[4][4];
73 |
74 |
75 |
76 | // The lookup-tables are marked const so they can be placed in read-only storage instead of RAM
77 | // The numbers below can be computed dynamically trading ROM for RAM -
78 | // This can be useful in (embedded) bootloader applications, where ROM is often limited.
79 | static const uint8_t sbox[256] = {
80 | //0 1 2 3 4 5 6 7 8 9 A B C D E F
81 | 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
82 | 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
83 | 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
84 | 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
85 | 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
86 | 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
87 | 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
88 | 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
89 | 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
90 | 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
91 | 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
92 | 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
93 | 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
94 | 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
95 | 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
96 | 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 };
97 |
98 | static const uint8_t rsbox[256] = {
99 | 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
100 | 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
101 | 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
102 | 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
103 | 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
104 | 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
105 | 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
106 | 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
107 | 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
108 | 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
109 | 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
110 | 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
111 | 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
112 | 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
113 | 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
114 | 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d };
115 |
116 | // The round constant word array, Rcon[i], contains the values given by
117 | // x to the power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8)
118 | static const uint8_t Rcon[11] = {
119 | 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
120 |
121 | /*
122 | * Jordan Goulder points out in PR #12 (https://github.com/kokke/tiny-AES-C/pull/12),
123 | * that you can remove most of the elements in the Rcon array, because they are unused.
124 | *
125 | * From Wikipedia's article on the Rijndael key schedule @ https://en.wikipedia.org/wiki/Rijndael_key_schedule#Rcon
126 | *
127 | * "Only the first some of these constants are actually used – up to rcon[10] for AES-128 (as 11 round keys are needed),
128 | * up to rcon[8] for AES-192, up to rcon[7] for AES-256. rcon[0] is not used in AES algorithm."
129 | */
130 |
131 |
132 | /*****************************************************************************/
133 | /* Private functions: */
134 | /*****************************************************************************/
135 | /*
136 | static uint8_t getSBoxValue(uint8_t num)
137 | {
138 | return sbox[num];
139 | }
140 | */
141 | #define getSBoxValue(num) (sbox[(num)])
142 | /*
143 | static uint8_t getSBoxInvert(uint8_t num)
144 | {
145 | return rsbox[num];
146 | }
147 | */
148 | #define getSBoxInvert(num) (rsbox[(num)])
149 |
150 | // This function produces Nb(Nr+1) round keys. The round keys are used in each round to decrypt the states.
151 | static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key)
152 | {
153 | unsigned i, j, k;
154 | uint8_t tempa[4]; // Used for the column/row operations
155 |
156 | // The first round key is the key itself.
157 | for (i = 0; i < Nk; ++i)
158 | {
159 | RoundKey[(i * 4) + 0] = Key[(i * 4) + 0];
160 | RoundKey[(i * 4) + 1] = Key[(i * 4) + 1];
161 | RoundKey[(i * 4) + 2] = Key[(i * 4) + 2];
162 | RoundKey[(i * 4) + 3] = Key[(i * 4) + 3];
163 | }
164 |
165 | // All other round keys are found from the previous round keys.
166 | for (i = Nk; i < Nb * (Nr + 1); ++i)
167 | {
168 | {
169 | k = (i - 1) * 4;
170 | tempa[0]=RoundKey[k + 0];
171 | tempa[1]=RoundKey[k + 1];
172 | tempa[2]=RoundKey[k + 2];
173 | tempa[3]=RoundKey[k + 3];
174 |
175 | }
176 |
177 | if (i % Nk == 0)
178 | {
179 | // This function shifts the 4 bytes in a word to the left once.
180 | // [a0,a1,a2,a3] becomes [a1,a2,a3,a0]
181 |
182 | // Function RotWord()
183 | {
184 | const uint8_t u8tmp = tempa[0];
185 | tempa[0] = tempa[1];
186 | tempa[1] = tempa[2];
187 | tempa[2] = tempa[3];
188 | tempa[3] = u8tmp;
189 | }
190 |
191 | // SubWord() is a function that takes a four-byte input word and
192 | // applies the S-box to each of the four bytes to produce an output word.
193 |
194 | // Function Subword()
195 | {
196 | tempa[0] = getSBoxValue(tempa[0]);
197 | tempa[1] = getSBoxValue(tempa[1]);
198 | tempa[2] = getSBoxValue(tempa[2]);
199 | tempa[3] = getSBoxValue(tempa[3]);
200 | }
201 |
202 | tempa[0] = tempa[0] ^ Rcon[i/Nk];
203 | }
204 | #if defined(AES256) && (AES256 == 1)
205 | if (i % Nk == 4)
206 | {
207 | // Function Subword()
208 | {
209 | tempa[0] = getSBoxValue(tempa[0]);
210 | tempa[1] = getSBoxValue(tempa[1]);
211 | tempa[2] = getSBoxValue(tempa[2]);
212 | tempa[3] = getSBoxValue(tempa[3]);
213 | }
214 | }
215 | #endif
216 | j = i * 4; k=(i - Nk) * 4;
217 | RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0];
218 | RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1];
219 | RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2];
220 | RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3];
221 | }
222 | }
223 |
224 | void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key)
225 | {
226 | KeyExpansion(ctx->RoundKey, key);
227 | }
228 | #if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
229 | void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv)
230 | {
231 | KeyExpansion(ctx->RoundKey, key);
232 | memcpy (ctx->Iv, iv, AES_BLOCKLEN);
233 | }
234 | void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv)
235 | {
236 | memcpy (ctx->Iv, iv, AES_BLOCKLEN);
237 | }
238 | #endif
239 |
240 | // This function adds the round key to state.
241 | // The round key is added to the state by an XOR function.
242 | static void AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey)
243 | {
244 | uint8_t i,j;
245 | for (i = 0; i < 4; ++i)
246 | {
247 | for (j = 0; j < 4; ++j)
248 | {
249 | (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j];
250 | }
251 | }
252 | }
253 |
254 | // The SubBytes Function Substitutes the values in the
255 | // state matrix with values in an S-box.
256 | static void SubBytes(state_t* state)
257 | {
258 | uint8_t i, j;
259 | for (i = 0; i < 4; ++i)
260 | {
261 | for (j = 0; j < 4; ++j)
262 | {
263 | (*state)[j][i] = getSBoxValue((*state)[j][i]);
264 | }
265 | }
266 | }
267 |
268 | // The ShiftRows() function shifts the rows in the state to the left.
269 | // Each row is shifted with different offset.
270 | // Offset = Row number. So the first row is not shifted.
271 | static void ShiftRows(state_t* state)
272 | {
273 | uint8_t temp;
274 |
275 | // Rotate first row 1 columns to left
276 | temp = (*state)[0][1];
277 | (*state)[0][1] = (*state)[1][1];
278 | (*state)[1][1] = (*state)[2][1];
279 | (*state)[2][1] = (*state)[3][1];
280 | (*state)[3][1] = temp;
281 |
282 | // Rotate second row 2 columns to left
283 | temp = (*state)[0][2];
284 | (*state)[0][2] = (*state)[2][2];
285 | (*state)[2][2] = temp;
286 |
287 | temp = (*state)[1][2];
288 | (*state)[1][2] = (*state)[3][2];
289 | (*state)[3][2] = temp;
290 |
291 | // Rotate third row 3 columns to left
292 | temp = (*state)[0][3];
293 | (*state)[0][3] = (*state)[3][3];
294 | (*state)[3][3] = (*state)[2][3];
295 | (*state)[2][3] = (*state)[1][3];
296 | (*state)[1][3] = temp;
297 | }
298 |
299 | static uint8_t xtime(uint8_t x)
300 | {
301 | return ((x<<1) ^ (((x>>7) & 1) * 0x1b));
302 | }
303 |
304 | // MixColumns function mixes the columns of the state matrix
305 | static void MixColumns(state_t* state)
306 | {
307 | uint8_t i;
308 | uint8_t Tmp, Tm, t;
309 | for (i = 0; i < 4; ++i)
310 | {
311 | t = (*state)[i][0];
312 | Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ;
313 | Tm = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm); (*state)[i][0] ^= Tm ^ Tmp ;
314 | Tm = (*state)[i][1] ^ (*state)[i][2] ; Tm = xtime(Tm); (*state)[i][1] ^= Tm ^ Tmp ;
315 | Tm = (*state)[i][2] ^ (*state)[i][3] ; Tm = xtime(Tm); (*state)[i][2] ^= Tm ^ Tmp ;
316 | Tm = (*state)[i][3] ^ t ; Tm = xtime(Tm); (*state)[i][3] ^= Tm ^ Tmp ;
317 | }
318 | }
319 |
320 | // Multiply is used to multiply numbers in the field GF(2^8)
321 | // Note: The last call to xtime() is unneeded, but often ends up generating a smaller binary
322 | // The compiler seems to be able to vectorize the operation better this way.
323 | // See https://github.com/kokke/tiny-AES-c/pull/34
324 | #if MULTIPLY_AS_A_FUNCTION
325 | static uint8_t Multiply(uint8_t x, uint8_t y)
326 | {
327 | return (((y & 1) * x) ^
328 | ((y>>1 & 1) * xtime(x)) ^
329 | ((y>>2 & 1) * xtime(xtime(x))) ^
330 | ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^
331 | ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))); /* this last call to xtime() can be omitted */
332 | }
333 | #else
334 | #define Multiply(x, y) \
335 | ( ((y & 1) * x) ^ \
336 | ((y>>1 & 1) * xtime(x)) ^ \
337 | ((y>>2 & 1) * xtime(xtime(x))) ^ \
338 | ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ \
339 | ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))) \
340 |
341 | #endif
342 |
343 | #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
344 | // MixColumns function mixes the columns of the state matrix.
345 | // The method used to multiply may be difficult to understand for the inexperienced.
346 | // Please use the references to gain more information.
347 | static void InvMixColumns(state_t* state)
348 | {
349 | int i;
350 | uint8_t a, b, c, d;
351 | for (i = 0; i < 4; ++i)
352 | {
353 | a = (*state)[i][0];
354 | b = (*state)[i][1];
355 | c = (*state)[i][2];
356 | d = (*state)[i][3];
357 |
358 | (*state)[i][0] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^ Multiply(d, 0x09);
359 | (*state)[i][1] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^ Multiply(d, 0x0d);
360 | (*state)[i][2] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^ Multiply(d, 0x0b);
361 | (*state)[i][3] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^ Multiply(d, 0x0e);
362 | }
363 | }
364 |
365 |
366 | // The SubBytes Function Substitutes the values in the
367 | // state matrix with values in an S-box.
368 | static void InvSubBytes(state_t* state)
369 | {
370 | uint8_t i, j;
371 | for (i = 0; i < 4; ++i)
372 | {
373 | for (j = 0; j < 4; ++j)
374 | {
375 | (*state)[j][i] = getSBoxInvert((*state)[j][i]);
376 | }
377 | }
378 | }
379 |
380 | static void InvShiftRows(state_t* state)
381 | {
382 | uint8_t temp;
383 |
384 | // Rotate first row 1 columns to right
385 | temp = (*state)[3][1];
386 | (*state)[3][1] = (*state)[2][1];
387 | (*state)[2][1] = (*state)[1][1];
388 | (*state)[1][1] = (*state)[0][1];
389 | (*state)[0][1] = temp;
390 |
391 | // Rotate second row 2 columns to right
392 | temp = (*state)[0][2];
393 | (*state)[0][2] = (*state)[2][2];
394 | (*state)[2][2] = temp;
395 |
396 | temp = (*state)[1][2];
397 | (*state)[1][2] = (*state)[3][2];
398 | (*state)[3][2] = temp;
399 |
400 | // Rotate third row 3 columns to right
401 | temp = (*state)[0][3];
402 | (*state)[0][3] = (*state)[1][3];
403 | (*state)[1][3] = (*state)[2][3];
404 | (*state)[2][3] = (*state)[3][3];
405 | (*state)[3][3] = temp;
406 | }
407 | #endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
408 |
409 | // Cipher is the main function that encrypts the PlainText.
410 | static void Cipher(state_t* state, const uint8_t* RoundKey)
411 | {
412 | uint8_t round = 0;
413 |
414 | // Add the First round key to the state before starting the rounds.
415 | AddRoundKey(0, state, RoundKey);
416 |
417 | // There will be Nr rounds.
418 | // The first Nr-1 rounds are identical.
419 | // These Nr rounds are executed in the loop below.
420 | // Last one without MixColumns()
421 | for (round = 1; ; ++round)
422 | {
423 | SubBytes(state);
424 | ShiftRows(state);
425 | if (round == Nr) {
426 | break;
427 | }
428 | MixColumns(state);
429 | AddRoundKey(round, state, RoundKey);
430 | }
431 | // Add round key to last round
432 | AddRoundKey(Nr, state, RoundKey);
433 | }
434 |
435 | #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
436 | static void InvCipher(state_t* state, const uint8_t* RoundKey)
437 | {
438 | uint8_t round = 0;
439 |
440 | // Add the First round key to the state before starting the rounds.
441 | AddRoundKey(Nr, state, RoundKey);
442 |
443 | // There will be Nr rounds.
444 | // The first Nr-1 rounds are identical.
445 | // These Nr rounds are executed in the loop below.
446 | // Last one without InvMixColumn()
447 | for (round = (Nr - 1); ; --round)
448 | {
449 | InvShiftRows(state);
450 | InvSubBytes(state);
451 | AddRoundKey(round, state, RoundKey);
452 | if (round == 0) {
453 | break;
454 | }
455 | InvMixColumns(state);
456 | }
457 |
458 | }
459 | #endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
460 |
461 | /*****************************************************************************/
462 | /* Public functions: */
463 | /*****************************************************************************/
464 | #if defined(ECB) && (ECB == 1)
465 |
466 |
467 | void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf)
468 | {
469 | // The next function call encrypts the PlainText with the Key using AES algorithm.
470 | Cipher((state_t*)buf, ctx->RoundKey);
471 | }
472 |
473 | void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf)
474 | {
475 | // The next function call decrypts the PlainText with the Key using AES algorithm.
476 | InvCipher((state_t*)buf, ctx->RoundKey);
477 | }
478 |
479 |
480 | #endif // #if defined(ECB) && (ECB == 1)
481 |
482 |
483 |
484 |
485 |
486 | #if defined(CBC) && (CBC == 1)
487 |
488 |
489 | static void XorWithIv(uint8_t* buf, const uint8_t* Iv)
490 | {
491 | uint8_t i;
492 | for (i = 0; i < AES_BLOCKLEN; ++i) // The block in AES is always 128bit no matter the key size
493 | {
494 | buf[i] ^= Iv[i];
495 | }
496 | }
497 |
498 | void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t* buf, uint32_t length)
499 | {
500 | uintptr_t i;
501 | uint8_t *Iv = ctx->Iv;
502 | for (i = 0; i < length; i += AES_BLOCKLEN)
503 | {
504 | XorWithIv(buf, Iv);
505 | Cipher((state_t*)buf, ctx->RoundKey);
506 | Iv = buf;
507 | buf += AES_BLOCKLEN;
508 | }
509 | /* store Iv in ctx for next call */
510 | memcpy(ctx->Iv, Iv, AES_BLOCKLEN);
511 | }
512 |
513 | void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
514 | {
515 | uintptr_t i;
516 | uint8_t storeNextIv[AES_BLOCKLEN];
517 | for (i = 0; i < length; i += AES_BLOCKLEN)
518 | {
519 | memcpy(storeNextIv, buf, AES_BLOCKLEN);
520 | InvCipher((state_t*)buf, ctx->RoundKey);
521 | XorWithIv(buf, ctx->Iv);
522 | memcpy(ctx->Iv, storeNextIv, AES_BLOCKLEN);
523 | buf += AES_BLOCKLEN;
524 | }
525 |
526 | }
527 |
528 | #endif // #if defined(CBC) && (CBC == 1)
529 |
530 |
531 |
532 | #if defined(CTR) && (CTR == 1)
533 |
534 | /* Symmetrical operation: same function for encrypting as for decrypting. Note any IV/nonce should never be reused with the same key */
535 | void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
536 | {
537 | uint8_t buffer[AES_BLOCKLEN];
538 |
539 | unsigned i;
540 | int bi;
541 | for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi)
542 | {
543 | if (bi == AES_BLOCKLEN) /* we need to regen xor compliment in buffer */
544 | {
545 |
546 | memcpy(buffer, ctx->Iv, AES_BLOCKLEN);
547 | Cipher((state_t*)buffer,ctx->RoundKey);
548 |
549 | /* Increment Iv and handle overflow */
550 | for (bi = (AES_BLOCKLEN - 1); bi >= 0; --bi)
551 | {
552 | /* inc will overflow */
553 | if (ctx->Iv[bi] == 255)
554 | {
555 | ctx->Iv[bi] = 0;
556 | continue;
557 | }
558 | ctx->Iv[bi] += 1;
559 | break;
560 | }
561 | bi = 0;
562 | }
563 |
564 | buf[i] = (buf[i] ^ buffer[bi]);
565 | }
566 | }
567 |
568 | #endif // #if defined(CTR) && (CTR == 1)
569 |
570 |
--------------------------------------------------------------------------------
/src/aes.h:
--------------------------------------------------------------------------------
1 | #ifndef _AES_H_
2 | #define _AES_H_
3 |
4 | #include
5 |
6 | // #define the macros below to 1/0 to enable/disable the mode of operation.
7 | //
8 | // CBC enables AES encryption in CBC-mode of operation.
9 | // CTR enables encryption in counter-mode.
10 | // ECB enables the basic ECB 16-byte block algorithm. All can be enabled simultaneously.
11 |
12 | // The #ifndef-guard allows it to be configured before #include'ing or at compile time.
13 | #ifndef CBC
14 | #define CBC 1
15 | #endif
16 |
17 | #ifndef ECB
18 | #define ECB 1
19 | #endif
20 |
21 | #ifndef CTR
22 | #define CTR 1
23 | #endif
24 |
25 |
26 | #define AES128 1
27 | //#define AES192 1
28 | //#define AES256 1
29 |
30 | #define AES_BLOCKLEN 16 // Block length in bytes - AES is 128b block only
31 |
32 | #if defined(AES256) && (AES256 == 1)
33 | #define AES_KEYLEN 32
34 | #define AES_keyExpSize 240
35 | #elif defined(AES192) && (AES192 == 1)
36 | #define AES_KEYLEN 24
37 | #define AES_keyExpSize 208
38 | #else
39 | #define AES_KEYLEN 16 // Key length in bytes
40 | #define AES_keyExpSize 176
41 | #endif
42 |
43 | struct AES_ctx
44 | {
45 | uint8_t RoundKey[AES_keyExpSize];
46 | #if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
47 | uint8_t Iv[AES_BLOCKLEN];
48 | #endif
49 | };
50 |
51 | void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key);
52 | #if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
53 | void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv);
54 | void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv);
55 | #endif
56 |
57 | #if defined(ECB) && (ECB == 1)
58 | // buffer size is exactly AES_BLOCKLEN bytes;
59 | // you need only AES_init_ctx as IV is not used in ECB
60 | // NB: ECB is considered insecure for most uses
61 | void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf);
62 | void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf);
63 |
64 | #endif // #if defined(ECB) && (ECB == !)
65 |
66 |
67 | #if defined(CBC) && (CBC == 1)
68 | // buffer size MUST be mutile of AES_BLOCKLEN;
69 | // Suggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme
70 | // NOTES: you need to set IV in ctx via AES_init_ctx_iv() or AES_ctx_set_iv()
71 | // no IV should ever be reused with the same key
72 | void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
73 | void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
74 |
75 | #endif // #if defined(CBC) && (CBC == 1)
76 |
77 |
78 | #if defined(CTR) && (CTR == 1)
79 |
80 | // Same function for encrypting as for decrypting.
81 | // IV is incremented for every block, and used after encryption as XOR-compliment for output
82 | // Suggesting https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme
83 | // NOTES: you need to set IV in ctx with AES_init_ctx_iv() or AES_ctx_set_iv()
84 | // no IV should ever be reused with the same key
85 | void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
86 |
87 | #endif // #if defined(CTR) && (CTR == 1)
88 |
89 |
90 | #endif // _AES_H_
91 |
--------------------------------------------------------------------------------
/src/ludevice.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2017 Ronan Gaillard
3 |
4 | This program is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU General Public License
6 | version 2 as published by the Free Software Foundation.
7 | */
8 | #include "ludevice.h"
9 |
10 | #ifdef EEPROM_SUPPORT
11 | #include
12 | #endif
13 |
14 | ludevice::ludevice() : ludevice(DEFAULT_CE_PIN, DEFAULT_CS_PIN)
15 | {
16 | }
17 |
18 | ludevice::ludevice(uint8_t _cepin, uint8_t _cspin) : radio(_cepin, _cspin)
19 | {
20 | }
21 |
22 | void ludevice::setAddress(uint64_t address)
23 | {
24 | setAddress((uint8_t *)&address);
25 | }
26 |
27 | void ludevice::setAddress(uint8_t *address)
28 | {
29 | uint8_t address_dongle[5];
30 |
31 | // printf("Setting address: %s\r\n", hexa(address, 5));
32 |
33 | memcpy(address_dongle, address, 4);
34 | address_dongle[0] = 0;
35 |
36 | radio.stopListening();
37 | radio.openReadingPipe(2, address_dongle);
38 | radio.openReadingPipe(1, address);
39 | radio.openWritingPipe(address);
40 | }
41 |
42 | bool ludevice::begin()
43 | {
44 | uint8_t init_status = radio.begin();
45 |
46 | // radio.printDetails();
47 |
48 | if (init_status == 0 || init_status == 0xff)
49 | {
50 | return false;
51 | }
52 |
53 | // aes_base = 0x5897AF67;
54 | // aes_base = 0x5897AF60;
55 | aes_base = random(0xfffffff + 1) << 4;
56 |
57 | EEPROM.begin(1 + 5 + 16);
58 | EEPROM.get(MAC_ADDRESS_EEPROM_ADDRESS + 0, current_channel);
59 | EEPROM.get(MAC_ADDRESS_EEPROM_ADDRESS + 1, rf_address);
60 | EEPROM.get(MAC_ADDRESS_EEPROM_ADDRESS + 1 + 5, device_key);
61 |
62 | radio.stopListening();
63 | if (1)
64 | {
65 | radio.setAutoAck(1);
66 | radio.setRetries(3, 1);
67 | radio.setPayloadSize(PAYLOAD_SIZE);
68 | radio.enableDynamicPayloads();
69 | radio.enableAckPayload();
70 | radio.enableDynamicAck();
71 | radio.openWritingPipe(PAIRING_MAC_ADDRESS);
72 | radio.openReadingPipe(1, PAIRING_MAC_ADDRESS);
73 | changeChannel();
74 | radio.setDataRate(RF24_2MBPS);
75 | {
76 | // writeRegister(SETUP_AW, 0x03); // Reset addr size to 5 bytes
77 | digitalWrite(DEFAULT_CS_PIN, LOW);
78 | SPI.transfer(W_REGISTER | (REGISTER_MASK & 0x3));
79 | SPI.transfer(0x03);
80 | digitalWrite(DEFAULT_CS_PIN, HIGH);
81 | }
82 | }
83 | radio.stopListening();
84 |
85 | // radio.openWritingPipe(PAIRING_MAC_ADDRESS);
86 | // radio.openReadingPipe(1, PAIRING_MAC_ADDRESS);
87 | // radio.setAutoAck(1);
88 |
89 | // radio.setPALevel(RF24_PA_MAX);
90 |
91 | // radio.setDataRate(RF24_2MBPS);
92 | // radio.setPayloadSize(PAYLOAD_SIZE);
93 | // radio.enableDynamicPayloads();
94 | // radio.enableAckPayload();
95 | // radio.enableDynamicAck();
96 | // radio.setRetries(3, 1);
97 | // changeChannel();
98 |
99 | radio.stopListening();
100 |
101 | return true;
102 | }
103 |
104 | void ludevice::setChecksum(uint8_t *payload, uint8_t len)
105 | {
106 | uint8_t checksum = 0;
107 |
108 | for (uint8_t i = 0; i < (len - 1); i++)
109 | checksum += payload[i];
110 |
111 | payload[len - 1] = -checksum;
112 | }
113 |
114 | void ludevice::hidpp10(uint8_t *rf_payload, uint8_t payload_size)
115 | {
116 | uint8_t rf_response[22] = {0};
117 | uint8_t reply = 22;
118 | char *name = "UNKNOWN PACKET!!! PLEASE TEST AT DONGLE SIDE!!!";
119 |
120 | rf_response[0] = rf_payload[0];
121 | rf_response[1] = 0x40 | rf_payload[1]; // report ID
122 | rf_response[2] = rf_payload[2]; // device index
123 | rf_response[3] = rf_payload[3]; // sub id
124 | rf_response[4] = rf_payload[4]; // address
125 |
126 | uint32_t feature_id = (rf_payload[5] << 8) + (rf_payload[6]);
127 | uint32_t addr_param = (rf_payload[4] << 8) + (rf_payload[5]);
128 |
129 | // request sub_id is [2 + 1]
130 | switch (rf_payload[3])
131 | {
132 | case 0x80: // SET_REGISTER
133 | // reply = 10;
134 | printf("SETTING REGISTER!!!!!!!!!");
135 | break;
136 | case 0x81: // GET_REGISTER
137 | reply = 10;
138 | switch (addr_param)
139 | {
140 | case 0xf101:
141 | // firmware major
142 | name = "Firmware Major";
143 | rf_response[5] = rf_payload[5];
144 | rf_response[6] = (firmware_version >> 24) & 0xff;
145 | rf_response[7] = (firmware_version >> 16) & 0xff;
146 | break;
147 | case 0xf102:
148 | name = "Firmware Minor";
149 | rf_response[5] = rf_payload[5];
150 | rf_response[6] = (firmware_version >> 8) & 0xff;
151 | rf_response[7] = (firmware_version >> 0) & 0xff;
152 | break;
153 | case 0xf103:
154 | name = "Firmware 0x03";
155 | rf_response[5] = rf_payload[5];
156 | rf_response[6] = 0x01;
157 | rf_response[7] = 0x02;
158 | break;
159 | case 0xf104:
160 | name = "Firmware 0x04";
161 | rf_response[5] = rf_payload[5];
162 | rf_response[6] = 0x02;
163 | rf_response[7] = 0x14;
164 | break;
165 | case 0x700:
166 | name = "HIDPP_REG_BATTERY_STATUS bad";
167 | rf_response[5] = 0x7; //rf_payload[5];
168 | rf_response[6] = 3; // capacity
169 | rf_response[7] = 0x0; // level 1-7
170 | rf_response[8] = 0x0; // discharing
171 | break;
172 | case 0xd00:
173 | // reply = 0;
174 | name = "HIDPP_REG_BATTERY_MILEAGE";
175 | rf_response[5] = 50; // capacity: 0 - 100
176 | rf_response[6] = 0; // nothing: 0
177 | rf_response[7] = 0 << 6; // status: 0 - discharging, 1 - charging
178 | break;
179 | default:
180 | reply = 0;
181 | name = "UNKNOWN";
182 | break;
183 | }
184 | break;
185 | default:
186 | switch (feature_id)
187 | {
188 | case 0x03:
189 | // 00 10 9E 00 02 00 03 00 B6 97
190 | // 00 51 9E 00 02 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0D - response
191 | if (addr_param = 0x200)
192 | {
193 | name = "copied from K270 (2)";
194 | reply = 22;
195 | rf_response[3] = 0x02;
196 | rf_response[4] = 0x02;
197 | rf_response[5] = 0x00;
198 | }
199 | break;
200 | case 0x3f13:
201 | // 00 10 0E 00 12 3F 13 00 00 7E
202 | // 00 51 0E 00 12 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 8D - response
203 | name = "copied from K270 (1)";
204 | reply = 22;
205 | rf_response[3] = 0x00;
206 | rf_response[4] = 0x12;
207 | rf_response[5] = 0x02;
208 | break;
209 | case 0x0000: // 00 10 0E 00 12 00 00 00 B6 1A
210 | name = "we don't understand HID++ 2.0";
211 | reply = 10;
212 | // HID++ 1.0
213 | rf_response[3] = 0x8f;
214 | rf_response[4] = 0;
215 | // RF rf_response Results start from [4 + 1]
216 | rf_response[5] = 0x10 + (rf_payload[4] & 0xf);
217 | rf_response[6] = 1;
218 | rf_response[7] = 0;
219 | rf_response[8] = 0;
220 | }
221 | break;
222 | }
223 |
224 | if (reply && (rf_payload[1] == 0x10 || rf_payload[1] == 0x11))
225 | {
226 | if (reply == 10)
227 | rf_response[1] = 0x50;
228 | if (reply == 22)
229 | rf_response[1] = 0x51;
230 | radiowrite(rf_response, reply, name, 5);
231 | }
232 | }
233 |
234 | void ludevice::hidpp20(uint8_t *rf_payload, uint8_t payload_size)
235 | {
236 | // https://initrd.net/stuff/mousejack/doc/pdf/DEFCON-24-Marc-Newlin-MouseJack-Injecting-Keystrokes-Into-Wireless-Mice.slides.pdf
237 | // https://drive.google.com/file/d/0B4Pb6jGAmjoKQ3hlZDFxUHVqRkU/view
238 |
239 | // [16.922] 9D:65:CB:58:4D 0040006E52 // keepalive, 110ms interval
240 | // [16.923] 9D:65:CB:58:4D // ACK
241 | // [17.015] 9D:65:CB:58:4D 0040006E52 // keepalive, 110ms interval
242 | // [17.015] 9D:65:CB:58:4D // ACK
243 | // [17.108] 9D:65:CB:58:4D 0040006E52 // keepalive, 110ms interval
244 | // [17.108] 9D:65:CB:58:4D // ACK
245 | // [17.201] 9D:65:CB:58:4D 0040006E52 // keepalive, 110ms interval
246 | // [17.201] 9D:65:CB:58:4D // ACK
247 | // [17.294] 9D:65:CB:58:4D 0040006E52 // keepalive, 110ms interval
248 | // [17.294] 9D:65:CB:58:4D 00:10:4D:00:14:00:00:00:00:8F // ACK payload; requesting HID++ version
249 | // 00:10:ce:00:12:3f:13:00:00:be
250 | // 00:10:ce:00:12:00:00:00:11:ff
251 | // [17.302] 9D:65:CB:58:4D 00:51:4D:00:14:04:05:0000000000000000000000000000:45 // response (HID++ 4.5)
252 | // [17.302] 9D:65:CB:58:4D // ACK
253 | // [17.387] 9D:65:CB:58:4D 0040006E52 // keepalive, 110ms interval
254 | // [17.387] 9D:65:CB:58:4D // ACK
255 | // https://lekensteyn.nl/files/logitech/logitech_hidpp_2.0_specification_draft_2012-06-04.pdf
256 | // https://github.com/mame82/UnifyingVulnsDisclosureRepo/blob/master/talk/phishbot_2019_redacted3.pdf
257 | // https://raw.githubusercontent.com/torvalds/linux/master/drivers/hid/hid-logitech-hidpp.c
258 |
259 | // [0] 00 - device index
260 | // [1] 10 - Report ID
261 | // 0x10, 7 bytes UNIFYING_RF_REPORT_HIDPP_SHORT, 0x0E = UNIFYING_RF_REPORT_LED
262 | // 0x11, 20 bytes REPORT_ID_HIDPP_VERY_LONG
263 | // [2] CE - Device Index / RF prefix
264 | // [3] 00 - Sub ID
265 | // ---
266 | // [4] 12 - Address
267 | // [5] xx - value 0
268 | // [6] xx - value 1
269 | // [7] xx - value 2
270 | // [8] 00 -
271 | // [9] xx - checksum
272 |
273 | uint8_t rf_response[22] = {0};
274 | uint8_t reply = 22;
275 | char *name;
276 |
277 | rf_response[0] = rf_payload[0];
278 | rf_response[1] = 0x51;
279 | rf_response[2] = rf_payload[2];
280 | rf_response[3] = rf_payload[3];
281 | rf_response[4] = rf_payload[4];
282 |
283 | uint32_t feature_id = (rf_payload[5] << 8) + (rf_payload[6]);
284 | // https://lekensteyn.nl/files/logitech/logitech_hidpp_2.0_specification_draft_2012-06-04.pdf
285 | switch (feature_id)
286 | {
287 | default:
288 | reply = 0;
289 | break;
290 | case 0x0000: // root
291 | name = "root 0x0000";
292 | reply = 10;
293 | // HID++ 2.0, 4.5
294 | // rf_response[3] = 0x0;
295 | // rf_response[4] = 0x10 + (ack_payload[4] & 0xf);
296 | // RF rf_response Results start from [4 + 1]
297 | rf_response[5] = 0x2;
298 | rf_response[6] = 0x0;
299 | rf_response[7] = rf_payload[8]; // ping
300 | rf_response[8] = 0;
301 | break;
302 | case 0x0003: //device info
303 |
304 | // request parms starts from ack_payload[4]
305 | name = "firmware 0x0003";
306 | // RF rf_response Results start from [4 + 1]
307 | rf_response[5] = 0x0;
308 | rf_response[6] = 'a';
309 | rf_response[7] = 'b';
310 | rf_response[8] = 'c';
311 | rf_response[9] = 0x33;
312 | rf_response[10] = 0x44;
313 | rf_response[11] = 0x1;
314 | rf_response[12] = 0x1;
315 | rf_response[13] = 0x0; //xx
316 | rf_response[14] = 'K';
317 | rf_response[15] = 'S';
318 | rf_response[16] = 'B';
319 |
320 | break;
321 | case 0x1000: // battery
322 | name = "battery 0x1000";
323 | // RF rf_response Results start from [4 + 1]
324 | rf_response[5] = 80; // BatteryDischargeLevel
325 | rf_response[6] = 70; // BatteryDischargeNextLevel
326 | rf_response[7] = 2; // 0 - charging
327 | break;
328 | case 0x1d4b: //wireless device status
329 | name = "wireless 0x1d4b";
330 | rf_response[5] = 0;
331 | rf_response[6] = 0;
332 | rf_response[7] = 0;
333 | break;
334 | }
335 | if (reply && rf_payload[1] == 0x10)
336 | {
337 | if (reply == 10)
338 | rf_response[1] = 0x50;
339 | if (reply == 22)
340 | rf_response[1] = 0x51;
341 | radiowrite(rf_response, reply, name, 1);
342 | }
343 | }
344 |
345 | void ludevice::loop(void)
346 | {
347 | uint8_t response_size = 0;
348 | if (!is_connected)
349 | return;
350 |
351 | uint8_t *rf_payload;
352 |
353 | if (radio.available())
354 | {
355 | response_size = read(rf_payload);
356 | hidpp10(rf_payload, response_size);
357 | // hidpp20(rf_payload, response_size);
358 | }
359 | // stay_alive_mouse();
360 | stay_alive_keyboard();
361 | }
362 |
363 | void ludevice::stay_alive_keyboard(void)
364 | {
365 | uint8_t retry = 5;
366 | uint16_t send_interval;
367 | bool silent = true;
368 | char buffer[30];
369 |
370 | // 8ms for movement, 110ms for 5 seoncds when movement stops, 1200ms after
371 | if (1)
372 | {
373 | switch (keep_alive)
374 | {
375 | case 278:
376 | if (idle_timer > 60000)
377 | {
378 | update_keep_alive(1200, retry, silent);
379 | return;
380 | }
381 | break;
382 | case 1200:
383 | if (idle_timer > (1000 * 5 * 60))
384 | {
385 | printf("- 5 minutes of idle, TODO: go to sleep\r\n");
386 | idle_timer = 6000;
387 | }
388 | break;
389 | default:
390 | if (idle_timer > 30000)
391 | {
392 | update_keep_alive(278, retry, silent);
393 | return;
394 | }
395 | break;
396 | }
397 |
398 | send_interval = keep_alive;
399 | switch (keep_alive)
400 | {
401 | case 278:
402 | send_interval = 250;
403 | break;
404 | case 1200:
405 | send_interval = 1100;
406 | break;
407 | }
408 | }
409 |
410 | if (send_alive_timer > send_interval)
411 | {
412 | unsigned long t = idle_timer;
413 | sprintf(buffer, "%dms keep alive (idle: %d)", keep_alive, t);
414 | radiowrite_ex(keep_alive_packet, sizeof(keep_alive_packet), buffer, retry, silent);
415 | send_alive_timer = 0;
416 | stay_alive_counter++;
417 | }
418 | }
419 |
420 | void ludevice::stay_alive_mouse(void)
421 | {
422 | uint8_t retry = 5;
423 | uint16_t send_interval;
424 | bool silent = false;
425 | char buffer[30];
426 |
427 | // 8ms for movement, 110ms for 5 seoncds when movement stops, 1200ms after
428 |
429 | switch (keep_alive)
430 | {
431 | case 110:
432 | if (idle_timer > 5000)
433 | {
434 | update_keep_alive(1200, retry, silent);
435 | return;
436 | }
437 | break;
438 | case 1200:
439 | if (idle_timer > (1000 * 5 * 60))
440 | {
441 | printf("- 5 minutes of idle, TODO: go to sleep\r\n");
442 | idle_timer = 6000;
443 | }
444 | break;
445 | default:
446 | if (idle_timer > 80)
447 | {
448 | update_keep_alive(110, retry, silent);
449 | return;
450 | }
451 | break;
452 | }
453 |
454 | send_interval = keep_alive;
455 | switch (keep_alive)
456 | {
457 | case 110:
458 | send_interval = 100;
459 | break;
460 | case 1200:
461 | send_interval = 1100;
462 | break;
463 | }
464 |
465 | if (send_alive_timer > send_interval)
466 | {
467 | unsigned long t = idle_timer;
468 | sprintf(buffer, "%dms keep alive (idle: %d)", keep_alive, t);
469 | radiowrite_ex(keep_alive_packet, sizeof(keep_alive_packet), buffer, retry, silent);
470 | send_alive_timer = 0;
471 | stay_alive_counter++;
472 | }
473 | }
474 |
475 | bool ludevice::update_keep_alive(uint16_t timeout, uint8_t retry, bool silent)
476 | {
477 | char buffer[30];
478 | keep_alive_packet[2] = ((timeout & 0xff00) >> 8); // timeout
479 | keep_alive_packet[3] = ((timeout & 0x00ff)); // timeout
480 | setChecksum(keep_alive_packet, 5);
481 |
482 | keep_alive_change_packet[3] = ((timeout & 0xff00) >> 8); // timeout
483 | keep_alive_change_packet[4] = ((timeout & 0x00ff)); // timeout
484 | setChecksum(keep_alive_change_packet, 10);
485 |
486 | retry = 10;
487 | sprintf(buffer, "set keep alive to %d ms", timeout);
488 | if (radiowrite_ex(keep_alive_change_packet, sizeof(keep_alive_change_packet), buffer, retry, silent))
489 | {
490 | // uint8_t *response;
491 | // read(response);
492 | keep_alive = timeout;
493 | return true;
494 | }
495 | return false;
496 | }
497 |
498 | bool ludevice::pair_response(uint8_t *packet, char *name, uint8_t retry)
499 | {
500 | while (retry)
501 | {
502 | if (!radiowrite(packet, 5, name, 1))
503 | {
504 | retry--;
505 | if (retry == 0)
506 | return false;
507 | }
508 | else
509 | {
510 | if (radio.available())
511 | break;
512 | }
513 | }
514 | }
515 |
516 | int ludevice::pair()
517 | {
518 | bool passed;
519 | uint8_t retry = 10;
520 | uint8_t bis_retry;
521 | uint8_t response_size;
522 | uint8_t *response;
523 | uint8_t prefix;
524 |
525 | is_pairing = true;
526 | setAddress(PAIRING_MAC_ADDRESS);
527 |
528 | {
529 | // Send REQ1
530 | prefix = PAIRING_MARKER_PHASE_1; //random(256);
531 | pairing_packet_1[0] = prefix;
532 | pairing_packet_1[3] = rf_address[4];
533 | pairing_packet_1[4] = rf_address[3];
534 | pairing_packet_1[5] = rf_address[2];
535 | pairing_packet_1[6] = rf_address[1];
536 | pairing_packet_1[7] = rf_address[0];
537 |
538 | // lock_channel = false;
539 | if (!radiowrite(pairing_packet_1, 22, "REQ1", retry))
540 | return -10;
541 |
542 | lock_channel = true;
543 |
544 | memcpy(device_raw_key_material, pairing_packet_1 + LOGITACKER_UNIFYING_PAIRING_RSP1_OFFSET_BASE_ADDR, 4); //REQ1 device_rf_address
545 | memcpy(device_raw_key_material + 4, pairing_packet_1 + LOGITACKER_UNIFYING_PAIRING_REQ1_OFFSET_DEVICE_WPID, 2); //REQ1 device_wpid
546 |
547 | // sending REQ1 success, try sending BIS1 to get a response from dongle
548 | pairing_packet_1_bis[0] = prefix;
549 | pairing_packet_1_bis[3] = pairing_packet_1[3];
550 | bis_retry = 10;
551 | while (bis_retry)
552 | {
553 | if (radiowrite(pairing_packet_1_bis, sizeof(pairing_packet_1_bis), "BIS1", 1))
554 | {
555 | response_size = read(response);
556 | if (response_size > 0)
557 | {
558 | if (response[0] != prefix)
559 | {
560 | printf("Wrong prefix\r\n");
561 | }
562 | else
563 | break;
564 | }
565 | else
566 | printf("Empty response\r\n");
567 | }
568 | bis_retry--;
569 | }
570 | if (bis_retry == 0)
571 | return false;
572 |
573 | // extract info from BIS1 response
574 | {
575 | memcpy(device_raw_key_material + 6, response + LOGITACKER_UNIFYING_PAIRING_RSP1_OFFSET_DONGLE_WPID, 2); //RSP1 dongle_wpid
576 | for (int i = 0; i < 5; i++)
577 | rf_address[i] = response[(3 + (4 - i))];
578 | setAddress(rf_address);
579 | }
580 | }
581 |
582 | {
583 | // Send REQ2
584 | prefix = PAIRING_MARKER_PHASE_2; //0; //random(256);
585 | pairing_packet_2[0] = prefix;
586 |
587 | nonce = random(0xffffffff);
588 | pairing_packet_2[3] = ((nonce & 0xff000000) >> 24); // device nonce MSB
589 | pairing_packet_2[4] = ((nonce & 0x00ff0000) >> 16); // device nonce
590 | pairing_packet_2[5] = ((nonce & 0x0000ff00) >> 8); // device nonce
591 | pairing_packet_2[6] = ((nonce & 0x000000ff) >> 0); // device nonce LSB
592 |
593 | serial = random(0xffffffff);
594 | pairing_packet_2[7] = ((serial & 0xff000000) >> 24); // device serial MSB
595 | pairing_packet_2[8] = ((serial & 0x00ff0000) >> 16); // device serial
596 | pairing_packet_2[9] = ((serial & 0x0000ff00) >> 8); // device serial
597 | pairing_packet_2[10] = ((serial & 0x000000ff) >> 0); // device serial LSB
598 | if (!radiowrite(pairing_packet_2, 22, "REQ2", retry))
599 | return false;
600 |
601 | memcpy(device_raw_key_material + 8, pairing_packet_2 + LOGITACKER_UNIFYING_PAIRING_REQ2_OFFSET_DEVICE_NONCE, 4); //REQ2 device_nonce
602 |
603 | // sending REQ2 success, try sending BIS2 to get a response from dongle
604 | pairing_packet_2_bis[0] = prefix;
605 | pairing_packet_2_bis[3] = pairing_packet_2[3];
606 | bis_retry = 10;
607 | while (bis_retry)
608 | {
609 | if (radiowrite(pairing_packet_2_bis, sizeof(pairing_packet_2_bis), "BIS2", 1))
610 | {
611 | response_size = read(response);
612 | if (response_size > 0)
613 | {
614 | if (response[0] != prefix)
615 | {
616 | printf("Wrong prefix\r\n");
617 | }
618 | else
619 | break;
620 | }
621 | else
622 | printf("Empty response\r\n");
623 | }
624 | bis_retry--;
625 | }
626 | if (bis_retry == 0)
627 | return false;
628 |
629 | // extract info from BIS2 response
630 | memcpy(device_raw_key_material + 12, response + LOGITACKER_UNIFYING_PAIRING_RSP2_OFFSET_DONGLE_NONCE, 4); //RSP2 dongle_nonce
631 | }
632 |
633 | {
634 | prefix = PAIRING_MARKER_PHASE_3;
635 | pairing_packet_3[0] = prefix;
636 | pairing_packet_3[4] = strlen(device_name);
637 | memcpy(pairing_packet_3 + 5, device_name, pairing_packet_3[4]);
638 |
639 | if (!radiowrite(pairing_packet_3, 22, "REQ3", retry))
640 | return false;
641 |
642 | pairing_packet_3_bis[0] = prefix;
643 | if (!pair_response(pairing_packet_3_bis, "BIS3", retry))
644 | {
645 | printf("BIS3 failed");
646 | }
647 |
648 | response_size = read(response);
649 | if (response_size == 0)
650 | {
651 | printf("No response\r\n");
652 | return false;
653 | }
654 | }
655 |
656 | {
657 | if (!radiowrite(pairing_packet_4, 10, "Final", retry))
658 | return false;
659 | }
660 |
661 | #ifdef EEPROM_SUPPORT
662 | /* Save address to eeprom */
663 | device_key[2] = device_raw_key_material[0];
664 | device_key[1] = device_raw_key_material[1] ^ 0xFF;
665 | device_key[5] = device_raw_key_material[2] ^ 0xFF;
666 | device_key[3] = device_raw_key_material[3];
667 | device_key[14] = device_raw_key_material[4];
668 | device_key[11] = device_raw_key_material[5];
669 | device_key[9] = device_raw_key_material[6];
670 | device_key[0] = device_raw_key_material[7];
671 | device_key[8] = device_raw_key_material[8];
672 | device_key[6] = device_raw_key_material[9] ^ 0x55;
673 | device_key[4] = device_raw_key_material[10];
674 | device_key[15] = device_raw_key_material[11];
675 | device_key[10] = device_raw_key_material[12] ^ 0xFF;
676 | device_key[12] = device_raw_key_material[13];
677 | device_key[7] = device_raw_key_material[14];
678 | device_key[13] = device_raw_key_material[15] ^ 0x55;
679 |
680 | printf("- Given RF Address: %s\r\n", hexa(rf_address, 5));
681 | printf("- Device Key Raw: %s\r\n", hexs(device_raw_key_material, 16));
682 | printf("- Device Key Derived: %s\r\n", hexs(device_key, 16));
683 | printf("- CHANNEL: %d\r\n", current_channel);
684 |
685 | EEPROM.put(MAC_ADDRESS_EEPROM_ADDRESS + 0, current_channel);
686 | EEPROM.put(MAC_ADDRESS_EEPROM_ADDRESS + 1, rf_address);
687 | EEPROM.put(MAC_ADDRESS_EEPROM_ADDRESS + 1 + 5, device_key);
688 | EEPROM.commit();
689 | #endif
690 |
691 | lock_channel = false;
692 | AES_init_ctx(&ctx, device_key);
693 | return true;
694 | }
695 |
696 | uint8_t ludevice::read(uint8_t *&packet)
697 | {
698 | uint8_t packet_size = 22;
699 |
700 | if (radio.available())
701 | {
702 | packet = _read_buffer;
703 | radio.read(packet, packet_size);
704 | if (1)
705 | {
706 | if ((packet[19] == packet[20]) && (packet[20] == packet[21]))
707 | packet_size = 10;
708 | if (packet_size == 10 && ((packet[7] == packet[8]) && (packet[8] == packet[9])))
709 | packet_size = 5;
710 | }
711 | if (packet[1] != 0xe)
712 | {
713 | // printf("IN [%2d]: %2d ", packet_size, current_channel);
714 | printf("IN [%2d]: %2d ", packet_size, current_channel);
715 | printf("%s\r\n", hexs(packet, packet_size));
716 | }
717 | return packet_size;
718 | }
719 | return 0;
720 | }
721 |
722 | bool ludevice::radiowrite(uint8_t *packet, uint8_t packet_size, char *name, uint8_t retry)
723 | {
724 | return radiowrite_ex(packet, packet_size, name, retry, false);
725 | }
726 |
727 | bool ludevice::radiowrite_ex(uint8_t *packet, uint8_t packet_size, char *name, uint8_t retry, bool silent)
728 | {
729 | char outcome;
730 |
731 | // retry = 1;
732 | outcome = '!';
733 | while (retry)
734 | {
735 | setChecksum(packet, packet_size);
736 | if (radio.write(packet, packet_size))
737 | outcome = ' ';
738 | else
739 | retry--;
740 |
741 | if (!silent)
742 | {
743 | // printf("OUT[%2d]: %2d %s %c ", packet_size, current_channel, hexa(rf_address, 5), outcome);
744 | // printf("%d OUT[%2d]: %s %2d %c ", millis(), packet_size, hexa(rf_address, 5), current_channel, outcome);
745 | printf("OUT[%2d]: %s %2d %c ", packet_size, hexa(rf_address, 5), current_channel, outcome);
746 | printf("%s", hexs(packet, packet_size));
747 | if (name != NULL)
748 | printf(" - %s\r\n", name);
749 | else
750 | printf("\r\n");
751 | }
752 |
753 | if (outcome == '!')
754 | {
755 | if (!lock_channel)
756 | {
757 | changeChannel();
758 | }
759 | }
760 | else
761 | break;
762 | };
763 |
764 | if (outcome == '!')
765 | return false;
766 |
767 | return true;
768 | }
769 |
770 | void ludevice::changeChannel()
771 | {
772 | if (is_pairing)
773 | {
774 | channel_pairing_id++;
775 | if (channel_pairing_id > sizeof(channel_tx))
776 | channel_pairing_id = 0;
777 | current_channel = channel_pairing[channel_pairing_id];
778 | }
779 | else
780 | {
781 | channel_tx_id++;
782 | if (channel_tx_id > sizeof(channel_tx))
783 | channel_tx_id = 0;
784 | current_channel = channel_pairing[channel_tx_id];
785 | }
786 | current_channel = 32;
787 | radio.setChannel(current_channel);
788 | }
789 |
790 | bool ludevice::reconnect()
791 | {
792 | return register_device();
793 | }
794 |
795 | bool ludevice::register_device()
796 | {
797 | #ifndef EEPROM_SUPPORT
798 | #warning "EEPROM support is not enabled"
799 | return false;
800 | #else
801 | uint8_t prefix;
802 | uint8_t *response;
803 | bool failed;
804 | uint8_t packet_size;
805 |
806 | is_pairing = false;
807 |
808 | EEPROM.get(MAC_ADDRESS_EEPROM_ADDRESS + 1, rf_address);
809 |
810 | prefix = rf_address[0];
811 |
812 | rf_address[0] = 0;
813 | setAddress(rf_address);
814 |
815 | register1[0] = prefix;
816 | register1[2] = prefix;
817 | packet_size = sizeof(register1);
818 | if (!radiowrite(register1, packet_size, "register1", 5))
819 | return false;
820 |
821 | register2[0] = prefix;
822 | packet_size = sizeof(register2);
823 | if (!radiowrite(register2, packet_size, "register2", 5))
824 | return false;
825 |
826 | rf_address[0] = prefix;
827 | setAddress(rf_address);
828 |
829 | hello[2] = prefix;
830 | packet_size = sizeof(hello);
831 | if (!radiowrite(hello, packet_size, "hello", 5))
832 | return false;
833 |
834 | if (!update_keep_alive(110, 5, false))
835 | return false;
836 |
837 | is_connected = true;
838 | AES_init_ctx(&ctx, device_key);
839 | return true;
840 | #endif
841 | }
842 |
843 | void ludevice::move(uint16_t x_move, uint16_t y_move)
844 | {
845 | move(x_move, y_move, false, false);
846 | }
847 |
848 | void ludevice::move(uint16_t x_move, uint16_t y_move, bool leftClick, bool rightClick)
849 | {
850 | move(x_move, y_move, 0, 0, leftClick, rightClick);
851 | }
852 |
853 | void ludevice::move(uint16_t x_move, uint16_t y_move, uint8_t scroll_v, uint8_t scroll_h)
854 | {
855 | move(x_move, y_move, scroll_v, scroll_h, false, false);
856 | }
857 |
858 | void ludevice::move(uint16_t x_move, uint16_t y_move, uint8_t scroll_v, uint8_t scroll_h, bool leftClick, bool rightClick)
859 | {
860 | idle_timer = 0;
861 |
862 | uint8_t mouse_payload[] = {0x00, 0xC2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
863 |
864 | uint32_t cursor_velocity;
865 |
866 | cursor_velocity = ((uint32_t)y_move & 0xFFF) << 12 | (x_move & 0xFFF);
867 |
868 | memcpy(mouse_payload + 4, &cursor_velocity, 3);
869 |
870 | if (leftClick)
871 | mouse_payload[2] = 1;
872 |
873 | if (rightClick)
874 | mouse_payload[2] |= 2; //1 << 1;
875 |
876 | mouse_payload[7] = scroll_v;
877 | mouse_payload[8] = scroll_h;
878 |
879 | setChecksum(mouse_payload, 10);
880 | while (!radio.write(mouse_payload, 10, 0))
881 | ;
882 |
883 | radio.flush_rx();
884 | }
885 |
886 | void ludevice::click(bool leftClick, bool rightClick)
887 | {
888 | move(0, 0, leftClick, rightClick);
889 | }
890 |
891 | void ludevice::scroll(uint8_t scroll_v, uint8_t scroll_h)
892 | {
893 | move(0, 0, scroll_v, scroll_h, false, false);
894 | }
895 |
896 | void ludevice::scroll(uint8_t scroll_v)
897 | {
898 | scroll(scroll_v, 0);
899 | }
900 |
901 | void ludevice::wipe_pairing(void)
902 | {
903 | uint8_t erase[15 + 6] = {0};
904 | EEPROM.put(MAC_ADDRESS_EEPROM_ADDRESS, erase);
905 | EEPROM.commit();
906 | }
907 |
908 | char *ludevice::hexs_ex(uint8_t *x, uint8_t length, bool reverse, char separator)
909 | {
910 | uint8_t c;
911 | _hexs[0] = 0;
912 | for (int i = 0; i < length; i++)
913 | {
914 | c = x[i];
915 | if (reverse)
916 | c = x[length - 1 - i];
917 | sprintf(_hexs + (i * 3), "%02X", c);
918 | if (i < length - 1)
919 | sprintf(_hexs + (i * 3) + 2, "%c", separator);
920 | }
921 |
922 | return _hexs;
923 | }
924 |
925 | char *ludevice::hexa(uint8_t *x, uint8_t length)
926 | {
927 | return hexs_ex(x, length, true, ':');
928 | }
929 |
930 | char *ludevice::hexs(uint8_t *x, uint8_t length)
931 | {
932 | return hexs_ex(x, length, false, ' ');
933 | }
934 |
935 | void ludevice::typep(uint8_t scan1, uint8_t scan2, uint8_t scan3, uint8_t scan4, uint8_t scan5, uint8_t scan6)
936 | {
937 | idle_timer = 0;
938 |
939 | uint8_t key_payload[] = {
940 | 0x00,
941 | LOGITACKER_DEVICE_REPORT_TYPES_KEYBOARD | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE | 0x80,
942 | 0x00, // [2] modifier
943 | 0x00,
944 | 0x00, // [4] scancode
945 | 0x00, 0x00, 0x00, 0x00,
946 | 0x00};
947 |
948 | key_payload[3] = 0x4; // send 'a'
949 | key_payload[4] = 0x37; // send '.'
950 | key_payload[3] = scan1;
951 | key_payload[4] = scan2;
952 | key_payload[5] = scan3;
953 | key_payload[6] = scan4;
954 | key_payload[7] = scan5;
955 | key_payload[8] = scan6;
956 | setChecksum(key_payload, 10);
957 | radiowrite(key_payload, 10, "plain key", 5);
958 | return;
959 | while (1)
960 | {
961 | status = failed;
962 | if (radio.write(key_payload, 10, 0))
963 | status = success;
964 |
965 | printf("- plain keyboard: %s, %s\r\n", hexs(key_payload, 10), status);
966 | break;
967 | }
968 | }
969 |
970 | void ludevice::typem(uint16_t scan1, uint16_t scan2)
971 | {
972 | idle_timer = 0;
973 |
974 | uint8_t key_payload[] = {
975 | 0x00, 0xC3,
976 | 0x00, // [2] scancode
977 | 0x00,
978 | 0x00, // [4] scancode
979 | 0x00,
980 | 0x00, 0x00, 0x00, // unused
981 | 0x00};
982 |
983 | // PAGE UP (0x4B)
984 | // PAGE DOWN (0x4E)
985 | // ESC (0x29)
986 | // F5 (0x3E)
987 | // PERIOD (0x37)
988 | // B (0x05)
989 |
990 | // 00 C3 E2 00 00 00 00 00 00 5B (10 bytes) // toggle mute
991 |
992 | key_payload[2] = ((scan1 & 0x00ff) >> 0);
993 | key_payload[3] = ((scan1 & 0xff00) >> 8);
994 | key_payload[4] = ((scan2 & 0x00ff) >> 0);
995 | key_payload[5] = ((scan2 & 0xff00) >> 8);
996 |
997 | radiowrite(key_payload, 10, "media key", 5);
998 | }
999 |
1000 | void ludevice::typee(uint8_t scan1, uint8_t scan2, uint8_t scan3, uint8_t scan4, uint8_t scan5, uint8_t scan6)
1001 | {
1002 | uint32_t temp_counter;
1003 | bool ret;
1004 |
1005 | uint8_t rf_frame[22] = {0};
1006 | uint8_t plain_payload[8] = {0};
1007 |
1008 | idle_timer = 0;
1009 |
1010 | plain_payload[1] = scan1;
1011 | plain_payload[2] = scan2;
1012 | plain_payload[3] = scan3;
1013 | plain_payload[4] = scan4;
1014 | plain_payload[5] = scan5;
1015 | plain_payload[6] = scan6;
1016 |
1017 | temp_counter = (aes_counter & 0xf);
1018 | temp_counter = aes_base + (aes_counter & 0xf);
1019 | logitacker_unifying_crypto_encrypt_keyboard_frame(rf_frame, plain_payload, temp_counter);
1020 |
1021 | if (scan1 == 0 && scan2 == 0 && scan3 == 0 && scan4 == 0 && scan5 == 0 && scan6 == 0)
1022 | ret = radiowrite(rf_frame, 22, "encrypted key up", 1);
1023 | else
1024 | ret = radiowrite(rf_frame, 22, "encrypted key down", 1);
1025 |
1026 | if (ret)
1027 | // aes_counter++;
1028 | aes_base++;
1029 | }
1030 |
1031 | void ludevice::update_little_known_secret_counter(uint8_t *counter_bytes)
1032 | {
1033 | memcpy(little_known_secret + 7, counter_bytes, 4);
1034 | }
1035 |
1036 | void ludevice::logitacker_unifying_crypto_calculate_frame_key(uint8_t *ciphertext, uint8_t *counter_bytes, bool silent)
1037 | {
1038 | if (!silent)
1039 | printf("1. last plain l_k_s: %s\r\n", hexs(little_known_secret, 16));
1040 | update_little_known_secret_counter(counter_bytes); // copy counter_bytes into little_known_secret
1041 | if (!silent)
1042 | printf("2. plain l_k_s+counter: %s\r\n", hexs(little_known_secret, 16));
1043 |
1044 | if (!silent)
1045 | printf("3. device_key: %s\r\n", hexs(device_key, 16));
1046 | memcpy(ciphertext, little_known_secret, 16); // copy little_known_secret into ciphertext
1047 | AES_ECB_encrypt(&ctx, ciphertext); // encrypt ciphertext
1048 |
1049 | if (!silent)
1050 | printf("4. frame_key: %s\r\n", hexs(ciphertext, 16));
1051 | return;
1052 | }
1053 |
1054 | void ludevice::logitacker_unifying_crypto_encrypt_keyboard_frame(uint8_t *rf_frame, uint8_t *plain_payload, uint32_t counter)
1055 | {
1056 | rf_frame[1] = LOGITACKER_DEVICE_REPORT_TYPES_ENCRYPTED_KEYBOARD | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE | 0x80;
1057 | bool silent = false;
1058 |
1059 | uint8_t counter_bytes[4] = {0};
1060 | // K800
1061 | // counter_bytes[3] = (uint8_t)((counter & 0xff000000) >> 24);
1062 | // counter_bytes[2] = (uint8_t)((counter & 0x00ff0000) >> 16);
1063 | // counter_bytes[1] = (uint8_t)((counter & 0x0000ff00) >> 8);
1064 | // counter_bytes[0] = (uint8_t)((counter & 0x000000ff) >> 0);
1065 |
1066 | // K270
1067 | counter_bytes[0] = (uint8_t)((counter & 0xff000000) >> 24);
1068 | counter_bytes[1] = (uint8_t)((counter & 0x00ff0000) >> 16);
1069 | counter_bytes[2] = (uint8_t)((counter & 0x0000ff00) >> 8);
1070 | counter_bytes[3] = (uint8_t)((counter & 0x000000ff) >> 0);
1071 | memcpy(rf_frame + 10, counter_bytes, 4);
1072 |
1073 | uint8_t frame_key[16] = {0};
1074 | logitacker_unifying_crypto_calculate_frame_key(frame_key, counter_bytes, silent);
1075 |
1076 | plain_payload[7] = 0xC9;
1077 | memcpy(rf_frame + 2, plain_payload, 8);
1078 |
1079 | if (!silent)
1080 | printf("5. plain rf_frame: %s\r\n", hexs(rf_frame, 22));
1081 |
1082 | for (int i = 0; i < 8; i++)
1083 | rf_frame[2 + i] ^= frame_key[i];
1084 |
1085 | setChecksum(rf_frame, 22);
1086 |
1087 | if (!silent)
1088 | printf("6. encrypted rf_frame: %s\r\n", hexs(rf_frame, 22));
1089 | }
--------------------------------------------------------------------------------
/src/ludevice.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2020 bilogic
3 | Heavily modified with the aim to be fully compatible with logitech unifying protocol
4 |
5 | Copyright (C) 2017 Ronan Gaillard
6 |
7 | This program is free software; you can redistribute it and/or
8 | modify it under the terms of the GNU General Public License
9 | version 2 as published by the Free Software Foundation.
10 | */
11 |
12 | #ifndef LOGITECH_MOUSE
13 | #define LOGITECH_MOUSE
14 |
15 | #define PAIRING_MARKER_PHASE_1 0xe1
16 | #define PAIRING_MARKER_PHASE_2 0xe2
17 | #define PAIRING_MARKER_PHASE_3 0xe3
18 |
19 | #define LOGITACKER_DEVICE_PROTOCOL_UNIFYING 0x04
20 | #define LOGITACKER_DEVICE_PROTOCOL_LIGHTSPEED 0x0C
21 | #define LOGITACKER_DEVICE_PROTOCOL_G700 0x07
22 |
23 | #define LOGITACKER_DEVICE_UNIFYING_TYPE_UNKNOWN 0x00
24 | #define LOGITACKER_DEVICE_UNIFYING_TYPE_KEYBOARD 0x01
25 | #define LOGITACKER_DEVICE_UNIFYING_TYPE_MOUSE 0x02
26 | #define LOGITACKER_DEVICE_UNIFYING_TYPE_NUMPAD 0x03
27 | #define LOGITACKER_DEVICE_UNIFYING_TYPE_PRESENTER 0x04
28 | #define LOGITACKER_DEVICE_UNIFYING_TYPE_REMOTE 0x07
29 | #define LOGITACKER_DEVICE_UNIFYING_TYPE_TRACKBALL 0x08
30 | #define LOGITACKER_DEVICE_UNIFYING_TYPE_TOUCHPAD 0x09
31 | #define LOGITACKER_DEVICE_UNIFYING_TYPE_TABLET 0x0a
32 | #define LOGITACKER_DEVICE_UNIFYING_TYPE_GAMEPAD 0x0b
33 | #define LOGITACKER_DEVICE_UNIFYING_TYPE_JOYSTICK 0x0c
34 |
35 | #define LOGITACKER_DEVICE_USABILITY_INFO_RESERVED 0x0
36 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_BASE 0x1
37 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_TOP_CASE 0x2
38 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_EDGE_OF_TOP_RIGHT_CORNER 0x3
39 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_OTHER 0x4
40 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_TOP_LEFT_CORNER 0x5
41 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_BOTTOM_LEFT_CORNER 0x6
42 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_TOP_RIGHT_CORNER 0x7
43 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_BOTTOM_RIGHT_CORNER 0x8
44 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_TOP_EDGE 0x9
45 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_RIGHT_EDGE 0xa
46 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_LEFT_EDGE 0xb
47 | #define LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_BOTTOM_EDGE 0xc
48 |
49 | #define LOGITACKER_DEVICE_REPORT_TYPES_KEYBOARD 0x1
50 | #define LOGITACKER_DEVICE_REPORT_TYPES_MOUSE 0x2
51 | #define LOGITACKER_DEVICE_REPORT_TYPES_MULTIMEDIA 0x3
52 | #define LOGITACKER_DEVICE_REPORT_TYPES_POWER_KEYS 0x4
53 | #define LOGITACKER_DEVICE_REPORT_TYPES_MEDIA_CENTER 0x8
54 | #define LOGITACKER_DEVICE_REPORT_TYPES_KEYBOARD_LED 0xe
55 | #define LOGITACKER_DEVICE_REPORT_TYPES_SET_KEEP_ALIVE 0xf
56 | #define LOGITACKER_DEVICE_REPORT_TYPES_SHORT_HIDPP 0x10
57 | #define LOGITACKER_DEVICE_REPORT_TYPES_LONG_HIDPP 0x11
58 | #define LOGITACKER_DEVICE_REPORT_TYPES_ENCRYPTED_KEYBOARD 0x13
59 | #define LOGITACKER_DEVICE_REPORT_TYPES_ENCRYPTED_HIDPP_LONG 0x1b
60 | #define LOGITACKER_DEVICE_REPORT_TYPES_PAIRING 0x1f
61 | #define LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE 0x40
62 |
63 | #define LOGITACKER_DEVICE_CAPS_LINK_ENCRYPTION 0x1 // (1 << 0)
64 | #define LOGITACKER_DEVICE_CAPS_BATTERY_STATUS 0x2 // (1 << 1)
65 | #define LOGITACKER_DEVICE_CAPS_UNIFYING_COMPATIBLE 0x4 // (1 << 2)
66 | #define LOGITACKER_DEVICE_CAPS_UNKNOWN1 0x8 // (1 << 3)
67 |
68 | #define LOGITACKER_UNIFYING_PAIRING_REQ1_OFFSET_DEVICE_WPID 9
69 | #define LOGITACKER_UNIFYING_PAIRING_REQ1_OFFSET_DEVICE_TYPE 13
70 | #define LOGITACKER_UNIFYING_PAIRING_REQ1_OFFSET_DEVICE_CAPS 14
71 |
72 | #define LOGITACKER_UNIFYING_PAIRING_RSP1_OFFSET_DONGLE_WPID 9
73 | #define LOGITACKER_UNIFYING_PAIRING_RSP1_OFFSET_BASE_ADDR 3
74 | #define LOGITACKER_UNIFYING_PAIRING_RSP1_OFFSET_ADDR_PREFIX 7
75 |
76 | #define LOGITACKER_UNIFYING_PAIRING_REQ2_OFFSET_DEVICE_NONCE 3
77 | #define LOGITACKER_UNIFYING_PAIRING_REQ2_OFFSET_DEVICE_SERIAL 7
78 | #define LOGITACKER_UNIFYING_PAIRING_REQ2_OFFSET_DEVICE_REPORT_TYPES_LE 11 //little endian 32bit uint
79 | #define LOGITACKER_UNIFYING_PAIRING_REQ2_OFFSET_DEVICE_USABILITY_INFO 15
80 |
81 | #define LOGITACKER_UNIFYING_PAIRING_RSP2_OFFSET_DONGLE_NONCE 3
82 |
83 | #define LOGITACKER_UNIFYING_PAIRING_REQ3_OFFSET_DEVICE_NAME_LEN 4
84 | #define LOGITACKER_UNIFYING_PAIRING_REQ3_OFFSET_DEVICE_NAME 5
85 |
86 | #define ECB 1
87 |
88 | #include "aes.h"
89 | #include
90 | #include
91 | #include
92 |
93 | #define DEFAULT_CE_PIN D4
94 | #define DEFAULT_CS_PIN D3
95 | #define CHANNEL 5
96 | #define PAYLOAD_SIZE 22
97 | #define PAIRING_MAC_ADDRESS 0xBB0ADCA575LL
98 | #define EEPROM_SUPPORT
99 | #define MAC_ADDRESS_EEPROM_ADDRESS 0
100 |
101 | #ifdef EEPROM_SUPPORT
102 | #include
103 | #endif
104 |
105 | class ludevice
106 | {
107 | private:
108 | RF24 radio;
109 |
110 | void setChecksum(uint8_t *payload, uint8_t len);
111 | void setAddress(uint8_t *address);
112 | void setAddress(uint64_t address);
113 |
114 | struct AES_ctx ctx;
115 |
116 | bool is_pairing = false;
117 | uint8_t current_channel;
118 | uint8_t channel_pairing_id = -1;
119 | uint8_t channel_tx_id = -1;
120 | uint8_t channel_pairing[11] = {62, 8, 35, 65, 14, 41, 71, 17, 44, 74, 5};
121 | uint8_t channel_tx[25] = {5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74, 77};
122 |
123 | bool lock_channel = false;
124 | bool is_connected = false;
125 | char *success = "success";
126 | char *failed = "failed";
127 | char *status;
128 | uint8_t aes_counter = 0;
129 | // uint32_t aes_base = 0x171df9f0;
130 | uint32_t aes_base = 0xed3456ed;
131 |
132 | uint8_t *wakeup_packet;
133 | char _hexs[66];
134 | uint8_t _read_buffer[22];
135 |
136 | uint32_t stay_alive_counter = 0;
137 |
138 | uint8_t rf_address[5];
139 | uint8_t send_address[5];
140 | uint8_t recv_address[5][5];
141 |
142 | // uint8_t rf_address[5];
143 | uint8_t device_key[16];
144 | uint8_t device_raw_key_material[16];
145 |
146 | elapsedMillis send_alive_timer;
147 | elapsedMillis idle_timer;
148 |
149 | // uint32_t firmware_version = 0x22000017; // K800
150 | uint32_t firmware_version = 0x35000017; // K270
151 | // char *device_name = "K800";
152 | // char *device_name = "K270";
153 | char *device_name = "KespB";
154 |
155 | // keyboard at 20ms, 0x14
156 | // mouse keep alive at 8ms interval
157 | uint16_t keep_alive = 0x14;
158 |
159 | // https://github.com/pwr-Solaar/Solaar/blob/master/lib/logitech_receiver/descriptors.py
160 | // uint16_t device_wpid = 0x2010; // actual K800, p=1.0
161 | uint16_t device_wpid = 0x4003; // actual k270
162 | // uint16_t device_wpid = 0x406E; // K800 new, p=4.5
163 | // uint16_t device_wpid = 0x4024; // Anywhere MX
164 | // uint16_t device_wpid = 0x200F; // MK320, p=1.0
165 | // uint16_t device_wpid = 0x1337; // custom
166 | uint8_t protocol = LOGITACKER_DEVICE_PROTOCOL_UNIFYING; // unifying
167 | uint8_t device_type = LOGITACKER_DEVICE_UNIFYING_TYPE_KEYBOARD; // 1
168 | uint8_t caps =
169 | LOGITACKER_DEVICE_CAPS_LINK_ENCRYPTION | // 0001, 1
170 | LOGITACKER_DEVICE_CAPS_BATTERY_STATUS | // 0010, 2
171 | LOGITACKER_DEVICE_CAPS_UNIFYING_COMPATIBLE | // 0100, 4
172 | LOGITACKER_DEVICE_CAPS_UNKNOWN1 | // 1000, 8
173 | 0;
174 |
175 | uint8_t pp1_unknown = 0x1A; // 0010 1010, K270
176 | // uint8_t pp1_unknown = 0x00; // 0000 0000 K800
177 | // uint8_t pp1_unknown = 0x01; // 0000 0001 Hacker
178 |
179 | /* Pre-defined pairing packets */
180 | uint8_t pairing_packet_1_bis[5] = {
181 | 0xF0,
182 | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
183 | 0x01, 0x84,
184 | 0x26};
185 | // [CH: 17] BB:0A:DC:A5:75 05 5F 01 49 16 90 09 F2 14 40 03 04 00 01 0D 00 00 00 00 00 2A 1E (22 bytes)
186 | uint8_t pairing_packet_1[22] = {
187 | 0xF0,
188 | LOGITACKER_DEVICE_REPORT_TYPES_PAIRING | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
189 | 0x01, // step 1
190 | 0xfa, 0xde, 0x11, 0x11, 0x07, // rfaddress
191 | keep_alive, // default keep_alive
192 | ((device_wpid & 0xff00) >> 8), // wireless PID MSB
193 | ((device_wpid & 0x00ff) >> 0), // wireless PID LSB
194 | protocol, 0x00,
195 | device_type,
196 | caps,
197 | 0x00, 0x00, 0x00, 0x00, 0x00,
198 | pp1_unknown,
199 | 0xEC};
200 |
201 | uint32_t nonce = 0xDF850991;
202 | uint32_t serial = 0xA58094B6; // K270
203 | uint32_t report_types =
204 | LOGITACKER_DEVICE_REPORT_TYPES_KEYBOARD |
205 | // LOGITACKER_DEVICE_REPORT_TYPES_MOUSE |
206 | LOGITACKER_DEVICE_REPORT_TYPES_MULTIMEDIA |
207 | LOGITACKER_DEVICE_REPORT_TYPES_POWER_KEYS |
208 | // LOGITACKER_DEVICE_REPORT_TYPES_MEDIA_CENTER |
209 | LOGITACKER_DEVICE_REPORT_TYPES_KEYBOARD_LED |
210 | // LOGITACKER_DEVICE_REPORT_TYPES_SHORT_HIDPP |
211 | // LOGITACKER_DEVICE_REPORT_TYPES_LONG_HIDPP |
212 | // LOGITACKER_DEVICE_REPORT_TYPES_ENCRYPTED_KEYBOARD |
213 | // LOGITACKER_DEVICE_REPORT_TYPES_ENCRYPTED_HIDPP_LONG |
214 | 0;
215 |
216 | uint8_t pairing_packet_2_bis[5] = {
217 | 0x00,
218 | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
219 | 0x02,
220 | 0x12,
221 | 0xbd};
222 | uint8_t pairing_packet_2[22] = {
223 | 0x00,
224 | LOGITACKER_DEVICE_REPORT_TYPES_PAIRING | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
225 | 0x02, // step 2
226 | ((nonce & 0xff000000) >> 24), // device nonce MSB
227 | ((nonce & 0x00ff0000) >> 16), // device nonce
228 | ((nonce & 0x0000ff00) >> 8), // device nonce
229 | ((nonce & 0x000000ff) >> 0), // device nonce LSB
230 | ((serial & 0xff000000) >> 24), // device serial MSB
231 | ((serial & 0x00ff0000) >> 16), // device serial
232 | ((serial & 0x0000ff00) >> 8), // device serial
233 | ((serial & 0x000000ff) >> 0), // device serial LSB
234 | ((report_types & 0x000000ff) >> 0), // device report types
235 | ((report_types & 0x0000ff00) >> 8), // device report types
236 | ((report_types & 0x00ff0000) >> 16), // device report types
237 | ((report_types & 0xff000000) >> 24), // device report types
238 | LOGITACKER_DEVICE_USABILITY_INFO_PS_LOCATION_ON_THE_EDGE_OF_TOP_RIGHT_CORNER, // device_usability_info
239 | 0x00, 0x00, 0x00, 0x00, 0x00,
240 | 0x79};
241 |
242 | uint8_t pairing_packet_3_bis[5] = {
243 | 0x00,
244 | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
245 | 0x03,
246 | 0x01,
247 | 0x0f};
248 | uint8_t pairing_packet_3[22] = {
249 | 0x00,
250 | LOGITACKER_DEVICE_REPORT_TYPES_PAIRING | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE, // 0x40 is device to dongle
251 | 0x03, // step 3
252 | 0x1, // number of reports fixed to 1
253 | 0x3, // length of device name
254 | 65, 66, 67, 0, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255 | 0xB6};
256 |
257 | uint8_t pairing_packet_4[10] = {
258 | 0x00,
259 | LOGITACKER_DEVICE_REPORT_TYPES_SET_KEEP_ALIVE | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
260 | 0x6,
261 | 0x01, 0x00,
262 | 0x00, 0x00, 0x00, 0x00,
263 | 0xED};
264 |
265 | uint8_t keep_alive_change_packet[10] = {
266 | 0x00,
267 | LOGITACKER_DEVICE_REPORT_TYPES_SET_KEEP_ALIVE | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE, // 0x40 is device to dongle
268 | 0x00, // unused
269 |
270 | // timeout, 00:6E is 110ms, 01:00 is 256ms, 04:B0 is 1200ms
271 | ((keep_alive & 0xff00) >> 8), // MSB
272 | ((keep_alive & 0x00ff) >> 0), // LSB
273 | 0x00, 0x00, 0x00, 0x00, // unused
274 | 0xEA // checksum
275 | };
276 | uint8_t keep_alive_packet[5] = {
277 | 0x00,
278 | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
279 | 0x01, 0x00, // timeout, 00:6E is 110ms, 01:00 is 256ms, 04:B0 is 1200ms
280 | 0xEA // checksum
281 | };
282 | /* Enf of pre-defined pairing packets */
283 |
284 | uint8_t register1[22] = {
285 | 0x62, // RF of device
286 | LOGITACKER_DEVICE_REPORT_TYPES_LONG_HIDPP | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
287 | // LOGITACKER_DEVICE_REPORT_TYPES_ENCRYPTED_HIDPP_LONG | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
288 | 0x62, // RF of device
289 | 0x07, 0x00, 0x01, 0x01,
290 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291 | 0xE1};
292 |
293 | uint8_t register2[10] = {
294 | 0x62, // RF of device
295 | LOGITACKER_DEVICE_REPORT_TYPES_SET_KEEP_ALIVE | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
296 | 0x07,
297 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298 | 0x48};
299 |
300 | uint8_t hello[22] = {
301 | 0x00,
302 | LOGITACKER_DEVICE_REPORT_TYPES_LONG_HIDPP | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
303 | // LOGITACKER_DEVICE_REPORT_TYPES_ENCRYPTED_HIDPP_LONG | LOGITACKER_DEVICE_REPORT_TYPES_KEEP_ALIVE,
304 | 0x62, // RF of device
305 | 0x04, 0x00, 0x46, 0x14,
306 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307 | 0xEF};
308 |
309 | uint8_t little_known_secret[16] = {
310 | // 81B4 81B5 81B6 81B7 81B8 81B9
311 | // 0 1 2 3 4 5 6 (7) (8) (9) (A) B C D E F
312 | 0x04, 0x14, 0x1d, 0x1f, 0x27, 0x28, 0x0d, 0xde, 0xad, 0xbe, 0xef, 0x0a, 0x0d, 0x13, 0x26, 0x0e};
313 |
314 | public:
315 | ludevice(uint8_t _cepin, uint8_t _cspin);
316 | ludevice();
317 |
318 | bool begin();
319 |
320 | int pair();
321 | bool pairing();
322 | bool pair_response(uint8_t *packet, char *name, uint8_t retry);
323 | bool reconnect();
324 | bool register_device();
325 |
326 | void move(uint16_t x_move, uint16_t y_move);
327 | void move(uint16_t x_move, uint16_t y_move, bool leftClick, bool rightClick);
328 | void move(uint16_t x_move, uint16_t y_move, uint8_t scroll_v, uint8_t scroll_h);
329 | void move(uint16_t x_move, uint16_t y_move, uint8_t scroll_v, uint8_t scroll_h, bool leftClick, bool rightClick);
330 | void click(bool leftClick, bool rightClick);
331 | void scroll(uint8_t scroll_v, uint8_t scroll_h);
332 | void scroll(uint8_t scroll_v);
333 | char *hexs(uint8_t *x, uint8_t length);
334 | char *hexa(uint8_t *x, uint8_t length);
335 | char *hexs_ex(uint8_t *x, uint8_t length, bool reverse, char separator);
336 | void typep(uint8_t scan1 = 0, uint8_t scan2 = 0, uint8_t scan3 = 0, uint8_t scan4 = 0, uint8_t scan5 = 0, uint8_t scan6 = 0);
337 | void typee(uint8_t scan1 = 0, uint8_t scan2 = 0, uint8_t scan3 = 0, uint8_t scan4 = 0, uint8_t scan5 = 0, uint8_t scan6 = 0);
338 | void typem(uint16_t scan1 = 0, uint16_t scan2 = 0);
339 |
340 | void changeChannel();
341 |
342 | void wipe_pairing(void);
343 | void loop(void);
344 | void stay_alive_mouse(void);
345 | void stay_alive_keyboard(void);
346 | bool update_keep_alive(uint16_t timeout, uint8_t retry, bool silent);
347 | bool radiowrite(uint8_t *packet, uint8_t packet_size, char *name, uint8_t retry);
348 | bool radiowrite_ex(uint8_t *packet, uint8_t packet_size, char *name, uint8_t retry, bool silent);
349 | uint8_t read(uint8_t *&packet);
350 |
351 | void hidpp10(uint8_t *rf_payload, uint8_t payload_size);
352 | void hidpp20(uint8_t *rf_payload, uint8_t payload_size);
353 |
354 | void logitacker_unifying_crypto_encrypt_keyboard_frame(uint8_t *encrypted, uint8_t *plain, uint32_t counter);
355 | void logitacker_unifying_crypto_calculate_frame_key(uint8_t *frame_key, uint8_t *counter_bytes, bool silent);
356 | void update_little_known_secret_counter(uint8_t *counter);
357 | bool connected();
358 | };
359 |
360 | #endif
361 |
--------------------------------------------------------------------------------
/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "ludevice.h"
4 |
5 | elapsedMillis move_timer;
6 | ludevice kespb(D4, D3);
7 |
8 | float mouseSpeed = 10.0f;
9 | float degreesToRadians = 2.0f * 3.14f / 360.0f;
10 | bool keydown = false;
11 |
12 | void setup()
13 | {
14 | int retcode;
15 | Serial.setDebugOutput(true);
16 | Serial.begin(921600);
17 | Serial.println("Starting");
18 |
19 | kespb.begin();
20 | while (1)
21 | {
22 | if (kespb.reconnect())
23 | {
24 | printf("Reconnected!\r\n");
25 | break;
26 | }
27 | else
28 | {
29 | retcode = kespb.pair();
30 | if (retcode == true)
31 | {
32 | if (kespb.register_device())
33 | {
34 | printf("Paired and connected\r\n");
35 | break;
36 | }
37 | }
38 | else
39 | {
40 | if (retcode == false)
41 | {
42 | printf("No dongle wants to pair\r\n");
43 | delay(5000); // sleep for 5 seconds before trying to pair again
44 | }
45 | }
46 | }
47 | yield();
48 | }
49 | }
50 |
51 | void loop()
52 | {
53 | // kespb.loop();
54 | // return;
55 | if ((move_timer > 5000))
56 | {
57 | // keydown
58 | if (!keydown)
59 | {
60 | kespb.move(0, 0, 0, 0, true, false); // left click down
61 | kespb.typee(4, 5, 6, 7, 8, 9); // encrypted payload: a, b, c, d, e, f
62 | // kespb.typep(4, 5, 6, 7, 8, 9); // plain payload: a, b, c, d, e, f
63 | // kespb.typem(0x192, 0); // calculator
64 | // kespb.typem(0x183, 0); // video player
65 |
66 | kespb.typem(0xe2); // toggle mute
67 | // kespb.typem(0xe9); // volume up
68 | // kespb.typem(0xea); // volume down
69 | // kespb.typem(0xb6); // rev
70 | // kespb.typem(0xcd); // play/pause
71 | // kespb.typem(0xb5); // fwd
72 |
73 | keydown = true;
74 | }
75 | else
76 | {
77 | kespb.move(0, 0, 0, 0, false, false); // left click up
78 | kespb.typep(); // plain release all keys
79 | kespb.typee(); // encrypted release all keys
80 | kespb.typem(); // multimedia release all keys
81 | keydown = false;
82 | move_timer = 0;
83 | }
84 | }
85 |
86 | kespb.loop();
87 | return;
88 |
89 | if (move_timer > 1000)
90 | {
91 | int x, y = 0;
92 |
93 | Serial.println("moving mouse ");
94 | for (x = 0; x < 360; x += 5)
95 | {
96 | Serial.print(".");
97 |
98 | kespb.move((uint16_t)(mouseSpeed * cos(((float)x) * degreesToRadians)),
99 | (uint16_t)(mouseSpeed * sin(((float)x) * degreesToRadians)));
100 |
101 | // delay(1000);
102 | // kespb.typee();
103 | }
104 | Serial.println("");
105 | move_timer = 0;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/test/README:
--------------------------------------------------------------------------------
1 |
2 | This directory is intended for PIO Unit Testing and project tests.
3 |
4 | Unit Testing is a software testing method by which individual units of
5 | source code, sets of one or more MCU program modules together with associated
6 | control data, usage procedures, and operating procedures, are tested to
7 | determine whether they are fit for use. Unit testing finds problems early
8 | in the development cycle.
9 |
10 | More information about PIO Unit Testing:
11 | - https://docs.platformio.org/page/plus/unit-testing.html
12 |
--------------------------------------------------------------------------------