• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
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.4k 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.
  • S
    stephenw10 Netgate Administrator
    last edited by Feb 19, 2012, 8:44 PM

    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

    1 Reply Last reply Reply Quote 0
    • J
      jamesc
      last edited by Feb 19, 2012, 8:59 PM

      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!

      1 Reply Last reply Reply Quote 0
      • S
        stephenw10 Netgate Administrator
        last edited by Feb 19, 2012, 9:26 PM

        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

        1 Reply Last reply Reply Quote 0
        • J
          jamesc
          last edited by Feb 19, 2012, 9:52 PM

          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.

          1 Reply Last reply Reply Quote 0
          • J
            jly2680
            last edited by Mar 5, 2012, 2:02 PM

            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

            1 Reply Last reply Reply Quote 0
            • S
              stephenw10 Netgate Administrator
              last edited by Mar 5, 2012, 2:36 PM

              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

              1 Reply Last reply Reply Quote 0
              • J
                jly2680
                last edited by Mar 5, 2012, 3:03 PM

                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

                1 Reply Last reply Reply Quote 0
                • S
                  stephenw10 Netgate Administrator
                  last edited by Mar 5, 2012, 3:12 PM

                  Yes Jamesc experienced that problem above.
                  Doesn't it redial when you reload the interfaces in the script?

                  Steve

                  1 Reply Last reply Reply Quote 0
                  • J
                    jly2680
                    last edited by Mar 5, 2012, 3:23 PM

                    thanks..reload interfaces did the trick..now i will add 1 more different usb modem.. :)

                    1 Reply Last reply Reply Quote 0
                    • J
                      jly2680
                      last edited by Mar 5, 2012, 5:35 PM

                      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..

                      1 Reply Last reply Reply Quote 0
                      • S
                        stephenw10 Netgate Administrator
                        last edited by Mar 5, 2012, 7:02 PM Mar 5, 2012, 6:34 PM

                        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!

                        1 Reply Last reply Reply Quote 0
                        • J
                          jly2680
                          last edited by Mar 5, 2012, 8:07 PM

                          i think ppp error side?

                          Mar 5 23:07:52	ppp: [opt2] IPCP: SendConfigReq #3
                          Mar 5 23:07:52	ppp: [opt2] IPADDR 176.225.134.77
                          Mar 5 23:07:52	ppp: [opt2] IPCP: rec'd Configure Ack #3 (Ack-Sent)
                          Mar 5 23:07:52	ppp: [opt2] IPADDR 176.225.134.77
                          Mar 5 23:07:52	ppp: [opt2] IPCP: state change Ack-Sent --> Opened
                          Mar 5 23:07:52	ppp: [opt2] IPCP: LayerUp
                          Mar 5 23:07:52	ppp: [opt2] 176.225.134.77 -> 10.0.0.1
                          Mar 5 23:07:52	ppp: [opt2] IFACE: Up event
                          Mar 5 23:08:36	ppp: Multi-link PPP daemon for FreeBSD
                          Mar 5 23:08:36	ppp:
                          Mar 5 23:08:36	ppp: process 28199 started, version 5.5 (root@FreeBSD_8.0_pfSense_2.0-snaps.pfsense.org 10:25 12-Oct-2011)
                          Mar 5 23:08:36	ppp: caught fatal signal term
                          Mar 5 23:08:36	ppp: [opt2] IFACE: Close event
                          Mar 5 23:08:36	ppp: [opt2] IPCP: Close event
                          Mar 5 23:08:36	ppp: [opt2] IPCP: state change Opened --> Closing
                          Mar 5 23:08:36	ppp: [opt2] IPCP: SendTerminateReq #4
                          Mar 5 23:08:36	ppp: [opt2] IPCP: LayerDown
                          Mar 5 23:08:36	ppp: waiting for process 16679 to die...
                          Mar 5 23:08:36	ppp: [opt2] IFACE: Down event
                          Mar 5 23:08:36	ppp: [opt2] IPCP: rec'd Terminate Ack #4 (Closing)
                          Mar 5 23:08:36	ppp: [opt2] IPCP: state change Closing --> Closed
                          Mar 5 23:08:36	ppp: [opt2] IPCP: LayerFinish
                          Mar 5 23:08:36	ppp: [opt2] Bundle: No NCPs left. Closing links...
                          Mar 5 23:08:36	ppp: [opt2] Bundle: closing link "opt2_link0"...
                          Mar 5 23:08:36	ppp: [opt2_link0] Link: CLOSE event
                          Mar 5 23:08:36	ppp: [opt2_link0] LCP: Close event
                          Mar 5 23:08:36	ppp: [opt2_link0] LCP: state change Opened --> Closing
                          Mar 5 23:08:36	ppp: [opt2_link0] Link: Leave bundle "opt2"
                          Mar 5 23:08:36	ppp: [opt2] Bundle: Status update: up 0 links, total bandwidth 9600 bps
                          Mar 5 23:08:36	ppp: [opt2] IPCP: Close event
                          Mar 5 23:08:36	ppp: [opt2] IPCP: Down event
                          Mar 5 23:08:36	ppp: [opt2] IPCP: state change Closed --> Initial
                          Mar 5 23:08:36	ppp: [opt2_link0] LCP: SendTerminateReq #3
                          Mar 5 23:08:36	ppp: [opt2_link0] LCP: LayerDown
                          Mar 5 23:08:36	ppp: [opt2_link0] LCP: rec'd Terminate Ack #3 (Closing)
                          Mar 5 23:08:36	ppp: [opt2_link0] LCP: state change Closing --> Closed
                          Mar 5 23:08:36	ppp: [opt2_link0] LCP: LayerFinish
                          Mar 5 23:08:36	ppp: [opt2_link0] Link: DOWN event
                          Mar 5 23:08:36	ppp: [opt2_link0] LCP: Down event
                          Mar 5 23:08:36	ppp: [opt2_link0] LCP: state change Closed --> Initial
                          
                          1 Reply Last reply Reply Quote 0
                          • J
                            jly2680
                            last edited by Mar 6, 2012, 8:47 AM

                            /etc/rc.reload_interfaces in my script causes my 3g ppp connection to restart every 10-20 secs..

                            1 Reply Last reply Reply Quote 0
                            • S
                              stephenw10 Netgate Administrator
                              last edited by Mar 6, 2012, 10:03 AM

                              Can you show us your script?
                              It should only be run once at boot, I can't see how it could possibly effect the ppp cycling time.  :-\

                              Steve

                              1 Reply Last reply Reply Quote 0
                              • J
                                jly2680
                                last edited by Mar 6, 2012, 1:36 PM Mar 6, 2012, 1:31 PM

                                #!/bin/sh
                                /usr/local/sbin/usb_modeswitch usb_modeswitch -v 1a8d -p 2000 -M "5553424312345678000000000000061e000000000000000000000000000000" -2 "5553424312345679000000000000061b000000020000000000000000000000" -n 1 -W
                                sleep 5
                                /etc/rc.reload_interfaces
                                

                                removing reload interfaces makes my 3g ppp connection stable..is there a place where my script will run first then ppp dials in?or to restart ppp connection after my script run?
                                i can easily do this with openwrt/ddwrt but i want to try pfsense..

                                1 Reply Last reply Reply Quote 0
                                • S
                                  stephenw10 Netgate Administrator
                                  last edited by Mar 6, 2012, 8:44 PM

                                  The code in /usr/local/etc.rc.d should only be run once as far as I know.
                                  You could try calling the script using shellcmd or earlyshellcmd instead:
                                  http://doc.pfsense.org/index.php/Executing_commands_at_boot_time

                                  Steve

                                  1 Reply Last reply Reply Quote 0
                                  • J
                                    jly2680
                                    last edited by Mar 6, 2012, 10:40 PM

                                    thanks,,same thing it doesnt auto connect on boot even if i edit my xml with earlyshellcmd or shellcmd..
                                    on openwrt,,i usually put my script in /etc/rc.local and run a cron job with a watchdog scripts,,it automatically restart my 3g interface when ppp hangs up.hope i can do same thing on pfsense.am total noob with pfsense thats why im still catching up with it..

                                    1 Reply Last reply Reply Quote 0
                                    • T
                                      th3r3isnospoon
                                      last edited by Mar 13, 2012, 2:47 AM

                                      Hello,

                                      I'd really like to get this feature working on my pfSense box.

                                      I read through this thread 3 times but, I don't see how to go about actually installing the port or using one of your scripts.

                                      If you have a minute or two, can you just throw together a how-to so I can take the necessary steps to get this to work?  I'd really appreciate it!

                                      Thank you!

                                      -th3r3isnospoon

                                      1 Reply Last reply Reply Quote 0
                                      • S
                                        stephenw10 Netgate Administrator
                                        last edited by Mar 13, 2012, 2:35 PM Mar 13, 2012, 2:32 PM

                                        Ok, this may have to be multipart as I'm pushed for time!  ::)

                                        First check the usb-modeswitch forum/website to see if your modem is supported at all:
                                        http://www.draisberghof.de/usb_modeswitch/
                                        Note down any relevant switching code that other users may have posted if it's not included as standard in device_reference.txt:
                                        http://www.draisberghof.de/usb_modeswitch/device_reference.txt

                                        Install the FreeBSD package in pfSense. This will vary depending on your pfSense version.
                                        For 2.0.X NanoBSD:

                                        
                                        /etc/rc.conf_mount_rw
                                        pkg_add -r ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8-stable/Latest/usb_modeswitch.tbz
                                        /etc/rc.conf_mount_ro
                                        
                                        

                                        For 2.0.X full install:

                                        
                                        pkg_add -r ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8-stable/Latest/usb_modeswitch.tbz
                                        
                                        

                                        Now depending on what the required code for your modem is you can either just enter it at the command line directly, e.g.:

                                        
                                        /usr/local/sbin/usb_modeswitch usb_modeswitch -v 1a8d -p 2000 -M "5553424312345678000000000000061e000000000000000000000000000000" -2 "5553424312345679000000000000061b000000020000000000000000000000" -n 1 -W
                                        
                                        

                                        or call a file containing the appropriate section from device_reference.txt (or some custom code), e.g.:

                                        /usr/local/sbin/usb_modeswitch -c yourmodem.txt
                                        

                                        You can run it with -h to list the command line options:

                                        /usr/local/sbin/usb_modeswitch -h
                                        

                                        If you get it right usb_modeswitch will report success and you will see some lines in the pfSense log showing devices removed and attached.

                                        If you have found the code to correctly switch your modem you can put a script file in /usr/local/etc/rc.d.
                                        Call it whateveryouwant.sh:

                                        
                                        #!/bin/sh
                                        /usr/local/sbin/usb_modeswitch -c yourmodem.txt
                                        sleep 5
                                        /etc/rc.reload_interfaces
                                        
                                        

                                        I am still of the opinion that /etc/rc.reload_interfaces is probably not the correct way to get the modem running, it seems too crude, but it worked for jamesc.

                                        Steve

                                        1 Reply Last reply Reply Quote 0
                                        • T
                                          th3r3isnospoon
                                          last edited by Mar 13, 2012, 2:42 PM

                                          You sir are a gentleman and scholar.  I really appreciate this.

                                          I will try this out, this evening and report back.

                                          THANK YOU!

                                          -th3r3isnospoon.

                                          1 Reply Last reply Reply Quote 0
                                          • First post
                                            Last post
                                          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
                                            This community forum collects and processes your personal information.
                                            consent.not_received