Krzychu.Net

PLD Linux + bluetooth + palmtop

Sprzęt

Adapter USB Bluetooth Trust BT180, laptop ASUS A3FC-5056 z systemem PLD Linux 2.0 (Ac) i kernelem 2.6.17 oraz palmtop iPAQ hx2490 z systemem WindowsMobile.

Soft

Dla adaptera bluetooth na USB wymagane są moduły do kernela:

 uhci_hcd
 hci_usb
 l2cap
 bnep
Bluetooth jest obsługiwany w Linuxie przez Bluez.
W systemie PLD Linux należy zainstalować następujące pakiety:

  bluez-hcidump-1.30-1
  bluez-utils-init-2.25-3
  bluez-utils-2.25-3
  bluez-hciemu-1.2-1
  bluez-qube-0.1-2
  bluez-libs-2.25-1
  bluez-pin-0.26-2
  ppp-2.4.2-7
oraz sprawdzić obecność urządzeń /dev/rfcomm*

  ls  -la  /dev/rfcomm*
  crw-rw-r--    1  root  ttyS  216,    0  2005-12-16  15:49  /dev/rfcomm0
  crw-rw-r--    1  root  ttyS  216,    1  2005-12-16  15:49  /dev/rfcomm1
  crw-rw-r--    1  root  ttyS  216,  10  2005-12-16  15:49  /dev/rfcomm10
  crw-rw-r--    1  root  ttyS  216,  11  2005-12-16  15:49  /dev/rfcomm11
  crw-rw-r--    1  root  ttyS  216,  12  2005-12-16  15:49  /dev/rfcomm12
  crw-rw-r--    1  root  ttyS  216,  13  2005-12-16  15:49  /dev/rfcomm13
  crw-rw-r--    1  root  ttyS  216,  14  2005-12-16  15:49  /dev/rfcomm14
  crw-rw-r--    1  root  ttyS  216,  15  2005-12-16  15:49  /dev/rfcomm15
  crw-rw-r--    1  root  ttyS  216,    2  2005-12-16  15:49  /dev/rfcomm2
  crw-rw-r--    1  root  ttyS  216,    3  2005-12-16  15:49  /dev/rfcomm3
  crw-rw-r--    1  root  ttyS  216,    4  2005-12-16  15:49  /dev/rfcomm4
  crw-rw-r--    1  root  ttyS  216,    5  2005-12-16  15:49  /dev/rfcomm5
  crw-rw-r--    1  root  ttyS  216,    6  2005-12-16  15:49  /dev/rfcomm6
  crw-rw-r--    1  root  ttyS  216,    7  2005-12-16  15:49  /dev/rfcomm7
  crw-rw-r--    1  root  ttyS  216,    8  2005-12-16  15:49  /dev/rfcomm8
  crw-rw-r--    1  root  ttyS  216,    9  2005-12-16  15:49  /dev/rfcomm9
a w przypadku ich braku wygenerować odpowiednie wpisy skryptem:

  #!/bin/sh 
  C=0;
  while [ $C -lt 16 ]; do
  if [ ! -c /dev/rfcomm$C ]; then
  mknod -m 666 /dev/rfcomm$C c 216 $C
  fi
  C=`expr $C + 1`
  done
Następnie dostosowujemy odpowiednio /etc/bluetooth/hcid.conf.

  #
  # HCI daemon configuration file.
  #

  # HCId options
  options {
	  # Automatically initialize new devices
	  autoinit yes;

	  # Security Manager mode
	  #   none - Security manager disabled
	  #   auto - Use local PIN for incoming connections
	  #   user - Always ask user for a PIN
	  #
	  security auto;

	  # Pairing mode
	  #   none  - Pairing disabled
	  #   multi - Allow pairing with already paired devices
	  #   once  - Pair once and deny successive attempts
	  pairing multi;

	  # PIN helper
  #       pin_helper /bin/bluepin;
          pin_helper /usr/local/bin/sendpin;

  }

  # Default settings for HCI devices
  device {
	  # Local device name
	  #   %d - device id
	  #   %h - host name
	  name "BlueZ (%d)";

	  # Local device class
	  class 0x3e0100;

	  # Default packet type
	  #pkt_type DH1,DM1,HV1;

	  # Inquiry and Page scan
	  iscan enable; pscan enable;

	  # Default link mode
	  #   none   - no specific policy 
	  #   accept - always accept incoming connections
	  #   master - become master on incoming connections,
	  #            deny role switch on outgoing connections
	  #
	  lm accept;
	  #
	  # lm accept,master;

	  # Default link policy
	  #   none    - no specific policy
	  #   rswitch - allow role switch
	  #   hold    - allow hold mode
	  #   sniff   - allow sniff mode
	  #   park    - allow park mode
	  #
	  #lp hold,sniff;
	  #
	  lp hold,sniff,park;

	  # Authentication and Encryption
	  auth enable;
	  #encrypt enable;
  }


W pliku wykonywalnym /usr/local/bin/sendpin umieszczamy PIN którym autentykować się będzie komputer do palmtopa, zawiera on:

  #!/bin/sh
  echo "PIN:123456"
W pliku /etc/bluetooth/pin umieszczamy PIN którym autentykować się będzie palmtop do komputera.
Podłączamy adapter bluetooth do portu usb i startujemy obsługę bluetooth poleceniem


/etc/rc.d/init.d/bluetooth start
Sprawdzamy czy poprawnie wykryte zostało nasze urządzenie poleceniem

  hciconfig -a 
które powinno zwrócić informacje

  hci0:   Type: USB
          BD Address: 00:0B:0D:62:27:1A ACL MTU: 377:10 SCO MTU: 64:8
          UP RUNNING PSCAN ISCAN AUTH
          RX bytes:656 acl:0 sco:0 events:20 errors:0
          TX bytes:327 acl:0 sco:0 commands:20 errors:0
          Features: 0xff 0xfe 0x0d 0x38 0x08 0x08 0x00 0x00
          Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
          Link policy: RSWITCH HOLD SNIFF PARK
          Link mode: SLAVE ACCEPT
          Name: 'BlueZ (0)'
          Class: 0x3e0100
          Service Classes: Networking, Rendering, Capturing
          Device Class: Computer, Uncategorized
          HCI Ver: 1.2 (0x2) HCI Rev: 0x4 LMP Ver: 1.2 (0x2) LMP Subver: 0x309
          Manufacturer: Broadcom Corporation (15)

Jeśli nie pojawi się status podobny o powyższego można spróbować sekwencji:


  hciconfig hci0 down
  hciconfig hci0 up
  hciconfig -a

Brak informacji o urządzeniu oznacza iż nie działa ono prawidłowo.

Łączenie urządzeń

Wydajemy polecenie aby komputer wyszukał urządzenia bluetooth dostępne w jego pobliżu. Należy pamiętać aby uaktywnić bluetooth w palmtopie a następnie wykonać polecenie

  hcitool scan

Powinno ono zwrócić informację:

  Scanning ...
        00:12:D1:0B:B3:F5       Pocket_PC


Sprawdzamy połączenie w warstwie drugiej parując przy okazji palmtopa z komputerem przy użyciu PINu z pliku /usr/local/bin/sendpin

  l2ping 00:12:D1:0B:B3:F5
Powinniśmy dostać w odpowiedzi

  Ping: 00:12:D1:0B:B3:F5 from 00:0B:0D:62:27:1A (data size 44) ...
  44 bytes from 00:12:D1:0B:B3:F5 id 0 time 38.99ms
  44 bytes from 00:12:D1:0B:B3:F5 id 1 time 16.58ms
  44 bytes from 00:12:D1:0B:B3:F5 id 2 time 14.55ms
Nastepnie konfigurujemy serwer Dialup na komputerze. W pliku /etc/sysconfig/bluetooth ustawiamy

DUND_ENABLE=yes
DUND_OPTIONS="--listen --channel 1 --msdun call dun"
gdzie channel 1 to kanal na którym ma działąć serwer Dialup a dun do opcje dla serwera ppp z jakimi ma byc zestawiane połączenie.
W pliku /etc/ppp/peers/dun ustawiamy opcje pppd

# Increase debugging level (same as -d). The debug output is written
# to syslog LOG_LOCAL2.
#debug
# noauth means do not require the peer to authenticate itself, this must
# be set if you want to use pppd to connect to the internet. In this case
# *you* must authenicate yourself to the peer(internet provider), so do
# not disable this setting unless you are the dial-in server which where
# the peer has to autenticate to.
noauth
# Specifies that pppd should use a UUCP-style lock on the serial device
# to ensure exclusive access to the device.
lock

# Connect without using a modem
local

# async character map -- 32-bit hex; each bit is a character
# that needs to be escaped for pppd to receive it.  0x00000001
# represents '\x01', and 0x80000000 represents '\x1f'.
asyncmap 0
# Don't fork to become a background process (otherwise pppd will do so
# if a serial device is specified).
# nodetach

# Specifies that pppd should disconnect if the link is idle for n seconds.
idle 6000

# set low mtu for better interactivity

mtu 340
mru 340
# Disable the IPXCP and IPX protocols.
noipx

# set your own dns server here, otherwise on the palm
ms-dns 192.168.23.1

# wait for client to re-initiate a connection
passive
silent
# the two addresses to use for the client and the local ppp interface
192.168.23.1:192.168.23.2
Następnie restartujemy usługę bluetooth poleceniem

/etc/rc.d/init.d/bluetooth restart
Teraz palmtop powinien umieć wykryć na naszym komputerze serwer Dialup.

Połączenie z palmtopa do komputera

Wywołując połączenie musimy podać PIN z pliku /etc/bluetooth/pin użytkownika ppp i hasło należy zostawić puste.
Z palmtopem łączymy się poprzez adres 192.168.23.2 natomiast z komputerem poprzez adres 192.168.23.1
Jeśli chcemy uzyskać polączenie z internetem z palmtopa poprzez komputer należy odpowiednio skonfigurować na komputerze maskaradę i serwer dns.

Koniec.