LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-26-2008, 06:14 PM   #1
Peatmoss
Member
 
Registered: Nov 2007
Location: Vancouver
Distribution: Ubuntu 7.10
Posts: 43

Rep: Reputation: 15
Can A User Space Program Create a /dev/tty?


Hi All,

I have done a small amount of searching for the answer to this question, but being a Linux noob, I still haven't learned all the places to look for answers, so sorry if this sounds like a stoopid question.

I have a program that runs on Linux. It communicates with a modem via USB. The modem has a limited number of endpoints, so we've implemented a mux protocol over one of the endpoints that allows us to do a bunch of extra stuff that would normally require its own /dev/tty. On Windows, our driver is pretty good and can demux this traffic and present it to the rest of Windows as virtual COM ports.

We'd like to accomplish the same kind of thing with our Linux code; accept this mux protocol data into a user-mode application, have that application demux each of the virtual COM ports and expose them to the rest of the Linux system as /dev/ttyXXXs.

Seems to me it would be relatively straightforward if we did the whole thing in the USB driver, but we'd prefer to do it in user space. Can anyone point me in the right direction for where to learn how to do this, assuming its even possible?

Regards

peatmoss
 
Old 08-26-2008, 06:45 PM   #2
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,285
Blog Entries: 1

Rep: Reputation: 103Reputation: 103
Quote:
Originally Posted by Peatmoss View Post
Seems to me it would be relatively straightforward if we did the whole thing in the USB driver, but we'd prefer to do it in user space. Can anyone point me in the right direction for where to learn how to do this, assuming its even possible?
Sounds like you want libusb.
 
Old 08-26-2008, 06:48 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu (x86), Debian (PPC)
Posts: 3,528

Rep: Reputation: 60
Before udev, which creates nodes in /dev on the fly, it used to be the case the these special files would be created by the utility mknod. However, just making a device node is one thing - having a working driver is another.

I'm not a kernel hacker, and I've never written a device driver. However, I did find this book which looks like it has some useful information about USB in chapter 13. I hope that helps.
 
Old 08-26-2008, 07:41 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: Slackware64 13.37, Kubuntu 10.04
Posts: 2,944

Rep: Reputation: Disabled
Is it the character device or the terminal emulation you require? If you create a pseudo-terminal from user-space then your program will still need to be able to interface with the device on its own.
ta0kira
 
Old 08-27-2008, 05:48 PM   #5
Peatmoss
Member
 
Registered: Nov 2007
Location: Vancouver
Distribution: Ubuntu 7.10
Posts: 43

Original Poster
Rep: Reputation: 15
Hi Everyone,

Thanks for your replies they have been helpful. Going the device driver route is tempting, but also likely to consume a lot of time. At this point we're looking for a user-mode solution that could be robust but easier to code. So the mknod suggestion seems to come the closest to meeting our requirements. I've done a small amount of reading about it and it looks promising for our needs.

In fact, it reminds of me good old Beej's IPC page, something I read about several months ago, but didn't make the connection until now.

It remains to research exactly what kinds of things can be done via the system calls to a node we've created with mknod(), but at the very least as long as we can send/receive binary data between two processes, it should solve the problem quite nicely.

Regards!!

/Peatmoss
 
Old 08-27-2008, 08:19 PM   #6
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: Slackware64 13.37, Kubuntu 10.04
Posts: 2,944

Rep: Reputation: Disabled
Or look at openpty and forkpty.
ta0kira
 
Old 08-27-2008, 11:45 PM   #7
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,858
Blog Entries: 1

Rep: Reputation: Disabled
Another easy solution to consider might be "mkfifo" (nee "mknod -p"). It creates a named pipe for two or more processes to communicate with each other). I'm sure you already noticed this on Beej's page; here's another link:

http://www.linuxjournal.com/article/2156
 
Old 08-30-2008, 04:02 AM   #8
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 49
A few days ago I would have said "no", but while checking to make sure I was right I ran across this:

http://kerneltrap.org/mailarchive/li...ad#mid-3116524

So the answer is now "yes" - if you have that patch.

UNIX sockets would have worked well for what you describe; unfortunately you need socket code rather than plain "fopen" to deal with UNIX sockets. Character devices are best; they can support read, write, asynchronous/non-blocking r/w, multiple opens, ioctls, and so on.

FIFOs would be useful as already suggested, BUT each time you attempt to write to the FIFO and no process has opened it for reading, you will get SIGPIPE (not to mention the numerous other return values indicating that things are not ready yet). So that gets kind of messy. With a character device on the other hand, you know how many processes have it open and you don't really write unless a read was requested. The only problem with the character device solution: it takes some work.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to start a user-space program automatically just before shutdown? nikhil86 Linux - General 1 04-12-2008 12:52 PM
Accessing tty in kernel space RichardS Programming 10 01-18-2008 11:13 AM
How many thread can be created in user space program? Honor Linux - Networking 1 09-08-2006 06:45 AM
Calling User-space program functions from Kernel modules shivanu Programming 1 03-05-2005 02:11 PM
How to create one non-preemptible and another preemptible thread in the user space? vinayparam Linux - Software 0 01-10-2005 09:17 AM


All times are GMT -5. The time now is 03:14 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration