Статью скопипастил прямо от сюда. По мере продвежения в этом деле (у меня лично не получилось подключить) будут вноситься изменения.
Длинное вступление
Обычно бывает наоборот – подключают компьютер к интернет именно через телефон, но вот решил попробовать наоборот.
Итак по порядку.
Решил я как-то узнать – а как обстоят дела с bluetooth под Linux(на ubuntu не проверялось).
Погуглил, погулил и выгугли. Дела в общем-то обстоят не плохо. Ну конечно не заюзаешь нокию_писи_сьют или еще что-то в этом роде.
Файлы туда-сюда покопировать – это без проблем, гпрс-модем прикрутить и все дела тоже можно.
Но есть другие приятные моменты.
Обычно как – обычно берешь и коннектишь с ноута в нет через gprs твоего сотового оператара.
А как на счет – выйти в интернет с мобилы, соеденненной с компьютером посредством bluetooth, который (компьютер) в свою очередь подключен к интернету каким-либо другим способом?
Я пока не придумал как это использовать с пользой, кроме как – коннектиться с телефона на халявный жаббер от байфлая сидя на унитазе…
Может у кого-то еще будут идеи?
Итак чтобы подключить инет на мобиле нужно через комп:Итак по порядку.
Решил я как-то узнать – а как обстоят дела с bluetooth под Linux(на ubuntu не проверялось).
Погуглил, погулил и выгугли. Дела в общем-то обстоят не плохо. Ну конечно не заюзаешь нокию_писи_сьют или еще что-то в этом роде.
Файлы туда-сюда покопировать – это без проблем, гпрс-модем прикрутить и все дела тоже можно.
Но есть другие приятные моменты.
Обычно как – обычно берешь и коннектишь с ноута в нет через gprs твоего сотового оператара.
А как на счет – выйти в интернет с мобилы, соеденненной с компьютером посредством bluetooth, который (компьютер) в свою очередь подключен к интернету каким-либо другим способом?
Я пока не придумал как это использовать с пользой, кроме как – коннектиться с телефона на халявный жаббер от байфлая сидя на унитазе…
Может у кого-то еще будут идеи?
1) Иметь ядро собраное для использования блютуза
У меня стоит Debian 40r0 и я всеголишь поставил пакет bluez.
2) Поправил конфиги:
hcid.conf:
options {
autoinit yes;
security user;
pairing multi;
pin_helper /etc/bluetooth/pin;
}
device {
name “%h”; # Local device name: %d - device id, %h - host name.
class 0×100;
iscan enable;pscan enable;
lm accept; lp hold,sniff,park;
}
autoinit yes;
security user;
pairing multi;
pin_helper /etc/bluetooth/pin;
}
device {
name “%h”; # Local device name: %d - device id, %h - host name.
class 0×100;
iscan enable;pscan enable;
lm accept; lp hold,sniff,park;
}
rfcomm.conf:
rfcomm0 {
bind no;
device 00:00:00:00:00:00; # измени это на MAC адрес своего телефона
channel 3;
comment “Linux bluetooth connection”;
}
bind no;
device 00:00:00:00:00:00; # измени это на MAC адрес своего телефона
channel 3;
comment “Linux bluetooth connection”;
}
3) Создал девайсы для блютуза
mknod -m 660 /dev/rfcomm0 c 216 0
mknod -m 660 /dev/rfcomm1 c 216 0
mknod -m 660 /dev/rfcomm2 c 216 0
mknod -m 660 /dev/rfcomm3 c 216 0
mknod -m 660 /dev/rfcomm4 c 216 0
mknod -m 660 /dev/rfcomm1 c 216 0
mknod -m 660 /dev/rfcomm2 c 216 0
mknod -m 660 /dev/rfcomm3 c 216 0
mknod -m 660 /dev/rfcomm4 c 216 0
4) поправил под себя скриптик
5) запустил
6) и убедился в том что нет никаких ошибок
#!/bin/sh PHONE_MAC=00:00:00:00:00:00 # Phones MAC address
EXT_IF=eth0 # Your externl interface (to the net)
INT_NET=xxx.xxx.xxx.xxx/24
# Внутренняя подсеть (eg. 192.168.1.0/24)
MY_IP=xxx.xxx.xxx.xxx # IP твоего компьютера (eg. 192.168.1.1)
PHONE_IP=xxx.xxx.xxx.xxx
#IP который ты хочешь дать телефону(eg. 192.168.1.10)
DNS_SERVER=xxx.xxx.xxx.xxx # Your ISPs DNS server ANY=0.0.0.0/0
IPTABLES=/usr/sbin/iptables
MODPROBE=/sbin/modprobe
/usr/sbin/hcid
hciconfig hci0 up
/usr/sbin/sdpd
rfcomm bind /dev/rfcomm1 $PHONE_MAC 10
rfcomm bind /dev/rfcomm2 $PHONE_MAC 3
dund --nodetach --listen --channel 3 --msdun 30 noauth
$MY_IP:
$PHONE_IP crtscts 115200 ms-dns
$DNS_SERVER lock &
sdptool add --channel=3 SP
sdptool add --channel=10 OPUSH
$MODPROBE ip_tables
$MODPROBE iptable_filter
$MODPROBE ip_nat_ftp
$MODPROBE ip_conntrack
$MODPROBE ip_conntrack_ftp
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -A FORWARD -i $EXT_IF -o ppp0 -s $ANY -d $INT_NET
-m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -d $ANY -j ACCEPT
$IPTABLES -A POSTROUTING -t nat -o $EXT_IF -j MASQUERADE
EXT_IF=eth0 # Your externl interface (to the net)
INT_NET=xxx.xxx.xxx.xxx/24
# Внутренняя подсеть (eg. 192.168.1.0/24)
MY_IP=xxx.xxx.xxx.xxx # IP твоего компьютера (eg. 192.168.1.1)
PHONE_IP=xxx.xxx.xxx.xxx
#IP который ты хочешь дать телефону(eg. 192.168.1.10)
DNS_SERVER=xxx.xxx.xxx.xxx # Your ISPs DNS server ANY=0.0.0.0/0
IPTABLES=/usr/sbin/iptables
MODPROBE=/sbin/modprobe
/usr/sbin/hcid
hciconfig hci0 up
/usr/sbin/sdpd
rfcomm bind /dev/rfcomm1 $PHONE_MAC 10
rfcomm bind /dev/rfcomm2 $PHONE_MAC 3
dund --nodetach --listen --channel 3 --msdun 30 noauth
$MY_IP:
$PHONE_IP crtscts 115200 ms-dns
$DNS_SERVER lock &
sdptool add --channel=3 SP
sdptool add --channel=10 OPUSH
$MODPROBE ip_tables
$MODPROBE iptable_filter
$MODPROBE ip_nat_ftp
$MODPROBE ip_conntrack
$MODPROBE ip_conntrack_ftp
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -A FORWARD -i $EXT_IF -o ppp0 -s $ANY -d $INT_NET
-m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -d $ANY -j ACCEPT
$IPTABLES -A POSTROUTING -t nat -o $EXT_IF -j MASQUERADE
7) Который в свою очередь подправил под себя
8) Для того что бы узнать мак адрес телефона – можно использовать команд:
hcitool scan
9) Далее скачивается и ставится на телефон софтина gnubox (http://www.symbianos.org/cgi-bin/viewcvs.cgi/gnubox/)
10) На телефоне создается новое подключени:
Name:Bt (это важно, регистрозависимо)
Data bearer: GSM data
Dial-up number: 2222 (number doesn't mattter as long as it's not blank)
Username: None
Prompt password: No
Password: None
Authentication: Normal
Homepage: None
Data call type: Analogue
Maximum data speed automatic: Automatic
Data bearer: GSM data
Dial-up number: 2222 (number doesn't mattter as long as it's not blank)
Username: None
Prompt password: No
Password: None
Authentication: Normal
Homepage: None
Data call type: Analogue
Maximum data speed automatic: Automatic
11) Запускаем на телефоне gnubox и указываем в опциях 2box Direct->bluetooth->выбираем наш компутер
Открывем на телефоне оперу – загружаем любую страничку – выбираем наше созданное подключение…
И О ЧУДО – она загружается
А теперь всё это на английском из первоисточника
Your phone, bluetooth, the internet and Linux
Copyright © mazzanet 2005
This small how-to will allow your phone to connect to the internet via Bluetooth and a Linux box and send/receive files between your phone and your PC. A number of packages and scripts will need to be installed and configured.
It will assume you're using a USB Bluetooth dongle (though a PCI card might work following the same method - but not using hcid) and have Bluetooth support compiled into your kernel, you will need to have these option in your kernel config:
CONFIG_BLUEZ=m
CONFIG_BLUEZ_L2CAP=m
CONFIG_BLUEZ_SCO=m
CONFIG_BLUEZ_RFCOMM=m
CONFIG_BLUEZ_RFCOMM_TTY=y
CONFIG_BLUEZ_BNEP=m
CONDIF_BLUEZ_HCIUSB=m
You'll also need the following entries in /etc/modules.conf:
alias net-pf-31 bluez
alias bt-proto-0 l2cap
alias bt-proto-1 sco
alias bt-proto-2 rfcomm
1) You will need the following files (the versions listed have been tested and work, latest versions might not...):
bluez-firmware-1.0.tar.gz
bluez-libs-2.12.tar.gz
bluez-utils-2.12.tar.gz
openobex-1.0.1.tar.gz
openobex-apps-1.0.0.tar.gz
The standard ./configure && make && make install should do fine.
2) BlueZ stores all its configuration files in /etc/bluetooth/ by default. You will need to edit hcid.conf, rfcomm.conf and pin. Below are my tested working files.
hcid.conf:
options {
autoinit yes;
security user;
pairing multi;
pin_helper /etc/bluetooth/pin;
}
device {
name "%h"; # Local device name: %d - device id, %h - host name.
class 0x100;
iscan enable; pscan enable;
lm accept;
lp hold,sniff,park;
}
rfcomm.conf:
rfcomm0 {
bind no;
device 00:00:00:00:00:00; # Change this to your phones MAC address (To find this out, see step 4)
channel 3;
comment "Linux bluetooth connection";
}
pin:
#!/bin/sh
echo "PIN:1234"
Make sure you chmod this file as 755 (well as long as it's executable).
3) Next, create the RFCOMM devices:
mknod -m 660 /dev/rfcomm0 c 216 0
mknod -m 660 /dev/rfcomm1 c 216 0
mknod -m 660 /dev/rfcomm2 c 216 0
mknod -m 660 /dev/rfcomm3 c 216 0
mknod -m 660 /dev/rfcomm4 c 216 0
4) Now create an appropriate rc script (path depends on your OS, on Slackware: /etc/rc.d/rc.mobile)
#!/bin/sh
PHONE_MAC=00:00:00:00:00:00 # Phones MAC address
EXT_IF=eth0 # Your externl interface (to the net)
INT_NET=xxx.xxx.xxx.xxx/24 # Your internal subnet (eg. 192.168.1.0/24)
MY_IP=xxx.xxx.xxx.xxx # This PCs internal IP address (eg. 192.168.1.1)
PHONE_IP=xxx.xxx.xxx.xxx # The IP you want to give your phone (eg. 192.168.1.10)
DNS_SERVER=xxx.xxx.xxx.xxx # Your ISPs DNS server
ANY=0.0.0.0/0
IPTABLES=/usr/sbin/iptables
MODPROBE=/sbin/modprobe
/usr/sbin/hcid
hciconfig hci0 up
/usr/sbin/sdpd
rfcomm bind /dev/rfcomm1 $PHONE_MAC 10
rfcomm bind /dev/rfcomm2 $PHONE_MAC 3
dund --nodetach --listen --channel 3 --msdun 30 noauth $MY_IP:$PHONE_IP crtscts 115200 ms-dns $DNS_SERVER lock &
sdptool add --channel=3 SP
sdptool add --channel=10 OPUSH
$MODPROBE ip_tables
$MODPROBE iptable_filter
$MODPROBE ip_nat_ftp
$MODPROBE ip_conntrack
$MODPROBE ip_conntrack_ftp
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -A FORWARD -i $EXT_IF -o ppp0 -s $ANY -d $INT_NET -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -d $ANY -j ACCEPT
$IPTABLES -A POSTROUTING -t nat -o $EXT_IF -j MASQUERADE
To find your phones MAC address, run:
/usr/sbin/hcid
hciconfig hci0 up
hcitool scan
Don't forget to give it the right permissions :) Also change ppp0 to ppp1 if you're on dialup.
5) Run the rc script and on your phone, go through the appropriate menu options to pair a new Bluetooth device.
(on a Nokia 6660: Connectivity->Bluetooth->Paired-Devices->New Paired Device)
When asked for a PIN, enter 1234 (see /etc/bluetooth/pin).
Next, run:
l2ping [Phones MAC address]
If you get a response, well done :)
6) Next we'll do some setting up on your phone.
Download and install gnubox, locally mirrored here or here for Nokia 6600.
Now create a new connection (Tools->Settings->Access points->New access point->Use default settings)
Name: Bt (name is important, case-sensitive)
Data bearer: GSM data
Dial-up number: 2222 (number doesn't mattter as long as it's not blank)
Username: None
Prompt password: No
Password: None
Authentication: Normal
Homepage: None
Data call type: Analogue
Maximum data speed automatic: Automatic
Now run gnubox, go Options->2box Direct->Bluetooth and select your PC.
The output should look like:
Bluetooth settings...
DialOutISP
Description: Direct 2box
DefaultTelNum:
ModemBearer
PortName: BTCOMM::0
CSYName: BTCOMM
TSYName: PHONETSY
7) Now load up a webbrowser ([shamless plug for Opera]), select your new access point and pray :)
8) Assuming everything is all working, onto file sending/receiving. Hopefully you haven't removed the openobex-apps source tree yet...
Download obexserver.c and compile it in openobex-apps-1.0.0./src:
cc -o obexserver obexserver.c libmisc.a -lopenobex
cp obexserver /usr/local/bin
Download ussp-push, compile and install.
Below are some wrapper scripts for obexserver and ussp-push, put them in /usr/local/bin/ and
give them the right permissions.
obexsend:
#!/bin/sh
if [ -z "$1" ]
then
echo "usage: obexsend "
exit
fi
tosave=`echo $1 | awk -F '/' '{print $NF}'`
echo "Saving to phone as: $tosave"
ussp-push /dev/rfcomm1 $1 $tosave
obexrecv:
#!/bin/sh
while [ true ]
do
obexserver
done
To send a file to your phone, run `obexsend ` and to receive files, run `obexrecv` (obexserver sits and waits for a connection from the phone, stores the sent file in /tmp and exits).
9) All done! Have fun and if you have any comments or queries, email me: mazzanet@mazzanet.id.au
Copyright © mazzanet 2005
This small how-to will allow your phone to connect to the internet via Bluetooth and a Linux box and send/receive files between your phone and your PC. A number of packages and scripts will need to be installed and configured.
It will assume you're using a USB Bluetooth dongle (though a PCI card might work following the same method - but not using hcid) and have Bluetooth support compiled into your kernel, you will need to have these option in your kernel config:
CONFIG_BLUEZ=m
CONFIG_BLUEZ_L2CAP=m
CONFIG_BLUEZ_SCO=m
CONFIG_BLUEZ_RFCOMM=m
CONFIG_BLUEZ_RFCOMM_TTY=y
CONFIG_BLUEZ_BNEP=m
CONDIF_BLUEZ_HCIUSB=m
You'll also need the following entries in /etc/modules.conf:
alias net-pf-31 bluez
alias bt-proto-0 l2cap
alias bt-proto-1 sco
alias bt-proto-2 rfcomm
1) You will need the following files (the versions listed have been tested and work, latest versions might not...):
bluez-firmware-1.0.tar.gz
bluez-libs-2.12.tar.gz
bluez-utils-2.12.tar.gz
openobex-1.0.1.tar.gz
openobex-apps-1.0.0.tar.gz
The standard ./configure && make && make install should do fine.
2) BlueZ stores all its configuration files in /etc/bluetooth/ by default. You will need to edit hcid.conf, rfcomm.conf and pin. Below are my tested working files.
hcid.conf:
options {
autoinit yes;
security user;
pairing multi;
pin_helper /etc/bluetooth/pin;
}
device {
name "%h"; # Local device name: %d - device id, %h - host name.
class 0x100;
iscan enable; pscan enable;
lm accept;
lp hold,sniff,park;
}
rfcomm.conf:
rfcomm0 {
bind no;
device 00:00:00:00:00:00; # Change this to your phones MAC address (To find this out, see step 4)
channel 3;
comment "Linux bluetooth connection";
}
pin:
#!/bin/sh
echo "PIN:1234"
Make sure you chmod this file as 755 (well as long as it's executable).
3) Next, create the RFCOMM devices:
mknod -m 660 /dev/rfcomm0 c 216 0
mknod -m 660 /dev/rfcomm1 c 216 0
mknod -m 660 /dev/rfcomm2 c 216 0
mknod -m 660 /dev/rfcomm3 c 216 0
mknod -m 660 /dev/rfcomm4 c 216 0
4) Now create an appropriate rc script (path depends on your OS, on Slackware: /etc/rc.d/rc.mobile)
#!/bin/sh
PHONE_MAC=00:00:00:00:00:00 # Phones MAC address
EXT_IF=eth0 # Your externl interface (to the net)
INT_NET=xxx.xxx.xxx.xxx/24 # Your internal subnet (eg. 192.168.1.0/24)
MY_IP=xxx.xxx.xxx.xxx # This PCs internal IP address (eg. 192.168.1.1)
PHONE_IP=xxx.xxx.xxx.xxx # The IP you want to give your phone (eg. 192.168.1.10)
DNS_SERVER=xxx.xxx.xxx.xxx # Your ISPs DNS server
ANY=0.0.0.0/0
IPTABLES=/usr/sbin/iptables
MODPROBE=/sbin/modprobe
/usr/sbin/hcid
hciconfig hci0 up
/usr/sbin/sdpd
rfcomm bind /dev/rfcomm1 $PHONE_MAC 10
rfcomm bind /dev/rfcomm2 $PHONE_MAC 3
dund --nodetach --listen --channel 3 --msdun 30 noauth $MY_IP:$PHONE_IP crtscts 115200 ms-dns $DNS_SERVER lock &
sdptool add --channel=3 SP
sdptool add --channel=10 OPUSH
$MODPROBE ip_tables
$MODPROBE iptable_filter
$MODPROBE ip_nat_ftp
$MODPROBE ip_conntrack
$MODPROBE ip_conntrack_ftp
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -A FORWARD -i $EXT_IF -o ppp0 -s $ANY -d $INT_NET -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -d $ANY -j ACCEPT
$IPTABLES -A POSTROUTING -t nat -o $EXT_IF -j MASQUERADE
To find your phones MAC address, run:
/usr/sbin/hcid
hciconfig hci0 up
hcitool scan
Don't forget to give it the right permissions :) Also change ppp0 to ppp1 if you're on dialup.
5) Run the rc script and on your phone, go through the appropriate menu options to pair a new Bluetooth device.
(on a Nokia 6660: Connectivity->Bluetooth->Paired-Devices->New Paired Device)
When asked for a PIN, enter 1234 (see /etc/bluetooth/pin).
Next, run:
l2ping [Phones MAC address]
If you get a response, well done :)
6) Next we'll do some setting up on your phone.
Download and install gnubox, locally mirrored here or here for Nokia 6600.
Now create a new connection (Tools->Settings->Access points->New access point->Use default settings)
Name: Bt (name is important, case-sensitive)
Data bearer: GSM data
Dial-up number: 2222 (number doesn't mattter as long as it's not blank)
Username: None
Prompt password: No
Password: None
Authentication: Normal
Homepage: None
Data call type: Analogue
Maximum data speed automatic: Automatic
Now run gnubox, go Options->2box Direct->Bluetooth and select your PC.
The output should look like:
Bluetooth settings...
DialOutISP
Description: Direct 2box
DefaultTelNum:
ModemBearer
PortName: BTCOMM::0
CSYName: BTCOMM
TSYName: PHONETSY
7) Now load up a webbrowser ([shamless plug for Opera]), select your new access point and pray :)
8) Assuming everything is all working, onto file sending/receiving. Hopefully you haven't removed the openobex-apps source tree yet...
Download obexserver.c and compile it in openobex-apps-1.0.0./src:
cc -o obexserver obexserver.c libmisc.a -lopenobex
cp obexserver /usr/local/bin
Download ussp-push, compile and install.
Below are some wrapper scripts for obexserver and ussp-push, put them in /usr/local/bin/ and
give them the right permissions.
obexsend:
#!/bin/sh
if [ -z "$1" ]
then
echo "usage: obexsend "
exit
fi
tosave=`echo $1 | awk -F '/' '{print $NF}'`
echo "Saving to phone as: $tosave"
ussp-push /dev/rfcomm1 $1 $tosave
obexrecv:
#!/bin/sh
while [ true ]
do
obexserver
done
To send a file to your phone, run `obexsend ` and to receive files, run `obexrecv` (obexserver sits and waits for a connection from the phone, stores the sent file in /tmp and exits).
9) All done! Have fun and if you have any comments or queries, email me: mazzanet@mazzanet.id.au
Комментариев нет:
Отправить комментарий