mknod /dev/rfcomm0 c 216 0
216是RFCOMM的裝置號,可以參考..../bluez-utils-2.x/scripts/create_dev指令碼
綁定
rfcomm.conf表示的是將rfcomm0綁定到某個MAC和channel上。這個功能用下面的命令也可以完成
rfcomm bind /dev/rfcomm0 [MAC] [channel]
解除綁定使用
rfcomm release /dev/rfcomm0
查看綁定使用
rfcomm show
所謂綁定,類似於設定/dev/rfcomm0對應某個確定的藍牙裝置和它的某個channel。可以把它想像為將一條串口電纜連線到某台電腦上的某個串口上。
串連
rfcomm conn /dev/rfcomm0 [MAC] 10
該命令建立一個與[MAC]的rfcomm串連。這時,可能被串連方會發送一下LINK_PIN_REQUEST,要求數字 PIN 碼。
數字 PIN 碼是由hcid/secury.c處理的,當hcid收到LINK_PIN_REQUEST,就調用下面的這個函數。見下面的代碼:
static void pin_code_request(int dev, bdaddr_t *sba, bdaddr_t *dba)
{
......
pinlen = read_pin_code(sba, dba, pin);/*這裡是從本機檔案中讀取數字 PIN 碼*/
if (pairing == HCID_PAIRING_ONCE) {
struct link_key *key = get_link_key(sba, dba);
if (key) {
ba2str(dba, da);
syslog(LOG_WARNING, "PIN code request for already paired device %s", da);
goto reject;
}
} else if (pairing == HCID_PAIRING_NONE) /*hcid.conf中security設定為none*/
goto reject;/*發送PIN_Code_Request_Negative_Reply*/
if (hcid.security == HCID_SEC_AUTO) {/*hcid.conf中security設定為auto*/
......
hci_send_cmd(dev, OGF_LINK_CTL, OCF_PIN_CODE_REPLY,
PIN_CODE_REPLY_CP_SIZE, &pr);
} else {
/* Let PIN helper handle that */
request_pin(dev, sba, ci);/*調用hcid.conf中pin_helper對應的PIN輸入程式*/
}
}
} else {
/* Let PIN helper handle that */
request_pin(dev, sba, ci););/*調用hcid.conf中pin_helper對應的PIN輸入程式*/
}
}
可見,hcid的處理行為是在/etc/bluetooth/hcid.conf檔案中確定的。在實際使用中發現hcid.conf中的pin_helper設定的bluepin不起作用。(註:bluepin是一個python指令檔)
read_pin_code()是從檔案中讀取數字 PIN 碼,下面是這個函數的代碼:
#define STORAGEDIR "/var/lib/bluetooth"
snprintf(filename, PATH_MAX, "%s/%s/pincodes", STORAGEDIR, addr);
可見數字 PIN 碼的檔案是在/var/lib/bluetooth/xx:xx:xx:xx:xx:xx/pincodes中。手工的建立這個檔案,然後使用上面的命令
rfcomm conn /dev/rfcomm0 [MAC] 10
這可以成功串連上需要數字 PIN 碼的藍牙裝置 |