magic 2.0下使用雜牌藍牙適配器並通過手機gprs上網

一、.安裝
bluez-libs 2.24 http://download.chinaunix.net/download/0001000/990.shtml
bluez-utils 2.24 http://download.chinaunix.net/download/0001000/991.shtml
官方網站上有提供3.7版的下載。但經過小弟試驗,好像因爲3.x版的不支持kdebluetooth1.0-0.beta1版的kbluepin。導致無法與手機配對。我在ChinaUnix.net下載了這兩個程序的源碼包。(很奇怪,2.25版的在我的機器上無法編譯.......)

二、.裝完這兩個程序後,插上藍牙適配器。打開Konsole,su 取得root權限。

1. 運行命令 lsusb 應該可以看到: (如果沒有請確認你的適配器有正確插入,usb插口跟適配器無損壞,還是沒有的話,那以下就可以不用看了)

Bus 001 Device 002: ID 1131:1001 Integrated System Solution Corp. KY-BT100 Bluetooth Adapter <------不同型號顯示有所不同,能認出就行

運行 hciconfig 可以看到:

hci0: Type: USB
BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0
DOWN
RX bytes:0 acl:0 sco:0 events:0 errors:0
TX bytes:0 acl:0 sco:0 commands:0 errors:0

沒有激活。激活它。運行:

hciconfig hci0 up

2. 配置 Bluez
修改 /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 user; <--------安全模式,需要手動輸入密碼

# 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 /usr/lib/kdebluetooth/kbluepin; <--------pin_helper 的位置。

# D-Bus PIN helper
#dbus_pin_helper;
}

# Default settings for HCI devices
device {
# Local device name
# %d - device id
# %h - host name
name "BlueZ (%d)"; <---------設備名稱,可以自己修改雙引號內的內容爲自己想要的名稱

# Local device class
class 0xff0100;

# 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;

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

# Authentication and Encryption (Security Mode 3)
#auth enable;
#encrypt enable;
}

********************************************************************************

3. 打開手機的藍牙。運行 hcitool scan 可以得到:

Scanning ...
00:13:70:2D:0E:08 Nokia 3230 <---------你的手機。偶的是“挪積壓 3230”。前面是手機的MAC地址。

運行命令
sdpd
hcid start
kbluetoothd 或者是K菜單--->互聯網--->kbluetoothd (藍牙服務器)
然後在手機上進行藍牙配對。成功後,就可以試試在電腦上右鍵點任一文件,動作-->通過藍牙發送,將文件發送給手機。手機也可以傳送文件進電腦了。

三、現在,要設置藍牙連接手機WAP代理上網了 (忘記在哪個網看到的了,原文是E文的。)
所用的工具:
pppd(用來撥號的)
rfcomm(用來連接手機撥號服務)

1. 需要建立編輯的文件有2個:
第一個:/etc/ppp/peers/gprs
內容如下:

/dev/rfcomm0
230400
defaultroute
usepeerdns
user ''
password bobo
nodetach
crtscts
lock
noauth
local
debug
connect "/usr/sbin/chat -v -f /etc/ppp/chat-gprs"

第二個:/etc/ppp/chat-gprs
內容如下:

TIMEOUT 10
ABORT 'BUSY'
ABORT 'NO ANSWER'
ABORT 'ERROR'
"" 'ATZ'
OK 'AT+CGDCONT=1,"IP","cmwap" ' <---------如果你是使用cmnet節點的,可以將cmwap改成cmnet,那不用代理就能上網,不過錢就..貴啊!
ABORT 'NO CARRIER'
SAY 'Dialing..../n'
OK 'ATD*99#' <---------"*99#"這個號碼各地都不一樣,請自己查找地方移動的網站
CONNECT ''


2.運行 sdptool search DUN 搜索設備的DUN服務,即網絡撥號服務。

Inquiring ...
Searching for DUN on 00:13:70:2D:0E:08 ...
Service Name: Dial-Up Networking
Service RecHandle: 0x10005
Service Class ID List:
"Dialup Networking" (0x1103)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 2 <---------你手機RFCOMM的工作信道。記住了啊。不同機型是不同的
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"Dialup Networking" (0x1103)
Version: 0x0100

3. 修改/etc/bluetooth/rfcomm.conf

*******************************************************************************
#
# RFCOMM configuration file.
#

rfcomm0 {
# Automatically bind the device at startup
bind yes; <---------將 no 改爲 yes

# Bluetooth address of the device
device 00:13:70:2D:0E:08; <---------改爲你手機的MAC地址

# RFCOMM channel for the connection
channel 2; <---------改爲你手機RFCOMM的工作信道。

# Description of the connection
comment "Example Bluetooth device";
}
**********************************************************************************

4. 綁定rfcomm0到手機上:

rfcomm bind /dev/rfcomm0 [MAC] [channel]

根據你手機的情況編寫。這裏的命令應該寫成:

rfcomm bind /dev/rfcomm0 00:13:70:2D:0E:08 2

所謂綁定,類似於設定/dev/rfcomm0對應某個確定的藍牙設備和它的某個channel。可以把它想像爲將一條串口電纜連接到某臺計算機上的某個串口上。

5. 運行命令進行撥號:

pppd call gprs

輸出差不多如下的東東,那麼恭喜你 ,成功了!!!
Dialing....
Serial connection established.
using channel 3
Using interface ppp0
Connect: ppp0 <--> /dev/rfcomm0
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x6df58d43> <pcomp> <accomp>]
rcvd [LCP ConfRej id=0x1 <magic 0x6df58d43> <pcomp> <accomp>]
sent [LCP ConfReq id=0x2 <asyncmap 0x0>]
rcvd [LCP ConfAck id=0x2 <asyncmap 0x0>]
rcvd [LCP ConfReq id=0x0 <auth pap> <mru 1500> <asyncmap 0xa0000>]
sent [LCP ConfAck id=0x0 <auth pap> <mru 1500> <asyncmap 0xa0000>]
sent [PAP AuthReq id=0x1 user="MagicLinux" password=<hidden>]
sent [PAP AuthReq id=0x2 user="MagicLinux" password=<hidden>]
rcvd [PAP AuthAck id=0x2 ""]
PAP authentication succeeded
sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15>]
sent [IPCP ConfReq id=0x1 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]
rcvd [IPCP ConfReq id=0x0 <addr 10.6.6.6>]
sent [IPCP ConfAck id=0x0 <addr 10.6.6.6>]
rcvd [LCP ProtRej id=0x0 80 fd 01 01 00 0c 1a 04 78 00 18 04 78 00]
rcvd [IPCP ConfRej id=0x1 <compress VJ 0f 01>]
sent [IPCP ConfReq id=0x2 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]
rcvd [IPCP ConfNak id=0x2 <addr 10.213.77.9> <ms-dns1 0.0.0.19> <ms-dns3 0.71.35.128>]
sent [IPCP ConfReq id=0x3 <addr 10.213.77.9> <ms-dns1 0.0.0.19> <ms-dns3 0.71.35.128>]
rcvd [IPCP ConfAck id=0x3 <addr 10.213.77.9> <ms-dns1 0.0.0.19> <ms-dns3 0.71.35.128>]
local IP address 10.213.77.9
remote IP address 10.6.6.6
primary DNS address 0.0.0.19
secondary DNS address 0.71.35.128
Script /etc/ppp/ip-up started (pid 3208)
Script /etc/ppp/ip-up finished (pid 3208), status = 0x0

6.打開firefox瀏覽器,(其它的瀏覽器請自己查找代理服器的設置)
編輯--->首選項--->高級--->網絡--->連接--->設置--->手動配置代理
HTTP 代理 填上 10.0.0.172 端口爲 80
OK!!現在可以上網了,速度跟用MODEM撥號差不多。。

PS:如果沒有配對或是沒有設置電腦爲授權設備,會要求確認聯接,另外,每次開機都要以root權限運行
hciconfig hci0 up
sdpd
hcid start
rfcomm bind /dev/rfcomm0 00:13:70:2D:0E:08 2
你可以將以上命令編成一個Shell腳本。嘿嘿。

注意:要退出系統時最好把kbluetoothd退出,並選擇不要在系統啓動時運行,不然下次啓動系統會導致kbluetoothd出錯並失去響應。 
發佈了2 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章