openwrt藍牙文件傳輸

openwrt支持:

USB Supprot-------------------------------app

kmod-usb-ohcisocket

kmod-usb-uhci工具

kmod-usb-storage-extras測試

kmod-usb2unix

 

Utilities-------------------------------ip

bluez-utilsci

bluez-daemoncmd

 

Utilities-------------------------------it

openobexio

openobex-apps

 

工具說明:

bluez-utils依賴bluez-libs,dbus

生成工具:bccmd,bluemoon,btattach,btmon,btmgmt,ciptool,hciattach,hciconfig,hcidump,hcitool,hex2hcd,l2ping,l2test,mpris-proxy,rctest,rfcomm,sdptool,gatttool

 

bluez-libs依賴kmod-bluetooth藍牙hci驅動

bluez-daemon生成工具:bluetoothd,bluetoothctl,obexd

openobex-apps生成工具:obex_test

 

kmod-bluetooth驅動

openwrt藍牙驅動ko參考:kmod-bluetooth

        $(LINUX_DIR)/net/bluetooth/bluetooth.ko \

        $(LINUX_DIR)/net/bluetooth/rfcomm/rfcomm.ko \

        $(LINUX_DIR)/net/bluetooth/bnep/bnep.ko \

        $(LINUX_DIR)/net/bluetooth/hidp/hidp.ko \

        $(LINUX_DIR)/drivers/bluetooth/hci_uart.ko \

        $(LINUX_DIR)/drivers/bluetooth/btusb.ko

 

工具使用:

bluetoothd完成藍牙hci層的統一管理服務端

bluetoothctl 藍牙服務控制,經過dbus與bluetoothd通訊

obexd藍牙文件傳輸協議接收服務端,經過dbus與bluetoothd通訊

hciconfig,hcitool 藍牙hci層控制工具

obex_test藍牙文件傳輸客戶端,支持點對點藍牙的文件發送與接收

sdptool 藍牙從設備profile服務掃描工具

 

# 創建串口和藍牙hci協議層的數據鏈接通道,usb方式不用

hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -

hciconfig hci0 up

hcitool scan

hciconfig hci0 sspmode disable #關閉簡易配對模式,有這個模式的被配對方就不用點擊確認

# 查找目標mac藍牙服務,文件傳輸服務爲"OBEX Object Push" (0x1105),找出服務所在信道

sdptool brower F4:63:1F:D8:E0:89

sdptool search --bdaddr F4:63:1F:D8:E0:89 0x1105

# 藍牙應用層使用工具

 

bluetoothctl

power on -- 啓動藍牙模塊

agent on -- 藍牙模塊agent 打開

scan on -- 掃描周邊設備,獲得手機MAC:DC:09:4C:62:B3:CA

trust DC:09:4C:62:B3:CA -- trust該手機

pairable on -- 配對使能

discoverable on -- 開放檢測

show -- 查看藍牙配置信息

 

echo "power on" | bluetoothctl

echo "agent on" | bluetoothctl

echo "pairable on" | bluetoothctl

echo "discoverable on" | bluetoothctl

echo "show" | bluetoothctl

 

# obex_test發送文件,須要帶上對方mac的obex文件傳輸服務所在信道,與sdptool結合使用

obex_test -b F4:63:1F:D8:E0:89 5

 

# obexd開啓obex服務,接收文件

export DBUS_SESSION_BUS_ADDRESS="unix:path=/var/run/dbus/system_bus_socket"

obexd -a -r /tmp/ -n

 

 

obexd的dbus啓動配置文件編寫:

========================================

root@OpenWrt:~# cat /etc/dbus-1/system.d/obex-dbus.conf

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"

 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">

<busconfig>

 

  <!-- ../system.conf have denied everything, so we just punch some holes -->

 

  <policy user="root">

    <allow own="org.bluez.obex"/>

    <allow send_destination="org.bluez.obex"/>

  </policy>

 

  <policy at_console="true">

    <allow send_destination="org.bluez.obex"/>

  </policy>

 

  <policy group="lp">

    <allow send_destination="org.bluez.obex"/>

  </policy>

 

  <policy context="default">

    <deny send_destination="org.bluez.obex"/>

  </policy>

 

</busconfig>

 

測試藍牙特性

1.某些手機藍牙要在藍牙設置頁面才能被其餘藍牙掃描到(華爲暢享9)2.某些手機藍牙接收不了無後綴或特殊文件(小米8)3.蘋果IOS系統是絕對的封閉性,因此iPhone藍牙只能用於鏈接外設不能傳輸文件4.藍牙同時鏈接7個設備後,第8個設備使用sdptool查找服務不成功5.某些手機藍牙鏈接時須要點擊確認配對6.須要點擊確認配對的某些手機拒絕屢次後(>8次),接收鏈路會失敗,須要從新鏈接配對7.藍牙做爲從模式,有鏈接傳輸文件時,主模式文件傳輸失敗8.獲取不到主模式設備的rssi,主模式能夠再beacon和scan request獲取到應用層上報的從模式rssi

相關文章
相關標籤/搜索