Useful 3G modem 'mode switching' script
-
I'll give the ZTE a try on Sunday, ive tried this modem previously with pfSense and failed because it is definately seen as a storage device. Will report back with my results.
-
You might think that but here is the system log from when I plugged it in:
Feb 17 18:16:17 pfsense kernel: ugen2.2: <huawei technology="">at usbus2 Feb 17 18:16:17 pfsense kernel: ugen2.2: <huawei technology="">at usbus2 (disconnected) Feb 17 18:16:24 pfsense kernel: ugen2.2: <huawei technology="">at usbus2 Feb 17 18:16:24 pfsense kernel: u3g0: <huawei 0="" 2="" technology="" huawei="" mobile,="" class="" 0,="" rev="" 2.00="" 0.00,="" addr="">on usbus2 Feb 17 18:16:24 pfsense kernel: u3g0: Found 3 ports. Feb 17 18:16:24 pfsense kernel: umass0: <huawei 0="" 2="" technology="" huawei="" mobile,="" class="" 0,="" rev="" 2.00="" 0.00,="" addr="">on usbus2 Feb 17 18:16:26 pfsense kernel: umass1: <huawei 0="" 2="" technology="" huawei="" mobile,="" class="" 0,="" rev="" 2.00="" 0.00,="" addr="">on usbus2 Feb 17 18:16:26 pfsense kernel: (probe0:umass-sim0:0:0:0): TEST UNIT READY. CDB: 0 0 0 0 0 0 Feb 17 18:16:26 pfsense kernel: (probe0:umass-sim0:0:0:0): CAM status: SCSI Status Error Feb 17 18:16:26 pfsense kernel: (probe0:umass-sim0:0:0:0): SCSI status: Check Condition Feb 17 18:16:26 pfsense kernel: (probe0:umass-sim0:0:0:0): SCSI sense: NOT READY asc:3a,0 (Medium not present) Feb 17 18:16:26 pfsense kernel: cd0 at umass-sim0 bus 0 scbus0 target 0 lun 0 Feb 17 18:16:26 pfsense kernel: cd0: <huawei mass="" storage="" 2.31="">Removable CD-ROM SCSI-2 device Feb 17 18:16:26 pfsense kernel: cd0: 40.000MB/s transfers Feb 17 18:16:26 pfsense kernel: cd0: Attempt to query device size failed: NOT READY, Medium not present Feb 17 18:16:27 pfsense kernel: (probe0:umass-sim1:1:0:0): TEST UNIT READY. CDB: 0 0 0 0 0 0 Feb 17 18:16:27 pfsense kernel: (probe0:umass-sim1:1:0:0): CAM status: SCSI Status Error Feb 17 18:16:27 pfsense kernel: (probe0:umass-sim1:1:0:0): SCSI status: Check Condition Feb 17 18:16:27 pfsense kernel: (probe0:umass-sim1:1:0:0): SCSI sense: NOT READY asc:3a,0 (Medium not present) Feb 17 18:16:27 pfsense kernel: da0 at umass-sim1 bus 1 scbus1 target 0 lun 0 Feb 17 18:16:27 pfsense kernel: da0: <huawei mmc="" storage="" 2.31="">Removable Direct Access SCSI-2 device Feb 17 18:16:27 pfsense kernel: da0: 40.000MB/s transfers Feb 17 18:16:27 pfsense kernel: da0: Attempt to query device size failed: NOT READY, Medium not present</huawei></huawei></huawei></huawei></huawei></huawei></huawei></huawei>
It clearly comes up as a CD-ROM drive (cd0) and the micro SD reader (da0).
But u3g also shows 'found 3 ports' and looking in /dev there are cuaU0.0 1.1 and 2.2.
I haven't actually tried using this as a modem though, I'm not sure I have a simcard that can do it.Steve
-
We have some progress….
Fresh install of 2.0.1 full on an old Celeron box to avoid mapping USB devices through to a VMWare VM.
Modem is a ZTE MF112Here's what happens initially when plugging the modem in (not using modeswitch)
Feb 19 15:55:56 pfSense kernel: umass0: <zte,incorporated 0="" 2="" zte="" wcdma="" technologies="" msm,="" class="" 0,="" rev="" 2.00="" 0.00,="" addr="">on usbus3 Feb 19 15:55:56 pfSense kernel: umass0: SCSI over Bulk-Only; quirks = 0x0000 Feb 19 15:55:57 pfSense kernel: umass0:0:0:-1: Attached to scbus0 Feb 19 15:55:57 pfSense kernel: (probe0:umass-sim0:0:0:0): TEST UNIT READY. CDB: 0 0 0 0 0 0 Feb 19 15:55:57 pfSense kernel: (probe0:umass-sim0:0:0:0): CAM status: SCSI Status Error Feb 19 15:55:57 pfSense kernel: (probe0:umass-sim0:0:0:0): SCSI status: Check Condition Feb 19 15:55:57 pfSense kernel: (probe0:umass-sim0:0:0:0): SCSI sense: NOT READY asc:3a,0 (Medium not present) Feb 19 15:55:57 pfSense kernel: cd0 at umass-sim0 bus 0 scbus0 target 0 lun 0 Feb 19 15:55:57 pfSense kernel: cd0: <hspa usb="" scsi="" cd-rom="" 2.31="">Removable CD-ROM SCSI-2 device Feb 19 15:55:57 pfSense kernel: cd0: 40.000MB/s transfers Feb 19 15:55:57 pfSense kernel: cd0: Attempt to query device size failed: NOT READY, Medium not present</hspa></zte,incorporated>
No interfaces are available to assign under PPP.
I then install the port and create a config file for the MF112 and run modeswitch
Looking for target devices ... No devices in target mode or class found Looking for default devices ... found matching product ID adding device Found device in default mode, class or configuration (1) Accessing device 005 on bus 000 ... Getting the current device configuration ... OK, got current device configuration (1) Using first interface: 0x00 Using endpoints 0x01 (out) and 0x81 (in) Inquiring device details; driver will be detached ... Cant't do driver detection and detaching on this platform. SCSI inquiry data (for identification) ------------------------- Vendor String: HSPA Model String: USB SCSI CD-ROM Revision String: 2.31 ------------------------- USB description data (for identification) ------------------------- Manufacturer: ZTE,Incorporated Product: ZTE WCDMA Technologies MSM Serial No.: P673A3H3GD010000 ------------------------- Setting up communication with interface 0 Using endpoint 0x01 for message sending ... Trying to send message 1 to endpoint 0x01 ... OK, message successfully sent Reading the response to message 1 (CSW) ... OK, response successfully read (13 bytes). Trying to send message 2 to endpoint 0x01 ... OK, message successfully sent Reading the response to message 2 (CSW) ... Response reading got error -6 Device is gone, skipping any further commands -> Run lsusb to note any changes. Bye.
I then have two new PPP interfaces /dev/cuaU0.1 and /dev/cuaU0.2
Unfortunately, I have no simcard to test any further :(
-
Ah, looks promising. :)
You can try talking to the modem with cu or tip like I did. If it responds to AT commands I would expect it to work.Steve
-
The next thing to try is adding the below line to the firewall config to test whether pfSense will switch the modem before it does the PPP dial:
<shellcmd>usb_modeswitch -c /usr/local/etc/modem.txt</shellcmd>
-
If not then try <earlyshellcmd>instead.
Steve</earlyshellcmd>
-
It does respond to AT commands on cuaU0.2 :)
My question is, what is cuaU0.1 which is also available to assign under PPP
Also, when I assign the PPP to an interface, I also see cuaU0.0 and cuau0 in the 'Modem Port' dropdown list so i'm a little confused ???
-
Probably due to the way pfSense finds the serial ports to display:
$serialports = pfSense_get_modem_devices();
I can't find that function but if it relies on, for example, sysctl dev.u3g then they won't appear there.
The reason that the modem provides several serial ports is not obvious to me but it seems it's possible to get stats from the modem on one interface whilst connected via another, signal strength, baud rate etc.
Steve
-
Thanks Steve.
I found a simcard, there's no credit on it but it still connects and gets an IP address.
I've tried both the shellcmd and earlyshellcmd options but sometimes there is a delay until the actual switch occurs. The boot sequence continues regardless, the PPP interface is brought up but the modem is not yet ready so a WAN connection isn't established. If I go into the GUI and manually hit connect, PPP is dialled and the WAN comes online.
Any idea of how we can delay bringing up PPP until we know the modem has successfully switched?
-
What happens when it tries to dial out before the interface is switched?
I'm surprised that it doesn't just keep trying.
Maybe using dial-on demand or idle time out.You could write a script that ran usb_modeswitch, waited and then called the appropriate interface connect function.
Steve
-
It doesnt do anything, the box continues its boot process as if no modem was plugged in. I see the modem details flash up on the console towards the end of the boot process but PPP has already initialised at this point (without seeing the modem) so i suspect it wont keep on attempting a dial out because as far it's concerned, no modem was detected at the time of initialisation, I hope that makes sense!
-
Yes I see exactly what you mean.
Would probably be best to use an rc script then.
This is just a guess but perhaps:#!/bin/sh /usr/local/sbin/usb_modeswitch -c yourmodem.txt sleep 5 /etc/rc.reload_interfaces
Try issuing a /etc/rc.reload_interfaces and see if it finds the modem and connects.
Steve
-
I had just finished creating a similar script and was looking for a command that would restart PPP, the reload_interfaces seems to do the trick nicely, thank you.
-
how can i put my usbmode_switch script in startup??i have bandluxe 21 mbps 3g modem and successfully flip it to modem mode using usb_modeswitch..I want to connect my modem's ppp in start up..thanks
-
If it's an RC script, as I detailed above, put it in /usr/local/etc/rc.d and it will run at boot.
Steve
-
i already put my script in /usr/local/etc/rc.d/ but when i reboot pfsense,,ppp dials in fiirst before flipping my usb modem,thus i need to dial my ppp manually..i want to flip my modem first then ppp dials in..TIA
-
Yes Jamesc experienced that problem above.
Doesn't it redial when you reload the interfaces in the script?Steve
-
thanks..reload interfaces did the trick..now i will add 1 more different usb modem.. :)
-
problem occurs: persistent disconnections..i cant make my modem to hold for an hour or so..my ppp connection disconnects every 10 seconds..i try to use my 3g modem directly with my laptop but never had a connection hangup..
-
Is it exactly 10 seconds every time? This might indicate some sort of ppp error. Or more random?
What do you see in the logs? Does it do this if you setup the connection manually instead of using the script?
Have you set the PPP session to be 'always on' (idle timeout = 0, which is the default setting)using rc.reload_interfaces seemed a bit crude when I suggested it earlier and it still does. It maybe that it is causing some other undesired consequence. It would be much better to simply reload WAN or indeed just have it redial. Sadly I'm not sufficiently familiar with the code to suggest anything better. :(
Steve
Edit: rc.linkup WAN up (or should that be 'up WAN') perhaps? :-\ Complete guesswork!