📄 bt_vendor.c
字号:
/* Make sure that deep sleep timer is disabled to prevent problems when setting new ps keys */ if (csr_disable_deep_sleep(bt_cfd)) { reset_hw(); if (ioctl(bt_cfd, BTINITBCSP) < 0) { perror(__FUNCTION__); exit(1); } sleep(1); } /* Read params for ps key PSKEY_HOSTIO_UART_PS_BLOCK */ csr_pskey(bt_cfd, PSKEY_HOSTIO_UART_PS_BLOCK, CSR_PSKEY_GETREQ, ps_parbuf, 10); if (ps_parbuf[1] == 6) /* BCSP */ { /* Set UART to no parity, non-bcsp, flow control on */ ps_parbuf[1] = 0x00a8; csr_pskey(bt_cfd, PSKEY_HOSTIO_UART_PS_BLOCK, CSR_PSKEY_SETREQ, ps_parbuf, 10); sleep(1); /* Set ps key PSKEY_HOST_INTERFACE */ ps_parbuf[0] = 0x0003; /* H4 */ csr_pskey(bt_cfd, PSKEY_HOST_INTERFACE, CSR_PSKEY_SETREQ, ps_parbuf, 1); sleep(1); } else { syslog(LOG_ERR, __FUNCTION__ ": Unknown PS key parameter: %d", ps_parbuf[1]); } /* Set back stack to use H4 framing */ bt_bcsp_mode(bt_cfd, 0); shutdown_stack(bt_cfd);}void csr_h4_to_bcsp(int bt_cfd, int phys_fd, const char *speedstr, int flow_control){ unsigned short ps_parbuf[10]; syslog(LOG_INFO, "Changing CSR host IF: H4 -> BCSP"); /* Set stack to use H4 temporarily */ bt_bcsp_mode(bt_cfd, 0); if (speedstr) fd_setup(phys_fd, speedstr, flow_control); else init_phys(phys_fd, flow_control); reset_hw(); sleep(1); /* Initialize stack */ init_stack(bt_cfd); if (csr_disable_deep_sleep(bt_cfd)) { reset_hw(); init_stack(bt_cfd); /* reinitialize */ } /* Read params for ps key PSKEY_HOSTIO_UART_PS_BLOCK */ csr_pskey(bt_cfd, PSKEY_HOSTIO_UART_PS_BLOCK, CSR_PSKEY_GETREQ, ps_parbuf, 10); if (ps_parbuf[1] == 0xa8) /* non-BCSP */ { /* Enable parity bit, disable flow */ ps_parbuf[1] = 0x6; csr_pskey(bt_cfd, PSKEY_HOSTIO_UART_PS_BLOCK, CSR_PSKEY_SETREQ, ps_parbuf, 10); sleep(1); /* Set ps key PSKEY_HOST_INTERFACE */ ps_parbuf[0] = 0x1; /* BCSP */ csr_pskey(bt_cfd, PSKEY_HOST_INTERFACE, CSR_PSKEY_SETREQ, ps_parbuf, 1); } else { syslog(LOG_ERR, __FUNCTION__ ": Unknown PS key parameter: %d", ps_parbuf[1]); } /* Set back stack to use BCSP framing */ bt_bcsp_mode(bt_cfd, 1); shutdown_stack(bt_cfd);}/* fixme -- remove hardcoded values */voidcsr_init_hw(int bt_cfd, int phys_fd, const char *speedstr){ /* Connection setup, all devices, no auto accept */ unsigned char filter[3] = { 0x02, 0x00, 0x01 }; unsigned int wrscan = (PAGE_SCAN_ENABLE | INQUIRY_SCAN_ENABLE); int firmware = -1; char* buf; if (bt_bcsp_mode(bt_cfd, -1) && csr_disable_deep_sleep(bt_cfd)) kill(getpid(), SIGUSR1); /* Restart btd (and HW) to activate changes */ D(syslog(LOG_INFO, "Setting write_scan_enable in CSR module")); bt_write_scan_enable(bt_cfd, wrscan); /* improves reliability when doing a connect */ D(syslog(LOG_INFO, "Setting write_pagescan_activity in CSR module")); bt_write_pagescan_activity(bt_cfd, 0x0800, 0x12); bt_set_event_filter(bt_cfd, filter); sleep(1); if ((buf = bt_firmware_info())) { sscanf(buf, " Firmware version: %d", &firmware); } if (speedstr) { /* Only try to set the speed if the CSR firmware is new enough (temporarily setting the speed does not work correctly in 9.x) */ if (firmware >= 90) { D(syslog(LOG_INFO, "Setting baudrate in CSR module [%s baud]", speedstr)); bt_set_baudrate(bt_cfd, speedstr); /* Now set phys device speed to whatever HW was set to use */ fd_setup(phys_fd, speedstr, USE_CURRENT_FLOW); tcflush(phys_fd, TCIOFLUSH); D(syslog(LOG_INFO, "Baudrate set")); } else { syslog(LOG_INFO, "Did not set baudrate in CSR module as its firmware is too old (%d)", firmware); } }}intcsr_set_max_power(int bt_cfd, short max_power){ short old_max_power = SHRT_MAX; /* We need to wait a little here for some reason, or the reading of the current maximum power may fail and return 0 */ usleep(50000); csr_pskey(bt_cfd, PSKEY_LC_MAX_TX_POWER, CSR_PSKEY_GETREQ, (unsigned short *)&old_max_power, 1); if (old_max_power != max_power) { csr_pskey(bt_cfd, PSKEY_LC_MAX_TX_POWER, CSR_PSKEY_SETREQ, (unsigned short *)&max_power, 1); if (restart_btd() < 0) { syslog(LOG_INFO, "Failed to restart btd"); } } return 0;}/* ===============================================================*//* Digianswer specific commands *//* ===============================================================*//* Set the phys device to Digianswer default, 9600 */ voiddigianswer_init_phys(int fd, int flow_control){ fd_setup(fd, "9600", flow_control);}voiddigianswer_init_hw(int bt_cfd, int phys_fd, const char *speedstr){ /* Connection setup, all devices, no auto accept */ unsigned char filter[3] = { 0x02, 0x00, 0x01 }; D(syslog(LOG_INFO, "Setting baudrate in Digianswer PC card")); bt_set_event_filter(bt_cfd, filter); if (speedstr) { bt_set_baudrate(bt_cfd, speedstr); if (speedstrtoli(speedstr) > 115200) { printf("WARNING: Does this HW really support speeds > 115200?\n"); } /* Now set phys device speed to whatever HW was set to use */ fd_setup(phys_fd, speedstr, USE_CURRENT_FLOW); tcflush(phys_fd, TCIOFLUSH); }}/* ===============================================================*//* Ericsson specific commands *//* ===============================================================*//* Set the phys device to Ericsson default speed, 57600 */voidericsson_init_phys(int fd, int flow_control){ fd_setup(fd, "57600", flow_control);}voidericsson_init_hw(int bt_cfd, int phys_fd, const char *speedstr){ /* Connection setup, all devices, no auto accept */ unsigned char filter[3] = { 0x02, 0x00, 0x01 }; unsigned int wrscan = (PAGE_SCAN_ENABLE | INQUIRY_SCAN_ENABLE); bt_write_scan_enable(bt_cfd, wrscan); sleep(1); /* set_event_filter must be called for m/s switch on IrmaC! */ bt_set_event_filter(bt_cfd, filter); sleep(1); // wait for HW... if (speedstr) { D(syslog(LOG_INFO, "Setting baudrate in Ericsson module")); bt_set_baudrate(bt_cfd, speedstr); usleep(10000); /* Now set phys device speed to whatever HW was set to use */ fd_setup(phys_fd, speedstr, USE_CURRENT_FLOW); tcflush(phys_fd, TCIOFLUSH); }}/* ===============================================================*//* Infineon specific commands *//* ===============================================================*/voidinfineon_init_phys(int fd, int flow_control){ fd_setup(fd, "115200", flow_control);}voidinfineon_init_hw(int bt_cfd, int phys_fd, const char *speedstr){ unsigned int wrscan = (PAGE_SCAN_ENABLE | INQUIRY_SCAN_ENABLE); sleep(1); D(syslog(LOG_INFO, "Setting write_scan_enable in Infineon module")); bt_write_scan_enable(bt_cfd, wrscan); sleep(1); // wait for HW... if (speedstr) { D(syslog(LOG_INFO, "Setting baudrate in Infineon module")); bt_set_baudrate(bt_cfd, speedstr); /* Now set phys device speed to whatever HW was set to use */ fd_setup(phys_fd, speedstr, USE_CURRENT_FLOW); tcflush(phys_fd, TCIOFLUSH); }}/* ===============================================================*//* USB specific commands *//* ===============================================================*/voidusb_init_phys(int fd, int flow_control){ fd_setup(fd, "115200", flow_control);}voidusb_init_hw(int bt_cfd, int phys_fd, const char *speedstr){ /* Connection setup, all devices, no auto accept */ unsigned char filter[3] = { 0x02, 0x00, 0x01 }; unsigned int wrscan = (PAGE_SCAN_ENABLE | INQUIRY_SCAN_ENABLE); D(syslog(LOG_INFO, "Setting write_scan_enable in USB module")); bt_write_scan_enable(bt_cfd, wrscan); /* improves reliability when doing a connect */ D(syslog(LOG_INFO, "Setting write_pagescan_activity in USB module")); bt_write_pagescan_activity(bt_cfd, 0x0800, 0x12); sleep(1); bt_set_event_filter(bt_cfd, filter);}/* ===============================================================*//* Generic commands *//* ===============================================================*/voidgeneric_init_phys(int fd, int flow_control){ fd_setup(fd, "115200", flow_control);}voidgeneric_init_hw(int bt_cfd, int phys_fd, const char *speedstr){ /* Connection setup, all devices, no auto accept */ unsigned char filter[3] = { 0x02, 0x00, 0x01 }; unsigned int wrscan = (PAGE_SCAN_ENABLE | INQUIRY_SCAN_ENABLE); D(syslog(LOG_INFO, "Setting write_scan_enable in generic module")); bt_write_scan_enable(bt_cfd, wrscan); bt_set_event_filter(bt_cfd, filter);}/* ===============================================================*//* No HW init commands *//* ===============================================================*/voidno_init_phys(int fd, int flow_control){}voidno_init_hw(int bt_cfd, int phys_fd, const char *speedstr){}/* ===============================================================*//* Default *//* ===============================================================*/voidunknown_init_phys(int fd, int flow_control){ printf("ERROR: init_phys() not implemented!\n");}voidunknown_init_hw(int bt_cfd, int phys_fd, const char *speedstr){ printf("ERROR: init_hw() not implemented!\n");}/*********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -