# USB 3G Modem



## dead (Nov 21, 2011)

I've been trying to find a good guide (Google, Forum search) on how to set up my 3G modem using only the base system. Previously I've been succesful using modemmanager. I understand it involves u3g/ppp, but that's about it. The manpage for u3g mentions the u3gstub manpage in order to switch from mass storage mode into modem mode but there seems to be no such manpage, instead usb_modeswitch has caught my attention, but I'm out of luck. It's an Huawei modem. Thanks in advance!


----------



## SirDice (Nov 22, 2011)

Is the modem detected as a serial (com) port? If that's the case you don't need to switch. 

Use the serial port of the 3G modem as a 'regular' POTS modem and set up a ppp connection. You usually need to dial a special number; *99#.

Chapter 28 PPP and SLIP


----------



## dead (Nov 23, 2011)

In order to connect I need to enter a PIN. How would I do this in FreeBSD?


----------



## mky (Nov 24, 2011)

The AT Command is:


```
AT+CPIN="1234"
```

Check also this page: https://www.anywi.com/3g/


----------



## dead (Nov 26, 2011)

```
set ifaddr 10.0.0.1/0 10.0.0.2/0 255.255.255.0 0.0.0.0
```
What are the four fields? The third field looks like the netmask. In Windows, it's ends with 248, should I set my ppp accordingly?


```
AT+CGDCONT=1,\\\"IP\\\",\\\"internet\\\" OK
```
Why override the already present CGDCONT? If it's the matter of simply setting one to "active" - wouldn't AT+CGDCONT=1 (assuming the entry '1' is existant) be enough?


```
AT+CGACT? OK-AT-OK
AT+CGATT? OK
AT+COPS? OK
```
As far as I know, '?' probes the modem for information. Why is this necessary in the ppp.conf, and what's the difference between 'OK-AT-OK' and 'OK'? Very confusing. Where's the big bad manual on ppp.conf?


```
enable dns
resolv rewrite
set vj slotcomp off
set crtscts on
disable lqr
disable echo
disable ipv6cp
```
Another handfull of confusing options. Where is this documented!? How do I know what will work with my particular modem? ... Am I right in assuming that for each and every u3g ppp.conf I've come across so far, the author simply didn't bother with finetuning the configuration for the most minimal and simple configuration possible? The honestly look like copies of each other.

Hope to get this mess sorted out soon, thanks in advance guys!


----------



## dead (Nov 27, 2011)

I'm back with some logs and configs.

Disabling the option "ipv6cp" removed a whole lot of errors from /var/log/ppp.log.

/etc/ppp/ppp.conf

```
huawei:

 set device /dev/cuaU0.0
 set phone *99***2\#
 set speed 360800

 set dial "ABORT BUSY ABORT NO\\sCARRIER TIMEOUT 5 \
           \"\" \
	   AT OK-AT-OK \
	   AT+CSQ OK \
	   AT+CGDCONT=2,\\\"IP\\\",\\\"bredband.tre.se\\\" OK \
	   ATD*99***2# CONNECT"

 set timeout 180
 set ifaddr 10.0.0.1/0 10.0.0.2/0 255.255.255.255 0.0.0.0
 add default HISADDR

 enable dns
 disable ipv6cp
```

/var/log/ppp.log

```
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: deflink: RecvConfigRej(4) state = Req-Sent
Nov 27 01:14:49 morgue ppp[1533]: tun0: LCP: deflink: SendIdent(1) state = Opened
Nov 27 01:14:49 morgue ppp[1533]: tun0: LCP:  MAGICNUM 77c2a42f
Nov 27 01:14:49 morgue ppp[1533]: tun0: LCP:  TEXT user-ppp 3.4.2
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  COMPPROTO[6] 16 VJ slots with slot compression
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: deflink: SendConfigReq(5) state = Req-Sent
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  IPADDR[6] 0.0.0.0
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  PRIDNS[6] 10.11.12.13
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  SECDNS[6] 10.11.12.14
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: deflink: RecvConfigReq(13) state = Req-Sent
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:   [EMPTY]
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: deflink: SendConfigAck(13) state = Req-Sent
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:   [EMPTY]
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: deflink: State change Req-Sent --> Ack-Sent
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: deflink: RecvConfigNak(5) state = Ack-Sent
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  IPADDR[6] 109.58.242.202
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  IPADDR[6] changing address: 0.0.0.0  --> 109.58.242.202
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  PRIDNS[6] 10.11.12.14
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  SECDNS[6] 255.255.255.255
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: Primary nameserver set to 10.11.12.14
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: deflink: SendConfigReq(6) state = Ack-Sent
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  IPADDR[6] 109.58.242.202
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  PRIDNS[6] 10.11.12.14
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  SECDNS[6] 255.255.255.255
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: deflink: RecvConfigAck(6) state = Ack-Sent
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  IPADDR[6] 109.58.242.202
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  PRIDNS[6] 10.11.12.14
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP:  SECDNS[6] 255.255.255.255
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: deflink: State change Ack-Sent --> Opened
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: deflink: LayerUp.
Nov 27 01:14:49 morgue ppp[1533]: tun0: IPCP: myaddr 109.58.242.202 hisaddr = 10.0.0.2
Nov 27 01:14:49 morgue ppp[1533]: tun0: Warning: 0.0.0.0: Change route failed: errno: No such process
```

Finally. This is what 'ATI' returns.

```
ATI
Manufacturer: huawei
Model: E367
Revision: 11.807.05.00.00
IMEI: 860108010197564
+GCAP: +CGSM,+DS,+ES

OK
```


----------



## dead (Nov 28, 2011)

When I dial the led is activated and set to blue. The interface tun0 is created and assigned an IP (see ppp.log). I can't ping the DNS or the gateway (10.0.0.2). I feel like I'm very close here guys, just missing out on some small setting. I will post ifconfig and netstat information.


----------



## dead (Nov 28, 2011)

ifconfig tun0

```
tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1500
	options=80000<LINKSTATE>
	inet 95.209.13.22 --> 10.0.0.2 netmask 0xffffff00 
	nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
	Opened by PID 2602
```
netstat -rn

```
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            10.0.0.2           UGS         0        1   tun0
10.0.0.2           link#15            UHS         0        0   tun0
95.209.13.22       link#15            UHS         0        0    lo0
127.0.0.1          link#14            UH          0       32    lo0

Internet6:
Destination                       Gateway                       Flags      Netif Expire
::/96                             ::1                           UGRS        lo0
::1                               ::1                           UH          lo0
::ffff:0.0.0.0/96                 ::1                           UGRS        lo0
fe80::/10                         ::1                           UGRS        lo0
fe80::%lo0/64                     link#14                       U           lo0
fe80::1%lo0                       link#14                       UHS         lo0
ff01::%lo0/32                     ::1                           U           lo0
ff02::/16                         ::1                           UGRS        lo0
ff02::%lo0/32                     ::1                           U           lo0
```


----------



## gpw928 (Nov 30, 2011)

Hi,

I can't diagnose your problem, but I can show you a working 3G ppp setup.

I normally have my Huawei E1762 USB 3G modem plugged into my Billion router where it provides the Internet gateway for the entire home network.  However, life was not always so easy, as the Billion firmware used to be troublesome on cloudy days (despite a dual bandwidth 3G antenna on a 6.5 m mast).

On those cloudy days, I would switch the 3G modem to a USB port on my FreeBSD system.  The ppp configuration file I use to dial out is shown below.

The linkup and linkdown scripts show the default route being managed (moved between the ppp link and the Billion router).

The IP address of the Billion router is 192.168.1.254 (host name is billion).

Below is the ifconfig and netstat with the Billion router providing the default route (no ppp) and then with ppp running and providing the default route.

What's not shown is that when ppp is running, I usually also turn off the Billion router and push its IP address as an alias onto em0 (my kernel routes) -- so the the old default route still works for everything else on the network.

My ISP identifies itself as "internode" and the script tag "internerd" is for them.

Upon review, there are a couple of things that worry me below, including a netmask of 0xffffffff.  I need to investigate this.  But it works reliably.

/etc/ppp/ppp.conf


```
# Run this as root (if you want linkup and linkdown route changes to work)
#
#   /usr/sbin/ppp -ddial internerd
#
default:
 allow users *
 #set log Phase Chat Connect hdlc LCP IPCP IPV6CP CCP tun
 set log Phase Chat Connect
internerd:
 set device /dev/cuaU0.0
 set timeout 0
 set authname my.login.name
 set authkey my.login.password
 set dial "ABORT BUSY ABORT NO\\sCARRIER TIMEOUT 5 \
        \"\" \
        AT OK-AT-OK \
        AT+CFUN=1 OK-AT-OK \
        AT+CMEE=2 OK-AT-OK \
        AT+CSQ OK \
        AT+CGDCONT=1,\\\"IP\\\",\\\"internode\\\" OK \
        AT+CGACT? OK-AT-OK \
        AT+CGATT? OK \
        AT+CGCLASS? OK \
        AT+COPS? OK \
        \\dATD*99# TIMEOUT 40 CONNECT"
 set crtscts on
 disable vjcomp
 disable acfcomp
 disable deflate
 disable deflate24
 disable pred1
 disable protocomp
 disable mppe
 disable ipv6cp
 disable lqr
 disable echo
 nat enable yes
 #disable dns
 resolv writable
 #set dns 208.67.220.220 208.67.222.222
 set ifaddr 10.1.0.2/0 10.1.0.1/0 255.255.255.255 0.0.0.0
 #add default HISADDR
```

/etc/ppp/ppp.linkup


```
# These commands executed with uid of ppp invoker!
internerd:
 shell route delete default
 shell route add default -interface INTERFACE
```

/etc/ppp/ppp.linkdown


```
# These commands executed with uid of ppp invoker!
default:
 shell logger "LABEL down (up UPTIME): OCTETSIN received, OCTETSOUT sent"
internerd:
 shell route delete default
 shell route add default billion
```

[CMD=""]ifconfig -a # before dialing out[/CMD] 


```
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
     options=209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC>
     ether 00:07:e9:d4:e9:3b
     inet 192.168.1.24 netmask 0xffffff00 broadcast 192.168.1.255
     media: Ethernet autoselect (1000baseT <full-duplex>)
     status: active
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
     options=3<RXCSUM,TXCSUM>
     inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
     inet6 ::1 prefixlen 128
     inet 127.0.0.1 netmask 0xff000000
     nd6 options=3<PERFORMNUD,ACCEPT_RTADV>
```

[CMD=""]netstat -rn # before dialing out[/CMD]


```
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            192.168.1.254      UGS         0    10260    em0
127.0.0.1          link#4             UH          0      215    lo0
192.168.1.0/24     link#2             U           2     9870    em0
192.168.1.24       link#2             UHS         0        0    lo0
```

[CMD=""]ifconfig -a # after dialing out[/CMD]


```
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
    options=209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC>
    ether 00:07:e9:d4:e9:3b
    inet 192.168.1.24 netmask 0xffffff00 broadcast 192.168.1.255
    media: Ethernet autoselect (1000baseT <full-duplex>)
    status: active
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
    options=3<RXCSUM,TXCSUM>
    inet 127.0.0.1 netmask 0xff000000
tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1500
    options=80000<LINKSTATE>
    inet 59.167.9.135 --> 10.1.0.1 netmask 0xffffffff
    Opened by PID 1634
```

[CMD=""]netstat -rn # after dialing out[/CMD]


```
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            tun0               US          0        5   tun0
10.1.0.1           link#5             UHS         0        0   tun0
59.167.9.135       link#5             UHS         0        0    lo0
127.0.0.1          link#4             UH          0        0    lo0
192.168.1.0/24     link#2             U           2      808    em0
192.168.1.24       link#2             UHS         0        0    lo0
```

I have attached the ppp log View attachment ppp_log.txt.

HTH.

-- 
Phil


----------



## dead (Nov 30, 2011)

Hey Phil! Thank's for your reply 

I didn't have a ppp.linkup before, so I made one real fast.
ppp.linkup

```
add default HISADDR
```

Now, this still didn't work. I think the problem lies with the external IP "binds" ( I'm not good in networking) to lo0 in *netstat -rn*, rather than tun0.

I'm short on time here, but I will be back later. Again, thank you for your time


----------



## gpw928 (Dec 1, 2011)

Hi,

There are two ways you can add the default route.  One is in ppp.conf (this uses a specific IP address):


```
add default HISADDR
```

The other is from the ppp.linkup script (this uses an interface):


```
shell route add default -interface INTERFACE
```

They achieve a similar result in slightly different ways.

I used the latter because it was easier in the context of the scripts that I needed (linkup and linkdown) to manage the default route moving from and to the Billion router.

Your *netstat -rn* output suggests you did the former, which is OK.

Your ppp log entries suggest that the ppp link is up:


```
ppp[1533]: tun0: IPCP: deflink: LayerUp.
ppp[1533]: tun0: IPCP: myaddr 109.58.242.202 hisaddr = 10.0.0.2
```
 
Your default route should be via "hisaddr" (10.0.0.2) and it is:


```
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            10.0.0.2           UGS         0        1   tun0
10.0.0.2           link#15            UHS         0        0   tun0
```

You should not necessarily expect to be able to ping "hisaddr" (the outcome depends on the setup at your ISP).  It's also possible that your DNS setup may be not quite right.  This could explain why your tests are proving negative.

I can't see anything clearly wrong with your setup.  I agree that you are very close.  In fact, maybe it is working.  Try to ping google.com (without using the DNS):


```
ping 74.125.237.116
```

Cheers,

-- 
Phil


----------

