├── LICENSE ├── README.md ├── TOSMotionSensor.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ ├── j.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── xord.xcuserdatad │ │ └── UserInterfaceState.xcuserstate ├── xcshareddata │ └── xcschemes │ │ └── TOSMotionSensor.xcscheme └── xcuserdata │ ├── j.xcuserdatad │ └── xcschemes │ │ ├── TOSMotionSensor.xcscheme │ │ └── xcschememanagement.plist │ └── xord.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── TOSMotionSensor ├── Info.plist ├── TOSMotionSensor.cpp ├── TOSMotionSensor.hpp ├── TOSMotionSensorClient.cpp ├── ToshibaHAPS.cpp └── ToshibaHAPS.hpp └── Test ├── test └── test.c /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## TOSMotionSensor 2 | TOSMotionSensor is an accelerometer driver for Toshiba hackintosh devices. It has been designed to use the built-in accelerometer in any Toshiba device sporting one and should be compatible with any supported device. 3 | 4 | TOSMotionSensor also kinda-sorta emulates the built in accelerometer HDD MacBook and MacBook Pros used to come with by publishing the same IOService and can be queried by user-space applications in the same way. 5 | 6 | tldr: This is compatible with native macOS applications that use SMS (SMCMotionSensor/Sudden Motion Sensor) data. No proprietary software/patches/hacks necessary. 7 | 8 | **NOTE: This driver does NOT offer HDD protection. A lot more testing and research needs to be done in order for that to happen.** I did not include this in the first release as I don't feel this is as important as it used to be. Most of us are using solid state storage these days. Would still be cool to get working though. 9 | 10 | ## Usage 11 | I have tested this kext on High Sierra and Mojave in Clover's 'kexts/Other', SLE, and LE. All seem to be working. 12 | 13 | If you do not want to build it yourself you can **[Download the latest release here](https://github.com/jslegendre/TOSMotionSensor)** 14 | 15 | ## Development 16 | If you would like to get started developing motion-based applications you can check out [SMSLib](http://suitable.com/smslib.html), a library made especially for grabbing accelerometer data on Apple hardware or check out my own display autorotation app [Displace](https://github.com/jslegendre/Displace) for a real-world example. 17 | 18 | ## Future 19 | I am really excited about iOS apps (supposedly) coming to macOS and the possibilities this opens up. Possible uses include: 20 | 21 | - Gaming. Playing motion-based iOS games "natively" on a bigger screen. 22 | - Testing for iOS motion-based app developers. 23 | 24 | ## Contributing 25 | I am very open to pull requests. This is my first kext release and I'm sure that I have some areas to improve upon. 26 | 27 | - Development. Check out the source, there are comments, questions, and todos all over the place. 28 | - Testing. If you have a Toshiba device with an accelerometer, please try this out alongside [Displace](https://github.com/jslegendre/Displace) and let me know how it worked for you. 29 | - Financially. Yeeeeessshh, okay, this is where I get uncomfortable. This and other projects take time and something I've come to learn since having a child is that time isn't free. Especially (and ironically) free time. The only thing I have up right now is a [Patreon](https://www.patreon.com/jslegendre) account if you are interested. \*cue Sarah McLachlan* Even $1/month is a huge help and allows me to dedicate more time to Hackintosh projects as well as access to more devices to make drivers for. 30 | 31 | I cannot thank you enough for even reading this far let alone helping out in any way you can. -------------------------------------------------------------------------------- /TOSMotionSensor.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 090B57D42293B9BE00879B1B /* TOSMotionSensor.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 090B57D32293B9BE00879B1B /* TOSMotionSensor.hpp */; }; 11 | 090B57D62293B9BE00879B1B /* TOSMotionSensor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 090B57D52293B9BE00879B1B /* TOSMotionSensor.cpp */; }; 12 | 09288B22229656F10061881A /* TOSMotionSensorClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 09288B21229656F10061881A /* TOSMotionSensorClient.cpp */; }; 13 | 09288B2522965BAA0061881A /* ToshibaHAPS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 09288B2322965BAA0061881A /* ToshibaHAPS.cpp */; }; 14 | 09288B2622965BAA0061881A /* ToshibaHAPS.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 09288B2422965BAA0061881A /* ToshibaHAPS.hpp */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | 090B57D02293B9BE00879B1B /* TOSMotionSensor.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TOSMotionSensor.kext; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | 090B57D32293B9BE00879B1B /* TOSMotionSensor.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = TOSMotionSensor.hpp; sourceTree = ""; }; 20 | 090B57D52293B9BE00879B1B /* TOSMotionSensor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TOSMotionSensor.cpp; sourceTree = ""; }; 21 | 090B57D72293B9BE00879B1B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 22 | 09288B21229656F10061881A /* TOSMotionSensorClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TOSMotionSensorClient.cpp; sourceTree = ""; }; 23 | 09288B2322965BAA0061881A /* ToshibaHAPS.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ToshibaHAPS.cpp; sourceTree = ""; }; 24 | 09288B2422965BAA0061881A /* ToshibaHAPS.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ToshibaHAPS.hpp; sourceTree = ""; }; 25 | /* End PBXFileReference section */ 26 | 27 | /* Begin PBXFrameworksBuildPhase section */ 28 | 090B57CC2293B9BE00879B1B /* Frameworks */ = { 29 | isa = PBXFrameworksBuildPhase; 30 | buildActionMask = 2147483647; 31 | files = ( 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXFrameworksBuildPhase section */ 36 | 37 | /* Begin PBXGroup section */ 38 | 090B57C62293B9BE00879B1B = { 39 | isa = PBXGroup; 40 | children = ( 41 | 090B57D22293B9BE00879B1B /* TOSMotionSensor */, 42 | 090B57D12293B9BE00879B1B /* Products */, 43 | ); 44 | sourceTree = ""; 45 | }; 46 | 090B57D12293B9BE00879B1B /* Products */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 090B57D02293B9BE00879B1B /* TOSMotionSensor.kext */, 50 | ); 51 | name = Products; 52 | sourceTree = ""; 53 | }; 54 | 090B57D22293B9BE00879B1B /* TOSMotionSensor */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 09288B2422965BAA0061881A /* ToshibaHAPS.hpp */, 58 | 09288B2322965BAA0061881A /* ToshibaHAPS.cpp */, 59 | 090B57D32293B9BE00879B1B /* TOSMotionSensor.hpp */, 60 | 090B57D52293B9BE00879B1B /* TOSMotionSensor.cpp */, 61 | 09288B21229656F10061881A /* TOSMotionSensorClient.cpp */, 62 | 090B57D72293B9BE00879B1B /* Info.plist */, 63 | ); 64 | path = TOSMotionSensor; 65 | sourceTree = ""; 66 | }; 67 | /* End PBXGroup section */ 68 | 69 | /* Begin PBXHeadersBuildPhase section */ 70 | 090B57CD2293B9BE00879B1B /* Headers */ = { 71 | isa = PBXHeadersBuildPhase; 72 | buildActionMask = 2147483647; 73 | files = ( 74 | 090B57D42293B9BE00879B1B /* TOSMotionSensor.hpp in Headers */, 75 | 09288B2622965BAA0061881A /* ToshibaHAPS.hpp in Headers */, 76 | ); 77 | runOnlyForDeploymentPostprocessing = 0; 78 | }; 79 | /* End PBXHeadersBuildPhase section */ 80 | 81 | /* Begin PBXNativeTarget section */ 82 | 090B57CF2293B9BE00879B1B /* TOSMotionSensor */ = { 83 | isa = PBXNativeTarget; 84 | buildConfigurationList = 090B57DA2293B9BE00879B1B /* Build configuration list for PBXNativeTarget "TOSMotionSensor" */; 85 | buildPhases = ( 86 | 090B57CB2293B9BE00879B1B /* Sources */, 87 | 090B57CC2293B9BE00879B1B /* Frameworks */, 88 | 090B57CD2293B9BE00879B1B /* Headers */, 89 | 090B57CE2293B9BE00879B1B /* Resources */, 90 | ); 91 | buildRules = ( 92 | ); 93 | dependencies = ( 94 | ); 95 | name = TOSMotionSensor; 96 | productName = TOSMotionSensor; 97 | productReference = 090B57D02293B9BE00879B1B /* TOSMotionSensor.kext */; 98 | productType = "com.apple.product-type.kernel-extension"; 99 | }; 100 | /* End PBXNativeTarget section */ 101 | 102 | /* Begin PBXProject section */ 103 | 090B57C72293B9BE00879B1B /* Project object */ = { 104 | isa = PBXProject; 105 | attributes = { 106 | LastUpgradeCheck = 0940; 107 | ORGANIZATIONNAME = j; 108 | TargetAttributes = { 109 | 090B57CF2293B9BE00879B1B = { 110 | CreatedOnToolsVersion = 9.4; 111 | }; 112 | }; 113 | }; 114 | buildConfigurationList = 090B57CA2293B9BE00879B1B /* Build configuration list for PBXProject "TOSMotionSensor" */; 115 | compatibilityVersion = "Xcode 9.3"; 116 | developmentRegion = en; 117 | hasScannedForEncodings = 0; 118 | knownRegions = ( 119 | en, 120 | Base, 121 | ); 122 | mainGroup = 090B57C62293B9BE00879B1B; 123 | productRefGroup = 090B57D12293B9BE00879B1B /* Products */; 124 | projectDirPath = ""; 125 | projectRoot = ""; 126 | targets = ( 127 | 090B57CF2293B9BE00879B1B /* TOSMotionSensor */, 128 | ); 129 | }; 130 | /* End PBXProject section */ 131 | 132 | /* Begin PBXResourcesBuildPhase section */ 133 | 090B57CE2293B9BE00879B1B /* Resources */ = { 134 | isa = PBXResourcesBuildPhase; 135 | buildActionMask = 2147483647; 136 | files = ( 137 | ); 138 | runOnlyForDeploymentPostprocessing = 0; 139 | }; 140 | /* End PBXResourcesBuildPhase section */ 141 | 142 | /* Begin PBXSourcesBuildPhase section */ 143 | 090B57CB2293B9BE00879B1B /* Sources */ = { 144 | isa = PBXSourcesBuildPhase; 145 | buildActionMask = 2147483647; 146 | files = ( 147 | 090B57D62293B9BE00879B1B /* TOSMotionSensor.cpp in Sources */, 148 | 09288B2522965BAA0061881A /* ToshibaHAPS.cpp in Sources */, 149 | 09288B22229656F10061881A /* TOSMotionSensorClient.cpp in Sources */, 150 | ); 151 | runOnlyForDeploymentPostprocessing = 0; 152 | }; 153 | /* End PBXSourcesBuildPhase section */ 154 | 155 | /* Begin XCBuildConfiguration section */ 156 | 090B57D82293B9BE00879B1B /* Debug */ = { 157 | isa = XCBuildConfiguration; 158 | buildSettings = { 159 | ALWAYS_SEARCH_USER_PATHS = NO; 160 | CLANG_ANALYZER_NONNULL = YES; 161 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 162 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 163 | CLANG_CXX_LIBRARY = "libc++"; 164 | CLANG_ENABLE_MODULES = YES; 165 | CLANG_ENABLE_OBJC_ARC = YES; 166 | CLANG_ENABLE_OBJC_WEAK = YES; 167 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 168 | CLANG_WARN_BOOL_CONVERSION = YES; 169 | CLANG_WARN_COMMA = YES; 170 | CLANG_WARN_CONSTANT_CONVERSION = YES; 171 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 172 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 173 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 174 | CLANG_WARN_EMPTY_BODY = YES; 175 | CLANG_WARN_ENUM_CONVERSION = YES; 176 | CLANG_WARN_INFINITE_RECURSION = YES; 177 | CLANG_WARN_INT_CONVERSION = YES; 178 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 179 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 180 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 181 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 182 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 183 | CLANG_WARN_STRICT_PROTOTYPES = YES; 184 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 185 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 186 | CLANG_WARN_UNREACHABLE_CODE = YES; 187 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 188 | CODE_SIGN_IDENTITY = "-"; 189 | COPY_PHASE_STRIP = NO; 190 | DEBUG_INFORMATION_FORMAT = dwarf; 191 | ENABLE_STRICT_OBJC_MSGSEND = YES; 192 | ENABLE_TESTABILITY = YES; 193 | GCC_C_LANGUAGE_STANDARD = gnu11; 194 | GCC_DYNAMIC_NO_PIC = NO; 195 | GCC_NO_COMMON_BLOCKS = YES; 196 | GCC_OPTIMIZATION_LEVEL = 0; 197 | GCC_PREPROCESSOR_DEFINITIONS = ( 198 | "DEBUG=1", 199 | "$(inherited)", 200 | ); 201 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 202 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 203 | GCC_WARN_UNDECLARED_SELECTOR = YES; 204 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 205 | GCC_WARN_UNUSED_FUNCTION = YES; 206 | GCC_WARN_UNUSED_VARIABLE = YES; 207 | MACOSX_DEPLOYMENT_TARGET = 10.14; 208 | MTL_ENABLE_DEBUG_INFO = YES; 209 | ONLY_ACTIVE_ARCH = YES; 210 | SDKROOT = macosx; 211 | }; 212 | name = Debug; 213 | }; 214 | 090B57D92293B9BE00879B1B /* Release */ = { 215 | isa = XCBuildConfiguration; 216 | buildSettings = { 217 | ALWAYS_SEARCH_USER_PATHS = NO; 218 | CLANG_ANALYZER_NONNULL = YES; 219 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 220 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 221 | CLANG_CXX_LIBRARY = "libc++"; 222 | CLANG_ENABLE_MODULES = YES; 223 | CLANG_ENABLE_OBJC_ARC = YES; 224 | CLANG_ENABLE_OBJC_WEAK = YES; 225 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 226 | CLANG_WARN_BOOL_CONVERSION = YES; 227 | CLANG_WARN_COMMA = YES; 228 | CLANG_WARN_CONSTANT_CONVERSION = YES; 229 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 230 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 231 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN_ENUM_CONVERSION = YES; 234 | CLANG_WARN_INFINITE_RECURSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 237 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 238 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 239 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 240 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 241 | CLANG_WARN_STRICT_PROTOTYPES = YES; 242 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 243 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 244 | CLANG_WARN_UNREACHABLE_CODE = YES; 245 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 246 | CODE_SIGN_IDENTITY = "-"; 247 | COPY_PHASE_STRIP = NO; 248 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 249 | ENABLE_NS_ASSERTIONS = NO; 250 | ENABLE_STRICT_OBJC_MSGSEND = YES; 251 | GCC_C_LANGUAGE_STANDARD = gnu11; 252 | GCC_NO_COMMON_BLOCKS = YES; 253 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 254 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 255 | GCC_WARN_UNDECLARED_SELECTOR = YES; 256 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 257 | GCC_WARN_UNUSED_FUNCTION = YES; 258 | GCC_WARN_UNUSED_VARIABLE = YES; 259 | MACOSX_DEPLOYMENT_TARGET = 10.14; 260 | MTL_ENABLE_DEBUG_INFO = NO; 261 | SDKROOT = macosx; 262 | }; 263 | name = Release; 264 | }; 265 | 090B57DB2293B9BE00879B1B /* Debug */ = { 266 | isa = XCBuildConfiguration; 267 | buildSettings = { 268 | CODE_SIGN_IDENTITY = ""; 269 | CODE_SIGN_STYLE = Manual; 270 | COMBINE_HIDPI_IMAGES = YES; 271 | CURRENT_PROJECT_VERSION = 1.0.0d1; 272 | DEVELOPMENT_TEAM = ""; 273 | INFOPLIST_FILE = TOSMotionSensor/Info.plist; 274 | MACOSX_DEPLOYMENT_TARGET = 10.14; 275 | MODULE_NAME = com.github.jslegendre.TOSMotionSensor; 276 | MODULE_VERSION = 1.0.0d1; 277 | OTHER_CPLUSPLUSFLAGS = ( 278 | "$(OTHER_CFLAGS)", 279 | "-Wno-inconsistent-missing-override", 280 | ); 281 | PRODUCT_BUNDLE_IDENTIFIER = com.github.jslegendre.TOSMotionSensor; 282 | PRODUCT_NAME = "$(TARGET_NAME)"; 283 | PROVISIONING_PROFILE_SPECIFIER = ""; 284 | WRAPPER_EXTENSION = kext; 285 | }; 286 | name = Debug; 287 | }; 288 | 090B57DC2293B9BE00879B1B /* Release */ = { 289 | isa = XCBuildConfiguration; 290 | buildSettings = { 291 | CODE_SIGN_IDENTITY = ""; 292 | CODE_SIGN_STYLE = Manual; 293 | COMBINE_HIDPI_IMAGES = YES; 294 | CURRENT_PROJECT_VERSION = 1.0.0d1; 295 | DEVELOPMENT_TEAM = ""; 296 | INFOPLIST_FILE = TOSMotionSensor/Info.plist; 297 | MACOSX_DEPLOYMENT_TARGET = 10.14; 298 | MODULE_NAME = com.github.jslegendre.TOSMotionSensor; 299 | MODULE_VERSION = 1.0.0d1; 300 | OTHER_CPLUSPLUSFLAGS = ( 301 | "$(OTHER_CFLAGS)", 302 | "-Wno-inconsistent-missing-override", 303 | ); 304 | PRODUCT_BUNDLE_IDENTIFIER = com.github.jslegendre.TOSMotionSensor; 305 | PRODUCT_NAME = "$(TARGET_NAME)"; 306 | PROVISIONING_PROFILE_SPECIFIER = ""; 307 | WRAPPER_EXTENSION = kext; 308 | }; 309 | name = Release; 310 | }; 311 | /* End XCBuildConfiguration section */ 312 | 313 | /* Begin XCConfigurationList section */ 314 | 090B57CA2293B9BE00879B1B /* Build configuration list for PBXProject "TOSMotionSensor" */ = { 315 | isa = XCConfigurationList; 316 | buildConfigurations = ( 317 | 090B57D82293B9BE00879B1B /* Debug */, 318 | 090B57D92293B9BE00879B1B /* Release */, 319 | ); 320 | defaultConfigurationIsVisible = 0; 321 | defaultConfigurationName = Release; 322 | }; 323 | 090B57DA2293B9BE00879B1B /* Build configuration list for PBXNativeTarget "TOSMotionSensor" */ = { 324 | isa = XCConfigurationList; 325 | buildConfigurations = ( 326 | 090B57DB2293B9BE00879B1B /* Debug */, 327 | 090B57DC2293B9BE00879B1B /* Release */, 328 | ); 329 | defaultConfigurationIsVisible = 0; 330 | defaultConfigurationName = Release; 331 | }; 332 | /* End XCConfigurationList section */ 333 | }; 334 | rootObject = 090B57C72293B9BE00879B1B /* Project object */; 335 | } 336 | -------------------------------------------------------------------------------- /TOSMotionSensor.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TOSMotionSensor.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /TOSMotionSensor.xcodeproj/project.xcworkspace/xcuserdata/j.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jslegendre/TOSMotionSensor/20cc1d4f2cae1d0ee0114389902779c8865c931b/TOSMotionSensor.xcodeproj/project.xcworkspace/xcuserdata/j.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /TOSMotionSensor.xcodeproj/project.xcworkspace/xcuserdata/xord.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jslegendre/TOSMotionSensor/20cc1d4f2cae1d0ee0114389902779c8865c931b/TOSMotionSensor.xcodeproj/project.xcworkspace/xcuserdata/xord.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /TOSMotionSensor.xcodeproj/xcshareddata/xcschemes/TOSMotionSensor.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /TOSMotionSensor.xcodeproj/xcuserdata/j.xcuserdatad/xcschemes/TOSMotionSensor.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /TOSMotionSensor.xcodeproj/xcuserdata/j.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | TOSMotionSensor.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 090B57CF2293B9BE00879B1B 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /TOSMotionSensor.xcodeproj/xcuserdata/xord.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | TOSMotionSensor.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 090B57CF2293B9BE00879B1B 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /TOSMotionSensor/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | KEXT 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | IOKitPersonalities 22 | 23 | HCI Method Interface 24 | 25 | CFBundleIdentifier 26 | $(PRODUCT_BUNDLE_IDENTIFIER) 27 | IOClass 28 | SMCMotionSensor 29 | IONameMatch 30 | TOS1900 31 | IOProviderClass 32 | IOACPIPlatformDevice 33 | IOUserClientClass 34 | SMCMotionSensorClient 35 | 36 | HD Protection Scheme 37 | 38 | CFBundleIdentifier 39 | $(PRODUCT_BUNDLE_IDENTIFIER) 40 | IOClass 41 | ToshibaHAPS 42 | IONameMatch 43 | TOS620A 44 | IOProviderClass 45 | IOACPIPlatformDevice 46 | 47 | 48 | NSHumanReadableCopyright 49 | Copyright © 2019 jslegendre. All rights reserved. 50 | OSBundleLibraries 51 | 52 | com.apple.iokit.IOACPIFamily 53 | 1.0d1 54 | com.apple.kpi.iokit 55 | 9.0.0 56 | com.apple.kpi.libkern 57 | 9.0.0 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /TOSMotionSensor/TOSMotionSensor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 jslegendre / Xord. All rights reserved. 3 | * 4 | * Released under "The GNU General Public License (GPL-2.0)" 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | */ 21 | 22 | /* 23 | Credits: 24 | https://github.com/torvalds/linux/blob/master/drivers/platform/x86/toshiba_acpi.c 25 | */ 26 | 27 | #include "TOSMotionSensor.hpp" 28 | 29 | #ifdef DEBUG 30 | #define DPRINT(fmt, ...) \ 31 | IOLog("TOSMotionSensor::%s:%d(): " fmt, __func__, __LINE__, ##__VA_ARGS__); 32 | #else 33 | #define DPRINT(fmt, ...) do {} while (0) 34 | #endif 35 | 36 | #define HCI_GET 0xfe00 37 | #define HCI_ACCEL 0x6d 38 | #define HCI_ACCEL_SUPPORT 0xa6 39 | #define HCI_ACCEL_MASK 0x7fff 40 | #define HCI_ACCEL_DIRECTION_MASK 0x8000 41 | #define HCI_ACCEL_Y_SHIFT 0x10 42 | #define HCI_UNSUPPORTED 0x8000 43 | #define HCI_SUCCESSS 0x0 44 | 45 | UInt32 getUnsignedIntFromArray(OSArray * array, UInt8 index); 46 | 47 | #define super IOService 48 | OSDefineMetaClassAndStructors(SMCMotionSensor, IOService) 49 | 50 | bool TOSMotionSensor::init(OSDictionary *dict) 51 | { 52 | DPRINT("Initializing\n"); 53 | 54 | bool result = super::init(dict); 55 | TVAP = NULL; 56 | hci_method = NULL; 57 | _axes = { 0, 0, 0 }; 58 | HCI_OUT = NULL; 59 | axes = NULL; 60 | 61 | for(UInt8 i = 0; i < 6; i++) { 62 | HCI_IN[i] = OSNumber::withNumber((unsigned long long)0, 32); 63 | } 64 | 65 | return result; 66 | } 67 | 68 | const OSSymbol * TOSMotionSensor::findHCI() { 69 | if(!TVAP->validateObject("SPFC")) { 70 | DPRINT("Found HCI method SPFC"); 71 | return OSSymbol::withCString("SPFC"); 72 | } 73 | 74 | if(!TVAP->validateObject("GHCI")) { 75 | DPRINT("Found HCI method GHCI"); 76 | return OSSymbol::withCString("GHCI"); 77 | } 78 | 79 | return NULL; 80 | } 81 | 82 | bool TOSMotionSensor::isAccelSupported() { 83 | HCI_IN[0] = OSDynamicCast(OSObject, OSNumber::withNumber(HCI_GET, 32)); 84 | HCI_IN[1] = OSDynamicCast(OSObject, OSNumber::withNumber(HCI_ACCEL_SUPPORT, 32)); 85 | 86 | TVAP->evaluateObject(hci_method, &HCI_OUT, HCI_IN, 6); 87 | 88 | if(HCI_OUT && (OSTypeIDInst(HCI_OUT) == OSTypeID(OSArray))) { 89 | if(getUnsignedIntFromArray(OSDynamicCast(OSArray, HCI_OUT), 0) != HCI_UNSUPPORTED) { 90 | DPRINT("Accelerometer supported"); 91 | return true; 92 | } 93 | } 94 | 95 | return false; 96 | } 97 | 98 | bool TOSMotionSensor::start(IOService *provider) 99 | { 100 | DPRINT("TOSMotionSensor::start: called\n"); 101 | 102 | TVAP = OSDynamicCast(IOACPIPlatformDevice, provider); 103 | if (NULL == TVAP || !super::start(provider)) 104 | return false; 105 | 106 | /* 107 | * Make sure the accelerometer is activated 108 | * Sidenote: Not sure if SSD only Toshiba machines have this device. If they do 109 | * not, how to make sure devices shipped with HDD have activated the sensor hub 110 | * before continuing? 111 | */ 112 | IOService *haps_service = waitForMatchingService(serviceMatching("ToshibaHAPS")); 113 | if(!haps_service->getProperty("ProtectionLevel")) { 114 | DPRINT("Accelerometer not activated"); 115 | haps_service->release(); 116 | return false; 117 | } 118 | haps_service->release(); 119 | 120 | hci_method = findHCI(); 121 | if(!hci_method) { 122 | DPRINT("Could not find HCI method"); 123 | return false; 124 | } 125 | 126 | if(!isAccelSupported()) { 127 | DPRINT("Accelerometer not supported"); 128 | return false; 129 | } 130 | 131 | //Setup for HCI method to get accelerometer values as default 132 | HCI_IN[1] = OSNumber::withNumber(HCI_ACCEL, 32); 133 | HCI_IN[3] = OSNumber::withNumber(0x01, 32); 134 | 135 | registerService(); 136 | return true; 137 | } 138 | 139 | //Should this be locking? Specifically access to _axes? 140 | IOReturn TOSMotionSensor::getAxes(void *iBuf, void *oBuf) { 141 | DPRINT("getAxes Called"); 142 | TVAP->evaluateObject(hci_method, &HCI_OUT, HCI_IN, 6); 143 | if(HCI_OUT && (OSTypeIDInst(HCI_OUT) == OSTypeID(OSArray))) { 144 | axes = OSDynamicCast(OSArray, HCI_OUT); 145 | if(getUnsignedIntFromArray(axes, 0) != (UInt32)HCI_SUCCESSS){ //One more check 146 | DPRINT("HCI method did not return with HCI_SUCCESS"); 147 | return kIOReturnError; 148 | } 149 | _axes.z = (SInt16)getUnsignedIntFromArray(axes, 4); 150 | _axes.z = _axes.z & HCI_ACCEL_DIRECTION_MASK ? 151 | -(_axes.z & HCI_ACCEL_MASK) : _axes.z & HCI_ACCEL_MASK; 152 | 153 | UInt32 xy = getUnsignedIntFromArray(axes, 2); 154 | _axes.x = xy & HCI_ACCEL_DIRECTION_MASK ? 155 | -(xy & HCI_ACCEL_MASK) : xy & HCI_ACCEL_MASK; 156 | 157 | _axes.y = (xy >> HCI_ACCEL_Y_SHIFT) & HCI_ACCEL_DIRECTION_MASK ? 158 | -((xy >> HCI_ACCEL_Y_SHIFT) & HCI_ACCEL_MASK) : 159 | (xy >> HCI_ACCEL_Y_SHIFT) & HCI_ACCEL_MASK; 160 | } 161 | 162 | if(!HCI_OUT) { 163 | DPRINT("HCI_OUT is NULL"); 164 | return kIOReturnError; 165 | } 166 | 167 | memcpy((char*)oBuf, &_axes, sizeof(struct s_axes)); 168 | return kIOReturnSuccess; 169 | } 170 | 171 | void TOSMotionSensor::stop(IOService *provider) 172 | { 173 | DPRINT("called\n"); 174 | super::stop(provider); 175 | } 176 | 177 | UInt32 getUnsignedIntFromArray(OSArray * array, UInt8 index) { 178 | OSObject * obj = array->getObject(index); 179 | if(obj && (OSTypeIDInst(obj) == OSTypeID(OSNumber))) { 180 | OSNumber * num = OSDynamicCast(OSNumber, obj); 181 | return num->unsigned32BitValue(); 182 | } 183 | 184 | return -1; 185 | } 186 | -------------------------------------------------------------------------------- /TOSMotionSensor/TOSMotionSensor.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 jslegendre / Xord. All rights reserved. 3 | * 4 | * Released under "The GNU General Public License (GPL-2.0)" 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | */ 21 | 22 | #ifndef TOSMotionSensor_hpp 23 | #define TOSMotionSensor_hpp 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define TOSMotionSensor SMCMotionSensor 30 | #define TOSMotionSensorClient SMCMotionSensorClient 31 | 32 | class TOSMotionSensor : public IOService 33 | { 34 | OSDeclareDefaultStructors(TOSMotionSensor); 35 | friend class TOSMotionSensorClient; 36 | 37 | public: 38 | virtual bool init(OSDictionary *dictionary = 0); 39 | virtual bool start(IOService *provider); 40 | virtual void stop(IOService *provider); 41 | 42 | const OSSymbol * findHCI(); 43 | bool isAccelSupported(); 44 | IOReturn getAxes(void *iBuf, void *oBuf); 45 | protected: 46 | struct s_axes { SInt16 x; SInt16 y; SInt16 z; }; 47 | private: 48 | IOACPIPlatformDevice* TVAP; 49 | 50 | OSObject* HCI_IN[6]; 51 | OSObject* HCI_OUT; 52 | OSArray* axes; 53 | const OSSymbol* hci_method; //HCI: Hardware Configuration Interface 54 | 55 | struct s_axes _axes; 56 | }; 57 | 58 | class TOSMotionSensorClient : public IOUserClient 59 | { 60 | OSDeclareDefaultStructors(SMCMotionSensorClient); 61 | public: 62 | virtual bool start(IOService* provider); 63 | virtual void stop(IOService* provider); 64 | virtual bool initWithTask(task_t owningTask, void *securityToken, UInt32 type, OSDictionary *properties); 65 | virtual IOReturn clientClose(); 66 | virtual IOExternalMethod * getTargetAndMethodForIndex(IOService **targetP, UInt32 index); 67 | protected: 68 | TOSMotionSensor* p_provider; 69 | task_t p_task; 70 | private: 71 | IOSimpleLock *axes_lock; 72 | 73 | }; 74 | 75 | static const IOExternalMethod external_methods[1] = 76 | { 77 | { 78 | NULL, 79 | (IOMethod)&TOSMotionSensor::getAxes, 80 | kIOUCStructIStructO, 81 | 40, 82 | 40 83 | } 84 | }; 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /TOSMotionSensor/TOSMotionSensorClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 jslegendre / Xord. All rights reserved. 3 | * 4 | * Released under "The GNU General Public License (GPL-2.0)" 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | */ 21 | 22 | #include "TOSMotionSensor.hpp" 23 | 24 | #ifdef DEBUG 25 | #define DPRINT(fmt, ...) \ 26 | IOLog("TOSMotionSensorClient::%s:%d(): " fmt, __func__, __LINE__, ##__VA_ARGS__); 27 | #else 28 | #define DPRINT(fmt, ...) do {} while (0) 29 | #endif 30 | 31 | #define super IOUserClient 32 | OSDefineMetaClassAndStructors(SMCMotionSensorClient, IOUserClient); 33 | 34 | bool TOSMotionSensorClient::initWithTask(task_t owningTask, void *securityToken, UInt32 type, OSDictionary *properties) { 35 | DPRINT("TOS1900 initwithtask"); 36 | 37 | if(!super::initWithTask(owningTask, securityToken, type)) { 38 | DPRINT("TOS1900: could not initWithTask"); 39 | return false; 40 | } 41 | 42 | p_task = owningTask; 43 | return true; 44 | } 45 | 46 | IOReturn TOSMotionSensorClient::clientClose() { 47 | p_task = NULL; 48 | p_provider = NULL; 49 | 50 | if(terminate()) 51 | return kIOReturnSuccess; 52 | 53 | return kIOReturnError; 54 | } 55 | 56 | IOExternalMethod * TOSMotionSensorClient::getTargetAndMethodForIndex(IOService **targetP, UInt32 index) { 57 | DPRINT("called"); 58 | *targetP = p_provider; 59 | 60 | if(index == 5) //Index 5 is the orginal SMCMotionSensor selector to get accelerometer data 61 | index = 0; 62 | 63 | return (IOExternalMethod*)&external_methods[index]; 64 | } 65 | 66 | bool TOSMotionSensorClient::start(IOService* provider) { 67 | DPRINT("called"); 68 | if (!super::start(provider)) 69 | return false; 70 | 71 | p_provider = OSDynamicCast(TOSMotionSensor, provider); 72 | registerService(); 73 | return true; 74 | } 75 | 76 | void TOSMotionSensorClient::stop(IOService* provider) { 77 | DPRINT("called"); 78 | super::stop(provider); 79 | } 80 | -------------------------------------------------------------------------------- /TOSMotionSensor/ToshibaHAPS.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 jslegendre / Xord. All rights reserved. 3 | * 4 | * Released under "The GNU General Public License (GPL-2.0)" 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | */ 21 | 22 | #include "ToshibaHAPS.hpp" 23 | 24 | #ifdef DEBUG 25 | #define DPRINT(fmt, ...) \ 26 | IOLog("ToshibaHAPS::%s:%d(): " fmt, __func__, __LINE__, ##__VA_ARGS__); 27 | #else 28 | #define DPRINT(fmt, ...) do {} while (0) 29 | #endif 30 | 31 | #define super IOService 32 | OSDefineMetaClassAndStructors(ToshibaHAPS, IOService); 33 | 34 | IOReturn ToshibaHAPS::resetHaps() { 35 | UInt32 dummy; //Throwaway - Avoid NULL (de)referencing 36 | 37 | //ACPI method 'RSSS' does not return anything 38 | return haps->evaluateInteger(RSSS, &dummy); 39 | } 40 | 41 | IOReturn ToshibaHAPS::setCurrentPTLV(UInt32 level) { 42 | DPRINT("Setting protection level: %d", level); 43 | IOReturn ret = kIOReturnSuccess; 44 | 45 | /* Some models that ship with built in SSD have a HAPS device 46 | with no methods other than _STA (which unconditionally 47 | returns zero). In this case we set IORegistry protection level 48 | entry to 2 (default) return success, and move on. */ 49 | ret = haps->validateObject(PTLV); 50 | if(ret != kIOReturnSuccess) { 51 | setProperty(ptlv_io_reg_property, OSNumber::withNumber(2, 32)); 52 | return kIOReturnSuccess; 53 | } 54 | 55 | UInt32 dummy; 56 | OSObject* ptlv = OSDynamicCast(OSObject, OSNumber::withNumber(level, 32)); 57 | 58 | //ACPI method 'PTLV' does not return anything 59 | ret = haps->evaluateInteger(PTLV, &dummy, &ptlv, 1); 60 | if(ret == kIOReturnSuccess) { 61 | DPRINT("Setting protection level successful"); 62 | setProperty(ptlv_io_reg_property, ptlv); 63 | } else { 64 | DPRINT("Setting protection level failed with error: %d", ret); 65 | return ret; 66 | } 67 | 68 | ret = resetHaps(); 69 | if (ret != kIOReturnSuccess) { 70 | DPRINT("Could not activate HAPS device"); 71 | } 72 | return ret; 73 | } 74 | 75 | bool ToshibaHAPS::init(OSDictionary* properties) { 76 | DPRINT("ToshibaHAPS init"); 77 | 78 | if (!super::init(properties)) 79 | return false; 80 | 81 | haps = NULL; 82 | ptlv_io_reg_property = "ProtectionLevel"; 83 | 84 | RSSS = OSSymbol::withCStringNoCopy("RSSS"); 85 | PTLV = OSSymbol::withCStringNoCopy("PTLV"); 86 | 87 | setProperty(ptlv_io_reg_property, (UInt32)0); 88 | return true; 89 | } 90 | 91 | void ToshibaHAPS::free() { 92 | super::free(); 93 | } 94 | 95 | bool ToshibaHAPS::start(IOService* provider) { 96 | DPRINT("ToshibaHAPS starting"); 97 | haps = OSDynamicCast(IOACPIPlatformDevice, provider); 98 | 99 | if (!super::start(provider)) 100 | return false; 101 | 102 | //PT_LEVEL_MED: Enables accelerometers, no shock protection 103 | if(setCurrentPTLV(PT_LEVEL_MED) != kIOReturnSuccess) 104 | return false; 105 | 106 | this->registerService(); 107 | return true; 108 | } 109 | 110 | void ToshibaHAPS::stop(IOService* provider) { 111 | super::stop(provider); 112 | } 113 | -------------------------------------------------------------------------------- /TOSMotionSensor/ToshibaHAPS.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 jslegendre / Xord. All rights reserved. 3 | * 4 | * Released under "The GNU General Public License (GPL-2.0)" 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the 8 | * Free Software Foundation; either version 2 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | */ 21 | 22 | #ifndef ToshibaHAPS_hpp 23 | #define ToshibaHAPS_hpp 24 | 25 | #include 26 | #include 27 | 28 | //Various HD protection levels 29 | enum PT_LEVELS { 30 | PT_LEVEL_NONE, // Off 31 | PT_LEVEL_LOW, 32 | PT_LEVEL_MED, 33 | PT_LEVEL_HIGH // Do not use! Causes KP 34 | }; 35 | 36 | class ToshibaHAPS : public IOService { 37 | OSDeclareDefaultStructors(ToshibaHAPS); 38 | public: 39 | bool init(OSDictionary* properties); 40 | void free(); 41 | bool start(IOService* provider); 42 | void stop(IOService* provider); 43 | 44 | IOReturn resetHaps(); 45 | IOReturn setCurrentPTLV(UInt32 level); 46 | OSObject* getCurrentPTLV(); 47 | 48 | protected: 49 | private: 50 | IOACPIPlatformDevice* haps; 51 | const char* ptlv_io_reg_property; 52 | const OSSymbol* RSSS; // Reset - ACPI Method 53 | const OSSymbol* PTLV; // Protection Level - ACPI Method 54 | }; 55 | 56 | 57 | #endif /* ToshibaHAPS_hpp */ 58 | -------------------------------------------------------------------------------- /Test/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jslegendre/TOSMotionSensor/20cc1d4f2cae1d0ee0114389902779c8865c931b/Test/test -------------------------------------------------------------------------------- /Test/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Bare minimum setup to poll SMCMotionSensor service 3 | * Build: 4 | * gcc -framework CoreFoundation -framework IOKit test.c -o test 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | typedef struct { 12 | short x; 13 | short y; 14 | short z; 15 | } axes; 16 | 17 | int main(int argc, const char * argv[]) { 18 | CFMutableDictionaryRef dict = IOServiceMatching("SMCMotionSensor"); 19 | if(!dict) { 20 | printf("Could not find service\n"); 21 | return 1; 22 | } 23 | 24 | kern_return_t result; 25 | io_connect_t connection; 26 | io_service_t device = 0; 27 | 28 | device = IOServiceGetMatchingService(kIOMasterPortDefault, dict); 29 | if(!device) { 30 | printf("No device\n"); 31 | return 1; 32 | } 33 | 34 | 35 | if(IOServiceOpen(device, mach_task_self(), 0, &connection) != KERN_SUCCESS) { 36 | printf("Could not open device\n"); 37 | return 1; 38 | } 39 | 40 | size_t smc_arg_size = 40; 41 | axes *out_struct = NULL; 42 | 43 | void* smc_in = malloc(smc_arg_size); 44 | memset(smc_in, 1, smc_arg_size); 45 | 46 | void* smc_out = malloc(smc_arg_size); 47 | memset(smc_out, 0, smc_arg_size); 48 | 49 | result = IOConnectCallStructMethod(connection, 50 | 5, 51 | smc_in, 52 | 40, 53 | smc_out, 54 | &smc_arg_size); 55 | if(result != KERN_SUCCESS) { 56 | printf("Could not call struct method\n"); 57 | goto end; 58 | } 59 | 60 | out_struct = (axes*)smc_out; 61 | printf("Success\nAccelerometer reading: { x: %d, y: %d, z: %d }\n", out_struct->x, out_struct->y, out_struct->z); 62 | 63 | end: 64 | free(smc_in); 65 | free(smc_out); 66 | 67 | if(result != KERN_SUCCESS) 68 | return 1; 69 | 70 | return 0; 71 | } 72 | 73 | --------------------------------------------------------------------------------