Commit 80d9c5eecf199f38c9ef754d215d8e4167a79f8e
0 parents
Initial import
Showing
11 changed files
with
1253 additions
and
0 deletions
AUTHORS
0 → 100644
COPYING
0 → 100644
| 1 | +++ a/COPYING | ||
| 1 | + GNU GENERAL PUBLIC LICENSE | ||
| 2 | + Version 2, June 1991 | ||
| 3 | + | ||
| 4 | + Copyright (C) 1989, 1991 Free Software Foundation, Inc. | ||
| 5 | + 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 Library 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 | + <one line to give the program's name and a brief idea of what it does.> | ||
| 294 | + Copyright (C) <year> <name of author> | ||
| 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 | ||
| 307 | + along with this program; if not, write to the Free Software | ||
| 308 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 309 | + | ||
| 310 | + | ||
| 311 | +Also add information on how to contact you by electronic and paper mail. | ||
| 312 | + | ||
| 313 | +If the program is interactive, make it output a short notice like this | ||
| 314 | +when it starts in an interactive mode: | ||
| 315 | + | ||
| 316 | + Gnomovision version 69, Copyright (C) year name of author | ||
| 317 | + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | ||
| 318 | + This is free software, and you are welcome to redistribute it | ||
| 319 | + under certain conditions; type `show c' for details. | ||
| 320 | + | ||
| 321 | +The hypothetical commands `show w' and `show c' should show the appropriate | ||
| 322 | +parts of the General Public License. Of course, the commands you use may | ||
| 323 | +be called something other than `show w' and `show c'; they could even be | ||
| 324 | +mouse-clicks or menu items--whatever suits your program. | ||
| 325 | + | ||
| 326 | +You should also get your employer (if you work as a programmer) or your | ||
| 327 | +school, if any, to sign a "copyright disclaimer" for the program, if | ||
| 328 | +necessary. Here is a sample; alter the names: | ||
| 329 | + | ||
| 330 | + Yoyodyne, Inc., hereby disclaims all copyright interest in the program | ||
| 331 | + `Gnomovision' (which makes passes at compilers) written by James Hacker. | ||
| 332 | + | ||
| 333 | + <signature of Ty Coon>, 1 April 1989 | ||
| 334 | + Ty Coon, President of Vice | ||
| 335 | + | ||
| 336 | +This General Public License does not permit incorporating your program into | ||
| 337 | +proprietary programs. If your program is a subroutine library, you may | ||
| 338 | +consider it more useful to permit linking proprietary applications with the | ||
| 339 | +library. If this is what you want to do, use the GNU Library General | ||
| 340 | +Public License instead of this License. |
INSTALL
0 → 100644
| 1 | +++ a/INSTALL | ||
| 1 | +Installation: | ||
| 2 | + | ||
| 3 | +pts: | ||
| 4 | + make -To compile | ||
| 5 | + ./tty0tty -To run | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +module: | ||
| 9 | + make -To compile | ||
| 10 | + insmod tty0tty.ko -To load module (using root or sudo) | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +this version is not installable | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +Requirements: | ||
| 17 | + | ||
| 18 | + for module build is necessary kernel-headers or kernel source | ||
| 19 | + ( in debian use apt-get install linux-image-2.6.26-2-amd64 for example) |
README
0 → 100644
| 1 | +++ a/README | ||
| 1 | +tty0tty - linux null modem emulator | ||
| 2 | +Forked to instance on github since original project is dead. | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +This is the tty0tty directory tree: | ||
| 6 | + | ||
| 7 | + module - linux kernel module null-modem | ||
| 8 | + pts - null-modem using ptys (without handshake lines) | ||
| 9 | + | ||
| 10 | + | ||
| 11 | +pts: | ||
| 12 | + | ||
| 13 | + When run connect two pseudo-ttys and show the connection names: | ||
| 14 | + | ||
| 15 | + (/dev/pts/1) <=> (/dev/pts/2) | ||
| 16 | + | ||
| 17 | + the connection is: | ||
| 18 | + | ||
| 19 | + TX -> RX | ||
| 20 | + RX <- TX | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +module: | ||
| 25 | + | ||
| 26 | + The module is tested in kernel 2.6.26-2 (debian) and kernel 2.6.30 | ||
| 27 | + | ||
| 28 | + When loaded, create 8 ttys interconnected: | ||
| 29 | + /dev/tnt0 <=> /dev/tnt1 | ||
| 30 | + /dev/tnt2 <=> /dev/tnt3 | ||
| 31 | + /dev/tnt4 <=> /dev/tnt5 | ||
| 32 | + /dev/tnt6 <=> /dev/tnt7 | ||
| 33 | + | ||
| 34 | + the connection is: | ||
| 35 | + | ||
| 36 | + TX -> RX | ||
| 37 | + RX <- TX | ||
| 38 | + RTS -> CTS | ||
| 39 | + CTS <- RTS | ||
| 40 | + DSR <- DTR | ||
| 41 | + CD <- DTR | ||
| 42 | + DTR -> DSR | ||
| 43 | + DTR -> CD | ||
| 44 | + | ||
| 45 | + | ||
| 46 | +Requirements: | ||
| 47 | + | ||
| 48 | + for module build is necessary kernel-headers or kernel source | ||
| 49 | + ( in debian use apt-get install linux-image-2.6.26-2-amd64 for example) | ||
| 50 | + | ||
| 51 | + |
THANKS
0 → 100644
TODO
0 → 100644
| 1 | +++ a/TODO |
VERSION
0 → 100644
module/Makefile
0 → 100644
| 1 | +++ a/module/Makefile | ||
| 1 | +# Comment/uncomment the following line to disable/enable debugging | ||
| 2 | +#DEBUG = y | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +# Add your debugging flag (or not) to CFLAGS | ||
| 6 | +ifeq ($(DEBUG),y) | ||
| 7 | + DEBFLAGS = -O -g -DSCULL_DEBUG # "-O" is needed to expand inlines | ||
| 8 | +else | ||
| 9 | + DEBFLAGS = -O2 | ||
| 10 | +endif | ||
| 11 | + | ||
| 12 | +EXTRA_CFLAGS += $(DEBFLAGS) -I.. | ||
| 13 | + | ||
| 14 | +ifneq ($(KERNELRELEASE),) | ||
| 15 | +# call from kernel build system | ||
| 16 | + | ||
| 17 | +#obj-m := tiny_tty.o tiny_serial.o tty0tty.o | ||
| 18 | +obj-m := tty0tty.o | ||
| 19 | + | ||
| 20 | +else | ||
| 21 | + | ||
| 22 | +KERNELDIR ?= /lib/modules/$(shell uname -r)/build | ||
| 23 | +PWD := $(shell pwd) | ||
| 24 | + | ||
| 25 | +default: | ||
| 26 | + $(MAKE) -C $(KERNELDIR) M=$(PWD) modules | ||
| 27 | + | ||
| 28 | +endif | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + | ||
| 32 | +clean: | ||
| 33 | + rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions modules.order Module.symvers | ||
| 34 | + | ||
| 35 | +depend .depend dep: | ||
| 36 | + $(CC) $(CFLAGS) -M *.c > .depend | ||
| 37 | + | ||
| 38 | + | ||
| 39 | +ifeq (.depend,$(wildcard .depend)) | ||
| 40 | +include .depend | ||
| 41 | +endif |
module/tty0tty.c
0 → 100644
| 1 | +++ a/module/tty0tty.c | ||
| 1 | +/* ######################################################################## | ||
| 2 | + | ||
| 3 | + tty0tty - linux null modem emulator (module) | ||
| 4 | + | ||
| 5 | + ######################################################################## | ||
| 6 | + | ||
| 7 | + Copyright (c) : 2010 Luis Claudio Gambôa Lopes | ||
| 8 | + | ||
| 9 | + Based in Tiny TTY driver - Copyright (C) 2002-2004 Greg Kroah-Hartman (greg@kroah.com) | ||
| 10 | + | ||
| 11 | + This program is free software; you can redistribute it and/or modify | ||
| 12 | + it under the terms of the GNU General Public License as published by | ||
| 13 | + the Free Software Foundation; either version 2, or (at your option) | ||
| 14 | + any later version. | ||
| 15 | + | ||
| 16 | + This program is distributed in the hope that it will be useful, | ||
| 17 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | + GNU General Public License for more details. | ||
| 20 | + | ||
| 21 | + You should have received a copy of the GNU General Public License | ||
| 22 | + along with this program; if not, write to the Free Software | ||
| 23 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 24 | + | ||
| 25 | + For e-mail suggestions : lcgamboa@yahoo.com | ||
| 26 | + ######################################################################## */ | ||
| 27 | + | ||
| 28 | +#include <linux/kernel.h> | ||
| 29 | +#include <linux/errno.h> | ||
| 30 | +#include <linux/init.h> | ||
| 31 | +#include <linux/module.h> | ||
| 32 | +#include <linux/slab.h> | ||
| 33 | +#include <linux/wait.h> | ||
| 34 | +#include <linux/tty.h> | ||
| 35 | +#include <linux/tty_driver.h> | ||
| 36 | +#include <linux/tty_flip.h> | ||
| 37 | +#include <linux/serial.h> | ||
| 38 | +#include <linux/sched.h> | ||
| 39 | +#include <asm/uaccess.h> | ||
| 40 | + | ||
| 41 | + | ||
| 42 | +#define DRIVER_VERSION "v1.0" | ||
| 43 | +#define DRIVER_AUTHOR "Luis Claudio Gamboa Lopes <lcgamboa@yahoo.com>" | ||
| 44 | +#define DRIVER_DESC "tty0tty null modem driver" | ||
| 45 | + | ||
| 46 | +/* Module information */ | ||
| 47 | +MODULE_AUTHOR( DRIVER_AUTHOR ); | ||
| 48 | +MODULE_DESCRIPTION( DRIVER_DESC ); | ||
| 49 | +MODULE_LICENSE("GPL"); | ||
| 50 | + | ||
| 51 | + | ||
| 52 | +#define TINY_TTY_MAJOR 240 /* experimental range */ | ||
| 53 | +#define TINY_TTY_MINORS 8 /* device number, always even*/ | ||
| 54 | + | ||
| 55 | +/* fake UART values */ | ||
| 56 | +//out | ||
| 57 | +#define MCR_DTR 0x01 | ||
| 58 | +#define MCR_RTS 0x02 | ||
| 59 | +#define MCR_LOOP 0x04 | ||
| 60 | +//in | ||
| 61 | +#define MSR_CTS 0x10 | ||
| 62 | +#define MSR_CD 0x20 | ||
| 63 | +#define MSR_DSR 0x40 | ||
| 64 | +#define MSR_RI 0x80 | ||
| 65 | + | ||
| 66 | +struct tty0tty_serial { | ||
| 67 | + struct tty_struct *tty; /* pointer to the tty for this device */ | ||
| 68 | + int open_count; /* number of times this port has been opened */ | ||
| 69 | + struct semaphore sem; /* locks this structure */ | ||
| 70 | + | ||
| 71 | + /* for tiocmget and tiocmset functions */ | ||
| 72 | + int msr; /* MSR shadow */ | ||
| 73 | + int mcr; /* MCR shadow */ | ||
| 74 | + | ||
| 75 | + /* for ioctl fun */ | ||
| 76 | + struct serial_struct serial; | ||
| 77 | + wait_queue_head_t wait; | ||
| 78 | + struct async_icount icount; | ||
| 79 | +}; | ||
| 80 | + | ||
| 81 | +static struct tty0tty_serial *tty0tty_table[TINY_TTY_MINORS]; /* initially all NULL */ | ||
| 82 | + | ||
| 83 | + | ||
| 84 | +static int tty0tty_open(struct tty_struct *tty, struct file *file) | ||
| 85 | +{ | ||
| 86 | + struct tty0tty_serial *tty0tty; | ||
| 87 | + int index; | ||
| 88 | + int msr=0; | ||
| 89 | + int mcr=0; | ||
| 90 | + | ||
| 91 | +#ifdef SCULL_DEBUG | ||
| 92 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | ||
| 93 | +#endif | ||
| 94 | + /* initialize the pointer in case something fails */ | ||
| 95 | + tty->driver_data = NULL; | ||
| 96 | + | ||
| 97 | + /* get the serial object associated with this tty pointer */ | ||
| 98 | + index = tty->index; | ||
| 99 | + tty0tty = tty0tty_table[index]; | ||
| 100 | + if (tty0tty == NULL) { | ||
| 101 | + /* first time accessing this device, let's create it */ | ||
| 102 | + tty0tty = kmalloc(sizeof(*tty0tty), GFP_KERNEL); | ||
| 103 | + if (!tty0tty) | ||
| 104 | + return -ENOMEM; | ||
| 105 | + | ||
| 106 | + init_MUTEX(&tty0tty->sem); | ||
| 107 | + tty0tty->open_count = 0; | ||
| 108 | + | ||
| 109 | + tty0tty_table[index] = tty0tty; | ||
| 110 | + | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + if( (index % 2) == 0) | ||
| 114 | + { | ||
| 115 | + if(tty0tty_table[index+1] != NULL) | ||
| 116 | + if (tty0tty_table[index+1]->open_count > 0) | ||
| 117 | + mcr=tty0tty_table[index+1]->mcr; | ||
| 118 | + } | ||
| 119 | + else | ||
| 120 | + { | ||
| 121 | + if(tty0tty_table[index-1] != NULL) | ||
| 122 | + if (tty0tty_table[index-1]->open_count > 0) | ||
| 123 | + mcr=tty0tty_table[index-1]->mcr; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | +//null modem connection | ||
| 127 | + | ||
| 128 | + if( (mcr & MCR_RTS) == MCR_RTS ) | ||
| 129 | + { | ||
| 130 | + msr |= MSR_CTS; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + if( (mcr & MCR_DTR) == MCR_DTR ) | ||
| 134 | + { | ||
| 135 | + msr |= MSR_DSR; | ||
| 136 | + msr |= MSR_CD; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + tty0tty->msr = msr; | ||
| 140 | + | ||
| 141 | + down(&tty0tty->sem); | ||
| 142 | + | ||
| 143 | + /* save our structure within the tty structure */ | ||
| 144 | + tty->driver_data = tty0tty; | ||
| 145 | + tty0tty->tty = tty; | ||
| 146 | + | ||
| 147 | + ++tty0tty->open_count; | ||
| 148 | + | ||
| 149 | + up(&tty0tty->sem); | ||
| 150 | + return 0; | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +static void do_close(struct tty0tty_serial *tty0tty) | ||
| 154 | +{ | ||
| 155 | + down(&tty0tty->sem); | ||
| 156 | +#ifdef SCULL_DEBUG | ||
| 157 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | ||
| 158 | +#endif | ||
| 159 | + if (!tty0tty->open_count) { | ||
| 160 | + /* port was never opened */ | ||
| 161 | + goto exit; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + --tty0tty->open_count; | ||
| 165 | +exit: | ||
| 166 | + up(&tty0tty->sem); | ||
| 167 | + | ||
| 168 | + return; | ||
| 169 | +} | ||
| 170 | + | ||
| 171 | +static void tty0tty_close(struct tty_struct *tty, struct file *file) | ||
| 172 | +{ | ||
| 173 | + struct tty0tty_serial *tty0tty = tty->driver_data; | ||
| 174 | + | ||
| 175 | +#ifdef SCULL_DEBUG | ||
| 176 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | ||
| 177 | +#endif | ||
| 178 | + if (tty0tty) | ||
| 179 | + do_close(tty0tty); | ||
| 180 | +} | ||
| 181 | + | ||
| 182 | +static int tty0tty_write(struct tty_struct *tty, const unsigned char *buffer, int count) | ||
| 183 | +{ | ||
| 184 | + struct tty0tty_serial *tty0tty = tty->driver_data; | ||
| 185 | + int retval = -EINVAL; | ||
| 186 | + struct tty_struct *ttyx = NULL; | ||
| 187 | + | ||
| 188 | + if (!tty0tty) | ||
| 189 | + return -ENODEV; | ||
| 190 | + | ||
| 191 | + down(&tty0tty->sem); | ||
| 192 | + | ||
| 193 | + if (!tty0tty->open_count) | ||
| 194 | + /* port was not opened */ | ||
| 195 | + goto exit; | ||
| 196 | + | ||
| 197 | + if( (tty0tty->tty->index % 2) == 0) | ||
| 198 | + { | ||
| 199 | + if(tty0tty_table[tty0tty->tty->index+1] != NULL) | ||
| 200 | + if (tty0tty_table[tty0tty->tty->index+1]->open_count > 0) | ||
| 201 | + ttyx=tty0tty_table[tty0tty->tty->index+1]->tty; | ||
| 202 | + } | ||
| 203 | + else | ||
| 204 | + { | ||
| 205 | + if(tty0tty_table[tty0tty->tty->index-1] != NULL) | ||
| 206 | + if (tty0tty_table[tty0tty->tty->index-1]->open_count > 0) | ||
| 207 | + ttyx=tty0tty_table[tty0tty->tty->index-1]->tty; | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | +// tty->low_latency=1; | ||
| 211 | + | ||
| 212 | + if(ttyx != NULL) | ||
| 213 | + { | ||
| 214 | + tty_insert_flip_string(ttyx, buffer, count); | ||
| 215 | + tty_flip_buffer_push(ttyx); | ||
| 216 | + retval=count; | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | +exit: | ||
| 220 | + up(&tty0tty->sem); | ||
| 221 | + return retval; | ||
| 222 | +} | ||
| 223 | + | ||
| 224 | +static int tty0tty_write_room(struct tty_struct *tty) | ||
| 225 | +{ | ||
| 226 | + struct tty0tty_serial *tty0tty = tty->driver_data; | ||
| 227 | + int room = -EINVAL; | ||
| 228 | + | ||
| 229 | + if (!tty0tty) | ||
| 230 | + return -ENODEV; | ||
| 231 | + | ||
| 232 | + down(&tty0tty->sem); | ||
| 233 | + | ||
| 234 | + if (!tty0tty->open_count) { | ||
| 235 | + /* port was not opened */ | ||
| 236 | + goto exit; | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + /* calculate how much room is left in the device */ | ||
| 240 | + room = 255; | ||
| 241 | + | ||
| 242 | +exit: | ||
| 243 | + up(&tty0tty->sem); | ||
| 244 | + return room; | ||
| 245 | +} | ||
| 246 | + | ||
| 247 | +#define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) | ||
| 248 | + | ||
| 249 | +static void tty0tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios) | ||
| 250 | +{ | ||
| 251 | + unsigned int cflag; | ||
| 252 | + | ||
| 253 | +#ifdef SCULL_DEBUG | ||
| 254 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | ||
| 255 | +#endif | ||
| 256 | + cflag = tty->termios->c_cflag; | ||
| 257 | + | ||
| 258 | + /* check that they really want us to change something */ | ||
| 259 | + if (old_termios) { | ||
| 260 | + if ((cflag == old_termios->c_cflag) && | ||
| 261 | + (RELEVANT_IFLAG(tty->termios->c_iflag) == | ||
| 262 | + RELEVANT_IFLAG(old_termios->c_iflag))) { | ||
| 263 | +#ifdef SCULL_DEBUG | ||
| 264 | + printk(KERN_DEBUG " - nothing to change...\n"); | ||
| 265 | +#endif | ||
| 266 | + return; | ||
| 267 | + } | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | +#ifdef SCULL_DEBUG | ||
| 271 | + /* get the byte size */ | ||
| 272 | + switch (cflag & CSIZE) { | ||
| 273 | + case CS5: | ||
| 274 | + printk(KERN_DEBUG " - data bits = 5\n"); | ||
| 275 | + break; | ||
| 276 | + case CS6: | ||
| 277 | + printk(KERN_DEBUG " - data bits = 6\n"); | ||
| 278 | + break; | ||
| 279 | + case CS7: | ||
| 280 | + printk(KERN_DEBUG " - data bits = 7\n"); | ||
| 281 | + break; | ||
| 282 | + default: | ||
| 283 | + case CS8: | ||
| 284 | + printk(KERN_DEBUG " - data bits = 8\n"); | ||
| 285 | + break; | ||
| 286 | + } | ||
| 287 | + | ||
| 288 | + /* determine the parity */ | ||
| 289 | + if (cflag & PARENB) | ||
| 290 | + if (cflag & PARODD) | ||
| 291 | + printk(KERN_DEBUG " - parity = odd\n"); | ||
| 292 | + else | ||
| 293 | + printk(KERN_DEBUG " - parity = even\n"); | ||
| 294 | + else | ||
| 295 | + printk(KERN_DEBUG " - parity = none\n"); | ||
| 296 | + | ||
| 297 | + /* figure out the stop bits requested */ | ||
| 298 | + if (cflag & CSTOPB) | ||
| 299 | + printk(KERN_DEBUG " - stop bits = 2\n"); | ||
| 300 | + else | ||
| 301 | + printk(KERN_DEBUG " - stop bits = 1\n"); | ||
| 302 | + | ||
| 303 | + /* figure out the hardware flow control settings */ | ||
| 304 | + if (cflag & CRTSCTS) | ||
| 305 | + printk(KERN_DEBUG " - RTS/CTS is enabled\n"); | ||
| 306 | + else | ||
| 307 | + printk(KERN_DEBUG " - RTS/CTS is disabled\n"); | ||
| 308 | + | ||
| 309 | + /* determine software flow control */ | ||
| 310 | + /* if we are implementing XON/XOFF, set the start and | ||
| 311 | + * stop character in the device */ | ||
| 312 | + if (I_IXOFF(tty) || I_IXON(tty)) { | ||
| 313 | + unsigned char stop_char = STOP_CHAR(tty); | ||
| 314 | + unsigned char start_char = START_CHAR(tty); | ||
| 315 | + | ||
| 316 | + /* if we are implementing INBOUND XON/XOFF */ | ||
| 317 | + if (I_IXOFF(tty)) | ||
| 318 | + printk(KERN_DEBUG " - INBOUND XON/XOFF is enabled, " | ||
| 319 | + "XON = %2x, XOFF = %2x\n", start_char, stop_char); | ||
| 320 | + else | ||
| 321 | + printk(KERN_DEBUG" - INBOUND XON/XOFF is disabled\n"); | ||
| 322 | + | ||
| 323 | + /* if we are implementing OUTBOUND XON/XOFF */ | ||
| 324 | + if (I_IXON(tty)) | ||
| 325 | + printk(KERN_DEBUG" - OUTBOUND XON/XOFF is enabled, " | ||
| 326 | + "XON = %2x, XOFF = %2x\n", start_char, stop_char); | ||
| 327 | + else | ||
| 328 | + printk(KERN_DEBUG" - OUTBOUND XON/XOFF is disabled\n"); | ||
| 329 | + } | ||
| 330 | + | ||
| 331 | + /* get the baud rate wanted */ | ||
| 332 | + printk(KERN_DEBUG " - baud rate = %d\n", tty_get_baud_rate(tty)); | ||
| 333 | +#endif | ||
| 334 | +} | ||
| 335 | + | ||
| 336 | + | ||
| 337 | +static int tty0tty_tiocmget(struct tty_struct *tty, struct file *file) | ||
| 338 | +{ | ||
| 339 | + struct tty0tty_serial *tty0tty = tty->driver_data; | ||
| 340 | + | ||
| 341 | + unsigned int result = 0; | ||
| 342 | + unsigned int msr = tty0tty->msr; | ||
| 343 | + unsigned int mcr = tty0tty->mcr; | ||
| 344 | + | ||
| 345 | + | ||
| 346 | + result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) | /* DTR is set */ | ||
| 347 | + ((mcr & MCR_RTS) ? TIOCM_RTS : 0) | /* RTS is set */ | ||
| 348 | + ((mcr & MCR_LOOP) ? TIOCM_LOOP : 0) | /* LOOP is set */ | ||
| 349 | + ((msr & MSR_CTS) ? TIOCM_CTS : 0) | /* CTS is set */ | ||
| 350 | + ((msr & MSR_CD) ? TIOCM_CAR : 0) | /* Carrier detect is set*/ | ||
| 351 | + ((msr & MSR_RI) ? TIOCM_RI : 0) | /* Ring Indicator is set */ | ||
| 352 | + ((msr & MSR_DSR) ? TIOCM_DSR : 0); /* DSR is set */ | ||
| 353 | + | ||
| 354 | + return result; | ||
| 355 | +} | ||
| 356 | + | ||
| 357 | +static int tty0tty_tiocmset(struct tty_struct *tty, struct file *file, | ||
| 358 | + unsigned int set, unsigned int clear) | ||
| 359 | +{ | ||
| 360 | + struct tty0tty_serial *tty0tty = tty->driver_data; | ||
| 361 | + unsigned int mcr = tty0tty->mcr; | ||
| 362 | + unsigned int msr=0; | ||
| 363 | + | ||
| 364 | +#ifdef SCULL_DEBUG | ||
| 365 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | ||
| 366 | +#endif | ||
| 367 | + | ||
| 368 | + if( (tty0tty->tty->index % 2) == 0) | ||
| 369 | + { | ||
| 370 | + if(tty0tty_table[tty0tty->tty->index+1] != NULL) | ||
| 371 | + if (tty0tty_table[tty0tty->tty->index+1]->open_count > 0) | ||
| 372 | + msr=tty0tty_table[tty0tty->tty->index+1]->msr; | ||
| 373 | + } | ||
| 374 | + else | ||
| 375 | + { | ||
| 376 | + if(tty0tty_table[tty0tty->tty->index-1] != NULL) | ||
| 377 | + if (tty0tty_table[tty0tty->tty->index-1]->open_count > 0) | ||
| 378 | + msr=tty0tty_table[tty0tty->tty->index-1]->msr; | ||
| 379 | + } | ||
| 380 | + | ||
| 381 | +//null modem connection | ||
| 382 | + | ||
| 383 | + if (set & TIOCM_RTS) | ||
| 384 | + { | ||
| 385 | + mcr |= MCR_RTS; | ||
| 386 | + msr |= MSR_CTS; | ||
| 387 | + } | ||
| 388 | + | ||
| 389 | + if (set & TIOCM_DTR) | ||
| 390 | + { | ||
| 391 | + mcr |= MCR_DTR; | ||
| 392 | + msr |= MSR_DSR; | ||
| 393 | + msr |= MSR_CD; | ||
| 394 | + } | ||
| 395 | + | ||
| 396 | + if (clear & TIOCM_RTS) | ||
| 397 | + { | ||
| 398 | + mcr &= ~MCR_RTS; | ||
| 399 | + msr &= ~MSR_CTS; | ||
| 400 | + } | ||
| 401 | + | ||
| 402 | + if (clear & TIOCM_DTR) | ||
| 403 | + { | ||
| 404 | + mcr &= ~MCR_DTR; | ||
| 405 | + msr &= ~MSR_DSR; | ||
| 406 | + msr &= ~MSR_CD; | ||
| 407 | + } | ||
| 408 | + | ||
| 409 | + | ||
| 410 | + /* set the new MCR value in the device */ | ||
| 411 | + tty0tty->mcr = mcr; | ||
| 412 | + | ||
| 413 | + if( (tty0tty->tty->index % 2) == 0) | ||
| 414 | + { | ||
| 415 | + if(tty0tty_table[tty0tty->tty->index+1] != NULL) | ||
| 416 | + if (tty0tty_table[tty0tty->tty->index+1]->open_count > 0) | ||
| 417 | + tty0tty_table[tty0tty->tty->index+1]->msr=msr; | ||
| 418 | + } | ||
| 419 | + else | ||
| 420 | + { | ||
| 421 | + if(tty0tty_table[tty0tty->tty->index-1] != NULL) | ||
| 422 | + if (tty0tty_table[tty0tty->tty->index-1]->open_count > 0) | ||
| 423 | + tty0tty_table[tty0tty->tty->index-1]->msr=msr; | ||
| 424 | + } | ||
| 425 | + return 0; | ||
| 426 | +} | ||
| 427 | + | ||
| 428 | + | ||
| 429 | +static int tty0tty_ioctl_tiocgserial(struct tty_struct *tty, struct file *file, | ||
| 430 | + unsigned int cmd, unsigned long arg) | ||
| 431 | +{ | ||
| 432 | + struct tty0tty_serial *tty0tty = tty->driver_data; | ||
| 433 | + | ||
| 434 | +#ifdef SCULL_DEBUG | ||
| 435 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | ||
| 436 | +#endif | ||
| 437 | + if (cmd == TIOCGSERIAL) { | ||
| 438 | + struct serial_struct tmp; | ||
| 439 | + | ||
| 440 | + if (!arg) | ||
| 441 | + return -EFAULT; | ||
| 442 | + | ||
| 443 | + memset(&tmp, 0, sizeof(tmp)); | ||
| 444 | + | ||
| 445 | + tmp.type = tty0tty->serial.type; | ||
| 446 | + tmp.line = tty0tty->serial.line; | ||
| 447 | + tmp.port = tty0tty->serial.port; | ||
| 448 | + tmp.irq = tty0tty->serial.irq; | ||
| 449 | + tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; | ||
| 450 | + tmp.xmit_fifo_size = tty0tty->serial.xmit_fifo_size; | ||
| 451 | + tmp.baud_base = tty0tty->serial.baud_base; | ||
| 452 | + tmp.close_delay = 5*HZ; | ||
| 453 | + tmp.closing_wait = 30*HZ; | ||
| 454 | + tmp.custom_divisor = tty0tty->serial.custom_divisor; | ||
| 455 | + tmp.hub6 = tty0tty->serial.hub6; | ||
| 456 | + tmp.io_type = tty0tty->serial.io_type; | ||
| 457 | + | ||
| 458 | + if (copy_to_user((void __user *)arg, &tmp, sizeof(struct serial_struct))) | ||
| 459 | + return -EFAULT; | ||
| 460 | + return 0; | ||
| 461 | + } | ||
| 462 | + return -ENOIOCTLCMD; | ||
| 463 | +} | ||
| 464 | + | ||
| 465 | +static int tty0tty_ioctl_tiocmiwait(struct tty_struct *tty, struct file *file, | ||
| 466 | + unsigned int cmd, unsigned long arg) | ||
| 467 | +{ | ||
| 468 | + struct tty0tty_serial *tty0tty = tty->driver_data; | ||
| 469 | + | ||
| 470 | +#ifdef SCULL_DEBUG | ||
| 471 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | ||
| 472 | +#endif | ||
| 473 | + if (cmd == TIOCMIWAIT) { | ||
| 474 | + DECLARE_WAITQUEUE(wait, current); | ||
| 475 | + struct async_icount cnow; | ||
| 476 | + struct async_icount cprev; | ||
| 477 | + | ||
| 478 | + cprev = tty0tty->icount; | ||
| 479 | + while (1) { | ||
| 480 | + add_wait_queue(&tty0tty->wait, &wait); | ||
| 481 | + set_current_state(TASK_INTERRUPTIBLE); | ||
| 482 | + schedule(); | ||
| 483 | + remove_wait_queue(&tty0tty->wait, &wait); | ||
| 484 | + | ||
| 485 | + /* see if a signal woke us up */ | ||
| 486 | + if (signal_pending(current)) | ||
| 487 | + return -ERESTARTSYS; | ||
| 488 | + | ||
| 489 | + cnow = tty0tty->icount; | ||
| 490 | + if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && | ||
| 491 | + cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) | ||
| 492 | + return -EIO; /* no change => error */ | ||
| 493 | + if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || | ||
| 494 | + ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || | ||
| 495 | + ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || | ||
| 496 | + ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) { | ||
| 497 | + return 0; | ||
| 498 | + } | ||
| 499 | + cprev = cnow; | ||
| 500 | + } | ||
| 501 | + | ||
| 502 | + } | ||
| 503 | + return -ENOIOCTLCMD; | ||
| 504 | +} | ||
| 505 | + | ||
| 506 | +static int tty0tty_ioctl_tiocgicount(struct tty_struct *tty, struct file *file, | ||
| 507 | + unsigned int cmd, unsigned long arg) | ||
| 508 | +{ | ||
| 509 | + struct tty0tty_serial *tty0tty = tty->driver_data; | ||
| 510 | + | ||
| 511 | +#ifdef SCULL_DEBUG | ||
| 512 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | ||
| 513 | +#endif | ||
| 514 | + if (cmd == TIOCGICOUNT) { | ||
| 515 | + struct async_icount cnow = tty0tty->icount; | ||
| 516 | + struct serial_icounter_struct icount; | ||
| 517 | + | ||
| 518 | + icount.cts = cnow.cts; | ||
| 519 | + icount.dsr = cnow.dsr; | ||
| 520 | + icount.rng = cnow.rng; | ||
| 521 | + icount.dcd = cnow.dcd; | ||
| 522 | + icount.rx = cnow.rx; | ||
| 523 | + icount.tx = cnow.tx; | ||
| 524 | + icount.frame = cnow.frame; | ||
| 525 | + icount.overrun = cnow.overrun; | ||
| 526 | + icount.parity = cnow.parity; | ||
| 527 | + icount.brk = cnow.brk; | ||
| 528 | + icount.buf_overrun = cnow.buf_overrun; | ||
| 529 | + | ||
| 530 | + if (copy_to_user((void __user *)arg, &icount, sizeof(icount))) | ||
| 531 | + return -EFAULT; | ||
| 532 | + return 0; | ||
| 533 | + } | ||
| 534 | + return -ENOIOCTLCMD; | ||
| 535 | +} | ||
| 536 | + | ||
| 537 | +static int tty0tty_ioctl(struct tty_struct *tty, struct file *file, | ||
| 538 | + unsigned int cmd, unsigned long arg) | ||
| 539 | +{ | ||
| 540 | +#ifdef SCULL_DEBUG | ||
| 541 | + printk(KERN_DEBUG "%s - %04X \n", __FUNCTION__,cmd); | ||
| 542 | +#endif | ||
| 543 | + switch (cmd) { | ||
| 544 | + case TIOCGSERIAL: | ||
| 545 | + return tty0tty_ioctl_tiocgserial(tty, file, cmd, arg); | ||
| 546 | + case TIOCMIWAIT: | ||
| 547 | + return tty0tty_ioctl_tiocmiwait(tty, file, cmd, arg); | ||
| 548 | + case TIOCGICOUNT: | ||
| 549 | + return tty0tty_ioctl_tiocgicount(tty, file, cmd, arg); | ||
| 550 | + } | ||
| 551 | + | ||
| 552 | + return -ENOIOCTLCMD; | ||
| 553 | +} | ||
| 554 | + | ||
| 555 | +static struct tty_operations serial_ops = { | ||
| 556 | + .open = tty0tty_open, | ||
| 557 | + .close = tty0tty_close, | ||
| 558 | + .write = tty0tty_write, | ||
| 559 | + .write_room = tty0tty_write_room, | ||
| 560 | + .set_termios = tty0tty_set_termios, | ||
| 561 | + .tiocmget = tty0tty_tiocmget, | ||
| 562 | + .tiocmset = tty0tty_tiocmset, | ||
| 563 | + .ioctl = tty0tty_ioctl, | ||
| 564 | +}; | ||
| 565 | + | ||
| 566 | +static struct tty_driver *tty0tty_tty_driver; | ||
| 567 | + | ||
| 568 | +static int __init tty0tty_init(void) | ||
| 569 | +{ | ||
| 570 | + | ||
| 571 | + int retval; | ||
| 572 | +#ifdef SCULL_DEBUG | ||
| 573 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | ||
| 574 | +#endif | ||
| 575 | + /* allocate the tty driver */ | ||
| 576 | + tty0tty_tty_driver = alloc_tty_driver(TINY_TTY_MINORS); | ||
| 577 | + if (!tty0tty_tty_driver) | ||
| 578 | + return -ENOMEM; | ||
| 579 | + | ||
| 580 | + /* initialize the tty driver */ | ||
| 581 | + tty0tty_tty_driver->owner = THIS_MODULE; | ||
| 582 | + tty0tty_tty_driver->driver_name = "tty0tty"; | ||
| 583 | + tty0tty_tty_driver->name = "tnt"; | ||
| 584 | + /* no more devfs subsystem */ | ||
| 585 | + tty0tty_tty_driver->major = TINY_TTY_MAJOR; | ||
| 586 | + tty0tty_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; | ||
| 587 | + tty0tty_tty_driver->subtype = SERIAL_TYPE_NORMAL; | ||
| 588 | + tty0tty_tty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW ; | ||
| 589 | + /* no more devfs subsystem */ | ||
| 590 | + tty0tty_tty_driver->init_termios = tty_std_termios; | ||
| 591 | + tty0tty_tty_driver->init_termios.c_iflag = 0; | ||
| 592 | + tty0tty_tty_driver->init_termios.c_oflag = 0; | ||
| 593 | + tty0tty_tty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; | ||
| 594 | + tty0tty_tty_driver->init_termios.c_lflag = 0; | ||
| 595 | + tty0tty_tty_driver->init_termios.c_ispeed = 38400; | ||
| 596 | + tty0tty_tty_driver->init_termios.c_ospeed = 38400; | ||
| 597 | + | ||
| 598 | + | ||
| 599 | + tty_set_operations(tty0tty_tty_driver, &serial_ops); | ||
| 600 | + | ||
| 601 | + | ||
| 602 | + /* register the tty driver */ | ||
| 603 | + retval = tty_register_driver(tty0tty_tty_driver); | ||
| 604 | + if (retval) { | ||
| 605 | + printk(KERN_ERR "failed to register tty0tty tty driver"); | ||
| 606 | + put_tty_driver(tty0tty_tty_driver); | ||
| 607 | + return retval; | ||
| 608 | + } | ||
| 609 | + | ||
| 610 | + printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION); | ||
| 611 | + return retval; | ||
| 612 | +} | ||
| 613 | + | ||
| 614 | +static void __exit tty0tty_exit(void) | ||
| 615 | +{ | ||
| 616 | + struct tty0tty_serial *tty0tty; | ||
| 617 | + int i; | ||
| 618 | + | ||
| 619 | +#ifdef SCULL_DEBUG | ||
| 620 | + printk(KERN_DEBUG "%s - \n", __FUNCTION__); | ||
| 621 | +#endif | ||
| 622 | + for (i = 0; i < TINY_TTY_MINORS; ++i) | ||
| 623 | + tty_unregister_device(tty0tty_tty_driver, i); | ||
| 624 | + tty_unregister_driver(tty0tty_tty_driver); | ||
| 625 | + | ||
| 626 | + /* shut down all of the timers and free the memory */ | ||
| 627 | + for (i = 0; i < TINY_TTY_MINORS; ++i) { | ||
| 628 | + tty0tty = tty0tty_table[i]; | ||
| 629 | + if (tty0tty) { | ||
| 630 | + /* close the port */ | ||
| 631 | + while (tty0tty->open_count) | ||
| 632 | + do_close(tty0tty); | ||
| 633 | + | ||
| 634 | + /* shut down our timer and free the memory */ | ||
| 635 | + kfree(tty0tty); | ||
| 636 | + tty0tty_table[i] = NULL; | ||
| 637 | + } | ||
| 638 | + } | ||
| 639 | +} | ||
| 640 | + | ||
| 641 | +module_init(tty0tty_init); | ||
| 642 | +module_exit(tty0tty_exit); |
pts/Makefile
0 → 100644
pts/tty0tty.c
0 → 100644
| 1 | +++ a/pts/tty0tty.c | ||
| 1 | +/* ######################################################################## | ||
| 2 | + | ||
| 3 | + tty0tty - linux null modem emulator | ||
| 4 | + | ||
| 5 | + ######################################################################## | ||
| 6 | + | ||
| 7 | + Copyright (c) : 2010 Luis Claudio Gambôa Lopes | ||
| 8 | + | ||
| 9 | + This program is free software; you can redistribute it and/or modify | ||
| 10 | + it under the terms of the GNU General Public License as published by | ||
| 11 | + the Free Software Foundation; either version 2, or (at your option) | ||
| 12 | + any later version. | ||
| 13 | + | ||
| 14 | + This program is distributed in the hope that it will be useful, | ||
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + GNU General Public License for more details. | ||
| 18 | + | ||
| 19 | + You should have received a copy of the GNU General Public License | ||
| 20 | + along with this program; if not, write to the Free Software | ||
| 21 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 22 | + | ||
| 23 | + For e-mail suggestions : lcgamboa@yahoo.com | ||
| 24 | + ######################################################################## */ | ||
| 25 | + | ||
| 26 | + | ||
| 27 | +#include <stdio.h> | ||
| 28 | +#include <stdlib.h> | ||
| 29 | +#include <string.h> | ||
| 30 | +#include <unistd.h> | ||
| 31 | +#include <fcntl.h> | ||
| 32 | + | ||
| 33 | +#include <termio.h> | ||
| 34 | + | ||
| 35 | +int | ||
| 36 | +ptym_open(char *pts_name, char *pts_name_s , int pts_namesz) | ||
| 37 | +{ | ||
| 38 | + char *ptr; | ||
| 39 | + int fdm; | ||
| 40 | + | ||
| 41 | + strncpy(pts_name, "/dev/ptmx", pts_namesz); | ||
| 42 | + pts_name[pts_namesz - 1] = '\0'; | ||
| 43 | + | ||
| 44 | + fdm = posix_openpt(O_RDWR | O_NONBLOCK); | ||
| 45 | + if (fdm < 0) | ||
| 46 | + return(-1); | ||
| 47 | + if (grantpt(fdm) < 0) | ||
| 48 | + { | ||
| 49 | + close(fdm); | ||
| 50 | + return(-2); | ||
| 51 | + } | ||
| 52 | + if (unlockpt(fdm) < 0) | ||
| 53 | + { | ||
| 54 | + close(fdm); | ||
| 55 | + return(-3); | ||
| 56 | + } | ||
| 57 | + if ((ptr = ptsname(fdm)) == NULL) | ||
| 58 | + { | ||
| 59 | + close(fdm); | ||
| 60 | + return(-4); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + strncpy(pts_name_s, ptr, pts_namesz); | ||
| 64 | + pts_name[pts_namesz - 1] = '\0'; | ||
| 65 | + | ||
| 66 | + return(fdm); | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | + | ||
| 70 | +int | ||
| 71 | +conf_ser(int serialDev) | ||
| 72 | +{ | ||
| 73 | + | ||
| 74 | +int rc=0; | ||
| 75 | +struct termios params; | ||
| 76 | + | ||
| 77 | +// Get terminal atributes | ||
| 78 | +rc = tcgetattr(serialDev, ¶ms); | ||
| 79 | + | ||
| 80 | +// Modify terminal attributes | ||
| 81 | +cfmakeraw(¶ms); | ||
| 82 | + | ||
| 83 | +rc = cfsetispeed(¶ms, B9600); | ||
| 84 | + | ||
| 85 | +rc = cfsetospeed(¶ms, B9600); | ||
| 86 | + | ||
| 87 | +// CREAD - Enable port to read data | ||
| 88 | +// CLOCAL - Ignore modem control lines | ||
| 89 | +params.c_cflag |= (B9600 |CS8 | CLOCAL | CREAD); | ||
| 90 | + | ||
| 91 | +// Make Read Blocking | ||
| 92 | +//fcntl(serialDev, F_SETFL, 0); | ||
| 93 | + | ||
| 94 | +// Set serial attributes | ||
| 95 | +rc = tcsetattr(serialDev, TCSANOW, ¶ms); | ||
| 96 | + | ||
| 97 | +// Flush serial device of both non-transmitted | ||
| 98 | +// output data and non-read input data.... | ||
| 99 | +tcflush(serialDev, TCIOFLUSH); | ||
| 100 | + | ||
| 101 | + | ||
| 102 | + return EXIT_SUCCESS; | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | + | ||
| 106 | +int main(void) | ||
| 107 | +{ | ||
| 108 | + char master1[1024]; | ||
| 109 | + char slave1[1024]; | ||
| 110 | + char master2[1024]; | ||
| 111 | + char slave2[1024]; | ||
| 112 | + | ||
| 113 | + int fd1; | ||
| 114 | + int fd2; | ||
| 115 | + | ||
| 116 | + char c1,c2; | ||
| 117 | + | ||
| 118 | + fd1=ptym_open(master1,slave1,1024); | ||
| 119 | + | ||
| 120 | + fd2=ptym_open(master2,slave2,1024); | ||
| 121 | + | ||
| 122 | + printf("(%s) <=> (%s)\n",slave1,slave2); | ||
| 123 | + | ||
| 124 | + | ||
| 125 | + conf_ser(fd1); | ||
| 126 | + conf_ser(fd2); | ||
| 127 | + | ||
| 128 | + | ||
| 129 | + while(1) | ||
| 130 | + { | ||
| 131 | + if(read (fd1,&c1,1) == 1) write(fd2,&c1,1); | ||
| 132 | + usleep(20); | ||
| 133 | + if(read (fd2,&c2,1) == 1) write(fd1,&c2,1); | ||
| 134 | + usleep(20); | ||
| 135 | + }; | ||
| 136 | + | ||
| 137 | + close(fd1); | ||
| 138 | + close(fd2); | ||
| 139 | + | ||
| 140 | + return EXIT_SUCCESS; | ||
| 141 | +} |