Download This PDF! - Linux Magazine
  • No tags were found...

Download This PDF! - Linux Magazine

COVER STORYBluetooth with GPRSUsing your mobile phone as a wireless modemLAP CONNECTIONIf your mobile phone contract includes GPRS mobile Internet service,you can use a Bluetooth phone as a wireless modem for your Linuxportable computer. BY KLAUS KNOPPERIf you remember the days when computersconnected to the Internetthrough telephone lines, you mightbe wondering whether it is possible touse an Internet-enabled cellphone orPDA as a wireless Internet connectionfor a roaming laptop computer. This articledescribes a technique for connectinga Linux portable computer to the Internetthrough a Bluetooth connection to amobile phone. Of course, this procedurerequires a mobile phone service planthat comes with some form of Internetconnectivity.The example configuration describedin this article assumes Internet accessthrough General Packet Radio Service(GPRS), a mobile networking architecturesupported by many wireless providers.A similar approach may also workfor other service types. If your serviceplan provides Internet access throughan alternative method, consult yourprovider for details and adapt the proceduresdescribed in this article for yourown environment.01 knopper@Koffer:~$ dmesg | tail02 usb 1-2: configuration #1chosen from 1 choice03 Bluetooth: HCI USB driver ver2.904 usbcore: registered newinterface driver hci_usb05 usb 1-2: USB disconnect,address 206 usb 1-2: new full speed USBBluetooth AdapterBefore you even start to configuremodem emulation for the cellphone connection,you have to make sure the Bluetoothadapter on your computer is workingunder Linux. The task of bringing upthe Bluetooth adapter is fairly uncomplicatedwith current versions of the Linuxkernel, provided all Bluetooth-relatedkernel options are activated. Make sureyou have the bluez-utils package installed,and plug in the adapter. Run theBluetooth hci daemon if it is not alreadyrunning,sudo U/etc/init.d/bluetooth startListing 1: dmesg | tail outputdevice using uhci_hcd andaddress 307 usb 1-2: configuration #1chosen from 2 choices08 Bluetooth: BlueFRITZ! USBdriver ver 1.109 bfusb_probe: Firmware requestfailed10 bfusb: probe of 1-2:1.0failed with error -534 ISSUE 80 JULY 2007 W W W. L I N U X- M A G A Z I N E . C O M

Bluetooth with GPRSCOVER STORYor if you have an older Debian:sudo U/etc/init.d/bluez-utils startIf the Bluetooth daemon is present,the adapter will appear when you enterhcitool dev:knopper@Koffer:~$ hcitool devDevices:hci0 00:03:0D:00:71:8EIf this command is successful, just proceedto the next section and get startedwith configuring modem emulation.Unfortunately, some Bluetooth adapters,such as the AVM BlueFritz, don’tcome with preloaded firmware. You willnotice this from the output of the commanddmesg | tail shown in Listing 1.My preferred procedure is to use a“normal” Bluetooth adapter with firmwareinside; however, you can get the01 #!/bin/bash0203 PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin"04 export PATH0506 TITLE="BLUETOOTH PIN"0708 umask 0770910 TMP="/tmp/btpin.$$"1112 PIN=""1314 X="$(/bin/ps --format args15--no-headers -C X -C XFree86-C Xorg 2>/dev/null)"16 XAUTHORITY=""17 DISPLAY=""1819 if [ -n "$X" ]; then20 DISPLAY=":0"21 authfile=""22 for i in $X; do23 [ -n "$authfile" ] && exportXAUTHORITY="$i"AVM Bluetooth adapter to work by justcopying the firmware file bfubase.frmfrom the Internet or the driver CD. Thefollowing procedure is suggested in theGentoo AVM adapter HOWTO:root@Koffer# cd U/usr/lib/hotplug/firmwareroot@Koffer# wget U replugging the adapter, dmesgshould report:Bluetooth: BlueFRITZ! UUSB loading firmwareBluetooth: BlueFRITZ! UUSB device readyModem EmulationThe other part of this Bluetooth GPRSconfiguration is activating the serial lineListing 2: /usr/ local/ bin/ btpin.sh24 case "$i" in :*) exportDISPLAY="$i" ;; -auth)authfile="true"; continue ;;esac25 authfile=""26 done27 fi2829 if [ -n "$DISPLAY" ]; then30 DIALOG=Xdialog31 else32 DIALOG=dialog33 exec >/dev/console &136 rm -f "$TMP"3738 $DIALOG --title "$TITLE"39--insecure --passwordbox"$TITLE" 8 35 2>"$TMP"40 PIN="$(cat $TMP)"41 rm -f "$TMP"4243 [ -n "$PIN" ] && echo"PIN:$PIN" || echo "ERR"or modem emulation of the Bluetoothstack. Your cellphone now will act verymuch like a regular modem. For this,you need to create a connection betweenyour Bluetooth adapter and the cellphone,which means you have to definehow the connection is made between theadapter and the phone.You will need to find out which hardwareaddress your cellphone uses. If thecellphone's address is not listed anywherein the configuration menu of thecellphone, switch on “Bluetooth visibility”for a brief time so you’ll be ableto scan the Bluetooth environment fromyour computer with hcitool:root@Koffer# hcitool scan UScanning … U00:01:E3:07:3E:1A Blauer KlausWhat looks like a MAC address for aLAN adapter is the hardware addressyou need for setting up a “serial line” toissue modem-like commands.The text behind the address in thehcitool output is actually the Bluetoothname, which you set in your cellphone’sconfiguration menu.After finding out the Bluetooth hardwareaddress, switch to Enabled with NoBroadcast Bluetooth mode to keep peoplefrom bluejacking your cellphone.The Hidden mode is sufficient if youknow the cellphone’s address.Next, edit /etc/bluetooth/rfcomm.confand add this configuration section:rfcomm0 {bind yes;device 00:01:E3:07:3E:1A;channel 1;comment "Blauer Klaus";}Listing 3: /etc/ chatscripts/gprs01 TIMEOUT 12002 ABORT BUSY03 ABORT "NO CARRIER"04 ABORT ERROR05 "" 'ATE1'06 OK AT+CGDCONT=1,"IP","internet"07 OK ATD*99***1#08 CONNECT \d\cW W W. L I N U X- M A G A Z I N E . C O MISSUE 80 JULY 200735

COVER STORYBluetooth with GPRS01 # You usually need this ifthere is no PAP authentication02 noauth03 # The chat script for talkingto the modem04 connect "/usr/sbin/chat -v -f/etc/chatscripts/gprs"05 # Set up routing to go throughthis PPP link (the ip-upscript does this now)06 nodefaultroute07 # modem port (/dev/ircomm0 forIRDA)08 # /dev/ircomm009 /dev/rfcomm010 # Speed11 11520012 # Ignore carrier detect signalListing 4: /etc/ ppp/ peers/ gprsfrom the modem:13 local14 modem15 # Keep modem up even ifcurrent connection fails16 persist17 # Use hardware flow controlwith cable, Bluetooth, andUSB.18 crtscts19 # Be extra verbose20 debug21 # Let the server handle allconfiguration22 passive23 noipdefault24 ipcp-accept-local25 ipcp-accept-remote26 ipcp-restart 427 ipcp-max-configure 2028 ipcp-max-failure 2029 lcp-echo-interval 430 lcp-echo-failure 031 # Special protocol options32 # asyncmap 0xa000033 novj34 nodeflate35 nobsdcomp36 # Tell pppd to set up DNSservers set above37 usepeerdns38 # Leave username blank.Really!39 user ""If rfcomm0 is already used by differenthardware, you might want to use a differentrfcomm device number (alsoshown in the example configurationbelow).Instead of restarting Bluetooth nowwith the command /etc/init.d/bluetoothrestart, you can just add a binding forrfcomm0:root@Koffer# rfcomm bind Urfcomm0 00:01:E3:07:3E:1Aand check with:root@Koffer# rfcommto see whether the device is correctlylisted as clean or closed (unless it’salready in use).Shaking HandsBefore you can successfully launch aconnection to the cellphone via /dev/rfcomm0, you have to solve a problemrelated to the Bluetooth handshake procedure,which requires typing the sameBluetooth PIN or password on both yourcomputer and the cellphone.Whereas your cellphone will just presenta dialog asking for a PIN (which isnot the secret PIN number that protectsyour phone from unauthorized phonecalls), mechanisms for entering the Bluetoothhandshake PIN vary a lot withdifferent GNU/ Linux distributions.In older versions of bluez-utils, a PINhelper program was specified in /etc/bluetooth/hcid.conf with the pin_helperoption.This option is missing from newerversions and is replaced with dbus application-levelmessage exchange. ThisUniversal Mobile TelecommunicationsService (UMTS) is an alternative mobilenetworking technology. Portable computersoften connect to UMTS mobilenetworks with UMTS-ready PCMCIAcards. The UMTS PCMCIA solution is analternative to the Bluetooth cellphoneoption in some locations.What /dev/rfcomm* is for Bluetooth cellphones,/dev/ttyS* is for UMTS PCMCIAcards. The hardware configuration partis again easy: A UMTS PCMCIA cardshould identify itself as a PCMCIA serialmodem, which you can check by lookinginto the dmesg output after inserting thecard. Let’s assume for now that the cardwill show up as ttyS2. All mention of/dev/rfcomm0 should be changed to /dev/ttyS2 in the previous GPRS configurationfiles.For locally installed cards, no Bluetoothhandshake is necessary, but anotherproblem occurs: like many cellphones,the card is usually protected by a personalPIN number that you must enterimmediately after switching the deviceon. In this case, you can submit the PINwith the AT commandAT+CPIN=1234UMTSwhich has to be sent to the card’scorresponding serial device about fourseconds before sending the first configurationor dial commands. The 1234 isthe personal PIN number associated withthe card (usually printed in the documentsthat you received when buyingthe card).When entering this PIN, which is entirelydifferent from the Bluetooth handshakePIN, instead of sending the PIN manually,you could change the gprs chatscriptto something similar to the scriptin Listing 5, which is based on the eplusUMTS PCMCIA card.The 1234 has to be replaced by thecorrect personal PIN, of course.Please be aware that some cards willonly allow up to two or three failed attemptson entering the PIN, at whichpoint the card will be permanentlyblocked.The card will be blocked until either a differentcode is entered to unlock the PINor the card is sent to the vendor’s supportservice to get unlocked.The PPP configuration file will have to bechanged, at least to use a different serialport (Listing 6).36 ISSUE 80 JULY 2007 W W W. L I N U X- M A G A Z I N E . C O M

Bluetooth with GPRSCOVER STORYmeans it is no longer sufficient to directlyuse a small dialog/ Xdialog-basedshell script like the one in Listing 2 forkey exchange.Luckily, it is still possible to use ascript similar to Listing 2 with the newdbus-based passkey-agent, which iscurrently located in the kdebluetoothDebian package, even though it is just aconsole program that can be called with:knopper@Koffer:~U$ passkey-agent --default U/usr/local/bin/ &PIN on DemandBecause passkey-agent does not requireroot privileges to listen on dbus, you canstart passkey-agent as a normal user,which makes access to the graphicaldisplay easier in the actual PIN inputreader. (For instance, you could so it does not have to extractxauth cookies.)Some Linux distributions might requireyou to store the Bluetooth PIN foroutgoing connections in a file such as/etc/bluetooth/pin, but I think that providingthe PIN on demand is a betterapproach.Listing 5: /etc/ chatscripts/umts-with-pin01 TIMEOUT 12002 ABORT BUSY03 ABORT "NO CARRIER"04 "" 'ATE1'05 OK AT+CPIN=123406 TIMEOUT 407 OK-AT+CPIN?-OK AT+CGDCONT=1,"IP",""08 TIMEOUT 12009 ABORT ERROR10 # use OK AT_OPSYS=3,2 toprefer UMTS, but still acceptGPRS (default setting?)11 OK ATD*99***1#12 CONNECT \d\cChat and PPPOnce a modem connection to the cellphone is configured, you can set up achat script for a GPRS connection (Listing3). The line AT+CGDCONT=1,"IP","internet" is the correct setting for networkprovider O2; other possibilitiescould be:eplus: AT+CGDCONT=U1,"IP",""vodafone: AT+CGDCONT=U1,"IP",""D1: AT+CGDCONT=U1,"IP",""The line:ATD*99***1#actually initiates the GPRS “dialing” process,which will then require the PPPprotocol for local authentication and IPconfiguration.A PPP setup similar to the configurationshown Listing 4 should work withmost cellphones. Please note that youleave the “user” option argument emptyhere because authentication against yourprovider’s customer database is reallydone through your phone number andListing 6: /etc/ ppp/ peers/umts01 noauth02 connect "/usr/sbin/chat -v -f/etc/chatscripts/umts-with-pin"03 nodefaultroute04 /dev/ttyS205 11520006 local07 modem08 persist09 crtscts10 passive11 noipdefault12 ipcp-accept-local13 ipcp-accept-remote14 ipcp-restart 415 ipcp-max-configure 2016 ipcp-max-failure 2017 lcp-echo-interval 418 lcp-echo-failure 019 novj20 nodeflate21 nobsdcomp22 usepeerdns23 user ""the cellphone’s IMEI device identification.pppd merely handles a reliableconnection between your cellphoneand your computer on the TCP/ IP level,so your cellphone almost looks like anetwork card to your computer.Getting ConnectedAfter adding the configuration files describedin this article and setting theparameters to match your provider andcellphone or UMTS card, you can getconnected by starting the PPP daemon:root@Koffer# Upppd nodetach call gprsIf you want to see a more verbosedescription of what’s happening, adddebug right after the pppd command.As soon as two lines with IP addressesappear, you are connected. Don’t be confusedby the private IP networks thatpppd displays – these private networksare used internally between your computerand the GPRS provider, and theyare masqueraded via real, routed IPaddresses. However, because of thisdesign, GPRS and UMTS are currentlynot usable for running servers that arevisible from the Internet, except witha tunnel or proxy.A Ctrl-C in the preceding example willend the pppd command and disconnectyour GPRS or UMTS session.With GPRS and UMTS, as opposed toGSM phone mode, traffic is usuallybilled by volume (kilobytes transferred)and not by time. But please look up theactual price list to make sure you canafford it. ■GPRS HintsInteractive response of GPRS and UMTSis horrible; you will experience up tothree seconds of delay between hitting akey and seeing the letter appear in a remoteSSH session. You can get used tothis, but it is uncomfortable. For readingweb pages, you should probably disableautoloading of pictures to save yourphone bill and speed up page downloads.Because GPRS is not designed toautomatically compress transferreddata, you also might experience a dramaticspeed (and cost) improvement byusing a vtun or SSH tunnel to a remoteproxy instead of fetching raw data,especially for text-based protocols likehttp, imap, or pop3.W W W. L I N U X- M A G A Z I N E . C O MISSUE 80 JULY 200737

More magazines by this user
Similar magazines