Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-02-2012, 10:24 AM
|
#1
|
LQ Newbie
Registered: May 2011
Distribution: Ubuntu, Fedora
Posts: 17
Rep: 
|
How to find out which /dev/ttyUSB* can be used for 3G modem connection?
Hi
I am writing a Perl script that detects USB 3G modem (of various types), switches it and then creates a connection with the ISP provider.
My problem is that several /dev/ttyUSB* files are created, and most cannot be used to connect.
I managed to filter some out by using modem command such as "at+csq" or "ati" (I receive a "timeout" on unconnected ttyUSBs).
But in some cases I am left with more than one /dev/ttyUSB* that respond correctly to these commands, but only one ttyUSB will actually work correctly with pppd.
For a more concrete example: USB stick Alcatel X220 (Vendor 1bbb product 0017). Both ttyUSB3 and ttyUSB4 respond to ati commands, but only ttyUSB4 will actually create the ppp connection (on ttyUSB3 pppd sends configuration requests but no answers are received).
Is there a way I can find out which ttyUSB is usable through a script?
This way should be generic for all USB modem types
The only way I can think of now is to add specific udev rules for ALL supported USB modems. And every time we add another supported modem, to add another rule.
Will be very thankful if there is an easier way to find out which ttyUSB to use
Thank you
Karin
|
|
|
01-02-2012, 10:27 AM
|
#2
|
Member
Registered: Mar 2007
Location: Spain
Distribution: Debian
Posts: 202
Rep:
|
Have you tried using lsusb to locate the right one?.
|
|
|
01-03-2012, 12:29 AM
|
#3
|
LQ Newbie
Registered: May 2011
Distribution: Ubuntu, Fedora
Posts: 17
Original Poster
Rep: 
|
Can you please elaborate?
lsusb returns "Bus 001 Device 003: ID 1bbb:0017"
How can I use this output to locate the correct /dev/ttyUSB*?
(I understand it helps me locate the /proc/bus/usb file that I can use for usbreset, but how else can I use this?)
Thank you
Karin
|
|
|
01-03-2012, 01:37 AM
|
#4
|
Member
Registered: Mar 2007
Location: Spain
Distribution: Debian
Posts: 202
Rep:
|
Is /dev/ttyUSB* a file or a link to a file in /dev/bus/usb/00?
If it is not a link then maybe you can get the information you need from dmesg, otherwise you can use udev rules (create your own in /dev/udev/rules.d) to map your device to the same filename when connected to the system.
You will have to read de documentation to create your own rule (check this link), but you can also look inside the ones already created by the system (the one for the CD could help) and you will get a notion about how you should create your own.
Last edited by rodrifra; 01-03-2012 at 01:58 AM.
|
|
|
01-03-2012, 02:32 AM
|
#5
|
LQ Newbie
Registered: May 2011
Distribution: Ubuntu, Fedora
Posts: 17
Original Poster
Rep: 
|
/dev/ttyUSB* are files and not symbolic links
Also dmesg offers no help
I guess I will have to create a rule for each supported modem type (sadly - a few hundreds... :-( ). I guess I will create a script for that ... ;-)
Thank you for your help
K
|
|
|
01-25-2013, 01:00 AM
|
#6
|
LQ Newbie
Registered: Jan 2013
Posts: 12
Rep: 
|
I met the same problem ,did not have a way to find the true ttyUSB? between them.
And have you find a way to distinguish ?
|
|
|
01-29-2013, 06:45 AM
|
#7
|
LQ Newbie
Registered: May 2011
Distribution: Ubuntu, Fedora
Posts: 17
Original Poster
Rep: 
|
Yes I solved this
In a nutshell - I cannibalized usb_modeswitch way of switching:
I added to the udev rules a reference if it finds a tty file to call my script
I modified the usb_modeswitch scripts to my specific needs and it ended by creating a symbolic link (e.g /dev/modem3g) to the specific ttyUsb that is active
So far it has not failed me.
it has been a while since I did it and the code is no longer available to me immediately
Try to have a look at the way usb_modeswitch does it. If u still have trouble, I will try to dig around and find exactly what I did
|
|
|
01-30-2013, 02:59 AM
|
#8
|
LQ Newbie
Registered: Jan 2013
Posts: 12
Rep: 
|
Did you use the script usb_modeswitch.tcl?
I find that it seems to this script can make one a symbolic link to the specific ttyUSB, but I did not use the PC linux ,it based on the embedded Linux. So I can not use the tcl .
Thank you .
|
|
|
01-31-2013, 09:44 AM
|
#9
|
Member
Registered: Aug 2012
Distribution: Debian, CentOS
Posts: 74
Rep: 
|
Have u tried wvdial?
wvdialconf will automatically chooses which ttyUSB to use.
|
|
|
01-31-2013, 07:40 PM
|
#10
|
LQ Newbie
Registered: Jan 2013
Posts: 12
Rep: 
|
Yes ,I have tried wvdial
And I also find that wvdialconf will create a ttyUSB in the config file.
but this ttyUSB was not the PPP always ,it is just the first port between the AT and ppp.
For example , the at port is ttyUSB1 and the ppp port is ttyUSB2 ,the wvdialconf will create ttyUSB1 in the conf.
However , I'm now trying to porting the wvdial in my board , it will help me find the two ports, although will not find the true ppp port .
|
|
|
02-01-2013, 11:16 AM
|
#11
|
LQ Newbie
Registered: May 2011
Distribution: Ubuntu, Fedora
Posts: 17
Original Poster
Rep: 
|
I did not use tcl, I rewrote it in perl
I do not know tcl and was too lazy to learn, although I could read it well enough
I took the idea and re-wrote it in Perl (slim possibility of bash, I do not remember)
I will try to upload the script on Monday
|
|
|
02-01-2013, 11:35 PM
|
#12
|
LQ Newbie
Registered: Jan 2013
Posts: 12
Rep: 
|
Thank you !
I will try to debug the script in order to use in my board.
Also , I'm trying to change the tcl into C .
|
|
|
02-04-2013, 05:02 AM
|
#13
|
LQ Newbie
Registered: May 2011
Distribution: Ubuntu, Fedora
Posts: 17
Original Poster
Rep: 
|
The code I used:
udev rules:
=====================
kernel=="ttyUSB*", ATTRS{bNumConfigurations}=="*", PROGRAM="/etc/prysm/create_usb_symlink.pl %p %s{idVendor} %s{idProduct}", SYMLINK="%c"
kernel=="ttyACM*", ATTRS{bNumConfigurations}=="*", PROGRAM="/etc/prysm/create_usb_symlink.pl %p %s{idVendor} %s{idProduct}", SYMLINK="%c"
=====================
Perl script:
=====================
#!/usr/bin/perl
package links::3G;
use Sys::Syslog qw(:standard :macros);
openlog "Links:3G", "perror,pid", $LOCAL;
# This is not the first time - mode switch is already accomplished
my $path = "/sys$ARGV[0]/device";
syslog(LOG_DEBUG, "Executed with Vendor %s Product %s path %s real %s",$ARGV[1], $ARGV[2],$ARGV[0], $path) ;
# Make sure it is not a dialup modem
if ($ARGV[1] eq "0572" and $ARGV[2] eq "1329") {
syslog(LOG_DEBUG, "Executed for dialup modem");
print "";
closelog();
exit 0;
}
if (! -e $path) {
syslog(LOG_ERR, "Path %s does not exist", $path);
print"";
closelog();
exit 0;
}
if (-l $path) {
$link = readlink "$path";
syslog(LOG_DEBUG, "Using link %s", $link);
$link =~ s/\.\.//g;
$path = "/sys$link";
syslog(LOG_DEBUG, "Using path %s", $path);
}
my $ttyUSB;
if ($path =~ /(ttyUSB[0-9]+)/) {
$ttyUSB = $1;
syslog(LOG_DEBUG, "Using usb %s", $ttyUSB);
} else {
$ttyUSB = "unknown";
syslog(LOG_WARNING, "Path %s is not a ttyUSB port", $path);
#closelog();
#exit 0;
}
# remove ttyusb from path
@parts = split ("/", $path);
$count = 0;
foreach (@parts) {
if (/ttyUSB/) {
last;
}
$count++;
}
$path = "";
for ($i = 0; $i < $count; $i++) {
$path = $path."/".$parts[$i];
}
syslog(LOG_DEBUG, "Interrupt path %s", $path);
my $rc = &is_inter($path);
if ($rc == 0) {
syslog(LOG_DEBUG, "USB %s is not Interruptable", $ttyUSB);
print "";
closelog();
exit 0;
}
if ($ttyUSB eq "unknown") {
syslog(LOG_DEBUG, "USB %s is Interruptable", $ttyUSB);
print "gsmmodem";
closelog();
exit 0;
}
@numbers = split (/\./, $path);
$last = scalar(@numbers)-1;
$port = $numbers[$last];
if ($port > 0) {
syslog(LOG_DEBUG, "Looking for lower ports with inter");
for ($i = 0; $i < $port; $i++) {
$numbers[$last] = $i;
$path = join(".", @numbers);
$rc = &is_inter($path);
if ($rc == 1) {
syslog(LOG_DEBUG, "found an interrupt interface below %s", $ttyUSB);
print "";
closelog();
exit 0;
}
}
}
print "gsmmodem";
closelog();
exit 0;
sub is_inter($) {
my $path = $_[0];
if (! opendir(DIR, "$path")) {
syslog(LOG_ERR,"Could not open dir %s : %m", $path);
return 0;
}
@files = readdir(DIR);
closedir(DIR);
foreach $file (@files) {
if ($file =~ /^ep_/) {
$ep = "$path/$file/type";
if (!open(TYPE, $ep)) {
syslog(LOG_ERR,"Could not open file %s : %m", $ep);
next;
}
@lines = (<TYPE>);
close TYPE;
$count = grep (/Interrupt/, @lines);
if ($count > 0) {
syslog(LOG_DEBUG, "Interrupt path %s tty %s", $ep,$ttyUSB);
return 1;
}
}
}
return 0;
}
|
|
|
All times are GMT -5. The time now is 10:41 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|