Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Useful 3G modem 'mode switching' script

    Scheduled Pinned Locked Moved General pfSense Questions
    52 Posts 4 Posters 39.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • stephenw10S
      stephenw10 Netgate Administrator
      last edited by

      Is it a problem that u3g tries and fails? Usually it won't try anything on a modem it doesn't recognise.
      I'm unfamiliar with usb_modeswitch, though I have used it unwittingly with Unbuntu where it just worked.
      The data package instructs it how to handle a modem right?

      I would guess you just need to upload it and tell usb_modeswitch where to look for it.
      What version of pfSense are you running? (full, embedded, nano)

      What OS are you uploading from?

      Steve

      1 Reply Last reply Reply Quote 0
      • J
        jamesc
        last edited by

        The modem is recognised, i.e the console tells me its a ZTE but its not usable in pfSense.

        Yes, the data package contains all the vendor id's and device id's.

        Usb modeswitch then knows what to do with the device, i.e switch it to modem mode.

        Im using pfSense 2.0.1 full.

        1 Reply Last reply Reply Quote 0
        • stephenw10S
          stephenw10 Netgate Administrator
          last edited by

          Presumably the data packets are cross platform and one already exists for your modem?

          You can upload files to pfSense easily enough. Either via the webGUI Diagnostics: Command Prompt: Upload
          or using sftp/scp. I use WinSCP from Windows. If you use the web upload it will end up in /tmp which will be lost on reboot so you'll have to move the file afterwards. Also I have found that very small files sometimes refuse to upload via the webGUI.

          For testing you can tell usb_modeswitch where to find the file:

          
          /usr/share/usb_modeswitch -c /tmp/your_modem.txt
          
          

          Assuming  usb_modeswitch installs there in FreeBSD since the instructions are all for Linux.

          Steve

          1 Reply Last reply Reply Quote 0
          • J
            jamesc
            last edited by

            Ah, i probably didnt explain it well. I dont have a problem downloading the package onto pfSense (i use fetch to download it directly before extracting it). The problem is there are a number of components in the package and I dont know where in FreeBSD/pfSense these files need to reside.

            As you said, the data package is intended for Linux.

            1 Reply Last reply Reply Quote 0
            • stephenw10S
              stephenw10 Netgate Administrator
              last edited by

              You have a link to the package?

              Steve

              1 Reply Last reply Reply Quote 0
              • J
                jamesc
                last edited by

                http://www.draisberghof.de/usb_modeswitch/usb-modeswitch-data-20120120.tar.bz2

                1 Reply Last reply Reply Quote 0
                • stephenw10S
                  stephenw10 Netgate Administrator
                  last edited by

                  Ah OK, that is a collection of data for all supported modems rather than something specific to yours.
                  Does that not get installed with the port anyway?
                  I'm going to have to do some reading/testing…..

                  Steve

                  1 Reply Last reply Reply Quote 0
                  • stephenw10S
                    stephenw10 Netgate Administrator
                    last edited by

                    Hmm OK so it looks like under Linux usb_modeswitch ties into the usb subsystem and will automatically recognise devices as they are plugged in and switch them. FreeBSD has a completely different system so none of the automatic part is included in the port.

                    In FreeBSD you will have to call it manually either with the required parameters in the command line or pointing at a file that contains them.
                    That's not a problem we can easily make the script run at boot time.

                    So what is your modem? Specifically what are the VID and PID?

                    Steve

                    1 Reply Last reply Reply Quote 0
                    • J
                      jamesc
                      last edited by

                      That doesnt sound too painful, the script would need to be called at startup before pfSense did its ppp dial.

                      My modem is a ZTE 636, i also have a Huawei E220 and vodafone K3565 for further testing. Im away til Sunday so dont have access to my test environment but im still checking the forum via my iPhone :-)

                      1 Reply Last reply Reply Quote 0
                      • stephenw10S
                        stephenw10 Netgate Administrator
                        last edited by

                        Ok, to confirm we really need the VID and PID but according to the device_reference.txt:

                        ZTE MF622 (aka "Onda MDC502HS")

                        ZTE MF626

                        ZTE MF628+ (tested version from Telia / Sweden)

                        ZTE MF633

                        ZTE MF636 (aka "Telstra / BigPond 7.2 Mobile Card")

                        ZTE MF637

                        and probably others not listed here

                        Contributor: Joakim Wennergren and others

                        DefaultVendor=  0x19d2
                        DefaultProduct= 0x2000

                        TargetVendor=  0x19d2
                        TargetProduct=  0x0031

                        MessageContent="5553424312345678000000000000061e000000000000000000000000000000"
                        MessageContent2="5553424312345679000000000000061b000000020000000000000000000000"

                        NeedResponse=1

                        It says to not use the reference file directly, perhaps because it's quite large, so create a new file with the above lines in. Hope!  ;)

                        Steve

                        1 Reply Last reply Reply Quote 0
                        • J
                          jamesc
                          last edited by

                          Cheers Steve, it kinda makes sense now!  Were you able to find more documentation on the port, i.e you mentioned that a manual approach is required for FreeBSD, did you read this somewhere or is this from your own knowledge?

                          I'll do some testing on Sunday and report back here :-)

                          1 Reply Last reply Reply Quote 0
                          • stephenw10S
                            stephenw10 Netgate Administrator
                            last edited by

                            I just looked at what files are installed from the port and it's very few. Only the usb_modeswitch binary and a conf file for disabling it entirely.
                            Unless I'm missing something.

                            I too have a Huawei K3565. It's not listed but I bet someone has the data for it. Anyway here's an example of how to find the VIP and PID:

                            
                            [2.0.1-RELEASE][root@pfsense.fire.box]/dev(21): usbconfig 
                            ugen0.1: <uhci root="" hub="" intel="">at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON
                            ugen1.1: <uhci root="" hub="" intel="">at usbus1, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON
                            ugen2.1: <ehci root="" hub="" intel="">at usbus2, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON
                            ugen2.2: <huawei mobile="" huawei="" technology="">at usbus2, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON
                            [2.0.1-RELEASE][root@pfsense.fire.box]/dev(22): usbconfig -d 2.2 dump_device_desc
                            ugen2.2: <huawei mobile="" huawei="" technology="">at usbus2, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON
                            
                              bLength = 0x0012 
                              bDescriptorType = 0x0001 
                              bcdUSB = 0x0200 
                              bDeviceClass = 0x0000 
                              bDeviceSubClass = 0x0000 
                              bDeviceProtocol = 0x0000 
                              bMaxPacketSize0 = 0x0040 
                              idVendor = 0x12d1 
                              idProduct = 0x1001 
                              bcdDevice = 0x0000 
                              iManufacturer = 0x0002   <huawei technology="">iProduct = 0x0001   <huawei mobile="">iSerialNumber = 0x0000   <no string="">bNumConfigurations = 0x0001</no></huawei></huawei></huawei></huawei></ehci></uhci></uhci> 
                            

                            Steve

                            Edit: It is listed just as the E169.

                            1 Reply Last reply Reply Quote 0
                            • J
                              jamesc
                              last edited by

                              Yes, i think K3565 is just the Vodafone model number, its actually an E169 underneath. Have you managed to get it to switch?

                              1 Reply Last reply Reply Quote 0
                              • stephenw10S
                                stephenw10 Netgate Administrator
                                last edited by

                                Nope!  ::)

                                
                                [2.0.1-RELEASE][root@pfsense.fire.box]/dev(24): usb_modeswitch -c /tmp/e169.txt
                                
                                Looking for target devices ...
                                 No devices in target mode or class found
                                Looking for default devices ...
                                   found matching product ID
                                 No devices in default mode found. Nothing to do. Bye.
                                
                                [2.0.1-RELEASE][root@pfsense.fire.box]/dev(25): cat /tmp/e169.txt
                                # Huawei E169 and others
                                #
                                # Contributor: Dale Lane
                                
                                DefaultVendor=  0x12d1
                                DefaultProduct= 0x1001
                                
                                TargetClass=    0xff
                                
                                # choose one of these:
                                HuaweiMode=1
                                
                                

                                Steve

                                Edit: Seems to be because it's already in the target class (0xff):

                                
                                Looking for target devices ...
                                 No devices in target mode or class found
                                Looking for default devices ...
                                  searching devices, found USB ID 12d1:1001
                                   found matching vendor ID
                                   found matching product ID
                                   target class ff matching
                                   not adding device
                                  searching devices, found USB ID 0000:0000
                                  searching devices, found USB ID 0000:0000
                                  searching devices, found USB ID 0000:0000
                                 No devices in default mode found. Nothing to do. Bye.
                                
                                

                                Possibly already switched?  :-\

                                Doh! looks like E169 is already a supported modem.  ::)

                                1 Reply Last reply Reply Quote 0
                                • J
                                  jamesc
                                  last edited by

                                  Looks that way, your console output when you plug the device in doesnt say that its a SCSI device so its already switched!

                                  1 Reply Last reply Reply Quote 0
                                  • stephenw10S
                                    stephenw10 Netgate Administrator
                                    last edited by

                                    Yep, already works fine.

                                    
                                    [2.0.1-RELEASE][root@pfsense.fire.box]/root(1): cu -l cuaU0.0 -s 115200
                                    Connected
                                    at
                                    OK
                                    at I0
                                    Manufacturer: huawei
                                    Model: K3565
                                    Revision: 11.608.10.51.00
                                    IMEI: 359574032708530
                                    +GCAP: +CGSM,+DS,+ES
                                    
                                    OK
                                    
                                    

                                    Steve

                                    1 Reply Last reply Reply Quote 0
                                    • J
                                      jamesc
                                      last edited by

                                      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.

                                      1 Reply Last reply Reply Quote 0
                                      • stephenw10S
                                        stephenw10 Netgate Administrator
                                        last edited by

                                        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

                                        1 Reply Last reply Reply Quote 0
                                        • J
                                          jamesc
                                          last edited by

                                          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 MF112

                                          Here'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 :(

                                          1 Reply Last reply Reply Quote 0
                                          • stephenw10S
                                            stephenw10 Netgate Administrator
                                            last edited by

                                            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

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.