Tuesday, December 10, 2013

How to Setup a USB 3G Modem – Linux / Raspberry Pi

How to setup a USB 3G Modem on Raspberry PI using usb_modeswitch and wvdial

clip_image001 
Setting up a USB 3G/4G modem on a Raspberry Pi is not a simple task. There are many guides available using the now defunctsakis3g script, but getting my modem to work required a bit more understanding.

The main problem is that most USB modems act as two devices - a USB storage device and a USB modem. When plugged in to the Raspberry PI the device is usually in USB storage mode. There is a program calledusb_modeswitch that we can use to do the switching

The other missing part is a way to connect to the cellular network with the USB modem from the Raspberry. For this we will use the classic pppand wvdial programs.
Requirements

  • Raspberry PI computer
  • Raspbian OS installed
  • USB 3G Modem
  • 5V 1A power supply for the Raspberry PI
    ________________________________________

1. Install required software

  • Connect your Raspberry PI to the internet via LAN or Wifi
  • Open a terminal window and enter:

sudo apt-get update
sudo apt-get install ppp wvdial
sudo aptitude install usb-modeswitch

2. Get the USB switching codes

  • We need to get the codes of the USB device in USB storage mode and USB modem mode.
  • Connect your USB modem and reboot the Raspberry PI without LAN or Wifi connection
  • Once rebooted open a terminal window and enter:

lsusb

  • The output will look similar to the screenshot below. Your modem should be listed as one of the USB devices. Note the numbers underlined. These are the device vendor and product codes.

clip_image002[5]

  • Make a note of these numbers. In this case it is 19d2:2000
  • This value will later be used in the DefaultProduct value
  • Then we need to soft reboot the Rapberry PI with the modem connected.
  • Open a terminal window and enter:

sudo reboot

  • Once rebooted open a terminal window and enter:

lsusb

  • The output will look similar to the screenshot below. Your modem should be listed and if you are lucky the second set of numbers would have changed. This is usb_modeswitch doing it's job and switching the device to USB modem mode.

clip_image002

  • Make a note of the new numbers. In this case it is 19d2:2002
  • This value will be used later in the TargetProduct value

3. Create custom usb_modeswitch config file

  • We need to create a custom config file for usb_modeswitch on the Raspberry PI because on a cold boot the device is not always active yet when usb_modeswitch runs on startup and the device is left in USB storage mode.
  • We will extract some more information for our usb_modeswitch config file so that we can do the switching manually.
  • Open a terminal window and enter the following replacing the codes 19d2 and 2000 with the codes you noted in step 2. Also note the added backslash.

cd /tmp
tar -xzvf /usr/share/usb_modeswitch/configPack.tar.gz 19d2\:2000

  • Now open the extracted file with a text editor like leafpad replacing the codes noted in step 2.

nano 19d2:2000

  • The content of the file should look something similar to the screenshot below.
  • The parts we are interested in are shown in blue.

clip_image002[7]

  • Now open the /etc/usb_modeswitch.conf file and add the information obtained above to the file.
  • Open a terminal window and enter:

sudo nano /etc/usb_modeswitch.conf

  • Then add the following replacing the codes and MessageContent values with those of your device and save.

DefaultVendor=0x19d2
DefaultProduct=0x2000

TargetVendor=0x19d2
TargetProduct=0x2002

MessageContent="5553424312345678000000000000061e000000000000000000000000000000"
MessageContent2="5553424312345679000000000000061b000000020000000000000000000000"
MessageContent3="55534243123456702000000080000c85010101180101010101000000000000"

4. Create the wvdial config file

  • The next step is to create a config file for wvdial so you can connect to your service provider.
  • Open a terminal window and enter:

sudo nano /etc/wvdial.conf

  • Replace the content of the file with the following.

[Dialer 3gconnect]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 = AT+CGDCONT=1,"IP","internet"
Stupid Mode = 1
Modem Type = Analog Modem
ISDN = 0
Phone = *99#
Modem = /dev/gsmmodem
Username = { }
Password = { }
Baud = 460800

For the portuguese mobile operators configurations just check: http://myhowtosandprojects.blogspot.pt/2012/04/configuracoes-3g-e-mms-portugal.html 

  • Replace internet with your service provider's APN
  • Replace the Phone number if you need to dial a different code to connect.
  • Replace Username and Password if needed. To leave the username and password as blank use { }

5. Connect to the internet

  • To connect we need to make sure the device is in modem mode.
  • First get the actual modem state (CD-ROM):

lsusb

Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 19d2:2000 ZTE WCDMA Technologies MSM MF627/MF628/MF628+/MF636+ HSDPA/HSUPA

  • Open a terminal and enter:

sudo usb_modeswitch -c /etc/usb_modeswitch.conf

to change the from the CD-ROM mode to the modem mode

Now check that the mode switch occured:

lsusb

Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 005: ID 19d2:0031 ZTE WCDMA Technologies MSM MF110/MF627/MF636

  • Then connect to the internet with:

wvdial 3gconnect

6. Problems

If you have problems with the “wvdial”, you shoul run

wvdialconf

this will scan your system for modems, if it finds one, it will do some tests to determine your modem’s parameters, and write them to a template config in /etc/wvdial.conf :

Editing `/etc/wvdial.conf'.

Scanning your serial ports for a modem.

ttyUSB0<*1>: ATQ0 V1 E1 -- failed with 2400 baud, next try: 9600 baud
ttyUSB0<*1>: ATQ0 V1 E1 -- failed with 9600 baud, next try: 9600 baud
ttyUSB0<*1>: ATQ0 V1 E1 -- and failed too at 115200, giving up.
ttyUSB1<*1>: ATQ0 V1 E1 -- OK
ttyUSB1<*1>: ATQ0 V1 E1 Z -- OK
ttyUSB1<*1>: ATQ0 V1 E1 S0=0 -- ERROR
ttyUSB1<*1>: ATQ0 V1 E1 &C1 -- ERROR
ttyUSB1<*1>: ATQ0 V1 E1 &D2 -- ERROR
ttyUSB1<*1>: ATQ0 V1 E1 +FCLASS=0 -- OK
ttyUSB1<*1>: Modem Identifier: ATI -- Manufacturer: ZTE INCORPORATED
ttyUSB1<*1>: Speed 9600: AT -- OK
ttyUSB1<*1>: Max speed is 9600; that should be safe.
ttyUSB1<*1>: ATQ0 V1 E1 +FCLASS=0 -- OK
ttyUSB2<*1>: ATQ0 V1 E1 -- OK
ttyUSB2<*1>: ATQ0 V1 E1 Z -- OK
ttyUSB2<*1>: ATQ0 V1 E1 S0=0 -- ERROR
ttyUSB2<*1>: ATQ0 V1 E1 &C1 -- ERROR
ttyUSB2<*1>: ATQ0 V1 E1 &D2 -- ERROR
ttyUSB2<*1>: ATQ0 V1 E1 +FCLASS=0 -- OK
ttyUSB2<*1>: Modem Identifier: ATI -- Manufacturer: ZTE INCORPORATED
ttyUSB2<*1>: Speed 9600: AT -- OK
ttyUSB2<*1>: Max speed is 9600; that should be safe.
ttyUSB2<*1>: ATQ0 V1 E1 +FCLASS=0 -- OK

Found a modem on /dev/ttyUSB1.
Modem configuration written to /etc/wvdial.conf.

ttyUSB1<Info>: Speed 9600; init "ATQ0 V1 E1 +FCLASS=0"
ttyUSB2<Info>: Speed 9600; init "ATQ0 V1 E1 +FCLASS=0"

You config template should look something like this:

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 +FCLASS=0
Modem Type = Analog Modem
; Phone = <Target Phone Number>
ISDN = 0
; Password = <Your Password>
; Username = <Your Login Name>
Modem = /dev/ttyUSB1
Baud = 9600

go to step 4 and change:

[Dialer 3gconnect]
Init1 = ATZ

Init2 = ATQ0 V1 E1 +FCLASS=0
Init3 = AT+CGDCONT=1,"ip","internet"
Stupid Mode = 1
Modem Type = Analog Modem
ISDN = 0
Phone = *99#
Modem = /dev/ttyUSB1
Username = tmn
Password = tmn
Baud =
9600

and then try again:

wvdial 3gconnect

Base on: http://www.thefanclub.co.za/how-to/how-setup-usb-3g-modem-raspberry-pi-using-usbmodeswitch-and-wvdial

Related Info:

Sunday, December 8, 2013

Setting up Wifi via the Command Line – Linux/Raspberry Pi (WPA2)

image

The Raspberry Pi has many great features straight out of the box,  unfortunately WiFi is not one of them, in this guide I’ll show you how I WiFi equipped my Raspberry PI for only a fiver.
We will be assuming that you have a head less setup (without a monitor) so the guide should work for everyone, either via SSH (remote) or via a local terminal session if you do have a monitor.
Also its worth noting that some WiFi adapters will require a powered USB hub between the Raspberry PI and the USB module, the one used below doesn’t due to it’s power consumption assuming you don’t have anything else drawing large currents from the USB power.

1. What you will need…

  • Raspberry Pi, with Wheezy
  • Internet Connection (via the ethernet port to begin with)
  • WiFi network to test on image
  • USB WiFi Dongle, either of the below work:
  • Amazon Link (USA Amazon)
  • Amazon Link or Amazon Link (UK Amazon)


2. Update the OS

There are so many times you will run into a bug when installing something new and find out that it would have worked if your system was up to date, taking no risks here so get your system updated

sudo apt-get update
sudo apt-get upgrade

Due to the RAM/CPU power on the Pi’s, this might take a while, brew anyone? 
  
 
3. Reboot

Power down the device, install your WiFi USB module and turn it back on.


4. Setup the interface configuration

sudo nano /etc/network/interfaces

Normally your base configuration will look something like this?

  allow-hotplug wlan0
 
  iface wlan0 inet manual
  wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

  iface default inet dhcp

Assuming you have a DHCP server on your LAN (normally your DSL/Cable router) use the following configuration, your SSID and password will be put in the wpa_supplicant.conf later on in this guide.

## FILE: /etc/network/interfaces ##
  allow-hotplug wlan0
 
  iface wlan0 inet manual
  wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

  iface wlan0 inet dhcp

If you don’t have a DHCP server, or if you want to just statically assign the IP address you can use the following, however update the IP, Netmask and Gateway to match your network.

## FILE: /etc/network/interfaces ##
  allow-hotplug wlan0
 
  iface wlan0 inet manual                           
  wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
   
  iface wlan0 inet static
  network 192.168.1.0
  address 192.168.1.249
  netmask 255.255.255.0
  gateway 192.168.1.254
  broadcast 192.168.1.255
 

5. Setup the WPA configuration

Finally you will want to edit the WPA configuration as below, don’t forget to update it for your SSID and WPA password!

## FILE: /etc/wpa_supplicant/wpa_supplicant.conf ##
  network={
  ssid="SSID-GOES-HERE"
  proto=RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP TKIP
  group=CCMP TKIP
  psk="WIFI-PASSWORD-GOES-HERE"
  }

6. Final Reboot

Ok that should be it, do a final reboot remove the wired ethernet cable and your IP should automatically come onto the network as a normal WiFi device.

OR do the the following if you don’t want to reboot:

sudo ifdown wlan0
sudo ifup wlan0
   

Problems?

First

This device should work out of the box, if for any reason it doesn’t you will want to do the following:

sudo wget http://dl.dropbox.com/u/80256631/install-rtl8188cus-latest.sh -O /boot/install-rtl8188cus-latest.sh

sudo /boot/install-rtl8188cus-latest.sh

Now go back to step 3 and try again.


Second

Run the below command, you should see your WiFi device there? If not there could be an issue with the hardware, try it in another PC…

lsusb

You should see a line that looks like this:

Bus 001 Device 005: ID 0bda:8189 Realtek Semiconductor Corp. RTL8187B Wireless 802.11g Network adapter.

Based On: http://pingbin.com/2012/12/setup-wifi-raspberry-pi/

 

About WPA2 (aka IEEE 802.11i-2004) & WPA SUPLICANT

Short for Wi-Fi Protected Access 2, the follow on security method to WPA for wireless networks that provides stronger data protection and network access control.

It provides enterprise and consumer Wi-Fi users with a high level of assurance that only authorized users can access their wireless networks.

Based on the IEEE 802.11i standard, WPA2 provides government grade security by implementing the National Institute of Standards and Technology (NIST) FIPS 140-2 compliant AES encryption algorithm and 802.1x-based authentication.  [Adapted from Wi-Fi.org]

There are two versions of WPA2:

  • WPA2-Personal (password)
  • WPA2-Enterprise (server authentication)

WPA2-Personal protects unauthorized network access by utilizing a set-up password. WPA2-Enterprise verifies network users through a server. WPA2 is backward compatible with WPA.

LINKS

Saturday, December 7, 2013

Setting up Wifi via the Command Line – Linux/Raspberry Pi (WPA aka WPA1)

Setting up Wifi with the Command Line

Created by Simon Monk

This tutorial works best if your router is broadcasting the SSID. Make sure you have "Broadcast SSID" set up on your router! This may not work with "private" SSID setups

Setting up WiFi in Occidentalis, is also pretty straight forward. You just need to add the name of your wireless network (its SSID) and your password to a configuration file.

Step 1.

Boot the Raspberry Pi without the WiFi adapter plugged in.

Step 2.

Open a Terminal session by clicking on the LXTerminal icon, and enter the following command into it:

Copy Code

1. sudo nano /etc/network/interfaces

clip_image002

    auto lo

    iface lo inet loopback
    iface eth0 inet dhcp

    allow-hotplug wlan0
    auto wlan0

    iface wlan0 inet dhcp
    wpa-ssid "ssid"
    wpa-psk "password"

If you are using a 'hidden' SSID, try the following (hat-tip to http://www.dafinga.net/2013/01/how-to-setup-raspberry-pi-with-hidden.html)

    auto lo

    iface lo inet loopback
    iface eth0 inet dhcp

    auto wlan0
    allow-hotplug wlan0
    iface wlan0 inet dhcp
    wpa-scan-ssid 1
    wpa-ap-scan 1
    wpa-key-mgmt WPA-PSK
    wpa-proto RSN WPA
    wpa-pairwise CCMP TKIP
    wpa-group CCMP TKIP
    wpa-ssid "My Secret SSID"
    wpa-psk "My SSID PSK"

    iface default inet dhcp

Step 3.

This opens an editor screen of the wifi configuration file you need to change.

clip_image004

The two places where you need to make a change are on the last two lines. Change the file so that it looks like this:

clip_image006

Of course, you should put in your network and password! Note that you need to keep the double-quote characters around your wireless network name and password.

This kind of editor does not let you use the mouse. Instead, use the cursor keys to move around the file.

Step 4.

When you have finished press [ctrl]x. This will ask if you want to save the modified files.

clip_image008

Press 'Y' and then Return to save the file with the same name.

Step 5.

Shut down your Raspberry Pi, plug the WiFi adapter in and start it up again. You should find that the Raspberry Pi connects using the WiFi adapter as it boots up.

Taken From: http://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup/setting-up-wifi-with-occidentalis